text
stringlengths
1
1.05M
; float _fmul2 (float number) __z88dk_fastcall SECTION code_clib SECTION code_fp_am9511 PUBLIC asm_fmul2 EXTERN asm_am9511_fmul2_fastcall ; Multiply a float by 2 ; ; enter : stack = ret ; DEHL = sccz80_float number ; ; exit : DEHL = 2 * sccz80_float ; ; uses : de, hl defc asm_fmul2 = asm_am9511_fmul2_fastcall
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r15 push %r9 push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x17585, %r15 nop nop nop nop lfence movb $0x61, (%r15) nop nop nop xor %r12, %r12 lea addresses_WC_ht+0x14cf1, %rcx cmp $10208, %rbx mov $0x6162636465666768, %r10 movq %r10, (%rcx) nop nop nop add %rcx, %rcx lea addresses_UC_ht+0x4542, %r10 nop nop nop nop add $55583, %r15 mov $0x6162636465666768, %rdi movq %rdi, %xmm5 movups %xmm5, (%r10) nop nop nop nop xor %r15, %r15 lea addresses_UC_ht+0x965b, %rbx nop nop nop nop nop and %r10, %r10 mov (%rbx), %r12 nop xor $6991, %r12 lea addresses_D_ht+0x50fb, %rdi cmp $53437, %r10 movb (%rdi), %cl nop nop nop add $39746, %rcx lea addresses_A_ht+0xda5b, %rsi lea addresses_D_ht+0x1a51f, %rdi nop add %r9, %r9 mov $41, %rcx rep movsw nop add %r10, %r10 lea addresses_WT_ht+0x1dd5b, %rsi lea addresses_WC_ht+0x625b, %rdi clflush (%rsi) nop nop nop nop nop add %rbx, %rbx mov $28, %rcx rep movsb nop nop xor $56602, %r10 pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r15 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r8 push %r9 push %rax push %rdx push %rsi // Load lea addresses_WT+0x3edb, %r9 nop nop nop xor %r8, %r8 mov (%r9), %r12 cmp $15083, %r12 // Store lea addresses_UC+0x15c5b, %r12 cmp %rsi, %rsi movl $0x51525354, (%r12) nop nop nop nop nop add $12183, %rax // Store lea addresses_D+0x12ff7, %rax nop nop nop nop add $7709, %rsi mov $0x5152535455565758, %r8 movq %r8, %xmm4 vmovups %ymm4, (%rax) nop nop nop add %r12, %r12 // Load lea addresses_A+0x1aa5b, %r9 nop nop nop nop sub %rdx, %rdx mov (%r9), %r12 nop nop nop nop xor %r10, %r10 // Load lea addresses_A+0x1aa5b, %r9 nop nop sub $16716, %r12 movups (%r9), %xmm7 vpextrq $1, %xmm7, %rsi nop nop inc %r10 // Store mov $0xa3b, %r12 nop nop dec %r8 movl $0x51525354, (%r12) nop cmp $52493, %r12 // Faulty Load lea addresses_A+0x1aa5b, %rax and $54518, %r12 mov (%rax), %rsi lea oracles, %rax and $0xff, %rsi shlq $12, %rsi mov (%rax,%rsi,1), %rsi pop %rsi pop %rdx pop %rax pop %r9 pop %r8 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_P', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}} {'35': 203} 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 */
; int esxdos_f_fstat(uchar handle, void *buf) SECTION code_clib SECTION code_esxdos PUBLIC esxdos_f_fstat_callee EXTERN asm_esxdos_f_fstat esxdos_f_fstat_callee: pop af pop hl pop bc push af ld a,c jp asm_esxdos_f_fstat
; A057656: Number of points (x,y) in square lattice with (x-1/2)^2+y^2 <= n. ; 2,6,8,12,16,16,22,26,26,30,34,38,40,44,44,48,56,56,60,60,62,70,74,74,78,82,82,86,90,94,96,104,104,104,108,108,116,120,124,128,128,128,134,138,138,142,150,150,154,158,158,166,166,166,166,174 lpb $0 mov $2,$0 sub $0,1 seq $2,8441 ; Number of ways of writing n as the sum of 2 triangular numbers. add $3,$2 lpe mov $0,$3 mul $0,2 add $0,2
; A122507: Triangular in which row n contains first n terms of A018805. ; 1,1,3,1,3,7,1,3,7,11,1,3,7,11,19,1,3,7,11,19,23,1,3,7,11,19,23,35,1,3,7,11,19,23,35,43,1,3,7,11,19,23,35,43,55,1,3,7,11,19,23,35,43,55,63,1,3,7,11,19,23,35,43,55,63,83 seq $0,25675 ; Exponent of 8 (value of j) in n-th number of form 7^i*8^j. seq $0,15614 ; a(n) = -1 + Sum_{i=1..n} phi(i). mul $0,2 add $0,1
#ifndef OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_ #define OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_ /* Copyright 2010, Object Management Group, Inc. * Copyright 2010, PrismTech, Corp. * Copyright 2010, Real-Time Innovations, Inc. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <dds/core/Exception.hpp> #include <dds/core/ref_traits.hpp> #include <dds/topic/detail/AnyTopicDescription.hpp> #include <dds/topic/Topic.hpp> namespace dds { namespace topic { class AnyTopicDescription { public: /** * Construct AnyTopicDescription from a TopicDescription. */ template <typename T> inline AnyTopicDescription(const dds::topic::TopicDescription<T>& t); public: /** * Get the DomainParticipant for the AnyTopicDescription. * * @return the DomainParticipant for the AnyTopicDescription */ const dds::domain::DomainParticipant& domain_participant() const; /** * Get the Topic name for the AnyTopicDescription. * * @return the Topic name */ const std::string& name() const; /** * Get the type name for the AnyTopicDescription. * * @return the type name */ const std::string& type_name() const; protected: inline AnyTopicDescription(detail::TDHolderBase* holder); public: /** * Swap two AnyTopicDescription. */ inline AnyTopicDescription& swap(AnyTopicDescription& rhs); /** * Assign a typed Topic to a AnyTopicDescription. */ template <typename T> AnyTopicDescription& operator =(const dds::topic::Topic<T>& rhs); /** * Assign AnyTopicDescription to another AnyTopicDescription. */ inline AnyTopicDescription& operator =(AnyTopicDescription rhs); public: /** * Get a typed TopicDescription from an * AnyTopicDescription. * * @return the typed DataReader */ template <typename T> const dds::topic::TopicDescription<T>& get(); public: /** * Operator overload to get. */ const detail::TDHolderBase* operator->() const; /** * Operator overload to get. */ detail::TDHolderBase* operator->(); protected: dds::core::smart_ptr_traits<detail::TDHolderBase>::ref_type holder_; }; } } #endif /* OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_ */
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r13 push %r14 push %rbp push %rcx push %rdi push %rsi lea addresses_UC_ht+0xc773, %r12 clflush (%r12) nop nop nop nop sub $24743, %r10 movb (%r12), %r14b nop nop nop nop xor $32409, %rcx lea addresses_WT_ht+0x18a3b, %r12 nop nop nop nop nop xor %r11, %r11 movw $0x6162, (%r12) nop nop xor $60827, %r14 lea addresses_normal_ht+0xf33, %r10 nop dec %rbp mov (%r10), %r12 nop nop nop nop sub $5711, %rcx lea addresses_A_ht+0x1de33, %r12 nop nop nop sub %r13, %r13 mov $0x6162636465666768, %r14 movq %r14, %xmm6 vmovups %ymm6, (%r12) nop nop nop nop nop xor $23090, %rbp lea addresses_WT_ht+0xa173, %rbp nop nop nop nop xor $26176, %r11 mov (%rbp), %ecx xor $26851, %r14 lea addresses_normal_ht+0x13e93, %rcx nop nop nop and $12593, %r11 movb $0x61, (%rcx) and %r10, %r10 lea addresses_WC_ht+0x17f27, %r10 nop nop nop dec %rbp movw $0x6162, (%r10) nop nop xor $34785, %r10 lea addresses_WC_ht+0x1e273, %rsi lea addresses_D_ht+0x8df3, %rdi clflush (%rsi) sub %r14, %r14 mov $51, %rcx rep movsb nop nop nop nop cmp %rcx, %rcx lea addresses_WC_ht+0x19473, %r12 nop cmp $30505, %rcx mov $0x6162636465666768, %r13 movq %r13, (%r12) nop nop add $65073, %r11 lea addresses_WC_ht+0xea5b, %r12 nop nop nop nop nop sub %rcx, %rcx movw $0x6162, (%r12) sub $31885, %r14 pop %rsi pop %rdi pop %rcx pop %rbp pop %r14 pop %r13 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %r15 push %r8 push %r9 push %rsi // Store mov $0x6b7bb10000000173, %r9 nop nop nop nop inc %r8 movb $0x51, (%r9) nop nop nop add %r9, %r9 // Store lea addresses_US+0xf973, %r15 nop nop nop xor %rsi, %rsi mov $0x5152535455565758, %r14 movq %r14, %xmm3 movups %xmm3, (%r15) nop nop nop add $29254, %r11 // Store lea addresses_US+0x2e7f, %r14 xor $32557, %r11 movw $0x5152, (%r14) nop nop nop add %r12, %r12 // Store lea addresses_WC+0xfb47, %r15 nop nop nop nop nop and $62196, %r9 mov $0x5152535455565758, %r14 movq %r14, %xmm4 movups %xmm4, (%r15) nop nop nop nop and %r8, %r8 // Load lea addresses_WC+0x1eae2, %r9 cmp %r8, %r8 mov (%r9), %r14d nop nop nop nop sub %rsi, %rsi // Faulty Load lea addresses_US+0xf973, %r15 sub %r12, %r12 movups (%r15), %xmm5 vpextrq $1, %xmm5, %rsi lea oracles, %r9 and $0xff, %rsi shlq $12, %rsi mov (%r9,%rsi,1), %rsi pop %rsi pop %r9 pop %r8 pop %r15 pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 4, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': True}} {'00': 6007} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
_forktest: file format elf32-i386 Disassembly of section .text: 00000000 <main>: printf(1, "fork test OK\n"); } int main(void) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 51 push %ecx e: 83 ec 04 sub $0x4,%esp forktest(); 11: e8 3a 00 00 00 call 50 <forktest> exit(); 16: e8 87 03 00 00 call 3a2 <exit> 1b: 66 90 xchg %ax,%ax 1d: 66 90 xchg %ax,%ax 1f: 90 nop 00000020 <printf>: { 20: 55 push %ebp 21: 89 e5 mov %esp,%ebp 23: 53 push %ebx 24: 83 ec 10 sub $0x10,%esp 27: 8b 5d 0c mov 0xc(%ebp),%ebx write(fd, s, strlen(s)); 2a: 53 push %ebx 2b: e8 a0 01 00 00 call 1d0 <strlen> 30: 83 c4 0c add $0xc,%esp 33: 50 push %eax 34: 53 push %ebx 35: ff 75 08 pushl 0x8(%ebp) 38: e8 85 03 00 00 call 3c2 <write> } 3d: 83 c4 10 add $0x10,%esp 40: 8b 5d fc mov -0x4(%ebp),%ebx 43: c9 leave 44: c3 ret 45: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 49: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000050 <forktest>: { 50: 55 push %ebp 51: 89 e5 mov %esp,%ebp 53: 53 push %ebx for(n=0; n<N; n++){ 54: 31 db xor %ebx,%ebx { 56: 83 ec 10 sub $0x10,%esp write(fd, s, strlen(s)); 59: 68 84 04 00 00 push $0x484 5e: e8 6d 01 00 00 call 1d0 <strlen> 63: 83 c4 0c add $0xc,%esp 66: 50 push %eax 67: 68 84 04 00 00 push $0x484 6c: 6a 01 push $0x1 6e: e8 4f 03 00 00 call 3c2 <write> 73: 83 c4 10 add $0x10,%esp 76: eb 19 jmp 91 <forktest+0x41> 78: 90 nop 79: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(pid == 0) 80: 0f 84 7c 00 00 00 je 102 <forktest+0xb2> for(n=0; n<N; n++){ 86: 83 c3 01 add $0x1,%ebx 89: 81 fb e8 03 00 00 cmp $0x3e8,%ebx 8f: 74 4f je e0 <forktest+0x90> pid = fork(); 91: e8 04 03 00 00 call 39a <fork> if(pid < 0) 96: 85 c0 test %eax,%eax 98: 79 e6 jns 80 <forktest+0x30> for(; n > 0; n--){ 9a: 85 db test %ebx,%ebx 9c: 74 10 je ae <forktest+0x5e> 9e: 66 90 xchg %ax,%ax if(wait() < 0){ a0: e8 05 03 00 00 call 3aa <wait> a5: 85 c0 test %eax,%eax a7: 78 5e js 107 <forktest+0xb7> for(; n > 0; n--){ a9: 83 eb 01 sub $0x1,%ebx ac: 75 f2 jne a0 <forktest+0x50> if(wait() != -1){ ae: e8 f7 02 00 00 call 3aa <wait> b3: 83 f8 ff cmp $0xffffffff,%eax b6: 75 71 jne 129 <forktest+0xd9> write(fd, s, strlen(s)); b8: 83 ec 0c sub $0xc,%esp bb: 68 b6 04 00 00 push $0x4b6 c0: e8 0b 01 00 00 call 1d0 <strlen> c5: 83 c4 0c add $0xc,%esp c8: 50 push %eax c9: 68 b6 04 00 00 push $0x4b6 ce: 6a 01 push $0x1 d0: e8 ed 02 00 00 call 3c2 <write> } d5: 8b 5d fc mov -0x4(%ebp),%ebx d8: c9 leave d9: c3 ret da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi write(fd, s, strlen(s)); e0: 83 ec 0c sub $0xc,%esp e3: 68 c4 04 00 00 push $0x4c4 e8: e8 e3 00 00 00 call 1d0 <strlen> ed: 83 c4 0c add $0xc,%esp f0: 50 push %eax f1: 68 c4 04 00 00 push $0x4c4 f6: 6a 01 push $0x1 f8: e8 c5 02 00 00 call 3c2 <write> exit(); fd: e8 a0 02 00 00 call 3a2 <exit> exit(); 102: e8 9b 02 00 00 call 3a2 <exit> write(fd, s, strlen(s)); 107: 83 ec 0c sub $0xc,%esp 10a: 68 8f 04 00 00 push $0x48f 10f: e8 bc 00 00 00 call 1d0 <strlen> 114: 83 c4 0c add $0xc,%esp 117: 50 push %eax 118: 68 8f 04 00 00 push $0x48f 11d: 6a 01 push $0x1 11f: e8 9e 02 00 00 call 3c2 <write> exit(); 124: e8 79 02 00 00 call 3a2 <exit> write(fd, s, strlen(s)); 129: 83 ec 0c sub $0xc,%esp 12c: 68 a3 04 00 00 push $0x4a3 131: e8 9a 00 00 00 call 1d0 <strlen> 136: 83 c4 0c add $0xc,%esp 139: 50 push %eax 13a: 68 a3 04 00 00 push $0x4a3 13f: 6a 01 push $0x1 141: e8 7c 02 00 00 call 3c2 <write> exit(); 146: e8 57 02 00 00 call 3a2 <exit> 14b: 66 90 xchg %ax,%ax 14d: 66 90 xchg %ax,%ax 14f: 90 nop 00000150 <strcpy>: 150: 55 push %ebp 151: 89 e5 mov %esp,%ebp 153: 53 push %ebx 154: 8b 45 08 mov 0x8(%ebp),%eax 157: 8b 4d 0c mov 0xc(%ebp),%ecx 15a: 89 c2 mov %eax,%edx 15c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 160: 83 c1 01 add $0x1,%ecx 163: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 167: 83 c2 01 add $0x1,%edx 16a: 84 db test %bl,%bl 16c: 88 5a ff mov %bl,-0x1(%edx) 16f: 75 ef jne 160 <strcpy+0x10> 171: 5b pop %ebx 172: 5d pop %ebp 173: c3 ret 174: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 17a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000180 <strcmp>: 180: 55 push %ebp 181: 89 e5 mov %esp,%ebp 183: 53 push %ebx 184: 8b 55 08 mov 0x8(%ebp),%edx 187: 8b 4d 0c mov 0xc(%ebp),%ecx 18a: 0f b6 02 movzbl (%edx),%eax 18d: 0f b6 19 movzbl (%ecx),%ebx 190: 84 c0 test %al,%al 192: 75 1c jne 1b0 <strcmp+0x30> 194: eb 2a jmp 1c0 <strcmp+0x40> 196: 8d 76 00 lea 0x0(%esi),%esi 199: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 1a0: 83 c2 01 add $0x1,%edx 1a3: 0f b6 02 movzbl (%edx),%eax 1a6: 83 c1 01 add $0x1,%ecx 1a9: 0f b6 19 movzbl (%ecx),%ebx 1ac: 84 c0 test %al,%al 1ae: 74 10 je 1c0 <strcmp+0x40> 1b0: 38 d8 cmp %bl,%al 1b2: 74 ec je 1a0 <strcmp+0x20> 1b4: 29 d8 sub %ebx,%eax 1b6: 5b pop %ebx 1b7: 5d pop %ebp 1b8: c3 ret 1b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1c0: 31 c0 xor %eax,%eax 1c2: 29 d8 sub %ebx,%eax 1c4: 5b pop %ebx 1c5: 5d pop %ebp 1c6: c3 ret 1c7: 89 f6 mov %esi,%esi 1c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001d0 <strlen>: 1d0: 55 push %ebp 1d1: 89 e5 mov %esp,%ebp 1d3: 8b 4d 08 mov 0x8(%ebp),%ecx 1d6: 80 39 00 cmpb $0x0,(%ecx) 1d9: 74 15 je 1f0 <strlen+0x20> 1db: 31 d2 xor %edx,%edx 1dd: 8d 76 00 lea 0x0(%esi),%esi 1e0: 83 c2 01 add $0x1,%edx 1e3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 1e7: 89 d0 mov %edx,%eax 1e9: 75 f5 jne 1e0 <strlen+0x10> 1eb: 5d pop %ebp 1ec: c3 ret 1ed: 8d 76 00 lea 0x0(%esi),%esi 1f0: 31 c0 xor %eax,%eax 1f2: 5d pop %ebp 1f3: c3 ret 1f4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1fa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000200 <memset>: 200: 55 push %ebp 201: 89 e5 mov %esp,%ebp 203: 57 push %edi 204: 8b 55 08 mov 0x8(%ebp),%edx 207: 8b 4d 10 mov 0x10(%ebp),%ecx 20a: 8b 45 0c mov 0xc(%ebp),%eax 20d: 89 d7 mov %edx,%edi 20f: fc cld 210: f3 aa rep stos %al,%es:(%edi) 212: 89 d0 mov %edx,%eax 214: 5f pop %edi 215: 5d pop %ebp 216: c3 ret 217: 89 f6 mov %esi,%esi 219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000220 <strchr>: 220: 55 push %ebp 221: 89 e5 mov %esp,%ebp 223: 53 push %ebx 224: 8b 45 08 mov 0x8(%ebp),%eax 227: 8b 5d 0c mov 0xc(%ebp),%ebx 22a: 0f b6 10 movzbl (%eax),%edx 22d: 84 d2 test %dl,%dl 22f: 74 1d je 24e <strchr+0x2e> 231: 38 d3 cmp %dl,%bl 233: 89 d9 mov %ebx,%ecx 235: 75 0d jne 244 <strchr+0x24> 237: eb 17 jmp 250 <strchr+0x30> 239: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 240: 38 ca cmp %cl,%dl 242: 74 0c je 250 <strchr+0x30> 244: 83 c0 01 add $0x1,%eax 247: 0f b6 10 movzbl (%eax),%edx 24a: 84 d2 test %dl,%dl 24c: 75 f2 jne 240 <strchr+0x20> 24e: 31 c0 xor %eax,%eax 250: 5b pop %ebx 251: 5d pop %ebp 252: c3 ret 253: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000260 <gets>: 260: 55 push %ebp 261: 89 e5 mov %esp,%ebp 263: 57 push %edi 264: 56 push %esi 265: 53 push %ebx 266: 31 f6 xor %esi,%esi 268: 89 f3 mov %esi,%ebx 26a: 83 ec 1c sub $0x1c,%esp 26d: 8b 7d 08 mov 0x8(%ebp),%edi 270: eb 2f jmp 2a1 <gets+0x41> 272: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 278: 8d 45 e7 lea -0x19(%ebp),%eax 27b: 83 ec 04 sub $0x4,%esp 27e: 6a 01 push $0x1 280: 50 push %eax 281: 6a 00 push $0x0 283: e8 32 01 00 00 call 3ba <read> 288: 83 c4 10 add $0x10,%esp 28b: 85 c0 test %eax,%eax 28d: 7e 1c jle 2ab <gets+0x4b> 28f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 293: 83 c7 01 add $0x1,%edi 296: 88 47 ff mov %al,-0x1(%edi) 299: 3c 0a cmp $0xa,%al 29b: 74 23 je 2c0 <gets+0x60> 29d: 3c 0d cmp $0xd,%al 29f: 74 1f je 2c0 <gets+0x60> 2a1: 83 c3 01 add $0x1,%ebx 2a4: 3b 5d 0c cmp 0xc(%ebp),%ebx 2a7: 89 fe mov %edi,%esi 2a9: 7c cd jl 278 <gets+0x18> 2ab: 89 f3 mov %esi,%ebx 2ad: 8b 45 08 mov 0x8(%ebp),%eax 2b0: c6 03 00 movb $0x0,(%ebx) 2b3: 8d 65 f4 lea -0xc(%ebp),%esp 2b6: 5b pop %ebx 2b7: 5e pop %esi 2b8: 5f pop %edi 2b9: 5d pop %ebp 2ba: c3 ret 2bb: 90 nop 2bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 2c0: 8b 75 08 mov 0x8(%ebp),%esi 2c3: 8b 45 08 mov 0x8(%ebp),%eax 2c6: 01 de add %ebx,%esi 2c8: 89 f3 mov %esi,%ebx 2ca: c6 03 00 movb $0x0,(%ebx) 2cd: 8d 65 f4 lea -0xc(%ebp),%esp 2d0: 5b pop %ebx 2d1: 5e pop %esi 2d2: 5f pop %edi 2d3: 5d pop %ebp 2d4: c3 ret 2d5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 2d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002e0 <stat>: 2e0: 55 push %ebp 2e1: 89 e5 mov %esp,%ebp 2e3: 56 push %esi 2e4: 53 push %ebx 2e5: 83 ec 08 sub $0x8,%esp 2e8: 6a 00 push $0x0 2ea: ff 75 08 pushl 0x8(%ebp) 2ed: e8 f0 00 00 00 call 3e2 <open> 2f2: 83 c4 10 add $0x10,%esp 2f5: 85 c0 test %eax,%eax 2f7: 78 27 js 320 <stat+0x40> 2f9: 83 ec 08 sub $0x8,%esp 2fc: ff 75 0c pushl 0xc(%ebp) 2ff: 89 c3 mov %eax,%ebx 301: 50 push %eax 302: e8 f3 00 00 00 call 3fa <fstat> 307: 89 1c 24 mov %ebx,(%esp) 30a: 89 c6 mov %eax,%esi 30c: e8 b9 00 00 00 call 3ca <close> 311: 83 c4 10 add $0x10,%esp 314: 8d 65 f8 lea -0x8(%ebp),%esp 317: 89 f0 mov %esi,%eax 319: 5b pop %ebx 31a: 5e pop %esi 31b: 5d pop %ebp 31c: c3 ret 31d: 8d 76 00 lea 0x0(%esi),%esi 320: be ff ff ff ff mov $0xffffffff,%esi 325: eb ed jmp 314 <stat+0x34> 327: 89 f6 mov %esi,%esi 329: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000330 <atoi>: 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 53 push %ebx 334: 8b 4d 08 mov 0x8(%ebp),%ecx 337: 0f be 11 movsbl (%ecx),%edx 33a: 8d 42 d0 lea -0x30(%edx),%eax 33d: 3c 09 cmp $0x9,%al 33f: b8 00 00 00 00 mov $0x0,%eax 344: 77 1f ja 365 <atoi+0x35> 346: 8d 76 00 lea 0x0(%esi),%esi 349: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 350: 8d 04 80 lea (%eax,%eax,4),%eax 353: 83 c1 01 add $0x1,%ecx 356: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax 35a: 0f be 11 movsbl (%ecx),%edx 35d: 8d 5a d0 lea -0x30(%edx),%ebx 360: 80 fb 09 cmp $0x9,%bl 363: 76 eb jbe 350 <atoi+0x20> 365: 5b pop %ebx 366: 5d pop %ebp 367: c3 ret 368: 90 nop 369: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000370 <memmove>: 370: 55 push %ebp 371: 89 e5 mov %esp,%ebp 373: 56 push %esi 374: 53 push %ebx 375: 8b 5d 10 mov 0x10(%ebp),%ebx 378: 8b 45 08 mov 0x8(%ebp),%eax 37b: 8b 75 0c mov 0xc(%ebp),%esi 37e: 85 db test %ebx,%ebx 380: 7e 14 jle 396 <memmove+0x26> 382: 31 d2 xor %edx,%edx 384: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 388: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 38c: 88 0c 10 mov %cl,(%eax,%edx,1) 38f: 83 c2 01 add $0x1,%edx 392: 39 d3 cmp %edx,%ebx 394: 75 f2 jne 388 <memmove+0x18> 396: 5b pop %ebx 397: 5e pop %esi 398: 5d pop %ebp 399: c3 ret 0000039a <fork>: 39a: b8 01 00 00 00 mov $0x1,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <exit>: 3a2: b8 02 00 00 00 mov $0x2,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <wait>: 3aa: b8 03 00 00 00 mov $0x3,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <pipe>: 3b2: b8 04 00 00 00 mov $0x4,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <read>: 3ba: b8 05 00 00 00 mov $0x5,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <write>: 3c2: b8 10 00 00 00 mov $0x10,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <close>: 3ca: b8 15 00 00 00 mov $0x15,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <kill>: 3d2: b8 06 00 00 00 mov $0x6,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 000003da <exec>: 3da: b8 07 00 00 00 mov $0x7,%eax 3df: cd 40 int $0x40 3e1: c3 ret 000003e2 <open>: 3e2: b8 0f 00 00 00 mov $0xf,%eax 3e7: cd 40 int $0x40 3e9: c3 ret 000003ea <mknod>: 3ea: b8 11 00 00 00 mov $0x11,%eax 3ef: cd 40 int $0x40 3f1: c3 ret 000003f2 <unlink>: 3f2: b8 12 00 00 00 mov $0x12,%eax 3f7: cd 40 int $0x40 3f9: c3 ret 000003fa <fstat>: 3fa: b8 08 00 00 00 mov $0x8,%eax 3ff: cd 40 int $0x40 401: c3 ret 00000402 <link>: 402: b8 13 00 00 00 mov $0x13,%eax 407: cd 40 int $0x40 409: c3 ret 0000040a <mkdir>: 40a: b8 14 00 00 00 mov $0x14,%eax 40f: cd 40 int $0x40 411: c3 ret 00000412 <chdir>: 412: b8 09 00 00 00 mov $0x9,%eax 417: cd 40 int $0x40 419: c3 ret 0000041a <dup>: 41a: b8 0a 00 00 00 mov $0xa,%eax 41f: cd 40 int $0x40 421: c3 ret 00000422 <getpid>: 422: b8 0b 00 00 00 mov $0xb,%eax 427: cd 40 int $0x40 429: c3 ret 0000042a <sbrk>: 42a: b8 0c 00 00 00 mov $0xc,%eax 42f: cd 40 int $0x40 431: c3 ret 00000432 <sleep>: 432: b8 0d 00 00 00 mov $0xd,%eax 437: cd 40 int $0x40 439: c3 ret 0000043a <uptime>: 43a: b8 0e 00 00 00 mov $0xe,%eax 43f: cd 40 int $0x40 441: c3 ret 00000442 <hello>: 442: b8 16 00 00 00 mov $0x16,%eax 447: cd 40 int $0x40 449: c3 ret 0000044a <hello_name>: 44a: b8 17 00 00 00 mov $0x17,%eax 44f: cd 40 int $0x40 451: c3 ret 00000452 <get_num_proc>: 452: b8 18 00 00 00 mov $0x18,%eax 457: cd 40 int $0x40 459: c3 ret 0000045a <get_max_pid>: 45a: b8 19 00 00 00 mov $0x19,%eax 45f: cd 40 int $0x40 461: c3 ret 00000462 <get_proc_info>: 462: b8 1a 00 00 00 mov $0x1a,%eax 467: cd 40 int $0x40 469: c3 ret 0000046a <cps>: 46a: b8 1b 00 00 00 mov $0x1b,%eax 46f: cd 40 int $0x40 471: c3 ret 00000472 <get_prio>: 472: b8 1c 00 00 00 mov $0x1c,%eax 477: cd 40 int $0x40 479: c3 ret 0000047a <set_prio>: 47a: b8 1d 00 00 00 mov $0x1d,%eax 47f: cd 40 int $0x40 481: c3 ret
.extern err_display .extern hard_halt .global err_0_isr .type err_0_isr, @function err_0_isr: # divide by zero fault pusha cld mov $0,%edx call err_display popa call hard_halt .global err_1_isr .type err_1_isr, @function err_1_isr: # debug pusha cld mov $1,%edx call err_display popa .global err_2_isr .type err_2_isr, @function err_2_isr: # non maskable interrupt pusha cld mov $2,%edx call err_display popa .global err_3_isr .type err_3_isr, @function err_3_isr: # breakpoint pusha cld mov $3,%edx call err_display popa .global err_4_isr .type err_4_isr, @function err_4_isr: # overflow pusha cld mov $4,%edx call err_display popa .global err_5_isr .type err_5_isr, @function err_5_isr: # bound range exceeded pusha cld mov $5,%edx call err_display popa .global err_6_isr .type err_6_isr, @function err_6_isr: # invalid opcode pusha cld mov $6,%edx call err_display popa .global err_7_isr .type err_7_isr, @function err_7_isr: # device not available pusha cld mov $7,%edx call err_display popa .global err_8_isr .type err_8_isr, @function err_8_isr: # double fault cld mov $8,%edx call err_display call hard_halt .global err_9_isr .type err_9_isr, @function err_9_isr: # unused (coprocessor segment overrun) call hard_halt .global err_A_isr .type err_A_isr, @function err_A_isr: # invalid tss pusha cld mov $0xA,%edx call err_display popa
; lzo1x_s1.asm -- lzo1x_decompress_asm ; ; This file is part of the LZO real-time data compression library. ; ; Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer ; Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer ; All Rights Reserved. ; ; The LZO library is free software; you can redistribute it and/or ; modify it under the terms of the GNU General Public License as ; published by the Free Software Foundation; either version 2 of ; the License, or (at your option) any later version. ; ; The LZO library is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with the LZO library; see the file COPYING. ; If not, write to the Free Software Foundation, Inc., ; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ; ; Markus F.X.J. Oberhumer ; <markus@oberhumer.com> ; http://www.oberhumer.com/opensource/lzo/ ; ; /***** DO NOT EDIT - GENERATED AUTOMATICALLY *****/ include asminit.def public _lzo1x_decompress_asm _lzo1x_decompress_asm: db 85,87,86,83,81,82,131,236,12,252,139,116,36,40,139,124 db 36,48,189,3,0,0,0,49,192,49,219,172,60,17,118,35 db 44,17,60,4,115,40,137,193,235,56,5,255,0,0,0,138 db 30,70,8,219,116,244,141,68,24,18,235,18,141,116,38,0 db 138,6,70,60,16,115,73,8,192,116,228,131,192,3,137,193 db 193,232,2,33,233,139,22,131,198,4,137,23,131,199,4,72 db 117,243,243,164,138,6,70,60,16,115,37,193,232,2,138,30 db 141,151,255,247,255,255,141,4,152,70,41,194,138,2,136,7 db 138,66,1,136,71,1,138,66,2,136,71,2,1,239,235,119 db 60,64,114,52,137,193,193,232,2,141,87,255,131,224,7,138 db 30,193,233,5,141,4,216,70,41,194,65,57,232,115,55,235 db 119,5,255,0,0,0,138,30,70,8,219,116,244,141,76,24 db 33,49,192,235,15,141,118,0,60,32,114,124,131,224,31,116 db 229,141,72,2,102,139,6,141,87,255,193,232,2,131,198,2 db 41,194,57,232,114,66,137,203,193,235,2,116,17,139,2,131 db 194,4,137,7,131,199,4,75,117,243,33,233,116,9,138,2 db 66,136,7,71,73,117,247,138,70,254,33,232,15,132,46,255 db 255,255,138,14,70,136,15,71,72,117,247,138,6,70,233,109 db 255,255,255,144,141,116,38,0,135,214,243,164,137,214,235,215 db 129,193,255,0,0,0,138,30,70,8,219,116,243,141,76,11 db 9,235,25,144,141,116,38,0,60,16,114,44,137,193,131,224 db 8,193,224,13,131,225,7,116,221,131,193,2,102,139,6,131 db 198,2,141,151,0,192,255,255,193,232,2,116,43,41,194,233 db 114,255,255,255,141,116,38,0,193,232,2,138,30,141,87,255 db 141,4,152,70,41,194,138,2,136,7,138,90,1,136,95,1 db 131,199,2,233,111,255,255,255,131,249,3,15,149,192,139,84 db 36,40,3,84,36,44,57,214,119,38,114,29,43,124,36,48 db 139,84,36,52,137,58,247,216,131,196,12,90,89,91,94,95 db 93,195,184,1,0,0,0,235,227,184,8,0,0,0,235,220 db 184,4,0,0,0,235,213,137,246,141,188,39,0,0,0,0 end
// The MIT License (MIT) // // Copyright (c) 2017 Darrell Wright // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files( the "Software" ), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #define BOOST_TEST_MODULE aoc_2017_day11 #include <daw/boost_test.h> #include <cstdint> #include <cstdlib> #include <iostream> #include "day11.h" namespace daw { namespace aoc_2017 { namespace day11 { BOOST_AUTO_TEST_CASE( test_001 ) { std::string tst = "ne,ne,ne"; auto ans = calc_dist( daw::string_view{tst.data( ), tst.size( )} ).final; BOOST_REQUIRE_EQUAL( ans, 3 ); } BOOST_AUTO_TEST_CASE( test_002 ) { std::string tst = "ne,ne,sw,sw"; auto ans = calc_dist( daw::string_view{tst.data( ), tst.size( )} ).final; BOOST_REQUIRE_EQUAL( ans, 0 ); } BOOST_AUTO_TEST_CASE( test_003 ) { std::string tst = "ne,ne,s,s"; auto ans = calc_dist( daw::string_view{tst.data( ), tst.size( )} ).final; BOOST_REQUIRE_EQUAL( ans, 2 ); } BOOST_AUTO_TEST_CASE( test_004 ) { std::string tst = "se,sw,se,sw,sw"; auto ans = calc_dist( daw::string_view{tst.data( ), tst.size( )} ).final; BOOST_REQUIRE_EQUAL( ans, 3 ); } BOOST_AUTO_TEST_CASE( test_005 ) { std::string tst = "ne,se,se,s,nw,s,ne,sw,s,nw,sw,sw,sw,sw,sw,s,sw,nw,nw,nw,nw,ne,nw,nw,n,n,n,nw,nw,nw,n,n,s,nw,sw,se,n,n,ne,n," "n,n,sw,n,ne,n,nw,n,sw,n,se,n,ne,ne,sw,n,n,ne,ne,ne,ne,s,se,ne,ne,ne,n,ne,ne,ne,sw,ne,ne,sw,se,se,ne,sw,nw," "se,s,nw,se,nw,se,se,se,se,se,ne,se,se,n,n,se,se,sw,se,se,se,se,se,se,se,se,se,ne,se,ne,se,se,s,se,se,se,se," "se,s,se,ne,s,se,s,se,ne,s,se,s,s,s,se,se,s,s,nw,s,s,s,se,s,s,s,s,nw,nw,s,s,nw,s,s,nw,s,s,s,s,s,s,s,nw,s,sw," "s,s,sw,s,s,s,s,s,ne,nw,s,s,n,s,sw,s,n,sw,sw,sw,sw,s,sw,sw,sw,sw,sw,sw,s,s,se,se,sw,sw,nw,s,s,s,s,sw,sw,sw," "ne,s,sw,s,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,nw,sw,sw,sw,se,se,sw,sw,sw,sw,sw,sw,sw,nw,nw,sw,sw,nw,nw,s,sw,sw,sw," "sw,se,sw,s,nw,se,sw,nw,sw,sw,sw,sw,sw,sw,nw,nw,sw,sw,sw,sw,sw,n,n,nw,sw,sw,nw,se,sw,nw,sw,ne,sw,nw,n,n,nw," "sw,nw,nw,nw,nw,nw,sw,n,nw,nw,sw,nw,n,nw,sw,nw,s,sw,sw,sw,nw,nw,sw,nw,nw,nw,sw,sw,nw,nw,nw,nw,nw,nw,sw,nw,nw," "nw,nw,ne,nw,ne,nw,nw,sw,nw,nw,se,nw,nw,se,nw,nw,nw,sw,n,n,nw,n,nw,nw,sw,nw,n,nw,s,nw,nw,ne,nw,nw,nw,nw,nw,n," "nw,n,nw,nw,nw,se,nw,nw,n,se,n,ne,nw,nw,nw,nw,nw,nw,n,nw,nw,nw,n,nw,ne,n,nw,se,n,nw,se,nw,n,n,s,nw,n,n,n,ne," "sw,n,se,nw,nw,nw,nw,nw,n,n,nw,n,nw,nw,nw,n,n,nw,s,nw,nw,nw,nw,n,n,sw,n,n,nw,nw,se,nw,ne,nw,n,nw,se,n,n,n,n," "n,n,n,n,n,n,n,n,n,n,n,nw,s,s,ne,nw,nw,ne,sw,nw,se,n,se,ne,ne,nw,nw,n,nw,s,n,se,n,n,n,n,n,n,n,n,n,n,n,n,nw,n," "n,n,n,nw,n,se,n,n,sw,n,n,ne,s,n,n,n,n,n,n,n,n,n,s,n,nw,n,n,ne,s,n,ne,se,n,n,ne,ne,n,s,s,n,n,nw,n,n,s,ne,n,n," "n,ne,ne,n,se,n,n,n,n,sw,n,sw,n,se,s,nw,n,n,n,ne,n,ne,n,ne,se,s,se,ne,n,n,n,ne,ne,ne,ne,ne,ne,n,ne,n,n,ne,n," "n,se,ne,n,n,n,n,se,ne,n,n,n,se,s,ne,ne,ne,ne,ne,ne,ne,sw,sw,ne,ne,ne,nw,n,ne,n,ne,ne,ne,n,ne,ne,sw,ne,n,se," "ne,nw,ne,n,s,ne,ne,ne,ne,n,ne,ne,ne,ne,ne,ne,sw,s,n,ne,n,ne,ne,ne,n,nw,sw,ne,ne,ne,ne,ne,ne,se,ne,n,s,ne,sw," "nw,ne,n,ne,n,n,ne,n,ne,ne,ne,s,ne,ne,ne,ne,ne,ne,se,ne,ne,ne,ne,ne,ne,s,ne,se,n,ne,sw,ne,n,ne,ne,ne,ne,ne," "ne,s,ne,ne,ne,ne,se,ne,s,ne,ne,ne,ne,s,ne,ne,s,ne,ne,ne,ne,ne,ne,ne,se,se,se,ne,ne,n,ne,ne,ne,s,n,ne,s,ne," "se,ne,ne,ne,ne,ne,s,sw,ne,s,ne,se,se,ne,nw,ne,se,se,se,ne,nw,sw,ne,ne,ne,ne,ne,ne,ne,ne,ne,s,se,ne,ne,se,s," "se,ne,se,ne,nw,s,se,ne,ne,se,se,se,s,ne,se,ne,sw,se,ne,se,se,ne,ne,ne,se,se,ne,se,nw,s,ne,ne,n,ne,ne,se,ne," "ne,se,ne,ne,se,ne,ne,ne,se,ne,nw,ne,ne,sw,se,se,sw,se,ne,ne,se,nw,sw,ne,s,ne,ne,se,ne,ne,s,se,ne,ne,ne,n,sw," "n,se,ne,ne,ne,se,n,ne,sw,ne,sw,se,se,ne,ne,se,ne,ne,se,se,se,se,nw,nw,se,se,ne,se,sw,ne,s,ne,ne,se,se,se,sw," "sw,se,ne,ne,nw,n,ne,se,ne,ne,se,se,se,ne,ne,sw,se,ne,se,ne,se,se,se,se,ne,se,se,se,ne,se,se,sw,se,se,se,se," "se,ne,se,se,se,se,se,ne,se,se,se,se,se,ne,ne,sw,se,se,ne,ne,ne,nw,se,se,nw,se,se,se,sw,se,se,se,sw,ne,se,se," "sw,se,s,se,se,se,se,se,se,s,se,se,s,s,se,se,se,se,se,se,se,sw,se,se,se,se,se,se,ne,n,se,se,n,se,se,se,sw,s," "ne,s,se,se,se,se,se,se,se,se,sw,ne,se,se,s,se,se,se,se,s,n,se,se,nw,se,ne,se,se,nw,se,se,se,se,n,se,se,se," "se,se,se,se,se,n,se,se,se,se,n,se,s,se,n,s,se,s,s,sw,se,s,se,n,se,sw,s,se,sw,se,se,se,se,se,se,se,se,se,se," "se,se,se,se,se,sw,n,sw,se,se,se,s,se,nw,se,s,s,s,se,s,se,se,sw,sw,se,se,ne,se,s,se,s,se,ne,s,s,se,s,nw,se," "se,s,sw,s,se,s,s,se,s,s,sw,nw,se,se,se,sw,s,nw,se,n,se,s,s,s,se,se,se,se,ne,ne,s,s,se,se,sw,s,s,se,se,nw,s," "nw,s,se,s,s,s,se,se,s,s,s,nw,n,sw,se,se,s,se,se,se,se,se,s,s,se,se,s,s,s,s,se,sw,se,ne,nw,sw,ne,s,s,s,se,n," "nw,se,se,se,s,se,ne,sw,s,s,se,s,s,s,nw,nw,s,s,se,s,s,se,s,s,s,sw,s,se,se,ne,s,se,s,nw,s,se,s,se,se,s,s,nw,n," "se,n,se,s,s,se,se,se,s,se,s,s,sw,s,s,nw,se,sw,s,sw,s,s,s,se,se,n,s,se,s,ne,s,s,se,s,se,se,s,nw,s,s,s,n,se," "sw,s,s,se,ne,s,s,s,n,s,s,s,s,nw,s,s,s,n,s,se,s,s,s,se,s,s,s,s,s,n,s,s,se,se,s,ne,se,se,s,s,ne,s,s,s,se,se," "se,nw,s,s,se,s,se,s,s,s,s,s,s,se,s,s,s,s,s,n,s,s,ne,n,s,s,s,s,n,n,ne,se,s,sw,s,s,s,s,s,s,s,ne,s,s,se,s,se," "se,s,s,s,s,s,ne,s,s,sw,s,se,nw,s,s,sw,s,s,s,sw,s,s,s,s,s,se,nw,s,s,s,s,s,sw,s,s,s,s,sw,s,nw,ne,se,s,ne,s,s," "s,nw,s,s,s,s,se,s,s,sw,s,s,s,s,s,s,s,se,s,sw,ne,s,s,s,s,sw,sw,sw,s,nw,s,ne,s,s,s,n,sw,sw,s,sw,sw,s,se,s,s," "se,s,s,s,s,sw,s,s,sw,s,s,s,s,nw,sw,s,s,sw,s,s,se,nw,s,s,s,s,s,nw,s,sw,s,s,n,s,s,s,n,sw,se,s,se,s,se,s,s,sw," "sw,n,sw,s,s,se,s,sw,sw,se,s,nw,s,sw,s,s,s,nw,s,s,s,s,sw,nw,sw,s,s,s,s,s,s,s,s,nw,s,sw,sw,sw,s,sw,n,s,sw,n," "sw,s,sw,sw,s,s,s,sw,s,s,n,n,s,sw,s,sw,s,s,sw,nw,s,se,s,s,s,n,s,s,se,sw,s,s,sw,s,s,sw,s,sw,sw,s,s,s,sw,s,s,s," "s,s,sw,sw,sw,se,n,s,sw,sw,sw,s,n,se,s,s,sw,s,s,sw,sw,se,se,sw,sw,sw,s,s,s,sw,s,sw,s,s,sw,sw,sw,se,s,sw,s,sw," "sw,sw,se,sw,sw,sw,n,sw,sw,s,s,s,sw,s,sw,sw,s,sw,ne,s,sw,s,s,sw,s,s,n,sw,s,s,sw,se,s,s,n,sw,sw,s,s,s,s,sw,nw," "se,sw,sw,sw,s,sw,s,sw,s,sw,s,sw,s,nw,s,s,sw,sw,s,s,sw,nw,ne,sw,sw,sw,sw,ne,s,s,sw,s,sw,sw,s,sw,sw,s,sw,sw," "sw,sw,s,sw,ne,sw,sw,s,nw,sw,s,s,s,s,sw,sw,se,ne,nw,sw,sw,sw,s,s,se,s,s,sw,s,sw,sw,s,n,ne,sw,sw,s,sw,s,sw,s," "sw,s,sw,sw,sw,sw,s,sw,s,sw,sw,s,nw,s,nw,s,sw,sw,sw,sw,s,sw,sw,s,sw,sw,s,se,s,sw,sw,sw,sw,sw,sw,sw,s,sw,sw," "sw,se,s,s,sw,sw,s,s,sw,sw,sw,s,sw,s,sw,sw,s,sw,sw,ne,sw,s,sw,s,sw,sw,sw,sw,s,sw,se,sw,sw,sw,sw,sw,sw,sw,sw," "sw,sw,nw,sw,sw,s,sw,sw,sw,nw,sw,sw,sw,se,n,sw,sw,s,s,sw,sw,sw,s,sw,sw,sw,nw,sw,sw,nw,sw,sw,sw,sw,s,n,sw,s," "sw,sw,sw,s,sw,se,sw,sw,sw,ne,sw,sw,sw,s,sw,sw,sw,n,sw,sw,s,sw,sw,s,sw,sw,s,se,s,sw,sw,sw,ne,sw,sw,sw,n,sw," "sw,sw,sw,sw,sw,ne,se,sw,sw,n,sw,sw,sw,sw,se,sw,sw,nw,sw,n,sw,sw,sw,sw,sw,se,sw,sw,sw,sw,sw,nw,sw,se,sw,sw," "sw,s,n,se,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,ne,sw,se,sw,se,sw,sw,sw,sw,sw,s,sw,nw,n,se,sw,ne,sw,sw,sw,n,s,se," "sw,se,sw,se,n,s,sw,sw,sw,nw,n,se,sw,sw,nw,sw,sw,ne,sw,sw,s,sw,sw,s,sw,sw,sw,nw,s,sw,s,s,sw,ne,sw,sw,sw,sw," "nw,sw,s,sw,nw,sw,nw,s,sw,sw,sw,s,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,ne,sw,s,sw,sw,sw,sw,nw,sw,sw,nw,sw,sw,nw," "sw,sw,nw,sw,sw,sw,sw,sw,sw,sw,sw,sw,nw,sw,sw,sw,s,sw,se,s,sw,sw,nw,sw,sw,n,se,sw,s,sw,sw,sw,nw,sw,sw,sw,sw," "sw,nw,nw,nw,sw,sw,sw,sw,sw,n,se,sw,sw,n,nw,sw,sw,n,sw,n,sw,sw,sw,sw,nw,se,nw,sw,sw,sw,ne,sw,nw,nw,sw,sw,sw," "sw,sw,nw,sw,nw,nw,nw,sw,sw,sw,ne,sw,sw,sw,se,sw,nw,ne,sw,sw,sw,nw,sw,sw,n,sw,nw,nw,nw,nw,sw,sw,sw,sw,sw,se," "sw,sw,ne,sw,s,sw,sw,sw,sw,sw,sw,sw,sw,ne,nw,sw,sw,nw,se,nw,sw,sw,sw,sw,sw,nw,nw,sw,sw,sw,ne,sw,nw,sw,sw,sw," "nw,sw,sw,sw,sw,ne,n,nw,sw,sw,nw,sw,nw,n,sw,sw,sw,ne,sw,sw,sw,nw,sw,nw,sw,nw,sw,sw,nw,se,sw,sw,nw,nw,nw,nw," "nw,nw,n,sw,sw,s,sw,sw,sw,s,se,sw,n,sw,se,nw,sw,sw,sw,sw,nw,nw,nw,se,sw,ne,sw,n,sw,se,sw,nw,nw,sw,nw,sw,sw," "sw,ne,sw,n,nw,sw,nw,se,sw,ne,se,nw,sw,nw,se,sw,nw,sw,se,n,nw,se,sw,n,se,sw,nw,se,s,sw,sw,nw,sw,sw,sw,nw,sw," "s,nw,ne,nw,sw,n,nw,nw,ne,ne,nw,ne,sw,nw,sw,nw,nw,nw,nw,sw,sw,se,sw,nw,sw,nw,sw,sw,sw,nw,nw,ne,nw,sw,sw,se," "sw,nw,sw,sw,sw,sw,se,sw,ne,nw,sw,sw,nw,nw,nw,sw,se,sw,nw,sw,sw,sw,nw,sw,sw,se,sw,nw,sw,ne,sw,sw,nw,nw,sw,sw," "ne,nw,sw,s,sw,sw,sw,nw,nw,n,nw,nw,sw,sw,sw,sw,sw,nw,nw,nw,nw,nw,nw,nw,sw,n,nw,sw,sw,n,nw,nw,sw,s,sw,ne,se," "nw,nw,nw,sw,nw,sw,nw,s,nw,nw,n,s,nw,s,nw,sw,sw,nw,nw,nw,nw,nw,nw,se,nw,se,nw,nw,s,sw,nw,nw,nw,se,nw,nw,sw," "sw,nw,sw,nw,sw,nw,s,nw,nw,nw,nw,sw,nw,ne,n,nw,nw,nw,sw,nw,nw,nw,sw,ne,nw,sw,nw,sw,nw,nw,nw,nw,nw,nw,s,nw,nw," "ne,nw,nw,nw,n,sw,nw,nw,nw,nw,se,nw,sw,nw,sw,nw,nw,se,nw,nw,se,nw,sw,sw,sw,nw,sw,s,nw,nw,nw,s,nw,nw,se,sw,nw," "sw,se,nw,ne,nw,nw,n,nw,nw,sw,nw,nw,ne,nw,ne,s,nw,sw,nw,nw,nw,nw,nw,sw,sw,sw,nw,sw,n,nw,nw,n,sw,sw,nw,ne,se," "sw,nw,n,nw,nw,ne,nw,sw,se,sw,sw,n,nw,ne,nw,nw,sw,n,nw,sw,nw,ne,n,n,nw,nw,sw,nw,nw,nw,nw,nw,nw,sw,nw,nw,nw," "nw,nw,nw,nw,nw,nw,nw,nw,nw,sw,nw,nw,sw,se,nw,nw,s,nw,sw,nw,nw,nw,nw,nw,nw,nw,sw,nw,nw,nw,nw,sw,sw,nw,nw,nw," "nw,ne,nw,nw,nw,nw,nw,nw,sw,nw,nw,n,n,nw,nw,ne,nw,nw,nw,n,sw,nw,sw,se,s,nw,nw,nw,s,nw,nw,nw,ne,se,nw,se,sw," "sw,nw,nw,nw,nw,nw,se,nw,ne,nw,nw,se,se,se,nw,nw,nw,nw,nw,nw,nw,nw,nw,n,nw,nw,nw,nw,nw,nw,nw,ne,n,nw,nw,ne," "se,nw,nw,sw,s,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,se,n,n,sw,nw,nw,se,s,nw,n,nw,s,nw,nw,nw,nw,nw,nw,nw,nw,s,nw,nw," "nw,sw,n,n,nw,ne,ne,n,nw,sw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,ne,nw,s,nw,nw,nw,nw,nw,nw,nw,n,nw,ne,n,nw,nw," "nw,nw,nw,ne,ne,nw,nw,nw,nw,nw,sw,ne,nw,ne,s,nw,nw,sw,nw,nw,nw,nw,nw,nw,se,nw,nw,nw,nw,nw,nw,nw,se,n,nw,nw," "nw,nw,nw,nw,nw,nw,n,nw,nw,s,n,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,n,sw,nw,nw,nw,nw,se,n,se,n,nw,nw,nw,nw,nw,nw," "nw,nw,n,sw,nw,nw,s,s,n,n,nw,sw,nw,n,nw,s,nw,nw,n,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,ne,nw,nw,nw,nw,nw," "nw,nw,nw,n,n,nw,n,nw,se,nw,nw,nw,nw,s,nw,nw,nw,nw,se,n,nw,s,nw,nw,nw,nw,nw,nw,nw,nw,n,nw,sw,n,nw,nw,ne,n,nw," "ne,n,s,n,n,ne,n,nw,nw,ne,nw,nw,nw,n,sw,nw,sw,nw,n,s,nw,nw,nw,nw,n,nw,nw,nw,nw,sw,nw,nw,n,sw,nw,sw,nw,n,ne," "nw,nw,sw,n,n,nw,nw,nw,sw,nw,n,nw,nw,nw,s,nw,nw,nw,nw,nw,n,nw,nw,nw,sw,nw,se,n,nw,nw,s,nw,n,nw,se,n,sw,n,nw," "n,nw,nw,nw,nw,n,n,n,n,nw,sw,s,nw,nw,n,se,nw,n,nw,nw,nw,ne,sw,nw,se,nw,n,s,ne,s,nw,n,n,n,nw,nw,nw,n,nw,nw,nw," "nw,n,n,nw,nw,n,sw,n,se,nw,nw,nw,n,nw,nw,ne,n,se,n,ne,n,n,se,n,n,n,nw,n,nw,n,nw,ne,nw,nw,nw,n,n,n,n,nw,se,n," "sw,nw,nw,n,s,nw,n,nw,n,n,nw,n,nw,n,ne,nw,sw,nw,sw,nw,nw,nw,nw,ne,nw,nw,n,ne,sw,nw,nw,n,n,se,nw,n,sw,nw,nw," "se,n,nw,n,ne,nw,nw,se,nw,ne,n,n,se,n,nw,nw,nw,nw,nw,n,nw,n,nw,nw,nw,n,n,nw,nw,ne,nw,nw,nw,n,n,nw,nw,s,se,nw," "n,nw,n,n,ne,nw,nw,n,n,nw,sw,nw,nw,nw,nw,nw,nw,nw,s,n,n,n,n,n,nw,nw,nw,nw,n,n,nw,n,s,n,nw,nw,nw,nw,sw,ne,nw," "nw,nw,nw,nw,nw,se,nw,n,n,nw,s,sw,nw,nw,n,n,nw,n,n,nw,n,nw,sw,n,n,nw,n,nw,ne,sw,nw,nw,nw,n,n,nw,s,s,nw,nw,nw," "nw,nw,n,nw,n,n,s,nw,nw,n,nw,n,nw,se,n,n,nw,n,n,sw,s,nw,s,nw,nw,n,n,nw,nw,nw,nw,n,nw,sw,n,se,n,nw,nw,n,n,nw," "n,n,nw,n,n,se,nw,sw,n,nw,nw,n,s,sw,s,n,n,nw,n,n,n,se,n,nw,nw,se,se,n,n,n,nw,nw,ne,n,n,n,n,n,sw,n,nw,n,s,nw," "nw,n,ne,nw,se,nw,nw,n,nw,sw,n,n,n,nw,n,nw,nw,n,nw,n,n,nw,nw,n,n,nw,n,sw,n,n,n,se,ne,nw,nw,sw,nw,n,s,nw,nw,n," "nw,n,nw,n,nw,n,nw,nw,nw,n,nw,n,nw,n,n,nw,n,nw,nw,n,nw,n,n,n,nw,n,sw,n,nw,n,nw,n,n,nw,nw,n,n,nw,n,nw,nw,sw,n," "n,nw,nw,nw,n,n,n,n,n,nw,n,ne,nw,nw,n,ne,n,nw,nw,sw,se,n,n,n,sw,n,n,ne,n,ne,nw,nw,nw,n,n,n,ne,nw,n,n,nw,n,n," "nw,n,n,n,n,nw,n,nw,sw,n,ne,n,nw,nw,n,nw,n,se,n,n,nw,n,n,n,nw,ne,s,nw,nw,nw,n,n,sw,n,sw,sw,n,n,n,n,n,n,sw,nw," "n,n,n,nw,n,nw,n,n,se,n,ne,n,nw,n,nw,n,n,n,n,n,n,ne,se,n,nw,n,nw,n,nw,n,nw,nw,n,n,n,sw,se,nw,n,n,nw,ne,nw,n," "nw,nw,nw,n,n,s,se,s,n,sw,sw,n,n,nw,ne,s,n,nw,n,nw,n,n,se,n,n,n,sw,n,n,n,n,n,nw,nw,n,nw,nw,n,n,nw,n,n,n,n,n," "n,n,n,nw,n,ne,nw,n,nw,nw,n,s,se,nw,n,se,n,s,n,n,n,nw,sw,n,n,nw,n,nw,n,se,n,sw,nw,n,n,n,n,n,nw,s,nw,n,n,n,n," "nw,n,n,nw,n,nw,n,n,nw,n,nw,n,n,s,n,s,n,nw,sw,ne,n,n,n,nw,n,n,n,n,n,n,s,n,s,n,nw,n,n,nw,n,n,s,n,n,sw,s,n,n,n," "nw,n,sw,n,n,ne,n,n,n,n,n,n,n,sw,n,n,n,nw,n,n,n,n,n,n,n,n,n,n,nw,nw,n,n,ne,n,n,n,se,n,nw,s,sw,nw,n,n,sw,nw," "se,n,n,nw,n,n,n,s,sw,n,ne,n,n,nw,n,n,n,s,ne,ne,s,sw,n,ne,n,n,n,n,n,se,n,n,n,n,n,n,n,n,n,n,n,n,sw,n,s,n,n,n," "se,nw,nw,n,nw,n,se,sw,n,n,n,nw,sw,ne,nw,se,n,n,n,ne,n,nw,n,n,n,n,nw,n,n,n,n,n,n,sw,n,ne,n,nw,n,n,n,n,n,se,n," "n,n,n,n,n,n,n,n,ne,n,n,n,n,nw,se,se,ne,n,n,n,nw,n,n,se,n,n,n,n,ne,n,se,ne,n,n,n,se,s,sw,n,n,n,n,n,s,n,n,s,n," "n,n,n,s,n,sw,nw,n,n,s,n,n,n,ne,ne,n,ne,n,sw,n,se,n,n,n,nw,n,n,n,n,sw,nw,n,s,n,n,se,n,nw,n,n,n,n,n,n,se,n,n," "n,n,n,se,n,n,n,n,s,n,n,n,n,se,se,n,n,s,n,n,n,nw,n,n,n,n,n,n,n,ne,n,ne,n,n,n,n,ne,n,n,n,n,se,n,n,n,n,n,ne,n," "n,n,se,n,s,n,n,s,n,n,se,n,n,n,n,ne,n,s,n,n,ne,n,n,ne,nw,n,ne,n,ne,n,ne,n,n,s,n,sw,ne,s,n,n,n,n,se,n,ne,n,n," "n,s,n,n,n,sw,n,n,n,n,n,n,n,n,nw,n,n,n,n,n,n,ne,ne,s,n,n,s,n,n,n,nw,nw,ne,n,sw,n,n,n,ne,se,n,sw,se,n,sw,n,n," "nw,n,n,n,ne,n,n,n,n,n,n,s,nw,n,n,n,n,sw,n,n,n,n,n,n,sw,ne,n,n,n,nw,ne,n,n,n,sw,nw,ne,s,nw,n,n,n,n,n,n,ne,n," "n,n,n,n,n,n,n,n,n,se,n,s,se,nw,n,n,n,n,s,n,n,n,ne,n,n,ne,n,ne,n,ne,ne,n,n,n,s,ne,n,ne,n,n,n,ne,se,n,n,n,ne," "n,n,ne,n,n,n,s,n,ne,n,n,n,n,n,n,n,n,n,n,n,n,ne,n,n,n,n,ne,n,n,n,se,n,ne,n,s,n,n,ne,n,sw,n,se,n,s,n,ne,n,s," "ne,s,n,n,se,n,ne,n,ne,n,ne,n,sw,n,n,s,ne,n,ne,ne,n,sw,n,n,s,ne,n,n,s,n,s,n,n,n,ne,n,s,ne,n,ne,n,n,n,s,n,n," "ne,s,n,ne,se,ne,nw,n,n,n,nw,n,n,ne,sw,s,n,n,n,n,se,n,n,ne,ne,n,nw,n,ne,n,n,n,n,ne,n,s,n,sw,n,n,n,n,ne,n,n,n," "n,s,sw,ne,n,n,n,n,n,ne,n,n,s,se,se,sw,n,n,n,n,ne,ne,n,ne,n,n,se,sw,n,ne,n,n,n,nw,ne,n,ne,n,ne,n,se,ne,ne,n," "n,n,n,n,n,se,ne,nw,sw,n,nw,ne,n,n,ne,sw,ne,s,n,se,se,ne,s,n,sw,ne,n,n,n,ne,n,ne,n,ne,n,n,ne,ne,n,ne,ne,n,se," "n,ne,ne,n,sw,ne,ne,ne,ne,n,n,n,ne,nw,ne,n,n,n,n,n,n,n,n,ne,ne,n,ne,n,ne,se,ne,n,ne,n,n,sw,sw,n,n,ne,n,n,ne," "ne,s,n,ne,ne,ne,n,ne,ne,s,n,sw,s,nw,n,n,n,se,n,ne,n,se,ne,ne,ne,sw,ne,ne,n,ne,n,n,n,ne,nw,n,n,n,ne,n,nw,n,n," "se,nw,n,ne,n,ne,n,ne,n,ne,nw,nw,n,ne,ne,sw,n,ne,ne,ne,ne,n,n,n,se,n,n,n,s,ne,ne,n,n,n,ne,n,n,n,nw,ne,ne,n," "ne,n,n,ne,n,sw,n,ne,n,n,ne,n,n,ne,n,n,ne,ne,sw,ne,ne,ne,se,n,sw,n,ne,n,n,n,n,ne,s,n,ne,n,ne,n,ne,n,ne,se,ne," "ne,n,ne,ne,ne,n,ne,ne,n,n,n,n,n,n,n,n,n,n,ne,se,n,n,n,ne,n,n,ne,ne,n,n,ne,ne,n,se,nw,se,n,sw,ne,ne,ne,ne,ne," "ne,ne,n,n,ne,n,ne,n,ne,n,ne,n,s,s,ne,ne,se,n,n,sw,n,n,n,ne,ne,nw,n,n,n,ne,n,n,n,n,n,ne,ne,ne,ne,n,ne,ne,n," "ne,ne,sw,n,n,n,nw,se,ne,ne,n,n,n,s,n,n,se,s,nw,ne,n,ne,ne,ne,ne,nw,s,n,se,sw,ne,ne,ne,n,ne,n,ne,sw,n,n,ne," "ne,ne,se,s,s,ne,ne,ne,s,n,ne,n,ne,ne,ne,n,s,se,ne,n,n,se,n,ne,ne,n,ne,ne,n,ne,ne,n,n,n,nw,n,ne,n,ne,n,s,se," "sw,ne,ne,n,n,ne,s,ne,ne,n,ne,ne,ne,ne,n,ne,ne,ne,ne,n,n,se,ne,s,ne,ne,ne,ne,ne,n,ne,ne,ne,n,n,ne,n,ne,ne,ne," "ne,n,n,n,n,n,nw,ne,n,ne,s,n,ne,n,ne,n,ne,ne,nw,ne,sw,nw,ne,n,n,s,se,nw,ne,nw,ne,ne,n,n,ne,n,se,ne,n,ne,n,n," "ne,n,s,ne,ne,n,se,ne,nw,ne,ne,sw,ne,ne,n,ne,ne,n,ne,s,ne,sw,n,n,ne,n,n,ne,ne,ne,s,n,n,n,n,nw,n,n,n,n,ne,ne," "nw,ne,ne,n,ne,n,ne,n,ne,ne,ne,n,sw,ne,ne,ne,ne,ne,n,sw,ne,n,ne,ne,ne,n,ne,n,ne,n,s,s,n,ne,ne,n,ne,n,ne,n,ne," "nw,ne,se,n,n,ne,n,n,ne,ne,n,ne,n,n,n,n,n,ne,ne,ne,n,ne,n,ne,ne,n,ne,ne,ne,ne,ne,n,n,ne,n,n,n,ne,ne,ne,ne,ne," "sw,n,n,ne,n,ne,ne,nw,n,ne,n,ne,ne,n,sw,n,n,ne,ne,nw,ne,nw,ne,se,se,se,ne,ne,se,ne,sw,n,n,ne,ne,ne,ne,n,ne," "ne,se,ne,ne,ne,ne,n,ne,ne,ne,n,s,ne,se,se,ne,ne,ne,n,ne,n,n,ne,n,nw,ne,ne,n,ne,se,sw,ne,ne,ne,n,ne,ne,n,ne," "ne,sw,ne,ne,ne,ne,n,sw,n,ne,ne,ne,ne,ne,ne,ne,n,ne,ne,ne,ne,n,se,n,ne,n,n,ne,ne,n,ne,ne,n,ne,n,ne,ne,n,ne,n," "n,ne,ne,n,n,ne,sw,ne,nw,ne,n,ne,se,ne,ne,sw,ne,ne,ne,n,ne,ne,n,n,n,ne,nw,ne,n,ne,ne,ne,n,ne,n,sw,ne,s,se,ne," "ne,sw,ne,ne,ne,ne,ne,se,ne,ne,n,ne,ne,ne,ne,ne,ne,n,n,n,ne,n,ne,ne,ne,n,n,ne,ne,nw,s,ne,ne,se,ne,n,ne,ne,ne," "ne,ne,n,ne,ne,ne,nw,s,n,ne,ne,ne,n,ne,ne,se,ne,ne,ne,ne,ne,ne,ne,n,ne,ne,s,ne,sw,ne,ne,ne,ne,nw,n,sw,ne,ne," "ne,ne,sw,ne,nw,ne,n,n,n,ne,ne,n,ne,se,sw,sw,ne,n,ne,n,ne,ne,nw,ne,ne,se,ne,ne,sw,ne,se,ne,n,ne,ne,ne,sw,ne," "ne,ne,ne,nw,ne,n,ne,ne,ne,n,ne,ne,ne,ne,se,ne,ne,n,ne,n,ne,ne,n,ne,n,sw,ne,ne,n,s,ne,ne,ne,ne,s,ne,ne,se,n," "ne,ne,ne,ne,ne,ne,ne,n,ne,ne,ne,n,ne,ne,ne,n,n,s,ne,ne,sw,se,n,ne,ne,ne,ne,ne,n,ne,n,ne,ne,ne,ne,n,ne,ne,ne," "ne,s,ne,nw,s,ne,se,se,ne,ne,ne,ne,sw,se,ne,ne,sw,se,ne,n,ne,n,ne,ne,n,sw,ne,ne,s,n,ne,ne,s,ne,s,n,ne,ne,ne," "ne,n,n,ne,ne,s,se,ne,ne,ne,se,ne,ne,ne,sw,ne,sw,ne,ne,ne,ne,ne,ne,n,ne,ne,ne,ne,ne,s,nw,ne,ne,n,ne,n,ne,ne," "ne,ne,ne,ne,ne,ne,ne,ne,nw,ne,ne,ne,n,se,ne,ne,s,n,n,ne,n,ne,nw,ne,nw,ne,ne,ne,ne,ne,ne,ne,ne,ne,n,ne,ne,ne," "n,ne,ne,nw,ne,ne,sw,ne,ne,ne,n,ne,ne,ne,n,ne,ne,ne,ne,ne,ne,ne,ne,ne,ne,ne,ne,ne,s,ne,ne,ne,nw,ne,ne,ne,ne," "ne,ne,ne,ne,ne,nw,ne,ne,ne,ne,ne,nw,ne,ne,n,n,sw,sw,sw,sw,se,s,sw,s,sw,se,s,sw,s,sw,sw,se,se,s,n,se,se,se," "se,se,se,nw,se,se,ne,ne,se,ne,nw,nw,ne,ne,sw,ne,ne,ne,ne,se,se,ne,n,ne,n,n,n,ne,n,n,ne,n,n,n,n,nw,n,n,se,n," "n,n,sw,se,n,n,se,se,n,nw,n,n,n,sw,n,nw,se,nw,nw,nw,se,n,n,s,nw,nw,nw,nw,nw,sw,nw,nw,se,nw,se,nw,n,nw,nw,sw," "nw,nw,nw,nw,nw,nw,ne,nw,nw,nw,s,nw,nw,sw,sw,nw,sw,nw,nw,sw,nw,sw,nw,nw,nw,s,sw,sw,nw,sw,nw,s,sw,sw,ne,sw,sw," "sw,sw,sw,sw,sw,sw,sw,sw,sw,n,sw,sw,sw,s,sw,sw,sw,sw,sw,nw,sw,sw,sw,sw,sw,sw,sw,sw,sw,se,nw,sw,sw,sw,sw,sw,s," "s,sw,sw,s,sw,ne,sw,sw,sw,sw,s,nw,s,s,s,sw,sw,sw,nw,s,sw,s,sw,se,s,n,s,s,s,s,s,nw,s,s,s,s,se,se,s,s,s,nw,s,s," "s,s,s,s,n,s,s,s,s,s,s,nw,s,s,s,se,s,se,nw,n,nw,se,n,s,n,sw,se,s,s,s,se,se,s,s,nw,se,s,n,s,se,s,s,sw,se,n,s," "sw,s,se,s,s,se,se,se,s,s,se,s,se,se,se,se,se,se,se,s,s,s,s,n,s,s,se,n,nw,se,nw,sw,nw,se,nw,se,se,se,se,se," "se,se,sw,se,s,se,se,nw,se,ne,se,se,se,s,se,se,se,se,se,sw,se,n,ne,se,ne,s,se,sw,se,se,se,se,nw,sw,se,se,n," "ne,se,ne,se,se,ne,se,nw,se,se,se,se,se,se,se,nw,se,se,se,n,se,ne,ne,se,ne,se,se,se,ne,nw,se,se,se,n,sw,ne,s," "ne,ne,se,nw,se,ne,nw,ne,se,ne,se,se,se,se,se,sw,ne,nw,se,sw,n,se,se,se,se,se,se,se,se,se,ne,sw,se,ne,ne,s," "ne,se,se,se,se,nw,ne,ne,ne,ne,ne,ne,n,ne,s,se,se,ne,ne,ne,se,se,ne,ne,se,ne,ne,s,s,ne,ne,ne,ne,ne,se,se,n," "ne,ne,ne,s,nw,sw,n,ne,ne,ne,ne,s,ne,s,ne,ne,ne,ne,ne,n,s,nw,ne,nw,n,sw,nw,se,ne,ne,nw,se,ne,ne,n,ne,ne,ne," "ne,sw,se,n,n,ne,ne,ne,ne,n,ne,ne,n,n,ne,ne,sw,n,ne,ne,ne,ne,ne,ne,se,ne,nw,se,ne,sw,ne,ne,ne,ne,ne,n,ne,ne," "n,n,ne,n,n,ne,n,se,n,sw,ne,ne,ne,ne,sw,ne,n,ne,ne,ne,ne,se,ne,ne,sw,ne,n,n,ne,ne,ne,n,ne,ne,ne,ne,n,ne,n,n," "ne,n,ne,n,ne,sw,n,n,n,nw,ne,n,n,n,n,ne,n,ne,ne,n,sw,sw,n,nw,n,ne,n,se,s,n,ne,sw,n,ne,ne,sw,n,n,sw,nw,n,n,n," "s,n,n,n,ne,n,se,ne,n,n,s,n,nw,ne,ne,n,se,n,n,n,n,n,n,n,n,n,n,ne,sw,n,nw,n,n,sw,n,sw,n,n,ne,n,n,n,n,n,n,n,n," "ne,n,ne,s,ne,n,n,ne,se,n,n,n,n,n,n,n,n,s,n,n,s,n,sw,se,n,n,n,n,n,ne,n,n,ne,se,n,nw,n,n,ne,nw,n,n,ne,n,n,nw," "se,n,n,n,n,n,n,n,n,n,n,nw,n,n,n,n,n,n,ne,n,n,s,n,n,n,nw,n,n,n,n,n,n,n,n,n,se,se,ne,n,se,n,n,n,n,n,n,n,n,n," "nw,n,nw,n,nw,n,n,n,n,n,sw,n,nw,n,nw,n,n,se,nw,n,nw,n,s,nw,nw,n,ne,n,se,n,sw,nw,nw,nw,nw,nw,nw,se,n,n,n,nw,n," "n,s,nw,s,nw,n,nw,nw,se,sw,n,n,n,n,ne,nw,n,nw,nw,ne,n,nw,sw,nw,nw,n,se,nw,se,nw,nw,n,n,n,nw,nw,n,n,n,nw,nw,n," "ne,nw,n,ne,nw,nw,s,se,nw,nw,n,s,nw,n,n,n,n,nw,nw,n,n,se,nw,s,n,nw,nw,nw,nw,nw,nw,nw,sw,nw,nw,nw,sw,n,nw,nw," "n,nw,s,nw,nw,se,n,n,n,ne,nw,ne,nw,nw,nw,nw,nw,n,nw,ne,n,nw,n,nw,se,n,n,nw,nw,n,nw,nw,nw,nw,se,n,s,ne,sw,n,s," "nw,nw,nw,nw,nw,ne,ne,s,nw,se,nw,nw,n,nw,nw,nw,nw,nw,s,nw,nw,n,nw,nw,nw,nw,nw,ne,sw,nw,nw,nw,ne,nw,nw,nw,nw," "nw,se,nw,nw,ne,nw,se,ne,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,nw,se,nw,nw,nw,nw,nw,sw,ne,nw,nw,nw,nw,nw," "nw,ne,nw,n,nw,nw,nw,n,nw,ne,nw,nw,nw,nw,n,nw,se,nw,nw,s,nw,ne,nw,nw,ne,ne,nw,ne,nw,ne,nw,nw,nw,nw,nw,nw,sw," "nw,ne,sw,nw,sw,nw,n,nw,se,nw,nw,nw,nw,nw,nw,nw,sw,se,nw,n,sw,sw,n,nw,n,nw,s,nw,nw,nw,nw,nw,nw,nw,nw,sw,sw," "nw,sw,nw,nw,se,se,nw,nw,n,s,s,nw,nw,nw,sw,nw,sw,ne,se,s,nw,s,nw,sw,nw,nw,nw,sw,nw,sw,sw,s,nw,nw,nw,nw,nw,sw," "nw,ne,nw,nw,nw,se,nw,nw,n,sw,sw,sw,sw,nw,nw,nw,sw,nw,sw,sw,nw,nw,sw,sw,n,se,nw,nw,nw,s,se,nw,sw,s,se,se,se," "sw,sw,sw,nw,sw,sw,sw,nw,nw,nw,sw,nw,n,se,sw,sw,s,sw,sw,sw,nw,nw,sw,n,nw,nw,sw,n,s,sw,sw,nw,sw,nw,sw,sw,nw," "sw,sw,nw,nw,s,sw,nw,sw,nw,nw,sw,nw,sw,sw,nw,sw,se,sw,n,sw,se,nw,sw,nw,ne,nw,sw,s,nw,sw,sw,sw,n,sw,sw,nw,n," "nw,sw,sw,s,sw,sw,nw,sw,nw,nw,sw,sw,nw,nw,nw,sw,sw,sw,sw,nw,sw,sw,ne,sw,sw,se,sw,sw,s,nw,sw,sw,sw,nw,sw,s,sw," "sw,s,ne,sw,sw,nw,sw,sw,nw,nw,nw,sw,sw,nw,sw,sw,sw,sw,sw,n,nw,sw,sw,nw,ne,nw,n,sw,sw,sw,n,nw,sw,n,sw,sw,sw," "sw,sw,sw,n,ne,nw,nw,nw,sw,sw,n,n,sw,sw,sw,sw,sw,sw,se,sw,sw,nw,sw,ne,sw,sw,ne,nw,sw,nw,sw,sw,sw,sw,s,sw,sw," "sw,sw,sw,sw,sw,sw,sw,sw,sw,se,sw,sw,se,se,sw,sw,sw,sw,sw,se,sw,nw,se,nw,sw,n,nw,sw,ne,ne,sw,sw,sw,sw,sw,se," "sw,n,sw,sw,n,sw,sw,sw,sw,sw,sw,sw,ne,sw,sw,se,sw,sw,sw,sw,sw,sw,se,s,s,sw,s,ne,sw,se,sw,sw,sw,sw,sw,ne,s,s," "nw,sw,sw,sw,sw,sw,sw,s,n,sw,sw,sw,sw,se,sw,sw,sw,sw,sw,sw,se,s,sw,nw,sw,ne,sw,s,s,sw,sw,sw,sw,sw,sw,s,s,sw," "sw,nw,sw,sw,sw,sw,sw,sw,nw,sw,sw,sw,n,sw,s,s,s,sw,sw,sw,sw,sw,sw,sw,sw,sw,sw,s,sw,sw,ne,s,nw,s,s,nw,sw,sw," "sw,sw,sw,sw,sw,sw,sw,nw,sw,sw,sw,sw,s,s,se,se,s,se,sw,sw,nw,sw,sw,sw,sw,s,ne,sw,s,s,s,sw,sw,nw,n,s,s,sw,n," "nw,s,s,sw,ne,sw,s,nw,sw,ne,s,s,sw,s,sw,sw,sw,sw,s,s,sw,sw,sw,nw,sw,n,s,sw,sw,sw,sw,s,s,nw,sw,s,nw,ne,sw,se," "sw,s,sw,sw,ne,sw,s,sw,n,sw,s,se,se,sw,sw,ne,s,sw,sw,sw,sw,n,sw,sw,s,s,sw,nw,sw,ne,s,s,sw,sw,n,sw,ne,sw,se," "sw,sw,s,s,s,sw,s,s,nw,n,sw,sw,ne,sw,s,ne,nw,s,se,s,sw,nw,s,n,s,sw,sw,nw,n,sw,sw,s,n,s,sw,n,s,s,s,s,s,s,sw,s," "sw,s,s,s,sw,sw,n,sw,sw,s,sw,sw,sw,sw,sw,sw,s,sw,sw,s,se,s,sw,n,se,nw,sw,s,s,se,se,sw,sw,s,se,s,nw,n,s,sw,s," "nw,se,sw,s,s,sw,s,sw,sw,s,sw,sw,s,s,se,n,nw,sw,sw,s,sw,sw,sw,s,s,s,sw,ne,s,s,se,sw,sw,sw,sw,n,s,s,s,sw,se," "sw,n,s,sw,sw,nw,sw,s,s,sw,s,s,ne,s,s,s,s,sw,ne,sw,nw,s,sw,ne,sw,sw,ne,s,sw,nw,s,s,sw,s,s,s,s,s,nw,sw,s,se,s," "s,s,n,s,sw,s,s,s,sw,s,nw,s,s,s,n,s,s,se,s,s,se,sw,ne,s,s,sw,se,s,s,s,se,s,sw,se,s,s,sw,se,s,s,s,s,nw,s,sw," "sw,s,s,nw,s,ne,s,s,s,sw,s,s,sw,s,nw,sw,s,sw,sw,s,s,s,ne,sw,nw,s,s,s,s,s,s,s,sw,s,s,s,s,s,se,s,s,s,s,s,s,sw," "s,sw,s,s,s,se,s,s,s,s,s,se,nw,n,se,s,s,s,s,s,s,nw,n,s,s,s,sw,s,s,s,s,n,s,s,nw,n,s,se,s,s,n,s,n,s,s,n,sw,s,s," "s,nw,sw,se,ne,ne,s,s,s,ne,n,nw,s,se,sw,s,s,s,s,s,s,se,s,s,s,s,s,se,s,s,s,s,s,nw,s,s,s,s,n,s,nw,s,s,se,s,nw," "s,s,s,s,s,nw,s,s,s,s,s,ne,s,nw,s,s,ne,s,ne,s,s,s,s,s,s,ne,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,se,s,s,ne,s,sw,s," "nw,s,s,s,s,s,ne,s,se,s,s,s,s,s,s,s,s,ne,s,s,ne,s,s,s,n,s,s,n,s,s,s,s,s,n,n,s,s,s,ne,s,s,ne,s,se,n,s,s,s,n," "se,s,s,s,s,s,s,s,s,s,s,se,s,s,s,n,s,s,ne,se,s,s,s,sw,se,n,s,se,s,s,ne,s,se,s,s,nw,nw,se,se,se,se,s,s,s,s,se," "se,nw,se,se,sw,s,s,s,ne,s,nw,s,s,sw,se,s,se,se,s,s,n,s,s,ne,s,s,s,s,n,s,s,sw,s,se,nw,sw,s,n,s,s,ne,s,se,s," "nw,s,s,nw,s,se,sw,s,se,s,se,ne,se,se,se,s,nw,s,nw,s,nw,se,n,se,se,se,s,s,s,s,se,s,nw,se,nw,s,se,sw,se,se,se," "n,s,ne,se,s,s,se,s,s,ne,se,ne,sw,se,s,se,s,s,s,s,se,s,s,s,s,s,se,se,se,s,n,se,se,s,s,se,s,se,s,s,s,se,nw,se," "se,s,se,se,s,ne,ne,se,s,ne,n,se,s,s,se,s,s,se,s,s,s,sw,se,s,s,se,sw,se,se,s,se,s,s,s,nw,s,s,s,se,se,se,s,s," "s,s,sw,s,se,se,s,s,s,s,s,sw,sw,se,s,se,se,s,s,s,se,s,se,se,s,s,se,s,se,s,ne,ne,s,s,se,s,s,s,s,s,s,se,s,s,se," "se,sw,s,ne,s,s,se,s,se,sw,se,n,s,s,s,se,s,s,s,se,s,se,s,ne,se,se,s,s,s,s,se,se,se,se,se,se,se,s,s,ne,nw,s,s," "se,s,ne,s,s,se,se,s,n,s,s,se,nw,s,s,se,se,s,se,s,se,s,se,nw,se,ne,n,s,s,se,se,ne,se,nw,se,se,se,se,se,se,se," "se,s,s,se,se,n,se,s,se,se,nw,s,sw,se,sw,n,se,s,s,se,s,ne,se,s,ne,se,se,s,s,s,se,nw,se,se,se,se,s,se,se,se," "se,se,se,se,s,se,se,se,sw,se,n,se,se,sw,se,se,se,se,se,se,s,se,se,n,se,se,se,se,se,se,se,s,se,se,se,s,se,nw," "s,s,se,se,s,se,se,s,se,se,s,n,se,se,se,se,se,se,se,s,s,se,se,se,s,se,s,s,n,nw,se,se,s,se,s,se,s,sw,se,se,nw," "se,nw,s,n,s,se,s,s,se,se,se,nw,se,nw,nw,se,se,s,s,s,nw,se,n,ne,se,se,se,se,ne,se,se,se,s,se,sw,s,n,s,s,se," "se,s,n,s,se,se,sw,se,se,se,s,se,sw,s,se,se,se,se,se,ne,se,se,se,se,se,se,s,se,se,se,se,se,se,se,n,se,se,ne," "s,se,se,se,s,se,ne,se,se,se,se,se,se,se,s,se,se,se,se,se,se,se,se,sw,se,se,se,se,nw,s,se,se,nw,se,s,s,se,se," "se,se,se,se,se,se,se,sw,se,se,n,nw,n,se,ne,se,n,se,nw,nw,se,ne,s,se,se,s,se,se,s,se,se,s,se,s,se,n,se,se,se," "se,se,n,s,se,se,se,se,se,se,s,se,se,nw,ne,s,se,ne,se,se,se,n,se,se,se,s,se,se,se,se,se,se,n,se,se,s,se,se,s," "s,se,se,se,se,se,n,ne,se,se,nw,se,se,se,se,se,se,se,se,se,se,se,se,s,n,se,s,s,s,se,n,ne,se,s,se,se,se,ne,ne," "s,se,se,s,se,se,se,se"; auto ans = calc_dist( daw::string_view{tst.data( ), tst.size( )} ); BOOST_REQUIRE_EQUAL( ans.final, 707 ); BOOST_REQUIRE_EQUAL( ans.furthest, 1490 ); std::cout << "Answer #1: " << ans.final << '\n'; std::cout << "Answer #2: " << ans.furthest << '\n'; } } // namespace day11 } // namespace aoc_2017 } // namespace daw
; A174836: a(n) = 1 + ((6*n-1)*2^n + (-1)^n)/3. ; 1,4,16,46,124,310,748,1750,4012,9046,20140,44374,96940,210262,453292,972118,2075308,4412758,9349804,19748182,41593516,87381334,183151276,383079766,799713964,1666536790,3467291308,7203018070,14942907052,30959555926,64066595500,132428158294 mov $2,$0 lpb $2 add $0,$1 mul $0,2 add $0,$2 cmp $1,0 sub $2,1 lpe add $0,1
; A167300: Totally multiplicative sequence with a(p) = 8*(p-2) for prime p. ; Submitted by Jon Maiga ; 1,0,8,0,24,0,40,0,64,0,72,0,88,0,192,0,120,0,136,0,320,0,168,0,576,0,512,0,216,0,232,0,576,0,960,0,280,0,704,0,312,0,328,0,1536,0,360,0,1600,0,960,0,408,0,1728,0,1088,0,456,0,472,0,2560,0,2112,0,520,0,1344,0,552,0,568,0,4608,0,2880,0,616,0,4096,0,648,0,2880,0,1728,0,696,0,3520,0,1856,0,3264,0,760,0,4608,0 add $0,1 mov $1,1 mov $2,2 mov $4,1 lpb $0 mul $1,$4 mov $3,$0 lpb $3 mov $4,$0 mod $4,$2 add $2,1 cmp $4,0 cmp $4,0 sub $3,$4 lpe div $0,$2 mul $1,8 mov $4,$2 sub $4,2 lpe mov $0,$1 div $0,8
/** * @file timer_helper.cc * @brief 定时器辅助函数 * @author kurtlau * @date 2013-04-08 */ #include "timer_helper.h" namespace TimerHelper { int TimevalInterval(const struct timeval& tv1, const struct timeval& tv2) { return (tv1.tv_sec - tv2.tv_sec) * MILLISEC_PER_SEC + (tv1.tv_usec - tv2.tv_usec) / MICROSEC_PER_MS; } unsigned int MsToTick(const unsigned int ms, const unsigned int tick_interval) { return (ms - 1) / tick_interval + 1; } unsigned int GetTicks(const struct timeval& tv1, const struct timeval& tv2, const unsigned int tick_interval) { int ms = TimevalInterval(tv1, tv2); if (ms <= 0) { return 0; } return MsToTick(ms, tick_interval); } }
; A113618: a(n) = 1 + 2*n + 3*n^2 + 4*n^3 + 5*n^4 + 6*n^5 + 7*n^6 + 8*n^7. ; 1,36,1793,24604,167481,756836,2620201,7526268,18831569,42374116,87654321,169343516,309160393,538155684,899445401,1451432956,2271560481,3460629668,5147732449,7495831836,10708033241,15034586596,20780659593 mov $2,$0 mov $3,8 lpb $3,1 mul $1,$2 add $1,$3 sub $3,1 lpe
/* * Copyright (c) 2013, Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "core/animation/TimingCalculations.h" #include <gtest/gtest.h> using namespace WebCore; namespace { TEST(AnimationTimingCalculationsTest, ActiveTime) { Timing timing; // calculateActiveTime(activeDuration, fillMode, localTime, parentPhase, phase, timing) // Before Phase timing.startDelay = 10; EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 0, AnimationNode::PhaseActive, AnimationNode::PhaseBefore, timing))); EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 0, AnimationNode::PhaseActive, AnimationNode::PhaseBefore, timing))); EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBackwards, 0, AnimationNode::PhaseActive, AnimationNode::PhaseBefore, timing)); EXPECT_EQ(0, calculateActiveTime(20, Timing::FillModeBoth, 0, AnimationNode::PhaseActive, AnimationNode::PhaseBefore, timing)); // Active Phase timing.startDelay = 10; // Active, and parent Before EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, AnimationNode::PhaseBefore, AnimationNode::PhaseActive, timing))); EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeForwards, 15, AnimationNode::PhaseBefore, AnimationNode::PhaseActive, timing))); // Active, and parent After EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeNone, 15, AnimationNode::PhaseAfter, AnimationNode::PhaseActive, timing))); EXPECT_TRUE(isNull(calculateActiveTime(20, Timing::FillModeBackwards, 15, AnimationNode::PhaseAfter, AnimationNode::PhaseActive, timing))); // Active, and parent Active EXPECT_EQ(5, calculateActiveTime(20, Timing::FillModeForwards, 15, AnimationNode::PhaseActive, AnimationNode::PhaseActive, timing)); // After Phase timing.startDelay = 10; EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeForwards, 45, AnimationNode::PhaseActive, AnimationNode::PhaseAfter, timing)); EXPECT_EQ(21, calculateActiveTime(21, Timing::FillModeBoth, 45, AnimationNode::PhaseActive, AnimationNode::PhaseAfter, timing)); EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeBackwards, 45, AnimationNode::PhaseActive, AnimationNode::PhaseAfter, timing))); EXPECT_TRUE(isNull(calculateActiveTime(21, Timing::FillModeNone, 45, AnimationNode::PhaseActive, AnimationNode::PhaseAfter, timing))); // None EXPECT_TRUE(isNull(calculateActiveTime(32, Timing::FillModeNone, nullValue(), AnimationNode::PhaseNone, AnimationNode::PhaseNone, timing))); } TEST(AnimationTimingCalculationsTest, ScaledActiveTime) { Timing timing; // calculateScaledActiveTime(activeDuration, activeTime, startOffset, timing) // if the active time is null EXPECT_TRUE(isNull(calculateScaledActiveTime(4, nullValue(), 5, timing))); // if the playback rate is negative timing.playbackRate = -1; EXPECT_EQ(35, calculateScaledActiveTime(40, 10, 5, timing)); // otherwise timing.playbackRate = 0; EXPECT_EQ(5, calculateScaledActiveTime(40, 10, 5, timing)); timing.playbackRate = 1; EXPECT_EQ(15, calculateScaledActiveTime(40, 10, 5, timing)); // infinte activeTime timing.playbackRate = 0; EXPECT_EQ(0, calculateScaledActiveTime(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), 0, timing)); timing.playbackRate = 1; EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateScaledActiveTime(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), 0, timing)); } TEST(AnimationTimingCalculationsTest, IterationTime) { Timing timing; // calculateIterationTime(iterationDuration, repeatedDuration, scaledActiveTime, startOffset, timing) // if the scaled active time is null EXPECT_TRUE(isNull(calculateIterationTime(1, 1, nullValue(), 1, timing))); // if (complex-conditions)... EXPECT_EQ(12, calculateIterationTime(12, 12, 12, 0, timing)); // otherwise timing.iterationCount = 10; EXPECT_EQ(5, calculateIterationTime(10, 100, 25, 4, timing)); EXPECT_EQ(7, calculateIterationTime(11, 110, 29, 1, timing)); timing.iterationStart = 1.1; EXPECT_EQ(8, calculateIterationTime(12, 120, 20, 7, timing)); } TEST(AnimationTimingCalculationsTest, CurrentIteration) { Timing timing; // calculateCurrentIteration(iterationDuration, iterationTime, scaledActiveTime, timing) // if the scaled active time is null EXPECT_TRUE(isNull(calculateCurrentIteration(1, 1, nullValue(), timing))); // if the scaled active time is zero EXPECT_EQ(0, calculateCurrentIteration(1, 1, 0, timing)); // if the iteration time equals the iteration duration timing.iterationStart = 4; timing.iterationCount = 7; EXPECT_EQ(10, calculateCurrentIteration(5, 5, 9, timing)); // otherwise EXPECT_EQ(3, calculateCurrentIteration(3.2, 3.1, 10, timing)); } TEST(AnimationTimingCalculationsTest, DirectedTime) { Timing timing; // calculateDirectedTime(currentIteration, iterationDuration, iterationTime, timing) // if the iteration time is null EXPECT_TRUE(isNull(calculateDirectedTime(1, 2, nullValue(), timing))); // forwards EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); timing.direction = Timing::PlaybackDirectionAlternate; EXPECT_EQ(17, calculateDirectedTime(0, 20, 17, timing)); EXPECT_EQ(17, calculateDirectedTime(2, 20, 17, timing)); timing.direction = Timing::PlaybackDirectionAlternateReverse; EXPECT_EQ(17, calculateDirectedTime(1, 20, 17, timing)); EXPECT_EQ(17, calculateDirectedTime(3, 20, 17, timing)); // reverse timing.direction = Timing::PlaybackDirectionReverse; EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); timing.direction = Timing::PlaybackDirectionAlternate; EXPECT_EQ(3, calculateDirectedTime(1, 20, 17, timing)); EXPECT_EQ(3, calculateDirectedTime(3, 20, 17, timing)); timing.direction = Timing::PlaybackDirectionAlternateReverse; EXPECT_EQ(3, calculateDirectedTime(0, 20, 17, timing)); EXPECT_EQ(3, calculateDirectedTime(2, 20, 17, timing)); } TEST(AnimationTimingCalculationsTest, TransformedTime) { Timing timing; // calculateTransformedTime(currentIteration, iterationDuration, iterationTime, timing) // Iteration time is null EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); // PlaybackDirectionForwards EXPECT_EQ(12, calculateTransformedTime(0, 20, 12, timing)); EXPECT_EQ(12, calculateTransformedTime(1, 20, 12, timing)); // PlaybackDirectionForwards with timing function timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::StepAtEnd); EXPECT_EQ(10, calculateTransformedTime(0, 20, 12, timing)); EXPECT_EQ(10, calculateTransformedTime(1, 20, 12, timing)); // PlaybackDirectionReverse timing.timingFunction = Timing::defaults().timingFunction; timing.direction = Timing::PlaybackDirectionReverse; EXPECT_EQ(8, calculateTransformedTime(0, 20, 12, timing)); EXPECT_EQ(8, calculateTransformedTime(1, 20, 12, timing)); // PlaybackDirectionReverse with timing function timing.timingFunction = StepsTimingFunction::create(4, StepsTimingFunction::StepAtEnd); EXPECT_EQ(5, calculateTransformedTime(0, 20, 12, timing)); EXPECT_EQ(5, calculateTransformedTime(1, 20, 12, timing)); // Timing function when directed time is null. EXPECT_TRUE(isNull(calculateTransformedTime(1, 2, nullValue(), timing))); // Timing function when iterationDuration is infinity timing.direction = Timing::PlaybackDirectionNormal; EXPECT_EQ(0, calculateTransformedTime(0, std::numeric_limits<double>::infinity(), 0, timing)); EXPECT_EQ(1, calculateTransformedTime(0, std::numeric_limits<double>::infinity(), 1, timing)); timing.direction = Timing::PlaybackDirectionReverse; EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(0, std::numeric_limits<double>::infinity(), 0, timing)); EXPECT_EQ(std::numeric_limits<double>::infinity(), calculateTransformedTime(0, std::numeric_limits<double>::infinity(), 1, timing)); } }
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1994 -- All Rights Reserved PROJECT: MODULE: FILE: outboxRegister.asm AUTHOR: Adam de Boor, Apr 29, 1994 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- Adam 4/29/94 Initial revision DESCRIPTION: Functions to handle the registration of a new message in the outbox. $Id: outboxRegister.asm,v 1.1 97/04/05 01:21:23 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ Outbox segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutboxMessageAdded %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Notification routine called when a message is added to the outbox DBQ. CALLED BY: (EXTERNAL) DBQAdd PASS: bx = VM file handle holding the message di = DBQ handle dxax = DBGroupAndItem of the message RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: For each address: if MITA_addrList is 0: allocate talID & mark address & all other addresses with same medium if current time after start time & medium is available: send MSG_MA_OUTBOX_SENDABLE_CONFIRMATION else send MSG_MA_OUTBOX_CONFIRMATION REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/29/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OutboxMessageAdded proc far uses cx, ax, ds, di, si, bx, bp, dx .enter call MessageLock ; *ds:di <- MMD mov cx, di ; pass to enum in CX mov si, ds:[di] if _AUTO_RETRY_AFTER_TEMP_FAILURE ; ; If a transmission-window-open time has been set for the message, make ; that the initial retry time for the message. ; mov bx, ds:[si].MMD_transWinOpen.FDAT_date or bx, ds:[si].MMD_transWinOpen.FDAT_time jz initialRetryHandled movdw ds:[si].MMD_autoRetryTime, ds:[si].MMD_transWinOpen, bx initialRetryHandled: endif ; _AUTO_RETRY_AFTER_TEMP_FAILURE if _OUTBOX_SEND_WITHOUT_QUERY or _AUTO_RETRY_AFTER_TEMP_FAILURE ; ; Forcibly set the SEND_WITHOUT_QUERY flag for these systems. Block ; will be dirtied in a moment. ; ; 10/27/95: if third-class or worse priority, do not set this bit. ; Wait for user to request it or some other thing to happen before ; attempting to send the message. -- ardeb ; mov bx, ds:[si].MMD_flags if _OUTBOX_SEND_WITHOUT_QUERY ornf bx, mask MMF_SEND_WITHOUT_QUERY mov ds:[si].MMD_flags, bx ; assume not 3d class endif ; _OUTBOX_SEND_WITHOUT_QUERY andnf bx, mask MMF_PRIORITY cmp bx, MMP_THIRD_CLASS shl offset MMF_PRIORITY jb swqDone if _AUTO_RETRY_AFTER_TEMP_FAILURE ; ; Flag Upon Request state by setting retry to eternity ; movdw ds:[si].MMD_autoRetryTime, MAILBOX_ETERNITY endif if _OUTBOX_SEND_WITHOUT_QUERY andnf ds:[si].MMD_flags, not mask MMF_SEND_WITHOUT_QUERY endif swqDone: endif ; _OUTBOX_SEND_WITHOUT_QUERY or _AUTO_RETRY_AFTER_TEMP_FAILURE mov si, ds:[si].MMD_transAddrs mov bx, cs mov di, offset ORMessageAddedCallback mov bp, ax ; ds:bp = MailboxMessage pushdw dxax call ChunkArrayEnum call UtilVMDirtyDS ; addresses were changed... call UtilVMUnlockDS popdw cxdx mov bp, (MABC_ALL shl offset MABC_ADDRESS) or \ mask MABC_OUTBOX or \ (MACT_EXISTS shl offset MABC_TYPE) mov ax, MSG_MA_BOX_CHANGED clr di ; di <- additional msg flags call UtilForceQueueMailboxApp; queue to avoid stack overflow ; when sending poof message ; -- ardeb 9/11/95 .leave ret OutboxMessageAdded endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORNotifyIndicator %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Let the indicator app know how many documents are in the outbox CALLED BY: (INTERNAL) OutboxMessageAdded PASS: nothing RETURN: nothing DESTROYED: nothing SIDE EFFECTS: GCN notification sent out PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 9/19/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORMessageAddedCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Check this address to see if it's a new medium and, if so, whether it can be sent, generating an appropriate confirmation box for the user for each medium used. CALLED BY: (INTERNAL) OutboxMessageAdded via ChunkArrayEnum PASS: ds:di = MailboxInternalTransAddr ax = size of MailboxInternalTransAddr *ds:si = address array dxbp = MailboxMessage *ds:cx = MailboxMessageDesc RETURN: carry set to stop enumerating (always clear) DESTROYED: bx, si, di allowed SIDE EFFECTS: message may be sent to the mailbox library app object to tell the user about the message. PSEUDO CODE/STRATEGY: if MITA_addrList is 0: allocate talID & mark address & all other addresses with same medium if current time after start time & medium is available: send MSG_MA_OUTBOX_SENDABLE_CONFIRMATION else send MSG_MA_OUTBOX_CONFIRMATION NOTES: If MMD_transWinOpen is set to MAILBOX_ETERNITY, we are treating that as a request to send the message using the next available connection. This was added for Lizzy by partner's request. _OUTBOX_SEND_WITHOUT_QUERY and _AUTO_RETRY_AFTER_TEMP_FAILURE must both be TRUE for this change to work. I'm leaving the code responder-only until someone decides to include the "clear talID" fix for all products. -jwu 3/4/97 REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/29/94 Initial version jwu 3/04/97 Added transWinOpen set to ETERNITY code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORMessageAddedCallback proc far .enter ; ; See if this address has already been handled (field initialized to 0 ; when address stored) ; tst ds:[di].MITA_addrList LONG jnz done ; => it has ; ; Mark it and all the other addresses that use the same medium with ; a new talID that will be used when creating the display in the ; confirmation box (and also tell us when we've dealt with subsequent ; addresses using the same medium). ; push dx, di call AdminAllocTALID push cx mov_tr cx, ax mov dx, ds:[di].MITA_medium mov bx, cs mov di, offset ORMessageAddedMarkCallback call ChunkArrayEnum pop cx ; ; Now see if the message is into its transmission window. If it's not, ; the presence or absence of the medium is irrelevant. (can't use cmpdw ; for the comparison b/c FileDateAndTime has the words in the wrong ; order.) ; call TimerGetFileDateTime ; dxax <- date & time mov di, cx mov di, ds:[di] ; ds:di <- MailboxMessageDesc cmp ds:[di].MMD_transWinOpen.FDAT_date, ax jne dateCheckComplete ; (branch at dCC will handle ; both > & < cases) cmp ds:[di].MMD_transWinOpen.FDAT_time, dx dateCheckComplete: mov si, di ; ds:si = MailboxMessageDesc mov ax, MSG_MA_START_NEXT_EVENT_TIMER pop dx, di ja notEligible ; start of transmit window is beyond ; the current time, so message is ; not sendable ; ; start of xmit window is open. Schedule an event for the deadline. ; BitSet ds:[si].MMD_flags, MIMF_NOTIFIED_TRANS_WIN_OPEN push cx, dx movdw dxcx, ds:[si].MMD_transWinClose cmpdw dxcx, MAILBOX_ETERNITY je afterDeadline ; jump if no deadline to schedule call UtilSendToMailboxApp afterDeadline: pop cx, dx if _OUTBOX_SEND_WITHOUT_QUERY test ds:[si].MMD_flags, mask MMF_SEND_WITHOUT_QUERY jnz checkMedium mov ax, handle uiSentUponRequestStr mov si, offset uiSentUponRequestStr jmp notEligibleAfterStartSchedule checkMedium: endif ; _OUTBOX_SEND_WITHOUT_QUERY ; ; Ask the OM code to see if the medium this message needs ; is available. If it is, then we use the confirmation box that says ; the message can be sent... ; mov ax, ds:[di].MITA_medium if _OUTBOX_SEND_WITHOUT_QUERY push es, si, cx, dx, di segmov es, ds add di, offset MITA_opaqueLen movdw cxdx, ds:[si].MMD_transport mov si, ds:[si].MMD_transOption call OMCheckConnectable pop es, si, cx, dx, di else ; !_OUTBOX_SEND_WITHOUT_QUERY call OMCheckMediumAvailable endif ; _OUTBOX_SEND_WITHOUT_QUERY mov bx, si ; ds:bx = MailboxMessageDesc mov si, MSG_MA_OUTBOX_SENDABLE_CONFIRMATION jc tellApp push cx mov si, ds:[bx].MMD_transAddrs ; *ds:si = addr array push si push dx sub di, ds:[si] ; di = offset to current MITA element mov dx, ds:[bx].MMD_transOption mov cx, ds:[bx].MMD_transport.MT_id mov bx, ds:[bx].MMD_transport.MT_manuf ; ; Unlock message to avoid possibility of deadlock. ; ORGetMediumNotAvailReason tries to find an active ; transmission thread for this medium/transport using ; OTFindThread. If there was a (unrelated) transmission ; thread active with the MainThread resource locked and ; trying to lock a message in the same DB item group as ; our message, we'd deadlock on MainThread and the DB item ; group. See bug 56777, for example. ; call UtilVMUnlockDS ; unlock message to avoid poss. of ; deadlock, we re-deref when ; re-locking to handle possible ; lmem movement call ORGetMediumNotAvailReason pop dx ; ; address array for this message won't change, so we can ; just re-derefence this way ; di = offset to current MITA element in addr array ; dxbp = Message ; ^lax:si = reason string ; (on stack) = addr array chunk ; push di xchg ax, bp ; dxax = Message, bp = reason handle call MessageLock ; ds = Message block xchg ax, bp ; dxbp = Message, ax = reason handle pop di pop bx ; *ds:bx = addr array add di, ds:[bx] ; ds:di = current MITA element pop cx jmp notEligibleAfterStartSchedule notEligible: ; ; Send MSG_MA_START_NEXT_EVENT_TIMER to schedule an event for ; the start of xmit window. ds:[si].MMD_transWinOpen is when ; message will be sent. ; push cx, dx movdw dxcx, ds:[si].MMD_transWinOpen call UtilSendToMailboxApp pop cx, dx mov ax, handle uiNotTimeForTransmissionStr mov si, offset uiNotTimeForTransmissionStr notEligibleAfterStartSchedule: ; ; Set the reason we weren't willing to send the message. ; push cx, dx movdw cxdx, axsi call ORStoreReason mov ds:[di].MITA_reason, ax CheckHack <offset MTF_TRIES eq 0> inc ds:[di].MITA_flags call UtilVMDirtyDS ; ; Free the lmem block we might have allocated to fetch the reason ; the medium's not available. ; cmp cx, handle ROStrings je reasonStored mov bx, cx call MemFree reasonStored: pop cx, dx mov si, MSG_MA_OUTBOX_CONFIRMATION tellApp: ; ; Time now to tell the application to put up a confirmation box. ; First we need to add a reference to the message (which will be ; removed when the box comes down). ; mov ax, bp ; dxax = MailboxMessage ; ds:di = MailboxInternalTransAddr ; si = message to send to app ; push cx, dx, bp, ax call MailboxGetAdminFile call DBQAddRef ; ; Rearrange the registers for the call: ; cxdx <- MailboxMessage ; bp <- talID ; ax <- message for app ; mov cx, dx mov_tr dx, ax mov_tr ax, si mov bp, ds:[di].MITA_addrList ; ; Tell our application object, asynchronously, to tell the user. ; call UtilSendToMailboxApp pop cx, dx, bp, ax done: clc .leave ret ORMessageAddedCallback endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORGenerateTimeMessageString %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Generate "Send time <time> string" CALLED BY: ORMessageAddedCallback PASS: ax = FileTime RETURN: ^lax:si is null terminated string for why message not sent DESTROYED: nothing NOTES: Replaces '\1' in uiNotTimeForTransmissionStr with passed time REVISION HISTORY: Name Date Description ---- ---- ----------- SK 12/10/96 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORGetMediumNotAvailReason %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Fetch the reason the medium's not available into an lmem chunk we can use. CALLED BY: (INTERNAL) ORMessageAddedCallback PASS: ax = OutboxMedia token bxcx = MailboxTransport (can pass bx > MANUFACTURER_ID_DATABASE_LAST if there is no associated transport) dx = MailboxTransportOption (ignored if bx > MANUFACTURER_ID_DATABASE_LAST) RETURN: ^lax:si = reason string to use. ax may be dynamically allocated global block that must be freed by the caller. DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 10/31/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORGetMediumNotAvailReason proc far uses ds, di, cx, dx, bx .enter push es ; (done outside uses to be popped ; earlier and avoid segment ec ; death) ; ; Allocate an lmem block into which we can fetch the medium descriptor ; and the reason for its absence. ; push ax mov ax, LMEM_TYPE_GENERAL clr cx call MemAllocLMem call MemLock mov es, ax mov ds, ax pop ax ; ; Find out how big we need to make the chunk for the medium descriptor ; clr di, cx call OMGetMediumDesc ; cx <- # bytes ; ; Allocate a chunk that big ; push ax call LMemAlloc mov_tr si, ax pop ax ; ; Fetch the descriptor, s'il vous plais ; mov di, ds:[si] call OMGetMediumDesc pop es ; es <- passed es (avoid ec +segment) ; ; See if there's a reason stored. ; movdw cxdx, dsdi call MediaGetReason tst ax jz useDefault ; => no, use default ; ; Release the lmem block and return it and the chunk. ; call MemUnlock mov_tr si, ax mov_tr ax, bx ; ^lax:si <- reason done: .leave ret useDefault: push es segmov es, ds call MediaCheckMediumAvailableByPtr pop es jc isAvailable mov ax, handle uiMediumNotAvailableStr mov si, offset uiMediumNotAvailableStr toDone: call MemFree jmp done isAvailable: mov ax, handle uiMediumBusyStr mov si, offset uiMediumBusyStr jmp toDone ORGetMediumNotAvailReason endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORMessageAddedMarkCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Callback function to mark all the addresses for the same medium with the same talID CALLED BY: (INTERNAL) ORMessageAddedCallback via ChunkArrayEnum, OSCMsndDeleteMessage via ChunkArrayEnum PASS: ds:di = MailboxInternalTransAddr dx = medium token cx = talID, or 0 to unmark addresses RETURN: carry set to stop enumerating (always clear) DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 6/ 2/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORMessageAddedMarkCallback proc far .enter cmp ds:[di].MITA_medium, dx jne done EC < tst ds:[di].MITA_addrList > EC < jz EC_ok > EC < tst cx > EC < ERROR_NZ NEW_ADDRESS_IS_ALREADY_MARKED > EC < EC_ok: > mov ds:[di].MITA_addrList, cx call UtilVMDirtyDS done: clc .leave ret ORMessageAddedMarkCallback endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OutboxStoreAddresses %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Store the addresses for an outgoing message. CALLED BY: (EXTERNAL) MRStoreAddresses PASS: cx = number of addresses es:si = MailboxTransAddr array *ds:di = MailboxMessageDesc ds:bx = MailboxMessageDesc ax = MailboxTransportOption RETURN: carry set on error ax = MailboxError DESTROYED: es, si, cx, bx SIDE EFFECTS: loads PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 3/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ OutboxStoreAddresses proc far ; ; Attempt to load the transport driver, as we'll need it for each ; address. ; push ax, cx, dx movdw cxdx, ds:[bx].MMD_transport call MailboxLoadTransportDriver pop ax, cx, dx jc loadError ; ; Loop over all the addresses, storing them one at a time. ; addrLoop: call ORStoreOneAddress jc doneUnloadDriver call ORCheckDuplicate add si, size MailboxTransAddr loop addrLoop clc doneUnloadDriver: pushf call MailboxFreeDriver popf ret loadError: mov ax, ME_CANNOT_LOAD_TRANSPORT_DRIVER ret OutboxStoreAddresses endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORCheckDuplicate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: See if the address just added is a duplicate, in its significant opaque bytes, of another address already specified for the message. CALLED BY: (INTERNAL) OutboxStoreAddresses PASS: *ds:di = MailboxMessageDesc RETURN: nothing DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 3/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORCheckDuplicate proc near uses bx, cx, si, di, ax, dx, bp, es .enter ; ; Find how many addresses there are, so we can (1) do nothing when ; there's only one address, and (2) find the last element in the array ; mov si, ds:[di] movdw axdx, ds:[si].MMD_transport ; axdx <- transport, for ; getting sig # bytes mov bx, ds:[si].MMD_transOption ; bx <- trans option, ; for same reason mov si, ds:[si].MMD_transAddrs call ChunkArrayGetCount dec cx ; (1-byte check for == 1, and ; gets us 0-origin index from ; 1-origin count) jz done ; => only 1 addr, so no dup ; possible ; ; Point to the last element in the array (nukes CX [var sized elts], so ; use mov_tr...) ; push ax ; save transport.high mov_tr ax, cx ; ax <- idx of last elt call ChunkArrayElementToPtr pop cx ; cxdx <- transport ; ; Find the number of significant address bytes for the medium/transport ; pair. ; mov ax, ds:[di].MITA_medium push ax ; save for enum... call OMGetSigAddrBytes ; ax <- # bytes ; ; Arrange the registers for ChunkArrayEnum and loop over all the ; addresses, looking for ones that use the same medium and whose first ; n bytes compare the same. ; pop dx ; dx <- medium token mov_tr bp, ax ; bp <- # significant bytes mov cx, di ; cx <- last elt segmov es, ds ; es <- ds, so doesn't have to ; be done each time through ; the callback mov bx, cs mov di, offset ORCheckDuplicateCallback call ChunkArrayEnum ; ax <- index of first dup jnc done ; ; Found a duplicate, so run to the end of the list and point it to ; the last element. ; linkLoop: call ChunkArrayElementToPtr EC < ERROR_C INVALID_DUPLICATE_ADDR_LIST > mov ax, ds:[di].MITA_next cmp ax, MITA_NIL jne linkLoop call ChunkArrayGetCount dec cx mov ds:[di].MITA_next, cx ; ; Mark the new thing as a duplicate. ; mov_tr ax, cx call ChunkArrayElementToPtr ornf ds:[di].MITA_flags, mask MTF_DUP done: .leave ret ORCheckDuplicate endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORCheckDuplicateCallback %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Callback routine to see if this address is the same, in its significant opaque address bytes, to the one just added. CALLED BY: (INTERNAL) ORCheckDuplicate via ChunkArrayEnum PASS: ds:di = MailboxInternalTransAddr to check ds:cx = MailboxInternalTransAddr just added es = ds dx = medium used by ds:cx bp = # bytes to compare RETURN: carry set if the same: ax = index of address checked carry clear if different ax = destroyed DESTROYED: bx, si, di allowed SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/ 3/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORCheckDuplicateCallback proc far .enter cmp di, cx je done ; => same element, so don't compare cmp ds:[di].MITA_medium, dx jne notEqual ; => can't possibly be the same addr xchg si, cx call OUCompareAddresses xchg cx, si je match notEqual: clc done: .leave ret match: ; ; Same address, so return the index of this element and stop enumerating ; call ChunkArrayPtrToElement stc jmp done ORCheckDuplicateCallback endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORStoreOneAddress %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Store a single transport address at the end of the array of addresses for the message. CALLED BY: (INTERNAL) OutboxStoreAddresses PASS: es:si = MailboxTransAddr to add *ds:di = MailboxMessageDesc bx = loaded transport driver ax = MailboxTransportOption RETURN: carry set on error: ax = MailboxError carry clear if ok: ax = destroyed ds = fixed up DESTROYED: nothing SIDE EFFECTS: variable-sized element appended to MMD_transAddrs array PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/20/94 Initial version ardeb 2/17/95 Commonized grunt work of storing an address for both InboxStoreAddresses and ORStoreOneAddress %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORStoreOneAddress proc near uses cx, di, bx .enter ; ; Fetch the medium & unit for the address and have the outbox ; store it away. ; call ORGetAndStoreMedium ; ax <- medium token jc done call MessageStoreAddress jc allocErr done: .leave ret allocErr: ; ; Unregister the medium & transport. ; *ds:di = MMD ; ax = medium token ; push dx mov di, ds:[di] movdw cxdx, ds:[di].MMD_transport mov bx, ds:[di].MMD_transOption call OMUnregister pop dx mov ax, ME_NOT_ENOUGH_MEMORY stc jmp done ORStoreOneAddress endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ORGetAndStoreMedium %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Load and call the transport driver to get the medium & unit for an address. CALLED BY: (INTERNAL) ORStoreOneAddress PASS: *ds:di = MailboxMessageDesc es:si = MailboxTransAddr bx = loaded transport driver ax = MailboxTransportOption RETURN: carry set on error: ax = MailboxError carry clear if ok: ax = token for medium DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 4/23/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ORGetAndStoreMedium proc near mapArgs local MBTDMediumMapArgs uses bx, di, cx, dx, si .enter ; ; Set up the MBTDMediumMapArgs thing on the stack for ; fetching the medium. ; mov ss:[mapArgs].MBTDMMA_transOption, ax mov ax, es:[si].MTA_transAddrLen mov ss:[mapArgs].MBTDMMA_transAddrLen, ax movdw ss:[mapArgs].MBTDMMA_transAddr, \ es:[si].MTA_transAddr, ax ; ; Call the driver to ask for the medium. This also serves to ; error-check the address... ; push ds, di call GeodeInfoDriver mov cx, ss lea dx, ss:[mapArgs] mov di, DR_MBTD_GET_ADDRESS_MEDIUM call ds:[si].DIS_strategy pop ds, di mov ax, ME_ADDRESS_INVALID jc done ; ; Fetch the transport for the message, and let the outbox know ; what's in store. ; mov di, ds:[di] mov bx, ds:[di].MMD_transOption mov si, ds:[di].MMD_transport.high mov di, ds:[di].MMD_transport.low call OMRegister ; ; While we've got the medium token, clear the phone blacklist, ; if necessary ; clc done: .leave ret ORGetAndStoreMedium endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MailboxGetTransAddr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Fetch the opaque portion of the indicated transport address CALLED BY: (GLOBAL) PASS: cxdx = MailboxMessage es:di = buffer for copy ax = # bytes in buffer bx = address # requested RETURN: carry set if couldn't copy: ax = 0 if message or address invalid = # bytes needed if buffer was too small carry clear if address copied out: ax = # bytes copied out DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 10/31/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MailboxGetTransAddr proc far uses ds, si, di, bp, bx, cx .enter EC < tst ax > EC < jz bufferPtrOK > EC < Assert fptr, esdi > EC <bufferPtrOK: > mov bp, di ; preserve dest ptr call MessageLockCXDX ; *ds:di <- MMD jc invalidMsg ; ; Fetch out the address array. If there is none, the address # is ; invalid. ; mov di, ds:[di] mov si, ds:[di].MMD_transAddrs tst si jz invalidAddress ; ; Point to the address element. ; xchg ax, bx ; ax <- addr #, bx <- buf size call ChunkArrayElementToPtr jc invalidAddress ; => beyond the pale, so addr ; is invalid ; ; Fetch the size of the opaque data into AX for comparison and return. ; mov ax, ds:[di].MITA_opaqueLen cmp ax, bx ja errReturn ; => not enough room in buf ; ; Move the data into the passed buffer. ; lea si, ds:[di].MITA_opaque mov di, bp ; es:di <- dest buffer mov cx, ax ; cx <- # bytes to copy rep movsb clc ; signal happiness done: ; ; Release the message block. ; call UtilVMUnlockDS exit: .leave ret invalidAddress: clr ax ; signal no amount of buffer ; space could hold the address, ; as the thing is bad errReturn: stc jmp done invalidMsg: mov ax, 0 ; signal no amount of buffer ; space could hold the address ; as the thing is bad jmp exit MailboxGetTransAddr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MailboxGetNumTransAddrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Return the number of addresses bound to the given message CALLED BY: (GLOBAL) PASS: cxdx = MailboxMessage RETURN: carry set on error: ax = MailboxError (message invalid) carry clear if ok: ax = number of addresses = 0 if message is in the inbox DESTROYED: nothing SIDE EFFECTS: none PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 11/ 6/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MailboxGetNumTransAddrs proc far uses ds, di, si .enter call MessageLockCXDX jc exit mov di, ds:[di] mov si, ds:[di].MMD_transAddrs clr ax ; assume no addresses tst si jz done ; correct -- return 0 mov_tr ax, cx ; ax <- entry cx call ChunkArrayGetCount xchg ax, cx ; ax <- count, cx <- saved cx done: call UtilVMUnlockDS clc exit: .leave ret MailboxGetNumTransAddrs endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MailboxSetTransAddr %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Sets the opaque transport address for a message, replacing the existing one. NOTE: the new address may not differ from the old address in its significant address bytes. This is not intended to allow arbitrary redirection of a message, but simply for trans- port drivers to record their progress for a particular address in the insignificant portion of the address. CALLED BY: (GLOBAL) PASS: cxdx = MailboxMessage es:di = buffer containing the new address bx = address number to set ax = number of bytes in the buffer. RETURN: carry set if copy couldn't be completed: ax = MailboxError (message is invalid or not enough memory available) carry clear if address successfully changed: ax = ME_SUCCESS DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 11/ 6/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MailboxSetTransAddr proc far uses ds, si, di, cx, dx, es, bx EC < uses bp > .enter push di ; preserve new addr base call MessageLockCXDX pop dx ; es:dx <- new addr jc toDone ; ; Point to the element in the transAddrs array. ; mov si, ds:[di] EC < mov bp, si > mov si, ds:[si].MMD_transAddrs tst si jz invalidAddress xchg ax, bx ; ax <- addr #, bx <- addr size call ChunkArrayElementToPtr ; cx <- elt size jc invalidAddress ; => index beyond the pale CheckHack <MAS_SENT eq 0> test ds:[di].MITA_flags, mask MTF_STATE jnz doResize ; => address not sent to yet, ; so it may be changed invalidAddress: call UtilVMUnlockDS mov ax, ME_ADDRESS_INVALID stc toDone: jmp done doResize: ; ; EC: Make sure the caller isn't attempting to change the significant ; bytes of the address. ; EC < push ax, cx, si, di > EC < push bx > EC < push dx > EC < mov ax, ds:[di].MITA_medium > EC < movdw cxdx, ds:[bp].MMD_transport > EC < mov bx, ds:[bp].MMD_transOption > EC < call OMGetSigAddrBytes > EC < pop dx > EC < mov cx, ds:[di].MITA_opaqueLen > EC < cmp cx, ax > EC < jbe haveCmpSize > EC < mov cx, ax > EC <haveCmpSize: > EC < lea si, ds:[di].MITA_opaque > EC < mov di, dx > EC < ; cx = # avail, or # significant, whichever is smaller > EC < pop bx ; bx <- # passed > EC < cmp bx, cx > EC < ERROR_B CANNOT_CHANGE_SIGNIFICANT_ADDRESS_BYTES > EC < je doCompare ; => can compare bytes > EC < ; compare ax to cx here to catch case where MITA holds fewer > EC < ; than the # of significant, where # sig is not ALL_BYTES_SIG > EC < cmp ax, cx ; are bytes beyond cx significant?> EC < ERROR_A CANNOT_CHANGE_SIGNIFICANT_ADDRESS_BYTES ; yes > EC <doCompare: > EC < repe cmpsb > EC < ERROR_NE CANNOT_CHANGE_SIGNIFICANT_ADDRESS_BYTES > EC < pop ax, cx, si, di > ; ; Resize the element properly. XXX: have to mess with the chunkarray ; offset table by hand, here, as kernel provides no way to insert or ; delete within an element, and we can't use ChunkArrayElementResize, ; as that'll destroy the user-readable stuff (it deletes at the end). ; blech. ; sub bx, ds:[di].MITA_opaqueLen je copy ; same size. yea! push ax ; save element # mov cx, bx ; cx <- # bytes difference (+/-) lahf ; save carry for figuring which ; LMem routine to call lea bx, ds:[di].MITA_opaque sub bx, ds:[si] ; bx <- insert/delete offset sahf mov ax, si ; *ds:ax <- chunk to adjust jb deleteSpace call LMemInsertAt jmp adjust deleteSpace: neg cx ; cx <- # bytes to delete call LMemDeleteAt neg cx ; cx <- adjustment value, again adjust: ; ; Now adjust the offset array in the header. ; pop ax ; ax <- address # add bx, ds:[si] ; ds:bx <- opaque data lea di, ds:[bx-offset MITA_opaque] ; ds:di <- MITA again add ds:[di].MITA_opaqueLen, cx ; adjust the opaqueLen ; properly, while we've ; still got cx mov bx, ax ; bx <- address # mov_tr ax, cx ; ax <- adjustment value ; ; Compute the number of elements that need adjusting. ; mov si, ds:[si] mov cx, ds:[si].CAH_count inc bx ; start adjusting with following ; element sub cx, bx ; cx <- # to adjust jz copy shl bx add bx, ds:[si].CAH_offset ; bx <- entry to adjust first adjustLoop: add ds:[bx], ax ; adjust element base up or ; down, as appropriate inc bx ; advance to next inc bx loop adjustLoop copy: ; ; Copy the new data into the properly-sized element ; mov cx, ds:[di].MITA_opaqueLen add di, offset MITA_opaque mov si, dx segxchg ds, es ; ds:si <- source ; es:di <- dest rep movsb ; ; Dirty and unlock the message block. ; segmov ds, es ; ds <- msg block again call UtilVMDirtyDS call UtilVMUnlockDS call UtilUpdateAdminFile CheckHack <ME_SUCCESS eq 0> clr ax ; (clears carry) done: .leave ret MailboxSetTransAddr endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MailboxGetUserTransAddrLMem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Fetch the user-readable form of the passed address CALLED BY: (GLOBAL) PASS: cxdx = MailboxMessage bx = lmem block in which to allocate a chunk to hold the address ax = address # requested RETURN: carry set on error: ax = MailboxError (invalid message, insufficient memory) carry clear if ok: ^lbx:ax = null-terminated subject DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 5/22/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ MailboxGetUserTransAddrLMem proc far uses si, di, cx, bx, dx .enter mov si, ds ; preserve DS in case it points to ^hbx ; ; Lock down the message. ; call MessageLockCXDX mov dx, si ; dx <- DS on entry, for restore jc done ; => message invalid, so boogie. ; ax = MailboxError ; ; Point to the address desired. ; mov si, ds:[di] mov si, ds:[si].MMD_transAddrs call ChunkArrayElementToPtr mov ax, ME_ADDRESS_INVALID jc unlockDone ; ; Compute the size and location of the user-readable portion. ; sub cx, ds:[di].MITA_opaqueLen sub cx, size MailboxInternalTransAddr lea si, ds:[di].MITA_opaque add si, ds:[di].MITA_opaqueLen ; ; Lock down the destination block and note if DS on entry was pointing ; there. (bx = -1 if so, else 0) ; push ds call ObjLockObjBlock ; in case lmem block is an object block mov ds, ax clr bx ; assume not pointing to block cmp ax, dx jne allocChunk ; yes dec bx ; no -- flag it allocChunk: ; ; Allocate a chunk to hold the address. ; mov ax, mask OCF_DIRTY call LMemAlloc mov di, ds ; di <- new location of dest block, ; for setting ES and adjusting return ; value for DS pop ds jc allocErr ; ; If DS was pointing to the block on entry, make sure it'll point there ; on return. ; inc bx jnz doCopy ; => not pointing there mov dx, di ; dx <- new segment doCopy: ; ; Copy the data from the trans addr to the chunk. ; push es ; preserve ES from entry (fixed up if ; was pointing to the destination ; block) mov es, di mov di, ax mov di, es:[di] ; es:di <- destination rep movsb mov bx, es:[LMBH_handle] pop es call MemUnlock clc unlockDone: call UtilVMUnlockDS done: mov ds, dx ; ds <- passed DS, possibly fixed up .leave ret allocErr: call UtilUnlockDS pop ds mov ax, ME_NOT_ENOUGH_MEMORY jmp unlockDone MailboxGetUserTransAddrLMem endp Outbox ends
; ; This file is automatically generated ; ; Do not edit!!! ; ; djm 12/2/2000 ; ; ZSock Lib function: sock_shutdown XLIB sock_shutdown LIB no_zsock INCLUDE "#packages.def" INCLUDE "#zsock.def" .sock_shutdown ld a,r_sock_shutdown call_pkg(tcp_all) ret nc ; We failed..are we installed? cp rc_pnf scf ;signal error ret nz ;Internal error call_pkg(tcp_ayt) jr nc,sock_shutdown jp no_zsock
#include<iostream> using namespace std; int findS(int s) { if (s == 1) { return s; } if (s <= 2) { return -1; } if (s == 3) { return 2; } int l = 1, r = s / 2; while (l <= r) { int mid = (l + r) / 2; int sum = mid * (mid + 1) / 2; if (sum == s) { return mid; } else if (sum > s) { r = mid - 1; } else { l = mid + 1; } } return -1; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << findS(n) << "\n"; } return 0; }
SECTION code_fp_math32 PUBLIC cm32_sccz80_sin EXTERN cm32_sccz80_fsread1, _m32_sinf cm32_sccz80_sin: call cm32_sccz80_fsread1 jp _m32_sinf
// Copyright WRLD Ltd (2018-), All Rights Reserved #include "SearchMenuSearchWithContextMessage.h" namespace ExampleApp { namespace SearchMenu { SearchMenuSearchWithContextMessage::SearchMenuSearchWithContextMessage(const std::string& searchQuery, const View::QueryContext& queryContext) : m_searchQuery(searchQuery) , m_queryContext(queryContext) { } const std::string& SearchMenuSearchWithContextMessage::SearchQuery() const { return m_searchQuery; } const View::QueryContext& SearchMenuSearchWithContextMessage::QueryContext() const { return m_queryContext; } } }
; A171480: a(n) = 6*a(n-1) - 8*a(n-2) + 4 for n > 1; a(0) = 1, a(1) = 9. ; 1,9,50,232,996,4124,16780,67692,271916,1089964,4364460,17467052,69886636,279583404,1118407340,4473776812,17895402156,71582198444,286329973420,1145322252972,4581293730476,18325184359084,73300756310700,293203062991532,1172812327463596,4691249460849324,18764998145387180,75059993185528492,300239973950073516,1200959898216213164,4803839597696690860,19215358400450439852,76861433621129112236,307445734523171154604,1229782938169994029740,4919131752834594941612,19676527011647617411756,78706108047208944937644,314824432190072730331820,1259297728762764822489772,5037190915056007092284076,20148763660233923973786284,80595054640955487104445100,322380218563861530836380332,1289520874255525288182721196,5158083497022259482405284524,20632333988089354588969937580,82529335952358051674577349292,330117343809433473335704595116,1320469375237736426617608776364,5281877500950950773020015897260,21127510003803813225179225172652,84510040015215273166915223857836,338040160060861133200057541765804,1352160640243444613865023459732140,5408642560973778617589680424266412,21634570243895114794617894867741356,86538280975580459826989925812316844,346153123902321840604996395931970220 mul $0,2 add $0,2 lpb $0 trn $0,4 add $0,2 add $1,2 mul $1,4 mul $2,2 trn $2,1 add $1,$2 add $2,5 lpe add $1,1 mov $0,$1
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <boost/algorithm/string/replace.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include "alert.h" #include "chainparams.h" #include "checkpoints.h" #include "db.h" #include "init.h" #include "kernel.h" #include "net.h" #include "txdb.h" #include "txmempool.h" #include "ui_interface.h" using namespace std; using namespace boost; // // Global state // CCriticalSection cs_setpwalletRegistered; set<CWallet*> setpwalletRegistered; CCriticalSection cs_main; CTxMemPool mempool; map<uint256, CBlockIndex*> mapBlockIndex; set<pair<COutPoint, unsigned int> > setStakeSeen; CBigNum bnProofOfStakeLimit(~uint256(0) >> 20); CBigNum bnProofOfStakeLimitV2(~uint256(0) >> 48); unsigned int nStakeMinAge = 8 * 60 * 60; // 8 hours unsigned int nModifierInterval = 10 * 60; // time to elapse before new modifier is computed int nCoinbaseMaturity = 500; CBlockIndex* pindexGenesisBlock = NULL; int nBestHeight = -1; uint256 nBestChainTrust = 0; uint256 nBestInvalidTrust = 0; uint256 hashBestChain = 0; CBlockIndex* pindexBest = NULL; int64_t nTimeBestReceived = 0; bool fImporting = false; bool fReindex = false; bool fHaveGUI = false; struct COrphanBlock { uint256 hashBlock; uint256 hashPrev; std::pair<COutPoint, unsigned int> stake; vector<unsigned char> vchBlock; }; map<uint256, COrphanBlock*> mapOrphanBlocks; multimap<uint256, COrphanBlock*> mapOrphanBlocksByPrev; set<pair<COutPoint, unsigned int> > setStakeSeenOrphan; map<uint256, CTransaction> mapOrphanTransactions; map<uint256, set<uint256> > mapOrphanTransactionsByPrev; // Constant stuff for coinbase transactions we create: CScript COINBASE_FLAGS; const string strMessageMagic = "BlackCoin Signed Message:\n"; extern enum Checkpoints::CPMode CheckpointsMode; ////////////////////////////////////////////////////////////////////////////// // // dispatching functions // // These functions dispatch to one or all registered wallets namespace { struct CMainSignals { // Notifies listeners of updated transaction data (passing hash, transaction, and optionally the block it is found in. boost::signals2::signal<void (const CTransaction &, const CBlock *, bool)> SyncTransaction; // Notifies listeners of an erased transaction (currently disabled, requires transaction replacement). boost::signals2::signal<void (const uint256 &)> EraseTransaction; // Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). boost::signals2::signal<void (const uint256 &)> UpdatedTransaction; // Notifies listeners of a new active block chain. boost::signals2::signal<void (const CBlockLocator &)> SetBestChain; // Notifies listeners about an inventory item being seen on the network. boost::signals2::signal<void (const uint256 &)> Inventory; // Tells listeners to broadcast their data. boost::signals2::signal<void (bool)> Broadcast; } g_signals; } void RegisterWallet(CWalletInterface* pwalletIn) { g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3)); g_signals.EraseTransaction.connect(boost::bind(&CWalletInterface::EraseFromWallet, pwalletIn, _1)); g_signals.UpdatedTransaction.connect(boost::bind(&CWalletInterface::UpdatedTransaction, pwalletIn, _1)); g_signals.SetBestChain.connect(boost::bind(&CWalletInterface::SetBestChain, pwalletIn, _1)); g_signals.Inventory.connect(boost::bind(&CWalletInterface::Inventory, pwalletIn, _1)); g_signals.Broadcast.connect(boost::bind(&CWalletInterface::ResendWalletTransactions, pwalletIn, _1)); } void UnregisterWallet(CWalletInterface* pwalletIn) { g_signals.Broadcast.disconnect(boost::bind(&CWalletInterface::ResendWalletTransactions, pwalletIn, _1)); g_signals.Inventory.disconnect(boost::bind(&CWalletInterface::Inventory, pwalletIn, _1)); g_signals.SetBestChain.disconnect(boost::bind(&CWalletInterface::SetBestChain, pwalletIn, _1)); g_signals.UpdatedTransaction.disconnect(boost::bind(&CWalletInterface::UpdatedTransaction, pwalletIn, _1)); g_signals.EraseTransaction.disconnect(boost::bind(&CWalletInterface::EraseFromWallet, pwalletIn, _1)); g_signals.SyncTransaction.disconnect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3)); } void UnregisterAllWallets() { g_signals.Broadcast.disconnect_all_slots(); g_signals.Inventory.disconnect_all_slots(); g_signals.SetBestChain.disconnect_all_slots(); g_signals.UpdatedTransaction.disconnect_all_slots(); g_signals.EraseTransaction.disconnect_all_slots(); g_signals.SyncTransaction.disconnect_all_slots(); } void SyncWithWallets(const CTransaction &tx, const CBlock *pblock, bool fConnect) { g_signals.SyncTransaction(tx, pblock, fConnect); } void ResendWalletTransactions(bool fForce) { g_signals.Broadcast(fForce); } ////////////////////////////////////////////////////////////////////////////// // // Registration of network node signals. // void RegisterNodeSignals(CNodeSignals& nodeSignals) { nodeSignals.ProcessMessages.connect(&ProcessMessages); nodeSignals.SendMessages.connect(&SendMessages); } void UnregisterNodeSignals(CNodeSignals& nodeSignals) { nodeSignals.ProcessMessages.disconnect(&ProcessMessages); nodeSignals.SendMessages.disconnect(&SendMessages); } ////////////////////////////////////////////////////////////////////////////// // // mapOrphanTransactions // bool AddOrphanTx(const CTransaction& tx) { uint256 hash = tx.GetHash(); if (mapOrphanTransactions.count(hash)) return false; // Ignore big transactions, to avoid a // send-big-orphans memory exhaustion attack. If a peer has a legitimate // large transaction with a missing parent then we assume // it will rebroadcast it later, after the parent transaction(s) // have been mined or received. // 10,000 orphans, each of which is at most 5,000 bytes big is // at most 500 megabytes of orphans: size_t nSize = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION); if (nSize > 5000) { LogPrint("mempool", "ignoring large orphan tx (size: %"PRIszu", hash: %s)\n", nSize, hash.ToString()); return false; } mapOrphanTransactions[hash] = tx; BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash); LogPrint("mempool", "stored orphan tx %s (mapsz %"PRIszu")\n", hash.ToString(), mapOrphanTransactions.size()); return true; } void static EraseOrphanTx(uint256 hash) { map<uint256, CTransaction>::iterator it = mapOrphanTransactions.find(hash); if (it == mapOrphanTransactions.end()) return; BOOST_FOREACH(const CTxIn& txin, it->second.vin) { map<uint256, set<uint256> >::iterator itPrev = mapOrphanTransactionsByPrev.find(txin.prevout.hash); if (itPrev == mapOrphanTransactionsByPrev.end()) continue; itPrev->second.erase(hash); if (itPrev->second.empty()) mapOrphanTransactionsByPrev.erase(itPrev); } mapOrphanTransactions.erase(it); } unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) { unsigned int nEvicted = 0; while (mapOrphanTransactions.size() > nMaxOrphans) { // Evict a random orphan: uint256 randomhash = GetRandHash(); map<uint256, CTransaction>::iterator it = mapOrphanTransactions.lower_bound(randomhash); if (it == mapOrphanTransactions.end()) it = mapOrphanTransactions.begin(); EraseOrphanTx(it->first); ++nEvicted; } return nEvicted; } ////////////////////////////////////////////////////////////////////////////// // // CTransaction and CTxIndex // bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout, CTxIndex& txindexRet) { SetNull(); if (!txdb.ReadTxIndex(prevout.hash, txindexRet)) return false; if (!ReadFromDisk(txindexRet.pos)) return false; if (prevout.n >= vout.size()) { SetNull(); return false; } return true; } bool CTransaction::ReadFromDisk(CTxDB& txdb, COutPoint prevout) { CTxIndex txindex; return ReadFromDisk(txdb, prevout, txindex); } bool CTransaction::ReadFromDisk(COutPoint prevout) { CTxDB txdb("r"); CTxIndex txindex; return ReadFromDisk(txdb, prevout, txindex); } bool IsStandardTx(const CTransaction& tx, string& reason) { if (tx.nVersion > CTransaction::CURRENT_VERSION) { reason = "version"; return false; } // Treat non-final transactions as non-standard to prevent a specific type // of double-spend attack, as well as DoS attacks. (if the transaction // can't be mined, the attacker isn't expending resources broadcasting it) // Basically we don't want to propagate transactions that can't be included in // the next block. // // However, IsFinalTx() is confusing... Without arguments, it uses // chainActive.Height() to evaluate nLockTime; when a block is accepted, chainActive.Height() // is set to the value of nHeight in the block. However, when IsFinalTx() // is called within CBlock::AcceptBlock(), the height of the block *being* // evaluated is what is used. Thus if we want to know if a transaction can // be part of the *next* block, we need to call IsFinalTx() with one more // than chainActive.Height(). // // Timestamps on the other hand don't get any special treatment, because we // can't know what timestamp the next block will have, and there aren't // timestamp applications where it matters. if (!IsFinalTx(tx, nBestHeight + 1)) { reason = "non-final"; return false; } // nTime has different purpose from nLockTime but can be used in similar attacks if (tx.nTime > FutureDrift(GetAdjustedTime(), nBestHeight + 1)) { reason = "time-too-new"; return false; } // Extremely large transactions with lots of inputs can cost the network // almost as much to process as they cost the sender in fees, because // computing signature hashes is O(ninputs*txsize). Limiting transactions // to MAX_STANDARD_TX_SIZE mitigates CPU exhaustion attacks. unsigned int sz = tx.GetSerializeSize(SER_NETWORK, CTransaction::CURRENT_VERSION); if (sz >= MAX_STANDARD_TX_SIZE) { reason = "tx-size"; return false; } BOOST_FOREACH(const CTxIn& txin, tx.vin) { // Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed // keys. (remember the 520 byte limit on redeemScript size) That works // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)+3=1627 // bytes of scriptSig, which we round off to 1650 bytes for some minor // future-proofing. That's also enough to spend a 20-of-20 // CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not // considered standard) if (txin.scriptSig.size() > 1650) { reason = "scriptsig-size"; return false; } if (!txin.scriptSig.IsPushOnly()) { reason = "scriptsig-not-pushonly"; return false; } if (!txin.scriptSig.HasCanonicalPushes()) { reason = "scriptsig-non-canonical-push"; return false; } } unsigned int nDataOut = 0; txnouttype whichType; BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (!::IsStandard(txout.scriptPubKey, whichType)) { reason = "scriptpubkey"; return false; } if (whichType == TX_NULL_DATA) nDataOut++; if (txout.nValue == 0) { reason = "dust"; return false; } if (!txout.scriptPubKey.HasCanonicalPushes()) { reason = "scriptpubkey-non-canonical-push"; return false; } } // not more than one data txout per non-data txout is permitted // only one data txout is permitted too if (nDataOut > 1 && nDataOut > tx.vout.size()/2) { reason = "multi-op-return"; return false; } return true; } bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { AssertLockHeld(cs_main); // Time based nLockTime implemented in 0.1.6 if (tx.nLockTime == 0) return true; if (nBlockHeight == 0) nBlockHeight = nBestHeight; if (nBlockTime == 0) nBlockTime = GetAdjustedTime(); if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; BOOST_FOREACH(const CTxIn& txin, tx.vin) if (!txin.IsFinal()) return false; return true; } // // Check transaction inputs, and make sure any // pay-to-script-hash transactions are evaluating IsStandard scripts // // Why bother? To avoid denial-of-service attacks; an attacker // can submit a standard HASH... OP_EQUAL transaction, // which will get accepted into blocks. The redemption // script can be anything; an attacker could use a very // expensive-to-check-upon-redemption script like: // DUP CHECKSIG DROP ... repeated 100 times... OP_1 // bool AreInputsStandard(const CTransaction& tx, const MapPrevTx& mapInputs) { if (tx.IsCoinBase()) return true; // Coinbases don't use vin normally for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxOut& prev = tx.GetOutputFor(tx.vin[i], mapInputs); vector<vector<unsigned char> > vSolutions; txnouttype whichType; // get the scriptPubKey corresponding to this input: const CScript& prevScript = prev.scriptPubKey; if (!Solver(prevScript, whichType, vSolutions)) return false; int nArgsExpected = ScriptSigArgsExpected(whichType, vSolutions); if (nArgsExpected < 0) return false; // Transactions with extra stuff in their scriptSigs are // non-standard. Note that this EvalScript() call will // be quick, because if there are any operations // beside "push data" in the scriptSig the // IsStandard() call returns false vector<vector<unsigned char> > stack; if (!EvalScript(stack, tx.vin[i].scriptSig, tx, i, SCRIPT_VERIFY_NONE, 0)) return false; if (whichType == TX_SCRIPTHASH) { if (stack.empty()) return false; CScript subscript(stack.back().begin(), stack.back().end()); vector<vector<unsigned char> > vSolutions2; txnouttype whichType2; if (!Solver(subscript, whichType2, vSolutions2)) return false; if (whichType2 == TX_SCRIPTHASH) return false; int tmpExpected; tmpExpected = ScriptSigArgsExpected(whichType2, vSolutions2); if (tmpExpected < 0) return false; nArgsExpected += tmpExpected; } if (stack.size() != (unsigned int)nArgsExpected) return false; } return true; } unsigned int GetLegacySigOpCount(const CTransaction& tx) { unsigned int nSigOps = 0; BOOST_FOREACH(const CTxIn& txin, tx.vin) { nSigOps += txin.scriptSig.GetSigOpCount(false); } BOOST_FOREACH(const CTxOut& txout, tx.vout) { nSigOps += txout.scriptPubKey.GetSigOpCount(false); } return nSigOps; } unsigned int GetP2SHSigOpCount(const CTransaction& tx, const MapPrevTx& inputs) { if (tx.IsCoinBase()) return 0; unsigned int nSigOps = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxOut& prevout = tx.GetOutputFor(tx.vin[i], inputs); if (prevout.scriptPubKey.IsPayToScriptHash()) nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig); } return nSigOps; } int CMerkleTx::SetMerkleBranch(const CBlock* pblock) { AssertLockHeld(cs_main); CBlock blockTmp; if (pblock == NULL) { // Load the block this tx is in CTxIndex txindex; if (!CTxDB("r").ReadTxIndex(GetHash(), txindex)) return 0; if (!blockTmp.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos)) return 0; pblock = &blockTmp; } // Update the tx's hashBlock hashBlock = pblock->GetHash(); // Locate the transaction for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++) if (pblock->vtx[nIndex] == *(CTransaction*)this) break; if (nIndex == (int)pblock->vtx.size()) { vMerkleBranch.clear(); nIndex = -1; LogPrintf("ERROR: SetMerkleBranch() : couldn't find tx in block\n"); return 0; } // Fill in merkle branch vMerkleBranch = pblock->GetMerkleBranch(nIndex); // Is the tx in a block that's in the main chain map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) return 0; CBlockIndex* pindex = (*mi).second; if (!pindex || !pindex->IsInMainChain()) return 0; return pindexBest->nHeight - pindex->nHeight + 1; } bool CTransaction::CheckTransaction() const { // Basic checks that don't depend on any context if (vin.empty()) return DoS(10, error("CTransaction::CheckTransaction() : vin empty")); if (vout.empty()) return DoS(10, error("CTransaction::CheckTransaction() : vout empty")); // Size limits if (::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) return DoS(100, error("CTransaction::CheckTransaction() : size limits failed")); // Check for negative or overflow output values int64_t nValueOut = 0; for (unsigned int i = 0; i < vout.size(); i++) { const CTxOut& txout = vout[i]; if (txout.IsEmpty() && !IsCoinBase() && !IsCoinStake()) return DoS(100, error("CTransaction::CheckTransaction() : txout empty for user transaction")); if (txout.nValue < 0) return DoS(100, error("CTransaction::CheckTransaction() : txout.nValue negative")); if (txout.nValue > MAX_MONEY) return DoS(100, error("CTransaction::CheckTransaction() : txout.nValue too high")); nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) return DoS(100, error("CTransaction::CheckTransaction() : txout total out of range")); } // Check for duplicate inputs set<COutPoint> vInOutPoints; BOOST_FOREACH(const CTxIn& txin, vin) { if (vInOutPoints.count(txin.prevout)) return false; vInOutPoints.insert(txin.prevout); } if (IsCoinBase()) { if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100) return DoS(100, error("CTransaction::CheckTransaction() : coinbase script size is invalid")); } else { BOOST_FOREACH(const CTxIn& txin, vin) if (txin.prevout.IsNull()) return DoS(10, error("CTransaction::CheckTransaction() : prevout is null")); } return true; } int64_t GetMinFee(const CTransaction& tx, unsigned int nBlockSize, enum GetMinFee_mode mode, unsigned int nBytes) { // Base fee is either MIN_TX_FEE or MIN_RELAY_TX_FEE int64_t nBaseFee = (mode == GMF_RELAY) ? MIN_RELAY_TX_FEE : MIN_TX_FEE; unsigned int nNewBlockSize = nBlockSize + nBytes; int64_t nMinFee = (1 + (int64_t)nBytes / 1000) * nBaseFee; // Raise the price as the block approaches full if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2) { if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN) return MAX_MONEY; nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize); } if (!MoneyRange(nMinFee)) nMinFee = MAX_MONEY; return nMinFee; } bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree, bool* pfMissingInputs) { AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; if (!tx.CheckTransaction()) return error("AcceptToMemoryPool : CheckTransaction failed"); // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) return tx.DoS(100, error("AcceptToMemoryPool : coinbase as individual tx")); // ppcoin: coinstake is also only valid in a block, not as a loose transaction if (tx.IsCoinStake()) return tx.DoS(100, error("AcceptToMemoryPool : coinstake as individual tx")); // Rather not work on nonstandard transactions (unless -testnet) string reason; if (!TestNet() && !IsStandardTx(tx, reason)) return error("AcceptToMemoryPool : nonstandard transaction: %s", reason); // is it already in the memory pool? uint256 hash = tx.GetHash(); if (pool.exists(hash)) return false; // Check for conflicts with in-memory transactions { LOCK(pool.cs); // protect pool.mapNextTx for (unsigned int i = 0; i < tx.vin.size(); i++) { COutPoint outpoint = tx.vin[i].prevout; if (pool.mapNextTx.count(outpoint)) { // Disable replacement feature for now return false; } } } { CTxDB txdb("r"); // do we already have it? if (txdb.ContainsTx(hash)) return false; MapPrevTx mapInputs; map<uint256, CTxIndex> mapUnused; bool fInvalid = false; if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid)) { if (fInvalid) return error("AcceptToMemoryPool : FetchInputs found invalid tx %s", hash.ToString()); if (pfMissingInputs) *pfMissingInputs = true; return false; } // Check for non-standard pay-to-script-hash in inputs if (!TestNet() && !AreInputsStandard(tx, mapInputs)) return error("AcceptToMemoryPool : nonstandard transaction input"); // Check that the transaction doesn't have an excessive number of // sigops, making it impossible to mine. Since the coinbase transaction // itself can contain sigops MAX_TX_SIGOPS is less than // MAX_BLOCK_SIGOPS; we still consider this an invalid rather than // merely non-standard transaction. unsigned int nSigOps = GetLegacySigOpCount(tx); nSigOps += GetP2SHSigOpCount(tx, mapInputs); if (nSigOps > MAX_TX_SIGOPS) return tx.DoS(0, error("AcceptToMemoryPool : too many sigops %s, %d > %d", hash.ToString(), nSigOps, MAX_TX_SIGOPS)); int64_t nFees = tx.GetValueIn(mapInputs)-tx.GetValueOut(); unsigned int nSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); // Don't accept it if it can't get into a block int64_t txMinFee = GetMinFee(tx, 1000, GMF_RELAY, nSize); if ((fLimitFree && nFees < txMinFee) || (!fLimitFree && nFees < MIN_TX_FEE)) return error("AcceptToMemoryPool : not enough fees %s, %d < %d", hash.ToString(), nFees, txMinFee); // Continuously rate-limit free transactions // This mitigates 'penny-flooding' -- sending thousands of free transactions just to // be annoying or make others' transactions take longer to confirm. if (fLimitFree && nFees < MIN_RELAY_TX_FEE) { static CCriticalSection csFreeLimiter; static double dFreeCount; static int64_t nLastTime; int64_t nNow = GetTime(); LOCK(csFreeLimiter); // Use an exponentially decaying ~10-minute window: dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime)); nLastTime = nNow; // -limitfreerelay unit is thousand-bytes-per-minute // At default rate it would take over a month to fill 1GB if (dFreeCount > GetArg("-limitfreerelay", 15)*10*1000) return error("AcceptToMemoryPool : free transaction rejected by rate limiter"); LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize); dFreeCount += nSize; } // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. if (!tx.ConnectInputs(txdb, mapInputs, mapUnused, CDiskTxPos(1,1,1), pindexBest, false, false, STANDARD_SCRIPT_VERIFY_FLAGS)) { return error("AcceptToMemoryPool : ConnectInputs failed %s", hash.ToString()); } } // Store transaction in memory pool.addUnchecked(hash, tx); SyncWithWallets(tx, NULL); LogPrint("mempool", "AcceptToMemoryPool : accepted %s (poolsz %"PRIszu")\n", hash.ToString(), pool.mapTx.size()); return true; } int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const { if (hashBlock == 0 || nIndex == -1) return 0; AssertLockHeld(cs_main); // Find the block it claims to be in map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock); if (mi == mapBlockIndex.end()) return 0; CBlockIndex* pindex = (*mi).second; if (!pindex || !pindex->IsInMainChain()) return 0; // Make sure the merkle branch connects to this block if (!fMerkleVerified) { if (CBlock::CheckMerkleBranch(GetHash(), vMerkleBranch, nIndex) != pindex->hashMerkleRoot) return 0; fMerkleVerified = true; } pindexRet = pindex; return pindexBest->nHeight - pindex->nHeight + 1; } int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const { AssertLockHeld(cs_main); int nResult = GetDepthInMainChainINTERNAL(pindexRet); if (nResult == 0 && !mempool.exists(GetHash())) return -1; // Not in chain, not in mempool return nResult; } int CMerkleTx::GetBlocksToMaturity() const { if (!(IsCoinBase() || IsCoinStake())) return 0; return max(0, (nCoinbaseMaturity+1) - GetDepthInMainChain()); } bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree) { return ::AcceptToMemoryPool(mempool, *this, fLimitFree, NULL); } bool CWalletTx::AcceptWalletTransaction(CTxDB& txdb) { { // Add previous supporting transactions first BOOST_FOREACH(CMerkleTx& tx, vtxPrev) { if (!(tx.IsCoinBase() || tx.IsCoinStake())) { uint256 hash = tx.GetHash(); if (!mempool.exists(hash) && !txdb.ContainsTx(hash)) tx.AcceptToMemoryPool(false); } } return AcceptToMemoryPool(false); } return false; } bool CWalletTx::AcceptWalletTransaction() { CTxDB txdb("r"); return AcceptWalletTransaction(txdb); } int CTxIndex::GetDepthInMainChain() const { // Read block header CBlock block; if (!block.ReadFromDisk(pos.nFile, pos.nBlockPos, false)) return 0; // Find the block in the index map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(block.GetHash()); if (mi == mapBlockIndex.end()) return 0; CBlockIndex* pindex = (*mi).second; if (!pindex || !pindex->IsInMainChain()) return 0; return 1 + nBestHeight - pindex->nHeight; } // Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock) { { LOCK(cs_main); { if (mempool.lookup(hash, tx)) { return true; } } CTxDB txdb("r"); CTxIndex txindex; if (tx.ReadFromDisk(txdb, COutPoint(hash, 0), txindex)) { CBlock block; if (block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) hashBlock = block.GetHash(); return true; } } return false; } ////////////////////////////////////////////////////////////////////////////// // // CBlock and CBlockIndex // static CBlockIndex* pblockindexFBBHLast; CBlockIndex* FindBlockByHeight(int nHeight) { CBlockIndex *pblockindex; if (nHeight < nBestHeight / 2) pblockindex = pindexGenesisBlock; else pblockindex = pindexBest; if (pblockindexFBBHLast && abs(nHeight - pblockindex->nHeight) > abs(nHeight - pblockindexFBBHLast->nHeight)) pblockindex = pblockindexFBBHLast; while (pblockindex->nHeight > nHeight) pblockindex = pblockindex->pprev; while (pblockindex->nHeight < nHeight) pblockindex = pblockindex->pnext; pblockindexFBBHLast = pblockindex; return pblockindex; } bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions) { if (!fReadTransactions) { *this = pindex->GetBlockHeader(); return true; } if (!ReadFromDisk(pindex->nFile, pindex->nBlockPos, fReadTransactions)) return false; if (GetHash() != pindex->GetBlockHash()) return error("CBlock::ReadFromDisk() : GetHash() doesn't match index"); return true; } uint256 static GetOrphanRoot(const uint256& hash) { map<uint256, COrphanBlock*>::iterator it = mapOrphanBlocks.find(hash); if (it == mapOrphanBlocks.end()) return hash; // Work back to the first block in the orphan chain do { map<uint256, COrphanBlock*>::iterator it2 = mapOrphanBlocks.find(it->second->hashPrev); if (it2 == mapOrphanBlocks.end()) return it->first; it = it2; } while(true); } // ppcoin: find block wanted by given orphan block uint256 WantedByOrphan(const COrphanBlock* pblockOrphan) { // Work back to the first block in the orphan chain while (mapOrphanBlocks.count(pblockOrphan->hashPrev)) pblockOrphan = mapOrphanBlocks[pblockOrphan->hashPrev]; return pblockOrphan->hashPrev; } // Remove a random orphan block (which does not have any dependent orphans). void static PruneOrphanBlocks() { if (mapOrphanBlocksByPrev.size() <= (size_t)std::max((int64_t)0, GetArg("-maxorphanblocks", DEFAULT_MAX_ORPHAN_BLOCKS))) return; // Pick a random orphan block. int pos = insecure_rand() % mapOrphanBlocksByPrev.size(); std::multimap<uint256, COrphanBlock*>::iterator it = mapOrphanBlocksByPrev.begin(); while (pos--) it++; // As long as this block has other orphans depending on it, move to one of those successors. do { std::multimap<uint256, COrphanBlock*>::iterator it2 = mapOrphanBlocksByPrev.find(it->second->hashBlock); if (it2 == mapOrphanBlocksByPrev.end()) break; it = it2; } while(1); setStakeSeenOrphan.erase(it->second->stake); uint256 hash = it->second->hashBlock; delete it->second; mapOrphanBlocksByPrev.erase(it); mapOrphanBlocks.erase(hash); } static CBigNum GetProofOfStakeLimit(int nHeight) { if (IsProtocolV2(nHeight)) return bnProofOfStakeLimitV2; else return bnProofOfStakeLimit; } // miner's coin base reward int64_t GetProofOfWorkReward(int64_t nFees) { int64_t nSubsidy = POW_BLOCK_REWARD * COIN; LogPrint("creation", "GetProofOfWorkReward() : create=%s nSubsidy=%d\n", FormatMoney(nSubsidy), nSubsidy); return nSubsidy + nFees; } // miner's coin stake reward based on coin age spent (coin-days) int64_t GetProofOfStakeReward(int64_t nCoinAge, int64_t nFees) { int64_t nSubsidy = nCoinAge * COIN_YEAR_REWARD * 33 / (365 * 33 + 8); LogPrint("creation", "GetProofOfStakeReward(): create=%s nCoinAge=%d\n", FormatMoney(nSubsidy), nCoinAge); return nSubsidy + nFees; } static const int64_t nTargetTimespan = 16 * 60; // 16 mins // // maximum nBits value could possible be required nTime after // unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64_t nTime) { CBigNum bnResult; bnResult.SetCompact(nBase); bnResult *= 2; while (nTime > 0 && bnResult < bnTargetLimit) { // Maximum 200% adjustment per day... bnResult *= 2; nTime -= 24 * 60 * 60; } if (bnResult > bnTargetLimit) bnResult = bnTargetLimit; return bnResult.GetCompact(); } // // minimum amount of work that could possibly be required nTime after // minimum proof-of-work required was nBase // unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime) { return ComputeMaxBits(Params().ProofOfWorkLimit(), nBase, nTime); } // // minimum amount of stake that could possibly be required nTime after // minimum proof-of-stake required was nBase // unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime) { return ComputeMaxBits(bnProofOfStakeLimit, nBase, nTime); } // ppcoin: find last block index up to pindex const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake) { while (pindex && pindex->pprev && (pindex->IsProofOfStake() != fProofOfStake)) pindex = pindex->pprev; return pindex; } unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake) { CBigNum bnTargetLimit = fProofOfStake ? GetProofOfStakeLimit(pindexLast->nHeight) : Params().ProofOfWorkLimit(); if (pindexLast == NULL) return bnTargetLimit.GetCompact(); // genesis block const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake); if (pindexPrev->pprev == NULL) return bnTargetLimit.GetCompact(); // first block const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake); if (pindexPrevPrev->pprev == NULL) return bnTargetLimit.GetCompact(); // second block int64_t nTargetSpacing = GetTargetSpacing(pindexLast->nHeight); int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime(); if (IsProtocolV1RetargetingFixed(pindexLast->nHeight)) { if (nActualSpacing < 0) nActualSpacing = nTargetSpacing; } // ppcoin: target change every block // ppcoin: retarget with exponential moving toward target spacing CBigNum bnNew; bnNew.SetCompact(pindexPrev->nBits); int64_t nInterval = nTargetTimespan / nTargetSpacing; bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing); bnNew /= ((nInterval + 1) * nTargetSpacing); if (bnNew <= 0 || bnNew > bnTargetLimit) bnNew = bnTargetLimit; return bnNew.GetCompact(); } bool CheckProofOfWork(uint256 hash, unsigned int nBits) { CBigNum bnTarget; bnTarget.SetCompact(nBits); // Check range if (bnTarget <= 0 || bnTarget > Params().ProofOfWorkLimit()) return error("CheckProofOfWork() : nBits below minimum work"); // Check proof of work matches claimed amount if (hash > bnTarget.getuint256()) return error("CheckProofOfWork() : hash doesn't match nBits"); return true; } bool IsInitialBlockDownload() { LOCK(cs_main); if (pindexBest == NULL || nBestHeight < Checkpoints::GetTotalBlocksEstimate()) return true; static int64_t nLastUpdate; static CBlockIndex* pindexLastBest; if (pindexBest != pindexLastBest) { pindexLastBest = pindexBest; nLastUpdate = GetTime(); } return (GetTime() - nLastUpdate < 15 && pindexBest->GetBlockTime() < GetTime() - 8 * 60 * 60); } void static InvalidChainFound(CBlockIndex* pindexNew) { if (pindexNew->nChainTrust > nBestInvalidTrust) { nBestInvalidTrust = pindexNew->nChainTrust; CTxDB().WriteBestInvalidTrust(CBigNum(nBestInvalidTrust)); } uint256 nBestInvalidBlockTrust = pindexNew->nChainTrust - pindexNew->pprev->nChainTrust; uint256 nBestBlockTrust = pindexBest->nHeight != 0 ? (pindexBest->nChainTrust - pindexBest->pprev->nChainTrust) : pindexBest->nChainTrust; LogPrintf("InvalidChainFound: invalid block=%s height=%d trust=%s blocktrust=%d date=%s\n", pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, CBigNum(pindexNew->nChainTrust).ToString(), nBestInvalidBlockTrust.Get64(), DateTimeStrFormat("%x %H:%M:%S", pindexNew->GetBlockTime())); LogPrintf("InvalidChainFound: current best=%s height=%d trust=%s blocktrust=%d date=%s\n", hashBestChain.ToString(), nBestHeight, CBigNum(pindexBest->nChainTrust).ToString(), nBestBlockTrust.Get64(), DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime())); } void CBlock::UpdateTime(const CBlockIndex* pindexPrev) { nTime = max(GetBlockTime(), GetAdjustedTime()); } bool CTransaction::DisconnectInputs(CTxDB& txdb) { // Relinquish previous transactions' spent pointers if (!IsCoinBase()) { BOOST_FOREACH(const CTxIn& txin, vin) { COutPoint prevout = txin.prevout; // Get prev txindex from disk CTxIndex txindex; if (!txdb.ReadTxIndex(prevout.hash, txindex)) return error("DisconnectInputs() : ReadTxIndex failed"); if (prevout.n >= txindex.vSpent.size()) return error("DisconnectInputs() : prevout.n out of range"); // Mark outpoint as not spent txindex.vSpent[prevout.n].SetNull(); // Write back if (!txdb.UpdateTxIndex(prevout.hash, txindex)) return error("DisconnectInputs() : UpdateTxIndex failed"); } } // Remove transaction from index // This can fail if a duplicate of this transaction was in a chain that got // reorganized away. This is only possible if this transaction was completely // spent, so erasing it would be a no-op anyway. txdb.EraseTxIndex(*this); return true; } bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTestPool, bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid) { // FetchInputs can return false either because we just haven't seen some inputs // (in which case the transaction should be stored as an orphan) // or because the transaction is malformed (in which case the transaction should // be dropped). If tx is definitely invalid, fInvalid will be set to true. fInvalid = false; if (IsCoinBase()) return true; // Coinbase transactions have no inputs to fetch. for (unsigned int i = 0; i < vin.size(); i++) { COutPoint prevout = vin[i].prevout; if (inputsRet.count(prevout.hash)) continue; // Got it already // Read txindex CTxIndex& txindex = inputsRet[prevout.hash].first; bool fFound = true; if ((fBlock || fMiner) && mapTestPool.count(prevout.hash)) { // Get txindex from current proposed changes txindex = mapTestPool.find(prevout.hash)->second; } else { // Read txindex from txdb fFound = txdb.ReadTxIndex(prevout.hash, txindex); } if (!fFound && (fBlock || fMiner)) return fMiner ? false : error("FetchInputs() : %s prev tx %s index entry not found", GetHash().ToString(), prevout.hash.ToString()); // Read txPrev CTransaction& txPrev = inputsRet[prevout.hash].second; if (!fFound || txindex.pos == CDiskTxPos(1,1,1)) { // Get prev tx from single transactions in memory if (!mempool.lookup(prevout.hash, txPrev)) return error("FetchInputs() : %s mempool Tx prev not found %s", GetHash().ToString(), prevout.hash.ToString()); if (!fFound) txindex.vSpent.resize(txPrev.vout.size()); } else { // Get prev tx from disk if (!txPrev.ReadFromDisk(txindex.pos)) return error("FetchInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString(), prevout.hash.ToString()); } } // Make sure all prevout.n indexes are valid: for (unsigned int i = 0; i < vin.size(); i++) { const COutPoint prevout = vin[i].prevout; assert(inputsRet.count(prevout.hash) != 0); const CTxIndex& txindex = inputsRet[prevout.hash].first; const CTransaction& txPrev = inputsRet[prevout.hash].second; if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) { // Revisit this if/when transaction replacement is implemented and allows // adding inputs: fInvalid = true; return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString(), txPrev.ToString())); } } return true; } const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const { MapPrevTx::const_iterator mi = inputs.find(input.prevout.hash); if (mi == inputs.end()) throw std::runtime_error("CTransaction::GetOutputFor() : prevout.hash not found"); const CTransaction& txPrev = (mi->second).second; if (input.prevout.n >= txPrev.vout.size()) throw std::runtime_error("CTransaction::GetOutputFor() : prevout.n out of range"); return txPrev.vout[input.prevout.n]; } int64_t CTransaction::GetValueIn(const MapPrevTx& inputs) const { if (IsCoinBase()) return 0; int64_t nResult = 0; for (unsigned int i = 0; i < vin.size(); i++) { nResult += GetOutputFor(vin[i], inputs).nValue; } return nResult; } bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map<uint256, CTxIndex>& mapTestPool, const CDiskTxPos& posThisTx, const CBlockIndex* pindexBlock, bool fBlock, bool fMiner, unsigned int flags) { // Take over previous transactions' spent pointers // fBlock is true when this is called from AcceptBlock when a new best-block is added to the blockchain // fMiner is true when called from the internal bitcoin miner // ... both are false when called from CTransaction::AcceptToMemoryPool if (!IsCoinBase()) { int64_t nValueIn = 0; int64_t nFees = 0; for (unsigned int i = 0; i < vin.size(); i++) { COutPoint prevout = vin[i].prevout; assert(inputs.count(prevout.hash) > 0); CTxIndex& txindex = inputs[prevout.hash].first; CTransaction& txPrev = inputs[prevout.hash].second; if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size()) return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %"PRIszu" %"PRIszu" prev tx %s\n%s", GetHash().ToString(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString(), txPrev.ToString())); // If prev is coinbase or coinstake, check that it's matured if (txPrev.IsCoinBase() || txPrev.IsCoinStake()) for (const CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < nCoinbaseMaturity; pindex = pindex->pprev) if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile) return error("ConnectInputs() : tried to spend %s at depth %d", txPrev.IsCoinBase() ? "coinbase" : "coinstake", pindexBlock->nHeight - pindex->nHeight); // ppcoin: check transaction timestamp if (txPrev.nTime > nTime) return DoS(100, error("ConnectInputs() : transaction timestamp earlier than input transaction")); // Check for negative or overflow input values nValueIn += txPrev.vout[prevout.n].nValue; if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn)) return DoS(100, error("ConnectInputs() : txin values out of range")); } // The first loop above does all the inexpensive checks. // Only if ALL inputs pass do we perform expensive ECDSA signature checks. // Helps prevent CPU exhaustion attacks. for (unsigned int i = 0; i < vin.size(); i++) { COutPoint prevout = vin[i].prevout; assert(inputs.count(prevout.hash) > 0); CTxIndex& txindex = inputs[prevout.hash].first; CTransaction& txPrev = inputs[prevout.hash].second; // Check for conflicts (double-spend) // This doesn't trigger the DoS code on purpose; if it did, it would make it easier // for an attacker to attempt to split the network. if (!txindex.vSpent[prevout.n].IsNull()) return fMiner ? false : error("ConnectInputs() : %s prev tx already used at %s", GetHash().ToString(), txindex.vSpent[prevout.n].ToString()); // Skip ECDSA signature verification when connecting blocks (fBlock=true) // before the last blockchain checkpoint. This is safe because block merkle hashes are // still computed and checked, and any change will be caught at the next checkpoint. if (!(fBlock && (nBestHeight < Checkpoints::GetTotalBlocksEstimate()))) { // Verify signature if (!VerifySignature(txPrev, *this, i, flags, 0)) { if (flags & STANDARD_NOT_MANDATORY_VERIFY_FLAGS) { // Check whether the failure was caused by a // non-mandatory script verification check, such as // non-null dummy arguments; // if so, don't trigger DoS protection to // avoid splitting the network between upgraded and // non-upgraded nodes. if (VerifySignature(txPrev, *this, i, flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, 0)) return error("ConnectInputs() : %s non-mandatory VerifySignature failed", GetHash().ToString()); } // Failures of other flags indicate a transaction that is // invalid in new blocks, e.g. a invalid P2SH. We DoS ban // such nodes as they are not following the protocol. That // said during an upgrade careful thought should be taken // as to the correct behavior - we may want to continue // peering with non-upgraded nodes even after a soft-fork // super-majority vote has passed. return DoS(100,error("ConnectInputs() : %s VerifySignature failed", GetHash().ToString())); } } // Mark outpoints as spent txindex.vSpent[prevout.n] = posThisTx; // Write back if (fBlock || fMiner) { mapTestPool[prevout.hash] = txindex; } } if (!IsCoinStake()) { if (nValueIn < GetValueOut()) return DoS(100, error("ConnectInputs() : %s value in < value out", GetHash().ToString())); // Tally transaction fees int64_t nTxFee = nValueIn - GetValueOut(); if (nTxFee < 0) return DoS(100, error("ConnectInputs() : %s nTxFee < 0", GetHash().ToString())); // enforce transaction fees for every block int64_t nRequiredFee = GetMinFee(*this); if (nTxFee < nRequiredFee) return fBlock? DoS(100, error("ConnectInputs() : %s not paying required fee=%s, paid=%s", GetHash().ToString(), FormatMoney(nRequiredFee), FormatMoney(nTxFee))) : false; nFees += nTxFee; if (!MoneyRange(nFees)) return DoS(100, error("ConnectInputs() : nFees out of range")); } } return true; } bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex) { // Disconnect in reverse order for (int i = vtx.size()-1; i >= 0; i--) if (!vtx[i].DisconnectInputs(txdb)) return false; // Update block index on disk without changing it in memory. // The memory index structure will be changed after the db commits. if (pindex->pprev) { CDiskBlockIndex blockindexPrev(pindex->pprev); blockindexPrev.hashNext = 0; if (!txdb.WriteBlockIndex(blockindexPrev)) return error("DisconnectBlock() : WriteBlockIndex failed"); } // ppcoin: clean up wallet after disconnecting coinstake BOOST_FOREACH(CTransaction& tx, vtx) SyncWithWallets(tx, this, false); return true; } bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck) { // Check it again in case a previous version let a bad block in, but skip BlockSig checking if (!CheckBlock(!fJustCheck, !fJustCheck, false)) return false; unsigned int flags = SCRIPT_VERIFY_NOCACHE; //// issue here: it doesn't know the version unsigned int nTxPos; if (fJustCheck) // FetchInputs treats CDiskTxPos(1,1,1) as a special "refer to memorypool" indicator // Since we're just checking the block and not actually connecting it, it might not (and probably shouldn't) be on the disk to get the transaction from nTxPos = 1; else nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK, CLIENT_VERSION) - (2 * GetSizeOfCompactSize(0)) + GetSizeOfCompactSize(vtx.size()); map<uint256, CTxIndex> mapQueuedChanges; int64_t nFees = 0; int64_t nValueIn = 0; int64_t nValueOut = 0; int64_t nStakeReward = 0; unsigned int nSigOps = 0; BOOST_FOREACH(CTransaction& tx, vtx) { uint256 hashTx = tx.GetHash(); // Do not allow blocks that contain transactions which 'overwrite' older transactions, // unless those are already completely spent. // If such overwrites are allowed, coinbases and transactions depending upon those // can be duplicated to remove the ability to spend the first instance -- even after // being sent to another address. // See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information. // This logic is not necessary for memory pool transactions, as AcceptToMemoryPool // already refuses previously-known transaction ids entirely. // This rule was originally applied all blocks whose timestamp was after March 15, 2012, 0:00 UTC. // Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the // two in the chain that violate it. This prevents exploiting the issue against nodes in their // initial block download. CTxIndex txindexOld; if (txdb.ReadTxIndex(hashTx, txindexOld)) { BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent) if (pos.IsNull()) return DoS(100, error("ConnectBlock() : tried to overwrite transaction")); } nSigOps += GetLegacySigOpCount(tx); if (nSigOps > MAX_BLOCK_SIGOPS) return DoS(100, error("ConnectBlock() : too many sigops")); CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos); if (!fJustCheck) nTxPos += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); MapPrevTx mapInputs; if (tx.IsCoinBase()) nValueOut += tx.GetValueOut(); else { bool fInvalid; if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs, fInvalid)) return false; // Add in sigops done by pay-to-script-hash inputs; // this is to prevent a "rogue miner" from creating // an incredibly-expensive-to-validate block. nSigOps += GetP2SHSigOpCount(tx, mapInputs); if (nSigOps > MAX_BLOCK_SIGOPS) return DoS(100, error("ConnectBlock() : too many sigops")); int64_t nTxValueIn = tx.GetValueIn(mapInputs); int64_t nTxValueOut = tx.GetValueOut(); nValueIn += nTxValueIn; nValueOut += nTxValueOut; if (!tx.IsCoinStake()) nFees += nTxValueIn - nTxValueOut; if (tx.IsCoinStake()) nStakeReward = nTxValueOut - nTxValueIn; if (!tx.ConnectInputs(txdb, mapInputs, mapQueuedChanges, posThisTx, pindex, true, false, flags)) return false; } mapQueuedChanges[hashTx] = CTxIndex(posThisTx, tx.vout.size()); } if (IsProofOfWork()) { int64_t nReward = GetProofOfWorkReward(nFees); // Check coinbase reward if (vtx[0].GetValueOut() > nReward) return DoS(50, error("ConnectBlock() : coinbase reward exceeded (actual=%d vs calculated=%d)", vtx[0].GetValueOut(), nReward)); } if (IsProofOfStake()) { // ppcoin: coin stake tx earns reward instead of paying fee uint64_t nCoinAge; if (!vtx[1].GetCoinAge(txdb, nCoinAge)) return error("ConnectBlock() : %s unable to get coin age for coinstake", vtx[1].GetHash().ToString()); int64_t nCalculatedStakeReward = GetProofOfStakeReward(nCoinAge, nFees); if (nStakeReward > nCalculatedStakeReward) return DoS(100, error("ConnectBlock() : coinstake pays too much(actual=%d vs calculated=%d)", nStakeReward, nCalculatedStakeReward)); } // ppcoin: track money supply and mint amount info pindex->nMint = nValueOut - nValueIn + nFees; pindex->nMoneySupply = (pindex->pprev? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn; if (!txdb.WriteBlockIndex(CDiskBlockIndex(pindex))) return error("Connect() : WriteBlockIndex for pindex failed"); if (fJustCheck) return true; // Write queued txindex changes for (map<uint256, CTxIndex>::iterator mi = mapQueuedChanges.begin(); mi != mapQueuedChanges.end(); ++mi) { if (!txdb.UpdateTxIndex((*mi).first, (*mi).second)) return error("ConnectBlock() : UpdateTxIndex failed"); } // Update block index on disk without changing it in memory. // The memory index structure will be changed after the db commits. if (pindex->pprev) { CDiskBlockIndex blockindexPrev(pindex->pprev); blockindexPrev.hashNext = pindex->GetBlockHash(); if (!txdb.WriteBlockIndex(blockindexPrev)) return error("ConnectBlock() : WriteBlockIndex failed"); } // Watch for transactions paying to me BOOST_FOREACH(CTransaction& tx, vtx) SyncWithWallets(tx, this); return true; } bool static Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) { LogPrintf("REORGANIZE\n"); // Find the fork CBlockIndex* pfork = pindexBest; CBlockIndex* plonger = pindexNew; while (pfork != plonger) { while (plonger->nHeight > pfork->nHeight) if (!(plonger = plonger->pprev)) return error("Reorganize() : plonger->pprev is null"); if (pfork == plonger) break; if (!(pfork = pfork->pprev)) return error("Reorganize() : pfork->pprev is null"); } // List of what to disconnect vector<CBlockIndex*> vDisconnect; for (CBlockIndex* pindex = pindexBest; pindex != pfork; pindex = pindex->pprev) vDisconnect.push_back(pindex); // List of what to connect vector<CBlockIndex*> vConnect; for (CBlockIndex* pindex = pindexNew; pindex != pfork; pindex = pindex->pprev) vConnect.push_back(pindex); reverse(vConnect.begin(), vConnect.end()); LogPrintf("REORGANIZE: Disconnect %"PRIszu" blocks; %s..%s\n", vDisconnect.size(), pfork->GetBlockHash().ToString(), pindexBest->GetBlockHash().ToString()); LogPrintf("REORGANIZE: Connect %"PRIszu" blocks; %s..%s\n", vConnect.size(), pfork->GetBlockHash().ToString(), pindexNew->GetBlockHash().ToString()); // Disconnect shorter branch list<CTransaction> vResurrect; BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) { CBlock block; if (!block.ReadFromDisk(pindex)) return error("Reorganize() : ReadFromDisk for disconnect failed"); if (!block.DisconnectBlock(txdb, pindex)) return error("Reorganize() : DisconnectBlock %s failed", pindex->GetBlockHash().ToString()); // Queue memory transactions to resurrect. // We only do this for blocks after the last checkpoint (reorganisation before that // point should only happen with -reindex/-loadblock, or a misbehaving peer. BOOST_REVERSE_FOREACH(const CTransaction& tx, block.vtx) if (!(tx.IsCoinBase() || tx.IsCoinStake()) && pindex->nHeight > Checkpoints::GetTotalBlocksEstimate()) vResurrect.push_front(tx); } // Connect longer branch vector<CTransaction> vDelete; for (unsigned int i = 0; i < vConnect.size(); i++) { CBlockIndex* pindex = vConnect[i]; CBlock block; if (!block.ReadFromDisk(pindex)) return error("Reorganize() : ReadFromDisk for connect failed"); if (!block.ConnectBlock(txdb, pindex)) { // Invalid block return error("Reorganize() : ConnectBlock %s failed", pindex->GetBlockHash().ToString()); } // Queue memory transactions to delete BOOST_FOREACH(const CTransaction& tx, block.vtx) vDelete.push_back(tx); } if (!txdb.WriteHashBestChain(pindexNew->GetBlockHash())) return error("Reorganize() : WriteHashBestChain failed"); // Make sure it's successfully written to disk before changing memory structure if (!txdb.TxnCommit()) return error("Reorganize() : TxnCommit failed"); // Disconnect shorter branch BOOST_FOREACH(CBlockIndex* pindex, vDisconnect) if (pindex->pprev) pindex->pprev->pnext = NULL; // Connect longer branch BOOST_FOREACH(CBlockIndex* pindex, vConnect) if (pindex->pprev) pindex->pprev->pnext = pindex; // Resurrect memory transactions that were in the disconnected branch BOOST_FOREACH(CTransaction& tx, vResurrect) AcceptToMemoryPool(mempool, tx, false, NULL); // Delete redundant memory transactions that are in the connected branch BOOST_FOREACH(CTransaction& tx, vDelete) { mempool.remove(tx); mempool.removeConflicts(tx); } LogPrintf("REORGANIZE: done\n"); return true; } // Called from inside SetBestChain: attaches a block to the new best chain being built bool CBlock::SetBestChainInner(CTxDB& txdb, CBlockIndex *pindexNew) { uint256 hash = GetHash(); // Adding to current best branch if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash)) { txdb.TxnAbort(); InvalidChainFound(pindexNew); return false; } if (!txdb.TxnCommit()) return error("SetBestChain() : TxnCommit failed"); // Add to current best branch pindexNew->pprev->pnext = pindexNew; // Delete redundant memory transactions BOOST_FOREACH(CTransaction& tx, vtx) mempool.remove(tx); return true; } bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew) { uint256 hash = GetHash(); if (!txdb.TxnBegin()) return error("SetBestChain() : TxnBegin failed"); if (pindexGenesisBlock == NULL && hash == Params().HashGenesisBlock()) { txdb.WriteHashBestChain(hash); if (!txdb.TxnCommit()) return error("SetBestChain() : TxnCommit failed"); pindexGenesisBlock = pindexNew; } else if (hashPrevBlock == hashBestChain) { if (!SetBestChainInner(txdb, pindexNew)) return error("SetBestChain() : SetBestChainInner failed"); } else { // the first block in the new chain that will cause it to become the new best chain CBlockIndex *pindexIntermediate = pindexNew; // list of blocks that need to be connected afterwards std::vector<CBlockIndex*> vpindexSecondary; // Reorganize is costly in terms of db load, as it works in a single db transaction. // Try to limit how much needs to be done inside while (pindexIntermediate->pprev && pindexIntermediate->pprev->nChainTrust > pindexBest->nChainTrust) { vpindexSecondary.push_back(pindexIntermediate); pindexIntermediate = pindexIntermediate->pprev; } if (!vpindexSecondary.empty()) LogPrintf("Postponing %"PRIszu" reconnects\n", vpindexSecondary.size()); // Switch to new best branch if (!Reorganize(txdb, pindexIntermediate)) { txdb.TxnAbort(); InvalidChainFound(pindexNew); return error("SetBestChain() : Reorganize failed"); } // Connect further blocks BOOST_REVERSE_FOREACH(CBlockIndex *pindex, vpindexSecondary) { CBlock block; if (!block.ReadFromDisk(pindex)) { LogPrintf("SetBestChain() : ReadFromDisk failed\n"); break; } if (!txdb.TxnBegin()) { LogPrintf("SetBestChain() : TxnBegin 2 failed\n"); break; } // errors now are not fatal, we still did a reorganisation to a new chain in a valid way if (!block.SetBestChainInner(txdb, pindex)) break; } } // Update best block in wallet (so we can detect restored wallets) bool fIsInitialDownload = IsInitialBlockDownload(); if ((pindexNew->nHeight % 20160) == 0 || (!fIsInitialDownload && (pindexNew->nHeight % 144) == 0)) { const CBlockLocator locator(pindexNew); g_signals.SetBestChain(locator); } // New best block hashBestChain = hash; pindexBest = pindexNew; pblockindexFBBHLast = NULL; nBestHeight = pindexBest->nHeight; nBestChainTrust = pindexNew->nChainTrust; nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); uint256 nBestBlockTrust = pindexBest->nHeight != 0 ? (pindexBest->nChainTrust - pindexBest->pprev->nChainTrust) : pindexBest->nChainTrust; LogPrintf("SetBestChain: new best=%s height=%d trust=%s blocktrust=%d date=%s\n", hashBestChain.ToString(), nBestHeight, CBigNum(nBestChainTrust).ToString(), nBestBlockTrust.Get64(), DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime())); // Check the version of the last 100 blocks to see if we need to upgrade: if (!fIsInitialDownload) { int nUpgraded = 0; const CBlockIndex* pindex = pindexBest; for (int i = 0; i < 100 && pindex != NULL; i++) { if (pindex->nVersion > CBlock::CURRENT_VERSION) ++nUpgraded; pindex = pindex->pprev; } if (nUpgraded > 0) LogPrintf("SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, (int)CBlock::CURRENT_VERSION); if (nUpgraded > 100/2) // strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user: strMiscWarning = _("Warning: This version is obsolete, upgrade required!"); } std::string strCmd = GetArg("-blocknotify", ""); if (!fIsInitialDownload && !strCmd.empty()) { boost::replace_all(strCmd, "%s", hashBestChain.GetHex()); boost::thread t(runCommand, strCmd); // thread runs free } return true; } // ppcoin: total coin age spent in transaction, in the unit of coin-days. // Only those coins meeting minimum age requirement counts. As those // transactions not in main chain are not currently indexed so we // might not find out about their coin age. Older transactions are // guaranteed to be in main chain by sync-checkpoint. This rule is // introduced to help nodes establish a consistent view of the coin // age (trust score) of competing branches. bool CTransaction::GetCoinAge(CTxDB& txdb, uint64_t& nCoinAge) const { CBigNum bnCentSecond = 0; // coin age in the unit of cent-seconds nCoinAge = 0; if (IsCoinBase()) return true; BOOST_FOREACH(const CTxIn& txin, vin) { // First try finding the previous transaction in database CTransaction txPrev; CTxIndex txindex; if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) continue; // previous transaction not in main chain if (nTime < txPrev.nTime) return false; // Transaction timestamp violation // Read block header CBlock block; if (!block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) return false; // unable to read block of previous transaction if (block.GetBlockTime() + nStakeMinAge > nTime) continue; // only count coins meeting min age requirement int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue; bnCentSecond += CBigNum(nValueIn) * (nTime-txPrev.nTime) / CENT; LogPrint("coinage", "coin age nValueIn=%d nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString()); } CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); LogPrint("coinage", "coin age bnCoinDay=%s\n", bnCoinDay.ToString()); nCoinAge = bnCoinDay.getuint64(); return true; } bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos, const uint256& hashProof) { AssertLockHeld(cs_main); // Check for duplicate uint256 hash = GetHash(); if (mapBlockIndex.count(hash)) return error("AddToBlockIndex() : %s already exists", hash.ToString()); // Construct new block index object CBlockIndex* pindexNew = new CBlockIndex(nFile, nBlockPos, *this); if (!pindexNew) return error("AddToBlockIndex() : new CBlockIndex failed"); pindexNew->phashBlock = &hash; map<uint256, CBlockIndex*>::iterator miPrev = mapBlockIndex.find(hashPrevBlock); if (miPrev != mapBlockIndex.end()) { pindexNew->pprev = (*miPrev).second; pindexNew->nHeight = pindexNew->pprev->nHeight + 1; } // ppcoin: compute chain trust score pindexNew->nChainTrust = (pindexNew->pprev ? pindexNew->pprev->nChainTrust : 0) + pindexNew->GetBlockTrust(); // ppcoin: compute stake entropy bit for stake modifier if (!pindexNew->SetStakeEntropyBit(GetStakeEntropyBit())) return error("AddToBlockIndex() : SetStakeEntropyBit() failed"); // Record proof hash value pindexNew->hashProof = hashProof; // ppcoin: compute stake modifier uint64_t nStakeModifier = 0; bool fGeneratedStakeModifier = false; if (!ComputeNextStakeModifier(pindexNew->pprev, nStakeModifier, fGeneratedStakeModifier)) return error("AddToBlockIndex() : ComputeNextStakeModifier() failed"); pindexNew->SetStakeModifier(nStakeModifier, fGeneratedStakeModifier); // Add to mapBlockIndex map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; if (pindexNew->IsProofOfStake()) setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime)); pindexNew->phashBlock = &((*mi).first); // Write to disk block index CTxDB txdb; if (!txdb.TxnBegin()) return false; txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew)); if (!txdb.TxnCommit()) return false; // New best if (pindexNew->nChainTrust > nBestChainTrust) if (!SetBestChain(txdb, pindexNew)) return false; if (pindexNew == pindexBest) { // Notify UI to display prev block's coinbase if it was ours static uint256 hashPrevBestCoinBase; g_signals.UpdatedTransaction(hashPrevBestCoinBase); hashPrevBestCoinBase = vtx[0].GetHash(); } return true; } bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) const { // These are checks that are independent of context // that can be verified before saving an orphan block. // Size limits if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) return DoS(100, error("CheckBlock() : size limits failed")); // Check proof of work matches claimed amount if (fCheckPOW && IsProofOfWork() && !CheckProofOfWork(GetPoWHash(), nBits)) return DoS(50, error("CheckBlock() : proof of work failed")); // Check timestamp if (GetBlockTime() > FutureDriftV2(GetAdjustedTime())) return error("CheckBlock() : block timestamp too far in the future"); // First transaction must be coinbase, the rest must not be if (vtx.empty() || !vtx[0].IsCoinBase()) return DoS(100, error("CheckBlock() : first tx is not coinbase")); for (unsigned int i = 1; i < vtx.size(); i++) if (vtx[i].IsCoinBase()) return DoS(100, error("CheckBlock() : more than one coinbase")); if (IsProofOfStake()) { // Coinbase output should be empty if proof-of-stake block if (vtx[0].vout.size() != 1 || !vtx[0].vout[0].IsEmpty()) return DoS(100, error("CheckBlock() : coinbase output not empty for proof-of-stake block")); // Second transaction must be coinstake, the rest must not be if (vtx.empty() || !vtx[1].IsCoinStake()) return DoS(100, error("CheckBlock() : second tx is not coinstake")); for (unsigned int i = 2; i < vtx.size(); i++) if (vtx[i].IsCoinStake()) return DoS(100, error("CheckBlock() : more than one coinstake")); } // Check proof-of-stake block signature if (fCheckSig && !CheckBlockSignature()) return DoS(100, error("CheckBlock() : bad proof-of-stake block signature")); // Check transactions BOOST_FOREACH(const CTransaction& tx, vtx) { if (!tx.CheckTransaction()) return DoS(tx.nDoS, error("CheckBlock() : CheckTransaction failed")); // ppcoin: check transaction timestamp if (GetBlockTime() < (int64_t)tx.nTime) return DoS(50, error("CheckBlock() : block timestamp earlier than transaction timestamp")); } // Check for duplicate txids. This is caught by ConnectInputs(), // but catching it earlier avoids a potential DoS attack: set<uint256> uniqueTx; BOOST_FOREACH(const CTransaction& tx, vtx) { uniqueTx.insert(tx.GetHash()); } if (uniqueTx.size() != vtx.size()) return DoS(100, error("CheckBlock() : duplicate transaction")); unsigned int nSigOps = 0; BOOST_FOREACH(const CTransaction& tx, vtx) { nSigOps += GetLegacySigOpCount(tx); } if (nSigOps > MAX_BLOCK_SIGOPS) return DoS(100, error("CheckBlock() : out-of-bounds SigOpCount")); // Check merkle root if (fCheckMerkleRoot && hashMerkleRoot != BuildMerkleTree()) return DoS(100, error("CheckBlock() : hashMerkleRoot mismatch")); return true; } bool CBlock::AcceptBlock() { AssertLockHeld(cs_main); if (nVersion > CURRENT_VERSION) return DoS(100, error("AcceptBlock() : reject unknown block version %d", nVersion)); // Check for duplicate uint256 hash = GetHash(); if (mapBlockIndex.count(hash)) return error("AcceptBlock() : block already in mapBlockIndex"); // Get prev block index map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashPrevBlock); if (mi == mapBlockIndex.end()) return DoS(10, error("AcceptBlock() : prev block not found")); CBlockIndex* pindexPrev = (*mi).second; int nHeight = pindexPrev->nHeight+1; if (IsProtocolV2(nHeight) && nVersion < 7) return DoS(100, error("AcceptBlock() : reject too old nVersion = %d", nVersion)); else if (!IsProtocolV2(nHeight) && nVersion > 6) return DoS(100, error("AcceptBlock() : reject too new nVersion = %d", nVersion)); if (IsProofOfWork() && nHeight > LAST_POW_BLOCK) return DoS(100, error("AcceptBlock() : reject proof-of-work at height %d", nHeight)); // Check coinbase timestamp if (GetBlockTime() > FutureDrift((int64_t)vtx[0].nTime, nHeight)) return DoS(50, error("AcceptBlock() : coinbase timestamp is too early")); // Check coinstake timestamp if (IsProofOfStake() && !CheckCoinStakeTimestamp(nHeight, GetBlockTime(), (int64_t)vtx[1].nTime)) return DoS(50, error("AcceptBlock() : coinstake timestamp violation nTimeBlock=%d nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); // Check proof-of-work or proof-of-stake if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake())) return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); // Check timestamp against prev if (GetBlockTime() <= pindexPrev->GetPastTimeLimit() || FutureDrift(GetBlockTime(), nHeight) < pindexPrev->GetBlockTime()) return error("AcceptBlock() : block's timestamp is too early"); // Check that all transactions are finalized BOOST_FOREACH(const CTransaction& tx, vtx) if (!IsFinalTx(tx, nHeight, GetBlockTime())) return DoS(10, error("AcceptBlock() : contains a non-final transaction")); // Check that the block chain matches the known block chain up to a checkpoint if (!Checkpoints::CheckHardened(nHeight, hash)) return DoS(100, error("AcceptBlock() : rejected by hardened checkpoint lock-in at %d", nHeight)); uint256 hashProof; // Verify hash target and signature of coinstake tx if (IsProofOfStake()) { uint256 targetProofOfStake; if (!CheckProofOfStake(pindexPrev, vtx[1], nBits, hashProof, targetProofOfStake)) { return error("AcceptBlock() : check proof-of-stake failed for block %s", hash.ToString()); } } // PoW is checked in CheckBlock() if (IsProofOfWork()) { hashProof = GetPoWHash(); } bool cpSatisfies = Checkpoints::CheckSync(hash, pindexPrev); // Check that the block satisfies synchronized checkpoint if (CheckpointsMode == Checkpoints::STRICT && !cpSatisfies) return error("AcceptBlock() : rejected by synchronized checkpoint"); if (CheckpointsMode == Checkpoints::ADVISORY && !cpSatisfies) strMiscWarning = _("WARNING: syncronized checkpoint violation detected, but skipped!"); // Enforce rule that the coinbase starts with serialized block height CScript expect = CScript() << nHeight; if (vtx[0].vin[0].scriptSig.size() < expect.size() || !std::equal(expect.begin(), expect.end(), vtx[0].vin[0].scriptSig.begin())) return DoS(100, error("AcceptBlock() : block height mismatch in coinbase")); // Write block to history file if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION))) return error("AcceptBlock() : out of disk space"); unsigned int nFile = -1; unsigned int nBlockPos = 0; if (!WriteToDisk(nFile, nBlockPos)) return error("AcceptBlock() : WriteToDisk failed"); if (!AddToBlockIndex(nFile, nBlockPos, hashProof)) return error("AcceptBlock() : AddToBlockIndex failed"); // Relay inventory, but don't relay old inventory during initial block download int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(); if (hashBestChain == hash) { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) pnode->PushInventory(CInv(MSG_BLOCK, hash)); } // ppcoin: check pending sync-checkpoint Checkpoints::AcceptPendingSyncCheckpoint(); return true; } uint256 CBlockIndex::GetBlockTrust() const { CBigNum bnTarget; bnTarget.SetCompact(nBits); if (bnTarget <= 0) return 0; return ((CBigNum(1)<<256) / (bnTarget+1)).getuint256(); } bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck) { unsigned int nFound = 0; for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++) { if (pstart->nVersion >= minVersion) ++nFound; pstart = pstart->pprev; } return (nFound >= nRequired); } void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd) { // Filter out duplicate requests if (pindexBegin == pnode->pindexLastGetBlocksBegin && hashEnd == pnode->hashLastGetBlocksEnd) return; pnode->pindexLastGetBlocksBegin = pindexBegin; pnode->hashLastGetBlocksEnd = hashEnd; pnode->PushMessage("getblocks", CBlockLocator(pindexBegin), hashEnd); } bool static ReserealizeBlockSignature(CBlock* pblock) { if (pblock->IsProofOfWork()) { pblock->vchBlockSig.clear(); return true; } return CKey::ReserealizeSignature(pblock->vchBlockSig); } bool static IsCanonicalBlockSignature(CBlock* pblock) { if (pblock->IsProofOfWork()) { return pblock->vchBlockSig.empty(); } return IsDERSignature(pblock->vchBlockSig, false); } bool ProcessBlock(CNode* pfrom, CBlock* pblock) { AssertLockHeld(cs_main); // Check for duplicate uint256 hash = pblock->GetHash(); if (mapBlockIndex.count(hash)) return error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()); if (mapOrphanBlocks.count(hash)) return error("ProcessBlock() : already have block (orphan) %s", hash.ToString()); // ppcoin: check proof-of-stake // Limited duplicity on stake: prevents block flood attack // Duplicate stake allowed only when there is orphan child block if (pblock->IsProofOfStake() && setStakeSeen.count(pblock->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash) && !Checkpoints::WantedByPendingSyncCheckpoint(hash)) return error("ProcessBlock() : duplicate proof-of-stake (%s, %d) for block %s", pblock->GetProofOfStake().first.ToString(), pblock->GetProofOfStake().second, hash.ToString()); CBlockIndex* pcheckpoint = Checkpoints::GetLastSyncCheckpoint(); if (pcheckpoint && pblock->hashPrevBlock != hashBestChain && !Checkpoints::WantedByPendingSyncCheckpoint(hash)) { // Extra checks to prevent "fill up memory by spamming with bogus blocks" int64_t deltaTime = pblock->GetBlockTime() - pcheckpoint->nTime; if (deltaTime < -10*60) { if (pfrom) pfrom->Misbehaving(1); return error("ProcessBlock() : block with timestamp before last checkpoint"); } /* FIXME CBigNum bnNewBlock; bnNewBlock.SetCompact(pblock->nBits); CBigNum bnRequired; if (pblock->IsProofOfStake()) bnRequired.SetCompact(ComputeMinStake(GetLastBlockIndex(pcheckpoint, true)->nBits, deltaTime, pblock->nTime)); else bnRequired.SetCompact(ComputeMinWork(GetLastBlockIndex(pcheckpoint, false)->nBits, deltaTime)); if (bnNewBlock > bnRequired) { if (pfrom) pfrom->Misbehaving(100); return error("ProcessBlock() : block with too little %s", pblock->IsProofOfStake()? "proof-of-stake" : "proof-of-work"); } */ } // Block signature can be malleated in such a way that it increases block size up to maximum allowed by protocol // For now we just strip garbage from newly received blocks if (!IsCanonicalBlockSignature(pblock)) { if (!ReserealizeBlockSignature(pblock)) LogPrintf("WARNING: ProcessBlock() : ReserealizeBlockSignature FAILED\n"); } // Preliminary checks if (!pblock->CheckBlock()) return error("ProcessBlock() : CheckBlock FAILED"); // ppcoin: ask for pending sync-checkpoint if any if (!IsInitialBlockDownload()) Checkpoints::AskForPendingSyncCheckpoint(pfrom); // If we don't already have its previous block, shunt it off to holding area until we get it if (!mapBlockIndex.count(pblock->hashPrevBlock)) { LogPrintf("ProcessBlock: ORPHAN BLOCK %lu, prev=%s\n", (unsigned long)mapOrphanBlocks.size(), pblock->hashPrevBlock.ToString()); // Accept orphans as long as there is a node to request its parents from if (pfrom) { // ppcoin: check proof-of-stake if (pblock->IsProofOfStake()) { // Limited duplicity on stake: prevents block flood attack // Duplicate stake allowed only when there is orphan child block if (setStakeSeenOrphan.count(pblock->GetProofOfStake()) && !mapOrphanBlocksByPrev.count(hash) && !Checkpoints::WantedByPendingSyncCheckpoint(hash)) return error("ProcessBlock() : duplicate proof-of-stake (%s, %d) for orphan block %s", pblock->GetProofOfStake().first.ToString(), pblock->GetProofOfStake().second, hash.ToString()); } PruneOrphanBlocks(); COrphanBlock* pblock2 = new COrphanBlock(); { CDataStream ss(SER_DISK, CLIENT_VERSION); ss << *pblock; pblock2->vchBlock = std::vector<unsigned char>(ss.begin(), ss.end()); } pblock2->hashBlock = hash; pblock2->hashPrev = pblock->hashPrevBlock; pblock2->stake = pblock->GetProofOfStake(); mapOrphanBlocks.insert(make_pair(hash, pblock2)); mapOrphanBlocksByPrev.insert(make_pair(pblock2->hashPrev, pblock2)); if (pblock->IsProofOfStake()) setStakeSeenOrphan.insert(pblock->GetProofOfStake()); // Ask this guy to fill in what we're missing PushGetBlocks(pfrom, pindexBest, GetOrphanRoot(hash)); // ppcoin: getblocks may not obtain the ancestor block rejected // earlier by duplicate-stake check so we ask for it again directly if (!IsInitialBlockDownload()) pfrom->AskFor(CInv(MSG_BLOCK, WantedByOrphan(pblock2))); } return true; } // Store to disk if (!pblock->AcceptBlock()) return error("ProcessBlock() : AcceptBlock FAILED"); // Recursively process any orphan blocks that depended on this one vector<uint256> vWorkQueue; vWorkQueue.push_back(hash); for (unsigned int i = 0; i < vWorkQueue.size(); i++) { uint256 hashPrev = vWorkQueue[i]; for (multimap<uint256, COrphanBlock*>::iterator mi = mapOrphanBlocksByPrev.lower_bound(hashPrev); mi != mapOrphanBlocksByPrev.upper_bound(hashPrev); ++mi) { CBlock block; { CDataStream ss(mi->second->vchBlock, SER_DISK, CLIENT_VERSION); ss >> block; } block.BuildMerkleTree(); if (block.AcceptBlock()) vWorkQueue.push_back(mi->second->hashBlock); mapOrphanBlocks.erase(mi->second->hashBlock); setStakeSeenOrphan.erase(block.GetProofOfStake()); delete mi->second; } mapOrphanBlocksByPrev.erase(hashPrev); } LogPrintf("ProcessBlock: ACCEPTED\n"); // ppcoin: if responsible for sync-checkpoint send it if (pfrom && !CSyncCheckpoint::strMasterPrivKey.empty()) Checkpoints::SendSyncCheckpoint(Checkpoints::AutoSelectSyncCheckpoint()); return true; } #ifdef ENABLE_WALLET // novacoin: attempt to generate suitable proof-of-stake bool CBlock::SignBlock(CWallet& wallet, int64_t nFees) { // if we are trying to sign // something except proof-of-stake block template if (!vtx[0].vout[0].IsEmpty()) return false; // if we are trying to sign // a complete proof-of-stake block if (IsProofOfStake()) return true; static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp CKey key; CTransaction txCoinStake; if (IsProtocolV2(nBestHeight+1)) txCoinStake.nTime &= ~STAKE_TIMESTAMP_MASK; int64_t nSearchTime = txCoinStake.nTime; // search to current time if (nSearchTime > nLastCoinStakeSearchTime) { int64_t nSearchInterval = IsProtocolV2(nBestHeight+1) ? 1 : nSearchTime - nLastCoinStakeSearchTime; if (wallet.CreateCoinStake(wallet, nBits, nSearchInterval, nFees, txCoinStake, key)) { if (txCoinStake.nTime >= max(pindexBest->GetPastTimeLimit()+1, PastDrift(pindexBest->GetBlockTime(), pindexBest->nHeight+1))) { // make sure coinstake would meet timestamp protocol // as it would be the same as the block timestamp vtx[0].nTime = nTime = txCoinStake.nTime; nTime = max(pindexBest->GetPastTimeLimit()+1, GetMaxTransactionTime()); nTime = max(GetBlockTime(), PastDrift(pindexBest->GetBlockTime(), pindexBest->nHeight+1)); // we have to make sure that we have no future timestamps in // our transactions set for (vector<CTransaction>::iterator it = vtx.begin(); it != vtx.end();) if (it->nTime > nTime) { it = vtx.erase(it); } else { ++it; } vtx.insert(vtx.begin() + 1, txCoinStake); hashMerkleRoot = BuildMerkleTree(); // append a signature to our block return key.Sign(GetHash(), vchBlockSig); } } nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime; nLastCoinStakeSearchTime = nSearchTime; } return false; } #endif bool CBlock::CheckBlockSignature() const { if (IsProofOfWork()) return vchBlockSig.empty(); if (vchBlockSig.empty()) return false; vector<valtype> vSolutions; txnouttype whichType; const CTxOut& txout = vtx[1].vout[1]; if (!Solver(txout.scriptPubKey, whichType, vSolutions)) return false; if (whichType == TX_PUBKEY) { valtype& vchPubKey = vSolutions[0]; return CPubKey(vchPubKey).Verify(GetHash(), vchBlockSig); } return false; } bool CheckDiskSpace(uint64_t nAdditionalBytes) { uint64_t nFreeBytesAvailable = filesystem::space(GetDataDir()).available; // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) { string strMessage = _("Error: Disk space is low!"); strMiscWarning = strMessage; LogPrintf("*** %s\n", strMessage); uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_ERROR); StartShutdown(); return false; } return true; } static filesystem::path BlockFilePath(unsigned int nFile) { string strBlockFn = strprintf("blk%04u.dat", nFile); return GetDataDir() / strBlockFn; } FILE* OpenBlockFile(unsigned int nFile, unsigned int nBlockPos, const char* pszMode) { if ((nFile < 1) || (nFile == (unsigned int) -1)) return NULL; FILE* file = fopen(BlockFilePath(nFile).string().c_str(), pszMode); if (!file) return NULL; if (nBlockPos != 0 && !strchr(pszMode, 'a') && !strchr(pszMode, 'w')) { if (fseek(file, nBlockPos, SEEK_SET) != 0) { fclose(file); return NULL; } } return file; } static unsigned int nCurrentBlockFile = 1; FILE* AppendBlockFile(unsigned int& nFileRet) { nFileRet = 0; while (true) { FILE* file = OpenBlockFile(nCurrentBlockFile, 0, "ab"); if (!file) return NULL; if (fseek(file, 0, SEEK_END) != 0) return NULL; // FAT32 file size max 4GB, fseek and ftell max 2GB, so we must stay under 2GB if (ftell(file) < (long)(0x7F000000 - MAX_SIZE)) { nFileRet = nCurrentBlockFile; return file; } fclose(file); nCurrentBlockFile++; } } bool LoadBlockIndex(bool fAllowNew) { LOCK(cs_main); if (TestNet()) { nStakeMinAge = 1 * 60 * 60; // test net min age is 1 hour nCoinbaseMaturity = 10; // test maturity is 10 blocks } // // Load block index // CTxDB txdb("cr+"); if (!txdb.LoadBlockIndex()) return false; // // Init with genesis block // if (mapBlockIndex.empty()) { if (!fAllowNew) return false; CBlock &block = const_cast<CBlock&>(Params().GenesisBlock()); // Start new block file unsigned int nFile; unsigned int nBlockPos; if (!block.WriteToDisk(nFile, nBlockPos)) return error("LoadBlockIndex() : writing genesis block to disk failed"); if (!block.AddToBlockIndex(nFile, nBlockPos, Params().HashGenesisBlock())) return error("LoadBlockIndex() : genesis block not accepted"); // ppcoin: initialize synchronized checkpoint if (!Checkpoints::WriteSyncCheckpoint(Params().HashGenesisBlock())) return error("LoadBlockIndex() : failed to init sync checkpoint"); } string strPubKey = ""; // if checkpoint master key changed must reset sync-checkpoint if (!txdb.ReadCheckpointPubKey(strPubKey) || strPubKey != CSyncCheckpoint::strMasterPubKey) { // write checkpoint master key to db txdb.TxnBegin(); if (!txdb.WriteCheckpointPubKey(CSyncCheckpoint::strMasterPubKey)) return error("LoadBlockIndex() : failed to write new checkpoint master key to db"); if (!txdb.TxnCommit()) return error("LoadBlockIndex() : failed to commit new checkpoint master key to db"); if ((Params().NetworkID() == CChainParams::MAIN) && !Checkpoints::ResetSyncCheckpoint()) return error("LoadBlockIndex() : failed to reset sync-checkpoint"); } return true; } void PrintBlockTree() { AssertLockHeld(cs_main); // pre-compute tree structure map<CBlockIndex*, vector<CBlockIndex*> > mapNext; for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) { CBlockIndex* pindex = (*mi).second; mapNext[pindex->pprev].push_back(pindex); // test //while (rand() % 3 == 0) // mapNext[pindex->pprev].push_back(pindex); } vector<pair<int, CBlockIndex*> > vStack; vStack.push_back(make_pair(0, pindexGenesisBlock)); int nPrevCol = 0; while (!vStack.empty()) { int nCol = vStack.back().first; CBlockIndex* pindex = vStack.back().second; vStack.pop_back(); // print split or gap if (nCol > nPrevCol) { for (int i = 0; i < nCol-1; i++) LogPrintf("| "); LogPrintf("|\\\n"); } else if (nCol < nPrevCol) { for (int i = 0; i < nCol; i++) LogPrintf("| "); LogPrintf("|\n"); } nPrevCol = nCol; // print columns for (int i = 0; i < nCol; i++) LogPrintf("| "); // print item CBlock block; block.ReadFromDisk(pindex); LogPrintf("%d (%u,%u) %s %08x %s mint %7s tx %"PRIszu"", pindex->nHeight, pindex->nFile, pindex->nBlockPos, block.GetHash().ToString(), block.nBits, DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()), FormatMoney(pindex->nMint), block.vtx.size()); // put the main time-chain first vector<CBlockIndex*>& vNext = mapNext[pindex]; for (unsigned int i = 0; i < vNext.size(); i++) { if (vNext[i]->pnext) { swap(vNext[0], vNext[i]); break; } } // iterate children for (unsigned int i = 0; i < vNext.size(); i++) vStack.push_back(make_pair(nCol+i, vNext[i])); } } bool LoadExternalBlockFile(FILE* fileIn) { int64_t nStart = GetTimeMillis(); int nLoaded = 0; { try { CAutoFile blkdat(fileIn, SER_DISK, CLIENT_VERSION); unsigned int nPos = 0; while (nPos != (unsigned int)-1 && blkdat.good()) { boost::this_thread::interruption_point(); unsigned char pchData[65536]; do { fseek(blkdat, nPos, SEEK_SET); int nRead = fread(pchData, 1, sizeof(pchData), blkdat); if (nRead <= 8) { nPos = (unsigned int)-1; break; } void* nFind = memchr(pchData, Params().MessageStart()[0], nRead+1-MESSAGE_START_SIZE); if (nFind) { if (memcmp(nFind, Params().MessageStart(), MESSAGE_START_SIZE)==0) { nPos += ((unsigned char*)nFind - pchData) + MESSAGE_START_SIZE; break; } nPos += ((unsigned char*)nFind - pchData) + 1; } else nPos += sizeof(pchData) - MESSAGE_START_SIZE + 1; boost::this_thread::interruption_point(); } while(true); if (nPos == (unsigned int)-1) break; fseek(blkdat, nPos, SEEK_SET); unsigned int nSize; blkdat >> nSize; if (nSize > 0 && nSize <= MAX_BLOCK_SIZE) { CBlock block; blkdat >> block; LOCK(cs_main); if (ProcessBlock(NULL,&block)) { nLoaded++; nPos += 4 + nSize; } } } } catch (std::exception &e) { LogPrintf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__); } } LogPrintf("Loaded %i blocks from external file in %dms\n", nLoaded, GetTimeMillis() - nStart); return nLoaded > 0; } struct CImportingNow { CImportingNow() { assert(fImporting == false); fImporting = true; } ~CImportingNow() { assert(fImporting == true); fImporting = false; } }; void ThreadImport(std::vector<boost::filesystem::path> vImportFiles) { RenameThread("blackcoin-loadblk"); CImportingNow imp; // -loadblock= BOOST_FOREACH(boost::filesystem::path &path, vImportFiles) { FILE *file = fopen(path.string().c_str(), "rb"); if (file) LoadExternalBlockFile(file); } // hardcoded $DATADIR/bootstrap.dat filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; if (filesystem::exists(pathBootstrap)) { FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); if (file) { filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; LoadExternalBlockFile(file); RenameOver(pathBootstrap, pathBootstrapOld); } } } ////////////////////////////////////////////////////////////////////////////// // // CAlert // extern map<uint256, CAlert> mapAlerts; extern CCriticalSection cs_mapAlerts; string GetWarnings(string strFor) { int nPriority = 0; string strStatusBar; string strRPC; if (GetBoolArg("-testsafemode", false)) strRPC = "test"; if (!CLIENT_VERSION_IS_RELEASE) strStatusBar = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"); // Misc warnings like out of disk space and clock is wrong if (strMiscWarning != "") { nPriority = 1000; strStatusBar = strMiscWarning; } // if detected invalid checkpoint enter safe mode if (Checkpoints::hashInvalidCheckpoint != 0) { nPriority = 3000; strStatusBar = strRPC = _("WARNING: Invalid checkpoint found! Displayed transactions may not be correct! You may need to upgrade, or notify developers."); } // Alerts { LOCK(cs_mapAlerts); BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) { const CAlert& alert = item.second; if (alert.AppliesToMe() && alert.nPriority > nPriority) { nPriority = alert.nPriority; strStatusBar = alert.strStatusBar; if (nPriority > 1000) strRPC = strStatusBar; } } } if (strFor == "statusbar") return strStatusBar; else if (strFor == "rpc") return strRPC; assert(!"GetWarnings() : invalid parameter"); return "error"; } ////////////////////////////////////////////////////////////////////////////// // // Messages // bool static AlreadyHave(CTxDB& txdb, const CInv& inv) { switch (inv.type) { case MSG_TX: { bool txInMap = false; txInMap = mempool.exists(inv.hash); return txInMap || mapOrphanTransactions.count(inv.hash) || txdb.ContainsTx(inv.hash); } case MSG_BLOCK: return mapBlockIndex.count(inv.hash) || mapOrphanBlocks.count(inv.hash); } // Don't know what it is, just say we already got one return true; } void static ProcessGetData(CNode* pfrom) { std::deque<CInv>::iterator it = pfrom->vRecvGetData.begin(); vector<CInv> vNotFound; LOCK(cs_main); while (it != pfrom->vRecvGetData.end()) { // Don't bother if send buffer is too full to respond anyway if (pfrom->nSendSize >= SendBufferSize()) break; const CInv &inv = *it; { boost::this_thread::interruption_point(); it++; if (inv.type == MSG_BLOCK) { // Send block from disk map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash); if (mi != mapBlockIndex.end()) { CBlock block; block.ReadFromDisk((*mi).second); pfrom->PushMessage("block", block); // Trigger them to send a getblocks request for the next batch of inventory if (inv.hash == pfrom->hashContinue) { // Bypass PushInventory, this must send even if redundant, // and we want it right after the last block so they don't // wait for other stuff first. vector<CInv> vInv; vInv.push_back(CInv(MSG_BLOCK, hashBestChain)); pfrom->PushMessage("inv", vInv); pfrom->hashContinue = 0; } } } else if (inv.IsKnownType()) { // Send stream from relay memory bool pushed = false; { LOCK(cs_mapRelay); map<CInv, CDataStream>::iterator mi = mapRelay.find(inv); if (mi != mapRelay.end()) { pfrom->PushMessage(inv.GetCommand(), (*mi).second); pushed = true; } } if (!pushed && inv.type == MSG_TX) { CTransaction tx; if (mempool.lookup(inv.hash, tx)) { CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss.reserve(1000); ss << tx; pfrom->PushMessage("tx", ss); pushed = true; } } if (!pushed) { vNotFound.push_back(inv); } } // Track requests for our stuff. g_signals.Inventory(inv.hash); if (inv.type == MSG_BLOCK /* || inv.type == MSG_FILTERED_BLOCK */) break; } } pfrom->vRecvGetData.erase(pfrom->vRecvGetData.begin(), it); if (!vNotFound.empty()) { // Let the peer know that we didn't find what it asked for, so it doesn't // have to wait around forever. Currently only SPV clients actually care // about this message: it's needed when they are recursively walking the // dependencies of relevant unconfirmed transactions. SPV clients want to // do that because they want to know about (and store and rebroadcast and // risk analyze) the dependencies of transactions relevant to them, without // having to download the entire memory pool. pfrom->PushMessage("notfound", vNotFound); } } bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, int64_t nTimeReceived) { RandAddSeedPerfmon(); LogPrint("net", "received: %s (%"PRIszu" bytes)\n", strCommand, vRecv.size()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); return true; } if (strCommand == "version") { // Each connection can only send one version message if (pfrom->nVersion != 0) { pfrom->Misbehaving(1); return false; } int64_t nTime; CAddress addrMe; CAddress addrFrom; uint64_t nNonce = 1; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) { // disconnect from peers older than this proto version LogPrintf("partner %s using obsolete version %i; disconnecting\n", pfrom->addr.ToString(), pfrom->nVersion); pfrom->fDisconnect = true; return false; } if (pfrom->nVersion == 10300) pfrom->nVersion = 300; if (!vRecv.empty()) vRecv >> addrFrom >> nNonce; if (!vRecv.empty()) vRecv >> pfrom->strSubVer; if (!vRecv.empty()) vRecv >> pfrom->nStartingHeight; // Disconnect if we connected to ourself if (nNonce == nLocalHostNonce && nNonce > 1) { LogPrintf("connected to self at %s, disconnecting\n", pfrom->addr.ToString()); pfrom->fDisconnect = true; return true; } pfrom->addrLocal = addrMe; if (pfrom->fInbound && addrMe.IsRoutable()) { SeenLocal(addrMe); } // Be shy and don't send version until we hear if (pfrom->fInbound) pfrom->PushVersion(); pfrom->fClient = !(pfrom->nServices & NODE_NETWORK); // Change version pfrom->PushMessage("verack"); pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); if (!pfrom->fInbound) { // Advertise our address if (!fNoListen && !IsInitialBlockDownload()) { CAddress addr = GetLocalAddress(&pfrom->addr); if (addr.IsRoutable()) { pfrom->PushAddress(addr); } else if (IsPeerAddrLocalGood(pfrom)) { addr.SetIP(pfrom->addrLocal); pfrom->PushAddress(addr); } } // Get recent addresses if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000) { pfrom->PushMessage("getaddr"); pfrom->fGetAddr = true; } addrman.Good(pfrom->addr); } else { if (((CNetAddr)pfrom->addr) == (CNetAddr)addrFrom) { addrman.Add(addrFrom, addrFrom); addrman.Good(addrFrom); } } // Relay alerts { LOCK(cs_mapAlerts); BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) item.second.RelayTo(pfrom); } // Relay sync-checkpoint { LOCK(Checkpoints::cs_hashSyncCheckpoint); if (!Checkpoints::checkpointMessage.IsNull()) Checkpoints::checkpointMessage.RelayTo(pfrom); } pfrom->fSuccessfullyConnected = true; LogPrintf("receive version message: version %d, blocks=%d, us=%s, them=%s, peer=%s\n", pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), addrFrom.ToString(), pfrom->addr.ToString()); // ppcoin: ask for pending sync-checkpoint if any if (!IsInitialBlockDownload()) Checkpoints::AskForPendingSyncCheckpoint(pfrom); if (GetBoolArg("-synctime", true)) AddTimeData(pfrom->addr, nTime); } else if (pfrom->nVersion == 0) { // Must have a version message before anything else pfrom->Misbehaving(1); return false; } else if (strCommand == "verack") { pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); } else if (strCommand == "addr") { vector<CAddress> vAddr; vRecv >> vAddr; // Don't want addr from older versions unless seeding if (pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000) return true; if (vAddr.size() > 1000) { pfrom->Misbehaving(20); return error("message addr size() = %"PRIszu"", vAddr.size()); } // Store the new addresses vector<CAddress> vAddrOk; int64_t nNow = GetAdjustedTime(); int64_t nSince = nNow - 10 * 60; BOOST_FOREACH(CAddress& addr, vAddr) { boost::this_thread::interruption_point(); if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60) addr.nTime = nNow - 5 * 24 * 60 * 60; pfrom->AddAddressKnown(addr); bool fReachable = IsReachable(addr); if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable()) { // Relay to a limited number of other nodes { LOCK(cs_vNodes); // Use deterministic randomness to send to the same nodes for 24 hours // at a time so the setAddrKnowns of the chosen nodes prevent repeats static uint256 hashSalt; if (hashSalt == 0) hashSalt = GetRandHash(); uint64_t hashAddr = addr.GetHash(); uint256 hashRand = hashSalt ^ (hashAddr<<32) ^ ((GetTime()+hashAddr)/(24*60*60)); hashRand = Hash(BEGIN(hashRand), END(hashRand)); multimap<uint256, CNode*> mapMix; BOOST_FOREACH(CNode* pnode, vNodes) { if (pnode->nVersion < CADDR_TIME_VERSION) continue; unsigned int nPointer; memcpy(&nPointer, &pnode, sizeof(nPointer)); uint256 hashKey = hashRand ^ nPointer; hashKey = Hash(BEGIN(hashKey), END(hashKey)); mapMix.insert(make_pair(hashKey, pnode)); } int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s) for (multimap<uint256, CNode*>::iterator mi = mapMix.begin(); mi != mapMix.end() && nRelayNodes-- > 0; ++mi) ((*mi).second)->PushAddress(addr); } } // Do not store addresses outside our network if (fReachable) vAddrOk.push_back(addr); } addrman.Add(vAddrOk, pfrom->addr, 2 * 60 * 60); if (vAddr.size() < 1000) pfrom->fGetAddr = false; if (pfrom->fOneShot) pfrom->fDisconnect = true; } else if (strCommand == "inv") { vector<CInv> vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); return error("message inv size() = %"PRIszu"", vInv.size()); } // find last block in inv vector unsigned int nLastBlock = (unsigned int)(-1); for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { if (vInv[vInv.size() - 1 - nInv].type == MSG_BLOCK) { nLastBlock = vInv.size() - 1 - nInv; break; } } LOCK(cs_main); CTxDB txdb("r"); for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { const CInv &inv = vInv[nInv]; boost::this_thread::interruption_point(); pfrom->AddInventoryKnown(inv); bool fAlreadyHave = AlreadyHave(txdb, inv); LogPrint("net", " got inventory: %s %s\n", inv.ToString(), fAlreadyHave ? "have" : "new"); if (!fAlreadyHave) { if (!fImporting) pfrom->AskFor(inv); } else if (inv.type == MSG_BLOCK && mapOrphanBlocks.count(inv.hash)) { PushGetBlocks(pfrom, pindexBest, GetOrphanRoot(inv.hash)); } else if (nInv == nLastBlock) { // In case we are on a very long side-chain, it is possible that we already have // the last block in an inv bundle sent in response to getblocks. Try to detect // this situation and push another getblocks to continue. PushGetBlocks(pfrom, mapBlockIndex[inv.hash], uint256(0)); if (fDebug) LogPrintf("force request: %s\n", inv.ToString()); } // Track requests for our stuff g_signals.Inventory(inv.hash); } } else if (strCommand == "getdata") { vector<CInv> vInv; vRecv >> vInv; if (vInv.size() > MAX_INV_SZ) { pfrom->Misbehaving(20); return error("message getdata size() = %"PRIszu"", vInv.size()); } if (fDebug || (vInv.size() != 1)) LogPrint("net", "received getdata (%"PRIszu" invsz)\n", vInv.size()); if ((fDebug && vInv.size() > 0) || (vInv.size() == 1)) LogPrint("net", "received getdata for: %s\n", vInv[0].ToString()); pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); ProcessGetData(pfrom); } else if (strCommand == "getblocks") { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; LOCK(cs_main); // Find the last block the caller has in the main chain CBlockIndex* pindex = locator.GetBlockIndex(); // Send the rest of the chain if (pindex) pindex = pindex->pnext; int nLimit = 500; LogPrint("net", "getblocks %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), nLimit); for (; pindex; pindex = pindex->pnext) { if (pindex->GetBlockHash() == hashStop) { LogPrint("net", " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); break; } pfrom->PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); if (--nLimit <= 0) { // When this block is requested, we'll send an inv that'll make them // getblocks the next batch of inventory. LogPrint("net", " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); pfrom->hashContinue = pindex->GetBlockHash(); break; } } } else if (strCommand == "checkpoint") { CSyncCheckpoint checkpoint; vRecv >> checkpoint; if (checkpoint.ProcessSyncCheckpoint(pfrom)) { // Relay pfrom->hashCheckpointKnown = checkpoint.hashCheckpoint; LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) checkpoint.RelayTo(pnode); } } else if (strCommand == "getheaders") { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; LOCK(cs_main); CBlockIndex* pindex = NULL; if (locator.IsNull()) { // If locator is null, return the hashStop block map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashStop); if (mi == mapBlockIndex.end()) return true; pindex = (*mi).second; } else { // Find the last block the caller has in the main chain pindex = locator.GetBlockIndex(); if (pindex) pindex = pindex->pnext; } vector<CBlock> vHeaders; int nLimit = 2000; LogPrint("net", "getheaders %d to %s\n", (pindex ? pindex->nHeight : -1), hashStop.ToString()); for (; pindex; pindex = pindex->pnext) { vHeaders.push_back(pindex->GetBlockHeader()); if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop) break; } pfrom->PushMessage("headers", vHeaders); } else if (strCommand == "tx") { vector<uint256> vWorkQueue; vector<uint256> vEraseQueue; CTransaction tx; vRecv >> tx; CInv inv(MSG_TX, tx.GetHash()); pfrom->AddInventoryKnown(inv); LOCK(cs_main); bool fMissingInputs = false; mapAlreadyAskedFor.erase(inv); if (AcceptToMemoryPool(mempool, tx, true, &fMissingInputs)) { RelayTransaction(tx, inv.hash); vWorkQueue.push_back(inv.hash); vEraseQueue.push_back(inv.hash); // Recursively process any orphan transactions that depended on this one for (unsigned int i = 0; i < vWorkQueue.size(); i++) { map<uint256, set<uint256> >::iterator itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue[i]); if (itByPrev == mapOrphanTransactionsByPrev.end()) continue; for (set<uint256>::iterator mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) { const uint256& orphanTxHash = *mi; CTransaction& orphanTx = mapOrphanTransactions[orphanTxHash]; bool fMissingInputs2 = false; if (AcceptToMemoryPool(mempool, orphanTx, true, &fMissingInputs2)) { LogPrint("mempool", " accepted orphan tx %s\n", orphanTxHash.ToString()); RelayTransaction(orphanTx, orphanTxHash); vWorkQueue.push_back(orphanTxHash); vEraseQueue.push_back(orphanTxHash); } else if (!fMissingInputs2) { // invalid or too-little-fee orphan vEraseQueue.push_back(orphanTxHash); LogPrint("mempool", " removed orphan tx %s\n", orphanTxHash.ToString()); } } } BOOST_FOREACH(uint256 hash, vEraseQueue) EraseOrphanTx(hash); } else if (fMissingInputs) { AddOrphanTx(tx); // DoS prevention: do not allow mapOrphanTransactions to grow unbounded unsigned int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS); if (nEvicted > 0) LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted); } if (tx.nDoS) pfrom->Misbehaving(tx.nDoS); } else if (strCommand == "block") { CBlock block; vRecv >> block; uint256 hashBlock = block.GetHash(); LogPrint("net", "received block %s\n", hashBlock.ToString()); CInv inv(MSG_BLOCK, hashBlock); pfrom->AddInventoryKnown(inv); LOCK(cs_main); if (ProcessBlock(pfrom, &block)) mapAlreadyAskedFor.erase(inv); if (block.nDoS) pfrom->Misbehaving(block.nDoS); } else if (strCommand == "getaddr") { // Don't return addresses older than nCutOff timestamp int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60); pfrom->vAddrToSend.clear(); vector<CAddress> vAddr = addrman.GetAddr(); BOOST_FOREACH(const CAddress &addr, vAddr) if(addr.nTime > nCutOff) pfrom->PushAddress(addr); } else if (strCommand == "mempool") { LOCK(cs_main); std::vector<uint256> vtxid; mempool.queryHashes(vtxid); vector<CInv> vInv; for (unsigned int i = 0; i < vtxid.size(); i++) { CInv inv(MSG_TX, vtxid[i]); vInv.push_back(inv); if (i == (MAX_INV_SZ - 1)) break; } if (vInv.size() > 0) pfrom->PushMessage("inv", vInv); } else if (strCommand == "ping") { if (pfrom->nVersion > BIP0031_VERSION) { uint64_t nonce = 0; vRecv >> nonce; // Echo the message back with the nonce. This allows for two useful features: // // 1) A remote node can quickly check if the connection is operational // 2) Remote nodes can measure the latency of the network thread. If this node // is overloaded it won't respond to pings quickly and the remote node can // avoid sending us more work, like chain download requests. // // The nonce stops the remote getting confused between different pings: without // it, if the remote node sends a ping once per second and this node takes 5 // seconds to respond to each, the 5th ping the remote sends would appear to // return very quickly. pfrom->PushMessage("pong", nonce); } } else if (strCommand == "pong") { int64_t pingUsecEnd = nTimeReceived; uint64_t nonce = 0; size_t nAvail = vRecv.in_avail(); bool bPingFinished = false; std::string sProblem; if (nAvail >= sizeof(nonce)) { vRecv >> nonce; // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) if (pfrom->nPingNonceSent != 0) { if (nonce == pfrom->nPingNonceSent) { // Matching pong received, this ping is no longer outstanding bPingFinished = true; int64_t pingUsecTime = pingUsecEnd - pfrom->nPingUsecStart; if (pingUsecTime > 0) { // Successful ping time measurement, replace previous pfrom->nPingUsecTime = pingUsecTime; } else { // This should never happen sProblem = "Timing mishap"; } } else { // Nonce mismatches are normal when pings are overlapping sProblem = "Nonce mismatch"; if (nonce == 0) { // This is most likely a bug in another implementation somewhere, cancel this ping bPingFinished = true; sProblem = "Nonce zero"; } } } else { sProblem = "Unsolicited pong without ping"; } } else { // This is most likely a bug in another implementation somewhere, cancel this ping bPingFinished = true; sProblem = "Short payload"; } if (!(sProblem.empty())) { LogPrint("net", "pong %s %s: %s, %x expected, %x received, %zu bytes\n" , pfrom->addr.ToString() , pfrom->strSubVer , sProblem , pfrom->nPingNonceSent , nonce , nAvail); } if (bPingFinished) { pfrom->nPingNonceSent = 0; } } else if (strCommand == "alert") { CAlert alert; vRecv >> alert; uint256 alertHash = alert.GetHash(); if (pfrom->setKnown.count(alertHash) == 0) { if (alert.ProcessAlert()) { // Relay pfrom->setKnown.insert(alertHash); { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) alert.RelayTo(pnode); } } else { // Small DoS penalty so peers that send us lots of // duplicate/expired/invalid-signature/whatever alerts // eventually get banned. // This isn't a Misbehaving(100) (immediate ban) because the // peer might be an older or different implementation with // a different signature key, etc. pfrom->Misbehaving(10); } } } else { // Ignore unknown commands for extensibility } // Update the last seen time for this node's address if (pfrom->fNetworkNode) if (strCommand == "version" || strCommand == "addr" || strCommand == "inv" || strCommand == "getdata" || strCommand == "ping") AddressCurrentlyConnected(pfrom->addr); return true; } // requires LOCK(cs_vRecvMsg) bool ProcessMessages(CNode* pfrom) { //if (fDebug) // LogPrintf("ProcessMessages(%zu messages)\n", pfrom->vRecvMsg.size()); // // Message format // (4) message start // (12) command // (4) size // (4) checksum // (x) data // bool fOk = true; if (!pfrom->vRecvGetData.empty()) ProcessGetData(pfrom); // this maintains the order of responses if (!pfrom->vRecvGetData.empty()) return fOk; std::deque<CNetMessage>::iterator it = pfrom->vRecvMsg.begin(); while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { // Don't bother if send buffer is too full to respond anyway if (pfrom->nSendSize >= SendBufferSize()) break; // get next message CNetMessage& msg = *it; //if (fDebug) // LogPrintf("ProcessMessages(message %u msgsz, %zu bytes, complete:%s)\n", // msg.hdr.nMessageSize, msg.vRecv.size(), // msg.complete() ? "Y" : "N"); // end, if an incomplete message is found if (!msg.complete()) break; // at this point, any failure means we can delete the current message it++; // Scan for message start if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) { LogPrintf("\n\nPROCESSMESSAGE: INVALID MESSAGESTART\n\n"); fOk = false; break; } // Read header CMessageHeader& hdr = msg.hdr; if (!hdr.IsValid()) { LogPrintf("\n\nPROCESSMESSAGE: ERRORS IN HEADER %s\n\n\n", hdr.GetCommand()); continue; } string strCommand = hdr.GetCommand(); // Message size unsigned int nMessageSize = hdr.nMessageSize; // Checksum CDataStream& vRecv = msg.vRecv; uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize); unsigned int nChecksum = 0; memcpy(&nChecksum, &hash, sizeof(nChecksum)); if (nChecksum != hdr.nChecksum) { LogPrintf("ProcessMessages(%s, %u bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n", strCommand, nMessageSize, nChecksum, hdr.nChecksum); continue; } // Process message bool fRet = false; try { fRet = ProcessMessage(pfrom, strCommand, vRecv, msg.nTime); boost::this_thread::interruption_point(); } catch (std::ios_base::failure& e) { if (strstr(e.what(), "end of data")) { // Allow exceptions from under-length message on vRecv LogPrintf("ProcessMessages(%s, %u bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand, nMessageSize, e.what()); } else if (strstr(e.what(), "size too large")) { // Allow exceptions from over-long size LogPrintf("ProcessMessages(%s, %u bytes) : Exception '%s' caught\n", strCommand, nMessageSize, e.what()); } else { PrintExceptionContinue(&e, "ProcessMessages()"); } } catch (boost::thread_interrupted) { throw; } catch (std::exception& e) { PrintExceptionContinue(&e, "ProcessMessages()"); } catch (...) { PrintExceptionContinue(NULL, "ProcessMessages()"); } if (!fRet) LogPrintf("ProcessMessage(%s, %u bytes) FAILED\n", strCommand, nMessageSize); break; } // In case the connection got shut down, its receive buffer was wiped if (!pfrom->fDisconnect) pfrom->vRecvMsg.erase(pfrom->vRecvMsg.begin(), it); return fOk; } bool SendMessages(CNode* pto, bool fSendTrickle) { TRY_LOCK(cs_main, lockMain); if (lockMain) { // Don't send anything until we get their version message if (pto->nVersion == 0) return true; // // Message: ping // bool pingSend = false; if (pto->fPingQueued) { // RPC ping request by user pingSend = true; } if (pto->nPingNonceSent == 0 && pto->nPingUsecStart + PING_INTERVAL * 1000000 < GetTimeMicros()) { // Ping automatically sent as a latency probe & keepalive. pingSend = true; } if (pingSend) { uint64_t nonce = 0; while (nonce == 0) { RAND_bytes((unsigned char*)&nonce, sizeof(nonce)); } pto->fPingQueued = false; pto->nPingUsecStart = GetTimeMicros(); if (pto->nVersion > BIP0031_VERSION) { pto->nPingNonceSent = nonce; pto->PushMessage("ping", nonce); } else { // Peer is too old to support ping command with nonce, pong will never arrive. pto->nPingNonceSent = 0; pto->PushMessage("ping"); } } // Start block sync if (pto->fStartSync && !fImporting && !fReindex) { pto->fStartSync = false; PushGetBlocks(pto, pindexBest, uint256(0)); } // Resend wallet transactions that haven't gotten in a block yet ResendWalletTransactions(); // Address refresh broadcast static int64_t nLastRebroadcast; if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > 24 * 60 * 60)) { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { // Periodically clear setAddrKnown to allow refresh broadcasts if (nLastRebroadcast) pnode->setAddrKnown.clear(); // Rebroadcast our address AdvertizeLocal(pnode); } if (!vNodes.empty()) nLastRebroadcast = GetTime(); } // // Message: addr // if (fSendTrickle) { vector<CAddress> vAddr; vAddr.reserve(pto->vAddrToSend.size()); BOOST_FOREACH(const CAddress& addr, pto->vAddrToSend) { // returns true if wasn't already contained in the set if (pto->setAddrKnown.insert(addr).second) { vAddr.push_back(addr); // receiver rejects addr messages larger than 1000 if (vAddr.size() >= 1000) { pto->PushMessage("addr", vAddr); vAddr.clear(); } } } pto->vAddrToSend.clear(); if (!vAddr.empty()) pto->PushMessage("addr", vAddr); } // // Message: inventory // vector<CInv> vInv; vector<CInv> vInvWait; { LOCK(pto->cs_inventory); vInv.reserve(pto->vInventoryToSend.size()); vInvWait.reserve(pto->vInventoryToSend.size()); BOOST_FOREACH(const CInv& inv, pto->vInventoryToSend) { if (pto->setInventoryKnown.count(inv)) continue; // trickle out tx inv to protect privacy if (inv.type == MSG_TX && !fSendTrickle) { // 1/4 of tx invs blast to all immediately static uint256 hashSalt; if (hashSalt == 0) hashSalt = GetRandHash(); uint256 hashRand = inv.hash ^ hashSalt; hashRand = Hash(BEGIN(hashRand), END(hashRand)); bool fTrickleWait = ((hashRand & 3) != 0); if (fTrickleWait) { vInvWait.push_back(inv); continue; } } // returns true if wasn't already contained in the set if (pto->setInventoryKnown.insert(inv).second) { vInv.push_back(inv); if (vInv.size() >= 1000) { pto->PushMessage("inv", vInv); vInv.clear(); } } } pto->vInventoryToSend = vInvWait; } if (!vInv.empty()) pto->PushMessage("inv", vInv); // // Message: getdata // vector<CInv> vGetData; int64_t nNow = GetTime() * 1000000; CTxDB txdb("r"); while (!pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow) { const CInv& inv = (*pto->mapAskFor.begin()).second; if (!AlreadyHave(txdb, inv)) { if (fDebug) LogPrint("net", "sending getdata: %s\n", inv.ToString()); vGetData.push_back(inv); if (vGetData.size() >= 1000) { pto->PushMessage("getdata", vGetData); vGetData.clear(); } mapAlreadyAskedFor[inv] = nNow; } pto->mapAskFor.erase(pto->mapAskFor.begin()); } if (!vGetData.empty()) pto->PushMessage("getdata", vGetData); } return true; }
; A190509: a(n) = n + [nr/s] + [nt/s] + [nu/s] where r=golden ratio, s=r^2, t=r^3, u=r^4, and [] represents the floor function. ; 4,11,15,22,29,33,40,44,51,58,62,69,76,80,87,91,98,105,109,116,120,127,134,138,145,152,156,163,167,174,181,185,192,199,203,210,214,221,228,232,239,243,250,257,261,268,275,279,286,290,297,304,308,315,319,326,333,337,344,351,355,362,366,373,380,384,391,398,402,409,413,420,427,431,438,442,449,456,460,467,474,478,485,489,496,503,507,514,521,525,532,536,543,550,554,561,565,572,579,583 mov $2,$0 seq $0,283233 ; 2*A000201. mov $1,$0 add $0,$2 div $1,2 add $0,$1 add $0,1
; A041009: Denominators of continued fraction convergents to sqrt(7). ; Submitted by Christian Krause ; 1,1,2,3,14,17,31,48,223,271,494,765,3554,4319,7873,12192,56641,68833,125474,194307,902702,1097009,1999711,3096720,14386591,17483311,31869902,49353213,229282754,278635967,507918721,786554688,3654137473,4440692161,8094829634,12535521795,58236916814,70772438609,129009355423,199781794032,928136531551,1127918325583,2056054857134,3183973182717,14791947588002,17975920770719,32767868358721,50743789129440,235743024876481,286486814005921,522229838882402,808716652888323,3757096450435694,4565813103324017 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 mov $3,$1 mov $1,$2 dif $2,3 mod $2,$1 mul $2,9 add $3,$2 mov $2,$1 lpe mov $0,$1
/* KJL 10:19:41 30/03/98 - ConsoleLog.hpp This file handles the mirroring of the console text to a log file. */ #ifndef ConsoleLog_h_included #define ConsoleLog_h_included extern void OutputToConsoleLogfile(char *messagePtr); extern void OutputBugReportToConsoleLogfile(char *messagePtr); #endif
; A044776: Numbers n such that string 6,3 occurs in the base 10 representation of n but not of n+1. ; Submitted by Christian Krause ; 63,163,263,363,463,563,639,663,763,863,963,1063,1163,1263,1363,1463,1563,1639,1663,1763,1863,1963,2063,2163,2263,2363,2463,2563,2639,2663,2763,2863,2963,3063,3163,3263,3363,3463,3563 add $0,1 seq $0,44407 ; Numbers n such that string 7,5 occurs in the base 10 representation of n but not of n-1. div $0,2 mul $0,2 sub $0,111
#include "hash_functions.hpp" #include <fstream> #include <mhash.h> namespace organizer { static std::string hash_to_string( unsigned char const *const hash, unsigned const block_size ) { std::ostringstream string_builder; string_builder.fill( '0' ); for( unsigned i = 0; i < block_size; i++ ) { string_builder << std::setw( 2 ) << std::hex << static_cast< unsigned int >( hash[i] ); } return string_builder.str(); } std::string get_file_sha1( Path const &path ) { std::ifstream file{path.string(), std::ios::binary}; if( !file.is_open() ) { return ""; } MHASH td{mhash_init( MHASH_SHA1 )}; if( td == MHASH_FAILED ) { return ""; } int bytes_read = 1; char buffer[1024]; while( bytes_read != 0 ) { bytes_read = file.readsome( buffer, 1024 ); if( bytes_read != 0 ) { mhash( td, buffer, bytes_read ); } } unsigned char *hash{static_cast< unsigned char * >( mhash_end( td ) )}; auto const block_size = mhash_get_block_size( MHASH_SHA1 ); std::string const hash_str{hash_to_string( hash, block_size )}; free( hash ); return hash_str; } } // namespace organizer
; A001823: Central factorial numbers: column 2 in triangle A008956. ; 0,9,259,1974,8778,28743,77077,179452,375972,725781,1312311,2249170,3686670,5818995,8892009,13211704,19153288,27170913,37808043,51708462,69627922,92446431,121181181,157000116,201236140,255401965,321205599,400566474,495632214,608796043,742714833,900327792,1084875792,1299921337,1549369171,1837487526,2168930010,2548758135,2982464485,3475996524,4035781044,4668749253,5382362503,6184638658,7084179102,8090196387,9212542521,10461737896,11849000856,13386277905,15086274555,16962486814,19029233314,21301688079,23795913933,26528896548,29518579132,32783897757,36344817327,40222368186,44438683366,49017036475,53981880225,59358885600,65174981664,71458396009,78238695843,85546829718,93415169898,101877555367,110969335477,120727414236,131190295236,142398127221,154392750295,167217742770,180918468654,195542125779,211137794569,227756487448,245451198888,264276956097,284290870347,305552188942,328122347826,352065024831,377446193565,404334177940,432799707340,462915972429,494758681599,528406118058,563939197558,601441526763,640999462257,682702170192,726641686576,772912978201,821614004211,872845778310,926712431610,983321276119,1042782868869,1105211076684,1170723141588,1239439746853,1311485083687,1386986918562,1466076661182,1548889433091,1635564136921,1726243526280,1821074276280,1920207054705,2023796593819,2132001762814,2244985640898,2362915591023,2485963334253,2614305024772,2748121325532,2887597484541,3032923411791,3184293756826,3341907986950,3505970466075,3676690534209,3854282587584,4038966159424,4230966001353,4430512165443,4637840086902,4853190667402,5076810359047,5308951248981,5549871144636,5799833659620,6059108300245,6327970552695,6606701970834,6895590264654,7194929389363,7505019635113,7826167717368,8158686867912,8502896926497,8859124433131,9227702721006,9608972010066,10003279501215,10410979471165,10832433367924,11268009906924,11718085167789,12183042691743,12663273579658,13159176590742,13671158241867,14199632907537,14745022920496,15307758672976,15888278718585,16487029874835,17104467326310,17741054728474,18397264312119,19073576988453,19770482454828,20488479301108,21228075116677,21989786598087,22774139657346,23581669530846,24412920888931,25268447946105,26148814571880,27054594402264,27986370951889,28944737726779,29930298337758,30943666614498,31985466720207,33056333266957,34156911431652,35287857072636,36449836846941,37643528328175,38869620125050,40128812000550,41421814991739,42749351530209,44112155563168,45510972675168,46946560210473,48419687396067,49931135465302,51481697782186,53072179966311,54703400018421,56376188446620,58091388393220,59849855762229,61652459347479,63500080961394,65393615564398,67333971394963,69322070100297,71358846867672,73445250556392,75582243830401,77770803291531,80011919613390,82306597675890,84655856700415,87060730385629,89522267043924,92041529738508,94619596421133,97257560070463,99956528831082,102717626153142,105541990932651,108430777652401,111385156523536,114406313627760,117495451060185,120653787072819,123882556218694,127183009496634,130556414496663,134004055546053,137527233856012,141127267669012,144805492406757,148563260818791,152401943131746,156322927199230,160327618652355,164417441050905,168593836035144,172858263478264,177212201639473,181657147317723,186194616006078,190826142046722,195553278786607,200377598733741,205300693714116,210324175029276,215449673614525 mov $3,1 mov $5,$0 add $5,$3 lpb $0 mov $0,1 add $2,$0 mov $6,$5 mov $3,$6 add $6,$3 add $6,1 mov $4,$6 clr $0,$2 lpe mov $1,$4 mul $1,5 add $1,2 bin $4,5 mov $3,$4 mul $3,$1 mov $1,$3 div $1,3
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r9 push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x8675, %r13 nop nop nop nop add %rbp, %rbp mov $0x6162636465666768, %rdx movq %rdx, %xmm3 and $0xffffffffffffffc0, %r13 movaps %xmm3, (%r13) nop nop cmp %r9, %r9 lea addresses_D_ht+0xdae2, %rsi lea addresses_A_ht+0x108d2, %rdi nop nop add $60948, %r9 mov $97, %rcx rep movsl nop nop nop nop nop cmp $41986, %r13 lea addresses_WC_ht+0x1db82, %rsi lea addresses_WT_ht+0x896a, %rdi nop and %rbp, %rbp mov $30, %rcx rep movsq nop nop nop nop add $34944, %rdi lea addresses_WT_ht+0x582, %rdi nop nop and $60294, %r13 mov $0x6162636465666768, %rsi movq %rsi, %xmm2 vmovups %ymm2, (%rdi) sub %r13, %r13 lea addresses_normal_ht+0x13a82, %r13 nop nop nop cmp $57202, %rsi mov $0x6162636465666768, %rbp movq %rbp, (%r13) nop nop and %rbp, %rbp lea addresses_normal_ht+0xb582, %rsi lea addresses_UC_ht+0x2582, %rdi nop nop nop nop nop sub %r13, %r13 mov $60, %rcx rep movsb nop nop nop xor %rsi, %rsi lea addresses_UC_ht+0x11c82, %rsi lea addresses_normal_ht+0x4782, %rdi clflush (%rsi) nop nop nop nop and %r13, %r13 mov $127, %rcx rep movsq nop nop nop nop nop and %rdx, %rdx lea addresses_D_ht+0x15b02, %rsi lea addresses_WT_ht+0xdf82, %rdi nop nop nop cmp %r13, %r13 mov $110, %rcx rep movsb nop nop nop nop nop cmp $48489, %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r9 pop %r13 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r13 push %rbp push %rbx push %rsi // Store lea addresses_PSE+0x4582, %rbx nop nop nop nop nop inc %r13 movw $0x5152, (%rbx) nop nop sub $31559, %r13 // Faulty Load lea addresses_PSE+0x16582, %r10 clflush (%r10) nop and $11647, %r12 mov (%r10), %bx lea oracles, %rsi and $0xff, %rbx shlq $12, %rbx mov (%rsi,%rbx,1), %rbx pop %rsi pop %rbx pop %rbp pop %r13 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_PSE', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_PSE', 'size': 2, 'AVXalign': False}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_PSE', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_D_ht', 'size': 16, 'AVXalign': True}} {'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}} {'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False}} {'src': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}} {'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}} {'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}} {'33': 21829} 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 */
; A157960: a(n) = 121*n^2 - n. ; 120,482,1086,1932,3020,4350,5922,7736,9792,12090,14630,17412,20436,23702,27210,30960,34952,39186,43662,48380,53340,58542,63986,69672,75600,81770,88182,94836,101732,108870,116250,123872,131736,139842,148190,156780,165612,174686,184002,193560,203360,213402,223686,234212,244980,255990,267242,278736,290472,302450,314670,327132,339836,352782,365970,379400,393072,406986,421142,435540,450180,465062,480186,495552,511160,527010,543102,559436,576012,592830,609890,627192,644736,662522,680550,698820,717332,736086,755082,774320,793800,813522,833486,853692,874140,894830,915762,936936,958352,980010,1001910,1024052,1046436,1069062,1091930,1115040,1138392,1161986,1185822,1209900 mov $1,11 mov $2,$0 add $2,1 mul $1,$2 pow $1,2 sub $1,$2 mov $0,$1
; A017398: a(n) = (11*n)^10. ; 0,25937424601,26559922791424,1531578985264449,27197360938418176,253295162119140625,1568336880910795776,7326680472586200649,27850097600940212224,90438207500880449001,259374246010000000000,672749994932560009201,1605976966052654874624,3575694237941010577249,7502520803928269464576,14956826027973134765625,28518499943362777317376,52289689788971837545849,92608724480901579777024,159024068785448665562401,265599227914240000000000,432633155225742562122801,688895994810941449421824,1074497011086501939579049,1644520413237918591614976,2473585567569732666015625,3661510899651594831102976,5340285714719489633060049,7682581303222547931725824,10912062142819279835644801,15315789852644490000000000,21259046894411315872085401,29202943942003483972993024,39725214450772735983309849,53544642343907161646949376,71549613990099615712890625,94831333868443217691672576,124722294597134862504103249,162840646436299433535898624,211141169056178733575976201,271973609384181760000000000,348149213801988574756617001,443016350951160383613748224,560546193016655269118409649,705429498686404044207947776,883185620125785634775390625,1100284939352577986128946176,1364286026444870446587635449,1683988903155628637813735424,2069605890837224702290236601,2532951621191406250000000000,3087653892348998035244837601,3749387161243233107049447424,4536130576265116619119118449,5468452571872757384253490176,6569824169263281339853515625,7866963254499889082087243776,9390212237711958252794216649,11173951634246942551700276224,13257052251043304223376506001,15683368809107957760000000000,18502277985913820993752267201,21769264019877187453015450624,25546555182924872550789276249,29903814596611567588344856576,34918889042392681418447265625,40678619597591281646909285376,47279718115413687185176006849,54829713760160933526476161024,63447974007646853030203264401,73266804725862006490000000000,84432634162210291056904825801,97107285881285854916272717824,111469345921246092702394323049,127715629667466099204201726976,146062754179425144195556640625,166748821950770619940760190976,190035222333323626806494766049,216208557113527023181799629824,245582696994585495294285391801,278500976009402122240000000000,315338531168471143342562833401,356504794933236300550775809024,402446148399162349699293298849,453648743373988232820478181376,510641501845428101033681640625,573999301649054995577251480576,644346357471335655014989854249,722359806654877741268938522624,808773509612996887630660168201,904382075008804490010000000000,1010045120210252210120045010001,1126691777897039857796040884224,1255325460068093790930770843649,1397028891079547337305738699776,1552969421732897124632822265625,1724404636831363725121265074176,1912688269029545800576346231449,2119276432217318095145202279424,2345734188103679287078463273601 pow $0,10 mul $0,25937424601
#include "MetaProperty.h" #include "MetaClass.h" #include "MetaAttribute.h" XE::MetaProperty::MetaProperty( const String & Name, bool IsStatic, bool IsConst, bool IsObject, bool IsPointer, bool IsSharedPtr, bool IsReference, MetaTypePtr Value, MetaClassPtr Owner, MetaModulePtr Module ) :MetaInfo( Name, MetaInfoType::PROPERTY, SP_CAST< MetaInfo >( Owner ), Module ), _IsStatic( IsStatic ), _IsConst( IsConst ), _IsObject( IsObject ), _IsPointer( IsPointer ), _IsSharedPtr( IsSharedPtr ), _IsReference( IsReference ), _Value( Value ) { } XE::MetaProperty::~MetaProperty() { } bool XE::MetaProperty::IsConst() const { return _IsConst; } bool XE::MetaProperty::IsStatic() const { return _IsStatic; } bool XE::MetaProperty::IsObject() const { return _IsObject; } bool XE::MetaProperty::IsPointer() const { return _IsPointer; } bool XE::MetaProperty::IsSharedPtr() const { return _IsSharedPtr; } bool XE::MetaProperty::IsReference() const { return _IsReference; } XE::MetaTypePtr XE::MetaProperty::GetValueType() const { return _Value.lock(); } const XE::Array< XE::MetaAttributeCPtr > & XE::MetaProperty::GetAttributes() const { return _Attributes; } XE::MetaAttributeCPtr XE::MetaProperty::FindAttribute( const XE::MetaClassPtr & val ) const { for( const auto & it : _Attributes ) { if( it->GetMetaClass() == val ) { return it; } } return nullptr; } XE::Variant XE::MetaProperty::Get( const XE::Variant & obj ) const { return Getter( obj ); } void XE::MetaProperty::Set( const XE::Variant & obj, const XE::Variant & val ) const { Setter( obj, val ); }
// Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ash/common/shelf/wm_shelf.h" #include "ash/common/shelf/shelf_controller.h" #include "ash/common/shelf/shelf_delegate.h" #include "ash/common/shelf/shelf_item_delegate.h" #include "ash/common/shelf/shelf_layout_manager.h" #include "ash/common/shelf/shelf_locking_manager.h" #include "ash/common/shelf/shelf_model.h" #include "ash/common/shelf/shelf_widget.h" #include "ash/common/shelf/wm_shelf_observer.h" #include "ash/common/system/tray/system_tray_delegate.h" #include "ash/common/wm_lookup.h" #include "ash/common/wm_root_window_controller.h" #include "ash/common/wm_shell.h" #include "ash/common/wm_window.h" #include "ash/public/cpp/shell_window_ids.h" #include "base/logging.h" #include "ui/gfx/geometry/rect.h" namespace ash { // static WmShelf* WmShelf::ForWindow(WmWindow* window) { return window->GetRootWindowController()->GetShelf(); } // static bool WmShelf::CanChangeShelfAlignment() { if (WmShell::Get()->system_tray_delegate()->IsUserSupervised()) return false; LoginStatus login_status = WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); switch (login_status) { case LoginStatus::LOCKED: // Shelf alignment changes can be requested while being locked, but will // be applied upon unlock. case LoginStatus::USER: case LoginStatus::OWNER: return true; case LoginStatus::PUBLIC: case LoginStatus::SUPERVISED: case LoginStatus::GUEST: case LoginStatus::KIOSK_APP: case LoginStatus::ARC_KIOSK_APP: case LoginStatus::NOT_LOGGED_IN: return false; } NOTREACHED(); return false; } void WmShelf::CreateShelfWidget(WmWindow* root) { DCHECK(!shelf_widget_); WmWindow* shelf_container = root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); shelf_widget_.reset(new ShelfWidget(shelf_container, this)); DCHECK(!shelf_layout_manager_); shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); shelf_layout_manager_->AddObserver(this); // Must occur after |shelf_widget_| is constructed because the system tray // constructors call back into WmShelf::shelf_widget(). DCHECK(!shelf_widget_->status_area_widget()); WmWindow* status_container = root->GetChildByShellWindowId(kShellWindowId_StatusContainer); shelf_widget_->CreateStatusAreaWidget(status_container); } void WmShelf::ShutdownShelfWidget() { if (shelf_widget_) shelf_widget_->Shutdown(); } void WmShelf::DestroyShelfWidget() { shelf_widget_.reset(); } void WmShelf::InitializeShelf() { DCHECK(shelf_layout_manager_); DCHECK(shelf_widget_); DCHECK(!shelf_view_); shelf_view_ = shelf_widget_->CreateShelfView(); shelf_locking_manager_.reset(new ShelfLockingManager(this)); // When the shelf is created the alignment is unlocked. Chrome will update the // alignment later from preferences. alignment_ = SHELF_ALIGNMENT_BOTTOM; WmShell::Get()->shelf_controller()->NotifyShelfCreated(this); } void WmShelf::ShutdownShelf() { DCHECK(shelf_view_); shelf_locking_manager_.reset(); shelf_view_ = nullptr; } bool WmShelf::IsShelfInitialized() const { return !!shelf_view_; } WmWindow* WmShelf::GetWindow() { return WmLookup::Get()->GetWindowForWidget(shelf_widget_.get()); } void WmShelf::SetAlignment(ShelfAlignment alignment) { DCHECK(shelf_layout_manager_); DCHECK(shelf_locking_manager_); if (alignment_ == alignment) return; if (shelf_locking_manager_->is_locked() && alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { shelf_locking_manager_->set_stored_alignment(alignment); return; } alignment_ = alignment; // The ShelfWidget notifies the ShelfView of the alignment change. shelf_widget_->OnShelfAlignmentChanged(); shelf_layout_manager_->LayoutShelf(); WmShell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); } bool WmShelf::IsHorizontalAlignment() const { switch (alignment_) { case SHELF_ALIGNMENT_BOTTOM: case SHELF_ALIGNMENT_BOTTOM_LOCKED: return true; case SHELF_ALIGNMENT_LEFT: case SHELF_ALIGNMENT_RIGHT: return false; } NOTREACHED(); return true; } int WmShelf::SelectValueForShelfAlignment(int bottom, int left, int right) const { switch (alignment_) { case SHELF_ALIGNMENT_BOTTOM: case SHELF_ALIGNMENT_BOTTOM_LOCKED: return bottom; case SHELF_ALIGNMENT_LEFT: return left; case SHELF_ALIGNMENT_RIGHT: return right; } NOTREACHED(); return bottom; } int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { return IsHorizontalAlignment() ? horizontal : vertical; } void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { DCHECK(shelf_layout_manager_); if (auto_hide_behavior_ == auto_hide_behavior) return; auto_hide_behavior_ = auto_hide_behavior; WmShell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( GetWindow()->GetRootWindow()); } ShelfAutoHideState WmShelf::GetAutoHideState() const { return shelf_layout_manager_->auto_hide_state(); } void WmShelf::UpdateAutoHideState() { shelf_layout_manager_->UpdateAutoHideState(); } ShelfBackgroundType WmShelf::GetBackgroundType() const { return shelf_widget_->GetBackgroundType(); } WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) { return nullptr; } bool WmShelf::IsDimmed() const { return shelf_widget_->GetDimsShelf(); } bool WmShelf::IsVisible() const { return shelf_widget_->IsShelfVisible(); } void WmShelf::UpdateVisibilityState() { if (shelf_layout_manager_) shelf_layout_manager_->UpdateVisibilityState(); } ShelfVisibilityState WmShelf::GetVisibilityState() const { return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() : SHELF_HIDDEN; } gfx::Rect WmShelf::GetIdealBounds() { return shelf_layout_manager_->GetIdealBounds(); } gfx::Rect WmShelf::GetUserWorkAreaBounds() const { return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() : gfx::Rect(); } void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { shelf_widget_->UpdateIconPositionForPanel(panel); } gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { if (!shelf_widget_) return gfx::Rect(); return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); } // static void WmShelf::LaunchShelfItem(int item_index) { ShelfModel* shelf_model = WmShell::Get()->shelf_model(); const ShelfItems& items = shelf_model->items(); int item_count = shelf_model->item_count(); int indexes_left = item_index >= 0 ? item_index : item_count; int found_index = -1; // Iterating until we have hit the index we are interested in which // is true once indexes_left becomes negative. for (int i = 0; i < item_count && indexes_left >= 0; i++) { if (items[i].type != TYPE_APP_LIST) { found_index = i; indexes_left--; } } // There are two ways how found_index can be valid: a.) the nth item was // found (which is true when indexes_left is -1) or b.) the last item was // requested (which is true when index was passed in as a negative number). if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { // Then set this one as active (or advance to the next item of its kind). ActivateShelfItem(found_index); } } // static void WmShelf::ActivateShelfItem(int item_index) { // We pass in a keyboard event which will then trigger a switch to the // next item if the current one is already active. ui::KeyEvent event(ui::ET_KEY_RELEASED, ui::VKEY_UNKNOWN, // The actual key gets ignored. ui::EF_NONE); ShelfModel* shelf_model = WmShell::Get()->shelf_model(); const ShelfItem& item = shelf_model->items()[item_index]; ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); item_delegate->ItemSelected(event); } bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { // Can be called at login screen. if (!shelf_layout_manager_) return false; return shelf_layout_manager_->ProcessGestureEvent(event); } void WmShelf::AddObserver(WmShelfObserver* observer) { observers_.AddObserver(observer); } void WmShelf::RemoveObserver(WmShelfObserver* observer) { observers_.RemoveObserver(observer); } void WmShelf::NotifyShelfIconPositionsChanged() { for (auto& observer : observers_) observer.OnShelfIconPositionsChanged(); } StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { return shelf_widget_->status_area_widget(); } void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); } ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { return shelf_locking_manager_.get(); } ShelfView* WmShelf::GetShelfViewForTesting() { return shelf_view_; } WmShelf::WmShelf() {} WmShelf::~WmShelf() {} void WmShelf::WillDeleteShelfLayoutManager() { DCHECK(shelf_layout_manager_); shelf_layout_manager_->RemoveObserver(this); shelf_layout_manager_ = nullptr; } void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { for (auto& observer : observers_) observer.WillChangeVisibilityState(new_state); } void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { for (auto& observer : observers_) observer.OnAutoHideStateChanged(new_state); } void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, BackgroundAnimatorChangeType change_type) { if (background_type == GetBackgroundType()) return; for (auto& observer : observers_) observer.OnBackgroundTypeChanged(background_type, change_type); } } // namespace ash
; A190876: Numbers 1 through 8 together with numbers congruent to 9 mod 10. ; 1,2,3,4,5,6,7,8,9,19,29,39,49,59,69,79,89,99,109,119,129,139,149,159,169,179,189,199,209,219,229,239,249,259,269,279,289,299,309,319,329,339,349,359,369,379,389,399,409,419,429,439,449,459,469,479,489,499,509,519,529,539,549,559,569,579,589,599,609,619,629,639,649,659,669,679,689,699,709,719,729,739,749,759,769,779,789,799,809,819,829,839,849,859,869,879,889,899,909,919 mov $1,$0 trn $1,8 mul $1,9 add $0,$1 add $0,1
; A047544: Numbers that are congruent to {1, 3, 4, 7} mod 8. ; 1,3,4,7,9,11,12,15,17,19,20,23,25,27,28,31,33,35,36,39,41,43,44,47,49,51,52,55,57,59,60,63,65,67,68,71,73,75,76,79,81,83,84,87,89,91,92,95,97,99,100,103,105,107,108,111,113,115,116,119,121,123,124,127,129,131,132,135,137,139,140,143,145,147,148,151,153,155,156,159,161,163,164,167,169,171,172,175,177,179,180,183,185,187,188,191,193,195,196,199,201,203,204,207,209,211,212,215,217,219,220,223,225,227,228,231,233,235,236,239,241,243,244,247,249,251,252,255,257,259,260,263,265,267,268,271,273,275,276,279,281,283,284,287,289,291,292,295,297,299,300,303,305,307,308,311,313,315,316,319,321,323,324,327,329,331,332,335,337,339,340,343,345,347,348,351,353,355,356,359,361,363,364,367,369,371,372,375,377,379,380,383,385,387,388,391,393,395,396,399,401,403,404,407,409,411,412,415,417,419,420,423,425,427,428,431,433,435,436,439,441,443,444,447,449,451,452,455,457,459,460,463,465,467,468,471,473,475,476,479,481,483,484,487,489,491,492,495,497,499 mov $1,$0 add $0,10 mod $0,4 mul $1,8 add $1,$0 sub $1,1 div $1,4 add $1,1
; A184050: T(n,k) is the number of order-preserving and order-decreasing partial isometries (of an n-chain) with exactly k fixed points. ; Submitted by Christian Krause ; 1,1,1,2,2,1,5,3,3,1,12,4,6,4,1,27,5,10,10,5,1,58,6,15,20,15,6,1,121,7,21,35,35,21,7,1 lpb $0 add $1,1 sub $0,$1 mov $2,$1 sub $2,$0 lpe bin $1,$0 mov $0,2 div $2,$1 pow $0,$2 mul $1,$0 sub $1,$2 mov $0,$1
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "word_store.h" #include <vespa/searchlib/datastore/datastore.hpp> namespace search::memoryindex { constexpr size_t MIN_BUFFER_ARRAYS = 1024; WordStore::WordStore() : _store(), _numWords(0), _type(RefType::align(1), MIN_BUFFER_ARRAYS, RefType::offsetSize() / RefType::align(1)), _typeId(0) { _store.addType(&_type); _store.initActiveBuffers(); } WordStore::~WordStore() { _store.dropBuffers(); } datastore::EntryRef WordStore::addWord(const vespalib::stringref word) { size_t wordSize = word.size() + 1; size_t bufferSize = RefType::align(wordSize); auto result = _store.rawAllocator<char>(_typeId).alloc(bufferSize); char *be = result.data; for (size_t i = 0; i < word.size(); ++i) { *be++ = word[i]; } *be++ = 0; for (size_t i = wordSize; i < bufferSize; ++i) { *be++ = 0; } ++_numWords; return result.ref; } }
#ifdef SHASTA_HTTP_SERVER // Shasta. #include "LocalMarkerGraph.hpp" #include "ConsensusCaller.hpp" #include "Marker.hpp" #include "MemoryMappedVectorOfVectors.hpp" using namespace shasta; // Boost libraries. #include <boost/graph/graphviz.hpp> // Standard libraries. #include "fstream.hpp" // Write the graph in Graphviz format. void LocalMarkerGraph::write( const string& fileName, int maxDistance, bool addLabels, bool useDotLayout, double vertexScalingFactor, double arrowScalingFactor) const { ofstream outputFileStream(fileName); if(!outputFileStream) { throw runtime_error("Error opening " + fileName); } write(outputFileStream, maxDistance, addLabels, useDotLayout, vertexScalingFactor, arrowScalingFactor); } void LocalMarkerGraph::write( ostream& s, int maxDistance, bool addLabels, bool useDotLayout, double vertexScalingFactor, double arrowScalingFactor) const { Writer writer(*this, maxDistance, addLabels, useDotLayout, vertexScalingFactor, arrowScalingFactor); boost::write_graphviz(s, *this, writer, writer, writer, boost::get(&LocalMarkerGraphVertex::vertexId, *this)); } LocalMarkerGraph::Writer::Writer( const LocalMarkerGraph& graph, int maxDistance, bool addLabels, bool useDotLayout, double vertexScalingFactor, double arrowScalingFactor) : graph(graph), maxDistance(maxDistance), addLabels(addLabels), useDotLayout(useDotLayout), vertexScalingFactor(vertexScalingFactor), arrowScalingFactor(arrowScalingFactor) { } // Vertex and edge colors. const string LocalMarkerGraph::Writer::vertexColorZeroDistance = "#6666ff"; const string LocalMarkerGraph::Writer::vertexColorIntermediateDistance = "#00ccff"; const string LocalMarkerGraph::Writer::vertexColorMaxDistance = "#66ffff"; const string LocalMarkerGraph::Writer::edgeArrowColorRemovedDuringTransitiveReduction = "#ff0000"; const string LocalMarkerGraph::Writer::edgeArrowColorRemovedDuringPruning = "#ff00ff"; const string LocalMarkerGraph::Writer::edgeArrowColorRemovedDuringSuperBubbleRemoval = "#009900"; const string LocalMarkerGraph::Writer::edgeArrowColorNotRemovedNotAssembled = "#663300"; const string LocalMarkerGraph::Writer::edgeArrowColorNotRemovedAssembled = "#000000"; const string LocalMarkerGraph::Writer::edgeLabelColorRemovedDuringTransitiveReduction = "#ff9999"; const string LocalMarkerGraph::Writer::edgeLabelColorRemovedDuringPruning = "#c03280"; const string LocalMarkerGraph::Writer::edgeLabelColorRemovedDuringSuperBubbleRemoval = "#99ff99"; const string LocalMarkerGraph::Writer::edgeLabelColorNotRemovedNotAssembled = "#996600"; const string LocalMarkerGraph::Writer::edgeLabelColorNotRemovedAssembled = "#999999"; const string& LocalMarkerGraph::Writer::vertexColor(const LocalMarkerGraphVertex& vertex) const { if(vertex.distance == 0) { return vertexColorZeroDistance; } else if(vertex.distance == maxDistance) { return vertexColorMaxDistance; } else { return vertexColorIntermediateDistance; } } const string& LocalMarkerGraph::Writer::edgeArrowColor(const LocalMarkerGraphEdge& edge) const { if(edge.wasRemovedByTransitiveReduction) { return edgeArrowColorRemovedDuringTransitiveReduction; } else if(edge.wasPruned) { return edgeArrowColorRemovedDuringPruning; } else if (edge.isSuperBubbleEdge) { return edgeArrowColorRemovedDuringSuperBubbleRemoval; } else { if(edge.wasAssembled) { return edgeArrowColorNotRemovedAssembled; } else { return edgeArrowColorNotRemovedNotAssembled; } } } const string& LocalMarkerGraph::Writer::edgeLabelColor(const LocalMarkerGraphEdge& edge) const { if(edge.wasRemovedByTransitiveReduction) { return edgeLabelColorRemovedDuringTransitiveReduction; } else if(edge.wasPruned) { return edgeLabelColorRemovedDuringPruning; } else if (edge.isSuperBubbleEdge) { return edgeLabelColorRemovedDuringSuperBubbleRemoval; } else { if(edge.wasAssembled) { return edgeLabelColorNotRemovedAssembled; } else { return edgeLabelColorNotRemovedNotAssembled; } } } void LocalMarkerGraph::writeColorLegend(ostream& html) { html << "<table style='font-size:10px'>" "<tr><th class=centered colspan=3>Marker graph color legend" "<tr><td rowspan=4>Vertices" "<tr><td>Zero distance<td style='width:50px;background-color:" << Writer::vertexColorZeroDistance << "'>" "<tr><td>Intermediate distances<td style='width:50px;background-color:" << Writer::vertexColorIntermediateDistance << "'>" "<tr><td>Maximum distance<td style='width:50px;background-color:" << Writer::vertexColorMaxDistance << "'>" "<tr><td rowspan=6>Edge<br>arrows" "<tr><td>Removed during transitive reduction<td style='width:50px;background-color:" << Writer::edgeArrowColorRemovedDuringTransitiveReduction << "'>" "<tr><td>Removed during pruning<td style='width:50px;background-color:" << Writer::edgeArrowColorRemovedDuringPruning << "'>" "<tr><td>Removed during bubble/superbubble removal<td style='width:50px;background-color:" << Writer::edgeArrowColorRemovedDuringSuperBubbleRemoval << "'>" "<tr><td>Not removed, not assembled<td style='width:50px;background-color:" << Writer::edgeArrowColorNotRemovedNotAssembled << "'>" "<tr><td>Not removed, assembled<td style='width:50px;background-color:" << Writer::edgeArrowColorNotRemovedAssembled << "'>" "<tr><td rowspan=6>Edge<br>labels" "<tr><td>Removed during transitive reduction<td style='width:50px;background-color:" << Writer::edgeLabelColorRemovedDuringTransitiveReduction << "'>" "<tr><td>Removed during pruning<td style='width:50px;background-color:" << Writer::edgeLabelColorRemovedDuringPruning << "'>" "<tr><td>Removed during bubble/superbubble removal<td style='width:50px;background-color:" << Writer::edgeLabelColorRemovedDuringSuperBubbleRemoval << "'>" "<tr><td>Not removed, not assembled<td style='width:50px;background-color:" << Writer::edgeLabelColorNotRemovedNotAssembled << "'>" "<tr><td>Not removed, assembled<td style='width:50px;background-color:" << Writer::edgeLabelColorNotRemovedAssembled << "'>" "</table>"; } void LocalMarkerGraph::Writer::operator()(std::ostream& s) const { // This turns off the tooltip on the graph and the edges. s << "tooltip = \" \";\n"; s << "ratio=expand;\n"; if(addLabels) { s << "overlap = false;\n"; s << "node [fontname = \"Courier New\" shape=rectangle];\n"; s << "edge [fontname = \"Courier New\"];\n"; } else { s << "node [shape=point];\n"; } if(useDotLayout) { s << "layout=dot;\n"; s << "rankdir=LR;\n"; } else { s << "layout=sfdp;\n"; s << "smoothing=triangle;\n"; } } void LocalMarkerGraph::Writer::operator()(std::ostream& s, vertex_descriptor v) const { const LocalMarkerGraphVertex& vertex = graph[v]; const auto coverage = vertex.markerInfos.size(); const string& color = vertexColor(vertex); SHASTA_ASSERT(coverage > 0); // Begin vertex attributes. s << "["; // Id, so we can use JavaScript code to manipulate the vertex. s << "id=vertex" << vertex.vertexId; // Tooltip. s << " tooltip=\""; s << "Vertex " << vertex.vertexId << ", coverage "; s << coverage << ", distance " << vertex.distance; s << ", click to recenter graph here, right click for detail\""; if(!addLabels) { // Vertex area is proportional to coverage. s << " width=\""; const auto oldPrecision = s.precision(4); s << vertexScalingFactor * 0.05 * sqrt(double(coverage)); s.precision(oldPrecision); s << "\""; // Color. s << " fillcolor=\"" << color << "\" color=\"" << color << "\""; } else { // Color. s << " style=filled"; s << " fillcolor=\"" << color << "\""; // Label. s << " label=\""; s << "Vertex " << vertex.vertexId << "\\n"; s << "Coverage " << coverage << "\\n"; s << "Distance " << vertex.distance << "\\n"; // Marker sequence (run-length). const size_t k = graph.k; const KmerId kmerId = graph.getKmerId(v); const Kmer kmer(kmerId, k); kmer.write(s, k); s << "\\n"; // Consensus repeat counts. if(vertex.storedConsensusRepeatCounts.size() == k) { for(size_t i=0; i<k; i++) { s << int(vertex.storedConsensusRepeatCounts[i]); } s << "\\n"; } // Consensus sequence (raw). for(size_t i=0; i<k; i++) { const Base base = kmer[i]; const int repeatCount = int(vertex.storedConsensusRepeatCounts[i]); for(int l=0; l<repeatCount; l++) { s << base; } } s << "\\n"; // End the label. s << "\""; } // End vertex attributes. s << "]"; } void LocalMarkerGraph::Writer::operator()(std::ostream& s, edge_descriptor e) const { const LocalMarkerGraphEdge& edge = graph[e]; const size_t coverage = edge.coverage(); const string& arrowColor = edgeArrowColor(edge); const string& labelColor = edgeLabelColor(edge); SHASTA_ASSERT(coverage > 0); // Begin edge attributes. s << "["; // Id, so we can use JavaScript code to manipulate the edge. s << "id=edge" << edge.edgeId; // Tooltip. const string tooltipText = "Edge " + to_string(edge.edgeId) + ", coverage " + to_string(coverage) + ", click to recenter graph here, right click for detail"; s << " tooltip=\"" << tooltipText << "\""; s << " labeltooltip=\"" << tooltipText << "\""; s << " URL=\"#a\""; // Hack to convince graphviz to not ignore the labeltooltip. // Thickness and weight are determined by coverage. const double thickness = 0.2 * double(coverage==0 ? 1 : coverage); s << " penwidth="; const auto oldPrecision = s.precision(4); s << thickness; s.precision(oldPrecision); s << " weight=" << coverage; // Arrow size. s << " arrowsize=\"" << arrowScalingFactor << "\""; // Color. s << " fillcolor=\"" << arrowColor << "\""; s << " color=\"" << arrowColor << "\""; // If the edge was not marked as a DAG edge during approximate topological sort, // tell graphviz not to use it in constraint assignment. // This results in better graph layouts when using dot, // because back-edges tend to be low coverage edges. if(useDotLayout && !edge.isDagEdge) { s << " constraint=false"; } // Label. if(addLabels) { s << " label=<<font color=\"black\">"; s << "<table"; s << " color=\"black\""; s << " bgcolor=\"" << labelColor << "\""; s << " border=\"1\""; s << " cellborder=\"0\""; s << " cellspacing=\"0\""; s << ">"; // Edge id. SHASTA_ASSERT(edge.edgeId != MarkerGraph::invalidEdgeId); s << "<tr><td>Edge " << edge.edgeId << "</td></tr>"; // Assembly edge id. if((edge.assemblyEdgeId != std::numeric_limits<AssemblyGraph::VertexId>::max())) { s << "<tr><td>Assembly " << edge.assemblyEdgeId << "-" << edge.positionInAssemblyEdge << "</td></tr>"; } // Coverage. s << "<tr><td>Coverage " << coverage << "</td></tr>"; // Consensus. if(edge.consensusSequence.empty()) { s << "<tr><td>Overlap " << int(edge.consensusOverlappingBaseCount) << "</td></tr>"; } else { // Consensus sequence (run-length). s << "<tr><td>"; for(const Base base: edge.consensusSequence) { s << base; } s << "</td></tr>"; // Consensus repeat counts. s << "<tr><td>"; for(const int repeatCount: edge.consensusRepeatCounts) { s << repeatCount; } s << "</td></tr>"; // Consensus sequence (raw). s << "<tr><td>"; for(size_t i=0; i<edge.consensusSequence.size(); i++) { const Base base = edge.consensusSequence[i]; const int repeatCount = edge.consensusRepeatCounts[i]; for(int l=0; l<repeatCount; l++) { s << base; } } s << "</td></tr>"; } // End the label. s << "</table></font>> decorate=true"; } // End edge attributes. s << "]"; } #endif
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r15 push %r8 push %rbp push %rcx push %rdi push %rsi lea addresses_D_ht+0xb9e6, %rsi lea addresses_UC_ht+0xe460, %rdi xor $9222, %r8 mov $84, %rcx rep movsb inc %r11 lea addresses_WT_ht+0x126b6, %rsi lea addresses_UC_ht+0x19c46, %rdi nop nop nop nop nop add $60037, %r15 mov $55, %rcx rep movsb nop nop nop nop nop dec %r15 lea addresses_normal_ht+0x30f6, %r8 nop nop nop xor %r12, %r12 mov (%r8), %edi nop nop nop nop and %r8, %r8 lea addresses_A_ht+0x5ff6, %r15 nop and $61434, %r8 vmovups (%r15), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $1, %xmm5, %r12 cmp $5233, %r11 lea addresses_UC_ht+0x932e, %r15 mfence mov $0x6162636465666768, %r12 movq %r12, (%r15) nop and $493, %r15 lea addresses_UC_ht+0x21f6, %rcx xor %r15, %r15 vmovups (%rcx), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $1, %xmm3, %rsi nop and $49526, %rsi lea addresses_WT_ht+0x11d76, %rsi lea addresses_UC_ht+0xc9f6, %rdi nop nop nop nop nop dec %rbp mov $49, %rcx rep movsb nop nop nop nop nop xor $8273, %r11 lea addresses_WT_ht+0xa698, %rbp nop nop nop nop nop add %r11, %r11 movb $0x61, (%rbp) nop nop nop nop and $36374, %r12 lea addresses_D_ht+0xe6a6, %rsi lea addresses_normal_ht+0x1cbf6, %rdi nop nop nop dec %r11 mov $5, %rcx rep movsq nop nop nop nop xor %r8, %r8 lea addresses_normal_ht+0x10ff6, %rsi lea addresses_normal_ht+0xc9f6, %rdi nop nop nop inc %r11 mov $51, %rcx rep movsq nop nop sub $35363, %rbp lea addresses_WC_ht+0x186f6, %rsi lea addresses_D_ht+0x119f6, %rdi nop nop nop mfence mov $107, %rcx rep movsw nop nop nop nop nop xor %rdi, %rdi lea addresses_normal_ht+0x2096, %r12 nop nop and %rcx, %rcx movw $0x6162, (%r12) nop nop nop nop nop cmp $26208, %r15 lea addresses_UC_ht+0x41f6, %rdi nop cmp %r11, %r11 movl $0x61626364, (%rdi) nop nop nop sub %r12, %r12 lea addresses_A_ht+0x1191e, %rbp add %rcx, %rcx movb $0x61, (%rbp) nop nop xor $58888, %rdi lea addresses_A_ht+0x11336, %rcx cmp %rsi, %rsi mov (%rcx), %di nop nop nop nop nop xor %r8, %r8 pop %rsi pop %rdi pop %rcx pop %rbp pop %r8 pop %r15 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r9 push %rax push %rcx push %rdi push %rsi // REPMOV lea addresses_D+0xe3b9, %rsi lea addresses_WC+0xfb3e, %rdi clflush (%rdi) nop mfence mov $89, %rcx rep movsb nop nop nop nop nop sub $19852, %rax // Faulty Load lea addresses_normal+0x1a1f6, %r9 nop add %rax, %rax mov (%r9), %cx lea oracles, %r10 and $0xff, %rcx shlq $12, %rcx mov (%r10,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_D'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WC'}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_UC_ht'}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_UC_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 8}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': True, 'AVXalign': False, 'size': 8, 'congruent': 3}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 11}} {'OP': 'REPM', 'src': {'same': True, 'congruent': 7, 'type': 'addresses_WT_ht'}, 'dst': {'same': True, 'congruent': 11, 'type': 'addresses_UC_ht'}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 1}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': True, 'AVXalign': False, 'size': 2, 'congruent': 5}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 3}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 3}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
section .data msg1: db "Enter the 1st string :" len1: equ $-msg1 msg2: db "Enter the 2nd string :" len2: equ $-msg2 msg3: db "Enter your choice :" len3: equ $-msg3 msg4: db "-------------MENU--------------",0x0A db "1.Concatenate the String",0x0A db "2.Total Occurences of Substring",0x0A db "3.Exit",0x0A len4: equ $-msg4 msg5: db "concatenated string is :" len5: equ $-msg5 msg6: db "occurence of substring is:" len6: equ $-msg6 n: db "",0x0A section .bss global l1,l2,cnt,str1,str2,str3 ;write before memory allocation ,follow same order extern concat,substr str1: resq 4 str2: resq 4 str3: resq 4 chc: resb 2 l1: resb 1 l2: resb 1 cnt: resb 1 %macro write 2 mov rax,1 mov rdi,1 mov rsi,%1 mov rdx,%2 syscall %endmacro %macro read 2 mov rax,0 mov rdi,0 mov rsi,%1 mov rdx,%2 syscall %endmacro global _start section .text _start: list: write msg4,len4 write msg3,len3 read chc,2 cmp byte[chc],31h je concatenation cmp byte[chc],32h je substring jmp exit concatenation: write msg1,len1 read str1,32 dec al mov byte[l1],al mov al,0 write msg2,len2 read str2,31 mov byte[l2],al write msg5,len5 call concat write str3,32 write n,1 jmp list substring: write msg1,len1 read str1,32 dec al mov byte[l1],al mov al,0 write msg2,len2 read str2,31 dec al mov byte[l2],al mov byte[cnt],0 write msg6,len6 call substr cmp byte[cnt],09h jbe add30 add byte[cnt],07h add30: add byte[cnt],30h write cnt,2 write n,1 write n,1 jmp list exit: mov rax,60 mov rdi,00 syscall
SECTION code_clib SECTION code_fp_math48 PUBLIC ___fsadd EXTERN cm48_sdccixp_dsadd defc ___fsadd = cm48_sdccixp_dsadd
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. #include "include/base/cef_bind.h" #include "include/cef_pack_resources.h" #include "include/cef_request_context_handler.h" #include "include/cef_resource_bundle.h" #include "include/wrapper/cef_closure_task.h" #include "include/wrapper/cef_stream_resource_handler.h" #include "tests/ceftests/routing_test_handler.h" #include "tests/gtest/include/gtest/gtest.h" #include "tests/shared/browser/client_app_browser.h" #include "tests/shared/browser/resource_util.h" namespace { std::string GetDataResourceAsString(int resource_id) { void* data; size_t data_size; if (CefResourceBundle::GetGlobal()->GetDataResource(resource_id, data, data_size)) { return std::string(static_cast<char*>(data), data_size); } return std::string(); } // Browser-side app delegate. class PluginBrowserTest : public client::ClientAppBrowser::Delegate { public: PluginBrowserTest() {} void OnBeforeCommandLineProcessing( CefRefPtr<client::ClientAppBrowser> app, CefRefPtr<CefCommandLine> command_line) override { // Allow all plugin loading by default. command_line->AppendSwitchWithValue("plugin-policy", "allow"); } private: IMPLEMENT_REFCOUNTING(PluginBrowserTest); }; const char kPdfTestOrigin[] = "http://tests/"; const char kPdfHtmlUrl[] = "http://tests/pdf.html"; const char kPdfDirectUrl[] = "http://tests/pdf.pdf"; // Delay waiting for the plugin placeholder to load. const int64 kPlaceholderLoadDelayMs = 1000; // Delay waiting for iframe tests to load the PDF file. #if defined(OS_LINUX) const int64 kPdfLoadDelayMs = 7000; #else const int64 kPdfLoadDelayMs = 5000; #endif // Browser-side test handler. class PluginTestHandler : public RoutingTestHandler, public CefContextMenuHandler { public: enum Mode { // No specified context or handler (implicitly uses the global context). GLOBAL_DEFAULT, // Global context with no handler. GLOBAL_NO_HANDLER, // Global context with handler that allows plugin load. GLOBAL_ALLOW, // Global context with handler that blocks plugin load. Then, load the // plugin via the context menu. GLOBAL_BLOCK_LOAD, // Global context with handler that blocks plugin load. Then, hide the // plugin via the context menu. GLOBAL_BLOCK_HIDE, // Global context with handler that disables plugin load. Then, hide the // plugin via the context menu. GLOBAL_DISABLE_HIDE, // Global context with handler that removes the plugin from the // `navigator.plugins` list and consequently disables plugin load. GLOBAL_NO_LIST, // Custom context with no handler. CUSTOM_NO_HANDLER, // Custom context with handler that allows plugin load. CUSTOM_ALLOW, // Custom context with handler that blocks plugin load. Then, load the // plugin via the context menu. CUSTOM_BLOCK_LOAD, // Custom context with handler that blocks plugin load. Then, hide the // plugin via the context menu. CUSTOM_BLOCK_HIDE, // Custom context with handler that disables plugin load. Then, hide the // plugin via the context menu. CUSTOM_DISABLE_HIDE, // Custom context with handler that removes the plugin from the // `navigator.plugins` list and consequently disables plugin load. CUSTOM_NO_LIST, }; class RequestContextHandler : public CefRequestContextHandler { public: explicit RequestContextHandler(PluginTestHandler* handler) : handler_(handler) {} bool OnBeforePluginLoad(const CefString& mime_type, const CefString& plugin_url, bool is_main_frame, const CefString& top_origin_url, CefRefPtr<CefWebPluginInfo> plugin_info, PluginPolicy* plugin_policy) override { const std::string& mime_type_str = mime_type; EXPECT_STREQ("application/pdf", mime_type_str.c_str()); EXPECT_STREQ("chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/", plugin_info->GetPath().ToString().c_str()); if (top_origin_url.empty()) { if (!handler_->got_on_before_plugin_empty_origin_) { // Checking for PDF support in the plugin frame (navigator.plugins // listing, pdf load, etc). EXPECT_EQ(handler_->HasDirectPluginLoad(), is_main_frame); handler_->got_on_before_plugin_empty_origin_.yes(); } else if (handler_->HasNoList()) { // When listing is disabled there should be an additional check in the // main frame for the navigator.plugins listing. if (!handler_->got_on_before_plugin_empty_origin2_) { EXPECT_EQ(true, is_main_frame); handler_->got_on_before_plugin_empty_origin2_.yes(); } else { NOTREACHED(); } } if (handler_->HasNoList()) { // Remove the PDF plugin from the `navigator.plugins` list. *plugin_policy = PLUGIN_POLICY_DISABLE; return true; } // Ignore requests for building the plugin list. return false; } // Should only get requests for the test origin. EXPECT_STREQ(kPdfTestOrigin, top_origin_url.ToString().c_str()); if (!handler_->got_on_before_plugin_load_pdf_) handler_->got_on_before_plugin_load_pdf_.yes(); else NOTREACHED(); if (handler_->HasAllow()) { *plugin_policy = PLUGIN_POLICY_ALLOW; return true; } else if (handler_->HasBlock()) { *plugin_policy = PLUGIN_POLICY_BLOCK; return true; } else if (handler_->HasDisable()) { *plugin_policy = PLUGIN_POLICY_DISABLE; return true; } return false; } void Detach() { handler_ = NULL; } private: PluginTestHandler* handler_; IMPLEMENT_REFCOUNTING(RequestContextHandler); }; PluginTestHandler(Mode mode, const std::string& url) : mode_(mode), url_(url) {} // Loading the PDF directly in the main frame instead of a sub-frame. bool HasDirectPluginLoad() const { return url_ == kPdfDirectUrl; } // Has a specified RequestContext but not necessarily a custom handler. bool HasRequestContext() const { return mode_ != GLOBAL_DEFAULT; } // Has a specified RequestContext and custom handler. bool HasRequestContextHandler() const { return mode_ != GLOBAL_DEFAULT && mode_ != GLOBAL_NO_HANDLER && mode_ != CUSTOM_NO_HANDLER; } // Using the global request context, either directly or with a custom handler. bool HasGlobalRequestContext() const { return mode_ >= GLOBAL_DEFAULT && mode_ <= GLOBAL_NO_LIST; } // Should allow the plugin load via the custom handler. bool HasAllow() const { return mode_ == GLOBAL_ALLOW || mode_ == CUSTOM_ALLOW; } // Should block the plugin load via the custom handler. bool HasBlock() const { return mode_ == GLOBAL_BLOCK_LOAD || mode_ == GLOBAL_BLOCK_HIDE || mode_ == CUSTOM_BLOCK_LOAD || mode_ == CUSTOM_BLOCK_HIDE; } // Should disable the plugin load via the custom handler. bool HasDisable() const { return mode_ == GLOBAL_DISABLE_HIDE || mode_ == CUSTOM_DISABLE_HIDE; } // Should exclude the plugin from the `navigator.plugins` list. bool HasNoList() const { return mode_ == GLOBAL_NO_LIST || mode_ == CUSTOM_NO_LIST; } // Should load the plugin via the context menu. bool HasContextLoad() const { return mode_ == GLOBAL_BLOCK_LOAD || mode_ == CUSTOM_BLOCK_LOAD; } // Should hide the plugin via the context menu. bool HasContextHide() const { return mode_ == GLOBAL_BLOCK_HIDE || mode_ == GLOBAL_DISABLE_HIDE || mode_ == CUSTOM_BLOCK_HIDE || mode_ == CUSTOM_DISABLE_HIDE; } std::string GetPluginNode() const { return "document.getElementsByTagName('embed')[0]"; } void WaitForNavigatorPlugins(CefRefPtr<CefFrame> frame) const { // Test if the `navigator.plugins` list includes the PDF extension. const std::string& code = " if (navigator.plugins['Chrome PDF Viewer'].filename == " " 'mhjfbmdgcfjbbpaeojofohoefgiehjai') {" " window.testQuery({request:'pdf_plugin_found'});" "} else {" " window.testQuery({request:'pdf_plugin_missing'});" "}"; frame->ExecuteJavaScript(code, frame->GetURL(), 0); } void WaitForPlaceholderLoad(CefRefPtr<CefFrame> frame) { // Waits for the placeholder to load. CefPostDelayedTask(TID_UI, base::Bind(&PluginTestHandler::TriggerContextMenu, this, frame->GetBrowser()), kPlaceholderLoadDelayMs); } void WaitForPlaceholderHide(CefRefPtr<CefFrame> frame) const { // Waits for the placeholder to be hidden (style set to display:none). // See PluginPlaceholderBase::HidePlugin. const std::string& code = "var plugin = " + GetPluginNode() + ";" "var observer = new MutationObserver(function(mutations) {" " mutations.forEach(function(mutationRecord) {" " window.testQuery({request:'placeholder_hidden'});" " observer.disconnect();" " });" "});" "observer.observe(plugin, " " { attributes : true, attributeFilter : ['style'] });"; frame->ExecuteJavaScript(code, frame->GetURL(), 0); } void WaitForPluginLoad(CefRefPtr<CefFrame> frame) { if (url_ == kPdfHtmlUrl) { // PDFScriptingAPI does not work with iframes (the LoadCallback will // never be executed). Use a timeout instead. if (got_context_menu_dismissed_) { // After context menu display. Destroy the test. CefPostDelayedTask(TID_UI, base::Bind(&PluginTestHandler::DestroyTest, this), kPdfLoadDelayMs); } else { // Trigger the context menu. CefPostDelayedTask(TID_UI, base::Bind(&PluginTestHandler::TriggerContextMenu, this, frame->GetBrowser()), kPdfLoadDelayMs); } return; } // Wait for the PDF file to load. // See chrome/browser/pdf/pdf_extension_test_util.cc. const std::string& scripting_api_js = GetDataResourceAsString(IDR_PDF_PDF_SCRIPTING_API_JS); EXPECT_TRUE(!scripting_api_js.empty()); frame->ExecuteJavaScript(scripting_api_js, frame->GetURL(), 0); const std::string& code = "var scriptingAPI = new PDFScriptingAPI(window, " + GetPluginNode() + ");" "scriptingAPI.setLoadCallback(function(success) {" " window.testQuery({request:'plugin_ready'});" "});"; frame->ExecuteJavaScript(code, frame->GetURL(), 0); } void EndTest() { CefPostTask(TID_UI, base::Bind(&PluginTestHandler::DestroyTest, this)); } CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override { return this; } void RunTest() override { CefRefPtr<CefRequestContext> request_context; if (HasRequestContext()) { if (HasRequestContextHandler()) context_handler_ = new RequestContextHandler(this); if (HasGlobalRequestContext()) { // Use the global request context. request_context = CefRequestContext::CreateContext( CefRequestContext::GetGlobalContext(), context_handler_.get()); } else { // Create the request context that will use an in-memory cache. CefRequestContextSettings settings; request_context = CefRequestContext::CreateContext(settings, context_handler_.get()); } } // Create the browser. CreateBrowser(url_, request_context); // Time out the test after a reasonable period of time. SetTestTimeout(5000 + kPdfLoadDelayMs); } CefRefPtr<CefResourceHandler> GetResourceHandler( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) override { const std::string& url = request->GetURL(); if (url == kPdfHtmlUrl) { CefRefPtr<CefStreamReader> stream = client::GetBinaryResourceReader("pdf.html"); return new CefStreamResourceHandler("text/html", stream); } else if (url == kPdfDirectUrl) { CefRefPtr<CefStreamReader> stream = client::GetBinaryResourceReader("pdf.pdf"); return new CefStreamResourceHandler("application/pdf", stream); } return NULL; } void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override { bool is_pdf1 = false; const std::string& url = frame->GetURL(); if (url == kPdfHtmlUrl) { if (!got_on_load_end_html_) got_on_load_end_html_.yes(); else NOTREACHED(); } else if (url == kPdfDirectUrl) { if (!got_on_load_end_pdf1_) { got_on_load_end_pdf1_.yes(); is_pdf1 = true; } else if (!got_on_load_end_pdf2_) { got_on_load_end_pdf2_.yes(); } else { NOTREACHED(); } } else { NOTREACHED(); } if (HasNoList()) { // If the plugin is not listed then the PDF documents will never load. EXPECT_STREQ(kPdfHtmlUrl, url.c_str()); WaitForNavigatorPlugins(frame); } else if (is_pdf1) { // The first PDF document has loaded. WaitForNavigatorPlugins(frame); } } bool OnQuery(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int64 query_id, const CefString& request, bool persistent, CefRefPtr<Callback> callback) override { if (request == "pdf_plugin_found" || request == "pdf_plugin_missing") { if (request == "pdf_plugin_found") got_pdf_plugin_found_.yes(); else got_pdf_plugin_missing_.yes(); if (HasNoList()) { // The plugin will not load. End the test. EndTest(); } else if (HasBlock() || HasDisable()) { // Wait for the plugin placeholder for the first PDF file to load. The // test will continue from OnQuery. WaitForPlaceholderLoad(frame); } else { // Wait for the first PDF file to load. WaitForPluginLoad(frame); } } else if (request == "placeholder_hidden") { EXPECT_FALSE(got_placeholder_hidden_); got_placeholder_hidden_.yes(); // The plugin placeholder has been hidden. End the test. EndTest(); } else if (request == "plugin_ready") { EXPECT_FALSE(got_plugin_ready_); got_plugin_ready_.yes(); // The plugin has loaded the PDF file. if (got_context_menu_dismissed_) { // After context menu display. End the test. EndTest(); } else { // Trigger the context menu. CefPostTask(TID_UI, base::Bind(&PluginTestHandler::TriggerContextMenu, this, browser)); } } else { NOTREACHED(); } return true; } void TriggerContextMenu(CefRefPtr<CefBrowser> browser) { CefMouseEvent mouse_event; // Somewhere in the first plugin. mouse_event.x = 100; mouse_event.y = 100; // Send right-click mouse down and mouse up to tigger context menu. browser->GetHost()->SendMouseClickEvent(mouse_event, MBT_RIGHT, false, 0); browser->GetHost()->SendMouseClickEvent(mouse_event, MBT_RIGHT, true, 0); } bool RunContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model, CefRefPtr<CefRunContextMenuCallback> callback) override { EXPECT_FALSE(got_run_context_menu_); got_run_context_menu_.yes(); if (HasContextLoad() || HasContextHide()) { // Should have 4 elements -- plugin name, separator, run, hide. EXPECT_EQ(4, model->GetCount()); int command_id; if (HasContextLoad()) { // Execute the run command. command_id = model->GetCommandIdAt(2); } else { // Wait for the plugin to be hidden. WaitForPlaceholderHide(frame); // Execute the hide command. command_id = model->GetCommandIdAt(3); } EXPECT_GE(command_id, MENU_ID_CUSTOM_FIRST); EXPECT_LE(command_id, MENU_ID_CUSTOM_LAST); callback->Continue(command_id, static_cast<EventFlags>(0)); } else { // Do nothing with the context menu. callback->Cancel(); } return true; } void OnContextMenuDismissed(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) override { EXPECT_FALSE(got_context_menu_dismissed_); got_context_menu_dismissed_.yes(); if (HasContextHide()) { // Nothing to do here. The test will continue from OnQuery. return; } if (HasContextLoad()) { // Wait for the PDF plugin to load. WaitForPluginLoad(frame); return; } EndTest(); } void DestroyTest() override { if (context_handler_.get()) { context_handler_->Detach(); context_handler_ = NULL; } if (HasContextHide()) { EXPECT_TRUE(got_placeholder_hidden_); EXPECT_FALSE(got_plugin_ready_); } else { EXPECT_FALSE(got_placeholder_hidden_); if (url_ == kPdfDirectUrl) EXPECT_TRUE(got_plugin_ready_); else EXPECT_FALSE(got_plugin_ready_); } if (HasRequestContextHandler()) EXPECT_TRUE(got_on_before_plugin_empty_origin_); else EXPECT_FALSE(got_on_before_plugin_empty_origin_); if (HasNoList()) { EXPECT_TRUE(got_on_before_plugin_empty_origin2_); EXPECT_FALSE(got_pdf_plugin_found_); EXPECT_TRUE(got_pdf_plugin_missing_); EXPECT_FALSE(got_run_context_menu_); EXPECT_FALSE(got_context_menu_dismissed_); } else { EXPECT_FALSE(got_on_before_plugin_empty_origin2_); EXPECT_TRUE(got_pdf_plugin_found_); EXPECT_FALSE(got_pdf_plugin_missing_); EXPECT_TRUE(got_run_context_menu_); EXPECT_TRUE(got_context_menu_dismissed_); } if (url_ == kPdfHtmlUrl) { // The HTML file will load the PDF twice in iframes. EXPECT_TRUE(got_on_load_end_html_); if (!HasNoList()) { EXPECT_TRUE(got_on_load_end_pdf1_); EXPECT_TRUE(got_on_load_end_pdf2_); if (HasRequestContextHandler()) { EXPECT_TRUE(got_on_before_plugin_load_pdf_); } } } else if (url_ == kPdfDirectUrl) { // Load the PDF file directly. EXPECT_FALSE(got_on_load_end_html_); EXPECT_TRUE(got_on_load_end_pdf1_); EXPECT_FALSE(got_on_load_end_pdf2_); if (HasRequestContextHandler()) { EXPECT_TRUE(got_on_before_plugin_load_pdf_); } } else { NOTREACHED(); } if (!HasRequestContextHandler() || HasNoList()) { EXPECT_FALSE(got_on_before_plugin_load_pdf_); } TestHandler::DestroyTest(); } const Mode mode_; const std::string url_; TrackCallback got_on_before_plugin_empty_origin_; TrackCallback got_on_before_plugin_empty_origin2_; TrackCallback got_on_before_plugin_load_pdf_; TrackCallback got_on_load_end_html_; TrackCallback got_on_load_end_pdf1_; TrackCallback got_on_load_end_pdf2_; TrackCallback got_pdf_plugin_found_; TrackCallback got_pdf_plugin_missing_; TrackCallback got_placeholder_hidden_; TrackCallback got_plugin_ready_; TrackCallback got_run_context_menu_; TrackCallback got_context_menu_dismissed_; CefRefPtr<RequestContextHandler> context_handler_; IMPLEMENT_REFCOUNTING(PluginTestHandler); }; } // namespace #define RUN_TEST(name, type, url) \ TEST(PluginTest, name) { \ CefRefPtr<PluginTestHandler> handler = \ new PluginTestHandler(PluginTestHandler::type, url); \ handler->ExecuteTest(); \ ReleaseAndWaitForDestructor(handler); \ } RUN_TEST(GlobalDefaultPdfDirect, GLOBAL_DEFAULT, kPdfDirectUrl) RUN_TEST(GlobalDefaultPdfHtml, GLOBAL_DEFAULT, kPdfHtmlUrl) RUN_TEST(GlobalNoHandlerPdfDirect, GLOBAL_NO_HANDLER, kPdfDirectUrl) RUN_TEST(GlobalNoHandlerPdfHtml, GLOBAL_NO_HANDLER, kPdfHtmlUrl) RUN_TEST(GlobalAllowPdfDirect, GLOBAL_ALLOW, kPdfDirectUrl) RUN_TEST(GlobalAllowPdfHtml, GLOBAL_ALLOW, kPdfHtmlUrl) RUN_TEST(GlobalBlockThenLoadPdfDirect, GLOBAL_BLOCK_LOAD, kPdfDirectUrl) RUN_TEST(GlobalBlockThenLoadPdfHtml, GLOBAL_BLOCK_LOAD, kPdfHtmlUrl) RUN_TEST(GlobalBlockThenHidePdfDirect, GLOBAL_BLOCK_HIDE, kPdfDirectUrl) RUN_TEST(GlobalBlockThenHidePdfHtml, GLOBAL_BLOCK_HIDE, kPdfHtmlUrl) RUN_TEST(GlobalDisableThenHidePdfDirect, GLOBAL_DISABLE_HIDE, kPdfDirectUrl) RUN_TEST(GlobalDisableThenHidePdfHtml, GLOBAL_DISABLE_HIDE, kPdfHtmlUrl) RUN_TEST(GlobalNoListHtml, GLOBAL_NO_LIST, kPdfHtmlUrl) RUN_TEST(CustomNoHandlerPdfDirect, CUSTOM_NO_HANDLER, kPdfDirectUrl) RUN_TEST(CustomNoHandlerPdfHtml, CUSTOM_NO_HANDLER, kPdfHtmlUrl) RUN_TEST(CustomAllowPdfDirect, CUSTOM_ALLOW, kPdfDirectUrl) RUN_TEST(CustomAllowPdfHtml, CUSTOM_ALLOW, kPdfHtmlUrl) RUN_TEST(CustomBlockThenLoadPdfDirect, CUSTOM_BLOCK_LOAD, kPdfDirectUrl) RUN_TEST(CustomBlockThenLoadPdfHtml, CUSTOM_BLOCK_LOAD, kPdfHtmlUrl) RUN_TEST(CustomBlockThenHidePdfDirect, CUSTOM_BLOCK_HIDE, kPdfDirectUrl) RUN_TEST(CustomBlockThenHidePdfHtml, CUSTOM_BLOCK_HIDE, kPdfHtmlUrl) RUN_TEST(CustomDisableThenHidePdfDirect, CUSTOM_DISABLE_HIDE, kPdfDirectUrl) RUN_TEST(CustomDisableThenHidePdfHtml, CUSTOM_DISABLE_HIDE, kPdfHtmlUrl) RUN_TEST(CustomNoListHtml, CUSTOM_NO_LIST, kPdfHtmlUrl) // Entry point for creating plugin browser test objects. // Called from client_app_delegates.cc. void CreatePluginBrowserTests( client::ClientAppBrowser::DelegateSet& delegates) { delegates.insert(new PluginBrowserTest); }
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r15 push %rax push %rcx push %rdi push %rsi // REPMOV lea addresses_WC+0x1479b, %rsi lea addresses_A+0x921b, %rdi nop nop dec %rax mov $77, %rcx rep movsw nop nop nop nop nop xor %r15, %r15 // REPMOV lea addresses_PSE+0x1f5db, %rsi lea addresses_D+0xdc9b, %rdi nop and $48979, %r10 mov $70, %rcx rep movsq sub %r10, %r10 // Faulty Load lea addresses_UC+0xcf9b, %rsi nop and %r11, %r11 movb (%rsi), %r15b lea oracles, %rcx and $0xff, %r15 shlq $12, %r15 mov (%rcx,%r15,1), %r15 pop %rsi pop %rdi pop %rcx pop %rax pop %r15 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 32, 'type': 'addresses_UC', 'congruent': 0}} {'dst': {'same': False, 'congruent': 3, 'type': 'addresses_A'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_WC'}} {'dst': {'same': False, 'congruent': 8, 'type': 'addresses_D'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_PSE'}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_UC', 'congruent': 0}} <gen_prepare_buffer> {'37': 21829} 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 */
// Copyright (c) 2017 Cloudflare, Inc. and contributors // Licensed under the MIT License: // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. #if KJ_HAS_ZLIB #include "gzip.h" #include <kj/test.h> #include <kj/debug.h> #include <stdlib.h> namespace kj { namespace { static const byte FOOBAR_GZIP[] = { 0x1F, 0x8B, 0x08, 0x00, 0xF9, 0x05, 0xB7, 0x59, 0x00, 0x03, 0x4B, 0xCB, 0xCF, 0x4F, 0x4A, 0x2C, 0x02, 0x00, 0x95, 0x1F, 0xF6, 0x9E, 0x06, 0x00, 0x00, 0x00, }; class MockInputStream: public InputStream { public: MockInputStream(kj::ArrayPtr<const byte> bytes, size_t blockSize) : bytes(bytes), blockSize(blockSize) {} size_t tryRead(void* buffer, size_t minBytes, size_t maxBytes) override { // Clamp max read to blockSize. size_t n = kj::min(blockSize, maxBytes); // Unless that's less than minBytes -- in which case, use minBytes. n = kj::max(n, minBytes); // But also don't read more data than we have. n = kj::min(n, bytes.size()); memcpy(buffer, bytes.begin(), n); bytes = bytes.slice(n, bytes.size()); return n; } private: kj::ArrayPtr<const byte> bytes; size_t blockSize; }; class MockAsyncInputStream: public AsyncInputStream { public: MockAsyncInputStream(kj::ArrayPtr<const byte> bytes, size_t blockSize) : bytes(bytes), blockSize(blockSize) {} Promise<size_t> tryRead(void* buffer, size_t minBytes, size_t maxBytes) override { // Clamp max read to blockSize. size_t n = kj::min(blockSize, maxBytes); // Unless that's less than minBytes -- in which case, use minBytes. n = kj::max(n, minBytes); // But also don't read more data than we have. n = kj::min(n, bytes.size()); memcpy(buffer, bytes.begin(), n); bytes = bytes.slice(n, bytes.size()); return n; } private: kj::ArrayPtr<const byte> bytes; size_t blockSize; }; class MockOutputStream: public OutputStream { public: kj::Vector<byte> bytes; kj::String decompress() { MockInputStream rawInput(bytes, kj::maxValue); GzipInputStream gzip(rawInput); return gzip.readAllText(); } void write(const void* buffer, size_t size) override { bytes.addAll(arrayPtr(reinterpret_cast<const byte*>(buffer), size)); } void write(ArrayPtr<const ArrayPtr<const byte>> pieces) override { for (auto& piece: pieces) { bytes.addAll(piece); } } }; class MockAsyncOutputStream: public AsyncOutputStream { public: kj::Vector<byte> bytes; kj::String decompress(WaitScope& ws) { MockAsyncInputStream rawInput(bytes, kj::maxValue); GzipAsyncInputStream gzip(rawInput); return gzip.readAllText().wait(ws); } Promise<void> write(const void* buffer, size_t size) override { bytes.addAll(arrayPtr(reinterpret_cast<const byte*>(buffer), size)); return kj::READY_NOW; } Promise<void> write(ArrayPtr<const ArrayPtr<const byte>> pieces) override { for (auto& piece: pieces) { bytes.addAll(piece); } return kj::READY_NOW; } }; KJ_TEST("gzip decompression") { // Normal read. { MockInputStream rawInput(FOOBAR_GZIP, kj::maxValue); GzipInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText() == "foobar"); } // Force read one byte at a time. { MockInputStream rawInput(FOOBAR_GZIP, 1); GzipInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText() == "foobar"); } // Read truncated input. { MockInputStream rawInput(kj::arrayPtr(FOOBAR_GZIP, sizeof(FOOBAR_GZIP) / 2), kj::maxValue); GzipInputStream gzip(rawInput); char text[16]; size_t n = gzip.tryRead(text, 1, sizeof(text)); text[n] = '\0'; KJ_EXPECT(StringPtr(text, n) == "fo"); KJ_EXPECT_THROW_MESSAGE("gzip compressed stream ended prematurely", gzip.tryRead(text, 1, sizeof(text))); } // Read concatenated input. { Vector<byte> bytes; bytes.addAll(ArrayPtr<const byte>(FOOBAR_GZIP)); bytes.addAll(ArrayPtr<const byte>(FOOBAR_GZIP)); MockInputStream rawInput(bytes, kj::maxValue); GzipInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText() == "foobarfoobar"); } } KJ_TEST("async gzip decompression") { auto io = setupAsyncIo(); // Normal read. { MockAsyncInputStream rawInput(FOOBAR_GZIP, kj::maxValue); GzipAsyncInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText().wait(io.waitScope) == "foobar"); } // Force read one byte at a time. { MockAsyncInputStream rawInput(FOOBAR_GZIP, 1); GzipAsyncInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText().wait(io.waitScope) == "foobar"); } // Read truncated input. { MockAsyncInputStream rawInput(kj::arrayPtr(FOOBAR_GZIP, sizeof(FOOBAR_GZIP) / 2), kj::maxValue); GzipAsyncInputStream gzip(rawInput); char text[16]; size_t n = gzip.tryRead(text, 1, sizeof(text)).wait(io.waitScope); text[n] = '\0'; KJ_EXPECT(StringPtr(text, n) == "fo"); KJ_EXPECT_THROW_MESSAGE("gzip compressed stream ended prematurely", gzip.tryRead(text, 1, sizeof(text)).wait(io.waitScope)); } // Read concatenated input. { Vector<byte> bytes; bytes.addAll(ArrayPtr<const byte>(FOOBAR_GZIP)); bytes.addAll(ArrayPtr<const byte>(FOOBAR_GZIP)); MockAsyncInputStream rawInput(bytes, kj::maxValue); GzipAsyncInputStream gzip(rawInput); KJ_EXPECT(gzip.readAllText().wait(io.waitScope) == "foobarfoobar"); } // Decompress using an output stream. { MockAsyncOutputStream rawOutput; GzipAsyncOutputStream gzip(rawOutput, GzipAsyncOutputStream::DECOMPRESS); auto mid = sizeof(FOOBAR_GZIP) / 2; gzip.write(FOOBAR_GZIP, mid).wait(io.waitScope); auto str1 = kj::heapString(rawOutput.bytes.asPtr().asChars()); KJ_EXPECT(str1 == "fo", str1); gzip.write(FOOBAR_GZIP + mid, sizeof(FOOBAR_GZIP) - mid).wait(io.waitScope); auto str2 = kj::heapString(rawOutput.bytes.asPtr().asChars()); KJ_EXPECT(str2 == "foobar", str2); gzip.end().wait(io.waitScope); } } KJ_TEST("gzip compression") { // Normal write. { MockOutputStream rawOutput; { GzipOutputStream gzip(rawOutput); gzip.write("foobar", 6); } KJ_EXPECT(rawOutput.decompress() == "foobar"); } // Multi-part write. { MockOutputStream rawOutput; { GzipOutputStream gzip(rawOutput); gzip.write("foo", 3); gzip.write("bar", 3); } KJ_EXPECT(rawOutput.decompress() == "foobar"); } // Array-of-arrays write. { MockOutputStream rawOutput; { GzipOutputStream gzip(rawOutput); ArrayPtr<const byte> pieces[] = { kj::StringPtr("foo").asBytes(), kj::StringPtr("bar").asBytes(), }; gzip.write(pieces); } KJ_EXPECT(rawOutput.decompress() == "foobar"); } } KJ_TEST("gzip huge round trip") { auto bytes = heapArray<byte>(65536); for (auto& b: bytes) { b = rand(); } MockOutputStream rawOutput; { GzipOutputStream gzipOut(rawOutput); gzipOut.write(bytes.begin(), bytes.size()); } MockInputStream rawInput(rawOutput.bytes, kj::maxValue); GzipInputStream gzipIn(rawInput); auto decompressed = gzipIn.readAllBytes(); KJ_ASSERT(decompressed.size() == bytes.size()); KJ_ASSERT(memcmp(bytes.begin(), decompressed.begin(), bytes.size()) == 0); } KJ_TEST("async gzip compression") { auto io = setupAsyncIo(); // Normal write. { MockAsyncOutputStream rawOutput; GzipAsyncOutputStream gzip(rawOutput); gzip.write("foobar", 6).wait(io.waitScope); gzip.end().wait(io.waitScope); KJ_EXPECT(rawOutput.decompress(io.waitScope) == "foobar"); } // Multi-part write. { MockAsyncOutputStream rawOutput; GzipAsyncOutputStream gzip(rawOutput); gzip.write("foo", 3).wait(io.waitScope); auto prevSize = rawOutput.bytes.size(); gzip.write("bar", 3).wait(io.waitScope); auto curSize = rawOutput.bytes.size(); KJ_EXPECT(prevSize == curSize, prevSize, curSize); gzip.flush().wait(io.waitScope); curSize = rawOutput.bytes.size(); KJ_EXPECT(prevSize < curSize, prevSize, curSize); gzip.end().wait(io.waitScope); KJ_EXPECT(rawOutput.decompress(io.waitScope) == "foobar"); } // Array-of-arrays write. { MockAsyncOutputStream rawOutput; GzipAsyncOutputStream gzip(rawOutput); ArrayPtr<const byte> pieces[] = { kj::StringPtr("foo").asBytes(), kj::StringPtr("bar").asBytes(), }; gzip.write(pieces).wait(io.waitScope); gzip.end().wait(io.waitScope); KJ_EXPECT(rawOutput.decompress(io.waitScope) == "foobar"); } } KJ_TEST("async gzip huge round trip") { auto io = setupAsyncIo(); auto bytes = heapArray<byte>(65536); for (auto& b: bytes) { b = rand(); } MockAsyncOutputStream rawOutput; GzipAsyncOutputStream gzipOut(rawOutput); gzipOut.write(bytes.begin(), bytes.size()).wait(io.waitScope); gzipOut.end().wait(io.waitScope); MockAsyncInputStream rawInput(rawOutput.bytes, kj::maxValue); GzipAsyncInputStream gzipIn(rawInput); auto decompressed = gzipIn.readAllBytes().wait(io.waitScope); KJ_ASSERT(decompressed.size() == bytes.size()); KJ_ASSERT(memcmp(bytes.begin(), decompressed.begin(), bytes.size()) == 0); } } // namespace } // namespace kj #endif // KJ_HAS_ZLIB
; Try setting the origin/program counter to some ; dec/hex/binary values .ORG $0000 // Let's start at the beginning of code area .DEF UART 15 // This is the 300 baud UART port CLR A ` // Zero out the registers we'll work with since CLR B // the CPU reset in real life doesn't do that for us CLR C CLR D LOOP INC A BRANZ LOOP INC B BRANZ LOOP LDAI 64 // Every 256*256 LOOPs send a @ character to the UART POKE UART INC C BRANZ LOOP INC D SJMP LOOP
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! #include "config.h" #include "V8GCObservation.h" #include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/V8DOMConfiguration.h" #include "bindings/core/v8/V8ObjectConstructor.h" #include "core/dom/ContextFeatures.h" #include "core/dom/Document.h" #include "platform/RuntimeEnabledFeatures.h" #include "platform/TraceEvent.h" #include "wtf/GetPtr.h" #include "wtf/RefPtr.h" namespace blink { // Suppress warning: global constructors, because struct WrapperTypeInfo is trivial // and does not depend on another global objects. #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wglobal-constructors" #endif const WrapperTypeInfo V8GCObservation::wrapperTypeInfo = { gin::kEmbedderBlink, V8GCObservation::domTemplate, V8GCObservation::refObject, V8GCObservation::derefObject, V8GCObservation::trace, 0, 0, V8GCObservation::preparePrototypeObject, V8GCObservation::installConditionallyEnabledProperties, "GCObservation", 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::NotInheritFromEventTarget, WrapperTypeInfo::Independent, WrapperTypeInfo::GarbageCollectedObject }; #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) #pragma clang diagnostic pop #endif // This static member must be declared by DEFINE_WRAPPERTYPEINFO in GCObservation.h. // For details, see the comment of DEFINE_WRAPPERTYPEINFO in // bindings/core/v8/ScriptWrappable.h. const WrapperTypeInfo& GCObservation::s_wrapperTypeInfo = V8GCObservation::wrapperTypeInfo; namespace GCObservationV8Internal { static void wasCollectedAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> holder = info.Holder(); GCObservation* impl = V8GCObservation::toImpl(holder); v8SetReturnValueBool(info, impl->wasCollected()); } static void wasCollectedAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); GCObservationV8Internal::wasCollectedAttributeGetter(info); TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); } } // namespace GCObservationV8Internal static const V8DOMConfiguration::AccessorConfiguration V8GCObservationAccessors[] = { {"wasCollected", GCObservationV8Internal::wasCollectedAttributeGetterCallback, 0, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnPrototype, V8DOMConfiguration::CheckHolder}, }; static void installV8GCObservationTemplate(v8::Local<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) { functionTemplate->ReadOnlyPrototype(); v8::Local<v8::Signature> defaultSignature; defaultSignature = V8DOMConfiguration::installDOMClassTemplate(isolate, functionTemplate, "GCObservation", v8::Local<v8::FunctionTemplate>(), V8GCObservation::internalFieldCount, 0, 0, V8GCObservationAccessors, WTF_ARRAY_LENGTH(V8GCObservationAccessors), 0, 0); v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate(); ALLOW_UNUSED_LOCAL(instanceTemplate); v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate(); ALLOW_UNUSED_LOCAL(prototypeTemplate); // Custom toString template functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); } v8::Local<v8::FunctionTemplate> V8GCObservation::domTemplate(v8::Isolate* isolate) { return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8GCObservationTemplate); } bool V8GCObservation::hasInstance(v8::Local<v8::Value> v8Value, v8::Isolate* isolate) { return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); } v8::Local<v8::Object> V8GCObservation::findInstanceInPrototypeChain(v8::Local<v8::Value> v8Value, v8::Isolate* isolate) { return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); } GCObservation* V8GCObservation::toImplWithTypeCheck(v8::Isolate* isolate, v8::Local<v8::Value> value) { return hasInstance(value, isolate) ? toImpl(v8::Local<v8::Object>::Cast(value)) : 0; } void V8GCObservation::refObject(ScriptWrappable* scriptWrappable) { } void V8GCObservation::derefObject(ScriptWrappable* scriptWrappable) { } } // namespace blink
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC/GEOS FILE: keyboard.asm AUTHOR: Gene Anderson, Jul 8, 1991 REVISION HISTORY: Name Date Description ---- ---- ----------- Gene 7/ 8/91 Initial revision DESCRIPTION: Manager file for keyboard driver $Id: keyboard.asm,v 1.1 97/04/18 11:47:16 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ include keyboardGeode.def include keyboardConstant.def idata segment ; ; number of accentables ; _NUM_ACCENTABLES equ KBD_NUM_ACCENTABLES include kmapSwissGermanExt.def idata ends include keyboardVariable.def include keyboardHotkey.asm include keyboardInit.asm include keyboardProcess.asm include keyboardUtils.asm KbdExtendedInfoSeg segment lmem LMEM_TYPE_GENERAL DriverExtendedInfoTable < {}, length kbdNameTable, offset kbdNameTable, 0 > kbdNameTable lptr.char kbdStr lptr.char 0 kbdStr chunk.char "Swiss-German Extended Keyboard",0 KbdExtendedInfoSeg ends end
#include <iostream> using namespace std; long long int iterations=0; long long int comparisons=0; long long int functionCalls=0; void insertSort(int *a,int n) { for (int i=1; i<n; ++i) { iterations++; int t=a[i]; int k; comparisons++; for (k=i-1; (k>=0)&&(a[k]>t); k--) { iterations++; comparisons++; a[k+1]=a[k]; } a[k+1]=t; } } void merge(int *t, int *u, int *v, int n) { int j=0, k=0; //showArray(u,n/2); //showArray(v,(n+1)/2); for (int i=0; i<n; i++) { iterations++; comparisons++; if (j<n/2) { comparisons++; if (k<(n+1)/2) { comparisons++; if (u[j]<=v[k]) { t[i]=u[j]; j++; } else { t[i]=v[k]; k++; } } else { t[i]=u[j]; j++; } } else { t[i]=v[k]; k++; } } } void mergeSort(int *t,int n) { functionCalls++; if (n<=16) { insertSort(t,n); } else { int *u=new int[n/2]; int *v=new int[(n+1)/2]; for (int i=0; i<n; i++) { iterations++; comparisons++; if (i<n/2) u[i]=t[i]; else v[i-n/2]=t[i]; } mergeSort(u,n/2); mergeSort(v,(n+1)/2); merge(t,u,v,n); } } int main () { int n; cout << "Give n:"<<endl; cin >> n; int *a=new int[n]; for (int i=n-1; i>=0; i--) { a[i]=i;//rand()%100000; //cout <<" "<< a[i]; } cout << endl; mergeSort(a,n); cout << "Done;"<<endl; cout << " iterations: "<<iterations<<" comparisons: "<<comparisons<<" function calls: "<<functionCalls ; //showArray(a,n); return 0; }
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r13 push %r14 push %r8 push %rax push %rbp push %rbx push %rcx // Store lea addresses_WC+0x86e9, %rbp nop nop nop nop nop sub $3468, %rax mov $0x5152535455565758, %rbx movq %rbx, (%rbp) nop nop nop cmp %rbp, %rbp // Store lea addresses_PSE+0xbe69, %rcx nop nop nop nop cmp $46418, %r13 movb $0x51, (%rcx) // Exception!!! nop nop nop nop mov (0), %rbp nop nop nop inc %rax // Faulty Load lea addresses_normal+0x1f269, %r13 nop nop nop nop add %r8, %r8 vmovups (%r13), %ymm1 vextracti128 $1, %ymm1, %xmm1 vpextrq $0, %xmm1, %rax lea oracles, %r14 and $0xff, %rax shlq $12, %rax mov (%r14,%rax,1), %rax pop %rcx pop %rbx pop %rbp pop %rax pop %r8 pop %r14 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_normal', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WC', 'congruent': 5}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_PSE', 'congruent': 10}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal', 'congruent': 0}} <gen_prepare_buffer> {'34': 30} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
generate_block: call procedure_delay ; Generamos un numero aleatorio mov bl,0x6 ; entre [0,5] este sera el color call procedure_generate_random_number ; de una de las secciones de una ; pieza inc al ; Aumentamos su valor en 1 para mov [block_color_1],al ; que no salga el "color" negro call procedure_delay mov bl,0x6 call procedure_generate_random_number inc al mov [block_color_2],al call procedure_delay mov bl,0x6 call procedure_generate_random_number inc al mov [block_color_3],al ret use_block: push ax ; Movemos los colores guardados ; y los asignamos al bloque actual mov al, byte [block_color_1] mov byte [cblock_color_1], al mov al, byte [block_color_2] mov byte [cblock_color_2], al mov al, byte [block_color_3] mov byte [cblock_color_3], al pop ax ret new_block: ; Comprobamos si es posible dibujar ; un nuevo bloque de ser asi ; se asigna su posicion inicial mov ah,02h xor bh,bh mov dh,8 mov dl,18 int 10h mov ah,08h int 10h cmp al,178 je quit ; De lo contratio game overs mov [block_x],dl mov [oblock_x],dl mov [block_y],dh mov [oblock_y],dh mov al,[lv_count] inc al mov [lv_count],al cmp al,5 je lv_up ret lv_up: mov al,[slowness] cmp al,1 je no_lv_up dec al mov [slowness],al mov byte [lv_count],0 ret no_lv_up: ret quit: mov ah,00h ; Terminamos la int 21h ; aplicacion
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld a, ff ldff(45), a ld b, 91 call lwaitly_b xor a, a ldff(40), a ld hl, fea0 lbegin_fill_oam: dec l ld(hl), a jrnz lbegin_fill_oam ld d, 10 ld a, d ld(hl), a inc l ld a, 08 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld(hl), a inc l inc l inc l ld(hl), a inc l ld a, 18 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, 20 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, 28 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, 30 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, 38 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, 38 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, a7 ld(hl), a inc l inc l inc l ld a, d ld(hl), a inc l ld a, a2 ld(hl), a inc l ld a, 40 ldff(41), a ld a, 02 ldff(ff), a xor a, a ldff(0f), a ei ld a, 01 ldff(45), a ld c, 41 ld a, 93 ldff(40), a .text@1000 lstatint: nop .text@104d ldff a, (c) and a, 03 jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
#pragma once #include <string> #include <vector> namespace editor { enum class Mode { NormalMode, InsertMode, VisualMode }; enum class Status { OK, Quit }; enum class Operation { None, Command, Delete, Copy }; enum class CopyMode { Lines, Chars }; class KeyHandling { public: KeyHandling(); Status processKeyPress(); char readKey() const; void changeMode(Mode mode); private: bool isNormalMode() const; bool isInsertMode() const; void processNormalMode(); void resetNormalMode(); void processInsertMode(); void executeCommand(); void handleCopy(); void handleDelete(); void handlePaste(); void handleCommandEdit(); uint32_t parseMultiplier(bool forceOne = true); void saveFile(std::string fname) const; Mode mode; char lastChar; std::string stack; Operation operation; Status status; CopyMode copyMode; std::vector<std::string> copyBuffer; std::string copyBufferChars; }; }
; ; Configuration vars ; %define BOOT_PROTECTED_MODE 0 ; ; Index of storage - in QEMU this vale is from 'index=0,if=floppy' ; %define DRIVE 0 ; ; Address the bootlodaer Stage 2 will be loaded at ; %define BOOTLOADER_SECOND_STAGE_ADDR 0x7E00 ; ; Address the kernel image will be copied into 2000h:0000h (20000h) ; This is not the intended region to execute code from ; .text section/code will be loaded at 10000h ; %define KERNEL_ADDR_ES 0x2000 %define KERNEL_ADDR_BX 0x0000 %define KERNEL_ADDR_32 0x20000 ; ; Poor mans breakpoint - infinite loop, then requires manual debugger break in ; Jmp to the ($) current address of the instruction, same as jmp -2 ; To continue in GDB step over 2 instructions: ; set $eip += 2 ; %define DEBUGBREAK jmp $
aci -128 ; CE 80 aci 127 ; CE 7F aci 255 ; CE FF adc (hl) ; 8E adc (ix) ; FD 8E 00 adc (ix+127) ; FD 8E 7F adc (ix-128) ; FD 8E 80 adc (iy) ; DD 8E 00 adc (iy+127) ; DD 8E 7F adc (iy-128) ; DD 8E 80 adc -128 ; CE 80 adc 127 ; CE 7F adc 255 ; CE FF adc a ; 8F adc a, (hl) ; 8E adc a, (ix) ; FD 8E 00 adc a, (ix+127) ; FD 8E 7F adc a, (ix-128) ; FD 8E 80 adc a, (iy) ; DD 8E 00 adc a, (iy+127) ; DD 8E 7F adc a, (iy-128) ; DD 8E 80 adc a, -128 ; CE 80 adc a, 127 ; CE 7F adc a, 255 ; CE FF adc a, a ; 8F adc a, b ; 88 adc a, c ; 89 adc a, d ; 8A adc a, e ; 8B adc a, h ; 8C adc a, l ; 8D adc b ; 88 adc c ; 89 adc d ; 8A adc e ; 8B adc h ; 8C adc hl, bc ; ED 4A adc hl, de ; ED 5A adc hl, hl ; ED 6A adc hl, sp ; ED 7A adc l ; 8D adc m ; 8E add (hl) ; 86 add (ix) ; FD 86 00 add (ix+127) ; FD 86 7F add (ix-128) ; FD 86 80 add (iy) ; DD 86 00 add (iy+127) ; DD 86 7F add (iy-128) ; DD 86 80 add -128 ; C6 80 add 127 ; C6 7F add 255 ; C6 FF add a ; 87 add a, (hl) ; 86 add a, (ix) ; FD 86 00 add a, (ix+127) ; FD 86 7F add a, (ix-128) ; FD 86 80 add a, (iy) ; DD 86 00 add a, (iy+127) ; DD 86 7F add a, (iy-128) ; DD 86 80 add a, -128 ; C6 80 add a, 127 ; C6 7F add a, 255 ; C6 FF add a, a ; 87 add a, b ; 80 add a, c ; 81 add a, d ; 82 add a, e ; 83 add a, h ; 84 add a, l ; 85 add b ; 80 add bc, -32768 ; E5 21 00 80 09 44 4D E1 add bc, 32767 ; E5 21 FF 7F 09 44 4D E1 add bc, 65535 ; E5 21 FF FF 09 44 4D E1 add bc, a ; CD @__z80asm__add_bc_a add c ; 81 add d ; 82 add de, -32768 ; E5 21 00 80 19 54 5D E1 add de, 32767 ; E5 21 FF 7F 19 54 5D E1 add de, 65535 ; E5 21 FF FF 19 54 5D E1 add de, a ; CD @__z80asm__add_de_a add e ; 83 add h ; 84 add hl, -32768 ; D5 11 00 80 19 D1 add hl, 32767 ; D5 11 FF 7F 19 D1 add hl, 65535 ; D5 11 FF FF 19 D1 add hl, a ; CD @__z80asm__add_hl_a add hl, bc ; 09 add hl, de ; 19 add hl, hl ; 29 add hl, sp ; 39 add ix, bc ; FD 09 add ix, de ; FD 19 add ix, ix ; FD 29 add ix, sp ; FD 39 add iy, bc ; DD 09 add iy, de ; DD 19 add iy, iy ; DD 29 add iy, sp ; DD 39 add l ; 85 add m ; 86 add.a sp, -128 ; E5 3E 80 6F 17 9F 67 39 F9 E1 add.a sp, 127 ; E5 3E 7F 6F 17 9F 67 39 F9 E1 adi -128 ; C6 80 adi 127 ; C6 7F adi 255 ; C6 FF ana a ; A7 ana b ; A0 ana c ; A1 ana d ; A2 ana e ; A3 ana h ; A4 ana l ; A5 ana m ; A6 and (hl) ; A6 and (ix) ; FD A6 00 and (ix+127) ; FD A6 7F and (ix-128) ; FD A6 80 and (iy) ; DD A6 00 and (iy+127) ; DD A6 7F and (iy-128) ; DD A6 80 and -128 ; E6 80 and 127 ; E6 7F and 255 ; E6 FF and a ; A7 and a, (hl) ; A6 and a, (ix) ; FD A6 00 and a, (ix+127) ; FD A6 7F and a, (ix-128) ; FD A6 80 and a, (iy) ; DD A6 00 and a, (iy+127) ; DD A6 7F and a, (iy-128) ; DD A6 80 and a, -128 ; E6 80 and a, 127 ; E6 7F and a, 255 ; E6 FF and a, a ; A7 and a, b ; A0 and a, c ; A1 and a, d ; A2 and a, e ; A3 and a, h ; A4 and a, l ; A5 and b ; A0 and c ; A1 and d ; A2 and e ; A3 and h ; A4 and l ; A5 and.a hl, bc ; 7C A0 67 7D A1 6F and.a hl, de ; 7C A2 67 7D A3 6F ani -128 ; E6 80 ani 127 ; E6 7F ani 255 ; E6 FF arhl ; CB 2C CB 1D bit 0, (hl) ; CB 46 bit 0, (ix) ; FD CB 00 46 bit 0, (ix+127) ; FD CB 7F 46 bit 0, (ix-128) ; FD CB 80 46 bit 0, (iy) ; DD CB 00 46 bit 0, (iy+127) ; DD CB 7F 46 bit 0, (iy-128) ; DD CB 80 46 bit 0, a ; CB 47 bit 0, b ; CB 40 bit 0, c ; CB 41 bit 0, d ; CB 42 bit 0, e ; CB 43 bit 0, h ; CB 44 bit 0, l ; CB 45 bit 1, (hl) ; CB 4E bit 1, (ix) ; FD CB 00 4E bit 1, (ix+127) ; FD CB 7F 4E bit 1, (ix-128) ; FD CB 80 4E bit 1, (iy) ; DD CB 00 4E bit 1, (iy+127) ; DD CB 7F 4E bit 1, (iy-128) ; DD CB 80 4E bit 1, a ; CB 4F bit 1, b ; CB 48 bit 1, c ; CB 49 bit 1, d ; CB 4A bit 1, e ; CB 4B bit 1, h ; CB 4C bit 1, l ; CB 4D bit 2, (hl) ; CB 56 bit 2, (ix) ; FD CB 00 56 bit 2, (ix+127) ; FD CB 7F 56 bit 2, (ix-128) ; FD CB 80 56 bit 2, (iy) ; DD CB 00 56 bit 2, (iy+127) ; DD CB 7F 56 bit 2, (iy-128) ; DD CB 80 56 bit 2, a ; CB 57 bit 2, b ; CB 50 bit 2, c ; CB 51 bit 2, d ; CB 52 bit 2, e ; CB 53 bit 2, h ; CB 54 bit 2, l ; CB 55 bit 3, (hl) ; CB 5E bit 3, (ix) ; FD CB 00 5E bit 3, (ix+127) ; FD CB 7F 5E bit 3, (ix-128) ; FD CB 80 5E bit 3, (iy) ; DD CB 00 5E bit 3, (iy+127) ; DD CB 7F 5E bit 3, (iy-128) ; DD CB 80 5E bit 3, a ; CB 5F bit 3, b ; CB 58 bit 3, c ; CB 59 bit 3, d ; CB 5A bit 3, e ; CB 5B bit 3, h ; CB 5C bit 3, l ; CB 5D bit 4, (hl) ; CB 66 bit 4, (ix) ; FD CB 00 66 bit 4, (ix+127) ; FD CB 7F 66 bit 4, (ix-128) ; FD CB 80 66 bit 4, (iy) ; DD CB 00 66 bit 4, (iy+127) ; DD CB 7F 66 bit 4, (iy-128) ; DD CB 80 66 bit 4, a ; CB 67 bit 4, b ; CB 60 bit 4, c ; CB 61 bit 4, d ; CB 62 bit 4, e ; CB 63 bit 4, h ; CB 64 bit 4, l ; CB 65 bit 5, (hl) ; CB 6E bit 5, (ix) ; FD CB 00 6E bit 5, (ix+127) ; FD CB 7F 6E bit 5, (ix-128) ; FD CB 80 6E bit 5, (iy) ; DD CB 00 6E bit 5, (iy+127) ; DD CB 7F 6E bit 5, (iy-128) ; DD CB 80 6E bit 5, a ; CB 6F bit 5, b ; CB 68 bit 5, c ; CB 69 bit 5, d ; CB 6A bit 5, e ; CB 6B bit 5, h ; CB 6C bit 5, l ; CB 6D bit 6, (hl) ; CB 76 bit 6, (ix) ; FD CB 00 76 bit 6, (ix+127) ; FD CB 7F 76 bit 6, (ix-128) ; FD CB 80 76 bit 6, (iy) ; DD CB 00 76 bit 6, (iy+127) ; DD CB 7F 76 bit 6, (iy-128) ; DD CB 80 76 bit 6, a ; CB 77 bit 6, b ; CB 70 bit 6, c ; CB 71 bit 6, d ; CB 72 bit 6, e ; CB 73 bit 6, h ; CB 74 bit 6, l ; CB 75 bit 7, (hl) ; CB 7E bit 7, (ix) ; FD CB 00 7E bit 7, (ix+127) ; FD CB 7F 7E bit 7, (ix-128) ; FD CB 80 7E bit 7, (iy) ; DD CB 00 7E bit 7, (iy+127) ; DD CB 7F 7E bit 7, (iy-128) ; DD CB 80 7E bit 7, a ; CB 7F bit 7, b ; CB 78 bit 7, c ; CB 79 bit 7, d ; CB 7A bit 7, e ; CB 7B bit 7, h ; CB 7C bit 7, l ; CB 7D bit.a 0, (hl) ; CB 46 bit.a 0, (ix) ; FD CB 00 46 bit.a 0, (ix+127) ; FD CB 7F 46 bit.a 0, (ix-128) ; FD CB 80 46 bit.a 0, (iy) ; DD CB 00 46 bit.a 0, (iy+127) ; DD CB 7F 46 bit.a 0, (iy-128) ; DD CB 80 46 bit.a 0, a ; CB 47 bit.a 0, b ; CB 40 bit.a 0, c ; CB 41 bit.a 0, d ; CB 42 bit.a 0, e ; CB 43 bit.a 0, h ; CB 44 bit.a 0, l ; CB 45 bit.a 1, (hl) ; CB 4E bit.a 1, (ix) ; FD CB 00 4E bit.a 1, (ix+127) ; FD CB 7F 4E bit.a 1, (ix-128) ; FD CB 80 4E bit.a 1, (iy) ; DD CB 00 4E bit.a 1, (iy+127) ; DD CB 7F 4E bit.a 1, (iy-128) ; DD CB 80 4E bit.a 1, a ; CB 4F bit.a 1, b ; CB 48 bit.a 1, c ; CB 49 bit.a 1, d ; CB 4A bit.a 1, e ; CB 4B bit.a 1, h ; CB 4C bit.a 1, l ; CB 4D bit.a 2, (hl) ; CB 56 bit.a 2, (ix) ; FD CB 00 56 bit.a 2, (ix+127) ; FD CB 7F 56 bit.a 2, (ix-128) ; FD CB 80 56 bit.a 2, (iy) ; DD CB 00 56 bit.a 2, (iy+127) ; DD CB 7F 56 bit.a 2, (iy-128) ; DD CB 80 56 bit.a 2, a ; CB 57 bit.a 2, b ; CB 50 bit.a 2, c ; CB 51 bit.a 2, d ; CB 52 bit.a 2, e ; CB 53 bit.a 2, h ; CB 54 bit.a 2, l ; CB 55 bit.a 3, (hl) ; CB 5E bit.a 3, (ix) ; FD CB 00 5E bit.a 3, (ix+127) ; FD CB 7F 5E bit.a 3, (ix-128) ; FD CB 80 5E bit.a 3, (iy) ; DD CB 00 5E bit.a 3, (iy+127) ; DD CB 7F 5E bit.a 3, (iy-128) ; DD CB 80 5E bit.a 3, a ; CB 5F bit.a 3, b ; CB 58 bit.a 3, c ; CB 59 bit.a 3, d ; CB 5A bit.a 3, e ; CB 5B bit.a 3, h ; CB 5C bit.a 3, l ; CB 5D bit.a 4, (hl) ; CB 66 bit.a 4, (ix) ; FD CB 00 66 bit.a 4, (ix+127) ; FD CB 7F 66 bit.a 4, (ix-128) ; FD CB 80 66 bit.a 4, (iy) ; DD CB 00 66 bit.a 4, (iy+127) ; DD CB 7F 66 bit.a 4, (iy-128) ; DD CB 80 66 bit.a 4, a ; CB 67 bit.a 4, b ; CB 60 bit.a 4, c ; CB 61 bit.a 4, d ; CB 62 bit.a 4, e ; CB 63 bit.a 4, h ; CB 64 bit.a 4, l ; CB 65 bit.a 5, (hl) ; CB 6E bit.a 5, (ix) ; FD CB 00 6E bit.a 5, (ix+127) ; FD CB 7F 6E bit.a 5, (ix-128) ; FD CB 80 6E bit.a 5, (iy) ; DD CB 00 6E bit.a 5, (iy+127) ; DD CB 7F 6E bit.a 5, (iy-128) ; DD CB 80 6E bit.a 5, a ; CB 6F bit.a 5, b ; CB 68 bit.a 5, c ; CB 69 bit.a 5, d ; CB 6A bit.a 5, e ; CB 6B bit.a 5, h ; CB 6C bit.a 5, l ; CB 6D bit.a 6, (hl) ; CB 76 bit.a 6, (ix) ; FD CB 00 76 bit.a 6, (ix+127) ; FD CB 7F 76 bit.a 6, (ix-128) ; FD CB 80 76 bit.a 6, (iy) ; DD CB 00 76 bit.a 6, (iy+127) ; DD CB 7F 76 bit.a 6, (iy-128) ; DD CB 80 76 bit.a 6, a ; CB 77 bit.a 6, b ; CB 70 bit.a 6, c ; CB 71 bit.a 6, d ; CB 72 bit.a 6, e ; CB 73 bit.a 6, h ; CB 74 bit.a 6, l ; CB 75 bit.a 7, (hl) ; CB 7E bit.a 7, (ix) ; FD CB 00 7E bit.a 7, (ix+127) ; FD CB 7F 7E bit.a 7, (ix-128) ; FD CB 80 7E bit.a 7, (iy) ; DD CB 00 7E bit.a 7, (iy+127) ; DD CB 7F 7E bit.a 7, (iy-128) ; DD CB 80 7E bit.a 7, a ; CB 7F bit.a 7, b ; CB 78 bit.a 7, c ; CB 79 bit.a 7, d ; CB 7A bit.a 7, e ; CB 7B bit.a 7, h ; CB 7C bit.a 7, l ; CB 7D call -32768 ; CD 00 80 call 32767 ; CD FF 7F call 65535 ; CD FF FF call c, -32768 ; DC 00 80 call c, 32767 ; DC FF 7F call c, 65535 ; DC FF FF call m, -32768 ; FC 00 80 call m, 32767 ; FC FF 7F call m, 65535 ; FC FF FF call nc, -32768 ; D4 00 80 call nc, 32767 ; D4 FF 7F call nc, 65535 ; D4 FF FF call nv, -32768 ; E4 00 80 call nv, 32767 ; E4 FF 7F call nv, 65535 ; E4 FF FF call nz, -32768 ; C4 00 80 call nz, 32767 ; C4 FF 7F call nz, 65535 ; C4 FF FF call p, -32768 ; F4 00 80 call p, 32767 ; F4 FF 7F call p, 65535 ; F4 FF FF call pe, -32768 ; EC 00 80 call pe, 32767 ; EC FF 7F call pe, 65535 ; EC FF FF call po, -32768 ; E4 00 80 call po, 32767 ; E4 FF 7F call po, 65535 ; E4 FF FF call v, -32768 ; EC 00 80 call v, 32767 ; EC FF 7F call v, 65535 ; EC FF FF call z, -32768 ; CC 00 80 call z, 32767 ; CC FF 7F call z, 65535 ; CC FF FF cc -32768 ; DC 00 80 cc 32767 ; DC FF 7F cc 65535 ; DC FF FF ccf ; 3F cm -32768 ; FC 00 80 cm 32767 ; FC FF 7F cm 65535 ; FC FF FF cma ; 2F cmc ; 3F cmp (hl) ; BE cmp (ix) ; FD BE 00 cmp (ix+127) ; FD BE 7F cmp (ix-128) ; FD BE 80 cmp (iy) ; DD BE 00 cmp (iy+127) ; DD BE 7F cmp (iy-128) ; DD BE 80 cmp -128 ; FE 80 cmp 127 ; FE 7F cmp 255 ; FE FF cmp a ; BF cmp a, (hl) ; BE cmp a, (ix) ; FD BE 00 cmp a, (ix+127) ; FD BE 7F cmp a, (ix-128) ; FD BE 80 cmp a, (iy) ; DD BE 00 cmp a, (iy+127) ; DD BE 7F cmp a, (iy-128) ; DD BE 80 cmp a, -128 ; FE 80 cmp a, 127 ; FE 7F cmp a, 255 ; FE FF cmp a, a ; BF cmp a, b ; B8 cmp a, c ; B9 cmp a, d ; BA cmp a, e ; BB cmp a, h ; BC cmp a, l ; BD cmp b ; B8 cmp c ; B9 cmp d ; BA cmp e ; BB cmp h ; BC cmp l ; BD cmp m ; BE cnc -32768 ; D4 00 80 cnc 32767 ; D4 FF 7F cnc 65535 ; D4 FF FF cnv -32768 ; E4 00 80 cnv 32767 ; E4 FF 7F cnv 65535 ; E4 FF FF cnz -32768 ; C4 00 80 cnz 32767 ; C4 FF 7F cnz 65535 ; C4 FF FF cp (hl) ; BE cp (ix) ; FD BE 00 cp (ix+127) ; FD BE 7F cp (ix-128) ; FD BE 80 cp (iy) ; DD BE 00 cp (iy+127) ; DD BE 7F cp (iy-128) ; DD BE 80 cp -128 ; FE 80 cp 127 ; FE 7F cp 255 ; FE FF cp a ; BF cp a, (hl) ; BE cp a, (ix) ; FD BE 00 cp a, (ix+127) ; FD BE 7F cp a, (ix-128) ; FD BE 80 cp a, (iy) ; DD BE 00 cp a, (iy+127) ; DD BE 7F cp a, (iy-128) ; DD BE 80 cp a, -128 ; FE 80 cp a, 127 ; FE 7F cp a, 255 ; FE FF cp a, a ; BF cp a, b ; B8 cp a, c ; B9 cp a, d ; BA cp a, e ; BB cp a, h ; BC cp a, l ; BD cp b ; B8 cp c ; B9 cp d ; BA cp e ; BB cp h ; BC cp l ; BD cpd ; ED A9 cpdr ; ED B9 cpe -32768 ; EC 00 80 cpe 32767 ; EC FF 7F cpe 65535 ; EC FF FF cpi ; ED A1 cpi -128 ; FE 80 cpi 127 ; FE 7F cpi 255 ; FE FF cpir ; ED B1 cpl ; 2F cpl a ; 2F cpo -32768 ; E4 00 80 cpo 32767 ; E4 FF 7F cpo 65535 ; E4 FF FF cv -32768 ; EC 00 80 cv 32767 ; EC FF 7F cv 65535 ; EC FF FF cz -32768 ; CC 00 80 cz 32767 ; CC FF 7F cz 65535 ; CC FF FF daa ; 27 dad b ; 09 dad bc ; 09 dad d ; 19 dad de ; 19 dad h ; 29 dad hl ; 29 dad sp ; 39 dcr a ; 3D dcr b ; 05 dcr c ; 0D dcr d ; 15 dcr e ; 1D dcr h ; 25 dcr l ; 2D dcr m ; 35 dcx b ; 0B dcx bc ; 0B dcx d ; 1B dcx de ; 1B dcx h ; 2B dcx hl ; 2B dcx sp ; 3B dec (hl) ; 35 dec (ix) ; FD 35 00 dec (ix+127) ; FD 35 7F dec (ix-128) ; FD 35 80 dec (iy) ; DD 35 00 dec (iy+127) ; DD 35 7F dec (iy-128) ; DD 35 80 dec a ; 3D dec b ; 05 dec bc ; 0B dec c ; 0D dec d ; 15 dec de ; 1B dec e ; 1D dec h ; 25 dec hl ; 2B dec ix ; FD 2B dec iy ; DD 2B dec l ; 2D dec sp ; 3B di ; F3 djnz ASMPC ; 10 FE djnz b, ASMPC ; 10 FE dsub ; CD @__z80asm__sub_hl_bc ei ; FB ex (sp), hl ; E3 ex (sp), ix ; FD E3 ex (sp), iy ; DD E3 ex af, af ; 08 ex af, af' ; 08 ex de, hl ; EB exx ; D9 halt ; 76 hlt ; 76 im 0 ; ED 46 im 1 ; ED 56 im 2 ; ED 5E in (c) ; ED 70 in -128 ; DB 80 in 127 ; DB 7F in 255 ; DB FF in a, (-128) ; DB 80 in a, (127) ; DB 7F in a, (255) ; DB FF in a, (c) ; ED 78 in b, (c) ; ED 40 in c, (c) ; ED 48 in d, (c) ; ED 50 in e, (c) ; ED 58 in f, (c) ; ED 70 in h, (c) ; ED 60 in l, (c) ; ED 68 in0 (-128) ; ED 30 80 in0 (127) ; ED 30 7F in0 (255) ; ED 30 FF in0 a, (-128) ; ED 38 80 in0 a, (127) ; ED 38 7F in0 a, (255) ; ED 38 FF in0 b, (-128) ; ED 00 80 in0 b, (127) ; ED 00 7F in0 b, (255) ; ED 00 FF in0 c, (-128) ; ED 08 80 in0 c, (127) ; ED 08 7F in0 c, (255) ; ED 08 FF in0 d, (-128) ; ED 10 80 in0 d, (127) ; ED 10 7F in0 d, (255) ; ED 10 FF in0 e, (-128) ; ED 18 80 in0 e, (127) ; ED 18 7F in0 e, (255) ; ED 18 FF in0 f, (-128) ; ED 30 80 in0 f, (127) ; ED 30 7F in0 f, (255) ; ED 30 FF in0 h, (-128) ; ED 20 80 in0 h, (127) ; ED 20 7F in0 h, (255) ; ED 20 FF in0 l, (-128) ; ED 28 80 in0 l, (127) ; ED 28 7F in0 l, (255) ; ED 28 FF inc (hl) ; 34 inc (ix) ; FD 34 00 inc (ix+127) ; FD 34 7F inc (ix-128) ; FD 34 80 inc (iy) ; DD 34 00 inc (iy+127) ; DD 34 7F inc (iy-128) ; DD 34 80 inc a ; 3C inc b ; 04 inc bc ; 03 inc c ; 0C inc d ; 14 inc de ; 13 inc e ; 1C inc h ; 24 inc hl ; 23 inc ix ; FD 23 inc iy ; DD 23 inc l ; 2C inc sp ; 33 ind ; ED AA indr ; ED BA ini ; ED A2 inir ; ED B2 inr a ; 3C inr b ; 04 inr c ; 0C inr d ; 14 inr e ; 1C inr h ; 24 inr l ; 2C inr m ; 34 inx b ; 03 inx bc ; 03 inx d ; 13 inx de ; 13 inx h ; 23 inx hl ; 23 inx sp ; 33 jc -32768 ; DA 00 80 jc 32767 ; DA FF 7F jc 65535 ; DA FF FF jm -32768 ; FA 00 80 jm 32767 ; FA FF 7F jm 65535 ; FA FF FF jmp -32768 ; C3 00 80 jmp 32767 ; C3 FF 7F jmp 65535 ; C3 FF FF jnc -32768 ; D2 00 80 jnc 32767 ; D2 FF 7F jnc 65535 ; D2 FF FF jnv -32768 ; E2 00 80 jnv 32767 ; E2 FF 7F jnv 65535 ; E2 FF FF jnz -32768 ; C2 00 80 jnz 32767 ; C2 FF 7F jnz 65535 ; C2 FF FF jp (bc) ; C5 C9 jp (de) ; D5 C9 jp (hl) ; E9 jp (ix) ; FD E9 jp (iy) ; DD E9 jp -32768 ; C3 00 80 jp 32767 ; C3 FF 7F jp 65535 ; C3 FF FF jp c, -32768 ; DA 00 80 jp c, 32767 ; DA FF 7F jp c, 65535 ; DA FF FF jp m, -32768 ; FA 00 80 jp m, 32767 ; FA FF 7F jp m, 65535 ; FA FF FF jp nc, -32768 ; D2 00 80 jp nc, 32767 ; D2 FF 7F jp nc, 65535 ; D2 FF FF jp nv, -32768 ; E2 00 80 jp nv, 32767 ; E2 FF 7F jp nv, 65535 ; E2 FF FF jp nz, -32768 ; C2 00 80 jp nz, 32767 ; C2 FF 7F jp nz, 65535 ; C2 FF FF jp p, -32768 ; F2 00 80 jp p, 32767 ; F2 FF 7F jp p, 65535 ; F2 FF FF jp pe, -32768 ; EA 00 80 jp pe, 32767 ; EA FF 7F jp pe, 65535 ; EA FF FF jp po, -32768 ; E2 00 80 jp po, 32767 ; E2 FF 7F jp po, 65535 ; E2 FF FF jp v, -32768 ; EA 00 80 jp v, 32767 ; EA FF 7F jp v, 65535 ; EA FF FF jp z, -32768 ; CA 00 80 jp z, 32767 ; CA FF 7F jp z, 65535 ; CA FF FF jpe -32768 ; EA 00 80 jpe 32767 ; EA FF 7F jpe 65535 ; EA FF FF jpo -32768 ; E2 00 80 jpo 32767 ; E2 FF 7F jpo 65535 ; E2 FF FF jr ASMPC ; 18 FE jr c, ASMPC ; 38 FE jr nc, ASMPC ; 30 FE jr nz, ASMPC ; 20 FE jr z, ASMPC ; 28 FE jv -32768 ; EA 00 80 jv 32767 ; EA FF 7F jv 65535 ; EA FF FF jz -32768 ; CA 00 80 jz 32767 ; CA FF 7F jz 65535 ; CA FF FF ld (-32768), a ; 32 00 80 ld (-32768), bc ; ED 43 00 80 ld (-32768), de ; ED 53 00 80 ld (-32768), hl ; 22 00 80 ld (-32768), ix ; FD 22 00 80 ld (-32768), iy ; DD 22 00 80 ld (-32768), sp ; ED 73 00 80 ld (32767), a ; 32 FF 7F ld (32767), bc ; ED 43 FF 7F ld (32767), de ; ED 53 FF 7F ld (32767), hl ; 22 FF 7F ld (32767), ix ; FD 22 FF 7F ld (32767), iy ; DD 22 FF 7F ld (32767), sp ; ED 73 FF 7F ld (65535), a ; 32 FF FF ld (65535), bc ; ED 43 FF FF ld (65535), de ; ED 53 FF FF ld (65535), hl ; 22 FF FF ld (65535), ix ; FD 22 FF FF ld (65535), iy ; DD 22 FF FF ld (65535), sp ; ED 73 FF FF ld (bc), a ; 02 ld (bc+), a ; 02 03 ld (bc-), a ; 02 0B ld (de), a ; 12 ld (de+), a ; 12 13 ld (de-), a ; 12 1B ld (hl), -128 ; 36 80 ld (hl), 127 ; 36 7F ld (hl), 255 ; 36 FF ld (hl), a ; 77 ld (hl), b ; 70 ld (hl), c ; 71 ld (hl), d ; 72 ld (hl), e ; 73 ld (hl), h ; 74 ld (hl), l ; 75 ld (hl+), a ; 77 23 ld (hl-), a ; 77 2B ld (hld), a ; 77 2B ld (hli), a ; 77 23 ld (ix), -128 ; FD 36 00 80 ld (ix), 127 ; FD 36 00 7F ld (ix), 255 ; FD 36 00 FF ld (ix), a ; FD 77 00 ld (ix), b ; FD 70 00 ld (ix), c ; FD 71 00 ld (ix), d ; FD 72 00 ld (ix), e ; FD 73 00 ld (ix), h ; FD 74 00 ld (ix), l ; FD 75 00 ld (ix+127), -128 ; FD 36 7F 80 ld (ix+127), 127 ; FD 36 7F 7F ld (ix+127), 255 ; FD 36 7F FF ld (ix+127), a ; FD 77 7F ld (ix+127), b ; FD 70 7F ld (ix+127), c ; FD 71 7F ld (ix+127), d ; FD 72 7F ld (ix+127), e ; FD 73 7F ld (ix+127), h ; FD 74 7F ld (ix+127), l ; FD 75 7F ld (ix-128), -128 ; FD 36 80 80 ld (ix-128), 127 ; FD 36 80 7F ld (ix-128), 255 ; FD 36 80 FF ld (ix-128), a ; FD 77 80 ld (ix-128), b ; FD 70 80 ld (ix-128), c ; FD 71 80 ld (ix-128), d ; FD 72 80 ld (ix-128), e ; FD 73 80 ld (ix-128), h ; FD 74 80 ld (ix-128), l ; FD 75 80 ld (iy), -128 ; DD 36 00 80 ld (iy), 127 ; DD 36 00 7F ld (iy), 255 ; DD 36 00 FF ld (iy), a ; DD 77 00 ld (iy), b ; DD 70 00 ld (iy), c ; DD 71 00 ld (iy), d ; DD 72 00 ld (iy), e ; DD 73 00 ld (iy), h ; DD 74 00 ld (iy), l ; DD 75 00 ld (iy+127), -128 ; DD 36 7F 80 ld (iy+127), 127 ; DD 36 7F 7F ld (iy+127), 255 ; DD 36 7F FF ld (iy+127), a ; DD 77 7F ld (iy+127), b ; DD 70 7F ld (iy+127), c ; DD 71 7F ld (iy+127), d ; DD 72 7F ld (iy+127), e ; DD 73 7F ld (iy+127), h ; DD 74 7F ld (iy+127), l ; DD 75 7F ld (iy-128), -128 ; DD 36 80 80 ld (iy-128), 127 ; DD 36 80 7F ld (iy-128), 255 ; DD 36 80 FF ld (iy-128), a ; DD 77 80 ld (iy-128), b ; DD 70 80 ld (iy-128), c ; DD 71 80 ld (iy-128), d ; DD 72 80 ld (iy-128), e ; DD 73 80 ld (iy-128), h ; DD 74 80 ld (iy-128), l ; DD 75 80 ld a, (-32768) ; 3A 00 80 ld a, (32767) ; 3A FF 7F ld a, (65535) ; 3A FF FF ld a, (bc) ; 0A ld a, (bc+) ; 0A 03 ld a, (bc-) ; 0A 0B ld a, (de) ; 1A ld a, (de+) ; 1A 13 ld a, (de-) ; 1A 1B ld a, (hl) ; 7E ld a, (hl+) ; 7E 23 ld a, (hl-) ; 7E 2B ld a, (hld) ; 7E 2B ld a, (hli) ; 7E 23 ld a, (ix) ; FD 7E 00 ld a, (ix+127) ; FD 7E 7F ld a, (ix-128) ; FD 7E 80 ld a, (iy) ; DD 7E 00 ld a, (iy+127) ; DD 7E 7F ld a, (iy-128) ; DD 7E 80 ld a, -128 ; 3E 80 ld a, 127 ; 3E 7F ld a, 255 ; 3E FF ld a, a ; 7F ld a, b ; 78 ld a, c ; 79 ld a, d ; 7A ld a, e ; 7B ld a, h ; 7C ld a, i ; ED 57 ld a, l ; 7D ld a, r ; ED 5F ld b, (hl) ; 46 ld b, (ix) ; FD 46 00 ld b, (ix+127) ; FD 46 7F ld b, (ix-128) ; FD 46 80 ld b, (iy) ; DD 46 00 ld b, (iy+127) ; DD 46 7F ld b, (iy-128) ; DD 46 80 ld b, -128 ; 06 80 ld b, 127 ; 06 7F ld b, 255 ; 06 FF ld b, a ; 47 ld b, b ; 40 ld b, c ; 41 ld b, d ; 42 ld b, e ; 43 ld b, h ; 44 ld b, l ; 45 ld bc, (-32768) ; ED 4B 00 80 ld bc, (32767) ; ED 4B FF 7F ld bc, (65535) ; ED 4B FF FF ld bc, -32768 ; 01 00 80 ld bc, 32767 ; 01 FF 7F ld bc, 65535 ; 01 FF FF ld bc, de ; 42 4B ld bc, hl ; 44 4D ld c, (hl) ; 4E ld c, (ix) ; FD 4E 00 ld c, (ix+127) ; FD 4E 7F ld c, (ix-128) ; FD 4E 80 ld c, (iy) ; DD 4E 00 ld c, (iy+127) ; DD 4E 7F ld c, (iy-128) ; DD 4E 80 ld c, -128 ; 0E 80 ld c, 127 ; 0E 7F ld c, 255 ; 0E FF ld c, a ; 4F ld c, b ; 48 ld c, c ; 49 ld c, d ; 4A ld c, e ; 4B ld c, h ; 4C ld c, l ; 4D ld d, (hl) ; 56 ld d, (ix) ; FD 56 00 ld d, (ix+127) ; FD 56 7F ld d, (ix-128) ; FD 56 80 ld d, (iy) ; DD 56 00 ld d, (iy+127) ; DD 56 7F ld d, (iy-128) ; DD 56 80 ld d, -128 ; 16 80 ld d, 127 ; 16 7F ld d, 255 ; 16 FF ld d, a ; 57 ld d, b ; 50 ld d, c ; 51 ld d, d ; 52 ld d, e ; 53 ld d, h ; 54 ld d, l ; 55 ld de, (-32768) ; ED 5B 00 80 ld de, (32767) ; ED 5B FF 7F ld de, (65535) ; ED 5B FF FF ld de, -32768 ; 11 00 80 ld de, 32767 ; 11 FF 7F ld de, 65535 ; 11 FF FF ld de, bc ; 50 59 ld de, hl ; 54 5D ld de, sp ; EB 21 00 00 39 EB ld de, sp+0 ; EB 21 00 00 39 EB ld de, sp+255 ; EB 21 FF 00 39 EB ld e, (hl) ; 5E ld e, (ix) ; FD 5E 00 ld e, (ix+127) ; FD 5E 7F ld e, (ix-128) ; FD 5E 80 ld e, (iy) ; DD 5E 00 ld e, (iy+127) ; DD 5E 7F ld e, (iy-128) ; DD 5E 80 ld e, -128 ; 1E 80 ld e, 127 ; 1E 7F ld e, 255 ; 1E FF ld e, a ; 5F ld e, b ; 58 ld e, c ; 59 ld e, d ; 5A ld e, e ; 5B ld e, h ; 5C ld e, l ; 5D ld h, (hl) ; 66 ld h, (ix) ; FD 66 00 ld h, (ix+127) ; FD 66 7F ld h, (ix-128) ; FD 66 80 ld h, (iy) ; DD 66 00 ld h, (iy+127) ; DD 66 7F ld h, (iy-128) ; DD 66 80 ld h, -128 ; 26 80 ld h, 127 ; 26 7F ld h, 255 ; 26 FF ld h, a ; 67 ld h, b ; 60 ld h, c ; 61 ld h, d ; 62 ld h, e ; 63 ld h, h ; 64 ld h, l ; 65 ld hl, (-32768) ; 2A 00 80 ld hl, (32767) ; 2A FF 7F ld hl, (65535) ; 2A FF FF ld hl, -32768 ; 21 00 80 ld hl, 32767 ; 21 FF 7F ld hl, 65535 ; 21 FF FF ld hl, bc ; 60 69 ld hl, de ; 62 6B ld hl, sp ; 21 00 00 39 ld hl, sp+-128 ; 21 80 FF 39 ld hl, sp+127 ; 21 7F 00 39 ld i, a ; ED 47 ld ix, (-32768) ; FD 2A 00 80 ld ix, (32767) ; FD 2A FF 7F ld ix, (65535) ; FD 2A FF FF ld ix, -32768 ; FD 21 00 80 ld ix, 32767 ; FD 21 FF 7F ld ix, 65535 ; FD 21 FF FF ld iy, (-32768) ; DD 2A 00 80 ld iy, (32767) ; DD 2A FF 7F ld iy, (65535) ; DD 2A FF FF ld iy, -32768 ; DD 21 00 80 ld iy, 32767 ; DD 21 FF 7F ld iy, 65535 ; DD 21 FF FF ld l, (hl) ; 6E ld l, (ix) ; FD 6E 00 ld l, (ix+127) ; FD 6E 7F ld l, (ix-128) ; FD 6E 80 ld l, (iy) ; DD 6E 00 ld l, (iy+127) ; DD 6E 7F ld l, (iy-128) ; DD 6E 80 ld l, -128 ; 2E 80 ld l, 127 ; 2E 7F ld l, 255 ; 2E FF ld l, a ; 6F ld l, b ; 68 ld l, c ; 69 ld l, d ; 6A ld l, e ; 6B ld l, h ; 6C ld l, l ; 6D ld r, a ; ED 4F ld sp, (-32768) ; ED 7B 00 80 ld sp, (32767) ; ED 7B FF 7F ld sp, (65535) ; ED 7B FF FF ld sp, -32768 ; 31 00 80 ld sp, 32767 ; 31 FF 7F ld sp, 65535 ; 31 FF FF ld sp, hl ; F9 ld sp, ix ; FD F9 ld sp, iy ; DD F9 lda -32768 ; 3A 00 80 lda 32767 ; 3A FF 7F lda 65535 ; 3A FF FF ldax b ; 0A ldax bc ; 0A ldax d ; 1A ldax de ; 1A ldd ; ED A8 ldd (bc), a ; 02 0B ldd (de), a ; 12 1B ldd (hl), a ; 77 2B ldd a, (bc) ; 0A 0B ldd a, (de) ; 1A 1B ldd a, (hl) ; 7E 2B lddr ; ED B8 ldi ; ED A0 ldi (bc), a ; 02 03 ldi (de), a ; 12 13 ldi (hl), a ; 77 23 ldi a, (bc) ; 0A 03 ldi a, (de) ; 1A 13 ldi a, (hl) ; 7E 23 ldir ; ED B0 lhld -32768 ; 2A 00 80 lhld 32767 ; 2A FF 7F lhld 65535 ; 2A FF FF lxi b, -32768 ; 01 00 80 lxi b, 32767 ; 01 FF 7F lxi b, 65535 ; 01 FF FF lxi bc, -32768 ; 01 00 80 lxi bc, 32767 ; 01 FF 7F lxi bc, 65535 ; 01 FF FF lxi d, -32768 ; 11 00 80 lxi d, 32767 ; 11 FF 7F lxi d, 65535 ; 11 FF FF lxi de, -32768 ; 11 00 80 lxi de, 32767 ; 11 FF 7F lxi de, 65535 ; 11 FF FF lxi h, -32768 ; 21 00 80 lxi h, 32767 ; 21 FF 7F lxi h, 65535 ; 21 FF FF lxi hl, -32768 ; 21 00 80 lxi hl, 32767 ; 21 FF 7F lxi hl, 65535 ; 21 FF FF lxi sp, -32768 ; 31 00 80 lxi sp, 32767 ; 31 FF 7F lxi sp, 65535 ; 31 FF FF mlt bc ; ED 4C mlt de ; ED 5C mlt hl ; ED 6C mlt sp ; ED 7C mov a, a ; 7F mov a, b ; 78 mov a, c ; 79 mov a, d ; 7A mov a, e ; 7B mov a, h ; 7C mov a, l ; 7D mov a, m ; 7E mov b, a ; 47 mov b, b ; 40 mov b, c ; 41 mov b, d ; 42 mov b, e ; 43 mov b, h ; 44 mov b, l ; 45 mov b, m ; 46 mov c, a ; 4F mov c, b ; 48 mov c, c ; 49 mov c, d ; 4A mov c, e ; 4B mov c, h ; 4C mov c, l ; 4D mov c, m ; 4E mov d, a ; 57 mov d, b ; 50 mov d, c ; 51 mov d, d ; 52 mov d, e ; 53 mov d, h ; 54 mov d, l ; 55 mov d, m ; 56 mov e, a ; 5F mov e, b ; 58 mov e, c ; 59 mov e, d ; 5A mov e, e ; 5B mov e, h ; 5C mov e, l ; 5D mov e, m ; 5E mov h, a ; 67 mov h, b ; 60 mov h, c ; 61 mov h, d ; 62 mov h, e ; 63 mov h, h ; 64 mov h, l ; 65 mov h, m ; 66 mov l, a ; 6F mov l, b ; 68 mov l, c ; 69 mov l, d ; 6A mov l, e ; 6B mov l, h ; 6C mov l, l ; 6D mov l, m ; 6E mov m, a ; 77 mov m, b ; 70 mov m, c ; 71 mov m, d ; 72 mov m, e ; 73 mov m, h ; 74 mov m, l ; 75 mvi a, -128 ; 3E 80 mvi a, 127 ; 3E 7F mvi a, 255 ; 3E FF mvi b, -128 ; 06 80 mvi b, 127 ; 06 7F mvi b, 255 ; 06 FF mvi c, -128 ; 0E 80 mvi c, 127 ; 0E 7F mvi c, 255 ; 0E FF mvi d, -128 ; 16 80 mvi d, 127 ; 16 7F mvi d, 255 ; 16 FF mvi e, -128 ; 1E 80 mvi e, 127 ; 1E 7F mvi e, 255 ; 1E FF mvi h, -128 ; 26 80 mvi h, 127 ; 26 7F mvi h, 255 ; 26 FF mvi l, -128 ; 2E 80 mvi l, 127 ; 2E 7F mvi l, 255 ; 2E FF mvi m, -128 ; 36 80 mvi m, 127 ; 36 7F mvi m, 255 ; 36 FF neg ; ED 44 neg a ; ED 44 nop ; 00 or (hl) ; B6 or (ix) ; FD B6 00 or (ix+127) ; FD B6 7F or (ix-128) ; FD B6 80 or (iy) ; DD B6 00 or (iy+127) ; DD B6 7F or (iy-128) ; DD B6 80 or -128 ; F6 80 or 127 ; F6 7F or 255 ; F6 FF or a ; B7 or a, (hl) ; B6 or a, (ix) ; FD B6 00 or a, (ix+127) ; FD B6 7F or a, (ix-128) ; FD B6 80 or a, (iy) ; DD B6 00 or a, (iy+127) ; DD B6 7F or a, (iy-128) ; DD B6 80 or a, -128 ; F6 80 or a, 127 ; F6 7F or a, 255 ; F6 FF or a, a ; B7 or a, b ; B0 or a, c ; B1 or a, d ; B2 or a, e ; B3 or a, h ; B4 or a, l ; B5 or b ; B0 or c ; B1 or d ; B2 or e ; B3 or h ; B4 or l ; B5 ora a ; B7 ora b ; B0 ora c ; B1 ora d ; B2 ora e ; B3 ora h ; B4 ora l ; B5 ora m ; B6 ori -128 ; F6 80 ori 127 ; F6 7F ori 255 ; F6 FF otdm ; ED 8B otdmr ; ED 9B otdr ; ED BB otim ; ED 83 otimr ; ED 93 otir ; ED B3 out (-128), a ; D3 80 out (127), a ; D3 7F out (255), a ; D3 FF out (c), 0 ; ED 71 out (c), a ; ED 79 out (c), b ; ED 41 out (c), c ; ED 49 out (c), d ; ED 51 out (c), e ; ED 59 out (c), f ; ED 71 out (c), h ; ED 61 out (c), l ; ED 69 out -128 ; D3 80 out 127 ; D3 7F out 255 ; D3 FF out0 (-128), a ; ED 39 80 out0 (-128), b ; ED 01 80 out0 (-128), c ; ED 09 80 out0 (-128), d ; ED 11 80 out0 (-128), e ; ED 19 80 out0 (-128), h ; ED 21 80 out0 (-128), l ; ED 29 80 out0 (127), a ; ED 39 7F out0 (127), b ; ED 01 7F out0 (127), c ; ED 09 7F out0 (127), d ; ED 11 7F out0 (127), e ; ED 19 7F out0 (127), h ; ED 21 7F out0 (127), l ; ED 29 7F out0 (255), a ; ED 39 FF out0 (255), b ; ED 01 FF out0 (255), c ; ED 09 FF out0 (255), d ; ED 11 FF out0 (255), e ; ED 19 FF out0 (255), h ; ED 21 FF out0 (255), l ; ED 29 FF outd ; ED AB outi ; ED A3 pchl ; E9 pop af ; F1 pop b ; C1 pop bc ; C1 pop d ; D1 pop de ; D1 pop h ; E1 pop hl ; E1 pop ix ; FD E1 pop iy ; DD E1 pop psw ; F1 push af ; F5 push b ; C5 push bc ; C5 push d ; D5 push de ; D5 push h ; E5 push hl ; E5 push ix ; FD E5 push iy ; DD E5 push psw ; F5 ral ; 17 rar ; 1F rc ; D8 rdel ; CB 13 CB 12 res 0, (hl) ; CB 86 res 0, (ix) ; FD CB 00 86 res 0, (ix+127) ; FD CB 7F 86 res 0, (ix-128) ; FD CB 80 86 res 0, (iy) ; DD CB 00 86 res 0, (iy+127) ; DD CB 7F 86 res 0, (iy-128) ; DD CB 80 86 res 0, a ; CB 87 res 0, b ; CB 80 res 0, c ; CB 81 res 0, d ; CB 82 res 0, e ; CB 83 res 0, h ; CB 84 res 0, l ; CB 85 res 1, (hl) ; CB 8E res 1, (ix) ; FD CB 00 8E res 1, (ix+127) ; FD CB 7F 8E res 1, (ix-128) ; FD CB 80 8E res 1, (iy) ; DD CB 00 8E res 1, (iy+127) ; DD CB 7F 8E res 1, (iy-128) ; DD CB 80 8E res 1, a ; CB 8F res 1, b ; CB 88 res 1, c ; CB 89 res 1, d ; CB 8A res 1, e ; CB 8B res 1, h ; CB 8C res 1, l ; CB 8D res 2, (hl) ; CB 96 res 2, (ix) ; FD CB 00 96 res 2, (ix+127) ; FD CB 7F 96 res 2, (ix-128) ; FD CB 80 96 res 2, (iy) ; DD CB 00 96 res 2, (iy+127) ; DD CB 7F 96 res 2, (iy-128) ; DD CB 80 96 res 2, a ; CB 97 res 2, b ; CB 90 res 2, c ; CB 91 res 2, d ; CB 92 res 2, e ; CB 93 res 2, h ; CB 94 res 2, l ; CB 95 res 3, (hl) ; CB 9E res 3, (ix) ; FD CB 00 9E res 3, (ix+127) ; FD CB 7F 9E res 3, (ix-128) ; FD CB 80 9E res 3, (iy) ; DD CB 00 9E res 3, (iy+127) ; DD CB 7F 9E res 3, (iy-128) ; DD CB 80 9E res 3, a ; CB 9F res 3, b ; CB 98 res 3, c ; CB 99 res 3, d ; CB 9A res 3, e ; CB 9B res 3, h ; CB 9C res 3, l ; CB 9D res 4, (hl) ; CB A6 res 4, (ix) ; FD CB 00 A6 res 4, (ix+127) ; FD CB 7F A6 res 4, (ix-128) ; FD CB 80 A6 res 4, (iy) ; DD CB 00 A6 res 4, (iy+127) ; DD CB 7F A6 res 4, (iy-128) ; DD CB 80 A6 res 4, a ; CB A7 res 4, b ; CB A0 res 4, c ; CB A1 res 4, d ; CB A2 res 4, e ; CB A3 res 4, h ; CB A4 res 4, l ; CB A5 res 5, (hl) ; CB AE res 5, (ix) ; FD CB 00 AE res 5, (ix+127) ; FD CB 7F AE res 5, (ix-128) ; FD CB 80 AE res 5, (iy) ; DD CB 00 AE res 5, (iy+127) ; DD CB 7F AE res 5, (iy-128) ; DD CB 80 AE res 5, a ; CB AF res 5, b ; CB A8 res 5, c ; CB A9 res 5, d ; CB AA res 5, e ; CB AB res 5, h ; CB AC res 5, l ; CB AD res 6, (hl) ; CB B6 res 6, (ix) ; FD CB 00 B6 res 6, (ix+127) ; FD CB 7F B6 res 6, (ix-128) ; FD CB 80 B6 res 6, (iy) ; DD CB 00 B6 res 6, (iy+127) ; DD CB 7F B6 res 6, (iy-128) ; DD CB 80 B6 res 6, a ; CB B7 res 6, b ; CB B0 res 6, c ; CB B1 res 6, d ; CB B2 res 6, e ; CB B3 res 6, h ; CB B4 res 6, l ; CB B5 res 7, (hl) ; CB BE res 7, (ix) ; FD CB 00 BE res 7, (ix+127) ; FD CB 7F BE res 7, (ix-128) ; FD CB 80 BE res 7, (iy) ; DD CB 00 BE res 7, (iy+127) ; DD CB 7F BE res 7, (iy-128) ; DD CB 80 BE res 7, a ; CB BF res 7, b ; CB B8 res 7, c ; CB B9 res 7, d ; CB BA res 7, e ; CB BB res 7, h ; CB BC res 7, l ; CB BD res.a 0, (hl) ; CB 86 res.a 0, (ix) ; FD CB 00 86 res.a 0, (ix+127) ; FD CB 7F 86 res.a 0, (ix-128) ; FD CB 80 86 res.a 0, (iy) ; DD CB 00 86 res.a 0, (iy+127) ; DD CB 7F 86 res.a 0, (iy-128) ; DD CB 80 86 res.a 0, a ; CB 87 res.a 0, b ; CB 80 res.a 0, c ; CB 81 res.a 0, d ; CB 82 res.a 0, e ; CB 83 res.a 0, h ; CB 84 res.a 0, l ; CB 85 res.a 1, (hl) ; CB 8E res.a 1, (ix) ; FD CB 00 8E res.a 1, (ix+127) ; FD CB 7F 8E res.a 1, (ix-128) ; FD CB 80 8E res.a 1, (iy) ; DD CB 00 8E res.a 1, (iy+127) ; DD CB 7F 8E res.a 1, (iy-128) ; DD CB 80 8E res.a 1, a ; CB 8F res.a 1, b ; CB 88 res.a 1, c ; CB 89 res.a 1, d ; CB 8A res.a 1, e ; CB 8B res.a 1, h ; CB 8C res.a 1, l ; CB 8D res.a 2, (hl) ; CB 96 res.a 2, (ix) ; FD CB 00 96 res.a 2, (ix+127) ; FD CB 7F 96 res.a 2, (ix-128) ; FD CB 80 96 res.a 2, (iy) ; DD CB 00 96 res.a 2, (iy+127) ; DD CB 7F 96 res.a 2, (iy-128) ; DD CB 80 96 res.a 2, a ; CB 97 res.a 2, b ; CB 90 res.a 2, c ; CB 91 res.a 2, d ; CB 92 res.a 2, e ; CB 93 res.a 2, h ; CB 94 res.a 2, l ; CB 95 res.a 3, (hl) ; CB 9E res.a 3, (ix) ; FD CB 00 9E res.a 3, (ix+127) ; FD CB 7F 9E res.a 3, (ix-128) ; FD CB 80 9E res.a 3, (iy) ; DD CB 00 9E res.a 3, (iy+127) ; DD CB 7F 9E res.a 3, (iy-128) ; DD CB 80 9E res.a 3, a ; CB 9F res.a 3, b ; CB 98 res.a 3, c ; CB 99 res.a 3, d ; CB 9A res.a 3, e ; CB 9B res.a 3, h ; CB 9C res.a 3, l ; CB 9D res.a 4, (hl) ; CB A6 res.a 4, (ix) ; FD CB 00 A6 res.a 4, (ix+127) ; FD CB 7F A6 res.a 4, (ix-128) ; FD CB 80 A6 res.a 4, (iy) ; DD CB 00 A6 res.a 4, (iy+127) ; DD CB 7F A6 res.a 4, (iy-128) ; DD CB 80 A6 res.a 4, a ; CB A7 res.a 4, b ; CB A0 res.a 4, c ; CB A1 res.a 4, d ; CB A2 res.a 4, e ; CB A3 res.a 4, h ; CB A4 res.a 4, l ; CB A5 res.a 5, (hl) ; CB AE res.a 5, (ix) ; FD CB 00 AE res.a 5, (ix+127) ; FD CB 7F AE res.a 5, (ix-128) ; FD CB 80 AE res.a 5, (iy) ; DD CB 00 AE res.a 5, (iy+127) ; DD CB 7F AE res.a 5, (iy-128) ; DD CB 80 AE res.a 5, a ; CB AF res.a 5, b ; CB A8 res.a 5, c ; CB A9 res.a 5, d ; CB AA res.a 5, e ; CB AB res.a 5, h ; CB AC res.a 5, l ; CB AD res.a 6, (hl) ; CB B6 res.a 6, (ix) ; FD CB 00 B6 res.a 6, (ix+127) ; FD CB 7F B6 res.a 6, (ix-128) ; FD CB 80 B6 res.a 6, (iy) ; DD CB 00 B6 res.a 6, (iy+127) ; DD CB 7F B6 res.a 6, (iy-128) ; DD CB 80 B6 res.a 6, a ; CB B7 res.a 6, b ; CB B0 res.a 6, c ; CB B1 res.a 6, d ; CB B2 res.a 6, e ; CB B3 res.a 6, h ; CB B4 res.a 6, l ; CB B5 res.a 7, (hl) ; CB BE res.a 7, (ix) ; FD CB 00 BE res.a 7, (ix+127) ; FD CB 7F BE res.a 7, (ix-128) ; FD CB 80 BE res.a 7, (iy) ; DD CB 00 BE res.a 7, (iy+127) ; DD CB 7F BE res.a 7, (iy-128) ; DD CB 80 BE res.a 7, a ; CB BF res.a 7, b ; CB B8 res.a 7, c ; CB B9 res.a 7, d ; CB BA res.a 7, e ; CB BB res.a 7, h ; CB BC res.a 7, l ; CB BD ret ; C9 ret c ; D8 ret m ; F8 ret nc ; D0 ret nv ; E0 ret nz ; C0 ret p ; F0 ret pe ; E8 ret po ; E0 ret v ; E8 ret z ; C8 reti ; ED 4D retn ; ED 45 rl (hl) ; CB 16 rl (ix) ; FD CB 00 16 rl (ix+127) ; FD CB 7F 16 rl (ix-128) ; FD CB 80 16 rl (iy) ; DD CB 00 16 rl (iy+127) ; DD CB 7F 16 rl (iy-128) ; DD CB 80 16 rl a ; CB 17 rl b ; CB 10 rl bc ; CB 11 CB 10 rl c ; CB 11 rl d ; CB 12 rl de ; CB 13 CB 12 rl e ; CB 13 rl h ; CB 14 rl hl ; CB 15 CB 14 rl l ; CB 15 rla ; 17 rlc ; 07 rlc (hl) ; CB 06 rlc (ix) ; FD CB 00 06 rlc (ix+127) ; FD CB 7F 06 rlc (ix-128) ; FD CB 80 06 rlc (iy) ; DD CB 00 06 rlc (iy+127) ; DD CB 7F 06 rlc (iy-128) ; DD CB 80 06 rlc a ; CB 07 rlc b ; CB 00 rlc c ; CB 01 rlc d ; CB 02 rlc e ; CB 03 rlc h ; CB 04 rlc l ; CB 05 rlca ; 07 rld ; ED 6F rlde ; CB 13 CB 12 rm ; F8 rnc ; D0 rnv ; E0 rnz ; C0 rp ; F0 rpe ; E8 rpo ; E0 rr (hl) ; CB 1E rr (ix) ; FD CB 00 1E rr (ix+127) ; FD CB 7F 1E rr (ix-128) ; FD CB 80 1E rr (iy) ; DD CB 00 1E rr (iy+127) ; DD CB 7F 1E rr (iy-128) ; DD CB 80 1E rr a ; CB 1F rr b ; CB 18 rr bc ; CB 18 CB 19 rr c ; CB 19 rr d ; CB 1A rr de ; CB 1A CB 1B rr e ; CB 1B rr h ; CB 1C rr hl ; CB 1C CB 1D rr l ; CB 1D rra ; 1F rrc ; 0F rrc (hl) ; CB 0E rrc (ix) ; FD CB 00 0E rrc (ix+127) ; FD CB 7F 0E rrc (ix-128) ; FD CB 80 0E rrc (iy) ; DD CB 00 0E rrc (iy+127) ; DD CB 7F 0E rrc (iy-128) ; DD CB 80 0E rrc a ; CB 0F rrc b ; CB 08 rrc c ; CB 09 rrc d ; CB 0A rrc e ; CB 0B rrc h ; CB 0C rrc l ; CB 0D rrca ; 0F rrd ; ED 67 rrhl ; CB 2C CB 1D rst 0 ; C7 rst 1 ; CF rst 16 ; D7 rst 2 ; D7 rst 24 ; DF rst 3 ; DF rst 32 ; E7 rst 4 ; E7 rst 40 ; EF rst 48 ; F7 rst 5 ; EF rst 56 ; FF rst 6 ; F7 rst 7 ; FF rst 8 ; CF rv ; E8 rz ; C8 sbb a ; 9F sbb b ; 98 sbb c ; 99 sbb d ; 9A sbb e ; 9B sbb h ; 9C sbb l ; 9D sbb m ; 9E sbc (hl) ; 9E sbc (ix) ; FD 9E 00 sbc (ix+127) ; FD 9E 7F sbc (ix-128) ; FD 9E 80 sbc (iy) ; DD 9E 00 sbc (iy+127) ; DD 9E 7F sbc (iy-128) ; DD 9E 80 sbc -128 ; DE 80 sbc 127 ; DE 7F sbc 255 ; DE FF sbc a ; 9F sbc a, (hl) ; 9E sbc a, (ix) ; FD 9E 00 sbc a, (ix+127) ; FD 9E 7F sbc a, (ix-128) ; FD 9E 80 sbc a, (iy) ; DD 9E 00 sbc a, (iy+127) ; DD 9E 7F sbc a, (iy-128) ; DD 9E 80 sbc a, -128 ; DE 80 sbc a, 127 ; DE 7F sbc a, 255 ; DE FF sbc a, a ; 9F sbc a, b ; 98 sbc a, c ; 99 sbc a, d ; 9A sbc a, e ; 9B sbc a, h ; 9C sbc a, l ; 9D sbc b ; 98 sbc c ; 99 sbc d ; 9A sbc e ; 9B sbc h ; 9C sbc hl, bc ; ED 42 sbc hl, de ; ED 52 sbc hl, hl ; ED 62 sbc hl, sp ; ED 72 sbc l ; 9D sbi -128 ; DE 80 sbi 127 ; DE 7F sbi 255 ; DE FF scf ; 37 set 0, (hl) ; CB C6 set 0, (ix) ; FD CB 00 C6 set 0, (ix+127) ; FD CB 7F C6 set 0, (ix-128) ; FD CB 80 C6 set 0, (iy) ; DD CB 00 C6 set 0, (iy+127) ; DD CB 7F C6 set 0, (iy-128) ; DD CB 80 C6 set 0, a ; CB C7 set 0, b ; CB C0 set 0, c ; CB C1 set 0, d ; CB C2 set 0, e ; CB C3 set 0, h ; CB C4 set 0, l ; CB C5 set 1, (hl) ; CB CE set 1, (ix) ; FD CB 00 CE set 1, (ix+127) ; FD CB 7F CE set 1, (ix-128) ; FD CB 80 CE set 1, (iy) ; DD CB 00 CE set 1, (iy+127) ; DD CB 7F CE set 1, (iy-128) ; DD CB 80 CE set 1, a ; CB CF set 1, b ; CB C8 set 1, c ; CB C9 set 1, d ; CB CA set 1, e ; CB CB set 1, h ; CB CC set 1, l ; CB CD set 2, (hl) ; CB D6 set 2, (ix) ; FD CB 00 D6 set 2, (ix+127) ; FD CB 7F D6 set 2, (ix-128) ; FD CB 80 D6 set 2, (iy) ; DD CB 00 D6 set 2, (iy+127) ; DD CB 7F D6 set 2, (iy-128) ; DD CB 80 D6 set 2, a ; CB D7 set 2, b ; CB D0 set 2, c ; CB D1 set 2, d ; CB D2 set 2, e ; CB D3 set 2, h ; CB D4 set 2, l ; CB D5 set 3, (hl) ; CB DE set 3, (ix) ; FD CB 00 DE set 3, (ix+127) ; FD CB 7F DE set 3, (ix-128) ; FD CB 80 DE set 3, (iy) ; DD CB 00 DE set 3, (iy+127) ; DD CB 7F DE set 3, (iy-128) ; DD CB 80 DE set 3, a ; CB DF set 3, b ; CB D8 set 3, c ; CB D9 set 3, d ; CB DA set 3, e ; CB DB set 3, h ; CB DC set 3, l ; CB DD set 4, (hl) ; CB E6 set 4, (ix) ; FD CB 00 E6 set 4, (ix+127) ; FD CB 7F E6 set 4, (ix-128) ; FD CB 80 E6 set 4, (iy) ; DD CB 00 E6 set 4, (iy+127) ; DD CB 7F E6 set 4, (iy-128) ; DD CB 80 E6 set 4, a ; CB E7 set 4, b ; CB E0 set 4, c ; CB E1 set 4, d ; CB E2 set 4, e ; CB E3 set 4, h ; CB E4 set 4, l ; CB E5 set 5, (hl) ; CB EE set 5, (ix) ; FD CB 00 EE set 5, (ix+127) ; FD CB 7F EE set 5, (ix-128) ; FD CB 80 EE set 5, (iy) ; DD CB 00 EE set 5, (iy+127) ; DD CB 7F EE set 5, (iy-128) ; DD CB 80 EE set 5, a ; CB EF set 5, b ; CB E8 set 5, c ; CB E9 set 5, d ; CB EA set 5, e ; CB EB set 5, h ; CB EC set 5, l ; CB ED set 6, (hl) ; CB F6 set 6, (ix) ; FD CB 00 F6 set 6, (ix+127) ; FD CB 7F F6 set 6, (ix-128) ; FD CB 80 F6 set 6, (iy) ; DD CB 00 F6 set 6, (iy+127) ; DD CB 7F F6 set 6, (iy-128) ; DD CB 80 F6 set 6, a ; CB F7 set 6, b ; CB F0 set 6, c ; CB F1 set 6, d ; CB F2 set 6, e ; CB F3 set 6, h ; CB F4 set 6, l ; CB F5 set 7, (hl) ; CB FE set 7, (ix) ; FD CB 00 FE set 7, (ix+127) ; FD CB 7F FE set 7, (ix-128) ; FD CB 80 FE set 7, (iy) ; DD CB 00 FE set 7, (iy+127) ; DD CB 7F FE set 7, (iy-128) ; DD CB 80 FE set 7, a ; CB FF set 7, b ; CB F8 set 7, c ; CB F9 set 7, d ; CB FA set 7, e ; CB FB set 7, h ; CB FC set 7, l ; CB FD set.a 0, (hl) ; CB C6 set.a 0, (ix) ; FD CB 00 C6 set.a 0, (ix+127) ; FD CB 7F C6 set.a 0, (ix-128) ; FD CB 80 C6 set.a 0, (iy) ; DD CB 00 C6 set.a 0, (iy+127) ; DD CB 7F C6 set.a 0, (iy-128) ; DD CB 80 C6 set.a 0, a ; CB C7 set.a 0, b ; CB C0 set.a 0, c ; CB C1 set.a 0, d ; CB C2 set.a 0, e ; CB C3 set.a 0, h ; CB C4 set.a 0, l ; CB C5 set.a 1, (hl) ; CB CE set.a 1, (ix) ; FD CB 00 CE set.a 1, (ix+127) ; FD CB 7F CE set.a 1, (ix-128) ; FD CB 80 CE set.a 1, (iy) ; DD CB 00 CE set.a 1, (iy+127) ; DD CB 7F CE set.a 1, (iy-128) ; DD CB 80 CE set.a 1, a ; CB CF set.a 1, b ; CB C8 set.a 1, c ; CB C9 set.a 1, d ; CB CA set.a 1, e ; CB CB set.a 1, h ; CB CC set.a 1, l ; CB CD set.a 2, (hl) ; CB D6 set.a 2, (ix) ; FD CB 00 D6 set.a 2, (ix+127) ; FD CB 7F D6 set.a 2, (ix-128) ; FD CB 80 D6 set.a 2, (iy) ; DD CB 00 D6 set.a 2, (iy+127) ; DD CB 7F D6 set.a 2, (iy-128) ; DD CB 80 D6 set.a 2, a ; CB D7 set.a 2, b ; CB D0 set.a 2, c ; CB D1 set.a 2, d ; CB D2 set.a 2, e ; CB D3 set.a 2, h ; CB D4 set.a 2, l ; CB D5 set.a 3, (hl) ; CB DE set.a 3, (ix) ; FD CB 00 DE set.a 3, (ix+127) ; FD CB 7F DE set.a 3, (ix-128) ; FD CB 80 DE set.a 3, (iy) ; DD CB 00 DE set.a 3, (iy+127) ; DD CB 7F DE set.a 3, (iy-128) ; DD CB 80 DE set.a 3, a ; CB DF set.a 3, b ; CB D8 set.a 3, c ; CB D9 set.a 3, d ; CB DA set.a 3, e ; CB DB set.a 3, h ; CB DC set.a 3, l ; CB DD set.a 4, (hl) ; CB E6 set.a 4, (ix) ; FD CB 00 E6 set.a 4, (ix+127) ; FD CB 7F E6 set.a 4, (ix-128) ; FD CB 80 E6 set.a 4, (iy) ; DD CB 00 E6 set.a 4, (iy+127) ; DD CB 7F E6 set.a 4, (iy-128) ; DD CB 80 E6 set.a 4, a ; CB E7 set.a 4, b ; CB E0 set.a 4, c ; CB E1 set.a 4, d ; CB E2 set.a 4, e ; CB E3 set.a 4, h ; CB E4 set.a 4, l ; CB E5 set.a 5, (hl) ; CB EE set.a 5, (ix) ; FD CB 00 EE set.a 5, (ix+127) ; FD CB 7F EE set.a 5, (ix-128) ; FD CB 80 EE set.a 5, (iy) ; DD CB 00 EE set.a 5, (iy+127) ; DD CB 7F EE set.a 5, (iy-128) ; DD CB 80 EE set.a 5, a ; CB EF set.a 5, b ; CB E8 set.a 5, c ; CB E9 set.a 5, d ; CB EA set.a 5, e ; CB EB set.a 5, h ; CB EC set.a 5, l ; CB ED set.a 6, (hl) ; CB F6 set.a 6, (ix) ; FD CB 00 F6 set.a 6, (ix+127) ; FD CB 7F F6 set.a 6, (ix-128) ; FD CB 80 F6 set.a 6, (iy) ; DD CB 00 F6 set.a 6, (iy+127) ; DD CB 7F F6 set.a 6, (iy-128) ; DD CB 80 F6 set.a 6, a ; CB F7 set.a 6, b ; CB F0 set.a 6, c ; CB F1 set.a 6, d ; CB F2 set.a 6, e ; CB F3 set.a 6, h ; CB F4 set.a 6, l ; CB F5 set.a 7, (hl) ; CB FE set.a 7, (ix) ; FD CB 00 FE set.a 7, (ix+127) ; FD CB 7F FE set.a 7, (ix-128) ; FD CB 80 FE set.a 7, (iy) ; DD CB 00 FE set.a 7, (iy+127) ; DD CB 7F FE set.a 7, (iy-128) ; DD CB 80 FE set.a 7, a ; CB FF set.a 7, b ; CB F8 set.a 7, c ; CB F9 set.a 7, d ; CB FA set.a 7, e ; CB FB set.a 7, h ; CB FC set.a 7, l ; CB FD shld -32768 ; 22 00 80 shld 32767 ; 22 FF 7F shld 65535 ; 22 FF FF sla (hl) ; CB 26 sla (ix) ; FD CB 00 26 sla (ix+127) ; FD CB 7F 26 sla (ix-128) ; FD CB 80 26 sla (iy) ; DD CB 00 26 sla (iy+127) ; DD CB 7F 26 sla (iy-128) ; DD CB 80 26 sla a ; CB 27 sla b ; CB 20 sla c ; CB 21 sla d ; CB 22 sla e ; CB 23 sla h ; CB 24 sla l ; CB 25 sli (hl) ; CB 36 sli (ix) ; FD CB 00 36 sli (ix+127) ; FD CB 7F 36 sli (ix-128) ; FD CB 80 36 sli (iy) ; DD CB 00 36 sli (iy+127) ; DD CB 7F 36 sli (iy-128) ; DD CB 80 36 sli a ; CB 37 sli b ; CB 30 sli c ; CB 31 sli d ; CB 32 sli e ; CB 33 sli h ; CB 34 sli l ; CB 35 sll (hl) ; CB 36 sll (ix) ; FD CB 00 36 sll (ix+127) ; FD CB 7F 36 sll (ix-128) ; FD CB 80 36 sll (iy) ; DD CB 00 36 sll (iy+127) ; DD CB 7F 36 sll (iy-128) ; DD CB 80 36 sll a ; CB 37 sll b ; CB 30 sll c ; CB 31 sll d ; CB 32 sll e ; CB 33 sll h ; CB 34 sll l ; CB 35 slp ; ED 76 sls (hl) ; CB 36 sls (ix) ; FD CB 00 36 sls (ix+127) ; FD CB 7F 36 sls (ix-128) ; FD CB 80 36 sls (iy) ; DD CB 00 36 sls (iy+127) ; DD CB 7F 36 sls (iy-128) ; DD CB 80 36 sls a ; CB 37 sls b ; CB 30 sls c ; CB 31 sls d ; CB 32 sls e ; CB 33 sls h ; CB 34 sls l ; CB 35 sphl ; F9 sra (hl) ; CB 2E sra (ix) ; FD CB 00 2E sra (ix+127) ; FD CB 7F 2E sra (ix-128) ; FD CB 80 2E sra (iy) ; DD CB 00 2E sra (iy+127) ; DD CB 7F 2E sra (iy-128) ; DD CB 80 2E sra a ; CB 2F sra b ; CB 28 sra bc ; CB 28 CB 19 sra c ; CB 29 sra d ; CB 2A sra de ; CB 2A CB 1B sra e ; CB 2B sra h ; CB 2C sra hl ; CB 2C CB 1D sra l ; CB 2D srl (hl) ; CB 3E srl (ix) ; FD CB 00 3E srl (ix+127) ; FD CB 7F 3E srl (ix-128) ; FD CB 80 3E srl (iy) ; DD CB 00 3E srl (iy+127) ; DD CB 7F 3E srl (iy-128) ; DD CB 80 3E srl a ; CB 3F srl b ; CB 38 srl c ; CB 39 srl d ; CB 3A srl e ; CB 3B srl h ; CB 3C srl l ; CB 3D sta -32768 ; 32 00 80 sta 32767 ; 32 FF 7F sta 65535 ; 32 FF FF stax b ; 02 stax bc ; 02 stax d ; 12 stax de ; 12 stc ; 37 sub (hl) ; 96 sub (ix) ; FD 96 00 sub (ix+127) ; FD 96 7F sub (ix-128) ; FD 96 80 sub (iy) ; DD 96 00 sub (iy+127) ; DD 96 7F sub (iy-128) ; DD 96 80 sub -128 ; D6 80 sub 127 ; D6 7F sub 255 ; D6 FF sub a ; 97 sub a, (hl) ; 96 sub a, (ix) ; FD 96 00 sub a, (ix+127) ; FD 96 7F sub a, (ix-128) ; FD 96 80 sub a, (iy) ; DD 96 00 sub a, (iy+127) ; DD 96 7F sub a, (iy-128) ; DD 96 80 sub a, -128 ; D6 80 sub a, 127 ; D6 7F sub a, 255 ; D6 FF sub a, a ; 97 sub a, b ; 90 sub a, c ; 91 sub a, d ; 92 sub a, e ; 93 sub a, h ; 94 sub a, l ; 95 sub b ; 90 sub c ; 91 sub d ; 92 sub e ; 93 sub h ; 94 sub hl, bc ; CD @__z80asm__sub_hl_bc sub hl, de ; CD @__z80asm__sub_hl_de sub hl, hl ; CD @__z80asm__sub_hl_hl sub hl, sp ; CD @__z80asm__sub_hl_sp sub l ; 95 sub m ; 96 sui -128 ; D6 80 sui 127 ; D6 7F sui 255 ; D6 FF test (hl) ; ED 34 test (ix) ; FD ED 00 34 test (ix+127) ; FD ED 7F 34 test (ix-128) ; FD ED 80 34 test (iy) ; DD ED 00 34 test (iy+127) ; DD ED 7F 34 test (iy-128) ; DD ED 80 34 test -128 ; ED 64 80 test 127 ; ED 64 7F test 255 ; ED 64 FF test a ; ED 3C test a, (hl) ; ED 34 test a, (ix) ; FD ED 00 34 test a, (ix+127) ; FD ED 7F 34 test a, (ix-128) ; FD ED 80 34 test a, (iy) ; DD ED 00 34 test a, (iy+127) ; DD ED 7F 34 test a, (iy-128) ; DD ED 80 34 test a, -128 ; ED 64 80 test a, 127 ; ED 64 7F test a, 255 ; ED 64 FF test a, a ; ED 3C test a, b ; ED 04 test a, c ; ED 0C test a, d ; ED 14 test a, e ; ED 1C test a, h ; ED 24 test a, l ; ED 2C test b ; ED 04 test c ; ED 0C test d ; ED 14 test e ; ED 1C test h ; ED 24 test l ; ED 2C tst (hl) ; ED 34 tst (ix) ; FD ED 00 34 tst (ix+127) ; FD ED 7F 34 tst (ix-128) ; FD ED 80 34 tst (iy) ; DD ED 00 34 tst (iy+127) ; DD ED 7F 34 tst (iy-128) ; DD ED 80 34 tst -128 ; ED 64 80 tst 127 ; ED 64 7F tst 255 ; ED 64 FF tst a ; ED 3C tst a, (hl) ; ED 34 tst a, (ix) ; FD ED 00 34 tst a, (ix+127) ; FD ED 7F 34 tst a, (ix-128) ; FD ED 80 34 tst a, (iy) ; DD ED 00 34 tst a, (iy+127) ; DD ED 7F 34 tst a, (iy-128) ; DD ED 80 34 tst a, -128 ; ED 64 80 tst a, 127 ; ED 64 7F tst a, 255 ; ED 64 FF tst a, a ; ED 3C tst a, b ; ED 04 tst a, c ; ED 0C tst a, d ; ED 14 tst a, e ; ED 1C tst a, h ; ED 24 tst a, l ; ED 2C tst b ; ED 04 tst c ; ED 0C tst d ; ED 14 tst e ; ED 1C tst h ; ED 24 tst l ; ED 2C tstio -128 ; ED 74 80 tstio 127 ; ED 74 7F tstio 255 ; ED 74 FF xchg ; EB xor (hl) ; AE xor (ix) ; FD AE 00 xor (ix+127) ; FD AE 7F xor (ix-128) ; FD AE 80 xor (iy) ; DD AE 00 xor (iy+127) ; DD AE 7F xor (iy-128) ; DD AE 80 xor -128 ; EE 80 xor 127 ; EE 7F xor 255 ; EE FF xor a ; AF xor a, (hl) ; AE xor a, (ix) ; FD AE 00 xor a, (ix+127) ; FD AE 7F xor a, (ix-128) ; FD AE 80 xor a, (iy) ; DD AE 00 xor a, (iy+127) ; DD AE 7F xor a, (iy-128) ; DD AE 80 xor a, -128 ; EE 80 xor a, 127 ; EE 7F xor a, 255 ; EE FF xor a, a ; AF xor a, b ; A8 xor a, c ; A9 xor a, d ; AA xor a, e ; AB xor a, h ; AC xor a, l ; AD xor b ; A8 xor c ; A9 xor d ; AA xor e ; AB xor h ; AC xor l ; AD xra a ; AF xra b ; A8 xra c ; A9 xra d ; AA xra e ; AB xra h ; AC xra l ; AD xra m ; AE xri -128 ; EE 80 xri 127 ; EE 7F xri 255 ; EE FF xthl ; E3
;;; Spawns additional PLMs into rooms without needing to repoint anything ;;; ;;; compile with asar (https://www.smwcentral.net/?a=details&id=14560&p=section), ;;; or a variant of xkas that supports arch directive arch snes.cpu lorom ;;; HIJACKS (room load routines in bank 82) org $82e8d5 jsl add_plms org $82eb8b jsl add_plms ;;; DATA in bank 8F free space org $8fe9a0 ;;; additional zero-terminated PLM lists go here (written at ROM generation) print "downwards plm_lists table start: ", pc plm_lists: ;;; TEST ;; dw $B76F ;; db $0B, $09 ;; dw $0007 ;;; dw $0000 ; PLM 1 ID dw $00,$00 ; PLM 1 X, PLM 1 Y dw $0000 ; PLM 1 argument ;; ... dw $0000 ; PLM n ID dw $00,$00 ; PLM n X, PLM n Y dw $0000 ; PLM n argument dw $0000 ; PLM list 1 terminator ;; ... ;;; *** Non-overlap in this space has to be handled at ROM generation *** org $8febf8 ;;; Additional PLM definitions for rooms *going upwards* (written at ROM generation) ;;; ;;; PLM lists are indexed by (Room ptr, Room State ptr, Entry Door ptr) and terminated by $0000 ;;; ;;; Only Room is mandatory, if any other is $0000 it will be ignored. ;;; ;;; List terminated by room ID $0000 room_plms: ;; Room State Door PLM list address dw $0000, $0000, $0000, $0000 ;;; TEST ;; room_plms: ;; dw $99bd, $99ca, $8b1a, plm_lists ;;; print "upwards room_plms table start: ", pc ;;; CODE in bank 8F org $8ff300 add_plms: phx ;; iterate through room table ;; we use only X as index register because of no "LDA bbaaaa,Y" instruction ldx #room_plms .room_loop: lda $8f0000,x : beq .end cmp $079b : beq .room_ok bra .next_entry .room_ok: lda $8f0002,x : beq .state_ok cmp $07bb : beq .state_ok bra .next_entry .state_ok: lda $8f0004,x : beq .load cmp $078d : beq .load bra .next_entry .load: phx ; save our room table iterator lda $8f0006,x : tax ; put PLM list address in X .plm_loop: lda $8f0000,x : beq .load_end jsl $84846a ; spawn room PLM. argument is X : PLM offset in bank 8F rep 6 : inx ; X += 6 bra .plm_loop .load_end: plx ; restore room table iterator .next_entry: txa : sec : sbc #$0008 : tax ; X -= 8 bra .room_loop .end: plx ;; vanilla code (call door asm) jsl $8fe8a3 rtl warnpc $8ff3ff
; --------------------------------------------------------------------------- ; Tell compiler to generate 64 bit code ; --------------------------------------------------------------------------- bits 64
; ; ZX Spectrum specific routines ; by Stefano Bodrato, 22/06/2006 ; ; This routine gives the length of the current BASIC program. ; Memory used by variables is not included. ; ; $Id: zx_basic_length.asm,v 1.1 2006/06/28 22:21:26 stefano Exp $ ; XLIB zx_basic_length zx_basic_length: ld de,($5c53) ; PROG :location of BASIC program ld hl,($5c4b) ; VARS :location of variables sbc hl,de ret
; A141107: Upper Odd Swappage of Upper Wythoff Sequence. ; 3,5,7,11,13,15,19,21,23,27,29,31,35,37,39,41,45,47,49,53,55,57,61,63,65,69,71,73,75,79,81,83,87,89,91,95,97,99,103,105,107,109,113,115,117,121,123,125,129,131,133,137,139,141,143,147,149,151,155,157,159,163 add $0,1 mov $1,17 mul $1,$0 div $1,13 mul $1,2 add $1,1 mov $0,$1
SECTION rodata_font SECTION rodata_font_fzx PUBLIC _ff_dkud4_Font04 _ff_dkud4_Font04: BINARY "font/fzx/fonts/dkud4/Font04/font04.fzx"
// Copyright (c) 2014-2015 The ShadowCoin developers // Copyright (c) 2017 The Particl developers // Copyright (c) 2018 The Efin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <key/extkey.h> #include <key/keyutil.h> #include <util.h> #include <base58.h> #include <crypto/hmac_sha512.h> #include <stdint.h> CCriticalSection cs_extKey; const char *ExtKeyGetString(int ind) { switch (ind) { case 2: return "Path string too long"; case 3: return "Path string empty"; case 4: return "Integer conversion invalid character"; case 5: return "Integer conversion out of range"; case 7: return "Malformed path"; case 8: return "Offset is hardened already"; case 9: return "Can't use BIP44 key as master"; case 10: return "Ext key not found in wallet"; case 11: return "This key is already the master key"; case 12: return "Derived key already exists in wallet"; case 13: return "Failed to unlock"; case 14: return "Account already exists in db."; case 15: return "Account not found in wallet"; case 16: return "Invalid params pointer"; default: return "Unknown error, check log"; }; }; std::vector<uint8_t> &SetCompressedInt64(std::vector<uint8_t> &v, uint64_t n) { int b = GetNumBytesReqForInt(n); v.resize(b); if (b > 0) memcpy(&v[0], (uint8_t*) &n, b); return v; }; int64_t GetCompressedInt64(const std::vector<uint8_t> &v, uint64_t &n) { int b = v.size(); n = 0; if (b < 1) n = 0; else if (b < 9) memcpy((uint8_t*) &n, &v[0], b); return (int64_t)n; }; std::vector<uint8_t> &SetCKeyID(std::vector<uint8_t> &v, CKeyID n) { v.resize(20); memcpy(&v[0], (uint8_t*) &n, 20); return v; }; bool GetCKeyID(const std::vector<uint8_t> &v, CKeyID &n) { if (v.size() != 20) return false; memcpy((uint8_t*) &n, &v[0], 20); return true; }; std::vector<uint8_t> &SetString(std::vector<uint8_t> &v, const char *s) { size_t len = strlen(s); v.resize(len); memcpy(&v[0], (uint8_t*) &s, len); return v; }; std::vector<uint8_t> &SetChar(std::vector<uint8_t> &v, const uint8_t c) { v.resize(1); v[0] = c; return v; }; std::vector<uint8_t> &PushUInt32(std::vector<uint8_t> &v, const uint32_t i) { size_t o = v.size(); v.resize(o+4); memcpy(&v[o], (uint8_t*) &i, 4); return v; }; #define _UINT32_MAX (0xffffffff) static uint32_t strtou32max(const char *nptr, int base) { const char *s; uintmax_t acc; char c; uintmax_t cutoff; int neg, any, cutlim; s = nptr; do { c = *s++; } while (isspace((unsigned char)c)); if (c == '-') { neg = 1; c = *s++; } else { neg = 0; if (c == '+') c = *s++; } if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X') && ((s[1] >= '0' && s[1] <= '9') || (s[1] >= 'A' && s[1] <= 'F') || (s[1] >= 'a' && s[1] <= 'f'))) { c = s[1]; s += 2; base = 16; } if (base == 0) base = c == '0' ? 8 : 10; acc = any = 0; if (base < 2 || base > 36) goto noconv; cutoff = _UINT32_MAX / base; cutlim = _UINT32_MAX % base; for ( ; ; c = *s++) { if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'A' && c <= 'Z') c -= 'A' - 10; else if (c >= 'a' && c <= 'z') c -= 'a' - 10; else break; if (c >= base) break; if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; acc *= base; acc += c; } } if (any < 0) { acc = _UINT32_MAX; errno = ERANGE; } else if (!any) { noconv: errno = EINVAL; } else if (neg) acc = -acc; return (acc); }; static inline int validDigit(char c, int base) { switch(base) { case 2: return c == '0' || c == '1'; case 10: return c >= '0' && c <= '9'; case 16: return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); default: errno = EINVAL; }; return 0; }; int ExtractExtKeyPath(const std::string &sPath, std::vector<uint32_t> &vPath) { char data[512]; vPath.clear(); if (sPath.length() > sizeof(data) -2) return 2; if (sPath.length() < 1) return 3; size_t nStart = 0; size_t nLen = sPath.length(); if (tolower(sPath[0]) == 'm') { nStart+=2; nLen-=2; }; if (nLen < 1) return 3; memcpy(data, sPath.data()+nStart, nLen); data[nLen] = '\0'; int nSlashes = 0; for (size_t k = 0; k < nLen; ++k) { if (data[k] == '/') { nSlashes++; // Catch start or end '/', and '//' if (k == 0 || k == nLen-1 || (k < nLen-1 && data[k+1] == '/')) return 7; }; }; vPath.reserve(nSlashes + 1); char *p = strtok(data, "/"); while (p) { uint32_t nChild; bool fHarden = false; // Don't allow octal, only hex and binary int nBase = *p == '0' && (*(p+1) == 'b' || *(p+1) == 'B') ? 2 : *p == '0' && (*(p+1) == 'x' || *(p+1) == 'X') ? 16 : 10; if (nBase != 10) p += 2; // step over 0b / 0x char *ps = p; for (; *p; ++p) { // Last char can be (h, H ,') if (!*(p+1) && (tolower(*p) == 'h' || *p == '\'')) { fHarden = true; *p = '\0'; } else if (!validDigit(*p, nBase)) return 4; }; errno = 0; nChild = strtou32max(ps, nBase); if (errno != 0) return 5; if (fHarden) { if ((nChild >> 31) == 0) { nChild |= 1 << 31; } else { return 8; }; }; vPath.push_back(nChild); p = strtok(nullptr, "/"); }; if (vPath.size() < 1) return 3; return 0; }; void CExtPubKey::Encode(unsigned char code[74]) const { code[0] = nDepth; memcpy(code+1, vchFingerprint, 4); code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; memcpy(code+9, vchChainCode, 32); assert(pubkey.size() == 33); memcpy(code+41, pubkey.begin(), 33); }; void CExtPubKey::Decode(const unsigned char code[74]) { nDepth = code[0]; memcpy(vchFingerprint, code+1, 4); nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; memcpy(vchChainCode, code+9, 32); pubkey.Set(code+41, code+74); }; bool CExtPubKey::Derive(CExtPubKey &out, unsigned int nChild) const { out.nDepth = nDepth + 1; CKeyID id = pubkey.GetID(); memcpy(&out.vchFingerprint[0], &id, 4); out.nChild = nChild; return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode); }; bool CExtKey::Derive(CExtKey &out, unsigned int nChild) const { out.nDepth = nDepth + 1; CKeyID id = key.GetPubKey().GetID(); memcpy(&out.vchFingerprint[0], &id, 4); out.nChild = nChild; return key.Derive(out.key, out.vchChainCode, nChild, vchChainCode); }; void CExtKey::SetMaster(const unsigned char *seed, unsigned int nSeedLen) { static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'}; std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data()); key.Set(&vout[0], &vout[32], true); memcpy(vchChainCode, &vout[32], 32); nDepth = 0; nChild = 0; memset(vchFingerprint, 0, sizeof(vchFingerprint)); }; int CExtKey::SetKeyCode(const unsigned char *pkey, const unsigned char *pcode) { key.Set(pkey, true); memcpy(vchChainCode, pcode, 32); nDepth = 0; nChild = 0; memset(vchFingerprint, 0, sizeof(vchFingerprint)); return 0; }; CExtPubKey CExtKey::Neutered() const { CExtPubKey ret; ret.nDepth = nDepth; memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4); ret.nChild = nChild; ret.pubkey = key.GetPubKey(); memcpy(&ret.vchChainCode[0], &vchChainCode[0], 32); return ret; }; void CExtKey::Encode(unsigned char code[74]) const { code[0] = nDepth; memcpy(code+1, vchFingerprint, 4); code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; memcpy(code+9, vchChainCode, 32); code[41] = 0; assert(key.size() == 32); memcpy(code+42, key.begin(), 32); }; void CExtKey::Decode(const unsigned char code[74]) { nDepth = code[0]; memcpy(vchFingerprint, code+1, 4); nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; memcpy(vchChainCode, code+9, 32); key.Set(code+42, code+74, true); }; void CExtKeyPair::EncodeV(unsigned char code[74]) const { code[0] = nDepth; memcpy(code+1, vchFingerprint, 4); code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; memcpy(code+9, vchChainCode, 32); code[41] = 0; assert(key.size() == 32); memcpy(code+42, key.begin(), 32); }; void CExtKeyPair::DecodeV(const unsigned char code[74]) { nDepth = code[0]; memcpy(vchFingerprint, code+1, 4); nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; memcpy(vchChainCode, code+9, 32); key.Set(code+42, code+74, true); pubkey = key.GetPubKey(); }; void CExtKeyPair::EncodeP(unsigned char code[74]) const { code[0] = nDepth; memcpy(code+1, vchFingerprint, 4); code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF; code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF; memcpy(code+9, vchChainCode, 32); assert(pubkey.size() == 33); memcpy(code+41, pubkey.begin(), 33); }; void CExtKeyPair::DecodeP(const unsigned char code[74]) { nDepth = code[0]; memcpy(vchFingerprint, code+1, 4); nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8]; memcpy(vchChainCode, code+9, 32); pubkey.Set(code+41, code+74); key.Clear(); }; bool CExtKeyPair::Derive(CExtKey &out, unsigned int nChild) const { if (!key.IsValid()) return false; out.nDepth = nDepth + 1; CKeyID id = key.GetPubKey().GetID(); memcpy(&out.vchFingerprint[0], &id, 4); out.nChild = nChild; return key.Derive(out.key, out.vchChainCode, nChild, vchChainCode); }; bool CExtKeyPair::Derive(CExtPubKey &out, unsigned int nChild) const { if ((nChild >> 31) == 0) { out.nDepth = nDepth + 1; CKeyID id = pubkey.GetID(); memcpy(&out.vchFingerprint[0], &id, 4); out.nChild = nChild; return pubkey.Derive(out.pubkey, out.vchChainCode, nChild, vchChainCode); }; if (!key.IsValid()) return false; out.nDepth = nDepth + 1; CKeyID id = pubkey.GetID(); memcpy(&out.vchFingerprint[0], &id, 4); out.nChild = nChild; CKey tkey; if (!key.Derive(tkey, out.vchChainCode, nChild, vchChainCode)) return false; out.pubkey = tkey.GetPubKey(); return true; }; bool CExtKeyPair::Derive(CKey &out, unsigned int nChild) const { if (!key.IsValid()) return false; unsigned char temp[32]; return key.Derive(out, temp, nChild, vchChainCode); }; bool CExtKeyPair::Derive(CPubKey &out, unsigned int nChild) const { unsigned char temp[32]; if ((nChild >> 31) == 0) { return pubkey.Derive(out, temp, nChild, vchChainCode); }; if (!key.IsValid()) return false; CKey tkey; if (!key.Derive(tkey, temp, nChild, vchChainCode)) return false; out = tkey.GetPubKey(); return true; }; CExtPubKey CExtKeyPair::GetExtPubKey() const { CExtPubKey ret; ret.nDepth = nDepth; memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4); ret.nChild = nChild; ret.pubkey = pubkey; memcpy(&ret.vchChainCode[0], &vchChainCode[0], 32); return ret; }; CExtKeyPair CExtKeyPair::Neutered() const { CExtKeyPair ret; ret.nDepth = nDepth; memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4); ret.nChild = nChild; ret.pubkey = pubkey; ret.key.Clear(); memcpy(&ret.vchChainCode[0], &vchChainCode[0], 32); return ret; } void CExtKeyPair::SetMaster(const unsigned char *seed, unsigned int nSeedLen) { static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'}; std::vector<unsigned char, secure_allocator<unsigned char>> vout(64); CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data()); key.Set(&vout[0], &vout[32], true); pubkey = key.GetPubKey(); memcpy(vchChainCode, &vout[32], 32); nDepth = 0; nChild = 0; memset(vchFingerprint, 0, sizeof(vchFingerprint)); }; int CExtKeyPair::SetKeyCode(const unsigned char *pkey, const unsigned char *pcode) { key.Set(pkey, true); pubkey = key.GetPubKey(); memcpy(vchChainCode, pcode, 32); nDepth = 0; nChild = 0; memset(vchFingerprint, 0, sizeof(vchFingerprint)); return 0; }; std::string CEKAStealthKey::ToStealthAddress() const { // Return base58 encoded public stealth address CStealthAddress sxAddr; SetSxAddr(sxAddr); return sxAddr.Encoded(); }; int CEKAStealthKey::SetSxAddr(CStealthAddress &sxAddr) const { sxAddr.prefix.number_bits = nPrefixBits; sxAddr.prefix.bitfield = nPrefix; sxAddr.scan_pubkey = pkScan; sxAddr.spend_pubkey = pkSpend; sxAddr.scan_secret.Set(skScan.begin(), true); return 0; }; int CEKAStealthKey::ToRaw(std::vector<uint8_t> &raw) const { // inefficient CStealthAddress sxAddr; SetSxAddr(sxAddr); return sxAddr.ToRaw(raw); }; std::string CStoredExtKey::GetIDString58() const { return HDKeyIDToString(kp.GetID()); }; int CStoredExtKey::SetPath(const std::vector<uint32_t> &vPath_) { if (vPath_.size() < 1) return 1; std::vector<uint8_t> vPath(4 * vPath_.size()); memcpy(vPath.data(), vPath_.data(), vPath.size()); mapValue[EKVT_PATH] = vPath; return 0; }; std::string CExtKeyAccount::GetIDString58() const { // 0th chain is always account chain if (vExtKeyIDs.size() < 1) return "Not Set"; return HDAccIDToString(vExtKeyIDs[0]); }; int CExtKeyAccount::HaveSavedKey(const CKeyID &id) { LOCK(cs_account); AccKeyMap::const_iterator mi = mapKeys.find(id); if (mi != mapKeys.end()) return HK_YES; return HK_NO; }; int CExtKeyAccount::HaveKey(const CKeyID &id, bool fUpdate, const CEKAKey *&pak, const CEKASCKey *&pasc, isminetype &ismine) { // If fUpdate, promote key if found in look ahead LOCK(cs_account); pasc = nullptr; AccKeyMap::const_iterator mi = mapKeys.find(id); if (mi != mapKeys.end()) { pak = &mi->second; ismine = IsMine(pak->nParent); return HK_YES; }; mi = mapLookAhead.find(id); if (mi != mapLookAhead.end()) { pak = &mi->second; ismine = IsMine(pak->nParent); if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("HaveKey in lookAhead %s\n", CBitcoinAddress(mi->first).ToString()); return fUpdate ? HK_LOOKAHEAD_DO_UPDATE : HK_LOOKAHEAD; }; pak = nullptr; return HaveStealthKey(id, pasc, ismine); }; int CExtKeyAccount::HaveStealthKey(const CKeyID &id, const CEKASCKey *&pasc, isminetype &ismine) { LOCK(cs_account); AccKeySCMap::const_iterator miSck = mapStealthChildKeys.find(id); if (miSck != mapStealthChildKeys.end()) { pasc = &miSck->second; AccStealthKeyMap::const_iterator miSk = mapStealthKeys.find(pasc->idStealthKey); if (miSk == mapStealthKeys.end()) ismine = ISMINE_NO; else ismine = IsMine(miSk->second.akSpend.nParent); return HK_YES; }; ismine = ISMINE_NO; return HK_NO; }; bool CExtKeyAccount::GetKey(const CKeyID &id, CKey &keyOut) const { CEKAKey ak; CKeyID idStealth; return GetKey(id, keyOut, ak, idStealth); }; bool CExtKeyAccount::GetKey(const CEKAKey &ak, CKey &keyOut) const { LOCK(cs_account); if (ak.nParent >= vExtKeys.size()) return error("%s: Account key invalid parent ext key %d, account %s.", __func__, ak.nParent, GetIDString58()); const CStoredExtKey *chain = vExtKeys[ak.nParent]; if (chain->fLocked) return error("%s: Chain locked, account %s.", __func__, GetIDString58()); if (!chain->kp.Derive(keyOut, ak.nKey)) return false; return true; }; bool CExtKeyAccount::GetKey(const CEKASCKey &asck, CKey &keyOut) const { LOCK(cs_account); AccStealthKeyMap::const_iterator miSk = mapStealthKeys.find(asck.idStealthKey); if (miSk == mapStealthKeys.end()) return error("%s: CEKASCKey Stealth key not found.", __func__); return (0 == ExpandStealthChildKey(&miSk->second, asck.sShared, keyOut)); }; int CExtKeyAccount::GetKey(const CKeyID &id, CKey &keyOut, CEKAKey &ak, CKeyID &idStealth) const { LOCK(cs_account); int rv = 0; AccKeyMap::const_iterator mi; AccKeySCMap::const_iterator miSck; if ((mi = mapKeys.find(id)) != mapKeys.end()) { ak = mi->second; if (!GetKey(ak, keyOut)) return 0; rv = 1; } else if ((miSck = mapStealthChildKeys.find(id)) != mapStealthChildKeys.end()) { idStealth = miSck->second.idStealthKey; if (!GetKey(miSck->second, keyOut)) return 0; rv = 2; } else { return 0; }; // [rm] necessary? if (LogAcceptCategory(BCLog::HDWALLET) && keyOut.GetPubKey().GetID() != id) return error("Stored key mismatch."); return rv; }; bool CExtKeyAccount::GetPubKey(const CKeyID &id, CPubKey &pkOut) const { LOCK(cs_account); AccKeyMap::const_iterator mi; AccKeySCMap::const_iterator miSck; if ((mi = mapKeys.find(id)) != mapKeys.end()) { if (!GetPubKey(mi->second, pkOut)) return false; } else if ((miSck = mapStealthChildKeys.find(id)) != mapStealthChildKeys.end()) { if (!GetPubKey(miSck->second, pkOut)) return false; } else { return false; }; if (LogAcceptCategory(BCLog::HDWALLET)) // [rm] necessary? { if (pkOut.GetID() != id) return errorN(1, "%s: Extracted public key mismatch.", __func__); }; return true; }; bool CExtKeyAccount::GetPubKey(const CEKAKey &ak, CPubKey &pkOut) const { LOCK(cs_account); if (ak.nParent >= vExtKeys.size()) return error("%s: Account key invalid parent ext key %d, account %s.", __func__, ak.nParent, GetIDString58()); const CStoredExtKey *chain = GetChain(ak.nParent); if (!chain) return error("%s: Chain unknown, account %s.", __func__, GetIDString58()); if (!chain->kp.Derive(pkOut, ak.nKey)) return false; return true; }; bool CExtKeyAccount::GetPubKey(const CEKASCKey &asck, CPubKey &pkOut) const { LOCK(cs_account); AccStealthKeyMap::const_iterator miSk = mapStealthKeys.find(asck.idStealthKey); if (miSk == mapStealthKeys.end()) return error("%s: CEKASCKey Stealth key not in this account!", __func__); return (0 == ExpandStealthChildPubKey(&miSk->second, asck.sShared, pkOut)); }; bool CExtKeyAccount::SaveKey(const CKeyID &id, const CEKAKey &keyIn) { // TODO: rename? this is taking a key from lookahead and saving it LOCK(cs_account); AccKeyMap::const_iterator mi = mapKeys.find(id); if (mi != mapKeys.end()) return false; // already saved if (mapLookAhead.erase(id) != 1) LogPrintf("Warning: SaveKey %s key not found in look ahead %s.\n", GetIDString58(), CBitcoinAddress(id).ToString()); mapKeys[id] = keyIn; CStoredExtKey *pc; if (!IsHardened(keyIn.nKey) && (pc = GetChain(keyIn.nParent)) != nullptr) { // TODO: gaps? if (keyIn.nKey == pc->nGenerated) pc->nGenerated++; else if (keyIn.nKey > pc->nGenerated) { // Incase keys have been processed out of order, go back and check for received keys for (uint32_t i = pc->nGenerated; i <= keyIn.nKey; ++i) { uint32_t nChildOut = 0; CPubKey pk; if (0 != pc->DeriveKey(pk, i, nChildOut, false)) { LogPrintf("%s DeriveKey failed %d.\n", __func__, i); break; }; const CEKAKey *pak = nullptr; const CEKASCKey *pasc = nullptr; isminetype ismine; if (HK_YES != HaveKey(pk.GetID(), false, pak, pasc, ismine)) break; pc->nGenerated = i; }; }; if (pc->nFlags & EAF_ACTIVE && pc->nFlags & EAF_RECEIVE_ON) AddLookAhead(keyIn.nParent, 1); }; if (LogAcceptCategory(BCLog::HDWALLET)) { LogPrintf("Saved key %s %d, %s.\n", GetIDString58(), keyIn.nParent, CBitcoinAddress(id).ToString()); // Check match CStoredExtKey *pa; if ((pa = GetChain(keyIn.nParent)) != nullptr) { if ((keyIn.nKey >> 31) == 1 && pa->fLocked == 1) { LogPrintf("Can't check hardened key when wallet locked.\n"); return true; }; CPubKey pk; if (!GetPubKey(keyIn, pk)) return error("GetPubKey failed."); if (pk.GetID() != id) return error("Key mismatch!"); LogPrintf("Key match verified.\n"); } else { return error("Unknown chain."); }; }; return true; }; bool CExtKeyAccount::SaveKey(const CKeyID &id, const CEKASCKey &keyIn) { LOCK(cs_account); AccKeySCMap::const_iterator mi = mapStealthChildKeys.find(id); if (mi != mapStealthChildKeys.end()) return false; // already saved AccStealthKeyMap::const_iterator miSk = mapStealthKeys.find(keyIn.idStealthKey); if (miSk == mapStealthKeys.end()) return error("SaveKey(): CEKASCKey Stealth key not in this account!"); mapStealthChildKeys[id] = keyIn; if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("SaveKey(): CEKASCKey %s, %s.\n", GetIDString58(), CBitcoinAddress(id).ToString()); return true; }; bool CExtKeyAccount::IsLocked(const CEKAStealthKey &aks) { // TODO: check aks belongs to account?? CStoredExtKey *pc = GetChain(aks.akSpend.nParent); if (pc && !pc->fLocked) return false; return true; }; int CExtKeyAccount::AddLookBehind(uint32_t nChain, uint32_t nKeys) { CStoredExtKey *pc = GetChain(nChain); if (!pc) return errorN(1, "%s: Unknown chain, %d.", __func__, nChain); if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: chain %s, keys %d.\n", __func__, pc->GetIDString58(), nKeys); AccKeyMap::const_iterator mi; uint32_t nChild = pc->nGenerated; uint32_t nChildOut = nChild; CKeyID keyId; CPubKey pk; for (uint32_t k = 0; k < nKeys; ++k) { bool fGotKey = false; if (nChild == 0) { LogPrint(BCLog::HDWALLET, "%s: chain %s, at key 0.\n", __func__, pc->GetIDString58()); break; } nChild -=1; uint32_t nMaxTries = 32; // TODO: link to lookahead size for (uint32_t i = 0; i < nMaxTries; ++i) // nMaxTries > lookahead pool { if (pc->DeriveKey(pk, nChild, nChildOut, false) != 0) { LogPrintf("Error: %s - DeriveKey failed, chain %d, child %d.\n", __func__, nChain, nChild); nChild = nChildOut-1; continue; }; nChild = nChildOut-1; keyId = pk.GetID(); if ((mi = mapKeys.find(keyId)) != mapKeys.end()) { if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: key exists in map skipping %s.\n", __func__, CBitcoinAddress(keyId).ToString()); continue; }; if ((mi = mapLookAhead.find(keyId)) != mapLookAhead.end()) continue; fGotKey = true; break; }; if (!fGotKey) { LogPrintf("Error: %s - DeriveKey loop failed, chain %d, child %d.\n", __func__, nChain, nChild); continue; }; mapLookAhead[keyId] = CEKAKey(nChain, nChildOut); if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: Added %s, look-ahead size %u.\n", __func__, CBitcoinAddress(keyId).ToString(), mapLookAhead.size()); }; return 0; }; int CExtKeyAccount::AddLookAhead(uint32_t nChain, uint32_t nKeys) { // Must start from key 0 CStoredExtKey *pc = GetChain(nChain); if (!pc) return errorN(1, "%s: Unknown chain, %d.", __func__, nChain); AccKeyMap::const_iterator mi; uint32_t nChild = std::max(pc->nGenerated, pc->nLastLookAhead); uint32_t nChildOut = nChild; if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: chain %s, keys %d, from %d.\n", __func__, pc->GetIDString58(), nKeys, nChildOut); CKeyID keyId; CPubKey pk; for (uint32_t k = 0; k < nKeys; ++k) { bool fGotKey = false; uint32_t nMaxTries = 1000; // TODO: link to lookahead size for (uint32_t i = 0; i < nMaxTries; ++i) // nMaxTries > lookahead pool { if (pc->DeriveKey(pk, nChild, nChildOut, false) != 0) { LogPrintf("Error: %s - DeriveKey failed, chain %d, child %d.\n", __func__, nChain, nChild); nChild = nChildOut+1; continue; }; nChild = nChildOut+1; keyId = pk.GetID(); if ((mi = mapKeys.find(keyId)) != mapKeys.end()) { if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: key exists in map skipping %s.\n", __func__, CBitcoinAddress(keyId).ToString()); continue; }; if ((mi = mapLookAhead.find(keyId)) != mapLookAhead.end()) continue; fGotKey = true; break; }; if (!fGotKey) { LogPrintf("Error: %s - DeriveKey loop failed, chain %d, child %d.\n", __func__, nChain, nChild); continue; }; mapLookAhead[keyId] = CEKAKey(nChain, nChildOut); pc->nLastLookAhead = nChildOut; if (LogAcceptCategory(BCLog::HDWALLET)) LogPrintf("%s: Added %s, look-ahead size %u.\n", __func__, CBitcoinAddress(keyId).ToString(), mapLookAhead.size()); }; return 0; }; int CExtKeyAccount::ExpandStealthChildKey(const CEKAStealthKey *aks, const CKey &sShared, CKey &kOut) const { // Derive the secret key of the stealth address and then the secret key out LOCK(cs_account); if (!aks) return errorN(1, "%s: Sanity checks failed.", __func__); CKey kSpend; if (!GetKey(aks->akSpend, kSpend)) return errorN(1, "%s: GetKey() failed.", __func__); if (StealthSharedToSecretSpend(sShared, kSpend, kOut) != 0) return errorN(1, "%s: StealthSharedToSecretSpend() failed.", __func__); return 0; }; int CExtKeyAccount::ExpandStealthChildPubKey(const CEKAStealthKey *aks, const CKey &sShared, CPubKey &pkOut) const { // Works with locked wallet LOCK(cs_account); if (!aks) return errorN(1, "%s: Sanity checks failed.", __func__); ec_point pkExtract; if (StealthSharedToPublicKey(aks->pkSpend, sShared, pkExtract) != 0) return errorN(1, "%s: StealthSharedToPublicKey() failed.", __func__); pkOut = CPubKey(pkExtract); if (!pkOut.IsValid()) return errorN(1, "%s: Invalid public key.", __func__); return 0; }; int CExtKeyAccount::WipeEncryption() { std::vector<CStoredExtKey*>::iterator it; for (it = vExtKeys.begin(); it != vExtKeys.end(); ++it) { if (!((*it)->nFlags & EAF_IS_CRYPTED)) continue; if ((*it)->fLocked) return errorN(1, "Attempting to undo encryption of a locked key."); (*it)->nFlags &= ~EAF_IS_CRYPTED; (*it)->vchCryptedSecret.clear(); }; return 0; }; inline void AppendPathLink(std::string &s, uint32_t n, char cH) { s += "/"; bool fHardened = false; if ((n >> 31) == 1) { n &= ~(1 << 31); fHardened = true; }; s += strprintf("%u", n); if (fHardened) s += cH; }; int PathToString(const std::vector<uint8_t> &vPath, std::string &sPath, char cH, size_t nStart) { sPath = ""; if (vPath.size() % 4 != 0) return 1; sPath = "m"; for (size_t o = nStart; o < vPath.size(); o+=4) { uint32_t n; memcpy(&n, &vPath[o], 4); AppendPathLink(sPath, n, cH); }; return 0; }; int PathToString(const std::vector<uint32_t> &vPath, std::string &sPath, char cH, size_t nStart) { sPath = "m"; for (size_t o = nStart; o < vPath.size(); ++o) AppendPathLink(sPath, vPath[o], cH); return 0; }; bool IsBIP32(const char *base58) { std::vector<uint8_t> vchBytes; if (!DecodeBase58(base58, vchBytes)) return false; if (vchBytes.size() != BIP32_KEY_LEN) return false; if (0 == memcmp(&vchBytes[0], &Params().Base58Prefix(CChainParams::EXT_SECRET_KEY)[0], 4) || 0 == memcmp(&vchBytes[0], &Params().Base58Prefix(CChainParams::EXT_PUBLIC_KEY)[0], 4)) return true; if (!VerifyChecksum(vchBytes)) return false; return false; }; int AppendChainPath(const CStoredExtKey *pc, std::vector<uint32_t> &vPath) { mapEKValue_t::const_iterator mvi = pc->mapValue.find(EKVT_PATH); if (mvi == pc->mapValue.end()) return 1; assert(mvi->second.size() % 4 == 0); // Path on pc is relative to master key, get path relative to account by starting at 1 for (size_t i = 4; i < mvi->second.size(); i+=4) { uint32_t tmp; memcpy(&tmp, &mvi->second[i], 4); vPath.push_back(tmp); }; return 0; }; int AppendChainPath(const CStoredExtKey *pc, std::vector<uint8_t> &vPath) { mapEKValue_t::const_iterator mvi = pc->mapValue.find(EKVT_PATH); if (mvi == pc->mapValue.end()) return 1; assert(mvi->second.size() % 4 == 0); // Path on pc is relative to master key, get path relative to account by starting at 1 for (size_t i = 4; i < mvi->second.size(); i+=4) { uint32_t tmp; memcpy(&tmp, &mvi->second[i], 4); PushUInt32(vPath, tmp); }; return 0; }; int AppendPath(const CStoredExtKey *pc, std::vector<uint32_t> &vPath) { // Path on account chain is relative to master key mapEKValue_t::const_iterator mvi = pc->mapValue.find(EKVT_PATH); if (mvi == pc->mapValue.end()) return 1; assert(mvi->second.size() % 4 == 0); for (size_t i = 0; i < mvi->second.size(); i+=4) { uint32_t tmp; memcpy(&tmp, &mvi->second[i], 4); vPath.push_back(tmp); }; return 0; }; std::string HDAccIDToString(const CKeyID &id) { CBitcoinAddress addr; addr.Set(id, CChainParams::EXT_ACC_HASH); return addr.ToString(); }; std::string HDKeyIDToString(const CKeyID &id) { CBitcoinAddress addr; addr.Set(id, CChainParams::EXT_KEY_HASH); return addr.ToString(); };
; A082585: a(1)=1, a(n) = ceiling(r(5)*a(n-1)) where r(5) = (1/2)*(5 + sqrt(29)) is the positive root of X^2 = 5*X + 1. ; 1,6,32,167,868,4508,23409,121554,631180,3277455,17018456,88369736,458867137,2382705422,12372394248,64244676663,333595777564,1732223564484,8994713599985,46705791564410,242523671422036 add $0,2 cal $0,15449 ; Expansion of (1-4*x)/(1-5*x-x^2). mov $1,$0 div $1,5
#pragma once // ARKSurvivalEvolved (329.9) SDK #ifdef _MSC_VER #pragma pack(push, 0x8) #endif #include "ARKSurvivalEvolved_EngramEntry_Saddle_Paracer_Platform_structs.hpp" namespace sdk { //--------------------------------------------------------------------------- //Classes //--------------------------------------------------------------------------- // BlueprintGeneratedClass EngramEntry_Saddle_Paracer_Platform.EngramEntry_Saddle_Paracer_Platform_C // 0x0000 (0x0090 - 0x0090) class UEngramEntry_Saddle_Paracer_Platform_C : public UPrimalEngramEntry { public: static UClass* StaticClass() { static auto ptr = UObject::FindClass("BlueprintGeneratedClass EngramEntry_Saddle_Paracer_Platform.EngramEntry_Saddle_Paracer_Platform_C"); return ptr; } void ExecuteUbergraph_EngramEntry_Saddle_Paracer_Platform(int EntryPoint); }; } #ifdef _MSC_VER #pragma pack(pop) #endif
// Copyright (C) 2018-2022 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #pragma once #include <memory> #include <set> #include <unordered_set> #include <vector> #include <ngraph/node.hpp> #include <ngraph/pass/graph_rewrite.hpp> #include <ngraph/variant.hpp> #include "low_precision/lpt_visibility.hpp" #include "low_precision/rt_info/attribute_parameters.hpp" #include "low_precision/rt_info/shared_value_attribute.hpp" namespace ngraph { /** * @ingroup ie_transformation_common_api * @brief PrecisionsAttribute defines precision which is required for input/output port or an operation. * * For more details about the attribute, refer to * [PrecisionsAttribute](@ref openvino_docs_IE_DG_lpt_Precisions) page in the Inference Engine Developer Guide. */ class LP_TRANSFORMATIONS_API PrecisionsAttribute : public SharedAttribute<std::vector<ngraph::element::Type>> { public: OPENVINO_RTTI("LowPrecision::Precisions", "", ov::RuntimeAttribute, 0); PrecisionsAttribute(const std::vector<ngraph::element::Type>& precisions); static ov::Any create( const std::shared_ptr<ngraph::Node>& node, const AttributeParameters& params); // merge attribute instances which can be got from different sources: node, input port or output port void merge(std::vector<ov::Any>& attributes); // vizualize shared attributes details in VizualizeTree pass std::string to_string() const override; }; } // namespace ngraph
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "chainparams.h" #include "random.h" #include "util.h" #include "utilstrencodings.h" #include <assert.h> #include <boost/assign/list_of.hpp> using namespace std; using namespace boost::assign; struct SeedSpec6 { uint8_t addr[16]; uint16_t port; }; #include "chainparamsseeds.h" /** * Main network */ //! Convert the pnSeeds6 array into usable address objects. static void convertSeed6(std::vector<CAddress> &vSeedsOut, const SeedSpec6 *data, unsigned int count) { // It'll only connect to one or two seed nodes because once it connects, // it'll get a pile of addresses with newer timestamps. // Seed nodes are given a random 'last seen time' of between one and two // weeks ago. const int64_t nOneWeek = 7*24*60*60; for (unsigned int i = 0; i < count; i++) { struct in6_addr ip; memcpy(&ip, data[i].addr, sizeof(ip)); CAddress addr(CService(ip, data[i].port)); addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek; vSeedsOut.push_back(addr); } } /** * What makes a good checkpoint block? * + Is surrounded by blocks with reasonable timestamps * (no blocks before with a timestamp after, none after with * timestamp before) * + Contains no strange transactions */ static Checkpoints::MapCheckpoints mapCheckpoints = boost::assign::map_list_of ( 11111, uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ( 33333, uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ( 74000, uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")) (105000, uint256("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")) (134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")) (168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")) (193000, uint256("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")) (210000, uint256("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")) (216116, uint256("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")) (225430, uint256("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")) (250000, uint256("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")) (279000, uint256("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")) (295000, uint256("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")) ; static const Checkpoints::CCheckpointData data = { &mapCheckpoints, 1397080064, // * UNIX timestamp of last checkpoint block 36544669, // * total number of transactions between genesis and last checkpoint // (the tx=... number in the SetBestChain debug.log lines) 60000.0 // * estimated number of transactions per day after checkpoint }; static Checkpoints::MapCheckpoints mapCheckpointsTestnet = boost::assign::map_list_of ( 546, uint256("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")) ; static const Checkpoints::CCheckpointData dataTestnet = { &mapCheckpointsTestnet, 1337966069, 1488, 300 }; static Checkpoints::MapCheckpoints mapCheckpointsRegtest = boost::assign::map_list_of ( 0, uint256("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")) ; static const Checkpoints::CCheckpointData dataRegtest = { &mapCheckpointsRegtest, 0, 0, 0 }; class CMainParams : public CChainParams { public: CMainParams() { networkID = CBaseChainParams::MAIN; strNetworkID = "main"; /** * The message start string is designed to be unlikely to occur in normal data. * The characters are rarely used upper ASCII, not valid as UTF-8, and produce * a large 4-byte int at any alignment. */ pchMessageStart[0] = 0xf9; pchMessageStart[1] = 0xbe; pchMessageStart[2] = 0xb4; pchMessageStart[3] = 0xd9; vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"); nDefaultPort = 8333; bnProofOfWorkLimit = ~uint256(0) >> 32; nSubsidyHalvingInterval = 210000; nEnforceBlockUpgradeMajority = 750; nRejectBlockOutdatedMajority = 950; nToCheckBlockUpgradeMajority = 1000; nMinerThreads = 0; nTargetTimespan = 14 * 24 * 60 * 60; // two weeks nTargetSpacing = 10 * 60; /** * Build the genesis block. Note that the output of the genesis coinbase cannot * be spent as it did not originally exist in the database. * * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1) * CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0) * CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73) * CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B) * vMerkleTree: 4a5e1e */ const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"; CMutableTransaction txNew; txNew.vin.resize(1); txNew.vout.resize(1); txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); txNew.vout[0].nValue = 50 * COIN; txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG; genesis.vtx.push_back(txNew); genesis.hashPrevBlock = 0; genesis.hashMerkleRoot = genesis.BuildMerkleTree(); genesis.nVersion = 1; genesis.nTime = 1231006505; genesis.nBits = 0x1d00ffff; genesis.nNonce = 2083236893; hashGenesisBlock = genesis.GetHash(); assert(hashGenesisBlock == uint256("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")); assert(genesis.hashMerkleRoot == uint256("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")); vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be")); vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me")); vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org")); vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com")); vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org")); base58Prefixes[PUBKEY_ADDRESS] = list_of(0); base58Prefixes[SCRIPT_ADDRESS] = list_of(5); base58Prefixes[SECRET_KEY] = list_of(128); base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E); base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4); convertSeed6(vFixedSeeds, pnSeed6_main, ARRAYLEN(pnSeed6_main)); fRequireRPCPassword = true; fMiningRequiresPeers = true; fAllowMinDifficultyBlocks = false; fDefaultConsistencyChecks = false; fRequireStandard = true; fMineBlocksOnDemand = false; fSkipProofOfWorkCheck = false; fTestnetToBeDeprecatedFieldRPC = false; } const Checkpoints::CCheckpointData& Checkpoints() const { return data; } }; static CMainParams mainParams; /** * Testnet (v3) */ class CTestNetParams : public CMainParams { public: CTestNetParams() { networkID = CBaseChainParams::TESTNET; strNetworkID = "test"; pchMessageStart[0] = 0x0b; pchMessageStart[1] = 0x11; pchMessageStart[2] = 0x09; pchMessageStart[3] = 0x07; vAlertPubKey = ParseHex("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"); nDefaultPort = 18333; nEnforceBlockUpgradeMajority = 51; nRejectBlockOutdatedMajority = 75; nToCheckBlockUpgradeMajority = 100; nMinerThreads = 0; nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks nTargetSpacing = 10 * 60; //! Modify the testnet genesis block so the timestamp is valid for a later start. genesis.nTime = 1296688602; genesis.nNonce = 414098458; hashGenesisBlock = genesis.GetHash(); assert(hashGenesisBlock == uint256("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); vFixedSeeds.clear(); vSeeds.clear(); vSeeds.push_back(CDNSSeedData("alexykot.me", "testnet-seed.alexykot.me")); vSeeds.push_back(CDNSSeedData("bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org")); vSeeds.push_back(CDNSSeedData("bluematt.me", "testnet-seed.bluematt.me")); vSeeds.push_back(CDNSSeedData("bitcoin.schildbach.de", "testnet-seed.bitcoin.schildbach.de")); base58Prefixes[PUBKEY_ADDRESS] = list_of(111); base58Prefixes[SCRIPT_ADDRESS] = list_of(196); base58Prefixes[SECRET_KEY] = list_of(239); base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x35)(0x87)(0xCF); base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x35)(0x83)(0x94); convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test)); fRequireRPCPassword = true; fMiningRequiresPeers = true; fAllowMinDifficultyBlocks = true; fDefaultConsistencyChecks = false; fRequireStandard = false; fMineBlocksOnDemand = false; fTestnetToBeDeprecatedFieldRPC = true; } const Checkpoints::CCheckpointData& Checkpoints() const { return dataTestnet; } }; static CTestNetParams testNetParams; /** * Regression test */ class CRegTestParams : public CTestNetParams { public: CRegTestParams() { networkID = CBaseChainParams::REGTEST; strNetworkID = "regtest"; pchMessageStart[0] = 0xfa; pchMessageStart[1] = 0xbf; pchMessageStart[2] = 0xb5; pchMessageStart[3] = 0xda; nSubsidyHalvingInterval = 150; nEnforceBlockUpgradeMajority = 750; nRejectBlockOutdatedMajority = 950; nToCheckBlockUpgradeMajority = 1000; nMinerThreads = 1; nTargetTimespan = 14 * 24 * 60 * 60; //! two weeks nTargetSpacing = 10 * 60; bnProofOfWorkLimit = ~uint256(0) >> 1; genesis.nTime = 1296688602; genesis.nBits = 0x207fffff; genesis.nNonce = 2; hashGenesisBlock = genesis.GetHash(); nDefaultPort = 18444; assert(hashGenesisBlock == uint256("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds. vSeeds.clear(); //! Regtest mode doesn't have any DNS seeds. fRequireRPCPassword = false; fMiningRequiresPeers = false; fAllowMinDifficultyBlocks = true; fDefaultConsistencyChecks = true; fRequireStandard = false; fMineBlocksOnDemand = true; fTestnetToBeDeprecatedFieldRPC = false; } const Checkpoints::CCheckpointData& Checkpoints() const { return dataRegtest; } }; static CRegTestParams regTestParams; /** * Unit test */ class CUnitTestParams : public CMainParams, public CModifiableParams { public: CUnitTestParams() { networkID = CBaseChainParams::UNITTEST; strNetworkID = "unittest"; nDefaultPort = 18445; vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds. vSeeds.clear(); //! Unit test mode doesn't have any DNS seeds. fRequireRPCPassword = false; fMiningRequiresPeers = false; fDefaultConsistencyChecks = true; fAllowMinDifficultyBlocks = false; fMineBlocksOnDemand = true; } const Checkpoints::CCheckpointData& Checkpoints() const { // UnitTest share the same checkpoints as MAIN return data; } //! Published setters to allow changing values in unit test cases virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval=anSubsidyHalvingInterval; } virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) { nEnforceBlockUpgradeMajority=anEnforceBlockUpgradeMajority; } virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) { nRejectBlockOutdatedMajority=anRejectBlockOutdatedMajority; } virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) { nToCheckBlockUpgradeMajority=anToCheckBlockUpgradeMajority; } virtual void setDefaultConsistencyChecks(bool afDefaultConsistencyChecks) { fDefaultConsistencyChecks=afDefaultConsistencyChecks; } virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) { fAllowMinDifficultyBlocks=afAllowMinDifficultyBlocks; } virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; } }; static CUnitTestParams unitTestParams; static CChainParams *pCurrentParams = 0; CModifiableParams *ModifiableParams() { assert(pCurrentParams); assert(pCurrentParams==&unitTestParams); return (CModifiableParams*)&unitTestParams; } const CChainParams &Params() { assert(pCurrentParams); return *pCurrentParams; } CChainParams &Params(CBaseChainParams::Network network) { switch (network) { case CBaseChainParams::MAIN: return mainParams; case CBaseChainParams::TESTNET: return testNetParams; case CBaseChainParams::REGTEST: return regTestParams; case CBaseChainParams::UNITTEST: return unitTestParams; default: assert(false && "Unimplemented network"); return mainParams; } } void SelectParams(CBaseChainParams::Network network) { SelectBaseParams(network); pCurrentParams = &Params(network); } bool SelectParamsFromCommandLine() { CBaseChainParams::Network network = NetworkIdFromCommandLine(); if (network == CBaseChainParams::MAX_NETWORK_TYPES) return false; SelectParams(network); return true; }
/********************************************************* * Copyright (C) 2021, Val Doroshchuk <valbok@gmail.com> * * * * This file is part of QtAVPlayer. * * Free Qt Media Player based on FFmpeg. * *********************************************************/ #include "qavvideoinputfilter_p.h" #include "qavinoutfilter_p_p.h" #include "qavdemuxer_p.h" #include <QDebug> extern "C" { #include <libavformat/avformat.h> #include <libavfilter/buffersrc.h> #include <libavutil/bprint.h> } QT_BEGIN_NAMESPACE class QAVVideoInputFilterPrivate : public QAVInOutFilterPrivate { public: QAVVideoInputFilterPrivate(QAVInOutFilter *q, const QAVDemuxer *demuxer) : QAVInOutFilterPrivate(q), demuxer(demuxer) { } const QAVDemuxer *demuxer = nullptr; }; QAVVideoInputFilter::QAVVideoInputFilter(QObject *parent) : QAVVideoInputFilter(nullptr, parent) { } QAVVideoInputFilter::QAVVideoInputFilter(const QAVDemuxer *demuxer, QObject *parent) : QAVInOutFilter(*new QAVVideoInputFilterPrivate(this, demuxer), parent) { } QAVVideoInputFilter::QAVVideoInputFilter(const QAVVideoInputFilter &other) : QAVVideoInputFilter() { *this = other; } QAVVideoInputFilter::~QAVVideoInputFilter() = default; QAVVideoInputFilter &QAVVideoInputFilter::operator=(const QAVVideoInputFilter &other) { Q_D(QAVVideoInputFilter); QAVInOutFilter::operator=(other); d->demuxer = other.d_func()->demuxer; return *this; } int QAVVideoInputFilter::configure(AVFilterGraph *graph, AVFilterInOut *in) { Q_D(QAVVideoInputFilter); AVStream *stream = d->demuxer ? d->demuxer->videoStream() : nullptr; if (!stream) return AVERROR(EINVAL); AVRational sample_aspect_ratio = stream->codecpar->sample_aspect_ratio; AVRational time_base = stream->time_base; AVBPrint args; av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprintf(&args, "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:" "pixel_aspect=%d/%d", stream->codecpar->width, stream->codecpar->height, stream->codecpar->format, time_base.num, time_base.den, sample_aspect_ratio.num, qMax(sample_aspect_ratio.den, 1)); auto fr = d->demuxer->frameRate(); if (fr.num && fr.den) av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); static int index = 0; char name[255]; snprintf(name, sizeof(name), "buffer_%d", index++); int ret = avfilter_graph_create_filter(&d->ctx, avfilter_get_by_name("buffer"), name, args.str, nullptr, graph); if (ret < 0) return ret; ret = avfilter_link(d->ctx, 0, in->filter_ctx, in->pad_idx); if (ret < 0) return ret; return 0; } QT_END_NAMESPACE
_bench: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #define vll volatile long long int #define MAX 100000000 int main(int argc, char *argv[]) { 0: f3 0f 1e fb endbr32 4: 8d 4c 24 04 lea 0x4(%esp),%ecx 8: 83 e4 f0 and $0xfffffff0,%esp b: ff 71 fc pushl -0x4(%ecx) e: 55 push %ebp f: 89 e5 mov %esp,%ebp 11: 57 push %edi 12: 56 push %esi 13: 53 push %ebx for (int i = 0; i < 10; i++) 14: 31 db xor %ebx,%ebx { 16: 51 push %ecx 17: 83 ec 48 sub $0x48,%esp 1a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi { int pid = fork(); 20: e8 66 03 00 00 call 38b <fork> if (pid < 0) 25: 85 c0 test %eax,%eax 27: 78 48 js 71 <main+0x71> { printf(2, "Failed to fork\n"); exit(); } else if (pid == 0) 29: 74 59 je 84 <main+0x84> for (int i = 0; i < 10; i++) 2b: 83 c3 01 add $0x1,%ebx 2e: 83 fb 0a cmp $0xa,%ebx 31: 75 ed jne 20 <main+0x20> 33: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 37: 90 nop exit(); } } for (int i = 0; i < 10; i++) wait(); 38: e8 5e 03 00 00 call 39b <wait> for (int i = 0; i < 10; i++) 3d: 83 eb 01 sub $0x1,%ebx 40: 75 f6 jne 38 <main+0x38> struct proc_stat p; int pid = getpid(); 42: e8 cc 03 00 00 call 413 <getpid> getpinfo(&p, pid); 47: 52 push %edx 48: 52 push %edx 49: 50 push %eax 4a: 8d 45 c0 lea -0x40(%ebp),%eax 4d: 50 push %eax 4e: e8 f0 03 00 00 call 443 <getpinfo> printf(1, "Process with PID=%d has\nRunTime=%d\nNum_Run=%d\n",p.pid, p.runtime, p.num_run); 53: 59 pop %ecx 54: ff 75 c8 pushl -0x38(%ebp) 57: ff 75 c4 pushl -0x3c(%ebp) 5a: ff 75 c0 pushl -0x40(%ebp) 5d: 68 d8 08 00 00 push $0x8d8 62: 6a 01 push $0x1 64: e8 f7 04 00 00 call 560 <printf> printf(1, "Queue no=%d\nThe ticks received in each queue are:\n",p.current_queue); for(int i=0; i<5; i++) printf(1, "%d: %d\n", i, p.ticks[i]); #endif exit(); 69: 83 c4 20 add $0x20,%esp 6c: e8 22 03 00 00 call 393 <exit> printf(2, "Failed to fork\n"); 71: 53 push %ebx 72: 53 push %ebx 73: 68 c8 08 00 00 push $0x8c8 78: 6a 02 push $0x2 7a: e8 e1 04 00 00 call 560 <printf> exit(); 7f: e8 0f 03 00 00 call 393 <exit> 84: 89 5d b4 mov %ebx,-0x4c(%ebp) for (vll k = 0; k < MAX; k++) 87: b9 ff e0 f5 05 mov $0x5f5e0ff,%ecx 8c: 89 c3 mov %eax,%ebx 8e: 89 75 a8 mov %esi,-0x58(%ebp) 91: 89 7d ac mov %edi,-0x54(%ebp) 94: eb 27 jmp bd <main+0xbd> 96: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 9d: 8d 76 00 lea 0x0(%esi),%esi sleep(200); a0: 83 ec 0c sub $0xc,%esp a3: 68 c8 00 00 00 push $0xc8 a8: e8 76 03 00 00 call 423 <sleep> ad: 83 c4 10 add $0x10,%esp b0: b9 ff e0 f5 05 mov $0x5f5e0ff,%ecx for(int j=0; j < 10; j++) b5: 83 c3 01 add $0x1,%ebx b8: 83 fb 0a cmp $0xa,%ebx bb: 74 af je 6c <main+0x6c> if(j <= i) bd: 39 5d b4 cmp %ebx,-0x4c(%ebp) c0: 7d de jge a0 <main+0xa0> for (vll k = 0; k < MAX; k++) c2: c7 45 c0 00 00 00 00 movl $0x0,-0x40(%ebp) c9: bf 00 00 00 00 mov $0x0,%edi ce: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) d5: 8b 45 c0 mov -0x40(%ebp),%eax d8: 8b 55 c4 mov -0x3c(%ebp),%edx db: 39 c1 cmp %eax,%ecx dd: 19 d7 sbb %edx,%edi df: 7c d4 jl b5 <main+0xb5> e1: 89 5d b0 mov %ebx,-0x50(%ebp) e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi k = 1 ^ k; //cpu e8: 8b 45 c0 mov -0x40(%ebp),%eax eb: 8b 55 c4 mov -0x3c(%ebp),%edx ee: 89 c3 mov %eax,%ebx f0: 89 d7 mov %edx,%edi f2: 83 f3 01 xor $0x1,%ebx f5: 89 5d c0 mov %ebx,-0x40(%ebp) f8: 89 de mov %ebx,%esi for (vll k = 0; k < MAX; k++) fa: bb 00 00 00 00 mov $0x0,%ebx k = 1 ^ k; //cpu ff: 89 55 c4 mov %edx,-0x3c(%ebp) for (vll k = 0; k < MAX; k++) 102: 8b 45 c0 mov -0x40(%ebp),%eax 105: 8b 55 c4 mov -0x3c(%ebp),%edx 108: 83 c0 01 add $0x1,%eax 10b: 83 d2 00 adc $0x0,%edx 10e: 89 45 c0 mov %eax,-0x40(%ebp) 111: 89 55 c4 mov %edx,-0x3c(%ebp) 114: 8b 45 c0 mov -0x40(%ebp),%eax 117: 8b 55 c4 mov -0x3c(%ebp),%edx 11a: 39 c1 cmp %eax,%ecx 11c: 19 d3 sbb %edx,%ebx 11e: 7d c8 jge e8 <main+0xe8> 120: 89 75 a8 mov %esi,-0x58(%ebp) 123: 8b 5d b0 mov -0x50(%ebp),%ebx 126: 89 7d ac mov %edi,-0x54(%ebp) 129: eb 8a jmp b5 <main+0xb5> 12b: 66 90 xchg %ax,%ax 12d: 66 90 xchg %ax,%ax 12f: 90 nop 00000130 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 130: f3 0f 1e fb endbr32 134: 55 push %ebp char *os; os = s; while((*s++ = *t++) != 0) 135: 31 c0 xor %eax,%eax { 137: 89 e5 mov %esp,%ebp 139: 53 push %ebx 13a: 8b 4d 08 mov 0x8(%ebp),%ecx 13d: 8b 5d 0c mov 0xc(%ebp),%ebx while((*s++ = *t++) != 0) 140: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 144: 88 14 01 mov %dl,(%ecx,%eax,1) 147: 83 c0 01 add $0x1,%eax 14a: 84 d2 test %dl,%dl 14c: 75 f2 jne 140 <strcpy+0x10> ; return os; } 14e: 89 c8 mov %ecx,%eax 150: 5b pop %ebx 151: 5d pop %ebp 152: c3 ret 153: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 15a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00000160 <strcmp>: int strcmp(const char *p, const char *q) { 160: f3 0f 1e fb endbr32 164: 55 push %ebp 165: 89 e5 mov %esp,%ebp 167: 53 push %ebx 168: 8b 4d 08 mov 0x8(%ebp),%ecx 16b: 8b 55 0c mov 0xc(%ebp),%edx while(*p && *p == *q) 16e: 0f b6 01 movzbl (%ecx),%eax 171: 0f b6 1a movzbl (%edx),%ebx 174: 84 c0 test %al,%al 176: 75 19 jne 191 <strcmp+0x31> 178: eb 26 jmp 1a0 <strcmp+0x40> 17a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 180: 0f b6 41 01 movzbl 0x1(%ecx),%eax p++, q++; 184: 83 c1 01 add $0x1,%ecx 187: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 18a: 0f b6 1a movzbl (%edx),%ebx 18d: 84 c0 test %al,%al 18f: 74 0f je 1a0 <strcmp+0x40> 191: 38 d8 cmp %bl,%al 193: 74 eb je 180 <strcmp+0x20> return (uchar)*p - (uchar)*q; 195: 29 d8 sub %ebx,%eax } 197: 5b pop %ebx 198: 5d pop %ebp 199: c3 ret 19a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1a0: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 1a2: 29 d8 sub %ebx,%eax } 1a4: 5b pop %ebx 1a5: 5d pop %ebp 1a6: c3 ret 1a7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1ae: 66 90 xchg %ax,%ax 000001b0 <strlen>: uint strlen(const char *s) { 1b0: f3 0f 1e fb endbr32 1b4: 55 push %ebp 1b5: 89 e5 mov %esp,%ebp 1b7: 8b 55 08 mov 0x8(%ebp),%edx int n; for(n = 0; s[n]; n++) 1ba: 80 3a 00 cmpb $0x0,(%edx) 1bd: 74 21 je 1e0 <strlen+0x30> 1bf: 31 c0 xor %eax,%eax 1c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1c8: 83 c0 01 add $0x1,%eax 1cb: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) 1cf: 89 c1 mov %eax,%ecx 1d1: 75 f5 jne 1c8 <strlen+0x18> ; return n; } 1d3: 89 c8 mov %ecx,%eax 1d5: 5d pop %ebp 1d6: c3 ret 1d7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1de: 66 90 xchg %ax,%ax for(n = 0; s[n]; n++) 1e0: 31 c9 xor %ecx,%ecx } 1e2: 5d pop %ebp 1e3: 89 c8 mov %ecx,%eax 1e5: c3 ret 1e6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1ed: 8d 76 00 lea 0x0(%esi),%esi 000001f0 <memset>: void* memset(void *dst, int c, uint n) { 1f0: f3 0f 1e fb endbr32 1f4: 55 push %ebp 1f5: 89 e5 mov %esp,%ebp 1f7: 57 push %edi 1f8: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1fb: 8b 4d 10 mov 0x10(%ebp),%ecx 1fe: 8b 45 0c mov 0xc(%ebp),%eax 201: 89 d7 mov %edx,%edi 203: fc cld 204: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 206: 89 d0 mov %edx,%eax 208: 5f pop %edi 209: 5d pop %ebp 20a: c3 ret 20b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 20f: 90 nop 00000210 <strchr>: char* strchr(const char *s, char c) { 210: f3 0f 1e fb endbr32 214: 55 push %ebp 215: 89 e5 mov %esp,%ebp 217: 8b 45 08 mov 0x8(%ebp),%eax 21a: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for(; *s; s++) 21e: 0f b6 10 movzbl (%eax),%edx 221: 84 d2 test %dl,%dl 223: 75 16 jne 23b <strchr+0x2b> 225: eb 21 jmp 248 <strchr+0x38> 227: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 22e: 66 90 xchg %ax,%ax 230: 0f b6 50 01 movzbl 0x1(%eax),%edx 234: 83 c0 01 add $0x1,%eax 237: 84 d2 test %dl,%dl 239: 74 0d je 248 <strchr+0x38> if(*s == c) 23b: 38 d1 cmp %dl,%cl 23d: 75 f1 jne 230 <strchr+0x20> return (char*)s; return 0; } 23f: 5d pop %ebp 240: c3 ret 241: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 248: 31 c0 xor %eax,%eax } 24a: 5d pop %ebp 24b: c3 ret 24c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000250 <gets>: char* gets(char *buf, int max) { 250: f3 0f 1e fb endbr32 254: 55 push %ebp 255: 89 e5 mov %esp,%ebp 257: 57 push %edi 258: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 259: 31 f6 xor %esi,%esi { 25b: 53 push %ebx 25c: 89 f3 mov %esi,%ebx 25e: 83 ec 1c sub $0x1c,%esp 261: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 264: eb 33 jmp 299 <gets+0x49> 266: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 26d: 8d 76 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 270: 83 ec 04 sub $0x4,%esp 273: 8d 45 e7 lea -0x19(%ebp),%eax 276: 6a 01 push $0x1 278: 50 push %eax 279: 6a 00 push $0x0 27b: e8 2b 01 00 00 call 3ab <read> if(cc < 1) 280: 83 c4 10 add $0x10,%esp 283: 85 c0 test %eax,%eax 285: 7e 1c jle 2a3 <gets+0x53> break; buf[i++] = c; 287: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 28b: 83 c7 01 add $0x1,%edi 28e: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 291: 3c 0a cmp $0xa,%al 293: 74 23 je 2b8 <gets+0x68> 295: 3c 0d cmp $0xd,%al 297: 74 1f je 2b8 <gets+0x68> for(i=0; i+1 < max; ){ 299: 83 c3 01 add $0x1,%ebx 29c: 89 fe mov %edi,%esi 29e: 3b 5d 0c cmp 0xc(%ebp),%ebx 2a1: 7c cd jl 270 <gets+0x20> 2a3: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 2a5: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 2a8: c6 03 00 movb $0x0,(%ebx) } 2ab: 8d 65 f4 lea -0xc(%ebp),%esp 2ae: 5b pop %ebx 2af: 5e pop %esi 2b0: 5f pop %edi 2b1: 5d pop %ebp 2b2: c3 ret 2b3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 2b7: 90 nop 2b8: 8b 75 08 mov 0x8(%ebp),%esi 2bb: 8b 45 08 mov 0x8(%ebp),%eax 2be: 01 de add %ebx,%esi 2c0: 89 f3 mov %esi,%ebx buf[i] = '\0'; 2c2: c6 03 00 movb $0x0,(%ebx) } 2c5: 8d 65 f4 lea -0xc(%ebp),%esp 2c8: 5b pop %ebx 2c9: 5e pop %esi 2ca: 5f pop %edi 2cb: 5d pop %ebp 2cc: c3 ret 2cd: 8d 76 00 lea 0x0(%esi),%esi 000002d0 <stat>: int stat(const char *n, struct stat *st) { 2d0: f3 0f 1e fb endbr32 2d4: 55 push %ebp 2d5: 89 e5 mov %esp,%ebp 2d7: 56 push %esi 2d8: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 2d9: 83 ec 08 sub $0x8,%esp 2dc: 6a 00 push $0x0 2de: ff 75 08 pushl 0x8(%ebp) 2e1: e8 ed 00 00 00 call 3d3 <open> if(fd < 0) 2e6: 83 c4 10 add $0x10,%esp 2e9: 85 c0 test %eax,%eax 2eb: 78 2b js 318 <stat+0x48> return -1; r = fstat(fd, st); 2ed: 83 ec 08 sub $0x8,%esp 2f0: ff 75 0c pushl 0xc(%ebp) 2f3: 89 c3 mov %eax,%ebx 2f5: 50 push %eax 2f6: e8 f0 00 00 00 call 3eb <fstat> close(fd); 2fb: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2fe: 89 c6 mov %eax,%esi close(fd); 300: e8 b6 00 00 00 call 3bb <close> return r; 305: 83 c4 10 add $0x10,%esp } 308: 8d 65 f8 lea -0x8(%ebp),%esp 30b: 89 f0 mov %esi,%eax 30d: 5b pop %ebx 30e: 5e pop %esi 30f: 5d pop %ebp 310: c3 ret 311: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return -1; 318: be ff ff ff ff mov $0xffffffff,%esi 31d: eb e9 jmp 308 <stat+0x38> 31f: 90 nop 00000320 <atoi>: int atoi(const char *s) { 320: f3 0f 1e fb endbr32 324: 55 push %ebp 325: 89 e5 mov %esp,%ebp 327: 53 push %ebx 328: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while('0' <= *s && *s <= '9') 32b: 0f be 02 movsbl (%edx),%eax 32e: 8d 48 d0 lea -0x30(%eax),%ecx 331: 80 f9 09 cmp $0x9,%cl n = 0; 334: b9 00 00 00 00 mov $0x0,%ecx while('0' <= *s && *s <= '9') 339: 77 1a ja 355 <atoi+0x35> 33b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 33f: 90 nop n = n*10 + *s++ - '0'; 340: 83 c2 01 add $0x1,%edx 343: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 346: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while('0' <= *s && *s <= '9') 34a: 0f be 02 movsbl (%edx),%eax 34d: 8d 58 d0 lea -0x30(%eax),%ebx 350: 80 fb 09 cmp $0x9,%bl 353: 76 eb jbe 340 <atoi+0x20> return n; } 355: 89 c8 mov %ecx,%eax 357: 5b pop %ebx 358: 5d pop %ebp 359: c3 ret 35a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00000360 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 360: f3 0f 1e fb endbr32 364: 55 push %ebp 365: 89 e5 mov %esp,%ebp 367: 57 push %edi 368: 8b 45 10 mov 0x10(%ebp),%eax 36b: 8b 55 08 mov 0x8(%ebp),%edx 36e: 56 push %esi 36f: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 372: 85 c0 test %eax,%eax 374: 7e 0f jle 385 <memmove+0x25> 376: 01 d0 add %edx,%eax dst = vdst; 378: 89 d7 mov %edx,%edi 37a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi *dst++ = *src++; 380: a4 movsb %ds:(%esi),%es:(%edi) while(n-- > 0) 381: 39 f8 cmp %edi,%eax 383: 75 fb jne 380 <memmove+0x20> return vdst; } 385: 5e pop %esi 386: 89 d0 mov %edx,%eax 388: 5f pop %edi 389: 5d pop %ebp 38a: c3 ret 0000038b <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 38b: b8 01 00 00 00 mov $0x1,%eax 390: cd 40 int $0x40 392: c3 ret 00000393 <exit>: SYSCALL(exit) 393: b8 02 00 00 00 mov $0x2,%eax 398: cd 40 int $0x40 39a: c3 ret 0000039b <wait>: SYSCALL(wait) 39b: b8 03 00 00 00 mov $0x3,%eax 3a0: cd 40 int $0x40 3a2: c3 ret 000003a3 <pipe>: SYSCALL(pipe) 3a3: b8 04 00 00 00 mov $0x4,%eax 3a8: cd 40 int $0x40 3aa: c3 ret 000003ab <read>: SYSCALL(read) 3ab: b8 05 00 00 00 mov $0x5,%eax 3b0: cd 40 int $0x40 3b2: c3 ret 000003b3 <write>: SYSCALL(write) 3b3: b8 10 00 00 00 mov $0x10,%eax 3b8: cd 40 int $0x40 3ba: c3 ret 000003bb <close>: SYSCALL(close) 3bb: b8 15 00 00 00 mov $0x15,%eax 3c0: cd 40 int $0x40 3c2: c3 ret 000003c3 <kill>: SYSCALL(kill) 3c3: b8 06 00 00 00 mov $0x6,%eax 3c8: cd 40 int $0x40 3ca: c3 ret 000003cb <exec>: SYSCALL(exec) 3cb: b8 07 00 00 00 mov $0x7,%eax 3d0: cd 40 int $0x40 3d2: c3 ret 000003d3 <open>: SYSCALL(open) 3d3: b8 0f 00 00 00 mov $0xf,%eax 3d8: cd 40 int $0x40 3da: c3 ret 000003db <mknod>: SYSCALL(mknod) 3db: b8 11 00 00 00 mov $0x11,%eax 3e0: cd 40 int $0x40 3e2: c3 ret 000003e3 <unlink>: SYSCALL(unlink) 3e3: b8 12 00 00 00 mov $0x12,%eax 3e8: cd 40 int $0x40 3ea: c3 ret 000003eb <fstat>: SYSCALL(fstat) 3eb: b8 08 00 00 00 mov $0x8,%eax 3f0: cd 40 int $0x40 3f2: c3 ret 000003f3 <link>: SYSCALL(link) 3f3: b8 13 00 00 00 mov $0x13,%eax 3f8: cd 40 int $0x40 3fa: c3 ret 000003fb <mkdir>: SYSCALL(mkdir) 3fb: b8 14 00 00 00 mov $0x14,%eax 400: cd 40 int $0x40 402: c3 ret 00000403 <chdir>: SYSCALL(chdir) 403: b8 09 00 00 00 mov $0x9,%eax 408: cd 40 int $0x40 40a: c3 ret 0000040b <dup>: SYSCALL(dup) 40b: b8 0a 00 00 00 mov $0xa,%eax 410: cd 40 int $0x40 412: c3 ret 00000413 <getpid>: SYSCALL(getpid) 413: b8 0b 00 00 00 mov $0xb,%eax 418: cd 40 int $0x40 41a: c3 ret 0000041b <sbrk>: SYSCALL(sbrk) 41b: b8 0c 00 00 00 mov $0xc,%eax 420: cd 40 int $0x40 422: c3 ret 00000423 <sleep>: SYSCALL(sleep) 423: b8 0d 00 00 00 mov $0xd,%eax 428: cd 40 int $0x40 42a: c3 ret 0000042b <uptime>: SYSCALL(uptime) 42b: b8 0e 00 00 00 mov $0xe,%eax 430: cd 40 int $0x40 432: c3 ret 00000433 <waitx>: SYSCALL(waitx) 433: b8 16 00 00 00 mov $0x16,%eax 438: cd 40 int $0x40 43a: c3 ret 0000043b <set_priority>: SYSCALL(set_priority) 43b: b8 18 00 00 00 mov $0x18,%eax 440: cd 40 int $0x40 442: c3 ret 00000443 <getpinfo>: SYSCALL(getpinfo) 443: b8 17 00 00 00 mov $0x17,%eax 448: cd 40 int $0x40 44a: c3 ret 0000044b <year>: SYSCALL(year) 44b: b8 19 00 00 00 mov $0x19,%eax 450: cd 40 int $0x40 452: c3 ret 00000453 <halt>: SYSCALL(halt) 453: b8 1a 00 00 00 mov $0x1a,%eax 458: cd 40 int $0x40 45a: c3 ret 0000045b <date>: SYSCALL(date) 45b: b8 1b 00 00 00 mov $0x1b,%eax 460: cd 40 int $0x40 462: c3 ret 00000463 <gettcount>: SYSCALL(gettcount) 463: b8 1d 00 00 00 mov $0x1d,%eax 468: cd 40 int $0x40 46a: c3 ret 0000046b <getrcount>: SYSCALL(getrcount) 46b: b8 1c 00 00 00 mov $0x1c,%eax 470: cd 40 int $0x40 472: c3 ret 00000473 <getwcount>: SYSCALL(getwcount) 473: b8 1e 00 00 00 mov $0x1e,%eax 478: cd 40 int $0x40 47a: c3 ret 0000047b <getwtcount>: SYSCALL(getwtcount) 47b: b8 1f 00 00 00 mov $0x1f,%eax 480: cd 40 int $0x40 482: c3 ret 00000483 <getcltcount>: SYSCALL(getcltcount) 483: b8 21 00 00 00 mov $0x21,%eax 488: cd 40 int $0x40 48a: c3 ret 0000048b <getclcount>: SYSCALL(getclcount) 48b: b8 20 00 00 00 mov $0x20,%eax 490: cd 40 int $0x40 492: c3 ret 00000493 <getocount>: SYSCALL(getocount) 493: b8 23 00 00 00 mov $0x23,%eax 498: cd 40 int $0x40 49a: c3 ret 0000049b <getotcount>: SYSCALL(getotcount) 49b: b8 22 00 00 00 mov $0x22,%eax 4a0: cd 40 int $0x40 4a2: c3 ret 4a3: 66 90 xchg %ax,%ax 4a5: 66 90 xchg %ax,%ax 4a7: 66 90 xchg %ax,%ax 4a9: 66 90 xchg %ax,%ax 4ab: 66 90 xchg %ax,%ax 4ad: 66 90 xchg %ax,%ax 4af: 90 nop 000004b0 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 4b0: 55 push %ebp 4b1: 89 e5 mov %esp,%ebp 4b3: 57 push %edi 4b4: 56 push %esi 4b5: 53 push %ebx 4b6: 83 ec 3c sub $0x3c,%esp 4b9: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 4bc: 89 d1 mov %edx,%ecx { 4be: 89 45 b8 mov %eax,-0x48(%ebp) if(sgn && xx < 0){ 4c1: 85 d2 test %edx,%edx 4c3: 0f 89 7f 00 00 00 jns 548 <printint+0x98> 4c9: f6 45 08 01 testb $0x1,0x8(%ebp) 4cd: 74 79 je 548 <printint+0x98> neg = 1; 4cf: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 4d6: f7 d9 neg %ecx } else { x = xx; } i = 0; 4d8: 31 db xor %ebx,%ebx 4da: 8d 75 d7 lea -0x29(%ebp),%esi 4dd: 8d 76 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 4e0: 89 c8 mov %ecx,%eax 4e2: 31 d2 xor %edx,%edx 4e4: 89 cf mov %ecx,%edi 4e6: f7 75 c4 divl -0x3c(%ebp) 4e9: 0f b6 92 10 09 00 00 movzbl 0x910(%edx),%edx 4f0: 89 45 c0 mov %eax,-0x40(%ebp) 4f3: 89 d8 mov %ebx,%eax 4f5: 8d 5b 01 lea 0x1(%ebx),%ebx }while((x /= base) != 0); 4f8: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 4fb: 88 14 1e mov %dl,(%esi,%ebx,1) }while((x /= base) != 0); 4fe: 39 7d c4 cmp %edi,-0x3c(%ebp) 501: 76 dd jbe 4e0 <printint+0x30> if(neg) 503: 8b 4d bc mov -0x44(%ebp),%ecx 506: 85 c9 test %ecx,%ecx 508: 74 0c je 516 <printint+0x66> buf[i++] = '-'; 50a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 50f: 89 d8 mov %ebx,%eax buf[i++] = '-'; 511: ba 2d 00 00 00 mov $0x2d,%edx while(--i >= 0) 516: 8b 7d b8 mov -0x48(%ebp),%edi 519: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 51d: eb 07 jmp 526 <printint+0x76> 51f: 90 nop 520: 0f b6 13 movzbl (%ebx),%edx 523: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 526: 83 ec 04 sub $0x4,%esp 529: 88 55 d7 mov %dl,-0x29(%ebp) 52c: 6a 01 push $0x1 52e: 56 push %esi 52f: 57 push %edi 530: e8 7e fe ff ff call 3b3 <write> while(--i >= 0) 535: 83 c4 10 add $0x10,%esp 538: 39 de cmp %ebx,%esi 53a: 75 e4 jne 520 <printint+0x70> putc(fd, buf[i]); } 53c: 8d 65 f4 lea -0xc(%ebp),%esp 53f: 5b pop %ebx 540: 5e pop %esi 541: 5f pop %edi 542: 5d pop %ebp 543: c3 ret 544: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 548: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 54f: eb 87 jmp 4d8 <printint+0x28> 551: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 558: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 55f: 90 nop 00000560 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 560: f3 0f 1e fb endbr32 564: 55 push %ebp 565: 89 e5 mov %esp,%ebp 567: 57 push %edi 568: 56 push %esi 569: 53 push %ebx 56a: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 56d: 8b 75 0c mov 0xc(%ebp),%esi 570: 0f b6 1e movzbl (%esi),%ebx 573: 84 db test %bl,%bl 575: 0f 84 b4 00 00 00 je 62f <printf+0xcf> ap = (uint*)(void*)&fmt + 1; 57b: 8d 45 10 lea 0x10(%ebp),%eax 57e: 83 c6 01 add $0x1,%esi write(fd, &c, 1); 581: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 584: 31 d2 xor %edx,%edx ap = (uint*)(void*)&fmt + 1; 586: 89 45 d0 mov %eax,-0x30(%ebp) 589: eb 33 jmp 5be <printf+0x5e> 58b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 58f: 90 nop 590: 89 55 d4 mov %edx,-0x2c(%ebp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 593: ba 25 00 00 00 mov $0x25,%edx if(c == '%'){ 598: 83 f8 25 cmp $0x25,%eax 59b: 74 17 je 5b4 <printf+0x54> write(fd, &c, 1); 59d: 83 ec 04 sub $0x4,%esp 5a0: 88 5d e7 mov %bl,-0x19(%ebp) 5a3: 6a 01 push $0x1 5a5: 57 push %edi 5a6: ff 75 08 pushl 0x8(%ebp) 5a9: e8 05 fe ff ff call 3b3 <write> 5ae: 8b 55 d4 mov -0x2c(%ebp),%edx } else { putc(fd, c); 5b1: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 5b4: 0f b6 1e movzbl (%esi),%ebx 5b7: 83 c6 01 add $0x1,%esi 5ba: 84 db test %bl,%bl 5bc: 74 71 je 62f <printf+0xcf> c = fmt[i] & 0xff; 5be: 0f be cb movsbl %bl,%ecx 5c1: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 5c4: 85 d2 test %edx,%edx 5c6: 74 c8 je 590 <printf+0x30> } } else if(state == '%'){ 5c8: 83 fa 25 cmp $0x25,%edx 5cb: 75 e7 jne 5b4 <printf+0x54> if(c == 'd'){ 5cd: 83 f8 64 cmp $0x64,%eax 5d0: 0f 84 9a 00 00 00 je 670 <printf+0x110> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 5d6: 81 e1 f7 00 00 00 and $0xf7,%ecx 5dc: 83 f9 70 cmp $0x70,%ecx 5df: 74 5f je 640 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 5e1: 83 f8 73 cmp $0x73,%eax 5e4: 0f 84 d6 00 00 00 je 6c0 <printf+0x160> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 5ea: 83 f8 63 cmp $0x63,%eax 5ed: 0f 84 8d 00 00 00 je 680 <printf+0x120> putc(fd, *ap); ap++; } else if(c == '%'){ 5f3: 83 f8 25 cmp $0x25,%eax 5f6: 0f 84 b4 00 00 00 je 6b0 <printf+0x150> write(fd, &c, 1); 5fc: 83 ec 04 sub $0x4,%esp 5ff: c6 45 e7 25 movb $0x25,-0x19(%ebp) 603: 6a 01 push $0x1 605: 57 push %edi 606: ff 75 08 pushl 0x8(%ebp) 609: e8 a5 fd ff ff call 3b3 <write> putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 60e: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 611: 83 c4 0c add $0xc,%esp 614: 6a 01 push $0x1 616: 83 c6 01 add $0x1,%esi 619: 57 push %edi 61a: ff 75 08 pushl 0x8(%ebp) 61d: e8 91 fd ff ff call 3b3 <write> for(i = 0; fmt[i]; i++){ 622: 0f b6 5e ff movzbl -0x1(%esi),%ebx putc(fd, c); 626: 83 c4 10 add $0x10,%esp } state = 0; 629: 31 d2 xor %edx,%edx for(i = 0; fmt[i]; i++){ 62b: 84 db test %bl,%bl 62d: 75 8f jne 5be <printf+0x5e> } } } 62f: 8d 65 f4 lea -0xc(%ebp),%esp 632: 5b pop %ebx 633: 5e pop %esi 634: 5f pop %edi 635: 5d pop %ebp 636: c3 ret 637: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 63e: 66 90 xchg %ax,%ax printint(fd, *ap, 16, 0); 640: 83 ec 0c sub $0xc,%esp 643: b9 10 00 00 00 mov $0x10,%ecx 648: 6a 00 push $0x0 64a: 8b 5d d0 mov -0x30(%ebp),%ebx 64d: 8b 45 08 mov 0x8(%ebp),%eax 650: 8b 13 mov (%ebx),%edx 652: e8 59 fe ff ff call 4b0 <printint> ap++; 657: 89 d8 mov %ebx,%eax 659: 83 c4 10 add $0x10,%esp state = 0; 65c: 31 d2 xor %edx,%edx ap++; 65e: 83 c0 04 add $0x4,%eax 661: 89 45 d0 mov %eax,-0x30(%ebp) 664: e9 4b ff ff ff jmp 5b4 <printf+0x54> 669: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi printint(fd, *ap, 10, 1); 670: 83 ec 0c sub $0xc,%esp 673: b9 0a 00 00 00 mov $0xa,%ecx 678: 6a 01 push $0x1 67a: eb ce jmp 64a <printf+0xea> 67c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi putc(fd, *ap); 680: 8b 5d d0 mov -0x30(%ebp),%ebx write(fd, &c, 1); 683: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 686: 8b 03 mov (%ebx),%eax write(fd, &c, 1); 688: 6a 01 push $0x1 ap++; 68a: 83 c3 04 add $0x4,%ebx write(fd, &c, 1); 68d: 57 push %edi 68e: ff 75 08 pushl 0x8(%ebp) putc(fd, *ap); 691: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 694: e8 1a fd ff ff call 3b3 <write> ap++; 699: 89 5d d0 mov %ebx,-0x30(%ebp) 69c: 83 c4 10 add $0x10,%esp state = 0; 69f: 31 d2 xor %edx,%edx 6a1: e9 0e ff ff ff jmp 5b4 <printf+0x54> 6a6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 6ad: 8d 76 00 lea 0x0(%esi),%esi putc(fd, c); 6b0: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 6b3: 83 ec 04 sub $0x4,%esp 6b6: e9 59 ff ff ff jmp 614 <printf+0xb4> 6bb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 6bf: 90 nop s = (char*)*ap; 6c0: 8b 45 d0 mov -0x30(%ebp),%eax 6c3: 8b 18 mov (%eax),%ebx ap++; 6c5: 83 c0 04 add $0x4,%eax 6c8: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) 6cb: 85 db test %ebx,%ebx 6cd: 74 17 je 6e6 <printf+0x186> while(*s != 0){ 6cf: 0f b6 03 movzbl (%ebx),%eax state = 0; 6d2: 31 d2 xor %edx,%edx while(*s != 0){ 6d4: 84 c0 test %al,%al 6d6: 0f 84 d8 fe ff ff je 5b4 <printf+0x54> 6dc: 89 75 d4 mov %esi,-0x2c(%ebp) 6df: 89 de mov %ebx,%esi 6e1: 8b 5d 08 mov 0x8(%ebp),%ebx 6e4: eb 1a jmp 700 <printf+0x1a0> s = "(null)"; 6e6: bb 07 09 00 00 mov $0x907,%ebx while(*s != 0){ 6eb: 89 75 d4 mov %esi,-0x2c(%ebp) 6ee: b8 28 00 00 00 mov $0x28,%eax 6f3: 89 de mov %ebx,%esi 6f5: 8b 5d 08 mov 0x8(%ebp),%ebx 6f8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 6ff: 90 nop write(fd, &c, 1); 700: 83 ec 04 sub $0x4,%esp s++; 703: 83 c6 01 add $0x1,%esi 706: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 709: 6a 01 push $0x1 70b: 57 push %edi 70c: 53 push %ebx 70d: e8 a1 fc ff ff call 3b3 <write> while(*s != 0){ 712: 0f b6 06 movzbl (%esi),%eax 715: 83 c4 10 add $0x10,%esp 718: 84 c0 test %al,%al 71a: 75 e4 jne 700 <printf+0x1a0> 71c: 8b 75 d4 mov -0x2c(%ebp),%esi state = 0; 71f: 31 d2 xor %edx,%edx 721: e9 8e fe ff ff jmp 5b4 <printf+0x54> 726: 66 90 xchg %ax,%ax 728: 66 90 xchg %ax,%ax 72a: 66 90 xchg %ax,%ax 72c: 66 90 xchg %ax,%ax 72e: 66 90 xchg %ax,%ax 00000730 <free>: static Header base; static Header *freep; void free(void *ap) { 730: f3 0f 1e fb endbr32 734: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 735: a1 c8 0b 00 00 mov 0xbc8,%eax { 73a: 89 e5 mov %esp,%ebp 73c: 57 push %edi 73d: 56 push %esi 73e: 53 push %ebx 73f: 8b 5d 08 mov 0x8(%ebp),%ebx 742: 8b 10 mov (%eax),%edx bp = (Header*)ap - 1; 744: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 747: 39 c8 cmp %ecx,%eax 749: 73 15 jae 760 <free+0x30> 74b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 74f: 90 nop 750: 39 d1 cmp %edx,%ecx 752: 72 14 jb 768 <free+0x38> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 754: 39 d0 cmp %edx,%eax 756: 73 10 jae 768 <free+0x38> { 758: 89 d0 mov %edx,%eax for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 75a: 8b 10 mov (%eax),%edx 75c: 39 c8 cmp %ecx,%eax 75e: 72 f0 jb 750 <free+0x20> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 760: 39 d0 cmp %edx,%eax 762: 72 f4 jb 758 <free+0x28> 764: 39 d1 cmp %edx,%ecx 766: 73 f0 jae 758 <free+0x28> break; if(bp + bp->s.size == p->s.ptr){ 768: 8b 73 fc mov -0x4(%ebx),%esi 76b: 8d 3c f1 lea (%ecx,%esi,8),%edi 76e: 39 fa cmp %edi,%edx 770: 74 1e je 790 <free+0x60> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 772: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 775: 8b 50 04 mov 0x4(%eax),%edx 778: 8d 34 d0 lea (%eax,%edx,8),%esi 77b: 39 f1 cmp %esi,%ecx 77d: 74 28 je 7a7 <free+0x77> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 77f: 89 08 mov %ecx,(%eax) freep = p; } 781: 5b pop %ebx freep = p; 782: a3 c8 0b 00 00 mov %eax,0xbc8 } 787: 5e pop %esi 788: 5f pop %edi 789: 5d pop %ebp 78a: c3 ret 78b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 78f: 90 nop bp->s.size += p->s.ptr->s.size; 790: 03 72 04 add 0x4(%edx),%esi 793: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 796: 8b 10 mov (%eax),%edx 798: 8b 12 mov (%edx),%edx 79a: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 79d: 8b 50 04 mov 0x4(%eax),%edx 7a0: 8d 34 d0 lea (%eax,%edx,8),%esi 7a3: 39 f1 cmp %esi,%ecx 7a5: 75 d8 jne 77f <free+0x4f> p->s.size += bp->s.size; 7a7: 03 53 fc add -0x4(%ebx),%edx freep = p; 7aa: a3 c8 0b 00 00 mov %eax,0xbc8 p->s.size += bp->s.size; 7af: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 7b2: 8b 53 f8 mov -0x8(%ebx),%edx 7b5: 89 10 mov %edx,(%eax) } 7b7: 5b pop %ebx 7b8: 5e pop %esi 7b9: 5f pop %edi 7ba: 5d pop %ebp 7bb: c3 ret 7bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 000007c0 <malloc>: return freep; } void* malloc(uint nbytes) { 7c0: f3 0f 1e fb endbr32 7c4: 55 push %ebp 7c5: 89 e5 mov %esp,%ebp 7c7: 57 push %edi 7c8: 56 push %esi 7c9: 53 push %ebx 7ca: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 7cd: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 7d0: 8b 3d c8 0b 00 00 mov 0xbc8,%edi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 7d6: 8d 70 07 lea 0x7(%eax),%esi 7d9: c1 ee 03 shr $0x3,%esi 7dc: 83 c6 01 add $0x1,%esi if((prevp = freep) == 0){ 7df: 85 ff test %edi,%edi 7e1: 0f 84 a9 00 00 00 je 890 <malloc+0xd0> base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 7e7: 8b 07 mov (%edi),%eax if(p->s.size >= nunits){ 7e9: 8b 48 04 mov 0x4(%eax),%ecx 7ec: 39 f1 cmp %esi,%ecx 7ee: 73 6d jae 85d <malloc+0x9d> 7f0: 81 fe 00 10 00 00 cmp $0x1000,%esi 7f6: bb 00 10 00 00 mov $0x1000,%ebx 7fb: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 7fe: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx 805: 89 4d e4 mov %ecx,-0x1c(%ebp) 808: eb 17 jmp 821 <malloc+0x61> 80a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 810: 8b 10 mov (%eax),%edx if(p->s.size >= nunits){ 812: 8b 4a 04 mov 0x4(%edx),%ecx 815: 39 f1 cmp %esi,%ecx 817: 73 4f jae 868 <malloc+0xa8> 819: 8b 3d c8 0b 00 00 mov 0xbc8,%edi 81f: 89 d0 mov %edx,%eax p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 821: 39 c7 cmp %eax,%edi 823: 75 eb jne 810 <malloc+0x50> p = sbrk(nu * sizeof(Header)); 825: 83 ec 0c sub $0xc,%esp 828: ff 75 e4 pushl -0x1c(%ebp) 82b: e8 eb fb ff ff call 41b <sbrk> if(p == (char*)-1) 830: 83 c4 10 add $0x10,%esp 833: 83 f8 ff cmp $0xffffffff,%eax 836: 74 1b je 853 <malloc+0x93> hp->s.size = nu; 838: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 83b: 83 ec 0c sub $0xc,%esp 83e: 83 c0 08 add $0x8,%eax 841: 50 push %eax 842: e8 e9 fe ff ff call 730 <free> return freep; 847: a1 c8 0b 00 00 mov 0xbc8,%eax if((p = morecore(nunits)) == 0) 84c: 83 c4 10 add $0x10,%esp 84f: 85 c0 test %eax,%eax 851: 75 bd jne 810 <malloc+0x50> return 0; } } 853: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 856: 31 c0 xor %eax,%eax } 858: 5b pop %ebx 859: 5e pop %esi 85a: 5f pop %edi 85b: 5d pop %ebp 85c: c3 ret if(p->s.size >= nunits){ 85d: 89 c2 mov %eax,%edx 85f: 89 f8 mov %edi,%eax 861: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p->s.size == nunits) 868: 39 ce cmp %ecx,%esi 86a: 74 54 je 8c0 <malloc+0x100> p->s.size -= nunits; 86c: 29 f1 sub %esi,%ecx 86e: 89 4a 04 mov %ecx,0x4(%edx) p += p->s.size; 871: 8d 14 ca lea (%edx,%ecx,8),%edx p->s.size = nunits; 874: 89 72 04 mov %esi,0x4(%edx) freep = prevp; 877: a3 c8 0b 00 00 mov %eax,0xbc8 } 87c: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 87f: 8d 42 08 lea 0x8(%edx),%eax } 882: 5b pop %ebx 883: 5e pop %esi 884: 5f pop %edi 885: 5d pop %ebp 886: c3 ret 887: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 88e: 66 90 xchg %ax,%ax base.s.ptr = freep = prevp = &base; 890: c7 05 c8 0b 00 00 cc movl $0xbcc,0xbc8 897: 0b 00 00 base.s.size = 0; 89a: bf cc 0b 00 00 mov $0xbcc,%edi base.s.ptr = freep = prevp = &base; 89f: c7 05 cc 0b 00 00 cc movl $0xbcc,0xbcc 8a6: 0b 00 00 for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 8a9: 89 f8 mov %edi,%eax base.s.size = 0; 8ab: c7 05 d0 0b 00 00 00 movl $0x0,0xbd0 8b2: 00 00 00 if(p->s.size >= nunits){ 8b5: e9 36 ff ff ff jmp 7f0 <malloc+0x30> 8ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 8c0: 8b 0a mov (%edx),%ecx 8c2: 89 08 mov %ecx,(%eax) 8c4: eb b1 jmp 877 <malloc+0xb7>
// stallTest - try progressive numbers of stalls. // // A test specifically for the pipelined implementation. // // CS/ECE 552, Spring 2006 // Andy Phelps 11 April 2006 // j .RealStart halt halt halt halt halt .Data1: halt halt .Data2: halt halt .Data3: halt halt .Data4: halt .Data5: halt halt halt halt halt halt halt halt halt halt .RealStart: lbi r0, 3 nop nop nop nop nop addi r0, r0, 1 // r0 = 4 lbi r1, 6 nop nop nop nop addi r1, r1, 1 // r1 = 7 lbi r2, 5 nop nop nop addi r2, r2, 1 // r2 = 6 lbi r3, 7 nop nop addi r3, r3, 1 // r3 = 8 lbi r4, 9 nop addi r4, r4, 1 // r4 = 10 lbi r5, 11 addi r5, r5, 1 // r5 = 12 add r0, r0, r1 // r0 = 11 add r2, r3, r2 // r2 = 14 add r4, r4, r5 // r4 = 22 add r0, r0, r2 // r0 = 25 add r7, r0, r4 // r7 = 47 = 0x002f lbi r6, 1 // r6 = 1 lbi r0, 3 nop nop nop nop nop add r0, r6, r0 // r0 = 4 lbi r1, 6 nop nop nop nop add r1, r6, r1 // r1 = 7 lbi r2, 5 nop nop nop add r2, r6, r2 // r2 = 6 lbi r3, 7 nop nop add r3, r6, r3 // r3 = 8 lbi r4, 9 nop add r4, r6, r4 // r4 = 10 lbi r5, 11 add r5, r6, r5 // r5 = 12 add r0, r1, r0 // r0 = 11 add r2, r2, r3 // r2 = 14 add r4, r5, r4 // r4 = 22 add r0, r2, r0 // r0 = 25 add r6, r4, r0 // r6 = 47 = 0x002f add r7, r6, r7 // r7 = 94 = 0x005e lbi r0, L.Data1 nop nop nop nop st r7, r0, 0 // .Data1 = 0x005e lbi r0, L.Data2 nop nop nop st r7, r0, 0 // .Data2 = 0x005e lbi r0, L.Data3 nop nop st r7, r0, 0 // .Data3 = 0x005e lbi r0, L.Data4 nop st r7, r0, 0 // .Data4 = 0x005e lbi r0, L.Data5 stu r6, r0, 2 // .Data5+2 = 0x002f nop nop nop nop stu r6, r0, 2 // .Data5+4 = 0x002f nop nop nop stu r6, r0, 2 // .Data5+6 = 0x002f nop nop stu r6, r0, 2 // .Data5+8 = 0x002f nop stu r6, r0, 2 // .Data5+10 = 0x002f stu r7, r0, 2 // .Data5+12 = 0x005e lbi r0, L.Data1 nop nop nop ld r1, r0, 0 // r1 = 0x005e nop nop nop addi r6, r1, 0 // r6 = 0x005e lbi r1, L.Data1 nop nop ld r2, r1, 0 // r2 = 0x005e nop nop add r6, r6, r2 // r6 = 0x00bc lbi r2, L.Data1 nop ld r3, r2, 0 // r3 = 0x005e nop add r6, r6, r3 // r6 = 0x011a lbi r3, L.Data1 ld r4, r3, 0 // r4 = 0x005e add r6, r6, r4 // r6 = 0x0178 st r6, r3, -2 // .Data1-1 = 0x0178 lbi r3, 0 beqz r3, .GoHere halt halt halt halt .GoHere: ld r3, r2, 0 // r3 = 0x005e bnez r3, .GoThere halt halt halt halt .GoThere: lbi r0, U.GoGoGo slbi r0, L.GoGoGo jalr r0, 0 .RetAddr: halt halt halt halt .GoGoGo: st r7, r2, -2 // .Data1-2 = .RetAddr (0x00a4) halt halt halt
;****************************************************************************** ;* MMX/SSE2-optimized functions for the VP3 decoder ;* Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "x86inc.asm" %include "x86util.asm" ; MMX-optimized functions cribbed from the original VP3 source code. SECTION_RODATA vp3_idct_data: times 8 dw 64277 times 8 dw 60547 times 8 dw 54491 times 8 dw 46341 times 8 dw 36410 times 8 dw 25080 times 8 dw 12785 cextern pb_1 cextern pb_3 cextern pb_7 cextern pb_1F cextern pb_81 cextern pw_8 cextern put_signed_pixels_clamped_mmx cextern add_pixels_clamped_mmx SECTION .text ; this is off by one or two for some cases when filter_limit is greater than 63 ; in: p0 in mm6, p1 in mm4, p2 in mm2, p3 in mm1 ; out: p1 in mm4, p2 in mm3 %macro VP3_LOOP_FILTER 0 movq m7, m6 pand m6, [pb_7] ; p0&7 psrlw m7, 3 pand m7, [pb_1F] ; p0>>3 movq m3, m2 ; p2 pxor m2, m4 pand m2, [pb_1] ; (p2^p1)&1 movq m5, m2 paddb m2, m2 paddb m2, m5 ; 3*(p2^p1)&1 paddb m2, m6 ; extra bits lost in shifts pcmpeqb m0, m0 pxor m1, m0 ; 255 - p3 pavgb m1, m2 ; (256 - p3 + extrabits) >> 1 pxor m0, m4 ; 255 - p1 pavgb m0, m3 ; (256 + p2-p1) >> 1 paddb m1, [pb_3] pavgb m1, m0 ; 128+2+( p2-p1 - p3) >> 2 pavgb m1, m0 ; 128+1+(3*(p2-p1) - p3) >> 3 paddusb m7, m1 ; d+128+1 movq m6, [pb_81] psubusb m6, m7 psubusb m7, [pb_81] movq m5, [r2+516] ; flim pminub m6, m5 pminub m7, m5 movq m0, m6 movq m1, m7 paddb m6, m6 paddb m7, m7 pminub m6, m5 pminub m7, m5 psubb m6, m0 psubb m7, m1 paddusb m4, m7 psubusb m4, m6 psubusb m3, m7 paddusb m3, m6 %endmacro %macro STORE_4_WORDS 1 movd r2d, %1 mov [r0 -1], r2w psrlq %1, 32 shr r2, 16 mov [r0+r1 -1], r2w movd r2d, %1 mov [r0+r1*2-1], r2w shr r2, 16 mov [r0+r3 -1], r2w %endmacro INIT_MMX cglobal vp3_v_loop_filter_mmx2, 3, 4 %ifdef ARCH_X86_64 movsxd r1, r1d %endif mov r3, r1 neg r1 movq m6, [r0+r1*2] movq m4, [r0+r1 ] movq m2, [r0 ] movq m1, [r0+r3 ] VP3_LOOP_FILTER movq [r0+r1], m4 movq [r0 ], m3 RET cglobal vp3_h_loop_filter_mmx2, 3, 4 %ifdef ARCH_X86_64 movsxd r1, r1d %endif lea r3, [r1*3] movd m6, [r0 -2] movd m4, [r0+r1 -2] movd m2, [r0+r1*2-2] movd m1, [r0+r3 -2] lea r0, [r0+r1*4 ] punpcklbw m6, [r0 -2] punpcklbw m4, [r0+r1 -2] punpcklbw m2, [r0+r1*2-2] punpcklbw m1, [r0+r3 -2] sub r0, r3 sub r0, r1 TRANSPOSE4x4B 6, 4, 2, 1, 0 VP3_LOOP_FILTER SBUTTERFLY bw, 4, 3, 5 STORE_4_WORDS m4 lea r0, [r0+r1*4 ] STORE_4_WORDS m3 RET ; from original comments: The Macro does IDct on 4 1-D Dcts %macro BeginIDCT 0 movq m2, I(3) movq m6, C(3) movq m4, m2 movq m7, J(5) pmulhw m4, m6 ; r4 = c3*i3 - i3 movq m1, C(5) pmulhw m6, m7 ; r6 = c3*i5 - i5 movq m5, m1 pmulhw m1, m2 ; r1 = c5*i3 - i3 movq m3, I(1) pmulhw m5, m7 ; r5 = c5*i5 - i5 movq m0, C(1) paddw m4, m2 ; r4 = c3*i3 paddw m6, m7 ; r6 = c3*i5 paddw m2, m1 ; r2 = c5*i3 movq m1, J(7) paddw m7, m5 ; r7 = c5*i5 movq m5, m0 ; r5 = c1 pmulhw m0, m3 ; r0 = c1*i1 - i1 paddsw m4, m7 ; r4 = C = c3*i3 + c5*i5 pmulhw m5, m1 ; r5 = c1*i7 - i7 movq m7, C(7) psubsw m6, m2 ; r6 = D = c3*i5 - c5*i3 paddw m0, m3 ; r0 = c1*i1 pmulhw m3, m7 ; r3 = c7*i1 movq m2, I(2) pmulhw m7, m1 ; r7 = c7*i7 paddw m5, m1 ; r5 = c1*i7 movq m1, m2 ; r1 = i2 pmulhw m2, C(2) ; r2 = c2*i2 - i2 psubsw m3, m5 ; r3 = B = c7*i1 - c1*i7 movq m5, J(6) paddsw m0, m7 ; r0 = A = c1*i1 + c7*i7 movq m7, m5 ; r7 = i6 psubsw m0, m4 ; r0 = A - C pmulhw m5, C(2) ; r5 = c2*i6 - i6 paddw m2, m1 ; r2 = c2*i2 pmulhw m1, C(6) ; r1 = c6*i2 paddsw m4, m4 ; r4 = C + C paddsw m4, m0 ; r4 = C. = A + C psubsw m3, m6 ; r3 = B - D paddw m5, m7 ; r5 = c2*i6 paddsw m6, m6 ; r6 = D + D pmulhw m7, C(6) ; r7 = c6*i6 paddsw m6, m3 ; r6 = D. = B + D movq I(1), m4 ; save C. at I(1) psubsw m1, m5 ; r1 = H = c6*i2 - c2*i6 movq m4, C(4) movq m5, m3 ; r5 = B - D pmulhw m3, m4 ; r3 = (c4 - 1) * (B - D) paddsw m7, m2 ; r3 = (c4 - 1) * (B - D) movq I(2), m6 ; save D. at I(2) movq m2, m0 ; r2 = A - C movq m6, I(0) pmulhw m0, m4 ; r0 = (c4 - 1) * (A - C) paddw m5, m3 ; r5 = B. = c4 * (B - D) movq m3, J(4) psubsw m5, m1 ; r5 = B.. = B. - H paddw m2, m0 ; r0 = A. = c4 * (A - C) psubsw m6, m3 ; r6 = i0 - i4 movq m0, m6 pmulhw m6, m4 ; r6 = (c4 - 1) * (i0 - i4) paddsw m3, m3 ; r3 = i4 + i4 paddsw m1, m1 ; r1 = H + H paddsw m3, m0 ; r3 = i0 + i4 paddsw m1, m5 ; r1 = H. = B + H pmulhw m4, m3 ; r4 = (c4 - 1) * (i0 + i4) paddsw m6, m0 ; r6 = F = c4 * (i0 - i4) psubsw m6, m2 ; r6 = F. = F - A. paddsw m2, m2 ; r2 = A. + A. movq m0, I(1) ; r0 = C. paddsw m2, m6 ; r2 = A.. = F + A. paddw m4, m3 ; r4 = E = c4 * (i0 + i4) psubsw m2, m1 ; r2 = R2 = A.. - H. %endmacro ; RowIDCT gets ready to transpose %macro RowIDCT 0 BeginIDCT movq m3, I(2) ; r3 = D. psubsw m4, m7 ; r4 = E. = E - G paddsw m1, m1 ; r1 = H. + H. paddsw m7, m7 ; r7 = G + G paddsw m1, m2 ; r1 = R1 = A.. + H. paddsw m7, m4 ; r1 = R1 = A.. + H. psubsw m4, m3 ; r4 = R4 = E. - D. paddsw m3, m3 psubsw m6, m5 ; r6 = R6 = F. - B.. paddsw m5, m5 paddsw m3, m4 ; r3 = R3 = E. + D. paddsw m5, m6 ; r5 = R5 = F. + B.. psubsw m7, m0 ; r7 = R7 = G. - C. paddsw m0, m0 movq I(1), m1 ; save R1 paddsw m0, m7 ; r0 = R0 = G. + C. %endmacro ; Column IDCT normalizes and stores final results %macro ColumnIDCT 0 BeginIDCT paddsw m2, OC_8 ; adjust R2 (and R1) for shift paddsw m1, m1 ; r1 = H. + H. paddsw m1, m2 ; r1 = R1 = A.. + H. psraw m2, 4 ; r2 = NR2 psubsw m4, m7 ; r4 = E. = E - G psraw m1, 4 ; r1 = NR2 movq m3, I(2) ; r3 = D. paddsw m7, m7 ; r7 = G + G movq I(2), m2 ; store NR2 at I2 paddsw m7, m4 ; r7 = G. = E + G movq I(1), m1 ; store NR1 at I1 psubsw m4, m3 ; r4 = R4 = E. - D. paddsw m4, OC_8 ; adjust R4 (and R3) for shift paddsw m3, m3 ; r3 = D. + D. paddsw m3, m4 ; r3 = R3 = E. + D. psraw m4, 4 ; r4 = NR4 psubsw m6, m5 ; r6 = R6 = F. - B.. psraw m3, 4 ; r3 = NR3 paddsw m6, OC_8 ; adjust R6 (and R5) for shift paddsw m5, m5 ; r5 = B.. + B.. paddsw m5, m6 ; r5 = R5 = F. + B.. psraw m6, 4 ; r6 = NR6 movq J(4), m4 ; store NR4 at J4 psraw m5, 4 ; r5 = NR5 movq I(3), m3 ; store NR3 at I3 psubsw m7, m0 ; r7 = R7 = G. - C. paddsw m7, OC_8 ; adjust R7 (and R0) for shift paddsw m0, m0 ; r0 = C. + C. paddsw m0, m7 ; r0 = R0 = G. + C. psraw m7, 4 ; r7 = NR7 movq J(6), m6 ; store NR6 at J6 psraw m0, 4 ; r0 = NR0 movq J(5), m5 ; store NR5 at J5 movq J(7), m7 ; store NR7 at J7 movq I(0), m0 ; store NR0 at I0 %endmacro ; Following macro does two 4x4 transposes in place. ; ; At entry (we assume): ; ; r0 = a3 a2 a1 a0 ; I(1) = b3 b2 b1 b0 ; r2 = c3 c2 c1 c0 ; r3 = d3 d2 d1 d0 ; ; r4 = e3 e2 e1 e0 ; r5 = f3 f2 f1 f0 ; r6 = g3 g2 g1 g0 ; r7 = h3 h2 h1 h0 ; ; At exit, we have: ; ; I(0) = d0 c0 b0 a0 ; I(1) = d1 c1 b1 a1 ; I(2) = d2 c2 b2 a2 ; I(3) = d3 c3 b3 a3 ; ; J(4) = h0 g0 f0 e0 ; J(5) = h1 g1 f1 e1 ; J(6) = h2 g2 f2 e2 ; J(7) = h3 g3 f3 e3 ; ; I(0) I(1) I(2) I(3) is the transpose of r0 I(1) r2 r3. ; J(4) J(5) J(6) J(7) is the transpose of r4 r5 r6 r7. ; ; Since r1 is free at entry, we calculate the Js first. %macro Transpose 0 movq m1, m4 ; r1 = e3 e2 e1 e0 punpcklwd m4, m5 ; r4 = f1 e1 f0 e0 movq I(0), m0 ; save a3 a2 a1 a0 punpckhwd m1, m5 ; r1 = f3 e3 f2 e2 movq m0, m6 ; r0 = g3 g2 g1 g0 punpcklwd m6, m7 ; r6 = h1 g1 h0 g0 movq m5, m4 ; r5 = f1 e1 f0 e0 punpckldq m4, m6 ; r4 = h0 g0 f0 e0 = R4 punpckhdq m5, m6 ; r5 = h1 g1 f1 e1 = R5 movq m6, m1 ; r6 = f3 e3 f2 e2 movq J(4), m4 punpckhwd m0, m7 ; r0 = h3 g3 h2 g2 movq J(5), m5 punpckhdq m6, m0 ; r6 = h3 g3 f3 e3 = R7 movq m4, I(0) ; r4 = a3 a2 a1 a0 punpckldq m1, m0 ; r1 = h2 g2 f2 e2 = R6 movq m5, I(1) ; r5 = b3 b2 b1 b0 movq m0, m4 ; r0 = a3 a2 a1 a0 movq J(7), m6 punpcklwd m0, m5 ; r0 = b1 a1 b0 a0 movq J(6), m1 punpckhwd m4, m5 ; r4 = b3 a3 b2 a2 movq m5, m2 ; r5 = c3 c2 c1 c0 punpcklwd m2, m3 ; r2 = d1 c1 d0 c0 movq m1, m0 ; r1 = b1 a1 b0 a0 punpckldq m0, m2 ; r0 = d0 c0 b0 a0 = R0 punpckhdq m1, m2 ; r1 = d1 c1 b1 a1 = R1 movq m2, m4 ; r2 = b3 a3 b2 a2 movq I(0), m0 punpckhwd m5, m3 ; r5 = d3 c3 d2 c2 movq I(1), m1 punpckhdq m4, m5 ; r4 = d3 c3 b3 a3 = R3 punpckldq m2, m5 ; r2 = d2 c2 b2 a2 = R2 movq I(3), m4 movq I(2), m2 %endmacro %macro VP3_IDCT_mmx 1 ; eax = quantized input ; ebx = dequantizer matrix ; ecx = IDCT constants ; M(I) = ecx + MaskOffset(0) + I * 8 ; C(I) = ecx + CosineOffset(32) + (I-1) * 8 ; edx = output ; r0..r7 = mm0..mm7 %define OC_8 [pw_8] %define C(x) [vp3_idct_data+16*(x-1)] ; at this point, function has completed dequantization + dezigzag + ; partial transposition; now do the idct itself %define I(x) [%1+16* x ] %define J(x) [%1+16*(x-4)+8] RowIDCT Transpose %define I(x) [%1+16* x +64] %define J(x) [%1+16*(x-4)+72] RowIDCT Transpose %define I(x) [%1+16*x] %define J(x) [%1+16*x] ColumnIDCT %define I(x) [%1+16*x+8] %define J(x) [%1+16*x+8] ColumnIDCT %endmacro %macro VP3_1D_IDCT_SSE2 0 movdqa m2, I(3) ; xmm2 = i3 movdqa m6, C(3) ; xmm6 = c3 movdqa m4, m2 ; xmm4 = i3 movdqa m7, I(5) ; xmm7 = i5 pmulhw m4, m6 ; xmm4 = c3 * i3 - i3 movdqa m1, C(5) ; xmm1 = c5 pmulhw m6, m7 ; xmm6 = c3 * i5 - i5 movdqa m5, m1 ; xmm5 = c5 pmulhw m1, m2 ; xmm1 = c5 * i3 - i3 movdqa m3, I(1) ; xmm3 = i1 pmulhw m5, m7 ; xmm5 = c5 * i5 - i5 movdqa m0, C(1) ; xmm0 = c1 paddw m4, m2 ; xmm4 = c3 * i3 paddw m6, m7 ; xmm6 = c3 * i5 paddw m2, m1 ; xmm2 = c5 * i3 movdqa m1, I(7) ; xmm1 = i7 paddw m7, m5 ; xmm7 = c5 * i5 movdqa m5, m0 ; xmm5 = c1 pmulhw m0, m3 ; xmm0 = c1 * i1 - i1 paddsw m4, m7 ; xmm4 = c3 * i3 + c5 * i5 = C pmulhw m5, m1 ; xmm5 = c1 * i7 - i7 movdqa m7, C(7) ; xmm7 = c7 psubsw m6, m2 ; xmm6 = c3 * i5 - c5 * i3 = D paddw m0, m3 ; xmm0 = c1 * i1 pmulhw m3, m7 ; xmm3 = c7 * i1 movdqa m2, I(2) ; xmm2 = i2 pmulhw m7, m1 ; xmm7 = c7 * i7 paddw m5, m1 ; xmm5 = c1 * i7 movdqa m1, m2 ; xmm1 = i2 pmulhw m2, C(2) ; xmm2 = i2 * c2 -i2 psubsw m3, m5 ; xmm3 = c7 * i1 - c1 * i7 = B movdqa m5, I(6) ; xmm5 = i6 paddsw m0, m7 ; xmm0 = c1 * i1 + c7 * i7 = A movdqa m7, m5 ; xmm7 = i6 psubsw m0, m4 ; xmm0 = A - C pmulhw m5, C(2) ; xmm5 = c2 * i6 - i6 paddw m2, m1 ; xmm2 = i2 * c2 pmulhw m1, C(6) ; xmm1 = c6 * i2 paddsw m4, m4 ; xmm4 = C + C paddsw m4, m0 ; xmm4 = A + C = C. psubsw m3, m6 ; xmm3 = B - D paddw m5, m7 ; xmm5 = c2 * i6 paddsw m6, m6 ; xmm6 = D + D pmulhw m7, C(6) ; xmm7 = c6 * i6 paddsw m6, m3 ; xmm6 = B + D = D. movdqa I(1), m4 ; Save C. at I(1) psubsw m1, m5 ; xmm1 = c6 * i2 - c2 * i6 = H movdqa m4, C(4) ; xmm4 = C4 movdqa m5, m3 ; xmm5 = B - D pmulhw m3, m4 ; xmm3 = ( c4 -1 ) * ( B - D ) paddsw m7, m2 ; xmm7 = c2 * i2 + c6 * i6 = G movdqa I(2), m6 ; save D. at I(2) movdqa m2, m0 ; xmm2 = A - C movdqa m6, I(0) ; xmm6 = i0 pmulhw m0, m4 ; xmm0 = ( c4 - 1 ) * ( A - C ) = A. paddw m5, m3 ; xmm5 = c4 * ( B - D ) = B. movdqa m3, I(4) ; xmm3 = i4 psubsw m5, m1 ; xmm5 = B. - H = B.. paddw m2, m0 ; xmm2 = c4 * ( A - C) = A. psubsw m6, m3 ; xmm6 = i0 - i4 movdqa m0, m6 ; xmm0 = i0 - i4 pmulhw m6, m4 ; xmm6 = (c4 - 1) * (i0 - i4) = F paddsw m3, m3 ; xmm3 = i4 + i4 paddsw m1, m1 ; xmm1 = H + H paddsw m3, m0 ; xmm3 = i0 + i4 paddsw m1, m5 ; xmm1 = B. + H = H. pmulhw m4, m3 ; xmm4 = ( c4 - 1 ) * ( i0 + i4 ) paddw m6, m0 ; xmm6 = c4 * ( i0 - i4 ) psubsw m6, m2 ; xmm6 = F - A. = F. paddsw m2, m2 ; xmm2 = A. + A. movdqa m0, I(1) ; Load C. from I(1) paddsw m2, m6 ; xmm2 = F + A. = A.. paddw m4, m3 ; xmm4 = c4 * ( i0 + i4 ) = 3 psubsw m2, m1 ; xmm2 = A.. - H. = R2 ADD(m2) ; Adjust R2 and R1 before shifting paddsw m1, m1 ; xmm1 = H. + H. paddsw m1, m2 ; xmm1 = A.. + H. = R1 SHIFT(m2) ; xmm2 = op2 psubsw m4, m7 ; xmm4 = E - G = E. SHIFT(m1) ; xmm1 = op1 movdqa m3, I(2) ; Load D. from I(2) paddsw m7, m7 ; xmm7 = G + G paddsw m7, m4 ; xmm7 = E + G = G. psubsw m4, m3 ; xmm4 = E. - D. = R4 ADD(m4) ; Adjust R4 and R3 before shifting paddsw m3, m3 ; xmm3 = D. + D. paddsw m3, m4 ; xmm3 = E. + D. = R3 SHIFT(m4) ; xmm4 = op4 psubsw m6, m5 ; xmm6 = F. - B..= R6 SHIFT(m3) ; xmm3 = op3 ADD(m6) ; Adjust R6 and R5 before shifting paddsw m5, m5 ; xmm5 = B.. + B.. paddsw m5, m6 ; xmm5 = F. + B.. = R5 SHIFT(m6) ; xmm6 = op6 SHIFT(m5) ; xmm5 = op5 psubsw m7, m0 ; xmm7 = G. - C. = R7 ADD(m7) ; Adjust R7 and R0 before shifting paddsw m0, m0 ; xmm0 = C. + C. paddsw m0, m7 ; xmm0 = G. + C. SHIFT(m7) ; xmm7 = op7 SHIFT(m0) ; xmm0 = op0 %endmacro %macro PUT_BLOCK 8 movdqa O(0), m%1 movdqa O(1), m%2 movdqa O(2), m%3 movdqa O(3), m%4 movdqa O(4), m%5 movdqa O(5), m%6 movdqa O(6), m%7 movdqa O(7), m%8 %endmacro %macro VP3_IDCT_sse2 1 %define I(x) [%1+16*x] %define O(x) [%1+16*x] %define C(x) [vp3_idct_data+16*(x-1)] %define SHIFT(x) %define ADD(x) VP3_1D_IDCT_SSE2 %ifdef ARCH_X86_64 TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, 8 %else TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, [%1], [%1+16] %endif PUT_BLOCK 0, 1, 2, 3, 4, 5, 6, 7 %define SHIFT(x) psraw x, 4 %define ADD(x) paddsw x, [pw_8] VP3_1D_IDCT_SSE2 PUT_BLOCK 0, 1, 2, 3, 4, 5, 6, 7 %endmacro %macro vp3_idct_funcs 3 cglobal vp3_idct_%1, 1, 1, %2 VP3_IDCT_%1 r0 RET cglobal vp3_idct_put_%1, 3, %3, %2 VP3_IDCT_%1 r2 %ifdef ARCH_X86_64 mov r3, r2 mov r2, r1 mov r1, r0 mov r0, r3 %else mov r0m, r2 mov r1m, r0 mov r2m, r1 %endif %ifdef WIN64 call put_signed_pixels_clamped_mmx RET %else jmp put_signed_pixels_clamped_mmx %endif cglobal vp3_idct_add_%1, 3, %3, %2 VP3_IDCT_%1 r2 %ifdef ARCH_X86_64 mov r3, r2 mov r2, r1 mov r1, r0 mov r0, r3 %else mov r0m, r2 mov r1m, r0 mov r2m, r1 %endif %ifdef WIN64 call add_pixels_clamped_mmx RET %else jmp add_pixels_clamped_mmx %endif %endmacro %ifdef ARCH_X86_64 %define REGS 4 %else %define REGS 3 %endif INIT_MMX vp3_idct_funcs mmx, 0, REGS INIT_XMM vp3_idct_funcs sse2, 9, REGS %undef REGS %macro DC_ADD 0 movq m2, [r0 ] movq m3, [r0+r1 ] paddusb m2, m0 movq m4, [r0+r1*2] paddusb m3, m0 movq m5, [r0+r3 ] paddusb m4, m0 paddusb m5, m0 psubusb m2, m1 psubusb m3, m1 movq [r0 ], m2 psubusb m4, m1 movq [r0+r1 ], m3 psubusb m5, m1 movq [r0+r1*2], m4 movq [r0+r3 ], m5 %endmacro INIT_MMX cglobal vp3_idct_dc_add_mmx2, 3, 4 %ifdef ARCH_X86_64 movsxd r1, r1d %endif lea r3, [r1*3] movsx r2, word [r2] add r2, 15 sar r2, 5 movd m0, r2d pshufw m0, m0, 0x0 pxor m1, m1 psubw m1, m0 packuswb m0, m0 packuswb m1, m1 DC_ADD lea r0, [r0+r1*4] DC_ADD RET
COMMENT @----------------------------------------------------------------------- Copyright (c) GeoWorks 1988 -- All Rights Reserved PROJECT: PC GEOS MODULE: Kernel FILE: heapInit.asm (heap initialization) AUTHOR: Tony Requist ROUTINES: Name Description ---- ----------- EXT InitHeap Initialize the heap REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 4/88 Initial version Tony 10/88 Comments from Jim's code review added DESCRIPTION: This module initializes the heap. See manager.asm for documentation. $Id: heapInit.asm,v 1.1 97/04/05 01:13:59 newdeal Exp $ -------------------------------------------------------------------------------@ COMMENT @----------------------------------------------------------------------- FUNCTION: InitHeap DESCRIPTION: Initialize the heap CALLED BY: EXTERNAL InitGeos PASS: ds - kernel variable segment RETURN: none DESTROYED: ax, bx, cx, dx, si, di REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 4/88 Initial version Tony 10/88 Comments from Jim's code review added Don 2/93 Added XIP initialization -------------------------------------------------------------------------------@ InitHeap proc near if FULL_EXECUTE_IN_PLACE ; Set the top of the heap - this is an optimization, so SearchHeap ; won't bother looking through all the blocks from the XIP image ; that never move/are never freed push es mov es, ds:[loaderVars].KLV_xipHeader mov bx, es:[FXIPH_bottomBlock] mov ds:[xipHandleTopBlock], bx pop es ; Initialize the heap with cc's since the loader can't handle it for ; XIP systems. EC< mov bx, ds:[loaderVars].KLV_handleBottomBlock > EC< call ECInitHeapCCCC > elseif KERNEL_EXECUTE_IN_PLACE ; ; For XIP, store the handle with the highest segment address that ; resides in the usable heap. The heap management code will not ; try to allocate anything beyond this, and will also not search ; needlessly through lots of fixed handles ; mov bx, ds:[loaderVars].KLV_handleBottomBlock handleLoop: test ds:[bx].HM_flags, mask HF_FIXED jnz done mov bx, ds:[bx].HM_next jmp handleLoop done: mov ds:[xipHandleTopBlock], bx endif if TRACK_FINAL_FREE ; ; Locate the last free block, searching from the end of the heap. ; mov bx, ds:[loaderVars].KLV_handleBottomBlock findFreeLoop: mov bx, ds:[bx].HM_prev cmp ds:[bx].HM_owner, 0 jne findFreeLoop mov ds:[lastFreeBlock], bx endif ret InitHeap endp if not NEVER_ENFORCE_HEAPSPACE_LIMITS COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InitHeapSize %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Calculates the size of the heap CALLED BY: InitGeos EXTERNAL PASS: ds - kdata RETURN: nothing DESTROYED: nothing SIDE EFFECTS: sets heapSize PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- RG 2/27/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InitHeapSize proc near uses ax,bx,cx,dx,si,di .enter mov bx, ds:[loaderVars].KLV_heapEnd sub bx, ds:[loaderVars].KLV_heapStart mov cl, 6 shr bx, cl ; divide by 64 to go from para to k ; this gives us the base heapsize in bx push ds mov ax, DOC_RESERVE_DEFAULT mov cx, cs mov dx, offset docReserveKeyString mov ds, cx mov si, offset heapSpaceCategoryString call InitFileReadInteger mov di, ax ; get the space reserved for documents for each app in di mov ax, EXEC_RESERVE_DEFAULT mov dx, offset execReserveKeyString call InitFileReadInteger add di, ax ; add in the space reserved for execution for each app mov ax, CONCURRENCY_DEFAULT mov dx, offset concurrencyKeyString call InitFileReadInteger mul di ; multiply the two by the concurrency given for the platform. ; This leaves the total app-based adjustment in dx:ax, but dx ; had better be 0.. EC< tst dx > EC< ERROR_NZ GASP_CHOKE_WHEEZE > sub bx, ax ; now we subtract the space set aside for app use from the ; total heap size. This may go negative.. we don't care at ; this point since swap drivers may pull it out of the hole. ; In fact on a desktop with it's high concurrency and ; docReserve and correspondingly high resources the heapSize ; probably is negative now. clr ax ; heapadjustment default mov dx, offset heapAdjustmentKeyString call InitFileReadInteger add bx, ax ; now we've added in the heapAdjustment to the heapSize mov ax, SYS_RESERVE_DEFAULT mov dx, offset sysReserveKeyString call InitFileReadInteger sub bx, ax ; next we subtract out some space for the system libraries mov ax, BW_TRUE ; Default is Limit Enforced mov dx, offset heapLimitEnforcedKeyString call InitFileReadBoolean ; lastly we check to see if all the heapspace limits are to be enforced pop ds mov ds:[heapSpaceLimitsEnforced], ax mov ds:[heapSize], bx IHS_initialHeapSize:: ; showcalls -H .leave ret InitHeapSize endp docReserveKeyString char "docReserve", 0 execReserveKeyString char "execReserve", 0 sysReserveKeyString char "sysReserve", 0 concurrencyKeyString char "concurrency", 0 heapAdjustmentKeyString char "heapAdjustment", 0 heapLimitEnforcedKeyString char "heapSpaceLimitsEnforced", 0 heapSpaceCategoryString char "heapspace", 0 endif ; not NEVER_ENFORCE_HEAPSPACE_LIMITS if FULL_EXECUTE_IN_PLACE COMMENT @---------------------------------------------------------------------- FUNCTION: ECInitHeapCCCC DESCRIPTION: Fill a block with 0xcc for EC purposes CALLED BY: GLOBAL PASS: ds = idata bx = block to fill RETURN: DESTROYED: REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 1/90 Initial version ------------------------------------------------------------------------------@ if ERROR_CHECK ECInitHeapCCCC proc near call PushAllFar mov es,ds:[bx][HM_addr] mov dx,ds:[bx][HM_size] mov ax, 0xcccc largeLoop: mov cx, 0xfff sub dx, cx ;assume 0xfff0 bytes jae 10$ ;=> ok add cx, dx ;downgrade count by overshoot 10$: shl cx ;convert paras to words shl cx shl cx ;cx = # words clr di rep stosw mov cx, es ;assume > 0xfff paragraphs add cx, 0xfff mov es, cx tst dx ;XXX: assumes no free block ; > 1/2 megabyte. Fair enough? jg largeLoop call PopAllFar ret ECInitHeapCCCC endp endif endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HeapStartScrub %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Create a scrub thread for the heap CALLED BY: InitGeos PASS: ds = idata RETURN: nothing DESTROYED: ? PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 6/25/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ HeapStartScrub proc near .enter ; ; Display log entry ; push ds segmov ds, cs mov si, offset scrubLogString call LogWriteInitEntry pop ds if 0 ; ; If this machine doesn't have much memory (initial free size is ; less than HEAP_LOW_MEM_SIZE), up the priority of the scrub thread ; so we keep the heap clean enough. ; mov al, PRIORITY_LOW cmp ds:[loaderVars].KLV_heapFreeSize, HEAP_LOW_MEM_SIZE shr 4 jae priorityOK mov al, PRIORITY_STANDARD priorityOK: endif if IDLE_UPDATE_ASYNC_VM ; ; Allocate a queue on which to place the handles of VM files that need ; to be updated at idle time. ; call GeodeAllocQueue mov ds:[heapAsyncVMQueue], bx endif ; IDLE_UPDATE_ASYNC_VM ; ; With the new heap functionality performance is better if the scrub ; thread just stands and waits... ; mov al, PRIORITY_IDLE mov bx, ds mov cx, segment HeapScrubThread mov dx, offset HeapScrubThread mov di, SCRUB_STACK_SIZE mov bp, handle 0 call ThreadCreate if INI_SETTABLE_HEAP_THRESHOLDS ; ; Initialize some thresholds from the .ini file, if there. ; push ds mov cx, cs mov ds, cx mov si, offset cs:systemCategoryString mov dx, offset cs:minSpaceForInitialCompactionKey mov ax, MIN_SPACE_FOR_INITIAL_COMPACTION ;default call InitFileReadInteger pop ds mov ds:minSpaceForInitialCompaction, ax push ds mov ds, cx mov dx, offset cs:minSpaceToThrowOutKey mov ax, MIN_SPACE_TO_THROW_OUT ;default call InitFileReadInteger pop ds mov ds:minSpaceToThrowOut, ax endif .leave ret HeapStartScrub endp scrubLogString char "Scrub Thread", 0 if INI_SETTABLE_HEAP_THRESHOLDS minSpaceForInitialCompactionKey char "minSpaceForInitialCompaction",0 minSpaceToThrowOutKey char "minSpaceToThrowOut",0 endif
; A165897: a(n) = a(n-1) + largest proper divisor of a(n-1), a(1)=4. ; 4,6,9,12,18,27,36,54,81,108,162,243,324,486,729,972,1458,2187,2916,4374,6561,8748,13122,19683,26244,39366,59049,78732,118098,177147,236196,354294,531441,708588,1062882,1594323,2125764,3188646,4782969,6377292,9565938,14348907,19131876,28697814,43046721,57395628,86093442,129140163,172186884,258280326,387420489,516560652,774840978,1162261467,1549681956,2324522934,3486784401,4649045868,6973568802,10460353203,13947137604,20920706406,31381059609,41841412812,62762119218,94143178827,125524238436,188286357654,282429536481,376572715308,564859072962,847288609443,1129718145924,1694577218886,2541865828329,3389154437772,5083731656658,7625597484987,10167463313316,15251194969974,22876792454961,30502389939948,45753584909922,68630377364883,91507169819844,137260754729766,205891132094649,274521509459532,411782264189298,617673396283947,823564528378596,1235346792567894,1853020188851841,2470693585135788,3706040377703682,5559060566555523,7412080755407364,11118121133111046,16677181699666569,22236242266222092 add $0,2 mov $1,2 lpb $0 add $1,4 mov $2,$0 gcd $2,3 sub $0,$2 mul $1,$2 lpe sub $1,10 div $1,4 add $1,4 mov $0,$1
/** @file Contains the LiquidScreen class definition. */ /* The MIT License (MIT) Copyright (c) 2016 Vasil Kalchev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "LiquidMenu.h" LiquidScreen::LiquidScreen() : _lineCount(0), _focus(0), _hidden(false) {} LiquidScreen::LiquidScreen(LiquidLine &liquidLine) : LiquidScreen() { add_line(liquidLine); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2) : LiquidScreen(liquidLine1) { add_line(liquidLine2); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2, LiquidLine &liquidLine3) : LiquidScreen(liquidLine1, liquidLine2) { add_line(liquidLine3); } LiquidScreen::LiquidScreen(LiquidLine &liquidLine1, LiquidLine &liquidLine2, LiquidLine &liquidLine3, LiquidLine &liquidLine4) : LiquidScreen(liquidLine1, liquidLine2, liquidLine3) { add_line(liquidLine4); } bool LiquidScreen::add_line(LiquidLine &liquidLine) { print_me(reinterpret_cast<uintptr_t>(this)); if (_lineCount < MAX_LINES) { _p_liquidLine[_lineCount] = &liquidLine; DEBUG(F("Added a new line (")); DEBUG(_lineCount); DEBUGLN(F(")")); _lineCount++; _focus++; // Naively set the number of lines the display has to the // number of added LiquidLine objects. When adding more // LiquidLine objects that the display's number of lines, // void LiquidScreen::set_displayLineCount(uint8_t lines) // must be used to set the number of lines the display has. _displayLineCount = _lineCount; return true; } DEBUG(F("Adding line ")); DEBUG(_lineCount); DEBUG(F(" failed, edit LiquidMenu_config.h to allow for more lines")); return false; } bool LiquidScreen::set_focusPosition(Position position) { print_me(reinterpret_cast<uintptr_t>(this)); if (position == Position::CUSTOM) { DEBUGLN(F("Can't set focus position to 'CUSTOM' for the whole screen at once")); return false; } else { DEBUG(F("Focus position set to : ")); DEBUGLN((uint8_t)position); for (uint8_t l = 0; l < _lineCount; l++) { _p_liquidLine[l]->set_focusPosition(position); } return true; } } void LiquidScreen::set_displayLineCount(uint8_t lines) { _displayLineCount = lines; } void LiquidScreen::hide(bool hide) { _hidden = hide; } void LiquidScreen::print(DisplayClass *p_liquidCrystal) const { uint8_t lOffset = 0; uint8_t displayLineCount = _displayLineCount; if (displayLineCount == 0) { displayLineCount = _lineCount; } else if (displayLineCount > _lineCount) { displayLineCount = _lineCount; } DEBUG("MaxLine: "); DEBUG(displayLineCount); DEBUG("\n"); if (_focus >= displayLineCount) { lOffset = (_focus - displayLineCount) + 1; if ((displayLineCount + lOffset) > _lineCount) { lOffset = (_lineCount - displayLineCount); } } uint8_t offsetRow = 0; for (uint8_t l = lOffset; l < displayLineCount + lOffset; l++) { bool focus = true; if (_focus != l) { focus = false; DEBUG(F("|")); } else { DEBUG(F("| -->")); } DEBUG(F("\tLine ")); DEBUG(l); if (displayLineCount < _lineCount) { _p_liquidLine[l]->_row = offsetRow; } _p_liquidLine[l]->print(p_liquidCrystal, focus); offsetRow++; } } void LiquidScreen::switch_focus(bool forward) { print_me(reinterpret_cast<uintptr_t>(this)); do { if (forward) { if (_focus < _lineCount) { _focus++; if (_focus == _lineCount) { break; } } else { _focus = 0; } } else { //else (forward) if (_focus == 0) { _focus = _lineCount; break; } else { _focus--; } } //else (forward) } while (_p_liquidLine[_focus]->_focusable == false); DEBUG(F("Focus switched to ")); DEBUGLN(_focus); } bool LiquidScreen::call_function(uint8_t number) const { if (_focus != _lineCount) { return _p_liquidLine[_focus]->call_function(number); } return false; }
//=========================================================================== /* Software License Agreement (BSD License) Copyright (c) 2003-2016, CHAI3D (www.chai3d.org) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of CHAI3D nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \author <http://www.chai3d.org> \author Francois Conti \version $MAJOR.$MINOR.$RELEASE $Rev: 1925 $ */ //=========================================================================== //--------------------------------------------------------------------------- #include "CDemo4.h" using namespace std; //--------------------------------------------------------------------------- //=========================================================================== /*! Constructor of cDemo4. */ //=========================================================================== cDemo4::cDemo4(const string a_resourceRoot, const int a_numDevices, shared_ptr<cGenericHapticDevice> a_hapticDevice0, shared_ptr<cGenericHapticDevice> a_hapticDevice1):cGenericDemo(a_resourceRoot, a_numDevices, a_hapticDevice0, a_hapticDevice1) { cMaterial matBase; matBase.setGrayLevel(0.3); matBase.setStiffness(1500); m_ODEBase0 = new cBulletCylinder(m_bulletWorld, 0.075, 0.01); m_bulletWorld->addChild(m_ODEBase0); m_ODEBase0->createAABBCollisionDetector(m_toolRadius); m_ODEBase0->setMaterial(matBase); m_ODEBase0->buildDynamicModel(); m_ODEBase0->setLocalPos(0.015, 0.0, 0.0375); // create a new ODE object that is automatically added to the ODE world m_ODEBody0 = new cBulletMesh(m_bulletWorld); m_bulletWorld->addChild(m_ODEBody0); cCreateRing(m_ODEBody0, 0.01, 0.025, 12, 16); cMaterial mat; mat.setWhite(); mat.m_specular.set(0.0, 0.0, 0.0); mat.setStiffness(1000); mat.setDynamicFriction(0.6); mat.setStaticFriction(0.6); m_ODEBody0->setMaterial(mat); m_ODEBody0->createAABBCollisionDetector(m_toolRadius); m_ODEBody0->buildContactConvexTriangles(0.001); m_ODEBody0->setMass(0.02); m_ODEBody0->estimateInertia(); m_ODEBody0->buildDynamicModel(); m_ODEBody0->setLocalPos(0.0, 0.0, 0.2); // initialize init(); }; //=========================================================================== /*! Set stiffness of environment \param a_stiffness Stiffness value [N/m] */ //=========================================================================== void cDemo4::setStiffness(double a_stiffness) { // set ground m_ground->setStiffness(a_stiffness, true); // set objects m_ODEBody0->setStiffness(a_stiffness); m_ODEBase0->setStiffness(a_stiffness); }; //=========================================================================== /*! Initialize position of objects */ //=========================================================================== void cDemo4::init() { m_ODEBody0->setLocalPos(0.04,-0.05, 0.04); }
/* Copyright (c) 2009-2014 Stanford University * Copyright (c) 2015 Diego Ongaro * Copyright (c) 2015 Scale Computing * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * * Some of this code is copied from RAMCloud src/Common.cc _generateRandom(), * Copyright (c) 2009-2014 Stanford University also under the same ISC license. */ #include <cassert> #include <cmath> #include <cstring> #include <fcntl.h> #include <limits> #include <mutex> #include <pthread.h> #include <sys/stat.h> #include <unistd.h> #include "../Core/Debug.h" #include "../Core/Random.h" namespace LogCabin { namespace Core { namespace Random { // forward declaration void acquireMutex(); void releaseMutex(); namespace { // forward declaration void resetRandomState(); /** * Keeps state needed by the random number generator, protected by a mutex. */ class RandomState { public: RandomState() : mutex() , init(false) , statebuf() , randbuf() { reset(); int err = pthread_atfork(LogCabin::Core::Random::acquireMutex, LogCabin::Core::Random::releaseMutex, resetRandomState); if (err != 0) { // too early to call ERROR in here fprintf(stderr, "Failed to set up pthread_atfork() handler to " "reset random number generator seed in child processes. " "As a result, child processes will generate the same " "sequence of random values as the parent they were forked " "from. Error: %s\n", strerror(err)); } } void reset() { std::lock_guard<std::mutex> lockGuard(mutex); int fd = open("/dev/urandom", O_RDONLY); if (fd < 0) { // too early to call PANIC in here fprintf(stderr, "Couldn't open /dev/urandom: %s\n", strerror(errno)); abort(); } unsigned int seed; ssize_t bytesRead = read(fd, &seed, sizeof(seed)); close(fd); if (bytesRead != sizeof(seed)) { // too early to call PANIC in here fprintf(stderr, "Couldn't read full seed from /dev/urandom\n"); abort(); } initstate_r(seed, statebuf, STATE_BYTES, &randbuf); static_assert(RAND_MAX >= (1L << 30), "RAND_MAX too small"); init = true; } uint64_t random64() { std::lock_guard<std::mutex> lockGuard(mutex); if (!init) { // probably too early to call PANIC in here fprintf(stderr, "Looks like you hit the so-called static " "initialization order fiasco in Core::Random\n"); abort(); } // Each call to random returns 31 bits of randomness, // so we need three to get 64 bits of randomness. int32_t lo, mid, hi; random_r(&randbuf, &lo); random_r(&randbuf, &mid); random_r(&randbuf, &hi); uint64_t r = (((uint64_t(hi) & 0x7FFFFFFF) << 33) | // NOLINT ((uint64_t(mid) & 0x7FFFFFFF) << 2) | // NOLINT (uint64_t(lo) & 0x00000003)); // NOLINT return r; } friend void LogCabin::Core::Random::acquireMutex(); friend void LogCabin::Core::Random::releaseMutex(); private: /** * Protect following members from concurrent access. */ std::mutex mutex; /** * Set to true when the constructor completes. */ bool init; /** * Size of 'statebuf'. 128 is the same size as initstate() uses for regular * random(), see manpages for details. */ enum { STATE_BYTES = 128 }; /** * Internal scratch state used by random_r. */ char statebuf[STATE_BYTES]; /** * random_r's state. Must be handed to each call, and seems to refer to * statebuf in some undocumented way. */ random_data randbuf; } randomState; /** * Called in child after fork() to reset random seed. */ void resetRandomState() { // we will have grabbed the mutex in pthread_atfork prepare, need // to release here releaseMutex(); randomState.reset(); } /** * Fill a variable of type T with some random bytes. */ template<typename T> T getRandomBytes() { T buf {}; size_t offset = 0; while (offset < sizeof(buf)) { uint64_t r = randomState.random64(); size_t copy = std::min(sizeof(r), sizeof(buf) - offset); memcpy(reinterpret_cast<char*>(&buf) + offset, &r, copy); offset += copy; } return buf; } /// Return a random number between 0 and 1. double randomUnit() { return (double(random64()) / double(std::numeric_limits<uint64_t>::max())); } } // anonymous namespace /** * Called before fork() to grab the mutex used in pthread_atfork. This * function is outside of the anonymous namespace so it can be called * from RandomTest. */ void acquireMutex() { randomState.mutex.lock(); } /** * Called in the parent post fork(). This function is outside of the * anonymous namespace so it can be called from RandomTest. */ void releaseMutex() { randomState.mutex.unlock(); } uint8_t random8() { return getRandomBytes<uint8_t>(); } uint16_t random16() { return getRandomBytes<uint16_t>(); } uint32_t random32() { return getRandomBytes<uint32_t>(); } uint64_t random64() { return randomState.random64(); } double randomRangeDouble(double start, double end) { return start + randomUnit() * (end - start); } uint64_t randomRange(uint64_t start, uint64_t end) { return uint64_t(lround(randomRangeDouble(double(start), double(end)))); } } // namespace LogCabin::Core::Random } // namespace LogCabin::Core } // namespace LogCabin
; A131895: a(n) = (n + 2)*(5*n + 1)/2. ; 1,9,22,40,63,91,124,162,205,253,306,364,427,495,568,646,729,817,910,1008,1111,1219,1332,1450,1573,1701,1834,1972,2115,2263,2416,2574,2737,2905,3078,3256,3439,3627,3820,4018,4221,4429,4642,4860,5083,5311,5544 mul $0,5 add $0,6 bin $0,2 div $0,5 sub $0,2
; void w_array_clear_fastcall(w_array_t *a) SECTION code_adt_w_array PUBLIC _w_array_clear_fastcall defc _w_array_clear_fastcall = asm_w_array_clear INCLUDE "adt/w_array/z80/asm_w_array_clear.asm"
; ::: include #ruledef test { ld {x} => { assert(x < 0x10) 0x55 @ x`8 } } ; ::: ld 0x5 ; = 0x5505 ; ::: ld -0x20 ; = 0x55e0 ; ::: ld 0x15 ; error: failed to resolve ; ::: ld var ; = 0x5505 var = 0x5 ; ::: ld var ; error: failed to resolve var = 0x15
; A133695: a(n) = 2*A008683 - 1. ; 1,-3,-3,-1,-3,1,-3,-1,-1,1,-3,-1,-3,1,1,-1,-3,-1,-3,-1,1,1,-3,-1,-1,1,-1,-1,-3,-3,-3,-1,1,1,1,-1,-3,1,1,-1,-3,-3,-3,-1,-1,1,-3,-1,-1,-1,1,-1,-3,-1,1,-1,1,1,-3,-1,-3,1,-1,-1,1,-3,-3,-1,1,-3,-3,-1,-3,1,-1,-1 seq $0,8683 ; Möbius (or Moebius) function mu(n). mu(1) = 1; mu(n) = (-1)^k if n is the product of k different primes; otherwise mu(n) = 0. mul $0,2 sub $0,1
#include "GAMER.h" //------------------------------------------------------------------------------------------------------- // Function : Aux_Record_CorrUnphy // Description : Record the number of cells with unphysical results and are corrected by Flu_Close()->CorrectUnphysical() // // Note : 1. These cells are corrected by either "OPT__1ST_FLUX_CORR" or "MIN_DENS/PRES" // 2. The number of corrected cells is recorded in NCorrUnphy in the file "Flu_Close.cpp" // 3. The total number of cell updates recorded here for the individual time-step integration is // only approximate since the number of patches at each level may change during one global time-step //------------------------------------------------------------------------------------------------------- void Aux_Record_CorrUnphy() { const char FileName[] = "Record__NCorrUnphy"; static bool FirstTime = true; long NCorrAllRank[NLEVEL]; FILE *File = NULL; // collect data from all ranks MPI_Reduce( NCorrUnphy, NCorrAllRank, NLEVEL, MPI_LONG, MPI_SUM, 0, MPI_COMM_WORLD ); // only rank 0 needs to take a note if ( MPI_Rank == 0 ) { // header if ( FirstTime ) { if ( Aux_CheckFileExist(FileName) ) Aux_Message( stderr, "WARNING : file \"%s\" already exists !!\n", FileName ); FirstTime = false; File = fopen( FileName, "a" ); fprintf( File, "#%13s %9s %10s", "Time", "Step", "NCorrAllLv" ); for (int lv=0; lv<NLEVEL; lv++) fprintf( File, "%16s %2d ", "Level", lv ); fprintf( File, "\n" ); fclose( File ); } // count the total number of cells and cell updates long NCorrAllLv=0, NUpdate; double Frac; for (int lv=0; lv<NLEVEL; lv++) NCorrAllLv += NCorrAllRank[lv]; File = fopen( FileName, "a" ); fprintf( File, "%14.7e %9ld %10ld", Time[0], Step, NCorrAllLv ); for (int lv=0; lv<NLEVEL; lv++) { NUpdate = amr->NUpdateLv[lv]*NPatchTotal[lv]*CUBE( PATCH_SIZE ); if ( NUpdate == 0 ) Frac = 0.0; else Frac = 100.0 * NCorrAllRank[lv] / NUpdate; fprintf( File, " %8ld(%8.2e%%)", NCorrAllRank[lv], Frac ); } fprintf( File, "\n" ); fclose( File ); } // if ( MPI_Rank == 0 ) // reset the counter for (int lv=0; lv<NLEVEL; lv++) NCorrUnphy[lv] = 0; } // FUNCTION : Aux_Record_CorrUnphy
section .rodata ; Base | Flags | Limit | Access | Base ; 31 24 | 3 0 | 19 16 | 7 0 | 23 16 ; Base | Limit ; 15 0 | 15 0 ; # Access byte ; 7 | 6 5 | 4 | 3 | 2 | 1 | 0 ; P | DPL | S | E | DC | RW | A ; P: Present bit. Allows an entry to refer to a valid segment. Must be set (1) ; for any valid segment. ; DPL: Descriptor privilege level field. Contains the CPU Privilege level of the ; segment. ; 0 = highest privilege (kernel), 3 = lowest privilege (user applications). ; S: Descriptor type bit. ; If clear (0) the descriptor defines a system segment (eg. a Task State ; Segment). ; If set (1) it defines a code or data segment. ; E: Executable bit. ; If clear (0) the descriptor defines a data segment. ; If set (1) it defines a code segment which can be executed from. ; DC: Direction bit/Conforming bit. ; For data selectors: Direction bit. ; If clear (0) the segment grows up. ; If set (1) the segment grows down, ie. the Offset has to be greater ; than the Limit. ; For code selectors: Conforming bit. ; If clear (0) code in this segment can only be executed from the ring ; set in Privl. ; If set (1) code in this segment can be executed from an equal or lower ; privilege level. For example, code in ring 3 can far-jump to conforming ; code in a ring 2 segment. The Privl field represent the highest ; privilege level that is allowed to execute the segment. For example, ; code in ring 0 cannot far-jump to a conforming code segment where Privl ; is 2, while code in ring 2 and 3 can. Note that the privilege level ; remains the same, ie. a far-jump from ring 3 to a segment with a Privl ; of 2 remains in ring 3 after the jump. ; RW: Readable bit/Writable bit. ; For code segments: Readable bit. If clear (0), read access for this segment ; is not allowed. If set (1) read access is allowed. Write access is never ; allowed for code segments. ; For data segments: Writeable bit. If clear (0), write access for this ; segment is not allowed. If set (1) write access is allowed. Read access is ; always allowed for data segments. ; A: Accessed bit. Best left clear (0), the CPU will set it when the segment is ; accessed. ; Flags ; 3 | 2 | 1 | 0 ; G | DB | L | Reserved ; G: Granularity flag, indicates the size the Limit value is scaled by. ; If clear (0), the Limit is in 1 Byte blocks (byte granularity). ; If set (1), the Limit is in 4 KiB blocks (page granularity). ; DB: Size flag. ; If clear (0), the descriptor defines a 16-bit protected mode segment. ; If set (1) it defines a 32-bit protected mode segment. A GDT can have both 16-bit and 32-bit selectors at once. ; L: Long-mode code flag. ; If set (1), the descriptor defines a 64-bit code segment. When set, Sz should always be clear. ; For any other type of segment (other code types or any data segment), it should be clear (0). ; 0x08 .code ; 0x10 .data ; 0x18 .user_data ; 0x20 .user_code ; 0x28 .tss gdt64: dq 0 ; Zero entry .code: equ $ - gdt64 ; Limit dw 0xffff ; Base dw 0x0000 ; Base (mid) db 0x00 ; Access ; present, dpl=0, descriptor, execute, readable db 10011010b ; Flags & limit ; Long mode, granularity ; 0b1010_1111 == (1 << 5) | (1 << 7) | 0x0f db 10101111b ; Base (high) db 0x00 .data: equ $ - gdt64 ; Limit dw 0xffff ; Base dw 0x0000 ; Base (mid) db 0x00 ; Access ; Present, dpl=0, descriptor, writable db 10010010b ; Flags & limit ; Long mode, granularity ; 0b1010_1111 == (1 << 5) | (1 << 7) | 0x0f db 10101111b ; Base (high) db 0x00 .user_data: equ $ - gdt64 ; Limit dw 0xffff ; Base dw 0x0000 ; Base (mid) db 0x00 ; Access ; Present, dpl=3, writeable db 0xf2 ; Flags & limit ; Long mode, granularity db 10101111b ; Base (high) db 0x00 .user_code: equ $ - gdt64 ; Limit dw 0xffff ; Base dw 0x0000 ; Base (mid) db 0x00 ; Access ; Present, dpl=3, execute, readable db 0xfa ; Flags & limit ; Long mode, granularity db 10101111b ; Base (high) db 0x00 .tss: equ $ - gdt64 ; Limit dw 0x67 ; Sizeof tss64 ; Base dw (tss64 - $$ + MULTIBOOT_ORG + 0x30) & 0xffff ; Base (mid) db ((tss64 - $$ + MULTIBOOT_ORG + 0x30) >> 16) & 0xff ; Access ; Present | TSS (0x9) ; ; "In most systems, the DPLs of TSS descriptors are set to values less than 3, ; so that only privileged software can perform task switching. However, in ; multitasking applications, DPLs for some TSS descriptors may be set to 3 to ; allow task switching at the application (or user) privilege level." ; db 10001001b ; Flags & limit db 00000000b ; Base high db ((tss64 - $$ + MULTIBOOT_ORG + 0x30) >> 24) & 0xff ; Base highest dd ((tss64 - $$ + MULTIBOOT_ORG + 0x30) >> 32) ; Reserved dd 0 .pointer: dw $ - gdt64 - 1 dq gdt64 tss64: dd 0 ; Reserved .rsp0 dq STACK_TOP .rsp1 dq 0 .rsp2 dq 0 dq 0 ; Reserved .ist1 dq 0 .ist2 dq 0 .ist3 dq 0 .ist4 dq 0 .ist5 dq 0 .ist6 dq 0 .ist7 dq 0 dq 0 ; Reserved dw 0 ; Reserved .iopb dw 0 ; no IOPB global init_long_mode section .text bits 32 init_long_mode: ; ebx contains the 32-bit physical address of the Multiboot2 information ; structure provided by the boot loader. mov esp, temp_stack_top push ebx call set_up_page_tables call map_kernel_stack call map_frame_buffer call enable_paging lgdt [gdt64.pointer] ; Load the TSS mov ax, gdt64.tss ltr ax jmp gdt64.code:long_mode_start bits 64 long_mode_start: ; Clear the interrupt flag. cli ; Kernel respects write protection. mov rax, cr0 or rax, CR0_WRITE_PROTECT mov cr0, rax ; Reset registers for sanity. mov rax, 0 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax mov rbx, gdt64.data mov ds, rbx mov rbx, 0 mov rcx, 0 mov rdi, 0 ; Fetch that multiboot structure, before we use our new fresh stack. pop rdi ; Set our kernel stack. mov rsp, STACK_TOP call main ; A hint that we have escaped the kernel. mov rax, 0xdeadbeef jmp $ %include "src/boot/paging.asm"
origin $0005CBA6 text_menu: gameMenu($06, "WEAPON ") gameMenu($05, "ITEMS ") gameMenu($06, "STATUS ") gameMenu($03, "MAP ") gameMenu($04, "SAVE ") gameMenu($03, "OK? ") status_menu: gameStatusMenu($04, $0E, $08, "RANK") gameStatusMenu($03, $0E, $0A, "H.P") gameStatusMenu($01, $16, $0A, "/") gameStatusMenu($03, $0E, $0C, "S.P") gameStatusMenu($01, $16, $0C, "/") gameStatusMenu($04, $0E, $0E, "KILL") origin $5CC04 status_menu_vars: gameStatusMenuVar($03, $17, $08) gameStatusMenuVar($03, $13, $0A) gameStatusMenuVar($03, $17, $0A) gameStatusMenuVar($03, $13, $0C) gameStatusMenuVar($03, $17, $0C) gameStatusMenuVar($05, $15, $0E) origin $3ED48 sound_menu: gameSoundMenu("TESTE SONORO") sound_menu_bgm: gameSoundMenu("BGM") sound_menu_sfx: gameSoundMenu("SFX") sound_menu_pcm: gameSoundMenu("PCM") sound_menu_exit: gameSoundMenu("SAIR")
; vars.asm ; Copyright 2020 Robin Verhagen-Guest ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ; Application SavedArgs: dw 0 SavedArgsLen dw 0 SavedStackPrint: dw $0000 IsNext: ds 0 ArgBuffer: ds 256 WantsHelp: ds 1 Force: ds 1 Progress: ds 16 ; 15 chars with terminating null CRbeforeErr: ds 1 ; Zero = no CR, Non-zero = CR ; UART Prescaler: ds 3 Dummy32: ds 4 ; ESP eFuses: eFuse1: ds 4 eFuse2: ds 4 eFuse3: ds 4 eFuse4: ds 4 MAC0: ds 4 MAC1: ds 4 MAC3: ds 4 MAC: OUI1: ds 1 OUI2: ds 1 OUI3: ds 1 OUI4: ds 1 OUI5: ds 1 OUI6: ds 1 FlashFreq: ds 1 FlashParams: ds 2 FWVersion: ds 11 ; 10 chars with terminating null FWMD5: ds 16 ; 16 bytes (binary not hex string) GotMD5: ds 16 ; MDS we got back from the ESP DataBlockSize: ds 2 FWCompLen: ds 4 FWCompLenStr: ds 11 HeaderBlockSize: ds 2 ; MSB is always zero BlockCount: ds 2 BlockHeaderStart: ds 2 TimeoutBackup: ds 2 InProgMode: ds 1 ; Features Features proc Is8285: ds 1 EmbFlash: ds 1 pend ; Files FWFileName: ds 256 ; Filename buffer to load firmware from HasFWFileName: ds 1
.class while:Obj .method $constructor .local x,y enter load x const 10 load x const 10 store x jump labelwhilecmp0 labelwhilebody1: load y const 0 load y const 0 store y jump labelwhilecmp2 labelwhilebody3: load y load y const 1 roll 1 call Int:plus load y load y const 1 roll 1 call Int:plus store y load y call Int:print labelwhilecmp2: load y const 3 call Int:greater jump_if labelwhilebody3 endlabelwhilecmp2: load x load x const 1 roll 1 call Int:minus load x load x const 1 roll 1 call Int:minus store x load x call Int:print labelwhilecmp0: load x const 1 call Int:less_eq jump_if labelwhilebody1 endlabelwhilecmp0: return 0
; CON2 16 bit Send characters to CONSOLE V2.01  1999 Tony Tebby ; 2016 Marcel Kilgus ; ; 2016-04-16 2.01 Added alpha blending (MK) section con xdef cn_sbyte xdef cn_smulc xref cn_cksize_p xref cn_donl xref bm_apixel include 'dev8_keys_con' include 'dev8_keys_k' include 'dev8_keys_err' include 'dev8_mac_assert' ;+++ ; Send a byte ; ; d1 c p byte to send ; a0 c p CDB ; a3 c p linkage ; ; status return standard ;--- cn_sbyte cnsb.reg reg d1/a1 movem.l cnsb.reg,-(sp) cmp.b #k.nl,d0 ; newline beq.s cnsb_nl ; ... yes lea 3(sp),a1 ; ... no, cheat moveq #0,d1 moveq #1,d2 bsr.s cn_smulc movem.l (sp)+,cnsb.reg rts cnsb_nl bclr #sd..gmod,sd_cattr(a0) ; ... newline, not graphic mode now tas sd_nlsta(a0) ; set pending nl bpl.s cnsb_exit ; there was not one before jsr cn_donl ; ... oh yes there was move.b #$80,sd_nlsta(a0) ; and still is cnsb_exit movem.l (sp)+,cnsb.reg rts cnsm_rtok moveq #0,d0 rts ;+++ ; Send multiple bytes ; ; d1 c u bytes sent so far ; d2 c s bytes to send ; a0 c p CDB ; a1 c u pointer to characters ; a3 c p linkage ; ; status return standard ;--- cn_smulc cnsm.reg reg a3/a6 sub.w d1,d2 ; count ble.s cnsm_rtok ; nothing to print, so quit movem.l cnsm.reg,-(sp) sub.w d1,a1 move.l a1,-(sp) ; start of buffer add.w d1,a1 move.w d2,-(sp) subq.l #6,sp ; number to get this time + screen base stk_base equ $00 stk_slice equ $04 stk_count equ $06 tst.b sd_sflag(a0) ; check if we can fit in bpl.s cnsm_do jsr cn_cksize_p ; re-check the size blo.l cnsm_orng ; ... oops cnsm_do move.w sd_linel(a0),a2 ; will be modified for print mode sub.w #12,a2 ; standard print mode moveq #$ff-1<<sd..gmod-1<<sd..flsh,d0 ; ignore graphics and flash bit and.b sd_cattr(a0),d0 cmp.b #$ff,sd_alpha(a0) beq.s cnsm_noalpha ori.b #1<<sd..flsh,d0 ; we abuse the flash bit for alpha here cnsm_noalpha add.w d0,d0 lea cnsm_optab,a5 ; operation table add.w (a5,d0.w),a5 ; ... operation ; loop slicing up string cnsm_sloop cmp.b #k.nl,(a1) ; new line? bne.s cnsm_doch ; ... no ; newline character found cnsm_fnl bclr #sd..gmod,sd_cattr(a0) ; ... yes, not graphic mode now tas sd_nlsta(a0) ; ... yes bpl.s cnsm_enl ; there was not one before jsr cn_donl ; ... oh yes there was move.b #$80,sd_nlsta(a0) ; and there still is cnsm_enl addq.l #1,a1 subq.w #1,stk_count(sp) ; one fewer to go bgt.s cnsm_sloop bra.l cnsm_finished ; process real characters in string cnsm_doch tst.b sd_nlsta(a0) ; pending newline? beq.s cnsm_count ; ... no, count characters on this line blt.s cnsm_donl ; ... yes genuine assert sd..gmod,7 tst.b sd_cattr(a0) ; graphic mode? bpl.s cnsm_donl ; ... no, do newline cnsm_lnl cmp.b #k.nl,(a1)+ ; look for newline beq.s cnsm_egraph subq.w #1,stk_count(sp) bgt.s cnsm_lnl bra.l cnsm_finished ; no newline found cnsm_egraph subq.l #1,a1 ; backspace to nl bra.s cnsm_fnl ; and carry on cnsm_donl jsr cn_donl ; do newline ; first count how many fit in cnsm_count move.w sd_xpos(a0),d0 move.w d0,d1 move.w sd_xinc(a0),d2 move.w sd_xsize(a0),d3 move.w stk_count(sp),d4 move.w d4,d5 move.l a1,a3 moveq #k.nl,d6 cnsm_cnt cmp.b (a3)+,d6 ; next is newline beq.s cnsm_scnt add.w d2,d1 cmp.w d3,d1 ; off edge yet? bgt.s cnsm_seol ; ... yes subq.w #1,d4 ; one more gone bge.s cnsm_cnt ; ... not all gone yet moveq #0,d4 ; all gone bra.s cnsm_scnt cnsm_seol move.b #1,sd_nlsta(a0) ; newline required cnsm_scnt move.w d4,stk_count(sp) ; number left to go sub.w d4,d5 ; number to go beq.s cnsm_more ; back to beginning of slicing loop move.w d5,stk_slice(sp) ; number in this slice assert sd.sfout,1 tst.b sd_sflag(a0) ; out of window? beq.s cnsm_scolour ; ... no add.w d5,a1 ; ... yes, skip these cnsm_more tst.w stk_count(sp) ; any more characters? bgt.l cnsm_sloop bra.l cnsm_finished ; set up colours cnsm_scolour movem.l sd_smask(a0),d5/d7 ; set colour contrast main ; ; d4 c p strip colour mask first pixel (second row, first row) ; d5 c p strip colour mask next pixel ; d6 c p ink colour mask first pixel ; d7 c p ink colour mask next pixel ; move.l d5,d4 ; assume strip colour is solid move.w #%11111000,d0 and.b sd_scolr(a0),d0 beq.s cnsm_icolr lsr.w #6,d0 add.w d0,d0 move.w cnsm_stable(pc,d0.w),d0 jmp cnsm_stable(pc,d0.w) cnsm_stable dc.w cnsms_1of4-cnsm_stable dc.w cnsms_horiz-cnsm_stable dc.w cnsms_vert-cnsm_stable dc.w cnsms_check-cnsm_stable cnsms_1of4 swap d5 move.w d5,d4 ; first column is solid swap d5 bra.s cnsm_icolr cnsms_vert swap d5 ; odd column is contrast move.w d4,d0 move.w d5,d4 ; in both lines move.w d0,d5 bra.s cnsm_icolr cnsms_horiz swap d4 ; even column is different cnsms_check swap d5 ; odd column is different cnsm_icolr move.l d7,d6 ; assume ink colour is solid move.w #%11111000,d0 and.b sd_icolr(a0),d0 beq.s cnsm_colrset lsr.w #6,d0 add.w d0,d0 move.w cnsm_itable(pc,d0.w),d0 jmp cnsm_itable(pc,d0.w) cnsm_itable dc.w cnsmi_1of4-cnsm_itable dc.w cnsmi_horiz-cnsm_itable dc.w cnsmi_vert-cnsm_itable dc.w cnsmi_check-cnsm_itable cnsmi_1of4 swap d7 move.w d7,d6 ; first column is solid swap d7 bra.s cnsm_colrset cnsmi_vert swap d7 ; odd column is contrast move.w d6,d0 move.w d7,d6 ; in both lines move.w d0,d7 bra.s cnsm_colrset cnsmi_horiz swap d6 ; even column is different cnsmi_check swap d7 ; odd column is different cnsm_colrset ; set row address cnsm_srow move.w sd_linel(a0),d2 move.w sd_ymin(a0),d1 add.w sd_ypos(a0),d1 mulu d1,d2 ; row start in screen add.l sd_scrb(a0),d2 move.l d2,stk_base(sp) ; veritable row address move.w sd_xmin(a0),d0 ; area origin add.w sd_xpos(a0),d0 ; cursor origin cnsm_colrpos btst #0,d0 beq.s cnsm_colry exg d4,d5 exg d6,d7 ; odd pixel cnsm_colry lsr.w #1,d1 bcc.s cnsm_colrdone swap d4 swap d5 swap d6 ; odd row swap d7 cnsm_colrdone ; now do a slice move.w stk_slice(sp),d1 cnsm_cloop move.l stk_base(sp),a4 move.w d1,-(sp) move.w d0,-(sp) add.w d0,d0 add.w d0,a4 ; screen address moveq #0,d1 move.b (a1)+,d1 ; next character move.l sd_font(a0),a3 ; base fount sub.b (a3)+,d1 ; offset in fount table blo.s cnsm_f2 ; ... off bottom cmp.b (a3)+,d1 ; top bls.s cnsm_fset ; ... ok subq.l #1,a3 cnsm_f2 add.b -(a3),d1 move.l sd_font+4(a0),a3 ; second fount sub.b (a3)+,d1 ; offset in fount table blo.s cnsm_f2z ; ... off bottom cmp.b (a3),d1 ; top bls.s cnsm_fs2 ; ... ok cnsm_f2z moveq #0,d1 ; ... no, use bottom cnsm_fs2 addq.l #1,a3 cnsm_fset add.w d1,a3 lsl.w #3,d1 add.w d1,a3 ; at last, the fount pointer jmp (a5) ; screen address, fount and colours set cnsm_next move.w (sp)+,d0 move.w (sp)+,d1 move.w sd_xinc(a0),d2 add.w d2,d0 ; new x pos lsr.w #1,d2 bcc.s cnsm_ecloop exg d4,d5 exg d6,d7 ; odd/even pixel cnsm_ecloop subq.w #1,d1 ; one more gone bgt.s cnsm_cloop sub.w sd_xmin(a0),d0 move.w d0,sd_xpos(a0) tst.w stk_count(sp) ; any more characters? bgt.l cnsm_sloop cnsm_finished moveq #0,d0 ; ... ok cnsm_exit addq.l #stk_count+2,sp ; remove frame from stack move.l a1,d1 ; set character count sub.l (sp)+,d1 movem.l (sp)+,cnsm.reg tst.l d0 rts cnsm_orng moveq #err.orng,d0 bra.s cnsm_exit page ; table of character operations cnsm_optab . dc.w cc_stdch-.,cc_stdul-.,cc_alpch-.,cc_alpul-. dc.w cc_ovrch-.,cc_ovrul-.,cc_alpch-.,cc_alpul-. dc.w cc_xorch-.,cc_xorul-.,cc_xorch-.,cc_xorul-. dc.w cc_xorch-.,cc_xorul-.,cc_xorch-.,cc_xorul-. dc.w ch_stdch-.,ch_stdul-.,ch_alpch-.,ch_alpul-. dc.w ch_ovrch-.,ch_ovrul-.,ch_alpch-.,ch_alpul-. dc.w ch_xorch-.,ch_xorul-.,ch_xorch-.,ch_xorul-. dc.w ch_xorch-.,ch_xorul-.,ch_xorch-.,ch_xorul-. dc.w cc_stdcx-.,cc_stdux-.,cc_alpcx-.,cc_alpux-. dc.w cc_ovrcx-.,cc_ovrux-.,cc_alpcx-.,cc_alpux-. dc.w cc_xorcx-.,cc_xorux-.,cc_xorcx-.,cc_xorux-. dc.w cc_xorcx-.,cc_xorux-.,cc_xorcx-.,cc_xorux-. dc.w ch_stdcx-.,ch_stdux-.,ch_alpcx-.,ch_alpux-. dc.w ch_ovrcx-.,ch_ovrux-.,ch_alpcx-.,ch_alpux-. dc.w ch_xorcx-.,ch_xorux-.,ch_xorcx-.,ch_xorux-. dc.w ch_xorcx-.,ch_xorux-.,ch_xorcx-.,ch_xorux-. dc.w cw_stdch-.,cw_stdul-.,cw_alpch-.,cw_alpul-. dc.w cw_ovrch-.,cw_ovrul-.,cw_alpch-.,cw_alpul-. dc.w cw_xorch-.,cw_xorul-.,cw_xorch-.,cw_xorul-. dc.w cw_xorch-.,cw_xorul-.,cw_xorch-.,cw_xorul-. dc.w cz_stdch-.,cz_stdul-.,cz_alpch-.,cz_alpul-. dc.w cz_ovrch-.,cz_ovrul-.,cz_alpch-.,cz_alpul-. dc.w cz_xorch-.,cz_xorul-.,cz_xorch-.,cz_xorul-. dc.w cz_xorch-.,cz_xorul-.,cz_xorch-.,cz_xorul-. dc.w cw_stdcx-.,cw_stdux-.,cw_alpcx-.,cw_alpux-. dc.w cw_ovrcx-.,cw_ovrux-.,cw_alpcx-.,cw_alpux-. dc.w cw_xorcx-.,cw_xorux-.,cw_xorcx-.,cw_xorux-. dc.w cw_xorcx-.,cw_xorux-.,cw_xorcx-.,cw_xorux-. dc.w cz_stdcx-.,cz_stdux-.,cz_alpcx-.,cz_alpux-. dc.w cz_ovrcx-.,cz_ovrux-.,cz_alpcx-.,cz_alpux-. dc.w cz_xorcx-.,cz_xorux-.,cz_xorcx-.,cz_xorux-. dc.w cz_xorcx-.,cz_xorux-.,cz_xorcx-.,cz_xorux-. page ;+++ ; General character drawing code ; ; d4 c p strip colour mask first pixel (second row, first row) ; d5 c p strip colour mask next pixel ; d6 c p ink colour mask first pixel ; d7 c p ink colour mask next pixel ; a2 c u line increment ; a3 cs pointer to fount patterns for this character ; a4 cs pointer to screen ; a5 cr pointer to character code ;--- ;+++ ; Standard size underline character drawing code ;--- cc_stdul move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_stdc1 ;+++ ; Standard size / attribute character drawing code ;--- cc_stdch moveq #8,d1 ; nine rows cc_stdc1 move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ swap d4 swap d5 swap d6 swap d7 cc_stdll add.l a2,a4 move.b (a3)+,d2 add.b d2,d2 bcc.s cc_stdpap0 move.w d6,(a4)+ ; ink point bra.s cc_stdpx1 cc_stdpap0 move.w d4,(a4)+ ; paper point cc_stdpx1 add.b d2,d2 bcc.s cc_stdpap1 move.w d7,(a4)+ ; ink point bra.s cc_stdpx2 cc_stdpap1 move.w d5,(a4)+ ; paper point cc_stdpx2 add.b d2,d2 bcc.s cc_stdpap2 move.w d6,(a4)+ ; ink point bra.s cc_stdpx3 cc_stdpap2 move.w d4,(a4)+ ; paper point cc_stdpx3 add.b d2,d2 bcc.s cc_stdpap3 move.w d7,(a4)+ ; ink point bra.s cc_stdpx4 cc_stdpap3 move.w d5,(a4)+ ; paper point cc_stdpx4 add.b d2,d2 bcc.s cc_stdpap4 move.w d6,(a4)+ ; ink point bra.s cc_stdpx5 cc_stdpap4 move.w d4,(a4)+ ; paper point cc_stdpx5 add.b d2,d2 bcc.s cc_stdpap5 move.w d7,(a4)+ ; ink point bra.s cc_stdls cc_stdpap5 move.w d5,(a4)+ ; paper point cc_stdls swap d4 swap d5 swap d6 swap d7 dbra d1,cc_stdll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_stdls ;+++ ; Standard size underline extended character drawing code ;--- cc_stdux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_stdx ;+++ ; Standard size extended character drawing code ;--- cc_stdcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #8,d1 ; one + nine rows cc_stdx moveq #3,d0 cc_stdxbl move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ dbra d0,cc_stdxbl swap d4 swap d5 swap d6 swap d7 cc_stdxll add.l a2,a4 move.b (a3)+,d2 moveq #3,d0 cc_stdxpl add.b d2,d2 bcs.s cc_stdxink0 move.w d4,(a4)+ ; paper point add.b d2,d2 bcs.s cc_stdxink1 move.w d5,(a4)+ ; paper point dbra d0,cc_stdxpl bra.s cc_stdxls cc_stdxink0 move.w d6,(a4)+ ; ink point add.b d2,d2 bcs.s cc_stdxink1 move.w d5,(a4)+ ; paper point dbra d0,cc_stdxpl bra.s cc_stdxls cc_stdxink1 move.w d7,(a4)+ ; ink point dbra d0,cc_stdxpl cc_stdxls swap d4 swap d5 swap d6 swap d7 dbra d1,cc_stdxll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 moveq #3,d0 cc_stdxull move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ dbra d0,cc_stdxull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_stdxls ;+++ ; Double width underline character drawing code ;--- cw_stdul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #5,d3 bra.s cw_std ;+++ ; Double width character drawing code ;--- cw_stdch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #5,d3 bra.s cw_std ;+++ ; Double width underline extended character drawing code ;--- cw_stdux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #7,d3 bra.s cw_std ;+++ ; Double width extended character drawing code ;--- cw_stdcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #7,d3 cw_std move.w d3,d0 cw_stdbl move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ dbra d0,cw_stdbl swap d4 swap d5 swap d6 swap d7 cw_stdll add.l a2,a4 move.b (a3)+,d2 move.w d3,d0 cw_stdpl add.b d2,d2 bcc.s cw_stdpap move.w d6,(a4)+ ; ink point move.w d7,(a4)+ ; ink point dbra d0,cw_stdpl bra.s cw_stdls cw_stdpap move.w d4,(a4)+ ; paper point move.w d5,(a4)+ ; paper point dbra d0,cw_stdpl cw_stdls swap d4 swap d5 swap d6 swap d7 dbra d1,cw_stdll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d3,d0 cw_stdull move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ dbra d0,cw_stdull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cw_stdls ;+++ ; Double height underline character drawing code ;--- ch_stdul move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #2,d3 bra.s ch_std ;+++ ; Double height character drawing code ;--- ch_stdch moveq #$11,d1 ; eighteen rows move.w #2,d3 bra.s ch_std ;+++ ; Double height underline extended character drawing code ;--- ch_stdux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #3,d3 bra.s ch_std ;+++ ; Double height extended character drawing code ;--- ch_stdcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #3,d3 ch_std move.w d3,d0 ch_stdbl move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ dbra d0,ch_stdbl swap d4 swap d5 swap d6 swap d7 add.l a2,a4 move.w d3,d0 ch_stdbl1 move.w d4,(a4)+ ; the second blank line move.w d5,(a4)+ dbra d0,ch_stdbl1 swap d4 swap d5 swap d6 swap d7 ch_stdll move.b (a3)+,d2 ch_stdllu add.l a2,a4 move.w d3,d0 ch_stdpl add.b d2,d2 bcs.s ch_stdink0 move.w d4,(a4)+ ; paper point add.b d2,d2 bcs.s ch_stdink1 move.w d5,(a4)+ ; paper point dbra d0,ch_stdpl bra.s ch_stdls ch_stdink0 move.w d6,(a4)+ ; ink point add.b d2,d2 bcs.s ch_stdink1 move.w d5,(a4)+ ; paper point dbra d0,ch_stdpl bra.s ch_stdls ch_stdink1 move.w d7,(a4)+ ; ink point dbra d0,ch_stdpl ch_stdls swap d4 swap d5 swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s ch_stdle ; ... no subq.l #1,a3 ; yes backspace ch_stdle dbra d1,ch_stdll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s ch_stdllu ; genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s ch_stdll ;+++ ; Double size underline character drawing code ;--- cz_stdul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #5,d3 bra.s cz_std ;+++ ; Double size character drawing code ;--- cz_stdch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #5,d3 bra.s cz_std ;+++ ; Double size underline extended character drawing code ;--- cz_stdux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #7,d3 bra.s cz_std ;+++ ; Double size extended character drawing code ;--- cz_stdcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #7,d3 cz_std move.w d3,d0 cz_stdbl move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ dbra d0,cz_stdbl swap d4 swap d5 swap d6 swap d7 add.l a2,a4 move.w d3,d0 cz_stdbl1 move.w d4,(a4)+ ; the blank line move.w d5,(a4)+ dbra d0,cz_stdbl1 swap d4 swap d5 swap d6 swap d7 cz_stdll move.b (a3)+,d2 cz_stdllu add.l a2,a4 move.w d3,d0 cz_stdpl add.b d2,d2 bcc.s cz_stdpap move.w d6,(a4)+ ; ink point move.w d7,(a4)+ ; ink point dbra d0,cz_stdpl bra.s cz_stdls cz_stdpap move.w d4,(a4)+ ; paper point move.w d5,(a4)+ ; paper point dbra d0,cz_stdpl cz_stdls swap d4 swap d5 swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s cz_stdle ; ... no subq.l #1,a3 ; yes backspace cz_stdle dbra d1,cz_stdll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s cz_stdllu ; ... genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s cz_stdll ;+++ ; Standard size over underline character drawing code ;--- cc_ovrul move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_ovrc1 ;+++ ; Standard size over character drawing code ;--- cc_ovrch moveq #8,d1 ; nine rows cc_ovrc1 swap d6 swap d7 add.w #12,a4 cc_ovrll add.l a2,a4 move.b (a3)+,d2 bne.s cc_ovrpx add.w #12,a4 ; blank line bra.s cc_ovrls cc_ovrpx add.b d2,d2 bcc.s cc_ovrpap0 move.w d6,(a4) ; ink point cc_ovrpap0 addq.l #2,a4 cc_ovrpx1 add.b d2,d2 bcc.s cc_ovrpap1 move.w d7,(a4) ; ink point cc_ovrpap1 addq.l #2,a4 cc_ovrpx2 add.b d2,d2 bcc.s cc_ovrpap2 move.w d6,(a4) ; ink point cc_ovrpap2 addq.l #2,a4 cc_ovrpx3 add.b d2,d2 bcc.s cc_ovrpap3 move.w d7,(a4) ; ink point cc_ovrpap3 addq.l #2,a4 cc_ovrpx4 add.b d2,d2 bcc.s cc_ovrpap4 move.w d6,(a4) ; ink point cc_ovrpap4 addq.l #2,a4 cc_ovrpx5 add.b d2,d2 bcc.s cc_ovrpap5 move.w d7,(a4) ; ink point cc_ovrpap5 addq.l #2,a4 cc_ovrls swap d6 swap d7 dbra d1,cc_ovrll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_ovrls ;+++ ; Standard size over underline extended character drawing code ;--- cc_ovrux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_ovrx ;+++ ; Standard size over extended character drawing code ;--- cc_ovrcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #8,d1 ; one + nine rows cc_ovrx swap d6 swap d7 add.w #16,a4 cc_ovrxll add.l a2,a4 move.b (a3)+,d2 bne.s cc_ovrxpx add.w #16,a4 ; blank line bra.s cc_ovrxls cc_ovrxpx moveq #3,d0 cc_ovrxpl add.b d2,d2 bcc.s cc_ovrxpap0 move.w d6,(a4) ; ink point cc_ovrxpap0 addq.l #2,a4 add.b d2,d2 bcc.s cc_ovrxpap1 move.w d7,(a4) ; ink point cc_ovrxpap1 addq.l #2,a4 dbra d0,cc_ovrxpl cc_ovrxls swap d6 swap d7 dbra d1,cc_ovrxll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 moveq #3,d0 cc_ovrxull move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ dbra d0,cc_ovrxull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_ovrxls ;+++ ; Double width over underline character drawing code ;--- cw_ovrul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #5,d3 bra.s cw_ovr ;+++ ; Double width over character drawing code ;--- cw_ovrch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #5,d3 bra.s cw_ovr ;+++ ; Double width over underline extended character drawing code ;--- cw_ovrux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #7,d3 bra.s cw_ovr ;+++ ; Double width over extended character drawing code ;--- cw_ovrcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #7,d3 cw_ovr swap d6 swap d7 move.w d3,d0 addq.w #1,d0 lsl.w #2,d0 add.w d0,a4 ; skip line cw_ovrll add.l a2,a4 move.b (a3)+,d2 bne.s cw_ovrpx move.w d3,d0 addq.w #1,d0 lsl.w #2,d0 add.w d0,a4 ; blank line bra.s cw_ovrls cw_ovrpx move.w d3,d0 cw_ovrpl add.b d2,d2 bcc.s cw_ovrpap move.w d6,(a4)+ ; ink point move.w d7,(a4)+ ; ink point dbra d0,cw_ovrpl bra.s cw_ovrls cw_ovrpap addq.l #4,a4 dbra d0,cw_ovrpl cw_ovrls swap d6 swap d7 dbra d1,cw_ovrll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d3,d0 cw_ovrull move.w d6,(a4)+ ; the underscore move.w d7,(a4)+ dbra d0,cw_ovrull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cw_ovrls ;+++ ; Double height over underline character drawing code ;--- ch_ovrul move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #2,d3 bra.s ch_ovr ;+++ ; Double height over character drawing code ;--- ch_ovrch moveq #$11,d1 ; eighteen rows move.w #2,d3 bra.s ch_ovr ;+++ ; Double height over underline extended character drawing code ;--- ch_ovrux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #3,d3 bra.s ch_ovr ;+++ ; Double height over extended character drawing code ;--- ch_ovrcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #3,d3 ch_ovr move.w d3,d0 ; skip two lines addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 ch_ovrll move.b (a3)+,d2 bne.s ch_ovrpx move.w d3,d0 ; two blank lines addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 add.l a2,a4 subq.w #1,d1 bra.s ch_ovrle ch_ovrpx ch_ovrllu add.l a2,a4 move.w d3,d0 ch_ovrpl add.b d2,d2 bcc.s ch_ovrpap0 move.w d6,(a4) ; ink point ch_ovrpap0 addq.l #2,a4 add.b d2,d2 bcc.s ch_ovrpap1 move.w d7,(a4) ; ink point ch_ovrpap1 addq.l #2,a4 dbra d0,ch_ovrpl ch_ovrls swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s ch_ovrle ; ... no subq.l #1,a3 ; yes backspace ch_ovrle dbra d1,ch_ovrll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s ch_ovrllu ; genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s ch_ovrll ;+++ ; Double size over underline character drawing code ;--- cz_ovrul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #5,d3 bra.s cz_ovr ;+++ ; Double size over character drawing code ;--- cz_ovrch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #5,d3 bra.s cz_ovr ;+++ ; Double size over underline extended character drawing code ;--- cz_ovrux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #7,d3 bra.s cz_ovr ;+++ ; Double size over extended character drawing code ;--- cz_ovrcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #7,d3 cz_ovr move.w d3,d0 addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 cz_ovrll move.b (a3)+,d2 bne.s cz_ovrpx move.w d3,d0 addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 add.l a2,a4 subq.w #1,d1 bra.s cz_ovrle cz_ovrpx cz_ovrllu add.l a2,a4 move.w d3,d0 cz_ovrpl add.b d2,d2 bcc.s cz_ovrpap move.w d6,(a4)+ ; ink point move.w d7,(a4)+ ; ink point dbra d0,cz_ovrpl bra.s cz_ovrls cz_ovrpap addq.l #4,a4 dbra d0,cz_ovrpl cz_ovrls swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s cz_ovrle ; ... no subq.l #1,a3 ; yes backspace cz_ovrle dbra d1,cz_ovrll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s cz_ovrllu ; ... genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s cz_ovrll ;+++ ; Standard size xor underline character drawing code ;--- cc_xorul move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_xorc1 ;+++ ; Standard size xor character drawing code ;--- cc_xorch moveq #8,d1 ; nine rows cc_xorc1 swap d6 swap d7 add.w #12,a4 cc_xorll add.l a2,a4 move.b (a3)+,d2 bne.s cc_xorpx add.w #12,a4 ; blank line bra.s cc_xorls cc_xorpx add.b d2,d2 bcc.s cc_xorpap0 eor.w d6,(a4) ; ink point cc_xorpap0 addq.l #2,a4 cc_xorpx1 add.b d2,d2 bcc.s cc_xorpap1 eor.w d7,(a4) ; ink point cc_xorpap1 addq.l #2,a4 cc_xorpx2 add.b d2,d2 bcc.s cc_xorpap2 eor.w d6,(a4) ; ink point cc_xorpap2 addq.l #2,a4 cc_xorpx3 add.b d2,d2 bcc.s cc_xorpap3 eor.w d7,(a4) ; ink point cc_xorpap3 addq.l #2,a4 cc_xorpx4 add.b d2,d2 bcc.s cc_xorpap4 eor.w d6,(a4) ; ink point cc_xorpap4 addq.l #2,a4 cc_xorpx5 add.b d2,d2 bcc.s cc_xorpap5 eor.w d7,(a4) ; ink point cc_xorpap5 addq.l #2,a4 cc_xorls swap d6 swap d7 dbra d1,cc_xorll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 eor.w d6,(a4)+ ; the underscore eor.w d7,(a4)+ eor.w d6,(a4)+ ; the underscore eor.w d7,(a4)+ eor.w d6,(a4)+ ; the underscore eor.w d7,(a4)+ moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_xorls ;+++ ; Standard size xor underline extended character drawing code ;--- cc_xorux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_xorx ;+++ ; Standard size xor extended character drawing code ;--- cc_xorcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #8,d1 ; one + nine rows cc_xorx swap d6 swap d7 add.w #16,a4 cc_xorxll add.l a2,a4 move.b (a3)+,d2 bne.s cc_xorxpx add.w #16,a4 ; blank line bra.s cc_xorxls cc_xorxpx moveq #3,d0 cc_xorxpl add.b d2,d2 bcc.s cc_xorxpap0 eor.w d6,(a4) ; ink point cc_xorxpap0 addq.l #2,a4 add.b d2,d2 bcc.s cc_xorxpap1 eor.w d7,(a4) ; ink point cc_xorxpap1 addq.l #2,a4 dbra d0,cc_xorxpl cc_xorxls swap d6 swap d7 dbra d1,cc_xorxll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 moveq #3,d0 cc_xorxull eor.w d6,(a4)+ ; the underscore eor.w d7,(a4)+ dbra d0,cc_xorxull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_xorxls ;+++ ; Double width xor underline character drawing code ;--- cw_xorul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #5,d3 bra.s cw_xor ;+++ ; Double width xor character drawing code ;--- cw_xorch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #5,d3 bra.s cw_xor ;+++ ; Double width xor underline extended character drawing code ;--- cw_xorux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #7,d3 bra.s cw_xor ;+++ ; Double width xor extended character drawing code ;--- cw_xorcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #7,d3 cw_xor swap d6 swap d7 move.w d3,d0 addq.w #1,d0 lsl.w #2,d0 add.w d0,a4 ; skip line cw_xorll add.l a2,a4 move.b (a3)+,d2 bne.s cw_xorpx move.w d3,d0 addq.w #1,d0 lsl.w #2,d0 add.w d0,a4 ; blank line bra.s cw_xorls cw_xorpx move.w d3,d0 cw_xorpl add.b d2,d2 bcc.s cw_xorpap eor.w d6,(a4)+ ; ink point eor.w d7,(a4)+ ; ink point dbra d0,cw_xorpl bra.s cw_xorls cw_xorpap addq.l #4,a4 dbra d0,cw_xorpl cw_xorls swap d6 swap d7 dbra d1,cw_xorll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d3,d0 cw_xorull eor.w d6,(a4)+ ; the underscore eor.w d7,(a4)+ dbra d0,cw_xorull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cw_xorls ;+++ ; Double height xor underline character drawing code ;--- ch_xorul move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #2,d3 bra.s ch_xor ;+++ ; Double height xor character drawing code ;--- ch_xorch moveq #$11,d1 ; eighteen rows move.w #2,d3 bra.s ch_xor ;+++ ; Double height xor underline extended character drawing code ;--- ch_xorux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #3,d3 bra.s ch_xor ;+++ ; Double height xor extended character drawing code ;--- ch_xorcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #3,d3 ch_xor move.w d3,d0 ; skip two lines addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 ch_xorll move.b (a3)+,d2 bne.s ch_xorpx move.w d3,d0 ; two blank lines addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 add.l a2,a4 subq.w #1,d1 bra.s ch_xorle ch_xorpx ch_xorllu add.l a2,a4 move.w d3,d0 ch_xorpl add.b d2,d2 bcc.s ch_xorpap0 eor.w d6,(a4) ; ink point ch_xorpap0 addq.l #2,a4 add.b d2,d2 bcc.s ch_xorpap1 eor.w d7,(a4) ; ink point ch_xorpap1 addq.l #2,a4 dbra d0,ch_xorpl ch_xorls swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s ch_xorle ; ... no subq.l #1,a3 ; yes backspace ch_xorle dbra d1,ch_xorll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s ch_xorllu ; genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s ch_xorll ;+++ ; Double size xor underline character drawing code ;--- cz_xorul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #5,d3 bra.s cz_xor ;+++ ; Double size xor character drawing code ;--- cz_xorch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #5,d3 bra.s cz_xor ;+++ ; Double size xor underline extended character drawing code ;--- cz_xorux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #7,d3 bra.s cz_xor ;+++ ; Double size xor extended character drawing code ;--- cz_xorcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #7,d3 cz_xor move.w d3,d0 addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 cz_xorll move.b (a3)+,d2 bne.s cz_xorpx move.w d3,d0 addq.w #1,d0 lsl.w #3,d0 add.w d0,a4 add.l a2,a4 add.l a2,a4 subq.w #1,d1 bra.s cz_xorle cz_xorpx cz_xorllu add.l a2,a4 move.w d3,d0 cz_xorpl add.b d2,d2 bcc.s cz_xorpap eor.w d6,(a4)+ ; ink point eor.w d7,(a4)+ ; ink point dbra d0,cz_xorpl bra.s cz_xorls cz_xorpap addq.l #4,a4 dbra d0,cz_xorpl cz_xorls swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s cz_xorle ; ... no subq.l #1,a3 ; yes backspace cz_xorle dbra d1,cz_xorll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s cz_xorllu ; ... genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s cz_xorll pp.reg reg d0-d7/a1 pp.d4 equ 16 pp.d5 equ 20 pp.d6 equ 24 pp.d7 equ 28 ; Put background colour d4 put_pixel_d4 btst #sd..over,sd_cattr(a0) bne.s pp_rts ; OVER mode, don't draw background movem.l pp.reg,-(sp) pp_all move.b sd_alpha(a0),d5 move.l a4,a1 jsr bm_apixel movem.l (sp)+,pp.reg pp_rts addq.w #2,a4 rts ; Put background colour d5 put_pixel_d5 btst #sd..over,sd_cattr(a0) bne.s pp_rts ; OVER mode, don't draw background movem.l pp.reg,-(sp) move.w d5,d4 bra.s pp_all ; Put ink colour d6 put_pixel_d6 movem.l pp.reg,-(sp) move.w d6,d4 bra.s pp_all ; Put ink colour d7 put_pixel_d7 movem.l pp.reg,-(sp) move.w d7,d4 bra.s pp_all ;+++ ; Standard size (over) underline alpha character drawing code ;--- cc_alpul move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_alpc1 ;+++ ; Standard size / attribute (over) alpha character drawing code ;--- cc_alpch moveq #8,d1 ; nine rows cc_alpc1 bsr.s put_pixel_d4 ; paper ink bsr.s put_pixel_d5 bsr.s put_pixel_d4 bsr.s put_pixel_d5 bsr.s put_pixel_d4 bsr.s put_pixel_d5 swap d4 swap d5 swap d6 swap d7 cc_alpll add.l a2,a4 move.b (a3)+,d2 moveq #2,d3 cc_alppxl add.b d2,d2 bcc.s cc_alppap0 bsr put_pixel_d6 ; ink point bra.s cc_alppx1 cc_alppap0 bsr put_pixel_d4 ; paper point cc_alppx1 add.b d2,d2 bcc.s cc_alppap1 bsr put_pixel_d7 ; ink point bra.s cc_alppx2 cc_alppap1 bsr put_pixel_d5 ; paper point cc_alppx2 dbf d3,cc_alppxl cc_alpls swap d4 swap d5 swap d6 swap d7 dbra d1,cc_alpll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 bsr.s put_pixel_d6 ; the underscore bsr.s put_pixel_d7 bsr.s put_pixel_d6 bsr.s put_pixel_d7 bsr.s put_pixel_d6 bsr.s put_pixel_d7 moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_alpls ;+++ ; Standard size (over) underline extended alpha character drawing code ;--- cc_alpux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows bra.s cc_alpx ;+++ ; Standard size (over) extended alpha character drawing code ;--- cc_alpcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #8,d1 ; one + nine rows cc_alpx moveq #3,d0 cc_alpxbl bsr put_pixel_d4 ; the blank line bsr put_pixel_d5 dbra d0,cc_alpxbl swap d4 swap d5 swap d6 swap d7 cc_alpxll add.l a2,a4 move.b (a3)+,d2 moveq #3,d0 cc_alpxpl add.b d2,d2 bcs.s cc_alpxink0 bsr put_pixel_d4 ; paper point add.b d2,d2 bcs.s cc_alpxink1 bsr put_pixel_d5 ; paper point dbra d0,cc_alpxpl bra.s cc_alpxls cc_alpxink0 bsr put_pixel_d6 ; ink point add.b d2,d2 bcs.s cc_alpxink1 bsr put_pixel_d5 ; paper point dbra d0,cc_alpxpl bra.s cc_alpxls cc_alpxink1 bsr put_pixel_d7 ; ink point dbra d0,cc_alpxpl cc_alpxls swap d4 swap d5 swap d6 swap d7 dbra d1,cc_alpxll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 moveq #3,d0 cc_alpxull bsr put_pixel_d6 ; the underscore bsr put_pixel_d7 dbra d0,cc_alpxull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cc_alpxls ;+++ ; Double width (over) underline character drawing code ;--- cw_alpul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #5,d3 bra.s cw_alp ;+++ ; Double width (over) character drawing code ;--- cw_alpch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #5,d3 bra.s cw_alp ;+++ ; Double width (over) underline extended character drawing code ;--- cw_alpux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$ffff0006,d1 ; one + seven + two rows move.w #7,d3 bra.s cw_alp ;+++ ; Double width (over) extended character drawing code ;--- cw_alpcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #8,d1 ; one + nine rows move.w #7,d3 cw_alp move.w d3,d0 cw_alpbl bsr put_pixel_d4 ; the blank line bsr put_pixel_d5 dbra d0,cw_alpbl swap d4 swap d5 swap d6 swap d7 cw_alpll add.l a2,a4 move.b (a3)+,d2 move.w d3,d0 cw_alppl add.b d2,d2 bcc.s cw_alppap bsr put_pixel_d6 ; ink point bsr put_pixel_d7 ; ink point dbra d0,cw_alppl bra.s cw_alpls cw_alppap bsr put_pixel_d4 ; paper point bsr put_pixel_d5 ; paper point dbra d0,cw_alppl cw_alpls swap d4 swap d5 swap d6 swap d7 dbra d1,cw_alpll tst.l d1 ; underscore? bpl cnsm_next ; ... no add.l a2,a4 move.w d3,d0 cw_alpull bsr put_pixel_d6 ; the underscore bsr put_pixel_d7 dbra d0,cw_alpull moveq #1,d1 addq.l #1,a3 ; skip font line bra.s cw_alpls ;+++ ; Double height underline character drawing code ;--- ch_alpul move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #2,d3 bra.s ch_alp ;+++ ; Double height (over) character drawing code ;--- ch_alpch moveq #$11,d1 ; eighteen rows move.w #2,d3 bra.s ch_alp ;+++ ; Double height (over) underline extended character drawing code ;--- ch_alpux subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #3,d3 bra.s ch_alp ;+++ ; Double height (over) extended character drawing code ;--- ch_alpcx subq.l #4,a2 ; reduce increment addq.l #4,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #3,d3 ch_alp move.w d3,d0 ch_alpbl bsr put_pixel_d4 ; the blank line bsr put_pixel_d5 dbra d0,ch_alpbl swap d4 swap d5 swap d6 swap d7 add.l a2,a4 move.w d3,d0 ch_alpbl1 bsr put_pixel_d4 ; the second blank line bsr put_pixel_d5 dbra d0,ch_alpbl1 swap d4 swap d5 swap d6 swap d7 ch_alpll move.b (a3)+,d2 ch_alpllu add.l a2,a4 move.w d3,d0 ch_alppl add.b d2,d2 bcs.s ch_alpink0 bsr put_pixel_d4 ; paper point add.b d2,d2 bcs.s ch_alpink1 bsr put_pixel_d5 ; paper point dbra d0,ch_alppl bra.s ch_alpls ch_alpink0 bsr put_pixel_d6 ; ink point add.b d2,d2 bcs.s ch_alpink1 bsr put_pixel_d5 ; paper point dbra d0,ch_alppl bra.s ch_alpls ch_alpink1 bsr put_pixel_d7 ; ink point dbra d0,ch_alppl ch_alpls swap d4 swap d5 swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s ch_alple ; ... no subq.l #1,a3 ; yes backspace ch_alple dbra d1,ch_alpll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s ch_alpllu ; genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s ch_alpll ;+++ ; Double size (over) underline character drawing code ;--- cz_alpul sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #5,d3 bra.s cz_alp ;+++ ; Double size (over) character drawing code ;--- cz_alpch sub.w #12,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #5,d3 bra.s cz_alp ;+++ ; Double size (over) underline extended character drawing code ;--- cz_alpux sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry move.l #$fffd000d,d1 ; two + fourteen + four rows move.w #7,d3 bra.s cz_alp ;+++ ; Double size (over) extended character drawing code ;--- cz_alpcx sub.w #20,a2 ; reduce increment addq.l #6,a5 ; and move entry moveq #$11,d1 ; eighteen rows move.w #7,d3 cz_alp move.w d3,d0 cz_alpbl bsr put_pixel_d4 ; the blank line bsr put_pixel_d5 dbra d0,cz_alpbl swap d4 swap d5 swap d6 swap d7 add.l a2,a4 move.w d3,d0 cz_alpbl1 bsr put_pixel_d4 ; the blank line bsr put_pixel_d5 dbra d0,cz_alpbl1 swap d4 swap d5 swap d6 swap d7 cz_alpll move.b (a3)+,d2 cz_alpllu add.l a2,a4 move.w d3,d0 cz_alppl add.b d2,d2 bcc.s cz_alppap bsr put_pixel_d6 ; ink point bsr put_pixel_d7 ; ink point dbra d0,cz_alppl bra.s cz_alpls cz_alppap bsr put_pixel_d4 ; paper point bsr put_pixel_d5 ; paper point dbra d0,cz_alppl cz_alpls swap d4 swap d5 swap d6 swap d7 btst #0,d1 ; first line of pair? beq.s cz_alple ; ... no subq.l #1,a3 ; yes backspace cz_alple dbra d1,cz_alpll tst.l d1 ; underscore? bpl cnsm_next ; ... no moveq #-1,d2 addq.l #1,d1 ; ... yes bne.s cz_alpllu ; ... genuine addq.l #1,a3 ; skip font line moveq #1,d1 bra.s cz_alpll end
; A178744: Partial sums of floor(4^n/9). ; Submitted by Jamie Morken(s1.) ; 0,0,1,8,36,149,604,2424,9705,38832,155340,621373,2485508,9942048,39768209,159072856,636291444,2545165797,10180663212,40722652872,162890611513,651562446080,2606249784348,10424999137421,41699996549716,166799986198896,667199944795617,2668799779182504,10675199116730052,42700796466920245,170803185867681020,683212743470724120,2732850973882896521,10931403895531586128,43725615582126344556,174902462328505378269,699609849314021513124,2798439397256086052544,11193757589024344210225,44775030356097376840952 mul $0,2 mov $1,-2 pow $1,$0 mul $1,2 div $1,3 sub $1,$0 mov $0,$1 mul $0,2 div $0,9
; A014616: a(n) = solution to the postage stamp problem with 2 denominations and n stamps. ; 2,4,7,10,14,18,23,28,34,40,47,54,62,70,79,88,98,108,119,130,142,154,167,180,194,208,223,238,254,270,287,304,322,340,359,378,398,418,439,460,482,504,527,550,574,598,623,648,674,700,727,754,782,810,839,868,898,928,959,990,1022,1054,1087,1120,1154,1188,1223,1258,1294,1330,1367,1404,1442,1480,1519,1558,1598,1638,1679,1720,1762,1804,1847,1890,1934,1978,2023,2068,2114,2160,2207,2254,2302,2350,2399,2448,2498,2548,2599,2650 mov $1,8 add $1,$0 mul $1,$0 div $1,4 add $1,2 mov $0,$1
db 0 ; species ID placeholder db 30, 105, 90, 50, 25, 25 ; hp atk def spd sat sdf db WATER, WATER ; type db 225 ; catch rate db 115 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F0 ; gender ratio db 100 ; unknown 1 db 20 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/krabby/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_FAST ; growth rate dn EGG_WATER_3, EGG_WATER_3 ; egg groups ; tm/hm learnset tmhm CURSE, TOXIC, ROCK_SMASH, HIDDEN_POWER, SNORE, BLIZZARD, ICY_WIND, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, RETURN, MUD_SLAP, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, REST, ATTRACT, THIEF, FURY_CUTTER, CUT, SURF, STRENGTH, WHIRLPOOL, ICE_BEAM ; end
; A344050: a(n) = Sum_{k=0..n} (-1)^(n-k)*binomial(n, k)*|Lah(n, k)|. Inverse binomial convolution of the unsigned Lah numbers A271703. ; Submitted by Christian Krause ; 1,1,-3,1,73,-699,3001,24697,-783999,10946233,-80958779,-656003919,40097528857,-944102982419,14449693290033,-81180376526759,-4110744092532479,203618771909117937,-5868277577182238579,117997016943575159713,-1055340561026036009559,-45279878749358024400299 mov $1,1 mov $3,$0 mov $4,1 lpb $3 sub $0,1 mul $1,$3 mul $1,-1 mul $1,$3 add $5,$4 div $1,$5 mul $1,$0 add $2,$1 sub $3,1 add $4,2 lpe mov $0,$2 add $0,1
.MODEL SMALL .STACK 100H .DATA STRING DB 100 DUP(?) MSG1 DB "ENTER A STRING: $" MSG2 DB 0DH, 0AH, "NO. OF VOWELS_FOUNDS: $" VOWELS DW 0 .CODE MAIN PROC MOV AX, @DATA MOV DS, AX MOV ES, AX MOV AH, 9 LEA DX, MSG1 INT 21H LEA DI, STRING MOV AH, 1 READ: INT 21H CMP AL, 0DH JE ENDOFSTRING STOSB JMP READ ENDOFSTRING: MOV AL, "$" STOSB XOR BX, BX COUNT: MOV AL, STRING[BX] CMP AL, "$" JE EXIT CMP AL, "a" JE VOWEL_FOUND CMP AL, "e" JE VOWEL_FOUND CMP AL, "i" JE VOWEL_FOUND CMP AL, "o" JE VOWEL_FOUND CMP AL, "u" JE VOWEL_FOUND CMP AL, "A" JE VOWEL_FOUND CMP AL, "E" JE VOWEL_FOUND CMP AL, "I" JE VOWEL_FOUND CMP AL, "O" JE VOWEL_FOUND CMP AL, "U" JE VOWEL_FOUND INC BX JMP COUNT VOWEL_FOUND: MOV CX, VOWELS INC CX MOV VOWELS, CX INC BX JMP COUNT EXIT: MOV AH, 9 LEA DX, MSG2 INT 21H MOV AH, 2 MOV DX, VOWELS ADD DX, 30H INT 21H MAIN ENDP END MAIN
/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_forms.hxx" #include "unohelper.hxx" #include <osl/diagnose.h> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/XInterface.hpp> #include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/beans/Property.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <unotools/processfactory.hxx> using com::sun::star::uno::Reference; using com::sun::star::uno::Sequence; using com::sun::star::uno::Exception; using com::sun::star::uno::XInterface; using com::sun::star::lang::XMultiServiceFactory; using com::sun::star::beans::Property; using com::sun::star::beans::XPropertySet; using com::sun::star::beans::XPropertySetInfo; using com::sun::star::beans::PropertyAttribute::READONLY; using rtl::OUString; Reference<XInterface> xforms::createInstance( const OUString& sServiceName ) { Reference<XMultiServiceFactory> xFactory = utl::getProcessServiceFactory(); OSL_ENSURE( xFactory.is(), "can't get service factory" ); Reference<XInterface> xInstance = xFactory->createInstance( sServiceName ); OSL_ENSURE( xInstance.is(), "failed to create instance" ); return xInstance; } void xforms::copy( const Reference<XPropertySet>& xFrom, Reference<XPropertySet>& xTo ) { OSL_ENSURE( xFrom.is(), "no source" ); OSL_ENSURE( xTo.is(), "no target" ); // get property names & infos, and iterate over target properties Sequence<Property> aProperties = xTo->getPropertySetInfo()->getProperties(); sal_Int32 nProperties = aProperties.getLength(); const Property* pProperties = aProperties.getConstArray(); Reference<XPropertySetInfo> xFromInfo = xFrom->getPropertySetInfo(); for( sal_Int32 n = 0; n < nProperties; n++ ) { const OUString& rName = pProperties[n].Name; // if both set have the property, copy the value // (catch and ignore exceptions, if any) if( xFromInfo->hasPropertyByName( rName ) ) { try { Property aProperty = xFromInfo->getPropertyByName( rName ); if ( ( aProperty.Attributes & READONLY ) == 0 ) xTo->setPropertyValue(rName, xFrom->getPropertyValue( rName )); } catch( const Exception& ) { // ignore any errors; we'll copy as good as we can } } // else: no property? then ignore. } }
Music_OreburghCity: channel_count 4 channel 1, Music_OreburghCity_Ch1 channel 2, Music_OreburghCity_Ch2 channel 3, Music_OreburghCity_Ch3 channel 4, Music_OreburghCity_Ch4 Music_OreburghCity_Ch1_sub_0: octave 3 note G_, 3 note G_, 1 note E_, 3 note E_, 1 note G_, 2 note G_, 1 note A#, 2 note G_, 1 note E_, 1 note F_, 1 octave 4 note C_, 3 note C_, 1 octave 3 note A_, 3 note A_, 1 note F_, 2 note F_, 1 note D_, 2 note D_, 1 octave 2 note A#, 1 sound_ret Music_OreburghCity_Ch1_sub_1: octave 4 note C_, 1 octave 3 note F#, 1 note G_, 1 octave 4 note C_, 1 octave 3 sound_ret Music_OreburghCity_Ch1:: tempo 226 duty_cycle 3 vibrato 8, 1, 5 stereo_panning TRUE, FALSE .loop pitch_offset 0 note_type 12, 11, 5 sound_call Music_OreburghCity_Ch1_sub_0 note B_, 1 sound_call Music_OreburghCity_Ch1_sub_0 octave 3 note D_, 1 note_type 12, 11, 2 note C#, 1 note D_, 1 note F#, 1 note D_, 2 note A_, 1 note F#, 1 note D_, 1 note F#, 1 note G_, 1 note B_, 1 note G_, 2 octave 4 note D#, 1 octave 3 note B_, 1 note G_, 1 octave 2 note B_, 1 octave 3 note C_, 1 note E_, 1 note C_, 2 note G_, 1 note E_, 1 note C_, 1 note C_, 1 note C#, 1 note F_, 1 note C#, 2 note G#, 1 note B_, 1 note C#, 1 octave 4 note D_, 3 note D_, 3 note G_, 4 note G_, 3 note G_, 3 note E_, 2 note C_, 2 octave 3 note G_, 1 note E_, 2 note A_, 1 note A#, 1 note A#, 1 note A_, 1 note A_, 1 note G#, 1 note G#, 1 note G_, 1 note G_, 1 note_type 12, 11, 3 note D#, 1 note E_, 2 note E_, 1 octave 2 note B_, 1 octave 3 note C_, 2 note C_, 1 note D_, 1 note D#, 2 note D#, 1 octave 2 note B_, 1 octave 3 note C_, 2 note C_, 1 note F#, 1 note G_, 2 note G_, 3 note G_, 1 note A_, 2 note A#, 1 note F#, 1 note G_, 1 note D#, 1 note E_, 1 note C_, 1 note C#, 2 note E_, 1 octave 2 note B_, 1 octave 3 note C_, 1 octave 2 note G#, 1 note A_, 1 note E_, 1 note F_, 1 octave 3 note D#, 2 note D#, 1 note C_, 2 note D#, 1 note C_, 2 note_type 12, 11, 2 pitch_offset 2 note D#, 1 note E_, 2 note D#, 1 note E_, 1 octave 2 note B_, 1 octave 3 note C_, 1 octave 2 note G_, 1 note F#, 1 note G_, 1 octave 3 note C_, 1 octave 2 note F#, 1 note G_, 1 octave 3 note C_, 1 octave 2 note F#, 1 note G_, 1 octave 3 note F#, 1 note G_, 2 note F#, 1 note G_, 1 note B_, 1 sound_call Music_OreburghCity_Ch1_sub_1 note F#, 1 note G_, 1 sound_call Music_OreburghCity_Ch1_sub_1 note G#, 1 note A_, 1 octave 4 note C_, 1 octave 3 note G#, 1 note A_, 1 octave 4 note C_, 1 octave 3 note G#, 1 note A_, 1 octave 4 note C_, 1 note C_, 1 octave 3 note E_, 1 note F_, 1 note A_, 1 note C_, 1 note E_, 1 note F_, 2 octave 2 note A#, 1 note A#, 2 note A#, 1 note A#, 2 note A#, 1 octave 3 note D#, 2 note D#, 1 note D#, 2 note D#, 1 note D#, 1 note D#, 1 sound_loop 0, .loop Music_OreburghCity_Ch2_sub_0: note C_, 2 octave 4 note A_, 3 note G_, 3 note C_, 2 note D#, 2 note D_, 2 note C_, 1 sound_ret Music_OreburghCity_Ch2:: duty_cycle 3 vibrato 16, 3, 6 stereo_panning FALSE, TRUE .loop note_type 12, 12, 5 octave 4 note C_, 3 note G_, 3 note D_, 2 note E_, 2 note F_, 2 note G_, 2 octave 5 sound_call Music_OreburghCity_Ch2_sub_0 note D_, 3 note C_, 3 note G_, 3 note D_, 2 note E_, 2 note G_, 2 octave 5 note D_, 2 sound_call Music_OreburghCity_Ch2_sub_0 note G#, 3 note_type 12, 12, 2 note G_, 3 note G_, 3 note F#, 4 note F_, 2 note F_, 4 note E_, 3 note E_, 3 note E_, 4 note F_, 2 note F_, 4 note G_, 3 note G_, 3 octave 5 note C_, 4 note D_, 3 note C_, 3 octave 4 note A#, 2 note A_, 2 note G_, 1 note C_, 2 note D_, 1 note E_, 1 note E_, 1 note D#, 1 note D#, 1 note D_, 1 note D_, 1 note C#, 1 note C#, 1 note_type 12, 12, 5 note C_, 3 octave 3 note A_, 3 octave 4 note C_, 2 note D_, 2 note C_, 2 note D#, 1 note C_, 3 note E_, 3 note D#, 3 note E_, 2 note A#, 2 note A_, 2 note G#, 1 note A_, 3 note E_, 3 octave 3 note A_, 3 octave 4 note C_, 2 note D#, 2 note C_, 2 note D_, 1 note C_, 3 note_type 12, 12, 3 note C_, 2 note C_, 2 note D_, 1 note C_, 3 octave 3 note G_, 1 octave 4 note C_, 1 note D_, 1 note C_, 5 note E_, 2 note E_, 2 note D#, 1 note E_, 3 octave 3 note G_, 1 octave 4 note E_, 1 note F_, 1 note E_, 2 note C_, 1 octave 3 note G_, 2 note A_, 2 note A_, 1 octave 4 note C_, 1 note D_, 1 note C_, 3 note D#, 1 note C_, 1 note D_, 1 note C_, 2 note C_, 1 note E_, 1 note F_, 1 note G_, 2 note G_, 2 octave 3 note G_, 4 octave 4 note G_, 1 note G_, 2 octave 3 note G_, 2 note G_, 1 note G_, 2 sound_loop 0, .loop Music_OreburghCity_Ch3_sub_0: note C_, 1 note E_, 1 note E_, 1 note G_, 1 note G_, 1 note A#, 1 note G_, 1 note E_, 1 note E_, 1 note G_, 1 note G_, 1 note A#, 1 note A#, 1 octave 3 note D_, 1 octave 2 note A#, 1 note F_, 1 note F_, 1 note A_, 1 note A_, 1 octave 3 note C_, 1 note C_, 1 note E_, 1 note C_, 1 octave 1 note A#, 1 note A#, 1 octave 2 note D_, 1 note D_, 1 note F_, 1 note F_, 1 note G#, 1 note F_, 1 sound_ret Music_OreburghCity_Ch3_sub_1: note C_, 1 rest 2 note C_, 1 note C_, 1 rest 2 note C_, 1 rest 1 note C_, 1 note C_, 1 rest 5 sound_ret Music_OreburghCity_Ch3:: note_type 12, 1, 4 .loop octave 2 note C_, 1 sound_call Music_OreburghCity_Ch3_sub_0 note C_, 1 sound_call Music_OreburghCity_Ch3_sub_0 note D_, 1 rest 2 note D_, 1 rest 2 note D_, 1 rest 3 note G_, 1 rest 1 note G_, 1 rest 3 note C_, 1 rest 2 note C_, 1 rest 2 note C_, 1 rest 3 note C#, 1 rest 1 note C#, 1 rest 4 note D_, 1 rest 1 note D_, 1 note D_, 1 rest 3 note G_, 1 rest 1 note G_, 1 note G_, 1 rest 5 note C_, 1 rest 1 note C_, 1 note C_, 1 rest 4 note G_, 1 rest 2 note A#, 1 rest 3 note F_, 1 note F_, 1 note A_, 1 note A_, 1 octave 3 note C_, 1 note C_, 1 note D_, 1 note C_, 1 octave 2 note F#, 1 note F#, 1 note A_, 1 note A_, 1 octave 3 note C_, 1 note C_, 1 note D_, 1 note C_, 1 octave 2 note G_, 1 note G_, 1 octave 3 note C_, 1 note C_, 1 note E_, 1 note E_, 1 note G_, 1 note E_, 1 octave 2 note A_, 1 note A_, 1 octave 3 note C#, 1 note C#, 1 note G_, 1 note G_, 1 note A#, 1 note G_, 1 octave 2 note D_, 1 note D_, 1 note F_, 1 note F_, 1 note A_, 1 note A_, 1 octave 3 note C_, 1 octave 2 note A_, 1 note F_, 1 note F_, 1 note A_, 1 note A_, 1 octave 3 note C_, 1 note C_, 1 note D#, 1 note C_, 1 rest 1 octave 2 sound_call Music_OreburghCity_Ch3_sub_1 sound_call Music_OreburghCity_Ch3_sub_1 note F_, 1 rest 2 note F_, 1 note F_, 1 rest 2 note F_, 1 rest 1 note F_, 1 note F_, 1 rest 5 note C_, 1 rest 2 note C_, 1 note C_, 1 rest 2 note G_, 1 rest 1 note G_, 1 note G_, 1 rest 4 sound_loop 0, .loop Music_OreburghCity_Ch4_sub_0: drum_note 2, 2 drum_note 8, 2 drum_note 2, 2 drum_note 8, 2 drum_note 2, 2 drum_note 8, 2 drum_note 2, 2 drum_note 8, 2 sound_ret Music_OreburghCity_Ch4_sub_1: drum_note 7, 2 drum_note 2, 1 drum_note 7, 2 drum_note 2, 1 drum_note 7, 2 drum_note 2, 2 drum_note 8, 2 drum_note 7, 2 drum_note 2, 2 sound_ret Music_OreburghCity_Ch4_sub_2: drum_note 2, 2 drum_note 8, 1 drum_note 7, 1 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 8, 1 drum_note 7, 1 drum_note 2, 2 drum_note 7, 2 sound_ret Music_OreburghCity_Ch4_sub_3: drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 8, 2 drum_note 7, 1 drum_note 8, 2 drum_note 7, 1 drum_note 8, 2 sound_ret Music_OreburghCity_Ch4:: toggle_noise 3 drum_speed 12 .loop sound_call Music_OreburghCity_Ch4_sub_0 sound_call Music_OreburghCity_Ch4_sub_0 sound_call Music_OreburghCity_Ch4_sub_0 sound_call Music_OreburghCity_Ch4_sub_0 sound_call Music_OreburghCity_Ch4_sub_1 sound_call Music_OreburghCity_Ch4_sub_1 drum_note 7, 2 drum_note 2, 1 drum_note 7, 2 drum_note 2, 1 drum_note 7, 2 drum_note 8, 2 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 2 drum_note 8, 1 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 drum_note 8, 1 sound_call Music_OreburghCity_Ch4_sub_2 sound_call Music_OreburghCity_Ch4_sub_2 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 7, 1 drum_note 2, 2 drum_note 2, 1 sound_call Music_OreburghCity_Ch4_sub_3 sound_call Music_OreburghCity_Ch4_sub_3 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 1 drum_note 2, 2 drum_note 2, 1 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 2, 2 drum_note 7, 2 drum_note 7, 1 drum_note 7, 1 drum_note 2, 1 drum_note 7, 2 drum_note 2, 1 drum_note 7, 1 drum_note 7, 1 sound_loop 0, .loop
; A004393: Binomial coefficient C(8n,n-12). ; 1,104,6216,280840,10668000,359933112,11143364232,323295330680,8917061687820,236236542585120,6057158960772920,151175678720167920,3689062737122341488,88326646952501966400,2080775440409128608600 mov $1,$0 add $0,12 mul $0,8 bin $0,$1
/* Sirikata * CommonOptions.cpp * * Copyright (c) 2009, Ewen Cheslack-Postava * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * Neither the name of Sirikata nor the names of its contributors may * be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <sirikata/core/options/CommonOptions.hpp> #include <sirikata/core/options/Options.hpp> #include <sirikata/core/util/Time.hpp> #include <sirikata/core/util/Timer.hpp> // daemon() method, getpid #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #elif SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX #include <sys/types.h> #include <unistd.h> #endif #include <boost/filesystem.hpp> namespace Sirikata { void ReportVersion() { bool do_version = GetOptionValue<bool>("version"); if (!do_version) return; SILOG(core,info,"Sirikata started at " << Timer::nowAsString()); SILOG(core,info,"Sirikata version " << SIRIKATA_VERSION << " (git #" << SIRIKATA_GIT_REVISION << ")"); } void InitOptions() { InitializeClassOptions::module(SIRIKATA_OPTIONS_MODULE) .addOption( reinterpret_cast<Sirikata::OptionValue*>(Sirikata_Logging_OptionValue_defaultLevel) ) .addOption( reinterpret_cast<Sirikata::OptionValue*>(Sirikata_Logging_OptionValue_atLeastLevel) ) .addOption( reinterpret_cast<Sirikata::OptionValue*>(Sirikata_Logging_OptionValue_moduleLevel) ) .addOption(new OptionValue("version","true",Sirikata::OptionValueType<bool>(),"Report version number.")) .addOption(new OptionValue(OPT_CRASHREPORT_URL,"http://crashes.sirikata.com/report",Sirikata::OptionValueType<String>(),"URL to report crashes to.")) .addOption(new OptionValue(OPT_PLUGINS,"tcpsst,servermap-tabular,core-local,graphite,core-http",Sirikata::OptionValueType<String>(),"Plugin list to load.")) .addOption(new OptionValue(OPT_EXTRA_PLUGINS,"",Sirikata::OptionValueType<String>(),"Extra list of plugins to load. Useful for using existing defaults as well as some additional plugins.")) .addOption(new OptionValue("ohstreamlib","tcpsst",Sirikata::OptionValueType<String>(),"Which library to use to communicate with the object host")) .addOption(new OptionValue("ohstreamoptions","--send-buffer-size=16384 --parallel-sockets=1 --no-delay=false",Sirikata::OptionValueType<String>(),"TCPSST stream options such as how many bytes to collect for sending during an ongoing asynchronous send call.")) .addOption(new OptionValue(OPT_SST_DEFAULT_WINDOW_SIZE,"10000",Sirikata::OptionValueType<uint32>(),"Default window (and buffer) size for SST streams.")) .addOption(new OptionValue(OPT_REGION_WEIGHT, "sqr", Sirikata::OptionValueType<String>(), "Type of region weight calculator to use, which affects communication falloff.")) .addOption(new OptionValue(OPT_REGION_WEIGHT_ARGS, "--flatness=8 --const-cutoff=64", Sirikata::OptionValueType<String>(), "Arguments to region weight calculator.")) .addOption(new OptionValue("region", "<<1,1,1>,<-1,-1,-1>>", Sirikata::OptionValueType<BoundingBox3f>(), "Simulation region")) .addOption(new OptionValue("layout", "<1,1,1>", Sirikata::OptionValueType<Vector3ui32>(), "Layout of servers in uniform grid - ixjxk servers")) .addOption(new OptionValue("max-servers", "0", Sirikata::OptionValueType<uint32>(), "Maximum number of servers available for the simulation; if set to 0, use the number of servers specified in the layout option")) .addOption(new OptionValue("duration", "0s", Sirikata::OptionValueType<Duration>(), "Duration of the simulation")) .addOption(new OptionValue("servermap", "local", Sirikata::OptionValueType<String>(), "The type of ServerIDMap to instantiate.")) .addOption(new OptionValue("servermap-options", "", Sirikata::OptionValueType<String>(), "Options to pass to the ServerIDMap constructor.")) .addOption(new OptionValue("capexcessbandwidth", "false", Sirikata::OptionValueType<bool>(), "Total bandwidth for this server in bytes per second")) .addOption(new OptionValue("rand-seed", "0", Sirikata::OptionValueType<uint32>(), "The random seed to synchronize all servers")) .addOption(new OptionValue(OPT_LOG_FILE, "", Sirikata::OptionValueType<String>(), "Filename to log SILOG messages to. If empty or -, uses stderr")) .addOption(new OptionValue(OPT_LOG_ALL_TO_FILE, "true", Sirikata::OptionValueType<bool>(), "If true and a log file is specified, redirect all output o it, including stdout and stderr, instead of just SILOG messages.")) .addOption(new OptionValue(OPT_DAEMON, "false", Sirikata::OptionValueType<bool>(), "If true, daemonize this process")) .addOption(new OptionValue(OPT_PID_FILE, "", Sirikata::OptionValueType<String>(), "Filename to write the process ID to. If empty, no pid file will be written.")) .addOption(new OptionValue(STATS_TRACE_FILE, "trace.txt", Sirikata::OptionValueType<String>(), "The filename to save the trace to")) .addOption(new OptionValue("time-server", "", Sirikata::OptionValueType<String>(), "The server to sync with")) .addOption(new OptionValue("wait-until","",Sirikata::OptionValueType<String>(),"The date to wait until before starting")) .addOption(new OptionValue("wait-additional","0s",Sirikata::OptionValueType<Duration>(),"How much additional time after date has passed to wait until before starting")) .addOption(new OptionValue("monitor-load", "false", Sirikata::OptionValueType<bool>(), "Does the LoadMonitor monitor queue sizes?")) .addOption(new OptionValue(PROFILE, "false", Sirikata::OptionValueType<bool>(), "Whether to report profiling information.")) .addOption(new OptionValue(OPT_CDN_HOST,"open3dhub.com",Sirikata::OptionValueType<String>(), "Hostname for CDN server.")) .addOption(new OptionValue(OPT_CDN_SERVICE, "http", Sirikata::OptionValueType<String>(), "Service to access CDN by.")) .addOption(new OptionValue(OPT_CDN_DNS_URI_PREFIX, "/dns", Sirikata::OptionValueType<String>(), "URI prefix for CDN HTTP name looksup.")) .addOption(new OptionValue(OPT_CDN_DOWNLOAD_URI_PREFIX, "/download", Sirikata::OptionValueType<String>(), "URI prefix for CDN HTTP downloads.")) .addOption(new OptionValue(OPT_CDN_UPLOAD_URI_PREFIX, "/api/upload", Sirikata::OptionValueType<String>(), "URI prefix for CDN HTTP uploads.")) .addOption(new OptionValue(OPT_CDN_UPLOAD_STATUS_URI_PREFIX, "/upload/processing", Sirikata::OptionValueType<String>(), "URI prefix for CDN HTTP upload status checks.")) .addOption(new OptionValue(OPT_TRACE_TIMESERIES, "null", Sirikata::OptionValueType<String>(), "Service to report TimeSeries data to.")) .addOption(new OptionValue(OPT_TRACE_TIMESERIES_OPTIONS, "", Sirikata::OptionValueType<String>(), "Options for TimeSeries reporting service.")) .addOption(new OptionValue(OPT_COMMAND_COMMANDER, "", Sirikata::OptionValueType<String>(), "Commander service to start")) .addOption(new OptionValue(OPT_COMMAND_COMMANDER_OPTIONS, "", Sirikata::OptionValueType<String>(), "Options for the Commander service")) ; } void FakeParseOptions() { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); int argc = 1; const char* argv[2] = { "bogus", NULL }; options->parse(argc, argv); } void ParseOptions(int argc, char** argv, UnregisteredOptionBehavior unreg) { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); options->parse(argc, argv, true, false, (unreg == AllowUnregisteredOptions)); } void ParseOptionsFile(const String& fname, bool required, UnregisteredOptionBehavior unreg) { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); options->parseFile(fname, required, true, false, (unreg == AllowUnregisteredOptions)); } void ParseOptions(int argc, char** argv, const String& config_file_option, UnregisteredOptionBehavior unreg) { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); // Parse command line once to make sure we have the right config // file. On this pass, use defaults so everything gets filled in. options->parse(argc, argv, true, false, (unreg == AllowUnregisteredOptions)); // Get the config file name and parse it. Don't use defaults to // avoid overwriting. String fname = GetOptionValue<String>(config_file_option.c_str()); if (!fname.empty()) options->parseFile(fname, false, false, false, (unreg == AllowUnregisteredOptions)); // And parse the command line args a second time to overwrite any settings // the config file may have overwritten. Don't use defaults to // avoid overwriting. options->parse(argc, argv, false, false, (unreg == AllowUnregisteredOptions)); } void FillMissingOptionDefaults() { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); // Parse command line once to make sure we have the right config // file. On this pass, use defaults so everything gets filled in. options->fillMissingDefaults(); } void DaemonizeAndSetOutputs() { // We only have daemon() on Unices #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX if (GetOptionValue<bool>(OPT_DAEMON)) { // We don't chdir to / because we don't have settings for getting out of // there. The user has to start the daemon in a good location. daemon(1 /* don't chdir to / */, 0 /* do redirect stdin/out/err to * /dev/null */); } #endif // Set log output { String logfile = GetOptionValue<String>(OPT_LOG_FILE); bool log_all_to_file = GetOptionValue<bool>(OPT_LOG_ALL_TO_FILE); bool changed = false; if (logfile != "" && logfile != "-") { if (log_all_to_file) { FILE* fp = fopen(logfile.c_str(), "w"); if (fp != NULL) { Sirikata::Logging::setOutputFP(fp); changed = true; } } else { // Try to open the log file std::ostream* logfs = new std::ofstream(logfile.c_str(), std::ios_base::out | std::ios_base::app); if (*logfs) { Sirikata::Logging::setLogStream(logfs); changed = true; } } } // If that failed, go back to cerr if (!changed) Sirikata::Logging::SirikataLogStream = &std::cerr; } // Write pid file if requested { String pidfile = GetOptionValue<String>(OPT_PID_FILE); if (pidfile != "") { std::ofstream pidfs(pidfile.c_str(), std::ios_base::out); if (!pidfs) { SILOG(pid, error, "Couldn't write to requested PID file: " << pidfile); } else { #if SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_MAC || SIRIKATA_PLATFORM == SIRIKATA_PLATFORM_LINUX pidfs << getpid() << std::endl; #endif } } } } void DaemonCleanup() { // Clean up the PID file if we wrote it String pidfile = GetOptionValue<String>(OPT_PID_FILE); if (pidfile == "") return; boost::filesystem::path pidpath(pidfile); if (boost::filesystem::exists(pidpath) && boost::filesystem::is_regular_file(pidpath)) boost::filesystem::remove(pidpath); } OptionValue* GetOption(const char* name) { OptionSet* options = OptionSet::getOptions(SIRIKATA_OPTIONS_MODULE,NULL); return options->referenceOption(name); } OptionValue* GetOption(const char* klass, const char* name) { OptionSet* options = OptionSet::getOptions(klass,NULL); return options->referenceOption(name); } template<typename T> T GetOptionValueUnsafe(const char* name) { OptionValue* opt = GetOption(name); return opt->unsafeAs<T>(); } #define DEFINE_UNSAFE_GETOPTIONVALUE(T) \ template<> \ T GetOptionValue<T>(const char* name) { return GetOptionValueUnsafe<T>(name); } DEFINE_UNSAFE_GETOPTIONVALUE(String) DEFINE_UNSAFE_GETOPTIONVALUE(Vector3f) DEFINE_UNSAFE_GETOPTIONVALUE(Vector3ui32) DEFINE_UNSAFE_GETOPTIONVALUE(BoundingBox3f) DEFINE_UNSAFE_GETOPTIONVALUE(ObjectHostID) DEFINE_UNSAFE_GETOPTIONVALUE(Task::DeltaTime) DEFINE_UNSAFE_GETOPTIONVALUE(uint32) DEFINE_UNSAFE_GETOPTIONVALUE(int32) DEFINE_UNSAFE_GETOPTIONVALUE(uint64) DEFINE_UNSAFE_GETOPTIONVALUE(int64) DEFINE_UNSAFE_GETOPTIONVALUE(bool) // FIXME method naming String GetPerServerString(const String& orig, const ServerID& sid) { int32 dot_pos = orig.rfind("."); String prefix = orig.substr(0, dot_pos); String ext = orig.substr(dot_pos+1); char buffer[1024]; sprintf(buffer, "%s-%04d.%s", prefix.c_str(), (uint32)sid, ext.c_str()); return buffer; } String GetPerServerFile(const char* opt_name, const ServerID& sid) { String orig = GetOptionValue<String>(opt_name); return GetPerServerString(orig, sid); } String GetPerServerFile(const char* opt_name, const ObjectHostID& ohid) { return (GetPerServerFile(opt_name, (ServerID)ohid.id)); // FIXME relies on fact that ServerID and ObjectHostID are both uint64 } } // namespace Sirikata
; void dostm_from_tm(struct dos_tm *,struct tm *) SECTION code_time PUBLIC _dostm_from_tm_callee EXTERN asm_dostm_from_tm _dostm_from_tm_callee: pop af pop hl pop de push af jp asm_dostm_from_tm
SECTION rodata_font SECTION rodata_font_fzx PUBLIC _ff_utz_Phraktur _ff_utz_Phraktur: BINARY "font/fzx/fonts/utz/Phraktur/kphraktur.fzx"
; A055845: a(n) = 4*a(n-1) - a(n-2) with a(0)=1, a(1)=8. ; 1,8,31,116,433,1616,6031,22508,84001,313496,1169983,4366436,16295761,60816608,226970671,847066076,3161293633,11798108456,44031140191,164326452308,613274669041,2288772223856,8541814226383,31878484681676,118972124500321,444010013319608,1657067928778111,6184261701792836,23079978878393233,86135653811780096,321462636368727151,1199714891663128508,4477396930283786881,16709872829472019016,62362094387604289183,232738504720945137716,868591924496176261681,3241629193263759909008,12097924848558863374351 mov $1,1 mov $2,7 lpb $0 sub $0,1 add $1,$2 add $2,$1 add $2,$1 lpe mov $0,$1
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include <service-appmgr/Actions.hpp> #include <service-appmgr/messages/Message.hpp> #include <Service/Service.hpp> #include <SwitchData.hpp> #include <i18n/i18n.hpp> #include <time/time_locale.hpp> #include <memory> #include <string> namespace sys { class Service; } // namespace sys namespace app::manager { enum class OnSwitchBehaviour { Close, RunInBackground }; class Controller { public: Controller() = delete; static auto finish(sys::Service *sender) -> bool; static auto applicationInitialised(sys::Service *sender, StartupStatus status, StartInBackground startInBackground) -> bool; static auto sendAction(sys::Service *sender, actions::ActionId actionId, actions::ActionParamsPtr &&data = nullptr, OnSwitchBehaviour onSwitchBehaviour = OnSwitchBehaviour::RunInBackground) -> bool; static auto switchBack(sys::Service *sender, std::unique_ptr<SwitchBackRequest> msg = nullptr) -> bool; static auto confirmSwitch(sys::Service *sender) -> bool; static auto closeApplication(sys::Service *sender, const ApplicationName &name) -> bool; static auto finalizingClose(sys::Service *sender) -> bool; static auto confirmClose(sys::Service *sender) -> bool; static auto changeDisplayLanguage(sys::Service *sender, const Language &language) -> bool; static auto changeInputLanguage(sys::Service *sender, const Language &language) -> bool; static auto changeAutomaticDateAndTimeIsOn(sys::Service *sender, bool isOn) -> bool; static auto changeAutomaticTimeZoneIsOn(sys::Service *sender, bool isOn) -> bool; static auto changeTimeFormat(sys::Service *sender, utils::time::Locale::TimeFormat timeFormat) -> bool; static auto changeDateFormat(sys::Service *sender, utils::time::Locale::DateFormat dateFormat) -> bool; static auto changePowerSaveMode(sys::Service *sender) -> bool; static auto preventBlockingDevice(sys::Service *sender) -> bool; static auto requestNotifications(sys::Service *sender) -> bool; }; } // namespace app::manager
; SUM OF TWO NUMBERS ; SUM OF THE NUMBERS MUST BE LESS THAN 10 .MODEL SAMLL .STACK 100H .DATA MSG1 DB 'ENTER THE FIRST NUMBER: $' MSG2 DB 0AH, 0DH, 'ENTER THE SECOND NUMBER: $' MSG DB 0AH, 0DH, 'THE SUM OF ' C1 DB ?, ' AND ' C2 DB ?, ' IS ', SUM DB ?, '$' .CODE MAIN PROC ; INITIALIZE DS MOV AX, @DATA MOV DS, AX ; READ FIRST DIGIT LEA DX, MSG1 MOV AH, 9 INT 21H MOV AH, 1 INT 21H MOV C1, AL ; READ SECOND DIGIT LEA DX, MSG2 MOV AH, 9 INT 21H MOV AH, 1 INT 21H MOV C2, AL ADD AL, C1 SUB AL, 30H MOV SUM, AL LEA DX, MSG MOV AH, 9 INT 21H ; DOS EXIT MOV AH, 4CH INT 21H MAIN ENDP END MAIN
// grepWin - regex search and replace for Windows // Copyright (C) 2012-2013, 2016-2020 - Stefan Kueng // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software Foundation, // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // #include "stdafx.h" #include "strsafe.h" #include "resource.h" #include "maxpath.h" #include "Settings.h" #include "BrowseFolder.h" #include "DirFileEnum.h" #include "Theme.h" #include "DarkModeHelper.h" #include <Commdlg.h> #include <thread> inline bool PathIsExistingFile(LPCWSTR pszPath) { return (PathFileExists(pszPath) && !PathIsDirectory(pszPath)); } //============================================================================= // // IsFontAvailable() // Test if a certain font is installed on the system // static int CALLBACK EnumFontsProc(CONST LOGFONT* plf, CONST TEXTMETRIC* ptm, DWORD FontType, LPARAM lParam) { UNREFERENCED_PARAMETER(plf); UNREFERENCED_PARAMETER(ptm); UNREFERENCED_PARAMETER(FontType); *((PBOOL)lParam) = true; return 0; } static inline bool IsFontAvailable(LPCWSTR lpszFontName) { BOOL fFound = FALSE; HDC const hDC = GetDC(NULL); EnumFonts(hDC, lpszFontName, EnumFontsProc, (LPARAM)&fFound); ReleaseDC(NULL, hDC); return fFound; } bool GetLocaleDefaultUIFont(std::wstring langFileName, LPWSTR lpFaceName, WORD& wSize) { LPCWSTR font = L"Segoe UI"; wSize = 9; std::transform(langFileName.begin(), langFileName.end(), langFileName.begin(), ::towlower); if (langFileName.find(L"[zh-cn]") != std::wstring::npos) { font = L"Microsoft JhengHei UI"; //wSize = 9; } else if (langFileName.find(L"[zh-tw]") != std::wstring::npos) { font = L"Microsoft YaHei UI"; //wSize = 9; } else if (langFileName.find(L"[ja-jp]") != std::wstring::npos) { font = L"Yu Gothic UI"; //wSize = 9; } else if (langFileName.find(L"[ko-kr]") != std::wstring::npos) { font = L"Malgun Gothic"; //wSize = 9; } bool const isAvail = IsFontAvailable(font); if (isAvail) { StringCchCopy(lpFaceName, LF_FACESIZE, font); } return isAvail; } //============================================================================= CSettingsDlg::CSettingsDlg(HWND hParent) : m_hParent(hParent) , m_regEditorCmd(_T("Software\\grepWinNP3\\editorcmd")) , m_regEsc(_T("Software\\grepWinNP3\\escclose"), FALSE) , m_themeCallbackId(0) { } CSettingsDlg::~CSettingsDlg() { } const wchar_t* const defaultLang = L"English (United States) [en-US]"; const wchar_t* const stdEditorCmd = _T(".\\Notepad3.exe /%mode% \"%pattern%\" /g %line% - %path%"); LRESULT CSettingsDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (uMsg) { case WM_INITDIALOG: { m_themeCallbackId = CTheme::Instance().RegisterThemeChangeCallback( [this]() { CTheme::Instance().SetThemeForDialog(*this, CTheme::Instance().IsDarkTheme()); CTheme::Instance().SetFontForDialog(*this, CTheme::Instance().GetDlgFontFaceName(), CTheme::Instance().GetDlgFontSize()); }); CTheme::Instance().SetThemeForDialog(*this, CTheme::Instance().IsDarkTheme()); CTheme::Instance().SetFontForDialog(*this, CTheme::Instance().GetDlgFontFaceName(), CTheme::Instance().GetDlgFontSize()); InitDialog(hwndDlg, IDI_GREPWIN); DarkModeHelper::Instance().AllowDarkModeForWindow(GetToolTipHWND(), CTheme::Instance().IsDarkTheme()); SetWindowTheme(GetToolTipHWND(), L"Explorer", nullptr); CLanguage::Instance().TranslateWindow(*this); AddToolTip(IDC_ONLYONE, TranslatedString(hResource, IDS_ONLYONE_TT).c_str()); std::wstring editorCmd = bPortable ? g_iniFile.GetValue(L"global", L"editorcmd", L"") : std::wstring(m_regEditorCmd); if (editorCmd.empty()) editorCmd = stdEditorCmd; SetDlgItemText(hwndDlg, IDC_EDITORCMD, editorCmd.c_str()); wchar_t moduledir[MAX_PATH] = {0}; GetModuleFileName(nullptr, moduledir, MAX_PATH); PathRemoveFileSpec(moduledir); std::wstring path = moduledir; bool bRecurse = false; bool bIsDirectory = false; CRegStdString regLang(L"Software\\grepWinNP3\\languagefile"); std::wstring setLang = regLang; if (bPortable) { wchar_t absLngPath[MAX_PATH] = {0}; StringCchCopy(absLngPath, MAX_PATH, g_iniFile.GetValue(L"global", L"languagefile", L"")); if (absLngPath[0] == L'\0') { StringCchCopy(absLngPath, MAX_PATH, defaultLang); StringCchCat(absLngPath, MAX_PATH, L".lang"); } if (PathIsRelative(absLngPath)) { wchar_t tmpPath[MAX_PATH] = {0}; StringCchCopy(tmpPath, MAX_PATH, moduledir); PathAppend(tmpPath, absLngPath); StringCchCopy(absLngPath, MAX_PATH, tmpPath); } // need to adapt file enumerator path if (PathIsExistingFile(absLngPath)) { StringCchCopy(moduledir, MAX_PATH, absLngPath); PathRemoveFileSpec(moduledir); } else absLngPath[0] = L'\0'; // empty setLang = absLngPath; path = moduledir; } // ordered map of language files std::wstring sPath; std::map<std::wstring, std::wstring> langFileMap; CDirFileEnum fileEnumerator(path.c_str()); while (fileEnumerator.NextFile(sPath, &bIsDirectory, bRecurse)) { size_t const dotpos = sPath.find_last_of('.'); if (dotpos == std::wstring::npos) continue; std::wstring const ext = sPath.substr(dotpos); if (ext.compare(L".lang")) continue; size_t const keypos = max(0, dotpos - 7); std::wstring const lngKey = sPath.substr(keypos, (dotpos - keypos - 1)); langFileMap.insert({ lngKey, sPath }); } // clean map and get [en-US] first ... int langIndex = -1; for (auto it = langFileMap.cbegin(); it != langFileMap.cend() /* not hoisted */; /* no increment */) { size_t const slashpos = (it->second).find_last_of('\\'); if (slashpos == std::wstring::npos) it = langFileMap.erase(it); else { sPath = (it->second).substr(slashpos + 1); size_t const dotpos = sPath.find_last_of('.'); sPath = sPath.substr(0, dotpos); if (sPath.compare(defaultLang) == 0) { if ((it->second).compare(setLang) == 0) langIndex = 0; m_langpaths.push_front(it->second); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)sPath.c_str()); it = langFileMap.erase(it); } else ++it; } } // build combobox auto index = static_cast<int>(m_langpaths.size()); for (const auto& lang : langFileMap) { size_t const slashpos = lang.second.find_last_of('\\'); if (slashpos == std::wstring::npos) continue; if ((langIndex < 0) && (lang.second.compare(setLang) == 0)) langIndex = index; sPath = lang.second.substr(slashpos + 1); size_t const dotpos = sPath.find_last_of('.'); sPath = sPath.substr(0, dotpos); m_langpaths.push_back(lang.second); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)sPath.c_str()); ++index; } if (langIndex < 0) // configured language file not found { langIndex = 0; m_langpaths.push_front(L""); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_INSERTSTRING, (WPARAM)0, (LPARAM)defaultLang); } auto const height = (int)SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_GETITEMHEIGHT, 0, NULL); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SETITEMHEIGHT, 0, (LPARAM)((int)(height*132)/100)); SendDlgItemMessage(hwndDlg, IDC_LANGUAGE, CB_SETCURSEL, langIndex, 0); SendDlgItemMessage(hwndDlg, IDC_ESCKEY, BM_SETCHECK, bPortable ? g_iniFile.GetBoolValue(L"settings", L"escclose", false) : !!DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\escclose", FALSE)) ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hwndDlg, IDC_BACKUPINFOLDER, BM_SETCHECK, bPortable ? g_iniFile.GetBoolValue(L"settings", L"backupinfolder", false) : !!DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\backupinfolder", FALSE)) ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hwndDlg, IDC_NOWARNINGIFNOBACKUP, BM_SETCHECK, bPortable ? g_iniFile.GetBoolValue(L"settings", L"nowarnifnobackup", false) : !!DWORD(CRegStdDWORD(L"Software\\grepWin\\nowarnifnobackup", FALSE)) ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hwndDlg, IDC_ONLYONE, BM_SETCHECK, bPortable ? g_iniFile.GetBoolValue(L"global", L"onlyone", false) : !!DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\onlyone", FALSE)) ? BST_CHECKED : BST_UNCHECKED, 0); #ifdef NP3_ALLOW_UPDATE SendDlgItemMessage(hwndDlg, IDC_DOUPDATECHECKS, BM_SETCHECK, bPortable ? g_iniFile.GetBoolValue(L"global", L"CheckForUpdates", false) : !!DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\CheckForUpdates", FALSE)) ? BST_CHECKED : BST_UNCHECKED, 0); #endif SendDlgItemMessage(hwndDlg, IDC_DARKMODE, BM_SETCHECK, CTheme::Instance().IsDarkTheme() ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(*this, IDC_DARKMODE), CTheme::Instance().IsDarkModeAllowed()); SetDlgItemText(*this, IDC_NUMNULL, bPortable ? g_iniFile.GetValue(L"settings", L"nullbytes", L"0") : std::to_wstring(DWORD(CRegStdDWORD(L"Software\\grepWin\\nullbytes", 0))).c_str()); DWORD const nMaxWorker = std::thread::hardware_concurrency() << 2; SendDlgItemMessage(hwndDlg, IDC_SPIN_MAXWORKER, UDM_SETRANGE, 0, MAKELPARAM(nMaxWorker, 1)); DWORD const nWorker = max(min(bPortable ? g_iniFile.GetLongValue(L"global", L"MaxNumOfWorker", nMaxWorker >> 1) : DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\MaxNumOfWorker", nMaxWorker >> 1)), nMaxWorker), 1); wchar_t number[32]; StringCchPrintf(number, ARRAYSIZE(number), L"%i", nWorker); SendDlgItemMessage(hwndDlg, IDC_MAXNUMWORKER, WM_SETTEXT, 0, (WPARAM)number); AddToolTip(IDC_BACKUPINFOLDER, TranslatedString(hResource, IDS_BACKUPINFOLDER_TT).c_str()); if (!CTheme::Instance().IsDarkModeAllowed()) SetDlgItemText(*this, IDC_DARKMODEINFO, TranslatedString(hResource, IDS_DARKMODE_TT).c_str()); m_resizer.Init(hwndDlg); m_resizer.UseSizeGrip(!CTheme::Instance().IsDarkTheme()); m_resizer.AddControl(hwndDlg, IDC_EDITORGROUP, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_EDITORCMD, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_SEARCHPATHBROWSE, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDC_STATIC1, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_STATIC2, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_STATIC3, RESIZER_TOPLEFT); m_resizer.AddControl(hwndDlg, IDC_STATIC4, RESIZER_TOPLEFT); m_resizer.AddControl(hwndDlg, IDC_NUMNULL, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDC_LANGUAGE, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDC_ESCKEY, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_BACKUPINFOLDER, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_NOWARNINGIFNOBACKUP, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_ONLYONE, RESIZER_TOPLEFTRIGHT); #ifdef NP3_ALLOW_UPDATE m_resizer.AddControl(hwndDlg, IDC_DOUPDATECHECKS, RESIZER_TOPLEFTRIGHT); #endif m_resizer.AddControl(hwndDlg, IDC_DARKMODE, RESIZER_TOPLEFT); m_resizer.AddControl(hwndDlg, IDC_DARKMODEINFO, RESIZER_TOPLEFTRIGHT); m_resizer.AddControl(hwndDlg, IDC_TEXT_NUMOFWORKER, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDC_MAXNUMWORKER, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDC_SPIN_MAXWORKER, RESIZER_TOPRIGHT); m_resizer.AddControl(hwndDlg, IDOK, RESIZER_BOTTOMRIGHT); m_resizer.AddControl(hwndDlg, IDCANCEL, RESIZER_BOTTOMRIGHT); } return TRUE; case WM_COMMAND: return DoCommand(LOWORD(wParam), HIWORD(wParam)); case WM_SIZE: { m_resizer.DoResize(LOWORD(lParam), HIWORD(lParam)); } break; case WM_GETMINMAXINFO: { auto * mmi = (MINMAXINFO*)lParam; mmi->ptMinTrackSize.x = m_resizer.GetDlgRectScreen()->right; mmi->ptMinTrackSize.y = m_resizer.GetDlgRectScreen()->bottom; return 0; } break; case WM_CLOSE: CTheme::Instance().RemoveRegisteredCallback(m_themeCallbackId); break; default: return FALSE; } return FALSE; } LRESULT CSettingsDlg::DoCommand(int id, int /*msg*/) { switch (id) { case IDC_RESETDEFAULT: SetDlgItemText(*this, IDC_EDITORCMD, stdEditorCmd); break; case IDOK: { auto buf = GetDlgItemText(IDC_EDITORCMD); if (bPortable) g_iniFile.SetValue(L"global", L"editorcmd", buf.get()); else m_regEditorCmd = buf.get(); auto langIndex = static_cast<size_t>(SendDlgItemMessage(*this, IDC_LANGUAGE, CB_GETCURSEL, 0, 0)); const std::wstring langpath = (langIndex < m_langpaths.size()) ? m_langpaths[langIndex] : L""; if (bPortable) { WCHAR moduledir[MAX_PATH] = {L'\0'}; GetModuleFileName(nullptr, moduledir, MAX_PATH); PathRemoveFileSpec(moduledir); WCHAR absLngPath[MAX_PATH] = {L'\0'}; StringCchCopy(absLngPath, MAX_PATH, langpath.c_str()); //~PathCanonicalize(tmp, absLngPath); if (PathIsExistingFile(absLngPath)) { WCHAR relLngPath[MAX_PATH] = {L'\0'}; if (PathRelativePathTo(relLngPath, moduledir, FILE_ATTRIBUTE_DIRECTORY, absLngPath, FILE_ATTRIBUTE_NORMAL)) g_iniFile.SetValue(L"global", L"languagefile", relLngPath); else g_iniFile.SetValue(L"global", L"languagefile", absLngPath); } else g_iniFile.DeleteValue(L"global", L"languagefile", nullptr, false); } else { CRegStdString regLang(L"Software\\grepWinNP3\\languagefile"); if (langIndex==0) regLang.removeValue(); else regLang = langpath; } WORD fntSize = 9; WCHAR fontFaceName[LF_FACESIZE]; if (GetLocaleDefaultUIFont(langpath, fontFaceName, fntSize)) { CTheme::Instance().SetDlgFontFaceName(fontFaceName, fntSize); } CLanguage::Instance().LoadFile(langpath); CLanguage::Instance().TranslateWindow(::GetParent(*this)); wchar_t worker[32]; SendDlgItemMessage(*this, IDC_MAXNUMWORKER, WM_GETTEXT, (LPARAM)32, (WPARAM)worker); long const nWorker = _wtol((wchar_t*)worker); std::wstring sNumNull = GetDlgItemText(IDC_NUMNULL).get(); if (bPortable) { g_iniFile.SetBoolValue(L"settings", L"escclose", (IsDlgButtonChecked(*this, IDC_ESCKEY) == BST_CHECKED)); g_iniFile.SetBoolValue(L"settings", L"backupinfolder", (IsDlgButtonChecked(*this, IDC_BACKUPINFOLDER) == BST_CHECKED)); g_iniFile.SetBoolValue(L"settings", L"nowarnifnobackup", (IsDlgButtonChecked(*this, IDC_NOWARNINGIFNOBACKUP) == BST_CHECKED)); g_iniFile.SetBoolValue(L"global", L"onlyone", (IsDlgButtonChecked(*this, IDC_ONLYONE) == BST_CHECKED)); #ifdef NP3_ALLOW_UPDATE g_iniFile.SetBoolValue(L"global", L"CheckForUpdates", (IsDlgButtonChecked(*this, IDC_DOUPDATECHECKS) == BST_CHECKED)); #endif g_iniFile.SetValue(L"settings", L"nullbytes", sNumNull.c_str()); g_iniFile.SetLongValue(L"global", L"MaxNumOfWorker", nWorker); } else { CRegStdDWORD esc(L"Software\\grepWinNP3\\escclose", FALSE); esc = (IsDlgButtonChecked(*this, IDC_ESCKEY) == BST_CHECKED); CRegStdDWORD backup(L"Software\\grepWinNP3\\backupinfolder", FALSE); backup = (IsDlgButtonChecked(*this, IDC_BACKUPINFOLDER) == BST_CHECKED); CRegStdDWORD nowarn(L"Software\\grepWinNP3\\nowarnifnobackup", FALSE); nowarn = (IsDlgButtonChecked(*this, IDC_NOWARNINGIFNOBACKUP) == BST_CHECKED); CRegStdDWORD regOnlyOne(L"Software\\grepWinNP3\\onlyone", FALSE); regOnlyOne = (IsDlgButtonChecked(*this, IDC_ONLYONE) == BST_CHECKED); #ifdef NP3_ALLOW_UPDATE CRegStdDWORD regCheckForUpdates(L"Software\\grepWinNP3\\CheckForUpdates", FALSE); regCheckForUpdates = (IsDlgButtonChecked(*this, IDC_DOUPDATECHECKS) == BST_CHECKED); #endif CRegStdDWORD regNumNull(L"Software\\grepWinNP3\\nullbytes", FALSE); regNumNull = _wtoi(sNumNull.c_str()); CRegStdDWORD regNumWorker(L"Software\\grepWinNP3\\MaxNumOfWorker", 1); regNumWorker = nWorker; } CTheme::Instance().SetDarkTheme(IsDlgButtonChecked(*this, IDC_DARKMODE) == BST_CHECKED); } // fall through case IDCANCEL: CTheme::Instance().RemoveRegisteredCallback(m_themeCallbackId); EndDialog(*this, id); break; case IDC_SEARCHPATHBROWSE: { OPENFILENAME ofn = {0}; // common dialog box structure TCHAR szFile[MAX_PATH] = {0}; // buffer for file name // Initialize OPENFILENAME ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = *this; ofn.lpstrFile = szFile; ofn.nMaxFile = _countof(szFile); std::wstring sTitle = TranslatedString(hResource, IDS_SELECTEDITOR); ofn.lpstrTitle = sTitle.c_str(); ofn.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_DONTADDTORECENT; auto sProgs = TranslatedString(hResource, IDS_PROGRAMS); auto sAllFiles = TranslatedString(hResource, IDS_ALLFILES); auto sFilter = sProgs; sFilter.append(L"\0*.exe;*.com\0", _countof(L"\0*.exe;*.com\0")-1); sFilter.append(sAllFiles); sFilter.append(L"\0*.*\0\0", _countof(L"\0*.*\0\0")-1); ofn.lpstrFilter = sFilter.c_str(); ofn.nFilterIndex = 1; // Display the Open dialog box. if (GetOpenFileName(&ofn)==TRUE) { SetDlgItemText(*this, IDC_EDITORCMD, szFile); } } break; } return 1; }
IF DEF(@) PRINTLN "defined" ELSE PRINTLN "not defined" ENDC