text
stringlengths
1
1.05M
; A158639: a(n) = 676*n^2 - 26. ; 650,2678,6058,10790,16874,24310,33098,43238,54730,67574,81770,97318,114218,132470,152074,173030,195338,218998,244010,270374,298090,327158,357578,389350,422474,456950,492778,529958,568490,608374,649610,692198,736138,781430,828074,876070,925418,976118,1028170,1081574,1136330,1192438,1249898,1308710,1368874,1430390,1493258,1557478,1623050,1689974,1758250,1827878,1898858,1971190,2044874,2119910,2196298,2274038,2353130,2433574,2515370,2598518,2683018,2768870,2856074,2944630,3034538,3125798,3218410,3312374,3407690,3504358,3602378,3701750,3802474,3904550,4007978,4112758,4218890,4326374,4435210,4545398,4656938,4769830,4884074,4999670,5116618,5234918,5354570,5475574,5597930,5721638,5846698,5973110,6100874,6229990,6360458,6492278,6625450,6759974,6895850,7033078,7171658,7311590,7452874,7595510,7739498,7884838,8031530,8179574,8328970,8479718,8631818,8785270,8940074,9096230,9253738,9412598,9572810,9734374,9897290,10061558,10227178,10394150,10562474,10732150,10903178,11075558,11249290,11424374,11600810,11778598,11957738,12138230,12320074,12503270,12687818,12873718,13060970,13249574,13439530,13630838,13823498,14017510,14212874,14409590,14607658,14807078,15007850,15209974,15413450,15618278,15824458,16031990,16240874,16451110,16662698,16875638,17089930,17305574,17522570,17740918,17960618,18181670,18404074,18627830,18852938,19079398,19307210,19536374,19766890,19998758,20231978,20466550,20702474,20939750,21178378,21418358,21659690,21902374,22146410,22391798,22638538,22886630,23136074,23386870,23639018,23892518,24147370,24403574,24661130,24920038,25180298,25441910,25704874,25969190,26234858,26501878,26770250,27039974,27311050,27583478,27857258,28132390,28408874,28686710,28965898,29246438,29528330,29811574,30096170,30382118,30669418,30958070,31248074,31539430,31832138,32126198,32421610,32718374,33016490,33315958,33616778,33918950,34222474,34527350,34833578,35141158,35450090,35760374,36072010,36384998,36699338,37015030,37332074,37650470,37970218,38291318,38613770,38937574,39262730,39589238,39917098,40246310,40576874,40908790,41242058,41576678,41912650,42249974 mov $1,2 add $1,$0 mul $1,$0 mul $1,676 add $1,650
.data keno: .asciiz "\n" str1: .asciiz "HELLO WORLD!\n" str2: .asciiz "TEI OF ATHENS\n" number: .word 5 str3: .asciiz "DWSE MOU ENAN AKERAIO ARITHMO\n" str4: .asciiz "DIAVASA TON ARITHMO: " on1: .asciiz "DWSE MOU TO ONOMATEPWNUMO SOU\n" on2: .asciiz "SE LENE: " on3: .space 50 .text .globl main main: #ask 3.A li $a0,'a' li $v0,11 syscall li $v0,4 la $a0,keno syscall #ask 3.B li $v0,11 li $a0,'a' syscall li $v0,4 la $a0,keno syscall li $v0,11 li $a0,'d' syscall li $v0,4 la $a0,keno syscall #ask 3.C li $v0,4 la $a0,str1 syscall #ask 3.D li $v0,4 la $a0,str1 syscall li $v0,4 la $a0,str2 syscall #ask3.E li $v0,1 lw $a0,number syscall li $v0,4 la $a0,keno syscall #ask3.F li $v0,4 la $a0,str3 syscall li $v0,5 syscall move $t0,$v0 li $v0,4 la $a0,str4 syscall li $v0,1 la $a0,($t0) syscall li $v0,4 la $a0,keno syscall #ask3.G li $v0,4 la $a0,on1 syscall li $v0,8 la $a0,on3 li $a1, 50 syscall li $v0,4 la $a0,on2 syscall li $v0,4 la $a0,on3 syscall #SWSTOS TERMATISMOS PROGRAMMATOS li $v0,10 syscall
; A188825: Number of 3Xn binary arrays without the pattern 0 1 diagonally or antidiagonally ; 8,16,48,144,432,1296,3888,11664,34992,104976,314928,944784,2834352,8503056,25509168,76527504,229582512,688747536,2066242608,6198727824,18596183472,55788550416,167365651248,502096953744,1506290861232 mov $1,3 pow $1,$0 mul $1,2 sub $1,2 div $1,3 mul $1,8 add $1,8
; A336705: Coordination sequence for the half-Manhattan lattice. ; 1,3,7,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228 mul $0,2 trn $0,1 mul $0,2 mov $2,$0 mov $3,1 lpb $2 add $0,$3 mod $2,7 lpe add $0,$3 mov $1,$0
SECTION code_fp_math48 PUBLIC _log1p EXTERN cm48_sdccix_log1p defc _log1p = cm48_sdccix_log1p
;/* ; * FreeRTOS Kernel <DEVELOPMENT BRANCH> ; * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. ; * ; * SPDX-License-Identifier: MIT ; * ; * 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. ; * ; * https://www.FreeRTOS.org ; * https://github.com/FreeRTOS ; * ; */ .thumb .ref pxCurrentTCB .ref vTaskSwitchContext .ref ulMaxSyscallInterruptPriority .def xPortPendSVHandler .def ulPortGetIPSR .def vPortSVCHandler .def vPortStartFirstTask .def vPortEnableVFP NVICOffsetConst: .word 0xE000ED08 CPACRConst: .word 0xE000ED88 pxCurrentTCBConst: .word pxCurrentTCB ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority ; ----------------------------------------------------------- .align 4 ulPortGetIPSR: .asmfunc mrs r0, ipsr bx r14 .endasmfunc ; ----------------------------------------------------------- .align 4 vPortSetInterruptMask: .asmfunc push {r0} ldr r0, ulMaxSyscallInterruptPriorityConst msr basepri, r0 pop {r0} bx r14 .endasmfunc ; ----------------------------------------------------------- .align 4 xPortPendSVHandler: .asmfunc mrs r0, psp isb ;/* Get the location of the current TCB. */ ldr r3, pxCurrentTCBConst ldr r2, [r3] ;/* Is the task using the FPU context? If so, push high vfp registers. */ tst r14, #0x10 it eq vstmdbeq r0!, {s16-s31} ;/* Save the core registers. */ stmdb r0!, {r4-r11, r14} ;/* Save the new top of stack into the first member of the TCB. */ str r0, [r2] stmdb sp!, {r0, r3} ldr r0, ulMaxSyscallInterruptPriorityConst ldr r1, [r0] msr basepri, r1 dsb isb bl vTaskSwitchContext mov r0, #0 msr basepri, r0 ldmia sp!, {r0, r3} ;/* The first item in pxCurrentTCB is the task top of stack. */ ldr r1, [r3] ldr r0, [r1] ;/* Pop the core registers. */ ldmia r0!, {r4-r11, r14} ;/* Is the task using the FPU context? If so, pop the high vfp registers ;too. */ tst r14, #0x10 it eq vldmiaeq r0!, {s16-s31} msr psp, r0 isb bx r14 .endasmfunc ; ----------------------------------------------------------- .align 4 vPortSVCHandler: .asmfunc ;/* Get the location of the current TCB. */ ldr r3, pxCurrentTCBConst ldr r1, [r3] ldr r0, [r1] ;/* Pop the core registers. */ ldmia r0!, {r4-r11, r14} msr psp, r0 isb mov r0, #0 msr basepri, r0 bx r14 .endasmfunc ; ----------------------------------------------------------- .align 4 vPortStartFirstTask: .asmfunc ;/* Use the NVIC offset register to locate the stack. */ ldr r0, NVICOffsetConst ldr r0, [r0] ldr r0, [r0] ;/* Set the msp back to the start of the stack. */ msr msp, r0 ;/* Clear the bit that indicates the FPU is in use in case the FPU was used ;before the scheduler was started - which would otherwise result in the ;unnecessary leaving of space in the SVC stack for lazy saving of FPU ;registers. */ mov r0, #0 msr control, r0 ;/* Call SVC to start the first task. */ cpsie i cpsie f dsb isb svc #0 .endasmfunc ; ----------------------------------------------------------- .align 4 vPortEnableVFP: .asmfunc ;/* The FPU enable bits are in the CPACR. */ ldr.w r0, CPACRConst ldr r1, [r0] ;/* Enable CP10 and CP11 coprocessors, then save back. */ orr r1, r1, #( 0xf << 20 ) str r1, [r0] bx r14 .endasmfunc .end ; -----------------------------------------------------------
%define PROT_READ 0x1 %define PROT_WRITE 0x2 global _main ; Arguments : rdi, rsi, rdx, rcx, r8, r9 section .text %include "io.asm" %include "mem.asm" %include "tests.asm" ; === === === === === === === === === === === === ; PROGRAM ; === === === === === === === === === === === === _main: call mem@init call test@execute call mem@uninit .end: call exit ; Dans .data on définie les données section .data new_line: db 10,0 ; ERROR MESSAGES err_prefix: db "ERR:",0 err_alloc: db "While allocating memory",0 err_alloc_too_big: db "The size to allocate was to large",0 err_read: db "While reading the stdin",0 err_read_too_long: db "The input was too long. Maximum number of chars exceeded",0 ; MESSAGE FOR TESTS test_title: db "Now doing TEST ",0 test_success: db "...The test succeeded",0 test_fail: db "...The test failed", 0 section .bss errno resb 1 ; When we need to print the error number io@buffer_char resb 1 ; When we need to print a char io@buffer_int resb 64 ; When we need to print a number mem@parent_page resb 8 ; Address of the parent page
// This is an open source non-commercial project. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // ---------------------------------------------------------------------------- // "THE BEER-WARE LICENSE" (Revision 42): // <ztn@zurreal.com> wrote this file. As long as you retain this notice you // can do whatever you want with this stuff. If we meet some day, and you think // this stuff is worth it, you can buy me a beer in return. Ziesche Til Newman // ---------------------------------------------------------------------------- // // role-enum.cpp // #include "role-enum.hpp" #include "misc/config-file.hpp" #include "misc/enum-util.hpp" #include "misc/log-macros.hpp" namespace heroespath { namespace creature { const std::string role::ToString(const role::Enum ROLE) { switch (ROLE) { case Beastmaster: { return "Beastmaster"; } case Sorcerer: { return "Sorcerer"; } case Cleric: { return "Cleric"; } case Knight: { return "Knight"; } case Archer: { return "Archer"; } case Bard: { return "Bard"; } case Thief: { return "Thief"; } case Wolfen: { return "Wolfen"; } case Firebrand: { return "Firebrand"; } case Sylavin: { return "Sylavin"; } // case Thug: { return "Thug"; } case Mugger: { return "Mugger"; } case Drunk: { return "Drunk"; } case Brute: { return "Brute"; } case Berserker: { return "Berserker"; } case Mountain: { return "Mountain"; } case Grunt: { return "Grunt"; } case Captain: { return "Captain"; } case Chieftain: { return "Chieftain"; } case Trader: { return "Trader"; } case Warlord: { return "Warlord"; } case Shaman: { return "Shaman"; } case Smasher: { return "Smasher"; } case Strangler: { return "Strangler"; } case Soldier: { return "Soldier"; } case TwoHeaded: { return "TwoHeaded"; } case Giant: { return "Giant"; } case Elder: { return "Elder"; } case FourArmed: { return "FourArmed"; } case Tendrilus: { return "Tendrilus"; } case Wing: { return "Wing"; } case Whelp: { return "Whelp"; } case Pod: { return "Pod"; } case Spike: { return "Spike"; } case Skeleton: { return "Skeleton"; } case Ranger: { return "Ranger"; } case Water: { return "Water"; } case Blacksmith: { return "Blacksmith"; } case Spider: { return "Spider"; } case Beetle: { return "Beetle"; } case Boar: { return "Boar"; } case Lion: { return "Lion"; } case Ramonaut: { return "Ramonaut"; } case Serpent: { return "Serpent"; } case Bat: { return "Bat"; } case Ghost: { return "Ghost"; } case Cat: { return "Cat"; } case Wolf: { return "Wolf"; } case Count: { return "(Count)"; } default: { M_HP_LOG_ERR( "enum_value=" << static_cast<EnumUnderlying_t>(ROLE) << " is invalid. (count=" << static_cast<EnumUnderlying_t>(Count) << ")"); return ""; } } } const std::string role::Desc(const role::Enum ENUM) { std::ostringstream ss; ss << "creature-role-" << ToString(ENUM) << "-desc"; return misc::ConfigFile::Instance()->Value(ss.str()); } const std::string role::Abbr(const role::Enum ENUM) { if (ENUM == Beastmaster) { return "Bsm"; } else if (ENUM == Thief) { return "Thf"; } else if (ENUM == Wolfen) { return "Wlf"; } else { return Name(ENUM).substr(0, 3); } } bool role::CanFly(const role::Enum ENUM) { return ( (ENUM == role::Firebrand) || (ENUM == role::Sylavin) || (ENUM == role::Wing) || (ENUM == role::Whelp) || (ENUM == role::Bat)); } bool role::WillInitiallyFly(const role::Enum ENUM) { return ((ENUM == role::Wing) || (ENUM == role::Whelp) || (ENUM == role::Bat)); } combat::BlockingPosType::Enum role::BlockingPosType(const role::Enum ENUM) { switch (ENUM) { case role::Mountain: case role::Spider: case role::Beetle: case role::Boar: case role::Lion: case role::Ramonaut: case role::Serpent: case role::Whelp: case role::Pod: case role::Spike: case role::Skeleton: case role::Thug: case role::Mugger: case role::Drunk: case role::Grunt: case role::FourArmed: case role::Tendrilus: case role::TwoHeaded: case role::Giant: case role::Smasher: case role::Strangler: case role::Soldier: case role::Brute: case role::Berserker: case role::Knight: case role::Wolfen: case role::Firebrand: case role::Ranger: case role::Water: case role::Blacksmith: case role::Cat: case role::Wolf: case role::Sylavin: { return combat::BlockingPosType::Front; } case role::Ghost: case role::Bat: case role::Beastmaster: case role::Bard: case role::Archer: case role::Wing: { return combat::BlockingPosType::Support; } case role::Captain: case role::Warlord: case role::Chieftain: { return combat::BlockingPosType::Commanders; } case role::Thief: { return combat::BlockingPosType::Reluctant; } case role::Elder: case role::Shaman: case role::Sorcerer: case role::Cleric: { return combat::BlockingPosType::Casters; } case role::Trader: { return combat::BlockingPosType::Last; } case role::Count: default: { M_HP_LOG_ERR( "enum_value=" << static_cast<EnumUnderlying_t>(ENUM) << " is invalid. (count=" << static_cast<EnumUnderlying_t>(Count) << ")"); return combat::BlockingPosType::Count; } } } std::vector<role::Enum> role::RolesOfBlockingPosType(const combat::BlockingPosType::Enum BLOCKING_POS_ENUM) { std::vector<role::Enum> rolesVec; for (EnumUnderlying_t i(0); i < role::Count; ++i) { const auto ROLE { static_cast<role::Enum>(i) }; if (BlockingPosType(ROLE) == BLOCKING_POS_ENUM) { rolesVec.emplace_back(ROLE); } } if (rolesVec.empty()) { M_HP_LOG_ERR( "role::RolesOfBlockingPosType(" << BLOCKING_POS_ENUM << ") produced no roles."); } return rolesVec; } } // namespace creature } // namespace heroespath
;------------------------------------------------------------------------------ ; security_check_cookie.asm ; MS_CHANGE_? ;------------------------------------------------------------------------------ EXTRN __security_cookie:QWORD .code ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; __security_check_cookie ( ; IN UINTN CheckValue); ;------------------------------------------------------------------------------ __security_check_cookie PROC PUBLIC cmp rcx, __security_cookie jne __security_check_cookie_Failure ret __security_check_cookie_Failure: int 3 ret __security_check_cookie ENDP END
Map_361FD6: dc.w Frame_362046-Map_361FD6 dc.w Frame_362078-Map_361FD6 dc.w Frame_362098-Map_361FD6 dc.w Frame_3620A6-Map_361FD6 dc.w Frame_3620AE-Map_361FD6 dc.w Frame_3620B6-Map_361FD6 dc.w Frame_3620BE-Map_361FD6 dc.w Frame_3620CC-Map_361FD6 dc.w Frame_3620D4-Map_361FD6 dc.w Frame_3620DC-Map_361FD6 dc.w Frame_3620E4-Map_361FD6 dc.w Frame_3620EC-Map_361FD6 dc.w Frame_3620FA-Map_361FD6 dc.w Frame_362108-Map_361FD6 dc.w Frame_362116-Map_361FD6 dc.w Frame_362124-Map_361FD6 dc.w Frame_362124-Map_361FD6 dc.w Frame_362132-Map_361FD6 dc.w Frame_362140-Map_361FD6 dc.w Frame_362148-Map_361FD6 dc.w Frame_362150-Map_361FD6 dc.w Frame_362158-Map_361FD6 dc.w Frame_362158-Map_361FD6 dc.w Frame_362166-Map_361FD6 dc.w Frame_362174-Map_361FD6 dc.w Frame_36217C-Map_361FD6 dc.w Frame_362184-Map_361FD6 dc.w Frame_36218C-Map_361FD6 dc.w Frame_3621BE-Map_361FD6 dc.w Frame_3621F0-Map_361FD6 dc.w Frame_362222-Map_361FD6 dc.w Frame_362242-Map_361FD6 dc.w Frame_362262-Map_361FD6 dc.w Frame_362282-Map_361FD6 dc.w Frame_362290-Map_361FD6 dc.w Frame_36229E-Map_361FD6 dc.w Frame_3622AC-Map_361FD6 dc.w Frame_362326-Map_361FD6 dc.w Frame_362326-Map_361FD6 dc.w Frame_36233A-Map_361FD6 dc.w Frame_36234E-Map_361FD6 dc.w Frame_362362-Map_361FD6 dc.w Frame_362376-Map_361FD6 dc.w Frame_36238A-Map_361FD6 dc.w Frame_36238C-Map_361FD6 dc.w Frame_3623EE-Map_361FD6 dc.w Frame_3623FC-Map_361FD6 dc.w Frame_36240A-Map_361FD6 dc.w Frame_362418-Map_361FD6 dc.w Frame_362426-Map_361FD6 dc.w Frame_3624A0-Map_361FD6 dc.w Frame_3624A8-Map_361FD6 dc.w Frame_3624B0-Map_361FD6 dc.w Frame_3624B8-Map_361FD6 dc.w Frame_3624C0-Map_361FD6 dc.w Frame_3624C8-Map_361FD6 Frame_362046: dc.w 8 dc.b $E0, $F, 0, 0,$FF,$E0 dc.b $E8, 2, 0,$10,$FF,$D8 dc.b 0, $D, 0,$13,$FF,$E0 dc.b $10, 9, 0,$1B,$FF,$E8 dc.b $E0, $F, 8, 0, 0, 0 dc.b $E8, 2, 8,$10, 0,$20 dc.b 0, $D, 8,$13, 0, 0 dc.b $10, 9, 8,$1B, 0, 0 Frame_362078: dc.w 5 dc.b $F4, 2, 0,$21,$FF,$DC dc.b $EC, $F, 0,$24,$FF,$E4 dc.b $C, $C, 0,$34,$FF,$E4 dc.b $EC, $F, 0,$38, 0, 4 dc.b $C, $C, 0,$48, 0, 4 Frame_362098: dc.w 2 dc.b $FC, 4, 0,$4C,$FF,$F0 dc.b $FC, 4, 8,$4C, 0, 0 Frame_3620A6: dc.w 1 dc.b $F4, $A, 0,$4E,$FF,$F4 Frame_3620AE: dc.w 1 dc.b $F4, 6, 0,$57,$FF,$F8 Frame_3620B6: dc.w 1 dc.b $F4, $A, 0,$5D,$FF,$F4 Frame_3620BE: dc.w 2 dc.b $FC, 4, 0,$66,$FF,$F0 dc.b $FC, 4, 8,$66, 0, 0 Frame_3620CC: dc.w 1 dc.b $F8, 5, 0,$68,$FF,$F8 Frame_3620D4: dc.w 1 dc.b $F8, 5, 0,$6C,$FF,$F8 Frame_3620DC: dc.w 1 dc.b $F8, 5, 0,$70,$FF,$F8 Frame_3620E4: dc.w 1 dc.b $F8, 5, 0,$74,$FF,$F8 Frame_3620EC: dc.w 2 dc.b $FC, 4,$10,$78,$FF,$F0 dc.b $FC, 4,$18,$78, 0, 0 Frame_3620FA: dc.w 2 dc.b $FC, 4,$10,$7A,$FF,$F0 dc.b $FC, 4,$18,$7A, 0, 0 Frame_362108: dc.w 2 dc.b $FC, 4,$10,$7C,$FF,$F0 dc.b $FC, 4,$18,$7C, 0, 0 Frame_362116: dc.w 2 dc.b $FC, 4,$10,$7E,$FF,$F0 dc.b $FC, 4,$18,$7E, 0, 0 Frame_362124: dc.w 2 dc.b $F4, $A, 0,$80,$FF,$F4 dc.b $F4, $A, 0,$89, 0, $C Frame_362132: dc.w 2 dc.b $F4, $A, 0,$80,$FF,$F4 dc.b $F4, $A, 0,$92, 0, $C Frame_362140: dc.w 1 dc.b $F8, 5, 0,$9B,$FF,$F8 Frame_362148: dc.w 1 dc.b $F8, 1, 0,$9F,$FF,$FC Frame_362150: dc.w 1 dc.b $FC, 0, 0,$A1,$FF,$FC Frame_362158: dc.w 2 dc.b $F4, $A, 0,$A2,$FF,$F4 dc.b $DC, $A, 0,$AB,$FF,$F4 Frame_362166: dc.w 2 dc.b $F4, $A, 0,$A2,$FF,$F4 dc.b $DC, $A, 0,$B4,$FF,$F4 Frame_362174: dc.w 1 dc.b $F8, 5, 0,$BD,$FF,$F8 Frame_36217C: dc.w 1 dc.b $FC, 4, 0,$C1,$FF,$F8 Frame_362184: dc.w 1 dc.b $FC, 0, 0,$C3,$FF,$FC Frame_36218C: dc.w 8 dc.b $E0, $F, 0,$C4,$FF,$E0 dc.b $E8, 2, 0,$D4,$FF,$D8 dc.b 0, $D, 0,$13,$FF,$E0 dc.b $10, 9, 0,$1B,$FF,$E8 dc.b $E0, $F, 8,$C4, 0, 0 dc.b $E8, 2, 8,$D4, 0,$20 dc.b 0, $D, 8,$13, 0, 0 dc.b $10, 9, 8,$1B, 0, 0 Frame_3621BE: dc.w 8 dc.b $E0, $F, 0,$D7,$FF,$E0 dc.b $E8, 2, 0,$E7,$FF,$D8 dc.b 0, $D, 0,$13,$FF,$E0 dc.b $10, 9, 0,$1B,$FF,$E8 dc.b $E0, $F, 8,$D7, 0, 0 dc.b $E8, 2, 8,$E7, 0,$20 dc.b 0, $D, 8,$13, 0, 0 dc.b $10, 9, 8,$1B, 0, 0 Frame_3621F0: dc.w 8 dc.b $E0, $F, 0,$EA,$FF,$E0 dc.b $E8, 2, 0,$FA,$FF,$D8 dc.b 0, $D, 0,$13,$FF,$E0 dc.b $10, 9, 0,$1B,$FF,$E8 dc.b $E0, $F, 8,$EA, 0, 0 dc.b $E8, 2, 8,$FA, 0,$20 dc.b 0, $D, 8,$13, 0, 0 dc.b $10, 9, 8,$1B, 0, 0 Frame_362222: dc.w 5 dc.b $F4, 2, 0,$FD,$FF,$DC dc.b $EC, $F, 1, 0,$FF,$E4 dc.b $EC, $F, 1,$10, 0, 4 dc.b $C, $C, 0,$34,$FF,$E4 dc.b $C, $C, 0,$48, 0, 4 Frame_362242: dc.w 5 dc.b $F4, 2, 1,$20,$FF,$DC dc.b $EC, $F, 1,$23,$FF,$E4 dc.b $EC, $F, 1,$33, 0, 4 dc.b $C, $C, 0,$34,$FF,$E4 dc.b $C, $C, 0,$48, 0, 4 Frame_362262: dc.w 5 dc.b $F4, 2, 1,$43,$FF,$DC dc.b $EC, $F, 1,$46,$FF,$E4 dc.b $EC, $F, 1,$56, 0, 4 dc.b $C, $C, 0,$34,$FF,$E4 dc.b $C, $C, 0,$48, 0, 4 Frame_362282: dc.w 2 dc.b $F0, $B, 1,$66,$FF,$E8 dc.b $F0, $B, 9,$66, 0, 0 Frame_362290: dc.w 2 dc.b $F0, $B, 1,$72,$FF,$E8 dc.b $F0, $B, 9,$72, 0, 0 Frame_36229E: dc.w 2 dc.b $F0, $A, 1,$7E,$FF,$E8 dc.b $F0, $A, 9,$7E, 0, 0 Frame_3622AC: dc.w $14 dc.b $B8, $F, 1,$87,$FF,$EC dc.b $B8, 3, 1,$97, 0, $C dc.b $D8, $C, 1,$9B,$FF,$EC dc.b $D8, 0, 1,$9F, 0, $C dc.b $C0, $F, 1,$87,$FF,$E0 dc.b $C0, 3, 1,$97, 0, 0 dc.b $E0, $C, 1,$9B,$FF,$E0 dc.b $E0, 0, 1,$9F, 0, 0 dc.b $C0, $F, 1,$87,$FF,$F8 dc.b $C0, 3, 1,$97, 0,$18 dc.b $E0, $C, 1,$9B,$FF,$F8 dc.b $E0, 0, 1,$9F, 0,$18 dc.b $D8, $F, 1,$87,$FF,$D0 dc.b $D8, 3, 1,$97,$FF,$F0 dc.b $F8, $C, 1,$9B,$FF,$D0 dc.b $F8, 0, 1,$9F,$FF,$F0 dc.b $D8, $F, 1,$87, 0, 8 dc.b $D8, 3, 1,$97, 0,$28 dc.b $F8, $C, 1,$9B, 0, 8 dc.b $F8, 0, 1,$9F, 0,$28 Frame_362326: dc.w 3 dc.b $F4, $E, 1,$A0,$FF,$F0 dc.b $E7, $D, 1,$AC,$FF,$F8 dc.b $F7, 0, 1,$B4, 0, 8 Frame_36233A: dc.w 3 dc.b $F4, $E, 1,$A0,$FF,$F0 dc.b $E7, $D, 1,$B5,$FF,$F8 dc.b $F7, 0, 1,$BD, 0, 8 Frame_36234E: dc.w 3 dc.b $F4, $E, 1,$A0,$FF,$F0 dc.b $E7, $D, 1,$BE,$FF,$F8 dc.b $F7, 4, 1,$C6, 0, 8 Frame_362362: dc.w 3 dc.b $F4, $E, 1,$A0,$FF,$F0 dc.b $E7, $D, 1,$C8,$FF,$F8 dc.b $F7, 4, 1,$D0, 0, 8 Frame_362376: dc.w 3 dc.b $F4, 2, 0,$21,$FF,$DC dc.b $EC, $F, 0,$24,$FF,$E4 dc.b $C, $C, 0,$34,$FF,$E4 Frame_36238A: dc.w 0 Frame_36238C: dc.w $10 dc.b $C8, $F, 1,$87,$FF,$E0 dc.b $C8, 3, 1,$97, 0, 0 dc.b $E8, $C, 1,$9B,$FF,$E0 dc.b $E8, 0, 1,$9F, 0, 0 dc.b $C8, $F, 1,$87,$FF,$F8 dc.b $C8, 3, 1,$97, 0,$18 dc.b $E8, $C, 1,$9B,$FF,$F8 dc.b $E8, 0, 1,$9F, 0,$18 dc.b $E0, $F, 1,$87,$FF,$D0 dc.b $E0, 3, 1,$97,$FF,$F0 dc.b 0, $C, 1,$9B,$FF,$D0 dc.b 0, 0, 1,$9F,$FF,$F0 dc.b $E0, $F, 1,$87, 0, 8 dc.b $E0, 3, 1,$97, 0,$28 dc.b 0, $C, 1,$9B, 0, 8 dc.b 0, 0, 1,$9F, 0,$28 Frame_3623EE: dc.w 2 dc.b $F4, $A,$10,$80,$FF,$F4 dc.b $F4, $A,$10,$89, 0, $C Frame_3623FC: dc.w 2 dc.b $F4, $A,$10,$80,$FF,$F4 dc.b $F4, $A,$10,$92, 0, $C Frame_36240A: dc.w 2 dc.b $F4, $A, 0,$A2,$FF,$F4 dc.b $DC, $A, 0,$AB,$FF,$F4 Frame_362418: dc.w 2 dc.b $F4, $A, 0,$A2,$FF,$F4 dc.b $DC, $A, 0,$B4,$FF,$F4 Frame_362426: dc.w $14 dc.b $B8, $F, 1,$D2,$FF,$EC dc.b $B8, 3, 1,$E2, 0, $C dc.b $D8, $C, 1,$E6,$FF,$EC dc.b $D8, 0, 1,$EA, 0, $C dc.b $C0, $F, 1,$D2,$FF,$E0 dc.b $C0, 3, 1,$E2, 0, 0 dc.b $E0, $C, 1,$E6,$FF,$E0 dc.b $E0, 0, 1,$EA, 0, 0 dc.b $C0, $F, 1,$D2,$FF,$F8 dc.b $C0, 3, 1,$E2, 0,$18 dc.b $E0, $C, 1,$E6,$FF,$F8 dc.b $E0, 0, 1,$EA, 0,$18 dc.b $D8, $F, 1,$D2,$FF,$D8 dc.b $D8, 3, 1,$E2,$FF,$F8 dc.b $F8, $C, 1,$E6,$FF,$D8 dc.b $F8, 0, 1,$EA,$FF,$F8 dc.b $D8, $F, 1,$D2, 0, 0 dc.b $D8, 3, 1,$E2, 0,$20 dc.b $F8, $C, 1,$E6, 0, 0 dc.b $F8, 0, 1,$EA, 0,$20 Frame_3624A0: dc.w 1 dc.b $F0, $F, 0, 0,$FF,$F0 Frame_3624A8: dc.w 1 dc.b $F0, $F, 8, 0,$FF,$F0 Frame_3624B0: dc.w 1 dc.b $F8, $D, 0,$13,$FF,$F0 Frame_3624B8: dc.w 1 dc.b $F8, $D, 8,$13,$FF,$F0 Frame_3624C0: dc.w 1 dc.b $F8, 9, 0,$1B,$FF,$F4 Frame_3624C8: dc.w 1 dc.b $F8, 9, 8,$1B,$FF,$F4
; A026059: a(n) = (d(n)-r(n))/5, where d = A026057 and r is the periodic sequence with fundamental period (1,0,3,1,0). ; 5,10,16,25,36,49,65,83,105,130,158,190,225,265,309,357,410,467,530,598,671,750,834,925,1022,1125,1235,1351,1475,1606,1744,1890,2043,2205,2375,2553,2740,2935,3140,3354,3577,3810,4052,4305,4568,4841,5125,5419,5725,6042,6370,6710,7061,7425,7801,8189,8590 mov $1,-3 mov $2,$0 mov $3,1 add $3,$0 mov $0,$3 mov $5,15 lpb $0 sub $0,1 add $1,1 add $3,$5 add $5,$1 lpe div $3,5 mov $1,$3 add $1,2 add $1,$2 mov $4,$2 mul $4,$2 add $1,$4
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # 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. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 4, 0x90 .globl y8_PurgeBlock .type y8_PurgeBlock, @function y8_PurgeBlock: movslq %esi, %rcx xor %rax, %rax sub $(8), %rcx jl .Ltest_purgegas_1 .Lpurge8gas_1: movq %rax, (%rdi) add $(8), %rdi sub $(8), %rcx jge .Lpurge8gas_1 .Ltest_purgegas_1: add $(8), %rcx jz .Lquitgas_1 .Lpurge1gas_1: movb %al, (%rdi) add $(1), %rdi sub $(1), %rcx jg .Lpurge1gas_1 .Lquitgas_1: ret .Lfe1: .size y8_PurgeBlock, .Lfe1-(y8_PurgeBlock)
; void *memccpy(void * restrict s1, const void * restrict s2, int c, size_t n) SECTION code_clib SECTION code_string PUBLIC memccpy EXTERN asm_memccpy memccpy: IF __CPU_INTEL__ | __CPU_GBZ80__ ld hl,sp+2 ld c,(hl) inc hl ld b,(hl) inc hl ld a,(hl) inc hl inc hl ld e,(hl) inc hl ld d,(hl) inc hl push de ld e,(hl) inc hl ld d,(hl) pop hl ELSE pop ix pop bc pop de ld a,e pop hl pop de push de push hl push de push bc push ix ENDIF IF __CLASSIC && __CPU_GBZ80__ call asm_memccpy ld d,h ld e,l ret ELSE jp asm_memccpy ENDIF ; SDCC bridge for Classic IF __CLASSIC PUBLIC _memccpy defc _memccpy = memccpy ENDIF
// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. // // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at // // https://opensource.org/licenses/BSD-3-Clause // // 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 "sigmoid_arm.h" #if __ARM_NEON #include "neon_mathfun.h" #include <arm_neon.h> #endif // __ARM_NEON #include <math.h> namespace ncnn { DEFINE_LAYER_CREATOR(Sigmoid_arm) Sigmoid_arm::Sigmoid_arm() { #if __ARM_NEON support_packing = true; #endif // __ARM_NEON support_bf16_storage = true; } int Sigmoid_arm::forward_inplace(Mat& bottom_top_blob, const Option& opt) const { if (opt.use_bf16_storage) return forward_inplace_bf16s(bottom_top_blob, opt); int w = bottom_top_blob.w; int h = bottom_top_blob.h; int channels = bottom_top_blob.c; int size = w * h; int elempack = bottom_top_blob.elempack; #if __ARM_NEON if (elempack == 4) { #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q < channels; q++) { float* ptr = bottom_top_blob.channel(q); float32x4_t _one = vdupq_n_f32(1.f); for (int i = 0; i < size; i++) { float32x4_t _p = vld1q_f32(ptr); _p = vnegq_f32(_p); _p = exp_ps(_p); _p = vaddq_f32(_p, _one); float32x4_t _outp = vrecpeq_f32(_p); _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); // _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); vst1q_f32(ptr, _outp); ptr += 4; } } return 0; } #endif // __ARM_NEON #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q < channels; q++) { float* ptr = bottom_top_blob.channel(q); #if __ARM_NEON int nn = size >> 2; int remain = size - (nn << 2); #else int remain = size; #endif // __ARM_NEON #if __ARM_NEON float32x4_t _one = vdupq_n_f32(1.f); for (; nn > 0; nn--) { float32x4_t _p = vld1q_f32(ptr); _p = vnegq_f32(_p); _p = exp_ps(_p); _p = vaddq_f32(_p, _one); float32x4_t _outp = vrecpeq_f32(_p); _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); // _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); vst1q_f32(ptr, _outp); ptr += 4; } #endif // __ARM_NEON for (; remain > 0; remain--) { *ptr = 1.f / (1.f + exp(-*ptr)); ptr++; } } return 0; } int Sigmoid_arm::forward_inplace_bf16s(Mat& bottom_top_blob, const Option& opt) const { int w = bottom_top_blob.w; int h = bottom_top_blob.h; int channels = bottom_top_blob.c; int size = w * h; int elempack = bottom_top_blob.elempack; #if __ARM_NEON if (elempack == 4) { #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q < channels; q++) { unsigned short* ptr = bottom_top_blob.channel(q); float32x4_t _one = vdupq_n_f32(1.f); for (int i = 0; i < size; i++) { float32x4_t _p = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(ptr), 16)); _p = vnegq_f32(_p); _p = exp_ps(_p); _p = vaddq_f32(_p, _one); float32x4_t _outp = vrecpeq_f32(_p); _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); // _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); vst1_u16(ptr, vshrn_n_u32(vreinterpretq_u32_f32(_outp), 16)); ptr += 4; } } return 0; } #endif // __ARM_NEON #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q < channels; q++) { unsigned short* ptr = bottom_top_blob.channel(q); #if __ARM_NEON int nn = size >> 2; int remain = size - (nn << 2); #else int remain = size; #endif // __ARM_NEON #if __ARM_NEON float32x4_t _one = vdupq_n_f32(1.f); for (; nn > 0; nn--) { float32x4_t _p = vreinterpretq_f32_u32(vshll_n_u16(vld1_u16(ptr), 16)); _p = vnegq_f32(_p); _p = exp_ps(_p); _p = vaddq_f32(_p, _one); float32x4_t _outp = vrecpeq_f32(_p); _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); // _outp = vmulq_f32(vrecpsq_f32(_p, _outp), _outp); vst1_u16(ptr, vshrn_n_u32(vreinterpretq_u32_f32(_outp), 16)); ptr += 4; } #endif // __ARM_NEON for (; remain > 0; remain--) { float v = bfloat16_to_float32(*ptr); v = 1.f / (1.f + exp(-v)); *ptr = float32_to_bfloat16(v); ptr++; } } return 0; } } // namespace ncnn
; A131466: a(n) = 5n^4 - 4n^3 + 3n^2 - 2n + 1. ; 1,3,57,319,1065,2691,5713,10767,18609,30115,46281,68223,97177,134499,181665,240271,312033,398787,502489,625215,769161,936643,1130097,1352079,1605265,1892451,2216553,2580607,2987769,3441315,3944641,4501263,5114817,5789059,6527865,7335231,8215273,9172227,10210449,11334415,12548721,13858083,15267337,16781439,18405465,20144611,22004193,23989647,26106529,28360515,30757401,33303103,36003657,38865219,41894065,45096591,48479313,52048867,55812009,59775615,63946681,68332323,72939777,77776399,82849665,88167171,93736633,99565887,105662889,112035715,118692561,125641743,132891697,140450979,148328265,156532351,165072153,173956707,183195169,192796815,202771041,213127363,223875417,235024959,246585865,258568131,270981873,283837327,297144849,310914915,325158121,339885183,355106937,370834339,387078465,403850511,421161793,439023747,457447929,476446015,496029801,516211203,537002257,558415119,580462065,603155491,626507913,650531967,675240409,700646115,726762081,753601423,781177377,809503299,838592665,868459071,899116233,930577987,962858289,995971215,1029930961,1064751843,1100448297,1137034879,1174526265,1212937251,1252282753,1292577807,1333837569,1376077315,1419312441,1463558463,1508831017,1555145859,1602518865,1650966031,1700503473,1751147427,1802914249,1855820415,1909882521,1965117283,2021541537,2079172239,2138026465,2198121411,2259474393,2322102847,2386024329,2451256515,2517817201,2585724303,2654995857,2725650019,2797705065,2871179391,2946091513,3022460067,3100303809,3179641615,3260492481,3342875523,3426809977,3512315199,3599410665,3688115971,3778450833,3870435087,3964088689,4059431715,4156484361,4255266943,4355799897,4458103779,4562199265,4668107151,4775848353,4885443907,4996914969,5110282815,5225568841,5342794563,5461981617,5583151759,5706326865,5831528931,5958780073,6088102527,6219518649,6353050915,6488721921,6626554383,6766571137,6908795139,7053249465,7199957311,7348941993,7500226947,7653835729,7809792015,7968119601,8128842403,8291984457,8457569919,8625623065,8796168291,8969230113,9144833167,9323002209,9503762115,9687137881,9873154623,10061837577,10253212099,10447303665,10644137871,10843740433,11046137187,11251354089,11459417215,11670352761,11884187043,12100946497,12320657679,12543347265,12769042051,12997768953,13229555007,13464427369,13702413315,13943540241,14187835663,14435327217,14686042659,14940009865,15197256831,15457811673,15721702627,15988958049,16259606415,16533676321,16811196483,17092195737,17376703039,17664747465,17956358211,18251564593,18550396047,18852882129,19159052515 mov $4,$0 bin $0,2 mov $3,$0 mul $0,4 mov $1,2 mov $2,8 sub $4,$3 pow $3,2 add $4,$0 div $0,2 add $0,1 add $2,$0 sub $3,2 pow $4,2 add $3,$4 add $3,$2 mul $3,9 add $1,$3 sub $1,65 div $1,9 mul $1,2 add $1,1
; A313475: Coordination sequence Gal.6.119.5 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,5,10,14,18,22,26,30,34,38,43,48,53,58,62,66,70,74,78,82,86,91,96,101,106,110,114,118,122,126,130,134,139,144,149,154,158,162,166,170,174,178,182,187,192,197,202,206,210,214 mov $2,$0 mov $3,4 mov $5,$0 add $0,2 mov $1,$2 mov $4,$0 lpb $0 add $1,1 add $3,$4 add $1,$3 sub $1,2 mov $3,7 sub $4,1 trn $4,3 mov $0,$4 sub $1,6 trn $1,$4 trn $4,7 lpe lpb $5 add $1,3 sub $5,1 lpe add $1,1
; Network stuff for racing game CARD_MAC dc.b $00,$80,$10,$0c,$64,$01 CARD_IP dc.b 192,168,1,64 CARD_MASK dc.b 255,255,255,0 CARD_GATE dc.b 192,168,1,1 CARD_GATE_MAC dc.b $00,$00,$00,$00,$00,$00 SERVER_IP .byte 208,79,218,201 ; Public SERVER_IP_LAN .byte 192,168,7,100 ; Private ; Default, overwritten by ARP SERVER_MAC .byte $01,$02,$03,$04,$05,$06 USER_UDP_PORT = 3000 UDP_DATA_IN equ INPACKET+$2A ; Beginning of UDP data buffer ;Various Flags... PACKET_RECEIVED ; Flag for incoming data .byte $00 NETSETUPFINISHED .byte $00 NETWORK_TIMEOUT ; Reset by packet receive. ; If this goes above a threshold, means no data received .byte $00 NET_TIMEDOUT ; Flag for main game loop .byte $00 NET_FAILED .byte $00 ;---------------------------------------------------------------- ; Called from main program NETWORK_SETUP PRINT CG_RED ; Basic card initialization jsr net_init ; Carry set if failed bcc UDPSETUP ;Failed jsr getanykey lda #$01 sta NET_FAILED jmp NETWORK_SETUP_x UDPSETUP ; UDP Setup lda #<3000 ; This doesn't have to match USER_UDP_PORT, but it does ldx #>3000 jsr UDP_SET_SRC_PORT lda #<3002 ldx #>3002 jsr UDP_SET_DEST_PORT lda #<SERVER_IP ldx #>SERVER_IP jsr UDP_SET_DEST_IP NETWORK_SETUP_x lda #$00 sta PACKET_RECEIVED rts ; ------------------------------------------------------------------------- ; Called from IRQ NETWORK_UPDATE jsr NETIRQ lda NETSETUPFINISHED beq NETWORK_UPDATEx lda NET_FAILED bne NETWORK_UPDATEx jsr SENDUPDATE ;Network timeouts lda NET_TIMEDOUT ; Timeout in progress bne NTIMEOUT inc NETWORK_TIMEOUT lda NETWORK_TIMEOUT ; Packets are sent every 50 milliseconds (20/sec) ; This routine is called every ~17 ms (NTSC) ; If we go 30 calls (~0.5 seconds) without a packet, freeze game. cmp #30 ;Decimal blt NETWORK_UPDATEx lda #$01 sta NET_TIMEDOUT lda #$00 sta PACKET_RECEIVED jsr NTIMEOUT NETWORK_UPDATEx rts NTIMEOUT lda #$02 sta $d020 jsr SOUND_TIMEOUT lda PACKET_RECEIVED beq NTIMEOUT_x ; No packet yet lda #$00 sta $d020 sta NET_TIMEDOUT NTIMEOUT_x rts ; ------------------------------------------------------------------------- ; Get Gateway MAC ; ------------------------------------------------------------------------- ;Only get gateway MAC if the opponent's not on the local subnet GATEWAYMAC lda #<UDP_DEST_IP ldx #>UDP_DEST_IP jsr IPMASK bcc MAC_SKIP PRINT CRLF,"RESOLVING GATEWAY MAC..." jsr get_macs bcc MAC_OK ;Flag errors PRINT CRLF,CG_WHT,"ERROR RESOLVING THE GW MAC!",CRLF nomac jmp nomac ;Freeze MAC_OK PRINT "OK",CRLF MAC_SKIP rts ; ------------------------------------------------------------------------- ; Get Server MAC (LAN Mode only) ; ------------------------------------------------------------------------- SERVERMAC PRINT CRLF,"RESOLVING SERVER MAC..." ;get MAC for server lda #<SERVER_IP ldx #>SERVER_IP jsr GET_ARP bcs SMAC_FAILED ;copy gateway mac ldx #$00 gm1_0 lda ARP_MAC,x sta SERVER_MAC,x inx cpx #$06 bne gm1_0 jmp MAC_OK SMAC_FAILED PRINT CRLF,CG_WHT,"ERROR RESOLVING THE SERVER MAC!",CRLF nomac1 jmp nomac1 ;Freeze ; ------------------------------------------------------------------------- ; Packet Send Routine ; ------------------------------------------------------------------------- SENDUPDATE lda #$0e ; Including zero-term. and checksum ldx #$00 jsr UDP_SET_DATALEN ; Packet type lda #$00 ; Game update sta UDP_DATA ; X Position lda MYXPOS+1 ldx MYXPOS+2 ; High byte, TODO sta UDP_DATA+1 stx UDP_DATA+2 ; Y Position lda REALTRACKPOS+1 ldx REALTRACKPOS+2 sta UDP_DATA+3 stx UDP_DATA+4 ;X Speed (include fractional) lda MYX_SPEED ldx MYX_SPEED+1 sta UDP_DATA+5 stx UDP_DATA+6 ;Y Speed (include fractional) lda MY_SPEED ldx MY_SPEED+1 sta UDP_DATA+7 stx UDP_DATA+8 ;Car color lda sprite1color sta UDP_DATA+9 ;Sprite# lda sprite1pnt sta UDP_DATA+10 ; Send! jsr UDP_SEND rts ; ------------------------------------------------------------------------- ; Packet Receive + Handling Routines ; ------------------------------------------------------------------------- ; Temporary holder of the checksum we received RCV_CSUM dc.b $ff ; ============================================================== ; Master packet receiver. This occurs inside the interrupt! ; A UDP packet has arrived, and the port matches the one we want. ; ============================================================== MYUDP_PROCESS SUBROUTINE ; Check checksum, and don't ack if bad ; jsr CHECKSUM ; jmp BADCSUM inc COMMSLED ; Reset timeout lda #$00 sta NETWORK_TIMEOUT ; Display sprites as commanded by the server ;-------------------------------------- ldx UDP_DATA_IN+1 ldy UDP_DATA_IN+3 stx sprite2x stx IN_XPOSLOW+1 sty sprite2y sty IN_YPOS+1 lda UDP_DATA_IN+5 sta IN_XSPEEDLOW+1 lda UDP_DATA_IN+6 sta IN_XSPEEDHIGH+1 lda UDP_DATA_IN+7 sta IN_YSPEEDLOW+1 lda UDP_DATA_IN+8 sta IN_YSPEEDHIGH+1 lda UDP_DATA_IN+9 sta sprite2color lda UDP_DATA_IN+10 sta sprite2pnt ;-------------------------------------- ldx UDP_DATA_IN+13 ldy UDP_DATA_IN+15 stx sprite3x stx IN_XPOSLOW+2 sty sprite3y sty IN_YPOS+2 lda UDP_DATA_IN+17 sta IN_XSPEEDLOW+2 lda UDP_DATA_IN+18 sta IN_XSPEEDHIGH+2 lda UDP_DATA_IN+19 sta IN_YSPEEDLOW+2 lda UDP_DATA_IN+20 sta IN_YSPEEDHIGH+2 lda UDP_DATA_IN+21 sta sprite3color lda UDP_DATA_IN+22 sta sprite3pnt ;-------------------------------------- ldx UDP_DATA_IN+25 ldy UDP_DATA_IN+27 stx sprite4x stx IN_XPOSLOW+3 sty sprite4y sty IN_YPOS+3 lda UDP_DATA_IN+29 sta IN_XSPEEDLOW+3 lda UDP_DATA_IN+30 sta IN_XSPEEDHIGH+3 lda UDP_DATA_IN+31 sta IN_YSPEEDLOW+3 lda UDP_DATA_IN+32 sta IN_YSPEEDHIGH+3 lda UDP_DATA_IN+33 sta sprite4color lda UDP_DATA_IN+34 sta sprite4pnt ;-------------------------------------- ldx UDP_DATA_IN+37 ldy UDP_DATA_IN+39 stx sprite5x stx IN_XPOSLOW+4 sty sprite5y sty IN_YPOS+4 lda UDP_DATA_IN+41 sta IN_XSPEEDLOW+4 lda UDP_DATA_IN+42 sta IN_XSPEEDHIGH+4 lda UDP_DATA_IN+43 sta IN_YSPEEDLOW+4 lda UDP_DATA_IN+44 sta IN_YSPEEDHIGH+4 lda UDP_DATA_IN+45 sta sprite5color lda UDP_DATA_IN+46 sta sprite5pnt ;-------------------------------------- ldx UDP_DATA_IN+49 ldy UDP_DATA_IN+51 stx sprite6x stx IN_XPOSLOW+5 sty sprite6y sty IN_YPOS+5 lda UDP_DATA_IN+53 sta IN_XSPEEDLOW+5 lda UDP_DATA_IN+54 sta IN_XSPEEDHIGH+5 lda UDP_DATA_IN+55 sta IN_YSPEEDLOW+5 lda UDP_DATA_IN+56 sta IN_YSPEEDHIGH+5 lda UDP_DATA_IN+57 sta sprite6color lda UDP_DATA_IN+58 sta sprite6pnt ;-------------------------------------- ldx UDP_DATA_IN+61 ldy UDP_DATA_IN+63 stx sprite7x stx IN_XPOSLOW+6 sty sprite7y sty IN_YPOS+6 lda UDP_DATA_IN+65 sta IN_XSPEEDLOW+6 lda UDP_DATA_IN+66 sta IN_XSPEEDHIGH+6 lda UDP_DATA_IN+67 sta IN_YSPEEDLOW+6 lda UDP_DATA_IN+68 sta IN_YSPEEDHIGH+6 lda UDP_DATA_IN+69 sta sprite7color lda UDP_DATA_IN+70 sta sprite7pnt ;-------------------------------------- ldx UDP_DATA_IN+73 ldy UDP_DATA_IN+75 stx sprite8x stx IN_XPOSLOW+7 sty sprite8y sty IN_YPOS+7 lda UDP_DATA_IN+77 sta IN_XSPEEDLOW+7 lda UDP_DATA_IN+78 sta IN_XSPEEDHIGH+7 lda UDP_DATA_IN+79 sta IN_YSPEEDLOW+7 lda UDP_DATA_IN+80 sta IN_YSPEEDHIGH+7 lda UDP_DATA_IN+81 sta sprite8color lda UDP_DATA_IN+82 sta sprite8pnt ;now, calculate MSB for sprites lda #0 ldx UDP_DATA_IN+2 stx IN_XPOSHIGH+1 beq .ahead1 ora #2 .ahead1 ldx UDP_DATA_IN+14 stx IN_XPOSHIGH+2 beq .ahead2 ora #4 .ahead2 ldx UDP_DATA_IN+26 stx IN_XPOSHIGH+3 beq .ahead3 ora #8 .ahead3 ldx UDP_DATA_IN+38 stx IN_XPOSHIGH+4 beq .ahead4 ora #16 .ahead4 ldx UDP_DATA_IN+50 stx IN_XPOSHIGH+5 beq .ahead5 ora #32 .ahead5 ldx UDP_DATA_IN+62 stx IN_XPOSHIGH+6 beq .ahead6 ora #64 .ahead6 ldx UDP_DATA_IN+74 stx IN_XPOSHIGH+7 beq .ahead7 ora #128 .ahead7 ;sta .self+1 ;lda $d010 ;and #1 ;.self ;ora #$ff ;self-mod! ;sta $d010 sta IN_XPOS_D010 ;-------------------------------------- MYUDP_PROCESS_x lda #$01 sta PACKET_RECEIVED rts ; ------------------------------------------------------------------------- ; Do Checksum here CHECKSUM ; lda INPACKET+???? ; A now holds the checksum we received ; sta RCV_CSUM ;Point x:a to start of received packet ;and calculate our own checksum ldx #<(INPACKET+$2A) lda #>(INPACKET+$2A) dey ; So we aren't including the checksum byte itself ; jsr DATACHECKSUM lda CSUM ;sta CSUM_SAVE lda RCV_CSUM cmp CSUM ; Zero bit now contains whether or not checksum matches, use bne/beq rts
BITS 32 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS= ;TEST_FILE_META_END ; NOT16r mov cx, 0x8 ;TEST_BEGIN_RECORDING not cx ;TEST_END_RECORDING
// Copyright John Maddock 2007. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // Note that this file contains quickbook mark-up as well as code // and comments, don't change any of the special comment mark-ups! #include <iostream> //[policy_eg_9 /*` The previous example was all well and good, but the custom error handlers didn't really do much of any use. In this example we'll implement all the custom handlers and show how the information provided to them can be used to generate nice formatted error messages. Each error handler has the general form: template <class T> T user_``['error_type]``( const char* function, const char* message, const T& val); and accepts three arguments: [variablelist [[const char* function] [The name of the function that raised the error, this string contains one or more %1% format specifiers that should be replaced by the name of type T.]] [[const char* message] [A message associated with the error, normally this contains a %1% format specifier that should be replaced with the value of ['value]: however note that overflow and underflow messages do not contain this %1% specifier (since the value of ['value] is immaterial in these cases).]] [[const T& value] [The value that caused the error: either an argument to the function if this is a domain or pole error, the tentative result if this is a denorm or evaluation error, or zero or infinity for underflow or overflow errors.]] ] As before we'll include the headers we need first: */ #include <iostream> #include <boost/math/special_functions.hpp> /*` Next we'll implement the error handlers for each type of error, starting with domain errors: */ namespace boost{ namespace math{ namespace policies{ template <class T> T user_domain_error(const char* function, const char* message, const T& val) { /*` We'll begin with a bit of defensive programming: */ if(function == 0) function = "Unknown function with arguments of type %1%"; if(message == 0) message = "Cause unknown with bad argument %1%"; /*` Next we'll format the name of the function with the name of type T: */ std::string msg("Error in function "); msg += (boost::format(function) % typeid(T).name()).str(); /*` Then likewise format the error message with the value of parameter /val/, making sure we output all the digits of /val/: */ msg += ": \n"; int prec = 2 + (std::numeric_limits<T>::digits * 30103UL) / 100000UL; msg += (boost::format(message) % boost::io::group(std::setprecision(prec), val)).str(); /*` Now we just have to do something with the message, we could throw an exception, but for the purposes of this example we'll just dump the message to std::cerr: */ std::cerr << msg << std::endl; /*` Finally the only sensible value we can return from a domain error is a NaN: */ return std::numeric_limits<T>::quiet_NaN(); } /*` Pole errors are essentially a special case of domain errors, so in this example we'll just return the result of a domain error: */ template <class T> T user_pole_error(const char* function, const char* message, const T& val) { return user_domain_error(function, message, val); } /*` Overflow errors are very similar to domain errors, except that there's no %1% format specifier in the /message/ parameter: */ template <class T> T user_overflow_error(const char* function, const char* message, const T& val) { if(function == 0) function = "Unknown function with arguments of type %1%"; if(message == 0) message = "Result of function is too large to represent"; std::string msg("Error in function "); msg += (boost::format(function) % typeid(T).name()).str(); msg += ": \n"; msg += message; std::cerr << msg << std::endl; // Value passed to the function is an infinity, just return it: return val; } /*` Underflow errors are much the same as overflow: */ template <class T> T user_underflow_error(const char* function, const char* message, const T& val) { if(function == 0) function = "Unknown function with arguments of type %1%"; if(message == 0) message = "Result of function is too small to represent"; std::string msg("Error in function "); msg += (boost::format(function) % typeid(T).name()).str(); msg += ": \n"; msg += message; std::cerr << msg << std::endl; // Value passed to the function is zero, just return it: return val; } /*` Denormalised results are much the same as underflow: */ template <class T> T user_denorm_error(const char* function, const char* message, const T& val) { if(function == 0) function = "Unknown function with arguments of type %1%"; if(message == 0) message = "Result of function is denormalised"; std::string msg("Error in function "); msg += (boost::format(function) % typeid(T).name()).str(); msg += ": \n"; msg += message; std::cerr << msg << std::endl; // Value passed to the function is denormalised, just return it: return val; } /*` Which leaves us with evaluation errors, these occur when an internal error occurs that prevents the function being fully evaluated. The parameter /val/ contains the closest approximation to the result found so far: */ template <class T> T user_evaluation_error(const char* function, const char* message, const T& val) { if(function == 0) function = "Unknown function with arguments of type %1%"; if(message == 0) message = "An internal evaluation error occured with " "the best value calculated so far of %1%"; std::string msg("Error in function "); msg += (boost::format(function) % typeid(T).name()).str(); msg += ": \n"; int prec = 2 + (std::numeric_limits<T>::digits * 30103UL) / 100000UL; msg += (boost::format(message) % boost::io::group(std::setprecision(prec), val)).str(); std::cerr << msg << std::endl; // What do we return here? This is generally a fatal error, // that should never occur, just return a NaN for the purposes // of the example: return std::numeric_limits<T>::quiet_NaN(); } }}} // namespaces /*` Now we'll need to define a suitable policy that will call these handlers, and define some forwarding functions that make use of the policy: */ namespace{ using namespace boost::math::policies; typedef policy< domain_error<user_error>, pole_error<user_error>, overflow_error<user_error>, underflow_error<user_error>, denorm_error<user_error>, evaluation_error<user_error> > user_error_policy; BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(user_error_policy) } // close unnamed namespace /*` We now have a set of forwarding functions defined in an unnamed namespace that all look something like this: `` template <class RealType> inline typename boost::math::tools::promote_args<RT>::type tgamma(RT z) { return boost::math::tgamma(z, user_error_policy()); } `` So that when we call `tgamma(z)` we really end up calling `boost::math::tgamma(z, user_error_policy())`, and any errors will get directed to our own error handlers: */ int main() { // Raise a domain error: std::cout << "Result of erf_inv(-10) is: " << erf_inv(-10) << std::endl << std::endl; // Raise a pole error: std::cout << "Result of tgamma(-10) is: " << tgamma(-10) << std::endl << std::endl; // Raise an overflow error: std::cout << "Result of tgamma(3000) is: " << tgamma(3000) << std::endl << std::endl; // Raise an underflow error: std::cout << "Result of tgamma(-190.5) is: " << tgamma(-190.5) << std::endl << std::endl; // Unfortunately we can't predicably raise a denormalised // result, nor can we raise an evaluation error in this example // since these should never really occur! } /*` Which outputs: [pre Error in function boost::math::erf_inv<double>(double, double): Argument outside range \[-1, 1\] in inverse erf function (got p=-10). Result of erf_inv(-10) is: 1.#QNAN Error in function boost::math::tgamma<long double>(long double): Evaluation of tgamma at a negative integer -10. Result of tgamma(-10) is: 1.#QNAN Error in function boost::math::tgamma<long double>(long double): Result of tgamma is too large to represent. Error in function boost::math::tgamma<double>(double): Result of function is too large to represent Result of tgamma(3000) is: 1.#INF Error in function boost::math::tgamma<long double>(long double): Result of tgamma is too large to represent. Error in function boost::math::tgamma<long double>(long double): Result of tgamma is too small to represent. Result of tgamma(-190.5) is: 0 ] Notice how some of the calls result in an error handler being called more than once, or for more than one handler to be called: this is an artefact of the fact that many functions are implemented in terms of one or more sub-routines each of which may have it's own error handling. For example `tgamma(-190.5)` is implemented in terms of `tgamma(190.5)` - which overflows - the reflection formula for `tgamma` then notices that it's dividing by infinity and underflows. */ //]
* Sprite f9 section sprite xdef mes_f9 include 'dev8_keys_sysspr' mes_f9 dc.b 0,sp.f9 * end
/********************************************************************** * Copyright (c) 2008-2014, Alliance for Sustainable Energy. * All rights reserved. * * This library 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. * * This 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA **********************************************************************/ #ifndef ENERGYPLUS_GEOMETRYTRANSLATOR_HPP #define ENERGYPLUS_GEOMETRYTRANSLATOR_HPP #include "EnergyPlusAPI.hpp" #include "../utilities/idf/Workspace.hpp" #include "../utilities/core/Logger.hpp" #include "../utilities/core/Enum.hpp" #include "../utilities/geometry/Transformation.hpp" #include "../utilities/geometry/Point3d.hpp" namespace openstudio { namespace energyplus { /** \class StartingVertexPosition * * \relates GeometryTranslator */ OPENSTUDIO_ENUM(StartingVertexPosition, ((UpperLeftCorner)) ((LowerLeftCorner)) ((UpperRightCorner)) ((LowerRightCorner))); /** \class VertexEntryDirection * * \relates GeometryTranslator */ OPENSTUDIO_ENUM(VertexEntryDirection, ((Counterclockwise)) ((Clockwise))); /** \class CoordinateSystem * * \relates GeometryTranslator */ OPENSTUDIO_ENUM(CoordinateSystem, ((Relative)) ((World)) ((Absolute))); /** \class CoordinateChange * * \relates GeometryTranslator */ OPENSTUDIO_ENUM(CoordinateChange, ((RelativeToAbsolute)) ((AbsoluteToRelative)) ((NoChange))); /// test equality of coordinate systems ENERGYPLUS_API bool equal(const CoordinateSystem& left, const CoordinateSystem& right); /* Translates EnergyPlus simulation input geometry between various coordinate systems and * changes simple geometry to detailed geometry. * * All geometry in the OpenStudio Building Model is expressed in relative coordinates using * the UpperLeftCorner, CounterClockWise convention. * */ class ENERGYPLUS_API GeometryTranslator { public: /// constructor with an EnergyPlus Workspace GeometryTranslator(const openstudio::Workspace& workspace); /// convert workspace to given coordinate systems /// all geometry will be converted to upper-left-corner, counterclockwise /// all simple geometry will be converted to detailed geometry bool convert(const CoordinateSystem& detailedSystem, const CoordinateSystem& daylightingSystem); private: REGISTER_LOGGER("openstudio.energyplus.GeometryTranslator"); // private struct to hold GlobalGeometryRules struct GlobalGeometryRules{ StartingVertexPosition svp; VertexEntryDirection ved; CoordinateSystem detailedSystem; CoordinateSystem daylightingSystem; CoordinateSystem rectangularSystem; }; // get the current GlobalGeometryRules GlobalGeometryRules globalGeometryRules() const; // set the GlobalGeometryRules, only changes the object does not transform geometry bool setGlobalGeometryRules(const StartingVertexPosition& svp, const VertexEntryDirection& ved, const CoordinateSystem& detailedSystem, const CoordinateSystem& daylightingSystem, const CoordinateSystem& rectangularSystem); // get the transformation from building to world Transformation buildingTransformation() const; // get the transformation from zone to building Transformation zoneTransformation(const WorkspaceObject& zone) const; // convert simple shading to detailed in the current system bool convertSimpleShading(const CoordinateChange& coordChange); // convert simple subsurfaces to detailed in the current system bool convertSimpleSubSurfaces(); // convert simple surfaces to detailed in the current system bool convertSimpleSurfaces(const CoordinateChange& coordChange); // convert daylighting geometry from the current system to the new system bool convertDaylightingGeometry(const CoordinateChange& daylightingCoordChange); // convert detailed geometry from the current system to the new system bool convertDetailedGeometry(const CoordinateChange& detailedCoordChange); // reverse all detailed vertices bool reverseAllDetailedVertices(); // apply upper left corner rule to all detailed vertices bool applyUpperLeftCornerRule(); openstudio::Workspace m_workspace; }; /** Get vertices for a surface. \relates GeometryTranslator */ ENERGYPLUS_API openstudio::Point3dVector getVertices(unsigned firstVertex, const IdfObject& surface); /** Set vertices for a surface, only detailed surfaces are supported. \relates GeometryTranslator */ ENERGYPLUS_API bool setVertices(unsigned firstVertex, WorkspaceObject& surface, const openstudio::Point3dVector& vertices); /** Convert azimuth, tilt, starting x, y, z, length, and width to vertices * azimith and tilt are in degrees. \relates GeometryTranslator */ ENERGYPLUS_API openstudio::Point3dVector verticesForAzimuthTiltXYZLengthWidthOrHeight( double azimuth, double tilt, double x0, double y0, double z0, double length, double widthOrHeight); } // energyplus } // openstudio #endif // ENERGYPLUS_GEOMETRYTRANSLATOR_HPP
/** * @file sampsonDistance.cpp * @brief mex interface for cv::sampsonDistance * @ingroup calib3d * @author Amro * @date 2016 */ #include "mexopencv.hpp" #include "opencv2/calib3d.hpp" using namespace std; using namespace cv; /** * Main entry called from Matlab * @param nlhs number of left-hand-side arguments * @param plhs pointers to mxArrays in the left-hand-side * @param nrhs number of right-hand-side arguments * @param prhs pointers to mxArrays in the right-hand-side */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Check the number of arguments nargchk(nrhs==3 && nlhs<=1); // Argument vector vector<MxArray> rhs(prhs, prhs+nrhs); // Process Vec3d pt1(rhs[0].toVec<double,3>()), pt2(rhs[1].toVec<double,3>()); Matx33d F(rhs[2].toMatx<double,3,3>()); double sd = sampsonDistance(pt1, pt2, F); plhs[0] = MxArray(sd); }
//--------------------------------------------------------------------------- // Greenplum Database // Copyright (C) 2012 EMC Corp. // // @filename: // CXformInlineCTEConsumerUnderSelect.cpp // // @doc: // Implementation of transform //--------------------------------------------------------------------------- #include "gpos/base.h" #include "gpopt/xforms/CXformInlineCTEConsumerUnderSelect.h" #include "gpopt/xforms/CXformUtils.h" #include "gpopt/operators/CLogicalCTEConsumer.h" #include "gpopt/operators/CLogicalSelect.h" #include "gpopt/operators/CPatternTree.h" #include "gpopt/operators/CNormalizer.h" using namespace gpopt; //--------------------------------------------------------------------------- // @function: // CXformInlineCTEConsumerUnderSelect::CXformInlineCTEConsumerUnderSelect // // @doc: // Ctor // //--------------------------------------------------------------------------- CXformInlineCTEConsumerUnderSelect::CXformInlineCTEConsumerUnderSelect( CMemoryPool *mp) : CXformExploration(GPOS_NEW(mp) CExpression( mp, GPOS_NEW(mp) CLogicalSelect(mp), GPOS_NEW(mp) CExpression( mp, GPOS_NEW(mp) CLogicalCTEConsumer(mp)), // relational child GPOS_NEW(mp) CExpression(mp, GPOS_NEW(mp) CPatternTree(mp)) // predicate tree )) { } //--------------------------------------------------------------------------- // @function: // CXformInlineCTEConsumerUnderSelect::Exfp // // @doc: // Compute promise of xform // //--------------------------------------------------------------------------- CXform::EXformPromise CXformInlineCTEConsumerUnderSelect::Exfp(CExpressionHandle & //exprhdl ) const { return CXform::ExfpHigh; } //--------------------------------------------------------------------------- // @function: // CXformInlineCTEConsumerUnderSelect::Transform // // @doc: // Actual transformation // //--------------------------------------------------------------------------- void CXformInlineCTEConsumerUnderSelect::Transform(CXformContext *pxfctxt, CXformResult *pxfres, CExpression *pexpr) const { GPOS_ASSERT(NULL != pxfctxt); GPOS_ASSERT(FPromising(pxfctxt->Pmp(), this, pexpr)); GPOS_ASSERT(FCheckPattern(pexpr)); CExpression *pexprConsumer = (*pexpr)[0]; CExpression *pexprScalar = (*pexpr)[1]; CLogicalCTEConsumer *popConsumer = CLogicalCTEConsumer::PopConvert(pexprConsumer->Pop()); ULONG id = popConsumer->UlCTEId(); CCTEInfo *pcteinfo = COptCtxt::PoctxtFromTLS()->Pcteinfo(); // only continue if inlining is enabled or if this CTE has only 1 consumer if (!pcteinfo->FEnableInlining() && 1 < pcteinfo->UlConsumers(id)) { return; } // don't push down selects with a const true or false, in case we end up // with a select(1) (coming from the anchor) right on top of the consumer if (CUtils::FScalarConstTrue(pexprScalar) || CUtils::FScalarConstFalse(pexprScalar) || !CXformUtils::FInlinableCTE(id)) { return; } CMemoryPool *mp = pxfctxt->Pmp(); // inline consumer GPOS_ASSERT(NULL != popConsumer->Phmulcr()); CExpression *pexprInlinedConsumer = popConsumer->PexprInlined(); pexprInlinedConsumer->AddRef(); pexprScalar->AddRef(); CExpression *pexprSelect = CUtils::PexprLogicalSelect(mp, pexprInlinedConsumer, pexprScalar); CExpression *pexprNormalized = CNormalizer::PexprNormalize(mp, pexprSelect); pexprSelect->Release(); // add alternative to xform result pxfres->Add(pexprNormalized); } // EOF
// $OpenLDAP$ /* * Copyright 2000-2015 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ #include "debug.h" #include "LDAPEntry.h" #include "LDAPAsynConnection.h" #include "LDAPException.h" using namespace std; LDAPEntry::LDAPEntry(const LDAPEntry& entry){ DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry(&)" << endl); m_dn=entry.m_dn; m_attrs=new LDAPAttributeList( *(entry.m_attrs)); } LDAPEntry::LDAPEntry(const string& dn, const LDAPAttributeList *attrs){ DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl); DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl); if ( attrs ) m_attrs=new LDAPAttributeList(*attrs); else m_attrs=new LDAPAttributeList(); m_dn=dn; } LDAPEntry::LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg){ DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl); char* tmp=ldap_get_dn(ld->getSessionHandle(),msg); m_dn=string(tmp); ldap_memfree(tmp); m_attrs = new LDAPAttributeList(ld, msg); } LDAPEntry::~LDAPEntry(){ DEBUG(LDAP_DEBUG_DESTROY,"LDAPEntry::~LDAPEntry()" << endl); delete m_attrs; } LDAPEntry& LDAPEntry::operator=(const LDAPEntry& from){ m_dn = from.m_dn; delete m_attrs; m_attrs = new LDAPAttributeList( *(from.m_attrs)); return *this; } void LDAPEntry::setDN(const string& dn){ DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setDN()" << endl); DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " dn:" << dn << endl); m_dn=dn; } void LDAPEntry::setAttributes(LDAPAttributeList *attrs){ DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setAttributes()" << endl); DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " attrs:" << *attrs << endl); if (m_attrs != 0){ delete m_attrs; } m_attrs=attrs; } const string& LDAPEntry::getDN() const{ DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getDN()" << endl); return m_dn; } const LDAPAttributeList* LDAPEntry::getAttributes() const{ DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getAttributes()" << endl); return m_attrs; } const LDAPAttribute* LDAPEntry::getAttributeByName(const std::string& name) const { return m_attrs->getAttributeByName(name); } void LDAPEntry::addAttribute(const LDAPAttribute& attr) { m_attrs->addAttribute(attr); } void LDAPEntry::delAttribute(const std::string& type) { m_attrs->delAttribute(type); } void LDAPEntry::replaceAttribute(const LDAPAttribute& attr) { m_attrs->replaceAttribute(attr); } ostream& operator << (ostream& s, const LDAPEntry& le){ s << "DN: " << le.m_dn << ": " << *(le.m_attrs); return s; }
LDA #$37 ASL A OUT A LDA #$AB ASL A OUT A
; A120881: a(n) = number of k's, for 1 <= k <= n, where GCD(k,floor(n/k)) > 1. ; Submitted by Jon Maiga ; 0,0,0,1,1,0,0,2,3,2,2,2,2,1,1,4,4,4,4,5,4,3,3,5,6,5,7,8,8,3,3,7,7,6,6,8,8,7,6,9,9,6,6,7,9,8,8,11,12,12,12,13,13,14,13,15,14,13,13,11,11,10,11,16,16,12,12,13,13,10,10,15,15,14,15,16,16,13,13,17,20,19,19,18,18,17,17,20,20,17,17,18,17,16,16,21,21,21,23,26 mov $1,$0 seq $1,120882 ; a(n) is the number of k's, for 1 <= k <= n, where gcd(k,floor(n/k)) = 1. sub $0,$1 add $0,1
/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include <aws/devops-guru/model/TimestampMetricValuePair.h> #include <aws/core/utils/json/JsonSerializer.h> #include <utility> using namespace Aws::Utils::Json; using namespace Aws::Utils; namespace Aws { namespace DevOpsGuru { namespace Model { TimestampMetricValuePair::TimestampMetricValuePair() : m_timestampHasBeenSet(false), m_metricValue(0.0), m_metricValueHasBeenSet(false) { } TimestampMetricValuePair::TimestampMetricValuePair(JsonView jsonValue) : m_timestampHasBeenSet(false), m_metricValue(0.0), m_metricValueHasBeenSet(false) { *this = jsonValue; } TimestampMetricValuePair& TimestampMetricValuePair::operator =(JsonView jsonValue) { if(jsonValue.ValueExists("Timestamp")) { m_timestamp = jsonValue.GetDouble("Timestamp"); m_timestampHasBeenSet = true; } if(jsonValue.ValueExists("MetricValue")) { m_metricValue = jsonValue.GetDouble("MetricValue"); m_metricValueHasBeenSet = true; } return *this; } JsonValue TimestampMetricValuePair::Jsonize() const { JsonValue payload; if(m_timestampHasBeenSet) { payload.WithDouble("Timestamp", m_timestamp.SecondsWithMSPrecision()); } if(m_metricValueHasBeenSet) { payload.WithDouble("MetricValue", m_metricValue); } return payload; } } // namespace Model } // namespace DevOpsGuru } // namespace Aws
#ifndef FREESHOP_LOADINGSTATE_HPP #define FREESHOP_LOADINGSTATE_HPP #include "State.hpp" #include <cpp3ds/Graphics/Sprite.hpp> #include <cpp3ds/Graphics/Texture.hpp> #include <cpp3ds/System/Clock.hpp> #include <cpp3ds/Graphics/RectangleShape.hpp> #include <cpp3ds/Graphics/Text.hpp> namespace FreeShop { class LoadingState : public State { public: LoadingState(StateStack& stack, Context& context, StateCallback callback); virtual void renderTopScreen(cpp3ds::Window& window); virtual void renderBottomScreen(cpp3ds::Window& window); virtual bool update(float delta); virtual bool processEvent(const cpp3ds::Event& event); private: cpp3ds::RectangleShape m_background; cpp3ds::Text m_icon; cpp3ds::Clock m_rotateClock; }; } // namespace FreeShop #endif // FREESHOP_LOADINGSTATE_HPP
.data # Test String str: .asciiz "O +Genie, der# Herr ehre Dein 3Ego!-" tPalindrom: .asciiz "Palindrom" tNPalindrom: .asciiz "Kein " .text main: la $s0, str # lade Adresse von str in $s0 add $v0, $0, $0 # setze $v0 auf 0 finde_ende: # setzt $s0 auf Endadresse lb $s1, 0($s0) # lade erstes byte von str in $s1 beq $s1, $0, e_finde_ende # $s1 == \0 -> e_finde_ende addi $s0, $s0, 1 # $s0 += 1, inc. pointer in str j finde_ende # while jump e_finde_ende: # setzt $s1 auf Anfangsadresse subi $s0, $s0, 1 # $s0 -= 1 la $s1, str # lade adresse von str in $s1 lb $s5, ($s1) # $s5 = str[$s1] lb $s6, ($s0) # $s6 = str[$s0] jal erzwinge_grossschreibung # ziehe 32 ab wenn nötig testschleife: jal endetest # pointer überlaufen sich ? -> ende jal sonderzeichentest # testet auf sonderzeichen und verändert pointer entsprechend jal vergleich # vergleicht $s5 $s6, bricht ab bei differenz jal lPointer_inkr # linker Pointer inkr. jal rPointer_dekr # rechter Pointer dekr. j testschleife # while jump # Unterfunktionen endetest: # testet, ob programm fertig ist, da pointer sich "überlaufen" sub $t0, $s0, $s1 # $t0 = $s0 - $s1 blez $t0, p_ende_ja # $t0 <= 0 -> abbruch jr $ra lPointer_inkr: # inkrementiert linken pointer # ra sichern subi $sp, $sp, 4 sw $ra, 4($sp) addi $s1, $s1, 1 # $s1 += 1 jal endetest # teste ob pointer "überlaufen" lb $s5, ($s1) # $s5 = str[$s1] jal erzwinge_grossschreibung # erzwinge grossschreibung # ra wierderherstellen lw $ra, 4($sp) addi $sp, $sp, 4 jr $ra rPointer_dekr: # dekrementiert rechten pointer # ra sichern subi $sp, $sp, 4 sw $ra, 4($sp) subi $s0, $s0, 1 # $s0 -= 1 jal endetest # teste ob pointer "überlaufen" lb $s6, ($s0) # $s6 = str[$s0] jal erzwinge_grossschreibung # erzwinge grossschreibung # ra wierderherstellen lw $ra, 4($sp) addi $sp, $sp, 4 jr $ra erzwinge_grossschreibung: # zieht von $s5 & $s6 30 ab, falls nötig um kleinschreibung zu gewährleisten # ra sichern subi $sp, $sp, 4 sw $ra, 4($sp) sub $t2, $s5, 91 # $t2 = $s5 - 91 bgezal $t2, s5_abziehen # $t2 >= 0 -> s5_abziehen sub $t2, $s6, 91 # $t2 = $s6 - 91 bgezal $t2, s6_abziehen # $t2 >= 0 -> s6_abziehen # ra wierderherstellen lw $ra, 4($sp) addi $sp, $sp, 4 jr $ra s5_abziehen: # ziehe 32 von $s5 ab, x_i -> X_i, x_i in [a-z], X_i in [A-Z] sub $s5, $s5, 32 jr $ra s6_abziehen: # ziehe 32 von $s6 ab, x_i -> X_i, x_i in [a-z], X_i in [A-Z] sub $s6, $s6, 32 jr $ra sonderzeichentest: # testet rekursiv auf sonderzeichen und verändert pointer falls notwendig # ra sichern subi $sp, $sp, 4 sw $ra, 4($sp) # test linke seite subi $t3, $s5, 65 # $t3 = $s5 - 65, 'A' bgez $t3, groesser_unterende1 # $t3 >= 0 -> groesser_unterende1, $t3 >= 'A' jal lPointer_inkr # inkr linken pointer, da sonderzeichen jal sonderzeichentest # rekursiver aufruf, test neuer pointer groesser_unterende1: subi $t3, $s5, 90 # $t3 = $s5 - 90, 'Z' bltz $t3, kleiner_oberende1 # $t3 < 0 -> kleiner_oberende1, $t3 <= 'Z' jal lPointer_inkr # inkr linken pointer, da sonderzeichen jal sonderzeichentest # rekursiver aufruf, test neuer pointer kleiner_oberende1: # test rechte seite subi $t3, $s6, 65 # $t3 = $s5 - 65, 'A' bgez $t3, groesser_unterende2 # $t3 >= 0 -> groesser_unterende2, $t3 >= 'A' jal rPointer_dekr # dekr rechten pointer, da sonderzeichen jal sonderzeichentest # rekursiver aufruf, test neuer pointer groesser_unterende2: subi $t3, $s6, 90 # $t3 = $s5 - 90, 'Z' bltz $t3, kleiner_oberende2 # $t3 < 0 -> kleiner_oberende2, $t3 <= 'Z' jal rPointer_dekr # dekr rechten pointer, da sonderzeichen jal sonderzeichentest # rekursiver aufruf, test neuer pointer kleiner_oberende2: jal endetest # test ob pointer sich "überlaufen" -> ende # ra wierderherstellen lw $ra, 4($sp) addi $sp, $sp, 4 jr $ra vergleich: # vergleicht ob $s5 == $s6, bricht andernfalls ab sub $t8, $s5, $s6 # $t8 = $s5 - $s6 bnez $t8, p_ende_nein # $t8 != 0 -> p_ende_nein jr $ra # Ende-Print funktionen p_ende_nein: # print tNPalindrom, durchlauf zu p_ende_ja li $v0, 4 la $a0, tNPalindrom syscall p_ende_ja: # print tPalindrom li $v0, 4 la $a0, tPalindrom syscall
//-------------------------------------------------------------------------------------------------- // Copyright (c) YugaByte, Inc. // // 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. //-------------------------------------------------------------------------------------------------- // This file contains flag definitions that should be known to master, tserver, and pggate // (linked into postgres). #include <gflags/gflags.h> #include "yb/util/flag_tags.h" #include "yb/yql/pggate/pggate_flags.h" DEFINE_int32(pgsql_rpc_keepalive_time_ms, 0, "If an RPC connection from a client is idle for this amount of time, the server " "will disconnect the client. Setting flag to 0 disables this clean up."); TAG_FLAG(pgsql_rpc_keepalive_time_ms, advanced); DEFINE_int32(pggate_rpc_timeout_secs, 60, "Timeout for RPCs from pggate to YB cluster"); DEFINE_int32(pggate_ybclient_reactor_threads, 2, "The number of reactor threads to be used for processing ybclient " "requests originating in the PostgreSQL proxy server"); DEFINE_string(pggate_proxy_bind_address, "", "Address to which the PostgreSQL proxy server is bound."); DEFINE_string(pggate_master_addresses, "", "Addresses of the master servers to which the PostgreSQL proxy server connects."); DEFINE_int32(pggate_tserver_shm_fd, -1, "File descriptor of the local tablet server's shared memory."); DEFINE_test_flag(bool, pggate_ignore_tserver_shm, false, "Ignore the shared memory of the local tablet server."); DEFINE_int32(ysql_request_limit, 1024, "Maximum number of requests to be sent at once"); DEFINE_uint64(ysql_prefetch_limit, 1024, "Maximum number of rows to prefetch"); DEFINE_double(ysql_backward_prefetch_scale_factor, 0.0625 /* 1/16th */, "Scale factor to reduce ysql_prefetch_limit for backward scan"); DEFINE_int32(ysql_session_max_batch_size, 512, "Maximum batch size for buffered writes between PostgreSQL server and YugaByte DocDB " "services"); DEFINE_bool(ysql_non_txn_copy, false, "Execute COPY inserts non-transactionally."); DEFINE_int32(ysql_max_read_restart_attempts, 20, "How many read restarts can we try transparently before giving up"); DEFINE_test_flag(bool, ysql_disable_transparent_cache_refresh_retry, false, "Never transparently retry commands that fail with cache version mismatch error"); DEFINE_test_flag(int64, inject_delay_between_prepare_ybctid_execute_batch_ybctid_ms, 0, "Inject delay between creation and dispatch of RPC ops for testing"); DEFINE_test_flag(bool, index_read_multiple_partitions, false, "Test flag used to set only one partiton to the variable table_partitions_ while testing" "tablet splitting."); DEFINE_int32(ysql_output_buffer_size, 262144, "Size of postgres-level output buffer, in bytes. " "While fetched data resides within this buffer and hasn't been flushed to client yet, " "we're free to transparently restart operation in case of restart read error."); DEFINE_bool(ysql_enable_update_batching, true, "Whether to enable batching of updates where possible. Currently update batching is " "only supported for PGSQL procedures."); DEFINE_bool(ysql_suppress_unsupported_error, false, "Suppress ERROR on use of unsupported SQL statement and use WARNING instead"); DEFINE_int32(ysql_sequence_cache_minval, 100, "Set how many sequence numbers to be preallocated in cache."); // Top-level flag to enable all YSQL beta features. DEFINE_bool(ysql_beta_features, false, "Whether to enable all ysql beta features"); // Per-feature flags -- only relevant if ysql_beta_features is false. DEFINE_bool(ysql_beta_feature_tablegroup, true, "Whether to enable the incomplete 'tablegroup' ysql beta feature"); TAG_FLAG(ysql_beta_feature_tablegroup, hidden); DEFINE_bool(ysql_serializable_isolation_for_ddl_txn, false, "Whether to use serializable isolation for separate DDL-only transactions. " "By default, repeatable read isolation is used. " "This flag should go away once full transactional DDL is implemented."); DEFINE_int32(ysql_select_parallelism, -1, "Number of read requests to issue in parallel to tablets of a table " "for SELECT."); DEFINE_int32(ysql_max_write_restart_attempts, 20, "Max number of restart attempts made for writes on transaction conflicts."); DEFINE_bool(ysql_sleep_before_retry_on_txn_conflict, true, "Whether to sleep before retrying the write on transaction conflicts."); // Flag for disabling runContext to Postgres's portal. Currently, each portal has two contexts. // - PortalContext whose lifetime lasts for as long as the Portal object. // - TmpContext whose lifetime lasts until one associated row of SELECT result set is sent out. // // We add one more context "ybRunContext". // - Its lifetime will begin when PortalRun() is called to process a user statement request until // the end of the PortalRun() process. // - A SELECT might be queried in small batches, and each batch is processed by one call to // PortalRun(). The "ybRunContext" is used for values that are private to one batch. // - Use boolean experimental flag just in case introducing "ybRunContext" is a wrong idea. DEFINE_bool(ysql_disable_portal_run_context, false, "Whether to use portal ybRunContext."); DEFINE_bool(yb_enable_read_committed_isolation, false, "Defines how READ COMMITTED (which is our default SQL-layer isolation) and" "READ UNCOMMITTED are mapped internally. If false (default), both map to the stricter " "REPEATABLE READ implementation. If true, both use the new READ COMMITTED " "implementation instead.");
copyright zengfr site:http://github.com/zengfr/romhack 0106B6 move.b ($49,A2), D0 0106BA beq $106da [123p+ 49] 010876 move.b ($49,A2), D0 01087A beq $1089a [123p+ 49] 0108FA move.b ($49,A2), D0 0108FE beq $1095e [123p+ 49] 01092E move.b ($49,A2), D0 010932 beq $1095e [123p+ 49] 01098A move.b ($49,A2), D0 01098E beq $109ae [123p+ 49] 010D38 move.b ($49,A2), D0 010D3C beq $10dca [123p+ 49] 0119D2 move.b ($49,A2), D0 0119D6 beq $119f2 [123p+ 49] 011B00 move.b ($49,A2), D0 011B04 beq $11b24 [123p+ 49] copyright zengfr site:http://github.com/zengfr/romhack
; significant level values MAX_LEVEL EQU 100 MIN_LEVEL EQU 2 EGG_LEVEL EQU 5 ; maximum moves known per mon NUM_MOVES EQU 4 ; significant stat values BASE_STAT_LEVEL EQU 7 MAX_STAT_LEVEL EQU 13 ; turns that sleep lasts REST_SLEEP_TURNS EQU 2 TREEMON_SLEEP_TURNS EQU 7 ; default move priority BASE_PRIORITY EQU 1 ; type effectiveness factors, scaled by 10 SUPER_EFFECTIVE EQU 20 MORE_EFFECTIVE EQU 15 EFFECTIVE EQU 10 NOT_VERY_EFFECTIVE EQU 05 NO_EFFECT EQU 00 ; enemy AI behavior BASE_AI_SWITCH_SCORE EQU 10 ; wPlayerStatLevels and wEnemyStatLevels indexes (see wram.asm) ; GetStatName arguments (see data/battle/stat_names.asm) const_def const ATTACK const DEFENSE const SPEED const SP_ATTACK const SP_DEFENSE const ACCURACY const EVASION const ABILITY ; used for BattleCommand_Curse NUM_LEVEL_STATS EQU const_value ; move struct members (see data/moves/moves.asm) rsreset MOVE_ANIM rb ; 0 MOVE_EFFECT rb ; 1 MOVE_POWER rb ; 2 MOVE_TYPE rb ; 3 MOVE_ACC rb ; 4 MOVE_PP rb ; 5 MOVE_CHANCE rb ; 6 MOVE_LENGTH EQU _RS ; stat constants ; indexes for: ; - wPlayerStats and wEnemyStats (see wram.asm) ; - party_struct and battle_struct members (see macros/wram.asm) const_def 1 const STAT_HP const STAT_ATK const STAT_DEF const STAT_SPD const STAT_SATK NUM_EXP_STATS EQU const_value - 1 const STAT_SDEF NUM_STATS EQU const_value - 1 NUM_BATTLE_STATS EQU NUM_STATS - 1 ; don't count HP ; stat formula constants STAT_MIN_NORMAL EQU 5 STAT_MIN_HP EQU 10 MAX_STAT_VALUE EQU 999 ; shiny dvs ATKDEFDV_SHINY EQU $EA SPDSPCDV_SHINY EQU $AA ; battle classes (wBattleMode values) const_def 1 const WILD_BATTLE const TRAINER_BATTLE ; battle types (wBattleType values) const_def const BATTLETYPE_NORMAL const BATTLETYPE_CANLOSE const BATTLETYPE_DEBUG const BATTLETYPE_TUTORIAL const BATTLETYPE_FISH const BATTLETYPE_ROAMING const BATTLETYPE_CONTEST const BATTLETYPE_SHINY const BATTLETYPE_TREE const BATTLETYPE_TRAP const BATTLETYPE_FORCEITEM const BATTLETYPE_CELEBI const BATTLETYPE_SUICUNE ; BattleVarPairs indexes (see home/battle_vars.asm) const_def const BATTLE_VARS_SUBSTATUS1 const BATTLE_VARS_SUBSTATUS2 const BATTLE_VARS_SUBSTATUS3 const BATTLE_VARS_SUBSTATUS4 const BATTLE_VARS_SUBSTATUS5 const BATTLE_VARS_SUBSTATUS1_OPP const BATTLE_VARS_SUBSTATUS2_OPP const BATTLE_VARS_SUBSTATUS3_OPP const BATTLE_VARS_SUBSTATUS4_OPP const BATTLE_VARS_SUBSTATUS5_OPP const BATTLE_VARS_STATUS const BATTLE_VARS_STATUS_OPP const BATTLE_VARS_MOVE_ANIM const BATTLE_VARS_MOVE_EFFECT const BATTLE_VARS_MOVE_POWER const BATTLE_VARS_MOVE_TYPE const BATTLE_VARS_MOVE const BATTLE_VARS_LAST_COUNTER_MOVE const BATTLE_VARS_LAST_COUNTER_MOVE_OPP const BATTLE_VARS_LAST_MOVE const BATTLE_VARS_LAST_MOVE_OPP NUM_BATTLE_VARS EQU const_value ; BattleVarLocations indexes (see home/battle_vars.asm) const_def const PLAYER_SUBSTATUS_1 const ENEMY_SUBSTATUS_1 const PLAYER_SUBSTATUS_2 const ENEMY_SUBSTATUS_2 const PLAYER_SUBSTATUS_3 const ENEMY_SUBSTATUS_3 const PLAYER_SUBSTATUS_4 const ENEMY_SUBSTATUS_4 const PLAYER_SUBSTATUS_5 const ENEMY_SUBSTATUS_5 const PLAYER_STATUS const ENEMY_STATUS const PLAYER_MOVE_ANIMATION const ENEMY_MOVE_ANIMATION const PLAYER_MOVE_EFFECT const ENEMY_MOVE_EFFECT const PLAYER_MOVE_POWER const ENEMY_MOVE_POWER const PLAYER_MOVE_TYPE const ENEMY_MOVE_TYPE const PLAYER_CUR_MOVE const ENEMY_CUR_MOVE const PLAYER_COUNTER_MOVE const ENEMY_COUNTER_MOVE const PLAYER_LAST_MOVE const ENEMY_LAST_MOVE assert const_value % 2 == 0 NUM_BATTLE_VAR_LOCATION_PAIRS EQU const_value / 2 ; status condition bit flags SLP EQU %111 ; 0-7 turns const_def 3 const PSN const BRN const FRZ const PAR ALL_STATUS EQU (1 << PSN) | (1 << BRN) | (1 << FRZ) | (1 << PAR) | SLP ; wPlayerSubStatus1 or wEnemySubStatus1 bit flags const_def const SUBSTATUS_NIGHTMARE const SUBSTATUS_CURSE const SUBSTATUS_PROTECT const SUBSTATUS_IDENTIFIED const SUBSTATUS_PERISH const SUBSTATUS_ENDURE const SUBSTATUS_ROLLOUT const SUBSTATUS_IN_LOVE ; wPlayerSubStatus2 or wEnemySubStatus2 bit flags const_def const SUBSTATUS_CURLED ; wPlayerSubStatus3 or wEnemySubStatus3 bit flags const_def const SUBSTATUS_BIDE const SUBSTATUS_RAMPAGE const SUBSTATUS_IN_LOOP const SUBSTATUS_FLINCHED const SUBSTATUS_CHARGED const SUBSTATUS_UNDERGROUND const SUBSTATUS_FLYING const SUBSTATUS_CONFUSED ; wPlayerSubStatus4 or wEnemySubStatus4 bit flags const_def const SUBSTATUS_X_ACCURACY const SUBSTATUS_MIST const SUBSTATUS_FOCUS_ENERGY const_skip const SUBSTATUS_SUBSTITUTE const SUBSTATUS_RECHARGE const SUBSTATUS_RAGE const SUBSTATUS_LEECH_SEED ; wPlayerSubStatus5 or wEnemySubStatus5 bit flags const_def const SUBSTATUS_TOXIC const_skip const_skip const SUBSTATUS_TRANSFORMED const SUBSTATUS_ENCORED const SUBSTATUS_LOCK_ON const SUBSTATUS_DESTINY_BOND const SUBSTATUS_CANT_RUN ; wPlayerScreens or wEnemyScreens bit flags const_def const SCREENS_SPIKES const_skip const SCREENS_SAFEGUARD const SCREENS_LIGHT_SCREEN const SCREENS_REFLECT ; values in wBattleWeather const_def const WEATHER_NONE const WEATHER_RAIN const WEATHER_SUN const WEATHER_SANDSTORM const WEATHER_RAIN_END const WEATHER_SUN_END const WEATHER_SANDSTORM_END ; wBattleAction const_def const BATTLEACTION_MOVE1 const BATTLEACTION_MOVE2 const BATTLEACTION_MOVE3 const BATTLEACTION_MOVE4 const BATTLEACTION_SWITCH1 const BATTLEACTION_SWITCH2 const BATTLEACTION_SWITCH3 const BATTLEACTION_SWITCH4 const BATTLEACTION_SWITCH5 const BATTLEACTION_SWITCH6 const_skip const_skip const_skip const BATTLEACTION_SKIPTURN const BATTLEACTION_STRUGGLE const BATTLEACTION_FORFEIT ; wBattlePlayerAction const_def const BATTLEPLAYERACTION_USEMOVE const BATTLEPLAYERACTION_USEITEM const BATTLEPLAYERACTION_SWITCH ; wBattleResult const_def const WIN const LOSE const DRAW BATTLERESULT_CAUGHT_CELEBI EQU 6 BATTLERESULT_BOX_FULL EQU 7 BATTLERESULT_BITMASK EQU (1 << BATTLERESULT_CAUGHT_CELEBI) | (1 << BATTLERESULT_BOX_FULL) ; link_battle_record struct LINK_BATTLE_RECORD_LENGTH EQU 2 + (NAME_LENGTH - 1) + 2 * 3 NUM_LINK_BATTLE_RECORDS EQU 5
// [AsmJit] // Complete x86/x64 JIT and Remote Assembler for C++. // // [License] // Zlib - See LICENSE.md file in the package. // [Export] #define ASMJIT_EXPORTS // [Dependencies] #include "../base/assembler.h" #include "../base/constpool.h" #include "../base/utils.h" #include "../base/vmem.h" #include <stdarg.h> // [Api-Begin] #include "../asmjit_apibegin.h" namespace asmjit { // ============================================================================ // [asmjit::Assembler - Construction / Destruction] // ============================================================================ Assembler::Assembler() noexcept : CodeEmitter(kTypeAssembler), _section(nullptr), _bufferData(nullptr), _bufferEnd(nullptr), _bufferPtr(nullptr) {} Assembler::~Assembler() noexcept { if (_code) sync(); } // ============================================================================ // [asmjit::Assembler - Events] // ============================================================================ Error Assembler::onAttach(CodeHolder* code) noexcept { // Attach to the end of the .text section. _section = code->_sections[0]; uint8_t* p = _section->_buffer._data; _bufferData = p; _bufferEnd = p + _section->_buffer._capacity; _bufferPtr = p + _section->_buffer._length; return Base::onAttach(code); } Error Assembler::onDetach(CodeHolder* code) noexcept { _section = nullptr; _bufferData = nullptr; _bufferEnd = nullptr; _bufferPtr = nullptr; return Base::onDetach(code); } // ============================================================================ // [asmjit::Assembler - Sync] // ============================================================================ void Assembler::sync() noexcept { ASMJIT_ASSERT(_code != nullptr); // Only called by CodeHolder, so we must be attached. ASMJIT_ASSERT(_section != nullptr); // One section must always be active, no matter what. ASMJIT_ASSERT(_bufferData == _section->_buffer._data); // `_bufferStart` is a shortcut to `_section->buffer.data`. // Update only if the current offset is greater than the section length. size_t offset = (size_t)(_bufferPtr - _bufferData); if (_section->getBuffer().getLength() < offset) _section->_buffer._length = offset; } // ============================================================================ // [asmjit::Assembler - Code-Buffer] // ============================================================================ Error Assembler::setOffset(size_t offset) { if (_lastError) return _lastError; size_t length = Utils::iMax(_section->getBuffer().getLength(), getOffset()); if (offset > length) return setLastError(DebugUtils::errored(kErrorInvalidArgument)); // If the `Assembler` generated any code the `_bufferPtr` may be higher than // the section length stored in `CodeHolder` as it doesn't update it each // time it generates machine code. This is the same as calling `sync()`. if (_section->_buffer._length < length) _section->_buffer._length = length; _bufferPtr = _bufferData + offset; return kErrorOk; } // ============================================================================ // [asmjit::Assembler - Comment] // ============================================================================ Error Assembler::comment(const char* s, size_t len) { if (_lastError) return _lastError; #if !defined(ASMJIT_DISABLE_LOGGING) if (_globalOptions & kOptionLoggingEnabled) { Logger* logger = _code->getLogger(); logger->log(s, len); logger->log("\n", 1); return kErrorOk; } #else ASMJIT_UNUSED(s); ASMJIT_UNUSED(len); #endif return kErrorOk; } // ============================================================================ // [asmjit::Assembler - Building Blocks] // ============================================================================ Label Assembler::newLabel() { uint32_t id = kInvalidValue; if (!_lastError) { ASMJIT_ASSERT(_code != nullptr); Error err = _code->newLabelId(id); if (ASMJIT_UNLIKELY(err)) setLastError(err); } return Label(id); } Label Assembler::newNamedLabel(const char* name, size_t nameLength, uint32_t type, uint32_t parentId) { uint32_t id = kInvalidValue; if (!_lastError) { ASMJIT_ASSERT(_code != nullptr); Error err = _code->newNamedLabelId(id, name, nameLength, type, parentId); if (ASMJIT_UNLIKELY(err)) setLastError(err); } return Label(id); } Error Assembler::bind(const Label& label) { if (_lastError) return _lastError; ASMJIT_ASSERT(_code != nullptr); LabelEntry* le = _code->getLabelEntry(label); if (ASMJIT_UNLIKELY(!le)) return setLastError(DebugUtils::errored(kErrorInvalidLabel)); // Label can be bound only once. if (ASMJIT_UNLIKELY(le->isBound())) return setLastError(DebugUtils::errored(kErrorLabelAlreadyBound)); #if !defined(ASMJIT_DISABLE_LOGGING) if (_globalOptions & kOptionLoggingEnabled) { StringBuilderTmp<256> sb; sb.setFormat("L%u:", Operand::unpackId(label.getId())); size_t binSize = 0; if (!_code->_logger->hasOption(Logger::kOptionBinaryForm)) binSize = kInvalidIndex; LogUtil::formatLine(sb, nullptr, binSize, 0, 0, getInlineComment()); _code->_logger->log(sb.getData(), sb.getLength()); } #endif // !ASMJIT_DISABLE_LOGGING Error err = kErrorOk; size_t pos = getOffset(); LabelLink* link = le->_links; LabelLink* prev = nullptr; while (link) { intptr_t offset = link->offset; uint32_t relocId = link->relocId; if (relocId != RelocEntry::kInvalidId) { // Adjust relocation data. RelocEntry* re = _code->_relocations[relocId]; re->_data += static_cast<uint64_t>(pos); } else { // Not using relocId, this means that we are overwriting a real // displacement in the CodeBuffer. int32_t patchedValue = static_cast<int32_t>( static_cast<intptr_t>(pos) - offset + link->rel); // Size of the value we are going to patch. Only BYTE/DWORD is allowed. uint32_t size = _bufferData[offset]; if (size == 4) Utils::writeI32u(_bufferData + offset, static_cast<int32_t>(patchedValue)); else if (size == 1 && Utils::isInt8(patchedValue)) _bufferData[offset] = static_cast<uint8_t>(patchedValue & 0xFF); else err = DebugUtils::errored(kErrorInvalidDisplacement); } prev = link->prev; _code->_unresolvedLabelsCount--; _code->_baseHeap.release(link, sizeof(LabelLink)); link = prev; } // Set as bound. le->_sectionId = _section->getId(); le->_offset = pos; le->_links = nullptr; resetInlineComment(); if (err != kErrorOk) return setLastError(err); return kErrorOk; } Error Assembler::embed(const void* data, uint32_t size) { if (_lastError) return _lastError; if (getRemainingSpace() < size) { Error err = _code->growBuffer(&_section->_buffer, size); if (ASMJIT_UNLIKELY(err != kErrorOk)) return setLastError(err); } ::memcpy(_bufferPtr, data, size); _bufferPtr += size; #if !defined(ASMJIT_DISABLE_LOGGING) if (_globalOptions & kOptionLoggingEnabled) _code->_logger->logBinary(data, size); #endif // !ASMJIT_DISABLE_LOGGING return kErrorOk; } Error Assembler::embedLabel(const Label& label) { if (_lastError) return _lastError; ASMJIT_ASSERT(_code != nullptr); RelocEntry* re; LabelEntry* le = _code->getLabelEntry(label); if (ASMJIT_UNLIKELY(!le)) return setLastError(DebugUtils::errored(kErrorInvalidLabel)); Error err; uint32_t gpSize = getGpSize(); if (getRemainingSpace() < gpSize) { err = _code->growBuffer(&_section->_buffer, gpSize); if (ASMJIT_UNLIKELY(err)) return setLastError(err); } #if !defined(ASMJIT_DISABLE_LOGGING) if (_globalOptions & kOptionLoggingEnabled) _code->_logger->logf(gpSize == 4 ? ".dd L%u\n" : ".dq L%u\n", Operand::unpackId(label.getId())); #endif // !ASMJIT_DISABLE_LOGGING err = _code->newRelocEntry(&re, RelocEntry::kTypeRelToAbs, gpSize); if (ASMJIT_UNLIKELY(err)) return setLastError(err); re->_sourceSectionId = _section->getId(); re->_sourceOffset = static_cast<uint64_t>(getOffset()); if (le->isBound()) { re->_targetSectionId = le->getSectionId(); re->_data = static_cast<uint64_t>(static_cast<int64_t>(le->getOffset())); } else { LabelLink* link = _code->newLabelLink(le, _section->getId(), getOffset(), 0); if (ASMJIT_UNLIKELY(!link)) return setLastError(DebugUtils::errored(kErrorNoHeapMemory)); link->relocId = re->getId(); } // Emit dummy DWORD/QWORD depending on the address size. ::memset(_bufferPtr, 0, gpSize); _bufferPtr += gpSize; return kErrorOk; } Error Assembler::embedConstPool(const Label& label, const ConstPool& pool) { if (_lastError) return _lastError; if (!isLabelValid(label)) return DebugUtils::errored(kErrorInvalidLabel); ASMJIT_PROPAGATE(align(kAlignData, static_cast<uint32_t>(pool.getAlignment()))); ASMJIT_PROPAGATE(bind(label)); size_t size = pool.getSize(); if (getRemainingSpace() < size) { Error err = _code->growBuffer(&_section->_buffer, size); if (ASMJIT_UNLIKELY(err)) return setLastError(err); } uint8_t* p = _bufferPtr; pool.fill(p); #if !defined(ASMJIT_DISABLE_LOGGING) if (_globalOptions & kOptionLoggingEnabled) _code->_logger->logBinary(p, size); #endif // !ASMJIT_DISABLE_LOGGING _bufferPtr += size; return kErrorOk; } } // asmjit namespace // [Api-End] #include "../asmjit_apiend.h"
; A160017: Lodumo_2 of Thue-Morse sequence A010060. ; Submitted by Simon Strandgaard ; 0,1,3,2,5,4,6,7,9,8,10,11,12,13,15,14,17,16,18,19,20,21,23,22,24,25,27,26,29,28,30,31,33,32,34,35,36,37,39,38,40,41,43,42,45,44,46,47,48,49,51,50,53,52,54,55,57,56,58,59,60,61,63,62,65,64,66,67,68,69,71,70,72 mov $1,$0 div $1,2 mul $1,2 lpb $0 add $2,$0 div $0,2 lpe lpb $2 mod $2,2 lpe mov $0,$2 add $0,$1
; A168300: a(n) = 6*n - a(n-1) - 2 with a(1)=5. ; 5,5,11,11,17,17,23,23,29,29,35,35,41,41,47,47,53,53,59,59,65,65,71,71,77,77,83,83,89,89,95,95,101,101,107,107,113,113,119,119,125,125,131,131,137,137,143,143,149,149,155,155,161,161,167,167,173,173,179,179,185,185,191,191,197,197,203,203,209,209,215,215,221,221,227,227,233,233,239,239,245,245,251,251,257,257,263,263,269,269,275,275,281,281,287,287,293,293,299,299,305,305,311,311,317,317,323,323,329,329,335,335,341,341,347,347,353,353,359,359,365,365,371,371,377,377,383,383,389,389,395,395,401,401,407,407,413,413,419,419,425,425,431,431,437,437,443,443,449,449,455,455,461,461,467,467,473,473,479,479,485,485,491,491,497,497,503,503,509,509,515,515,521,521,527,527,533,533,539,539,545,545,551,551,557,557,563,563,569,569,575,575,581,581,587,587,593,593,599,599,605,605,611,611,617,617,623,623,629,629,635,635,641,641,647,647,653,653,659,659,665,665,671,671,677,677,683,683,689,689,695,695,701,701,707,707,713,713,719,719,725,725,731,731,737,737,743,743,749,749 mov $1,$0 div $1,2 mul $1,6 add $1,5
; A211263: Number of integer pairs (x,y) such that 0<x<y<=n and x*y=floor(n/2). ; 0,0,0,1,1,1,1,1,1,1,1,2,2,1,1,2,2,1,1,2,2,1,1,3,3,1,1,2,2,2,2,2,2,1,1,3,3,1,1,3,3,2,2,2,2,1,1,4,4,1,1,2,2,2,2,3,3,1,1,4,4,1,1,3,3,2,2,2,2,2,2,4,4,1,1,2,2,2,2,4,4,1,1,4,4,1,1,3,3,3,3,2,2,1,1,5,5,1,1 sub $0,1 div $0,2 seq $0,5 ; d(n) (also called tau(n) or sigma_0(n)), the number of divisors of n. div $0,2
/** * @file main.cpp * @author Erfan Rasti (erfanrasty@gmail.com) * @brief * @version 1.0.2 * @date 2022-03-24 * * @copyright Copyright (c) 2022 * */ // Adding the libraries #include "client.h" #include "server.h" #include <gtest/gtest.h> #include <iostream> void show_pending_transactions() { std::cout << std::string(20, '*') << std::endl; for (const auto& trx : pending_trxs) std::cout << trx << std::endl; std::cout << std::string(20, '*') << std::endl; } int main(int argc, char** argv) { if (false) // make false to run unit-tests { // Server server; // auto bryan1 { server.add_client("bryan") }; // auto bryan2 { server.add_client("bryan") }; // auto bryan3 { server.add_client("bryan") }; // show_wallets(server); // std::cout<<"bryan1->get_id(): "<<bryan1->get_id()<<std::endl; // Server server {}; // pending_trxs.clear(); // auto bryan { server.add_client("bryan") }; // auto clint { server.add_client("clint") }; // auto sarah { server.add_client("sarah") }; // EXPECT_TRUE(bryan->transfer_money("clint", 1)); // EXPECT_TRUE(clint->transfer_money("sarah", 2.5)); // EXPECT_TRUE(sarah->transfer_money("bryan", 0.5)); // show_pending_transactions(); // std::string sender {}, receiver {}; // double value; // Server::parse_trx("sarah-clay--0.2", sender, receiver, value); // std::cout << "sender: " << sender << std::endl; // std::cout << "receiver: " << receiver << std::endl; // std::cout << "value: " << value << std::endl; } else { ::testing::InitGoogleTest(&argc, argv); std::cout << "RUNNING TESTS ..." << std::endl; int ret { RUN_ALL_TESTS() }; if (!ret) std::cout << "<<<SUCCESS>>>" << std::endl; else std::cout << "FAILED" << std::endl; } return 0; }
.size 8000 .text@48 ld a, ff ldff(45), a jp lstatint .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld a, ff ldff(45), a ld b, 03 call lwaitly_b ld a, 40 ldff(41), a ld a, 02 ldff(ff), a ei ld a, b inc a inc a ldff(45), a ld c, 41 .text@1000 lstatint: nop .text@1064 ld a, 20 ldff(c), a xor a, a ldff(0f), a ld a, 20 ldff(c), a ldff a, (0f) and a, b 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
/***************************************************************************************** * * * GHOUL * * General Helpful Open Utility Library * * * * Copyright (c) 2012-2020 * * * * 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 "ghoul/systemcapabilities/openglcapabilitiescomponent.h" #include <ghoul/fmt.h> #include <ghoul/logging/logmanager.h> #include <ghoul/opengl/ghoul_gl.h> #include <algorithm> #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include <Windows.h> #include <tchar.h> #pragma comment(lib, "User32.lib") #pragma comment(lib, "Kernel32.lib") typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); // NOLINT typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, DWORD); // NOLINT #else #include <sys/utsname.h> #endif namespace { constexpr const char* _loggerCat = "OpenGLCapabilities"; } // namespace namespace ghoul::systemcapabilities { OpenGLCapabilitiesComponent::OpenGLCapabilitiesComponentError:: OpenGLCapabilitiesComponentError(std::string msg) : RuntimeError(std::move(msg), "OpenGLCapabilitiesComponent") {} OpenGLCapabilitiesComponent::GPUVendorError::GPUVendorError(std::string msg) : OpenGLCapabilitiesComponentError(std::move(msg)) {} void OpenGLCapabilitiesComponent::detectCapabilities() { clearCapabilities(); detectGLSLVersion(); detectGPUVendor(); detectGLRenderer(); detectExtensions(); detectDriverInformation(); glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize); glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &_maxTextureSize3D); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &_nTextureUnits); glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &_nAtomicCounterBufferBindings); glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &_nShaderStorageBufferBindings); glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &_nUniformBufferBindings); glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &_maxFramebufferColorAttachments); } void OpenGLCapabilitiesComponent::detectGLSLVersion() { glGetIntegerv(GL_MAJOR_VERSION, &(_glVersion.major)); glGetIntegerv(GL_MINOR_VERSION, &(_glVersion.minor)); } void OpenGLCapabilitiesComponent::detectGPUVendor() { _glslCompiler = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); if (_glslCompiler.find("NVIDIA") != std::string::npos) { _vendor = Vendor::Nvidia; } else if (_glslCompiler.find("ATI") != std::string::npos) { _vendor = Vendor::ATI; } else if ((_glslCompiler.find("INTEL") != std::string::npos) || (_glslCompiler.find("Intel") != std::string::npos)) { _vendor = Vendor::Intel; } else { LINFO(fmt::format( "Vendor of graphics card is not in the enum 'Vendor'. Vendor information: {}", _glslCompiler )); _vendor = Vendor::Other; } } void OpenGLCapabilitiesComponent::detectGLRenderer() { _glRenderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); } void OpenGLCapabilitiesComponent::detectExtensions() { GLint nExtensions; glGetIntegerv(GL_NUM_EXTENSIONS, &nExtensions); for (GLint i = 0; i < nExtensions; ++i) { const GLubyte* ext = glGetStringi(GL_EXTENSIONS, i); if (ext) { std::string extension = std::string(reinterpret_cast<const char*>(ext)); _extensions.push_back(extension); } } } void OpenGLCapabilitiesComponent::detectDriverInformation() { #ifdef GHOUL_USE_WMI queryWMI("Win32_VideoController", "DriverVersion", _driverVersion); std::string driverDateFull; queryWMI("Win32_VideoController", "DriverDate", driverDateFull); _driverDate = driverDateFull.substr(0, 4) + '-' + driverDateFull.substr(4, 2) + '-' + driverDateFull.substr(6, 2); queryWMI("Win32_VideoController", "AdapterRAM", _adapterRAM); // adapterRAM is in bytes _adapterRAM = (_adapterRAM / 1024) / 1024; queryWMI("Win32_VideoController", "Name", _adapterName); #endif } void OpenGLCapabilitiesComponent::clearCapabilities() { _glVersion = { 0, 0, 0 }; _glslCompiler.clear(); _vendor = Vendor::Other; _glRenderer.clear(); _extensions.clear(); _glewVersion = { 0, 0, 0 }; _maxTextureSize = -1; _maxTextureSize3D = -1; _nTextureUnits = -1; #ifdef GHOUL_USE_WMI _driverVersion.clear(); _driverDate.clear(); _adapterRAM = 0; _adapterName.clear(); #endif } std::vector<SystemCapabilitiesComponent::CapabilityInformation> OpenGLCapabilitiesComponent::capabilities() const { std::vector<SystemCapabilitiesComponent::CapabilityInformation> result; result.push_back( { "OpenGL Version", ghoul::to_string(_glVersion), Verbosity::Minimal } ); result.push_back({ "OpenGL Compiler", _glslCompiler, Verbosity::Minimal }); result.push_back({ "OpenGL Renderer", _glRenderer, Verbosity::Minimal }); result.push_back({ "GPU Vendor", gpuVendorString(), Verbosity::Minimal }); result.push_back({ "GLEW Version", ghoul::to_string(_glewVersion),Verbosity::Minimal }); #ifdef GHOUL_USE_WMI result.push_back({ "GPU Name", _adapterName, Verbosity::Minimal }); result.push_back({ "GPU Driver Version", _driverVersion, Verbosity::Minimal }); result.push_back({ "GPU Driver Date", _driverDate, Verbosity::Minimal }); result.push_back({ "GPU RAM", ghoul::to_string(_adapterRAM) + " MB",Verbosity::Minimal } ); #endif result.push_back({ "Max Texture Size", ghoul::to_string(_maxTextureSize), Verbosity::Default } ); result.push_back({ "Max 3D Texture Size", ghoul::to_string(_maxTextureSize3D), Verbosity::Default } ); result.push_back({ "Num of Texture Units", ghoul::to_string(_nTextureUnits), Verbosity::Default } ); result.push_back({ "FBO Color Attachments", ghoul::to_string(_maxFramebufferColorAttachments), Verbosity::Default }); std::stringstream s; if (!_extensions.empty()) { for (size_t i = 0; i < _extensions.size() - 1; ++i) { s << _extensions[i] << ", "; } s << _extensions[_extensions.size() - 1] << "\n"; } result.push_back({ "Extensions", s.str(), Verbosity::Full }); return result; } Version OpenGLCapabilitiesComponent::openGLVersion() const { return _glVersion; } const std::string& OpenGLCapabilitiesComponent::glslCompiler() const { return _glslCompiler; } OpenGLCapabilitiesComponent::Vendor OpenGLCapabilitiesComponent::gpuVendor() const { return _vendor; } const std::vector<std::string>& OpenGLCapabilitiesComponent::extensions() const { return _extensions; } bool OpenGLCapabilitiesComponent::isExtensionSupported(const std::string& extension) const { auto result = std::find(_extensions.begin(), _extensions.end(), extension); return (result != _extensions.end()); } int OpenGLCapabilitiesComponent::maxTextureUnits() const { return _nTextureUnits; } int OpenGLCapabilitiesComponent::max2DTextureSize() const { return _maxTextureSize; } int OpenGLCapabilitiesComponent::max3DTextureSize() const { return _maxTextureSize3D; } int OpenGLCapabilitiesComponent::maxAtomicCounterBufferBindings() const { return _nAtomicCounterBufferBindings; } int OpenGLCapabilitiesComponent::maxShaderStorageBufferBindings() const { return _nShaderStorageBufferBindings; } int OpenGLCapabilitiesComponent::maxUniformBufferBindings() const { return _nUniformBufferBindings; } std::string OpenGLCapabilitiesComponent::gpuVendorString() const { switch (_vendor) { case Vendor::Nvidia: return "Nvidia"; case Vendor::ATI: return "ATI"; case Vendor::Intel: return "Intel"; default: return "other"; } } std::string OpenGLCapabilitiesComponent::name() const { return "OpenGL"; } } // namespace ghoul::systemcapabilities
/** * Copyright (c) 2018, University Osnabrück * 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 the University Osnabrück 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 University Osnabrück 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. */ /* * Options.h * * Created on: Aug 23 2012 * Author: Thomas Wiemann */ #ifndef OPTIONS_H_ #define OPTIONS_H_ #include <boost/program_options.hpp> #include <iostream> #include <string> #include <vector> using std::cout; using std::endl; using std::ostream; using std::string; using std::vector; namespace hdf5tool2 { using namespace boost::program_options; /** * @brief A class to parse the program options for the reconstruction * executable. */ class Options { public: /** * @brief Ctor. Parses the command parameters given to the main * function of the program */ Options(int argc, char** argv); virtual ~Options(); string getInputDir() const { return m_variables["inputDir"].as<string>(); } string getOutputDir() const { return m_variables["outputDir"].as<string>(); } string getOutputFile() const { return m_variables["outputFile"].as<string>(); } bool getPreview() const { return m_variables["createPreview"].as<bool>(); } int getPreviewReductionRatio() const { return m_variables["previewReduction"].as<int>(); } // int numPanoramaImages() const { return m_variables["nch"].as<int>();} // // size_t getHSPChunk0() const { return m_variables["hsp_chunk_0"].as<size_t>(); } // size_t getHSPChunk1() const { return m_variables["hsp_chunk_1"].as<size_t>(); } // size_t getHSPChunk2() const { return m_variables["hsp_chunk_2"].as<size_t>(); } // // bool addAnnotations() const { return (m_variables["addAnnotations"].as<int>() != 0);} private: /// The internally used variable map variables_map m_variables; /// The internally used option description options_description m_descr; /// The internally used positional option desription positional_options_description m_pdescr; }; /// Overlaoeded outpur operator inline ostream& operator<<(ostream& os, const Options& o) { cout << "##### Program options: " << endl; // cout << "##### Data directory \t\t: " << o.getDataDir() << endl; return os; } } // namespace hdf5tool2 #endif /* OPTIONS_H_ */
.model flat, c .code extern GetFileVersionInfoA_Original:DWORD extern GetFileVersionInfoByHandle_Original:DWORD extern GetFileVersionInfoExA_Original:DWORD extern GetFileVersionInfoExW_Original:DWORD extern GetFileVersionInfoSizeA_Original:DWORD extern GetFileVersionInfoSizeExA_Original:DWORD extern GetFileVersionInfoSizeExW_Original:DWORD extern GetFileVersionInfoSizeW_Original:DWORD extern GetFileVersionInfoW_Original:DWORD extern VerFindFileA_Original:DWORD extern VerFindFileW_Original:DWORD extern VerInstallFileA_Original:DWORD extern VerInstallFileW_Original:DWORD extern VerLanguageNameA_Original:DWORD extern VerLanguageNameW_Original:DWORD extern VerQueryValueA_Original:DWORD extern VerQueryValueW_Original:DWORD GetFileVersionInfoA_ML proc jmp DWORD ptr GetFileVersionInfoA_Original GetFileVersionInfoA_ML endp GetFileVersionInfoByHandle_ML proc jmp DWORD ptr GetFileVersionInfoByHandle_Original GetFileVersionInfoByHandle_ML endp GetFileVersionInfoExA_ML proc jmp DWORD ptr GetFileVersionInfoExA_Original GetFileVersionInfoExA_ML endp GetFileVersionInfoExW_ML proc jmp DWORD ptr GetFileVersionInfoExW_Original GetFileVersionInfoExW_ML endp GetFileVersionInfoSizeA_ML proc jmp DWORD ptr GetFileVersionInfoSizeA_Original GetFileVersionInfoSizeA_ML endp GetFileVersionInfoSizeExA_ML proc jmp DWORD ptr GetFileVersionInfoSizeExA_Original GetFileVersionInfoSizeExA_ML endp GetFileVersionInfoSizeExW_ML proc jmp DWORD ptr GetFileVersionInfoSizeExW_Original GetFileVersionInfoSizeExW_ML endp GetFileVersionInfoSizeW_ML proc jmp DWORD ptr GetFileVersionInfoSizeW_Original GetFileVersionInfoSizeW_ML endp GetFileVersionInfoW_ML proc jmp DWORD ptr GetFileVersionInfoW_Original GetFileVersionInfoW_ML endp VerFindFileA_ML proc jmp DWORD ptr VerFindFileA_Original VerFindFileA_ML endp VerFindFileW_ML proc jmp DWORD ptr VerFindFileW_Original VerFindFileW_ML endp VerInstallFileA_ML proc jmp DWORD ptr VerInstallFileA_Original VerInstallFileA_ML endp VerInstallFileW_ML proc jmp DWORD ptr VerInstallFileW_Original VerInstallFileW_ML endp VerLanguageNameA_ML proc jmp DWORD ptr VerLanguageNameA_Original VerLanguageNameA_ML endp VerLanguageNameW_ML proc jmp DWORD ptr VerLanguageNameW_Original VerLanguageNameW_ML endp VerQueryValueA_ML proc jmp DWORD ptr VerQueryValueA_Original VerQueryValueA_ML endp VerQueryValueW_ML proc jmp DWORD ptr VerQueryValueW_Original VerQueryValueW_ML endp end
; ; Spectrum C Library ; ; Print character to the screen in either 32/64 col mode ; ; We will corrupt any register ; ; Scrolling is now achieved by calling ROM3 routine 3582 ; ; We print over 24 lines at 64 columns ; ; djm 3/3/2000 ; ; ; $Id: fputc_cons.asm,v 1.18 2016-05-15 20:15:46 dom Exp $ ; SECTION code_clib PUBLIC fputc_cons_native EXTERN call_rom3 EXTERN CRT_FONT EXTERN CRT_FONT_64 EXTERN __zx_console_attr EXTERN __zx_32col_font EXTERN __zx_64col_font EXTERN __zx_32col_udgs EXTERN __ts2068_hrgmode EXTERN generic_console_scrollup ; ; Entry: a= char to print ; .fputc_cons_native IF FORts2068 in a,(255) ld hl,__ts2068_hrgmode and 7 ld (hl),a .normal ENDIF ld hl,2 add hl,sp ld a,(hl) ex af,af' ld a,(flags) and a jp z,putit_out1 ;no parameters pending ; Set up so dump into params so first param is at highest posn ld l,a ld h,0 ld de,params-1 add hl,de dec a ld (flags),a ex af,af' ld (hl),a ex af,af' and a ret nz ld hl,(flagrout) jp (hl) .putit_out1 ex af,af' bit 7,a jr z,putit_out2 ; deal with UDGs here sub 128 ld c,a ;save character call calc_screen_address ex de,hl ld l,c ld h,0 add hl,hl add hl,hl add hl,hl ld bc,(__zx_32col_udgs) add hl,bc jp print32_entry .putit_out2 ld hl,(print_routine) cp 32 jr c,handle_control jp (hl) ; Control characters .handle_control and 31 add a,a ;x2 ld l,a ld h,0 ld de,code_table add hl,de ld e,(hl) inc hl ld d,(hl) ld hl,(chrloc) ;most of them will need the position push de ret ;Normal print routine... ;Exit with carry set if OK.. .print64 sub 32 ld c,a ;save character call calc_screen_address ex de,hl ;de = screen address ld a,b ;mask ld l,c ld h,0 add hl,hl add hl,hl add hl,hl ld bc,(__zx_64col_font) add hl,bc ; a = mask ; de = screen address ; hl = &font ld b,8 ld c,a ex de,hl ld b,8 .print64_loop ld a,c ;mask off screen cpl and (hl) ld (hl),a ld a,(control_flags) rrca ld a,(de) jr nc,no_inverse64 cpl .no_inverse64 and c or (hl) ld (hl),a inc h inc de djnz print64_loop dec h IF FORts2068 ; No __zx_console_attribute setting for hires mode ld a,(__ts2068_hrgmode) cp 6 jr z,cbak ENDIF ld a,h rrca rrca rrca and 3 or 88 ld h,a ld a,(__zx_console_attr) ld (hl),a .cbak ld hl,(chrloc) inc l .posncheck bit 6,l jr z,char4 IF FORts2068 ld a,(__ts2068_hrgmode) cp 6 jr nz,cbak1 bit 7,l jr z,char4 ENDIF .cbak1 ld l,0 inc h ; ld a,h ; cp 24 ; jr nz,char4 ; call scrollup ; ld hl,23*256 .char4 ld (chrloc),hl ret ; 32 column print routine..quick 'n' dirty..we take ; x posn and divide by two to get our real position .print32 sub 32 ld c,a ;save character call calc_screen_address ex de,hl ;de = screen address ld l,c ld h,0 add hl,hl add hl,hl add hl,hl ld bc,(__zx_32col_font) add hl,bc .print32_entry ld b,8 ld a,(control_flags) ld c,a .loop32 bit 0,c ld a,(hl) jr z,no_inverse32 cpl .no_inverse32 ld (de),a inc d ;down screen row inc hl djnz loop32 dec d ld hl,(chrloc) IF FORts2068 ld a,(__ts2068_hrgmode) cp 6 jr z,increment ENDIF ld a,d rrca rrca rrca and 3 or 88 ld d,a ld a,(__zx_console_attr) ld (de),a .increment inc l inc l jp posncheck ; Calculate screen address from xy coords ; Entry: h = row ; l = column ; Exit: hl = screen address ; b = 64 column mask calc_screen_address: ld hl,(chrloc) ld a,h cp 24 jr c,noscroll ld hl,control_flags bit 1,(hl) call z,scrollup ld hl,23*256 ld (chrloc),hl noscroll: IF FORts2068 bit 1,l ;if set then we need to use alt screen push af ENDIF srl l ;divide column by 2 ld b,0x0f ;mask jr c,just_calculate ld b,0xf0 just_calculate: IF FORts2068 ; In highres mode, we've got to divide again ld a,(__ts2068_hrgmode) cp 6 jr nz,not_hrg_calc srl l .not_hrg_calc ENDIF ld a,h rrca rrca rrca and 248 or l ld l,a ld a,h and 0x18 or 0x40 ld h,a IF FORts2068 pop af ret z ld a,(__ts2068_hrgmode) cp 6 ret z ld a,$20 add h ld h,a not_second_screen: ENDIF ret ; Ooops..ain't written this yet! ; We should scroll the screen up one character here ; Blanking the bottom row.. .scrollup push hl call generic_console_scrollup pop hl ret ; This nastily inefficient table is the code table for the routines ; Done this way for future! Expansion .code_table defw noop ; 0 - NUL defw switch ; 1 - SOH defw setfont ; 2 defw setudg ; 3 defw setvscroll ; 4 defw noop ; 5 defw noop ; 6 defw noop ; 7 - BEL defw left ; 8 - BS defw right ; 9 - HT IF STANDARDESCAPECHARS defw cr ;13 - CR (+NL) ELSE defw down ;10 - LF ENDIF defw up ;11 - UP defw cls ;12 = FF (and HOME) IF STANDARDESCAPECHARS defw down ;10 - LF ELSE defw cr ;13 - CR (+NL) ENDIF defw noop ;14 defw noop ;15 defw setink ;16 - ink defw setpaper ;17 - paper defw setflash ;18 - flash defw setbright ;19 - bright defw setinverse ;20 - inverse defw noop ;21 - over defw setposn ;22 defw noop ;23 defw noop ;24 defw noop ;25 defw noop ;26 defw noop ;27 defw noop ;28 defw noop ;29 defw noop ;30 defw noop ;31 ; And now the magic routines ; No operation .noop ret ; Move print position left .left ld a,l and a jr nz,doleft ld l,63 jr up .doleft ld a,(deltax) neg add l ld l,a ld (chrloc),hl ret ;Move print position right .right ld a,l cp 63 ret z ld a,(deltax) add l ld l,a ld (chrloc),hl ret ;Move print position up .up ld a,h and a ret z dec h ld (chrloc),hl ret ;Move print position down .down ld a,h cp 23 ret z inc h ld (chrloc),hl ret ; Clear screen and move to home .cls ld hl,0 ld (chrloc),hl ld hl,16384 ld de,16385 ld bc,6144 ld (hl),l ldir IF FORts2068 ld a,(__ts2068_hrgmode) cp 6 jr z,cls_hrg ENDIF ld a,(__zx_console_attr) ld (hl),a ld bc,767 ldir ret IF FORts2068 cls_hrg: ld hl,$6000 ld de,$6001 ld bc,6144 ld (hl),l ldir ret ENDIF ;Move to new line .cr ld a,h cp 23 jr nz,cr_1 ld a,(control_flags) bit 1,a call z,scrollup ld h,22 .cr_1 inc h ld l,0 ld (chrloc),hl ret ; Set __zx_console_attributes etc .doinverse ld hl,control_flags set 0,(hl) ld a,(params) rrca ret c res 0,(hl) ret .dovscroll ld hl,control_flags res 1,(hl) ld a,(params) rrca ret c set 1,(hl) ret .dobright ld hl,__zx_console_attr set 6,(hl) ld a,(params) rrca ret c res 6,(hl) ret .doflash ld hl,__zx_console_attr set 7,(hl) ld a,(params) rrca ret c res 7,(hl) ret .dopaper ld hl,__zx_console_attr ld a,(hl) and @11000111 ld c,a ld a,(params) rlca rlca rlca and @00111000 or c ld (hl),a ret .doink ld hl,__zx_console_attr ld a,(hl) and @11111000 ld c,a ld a,(params) and 7 ;doesn't matter what chars were used.. or c ld (hl),a ret .dofont ld hl,(print_routine) and a ld de,print32 sbc hl,de ld de,__zx_32col_font jr nc,dofont_setit ld de,__zx_64col_font .dofont_setit ld hl,(params) ex de,hl ld (hl),e inc hl ld (hl),d ret .doudg ld hl,(params) ld (__zx_32col_udgs),hl ret .setfont ld hl,dofont ld a,2 jr setparams .setudg ld hl,doudg ld a,2 jr setparams .setvscroll ld hl,dovscroll jr setink1 .setinverse ld hl,doinverse jr setink1 .setbright ld hl,dobright jr setink1 .setflash ld hl,doflash jr setink1 .setpaper ld hl,dopaper jr setink1 .setink ld hl,doink .setink1 ld a,1 ;number to expect .setparams ld (flags),a ld (flagrout),hl ret ; Set xy position ; Code 22,y,x (as per ZX) .setposn ld a,2 ;number to expect ld hl,doposn jr setparams ; Setting the position ; We only care .doposn ld hl,(params) ld de,$2020 and a sbc hl,de ld a,(deltax) cp 1 jr z,nomult ; if not, do not double rl l .nomult ld a,h ;y position cp 24 ret nc bit 6,l ;is x > 64 ret nz ld (chrloc),hl ret ; Switch between 64 & 32 column text .switch ld a,1 ld (flags),a ld hl,doswitch ld (flagrout),hl ret .doswitch ld a,1 ld (deltax),a ld a,(params) ld hl,print64 ld (print_routine),hl cp 64 ret z ld a,2 ld (deltax),a ld hl,print32 ld (print_routine),hl ret SECTION bss_clib .chrloc defw 0 ; Attribute to use ; Flags..used for incoming bit sequences .flags defb 0 ; Routine to jump to when we have all the parameters .flagrout defw 0 ; Buffer for reading in parameters - 5 should be enuff ATM? .params defs 5 ; Bit 0 = inverse ; Bit 1 = scroll disabled .control_flags defb 0 SECTION data_clib .print_routine defw print64 .deltax defb 1 ;how much to move in x
; A153638: Odiousness of triangular numbers. ; 0,1,0,0,0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,1,1,0,0,1,0,1,0,1,1,0,0,1,0,1,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,1,1,1,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,1,1,0 mov $2,$0 mul $2,2 add $2,2 mul $0,$2 lpb $0,1 sub $0,1 div $0,2 add $1,1 mod $1,2 pow $1,2 sub $1,$0 lpe
// Copyright (c) 2017-2018 The PIVX developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "zmagwallet.h" #include "main.h" #include "txdb.h" #include "walletdb.h" #include "init.h" #include "wallet.h" #include "primitives/deterministicmint.h" #include "zmagchain.h" using namespace libzerocoin; CzMAGWallet::CzMAGWallet(std::string strWalletFile) { this->strWalletFile = strWalletFile; CWalletDB walletdb(strWalletFile); uint256 hashSeed; bool fFirstRun = !walletdb.ReadCurrentSeedHash(hashSeed); //Check for old db version of storing zmag seed if (fFirstRun) { uint256 seed; if (walletdb.ReadZMAGSeed_deprecated(seed)) { //Update to new format, erase old seedMaster = seed; hashSeed = Hash(seed.begin(), seed.end()); if (pwalletMain->AddDeterministicSeed(seed)) { if (walletdb.EraseZMAGSeed_deprecated()) { LogPrintf("%s: Updated zMAG seed databasing\n", __func__); fFirstRun = false; } else { LogPrintf("%s: failed to remove old zmag seed\n", __func__); } } } } //Don't try to do anything if the wallet is locked. if (pwalletMain->IsLocked()) { seedMaster = 0; nCountLastUsed = 0; this->mintPool = CMintPool(); return; } //First time running, generate master seed uint256 seed; if (fFirstRun) { // Borrow random generator from the key class so that we don't have to worry about randomness CKey key; key.MakeNewKey(true); seed = key.GetPrivKey_256(); seedMaster = seed; LogPrintf("%s: first run of zmag wallet detected, new seed generated. Seedhash=%s\n", __func__, Hash(seed.begin(), seed.end()).GetHex()); } else if (!pwalletMain->GetDeterministicSeed(hashSeed, seed)) { LogPrintf("%s: failed to get deterministic seed for hashseed %s\n", __func__, hashSeed.GetHex()); return; } if (!SetMasterSeed(seed)) { LogPrintf("%s: failed to save deterministic seed for hashseed %s\n", __func__, hashSeed.GetHex()); return; } this->mintPool = CMintPool(nCountLastUsed); } bool CzMAGWallet::SetMasterSeed(const uint256& seedMaster, bool fResetCount) { CWalletDB walletdb(strWalletFile); if (pwalletMain->IsLocked()) return false; if (seedMaster != 0 && !pwalletMain->AddDeterministicSeed(seedMaster)) { return error("%s: failed to set master seed.", __func__); } this->seedMaster = seedMaster; nCountLastUsed = 0; if (fResetCount) walletdb.WriteZMAGCount(nCountLastUsed); else if (!walletdb.ReadZMAGCount(nCountLastUsed)) nCountLastUsed = 0; mintPool.Reset(); return true; } void CzMAGWallet::Lock() { seedMaster = 0; } void CzMAGWallet::AddToMintPool(const std::pair<uint256, uint32_t>& pMint, bool fVerbose) { mintPool.Add(pMint, fVerbose); } //Add the next 20 mints to the mint pool void CzMAGWallet::GenerateMintPool(uint32_t nCountStart, uint32_t nCountEnd) { //Is locked if (seedMaster == 0) return; uint32_t n = nCountLastUsed + 1; if (nCountStart > 0) n = nCountStart; uint32_t nStop = n + 20; if (nCountEnd > 0) nStop = std::max(n, n + nCountEnd); bool fFound; uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); LogPrintf("%s : n=%d nStop=%d\n", __func__, n, nStop - 1); for (uint32_t i = n; i < nStop; ++i) { if (ShutdownRequested()) return; fFound = false; // Prevent unnecessary repeated minted for (auto& pair : mintPool) { if(pair.second == i) { fFound = true; break; } } if(fFound) continue; uint512 seedZerocoin = GetZerocoinSeed(i); CBigNum bnValue; CBigNum bnSerial; CBigNum bnRandomness; CKey key; SeedToZMAG(seedZerocoin, bnValue, bnSerial, bnRandomness, key); mintPool.Add(bnValue, i); CWalletDB(strWalletFile).WriteMintPoolPair(hashSeed, GetPubCoinHash(bnValue), i); LogPrintf("%s : %s count=%d\n", __func__, bnValue.GetHex().substr(0, 6), i); } } // pubcoin hashes are stored to db so that a full accounting of mints belonging to the seed can be tracked without regenerating bool CzMAGWallet::LoadMintPoolFromDB() { map<uint256, vector<pair<uint256, uint32_t> > > mapMintPool = CWalletDB(strWalletFile).MapMintPool(); uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); for (auto& pair : mapMintPool[hashSeed]) mintPool.Add(pair); return true; } void CzMAGWallet::RemoveMintsFromPool(const std::vector<uint256>& vPubcoinHashes) { for (const uint256& hash : vPubcoinHashes) mintPool.Remove(hash); } void CzMAGWallet::GetState(int& nCount, int& nLastGenerated) { nCount = this->nCountLastUsed + 1; nLastGenerated = mintPool.CountOfLastGenerated(); } //Catch the counter up with the chain void CzMAGWallet::SyncWithChain(bool fGenerateMintPool) { uint32_t nLastCountUsed = 0; bool found = true; CWalletDB walletdb(strWalletFile); set<uint256> setAddedTx; while (found) { found = false; if (fGenerateMintPool) GenerateMintPool(); LogPrintf("%s: Mintpool size=%d\n", __func__, mintPool.size()); std::set<uint256> setChecked; list<pair<uint256,uint32_t> > listMints = mintPool.List(); for (pair<uint256, uint32_t> pMint : listMints) { LOCK(cs_main); if (setChecked.count(pMint.first)) return; setChecked.insert(pMint.first); if (ShutdownRequested()) return; if (pwalletMain->zmagTracker->HasPubcoinHash(pMint.first)) { mintPool.Remove(pMint.first); continue; } uint256 txHash; CZerocoinMint mint; if (zerocoinDB->ReadCoinMint(pMint.first, txHash)) { //this mint has already occurred on the chain, increment counter's state to reflect this LogPrintf("%s : Found wallet coin mint=%s count=%d tx=%s\n", __func__, pMint.first.GetHex(), pMint.second, txHash.GetHex()); found = true; uint256 hashBlock; CTransaction tx; if (!GetTransaction(txHash, tx, hashBlock, true)) { LogPrintf("%s : failed to get transaction for mint %s!\n", __func__, pMint.first.GetHex()); found = false; nLastCountUsed = std::max(pMint.second, nLastCountUsed); continue; } //Find the denomination CoinDenomination denomination = CoinDenomination::ZQ_ERROR; bool fFoundMint = false; CBigNum bnValue = 0; for (const CTxOut& out : tx.vout) { if (!out.scriptPubKey.IsZerocoinMint()) continue; PublicCoin pubcoin(Params().Zerocoin_Params(false)); CValidationState state; if (!TxOutToPublicCoin(out, pubcoin, state)) { LogPrintf("%s : failed to get mint from txout for %s!\n", __func__, pMint.first.GetHex()); continue; } // See if this is the mint that we are looking for uint256 hashPubcoin = GetPubCoinHash(pubcoin.getValue()); if (pMint.first == hashPubcoin) { denomination = pubcoin.getDenomination(); bnValue = pubcoin.getValue(); fFoundMint = true; break; } } if (!fFoundMint || denomination == ZQ_ERROR) { LogPrintf("%s : failed to get mint %s from tx %s!\n", __func__, pMint.first.GetHex(), tx.GetHash().GetHex()); found = false; break; } CBlockIndex* pindex = nullptr; if (mapBlockIndex.count(hashBlock)) pindex = mapBlockIndex.at(hashBlock); if (!setAddedTx.count(txHash)) { CBlock block; CWalletTx wtx(pwalletMain, tx); if (pindex && ReadBlockFromDisk(block, pindex)) wtx.SetMerkleBranch(block); //Fill out wtx so that a transaction record can be created wtx.nTimeReceived = pindex->GetBlockTime(); pwalletMain->AddToWallet(wtx); setAddedTx.insert(txHash); } SetMintSeen(bnValue, pindex->nHeight, txHash, denomination); nLastCountUsed = std::max(pMint.second, nLastCountUsed); nCountLastUsed = std::max(nLastCountUsed, nCountLastUsed); LogPrint("zero", "%s: updated count to %d\n", __func__, nCountLastUsed); } } } } bool CzMAGWallet::SetMintSeen(const CBigNum& bnValue, const int& nHeight, const uint256& txid, const CoinDenomination& denom) { if (!mintPool.Has(bnValue)) return error("%s: value not in pool", __func__); pair<uint256, uint32_t> pMint = mintPool.Get(bnValue); // Regenerate the mint uint512 seedZerocoin = GetZerocoinSeed(pMint.second); CBigNum bnValueGen; CBigNum bnSerial; CBigNum bnRandomness; CKey key; SeedToZMAG(seedZerocoin, bnValueGen, bnSerial, bnRandomness, key); //Sanity check if (bnValueGen != bnValue) return error("%s: generated pubcoin and expected value do not match!", __func__); // Create mint object and database it uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); uint256 hashSerial = GetSerialHash(bnSerial); uint256 hashPubcoin = GetPubCoinHash(bnValue); uint256 nSerial = bnSerial.getuint256(); uint256 hashStake = Hash(nSerial.begin(), nSerial.end()); CDeterministicMint dMint(PrivateCoin::CURRENT_VERSION, pMint.second, hashSeed, hashSerial, hashPubcoin, hashStake); dMint.SetDenomination(denom); dMint.SetHeight(nHeight); dMint.SetTxHash(txid); // Check if this is also already spent int nHeightTx; uint256 txidSpend; CTransaction txSpend; if (IsSerialInBlockchain(hashSerial, nHeightTx, txidSpend, txSpend)) { //Find transaction details and make a wallettx and add to wallet dMint.SetUsed(true); CWalletTx wtx(pwalletMain, txSpend); CBlockIndex* pindex = chainActive[nHeightTx]; CBlock block; if (ReadBlockFromDisk(block, pindex)) wtx.SetMerkleBranch(block); wtx.nTimeReceived = pindex->nTime; pwalletMain->AddToWallet(wtx); } // Add to zmagTracker which also adds to database pwalletMain->zmagTracker->Add(dMint, true); //Update the count if it is less than the mint's count if (nCountLastUsed < pMint.second) { CWalletDB walletdb(strWalletFile); nCountLastUsed = pMint.second; walletdb.WriteZMAGCount(nCountLastUsed); } //remove from the pool mintPool.Remove(dMint.GetPubcoinHash()); return true; } // Check if the value of the commitment meets requirements bool IsValidCoinValue(const CBigNum& bnValue) { return bnValue >= Params().Zerocoin_Params(false)->accumulatorParams.minCoinValue && bnValue <= Params().Zerocoin_Params(false)->accumulatorParams.maxCoinValue && bnValue.isPrime(); } void CzMAGWallet::SeedToZMAG(const uint512& seedZerocoin, CBigNum& bnValue, CBigNum& bnSerial, CBigNum& bnRandomness, CKey& key) { ZerocoinParams* params = Params().Zerocoin_Params(false); //convert state seed into a seed for the private key uint256 nSeedPrivKey = seedZerocoin.trim256(); bool isValidKey = false; key = CKey(); while (!isValidKey) { nSeedPrivKey = Hash(nSeedPrivKey.begin(), nSeedPrivKey.end()); isValidKey = libzerocoin::GenerateKeyPair(params->coinCommitmentGroup.groupOrder, nSeedPrivKey, key, bnSerial); } //hash randomness seed with Bottom 256 bits of seedZerocoin & attempts256 which is initially 0 uint256 randomnessSeed = uint512(seedZerocoin >> 256).trim256(); uint256 hashRandomness = Hash(randomnessSeed.begin(), randomnessSeed.end()); bnRandomness.setuint256(hashRandomness); bnRandomness = bnRandomness % params->coinCommitmentGroup.groupOrder; //See if serial and randomness make a valid commitment // Generate a Pedersen commitment to the serial number CBigNum commitmentValue = params->coinCommitmentGroup.g.pow_mod(bnSerial, params->coinCommitmentGroup.modulus).mul_mod( params->coinCommitmentGroup.h.pow_mod(bnRandomness, params->coinCommitmentGroup.modulus), params->coinCommitmentGroup.modulus); CBigNum random; uint256 attempts256 = 0; // Iterate on Randomness until a valid commitmentValue is found while (true) { // Now verify that the commitment is a prime number // in the appropriate range. If not, we'll throw this coin // away and generate a new one. if (IsValidCoinValue(commitmentValue)) { bnValue = commitmentValue; return; } //Did not create a valid commitment value. //Change randomness to something new and random and try again attempts256++; hashRandomness = Hash(randomnessSeed.begin(), randomnessSeed.end(), attempts256.begin(), attempts256.end()); random.setuint256(hashRandomness); bnRandomness = (bnRandomness + random) % params->coinCommitmentGroup.groupOrder; commitmentValue = commitmentValue.mul_mod(params->coinCommitmentGroup.h.pow_mod(random, params->coinCommitmentGroup.modulus), params->coinCommitmentGroup.modulus); } } uint512 CzMAGWallet::GetZerocoinSeed(uint32_t n) { CDataStream ss(SER_GETHASH, 0); ss << seedMaster << n; uint512 zerocoinSeed = Hash512(ss.begin(), ss.end()); return zerocoinSeed; } void CzMAGWallet::UpdateCount() { nCountLastUsed++; CWalletDB walletdb(strWalletFile); walletdb.WriteZMAGCount(nCountLastUsed); } void CzMAGWallet::GenerateDeterministicZMAG(CoinDenomination denom, PrivateCoin& coin, CDeterministicMint& dMint, bool fGenerateOnly) { GenerateMint(nCountLastUsed + 1, denom, coin, dMint); if (fGenerateOnly) return; //TODO remove this leak of seed from logs before merge to master //LogPrintf("%s : Generated new deterministic mint. Count=%d pubcoin=%s seed=%s\n", __func__, nCount, coin.getPublicCoin().getValue().GetHex().substr(0,6), seedZerocoin.GetHex().substr(0, 4)); } void CzMAGWallet::GenerateMint(const uint32_t& nCount, const CoinDenomination denom, PrivateCoin& coin, CDeterministicMint& dMint) { uint512 seedZerocoin = GetZerocoinSeed(nCount); CBigNum bnValue; CBigNum bnSerial; CBigNum bnRandomness; CKey key; SeedToZMAG(seedZerocoin, bnValue, bnSerial, bnRandomness, key); coin = PrivateCoin(Params().Zerocoin_Params(false), denom, bnSerial, bnRandomness); coin.setPrivKey(key.GetPrivKey()); coin.setVersion(PrivateCoin::CURRENT_VERSION); uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); uint256 hashSerial = GetSerialHash(bnSerial); uint256 nSerial = bnSerial.getuint256(); uint256 hashStake = Hash(nSerial.begin(), nSerial.end()); uint256 hashPubcoin = GetPubCoinHash(bnValue); dMint = CDeterministicMint(coin.getVersion(), nCount, hashSeed, hashSerial, hashPubcoin, hashStake); dMint.SetDenomination(denom); } bool CzMAGWallet::RegenerateMint(const CDeterministicMint& dMint, CZerocoinMint& mint) { //Check that the seed is correct todo:handling of incorrect, or multiple seeds uint256 hashSeed = Hash(seedMaster.begin(), seedMaster.end()); if (hashSeed != dMint.GetSeedHash()) return error("%s: master seed does not match!\ndmint:\n %s \nhashSeed: %s\nseed: %s", __func__, dMint.ToString(), hashSeed.GetHex(), seedMaster.GetHex()); //Generate the coin PrivateCoin coin(Params().Zerocoin_Params(false), dMint.GetDenomination(), false); CDeterministicMint dMintDummy; GenerateMint(dMint.GetCount(), dMint.GetDenomination(), coin, dMintDummy); //Fill in the zerocoinmint object's details CBigNum bnValue = coin.getPublicCoin().getValue(); if (GetPubCoinHash(bnValue) != dMint.GetPubcoinHash()) return error("%s: failed to correctly generate mint, pubcoin hash mismatch", __func__); mint.SetValue(bnValue); CBigNum bnSerial = coin.getSerialNumber(); if (GetSerialHash(bnSerial) != dMint.GetSerialHash()) return error("%s: failed to correctly generate mint, serial hash mismatch", __func__); mint.SetSerialNumber(bnSerial); mint.SetRandomness(coin.getRandomness()); mint.SetPrivKey(coin.getPrivKey()); mint.SetVersion(coin.getVersion()); mint.SetDenomination(dMint.GetDenomination()); mint.SetUsed(dMint.IsUsed()); mint.SetTxHash(dMint.GetTxHash()); mint.SetHeight(dMint.GetHeight()); return true; }
[org 0x7c00] ; 以下は標準的なFAT12フォーマットフロッピーディスクのための記述 jmp short entry db 0x90 db "CLOUMO " ; ブートセクタの名前を自由に書いてよい(8バイト) dw 512 ; 1セクタの大きさ(512にしなければいけない) db 1 ; クラスタの大きさ(1セクタにしなければいけない) dw 1 ; FATがどこから始まるか(普通は1セクタ目からにする) db 2 ; FATの個数(2にしなければいけない) dw 224 ; ルートディレクトリ領域の大きさ(普通は224エントリにする) dw 2880 ; このドライブの大きさ(2880セクタにしなければいけない) db 0xf0 ; メディアのタイプ(0xf0にしなければいけない) dw 9 ; FAT領域の長さ(9セクタにしなければいけない) dw 18 ; 1トラックにいくつのセクタがあるか(18にしなければいけない) dw 2 ; ヘッドの数(2にしなければいけない) DD 0 ; パーティションを使ってないのでここは必ず0 DD 2880 ; このドライブ大きさをもう一度書く db 0,0,0x29 ; よくわからないけどこの値にしておくといいらしい DD 0xffffffff ; たぶんボリュームシリアル番号 db "CLOUMO " ; ディスクの名前(11バイト) db "FAT12 " ; フォーマットの名前(8バイト) times 18 db 0 ; とりあえず18バイトあけておく ; プログラム本体 entry: mov ax,0 ; レジスタ初期化 mov ss,ax mov sp,0x7c00 mov ds,ax call startingmsg ; ディスクを読む mov ax,0x0820 mov es,ax mov ch,0 ; シリンダ0 mov dh,0 ; ヘッド0 mov cl,2 ; セクタ2 mov bx,18*2-1 ; 読み込みたい合計セクタ数 (2006.12.23 バグ修正) call readfast ; 高速読み込み mov bx,4312+0x8200+2 fatloop: add bx,-2 cmp word [bx],0 jz fatloop mov ax,bx add ax,0x7e65 ; -0x8200-5+54+53 mov bl,54 div bl ; al = ax / bl cmp al,0 jnz fatskip1 mov al,1 fatskip1: cmp al,33 jbe fatskip2 mov al,33 fatskip2: mov [0x0ff0],al ; IPLがどこまで読んだのかをメモ add al,-1 jz fatskip3 mov ah,0 imul bx,ax,18*2 mov ax,0x0c80 mov es,ax mov ch,1 ; シリンダ1 mov dh,0 ; ヘッド0 mov cl,1 ; セクタ1 call readfast ; 高速読み込み fatskip3: ; 読み終わったのでos.sysを実行だ! jmp 0xc200 putloop: mov al,[si] add si,1 ; siに1を足す cmp al,0 je return mov ah,0x0e ; 一文字表示ファンクション mov bx,15 ; カラーコード int 0x10 ; ビデオBIOS呼び出し jmp putloop error: mov ax,0 mov es,ax mov si,msg call putloop fin: hlt ; 何かあるまでCPUを停止させる jmp fin ; 無限ループ msg: db 0x0a, 0x0a ; 改行を2つ db "load error" db 0x0a ; 改行 db 0 return: ret msg_starting: db "Starting Cloumo" db 0 startingmsg: mov si,msg_starting call putloop ret readfast: ; alを使ってできるだけまとめて読み出す ; es:読み込み番地, ch:シリンダ, dh:ヘッド, cl:セクタ, bx:読み込みセクタ数 mov ax,es ; < esからalの最大値を計算 > shl ax,3 ; axを32で割って、その結果をahに入れたことになる (shlは左シフト命令) and ah,0x7f ; ahはahを128で割った余り(512*128=64K) mov al,128 ; al = 128 - ah; 一番近い64KB境界まで最大何セクタ入るか sub al,ah mov ah,bl ; < bxからalの最大値をahに計算 > cmp bh,0 ; if (bh != 0) { ah = 18; } je .skip1 mov ah,18 .skip1: cmp al,ah ; if (al > ah) { al = ah; } jbe .skip2 mov al,ah .skip2: mov ah,19 ; < clからalの最大値をahに計算 > sub ah,cl ; ah = 19 - cl; cmp al,ah ; if (al > ah) { al = ah; } jbe .skip3 mov al,ah .skip3: push bx mov si,0 ; 失敗回数を数えるレジスタ retry: mov ah,0x02 ; ah=0x02 : ディスク読み込み mov bx,0 mov dl,0x00 ; Aドライブ push es push dx push cx push ax int 0x13 ; ディスクBIOS呼び出し jnc next ; エラーがおきなければnextへ add si,1 ; siに1を足す cmp si,5 ; siと5を比較 jae error ; si >= 5 だったらerrorへ mov ah,0x00 mov dl,0x00 ; Aドライブ int 0x13 ; ドライブのリセット pop ax pop cx pop dx pop es jmp retry next: pop ax pop cx pop dx pop bx ; esの内容をbxで受け取る shr bx,5 ; bxを16バイト単位から512バイト単位へ mov ah,0 add bx,ax ; bx += al; shl bx,5 ; bxを512バイト単位から16バイト単位へ mov es,bx ; これで es += al * 0x20; になる pop bx sub bx,ax jz .ret add cl,al ; clにalを足す cmp cl,18 ; clと18を比較 jbe readfast ; cl <= 18 だったらreadfastへ mov cl,1 add dh,1 cmp dh,2 jb readfast ; dh < 2 だったらreadfastへ mov dh,0 add ch,1 jmp readfast .ret: ret times 0x1fe-($-$$) db 0 ; 0x7dfeまでを0x00で埋める命令 db 0x55, 0xaa
; A131379: Period 4: repeat [1, 0, -1, 1]. ; 1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1,1,0,-1,1 add $0,1 mod $0,4 mul $0,13 trn $0,13 mov $1,13 sub $1,$0 div $1,13
; A172078: a(n) = n*(16*n^2 + 3*n - 13)/6. ; 0,1,19,70,170,335,581,924,1380,1965,2695,3586,4654,5915,7385,9080,11016,13209,15675,18430,21490,24871,28589,32660,37100,41925,47151,52794,58870,65395,72385,79856,87824,96305,105315,114870,124986,135679,146965,158860,171380,184541,198359,212850,228030,243915,260521,277864,295960,314825,334475,354926,376194,398295,421245,445060,469756,495349,521855,549290,577670,607011,637329,668640,700960,734305,768691,804134,840650,878255,916965,956796,997764,1039885,1083175,1127650,1173326,1220219,1268345,1317720,1368360,1420281,1473499,1528030,1583890,1641095,1699661,1759604,1820940,1883685,1947855,2013466,2080534,2149075,2219105,2290640,2363696,2438289,2514435,2592150,2671450,2752351,2834869,2919020,3004820,3092285,3181431,3272274,3364830,3459115,3555145,3652936,3752504,3853865,3957035,4062030,4168866,4277559,4388125,4500580,4614940,4731221,4849439,4969610,5091750,5215875,5342001,5470144,5600320,5732545,5866835,6003206,6141674,6282255,6424965,6569820,6716836,6866029,7017415,7171010,7326830,7484891,7645209,7807800,7972680,8139865,8309371,8481214,8655410,8831975,9010925,9192276,9376044,9562245,9750895,9942010,10135606,10331699,10530305,10731440,10935120,11141361,11350179,11561590,11775610,11992255,12211541,12433484,12658100,12885405,13115415,13348146,13583614,13821835,14062825,14306600,14553176,14802569,15054795,15309870,15567810,15828631,16092349,16358980,16628540,16901045,17176511,17454954,17736390,18020835,18308305,18598816,18892384,19189025,19488755,19791590,20097546,20406639,20718885,21034300,21352900,21674701,21999719,22327970,22659470,22994235,23332281,23673624,24018280,24366265,24717595,25072286,25430354,25791815,26156685,26524980,26896716,27271909,27650575,28032730,28418390,28807571,29200289,29596560,29996400,30399825,30806851,31217494,31631770,32049695,32471285,32896556,33325524,33758205,34194615,34634770,35078686,35526379,35977865,36433160,36892280,37355241,37822059,38292750,38767330,39245815,39728221,40214564,40704860,41199125 mov $3,$0 lpb $0 sub $0,1 add $2,$3 sub $2,1 add $2,$3 add $1,$2 add $3,5 lpe
; --------------------------------------------------------------------------- ; Animation script - doors (SBZ) ; --------------------------------------------------------------------------- dc.w Ani_obj2A_Shut-Ani_obj2A dc.w Ani_obj2A_Open-Ani_obj2A Ani_obj2A_Shut: dc.b 0, 8, 7, 6, 5, 4, 3, 2, 1, 0, $FE, 1 Ani_obj2A_Open: dc.b 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, $FE, 1 even
// // execution_context.hpp // ~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_ASIO_EXECUTION_CONTEXT_HPP #define BOOST_ASIO_EXECUTION_CONTEXT_HPP #if defined(_MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include <boost/asio/detail/config.hpp> #include <cstddef> #include <stdexcept> #include <typeinfo> #include <boost/asio/detail/noncopyable.hpp> #include <boost/asio/detail/variadic_templates.hpp> #include <boost/asio/detail/push_options.hpp> namespace boost { namespace asio { class execution_context; class io_context; #if !defined(GENERATING_DOCUMENTATION) template <typename Service> Service& use_service(execution_context&); template <typename Service> Service& use_service(io_context&); template <typename Service> void add_service(execution_context&, Service*); template <typename Service> bool has_service(execution_context&); #endif // !defined(GENERATING_DOCUMENTATION) namespace detail { class service_registry; } /// A context for function object execution. /** * An execution context represents a place where function objects will be * executed. An @c io_context is an example of an execution context. * * @par The execution_context class and services * * Class execution_context implements an extensible, type-safe, polymorphic set * of services, indexed by service type. * * Services exist to manage the resources that are shared across an execution * context. For example, timers may be implemented in terms of a single timer * queue, and this queue would be stored in a service. * * Access to the services of an execution_context is via three function * templates, use_service(), add_service() and has_service(). * * In a call to @c use_service<Service>(), the type argument chooses a service, * making available all members of the named type. If @c Service is not present * in an execution_context, an object of type @c Service is created and added * to the execution_context. A C++ program can check if an execution_context * implements a particular service with the function template @c * has_service<Service>(). * * Service objects may be explicitly added to an execution_context using the * function template @c add_service<Service>(). If the @c Service is already * present, the service_already_exists exception is thrown. If the owner of the * service is not the same object as the execution_context parameter, the * invalid_service_owner exception is thrown. * * Once a service reference is obtained from an execution_context object by * calling use_service(), that reference remains usable as long as the owning * execution_context object exists. * * All service implementations have execution_context::service as a public base * class. Custom services may be implemented by deriving from this class and * then added to an execution_context using the facilities described above. * * @par The execution_context as a base class * * Class execution_context may be used only as a base class for concrete * execution context types. The @c io_context is an example of such a derived * type. * * On destruction, a class that is derived from execution_context must perform * <tt>execution_context::shutdown()</tt> followed by * <tt>execution_context::destroy()</tt>. * * This destruction sequence permits programs to simplify their resource * management by using @c shared_ptr<>. Where an object's lifetime is tied to * the lifetime of a connection (or some other sequence of asynchronous * operations), a @c shared_ptr to the object would be bound into the handlers * for all asynchronous operations associated with it. This works as follows: * * @li When a single connection ends, all associated asynchronous operations * complete. The corresponding handler objects are destroyed, and all @c * shared_ptr references to the objects are destroyed. * * @li To shut down the whole program, the io_context function stop() is called * to terminate any run() calls as soon as possible. The io_context destructor * calls @c shutdown() and @c destroy() to destroy all pending handlers, * causing all @c shared_ptr references to all connection objects to be * destroyed. */ class execution_context : private noncopyable { public: class id; class service; public: /// Constructor. BOOST_ASIO_DECL execution_context(); /// Destructor. BOOST_ASIO_DECL ~execution_context(); protected: /// Shuts down all services in the context. /** * This function is implemented as follows: * * @li For each service object @c svc in the execution_context set, in * reverse order of the beginning of service object lifetime, performs @c * svc->shutdown(). */ BOOST_ASIO_DECL void shutdown(); /// Destroys all services in the context. /** * This function is implemented as follows: * * @li For each service object @c svc in the execution_context set, in * reverse order * of the beginning of service object lifetime, performs * <tt>delete static_cast<execution_context::service*>(svc)</tt>. */ BOOST_ASIO_DECL void destroy(); public: /// Fork-related event notifications. enum fork_event { /// Notify the context that the process is about to fork. fork_prepare, /// Notify the context that the process has forked and is the parent. fork_parent, /// Notify the context that the process has forked and is the child. fork_child }; /// Notify the execution_context of a fork-related event. /** * This function is used to inform the execution_context that the process is * about to fork, or has just forked. This allows the execution_context, and * the services it contains, to perform any necessary housekeeping to ensure * correct operation following a fork. * * This function must not be called while any other execution_context * function, or any function associated with the execution_context's derived * class, is being called in another thread. It is, however, safe to call * this function from within a completion handler, provided no other thread * is accessing the execution_context or its derived class. * * @param event A fork-related event. * * @throws boost::system::system_error Thrown on failure. If the notification * fails the execution_context object should no longer be used and should be * destroyed. * * @par Example * The following code illustrates how to incorporate the notify_fork() * function: * @code my_execution_context.notify_fork(execution_context::fork_prepare); * if (fork() == 0) * { * // This is the child process. * my_execution_context.notify_fork(execution_context::fork_child); * } * else * { * // This is the parent process. * my_execution_context.notify_fork(execution_context::fork_parent); * } @endcode * * @note For each service object @c svc in the execution_context set, * performs <tt>svc->notify_fork();</tt>. When processing the fork_prepare * event, services are visited in reverse order of the beginning of service * object lifetime. Otherwise, services are visited in order of the beginning * of service object lifetime. */ BOOST_ASIO_DECL void notify_fork(fork_event event); /// Obtain the service object corresponding to the given type. /** * This function is used to locate a service object that corresponds to the * given service type. If there is no existing implementation of the service, * then the execution_context will create a new instance of the service. * * @param e The execution_context object that owns the service. * * @return The service interface implementing the specified service type. * Ownership of the service interface is not transferred to the caller. */ template <typename Service> friend Service& use_service(execution_context& e); /// Obtain the service object corresponding to the given type. /** * This function is used to locate a service object that corresponds to the * given service type. If there is no existing implementation of the service, * then the io_context will create a new instance of the service. * * @param ioc The io_context object that owns the service. * * @return The service interface implementing the specified service type. * Ownership of the service interface is not transferred to the caller. * * @note This overload is preserved for backwards compatibility with services * that inherit from io_context::service. */ template <typename Service> friend Service& use_service(io_context& ioc); #if defined(GENERATING_DOCUMENTATION) /// Creates a service object and adds it to the execution_context. /** * This function is used to add a service to the execution_context. * * @param e The execution_context object that owns the service. * * @param args Zero or more arguments to be passed to the service * constructor. * * @throws boost::asio::service_already_exists Thrown if a service of the * given type is already present in the execution_context. */ template <typename Service, typename... Args> friend Service& make_service(execution_context& e, Args&&... args); #elif defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template <typename Service, typename... Args> friend Service& make_service(execution_context& e, BOOST_ASIO_MOVE_ARG(Args)... args); #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) template <typename Service> friend Service& make_service(execution_context& e); #define BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF(n) \ template <typename Service, BOOST_ASIO_VARIADIC_TPARAMS(n)> \ friend Service& make_service(execution_context& e, \ BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)); \ /**/ BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF) #undef BOOST_ASIO_PRIVATE_MAKE_SERVICE_DEF #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES) /// (Deprecated: Use make_service().) Add a service object to the /// execution_context. /** * This function is used to add a service to the execution_context. * * @param e The execution_context object that owns the service. * * @param svc The service object. On success, ownership of the service object * is transferred to the execution_context. When the execution_context object * is destroyed, it will destroy the service object by performing: @code * delete static_cast<execution_context::service*>(svc) @endcode * * @throws boost::asio::service_already_exists Thrown if a service of the * given type is already present in the execution_context. * * @throws boost::asio::invalid_service_owner Thrown if the service's owning * execution_context is not the execution_context object specified by the * @c e parameter. */ template <typename Service> friend void add_service(execution_context& e, Service* svc); /// Determine if an execution_context contains a specified service type. /** * This function is used to determine whether the execution_context contains a * service object corresponding to the given service type. * * @param e The execution_context object that owns the service. * * @return A boolean indicating whether the execution_context contains the * service. */ template <typename Service> friend bool has_service(execution_context& e); private: // The service registry. boost::asio::detail::service_registry* service_registry_; }; /// Class used to uniquely identify a service. class execution_context::id : private noncopyable { public: /// Constructor. id() {} }; /// Base class for all io_context services. class execution_context::service : private noncopyable { public: /// Get the context object that owns the service. execution_context& context(); protected: /// Constructor. /** * @param owner The execution_context object that owns the service. */ BOOST_ASIO_DECL service(execution_context& owner); /// Destructor. BOOST_ASIO_DECL virtual ~service(); private: /// Destroy all user-defined handler objects owned by the service. virtual void shutdown() = 0; /// Handle notification of a fork-related event to perform any necessary /// housekeeping. /** * This function is not a pure virtual so that services only have to * implement it if necessary. The default implementation does nothing. */ BOOST_ASIO_DECL virtual void notify_fork( execution_context::fork_event event); friend class boost::asio::detail::service_registry; struct key { key() : type_info_(0), id_(0) {} const std::type_info* type_info_; const execution_context::id* id_; } key_; execution_context& owner_; service* next_; }; /// Exception thrown when trying to add a duplicate service to an /// execution_context. class service_already_exists : public std::logic_error { public: BOOST_ASIO_DECL service_already_exists(); }; /// Exception thrown when trying to add a service object to an /// execution_context where the service has a different owner. class invalid_service_owner : public std::logic_error { public: BOOST_ASIO_DECL invalid_service_owner(); }; namespace detail { // Special derived service id type to keep classes header-file only. template <typename Type> class service_id : public execution_context::id { }; // Special service base class to keep classes header-file only. template <typename Type> class execution_context_service_base : public execution_context::service { public: static service_id<Type> id; // Constructor. execution_context_service_base(execution_context& e) : execution_context::service(e) { } }; template <typename Type> service_id<Type> execution_context_service_base<Type>::id; } // namespace detail } // namespace asio } // namespace boost #include <boost/asio/detail/pop_options.hpp> #include <boost/asio/impl/execution_context.hpp> #if defined(BOOST_ASIO_HEADER_ONLY) # include <boost/asio/impl/execution_context.ipp> #endif // defined(BOOST_ASIO_HEADER_ONLY) #endif // BOOST_ASIO_EXECUTION_CONTEXT_HPP
_sh: file format elf32-i386 Disassembly of section .text: 00000000 <main>: return 0; } 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 static char buf[100]; int fd; // Ensure that three file descriptors are open. while((fd = open("console", O_RDWR)) >= 0){ 11: eb 0e jmp 21 <main+0x21> 13: 90 nop 14: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if(fd >= 3){ 18: 83 f8 02 cmp $0x2,%eax 1b: 0f 8f c3 00 00 00 jg e4 <main+0xe4> { static char buf[100]; int fd; // Ensure that three file descriptors are open. while((fd = open("console", O_RDWR)) >= 0){ 21: 83 ec 08 sub $0x8,%esp 24: 6a 02 push $0x2 26: 68 31 12 00 00 push $0x1231 2b: e8 32 0d 00 00 call d62 <open> 30: 83 c4 10 add $0x10,%esp 33: 85 c0 test %eax,%eax 35: 79 e1 jns 18 <main+0x18> 37: eb 2e jmp 67 <main+0x67> 39: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi } } // Read and run input commands. while(getcmd(buf, sizeof(buf)) >= 0){ if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){ 40: 80 3d 42 18 00 00 20 cmpb $0x20,0x1842 47: 74 5d je a6 <main+0xa6> 49: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi int fork1(void) { int pid; pid = fork(); 50: e8 c5 0c 00 00 call d1a <fork> if(pid == -1) 55: 83 f8 ff cmp $0xffffffff,%eax 58: 74 3f je 99 <main+0x99> buf[strlen(buf)-1] = 0; // chop \n if(chdir(buf+3) < 0) printf(2, "cannot cd %s\n", buf+3); continue; } if(fork1() == 0) 5a: 85 c0 test %eax,%eax 5c: 0f 84 98 00 00 00 je fa <main+0xfa> runcmd(parsecmd(buf)); wait(); 62: e8 c3 0c 00 00 call d2a <wait> break; } } // Read and run input commands. while(getcmd(buf, sizeof(buf)) >= 0){ 67: 83 ec 08 sub $0x8,%esp 6a: 6a 64 push $0x64 6c: 68 40 18 00 00 push $0x1840 71: e8 9a 00 00 00 call 110 <getcmd> 76: 83 c4 10 add $0x10,%esp 79: 85 c0 test %eax,%eax 7b: 78 78 js f5 <main+0xf5> if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){ 7d: 80 3d 40 18 00 00 63 cmpb $0x63,0x1840 84: 75 ca jne 50 <main+0x50> 86: 80 3d 41 18 00 00 64 cmpb $0x64,0x1841 8d: 74 b1 je 40 <main+0x40> int fork1(void) { int pid; pid = fork(); 8f: e8 86 0c 00 00 call d1a <fork> if(pid == -1) 94: 83 f8 ff cmp $0xffffffff,%eax 97: 75 c1 jne 5a <main+0x5a> panic("fork"); 99: 83 ec 0c sub $0xc,%esp 9c: 68 ba 11 00 00 push $0x11ba a1: e8 ba 00 00 00 call 160 <panic> // Read and run input commands. while(getcmd(buf, sizeof(buf)) >= 0){ if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){ // Chdir must be called by the parent, not the child. buf[strlen(buf)-1] = 0; // chop \n a6: 83 ec 0c sub $0xc,%esp a9: 68 40 18 00 00 push $0x1840 ae: e8 ad 0a 00 00 call b60 <strlen> if(chdir(buf+3) < 0) b3: c7 04 24 43 18 00 00 movl $0x1843,(%esp) // Read and run input commands. while(getcmd(buf, sizeof(buf)) >= 0){ if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' '){ // Chdir must be called by the parent, not the child. buf[strlen(buf)-1] = 0; // chop \n ba: c6 80 3f 18 00 00 00 movb $0x0,0x183f(%eax) if(chdir(buf+3) < 0) c1: e8 cc 0c 00 00 call d92 <chdir> c6: 83 c4 10 add $0x10,%esp c9: 85 c0 test %eax,%eax cb: 79 9a jns 67 <main+0x67> printf(2, "cannot cd %s\n", buf+3); cd: 50 push %eax ce: 68 43 18 00 00 push $0x1843 d3: 68 39 12 00 00 push $0x1239 d8: 6a 02 push $0x2 da: e8 91 0d 00 00 call e70 <printf> df: 83 c4 10 add $0x10,%esp e2: eb 83 jmp 67 <main+0x67> int fd; // Ensure that three file descriptors are open. while((fd = open("console", O_RDWR)) >= 0){ if(fd >= 3){ close(fd); e4: 83 ec 0c sub $0xc,%esp e7: 50 push %eax e8: e8 5d 0c 00 00 call d4a <close> break; ed: 83 c4 10 add $0x10,%esp f0: e9 72 ff ff ff jmp 67 <main+0x67> } if(fork1() == 0) runcmd(parsecmd(buf)); wait(); } exit(); f5: e8 28 0c 00 00 call d22 <exit> if(chdir(buf+3) < 0) printf(2, "cannot cd %s\n", buf+3); continue; } if(fork1() == 0) runcmd(parsecmd(buf)); fa: 83 ec 0c sub $0xc,%esp fd: 68 40 18 00 00 push $0x1840 102: e8 69 09 00 00 call a70 <parsecmd> 107: 89 04 24 mov %eax,(%esp) 10a: e8 71 00 00 00 call 180 <runcmd> 10f: 90 nop 00000110 <getcmd>: exit(); } int getcmd(char *buf, int nbuf) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 56 push %esi 114: 53 push %ebx 115: 8b 75 0c mov 0xc(%ebp),%esi 118: 8b 5d 08 mov 0x8(%ebp),%ebx printf(2, "$ "); 11b: 83 ec 08 sub $0x8,%esp 11e: 68 90 11 00 00 push $0x1190 123: 6a 02 push $0x2 125: e8 46 0d 00 00 call e70 <printf> memset(buf, 0, nbuf); 12a: 83 c4 0c add $0xc,%esp 12d: 56 push %esi 12e: 6a 00 push $0x0 130: 53 push %ebx 131: e8 5a 0a 00 00 call b90 <memset> gets(buf, nbuf); 136: 58 pop %eax 137: 5a pop %edx 138: 56 push %esi 139: 53 push %ebx 13a: e8 b1 0a 00 00 call bf0 <gets> 13f: 83 c4 10 add $0x10,%esp 142: 31 c0 xor %eax,%eax 144: 80 3b 00 cmpb $0x0,(%ebx) 147: 0f 94 c0 sete %al if(buf[0] == 0) // EOF return -1; return 0; } 14a: 8d 65 f8 lea -0x8(%ebp),%esp 14d: f7 d8 neg %eax 14f: 5b pop %ebx 150: 5e pop %esi 151: 5d pop %ebp 152: c3 ret 153: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 159: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000160 <panic>: exit(); } void panic(char *s) { 160: 55 push %ebp 161: 89 e5 mov %esp,%ebp 163: 83 ec 0c sub $0xc,%esp printf(2, "%s\n", s); 166: ff 75 08 pushl 0x8(%ebp) 169: 68 2d 12 00 00 push $0x122d 16e: 6a 02 push $0x2 170: e8 fb 0c 00 00 call e70 <printf> exit(); 175: e8 a8 0b 00 00 call d22 <exit> 17a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00000180 <runcmd>: struct cmd *parsecmd(char*); // Execute cmd. Never returns. void runcmd(struct cmd *cmd) { 180: 55 push %ebp 181: 89 e5 mov %esp,%ebp 183: 53 push %ebx 184: 83 ec 14 sub $0x14,%esp 187: 8b 5d 08 mov 0x8(%ebp),%ebx struct execcmd *ecmd; struct listcmd *lcmd; struct pipecmd *pcmd; struct redircmd *rcmd; if(cmd == 0) 18a: 85 db test %ebx,%ebx 18c: 74 76 je 204 <runcmd+0x84> exit(); switch(cmd->type){ 18e: 83 3b 05 cmpl $0x5,(%ebx) 191: 0f 87 f8 00 00 00 ja 28f <runcmd+0x10f> 197: 8b 03 mov (%ebx),%eax 199: ff 24 85 48 12 00 00 jmp *0x1248(,%eax,4) runcmd(lcmd->right); break; case PIPE: pcmd = (struct pipecmd*)cmd; if(pipe(p) < 0) 1a0: 8d 45 f0 lea -0x10(%ebp),%eax 1a3: 83 ec 0c sub $0xc,%esp 1a6: 50 push %eax 1a7: e8 86 0b 00 00 call d32 <pipe> 1ac: 83 c4 10 add $0x10,%esp 1af: 85 c0 test %eax,%eax 1b1: 0f 88 07 01 00 00 js 2be <runcmd+0x13e> int fork1(void) { int pid; pid = fork(); 1b7: e8 5e 0b 00 00 call d1a <fork> if(pid == -1) 1bc: 83 f8 ff cmp $0xffffffff,%eax 1bf: 0f 84 d7 00 00 00 je 29c <runcmd+0x11c> case PIPE: pcmd = (struct pipecmd*)cmd; if(pipe(p) < 0) panic("pipe"); if(fork1() == 0){ 1c5: 85 c0 test %eax,%eax 1c7: 0f 84 fe 00 00 00 je 2cb <runcmd+0x14b> int fork1(void) { int pid; pid = fork(); 1cd: e8 48 0b 00 00 call d1a <fork> if(pid == -1) 1d2: 83 f8 ff cmp $0xffffffff,%eax 1d5: 0f 84 c1 00 00 00 je 29c <runcmd+0x11c> dup(p[1]); close(p[0]); close(p[1]); runcmd(pcmd->left); } if(fork1() == 0){ 1db: 85 c0 test %eax,%eax 1dd: 0f 84 16 01 00 00 je 2f9 <runcmd+0x179> dup(p[0]); close(p[0]); close(p[1]); runcmd(pcmd->right); } close(p[0]); 1e3: 83 ec 0c sub $0xc,%esp 1e6: ff 75 f0 pushl -0x10(%ebp) 1e9: e8 5c 0b 00 00 call d4a <close> close(p[1]); 1ee: 58 pop %eax 1ef: ff 75 f4 pushl -0xc(%ebp) 1f2: e8 53 0b 00 00 call d4a <close> wait(); 1f7: e8 2e 0b 00 00 call d2a <wait> wait(); 1fc: e8 29 0b 00 00 call d2a <wait> break; 201: 83 c4 10 add $0x10,%esp struct listcmd *lcmd; struct pipecmd *pcmd; struct redircmd *rcmd; if(cmd == 0) exit(); 204: e8 19 0b 00 00 call d22 <exit> int fork1(void) { int pid; pid = fork(); 209: e8 0c 0b 00 00 call d1a <fork> if(pid == -1) 20e: 83 f8 ff cmp $0xffffffff,%eax 211: 0f 84 85 00 00 00 je 29c <runcmd+0x11c> wait(); break; case BACK: bcmd = (struct backcmd*)cmd; if(fork1() == 0) 217: 85 c0 test %eax,%eax 219: 75 e9 jne 204 <runcmd+0x84> 21b: eb 49 jmp 266 <runcmd+0xe6> default: panic("runcmd"); case EXEC: ecmd = (struct execcmd*)cmd; if(ecmd->argv[0] == 0) 21d: 8b 43 04 mov 0x4(%ebx),%eax 220: 85 c0 test %eax,%eax 222: 74 e0 je 204 <runcmd+0x84> exit(); exec(ecmd->argv[0], ecmd->argv); 224: 52 push %edx 225: 52 push %edx 226: 8d 53 04 lea 0x4(%ebx),%edx 229: 52 push %edx 22a: 50 push %eax 22b: e8 2a 0b 00 00 call d5a <exec> printf(2, "exec %s failed\n", ecmd->argv[0]); 230: 83 c4 0c add $0xc,%esp 233: ff 73 04 pushl 0x4(%ebx) 236: 68 9a 11 00 00 push $0x119a 23b: 6a 02 push $0x2 23d: e8 2e 0c 00 00 call e70 <printf> break; 242: 83 c4 10 add $0x10,%esp 245: eb bd jmp 204 <runcmd+0x84> case REDIR: rcmd = (struct redircmd*)cmd; close(rcmd->fd); 247: 83 ec 0c sub $0xc,%esp 24a: ff 73 14 pushl 0x14(%ebx) 24d: e8 f8 0a 00 00 call d4a <close> if(open(rcmd->file, rcmd->mode) < 0){ 252: 59 pop %ecx 253: 58 pop %eax 254: ff 73 10 pushl 0x10(%ebx) 257: ff 73 08 pushl 0x8(%ebx) 25a: e8 03 0b 00 00 call d62 <open> 25f: 83 c4 10 add $0x10,%esp 262: 85 c0 test %eax,%eax 264: 78 43 js 2a9 <runcmd+0x129> break; case BACK: bcmd = (struct backcmd*)cmd; if(fork1() == 0) runcmd(bcmd->cmd); 266: 83 ec 0c sub $0xc,%esp 269: ff 73 04 pushl 0x4(%ebx) 26c: e8 0f ff ff ff call 180 <runcmd> int fork1(void) { int pid; pid = fork(); 271: e8 a4 0a 00 00 call d1a <fork> if(pid == -1) 276: 83 f8 ff cmp $0xffffffff,%eax 279: 74 21 je 29c <runcmd+0x11c> runcmd(rcmd->cmd); break; case LIST: lcmd = (struct listcmd*)cmd; if(fork1() == 0) 27b: 85 c0 test %eax,%eax 27d: 74 e7 je 266 <runcmd+0xe6> runcmd(lcmd->left); wait(); 27f: e8 a6 0a 00 00 call d2a <wait> runcmd(lcmd->right); 284: 83 ec 0c sub $0xc,%esp 287: ff 73 08 pushl 0x8(%ebx) 28a: e8 f1 fe ff ff call 180 <runcmd> if(cmd == 0) exit(); switch(cmd->type){ default: panic("runcmd"); 28f: 83 ec 0c sub $0xc,%esp 292: 68 93 11 00 00 push $0x1193 297: e8 c4 fe ff ff call 160 <panic> { int pid; pid = fork(); if(pid == -1) panic("fork"); 29c: 83 ec 0c sub $0xc,%esp 29f: 68 ba 11 00 00 push $0x11ba 2a4: e8 b7 fe ff ff call 160 <panic> case REDIR: rcmd = (struct redircmd*)cmd; close(rcmd->fd); if(open(rcmd->file, rcmd->mode) < 0){ printf(2, "open %s failed\n", rcmd->file); 2a9: 52 push %edx 2aa: ff 73 08 pushl 0x8(%ebx) 2ad: 68 aa 11 00 00 push $0x11aa 2b2: 6a 02 push $0x2 2b4: e8 b7 0b 00 00 call e70 <printf> exit(); 2b9: e8 64 0a 00 00 call d22 <exit> break; case PIPE: pcmd = (struct pipecmd*)cmd; if(pipe(p) < 0) panic("pipe"); 2be: 83 ec 0c sub $0xc,%esp 2c1: 68 bf 11 00 00 push $0x11bf 2c6: e8 95 fe ff ff call 160 <panic> if(fork1() == 0){ close(1); 2cb: 83 ec 0c sub $0xc,%esp 2ce: 6a 01 push $0x1 2d0: e8 75 0a 00 00 call d4a <close> dup(p[1]); 2d5: 58 pop %eax 2d6: ff 75 f4 pushl -0xc(%ebp) 2d9: e8 bc 0a 00 00 call d9a <dup> close(p[0]); 2de: 58 pop %eax 2df: ff 75 f0 pushl -0x10(%ebp) 2e2: e8 63 0a 00 00 call d4a <close> close(p[1]); 2e7: 58 pop %eax 2e8: ff 75 f4 pushl -0xc(%ebp) 2eb: e8 5a 0a 00 00 call d4a <close> runcmd(pcmd->left); 2f0: 58 pop %eax 2f1: ff 73 04 pushl 0x4(%ebx) 2f4: e8 87 fe ff ff call 180 <runcmd> } if(fork1() == 0){ close(0); 2f9: 83 ec 0c sub $0xc,%esp 2fc: 6a 00 push $0x0 2fe: e8 47 0a 00 00 call d4a <close> dup(p[0]); 303: 5a pop %edx 304: ff 75 f0 pushl -0x10(%ebp) 307: e8 8e 0a 00 00 call d9a <dup> close(p[0]); 30c: 59 pop %ecx 30d: ff 75 f0 pushl -0x10(%ebp) 310: e8 35 0a 00 00 call d4a <close> close(p[1]); 315: 58 pop %eax 316: ff 75 f4 pushl -0xc(%ebp) 319: e8 2c 0a 00 00 call d4a <close> runcmd(pcmd->right); 31e: 58 pop %eax 31f: ff 73 08 pushl 0x8(%ebx) 322: e8 59 fe ff ff call 180 <runcmd> 327: 89 f6 mov %esi,%esi 329: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000330 <fork1>: exit(); } int fork1(void) { 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 83 ec 08 sub $0x8,%esp int pid; pid = fork(); 336: e8 df 09 00 00 call d1a <fork> if(pid == -1) 33b: 83 f8 ff cmp $0xffffffff,%eax 33e: 74 02 je 342 <fork1+0x12> panic("fork"); return pid; } 340: c9 leave 341: c3 ret { int pid; pid = fork(); if(pid == -1) panic("fork"); 342: 83 ec 0c sub $0xc,%esp 345: 68 ba 11 00 00 push $0x11ba 34a: e8 11 fe ff ff call 160 <panic> 34f: 90 nop 00000350 <execcmd>: //PAGEBREAK! // Constructors struct cmd* execcmd(void) { 350: 55 push %ebp 351: 89 e5 mov %esp,%ebp 353: 53 push %ebx 354: 83 ec 10 sub $0x10,%esp struct execcmd *cmd; cmd = malloc(sizeof(*cmd)); 357: 6a 54 push $0x54 359: e8 42 0d 00 00 call 10a0 <malloc> memset(cmd, 0, sizeof(*cmd)); 35e: 83 c4 0c add $0xc,%esp struct cmd* execcmd(void) { struct execcmd *cmd; cmd = malloc(sizeof(*cmd)); 361: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 363: 6a 54 push $0x54 365: 6a 00 push $0x0 367: 50 push %eax 368: e8 23 08 00 00 call b90 <memset> cmd->type = EXEC; 36d: c7 03 01 00 00 00 movl $0x1,(%ebx) return (struct cmd*)cmd; } 373: 89 d8 mov %ebx,%eax 375: 8b 5d fc mov -0x4(%ebp),%ebx 378: c9 leave 379: c3 ret 37a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 00000380 <redircmd>: struct cmd* redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd) { 380: 55 push %ebp 381: 89 e5 mov %esp,%ebp 383: 53 push %ebx 384: 83 ec 10 sub $0x10,%esp struct redircmd *cmd; cmd = malloc(sizeof(*cmd)); 387: 6a 18 push $0x18 389: e8 12 0d 00 00 call 10a0 <malloc> memset(cmd, 0, sizeof(*cmd)); 38e: 83 c4 0c add $0xc,%esp struct cmd* redircmd(struct cmd *subcmd, char *file, char *efile, int mode, int fd) { struct redircmd *cmd; cmd = malloc(sizeof(*cmd)); 391: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 393: 6a 18 push $0x18 395: 6a 00 push $0x0 397: 50 push %eax 398: e8 f3 07 00 00 call b90 <memset> cmd->type = REDIR; cmd->cmd = subcmd; 39d: 8b 45 08 mov 0x8(%ebp),%eax { struct redircmd *cmd; cmd = malloc(sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd)); cmd->type = REDIR; 3a0: c7 03 02 00 00 00 movl $0x2,(%ebx) cmd->cmd = subcmd; 3a6: 89 43 04 mov %eax,0x4(%ebx) cmd->file = file; 3a9: 8b 45 0c mov 0xc(%ebp),%eax 3ac: 89 43 08 mov %eax,0x8(%ebx) cmd->efile = efile; 3af: 8b 45 10 mov 0x10(%ebp),%eax 3b2: 89 43 0c mov %eax,0xc(%ebx) cmd->mode = mode; 3b5: 8b 45 14 mov 0x14(%ebp),%eax 3b8: 89 43 10 mov %eax,0x10(%ebx) cmd->fd = fd; 3bb: 8b 45 18 mov 0x18(%ebp),%eax 3be: 89 43 14 mov %eax,0x14(%ebx) return (struct cmd*)cmd; } 3c1: 89 d8 mov %ebx,%eax 3c3: 8b 5d fc mov -0x4(%ebp),%ebx 3c6: c9 leave 3c7: c3 ret 3c8: 90 nop 3c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000003d0 <pipecmd>: struct cmd* pipecmd(struct cmd *left, struct cmd *right) { 3d0: 55 push %ebp 3d1: 89 e5 mov %esp,%ebp 3d3: 53 push %ebx 3d4: 83 ec 10 sub $0x10,%esp struct pipecmd *cmd; cmd = malloc(sizeof(*cmd)); 3d7: 6a 0c push $0xc 3d9: e8 c2 0c 00 00 call 10a0 <malloc> memset(cmd, 0, sizeof(*cmd)); 3de: 83 c4 0c add $0xc,%esp struct cmd* pipecmd(struct cmd *left, struct cmd *right) { struct pipecmd *cmd; cmd = malloc(sizeof(*cmd)); 3e1: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 3e3: 6a 0c push $0xc 3e5: 6a 00 push $0x0 3e7: 50 push %eax 3e8: e8 a3 07 00 00 call b90 <memset> cmd->type = PIPE; cmd->left = left; 3ed: 8b 45 08 mov 0x8(%ebp),%eax { struct pipecmd *cmd; cmd = malloc(sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd)); cmd->type = PIPE; 3f0: c7 03 03 00 00 00 movl $0x3,(%ebx) cmd->left = left; 3f6: 89 43 04 mov %eax,0x4(%ebx) cmd->right = right; 3f9: 8b 45 0c mov 0xc(%ebp),%eax 3fc: 89 43 08 mov %eax,0x8(%ebx) return (struct cmd*)cmd; } 3ff: 89 d8 mov %ebx,%eax 401: 8b 5d fc mov -0x4(%ebp),%ebx 404: c9 leave 405: c3 ret 406: 8d 76 00 lea 0x0(%esi),%esi 409: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000410 <listcmd>: struct cmd* listcmd(struct cmd *left, struct cmd *right) { 410: 55 push %ebp 411: 89 e5 mov %esp,%ebp 413: 53 push %ebx 414: 83 ec 10 sub $0x10,%esp struct listcmd *cmd; cmd = malloc(sizeof(*cmd)); 417: 6a 0c push $0xc 419: e8 82 0c 00 00 call 10a0 <malloc> memset(cmd, 0, sizeof(*cmd)); 41e: 83 c4 0c add $0xc,%esp struct cmd* listcmd(struct cmd *left, struct cmd *right) { struct listcmd *cmd; cmd = malloc(sizeof(*cmd)); 421: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 423: 6a 0c push $0xc 425: 6a 00 push $0x0 427: 50 push %eax 428: e8 63 07 00 00 call b90 <memset> cmd->type = LIST; cmd->left = left; 42d: 8b 45 08 mov 0x8(%ebp),%eax { struct listcmd *cmd; cmd = malloc(sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd)); cmd->type = LIST; 430: c7 03 04 00 00 00 movl $0x4,(%ebx) cmd->left = left; 436: 89 43 04 mov %eax,0x4(%ebx) cmd->right = right; 439: 8b 45 0c mov 0xc(%ebp),%eax 43c: 89 43 08 mov %eax,0x8(%ebx) return (struct cmd*)cmd; } 43f: 89 d8 mov %ebx,%eax 441: 8b 5d fc mov -0x4(%ebp),%ebx 444: c9 leave 445: c3 ret 446: 8d 76 00 lea 0x0(%esi),%esi 449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000450 <backcmd>: struct cmd* backcmd(struct cmd *subcmd) { 450: 55 push %ebp 451: 89 e5 mov %esp,%ebp 453: 53 push %ebx 454: 83 ec 10 sub $0x10,%esp struct backcmd *cmd; cmd = malloc(sizeof(*cmd)); 457: 6a 08 push $0x8 459: e8 42 0c 00 00 call 10a0 <malloc> memset(cmd, 0, sizeof(*cmd)); 45e: 83 c4 0c add $0xc,%esp struct cmd* backcmd(struct cmd *subcmd) { struct backcmd *cmd; cmd = malloc(sizeof(*cmd)); 461: 89 c3 mov %eax,%ebx memset(cmd, 0, sizeof(*cmd)); 463: 6a 08 push $0x8 465: 6a 00 push $0x0 467: 50 push %eax 468: e8 23 07 00 00 call b90 <memset> cmd->type = BACK; cmd->cmd = subcmd; 46d: 8b 45 08 mov 0x8(%ebp),%eax { struct backcmd *cmd; cmd = malloc(sizeof(*cmd)); memset(cmd, 0, sizeof(*cmd)); cmd->type = BACK; 470: c7 03 05 00 00 00 movl $0x5,(%ebx) cmd->cmd = subcmd; 476: 89 43 04 mov %eax,0x4(%ebx) return (struct cmd*)cmd; } 479: 89 d8 mov %ebx,%eax 47b: 8b 5d fc mov -0x4(%ebp),%ebx 47e: c9 leave 47f: c3 ret 00000480 <gettoken>: char whitespace[] = " \t\r\n\v"; char symbols[] = "<|>&;()"; int gettoken(char **ps, char *es, char **q, char **eq) { 480: 55 push %ebp 481: 89 e5 mov %esp,%ebp 483: 57 push %edi 484: 56 push %esi 485: 53 push %ebx 486: 83 ec 0c sub $0xc,%esp char *s; int ret; s = *ps; 489: 8b 45 08 mov 0x8(%ebp),%eax char whitespace[] = " \t\r\n\v"; char symbols[] = "<|>&;()"; int gettoken(char **ps, char *es, char **q, char **eq) { 48c: 8b 5d 0c mov 0xc(%ebp),%ebx 48f: 8b 75 10 mov 0x10(%ebp),%esi char *s; int ret; s = *ps; 492: 8b 38 mov (%eax),%edi while(s < es && strchr(whitespace, *s)) 494: 39 df cmp %ebx,%edi 496: 72 13 jb 4ab <gettoken+0x2b> 498: eb 29 jmp 4c3 <gettoken+0x43> 49a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi s++; 4a0: 83 c7 01 add $0x1,%edi { char *s; int ret; s = *ps; while(s < es && strchr(whitespace, *s)) 4a3: 39 fb cmp %edi,%ebx 4a5: 0f 84 ed 00 00 00 je 598 <gettoken+0x118> 4ab: 0f be 07 movsbl (%edi),%eax 4ae: 83 ec 08 sub $0x8,%esp 4b1: 50 push %eax 4b2: 68 38 18 00 00 push $0x1838 4b7: e8 f4 06 00 00 call bb0 <strchr> 4bc: 83 c4 10 add $0x10,%esp 4bf: 85 c0 test %eax,%eax 4c1: 75 dd jne 4a0 <gettoken+0x20> s++; if(q) 4c3: 85 f6 test %esi,%esi 4c5: 74 02 je 4c9 <gettoken+0x49> *q = s; 4c7: 89 3e mov %edi,(%esi) ret = *s; 4c9: 0f be 37 movsbl (%edi),%esi 4cc: 89 f1 mov %esi,%ecx 4ce: 89 f0 mov %esi,%eax switch(*s){ 4d0: 80 f9 29 cmp $0x29,%cl 4d3: 7f 5b jg 530 <gettoken+0xb0> 4d5: 80 f9 28 cmp $0x28,%cl 4d8: 7d 61 jge 53b <gettoken+0xbb> 4da: 84 c9 test %cl,%cl 4dc: 0f 85 de 00 00 00 jne 5c0 <gettoken+0x140> ret = 'a'; while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) s++; break; } if(eq) 4e2: 8b 55 14 mov 0x14(%ebp),%edx 4e5: 85 d2 test %edx,%edx 4e7: 74 05 je 4ee <gettoken+0x6e> *eq = s; 4e9: 8b 45 14 mov 0x14(%ebp),%eax 4ec: 89 38 mov %edi,(%eax) while(s < es && strchr(whitespace, *s)) 4ee: 39 fb cmp %edi,%ebx 4f0: 77 0d ja 4ff <gettoken+0x7f> 4f2: eb 23 jmp 517 <gettoken+0x97> 4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi s++; 4f8: 83 c7 01 add $0x1,%edi break; } if(eq) *eq = s; while(s < es && strchr(whitespace, *s)) 4fb: 39 fb cmp %edi,%ebx 4fd: 74 18 je 517 <gettoken+0x97> 4ff: 0f be 07 movsbl (%edi),%eax 502: 83 ec 08 sub $0x8,%esp 505: 50 push %eax 506: 68 38 18 00 00 push $0x1838 50b: e8 a0 06 00 00 call bb0 <strchr> 510: 83 c4 10 add $0x10,%esp 513: 85 c0 test %eax,%eax 515: 75 e1 jne 4f8 <gettoken+0x78> s++; *ps = s; 517: 8b 45 08 mov 0x8(%ebp),%eax 51a: 89 38 mov %edi,(%eax) return ret; } 51c: 8d 65 f4 lea -0xc(%ebp),%esp 51f: 89 f0 mov %esi,%eax 521: 5b pop %ebx 522: 5e pop %esi 523: 5f pop %edi 524: 5d pop %ebp 525: c3 ret 526: 8d 76 00 lea 0x0(%esi),%esi 529: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi while(s < es && strchr(whitespace, *s)) s++; if(q) *q = s; ret = *s; switch(*s){ 530: 80 f9 3e cmp $0x3e,%cl 533: 75 0b jne 540 <gettoken+0xc0> case '<': s++; break; case '>': s++; if(*s == '>'){ 535: 80 7f 01 3e cmpb $0x3e,0x1(%edi) 539: 74 75 je 5b0 <gettoken+0x130> case '&': case '<': s++; break; case '>': s++; 53b: 83 c7 01 add $0x1,%edi 53e: eb a2 jmp 4e2 <gettoken+0x62> while(s < es && strchr(whitespace, *s)) s++; if(q) *q = s; ret = *s; switch(*s){ 540: 7f 5e jg 5a0 <gettoken+0x120> 542: 83 e9 3b sub $0x3b,%ecx 545: 80 f9 01 cmp $0x1,%cl 548: 76 f1 jbe 53b <gettoken+0xbb> s++; } break; default: ret = 'a'; while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) 54a: 39 fb cmp %edi,%ebx 54c: 77 24 ja 572 <gettoken+0xf2> 54e: eb 7c jmp 5cc <gettoken+0x14c> 550: 0f be 07 movsbl (%edi),%eax 553: 83 ec 08 sub $0x8,%esp 556: 50 push %eax 557: 68 30 18 00 00 push $0x1830 55c: e8 4f 06 00 00 call bb0 <strchr> 561: 83 c4 10 add $0x10,%esp 564: 85 c0 test %eax,%eax 566: 75 1f jne 587 <gettoken+0x107> s++; 568: 83 c7 01 add $0x1,%edi s++; } break; default: ret = 'a'; while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) 56b: 39 fb cmp %edi,%ebx 56d: 74 5b je 5ca <gettoken+0x14a> 56f: 0f be 07 movsbl (%edi),%eax 572: 83 ec 08 sub $0x8,%esp 575: 50 push %eax 576: 68 38 18 00 00 push $0x1838 57b: e8 30 06 00 00 call bb0 <strchr> 580: 83 c4 10 add $0x10,%esp 583: 85 c0 test %eax,%eax 585: 74 c9 je 550 <gettoken+0xd0> ret = '+'; s++; } break; default: ret = 'a'; 587: be 61 00 00 00 mov $0x61,%esi 58c: e9 51 ff ff ff jmp 4e2 <gettoken+0x62> 591: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 598: 89 df mov %ebx,%edi 59a: e9 24 ff ff ff jmp 4c3 <gettoken+0x43> 59f: 90 nop while(s < es && strchr(whitespace, *s)) s++; if(q) *q = s; ret = *s; switch(*s){ 5a0: 80 f9 7c cmp $0x7c,%cl 5a3: 74 96 je 53b <gettoken+0xbb> 5a5: eb a3 jmp 54a <gettoken+0xca> 5a7: 89 f6 mov %esi,%esi 5a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi break; case '>': s++; if(*s == '>'){ ret = '+'; s++; 5b0: 83 c7 02 add $0x2,%edi s++; break; case '>': s++; if(*s == '>'){ ret = '+'; 5b3: be 2b 00 00 00 mov $0x2b,%esi 5b8: e9 25 ff ff ff jmp 4e2 <gettoken+0x62> 5bd: 8d 76 00 lea 0x0(%esi),%esi while(s < es && strchr(whitespace, *s)) s++; if(q) *q = s; ret = *s; switch(*s){ 5c0: 80 f9 26 cmp $0x26,%cl 5c3: 75 85 jne 54a <gettoken+0xca> 5c5: e9 71 ff ff ff jmp 53b <gettoken+0xbb> 5ca: 89 df mov %ebx,%edi ret = 'a'; while(s < es && !strchr(whitespace, *s) && !strchr(symbols, *s)) s++; break; } if(eq) 5cc: 8b 45 14 mov 0x14(%ebp),%eax 5cf: be 61 00 00 00 mov $0x61,%esi 5d4: 85 c0 test %eax,%eax 5d6: 0f 85 0d ff ff ff jne 4e9 <gettoken+0x69> 5dc: e9 36 ff ff ff jmp 517 <gettoken+0x97> 5e1: eb 0d jmp 5f0 <peek> 5e3: 90 nop 5e4: 90 nop 5e5: 90 nop 5e6: 90 nop 5e7: 90 nop 5e8: 90 nop 5e9: 90 nop 5ea: 90 nop 5eb: 90 nop 5ec: 90 nop 5ed: 90 nop 5ee: 90 nop 5ef: 90 nop 000005f0 <peek>: return ret; } int peek(char **ps, char *es, char *toks) { 5f0: 55 push %ebp 5f1: 89 e5 mov %esp,%ebp 5f3: 57 push %edi 5f4: 56 push %esi 5f5: 53 push %ebx 5f6: 83 ec 0c sub $0xc,%esp 5f9: 8b 7d 08 mov 0x8(%ebp),%edi 5fc: 8b 75 0c mov 0xc(%ebp),%esi char *s; s = *ps; 5ff: 8b 1f mov (%edi),%ebx while(s < es && strchr(whitespace, *s)) 601: 39 f3 cmp %esi,%ebx 603: 72 12 jb 617 <peek+0x27> 605: eb 28 jmp 62f <peek+0x3f> 607: 89 f6 mov %esi,%esi 609: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi s++; 610: 83 c3 01 add $0x1,%ebx peek(char **ps, char *es, char *toks) { char *s; s = *ps; while(s < es && strchr(whitespace, *s)) 613: 39 de cmp %ebx,%esi 615: 74 18 je 62f <peek+0x3f> 617: 0f be 03 movsbl (%ebx),%eax 61a: 83 ec 08 sub $0x8,%esp 61d: 50 push %eax 61e: 68 38 18 00 00 push $0x1838 623: e8 88 05 00 00 call bb0 <strchr> 628: 83 c4 10 add $0x10,%esp 62b: 85 c0 test %eax,%eax 62d: 75 e1 jne 610 <peek+0x20> s++; *ps = s; 62f: 89 1f mov %ebx,(%edi) return *s && strchr(toks, *s); 631: 0f be 13 movsbl (%ebx),%edx 634: 31 c0 xor %eax,%eax 636: 84 d2 test %dl,%dl 638: 74 17 je 651 <peek+0x61> 63a: 83 ec 08 sub $0x8,%esp 63d: 52 push %edx 63e: ff 75 10 pushl 0x10(%ebp) 641: e8 6a 05 00 00 call bb0 <strchr> 646: 83 c4 10 add $0x10,%esp 649: 85 c0 test %eax,%eax 64b: 0f 95 c0 setne %al 64e: 0f b6 c0 movzbl %al,%eax } 651: 8d 65 f4 lea -0xc(%ebp),%esp 654: 5b pop %ebx 655: 5e pop %esi 656: 5f pop %edi 657: 5d pop %ebp 658: c3 ret 659: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000660 <parseredirs>: return cmd; } struct cmd* parseredirs(struct cmd *cmd, char **ps, char *es) { 660: 55 push %ebp 661: 89 e5 mov %esp,%ebp 663: 57 push %edi 664: 56 push %esi 665: 53 push %ebx 666: 83 ec 1c sub $0x1c,%esp 669: 8b 75 0c mov 0xc(%ebp),%esi 66c: 8b 5d 10 mov 0x10(%ebp),%ebx 66f: 90 nop int tok; char *q, *eq; while(peek(ps, es, "<>")){ 670: 83 ec 04 sub $0x4,%esp 673: 68 e1 11 00 00 push $0x11e1 678: 53 push %ebx 679: 56 push %esi 67a: e8 71 ff ff ff call 5f0 <peek> 67f: 83 c4 10 add $0x10,%esp 682: 85 c0 test %eax,%eax 684: 74 6a je 6f0 <parseredirs+0x90> tok = gettoken(ps, es, 0, 0); 686: 6a 00 push $0x0 688: 6a 00 push $0x0 68a: 53 push %ebx 68b: 56 push %esi 68c: e8 ef fd ff ff call 480 <gettoken> 691: 89 c7 mov %eax,%edi if(gettoken(ps, es, &q, &eq) != 'a') 693: 8d 45 e4 lea -0x1c(%ebp),%eax 696: 50 push %eax 697: 8d 45 e0 lea -0x20(%ebp),%eax 69a: 50 push %eax 69b: 53 push %ebx 69c: 56 push %esi 69d: e8 de fd ff ff call 480 <gettoken> 6a2: 83 c4 20 add $0x20,%esp 6a5: 83 f8 61 cmp $0x61,%eax 6a8: 75 51 jne 6fb <parseredirs+0x9b> panic("missing file for redirection"); switch(tok){ 6aa: 83 ff 3c cmp $0x3c,%edi 6ad: 74 31 je 6e0 <parseredirs+0x80> 6af: 83 ff 3e cmp $0x3e,%edi 6b2: 74 05 je 6b9 <parseredirs+0x59> 6b4: 83 ff 2b cmp $0x2b,%edi 6b7: 75 b7 jne 670 <parseredirs+0x10> break; case '>': cmd = redircmd(cmd, q, eq, O_WRONLY|O_CREATE, 1); break; case '+': // >> cmd = redircmd(cmd, q, eq, O_WRONLY|O_CREATE, 1); 6b9: 83 ec 0c sub $0xc,%esp 6bc: 6a 01 push $0x1 6be: 68 01 02 00 00 push $0x201 6c3: ff 75 e4 pushl -0x1c(%ebp) 6c6: ff 75 e0 pushl -0x20(%ebp) 6c9: ff 75 08 pushl 0x8(%ebp) 6cc: e8 af fc ff ff call 380 <redircmd> break; 6d1: 83 c4 20 add $0x20,%esp break; case '>': cmd = redircmd(cmd, q, eq, O_WRONLY|O_CREATE, 1); break; case '+': // >> cmd = redircmd(cmd, q, eq, O_WRONLY|O_CREATE, 1); 6d4: 89 45 08 mov %eax,0x8(%ebp) break; 6d7: eb 97 jmp 670 <parseredirs+0x10> 6d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi tok = gettoken(ps, es, 0, 0); if(gettoken(ps, es, &q, &eq) != 'a') panic("missing file for redirection"); switch(tok){ case '<': cmd = redircmd(cmd, q, eq, O_RDONLY, 0); 6e0: 83 ec 0c sub $0xc,%esp 6e3: 6a 00 push $0x0 6e5: 6a 00 push $0x0 6e7: eb da jmp 6c3 <parseredirs+0x63> 6e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi cmd = redircmd(cmd, q, eq, O_WRONLY|O_CREATE, 1); break; } } return cmd; } 6f0: 8b 45 08 mov 0x8(%ebp),%eax 6f3: 8d 65 f4 lea -0xc(%ebp),%esp 6f6: 5b pop %ebx 6f7: 5e pop %esi 6f8: 5f pop %edi 6f9: 5d pop %ebp 6fa: c3 ret char *q, *eq; while(peek(ps, es, "<>")){ tok = gettoken(ps, es, 0, 0); if(gettoken(ps, es, &q, &eq) != 'a') panic("missing file for redirection"); 6fb: 83 ec 0c sub $0xc,%esp 6fe: 68 c4 11 00 00 push $0x11c4 703: e8 58 fa ff ff call 160 <panic> 708: 90 nop 709: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000710 <parseexec>: return cmd; } struct cmd* parseexec(char **ps, char *es) { 710: 55 push %ebp 711: 89 e5 mov %esp,%ebp 713: 57 push %edi 714: 56 push %esi 715: 53 push %ebx 716: 83 ec 30 sub $0x30,%esp 719: 8b 75 08 mov 0x8(%ebp),%esi 71c: 8b 7d 0c mov 0xc(%ebp),%edi char *q, *eq; int tok, argc; struct execcmd *cmd; struct cmd *ret; if(peek(ps, es, "(")) 71f: 68 e4 11 00 00 push $0x11e4 724: 57 push %edi 725: 56 push %esi 726: e8 c5 fe ff ff call 5f0 <peek> 72b: 83 c4 10 add $0x10,%esp 72e: 85 c0 test %eax,%eax 730: 0f 85 9a 00 00 00 jne 7d0 <parseexec+0xc0> return parseblock(ps, es); ret = execcmd(); 736: e8 15 fc ff ff call 350 <execcmd> cmd = (struct execcmd*)ret; argc = 0; ret = parseredirs(ret, ps, es); 73b: 83 ec 04 sub $0x4,%esp struct cmd *ret; if(peek(ps, es, "(")) return parseblock(ps, es); ret = execcmd(); 73e: 89 c3 mov %eax,%ebx 740: 89 45 cc mov %eax,-0x34(%ebp) cmd = (struct execcmd*)ret; argc = 0; ret = parseredirs(ret, ps, es); 743: 57 push %edi 744: 56 push %esi 745: 8d 5b 04 lea 0x4(%ebx),%ebx 748: 50 push %eax 749: e8 12 ff ff ff call 660 <parseredirs> 74e: 83 c4 10 add $0x10,%esp 751: 89 45 d0 mov %eax,-0x30(%ebp) return parseblock(ps, es); ret = execcmd(); cmd = (struct execcmd*)ret; argc = 0; 754: c7 45 d4 00 00 00 00 movl $0x0,-0x2c(%ebp) 75b: eb 16 jmp 773 <parseexec+0x63> 75d: 8d 76 00 lea 0x0(%esi),%esi cmd->argv[argc] = q; cmd->eargv[argc] = eq; argc++; if(argc >= MAXARGS) panic("too many args"); ret = parseredirs(ret, ps, es); 760: 83 ec 04 sub $0x4,%esp 763: 57 push %edi 764: 56 push %esi 765: ff 75 d0 pushl -0x30(%ebp) 768: e8 f3 fe ff ff call 660 <parseredirs> 76d: 83 c4 10 add $0x10,%esp 770: 89 45 d0 mov %eax,-0x30(%ebp) ret = execcmd(); cmd = (struct execcmd*)ret; argc = 0; ret = parseredirs(ret, ps, es); while(!peek(ps, es, "|)&;")){ 773: 83 ec 04 sub $0x4,%esp 776: 68 fb 11 00 00 push $0x11fb 77b: 57 push %edi 77c: 56 push %esi 77d: e8 6e fe ff ff call 5f0 <peek> 782: 83 c4 10 add $0x10,%esp 785: 85 c0 test %eax,%eax 787: 75 5f jne 7e8 <parseexec+0xd8> if((tok=gettoken(ps, es, &q, &eq)) == 0) 789: 8d 45 e4 lea -0x1c(%ebp),%eax 78c: 50 push %eax 78d: 8d 45 e0 lea -0x20(%ebp),%eax 790: 50 push %eax 791: 57 push %edi 792: 56 push %esi 793: e8 e8 fc ff ff call 480 <gettoken> 798: 83 c4 10 add $0x10,%esp 79b: 85 c0 test %eax,%eax 79d: 74 49 je 7e8 <parseexec+0xd8> break; if(tok != 'a') 79f: 83 f8 61 cmp $0x61,%eax 7a2: 75 66 jne 80a <parseexec+0xfa> panic("syntax"); cmd->argv[argc] = q; 7a4: 8b 45 e0 mov -0x20(%ebp),%eax cmd->eargv[argc] = eq; argc++; 7a7: 83 45 d4 01 addl $0x1,-0x2c(%ebp) 7ab: 83 c3 04 add $0x4,%ebx while(!peek(ps, es, "|)&;")){ if((tok=gettoken(ps, es, &q, &eq)) == 0) break; if(tok != 'a') panic("syntax"); cmd->argv[argc] = q; 7ae: 89 43 fc mov %eax,-0x4(%ebx) cmd->eargv[argc] = eq; 7b1: 8b 45 e4 mov -0x1c(%ebp),%eax 7b4: 89 43 24 mov %eax,0x24(%ebx) argc++; 7b7: 8b 45 d4 mov -0x2c(%ebp),%eax if(argc >= MAXARGS) 7ba: 83 f8 0a cmp $0xa,%eax 7bd: 75 a1 jne 760 <parseexec+0x50> panic("too many args"); 7bf: 83 ec 0c sub $0xc,%esp 7c2: 68 ed 11 00 00 push $0x11ed 7c7: e8 94 f9 ff ff call 160 <panic> 7cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi int tok, argc; struct execcmd *cmd; struct cmd *ret; if(peek(ps, es, "(")) return parseblock(ps, es); 7d0: 83 ec 08 sub $0x8,%esp 7d3: 57 push %edi 7d4: 56 push %esi 7d5: e8 56 01 00 00 call 930 <parseblock> 7da: 83 c4 10 add $0x10,%esp ret = parseredirs(ret, ps, es); } cmd->argv[argc] = 0; cmd->eargv[argc] = 0; return ret; } 7dd: 8d 65 f4 lea -0xc(%ebp),%esp 7e0: 5b pop %ebx 7e1: 5e pop %esi 7e2: 5f pop %edi 7e3: 5d pop %ebp 7e4: c3 ret 7e5: 8d 76 00 lea 0x0(%esi),%esi 7e8: 8b 45 cc mov -0x34(%ebp),%eax 7eb: 8b 55 d4 mov -0x2c(%ebp),%edx 7ee: 8d 04 90 lea (%eax,%edx,4),%eax argc++; if(argc >= MAXARGS) panic("too many args"); ret = parseredirs(ret, ps, es); } cmd->argv[argc] = 0; 7f1: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) cmd->eargv[argc] = 0; 7f8: c7 40 2c 00 00 00 00 movl $0x0,0x2c(%eax) 7ff: 8b 45 d0 mov -0x30(%ebp),%eax return ret; } 802: 8d 65 f4 lea -0xc(%ebp),%esp 805: 5b pop %ebx 806: 5e pop %esi 807: 5f pop %edi 808: 5d pop %ebp 809: c3 ret ret = parseredirs(ret, ps, es); while(!peek(ps, es, "|)&;")){ if((tok=gettoken(ps, es, &q, &eq)) == 0) break; if(tok != 'a') panic("syntax"); 80a: 83 ec 0c sub $0xc,%esp 80d: 68 e6 11 00 00 push $0x11e6 812: e8 49 f9 ff ff call 160 <panic> 817: 89 f6 mov %esi,%esi 819: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000820 <parsepipe>: return cmd; } struct cmd* parsepipe(char **ps, char *es) { 820: 55 push %ebp 821: 89 e5 mov %esp,%ebp 823: 57 push %edi 824: 56 push %esi 825: 53 push %ebx 826: 83 ec 14 sub $0x14,%esp 829: 8b 5d 08 mov 0x8(%ebp),%ebx 82c: 8b 75 0c mov 0xc(%ebp),%esi struct cmd *cmd; cmd = parseexec(ps, es); 82f: 56 push %esi 830: 53 push %ebx 831: e8 da fe ff ff call 710 <parseexec> if(peek(ps, es, "|")){ 836: 83 c4 0c add $0xc,%esp struct cmd* parsepipe(char **ps, char *es) { struct cmd *cmd; cmd = parseexec(ps, es); 839: 89 c7 mov %eax,%edi if(peek(ps, es, "|")){ 83b: 68 00 12 00 00 push $0x1200 840: 56 push %esi 841: 53 push %ebx 842: e8 a9 fd ff ff call 5f0 <peek> 847: 83 c4 10 add $0x10,%esp 84a: 85 c0 test %eax,%eax 84c: 75 12 jne 860 <parsepipe+0x40> gettoken(ps, es, 0, 0); cmd = pipecmd(cmd, parsepipe(ps, es)); } return cmd; } 84e: 8d 65 f4 lea -0xc(%ebp),%esp 851: 89 f8 mov %edi,%eax 853: 5b pop %ebx 854: 5e pop %esi 855: 5f pop %edi 856: 5d pop %ebp 857: c3 ret 858: 90 nop 859: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi { struct cmd *cmd; cmd = parseexec(ps, es); if(peek(ps, es, "|")){ gettoken(ps, es, 0, 0); 860: 6a 00 push $0x0 862: 6a 00 push $0x0 864: 56 push %esi 865: 53 push %ebx 866: e8 15 fc ff ff call 480 <gettoken> cmd = pipecmd(cmd, parsepipe(ps, es)); 86b: 58 pop %eax 86c: 5a pop %edx 86d: 56 push %esi 86e: 53 push %ebx 86f: e8 ac ff ff ff call 820 <parsepipe> 874: 89 7d 08 mov %edi,0x8(%ebp) 877: 89 45 0c mov %eax,0xc(%ebp) 87a: 83 c4 10 add $0x10,%esp } return cmd; } 87d: 8d 65 f4 lea -0xc(%ebp),%esp 880: 5b pop %ebx 881: 5e pop %esi 882: 5f pop %edi 883: 5d pop %ebp struct cmd *cmd; cmd = parseexec(ps, es); if(peek(ps, es, "|")){ gettoken(ps, es, 0, 0); cmd = pipecmd(cmd, parsepipe(ps, es)); 884: e9 47 fb ff ff jmp 3d0 <pipecmd> 889: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000890 <parseline>: return cmd; } struct cmd* parseline(char **ps, char *es) { 890: 55 push %ebp 891: 89 e5 mov %esp,%ebp 893: 57 push %edi 894: 56 push %esi 895: 53 push %ebx 896: 83 ec 14 sub $0x14,%esp 899: 8b 5d 08 mov 0x8(%ebp),%ebx 89c: 8b 75 0c mov 0xc(%ebp),%esi struct cmd *cmd; cmd = parsepipe(ps, es); 89f: 56 push %esi 8a0: 53 push %ebx 8a1: e8 7a ff ff ff call 820 <parsepipe> while(peek(ps, es, "&")){ 8a6: 83 c4 10 add $0x10,%esp struct cmd* parseline(char **ps, char *es) { struct cmd *cmd; cmd = parsepipe(ps, es); 8a9: 89 c7 mov %eax,%edi while(peek(ps, es, "&")){ 8ab: eb 1b jmp 8c8 <parseline+0x38> 8ad: 8d 76 00 lea 0x0(%esi),%esi gettoken(ps, es, 0, 0); 8b0: 6a 00 push $0x0 8b2: 6a 00 push $0x0 8b4: 56 push %esi 8b5: 53 push %ebx 8b6: e8 c5 fb ff ff call 480 <gettoken> cmd = backcmd(cmd); 8bb: 89 3c 24 mov %edi,(%esp) 8be: e8 8d fb ff ff call 450 <backcmd> 8c3: 83 c4 10 add $0x10,%esp 8c6: 89 c7 mov %eax,%edi parseline(char **ps, char *es) { struct cmd *cmd; cmd = parsepipe(ps, es); while(peek(ps, es, "&")){ 8c8: 83 ec 04 sub $0x4,%esp 8cb: 68 02 12 00 00 push $0x1202 8d0: 56 push %esi 8d1: 53 push %ebx 8d2: e8 19 fd ff ff call 5f0 <peek> 8d7: 83 c4 10 add $0x10,%esp 8da: 85 c0 test %eax,%eax 8dc: 75 d2 jne 8b0 <parseline+0x20> gettoken(ps, es, 0, 0); cmd = backcmd(cmd); } if(peek(ps, es, ";")){ 8de: 83 ec 04 sub $0x4,%esp 8e1: 68 fe 11 00 00 push $0x11fe 8e6: 56 push %esi 8e7: 53 push %ebx 8e8: e8 03 fd ff ff call 5f0 <peek> 8ed: 83 c4 10 add $0x10,%esp 8f0: 85 c0 test %eax,%eax 8f2: 75 0c jne 900 <parseline+0x70> gettoken(ps, es, 0, 0); cmd = listcmd(cmd, parseline(ps, es)); } return cmd; } 8f4: 8d 65 f4 lea -0xc(%ebp),%esp 8f7: 89 f8 mov %edi,%eax 8f9: 5b pop %ebx 8fa: 5e pop %esi 8fb: 5f pop %edi 8fc: 5d pop %ebp 8fd: c3 ret 8fe: 66 90 xchg %ax,%ax while(peek(ps, es, "&")){ gettoken(ps, es, 0, 0); cmd = backcmd(cmd); } if(peek(ps, es, ";")){ gettoken(ps, es, 0, 0); 900: 6a 00 push $0x0 902: 6a 00 push $0x0 904: 56 push %esi 905: 53 push %ebx 906: e8 75 fb ff ff call 480 <gettoken> cmd = listcmd(cmd, parseline(ps, es)); 90b: 58 pop %eax 90c: 5a pop %edx 90d: 56 push %esi 90e: 53 push %ebx 90f: e8 7c ff ff ff call 890 <parseline> 914: 89 7d 08 mov %edi,0x8(%ebp) 917: 89 45 0c mov %eax,0xc(%ebp) 91a: 83 c4 10 add $0x10,%esp } return cmd; } 91d: 8d 65 f4 lea -0xc(%ebp),%esp 920: 5b pop %ebx 921: 5e pop %esi 922: 5f pop %edi 923: 5d pop %ebp gettoken(ps, es, 0, 0); cmd = backcmd(cmd); } if(peek(ps, es, ";")){ gettoken(ps, es, 0, 0); cmd = listcmd(cmd, parseline(ps, es)); 924: e9 e7 fa ff ff jmp 410 <listcmd> 929: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000930 <parseblock>: return cmd; } struct cmd* parseblock(char **ps, char *es) { 930: 55 push %ebp 931: 89 e5 mov %esp,%ebp 933: 57 push %edi 934: 56 push %esi 935: 53 push %ebx 936: 83 ec 10 sub $0x10,%esp 939: 8b 5d 08 mov 0x8(%ebp),%ebx 93c: 8b 75 0c mov 0xc(%ebp),%esi struct cmd *cmd; if(!peek(ps, es, "(")) 93f: 68 e4 11 00 00 push $0x11e4 944: 56 push %esi 945: 53 push %ebx 946: e8 a5 fc ff ff call 5f0 <peek> 94b: 83 c4 10 add $0x10,%esp 94e: 85 c0 test %eax,%eax 950: 74 4a je 99c <parseblock+0x6c> panic("parseblock"); gettoken(ps, es, 0, 0); 952: 6a 00 push $0x0 954: 6a 00 push $0x0 956: 56 push %esi 957: 53 push %ebx 958: e8 23 fb ff ff call 480 <gettoken> cmd = parseline(ps, es); 95d: 58 pop %eax 95e: 5a pop %edx 95f: 56 push %esi 960: 53 push %ebx 961: e8 2a ff ff ff call 890 <parseline> if(!peek(ps, es, ")")) 966: 83 c4 0c add $0xc,%esp struct cmd *cmd; if(!peek(ps, es, "(")) panic("parseblock"); gettoken(ps, es, 0, 0); cmd = parseline(ps, es); 969: 89 c7 mov %eax,%edi if(!peek(ps, es, ")")) 96b: 68 20 12 00 00 push $0x1220 970: 56 push %esi 971: 53 push %ebx 972: e8 79 fc ff ff call 5f0 <peek> 977: 83 c4 10 add $0x10,%esp 97a: 85 c0 test %eax,%eax 97c: 74 2b je 9a9 <parseblock+0x79> panic("syntax - missing )"); gettoken(ps, es, 0, 0); 97e: 6a 00 push $0x0 980: 6a 00 push $0x0 982: 56 push %esi 983: 53 push %ebx 984: e8 f7 fa ff ff call 480 <gettoken> cmd = parseredirs(cmd, ps, es); 989: 83 c4 0c add $0xc,%esp 98c: 56 push %esi 98d: 53 push %ebx 98e: 57 push %edi 98f: e8 cc fc ff ff call 660 <parseredirs> return cmd; } 994: 8d 65 f4 lea -0xc(%ebp),%esp 997: 5b pop %ebx 998: 5e pop %esi 999: 5f pop %edi 99a: 5d pop %ebp 99b: c3 ret parseblock(char **ps, char *es) { struct cmd *cmd; if(!peek(ps, es, "(")) panic("parseblock"); 99c: 83 ec 0c sub $0xc,%esp 99f: 68 04 12 00 00 push $0x1204 9a4: e8 b7 f7 ff ff call 160 <panic> gettoken(ps, es, 0, 0); cmd = parseline(ps, es); if(!peek(ps, es, ")")) panic("syntax - missing )"); 9a9: 83 ec 0c sub $0xc,%esp 9ac: 68 0f 12 00 00 push $0x120f 9b1: e8 aa f7 ff ff call 160 <panic> 9b6: 8d 76 00 lea 0x0(%esi),%esi 9b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000009c0 <nulterminate>: } // NUL-terminate all the counted strings. struct cmd* nulterminate(struct cmd *cmd) { 9c0: 55 push %ebp 9c1: 89 e5 mov %esp,%ebp 9c3: 53 push %ebx 9c4: 83 ec 04 sub $0x4,%esp 9c7: 8b 5d 08 mov 0x8(%ebp),%ebx struct execcmd *ecmd; struct listcmd *lcmd; struct pipecmd *pcmd; struct redircmd *rcmd; if(cmd == 0) 9ca: 85 db test %ebx,%ebx 9cc: 0f 84 96 00 00 00 je a68 <nulterminate+0xa8> return 0; switch(cmd->type){ 9d2: 83 3b 05 cmpl $0x5,(%ebx) 9d5: 77 48 ja a1f <nulterminate+0x5f> 9d7: 8b 03 mov (%ebx),%eax 9d9: ff 24 85 60 12 00 00 jmp *0x1260(,%eax,4) nulterminate(pcmd->right); break; case LIST: lcmd = (struct listcmd*)cmd; nulterminate(lcmd->left); 9e0: 83 ec 0c sub $0xc,%esp 9e3: ff 73 04 pushl 0x4(%ebx) 9e6: e8 d5 ff ff ff call 9c0 <nulterminate> nulterminate(lcmd->right); 9eb: 58 pop %eax 9ec: ff 73 08 pushl 0x8(%ebx) 9ef: e8 cc ff ff ff call 9c0 <nulterminate> break; 9f4: 83 c4 10 add $0x10,%esp 9f7: 89 d8 mov %ebx,%eax bcmd = (struct backcmd*)cmd; nulterminate(bcmd->cmd); break; } return cmd; } 9f9: 8b 5d fc mov -0x4(%ebp),%ebx 9fc: c9 leave 9fd: c3 ret 9fe: 66 90 xchg %ax,%ax return 0; switch(cmd->type){ case EXEC: ecmd = (struct execcmd*)cmd; for(i=0; ecmd->argv[i]; i++) a00: 8b 4b 04 mov 0x4(%ebx),%ecx a03: 8d 43 2c lea 0x2c(%ebx),%eax a06: 85 c9 test %ecx,%ecx a08: 74 15 je a1f <nulterminate+0x5f> a0a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi *ecmd->eargv[i] = 0; a10: 8b 10 mov (%eax),%edx a12: 83 c0 04 add $0x4,%eax a15: c6 02 00 movb $0x0,(%edx) return 0; switch(cmd->type){ case EXEC: ecmd = (struct execcmd*)cmd; for(i=0; ecmd->argv[i]; i++) a18: 8b 50 d8 mov -0x28(%eax),%edx a1b: 85 d2 test %edx,%edx a1d: 75 f1 jne a10 <nulterminate+0x50> struct redircmd *rcmd; if(cmd == 0) return 0; switch(cmd->type){ a1f: 89 d8 mov %ebx,%eax bcmd = (struct backcmd*)cmd; nulterminate(bcmd->cmd); break; } return cmd; } a21: 8b 5d fc mov -0x4(%ebp),%ebx a24: c9 leave a25: c3 ret a26: 8d 76 00 lea 0x0(%esi),%esi a29: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi nulterminate(lcmd->right); break; case BACK: bcmd = (struct backcmd*)cmd; nulterminate(bcmd->cmd); a30: 83 ec 0c sub $0xc,%esp a33: ff 73 04 pushl 0x4(%ebx) a36: e8 85 ff ff ff call 9c0 <nulterminate> break; a3b: 89 d8 mov %ebx,%eax a3d: 83 c4 10 add $0x10,%esp } return cmd; } a40: 8b 5d fc mov -0x4(%ebp),%ebx a43: c9 leave a44: c3 ret a45: 8d 76 00 lea 0x0(%esi),%esi *ecmd->eargv[i] = 0; break; case REDIR: rcmd = (struct redircmd*)cmd; nulterminate(rcmd->cmd); a48: 83 ec 0c sub $0xc,%esp a4b: ff 73 04 pushl 0x4(%ebx) a4e: e8 6d ff ff ff call 9c0 <nulterminate> *rcmd->efile = 0; a53: 8b 43 0c mov 0xc(%ebx),%eax break; a56: 83 c4 10 add $0x10,%esp break; case REDIR: rcmd = (struct redircmd*)cmd; nulterminate(rcmd->cmd); *rcmd->efile = 0; a59: c6 00 00 movb $0x0,(%eax) break; a5c: 89 d8 mov %ebx,%eax bcmd = (struct backcmd*)cmd; nulterminate(bcmd->cmd); break; } return cmd; } a5e: 8b 5d fc mov -0x4(%ebp),%ebx a61: c9 leave a62: c3 ret a63: 90 nop a64: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi struct listcmd *lcmd; struct pipecmd *pcmd; struct redircmd *rcmd; if(cmd == 0) return 0; a68: 31 c0 xor %eax,%eax a6a: eb 8d jmp 9f9 <nulterminate+0x39> a6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000a70 <parsecmd>: struct cmd *parseexec(char**, char*); struct cmd *nulterminate(struct cmd*); struct cmd* parsecmd(char *s) { a70: 55 push %ebp a71: 89 e5 mov %esp,%ebp a73: 56 push %esi a74: 53 push %ebx char *es; struct cmd *cmd; es = s + strlen(s); a75: 8b 5d 08 mov 0x8(%ebp),%ebx a78: 83 ec 0c sub $0xc,%esp a7b: 53 push %ebx a7c: e8 df 00 00 00 call b60 <strlen> cmd = parseline(&s, es); a81: 59 pop %ecx parsecmd(char *s) { char *es; struct cmd *cmd; es = s + strlen(s); a82: 01 c3 add %eax,%ebx cmd = parseline(&s, es); a84: 8d 45 08 lea 0x8(%ebp),%eax a87: 5e pop %esi a88: 53 push %ebx a89: 50 push %eax a8a: e8 01 fe ff ff call 890 <parseline> a8f: 89 c6 mov %eax,%esi peek(&s, es, ""); a91: 8d 45 08 lea 0x8(%ebp),%eax a94: 83 c4 0c add $0xc,%esp a97: 68 a9 11 00 00 push $0x11a9 a9c: 53 push %ebx a9d: 50 push %eax a9e: e8 4d fb ff ff call 5f0 <peek> if(s != es){ aa3: 8b 45 08 mov 0x8(%ebp),%eax aa6: 83 c4 10 add $0x10,%esp aa9: 39 c3 cmp %eax,%ebx aab: 75 12 jne abf <parsecmd+0x4f> printf(2, "leftovers: %s\n", s); panic("syntax"); } nulterminate(cmd); aad: 83 ec 0c sub $0xc,%esp ab0: 56 push %esi ab1: e8 0a ff ff ff call 9c0 <nulterminate> return cmd; } ab6: 8d 65 f8 lea -0x8(%ebp),%esp ab9: 89 f0 mov %esi,%eax abb: 5b pop %ebx abc: 5e pop %esi abd: 5d pop %ebp abe: c3 ret es = s + strlen(s); cmd = parseline(&s, es); peek(&s, es, ""); if(s != es){ printf(2, "leftovers: %s\n", s); abf: 52 push %edx ac0: 50 push %eax ac1: 68 22 12 00 00 push $0x1222 ac6: 6a 02 push $0x2 ac8: e8 a3 03 00 00 call e70 <printf> panic("syntax"); acd: c7 04 24 e6 11 00 00 movl $0x11e6,(%esp) ad4: e8 87 f6 ff ff call 160 <panic> ad9: 66 90 xchg %ax,%ax adb: 66 90 xchg %ax,%ax add: 66 90 xchg %ax,%ax adf: 90 nop 00000ae0 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { ae0: 55 push %ebp ae1: 89 e5 mov %esp,%ebp ae3: 53 push %ebx ae4: 8b 45 08 mov 0x8(%ebp),%eax ae7: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) aea: 89 c2 mov %eax,%edx aec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi af0: 83 c1 01 add $0x1,%ecx af3: 0f b6 59 ff movzbl -0x1(%ecx),%ebx af7: 83 c2 01 add $0x1,%edx afa: 84 db test %bl,%bl afc: 88 5a ff mov %bl,-0x1(%edx) aff: 75 ef jne af0 <strcpy+0x10> ; return os; } b01: 5b pop %ebx b02: 5d pop %ebp b03: c3 ret b04: 8d b6 00 00 00 00 lea 0x0(%esi),%esi b0a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000b10 <strcmp>: int strcmp(const char *p, const char *q) { b10: 55 push %ebp b11: 89 e5 mov %esp,%ebp b13: 56 push %esi b14: 53 push %ebx b15: 8b 55 08 mov 0x8(%ebp),%edx b18: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) b1b: 0f b6 02 movzbl (%edx),%eax b1e: 0f b6 19 movzbl (%ecx),%ebx b21: 84 c0 test %al,%al b23: 75 1e jne b43 <strcmp+0x33> b25: eb 29 jmp b50 <strcmp+0x40> b27: 89 f6 mov %esi,%esi b29: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; b30: 83 c2 01 add $0x1,%edx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) b33: 0f b6 02 movzbl (%edx),%eax p++, q++; b36: 8d 71 01 lea 0x1(%ecx),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) b39: 0f b6 59 01 movzbl 0x1(%ecx),%ebx b3d: 84 c0 test %al,%al b3f: 74 0f je b50 <strcmp+0x40> b41: 89 f1 mov %esi,%ecx b43: 38 d8 cmp %bl,%al b45: 74 e9 je b30 <strcmp+0x20> p++, q++; return (uchar)*p - (uchar)*q; b47: 29 d8 sub %ebx,%eax } b49: 5b pop %ebx b4a: 5e pop %esi b4b: 5d pop %ebp b4c: c3 ret b4d: 8d 76 00 lea 0x0(%esi),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) b50: 31 c0 xor %eax,%eax p++, q++; return (uchar)*p - (uchar)*q; b52: 29 d8 sub %ebx,%eax } b54: 5b pop %ebx b55: 5e pop %esi b56: 5d pop %ebp b57: c3 ret b58: 90 nop b59: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000b60 <strlen>: uint strlen(const char *s) { b60: 55 push %ebp b61: 89 e5 mov %esp,%ebp b63: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) b66: 80 39 00 cmpb $0x0,(%ecx) b69: 74 12 je b7d <strlen+0x1d> b6b: 31 d2 xor %edx,%edx b6d: 8d 76 00 lea 0x0(%esi),%esi b70: 83 c2 01 add $0x1,%edx b73: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) b77: 89 d0 mov %edx,%eax b79: 75 f5 jne b70 <strlen+0x10> ; return n; } b7b: 5d pop %ebp b7c: c3 ret uint strlen(const char *s) { int n; for(n = 0; s[n]; n++) b7d: 31 c0 xor %eax,%eax ; return n; } b7f: 5d pop %ebp b80: c3 ret b81: eb 0d jmp b90 <memset> b83: 90 nop b84: 90 nop b85: 90 nop b86: 90 nop b87: 90 nop b88: 90 nop b89: 90 nop b8a: 90 nop b8b: 90 nop b8c: 90 nop b8d: 90 nop b8e: 90 nop b8f: 90 nop 00000b90 <memset>: void* memset(void *dst, int c, uint n) { b90: 55 push %ebp b91: 89 e5 mov %esp,%ebp b93: 57 push %edi b94: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : b97: 8b 4d 10 mov 0x10(%ebp),%ecx b9a: 8b 45 0c mov 0xc(%ebp),%eax b9d: 89 d7 mov %edx,%edi b9f: fc cld ba0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } ba2: 89 d0 mov %edx,%eax ba4: 5f pop %edi ba5: 5d pop %ebp ba6: c3 ret ba7: 89 f6 mov %esi,%esi ba9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000bb0 <strchr>: char* strchr(const char *s, char c) { bb0: 55 push %ebp bb1: 89 e5 mov %esp,%ebp bb3: 53 push %ebx bb4: 8b 45 08 mov 0x8(%ebp),%eax bb7: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) bba: 0f b6 10 movzbl (%eax),%edx bbd: 84 d2 test %dl,%dl bbf: 74 1d je bde <strchr+0x2e> if(*s == c) bc1: 38 d3 cmp %dl,%bl bc3: 89 d9 mov %ebx,%ecx bc5: 75 0d jne bd4 <strchr+0x24> bc7: eb 17 jmp be0 <strchr+0x30> bc9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi bd0: 38 ca cmp %cl,%dl bd2: 74 0c je be0 <strchr+0x30> } char* strchr(const char *s, char c) { for(; *s; s++) bd4: 83 c0 01 add $0x1,%eax bd7: 0f b6 10 movzbl (%eax),%edx bda: 84 d2 test %dl,%dl bdc: 75 f2 jne bd0 <strchr+0x20> if(*s == c) return (char*)s; return 0; bde: 31 c0 xor %eax,%eax } be0: 5b pop %ebx be1: 5d pop %ebp be2: c3 ret be3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi be9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000bf0 <gets>: char* gets(char *buf, int max) { bf0: 55 push %ebp bf1: 89 e5 mov %esp,%ebp bf3: 57 push %edi bf4: 56 push %esi bf5: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ bf6: 31 f6 xor %esi,%esi cc = read(0, &c, 1); bf8: 8d 7d e7 lea -0x19(%ebp),%edi return 0; } char* gets(char *buf, int max) { bfb: 83 ec 1c sub $0x1c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ bfe: eb 29 jmp c29 <gets+0x39> cc = read(0, &c, 1); c00: 83 ec 04 sub $0x4,%esp c03: 6a 01 push $0x1 c05: 57 push %edi c06: 6a 00 push $0x0 c08: e8 2d 01 00 00 call d3a <read> if(cc < 1) c0d: 83 c4 10 add $0x10,%esp c10: 85 c0 test %eax,%eax c12: 7e 1d jle c31 <gets+0x41> break; buf[i++] = c; c14: 0f b6 45 e7 movzbl -0x19(%ebp),%eax c18: 8b 55 08 mov 0x8(%ebp),%edx c1b: 89 de mov %ebx,%esi if(c == '\n' || c == '\r') c1d: 3c 0a cmp $0xa,%al for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; c1f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') c23: 74 1b je c40 <gets+0x50> c25: 3c 0d cmp $0xd,%al c27: 74 17 je c40 <gets+0x50> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ c29: 8d 5e 01 lea 0x1(%esi),%ebx c2c: 3b 5d 0c cmp 0xc(%ebp),%ebx c2f: 7c cf jl c00 <gets+0x10> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; c31: 8b 45 08 mov 0x8(%ebp),%eax c34: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } c38: 8d 65 f4 lea -0xc(%ebp),%esp c3b: 5b pop %ebx c3c: 5e pop %esi c3d: 5f pop %edi c3e: 5d pop %ebp c3f: c3 ret break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; c40: 8b 45 08 mov 0x8(%ebp),%eax gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ c43: 89 de mov %ebx,%esi break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; c45: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } c49: 8d 65 f4 lea -0xc(%ebp),%esp c4c: 5b pop %ebx c4d: 5e pop %esi c4e: 5f pop %edi c4f: 5d pop %ebp c50: c3 ret c51: eb 0d jmp c60 <stat> c53: 90 nop c54: 90 nop c55: 90 nop c56: 90 nop c57: 90 nop c58: 90 nop c59: 90 nop c5a: 90 nop c5b: 90 nop c5c: 90 nop c5d: 90 nop c5e: 90 nop c5f: 90 nop 00000c60 <stat>: int stat(const char *n, struct stat *st) { c60: 55 push %ebp c61: 89 e5 mov %esp,%ebp c63: 56 push %esi c64: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); c65: 83 ec 08 sub $0x8,%esp c68: 6a 00 push $0x0 c6a: ff 75 08 pushl 0x8(%ebp) c6d: e8 f0 00 00 00 call d62 <open> if(fd < 0) c72: 83 c4 10 add $0x10,%esp c75: 85 c0 test %eax,%eax c77: 78 27 js ca0 <stat+0x40> return -1; r = fstat(fd, st); c79: 83 ec 08 sub $0x8,%esp c7c: ff 75 0c pushl 0xc(%ebp) c7f: 89 c3 mov %eax,%ebx c81: 50 push %eax c82: e8 f3 00 00 00 call d7a <fstat> c87: 89 c6 mov %eax,%esi close(fd); c89: 89 1c 24 mov %ebx,(%esp) c8c: e8 b9 00 00 00 call d4a <close> return r; c91: 83 c4 10 add $0x10,%esp c94: 89 f0 mov %esi,%eax } c96: 8d 65 f8 lea -0x8(%ebp),%esp c99: 5b pop %ebx c9a: 5e pop %esi c9b: 5d pop %ebp c9c: c3 ret c9d: 8d 76 00 lea 0x0(%esi),%esi int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; ca0: b8 ff ff ff ff mov $0xffffffff,%eax ca5: eb ef jmp c96 <stat+0x36> ca7: 89 f6 mov %esi,%esi ca9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000cb0 <atoi>: return r; } int atoi(const char *s) { cb0: 55 push %ebp cb1: 89 e5 mov %esp,%ebp cb3: 53 push %ebx cb4: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') cb7: 0f be 11 movsbl (%ecx),%edx cba: 8d 42 d0 lea -0x30(%edx),%eax cbd: 3c 09 cmp $0x9,%al cbf: b8 00 00 00 00 mov $0x0,%eax cc4: 77 1f ja ce5 <atoi+0x35> cc6: 8d 76 00 lea 0x0(%esi),%esi cc9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; cd0: 8d 04 80 lea (%eax,%eax,4),%eax cd3: 83 c1 01 add $0x1,%ecx cd6: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') cda: 0f be 11 movsbl (%ecx),%edx cdd: 8d 5a d0 lea -0x30(%edx),%ebx ce0: 80 fb 09 cmp $0x9,%bl ce3: 76 eb jbe cd0 <atoi+0x20> n = n*10 + *s++ - '0'; return n; } ce5: 5b pop %ebx ce6: 5d pop %ebp ce7: c3 ret ce8: 90 nop ce9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000cf0 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { cf0: 55 push %ebp cf1: 89 e5 mov %esp,%ebp cf3: 56 push %esi cf4: 53 push %ebx cf5: 8b 5d 10 mov 0x10(%ebp),%ebx cf8: 8b 45 08 mov 0x8(%ebp),%eax cfb: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) cfe: 85 db test %ebx,%ebx d00: 7e 14 jle d16 <memmove+0x26> d02: 31 d2 xor %edx,%edx d04: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; d08: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx d0c: 88 0c 10 mov %cl,(%eax,%edx,1) d0f: 83 c2 01 add $0x1,%edx char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) d12: 39 da cmp %ebx,%edx d14: 75 f2 jne d08 <memmove+0x18> *dst++ = *src++; return vdst; } d16: 5b pop %ebx d17: 5e pop %esi d18: 5d pop %ebp d19: c3 ret 00000d1a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) d1a: b8 01 00 00 00 mov $0x1,%eax d1f: cd 40 int $0x40 d21: c3 ret 00000d22 <exit>: SYSCALL(exit) d22: b8 02 00 00 00 mov $0x2,%eax d27: cd 40 int $0x40 d29: c3 ret 00000d2a <wait>: SYSCALL(wait) d2a: b8 03 00 00 00 mov $0x3,%eax d2f: cd 40 int $0x40 d31: c3 ret 00000d32 <pipe>: SYSCALL(pipe) d32: b8 04 00 00 00 mov $0x4,%eax d37: cd 40 int $0x40 d39: c3 ret 00000d3a <read>: SYSCALL(read) d3a: b8 05 00 00 00 mov $0x5,%eax d3f: cd 40 int $0x40 d41: c3 ret 00000d42 <write>: SYSCALL(write) d42: b8 10 00 00 00 mov $0x10,%eax d47: cd 40 int $0x40 d49: c3 ret 00000d4a <close>: SYSCALL(close) d4a: b8 15 00 00 00 mov $0x15,%eax d4f: cd 40 int $0x40 d51: c3 ret 00000d52 <kill>: SYSCALL(kill) d52: b8 06 00 00 00 mov $0x6,%eax d57: cd 40 int $0x40 d59: c3 ret 00000d5a <exec>: SYSCALL(exec) d5a: b8 07 00 00 00 mov $0x7,%eax d5f: cd 40 int $0x40 d61: c3 ret 00000d62 <open>: SYSCALL(open) d62: b8 0f 00 00 00 mov $0xf,%eax d67: cd 40 int $0x40 d69: c3 ret 00000d6a <mknod>: SYSCALL(mknod) d6a: b8 11 00 00 00 mov $0x11,%eax d6f: cd 40 int $0x40 d71: c3 ret 00000d72 <unlink>: SYSCALL(unlink) d72: b8 12 00 00 00 mov $0x12,%eax d77: cd 40 int $0x40 d79: c3 ret 00000d7a <fstat>: SYSCALL(fstat) d7a: b8 08 00 00 00 mov $0x8,%eax d7f: cd 40 int $0x40 d81: c3 ret 00000d82 <link>: SYSCALL(link) d82: b8 13 00 00 00 mov $0x13,%eax d87: cd 40 int $0x40 d89: c3 ret 00000d8a <mkdir>: SYSCALL(mkdir) d8a: b8 14 00 00 00 mov $0x14,%eax d8f: cd 40 int $0x40 d91: c3 ret 00000d92 <chdir>: SYSCALL(chdir) d92: b8 09 00 00 00 mov $0x9,%eax d97: cd 40 int $0x40 d99: c3 ret 00000d9a <dup>: SYSCALL(dup) d9a: b8 0a 00 00 00 mov $0xa,%eax d9f: cd 40 int $0x40 da1: c3 ret 00000da2 <getpid>: SYSCALL(getpid) da2: b8 0b 00 00 00 mov $0xb,%eax da7: cd 40 int $0x40 da9: c3 ret 00000daa <sbrk>: SYSCALL(sbrk) daa: b8 0c 00 00 00 mov $0xc,%eax daf: cd 40 int $0x40 db1: c3 ret 00000db2 <sleep>: SYSCALL(sleep) db2: b8 0d 00 00 00 mov $0xd,%eax db7: cd 40 int $0x40 db9: c3 ret 00000dba <uptime>: SYSCALL(uptime) dba: b8 0e 00 00 00 mov $0xe,%eax dbf: cd 40 int $0x40 dc1: c3 ret 00000dc2 <abdur_rouf>: SYSCALL(abdur_rouf) dc2: b8 16 00 00 00 mov $0x16,%eax dc7: cd 40 int $0x40 dc9: c3 ret dca: 66 90 xchg %ax,%ax dcc: 66 90 xchg %ax,%ax dce: 66 90 xchg %ax,%ax 00000dd0 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { dd0: 55 push %ebp dd1: 89 e5 mov %esp,%ebp dd3: 57 push %edi dd4: 56 push %esi dd5: 53 push %ebx dd6: 89 c6 mov %eax,%esi dd8: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ ddb: 8b 5d 08 mov 0x8(%ebp),%ebx dde: 85 db test %ebx,%ebx de0: 74 7e je e60 <printint+0x90> de2: 89 d0 mov %edx,%eax de4: c1 e8 1f shr $0x1f,%eax de7: 84 c0 test %al,%al de9: 74 75 je e60 <printint+0x90> neg = 1; x = -xx; deb: 89 d0 mov %edx,%eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; ded: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) x = -xx; df4: f7 d8 neg %eax df6: 89 75 c0 mov %esi,-0x40(%ebp) } else { x = xx; } i = 0; df9: 31 ff xor %edi,%edi dfb: 8d 5d d7 lea -0x29(%ebp),%ebx dfe: 89 ce mov %ecx,%esi e00: eb 08 jmp e0a <printint+0x3a> e02: 8d b6 00 00 00 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; e08: 89 cf mov %ecx,%edi e0a: 31 d2 xor %edx,%edx e0c: 8d 4f 01 lea 0x1(%edi),%ecx e0f: f7 f6 div %esi e11: 0f b6 92 80 12 00 00 movzbl 0x1280(%edx),%edx }while((x /= base) != 0); e18: 85 c0 test %eax,%eax x = xx; } i = 0; do{ buf[i++] = digits[x % base]; e1a: 88 14 0b mov %dl,(%ebx,%ecx,1) }while((x /= base) != 0); e1d: 75 e9 jne e08 <printint+0x38> if(neg) e1f: 8b 45 c4 mov -0x3c(%ebp),%eax e22: 8b 75 c0 mov -0x40(%ebp),%esi e25: 85 c0 test %eax,%eax e27: 74 08 je e31 <printint+0x61> buf[i++] = '-'; e29: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1) e2e: 8d 4f 02 lea 0x2(%edi),%ecx e31: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi e35: 8d 76 00 lea 0x0(%esi),%esi e38: 0f b6 07 movzbl (%edi),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); e3b: 83 ec 04 sub $0x4,%esp e3e: 83 ef 01 sub $0x1,%edi e41: 6a 01 push $0x1 e43: 53 push %ebx e44: 56 push %esi e45: 88 45 d7 mov %al,-0x29(%ebp) e48: e8 f5 fe ff ff call d42 <write> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) e4d: 83 c4 10 add $0x10,%esp e50: 39 df cmp %ebx,%edi e52: 75 e4 jne e38 <printint+0x68> putc(fd, buf[i]); } e54: 8d 65 f4 lea -0xc(%ebp),%esp e57: 5b pop %ebx e58: 5e pop %esi e59: 5f pop %edi e5a: 5d pop %ebp e5b: c3 ret e5c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; } else { x = xx; e60: 89 d0 mov %edx,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; e62: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) e69: eb 8b jmp df6 <printint+0x26> e6b: 90 nop e6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000e70 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { e70: 55 push %ebp e71: 89 e5 mov %esp,%ebp e73: 57 push %edi e74: 56 push %esi e75: 53 push %ebx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ e76: 8d 45 10 lea 0x10(%ebp),%eax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { e79: 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++){ e7c: 8b 75 0c mov 0xc(%ebp),%esi } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { e7f: 8b 7d 08 mov 0x8(%ebp),%edi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ e82: 89 45 d0 mov %eax,-0x30(%ebp) e85: 0f b6 1e movzbl (%esi),%ebx e88: 83 c6 01 add $0x1,%esi e8b: 84 db test %bl,%bl e8d: 0f 84 b0 00 00 00 je f43 <printf+0xd3> e93: 31 d2 xor %edx,%edx e95: eb 39 jmp ed0 <printf+0x60> e97: 89 f6 mov %esi,%esi e99: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ ea0: 83 f8 25 cmp $0x25,%eax ea3: 89 55 d4 mov %edx,-0x2c(%ebp) state = '%'; ea6: ba 25 00 00 00 mov $0x25,%edx state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ eab: 74 18 je ec5 <printf+0x55> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); ead: 8d 45 e2 lea -0x1e(%ebp),%eax eb0: 83 ec 04 sub $0x4,%esp eb3: 88 5d e2 mov %bl,-0x1e(%ebp) eb6: 6a 01 push $0x1 eb8: 50 push %eax eb9: 57 push %edi eba: e8 83 fe ff ff call d42 <write> ebf: 8b 55 d4 mov -0x2c(%ebp),%edx ec2: 83 c4 10 add $0x10,%esp ec5: 83 c6 01 add $0x1,%esi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ ec8: 0f b6 5e ff movzbl -0x1(%esi),%ebx ecc: 84 db test %bl,%bl ece: 74 73 je f43 <printf+0xd3> c = fmt[i] & 0xff; if(state == 0){ ed0: 85 d2 test %edx,%edx uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; ed2: 0f be cb movsbl %bl,%ecx ed5: 0f b6 c3 movzbl %bl,%eax if(state == 0){ ed8: 74 c6 je ea0 <printf+0x30> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ eda: 83 fa 25 cmp $0x25,%edx edd: 75 e6 jne ec5 <printf+0x55> if(c == 'd'){ edf: 83 f8 64 cmp $0x64,%eax ee2: 0f 84 f8 00 00 00 je fe0 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ ee8: 81 e1 f7 00 00 00 and $0xf7,%ecx eee: 83 f9 70 cmp $0x70,%ecx ef1: 74 5d je f50 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ ef3: 83 f8 73 cmp $0x73,%eax ef6: 0f 84 84 00 00 00 je f80 <printf+0x110> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ efc: 83 f8 63 cmp $0x63,%eax eff: 0f 84 ea 00 00 00 je fef <printf+0x17f> putc(fd, *ap); ap++; } else if(c == '%'){ f05: 83 f8 25 cmp $0x25,%eax f08: 0f 84 c2 00 00 00 je fd0 <printf+0x160> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); f0e: 8d 45 e7 lea -0x19(%ebp),%eax f11: 83 ec 04 sub $0x4,%esp f14: c6 45 e7 25 movb $0x25,-0x19(%ebp) f18: 6a 01 push $0x1 f1a: 50 push %eax f1b: 57 push %edi f1c: e8 21 fe ff ff call d42 <write> f21: 83 c4 0c add $0xc,%esp f24: 8d 45 e6 lea -0x1a(%ebp),%eax f27: 88 5d e6 mov %bl,-0x1a(%ebp) f2a: 6a 01 push $0x1 f2c: 50 push %eax f2d: 57 push %edi f2e: 83 c6 01 add $0x1,%esi f31: e8 0c fe ff ff call d42 <write> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ f36: 0f b6 5e ff movzbl -0x1(%esi),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); f3a: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; f3d: 31 d2 xor %edx,%edx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ f3f: 84 db test %bl,%bl f41: 75 8d jne ed0 <printf+0x60> putc(fd, c); } state = 0; } } } f43: 8d 65 f4 lea -0xc(%ebp),%esp f46: 5b pop %ebx f47: 5e pop %esi f48: 5f pop %edi f49: 5d pop %ebp f4a: c3 ret f4b: 90 nop f4c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); f50: 83 ec 0c sub $0xc,%esp f53: b9 10 00 00 00 mov $0x10,%ecx f58: 6a 00 push $0x0 f5a: 8b 5d d0 mov -0x30(%ebp),%ebx f5d: 89 f8 mov %edi,%eax f5f: 8b 13 mov (%ebx),%edx f61: e8 6a fe ff ff call dd0 <printint> ap++; f66: 89 d8 mov %ebx,%eax f68: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; f6b: 31 d2 xor %edx,%edx if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; f6d: 83 c0 04 add $0x4,%eax f70: 89 45 d0 mov %eax,-0x30(%ebp) f73: e9 4d ff ff ff jmp ec5 <printf+0x55> f78: 90 nop f79: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi } else if(c == 's'){ s = (char*)*ap; f80: 8b 45 d0 mov -0x30(%ebp),%eax f83: 8b 18 mov (%eax),%ebx ap++; f85: 83 c0 04 add $0x4,%eax f88: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) s = "(null)"; f8b: b8 78 12 00 00 mov $0x1278,%eax f90: 85 db test %ebx,%ebx f92: 0f 44 d8 cmove %eax,%ebx while(*s != 0){ f95: 0f b6 03 movzbl (%ebx),%eax f98: 84 c0 test %al,%al f9a: 74 23 je fbf <printf+0x14f> f9c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi fa0: 88 45 e3 mov %al,-0x1d(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); fa3: 8d 45 e3 lea -0x1d(%ebp),%eax fa6: 83 ec 04 sub $0x4,%esp fa9: 6a 01 push $0x1 ap++; if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; fab: 83 c3 01 add $0x1,%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); fae: 50 push %eax faf: 57 push %edi fb0: e8 8d fd ff ff call d42 <write> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ fb5: 0f b6 03 movzbl (%ebx),%eax fb8: 83 c4 10 add $0x10,%esp fbb: 84 c0 test %al,%al fbd: 75 e1 jne fa0 <printf+0x130> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; fbf: 31 d2 xor %edx,%edx fc1: e9 ff fe ff ff jmp ec5 <printf+0x55> fc6: 8d 76 00 lea 0x0(%esi),%esi fc9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); fd0: 83 ec 04 sub $0x4,%esp fd3: 88 5d e5 mov %bl,-0x1b(%ebp) fd6: 8d 45 e5 lea -0x1b(%ebp),%eax fd9: 6a 01 push $0x1 fdb: e9 4c ff ff ff jmp f2c <printf+0xbc> } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); fe0: 83 ec 0c sub $0xc,%esp fe3: b9 0a 00 00 00 mov $0xa,%ecx fe8: 6a 01 push $0x1 fea: e9 6b ff ff ff jmp f5a <printf+0xea> fef: 8b 5d d0 mov -0x30(%ebp),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); ff2: 83 ec 04 sub $0x4,%esp ff5: 8b 03 mov (%ebx),%eax ff7: 6a 01 push $0x1 ff9: 88 45 e4 mov %al,-0x1c(%ebp) ffc: 8d 45 e4 lea -0x1c(%ebp),%eax fff: 50 push %eax 1000: 57 push %edi 1001: e8 3c fd ff ff call d42 <write> 1006: e9 5b ff ff ff jmp f66 <printf+0xf6> 100b: 66 90 xchg %ax,%ax 100d: 66 90 xchg %ax,%ax 100f: 90 nop 00001010 <free>: static Header base; static Header *freep; void free(void *ap) { 1010: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1011: a1 a4 18 00 00 mov 0x18a4,%eax static Header base; static Header *freep; void free(void *ap) { 1016: 89 e5 mov %esp,%ebp 1018: 57 push %edi 1019: 56 push %esi 101a: 53 push %ebx 101b: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 101e: 8b 10 mov (%eax),%edx void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 1020: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1023: 39 c8 cmp %ecx,%eax 1025: 73 19 jae 1040 <free+0x30> 1027: 89 f6 mov %esi,%esi 1029: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 1030: 39 d1 cmp %edx,%ecx 1032: 72 1c jb 1050 <free+0x40> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 1034: 39 d0 cmp %edx,%eax 1036: 73 18 jae 1050 <free+0x40> static Header base; static Header *freep; void free(void *ap) { 1038: 89 d0 mov %edx,%eax Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 103a: 39 c8 cmp %ecx,%eax if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 103c: 8b 10 mov (%eax),%edx free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 103e: 72 f0 jb 1030 <free+0x20> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 1040: 39 d0 cmp %edx,%eax 1042: 72 f4 jb 1038 <free+0x28> 1044: 39 d1 cmp %edx,%ecx 1046: 73 f0 jae 1038 <free+0x28> 1048: 90 nop 1049: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi break; if(bp + bp->s.size == p->s.ptr){ 1050: 8b 73 fc mov -0x4(%ebx),%esi 1053: 8d 3c f1 lea (%ecx,%esi,8),%edi 1056: 39 d7 cmp %edx,%edi 1058: 74 19 je 1073 <free+0x63> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 105a: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 105d: 8b 50 04 mov 0x4(%eax),%edx 1060: 8d 34 d0 lea (%eax,%edx,8),%esi 1063: 39 f1 cmp %esi,%ecx 1065: 74 23 je 108a <free+0x7a> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 1067: 89 08 mov %ecx,(%eax) freep = p; 1069: a3 a4 18 00 00 mov %eax,0x18a4 } 106e: 5b pop %ebx 106f: 5e pop %esi 1070: 5f pop %edi 1071: 5d pop %ebp 1072: c3 ret bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ bp->s.size += p->s.ptr->s.size; 1073: 03 72 04 add 0x4(%edx),%esi 1076: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 1079: 8b 10 mov (%eax),%edx 107b: 8b 12 mov (%edx),%edx 107d: 89 53 f8 mov %edx,-0x8(%ebx) } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ 1080: 8b 50 04 mov 0x4(%eax),%edx 1083: 8d 34 d0 lea (%eax,%edx,8),%esi 1086: 39 f1 cmp %esi,%ecx 1088: 75 dd jne 1067 <free+0x57> p->s.size += bp->s.size; 108a: 03 53 fc add -0x4(%ebx),%edx p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 108d: a3 a4 18 00 00 mov %eax,0x18a4 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ p->s.size += bp->s.size; 1092: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 1095: 8b 53 f8 mov -0x8(%ebx),%edx 1098: 89 10 mov %edx,(%eax) } else p->s.ptr = bp; freep = p; } 109a: 5b pop %ebx 109b: 5e pop %esi 109c: 5f pop %edi 109d: 5d pop %ebp 109e: c3 ret 109f: 90 nop 000010a0 <malloc>: return freep; } void* malloc(uint nbytes) { 10a0: 55 push %ebp 10a1: 89 e5 mov %esp,%ebp 10a3: 57 push %edi 10a4: 56 push %esi 10a5: 53 push %ebx 10a6: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 10a9: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 10ac: 8b 15 a4 18 00 00 mov 0x18a4,%edx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 10b2: 8d 78 07 lea 0x7(%eax),%edi 10b5: c1 ef 03 shr $0x3,%edi 10b8: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 10bb: 85 d2 test %edx,%edx 10bd: 0f 84 a3 00 00 00 je 1166 <malloc+0xc6> 10c3: 8b 02 mov (%edx),%eax 10c5: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 10c8: 39 cf cmp %ecx,%edi 10ca: 76 74 jbe 1140 <malloc+0xa0> 10cc: 81 ff 00 10 00 00 cmp $0x1000,%edi 10d2: be 00 10 00 00 mov $0x1000,%esi 10d7: 8d 1c fd 00 00 00 00 lea 0x0(,%edi,8),%ebx 10de: 0f 43 f7 cmovae %edi,%esi 10e1: ba 00 80 00 00 mov $0x8000,%edx 10e6: 81 ff ff 0f 00 00 cmp $0xfff,%edi 10ec: 0f 46 da cmovbe %edx,%ebx 10ef: eb 10 jmp 1101 <malloc+0x61> 10f1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 10f8: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 10fa: 8b 48 04 mov 0x4(%eax),%ecx 10fd: 39 cf cmp %ecx,%edi 10ff: 76 3f jbe 1140 <malloc+0xa0> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 1101: 39 05 a4 18 00 00 cmp %eax,0x18a4 1107: 89 c2 mov %eax,%edx 1109: 75 ed jne 10f8 <malloc+0x58> char *p; Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); 110b: 83 ec 0c sub $0xc,%esp 110e: 53 push %ebx 110f: e8 96 fc ff ff call daa <sbrk> if(p == (char*)-1) 1114: 83 c4 10 add $0x10,%esp 1117: 83 f8 ff cmp $0xffffffff,%eax 111a: 74 1c je 1138 <malloc+0x98> return 0; hp = (Header*)p; hp->s.size = nu; 111c: 89 70 04 mov %esi,0x4(%eax) free((void*)(hp + 1)); 111f: 83 ec 0c sub $0xc,%esp 1122: 83 c0 08 add $0x8,%eax 1125: 50 push %eax 1126: e8 e5 fe ff ff call 1010 <free> return freep; 112b: 8b 15 a4 18 00 00 mov 0x18a4,%edx } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 1131: 83 c4 10 add $0x10,%esp 1134: 85 d2 test %edx,%edx 1136: 75 c0 jne 10f8 <malloc+0x58> return 0; 1138: 31 c0 xor %eax,%eax 113a: eb 1c jmp 1158 <malloc+0xb8> 113c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) 1140: 39 cf cmp %ecx,%edi 1142: 74 1c je 1160 <malloc+0xc0> prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; 1144: 29 f9 sub %edi,%ecx 1146: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 1149: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 114c: 89 78 04 mov %edi,0x4(%eax) } freep = prevp; 114f: 89 15 a4 18 00 00 mov %edx,0x18a4 return (void*)(p + 1); 1155: 83 c0 08 add $0x8,%eax } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } } 1158: 8d 65 f4 lea -0xc(%ebp),%esp 115b: 5b pop %ebx 115c: 5e pop %esi 115d: 5f pop %edi 115e: 5d pop %ebp 115f: c3 ret base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) prevp->s.ptr = p->s.ptr; 1160: 8b 08 mov (%eax),%ecx 1162: 89 0a mov %ecx,(%edx) 1164: eb e9 jmp 114f <malloc+0xaf> Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 1166: c7 05 a4 18 00 00 a8 movl $0x18a8,0x18a4 116d: 18 00 00 1170: c7 05 a8 18 00 00 a8 movl $0x18a8,0x18a8 1177: 18 00 00 base.s.size = 0; 117a: b8 a8 18 00 00 mov $0x18a8,%eax 117f: c7 05 ac 18 00 00 00 movl $0x0,0x18ac 1186: 00 00 00 1189: e9 3e ff ff ff jmp 10cc <malloc+0x2c>
/******************************************************* * Copyright (c) 2014, ArrayFire * All rights reserved. * * This file is distributed under 3-clause BSD license. * The complete license agreement can be obtained at: * http://arrayfire.com/licenses/BSD-3-Clause ********************************************************/ #include <complex> #include <af/defines.h> #include <af/array.h> #include <af/dim4.hpp> #include <Array.hpp> #include <optypes.hpp> #include <err_cpu.hpp> #include <TNJ/BinaryNode.hpp> #include <TNJ/UnaryNode.hpp> namespace cpu { template<typename To, typename Ti> struct BinOp<To, Ti, af_cplx2_t> { To eval(Ti lhs, Ti rhs) { return To(lhs, rhs); } }; template<typename To, typename Ti> Array<To>* cplx(const Array<Ti> &lhs, const Array<Ti> &rhs, const af::dim4 &odims) { TNJ::Node_ptr lhs_node = lhs.getNode(); TNJ::Node_ptr rhs_node = rhs.getNode(); TNJ::BinaryNode<To, Ti, af_cplx2_t> *node = new TNJ::BinaryNode<To, Ti, af_cplx2_t>(lhs_node, rhs_node); return createNodeArray<To>(odims, TNJ::Node_ptr( reinterpret_cast<TNJ::Node *>(node))); } #define CPLX_UNARY_FN(op) \ template<typename To, typename Ti> \ struct UnOp<To, Ti, af_##op##_t> \ { \ To eval(Ti in) \ { \ return std::op(in); \ } \ }; \ CPLX_UNARY_FN(real) CPLX_UNARY_FN(imag) CPLX_UNARY_FN(conj) CPLX_UNARY_FN(abs) template<typename To, typename Ti> Array<To>* real(const Array<Ti> &in) { TNJ::Node_ptr in_node = in.getNode(); TNJ::UnaryNode<To, Ti, af_real_t> *node = new TNJ::UnaryNode<To, Ti, af_real_t>(in_node); return createNodeArray<To>(in.dims(), TNJ::Node_ptr(reinterpret_cast<TNJ::Node *>(node))); } template<typename To, typename Ti> Array<To>* imag(const Array<Ti> &in) { TNJ::Node_ptr in_node = in.getNode(); TNJ::UnaryNode<To, Ti, af_imag_t> *node = new TNJ::UnaryNode<To, Ti, af_imag_t>(in_node); return createNodeArray<To>(in.dims(), TNJ::Node_ptr(reinterpret_cast<TNJ::Node *>(node))); } template<typename To, typename Ti> Array<To>* abs(const Array<Ti> &in) { TNJ::Node_ptr in_node = in.getNode(); TNJ::UnaryNode<To, Ti, af_abs_t> *node = new TNJ::UnaryNode<To, Ti, af_abs_t>(in_node); return createNodeArray<To>(in.dims(), TNJ::Node_ptr(reinterpret_cast<TNJ::Node *>(node))); } template<typename T> Array<T>* conj(const Array<T> &in) { TNJ::Node_ptr in_node = in.getNode(); TNJ::UnaryNode<T, T, af_conj_t> *node = new TNJ::UnaryNode<T, T, af_conj_t>(in_node); return createNodeArray<T>(in.dims(), TNJ::Node_ptr(reinterpret_cast<TNJ::Node *>(node))); } }
; A062004: a(n) = mu(n)*(2n). ; 2,-4,-6,0,-10,12,-14,0,0,20,-22,0,-26,28,30,0,-34,0,-38,0,42,44,-46,0,0,52,0,0,-58,-60,-62,0,66,68,70,0,-74,76,78,0,-82,-84,-86,0,0,92,-94,0,0,0,102,0,-106,0,110,0,114,116,-118,0,-122,124,0,0,130,-132,-134,0,138,-140,-142,0,-146,148,0,0,154,-156,-158,0,0,164,-166,0,170,172,174,0,-178,0,182,0,186,188,190,0,-194,0,0,0,-202,-204,-206,0,-210,212,-214,0,-218,-220,222,0,-226,-228,230,0,0,236,238,0,0,244,246,0,0,0,-254,0,258,-260,-262,0,266,268,0,0,-274,-276,-278,0,282,284,286,0,290,292,0,0,-298,0,-302,0,0,-308,310,0,-314,316,318,0,322,0,-326,0,-330,332,-334,0,0,-340,0,0,-346,-348,0,0,354,356,-358,0,-362,-364,366,0,370,-372,374,0,0,-380,-382,0,-386,388,-390,0,-394,0,-398,0,402,404,406,0,410,412,0,0,418,420,-422,0,426,428,430,0,434,436,438,0,442,-444,-446,0,0,452,-454,0,-458,-460,-462,0,-466,0,470,0,474,-476,-478,0,-482,0,0,0,0,-492,494,0,498,0 mov $2,$0 add $2,1 cal $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 lpb $0 cal $0,259748 ; a(n) = (Sum_{0<x<y<n} x*y) mod n. add $0,$2 lpe mul $0,2 mov $1,$0
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC GEOS MODULE: Cluster mode dithering for filling mono bitmaps FILE: monoRaster.asm AUTHOR: Jim DeFrisco, Mar 3, 1992 ROUTINES: Name Description ---- ----------- INT FillBWScanCluster Transfer a scan line's worth of system memory to screen REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 3/ 3/92 Initial revision DESCRIPTION: Need a clustered dither filling mode for mono bitmaps $Id: monoRaster.asm,v 1.1 97/04/18 11:42:42 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FillBWScanCluster %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Transfer a scan line's worth of system memory to screen CALLED BY: INTERNAL PASS: d_x1 - x coordinate to start drawing d_y1 - scan line to draw to d_x2 - x coordinate of right side of image d_dx - width of image (pixels) d_bytes - width of image (bytes) (bytes/scan/plane) ds:si - pointer to bitmap data es:di - pointer into frame buffer to start of scan line RETURN: bp intact DESTROYED: ax,bx,cx,dx,si,di PSEUDO CODE/STRATEGY: set drawing color; mask left; shift and copy left byte; shift and copy middle bytes mask right; shift and copy right byte; KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Jim 03/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} FillBWScanCluster proc near uses bp .enter ; init some stuff. Get the dithers ready mov bx, ss:[bmLeft] mov ax, ss:[bmRight] ; calculate # bytes to fill in mov bp, bx ; get # bits into image sub bp, ss:[d_x1] ; get left coordinate mov cl, 3 ; want to get byte indices sar ax, cl sar bx, cl sar bp, cl add si, bp ; add bytes-to-left-side add di, bx ; add to screen offset too mov bp, ax ; get right side in bp sub bp, bx ; bp = # dest bytes to write mov al, ss:lineMask ; mov cs:[cmykMask], al ; store shift amount as self-mod value to save register space ; this won't affect the flags register, so last compare is ok clr ch ; assume no initial shift out clr ah mov cl, ss:[bmShift] ; load up shift amount tst ss:[bmPreload] jns FBS_skipPreload ; skip preload on flag value lodsb ; get first byte of bitmap ror ax, cl ; get shift out bits in ah mov ch, ah ; and save them FBS_skipPreload: mov bx, {word} ss:[bmRMask] ; get mask bytes or bp, bp ; test # bytes to draw jne FBS_left ; more than 1, don't combine and bl, bh mov cs:[cmykRightMask], bl ; store SELF MOD and-immediate jmp FBS_right FBS_left: mov cs:[cmykLeftMask], bh mov cs:[cmykRightMask], bl clr ah ; clear for future rotate lodsb ; get next byte of bitmap ror ax, cl ; shift bits xchg ch, ah ; save bits shifted out or al, ah ; get bitmap data for mask call CMYKbmLeftMask ; do left side dec bp ; if zero, then no center bytes jz FBS_right FBS_center: clr ah ; clear for rotate lodsb ; next data byte ror ax, cl ; rotate into place xchg ch, ah ; save out bits, or al, ah ; combine old/new bits call CMYKbmMidMask ; do middle bytes dec bp ; one less to do jg FBS_center ; loop to do next byte FBS_right: mov al, ds:[si] ; get last byte shr al, cl ; shift bits or al, ch ; get extra bits, if any call CMYKbmRightMask ; do right side .leave ret FillBWScanCluster endp
; A025738: Index of 9^n within sequence of numbers of form 8^i*9^j. ; 1,3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,191,212,234,257,281,306,332,359,387,416,446,477,509,542,576,611,647,684,723,763,804,846,889,933,978,1024,1071,1119,1168,1218,1269,1321,1374,1428,1483,1540,1598 mov $3,$0 add $3,1 mov $5,$0 lpb $3 mov $0,$5 sub $3,1 sub $0,$3 mov $6,$0 add $6,1 mov $7,0 mov $8,$0 lpb $6 mov $0,$8 sub $6,1 sub $0,$6 mov $10,2 mov $12,$0 lpb $10 mov $0,$12 sub $10,1 add $0,$10 sub $0,2 mov $2,$0 mul $2,2 add $2,1 div $2,35 mul $2,2 mov $4,$2 mov $9,$10 lpb $9 sub $9,1 mov $11,$4 lpe lpe lpb $12 sub $11,$4 mov $12,0 lpe mov $4,$11 div $4,2 add $4,1 add $7,$4 lpe add $1,$7 lpe mov $0,$1
#include "pepch.h" #include "Entity.h" //#include "Components\TransformComponent.h" #include "Components\Components.h" #include "editor\EditorLayer.h" namespace PrettyEngine { Entity::Entity(const String& entityName, const String& entityTag) : tag(entityTag), name(entityName) { /* memset(m_Properties.name, 0, 40 + 1); if (entityName.size() < 40) { for (int i = 0; i < entityName.size(); i++) { m_Properties.name[i] = entityName[i]; } m_Properties.name[41] = '\0'; } else { PE_ERROR("{0} Entity: Name is too long (max 40 characters) >> Used default name! ", entityName); m_Properties.name[0] = 'E'; m_Properties.name[1] = 'n'; m_Properties.name[2] = 't'; m_Properties.name[3] = 'i'; m_Properties.name[4] = 't'; m_Properties.name[5] = 'y'; m_Properties.name[6] = '\0'; }*/ AddComponent(new Transform()); } Entity::~Entity() { for (uint i = 0; i < m_Components.size(); i++) { delete m_Components[i]; } m_Components.clear(); } void Entity::AddComponent(Component * component) { if (component == nullptr || component->GetType() == ComponentType::Null) { PE_CORE_ERROR("Component does not exist: Type is NULL!"); return; } for (uint i = 0; i < m_Components.size();i++) { if (component->GetType() == m_Components[i]->GetType()) { PE_CORE_ERROR("Component already exists in this entity!"); return; } } switch (component->GetType()) { case ComponentType::Transform: { Transform* tr = (Transform*)component; m_Properties.position[0] = tr->position.x; m_Properties.position[1] = tr->position.y; m_Properties.position[2] = tr->position.z; m_Properties.rotation[0] = tr->rotation.x; m_Properties.rotation[1] = tr->rotation.y; m_Properties.rotation[2] = tr->rotation.z; m_Properties.scale[0] = tr->scale.x; m_Properties.scale[1] = tr->scale.y; m_Properties.scale[2] = tr->scale.z; } default: break; } /*m_Components[component->GetType()] = component;*/ component->entity = this; component->Init(); m_Components.push_back(component); } void Entity::RemoveComponent(Component * component) { auto it = std::find(m_Components.begin(), m_Components.end(), component); if (it != m_Components.end()) { m_Components.erase(it); } } }
db DEX_WIGGLYTUFF ; pokedex id db 140 ; base hp db 70 ; base attack db 45 ; base defense db 45 ; base speed db 85 ; base special db FIGHTING ; species type 1 db FAIRY ; species type 2 db FULL_HEAL ; catch rate db 60 ; base exp yield INCBIN "pic/ymon/wigglytuff.pic",0,1 ; 66, sprite dimensions dw WigglytuffPicFront dw WigglytuffPicBack ; attacks known at lvl 0 db SING db DISABLE db SUBMISSION db DOUBLESLAP db 4 ; growth rate ; learnset tmlearn 1,5,6,8 tmlearn 9,10,11,12,13,14,15 tmlearn 17,18,19,20,22,24 tmlearn 25,29,30,31,32 tmlearn 33,34,38,40 tmlearn 44,45,46 tmlearn 49,50,54,55 db BANK(WigglytuffPicFront)
.z180 #target bin #code TEXT, $100 #include "src/z180registers.z80" .org $100 start: ld hl, $81 ld de, srcaddr spaces: ld a, (hl) inc hl or a jr z, noargs cp a, ' ' jr z, spaces digits: call read_hex jr c, badarg ex de, hl rld inc hl rld dec hl ex de, hl or a jr nz, overflow ld a, (hl) inc hl or a jr z, memcpy jr digits badarg: dec hl ld a, (hl) ld (badchar), a ld de, badmsg jr bail noargs: ld de, usage jr bail overflow: ld de, toobig bail: ld c, 9 call 5 jp 0 memcpy: ;; (srcaddr) contains the desired memory read location, address bits 20:4 ;; SAR0L should be set to address bits 7:0, SAR0H to 15:8, SAR0B to 20:16 ;; the first rld sets (srcaddr) to bits 7:0 and moves bits 11:8 into a ;; the second rld moves bits 11:8 into (srcaddr+1) and shifts bits 15:12 up ;; and also moves bits 20:16 into the low nibble of a ld de, (srcaddr) ld hl, srcaddr ; a is zero when arriving here rld ; a[3:0] = (hl)[7:4], (hl)[7:0] = {(hl)[3:0], a[3:0]} inc hl ; high byte rld ; a[3:0] = (hl)[7:4], (hl)[7:0] = {(hl)[3:0], a[3:0]} out0 (SAR0B), a ld bc, (srcaddr) out0 (SAR0L), c out0 (SAR0H), b ;; put (srcaddr) back to how it was ld (srcaddr), de xor a out0 (DAR0B), a out0 (DAR0L), a ld a, $10 out0 (DAR0H), a ld bc, 320 out0 (BCR0L), c out0 (BCR0H), b ld bc, 0110000000000010b out0 (DMODE), c out0 (DSTAT), b ; burst mode will halt CPU until complete ld hl, $1000 ld c, 20 call dump_hex jp 0 srcaddr: .dw 0 badmsg: .text 'Invalid HEX digit "' badchar: .text '?"',13,10,'$' toobig: .text 'Address too large - max. 4 digits',13,10,'$' usage: .text 'Usage: romdump <addr>',13,10,' <addr> the 16-bit page address to dump',13,10,'$' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; read_hex - read an ascii HEX digit and convert it to binary ;; ;; in: a the hex digit to convert ;; out: a the binary digit, lower nibble ;; cf set if invalid input, clear otherwise ;; #local read_hex:: sub 48 ; convert to binary, if it's 0-9 jr c, invalid ; if < '0', it's no good cp 10 jr c, good ; if < 10, conversion is done or $20 ; convert to lower case sub $31 ; 'a' == 0 jr c, invalid ; less than 'a', it's no good add $a ; 'a' == $a cp $10 ; should be $a-$f ccf ; invert cf from the cp ret good: or a ret invalid: scf ret #endlocal ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; dump_hex - dump a region of memory in canonical hex output format ;; ;; in: hl the region of memory to dump ;; c the number of rows of 16 bytes to dump #local dump_hex:: ;; print a row of (up to) 16 bytes ld a, (srcaddr) call bin_to_hex ld (linemsg+2), de ld a, (srcaddr+1) call bin_to_hex ld (linemsg), de ld de, (srcaddr) inc de ld (srcaddr), de ld b, 16 ld ix, linemsg+7 ld iy, linemsg+59 writeloop: ld a, (hl) inc hl ld (iy+0), a cp ' ' ; control characters, replace with a dot jr c, dot cp '$' ; '$' would terminate the print... jr z, dot cp '~' ; high bit set, replace with a dot jr c, hex dot: ld (iy+0), '.' hex: inc iy call bin_to_hex ld (ix+0), e ld (ix+1), d inc ix inc ix inc ix ld a, 9 cp b jr nz, loopy inc ix loopy: djnz writeloop push bc push hl ld de, linemsg ld c, 9 call 5 pop hl pop bc dec c jr nz, dump_hex ret linemsg: .text '????: ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ????????????????', 13, 10, '$' #endlocal #include "src/bin2hex.z80" buffer equ $1000
; uint zx_saddr2px(void *pixeladdr, uchar mask) ; CALLER linkage for function pointers XLIB zx_saddr2px LIB zx_saddr2px_callee XREF ASMDISP_ZX_SADDR2PX_CALLEE .zx_saddr2px pop af pop de pop hl push hl push de push af ld a,e jp zx_saddr2px_callee + ASMDISP_ZX_SADDR2PX_CALLEE
<% from pwnlib.shellcraft.powerpc.linux import syscall %> <%page args="fd, iovec, count"/> <%docstring> Invokes the syscall writev. See 'man 2 writev' for more information. Arguments: fd(int): fd iovec(iovec): iovec count(int): count </%docstring> ${syscall('SYS_writev', fd, iovec, count)}
copyright zengfr site:http://github.com/zengfr/romhack 00042A move.l D1, (A0)+ 00042C dbra D0, $42a 00063A cmpi.b #-$1, (A0) [base+ 36] 00063E beq $69e [base+ 3A, base+ 4A, base+ 5A, base+ 8A, base+ 9A, base+ AA, base+ BA, base+ EA, base+ FA, base+12A, base+13A, base+16A, base+17A, base+1CA, base+1DA, base+20A, base+21A, base+24A, base+25A, base+28A, base+29A, base+2AA, base+2BA, base+2EA, base+2FA, base+32A, base+33A, base+36A, base+37A, base+3CA, base+3DA, base+40A, base+41A, base+42A] 00064A cmpi.w #$30, (A0) 00064E beq $65e [base+ 7A, base+ 9A, base+ BA, base+ CA, base+ DA, base+ EA, base+ FA, base+10A, base+11A, base+12A, base+13A, base+14A, base+15A, base+17A, base+19A, base+1BA] 009610 move.w D0, (A0)+ 009612 move.l D1, (A0)+ [base+ 3A, base+ 4A, base+ 5A, base+ 8A, base+ 9A, base+ AA, base+ BA, base+ EA, base+ FA, base+12A, base+13A, base+16A, base+17A, base+1CA, base+1DA, base+20A, base+21A, base+24A, base+25A, base+28A, base+29A, base+2AA, base+2BA, base+2EA, base+2FA, base+32A, base+33A, base+36A, base+37A, base+3CA, base+3DA, base+40A, base+41A, base+42A] 00968C move.w D0, (A0)+ 00968E move.l D1, (A0)+ [base+ 3A, base+ 4A, base+ 5A, base+ 8A, base+ 9A, base+ AA, base+ BA, base+ EA, base+ FA, base+12A, base+13A, base+16A, base+17A, base+1CA, base+1DA, base+20A, base+21A, base+24A, base+25A, base+28A, base+29A, base+2AA, base+2BA, base+2EA, base+2FA, base+32A, base+33A, base+36A, base+37A, base+3CA, base+3DA, base+40A, base+41A, base+42A] 00A61A move.l D1, (A0)+ 00A61C move.l D1, (A0)+ 00A64A move.w D0, (A0)+ 00A64C move.l D1, (A0)+ [base+ 3A, base+ 4A, base+ 5A, base+ 8A, base+ 9A, base+ AA, base+ BA, base+ EA, base+ FA, base+12A, base+13A, base+16A, base+17A, base+1CA, base+1DA, base+20A, base+21A, base+24A, base+25A, base+28A, base+29A, base+2AA, base+2BA, base+2EA, base+2FA, base+32A, base+33A, base+36A, base+37A, base+3CA, base+3DA, base+40A, base+41A, base+42A] 0AAACA move.l (A0), D2 0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAACE move.w D0, ($2,A0) 0AAAD2 cmp.l (A0), D0 0AAAD4 bne $aaafc 0AAAD8 move.l D2, (A0)+ 0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAE6 move.l (A0), D2 0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAF4 move.l D2, (A0)+ 0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] copyright zengfr site:http://github.com/zengfr/romhack
; void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) SECTION code_clib SECTION code_stdlib PUBLIC _qsort_callee EXTERN asm_qsort _qsort_callee: pop af pop bc pop hl pop de pop ix push af jp asm_qsort
////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2008. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_UPGRADABLE_MUTEX_HPP #define BOOST_INTERPROCESS_UPGRADABLE_MUTEX_HPP #if (defined _MSC_VER) && (_MSC_VER >= 1200) # pragma once #endif #include <boost/interprocess/detail/config_begin.hpp> #include <boost/interprocess/detail/workaround.hpp> #include <boost/interprocess/sync/scoped_lock.hpp> #include <boost/interprocess/sync/interprocess_mutex.hpp> #include <boost/interprocess/sync/interprocess_condition.hpp> #include <climits> //!\file //!Describes interprocess_upgradable_mutex class namespace boost { namespace interprocess { //!Wraps a interprocess_upgradable_mutex that can be placed in shared memory and can be //!shared between processes. Allows timed lock tries class interprocess_upgradable_mutex { //Non-copyable interprocess_upgradable_mutex(const interprocess_upgradable_mutex &); interprocess_upgradable_mutex &operator=(const interprocess_upgradable_mutex &); friend class interprocess_condition; public: //!Constructs the upgradable lock. //!Throws interprocess_exception on error. interprocess_upgradable_mutex(); //!Destroys the upgradable lock. //!Does not throw. ~interprocess_upgradable_mutex(); //Exclusive locking //!Effects: The calling thread tries to obtain exclusive ownership of the mutex, //! and if another thread has exclusive, sharable or upgradable ownership of //! the mutex, it waits until it can obtain the ownership. //!Throws: interprocess_exception on error. void lock(); //!Effects: The calling thread tries to acquire exclusive ownership of the mutex //! without waiting. If no other thread has exclusive, sharable or upgradable //! ownership of the mutex this succeeds. //!Returns: If it can acquire exclusive ownership immediately returns true. //! If it has to wait, returns false. //!Throws: interprocess_exception on error. bool try_lock(); //!Effects: The calling thread tries to acquire exclusive ownership of the mutex //! waiting if necessary until no other thread has has exclusive, sharable or //! upgradable ownership of the mutex or abs_time is reached. //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false. //!Throws: interprocess_exception on error. bool timed_lock(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have exclusive ownership of the mutex. //!Effects: The calling thread releases the exclusive ownership of the mutex. //!Throws: An exception derived from interprocess_exception on error. void unlock(); //Sharable locking //!Effects: The calling thread tries to obtain sharable ownership of the mutex, //! and if another thread has exclusive or upgradable ownership of the mutex, //! waits until it can obtain the ownership. //!Throws: interprocess_exception on error. void lock_sharable(); //!Effects: The calling thread tries to acquire sharable ownership of the mutex //! without waiting. If no other thread has has exclusive or upgradable ownership //! of the mutex this succeeds. //!Returns: If it can acquire sharable ownership immediately returns true. If it //! has to wait, returns false. //!Throws: interprocess_exception on error. bool try_lock_sharable(); //!Effects: The calling thread tries to acquire sharable ownership of the mutex //! waiting if necessary until no other thread has has exclusive or upgradable //! ownership of the mutex or abs_time is reached. //!Returns: If acquires sharable ownership, returns true. Otherwise returns false. //!Throws: interprocess_exception on error. bool timed_lock_sharable(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have sharable ownership of the mutex. //!Effects: The calling thread releases the sharable ownership of the mutex. //!Throws: An exception derived from interprocess_exception on error. void unlock_sharable(); //Upgradable locking //!Effects: The calling thread tries to obtain upgradable ownership of the mutex, //! and if another thread has exclusive or upgradable ownership of the mutex, //! waits until it can obtain the ownership. //!Throws: interprocess_exception on error. void lock_upgradable(); //!Effects: The calling thread tries to acquire upgradable ownership of the mutex //! without waiting. If no other thread has has exclusive or upgradable ownership //! of the mutex this succeeds. //!Returns: If it can acquire upgradable ownership immediately returns true. //! If it has to wait, returns false. //!Throws: interprocess_exception on error. bool try_lock_upgradable(); //!Effects: The calling thread tries to acquire upgradable ownership of the mutex //! waiting if necessary until no other thread has has exclusive or upgradable //! ownership of the mutex or abs_time is reached. //!Returns: If acquires upgradable ownership, returns true. Otherwise returns false. //!Throws: interprocess_exception on error. bool timed_lock_upgradable(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have upgradable ownership of the mutex. //!Effects: The calling thread releases the upgradable ownership of the mutex. //!Throws: An exception derived from interprocess_exception on error. void unlock_upgradable(); //Demotions //!Precondition: The thread must have exclusive ownership of the mutex. //!Effects: The thread atomically releases exclusive ownership and acquires //! upgradable ownership. This operation is non-blocking. //!Throws: An exception derived from interprocess_exception on error. void unlock_and_lock_upgradable(); //!Precondition: The thread must have exclusive ownership of the mutex. //!Effects: The thread atomically releases exclusive ownership and acquires //! sharable ownership. This operation is non-blocking. //!Throws: An exception derived from interprocess_exception on error. void unlock_and_lock_sharable(); //!Precondition: The thread must have upgradable ownership of the mutex. //!Effects: The thread atomically releases upgradable ownership and acquires //! sharable ownership. This operation is non-blocking. //!Throws: An exception derived from interprocess_exception on error. void unlock_upgradable_and_lock_sharable(); //Promotions //!Precondition: The thread must have upgradable ownership of the mutex. //!Effects: The thread atomically releases upgradable ownership and acquires //! exclusive ownership. This operation will block until all threads with //! sharable ownership release their sharable lock. //!Throws: An exception derived from interprocess_exception on error. void unlock_upgradable_and_lock(); //!Precondition: The thread must have upgradable ownership of the mutex. //!Effects: The thread atomically releases upgradable ownership and tries to //! acquire exclusive ownership. This operation will fail if there are threads //! with sharable ownership, but it will maintain upgradable ownership. //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false. //!Throws: An exception derived from interprocess_exception on error. bool try_unlock_upgradable_and_lock(); //!Precondition: The thread must have upgradable ownership of the mutex. //!Effects: The thread atomically releases upgradable ownership and tries to acquire //! exclusive ownership, waiting if necessary until abs_time. This operation will //! fail if there are threads with sharable ownership or timeout reaches, but it //! will maintain upgradable ownership. //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false. //!Throws: An exception derived from interprocess_exception on error. */ bool timed_unlock_upgradable_and_lock(const boost::posix_time::ptime &abs_time); //!Precondition: The thread must have sharable ownership of the mutex. //!Effects: The thread atomically releases sharable ownership and tries to acquire //! exclusive ownership. This operation will fail if there are threads with sharable //! or upgradable ownership, but it will maintain sharable ownership. //!Returns: If acquires exclusive ownership, returns true. Otherwise returns false. //!Throws: An exception derived from interprocess_exception on error. bool try_unlock_sharable_and_lock(); //!Precondition: The thread must have sharable ownership of the mutex. //!Effects: The thread atomically releases sharable ownership and tries to acquire //! upgradable ownership. This operation will fail if there are threads with sharable //! or upgradable ownership, but it will maintain sharable ownership. //!Returns: If acquires upgradable ownership, returns true. Otherwise returns false. //!Throws: An exception derived from interprocess_exception on error. bool try_unlock_sharable_and_lock_upgradable(); /// @cond private: typedef scoped_lock<interprocess_mutex> scoped_lock_t; //Pack all the control data in a word to be able //to use atomic instructions in the future struct control_word_t { unsigned exclusive_in : 1; unsigned upgradable_in : 1; unsigned num_upr_shar : sizeof(unsigned)*CHAR_BIT-2; } m_ctrl; interprocess_mutex m_mut; interprocess_condition m_first_gate; interprocess_condition m_second_gate; private: //Rollback structures for exceptions or failure return values struct exclusive_rollback { exclusive_rollback(control_word_t &ctrl ,interprocess_condition &first_gate) : mp_ctrl(&ctrl), m_first_gate(first_gate) {} void release() { mp_ctrl = 0; } ~exclusive_rollback() { if(mp_ctrl){ mp_ctrl->exclusive_in = 0; m_first_gate.notify_all(); } } control_word_t *mp_ctrl; interprocess_condition &m_first_gate; }; struct upgradable_to_exclusive_rollback { upgradable_to_exclusive_rollback(control_word_t &ctrl) : mp_ctrl(&ctrl) {} void release() { mp_ctrl = 0; } ~upgradable_to_exclusive_rollback() { if(mp_ctrl){ //Recover upgradable lock mp_ctrl->upgradable_in = 1; ++mp_ctrl->num_upr_shar; //Execute the second half of exclusive locking mp_ctrl->exclusive_in = 0; } } control_word_t *mp_ctrl; }; template<int Dummy> struct base_constants_t { static const unsigned max_readers = ~(unsigned(3) << (sizeof(unsigned)*CHAR_BIT-2)); }; typedef base_constants_t<0> constants; /// @endcond }; /// @cond template <int Dummy> const unsigned interprocess_upgradable_mutex::base_constants_t<Dummy>::max_readers; inline interprocess_upgradable_mutex::interprocess_upgradable_mutex() { this->m_ctrl.exclusive_in = 0; this->m_ctrl.upgradable_in = 0; this->m_ctrl.num_upr_shar = 0; } inline interprocess_upgradable_mutex::~interprocess_upgradable_mutex() {} inline void interprocess_upgradable_mutex::lock() { scoped_lock_t lock(m_mut); //The exclusive lock must block in the first gate //if an exclusive or upgradable lock has been acquired while (this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in){ this->m_first_gate.wait(lock); } //Mark that exclusive lock has been acquired this->m_ctrl.exclusive_in = 1; //Prepare rollback exclusive_rollback rollback(this->m_ctrl, this->m_first_gate); //Now wait until all readers are gone while (this->m_ctrl.num_upr_shar){ this->m_second_gate.wait(lock); } rollback.release(); } inline bool interprocess_upgradable_mutex::try_lock() { scoped_lock_t lock(m_mut, try_to_lock); //If we can't lock or any has there is any exclusive, upgradable //or sharable mark return false; if(!lock.owns() || this->m_ctrl.exclusive_in || this->m_ctrl.num_upr_shar){ return false; } this->m_ctrl.exclusive_in = 1; return true; } inline bool interprocess_upgradable_mutex::timed_lock (const boost::posix_time::ptime &abs_time) { scoped_lock_t lock(m_mut, abs_time); if(!lock.owns()) return false; //The exclusive lock must block in the first gate //if an exclusive or upgradable lock has been acquired while (this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in){ if(!this->m_first_gate.timed_wait(lock, abs_time)) return !(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in); } //Mark that exclusive lock has been acquired this->m_ctrl.exclusive_in = 1; //Prepare rollback exclusive_rollback rollback(this->m_ctrl, this->m_first_gate); //Now wait until all readers are gone while (this->m_ctrl.num_upr_shar){ if(!this->m_second_gate.timed_wait(lock, abs_time)){ return !(this->m_ctrl.num_upr_shar); } } rollback.release(); return true; } inline void interprocess_upgradable_mutex::unlock() { scoped_lock_t lock(m_mut); this->m_ctrl.exclusive_in = 0; this->m_first_gate.notify_all(); } //Upgradable locking inline void interprocess_upgradable_mutex::lock_upgradable() { scoped_lock_t lock(m_mut); //The upgradable lock must block in the first gate //if an exclusive or upgradable lock has been acquired //or there are too many sharable locks while(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in || this->m_ctrl.num_upr_shar == constants::max_readers){ this->m_first_gate.wait(lock); } //Mark that upgradable lock has been acquired //And add upgradable to the sharable count this->m_ctrl.upgradable_in = 1; ++this->m_ctrl.num_upr_shar; } inline bool interprocess_upgradable_mutex::try_lock_upgradable() { scoped_lock_t lock(m_mut, try_to_lock); //The upgradable lock must fail //if an exclusive or upgradable lock has been acquired //or there are too many sharable locks if(!lock.owns() || this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in || this->m_ctrl.num_upr_shar == constants::max_readers){ return false; } //Mark that upgradable lock has been acquired //And add upgradable to the sharable count this->m_ctrl.upgradable_in = 1; ++this->m_ctrl.num_upr_shar; return true; } inline bool interprocess_upgradable_mutex::timed_lock_upgradable (const boost::posix_time::ptime &abs_time) { scoped_lock_t lock(m_mut, abs_time); if(!lock.owns()) return false; //The upgradable lock must block in the first gate //if an exclusive or upgradable lock has been acquired //or there are too many sharable locks while(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in || this->m_ctrl.num_upr_shar == constants::max_readers){ if(!this->m_first_gate.timed_wait(lock, abs_time)){ return!(this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in || this->m_ctrl.num_upr_shar == constants::max_readers); } } //Mark that upgradable lock has been acquired //And add upgradable to the sharable count this->m_ctrl.upgradable_in = 1; ++this->m_ctrl.num_upr_shar; return true; } inline void interprocess_upgradable_mutex::unlock_upgradable() { scoped_lock_t lock(m_mut); //Mark that upgradable lock has been acquired //And add upgradable to the sharable count this->m_ctrl.upgradable_in = 0; --this->m_ctrl.num_upr_shar; this->m_first_gate.notify_all(); } //Sharable locking inline void interprocess_upgradable_mutex::lock_sharable() { scoped_lock_t lock(m_mut); //The sharable lock must block in the first gate //if an exclusive lock has been acquired //or there are too many sharable locks while(this->m_ctrl.exclusive_in || this->m_ctrl.num_upr_shar == constants::max_readers){ this->m_first_gate.wait(lock); } //Increment sharable count ++this->m_ctrl.num_upr_shar; } inline bool interprocess_upgradable_mutex::try_lock_sharable() { scoped_lock_t lock(m_mut, try_to_lock); //The sharable lock must fail //if an exclusive lock has been acquired //or there are too many sharable locks if(!lock.owns() || this->m_ctrl.exclusive_in || this->m_ctrl.num_upr_shar == constants::max_readers){ return false; } //Increment sharable count ++this->m_ctrl.num_upr_shar; return true; } inline bool interprocess_upgradable_mutex::timed_lock_sharable (const boost::posix_time::ptime &abs_time) { scoped_lock_t lock(m_mut, abs_time); if(!lock.owns()) return false; //The sharable lock must block in the first gate //if an exclusive lock has been acquired //or there are too many sharable locks while (this->m_ctrl.exclusive_in || this->m_ctrl.num_upr_shar == constants::max_readers){ if(!this->m_first_gate.timed_wait(lock, abs_time)){ return!(this->m_ctrl.exclusive_in || this->m_ctrl.num_upr_shar == constants::max_readers); } } //Increment sharable count ++this->m_ctrl.num_upr_shar; return true; } inline void interprocess_upgradable_mutex::unlock_sharable() { scoped_lock_t lock(m_mut); //Decrement sharable count --this->m_ctrl.num_upr_shar; if (this->m_ctrl.num_upr_shar == 0){ this->m_second_gate.notify_one(); } //Check if there are blocked sharables because of //there were too many sharables else if(this->m_ctrl.num_upr_shar == (constants::max_readers-1)){ this->m_first_gate.notify_all(); } } //Downgrading inline void interprocess_upgradable_mutex::unlock_and_lock_upgradable() { scoped_lock_t lock(m_mut); //Unmark it as exclusive this->m_ctrl.exclusive_in = 0; //Mark it as upgradable this->m_ctrl.upgradable_in = 1; //The sharable count should be 0 so increment it this->m_ctrl.num_upr_shar = 1; //Notify readers that they can enter m_first_gate.notify_all(); } inline void interprocess_upgradable_mutex::unlock_and_lock_sharable() { scoped_lock_t lock(m_mut); //Unmark it as exclusive this->m_ctrl.exclusive_in = 0; //The sharable count should be 0 so increment it this->m_ctrl.num_upr_shar = 1; //Notify readers that they can enter m_first_gate.notify_all(); } inline void interprocess_upgradable_mutex::unlock_upgradable_and_lock_sharable() { scoped_lock_t lock(m_mut); //Unmark it as upgradable (we don't have to decrement count) this->m_ctrl.upgradable_in = 0; //Notify readers/upgradable that they can enter m_first_gate.notify_all(); } //Upgrading inline void interprocess_upgradable_mutex::unlock_upgradable_and_lock() { scoped_lock_t lock(m_mut); //Simulate unlock_upgradable() without //notifying sharables. this->m_ctrl.upgradable_in = 0; --this->m_ctrl.num_upr_shar; //Execute the second half of exclusive locking this->m_ctrl.exclusive_in = 1; //Prepare rollback upgradable_to_exclusive_rollback rollback(m_ctrl); while (this->m_ctrl.num_upr_shar){ this->m_second_gate.wait(lock); } rollback.release(); } inline bool interprocess_upgradable_mutex::try_unlock_upgradable_and_lock() { scoped_lock_t lock(m_mut, try_to_lock); //Check if there are no readers if(!lock.owns() || this->m_ctrl.num_upr_shar != 1){ return false; } //Now unlock upgradable and mark exclusive this->m_ctrl.upgradable_in = 0; --this->m_ctrl.num_upr_shar; this->m_ctrl.exclusive_in = 1; return true; } inline bool interprocess_upgradable_mutex::timed_unlock_upgradable_and_lock (const boost::posix_time::ptime &abs_time) { scoped_lock_t lock(m_mut, abs_time); if(!lock.owns()) return false; //Simulate unlock_upgradable() without //notifying sharables. this->m_ctrl.upgradable_in = 0; --this->m_ctrl.num_upr_shar; //Execute the second half of exclusive locking this->m_ctrl.exclusive_in = 1; //Prepare rollback upgradable_to_exclusive_rollback rollback(m_ctrl); while (this->m_ctrl.num_upr_shar){ if(!this->m_second_gate.timed_wait(lock, abs_time)){ return !(this->m_ctrl.num_upr_shar); } } rollback.release(); return true; } inline bool interprocess_upgradable_mutex::try_unlock_sharable_and_lock() { scoped_lock_t lock(m_mut, try_to_lock); //If we can't lock or any has there is any exclusive, upgradable //or sharable mark return false; if(!lock.owns() || this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in || this->m_ctrl.num_upr_shar != 1){ return false; } this->m_ctrl.exclusive_in = 1; this->m_ctrl.num_upr_shar = 0; return true; } inline bool interprocess_upgradable_mutex::try_unlock_sharable_and_lock_upgradable() { scoped_lock_t lock(m_mut, try_to_lock); //The upgradable lock must fail //if an exclusive or upgradable lock has been acquired if(!lock.owns() || this->m_ctrl.exclusive_in || this->m_ctrl.upgradable_in){ return false; } //Mark that upgradable lock has been acquired this->m_ctrl.upgradable_in = 1; return true; } /// @endcond } //namespace interprocess { } //namespace boost { #include <boost/interprocess/detail/config_end.hpp> #endif //BOOST_INTERPROCESS_UPGRADABLE_MUTEX_HPP
; A050250: Number of nonzero palindromes less than 10^n. ; Submitted by Jon Maiga ; 9,18,108,198,1098,1998,10998,19998,109998,199998,1099998,1999998,10999998,19999998,109999998,199999998,1099999998,1999999998,10999999998,19999999998,109999999998,199999999998,1099999999998,1999999999998,10999999999998,19999999999998,109999999999998,199999999999998,1099999999999998,1999999999999998,10999999999999998,19999999999999998,109999999999999998,199999999999999998,1099999999999999998,1999999999999999998,10999999999999999998,19999999999999999998,109999999999999999998,199999999999999999998 mov $1,$0 mod $0,2 add $0,1 lpb $1 mul $0,10 add $0,2 sub $1,2 lpe mul $0,9
psect text,class=CODE global _RLEData,_workpage global _CEIL,_FLOOR muluw_hl_bc macro db 0xed,0xc3 ;de:hl<-hl*bc endm mulub_a_b macro db 0xED,0xC1 ;hl<- a*b endm ;; void hmmcTexRender(uchar x, uint lineHeight, char* texData); ; input: e = x-coord (e & 3) == 0 ; bc = lineHeight 64 means full height ; stack+2 = pointer to RLE texture data ; ; precondition: ; VDP R#17 points to CLR register ; VDP R#40 (NX) = 4 ; ; TODO - use SP trick to access RLE data ... does that actually speed ; things up? Probably it does for the zoom out loop. Maybe not ; for zoom in (because we still need 'exx' and 'pop' fetches both ; values in the same set of (shadow) registers). global _hmmcTexRender _hmmcTexRender: ld a,(_workpage) ; 0 or 1 add a,a ; 0 or 2 add a,e ; (e & 3) == 0, so no overflow exx ld hl,2 add hl,sp ld e,(hl) inc hl ; can be 'inc l' if we know SP is 2-aligned (only matters for Z80) ld d,(hl) ; de' = texData ld h,_RLEData/256 ld l,a ; hl' = &RLEData[x/4][workpage].low ld a,(hl) ; old texData.low cp e ; new texData.low jp nz,DiffTex1 inc l ld a,(hl) ; old texData.high cp d ; new texData.high jp nz,DiffTex2 SameTexture: dec h ; hl' = &lineHeight[x/4][workpage].high ld a,(hl) ; old lineHeight.high exx cp b ; new lineHeight.high jr nz,DiffHeight1 ld a,c ; new lineHeight.low exx ld b,(hl) ; b' = old lineHeight.high dec l ; hl' = &lineHeight[..][..].low cp (hl) ; old lineHeight.low jr nz,DiffHeight2 AllSame: pop hl ; return address inc sp ; pop parameter from stack inc sp ; (on Z80 'pop af' is cheaper) jp (hl) ; return DiffTex1: ld (hl),e ; store new texData.low inc l DiffTex2: ld (hl),d ; store new texData.high dec h ; hl = &lineHeight[x/4][workpage].high exx DiffHeight1: ld a,b ; lineHeight.high exx ld b,(hl) ; b' = old lineHeight.high ld (hl),a ; store new lineHeight.high dec l exx ld a,c ; lineHeight.low exx DiffHeight2: ld c,(hl) ; c' = old lineHeight.low ld (hl),a ; store new lineHeight.low ; at this point: ; bc = lineHeight ; e = x-coord ; bc' = old lineHeight ; de' = texData 1: in a,(0x99) rrca jr c,1b ; wait for CE di exx ld a,e ; x-coord out (0x99),a ld hl,-64 add hl,bc ld a,36+128 out (0x99),a ; dx jp c,ClipTex NoClipTex: ; lineHeight < 64 ; This means there's always at least 1 ceiling and 1 floor pixel. ; It also means 'lineHeight * 4' always fits in 8 bits exx ld a,b or a jr nz,ClipOld1 ; old lineHeight >= 256 -> clip to 64 ld a,c cp 64+1 ; old lineHeight <= 64 -> no need to clip jr c,ClipOld2 ClipOld1: ld a,64 ClipOld2: exx ld d,a ; d = min(64, old_lineHeight) sub c ; new lineHeight jr c,Wall1 jr z,Wall1 ; new >= old -> no need to draw ceiling pixels ; lineHeight < 64 and smaller than previous frame ; -> only draw 'extra' ceiling/floor pixels ; -- ceiling segment out (0x99),a ld a,42+128 out (0x99),a ; ny ld a,64 sub d ; old lineHeight out (0x99),a ld a,38+128 out (0x99),a ; dy ld a,_CEIL out (0x9b),a ; clr ld a,0xc0 ; HMMV out (0x99),a ld a,46+128 out (0x99),a ; cmd 2: in a,(0x99) rrca jr c,2b ; wait for CE jr Wall2 ; skip setting dy Wall1: ; lineHeight < 64, but bigger than previous frame ; -> no need to draw ceiling/floor pixels ld a,64 sub c ; new lineHeight out (0x99),a ld a,38+128 out (0x99),a ; dy ; -- wall segment ; pseudo code for inner loop: ; y = (64 - lineHeight) << 8; ; do { ; y2 = y + (*p++ * lineHeight * 4); ; plot((y2 >> 8) - (y >> 8), *p++); ; y = y2; ; } while (*p); Wall2: ld a,64 sub c exx ld b,a ; tmp ld a,d ld d,b ; d' = 64 - lineHeight exx ld h,a ; h = texData.high ld a,c ; lineHeight add a,a ; lineHeight * 2 out (0x99),a add a,a ; lineHeight < 64, so no overflow exx ld b,a ; b' = lineHeight * 4 ld a,e ld e,0 ; de' = (64 - lineHeight) << 8 = y exx ld l,a ; hl = texData dec hl ; cheaper than 'jr' to skip 'inc hl' instruction (on R800, but not on Z80) ld a,42+128 out (0x99),a ; ny Next0: inc hl ; skip texData->color ld a,(hl) ; texData->length inc hl exx mulub_a_b ; hl' = a*b' = length * lineHeight * 4 add hl,de ; hl' = y2 = y + (.. * ..) ex de,hl ; de' = y2 hl' = y ld a,d sub h ; (y2 >> 8) - (y >> 8) exx jr z,Next0 ; no need to check for (hl+1) == 0 add a,a ; 2 bytes per Y, cannot overflow (lineHeight < 64) ld b,a ; b = segment length on screen ld a,(hl) ; texData->color out (0x9b),a ; clr first pixel needs to be send separately ld a,0xf0 ; HMMC out (0x99),a ld a,46+128 out (0x99),a ; cmd djnz hmmc4 ; always more than 1 pixel ; cannot fall-through Next1: inc hl ; skip texData->color ld a,(hl) ; texData->length DoWhile1: inc hl exx mulub_a_b ; hl' = a*b' = length * lineHeight * 4 add hl,de ; hl' = y2 = y + (.. * ..) ex de,hl ; de' = y2 hl' = y ld a,d sub h ; (y2 >> 8) - (y >> 8) exx jr z,Next1 ; no need to check for (hl+1)==0 (last segment is always visible) add a,a ; 2 bytes (4 pixels) per Y, cannot overflow ld b,a ; b = segment length (on screen) (2*N, with N >= 1) hmmc4: ld a,(hl) ; texData: color hmmc3: out (0x9b),a ; clr djnz hmmc3 hmmc2: inc hl ld a,(hl) ; texData->length or a jr nz,DoWhile1 ; -- floor segment floor: ld a,c ; new lineHeight cp d ; old lineHeight jr nc,TexEnd ; new >= old -> no need to draw floor pixels ld a,d ; old lineHeight sub c ; new lineHeight out (0x99),a ld a,42+128 out (0x99),a ; ny ld a,_FLOOR out (0x9b),a ; clr ld a,0xc0 ; HMMV out (0x99),a ld a,46+128 out (0x99),a ; cmd TexEnd: pop hl ; return address inc sp ; pop parameter from stack inc sp ; (on Z80 'pop af' is cheaper) ei jp (hl) ; return ClipTex: ; lineHeight >= 64. Texture is at least as high as the full screen ; height, so there are no ceiling or floor pixels. ; Or in other words: we need to draw exactly 128 texture pixels. ; at this point: ; bc = lineHeight ; de' = texData xor a out (0x99),a ld a,c ; lineHeight.low add a,a exx ld c,a ; c' = (lineHeight * 2).low ld a,d ; texData.high exx ld d,a ; d = texData.high ld a,38+128 out (0x99),a ; dy ld a,b ; lineHeight.high adc a,a ; (lineHeight * 2).high exx ld b,a ; bc' = lineHeight * 2 sla c rl b ; bc' = lineHeight * 4 clears carry flag ; no overflow as long as lineHeight < 16384 ld a,e ; texData.low exx ld e,a ; de = texData ; y = (Hscr - lineHeight) << 8 ld a,128 ; full screen height out (0x99),a ld hl,64 ; carry-flag is already clear sbc hl,bc ; hl = 64 - lineHeight ld b,l ld c,0 ; bc = (64 - lineHeight) << 8 (lower 16 bits) ex de,hl ; d:bc = (64 - lineHeight) << 8 (full 24 bits) dec hl ; hl = texData-1 (doesn't change flags) ld a,42+128 out (0x99),a ; NY jr z,TopDone0 ; lineHeight == 64 -> no need to skip texels ; lineHeight > 64 ; -> y = 64 - lineHeight is negative ; skip texels till y becomes non-negative SkipTop: inc hl ld a,(hl) ; texData->length inc hl exx ld l,a ld h,0 ; hl' = zero-extend(length) muluw_hl_bc ; de':hl' = length * lineHeight * 4 ld a,l exx add a,c ld c,a exx ld a,h exx adc a,b ld b,a exx ld a,e exx adc a,d ld d,a ; d:bc += e':hl' jr nc,SkipTop ; while (d:bc < 0) jp nz,LastSegment0 ; more than 256 Y -> draw 128 Y ld a,b or a jr z,TopDone0 ; no need to draw partial segment (at top of screen) cp 128 jp nc,LastSegment0 ; 128 or more Y -> draw 128 Y add a,a ; 2 bytes per Y, cannot overflow ld d,a ; d = length of first partial segment (register B is not free) ld a,(hl) out (0x9b),a ; clr ld a,0xf0 ; HMMC out (0x99),a ld a,46+128 out (0x99),a ; cmd dec d ; cannot become 0 at this point ld a,(hl) hmmc7: out (0x9b),a dec d ; cannot use 'djnz' because reg B is not free jr nz,hmmc7 TopDone: ; at this point ; bc = y ~= lastDrawnY << 8 (exclusive) (includes fractional part) ; hl = texData-1 (one byte before the segment that should be drawn from start) ; bc' = lineHeight * 4 set 7,b ; b = last-drawn-y-coord (exclusive) ; add 128, that way we can detect overflow and '>128' ; using the carry-flag (so using only 1 test) ld d,b ; d = last-drawn-y-coord (exclusive) ZoomLoop: inc hl ld a,(hl) ; texData->length inc hl exx ld l,a ld h,0 ; hl' = zero-extend(length) muluw_hl_bc ; de':hl' = RLE-length * lineHeight * 4 ld a,l exx jr c,LastSegment ; carry set -> de' != 0 (result of muluw didn't fit in 16-bit) add a,c ld c,a exx ld a,h exx adc a,b jr c,LastSegment ld b,a ; bc += hl' sub d jr z,ZoomLoop add a,a ; 2 bytes per Y, cannot overflow ld e,a ; e = #bytes ld d,b ; d = newY hmmc8: ld a,(hl) ; texData->color hmmc5: out (0x9b),a ; clr dec e jr nz,hmmc5 jr ZoomLoop LastSegment: ; note: as soon as the last segment has more than one Y ; it's cheaper to draw it using HMMV instead of HMMC xor a sub d ; a = 128 - (y - 128) = 256 - y = 0 - y dec a ; was at least 1 ld a,(hl) ; texData->color out (0x9b),a ; clr jr z,hmmc6 ; was only one Y, finish HMMC command ld a,0xc0 ; otherwise finish with HMMV out (0x99),a ld a,46+128 out (0x99),a ; CMD jp TexEnd hmmc6: out (0x9b),a ; clr jp TexEnd TopDone0: ; this is similar to TopDone (above) except that the HMMC command is ; not yet started ld b,128 ld d,b ZoomLoop0: inc hl ld a,(hl) ; texData->length inc hl exx ld l,a ld h,0 ; hl' = zero-extend(length) muluw_hl_bc ; de':hl' = RLE-length * lineHeight * 4 ld a,l exx jr c,LastSegment0 ; carry set -> de' != 0 (result of muluw didn't fit in 16-bit) add a,c ld c,a exx ld a,h exx adc a,b jr c,LastSegment0 ld b,a ; bc += hl' sub d jr z,ZoomLoop0 add a,a ; 2 bytes per Y, cannot overflow ld e,a ; e = #bytes ld d,b ; d = newY ld a,(hl) out (0x9b),a ; first clr ld a,0xf0 ; hmmc out (0x99),a ld a,46+128 out (0x99),a ; cmd dec e ; cannot become 0 at this point jr hmmc8 LastSegment0: ; we need to write 128 Y of the same color, use HMMV (even ; though this is the hmmc renderer). ld a,(hl) ; texData->color out (0x9b),a ; first clr ld a,0xc0 ; hmmv out (0x99),a ld a,46+128 out (0x99),a ; cmd jp TexEnd
; void dzx1_smart_rcs_callee(void *src, void *dst) SECTION code_clib SECTION code_compress_zx1 PUBLIC dzx1_smart_rcs_callee EXTERN asm_dzx1_smart_rcs dzx1_smart_rcs_callee: IF __CPU_GBZ80__ pop bc pop de pop hl push bc ELSE pop hl pop de ex (sp),hl ENDIF jp asm_dzx1_smart_rcs
#include "stdafx.h" #include "CNodeScriptRuntime.h" CNodeScriptRuntime::CNodeScriptRuntime() { int eac; const char** eav; const char* argv[] = { "alt-server", "--experimental-modules", "--es-module-specifier-resolution=node", "--trace-warnings" }; int argc = sizeof(argv) / sizeof(const char*); node::Init(&argc, argv, &eac, &eav); auto* tracing_agent = node::CreateAgent(); // auto* tracing_controller = tracing_agent->GetTracingController(); node::tracing::TraceEventHelper::SetAgent(tracing_agent); platform.reset(node::CreatePlatform(4, node::tracing::TraceEventHelper::GetTracingController())); v8::V8::InitializePlatform(platform.get()); v8::V8::Initialize(); isolate = v8::Isolate::Allocate(); platform->RegisterIsolate(isolate, uv_default_loop()); v8::Isolate::CreateParams params; params.array_buffer_allocator = node::CreateArrayBufferAllocator(); v8::Isolate::Initialize(isolate, params); // IsWorker data slot isolate->SetData(v8::Isolate::GetNumberOfDataSlots() - 1, new bool(false)); { v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); V8Class::LoadAll(isolate); } } CNodeScriptRuntime::~CNodeScriptRuntime() {} alt::IResource::Impl* CNodeScriptRuntime::CreateImpl(alt::IResource* resource) { auto res = new CNodeResourceImpl{ this, isolate, resource }; resources.insert(res); return res; } void CNodeScriptRuntime::OnTick() { v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::SealHandleScope seal(isolate); platform->DrainTasks(isolate); } void CNodeScriptRuntime::OnDispose() { /*{ v8::SealHandleScope seal(isolate); do { uv_run(uv_default_loop(), UV_RUN_DEFAULT); platform->DrainTasks(isolate); } while (uv_loop_alive(uv_default_loop())); }*/ #ifdef WIN32 v8::V8::Dispose(); v8::V8::ShutdownPlatform(); #else platform->DrainTasks(isolate); platform->CancelPendingDelayedTasks(isolate); platform->UnregisterIsolate(isolate); isolate->Dispose(); v8::V8::Dispose(); platform.release(); #endif // node::FreePlatform(platform.release()); }
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r8 push %rax push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_UC_ht+0x2945, %rsi lea addresses_D_ht+0x11195, %rdi clflush (%rdi) nop nop nop nop nop cmp $23409, %rax mov $53, %rcx rep movsq nop nop nop xor %rdx, %rdx lea addresses_UC_ht+0x1e595, %r13 nop nop nop nop cmp %rbx, %rbx mov $0x6162636465666768, %rdi movq %rdi, (%r13) nop nop nop nop nop and $31008, %r13 lea addresses_D_ht+0x11875, %rsi lea addresses_normal_ht+0x189a2, %rdi nop nop cmp %r8, %r8 mov $7, %rcx rep movsw nop nop inc %rdi lea addresses_WC_ht+0x1a816, %rsi lea addresses_WC_ht+0x1550d, %rdi add %rbx, %rbx mov $59, %rcx rep movsq nop nop dec %r13 lea addresses_UC_ht+0x6d95, %rdx nop nop sub $54444, %r8 mov $0x6162636465666768, %r13 movq %r13, (%rdx) nop nop nop nop mfence lea addresses_D_ht+0x2d3d, %rcx nop nop dec %rsi mov $0x6162636465666768, %r13 movq %r13, %xmm3 and $0xffffffffffffffc0, %rcx vmovntdq %ymm3, (%rcx) nop nop nop sub $6151, %rdx lea addresses_UC_ht+0xdd79, %rdx inc %rax movl $0x61626364, (%rdx) nop nop cmp %rdi, %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %rax pop %r8 pop %r13 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %r8 push %r9 push %rbx push %rdi // Store lea addresses_UC+0xed65, %rdi nop nop nop and $29956, %r9 movl $0x51525354, (%rdi) nop inc %r11 // Store lea addresses_normal+0x14595, %r12 nop add %r8, %r8 movb $0x51, (%r12) nop nop dec %r12 // Store mov $0x3abed400000000b7, %r8 nop nop nop nop nop cmp %rbx, %rbx mov $0x5152535455565758, %r12 movq %r12, (%r8) nop nop xor %r14, %r14 // Faulty Load lea addresses_D+0xcd95, %rbx nop nop nop nop dec %r12 mov (%rbx), %edi lea oracles, %r12 and $0xff, %rdi shlq $12, %rdi mov (%r12,%rdi,1), %rdi pop %rdi pop %rbx pop %r9 pop %r8 pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': True, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 10, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 1, 'size': 8, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': True}, 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 11, 'size': 8, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 11, 'size': 8, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 2, 'size': 4, 'same': False, 'NT': False}} {'36': 21829} 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 */
; MH6111/TMP76C75T Bootstrap from Serial test code (TASM) ; Jane Hacker ; 9th Feb 2022 ; ; XTAL = 12MHz, E = 12MHz/6 = 2MHz ; Baud rate = 2Mhz/4096 = 488 Baud (Nice and slow) ; Baud rate = 2Mhz/128 = 15,625 Baud ; Baud rate = 2Mhz/16 = 125,000 Baud (Holy smokes!) ; ; Run in Mode 2, Multiplexed/RAM/No ROM, P20: L, P21: H, P22: L ; .msfirst ; ;Internal registers SCI_BAUD .equ $0010 SCI_SCR .equ $0011 rxbuff .equ $0012 txbuff .equ $0013 ram_ctrl .equ $0014 ; ;RAM RAM_BOT .equ $0040 ;The bottom of stored RAM RAM_CODE .equ $0057 ;The bottom of reset RAM STACK .equ $01BF ;The top of RAM ; ; ;...The Void... ; ;ROM start .equ $8000 ;start address of the external rom .org start : ; Strings HELLOSTR .text "\nJANE HACKER 2022 <3\n" .byte $00 READYSTR .text "READY" .byte $00 DONESTR .text "DONE" .byte $00 ; ;Code ENTRYPOINT lds #STACK ;setup the stack pointer ; ldaa #$C0 ;to RAM enable staa ram_ctrl ;enable RAM ; ldaa #$05 ;baud = E/16, async ;0x07 = baud = E/4096, async staa SCI_BAUD ldaa #$0A ;set acc. A to TE (Transmit Enable) and RE (Recieve Enable) bit in SCI_SCR staa SCI_SCR ;enable transmitter and reciever ; clra ;Clear acc. A ; COPYINIT ldx #RAM_CODE ;Put start addr. of code in RAM into X ; jsr PREADY ;Print "READY" to serial ; COPY jsr RCHAR ;Load acc. A with code staa $00,x ;Store acc. A into RAM code inx staa $00,x ;Peek for end of instruction marker cmpa #$F0 bne COPY ; ldd #$0000 ldx #$0000 ldy #$0000 ; jsr RAM_CODE ;Run the code copied into RAM ; jsr PDONE ;Print "DONE" to the serial ; INFLOOP bra INFLOOP ;Print a char out the serial port PCHAR psha ;save A PCHAR1 ldaa SCI_SCR ;get comms status ;clears the TDRE bit anda #$20 ;mask for tdre bit beq PCHAR1 ;wait till empty pula ;restore A staa txbuff ;send it rts ; ;Read a char from the serial port RCHAR ldaa SCI_SCR ;get comms status ;clears the RDRF bit? anda #$80 ;mask for rdrf bit beq RCHAR ;wait till full ldaa rxbuff ;read it rts ;the byte is now in acc. A ; ;Print a string out the serial port; expect start address of string in reg. D PSTR pshx ;Chuck ind. X onto the stack xgdx ;ind. X now has the string address pshx PSTRLOOP ldaa $00,x ;Load acc. A with data at address in X cmpa #$00 beq PSTRDONE ;If acc. A is zero (our "null byte") jsr PCHAR ;Print the char inx ;Increment X to the next byte bra PSTRLOOP ;loop PSTRDONE pulx ;restore acc. D xgdx pulx ;restore ind. X rts ;return ; ;Print the string READY to serial PREADY ldd #READYSTR ;Point to start of "READY" string jsr PSTR ;Print string routine rts ; ;Print the string DONE to serial PDONE ldd #DONESTR ;Point to start of "READY" string jsr PSTR ;Print string routine rts ; ;Clear accumulators CLRACC clra clrb rts ; ;ISRs sci_tr bra sci_tr tof_tr bra tof_tr ocf_tr bra ocf_tr icf_tr bra icf_tr irq_tr bra irq_tr swi_tr bra swi_tr nmi_tr bra nmi_tr ; ; Interrupt Vectors .org $fff0 ; .word sci_tr .word tof_tr .word ocf_tr .word icf_tr .word irq_tr .word swi_tr .word nmi_tr .word ENTRYPOINT .end
; float floor(float x) SECTION code_fp_math48 PUBLIC cm48_sdccix_floor EXTERN cm48_sdccix_floor_fastcall cm48_sdccix_floor: pop af pop hl pop de push de push hl push af jp cm48_sdccix_floor_fastcall
# Test5 - AND Test pushb false pushb true and halt
; Dieses Programm löscht den Bildschirm und gibt einen Text an einer definierten Position aus. ; Programmstart mit SYS 49152 *=$c000 ; Startadresse des Programms BSOUT = $FFD2 start lda #147 ; Steuerzeichen für Bildschirm löschen jsr BSOUT ; Löschen durchführen ldx #03 ; Zeile 3 ldy #10 ; Spalte 10 clc ; Carry-Flag = 0 Cursorposition setzen, = 1 Cursorposition lesen jsr $fff0 ; Cursor setzen ldx #$00 ; Index für Textbuchstaben in X-Register schleife lda $c01c,X ; Zeichen holen beq ende ; Endmarkierung? (wenn 0) jsr BSOUT ; Zeichen am Bildschirm ausgeben inx ; nächstes Zeichen der Zeichenkette jmp schleife ende rts ; Rücksprung ins Basic
INCLUDE "config_private.inc" SECTION code_clib SECTION code_math PUBLIC l_fast_divu_24_24x24, l0_fast_divu_24_24x24 EXTERN l0_fast_divu_16_16x16, l0_fast_divu_24_24x16, error_divide_by_zero_mc divu_24_16x24: ; hl / dbc inc d dec d jr nz, result_zero divu_24_16x16: ; hl / bc ld e,c ld d,b call l0_fast_divu_16_16x16 ; ahl = quotient ; de = remainder ld c,a ret divu_24_24x16: ; ehl / bc call l0_fast_divu_24_24x16 ; ahl = quotient ; de = remainder ld c,0 ret result_zero: ; dividend < divisor ld c,e ex de,hl xor a ld l,a ld h,a ret divide_by_zero: ld c,e ex de,hl ld a,$ff jp error_divide_by_zero_mc l_fast_divu_24_24x24: ; unsigned division of two 24-bit numbers ; ; enter : ehl = 24-bit dividend ; dbc = 24-bit divisor ; ; exit : success ; ; ahl = 24-bit quotient ; cde = 24-bit remainder ; carry reset ; ; divide by zero ; ; ahl = $ffffff = UINT_MAX ; cde = dividend ; carry set, errno = EDOM ; ; uses : af, bc, de, hl, ixh ; test for divide by zero ld a,d or b or c jr z, divide_by_zero l0_fast_divu_24_24x24: ; try to reduce the division inc e dec e jr z, divu_24_16x24 inc d dec d jr z, divu_24_24x16 ; ehl >= $ 01 00 00 ; dbc >= $ 01 00 00 ; check divisor size ld a,e cp d jr c, result_zero jp nz, begin ld a,h cp b jr c, result_zero jp nz, begin ld a,l cp c jr c, result_zero begin: ; ehl >= dbc ; ehl >= $ 01 00 00 ; dbc >= $ 01 00 00 ; ; max quotient is 255 ; ; this means the results of the first sixteen ; iterations of the division loop are known ; ; inside the loop the computation is ; e[hl']/dbc, ahl = remainder ; so initialize as if sixteen iterations done ld a,e ld e,l ld l,h ld h,a xor a ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_IMATH_FAST & $01 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ENABLE LOOP UNROLLING ;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; unroll divide eight times ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_IMATH_FAST & $02 ; eliminate leading zeroes loop_00: rl e adc hl,hl jr c, loop_10 rl e inc e adc hl,hl jr c, loop_20 rl e inc e adc hl,hl jr c, loop_30 rl e inc e adc hl,hl jr c, loop_40 rl e inc e adc hl,hl jr c, loop_50 rl e inc e adc hl,hl jr c, loop_60 rl e inc e adc hl,hl jr c, loop_70 scf jp loop_7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rl e adc hl,hl ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; general divide loop loop_10: rla sbc hl,bc sbc a,d jr nc, loop_1 add hl,bc adc a,d loop_1: rl e adc hl,hl loop_20: rla sbc hl,bc sbc a,d jr nc, loop_2 add hl,bc adc a,d loop_2: rl e adc hl,hl loop_30: rla sbc hl,bc sbc a,d jr nc, loop_3 add hl,bc adc a,d loop_3: rl e adc hl,hl loop_40: rla sbc hl,bc sbc a,d jr nc, loop_4 add hl,bc adc a,d loop_4: rl e adc hl,hl loop_50: rla sbc hl,bc sbc a,d jr nc, loop_5 add hl,bc adc a,d loop_5: rl e adc hl,hl loop_60: rla sbc hl,bc sbc a,d jr nc, loop_6 add hl,bc adc a,d loop_6: rl e adc hl,hl loop_70: rla sbc hl,bc sbc a,d jr nc, loop_7 add hl,bc adc a,d loop_7: rl e adc hl,hl rla sbc hl,bc sbc a,d jr nc, exit_loop add hl,bc adc a,d exit_loop: ; quotient = ~e[hl' ; remainder = ahl ; one more shift left on quotient ex de,hl ld c,a ld a,l rla cpl ld l,a xor a ld h,a ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DISABLE LOOP UNROLLING ;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ld ixh,8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_IMATH_FAST & $02 ; eliminate leading zeroes loop_00: rl e inc e adc hl,hl jr c, loop_01 dec ixh jp loop_00 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; scf ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; general divide loop_11: rl e adc hl,hl loop_01: rla sbc hl,bc sbc a,d jr nc, loop_02 add hl,bc adc a,d loop_02: dec ixh jp nz, loop_11 ; quotient = ~e[hl' ; remainder = ahl ; one more shift left on quotient ex de,hl ld c,a ld a,l rla cpl ld l,a xor a ld h,a ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.cseg .org 0x00 rcall main_thread ; include components interrupts ;.include "../../../../../src/kernel/drivers/{driver_name}_int.asm" .include "../../../../../src/kernel/drivers/soc/ac_int.asm" ; include SoC defaults .include "m8def.inc" ; include components definitions .include "../../../../../src/kernel/kernel_def.asm" ;.include "../../../../../src/kernel/drivers/{driver_name}_def.asm" .include "../../../../../src/kernel/drivers/device_def.asm" .include "../../../../../src/kernel/drivers/io/device_io_def.asm" .include "../../../../../src/kernel/drivers/io/in_bit_def.asm" .include "../../../../../src/kernel/drivers/io/hid/button_def.asm" .include "../../../../../src/kernel/drivers/io/out_bit_def.asm" .include "../../../../../src/kernel/drivers/io/hid/led_def.asm" .include "../../../../../src/kernel/drivers/soc/ac_def.asm" ;.include components data segments ;.include "../../../../../src/kernel/driver/{driver_name}_dseg.asm" .include "../../../../../src/kernel/drivers/soc/ac_dseg.asm" ; custom data & descriptors .dseg led1: .BYTE SZ_ST_LED led2: .BYTE SZ_ST_LED ; main thread .cseg ; skip interrupts vector .org 0x14 ; include components code segments .include "../../../../../src/kernel/kernel_cseg.asm" ;.include "../../../../../src/kernel/thread_cseg.asm" .include "../../../../../src/kernel/drivers/device_cseg.asm" .include "../../../../../src/kernel/drivers/io/device_io_cseg.asm" .include "../../../../../src/kernel/drivers/io/in_bit_cseg.asm" .include "../../../../../src/kernel/drivers/io/hid/button_cseg.asm" .include "../../../../../src/kernel/drivers/io/out_bit_cseg.asm" .include "../../../../../src/kernel/drivers/io/hid/led_cseg.asm" .include "../../../../../src/kernel/drivers/soc/ac_cseg.asm" main_thread: ; stack initialization m_init_stack ; init leds m_led_init led1, DDRC, PORTC, (1 << BIT5) m_led_init led2, DDRC, PORTC, (1 << BIT4) ; init ac m_ac_init AC_INPUT_NEGATIVE_A_IN1, AC_INPUT_POSITIVE_VREF_1_23_V, AC_INTERRPUT_MODE_ARISE_BOTH_FRONTS, ac_on_changed_handler m_ac_enable m_ac_interrupts_enable ; init global interrupts m_init_interrupts main_thread_loop: nop nop main_thread_loop_end: m_ac_output_value_get r16 cpi r16, AC_OUTPUT_VALUE_FALSE breq main_thread_loop_ac_false main_thread_loop_ac_true: m_led_on led2 rjmp main_thread_loop main_thread_loop_ac_false: m_led_off led2 rjmp main_thread_loop ret ac_on_changed_handler: cpi YL, AC_OUTPUT_VALUE_FALSE breq ac_on_changed_handler_value_false ac_on_changed_handler_value_true: m_led_toggle led1 rjmp ac_on_changed_handler_end ac_on_changed_handler_value_false: m_led_toggle led1 rjmp ac_on_changed_handler_end ac_on_changed_handler_end: ret
//============================================================================== // Copyright 2003 - 2012 LASMEA UMR 6602 CNRS/Univ. Clermont II // Copyright 2009 - 2012 LRI UMR 8623 CNRS/Univ Paris Sud XI // // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE.txt or copy at // http://www.boost.org/LICENSE_1_0.txt //============================================================================== #define NT2_UNIT_MODULE "nt2 linalg toolbox - svd solvers" #include <nt2/table.hpp> #include <nt2/include/functions/zeros.hpp> #include <nt2/include/functions/ones.hpp> #include <nt2/include/functions/eye.hpp> #include <nt2/include/functions/svd_solve.hpp> #include <nt2/include/functions/isulpequal.hpp> #include <nt2/include/functions/mtimes.hpp> #include <nt2/include/functions/globalmax.hpp> #include <nt2/sdk/unit/tests.hpp> #include <nt2/sdk/unit/module.hpp> #include <nt2/sdk/unit/tests/exceptions.hpp> #include <nt2/sdk/unit/tests/basic.hpp> NT2_TEST_CASE_TPL(svd_solve_result, NT2_REAL_TYPES) { using nt2::_; using nt2::tag::solvers::svd_solve_; typedef typename nt2::meta::as_integer<T, signed>::type itype_t; typedef nt2::table<T> t_t; typedef nt2::table<itype_t> it_t; t_t a = nt2::ones (4, 4, nt2::meta::as_<T>()) + T(10)*nt2::eye (4, 4, nt2::meta::as_<T>()); t_t b = nt2::ones(4, 1, nt2::meta::as_<T>()); nt2::display("a ", a); nt2::display("b ", b); typedef typename nt2::meta::call<svd_solve_(t_t const&, t_t const&)>::type result_type; result_type f = nt2::solvers::svd_solve(a, b); nt2::display("values", f.x()); std::cout << "rank " << f.rank() << std::endl; NT2_TEST(nt2::isulpequal(b, mtimes(a, f.x()), T(2.0))); }
object_const_def Osaka_MapScripts: db 0 ; scene scripts db 0 ; callbacks ;callback MAPCALLBACK_NEWMAP, .InitializeRoom ;callback MAPCALLBACK_TILES, .SetSpawn Osaka_MapEvents: db 0, 0 ; filler db 2 ; warp events warp_event 4, 10, KOCHI, 1 warp_event 4, 11, KOCHI, 2 db 0 ; coord events db 0 ; bg events ;bg_event 0, 1, BGEVENT_READ, RedsHouse1FBookshelf ;bg_event 1, 1, BGEVENT_READ, RedsHouse1FBookshelf ;bg_event 2, 1, BGEVENT_READ, RedsHouse1FTV db 0 ; object events ;object_event 5, 3, SPRITE_REDS_MOM, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, RedsMom, -1
;================================================================================ ; Inventory Updates ;================================================================================ !INVENTORY_SWAP = "$7EF38C" ; Item Tracking Slot ; brmpnskf ; b = blue boomerang ; r = red boomerang ; m = mushroom current ; p = magic powder ; n = mushroom past ; s = shovel ; k = fake flute ; f = working flute ;-------------------------------------------------------------------------------- !INVENTORY_SWAP_2 = "$7EF38E" ; Item Tracking Slot #2 ; bsp----- ; b = bow ; s = silver arrow bow ; p = 2nd progressive bow ; - ; - ; - ; - ; - ;-------------------------------------------------------------------------------- ; ProcessMenuButtons: ; out: Carry - 0 = No Button, 1 = Yes Button ;-------------------------------------------------------------------------------- ProcessMenuButtons: ;LDA #$FD : STA !INVENTORY_SWAP ; DEBUG MODE ;LDA $F6 : BIT #$20 : BNE .l_pressed ; check for P1 L-button LDA $F4 : BIT #$40 : BNE .y_pressed ; check for P1 Y-button BIT #$20 : BNE .sel_pressed ; check for P1 Select button LDA $F0 : BIT #$20 : BNE .sel_held .sel_unheld LDA !HUD_FLAG : AND #$20 : BEQ + LDA !HUD_FLAG : AND #$DF : STA !HUD_FLAG ; select is released, unset hud flag LDA $1B : BEQ + ; skip if outdoors LDA.b #$20 : STA $012F ; menu select sound + JSL.l ResetEquipment + .sel_held CLC ; no buttons RTL ;.l_pressed ;JSL.l SpawnAngryCucco ;RTL .sel_pressed LDA !HUD_FLAG : ORA #$20 : STA !HUD_FLAG ; set hud flag LDA.b #$20 : STA $012F ; menu select sound JSL.l ResetEquipment RTL .y_pressed ; Note: used as entry point by quickswap code. Must preserve X. LDA.b #$10 : STA $0207 LDA $0202 ; check selected item CMP #$02 : BNE + ; boomerang LDA !INVENTORY_SWAP : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both boomerangs LDA $7EF341 : EOR #$03 : STA $7EF341 ; swap blue & red boomerang LDA.b #$20 : STA $012F ; menu select sound BRL .captured + CMP #$01 : BNE + ; bow LDA !INVENTORY_SWAP_2 : AND #$C0 : CMP #$C0 : BNE .errorJump ; make sure we have both bows PHX : LDX.b #$00 ; scan ancilla table for arrows -- : CPX.b #$0A : !BGE ++ LDA $0C4A, X : CMP.b #$09 : BNE +++ PLX : BRA .errorJump2 ; found an arrow, don't allow the swap +++ INX : BRA -- : ++ PLX LDA.l SilverArrowsUseRestriction : BEQ ++ LDA $A0 : ORA $A1 : BEQ ++ ; not in ganon's room in restricted mode LDA $7EF340 : CMP.b #$03 : !BLT .errorJump : !SUB #$02 : STA $7EF340 BRA .errorJump2 ++ LDA $7EF340 : !SUB #$01 : EOR #$02 : !ADD #$01 : STA $7EF340 ; swap bows LDA.b #$20 : STA $012F ; menu select sound BRL .captured + BRA + .errorJump BRA .errorJump2 + CMP #$05 : BNE + ; powder LDA !INVENTORY_SWAP : AND #$30 : CMP #$30 : BNE .errorJump ; make sure we have mushroom & magic powder LDA $7EF344 : EOR #$03 : STA $7EF344 ; swap mushroom & magic powder LDA.b #$20 : STA $012F ; menu select sound BRL .captured + BRA + .errorJump2 BRA .error + CMP #$0D : BNE + ; flute LDA $037A : CMP #$01 : BEQ .midShovel ; inside a shovel animation, force the shovel & make error sound LDA !INVENTORY_SWAP : BIT #$04 : BEQ .error ; make sure we have shovel AND #$03 : BEQ .error ; make sure we have one of the flutes LDA $7EF34C : CMP #01 : BNE .toShovel ; not shovel LDA !INVENTORY_SWAP : AND #$01 : BEQ .toFakeFlute ; check for real flute LDA #$03 ; set real flute BRA .fluteSuccess .toFakeFlute LDA #$02 ; set fake flute BRA .fluteSuccess .toShovel LDA #$01 ; set shovel .fluteSuccess STA $7EF34C ; store set item LDA.b #$20 : STA $012F ; menu select sound BRA .captured + CMP #$10 : BNE .error : JSL.l ProcessBottleMenu : BRA .captured : + CLC RTL .midShovel ; LDA #$01 : STA $7EF34C ; set shovel .error LDA.b #$3C : STA $012E ; error sound .captured SEC RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ;ProcessBottleMenu: ;-------------------------------------------------------------------------------- ProcessBottleMenu: LDA $F4 : AND #$40 : BEQ .y_not_pressed ; skip if Y is not down LDA $7EF34F ; check bottle state BEQ .no_bottles ; skip if we have no bottles PHX INC : CMP #$05 : !BLT + : LDA #$01 : + ;increment and wrap 1-4 TAX : LDA $7EF35C-1, X ; check bottle BNE + : LDX #$01 : + ; wrap if we reached the last bottle TXA : STA $7EF34F ; set bottle index LDA.b #$20 : STA $012F ; menu select sound PLX .no_bottles LDA #$00 ; pretend like the controller state was 0 from the overridden load RTL .y_not_pressed LDA $F4 : AND.b #$0C ; thing we wrote over - load controller state RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ;OpenBottleMenu: ;-------------------------------------------------------------------------------- OpenBottleMenu: LDA $F6 : AND #$40 : BEQ .x_not_pressed ; skip if X is not down LDA.b #$10 : STA $0207 ; set 16 frame cool off LDA.b #$20 : STA $012F ; make menu sound LDA.b #$07 : STA $0200 ; thing we wrote over - opens bottle menu .x_not_pressed RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ;CloseBottleMenu: ;-------------------------------------------------------------------------------- CloseBottleMenu: LDA $F6 : AND #$40 : BEQ .x_not_pressed ; skip if X is not down LDA.b #$10 : STA $0207 ; set 16 frame cool off LDA.b #$20 : STA $012F ; make menu sound INC $0200 ; return to normal menu STZ $0205 LDA #$00 RTL .x_not_pressed LDA $F4 : AND.b #$0C ; thing we wrote over (probably) RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; AddInventory: ;-------------------------------------------------------------------------------- !LOCK_STATS = "$7EF443" macro TopHalf(address) LDA <address> : !ADD #$10 : STA <address> endmacro macro BottomHalf(address) PHA : PHX LDA <address> : INC : AND #$0F : TAX LDA <address> : AND #$F0 : STA <address> TXA : ORA <address> : STA <address> PLX : PLA endmacro ;-------------------------------------------------------------------------------- ;FullInventoryExternal: ; LDA !LOCK_STATS : BEQ + : RTL : + ; PHA : PHX : PHP : JMP AddInventory_fullItemCounts ;-------------------------------------------------------------------------------- FullInventoryExternal: LDA !LOCK_STATS : BEQ + : RTL : + PHA : PHX : PHP : JMP AddInventory_incrementCounts ;-------------------------------------------------------------------------------- !SHAME_CHEST = "$7EF416" ; ---s ---- AddInventory: PHA : PHX : PHP LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ + BRL .incrementCounts + CPY.b #$0C : BNE + ; Blue Boomerang LDA !INVENTORY_SWAP : ORA #$80 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$2A : BNE + ; Red Boomerang LDA !INVENTORY_SWAP : ORA #$40 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$29 : BNE + ; Mushroom LDA !INVENTORY_SWAP : ORA #$28 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$0D : BNE + ; Magic Powder LDA !INVENTORY_SWAP : ORA #$10 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$13 : BNE + ; Shovel LDA !INVENTORY_SWAP : ORA #$04 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$14 : BNE + ; Flute (Inactive) LDA !INVENTORY_SWAP : ORA #$02 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$4A : BNE + ; Flute (Active) LDA !INVENTORY_SWAP : ORA #$01 : STA !INVENTORY_SWAP BRL .incrementCounts + CPY.b #$0B : BNE + ; Bow LDA ArrowMode : BNE +++ LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 +++ BRL .incrementCounts + CPY.b #$3A : BNE + ; Bow & Arrows LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 BRL .incrementCounts + CPY.b #$3B : BNE + ; Bow & Silver Arrows LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2 LDA ArrowMode : BNE +++ LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows when not in rupee bow +++ BRL .incrementCounts + CPY.b #$43 : BNE + ; Single arrow LDA ArrowMode : BEQ +++ LDA !INVENTORY_SWAP_2 : ORA #$80 : STA !INVENTORY_SWAP_2 ; activate wood arrows in quick-swap +++ BRL .incrementCounts + CPY.b #$58 : BNE + ; Upgrade-Only Silver Arrows LDA !INVENTORY_SWAP_2 : ORA #$40 : STA !INVENTORY_SWAP_2 + .incrementCounts CPY.b #$6A : BEQ + ; Skip !LOCK_STATS for Triforce. so that it counts towards the stat. LDA !LOCK_STATS : BEQ + : BRL .done : + LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ + BRL .dungeonCounts + ; don't count any of this stuff CPY.b #$20 : BNE + : BRL .itemCounts : + ; Crystal CPY.b #$26 : BNE + : BRL .itemCounts : + ; Heart Piece Completion Heart CPY.b #$37 : BNE + : BRL .itemCounts : + ; Pendant CPY.b #$38 : BNE + : BRL .itemCounts : + ; Pendant CPY.b #$39 : BNE + : BRL .itemCounts : + ; Pendant CPY.b #$00 : BNE + : BRL .itemCounts : + ; Uncle Sword & Shield CPY.b #$04 : !BLT .isSword ; Swords - Skip Shop/Fairy Check for Swords CPY.b #$49 : BEQ .isSword CPY.b #$50 : BEQ .isSword CPY.b #$5E : BEQ .isSword BRA + .isSword BRL .dungeonCounts + CPY.b #$3B : BNE + : BRL .dungeonCounts : + ; Silver Arrow Bow - Skip Shop/Fairy Check for Silver Arrow Bow LDA $1B : BEQ ++ ; skip shop check if outdoors LDA $02E9 : CMP.b #$01 : BEQ ++ ; skip shop check for chests PHP : REP #$20 ; set 16-bit accumulator LDA $048E CMP.w #274 : BNE + : BRL .shop : + ; dark world death mountain shop, ornamental shield shop CMP.w #271 : BNE + : BRL .shop : + ; villiage of outcasts shop, lumberjack shop, lake hylia shop, dark world magic shop CMP.w #272 : BNE + : BRL .shop : + ; red shield shop CMP.w #284 : BNE + : BRL .shop : + ; bomb shop CMP.w #265 : BNE + : BRL .shop : + ; potion shop - commented this out because it's easier to just block potion refills because this one interferes with the powder item being counted CMP.w #287 : BNE + : BRL .shop : + ; kakariko shop CMP.w #255 : BNE + : BRL .shop : + ; light world death mountain shop CMP.w #276 : BNE + : BRL .shop : + ; waterfall fairy CMP.w #277 : BNE + : BRL .shop : + ; upgrade fairy (shop) CMP.w #278 : BNE + : BRL .shop : + ; pyramid fairy PLP : BRA ++ .shop PLP LDA.l !SHOP_ENABLE_COUNT : BNE ++ BRL .done ++ .dungeonCounts LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BNE + BRL .fullItemCounts + LDA $1B : BNE + : BRL .fullItemCounts : + ; ==BEGIN INDOOR-ONLY SECTION ;REP #$20 ; Set 16-bit Accumulator ;LDA $A0 ; load room ID ;CMP.w #$0010 : BNE + ; Ganon Fall Room - I think this got taken out ;!SHAME_CHEST = "$7EF416" ; ---s ---- ;LDA !SHAME_CHEST : ORA.w #$0010 : STA !SHAME_CHEST ;+ SEP #$20 ; Set 8-bit Accumulator LDA $040C ; get dungeon id BNE + INC #2 ; treat sewers as HC + CMP #$FF : BEQ .fullItemCounts CMP.b #$02 : BNE + CPY.b #$32 : BNE + ; Check if Big key is for Sewers/Hyrule Castle PHA LDA.b #$C0 : ORA $7EF367 : STA $7EF367 ; Big Key 2 PLA + CMP.l BallNChainDungeon : BNE + CPY.b #$32 : BNE + BRL .done + LSR : TAX : LDA $7EF4BF, X : INC : STA $7EF4BF, X CPX.b #$0D : BNE + LDA $7EF366 : AND #$04 : BNE ++ JSR .incrementGTowerPreBigKey ++ + ; == END INDOOR-ONLY SECTION .fullItemCounts ;LDA !MULTIWORLD_ITEM_PLAYER_ID : BNE + ; CPY.b #$3B : BNE + ; Skip Total Counts for Repeat Silver Arrows ; LDA $7EF42A : BIT #$20 : BEQ + : BRA .itemCounts ;+ LDA !MULTIWORLD_RECEIVING_ITEM : CMP #$01 : BEQ ++ LDA $7EF355 : BNE + ; Check for Boots REP #$20 LDA $7EF432 : INC : STA $7EF432 ; Increment Pre Boots Counter SEP #$20 + LDA $7EF353 : BNE + ; Check for Mirror REP #$20 LDA $7EF468 : INC : STA $7EF468 ; Increment Pre Mirror Counter SEP #$20 + REP #$20 LDA $7EF423 : INC : STA $7EF423 ; Increment Item Total SEP #$20 ++ .itemCounts LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ + BRL .done + CPY.b #$00 : BNE + ; Fighter's Sword & Fighter's Shield JSR .incrementSword JSR .incrementShield BRL .done + CPY.b #$01 : BNE + ; Master Sword JSR .incrementSword BRL .done + CPY.b #$02 : BNE + ; Tempered Sword JSR .incrementSword BRL .done + CPY.b #$03 : BNE + ; Golden Sword JSR .incrementSword BRL .done + CPY.b #$04 : BNE + ; Fighter's Shield JSR .incrementShield BRL .done + CPY.b #$05 : BNE + ; Red Shield JSR .incrementShield BRL .done + CPY.b #$06 : BNE + ; Mirror Shield JSR .incrementShield BRL .done + CPY.b #$07 : !BLT + ; Items $07 - $0D CPY.b #$0E : !BGE + JSR .incrementY BRL .done + CPY.b #$14 : BNE + ; Flute (Inactive) - LEAVE THIS ABOVE THE 0F-16 CONDITION - kkat JSR .stampFlute JSR .incrementY BRL .done + CPY.b #$0F : !BLT + ; Items $0F - $16 CPY.b #$17 : !BGE + JSR .incrementY BRL .done + CPY.b #$17 : BNE + ; Heart Piece JSR .incrementHeartPiece BRL .done + CPY.b #$18 : !BLT + ; Items $18 - $19 CPY.b #$1A : !BGE + JSR .incrementY BRL .done + CPY.b #$1A : BNE + ; Magic Mirror JSR .stampMirror JSR .incrementY BRL .done + CPY.b #$1D : BNE + ; Book of Mudora - LEAVE THIS ABOVE THE 1B-1F CONDITION - kkat JSR .incrementY BRL .done + CPY.b #$1B : !BLT + ; Items $1B - $1F CPY.b #$20 : !BGE + JSR .incrementA BRL .done + CPY.b #$20 : BNE + ; Crystal JSR .incrementCrystal JSR .setDungeonCompletion BRL .done + CPY.b #$21 : BNE + ; Bug Net JSR .incrementY BRL .done + CPY.b #$22 : !BLT + ; Items $22 - $23 CPY.b #$24 : !BGE + JSR .incrementMail BRL .done + CPY.b #$24 : BNE + ; Small Key JSR .incrementKey BRL .done + CPY.b #$25 : BNE + ; Compass JSR .incrementCompass BRL .done + CPY.b #$26 : BNE + ; Liar Heart (Container) ;JSR .incrementHeartContainer BRL .done + CPY.b #$27 : BNE + ; 1 Bomb JSR .maybeIncrementBombs BRL .done + CPY.b #$28 : BNE + ; 3 Bombs JSR .maybeIncrementBombs BRL .done + CPY.b #$29 : BNE + ; Musoroom JSR .incrementY BRL .done + CPY.b #$2A : !BLT + ; Items $2A - $2D CPY.b #$2E : !BGE + JSR .incrementY BRL .done + CPY.b #$31 : BNE + ; 10 Bombs JSR .maybeIncrementBombs BRL .done + CPY.b #$32 : BNE + ; Big Key JSR .incrementBigKey BRL .done + CPY.b #$33 : BNE + ; Map JSR .incrementMap BRL .done + CPY.b #$37 : !BLT + ; Items $37 - $39 - Pendants CPY.b #$3A : !BGE + JSR .incrementPendant JSR .setDungeonCompletion BRL .done + CPY.b #$3A : !BLT + ; Items $3A - $3B - Bow & Silver Arrows CPY.b #$3C : !BGE + JSR .incrementBow BRL .done + CPY.b #$3C : BNE + ; Bottle w/Bee JSR .incrementY BRL .done + CPY.b #$3D : BNE + ; Bottle w/Fairy JSR .incrementY BRL .done + CPY.b #$3E : !BLT + ; Items $3E - $3F - Heart Containers CPY.b #$40 : !BGE + JSR .incrementHeartContainer BRL .done + CPY.b #$48 : BNE + ; Bottle w/Gold Bee JSR .incrementY BRL .done + CPY.b #$49 : BNE + ; Fighter's Sword JSR .incrementSword BRL .done + CPY.b #$4A : BNE + ; Flute (Active) JSR .stampFlute JSR .incrementY BRL .done + CPY.b #$4B : BNE + ; Pegasus Boots JSR .stampBoots JSR .incrementA BRL .done + CPY.b #$4C : BNE + ; Bomb Capacity Upgrade JSR .incrementCapacity JSR .maybeIncrementBombs BRL .done + CPY.b #$4D : !BLT + ; Items $4D - $4F - Capacity Upgrades CPY.b #$50 : !BGE + JSR .incrementCapacity BRL .done + CPY.b #$50 : BNE + ; Master Sword (Safe) JSR .incrementSword BRL .done + CPY.b #$51 : !BLT + ; Items $51 - $54 - Capacity Upgrades CPY.b #$55 : !BGE + JSR .incrementCapacity BRL .done + CPY.b #$58 : BNE + ; Upgrade-Only Sivler Arrows JSR .incrementBow BRL .done + CPY.b #$5E : BNE + ; Progressive Sword JSR .incrementSword BRL .done + CPY.b #$5F : BNE + ; Progressive Shield JSR .incrementShield BRL .done + CPY.b #$60 : BNE + ; Progressive Armor JSR .incrementMail BRL .done + CPY.b #$61 : BNE + ; Progressive Lifting Glove JSR .incrementA BRL .done + CPY.b #$64 : !BLT + ; Items $64 & $65 - Progressive Bow CPY.b #$66 : !BGE + JSR .incrementBow BRL .done + CPY.b #$70 : !BLT + ; Items $70 - $7F - Free Maps CPY.b #$80 : !BGE + JSR .incrementMap BRL .done + CPY.b #$80 : !BLT + ; Items $80 - $8F - Free Compasses CPY.b #$90 : !BGE + JSR .incrementCompass BRL .done + CPY.b #$90 : !BLT + ; Items $90 - $9F - Free Big Keys CPY.b #$A0 : !BGE + JSR .incrementBigKey BRL .done + CPY.b #$A0 : !BLT + ; Items $A0 - $AF - Free Small Keys CPY.b #$B0 : !BGE + JSR .incrementKey BRL .done + .done PLP : PLX : PLA RTL ; WHICH BEE IS BOTTLED? ; MAKE SURE FAIRY FOUNTAINS DON'T FUCK THE COUNTS UP !NMI_TIME = "$7EF43E" !SWORD_TIME = "$7EF458" !BOOTS_TIME = "$7EF45C" !FLUTE_TIME = "$7EF460" !MIRROR_TIME = "$7EF464" .stampSword REP #$20 ; set 16-bit accumulator LDA !SWORD_TIME : BNE + LDA !SWORD_TIME+2 : BNE + LDA !NMI_TIME : STA !SWORD_TIME LDA !NMI_TIME+2 : STA !SWORD_TIME+2 + SEP #$20 ; set 8-bit accumulator RTS .stampBoots REP #$20 ; set 16-bit accumulator LDA !BOOTS_TIME : BNE + LDA !BOOTS_TIME+2 : BNE + LDA !NMI_TIME : STA !BOOTS_TIME LDA !NMI_TIME+2 : STA !BOOTS_TIME+2 + SEP #$20 ; set 8-bit accumulator RTS .stampFlute REP #$20 ; set 16-bit accumulator LDA !FLUTE_TIME : BNE + LDA !FLUTE_TIME+2 : BNE + LDA !NMI_TIME : STA !FLUTE_TIME LDA !NMI_TIME+2 : STA !FLUTE_TIME+2 + SEP #$20 ; set 8-bit accumulator RTS .stampMirror REP #$20 ; set 16-bit accumulator LDA !MIRROR_TIME : BNE + LDA !MIRROR_TIME+2 : BNE + LDA !NMI_TIME : STA !MIRROR_TIME LDA !NMI_TIME+2 : STA !MIRROR_TIME+2 + SEP #$20 ; set 8-bit accumulator RTS .incrementSword ; CHECK FOR DUPLICATE SWORDS JSR .stampSword TYA ; load sword item CMP.b #$50 : BNE + : LDA.b #$01 : + ; convert extra master sword to normal one CMP.b #$49 : BNE + : LDA.b #$00 : + ; convert extra fighter sword to normal one INC : CMP !HIGHEST_SWORD_LEVEL : !BLT + ; skip if highest is higher PHA LDA !HIGHEST_SWORD_LEVEL : AND #$F8 : ORA 1,s : STA !HIGHEST_SWORD_LEVEL PLA + LDA $7EF422 : !ADD #$20 : STA $7EF422 ; increment sword counter RTS .incrementShield ; CHECK FOR DUPLICATE SHIELDS LDA $7EF422 : !ADD #$08 : AND #$18 : TAX LDA $7EF422 : AND #$E7 : STA $7EF422 TXA : ORA $7EF422 : STA $7EF422 RTS .incrementBow CPY.b #$3B : BNE ++ LDA $7EF42A : BIT #$20 : BEQ + : RTS : + ORA #$20 : STA $7EF42A ++ .incrementY LDA $7EF421 : !ADD #$08 : STA $7EF421 RTS .incrementA LDA $7EF421 : INC : AND #$07 : TAX LDA $7EF421 : AND #$F8 : STA $7EF421 TXA : ORA $7EF421 : STA $7EF421 RTS .incrementPendant LDA $7EF429 : INC : AND #$03 : TAX LDA $7EF429 : AND #$FC : STA $7EF429 TXA : ORA $7EF429 : STA $7EF429 ; JSR .incrementBossSword RTS .incrementCapacity %BottomHalf($7EF452) RTS .incrementHeartPiece LDA $7EF448 : INC : AND #$1F : TAX LDA $7EF448 : AND #$E0 : STA $7EF448 TXA : ORA $7EF448 : STA $7EF448 RTS .incrementHeartContainer %TopHalf($7EF429) RTS .incrementCrystal LDA $7EF422 : INC : AND #$07 : TAX LDA $7EF422 : AND #$F8 : STA $7EF422 TXA : ORA $7EF422 : STA $7EF422 ; JSR .incrementBossSword RTS .incrementMail LDA $7EF46A : !ADD #$40 : STA $7EF46A RTS .incrementKeyLong JSR .incrementKey RTL .incrementKey PHA : PHX LDA $7EF46A : INC : AND #$3F : TAX LDA $7EF46A : AND #$C0 : STA $7EF46A TXA : ORA $7EF46A : STA $7EF46A PLX : PLA RTS .incrementCompass %BottomHalf($7EF428) RTS .incrementBigKey LDA $7EF427 : !ADD #$10 : STA $7EF427 RTS .incrementGTowerPreBigKey LDA $7EF42A : INC : AND #$1F : TAX LDA $7EF42A : AND #$E0 : STA $7EF42A TXA : ORA $7EF42A : STA $7EF42A RTS .maybeIncrementBombs LDA $7EF42A : AND #$80 : BNE + LDA $7EF42A : ORA #$80 : STA $7EF42A JSR .incrementY + RTS .incrementMap LDA $7EF428 : !ADD #$10 : STA $7EF428 RTS .incrementBossSwordLong JSR .incrementBossSword RTL .incrementBossSword LDA $7EF359 BNE + : - %TopHalf($7EF452) : RTS + CMP #$FF : BEQ - + CMP #$01 : BNE + %TopHalf($7EF425) : RTS + CMP #$02 : BNE + %BottomHalf($7EF425) : RTS + CMP #$03 : BNE + %TopHalf($7EF426) : RTS + CMP #$04 : BNE + %BottomHalf($7EF426) + RTS .setDungeonCompletion LDA $040C CMP #$FF : BEQ + LSR : AND #$0F : CMP #$08 : !BGE ++ JSR .valueShift ORA $7EF46B : STA $7EF46B BRA + ++ !SUB #$08 JSR .valueShift BIT.b #$C0 : BEQ +++ : LDA.b #$C0 : +++ ; Make Hyrule Castle / Sewers Count for Both ORA $7EF46C : STA $7EF46C + RTS .valueShift PHX TAX : LDA.b #$01 - CPX #$00 : BEQ + ASL DEX BRA - + PLX RTS ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; Link_ReceiveItem_HUDRefresh: ;-------------------------------------------------------------------------------- Link_ReceiveItem_HUDRefresh: LDA $7EF343 : BNE + ; skip if we have bombs LDA $7EF375 : BEQ + ; skip if we are filling no bombs DEC : STA $7EF375 ; decrease bomb fill count LDA.b #$01 : STA $7EF343 ; increase actual bomb count + JSL.l HUD_RefreshIconLong ; thing we wrote over JSL.l PostItemGet RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; HandleBombAbsorbtion: ;-------------------------------------------------------------------------------- HandleBombAbsorbtion: STA $7EF375 ; thing we wrote over LDA $0303 : BNE + ; skip if we already have some item selected LDA.b #$04 : STA $0202 ; set selected item to bombs LDA.b #$01 : STA $0303 ; set selected item to bombs JSL.l HUD_RebuildLong + RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; AddYMarker: ;-------------------------------------------------------------------------------- ;!JAR_STATUS = "$7F5030"; AddYMarker: LDA $0202 : AND.w #$FF ; load item value CMP.w #$02 : BNE + ; boomerang LDA !INVENTORY_SWAP : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal + CMP.w #$01 : BNE + ; bow LDA !INVENTORY_SWAP_2 : AND.w #$C0 : CMP.w #$C0 : BEQ .drawYBubble : BRA .drawNormal + CMP.w #$05 : BNE + ; powder LDA !INVENTORY_SWAP : AND.w #$30 : CMP.w #$30 : BEQ .drawYBubble : BRA .drawNormal + CMP.w #$0D : BNE + ; flute LDA !INVENTORY_SWAP : BIT.w #$04 : BEQ .drawNormal ; make sure we have shovel AND.w #$03 : BNE .drawYBubble ; make sure we have one of the flutes BRA .drawNormal + CMP.w #$10 : BEQ .drawJarMarker .drawNormal LDA.w #$7C60 BRA .drawTile .drawJarMarker ;SEP #$20 : LDA !JAR_STATUS : INC : AND.b #$01 : STA !JAR_STATUS : REP #$20 : BEQ .drawXBubble LDA $0207 : AND.w #$0020 : BNE .drawXBubble .drawYBubble LDA.w #$3D4F BRA .drawTile .drawXBubble JSR MakeCircleBlue LDA.w #$2D3E .drawTile STA $FFC4, Y RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; MakeCircleBlue ; this is horrible, make it better ;-------------------------------------------------------------------------------- MakeCircleBlue: LDA $FFC0, Y : AND.w #$EFFF : STA $FFC0, Y LDA $FFC2, Y : AND.w #$EFFF : STA $FFC2, Y LDA $FFFE, Y : AND.w #$EFFF : STA $FFFE, Y LDA $0004, Y : AND.w #$EFFF : STA $0004, Y LDA $003E, Y : AND.w #$EFFF : STA $003E, Y LDA $0044, Y : AND.w #$EFFF : STA $0044, Y LDA $0080, Y : AND.w #$EFFF : STA $0080, Y LDA $0082, Y : AND.w #$EFFF : STA $0082, Y LDA $FFBE, Y : AND.w #$EFFF : STA $FFBE, Y LDA $FFC4, Y : AND.w #$EFFF : STA $FFC4, Y LDA $0084, Y : AND.w #$EFFF : STA $0084, Y LDA $007E, Y : AND.w #$EFFF : STA $007E, Y RTS ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; UpgradeFlute: ;-------------------------------------------------------------------------------- UpgradeFlute: LDA !INVENTORY_SWAP : AND #$FC : ORA #$01 : STA !INVENTORY_SWAP ; switch to the working flute LDA.b #$03 : STA $7EF34C ; upgrade primary inventory RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; CheckKeys: ;-------------------------------------------------------------------------------- CheckKeys: LDA.l GenericKeys : BEQ + : RTL : + LDA $040C : CMP.b #$FF RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; DrawKeyIcon: ;-------------------------------------------------------------------------------- DrawKeyIcon: LDA $04 : AND.w #$00FF : CMP.w #$0090 : BNE + : LDA.w #$007F : + : ORA.w #$2400 : STA $7EC764 LDA $05 : AND.w #$00FF : ORA.w #$2400 : STA $7EC766 RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; LoadKeys: ;-------------------------------------------------------------------------------- LoadKeys: LDA.l GenericKeys : BEQ + LDA $7EF38B RTL + LDA $7EF37C, X RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; SaveKeys: ;-------------------------------------------------------------------------------- SaveKeys: PHA LDA.l GenericKeys : BEQ + PLA : STA $7EF38B RTL + PLA : STA $7EF37C, X RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; ClearOWKeys: ;-------------------------------------------------------------------------------- ClearOWKeys: PHA JSL.l TurtleRockEntranceFix JSL.l FakeWorldFix JSR.w FixBunnyOnExitToLightWorld LDA.l GenericKeys : BEQ + PLA : LDA $7EF38B : STA $7EF36F RTL + PLA : STA $7EF36F RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; GetWitchLootOAMTableIndex ; in: A - Loot ID ; out: A - Loot OAM Table Index ; check if this is even still referenced anywhere ;-------------------------------------------------------------------------------- ;GetWitchLootOAMTableIndex: ; PHX ; PHB : PHK : PLB ; ;-------- ; TAX : LDA .gfxSlots, X ; look up item gfx ; PLB : PLX ;RTL ; ;;DATA - Loot Identifier to Sprite ID ;{ ; .gfxSlots ; db $FF, $FF, $FF, $FF, $05, $06, $FF, $0C ; db $0B, $0D, $0A, $07, $13, $0E, $FF, $FF ; ; db $FF, $FF, $FF, $FF, $FF, $09, $FF, $FF ; db $08, $FF, $FF, $10, $11, $12, $FF, $FF ; ; db $FF, $FF, $03, $04, $FF, $FF, $02, $FF ; db $FF, $FF, $14, $15, $17, $16, $15, $17 ; ; db $16, $0F, $FF, $FF, $FF, $FF, $FF, $FF ; db $FF, $FF, $FF, $FF, $FF, $FF, $02, $02 ; ; db $FF, $FF, $FF, $FF, $01, $FF, $FF, $FF ; db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF ;} ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; PrepItemScreenBigKey: ;-------------------------------------------------------------------------------- PrepItemScreenBigKey: STZ $02 STZ $03 REP #$30 ; thing we wrote over - set 16-bit accumulator RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; LoadPowder: ;-------------------------------------------------------------------------------- LoadPowder: JSL.l Sprite_SpawnDynamically ; thing we wrote over %GetPossiblyEncryptedPlayerID(WitchItem_Player) : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID %GetPossiblyEncryptedItem(WitchItem, SpriteItemValues) STA $0DA0, Y ; Store item type JSL.l PrepDynamicTile STA $7F505E LDA #$00 STA $7F505F STA $7F5060 STA $7F5061 RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; InitializeBottles: ;-------------------------------------------------------------------------------- InitializeBottles: STA $7EF35C, X ; thing we wrote over PHA LDA $7EF34F : BNE + TXA : INC : STA $7EF34F ; write bottle index to menu properly + PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; DrawPowder: ;-------------------------------------------------------------------------------- !REDRAW = "$7F5000" ;-------------------------------------------------------------------------------- DrawPowder: ; this fights with the shopkeep code, so had to move the powder draw there LDA $02DA : BNE .defer ; defer if link is buying a potion LDA.l !REDRAW : BEQ + %GetPossiblyEncryptedPlayerID(WitchItem_Player) : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID LDA $0DA0, X ; Retrieve stored item type JSL.l PrepDynamicTile LDA #$00 : STA.l !REDRAW ; reset redraw flag BRA .defer + ; LDA $0DA0, X ; Retrieve stored item type ; JSL.l DrawDynamicTile .defer RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; LoadMushroom: ;-------------------------------------------------------------------------------- LoadMushroom: LDA.b #$00 : STA $0DC0, X ; thing we wrote over .justGFX ;LDA MushroomItem ;JSL.l PrepDynamicTile PHA LDA #$01 : STA !REDRAW LDA $5D : CMP #$14 : BEQ .skip ; skip if we're mid-mirror LDA #$00 : STA !REDRAW %GetPossiblyEncryptedPlayerID(MushroomItem_Player) : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID %GetPossiblyEncryptedItem(MushroomItem, SpriteItemValues) STA $0E80, X ; Store item type JSL.l PrepDynamicTile .skip PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; DrawMushroom: ;-------------------------------------------------------------------------------- !REDRAW = "$7F5000" ;-------------------------------------------------------------------------------- DrawMushroom: PHA : PHY LDA !REDRAW : BEQ .skipInit ; skip init if already ready JSL.l LoadMushroom_justGFX BRA .done ; don't draw on the init frame .skipInit LDA $0E80, X ; Retrieve stored item type JSL.l DrawDynamicTile .done PLY : PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; CollectPowder: ;-------------------------------------------------------------------------------- CollectPowder: LDY $0DA0, X ; Retrieve stored item type BNE + ; if for any reason the item value is 0 reload it, just in case %GetPossiblyEncryptedItem(WitchItem, SpriteItemValues) : TAY + PHA %GetPossiblyEncryptedPlayerID(WitchItem_Player) : STA !MULTIWORLD_ITEM_PLAYER_ID LDA.b #$01 : STA.l !SHOP_ENABLE_COUNT PLA STZ $02E9 ; item from NPC JSL.l Link_ReceiveItem PHA : LDA.b #$00 : STA.l !SHOP_ENABLE_COUNT : PLA ;JSL.l FullInventoryExternal JSL.l ItemSet_Powder RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; RemoveMushroom: ;-------------------------------------------------------------------------------- RemoveMushroom: LDA !INVENTORY_SWAP : AND #$DF : STA !INVENTORY_SWAP ; remove the mushroom AND #$10 : BEQ .empty ; check if we have powder LDA.b #$02 : STA $7EF344 ; give powder if we have it RTL .empty LDA.b #$00 : STA $7EF344 ; clear the inventory slot if we don't have powder RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; DrawMagicHeader: ;-------------------------------------------------------------------------------- DrawMagicHeader: LDA $7EF37B : AND.w #$00FF : CMP.w #$0002 : BEQ .quarterMagic .halfMagic LDA.w #$28F7 : STA $7EC704 LDA.w #$2851 : STA $7EC706 LDA.w #$28FA : STA $7EC708 RTL .quarterMagic LDA.w #$28F7 : STA $7EC704 LDA.w #$2800 : STA $7EC706 LDA.w #$2801 : STA $7EC708 RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; FixShovelLock: ;-------------------------------------------------------------------------------- ;FixShovelLock: ; LDA $037A : CMP #$01 : BEQ + ; skip if link is shoveling ; LDA $7EF34C ; load shovel/flute item ID ; + ; CMP #$00 ;RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; SpawnShovelGamePrizeSFX: ;-------------------------------------------------------------------------------- SpawnShovelGamePrizeSFX: STA $7FFE00 ; thing we wrote over PHA LDA.b #$1B : STA $012F ; play puzzle sound PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; SpawnChestGamePrizeSFX: ;-------------------------------------------------------------------------------- SpawnChestGamePrizeSFX: CPX.b #$07 : BNE .normal LDA $A0 : CMP.b #$06 : BNE .normal .prize LDA.b #$1B : STA $012F : RTL ; play puzzle sound .normal LDA.b #$0E : STA $012F ; play chest sound RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; SpawnShovelItem: ;-------------------------------------------------------------------------------- !REDRAW = "$7F5000" SpawnShovelItem: LDA.b #$01 : STA !REDRAW LDA $03FC : BEQ + JSL DiggingGameGuy_AttemptPrizeSpawn BRL .skip + LDA $035B : AND.b #$01 : BNE + : BRL .skip : + ; corner dig fix PHY : PHP PHB : PHK : PLB SEP #$30 ; set 8-bit accumulator and index registers LDA $1B : BEQ + : JMP .no_drop : + ; skip if indoors LDA $8A : CMP #$2A : BEQ .no_drop ; don't drop in the haunted grove CMP #$68 : BEQ .no_drop ; don't drop in the digging game area JSL GetRandomInt : BIT #$03 : BNE .no_drop ; drop with 1/4 chance LSR #2 : TAX ; clobber lower 2 bis - we have 64 slots now LDA.l ShovelSpawnTable, X ; look up the drop on the table ;most of this part below is copied from the digging game STA $7FFE00 JSL Sprite_SpawnDynamically LDX.b #$00 LDA $2F : CMP.b #$04 : BEQ + : INX : + LDA.l .x_speeds, X : STA $0D50, Y LDA.b #$00 : STA $0D40, Y LDA.b #$18 : STA $0F80, Y LDA.b #$FF : STA $0B58, Y LDA.b #$30 : STA $0F10, Y LDA $22 : !ADD.l .x_offsets, X AND.b #$F0 : STA $0D10, Y LDA $23 : ADC.b #$00 : STA $0D30, Y LDA $20 : !ADD.b #$16 : AND.b #$F0 : STA $0D00, Y LDA $21 : ADC.b #$00 : STA $0D20, Y LDA.b #$00 : STA $0F20, Y TYX LDA.b #$30 : JSL Sound_SetSfx3PanLong .no_drop PLB PLP : PLY .skip RTL ;DATA - Shovel Spawn Information { .x_speeds db $F0 db $10 .x_offsets db $00 db $13 } ;--------------------------------------------------------------------------------
; A117560: a(n) = n*(n^2 - 1)/2 - 1. ; 2,11,29,59,104,167,251,359,494,659,857,1091,1364,1679,2039,2447,2906,3419,3989,4619,5312,6071,6899,7799,8774,9827,10961,12179,13484,14879,16367,17951,19634,21419,23309,25307,27416,29639,31979,34439,37022,39731,42569,45539,48644,51887,55271,58799,62474,66299,70277,74411,78704,83159,87779,92567,97526,102659,107969,113459,119132,124991,131039,137279,143714,150347,157181,164219,171464,178919,186587,194471,202574,210899,219449,228227,237236,246479,255959,265679,275642,285851,296309,307019,317984 add $0,3 bin $0,3 mul $0,3 sub $0,1
/********************************************************************** * Copyright (c) 2008-2014, Alliance for Sustainable Energy. * All rights reserved. * * This library 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. * * This 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA **********************************************************************/ #ifndef ANALYSIS_FSUDACEALGORITHM_HPP #define ANALYSIS_FSUDACEALGORITHM_HPP #include "AnalysisAPI.hpp" #include "DakotaAlgorithm.hpp" namespace openstudio { namespace analysis { class FSUDaceAlgorithmOptions; namespace detail { class FSUDaceAlgorithm_Impl; } // detail /** FSUDaceAlgorithm is a DakotaAlgorithm that implements dakotaInFileDescription so as to * specify a particular Florida State University Design and Analysis of Computer Experiments * method and related options. Discrete variables are sampled by making them look continuous * to DAKOTA and then rounding the requested values. */ class ANALYSIS_API FSUDaceAlgorithm : public DakotaAlgorithm { public: /** @name Constructors and Destructors */ //@{ /** Construct from options. */ explicit FSUDaceAlgorithm(const FSUDaceAlgorithmOptions& options); /** Constructor provided for deserialization; not for general use. */ FSUDaceAlgorithm(const UUID& uuid, const UUID& versionUUID, const std::string& displayName, const std::string& description, bool complete, bool failed, int iter, const FSUDaceAlgorithmOptions& options, const boost::optional<FileReference>& restartFileReference, const boost::optional<FileReference>& outFileReference, const boost::optional<openstudio::runmanager::Job>& job); virtual ~FSUDaceAlgorithm() {} //@} /** @name Getters and Queries */ //@{ FSUDaceAlgorithmOptions fsudaceAlgorithmOptions() const; //@} protected: /// @cond typedef detail::FSUDaceAlgorithm_Impl ImplType; explicit FSUDaceAlgorithm(std::shared_ptr<detail::FSUDaceAlgorithm_Impl> impl); friend class detail::FSUDaceAlgorithm_Impl; friend class AnalysisObject; friend class detail::AnalysisObject_Impl; /// @endcond private: REGISTER_LOGGER("openstudio.analysis.FSUDaceAlgorithm"); }; /** \relates FSUDaceAlgorithm*/ typedef boost::optional<FSUDaceAlgorithm> OptionalFSUDaceAlgorithm; /** \relates FSUDaceAlgorithm*/ typedef std::vector<FSUDaceAlgorithm> FSUDaceAlgorithmVector; } // analysis } // openstudio #endif // ANALYSIS_FSUDACEALGORITHM_HPP
;;############################################################################# ;;! \file source/vector/add_SP_CSxCV.asm ;;! ;;! \brief C-Callable addition of a complex scalar from a complex vector ;;! \author David M. Alter ;;! \date 07/15/11 ;; ;; HISTORY: ;; 07/15/11 - original (D. Alter) ;; ;; DESCRIPTION: C-Callable addition of a complex scalar from a complex vector ;; y_re[i] = x_re[i] + c_re ;; y_im[i] = x_im[i] + c_im ;; ;; FUNCTION: ;; extern void add_SP_CSxCV(complex_float *y, const complex_float *x, const complex_float c, const Uint16 N) ;; ;; USAGE: add_SP_CVxCV(y, w, c, N); ;; ;; PARAMETERS: complex_float *y = result complex array ;; complex_float *x = input complex array ;; complex_float c = input complex scalar ;; Uint16 N = length of x and y arrays ;; ;; RETURNS: none ;; ;; BENCHMARK: 4*N + 18 cycles (including the call and return) ;; ;; NOTES: ;; 1) N must be at least 2. ;; 2) The inputs and return value are of type 'complex_float': ;; ;; typedef struct { ;; float32 dat[2]; ;; } complex_float; ;; ;; Group: C2000 ;; Target Family: C28x+FPU32 ;; ;;############################################################################# ;;$TI Release: C28x Floating Point Unit Library V1.50.00.00 $ ;;$Release Date: Oct 18, 2018 $ ;;$Copyright: Copyright (C) 2018 Texas Instruments Incorporated - ;; http://www.ti.com/ ALL RIGHTS RESERVED $ ;;############################################################################# .global _add_SP_CSxCV .text .word 0 ;needed for RPTB alignment _add_SP_CSxCV: MOVL XAR6, *-SP[4] ;XAR6 = &c MOV32 *SP++, R4H ;save R4H on stack ADDB AL, #-2 ;subtract 2 from N since RPTB is 'n-1' ;times and last iteration done separately MOV32 R2H, *XAR6++ ;R0H = c_re MOV32 R3H, *XAR6 ;R1H = c_im MOV32 R4H, *XAR5++ ;load first x_re[i] ;---Main loop RPTB end_loop, @AL ADDF32 R0H, R4H, R2H ;y_re[i] = x_re[i] + c_re || MOV32 R4H, *XAR5++ ;load next x_im[i] ADDF32 R1H, R4H, R3H ;y_im[i] = x_im[i] + c_im || MOV32 R4H, *XAR5++ ;load next x_re[i] MOV32 *XAR4++, R0H ;store y_re[i] MOV32 *XAR4++, R1H ;store y_im[i] end_loop: ;--- Last iteration done separately to avoid possible pointer overrun into ; undefined memory ADDF32 R0H, R4H, R2H ;y_re[i] = x_re[i] + c_re || MOV32 R4H, *XAR5 ;load next x_im[i] ADDF32 R1H, R4H, R3H ;y_im[i] = x_im[i] + c_im || MOV32 R4H, *--SP ;restore R4H from stack MOV32 *XAR4++, R0H ;store y_re[i] MOV32 *XAR4, R1H ;store y_im[i] ;Finish up LRETR ;return ;end of function _add_SP_CSxCV() ;********************************************************************* .end ;;############################################################################# ;; End of File ;;#############################################################################
; A170111: Number of reduced words of length n in Coxeter group on 6 generators S_i with relations (S_i)^2 = (S_i S_j)^38 = I. ; 1,6,30,150,750,3750,18750,93750,468750,2343750,11718750,58593750,292968750,1464843750,7324218750,36621093750,183105468750,915527343750,4577636718750,22888183593750,114440917968750,572204589843750 mov $1,5 pow $1,$0 mul $1,6 div $1,5
.constant_pool .const 0 string [start] .const 1 string [constructor] .const 2 string [var1] .const 3 string [Hello world !!!] .const 4 int [1] .const 5 string [io.writeln] .end .entity start .valid_context_when (always) .method constructor .var 0 string var1 ldconst 3 --> [Hello world !!!] stvar 0 --> [var1] ldvar 0 --> [var1] ldconst 4 --> [1] lcall 5 --> [io.writeln] exit .end .end
;_ faterr.asm ; Copyright (C) 1985-1994 Digital Mars ; All rights reserved. ; 32 bit fatal error exit ; $Revision: 1.1.1.2 $ include macros.asm extrn __Exit:near ifdef _WIN32 extrn __win32_faterr:near endif ifdef M_UNIX extrn _write:near endif ifdef __OS2__ extrn DosWrite:near endif ifdef M_UNIX begdata oneline db 0dh, 0ah, 0 onelineend equ $-oneline enddata endif begcode faterr ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Print out fatal message and terminate program. ; Input: ; PS[ESP] points to ASCIZ message public ___faterr ___faterr proc near ifdef M_UNIX push DS pop ES mov EDI,PS[ESP] ;ES:EDI -> string mov EDX,EDI clr EAX mov ECX,-1 repne scasb not ECX dec ECX push ECX ;Message length push EDX ;Message string push 2 ;stderr call _write add esp,12 push onelineend push offset DGROUP:oneline push 2 ;stderr call _write ;write an empty line add esp,12 else ifdef _WIN32 jmp __win32_faterr else ifdef __OS2__ ;Determine length of message in ECX push DS pop ES mov EDI,PS[ESP] ;ES:EDI -> string mov EDX,EDI clr EAX mov ECX,-1 repne scasb not ECX dec ECX push EBX ;space for return value mov EAX,ESP push EAX ;pointer to return value push ECX ;message length push EDX ;pointer to message push 2 ;stderr call DosWrite add ESP,4*4 else ;Get pointer to end of string push DS pop ES mov EDI,PS[ESP] ;ES:EDI -> string mov EDX,EDI clr EAX mov ECX,-1 repne scasb dec EDI mov byte ptr [EDI],'$' ;terminate string with $ bdos 9 endif endif endif ifndef _WIN32 push 1 ;error exit code call __Exit endif ___faterr endp endcode faterr end
;Running Ball ;Jackie Wu (Wu Kan) ;14348134 ;wkcn@live.cn ;totalDelay = outDelay * inDelay org 100H outDelay equ 40000 inDelay equ 1000 ;80 x 25 SCREEN_X equ 80 SCREEN_Y equ 25 ;Ball in this Rect MIN_X equ 40 MIN_Y equ 0 MAX_X equ 80 MAX_Y equ 13 ;set data segment ;mov ax,07c0h mov ax,cs mov ds,ax ;text window ;25 * 80 mov ax,0B800h mov es,ax %macro SINGLE 4 ;pos dw 0000h ;from 0,0 ;vel dw 0101h ;v = (1,1) ;char db '*' ;color db 07H mov ax, [%1] mov [pos], ax mov ax, [%2] mov [vel], ax mov al, [%3] mov [char], al mov al, [%4] mov [color], al call PLAY mov ax, [pos] mov [%1], ax mov ax, [vel] mov [%2], ax %endmacro START: call DELAY ;call PLAY SINGLE pos1,vel1,char1,color1 SINGLE pos2,vel2,char2,color2 ;SINGLE pos3,vel3,char3,color3 call SHOWNAME jmp START PLAY: call SETPOINTER call ELIMINATE call UPDATEPOS call SETPOINTER call SHOW ret SHOWNAME: mov cx,[msgLen] mov si,message mov di, (1*80 + 1) * 2 mov dl,[msgColor] printChar: mov al,[si] inc si and dl,0Fh mov ah,dl add dl,1 mov [es:di],ax add di,2 loop printChar inc byte[msgColor] ret DELAY: mov cx, outDelay LOOP1: mov ax, inDelay LOOP2: dec ax jg LOOP2 loop LOOP1 ret UPDATEPOS: ;parameter: pos, vel mov ax,[pos] mov bx,[vel] ;update x add ah,bh cmp ah,MIN_X ja XNZ ;if x <= MIN_X mov bh,1 XNZ: CMP ah,MAX_X-1 jb XNF ;if x >= MAX_X-1 mov bh,-1 XNF: ;update y add al,bl cmp al,MIN_Y ja YNZ ;if y <= MIN_Y mov bl,1 YNZ: CMP al,MAX_Y-1 jb YNF ;if y >= MAX_Y-1 mov bl,-1 YNF: mov [pos],ax mov [vel],bx ret SETPOINTER: ;parameter pos, char mov ax, 0 mov bx, [pos] ; bx = (x,y) mov al, bl mov cx, SCREEN_X mul cx ; ax *= SCREEN_X namely ax = y * SCREEN_X mov cx, 0 mov cl, bh add ax, cx ; ax += x mov cx, 2 mul cx mov bx, ax ret SHOW: ;new mov al, [char] mov ah, [color] mov [es:bx],ax ret ELIMINATE: ;clean mov ax, 0 mov [es:bx],ax ret DATA: message db "WuKan's Program 1" msgLen dw $-message msgColor db 00h outCount dw outDelay inCount dw inDelay pos dw 0000h ;from 0,0 vel dw 0101h ;v = (1,1) char db '*' color db 03H ;elements pos1 dw 0000h vel1 dw 0101h char1 db '*' color1 db 03H ;green pos2 dw 1003h vel2 dw 01FFh char2 db 'A' color2 db 0CFH ;twinkle red and light white pos3 dw 2019h vel3 dw 0FFFFh char3 db '@' color3 db 0EH ;yello times 510-($-$$) db 0 dw 0xaa55
//---------------------------------------------------------------------- // File: kd_split.cpp // Programmer: Sunil Arya and David Mount // Description: Methods for splitting kd-trees // Last modified: 01/04/05 (Version 1.0) //---------------------------------------------------------------------- // Copyright (c) 1997-2005 University of Maryland and Sunil Arya and // David Mount. All Rights Reserved. // // This software and related documentation is part of the Approximate // Nearest Neighbor Library (ANN). This software is provided under // the provisions of the Lesser GNU Public License (LGPL). See the // file ../ReadMe.txt for further information. // // The University of Maryland (U.M.) and the authors make no // representations about the suitability or fitness of this software for // any purpose. It is provided "as is" without express or implied // warranty. //---------------------------------------------------------------------- // History: // Revision 0.1 03/04/98 // Initial release // Revision 1.0 04/01/05 //---------------------------------------------------------------------- #include "kd_tree.h" // kd-tree definitions #include "kd_util.h" // kd-tree utilities #include "kd_split.h" // splitting functions //---------------------------------------------------------------------- // Constants //---------------------------------------------------------------------- const double ERR = 0.001; // a small value const double FS_ASPECT_RATIO = 2.5; // maximum allowed aspect ratio // in fair split. Must be >= 2. //---------------------------------------------------------------------- // kd_split - Bentley's standard splitting routine for kd-trees // Find the dimension of the greatest spread, and split // just before the median point along this dimension. //---------------------------------------------------------------------- void kd_split( ANNpointArray const& pa, // point array (permuted on return) ANNidxArray pidx, // point indices const ANNorthRect &/*bnds*/, // bounding rectangle for cell int n, // number of points int dim, // dimension of space int &cut_dim, // cutting dimension (returned) ANNcoord &cut_val, // cutting value (returned) int &n_lo) // num of points on low side (returned) { // find dimension of maximum spread cut_dim = annMaxSpread(pa, pidx, n, dim); n_lo = n/2; // median rank // split about median annMedianSplit(pa, pidx, n, cut_dim, cut_val, n_lo); } //---------------------------------------------------------------------- // midpt_split - midpoint splitting rule for box-decomposition trees // // This is the simplest splitting rule that guarantees boxes // of bounded aspect ratio. It simply cuts the box with the // longest side through its midpoint. If there are ties, it // selects the dimension with the maximum point spread. // // WARNING: This routine (while simple) doesn't seem to work // well in practice in high dimensions, because it tends to // generate a large number of trivial and/or unbalanced splits. // Either kd_split(), sl_midpt_split(), or fair_split() are // recommended, instead. //---------------------------------------------------------------------- void midpt_split( ANNpointArray const& pa, // point array ANNidxArray pidx, // point indices (permuted on return) const ANNorthRect &bnds, // bounding rectangle for cell int n, // number of points int dim, // dimension of space int &cut_dim, // cutting dimension (returned) ANNcoord &cut_val, // cutting value (returned) int &n_lo) // num of points on low side (returned) { int d; ANNcoord max_length = bnds.hi[0] - bnds.lo[0]; for (d = 1; d < dim; d++) { // find length of longest box side ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (length > max_length) { max_length = length; } } ANNcoord max_spread = -1; // find long side with most spread for (d = 0; d < dim; d++) { // is it among longest? if (double(bnds.hi[d] - bnds.lo[d]) >= (1-ERR)*max_length) { // compute its spread ANNcoord spr = annSpread(pa, pidx, n, d); if (spr > max_spread) { // is it max so far? max_spread = spr; cut_dim = d; } } } // split along cut_dim at midpoint cut_val = (bnds.lo[cut_dim] + bnds.hi[cut_dim]) / 2; // permute points accordingly int br1, br2; annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); //------------------------------------------------------------------ // On return: pa[0..br1-1] < cut_val // pa[br1..br2-1] == cut_val // pa[br2..n-1] > cut_val // // We can set n_lo to any value in the range [br1..br2]. // We choose split so that points are most evenly divided. //------------------------------------------------------------------ if (br1 > n/2) n_lo = br1; else if (br2 < n/2) n_lo = br2; else n_lo = n/2; } //---------------------------------------------------------------------- // sl_midpt_split - sliding midpoint splitting rule // // This is a modification of midpt_split, which has the nonsensical // name "sliding midpoint". The idea is that we try to use the // midpoint rule, by bisecting the longest side. If there are // ties, the dimension with the maximum spread is selected. If, // however, the midpoint split produces a trivial split (no points // on one side of the splitting plane) then we slide the splitting // (maintaining its orientation) until it produces a nontrivial // split. For example, if the splitting plane is along the x-axis, // and all the data points have x-coordinate less than the x-bisector, // then the split is taken along the maximum x-coordinate of the // data points. // // Intuitively, this rule cannot generate trivial splits, and // hence avoids midpt_split's tendency to produce trees with // a very large number of nodes. // //---------------------------------------------------------------------- void sl_midpt_split( ANNpointArray const& pa, // point array ANNidxArray pidx, // point indices (permuted on return) const ANNorthRect &bnds, // bounding rectangle for cell int n, // number of points int dim, // dimension of space int &cut_dim, // cutting dimension (returned) ANNcoord &cut_val, // cutting value (returned) int &n_lo) // num of points on low side (returned) { int d; ANNcoord max_length = bnds.hi[0] - bnds.lo[0]; for (d = 1; d < dim; d++) { // find length of longest box side ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (length > max_length) { max_length = length; } } ANNcoord max_spread = -1; // find long side with most spread for (d = 0; d < dim; d++) { // is it among longest? if ((bnds.hi[d] - bnds.lo[d]) >= (1-ERR)*max_length) { // compute its spread ANNcoord spr = annSpread(pa, pidx, n, d); if (spr > max_spread) { // is it max so far? max_spread = spr; cut_dim = d; } } } // ideal split at midpoint ANNcoord ideal_cut_val = (bnds.lo[cut_dim] + bnds.hi[cut_dim])/2; ANNcoord min, max; annMinMax(pa, pidx, n, cut_dim, min, max); // find min/max coordinates if (ideal_cut_val < min) // slide to min or max as needed cut_val = min; else if (ideal_cut_val > max) cut_val = max; else cut_val = ideal_cut_val; // permute points accordingly int br1, br2; annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); //------------------------------------------------------------------ // On return: pa[0..br1-1] < cut_val // pa[br1..br2-1] == cut_val // pa[br2..n-1] > cut_val // // We can set n_lo to any value in the range [br1..br2] to satisfy // the exit conditions of the procedure. // // if ideal_cut_val < min (implying br2 >= 1), // then we select n_lo = 1 (so there is one point on left) and // if ideal_cut_val > max (implying br1 <= n-1), // then we select n_lo = n-1 (so there is one point on right). // Otherwise, we select n_lo as close to n/2 as possible within // [br1..br2]. //------------------------------------------------------------------ if (ideal_cut_val < min) n_lo = 1; else if (ideal_cut_val > max) n_lo = n-1; else if (br1 > n/2) n_lo = br1; else if (br2 < n/2) n_lo = br2; else n_lo = n/2; } //---------------------------------------------------------------------- // fair_split - fair-split splitting rule // // This is a compromise between the kd-tree splitting rule (which // always splits data points at their median) and the midpoint // splitting rule (which always splits a box through its center. // The goal of this procedure is to achieve both nicely balanced // splits, and boxes of bounded aspect ratio. // // A constant FS_ASPECT_RATIO is defined. Given a box, those sides // which can be split so that the ratio of the longest to shortest // side does not exceed ASPECT_RATIO are identified. Among these // sides, we select the one in which the points have the largest // spread. We then split the points in a manner which most evenly // distributes the points on either side of the splitting plane, // subject to maintaining the bound on the ratio of long to short // sides. To determine that the aspect ratio will be preserved, // we determine the longest side (other than this side), and // determine how narrowly we can cut this side, without causing the // aspect ratio bound to be exceeded (small_piece). // // This procedure is more robust than either kd_split or midpt_split, // but is more complicated as well. When point distribution is // extremely skewed, this degenerates to midpt_split (actually // 1/3 point split), and when the points are most evenly distributed, // this degenerates to kd-split. //---------------------------------------------------------------------- void fair_split( ANNpointArray const& pa, // point array ANNidxArray pidx, // point indices (permuted on return) const ANNorthRect &bnds, // bounding rectangle for cell int n, // number of points int dim, // dimension of space int &cut_dim, // cutting dimension (returned) ANNcoord &cut_val, // cutting value (returned) int &n_lo) // num of points on low side (returned) { int d; ANNcoord max_length = bnds.hi[0] - bnds.lo[0]; cut_dim = 0; for (d = 1; d < dim; d++) { // find length of longest box side ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (length > max_length) { max_length = length; cut_dim = d; } } ANNcoord max_spread = 0; // find legal cut with max spread cut_dim = 0; for (d = 0; d < dim; d++) { ANNcoord length = bnds.hi[d] - bnds.lo[d]; // is this side midpoint splitable // without violating aspect ratio? if (((double) max_length)*2.0/((double) length) <= FS_ASPECT_RATIO) { // compute spread along this dim ANNcoord spr = annSpread(pa, pidx, n, d); if (spr > max_spread) { // best spread so far max_spread = spr; cut_dim = d; // this is dimension to cut } } } max_length = 0; // find longest side other than cut_dim for (d = 0; d < dim; d++) { ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (d != cut_dim && length > max_length) max_length = length; } // consider most extreme splits ANNcoord small_piece = max_length / FS_ASPECT_RATIO; ANNcoord lo_cut = bnds.lo[cut_dim] + small_piece;// lowest legal cut ANNcoord hi_cut = bnds.hi[cut_dim] - small_piece;// highest legal cut int br1, br2; // is median below lo_cut ? if (annSplitBalance(pa, pidx, n, cut_dim, lo_cut) >= 0) { cut_val = lo_cut; // cut at lo_cut annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = br1; } // is median above hi_cut? else if (annSplitBalance(pa, pidx, n, cut_dim, hi_cut) <= 0) { cut_val = hi_cut; // cut at hi_cut annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = br2; } else { // median cut preserves asp ratio n_lo = n/2; // split about median annMedianSplit(pa, pidx, n, cut_dim, cut_val, n_lo); } } //---------------------------------------------------------------------- // sl_fair_split - sliding fair split splitting rule // // Sliding fair split is a splitting rule that combines the // strengths of both fair split with sliding midpoint split. // Fair split tends to produce balanced splits when the points // are roughly uniformly distributed, but it can produce many // trivial splits when points are highly clustered. Sliding // midpoint never produces trivial splits, and shrinks boxes // nicely if points are highly clustered, but it may produce // rather unbalanced splits when points are unclustered but not // quite uniform. // // Sliding fair split is based on the theory that there are two // types of splits that are "good": balanced splits that produce // fat boxes, and unbalanced splits provided the cell with fewer // points is fat. // // This splitting rule operates by first computing the longest // side of the current bounding box. Then it asks which sides // could be split (at the midpoint) and still satisfy the aspect // ratio bound with respect to this side. Among these, it selects // the side with the largest spread (as fair split would). It // then considers the most extreme cuts that would be allowed by // the aspect ratio bound. This is done by dividing the longest // side of the box by the aspect ratio bound. If the median cut // lies between these extreme cuts, then we use the median cut. // If not, then consider the extreme cut that is closer to the // median. If all the points lie to one side of this cut, then // we slide the cut until it hits the first point. This may // violate the aspect ratio bound, but will never generate empty // cells. However the sibling of every such skinny cell is fat, // and hence packing arguments still apply. // //---------------------------------------------------------------------- void sl_fair_split( ANNpointArray const& pa, // point array ANNidxArray pidx, // point indices (permuted on return) const ANNorthRect &bnds, // bounding rectangle for cell int n, // number of points int dim, // dimension of space int &cut_dim, // cutting dimension (returned) ANNcoord &cut_val, // cutting value (returned) int &n_lo) // num of points on low side (returned) { int d; ANNcoord min, max; // min/max coordinates int br1, br2; // split break points ANNcoord max_length = bnds.hi[0] - bnds.lo[0]; cut_dim = 0; for (d = 1; d < dim; d++) { // find length of longest box side ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (length > max_length) { max_length = length; cut_dim = d; } } ANNcoord max_spread = 0; // find legal cut with max spread cut_dim = 0; for (d = 0; d < dim; d++) { ANNcoord length = bnds.hi[d] - bnds.lo[d]; // is this side midpoint splitable // without violating aspect ratio? if (((double) max_length)*2.0/((double) length) <= FS_ASPECT_RATIO) { // compute spread along this dim ANNcoord spr = annSpread(pa, pidx, n, d); if (spr > max_spread) { // best spread so far max_spread = spr; cut_dim = d; // this is dimension to cut } } } max_length = 0; // find longest side other than cut_dim for (d = 0; d < dim; d++) { ANNcoord length = bnds.hi[d] - bnds.lo[d]; if (d != cut_dim && length > max_length) max_length = length; } // consider most extreme splits ANNcoord small_piece = max_length / FS_ASPECT_RATIO; ANNcoord lo_cut = bnds.lo[cut_dim] + small_piece;// lowest legal cut ANNcoord hi_cut = bnds.hi[cut_dim] - small_piece;// highest legal cut // find min and max along cut_dim annMinMax(pa, pidx, n, cut_dim, min, max); // is median below lo_cut? if (annSplitBalance(pa, pidx, n, cut_dim, lo_cut) >= 0) { if (max > lo_cut) { // are any points above lo_cut? cut_val = lo_cut; // cut at lo_cut annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = br1; // balance if there are ties } else { // all points below lo_cut cut_val = max; // cut at max value annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = n-1; } } // is median above hi_cut? else if (annSplitBalance(pa, pidx, n, cut_dim, hi_cut) <= 0) { if (min < hi_cut) { // are any points below hi_cut? cut_val = hi_cut; // cut at hi_cut annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = br2; // balance if there are ties } else { // all points above hi_cut cut_val = min; // cut at min value annPlaneSplit(pa, pidx, n, cut_dim, cut_val, br1, br2); n_lo = 1; } } else { // median cut is good enough n_lo = n/2; // split about median annMedianSplit(pa, pidx, n, cut_dim, cut_val, n_lo); } }
org 0x100 bits 16 cpu 8086 COM1_BASE equ 0x3f8 COM1_THR equ COM1_BASE + 0 ; Transmitter Holding Buffer COM1_RBR equ COM1_BASE + 0 ; Receiver Buffer COM1_IER equ COM1_BASE + 1 ; Interrupt Enable Register COM1_FCR equ COM1_BASE + 2 ; FIFO Control Register COM1_IIR equ COM1_BASE + 2 ; Interrupt Identification Register COM1_LCR equ COM1_BASE + 3 ; Line Control Register COM1_LSR equ COM1_BASE + 5 ; Line Status Register COM1_DLL equ COM1_BASE + 0 ; Divisor Latch Low Byte COM1_DLH equ COM1_BASE + 1 ; Divisor Latch High Byte RECV_BUFFER_SIZE equ 100 ; As per Kermit documentation. SEND_BUFFER_SIZE equ 16 ; No packets sent from this program exceed this. PACKET_DATA_SIZE equ 94 ; Receive buffer size - 6 fields/terminator. section .text start: ; Set Baudrate on COM1 to 9600, divisor = 12: mov dx, COM1_LCR in al, dx or al, 0b10000000 ; Set Divisor Latch Access Bit (DLAB) out dx, al mov dx, COM1_DLL mov al, 0xc out dx, al mov dx, COM1_DLH mov al, 0 out dx, al mov dx, COM1_LCR in al, dx and al, 0b01111111 ; Reset Divisor Latch Access Bit (DLAB) out dx, al ; Disable and clear FIFO on COM1, to put it in 8250 compatibility mode: mov dx, COM1_FCR mov al, 0b00000110 ; Clear both FIFOs. out dx, al ; Set mode on COM1 to 8 data bits, no parity and 1 stop bit: mov dx, COM1_LCR mov al, 0b00000011 ; 8-N-1 out dx, al ; Enable interrupt bit on COM1: mov dx, COM1_IER in al, dx or al, 0b00000001 ; Enable Received Data Available Interrupt out dx, al ; Initialize sequence number: mov byte [send_seq_no], 0 ; Initialize retransmit message in send buffer: mov byte [send_buffer], 0x01 ; 'MARK' Start marker (Ctrl-A) mov byte [send_buffer + 1], 35 ; 'LEN' Packet length of 3 (+ 32) mov byte [send_buffer + 2], 32 ; 'SEQ' Sequence number 0 (+ 32) mov byte [send_buffer + 3], 'N' ; 'TYPE' Packet type 'N' meaning NAK mov byte [send_buffer + 4], 0x33 ; 'CHECK' Checksum 0x13 (+ 32) mov byte [send_buffer + 5], 0x13 ; Terminator (Carriage Return) mov word [send_buffer_index], 6 ; Get Send Initialization packet, exchange parameters... mov dx, message_waiting call print_string call get_valid_packet mov byte al, [packet_type] cmp al, 'S' ; 'S' = Send Initiation je _handle_s_packet ; Simplified version of error message: "<?> Packet in S State" mov byte [packet_data], al mov byte [packet_data + 1], 'S' mov byte [packet_type], 'E' ; 'E' = Error mov word [packet_data_len], 2 call send_packet jmp _main_end _handle_s_packet: ; Override local EOL marker from sender if available: mov byte al, [packet_data_len] cmp al, 4 jb _acknowledge_s_packet mov byte bl, [packet_data + 4] ; 'EOL' sub bl, 32 mov [eol_marker], bl ; Override local CTL marker from sender if available: cmp al, 5 jb _acknowledge_s_packet mov byte bl, [packet_data + 5] ; 'QCTL' mov [ctl_marker], bl _acknowledge_s_packet: mov byte [packet_type], 'Y' ; 'Y' = Acknowledgement (ACK) mov byte [packet_data], 72 ; 'MAXL' mov byte [packet_data + 1], 42 ; 'TIME' mov byte [packet_data + 2], 32 ; 'NPAD' mov byte [packet_data + 3], 64 ; 'PADC' mov byte [packet_data + 4], 45 ; 'EOL' = 0x0d (+ 32) mov byte [packet_data + 5], 35 ; 'QCTL' = '#' mov byte [packet_data + 6], 'N' ; 'QBIN' = 'N' = Will not do 8-bit quoting. mov byte [packet_data + 7], '1' ; 'CHKT' = '1' = Single character checksum. mov word [packet_data_len], 8 call send_packet _wait_for_file_header_packet: ; Get a File Header packet. If a B packet comes, we're all done: call get_valid_packet mov byte al, [packet_type] cmp al, 'B' ; 'B' = Break transmission je _handle_b_packet cmp al, 'F' ; 'F' = File Header je _handle_f_packet ; Simplified version of error message: "<?> Packet in F State" mov byte [packet_data], al mov byte [packet_data + 1], 'F' mov byte [packet_type], 'E' ; 'E' = Error mov word [packet_data_len], 2 call send_packet jmp _main_end _handle_b_packet: call send_acknowledgement_packet jmp _main_end _handle_f_packet: mov dx, message_receiving call print_string ; Dollar terminate the received filename: mov word di, [packet_data_len] mov byte [packet_data + di], '$' mov dx, packet_data call print_string ; Zero terminate the received filename: mov byte [packet_data + di], 0 ; Call DOS to create new file and handle. mov ah, 0x3c mov cx, 0 ; Standard attributes. ; DX already containing pointer to packet data. int 0x21 jc _handle_f_packet_error mov [file_handle], ax call send_acknowledgement_packet _wait_for_data_packet: ; Get Data packets. If a Z packet comes, the file is complete: call get_valid_packet mov byte al, [packet_type] cmp al, 'Z' ; 'Z' = End of file je _handle_z_packet cmp al, 'D' ; 'D' = Data Packet je _handle_d_packet ; Simplified version of error message: "<?> Packet in D State" mov byte [packet_data], al mov byte [packet_data + 1], 'D' mov byte [packet_type], 'E' ; 'E' = Error mov word [packet_data_len], 2 call send_packet jmp _main_end _handle_z_packet: ; Call DOS to close file handle. mov ah, 0x3e mov bx, [file_handle] int 0x21 call send_acknowledgement_packet mov dx, message_ok call print_string jmp _wait_for_file_header_packet _handle_d_packet: ; Call DOS to write to file. mov ah, 0x40 mov word bx, [file_handle] mov word cx, [packet_data_len] mov dx, packet_data int 0x21 jc _handle_d_packet_error call send_acknowledgement_packet jmp _wait_for_data_packet _handle_f_packet_error: ; Send error code 'C', since new file could not be created. mov byte [packet_data], 'C' mov byte [packet_type], 'E' ; 'E' = Error mov word [packet_data_len], 1 call send_packet jmp _main_end _handle_d_packet_error: ; Send error code 'W', since new file could not be written to. mov byte [packet_data], 'W' mov byte [packet_type], 'E' ; 'E' = Error mov word [packet_data_len], 1 call send_packet jmp _main_end _main_end: mov dx, message_done call print_string ; Disable interrupt bit on COM1: mov dx, COM1_IER in al, dx and al, 0b11111110 ; Disable Received Data Available Interrupt out dx, al ; Exit to DOS. mov ah, 0x4c int 0x21 ; PROCEDURE: get_valid_packet ; ; INPUT: ; N/A ; ; OUTPUT: ; ds:[packet_type] ; ds:[packet_data] ; ds:[packet_data_len] ; get_valid_packet: push ax push bx push cx ; Try to get a valid packet with the desired sequence number. mov cx, 5 ; Retry maximum 5 times. _get_valid_packet_loop: call recv_packet mov byte al, [recv_seq_no] mov byte bl, [send_seq_no] cmp al, bl jne _get_valid_packet_resend mov byte al, [packet_type] cmp al, 'Q' ; 'Q' = Block check error je _get_valid_packet_resend jmp _get_valid_packet_return ; Got a valid packet. _get_valid_packet_resend: call com_port_send ; Contains a retransmit message in send buffer already. push dx mov dl, '%' ; Indicate retry. call print_character pop dx loop _get_valid_packet_loop ; Until CX = 0 mov byte [packet_type], 'T' ; 'T' = Timeout _get_valid_packet_return: pop cx pop bx pop ax ret ; PROCEDURE: send_acknowledgement_packet ; ; INPUT: ; N/A ; ; OUTPUT: ; N/A ; send_acknowledgement_packet: mov byte [packet_type], 'Y' ; 'Y' = Acknowledgement (ACK) mov word [packet_data_len], 0 call send_packet ret ; PROCEDURE: send_packet ; ; INPUT: ; ds:[packet_type] ; ds:[packet_data] ; ds:[packet_data_len] ; ; OUTPUT: ; N/A ; send_packet: push ax push bx push cx push di push si mov di, send_buffer mov byte [di], 0x01 inc di mov word ax, [packet_data_len] add al, 35 ; 32 + 3 bytes for 'SEQ', 'TYPE' & 'CHECK' mov bl, al ; Checksum = LEN mov byte [di], al inc di mov byte al, [send_seq_no] add al, 32 add bl, al ; Checksum += SEQ mov byte [di], al inc di mov byte al, [packet_type] add bl, al ; Checksum += TYPE mov byte [di], al inc di mov si, packet_data mov word cx, [packet_data_len] test cx, cx jz _send_packet_empty _send_packet_loop: mov al, [si] mov [di], al add bl, al ; Checksum += DATA inc di inc si loop _send_packet_loop ; Until CX = 0 _send_packet_empty: ; Calculate checksum: mov cl, bl and cl, 192 shr cl, 1 ; 8086 is limited to one shift at a time. shr cl, 1 shr cl, 1 shr cl, 1 shr cl, 1 shr cl, 1 add cl, bl and cl, 63 add cl, 32 mov byte [di], cl inc di mov byte al, [eol_marker] mov byte [di], al mov word ax, [packet_data_len] add ax, 6 ; Add 'MARK', 'LEN', 'SEQ', 'TYPE' 'CHECK' and terminator. mov word [send_buffer_index], ax call com_port_send ; Increment packet sequence number: inc byte [send_seq_no] and byte [send_seq_no], 63 ; Always reduce to 6 bits. push dx mov dl, '.'; Indicate ACK sent. call print_character pop dx pop si pop di pop cx pop bx pop ax ret ; PROCEDURE: com_port_send ; ; INPUT: ; ds:[send_buffer] ; ds:[send_buffer_index] ; ; OUTPUT: ; N/A ; com_port_send: push ax push cx push dx push si mov si, 0 mov word cx, [send_buffer_index] _com_port_send_byte: mov dx, COM1_THR mov byte al, [send_buffer + si] out dx, al mov dx, COM1_LSR _com_port_send_wait: in al, dx and al, 0b00100000 ; Empty Transmit Holding Register test al, al jz _com_port_send_wait ; Busy wait... inc si loop _com_port_send_byte ; Until CX = 0 pop si pop dx pop cx pop ax ret ; PROCEDURE: recv_packet ; ; INPUT: ; N/A ; ; OUTPUT: ; ds:[packet_type] ; ds:[packet_data] ; ds:[packet_data_len] ; ds:[recv_seq_no] ; recv_packet: push ax push bx push cx push dx push di push si call com_port_recv ; Look for 'MARK' start marker 0x01 (Ctrl-A) in buffer: mov si, -1 _recv_packet_look_for_marker: inc si mov ax, [recv_buffer_index] cmp si, ax jge _recv_packet_fail ; Reached end of buffer. mov byte al, [recv_buffer + si] cmp al, 0x01 ; (Ctrl-A) jne _recv_packet_look_for_marker ; Start position now in SI register. ; Copy initial packet fields: ; * Using AL for data. ; * Using BL for checksum. ; * Using CX for packet length. inc si xor cx, cx mov byte cl, [recv_buffer + si] ; Packet 'LEN' field. mov bl, cl ; Checksum = LEN sub cx, 35 ; 32 + 3 bytes for 'SEQ', 'TYPE' & 'CHECK' inc si mov byte al, [recv_buffer + si] ; Packet 'SEQ' field. add bl, al ; Checksum += SEQ sub al, 32 mov byte [recv_seq_no], al inc si mov byte al, [recv_buffer + si] ; Packet 'TYPE' field. add bl, al ; Checksum += TYPE mov byte [packet_type], al inc si ; Packet length now in CX register. ; Checksum now in BL register. ; Start of data position now in SI register. mov word [packet_data_len], cx test cx, cx jz _recv_packet_checksum ; Zero size packet, skip decoding/copying. ; Copy packet data: ; * Using AL for data. ; * Using BL for checksum. ; * Using CX for packet length. ; * Using DL for comparisons and temporary storage. ; * Using DH for decode flag. xor dh, dh mov di, packet_data _recv_packet_copy: mov byte al, [recv_buffer + si] ; Packet 'DATA' field. add bl, al ; Checksum += DATA mov byte dl, [packet_type] cmp dl, 'S' ; 'S' = Send Initiation jne _recv_packet_decode ; Type 'S' packets shall not be decoded! mov [di], al ; Copy un-decoded. jmp _recv_packet_increment _recv_packet_decode: cmp dh, 0 jne _recv_packet_decode_flag_not_set_1 mov byte dl, [ctl_marker] cmp dl, al jne _recv_packet_decode_flag_not_set_1 mov dh, 1 dec byte [packet_data_len] ; Decoding reduces resulting packet size. jmp _recv_packet_increment_source_only _recv_packet_decode_flag_not_set_1: cmp dh, 1 jne _recv_packet_decode_flag_not_set_2 xor dh, dh mov dl, al and dl, 127 cmp dl, 62 jng _recv_packet_decode_flag_not_set_2 cmp dl, 96 jg _recv_packet_decode_flag_not_set_2 xor al, 64 _recv_packet_decode_flag_not_set_2: mov [di], al _recv_packet_increment: inc di _recv_packet_increment_source_only: inc si loop _recv_packet_copy ; Until CX = 0 _recv_packet_checksum: ; Calculate and check checksum: mov dl, bl and dl, 192 shr dl, 1 ; 8086 is limited to one shift at a time. shr dl, 1 shr dl, 1 shr dl, 1 shr dl, 1 shr dl, 1 add dl, bl and dl, 63 mov byte al, [recv_buffer + si] ; Packet 'CHECK' field. sub al, 32 cmp al, dl jne _recv_packet_fail ; All OK! jmp _recv_packet_ok _recv_packet_fail: mov byte [packet_type], 'Q' ; 'Q' = Block check error _recv_packet_ok: pop si pop di pop dx pop cx pop bx pop ax ret ; PROCEDURE: com_port_recv ; ; INPUT: ; N/A ; ; OUTPUT: ; ds:[recv_buffer] ; ds:[recv_buffer_index] ; com_port_recv: push ax push dx push di mov di, 0 _com_port_recv_byte: mov dx, COM1_IIR _com_port_recv_wait: in al, dx and al, 0b00001110 ; Identification cmp al, 0b00000100 ; Enable Received Data Available Interrupt jne _com_port_recv_wait ; Busy wait... mov dx, COM1_RBR in al, dx cmp di, RECV_BUFFER_SIZE jb _com_port_recv_copy mov di, 0 ; Reset and wrap to prevent overflow. _com_port_recv_copy: mov byte [recv_buffer + di], al inc di ; Keep reading until a terminator 0x0d (Carriage Return) arrives: cmp al, 0x0d jne _com_port_recv_byte mov word [recv_buffer_index], di pop di pop dx pop ax ret ; PROCEDURE: print_character ; ; INPUT: ; dl ; ; OUTPUT: ; N/A ; print_character: push ax push dx ; Call DOS to display character: mov ah, 0x2 ; DL set by caller... int 0x21 pop dx pop ax ret ; PROCEDURE: print_string ; ; INPUT: ; dx ; ; OUTPUT: ; N/A ; print_string: push ax ; Call DOS to display string: mov ah, 0x9 ; DS is already same as CS, no need to change. ; DX set by caller... int 0x21 pop ax ret section .data: recv_buffer_index: dw 0 ; 16-bit word due to SI/DI registers. recv_buffer: times RECV_BUFFER_SIZE db 0 send_buffer_index: dw 0 ; 16-bit word due to SI/DI registers. send_buffer: times SEND_BUFFER_SIZE db 0 send_seq_no: db 0 recv_seq_no: db 0 packet_type: db 0 packet_data_len: dw 0 ; 16-bit word due to SI/DI registers. packet_data: times PACKET_DATA_SIZE db 0 ctl_marker: db '#' ; Default eol_marker: db 0x0d ; Default file_handle: dw 0 message_waiting: db "Waiting...", 0x0d, 0x0a, "$" message_receiving: db "Receiving: $" message_ok: db "(OK)", 0x0d, 0x0a, "$" message_done: db "(DONE)", 0x0d, 0x0a, "$"
; ; ; ZX Maths Routines ; ; 21/03/03 - Stefano Bodrato ; ; $Id: sinh.asm,v 1.3 2015/01/19 01:32:57 pauloscustodio Exp $ ; ;double sinh(double) ; e = exp(x) ; ; return ((e-1.0/e)/2) ; IF FORzx INCLUDE "zxfp.def" ELSE INCLUDE "81fp.def" ENDIF PUBLIC sinh EXTERN fsetup1 EXTERN stkequ .sinh call fsetup1 defb ZXFP_EXP ; and at the beginning exp (x) defb ZXFP_DUPLICATE defb ZXFP_STK_ONE defb ZXFP_EXCHANGE defb ZXFP_DIVISION ; 1/e defb ZXFP_SUBTRACT defb ZXFP_STK_ONE ; STK_TWO :o) defb ZXFP_STK_ONE defb ZXFP_ADDITION defb ZXFP_DIVISION defb ZXFP_END_CALC jp stkequ
; A284723: Smallest odd prime that is relatively prime to n. ; 3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3,3,5,3,3,7,3,3,5,3,3,5,3,3,5,3 add $0,1 mov $1,1 lpb $0 add $1,2 dif $0,$1 lpe add $1,2 mov $0,$1
#include "Arduino.h" #include "test.h" #define DEBUG #ifdef DEBUG #include "avr8-stub.h" #include "app_api.h" // only needed with flash breakpoints #endif Test *test; int a; void setup() { #ifdef DEBUG debug_init(); #endif test = new Test(); // initialize LED digital pin as an output. pinMode(LED_BUILTIN, OUTPUT); } void loop() { // turn the LED on (HIGH is the voltage level) digitalWrite(LED_BUILTIN, HIGH); // wait for a second delay(300); // turn the LED off by making the voltage LOW digitalWrite(LED_BUILTIN, LOW); // wait for a second delay(300); a = test->add(a, 1); }
SECTION code_fp_am9511 PUBLIC cam32_sdcc_fabs EXTERN cam32_sdcc_read1, asm_am9511_fabs_fastcall .cam32_sdcc_fabs call cam32_sdcc_read1 jp asm_am9511_fabs_fastcall
// How many Fibs? // Created by Kim Jong-uk at 2017.02.09 // Protected by MIT license #include <stdio.h> #include <string.h> #define MAXIMUM_STRING_LENGTH 100 char Fib[3][MAXIMUM_STRING_LENGTH + 1]; char Result[2][MAXIMUM_STRING_LENGTH + 1]; int lengthA, lengthB, fibLength[3]; int compare(int targetA,char *point, int len) { int i; if (len > fibLength[targetA]) return 0; if (len < fibLength[targetA]); return 1; for (i = len - 1; i >= 0; i--) if (point[i] > Fib[targetA][i]) return 0; else return 1; } void Fibs(int destiny, int second, int first) { int i,len = 0, carry = 0; for (; len < fibLength[second] && len < fibLength[first]; len++) { Fib[destiny][len] = (Fib[second][len] + Fib[first][len] + carry); if (Fib[destiny][len] >= 10) carry = 1; else carry = 0; Fib[destiny][len] %= 10; } if (len < fibLength[second]) { for (; len < fibLength[second] ; len++) { Fib[destiny][len] = (Fib[second][len] + carry); if (Fib[destiny][len] >= 10) carry = 1; else carry = 0; Fib[destiny][len] %= 10; } } else { for (; len < fibLength[first]; len++) { Fib[destiny][len] = (Fib[first][len] + carry); if (Fib[destiny][len] >= 10) carry = 1; else carry = 0; Fib[destiny][len] %= 10; } } if (carry) Fib[destiny][len++] = 1; fibLength[destiny] = len; } int input() { int i; char temp1[MAXIMUM_STRING_LENGTH + 1], temp2[MAXIMUM_STRING_LENGTH + 1]; scanf("%s %s", &temp1, &temp2); lengthA = strlen(temp1); lengthB = strlen(temp2); if (temp1[0] == '0' && temp2[0] == '0') return 0; for (i = 0; i < lengthA; i++) Result[0][i] = Result[0][lengthA - 1 - i]- '0'; for (i = 0; i < lengthA; i++) Result[1][i] = Result[1][lengthA - 1 - i]- '0'; return 1; } int main() { while (input()) { int i, result; fibLength[0] = fibLength[1] = 1; Fib[0][0] = Fib[1][0] = 1; for (i = 0; compare(i % 3, Result[0], lengthA) == 0; i++) Fibs((i + 1) % 3, i % 3, (i - 1) % 3); result = i; for (i = 0; compare(i % 3, Result[1], lengthA) == 0; i++) Fibs((i + 1) % 3, i % 3, (i - 1) % 3); result = result - i; printf("%d", result);; } return 0; }
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # 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. ############################################################################### .text p256r1_data: _prime256r1: .long 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0, 0x0, 0x0, 0x1, 0xFFFFFFFF .p2align 5, 0x90 _h9_add_256: movl (%esi), %eax addl (%ebx), %eax movl %eax, (%edi) movl (4)(%esi), %eax adcl (4)(%ebx), %eax movl %eax, (4)(%edi) movl (8)(%esi), %eax adcl (8)(%ebx), %eax movl %eax, (8)(%edi) movl (12)(%esi), %eax adcl (12)(%ebx), %eax movl %eax, (12)(%edi) movl (16)(%esi), %eax adcl (16)(%ebx), %eax movl %eax, (16)(%edi) movl (20)(%esi), %eax adcl (20)(%ebx), %eax movl %eax, (20)(%edi) movl (24)(%esi), %eax adcl (24)(%ebx), %eax movl %eax, (24)(%edi) movl (28)(%esi), %eax adcl (28)(%ebx), %eax movl %eax, (28)(%edi) mov $(0), %eax adc $(0), %eax ret .p2align 5, 0x90 _h9_sub_256: movl (%esi), %eax subl (%ebx), %eax movl %eax, (%edi) movl (4)(%esi), %eax sbbl (4)(%ebx), %eax movl %eax, (4)(%edi) movl (8)(%esi), %eax sbbl (8)(%ebx), %eax movl %eax, (8)(%edi) movl (12)(%esi), %eax sbbl (12)(%ebx), %eax movl %eax, (12)(%edi) movl (16)(%esi), %eax sbbl (16)(%ebx), %eax movl %eax, (16)(%edi) movl (20)(%esi), %eax sbbl (20)(%ebx), %eax movl %eax, (20)(%edi) movl (24)(%esi), %eax sbbl (24)(%ebx), %eax movl %eax, (24)(%edi) movl (28)(%esi), %eax sbbl (28)(%ebx), %eax movl %eax, (28)(%edi) mov $(0), %eax adc $(0), %eax ret .p2align 5, 0x90 _h9_shl_256: movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movl (28)(%esi), %eax movdqa %xmm0, %xmm2 psllq $(1), %xmm0 psrlq $(63), %xmm2 movdqa %xmm1, %xmm3 psllq $(1), %xmm1 psrlq $(63), %xmm3 palignr $(8), %xmm2, %xmm3 pslldq $(8), %xmm2 por %xmm3, %xmm1 por %xmm2, %xmm0 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) shr $(31), %eax ret .p2align 5, 0x90 _h9_shr_256: movd %eax, %xmm4 movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 psllq $(63), %xmm4 movdqa %xmm0, %xmm2 psrlq $(1), %xmm0 psllq $(63), %xmm2 movdqa %xmm1, %xmm3 psrlq $(1), %xmm1 psllq $(63), %xmm3 palignr $(8), %xmm3, %xmm4 palignr $(8), %xmm2, %xmm3 por %xmm4, %xmm1 por %xmm3, %xmm0 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) ret .p2align 5, 0x90 .globl _h9_p256r1_add _h9_p256r1_add: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(36), %esp and $(-16), %esp movl %eax, (32)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebx call _h9_add_256 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi call .L__0000gas_5 .L__0000gas_5: pop %ebx sub $(.L__0000gas_5-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_sub_256 lea (%esp), %esi movl (8)(%ebp), %edi sub %eax, %edx cmovne %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (32)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_sub _h9_p256r1_sub: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(36), %esp and $(-16), %esp movl %eax, (32)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebx call _h9_sub_256 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi call .L__0001gas_6 .L__0001gas_6: pop %ebx sub $(.L__0001gas_6-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_add_256 lea (%esp), %esi movl (8)(%ebp), %edi test %edx, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (32)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_neg _h9_p256r1_neg: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(36), %esp and $(-16), %esp movl %eax, (32)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi mov $(0), %eax subl (%esi), %eax movl %eax, (%edi) mov $(0), %eax sbbl (4)(%esi), %eax movl %eax, (4)(%edi) mov $(0), %eax sbbl (8)(%esi), %eax movl %eax, (8)(%edi) mov $(0), %eax sbbl (12)(%esi), %eax movl %eax, (12)(%edi) mov $(0), %eax sbbl (16)(%esi), %eax movl %eax, (16)(%edi) mov $(0), %eax sbbl (20)(%esi), %eax movl %eax, (20)(%edi) mov $(0), %eax sbbl (24)(%esi), %eax movl %eax, (24)(%edi) mov $(0), %eax sbbl (28)(%esi), %eax movl %eax, (28)(%edi) sbb %edx, %edx lea (%esp), %edi movl (8)(%ebp), %esi call .L__0002gas_7 .L__0002gas_7: pop %ebx sub $(.L__0002gas_7-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_add_256 lea (%esp), %esi movl (8)(%ebp), %edi test %edx, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (32)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_mul_by_2 _h9_p256r1_mul_by_2: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(36), %esp and $(-16), %esp movl %eax, (32)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call _h9_shl_256 mov %eax, %edx mov %edi, %esi movl (8)(%ebp), %edi call .L__0003gas_8 .L__0003gas_8: pop %ebx sub $(.L__0003gas_8-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_sub_256 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (32)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_mul_by_3 _h9_p256r1_mul_by_3: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(72), %esp and $(-16), %esp movl %eax, (68)(%esp) call .L__0004gas_9 .L__0004gas_9: pop %eax sub $(.L__0004gas_9-p256r1_data), %eax lea ((_prime256r1-p256r1_data))(%eax), %eax movl %eax, (64)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call _h9_shl_256 mov %eax, %edx mov %edi, %esi lea (32)(%esp), %edi mov (64)(%esp), %ebx call _h9_sub_256 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov %edi, %esi movl (12)(%ebp), %ebx call _h9_add_256 mov %eax, %edx movl (8)(%ebp), %edi mov (64)(%esp), %ebx call _h9_sub_256 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (68)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_div_by_2 _h9_p256r1_div_by_2: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(36), %esp and $(-16), %esp movl %eax, (32)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call .L__0005gas_10 .L__0005gas_10: pop %ebx sub $(.L__0005gas_10-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_add_256 mov $(0), %edx movl (%esi), %ecx and $(1), %ecx cmovne %edi, %esi cmove %edx, %eax movl (8)(%ebp), %edi call _h9_shr_256 mov (32)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_mul_mont_slm _h9_p256r1_mul_mont_slm: push %ebp mov %esp, %ebp push %ebx push %esi push %edi push %ebp mov %esp, %eax sub $(52), %esp and $(-16), %esp movl %eax, (48)(%esp) pxor %mm0, %mm0 movq %mm0, (%esp) movq %mm0, (8)(%esp) movq %mm0, (16)(%esp) movq %mm0, (24)(%esp) movd %mm0, (32)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebp movl %edi, (36)(%esp) movl %esi, (40)(%esp) movl %ebp, (44)(%esp) mov $(8), %edi movd (4)(%esi), %mm1 movd (8)(%esi), %mm2 movd (12)(%esi), %mm3 movd (16)(%esi), %mm4 .p2align 5, 0x90 .Lmmul_loopgas_11: movd %edi, %mm7 movl (%ebp), %edx movl (%esi), %eax movd %edx, %mm0 add $(4), %ebp movl %ebp, (44)(%esp) pmuludq %mm0, %mm1 pmuludq %mm0, %mm2 mul %edx addl (%esp), %eax adc $(0), %edx pmuludq %mm0, %mm3 pmuludq %mm0, %mm4 movd %mm1, %ecx psrlq $(32), %mm1 add %edx, %ecx movd %mm1, %edx adc $(0), %edx addl (4)(%esp), %ecx movd (20)(%esi), %mm1 adc $(0), %edx movd %mm2, %ebx psrlq $(32), %mm2 add %edx, %ebx movd %mm2, %edx adc $(0), %edx addl (8)(%esp), %ebx movd (24)(%esi), %mm2 adc $(0), %edx pmuludq %mm0, %mm1 pmuludq %mm0, %mm2 movd %mm3, %ebp psrlq $(32), %mm3 add %edx, %ebp movd %mm3, %edx adc $(0), %edx addl (12)(%esp), %ebp movd (28)(%esi), %mm3 adc $(0), %edx movd %mm4, %edi psrlq $(32), %mm4 add %edx, %edi movd %mm4, %edx adc $(0), %edx addl (16)(%esp), %edi adc $(0), %edx pmuludq %mm0, %mm3 movl %ecx, (%esp) movl %ebx, (4)(%esp) add %eax, %ebp movl %ebp, (8)(%esp) adc $(0), %edi movl %edi, (12)(%esp) mov $(0), %edi adc $(0), %edi movd %mm1, %ecx psrlq $(32), %mm1 add %edx, %ecx movd %mm1, %edx adc $(0), %edx addl (20)(%esp), %ecx adc $(0), %edx movd %mm2, %ebx psrlq $(32), %mm2 add %edx, %ebx movd %mm2, %edx adc $(0), %edx addl (24)(%esp), %ebx adc $(0), %edx movd %mm3, %ebp psrlq $(32), %mm3 add %edx, %ebp movd %mm3, %edx adc $(0), %edx addl (28)(%esp), %ebp adc $(0), %edx add %edi, %ecx movl %ecx, (16)(%esp) adc %eax, %ebx movl %ebx, (20)(%esp) mov %eax, %ecx sbb $(0), %eax sub %eax, %ebp movl %ebp, (24)(%esp) movd %mm7, %edi sbb $(0), %ecx mov $(0), %ebx addl (32)(%esp), %edx adc $(0), %ebx add %ecx, %edx movl %edx, (28)(%esp) adc $(0), %ebx movl %ebx, (32)(%esp) sub $(1), %edi movd (4)(%esi), %mm1 movd (8)(%esi), %mm2 movd (12)(%esi), %mm3 movd (16)(%esi), %mm4 jz .Lexit_mmul_loopgas_11 movl (44)(%esp), %ebp jmp .Lmmul_loopgas_11 .Lexit_mmul_loopgas_11: emms mov (36)(%esp), %edi lea (%esp), %esi call .L__0006gas_11 .L__0006gas_11: pop %ebx sub $(.L__0006gas_11-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_sub_256 movl (32)(%esp), %edx sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) mov (48)(%esp), %esp pop %ebp pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_sqr_mont_slm _h9_p256r1_sqr_mont_slm: push %ebp mov %esp, %ebp push %esi push %edi movl (12)(%ebp), %esi movl (8)(%ebp), %edi push %esi push %esi push %edi call _h9_p256r1_mul_mont_slm add $(12), %esp pop %edi pop %esi pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_mred _h9_p256r1_mred: push %ebp mov %esp, %ebp push %ebx push %esi push %edi movl (12)(%ebp), %esi mov $(8), %ecx xor %edx, %edx .p2align 5, 0x90 .Lmred_loopgas_13: movl (%esi), %eax mov $(0), %ebx movl %ebx, (%esi) movl (12)(%esi), %ebx add %eax, %ebx movl %ebx, (12)(%esi) movl (16)(%esi), %ebx adc $(0), %ebx movl %ebx, (16)(%esi) movl (20)(%esi), %ebx adc $(0), %ebx movl %ebx, (20)(%esi) movl (24)(%esi), %ebx adc %eax, %ebx movl %ebx, (24)(%esi) movl (28)(%esi), %ebx push %eax sbb $(0), %eax sub %eax, %ebx movl %ebx, (28)(%esi) pop %eax movl (32)(%esi), %ebx sbb $(0), %eax add %edx, %eax mov $(0), %edx adc $(0), %edx add %eax, %ebx movl %ebx, (32)(%esi) adc $(0), %edx lea (4)(%esi), %esi sub $(1), %ecx jnz .Lmred_loopgas_13 movl (8)(%ebp), %edi call .L__0007gas_13 .L__0007gas_13: pop %ebx sub $(.L__0007gas_13-p256r1_data), %ebx lea ((_prime256r1-p256r1_data))(%ebx), %ebx call _h9_sub_256 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) pop %edi pop %esi pop %ebx pop %ebp ret .p2align 5, 0x90 .globl _h9_p256r1_select_pp_w5 _h9_p256r1_select_pp_w5: push %ebp mov %esp, %ebp push %esi push %edi pxor %xmm0, %xmm0 movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %eax movd %eax, %xmm7 pshufd $(0), %xmm7, %xmm7 mov $(1), %edx movd %edx, %xmm6 pshufd $(0), %xmm6, %xmm6 movdqa %xmm0, (%edi) movdqa %xmm0, (16)(%edi) movdqa %xmm0, (32)(%edi) movdqa %xmm0, (48)(%edi) movdqa %xmm0, (64)(%edi) movdqa %xmm0, (80)(%edi) movdqa %xmm6, %xmm5 mov $(16), %ecx .p2align 5, 0x90 .Lselect_loopgas_14: movdqa %xmm5, %xmm4 pcmpeqd %xmm7, %xmm4 movdqa (%esi), %xmm0 pand %xmm4, %xmm0 por (%edi), %xmm0 movdqa %xmm0, (%edi) movdqa (16)(%esi), %xmm1 pand %xmm4, %xmm1 por (16)(%edi), %xmm1 movdqa %xmm1, (16)(%edi) movdqa (32)(%esi), %xmm0 pand %xmm4, %xmm0 por (32)(%edi), %xmm0 movdqa %xmm0, (32)(%edi) movdqa (48)(%esi), %xmm1 pand %xmm4, %xmm1 por (48)(%edi), %xmm1 movdqa %xmm1, (48)(%edi) movdqa (64)(%esi), %xmm0 pand %xmm4, %xmm0 por (64)(%edi), %xmm0 movdqa %xmm0, (64)(%edi) movdqa (80)(%esi), %xmm1 pand %xmm4, %xmm1 por (80)(%edi), %xmm1 movdqa %xmm1, (80)(%edi) paddd %xmm6, %xmm5 add $(96), %esi sub $(1), %ecx jnz .Lselect_loopgas_14 pop %edi pop %esi pop %ebp ret
global read_eip read_eip: pop eax jmp eax global copy_page_physical copy_page_physical: push ebx pushf cli mov ebx, [esp+12] mov ecx, [esp+16] mov edx, cr0 and edx, 0x7fffffff mov cr0, edx mov edx, 1024 .loop: mov eax, [ebx] mov [ecx], eax add ebx, 4 add ecx, 4 dec edx jnz .loop mov edx, cr0 or edx, 0x80000000 mov cr0, edx popf pop ebx ret
;/* ************************************************************************* ;** INTEL Corporation Proprietary Information ;** ;** This listing is supplied under the terms of a license ;** agreement with INTEL Corporation and may not be copied ;** nor disclosed except in accordance with the terms of ;** that agreement. ;** ;** Copyright (c) 1995 Intel Corporation. ;** All Rights Reserved. ;** ;** ************************************************************************* ;*/ ;//////////////////////////////////////////////////////////////////////////// ;// ;// $Header: R:\h26x\h26x\src\enc\ex5me.asv 1.17 24 Sep 1996 11:27:00 BNICKERS $ ;// ;// $Log: R:\h26x\h26x\src\enc\ex5me.asv $ ;// ;// Rev 1.17 24 Sep 1996 11:27:00 BNICKERS ;// ;// Fix register colision. ;// ;// Rev 1.16 24 Sep 1996 10:40:32 BNICKERS ;// For H261, zero out motion vectors when classifying MB as Intra. ;// ;// Rev 1.13 19 Aug 1996 13:48:26 BNICKERS ;// Provide threshold and differential variables for spatial filtering. ;// ;// Rev 1.12 17 Jun 1996 15:19:34 BNICKERS ;// Fix recording of block and MB SWDs for Spatial Loop Filtering case in H261. ;// ;// Rev 1.11 30 May 1996 16:40:14 BNICKERS ;// Fix order of arguments. ;// ;// Rev 1.10 30 May 1996 15:08:36 BNICKERS ;// Fixed minor error in recent IA ME speed improvements. ;// ;// Rev 1.9 29 May 1996 15:37:58 BNICKERS ;// Acceleration of IA version of ME. ;// ;// Rev 1.8 15 Apr 1996 10:48:48 AKASAI ;// Fixed bug in Spatial loop filter code. Code had been unrolled and ;// the second case had not been updated in the fix put in place of ;// (for) the first case. Basically an ebx instead of bl that cased ;// and overflow from 7F to 3F. ;// ;// Rev 1.7 15 Feb 1996 15:39:26 BNICKERS ;// No change. ;// ;// Rev 1.6 15 Feb 1996 14:39:00 BNICKERS ;// Fix bug wherein access to area outside stack frame was occurring. ;// ;// Rev 1.5 15 Jan 1996 14:31:40 BNICKERS ;// Fix decrement of ref area addr when half pel upward is best in block ME. ;// Broadcast macroblock level MV when block gets classified as Intra. ;// ;// Rev 1.4 12 Jan 1996 13:16:08 BNICKERS ;// Fix SLF so that 3 7F pels doesn't overflow, and result in 3F instead of 7F. ;// ;// Rev 1.3 27 Dec 1995 15:32:46 RMCKENZX ;// Added copyright notice ;// ;// Rev 1.2 19 Dec 1995 17:11:16 RMCKENZX ;// fixed 2 bugs: ;// 1. do +-15 pel search if central and NOT 4 mv / macroblock ;// (was doing when central AND 4 mv / macroblock) ;// 2. correctly compute motion vectors when doing 4 motion ;// vectors per block. ;// ;// Rev 1.1 28 Nov 1995 15:25:48 AKASAI ;// Added white space so that will complie with the long lines. ;// ;// Rev 1.0 28 Nov 1995 14:37:00 BECHOLS ;// Initial revision. ;// ;// ;// Rev 1.13 22 Nov 1995 15:32:42 DBRUCKS ;// Brian made this change on my system. ;// Increased a value to simplify debugging ;// ;// ;// ;// Rev 1.12 17 Nov 1995 10:43:58 BNICKERS ;// Fix problems with B-Frame ME. ;// ;// ;// ;// Rev 1.11 31 Oct 1995 11:44:26 BNICKERS ;// Save/restore ebx. ;// ;//////////////////////////////////////////////////////////////////////////// ; ; MotionEstimation -- This function performs motion estimation for the macroblocks identified ; in the input list. ; Conditional assembly selects either the H263 or H261 version. ; ; Input Arguments: ; ; MBlockActionStream ; ; The list of macroblocks for which we need to perform motion estimation. ; ; Upon input, the following fields must be defined: ; ; CodedBlocks -- Bit 6 must be set for the last macroblock to be processed. ; ; FirstMEState -- must be 0 for macroblocks that are forced to be Intracoded. An ; IntraSWD will be calculated. ; Other macroblocks must have the following values: ; 1: upper left, without advanced prediction. (Advanced prediction ; only applies to H263.) ; 2: upper edge, without advanced prediction. ; 3: upper right, without advanced prediction. ; 4: left edge, without advanced prediction. ; 5: central block, or any block if advanced prediction is being done. ; 6: right edge, without advanced prediction. ; 7: lower left, without advanced prediction. ; 8: lower edge, without advanced prediction. ; 9: lower right, without advanced prediction. ; If vertical motion is NOT allowed: ; 10: left edge, without advanced prediction. ; 11: central block, or any block if advanced prediction is being done. ; 12: right edge, without advanced prediction. ; *** Note that with advanced prediction, only initial states 0, 4, or ; 11 can be specified. Doing block level motion vectors mandates ; advanced prediction, but in that case, only initial ; states 0 and 4 are allowed. ; ; BlkOffset -- must be defined for each of the blocks in the macroblocks. ; ; TargetFrameBaseAddress -- Address of upper left viewable pel in the target Y plane. ; ; PreviousFrameBaseAddress -- Address of upper left viewable pel in the previous Y plane. Whether this is the ; reconstructed previous frame, or the original, is up to the caller to decide. ; ; FilteredFrameBaseAddress -- Address of upper left viewable pel in the scratch area that this function can record ; the spatially filtered prediction for each block, so that frame differencing can ; utilize it rather than have to recompute it. (H261 only) ; ; DoRadius15Search -- TRUE if central macroblocks should search a distance of 15 from center. Else searches 7 out. ; ; DoHalfPelEstimation -- TRUE if we should do ME to half pel resolution. This is only applicable for H263 and must ; be FALSE for H261. (Note: TRUE must be 1; FALSE must be 0). ; ; DoBlockLevelVectors -- TRUE if we should do ME at block level. This is only applicable for H263 and must be FALSE ; for H261. (Note: TRUE must be 1; FALSE must be 0). ; DoSpatialFiltering -- TRUE if we should determine if spatially filtering the prediction reduces the SWD. Only ; applicable for H261 and must be FALSE for H263. (Note: TRUE must be 1; FALSE must be 0). ; ; ZeroVectorThreshold -- If the SWD for a macroblock is less than this threshold, we do not bother searching for a ; better motion vector. Compute as follows, where D is the average tolerable pel difference ; to satisfy this threshold. (Initial recommendation: D=2 ==> ZVT=384) ; ZVT = (128 * ((int)((D**1.6)+.5))) ; ; NonZeroDifferential -- After searching for the best motion vector (or individual block motion vectors, if enabled), ; if the macroblock's SWD is not better than it was for the zero vector -- not better by at ; least this amount -- then we revert to the zero vector. We are comparing two macroblock ; SWDs, both calculated as follows: (Initial recommendation: NZD=128) ; For each of 128 match points, where D is its Abs Diff, accumulate ((int)(M**1.6)+.5))) ; ; BlockMVDifferential -- The amount by which the sum of four block level SWDs must be better than a single macroblock ; level SWD to cause us to choose block level motion vectors. See NonZeroDifferential for ; how the SWDs are calculated. Only applicable for H261. (Initial recommendation: BMVD=128) ; ; EmptyThreshold -- If the SWD for a block is less than this, the block is forced empty. Compute as follows, where D ; is the average tolerable pel diff to satisfy threshold. (Initial recommendation: D=3 ==> ET=96) ; ET = (32 * ((int)((D**1.6)+.5))) ; ; InterCodingThreshold -- If any of the blocks are forced empty, we can simply skip calculating the INTRASWD for the ; macroblock. If none of the blocks are forced empty, we will compare the macroblock's SWD ; against this threshold. If below the threshold, we will likewise skip calculating the ; INTRASWD. Otherwise, we will calculate the INTRASWD, and if it is less than the [Inter]SWD, ; we will classify the block as INTRA-coded. Compute as follows, where D is the average ; tolerable pel difference to satisfy threshold. (Initial recommendation: D=4 ==> ICT=1152) ; ICT = (128 * ((int)((D**1.6)+.5))) ; ; IntraCodingDifferential -- For INTRA coding to occur, the INTRASWD must be better than the INTERSWD by at least ; this amount. ; ; Output Arguments ; ; MBlockActionStream ; ; These fields are defined as follows upon return: ; ; BlockType -- Set to INTRA, INTER1MV, or (H263 only) INTER4MV. ; ; PHMV and PVMV -- The horizontal and vertical motion vectors, in units of a half pel. ; ; BHMV and BVMV -- These fields get clobbered. ; ; PastRef -- If BlockType != INTRA, set to the address of the reference block. ; ; If Horizontal MV indicates a half pel position, the prediction for the upper left pel of the block ; is the average of the pel at PastRef and the one at PastRef+1. ; ; If Vertical MV indicates a half pel position, the prediction for the upper left pel of the block ; is the average of the pel at PastRef and the one at PastRef+PITCH. ; ; If both MVs indicate half pel positions, the prediction for the upper left pel of the block is the ; average of the pels at PastRef, PastRef+1, PastRef+PITCH, and PastRef+PITCH+1. ; ; Indications of a half pel position can only happen for H263. ; ; In H261, when spatial filtering is done, the address will be in the SpatiallyFilteredFrame, where ; this function stashes the spatially filtered prediction for subsequent reuse by frame differencing. ; ; CodedBlocks -- Bits 4 and 5 are turned on, indicating that the U and V blocks should be processed. (If the ; FDCT function finds them to quantize to empty, it will mark them as empty.) ; ; Bits 0 thru 3 are cleared for each of blocks 1 thru 4 that MotionEstimation forces empty; ; they are set otherwise. ; ; Bits 6 and 7 are left unchanged. ; ; SWD -- Set to the sum of the SWDs for the four luma blocks in the macroblock. The SWD for any block that is ; forced empty, is NOT included in the sum. ; ; ; ; IntraSWDTotal -- The sum of the block SWDs for all Intracoded macroblocks. ; ; IntraSWDBlocks -- The number of blocks that make up the IntraSWDTotal. ; ; InterSWDTotal -- The sum of the block SWDs for all Intercoded macroblocks. ; None of the blocks forced empty are included in this. ; ; InterSWDBlocks -- The number of blocks that make up the InterSWDTotal. ; ; ; Other assumptions: ; ; For performance reasons, it is assumed that the layout of current and previous frames (and spatially filtered ; frame for H261) rigourously conforms to the following guide. ; ; The spatially filtered frame (only present and applicable for H261) is an output frame into which MotionEstimation ; places spatially filtered macroblocks as it determines if filtering is good for a macroblock. If it determines ; such, frame differencing will be able to re-use the spatially filtered macroblock, rather than recomputing it. ; ; Cache ; Alignment ; Points: v v v v v v v v v v v v v ; 16 | 352 (narrower pictures are left justified) | 16 ; +---+---------------------------------------------------------------------------------------+---+ ; | D | Current Frame Y Plane | D | ; | u | | u | ; Frame | m | | m | ; Height | m | | m | ; Lines | y | | y | ; | | | | ; +---+---------------------------------------------------------------------------------------+---+ ; | | ; | | ; | | ; 24 lines | Dummy Space (24 lines plus 8 bytes. Can be reduced to 8 bytes if unrestricted motion | ; | vectors is NOT selected.) | ; | | ; | 8 176 16 176 |8 ; | +-+-------------------------------------------------------------------------------------------+-+ ; +-+D| Current Frame U Plane | D | Current Frame V Plane |D| ; Frame |u| | u | |u| ; Height |m| | m | |m| ; Div By 2 |m| | m | |m| ; Lines |y| | y | |y| ; +-+-------------------------------------------+---+-------------------------------------------+-+ ; 72 dummy bytes. I.e. enough dummy space to assure that MOD ((Previous_Frame - Current_Frame), 128) == 80 ; +-----------------------------------------------------------------------------------------------+ ; | | ; 16 lines | If Unrestricted Motion Vectors selected, 16 lines must appear above and below previous frame, | ; | and these lines plus the 16 columns to the left and 16 columns to the right of the previous | ; | frame must be initialized to the values at the edges and corners, propagated outward. If | ; | Unrestricted Motion Vectors is off, these lines don't have to be allocated. | ; | | ; | +---------------------------------------------------------------------------------------+ + ; Frame | | Previous Frame Y Plane | | ; Height | | | | ; Lines | | | | ; | | | | ; | | | | ; | +---------------------------------------------------------------------------------------+ + ; | | ; 16 lines | See comment above Previous Y Plane | ; | | ; |+--- 8 bytes of dummy space. Must be there, whether unrestricted MV or not. | ; || | ; |v+-----------------------------------------------+---------------------------------------------+-+ ; +-+ | | ; | See comment above Previous Y Plane. | See comment above Previous Y Plane. | ; 8 lines | Same idea here, but 8 lines are needed above | Same idea here, but 8 lines are needed | ; | and below U plane, and 8 columns on each side.| and below V plane, and 8 columns on each side.| ; | | | ; |8 176 8|8 176 8| ; | +-------------------------------------------+ | +-------------------------------------------+ | ; | | Previous Frame U Plane | | | Previous Frame V Plane | | ; Frame | | | | | | | ; Height | | | | | | | ; Div By 2 | | | | | | | ; Lines | | | | | | | ; | +-------------------------------------------+ | +-------------------------------------------+ | ; | | | ; 8 lines | See comment above Previous U Plane | See comment above Previous V Plane | ; | | | ; | | | ; | | | ; +-----------------------------------------------+---------------------------------------------+-+ ; Enough dummy space to assure that MOD ((Spatial_Frame - Previous_Frame), 4096) == 2032 ; +---+---------------------------------------------------------------------------------------+---+ ; | D | Spatially Filtered Y Plane (present only for H261) | D | ; | u | | u | ; Frame | m | | m | ; Height | m | | m | ; Lines | y | | y | ; | | | | ; +---+---------------------------------------------------------------------------------------+---+ ; | | ; | | ; | | ; 24 lines | Dummy Space (24 lines plus 8 bytes. Can be reduced to 8 bytes if unrestricted motion | ; | vectors is NOT selected, which is certainly the case for H261.) | ; | | ; | 8 176 16 176 |8 ; | +-+-------------------------------------------------------------------------------------------+-+ ; +-+D| Spatially Filtered U plane (H261 only) | D | Spatially Filtered V plane (H261 only) |D| ; Frame |u| | u | |u| ; Height |m| | m | |m| ; Div By 2 |m| | m | |m| ; Lines |y| | y | |y| ; +-+-------------------------------------------+---+-------------------------------------------+-+ ; ; Cache layout of the target block and the full range for the reference area (as restricted to +/- 7 in vertical, ; and +/- 7 (expandable to +/- 15) in horizontal, is as shown here. Each box represents a cache line (32 bytes), ; increasing incrementally from left to right, and then to the next row (like reading a book). The 128 boxes taken ; as a whole represent 4Kbytes. The boxes are populated as follows: ; ; R -- Data from the reference area. Each box contains 23 of the pels belonging to a line of the reference area. ; The remaining 7 pels of the line is either in the box to the left (for reference areas used to provide ; predictions for target macroblocks that begin at an address 0-mod-32), or to the right (for target MBs that ; begin at an address 16-mod-32). There are 30 R's corresponding to the 30-line limit on the vertical distance ; we might search. ; ; T -- Data from the target macroblock. Each box contains a full line (16 pels) for each of two adjacent ; macroblocks. There are 16 T's corresponding to the 16 lines of the macroblocks. ; ; S -- Space for the spatially filtered macroblock (H261 only). ; ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+---+---+---+---+ ; | T | | R | | S | | R | | ; +---+---+---+---+---+---+---+---+ ; ; Thus, in a logical sense, the above data fits into one of the 4K data cache pages, leaving the other for all other ; data. Care has been taken to assure that the tables and the stack space needed by this function fit nicely into ; the other data cache page. Only the MBlockActionStream remains to conflict with the above data structures. That ; is both unavoidable, and of minimal consequence. ; An algorithm has been selected that calculates fewer SWDs (Sum of Weighted Differences) than the typical log search. ; In the typical log search, a three level search is done, in which the SWDs are compared for the center point and a ; point at each 45 degrees, initially 4 pels away, then 2, then 1. This requires a total of 25 SWDs for each ; macroblock (except those near edges or corners). ; ; In this algorithm, six levels are performed, with each odd level being a horizontal search, and each even level being ; a vertical search. Each search compares the SWD for the center point with that of a point in each direction on the ; applicable axis. This requires 13 SWDs, and a lot simpler control structure. Here is an example picture of a ; search, in which "0" represents the initial center point (the 0,0 motion vector), "A", and "a" represent the first ; search points, etc. In this example, the "winner" of each level of the search proceeds as follows: a, B, C, C, E, F, ; arriving at a motion vector of -1 horizontal, 5 vertical. ; ; ............... ; ............... ; ............... ; ...b........... ; ............... ; ............... ; ............... ; ...a...0...A... ; ............... ; .....d......... ; ......f........ ; .c.BeCE........ ; ......F........ ; .....D......... ; ............... ; ; ; A word about data cache performance. Conceptually, the tables and local variables used by this function are placed ; in memory such that they will fit in one 4K page of the on-chip data cache. For the Pentium (tm) microprocessor, ; this leaves the other 4K page for other purposes. The other data structures consist of: ; ; The current frame, from which we need to access the lines of the 16*16 macroblock. Since cache lines are 32 bytes ; wide, the cache fill operations that fetch one target macroblock will serve to fetch the macroblock to the right, ; so an average of 8 cache lines are fetched for each macroblock. ; ; The previous frame, from which we need to access a reference area of 30*30 pels. For each macroblock for which we ; need to search for a motion vector, we will typically need to access no more than about 25 of these, but in general ; these lines span the 30 lines of the search area. Since cache lines are 32 bytes wide, the cache fill operations ; that fetch reference data for one macroblock, will tend to fetch data that is useful as reference data for the ; macroblock to the right, so an average of about 15 (rounded up to be safe) cache lines are fetched for each ; macroblock. ; ; The MBlockActionStream, which controls the searching (since we don't need to motion estimate blocks that are ; legislated to be intra) will disrupt cache behaviour of the other data structures, but not to a significant degree. ; ; By setting the pitch to a constant of 384, and by allocating the frames as described above, the one available 4K page ; of data cache will be able to contain the 30 lines of the reference area, the 16 lines of the target area, and the ; 16 lines of the spatially filtered area (H261 only) without any collisions. ; ; ; Here is a flowchart of the major sections of this function: ; ; +-- Execute once for Y part of each macroblock that is NOT Intra By Decree --+ ; | | ; | +---------------------------------------------------------------+ | ; | | 1) Compute average value for target match points. | | ; | | 2) Prepare match points in target MB for easier matching. | | ; | | 3) Compute the SWD for (0,0) motion vector. | | ; | +---------------------------------------------------------------+ | ; | | | ; | v | ; | /---------------------------------\ Yes | ; | < 4) Is 0-motion SWD good enough? >-------------------------+ | ; | \---------------------------------/ | | ; | | | | ; | |No | | ; | v | | ; | +--- 5) While state engine has more motion vectors to check ---+ | | ; | | | | | ; | | | | | ; | | +---------------------------------------------------+ | | | ; | | | 5) Compute SWDs for 2 ref MBs and pick best of 3. |----->| | | ; | | +---------------------------------------------------+ | | | ; | | | | | ; | +--------------------------------------------------------------+ | | ; | | | | ; | v | | ; | /-----------------------------------------\ | | ; | < 6) Is best motion vector the 0-vector? > | | ; | \-----------------------------------------/ | | ; | | | | | ; | |No |Yes | | ; | v v | | ; | +-----------------+ +-------------------------------------------+ | | ; | | Mark all blocks | | 6) Identify as empty block any in which: |<-+ | ; | +--| non-empty. | | --> 0-motion SWD < EmptyThresh, and | | ; | | +-----------------+ +-------------------------------------------+ | ; | | | | ; | | v | ; | | /--------------------------------\ Yes +--------------------------+ | ; | | < 6) Are all blocks marked empty? >--->| 6) Classify FORCEDEMPTY |-->| ; | | \--------------------------------/ +--------------------------+ | ; | | | | ; | | |No | ; | | v | ; | | /--------------------------------------------\ | ; | | < 7) Are any non-phantom blocks marked empty? > | ; | | \--------------------------------------------/ | ; | | | | | ; | | |No |Yes | ; | v v v | ; | +---------------------+ +--------------------------------+ | ; | | 8) Compute IntraSWD | | Set IntraSWD artificially high | | ; | +---------------------+ +--------------------------------+ | ; | | | | ; | v v | ; | +-------------------------------+ | ; | | 10) Classify block as one of: | | ; | | INTRA |--------------------------------->| ; | | INTER | | ; | +-------------------------------+ | ; | | ; +----------------------------------------------------------------------------+ ; ; OPTION PROLOGUE:None OPTION EPILOGUE:ReturnAndRelieveEpilogueMacro OPTION M510 include e3inst.inc include e3mbad.inc .xlist include memmodel.inc .list .DATA ; Storage for tables and temps used by Motion Estimation function. Fit into ; 4Kbytes contiguous memory so that it uses one cache page, leaving other ; for reference area of previous frame and target macroblock of current frame. PickPoint DB 0,4,?,4,0,?,2,2 ; Map CF accum to new central pt selector. PickPoint_BLS DB 6,4,?,4,6,?,2,2 ; Same, for when doing block level search. OffsetToRef LABEL DWORD ; Linearized adjustments to affect horz/vert motion. DD ? ; This index used when zero-valued motion vector is good enough. DD 0 ; Best fit of 3 SWDs is previous center. DD 1 ; Best fit of 3 SWDs is the ref block 1 pel to the right. DD -1 ; Best fit of 3 SWDs is the ref block 1 pel to the left. DD 1*PITCH ; Best fit of 3 SWDs is the ref block 1 pel above. DD -1*PITCH ; Best fit of 3 SWDs is the ref block 1 pel below. DD 2 ; Best fit of 3 SWDs is the ref block 2 pels to the right. DD -2 ; Best fit of 3 SWDs is the ref block 2 pels to the left. DD 2*PITCH ; Best fit of 3 SWDs is the ref block 2 pel above. DD -2*PITCH ; Best fit of 3 SWDs is the ref block 2 pel below. DD 4 ; Best fit of 3 SWDs is the ref block 4 pels to the right. DD -4 ; Best fit of 3 SWDs is the ref block 4 pels to the left. DD 4*PITCH ; Best fit of 3 SWDs is the ref block 4 pel above. DD -4*PITCH ; Best fit of 3 SWDs is the ref block 4 pel below. DD 7 ; Best fit of 3 SWDs is the ref block 7 pels to the right. DD -7 ; Best fit of 3 SWDs is the ref block 7 pels to the left. DD 7*PITCH ; Best fit of 3 SWDs is the ref block 7 pel above. DD -7*PITCH ; Best fit of 3 SWDs is the ref block 7 pel below. M0 = 4 ; Define symbolic indices into OffsetToRef lookup table. MHP1 = 8 MHN1 = 12 MVP1 = 16 MVN1 = 20 MHP2 = 24 MHN2 = 28 MVP2 = 32 MVN2 = 36 MHP4 = 40 MHN4 = 44 MVP4 = 48 MVN4 = 52 MHP7 = 56 MHN7 = 60 MVP7 = 64 MVN7 = 68 ; Map linearized motion vector to vertical part. ; (Mask bottom byte of linearized MV to zero, then use result ; as index into this array to get vertical MV.) IF PITCH-384 *** error: The magic of this table assumes a pitch of 384. ENDIF DB -32, -32 DB -30 DB -28, -28 DB -26 DB -24, -24 DB -22 DB -20, -20 DB -18 DB -16, -16 DB -14 DB -12, -12 DB -10 DB -8, -8 DB -6 DB -4, -4 DB -2 DB 0 UnlinearizedVertMV DB 0 DB 2 DB 4, 4 DB 6 DB 8, 8 DB 10 DB 12, 12 DB 14 DB 16, 16 DB 18 DB 20, 20 DB 22 DB 24, 24 DB 26 DB 28, 28 DB 30 ; Map initial states to initializers for half pel search. Where search would ; illegally take us off edge of picture, set initializer artificially high. InitHalfPelSearchHorz LABEL DWORD DD 040000000H, 000000000H, 000004000H DD 040000000H, 000000000H, 000004000H DD 040000000H, 000000000H, 000004000H DD 040000000H, 000000000H, 000004000H InitHalfPelSearchVert LABEL DWORD DD 040000000H, 040000000H, 040000000H DD 000000000H, 000000000H, 000000000H DD 000004000H, 000004000H, 000004000H DD 040004000H, 040004000H, 040004000H SWDState LABEL BYTE ; Rules that govern state engine of motion estimator. DB 8 DUP (?) ; 0: not used. ; 1: Upper Left Corner. Explore 4 right and 4 down. DB 21, M0 ; (0,0) DB 22, MHP4 ; (0,4) DB 23, MVP4, ?, ? ; (4,0) ; 2: Upper Edge. Explore 4 left and 4 right. DB 22, M0 ; (0, 0) DB 22, MHN4 ; (0,-4) DB 22, MHP4, ?, ? ; (0, 4) ; 3: Upper Right Corner. Explore 4 right and 4 down. DB 31, M0 ; (0, 0) DB 22, MHN4 ; (0,-4) DB 32, MVP4, ?, ? ; (4, 0) ; 4: Left Edge. Explore 4 up and 4 down. DB 23, M0 ; ( 0,0) DB 23, MVN4 ; (-4,0) DB 23, MVP4, ?, ? ; ( 4,0) ; 5: Interior Macroblock. Explore 4 up and 4 down. DB 37, M0 ; ( 0,0) DB 37, MVN4 ; (-4,0) DB 37, MVP4, ?, ? ; ( 4,0) ; 6: Right Edge. Explore 4 up and 4 down. DB 32, M0 ; ( 0,0) DB 32, MVN4 ; (-4,0) DB 32, MVP4, ?, ? ; ( 4,0) ; 7: Lower Left Corner. Explore 4 up and 4 right. DB 38, M0 ; ( 0,0) DB 39, MHP4 ; ( 0,4) DB 23, MVN4, ?, ? ; (-4,0) ; 8: Lower Edge. Explore 4 left and 4 right. DB 39, M0 ; (0, 0) DB 39, MHN4 ; (0,-4) DB 39, MHP4, ?, ? ; (0, 4) ; 9: Lower Right Corner. Explore 4 up and 4 left. DB 44, M0 ; ( 0, 0) DB 39, MHN4 ; ( 0,-4) DB 32, MVN4, ?, ? ; (-4, 0) ; 10: Left Edge, No Vertical Motion Allowed. DB 46, M0 ; (0,0) DB 48, MHP2 ; (0,2) DB 47, MHP4, ?, ? ; (0,4) ; 11: Interior Macroblock, No Vertical Motion Allowed. DB 47, M0 ; (0, 0) DB 47, MHN4 ; (0,-4) DB 47, MHP4, ?, ? ; (0, 4) ; 12: Right Edge, No Vertical Motion Allowed. DB 49, M0 ; (0, 0) DB 48, MHN2 ; (0,-2) DB 47, MHN4, ?, ? ; (0,-4) ; 13: Horz by 2, Vert by 2, Horz by 1, Vert by 1. DB 14, M0 DB 14, MHP2 DB 14, MHN2, ?, ? ; 14: Vert by 2, Horz by 1, Vert by 1. DB 15, M0 DB 15, MVP2 DB 15, MVN2, ?, ? ; 15: Horz by 1, Vert by 1. DB 16, M0 DB 16, MHP1 DB 16, MHN1, ?, ? ; 16: Vert by 1. DB 0, M0 DB 0, MVP1 DB 0, MVN1, ?, ? ; 17: Vert by 2, Horz by 2, Vert by 1, Horz by 1. DB 18, M0 DB 18, MVP2 DB 18, MVN2, ?, ? ; 18: Horz by 2, Vert by 1, Horz by 1. DB 19, M0 DB 19, MHP2 DB 19, MHN2, ?, ? ; 19: Vert by 1, Horz by 1. DB 20, M0 DB 20, MVP1 DB 20, MVN1, ?, ? ; 20: Horz by 1. DB 0, M0 DB 0, MHP1 DB 0, MHN1, ?, ? ; 21: From 1A. Upper Left. Try 2 right and 2 down. DB 24, M0 ; (0, 0) DB 25, MHP2 ; (0, 2) DB 26, MVP2, ?, ? ; (2, 0) ; 22: From 1B. ; From 2 center point would be (0,-4/0/4). ; From 3B center point would be (0,-4). DB 27, M0 ; (0, 4) DB 18, MVP2 ; (2, 4) Next: Horz 2, Vert 1, Horz 1. (1:3,1:7) DB 13, MVP4, ?, ? ; (4, 4) Next: Horz 2, Vert 2, Horz 1, Vert 1. (1:7,1:7) ; 23: From 1C. ; From 4 center point would be (-4/0/4,0). ; From 7C center point would be (-4,0). DB 29, M0 ; (4, 0) DB 14, MHP2 ; (4, 2) Next: Vert 2, Horz 1, Vert 1. (1:7,1:3) DB 17, MHP4, ?, ? ; (4, 4) Next: Vert 2, Horz 2, Vert 1, Horz 1. (1:7,1:7) ; 24: From 21A. Upper Left. Try 1 right and 1 down. DB 0, M0 ; (0, 0) DB 0, MHP1 ; (1, 0) DB 0, MVP1, ?, ? ; (0, 1) ; 25: From 21B. ; From 31B center point would be (0,-2). DB 20, M0 ; (0, 2) Next: Horz 1 (0,1:3) DB 20, MVP1 ; (1, 2) Next: Horz 1 (1,1:3) DB 15, MVP2, ?, ? ; (2, 2) Next: Horz 1, Vert 1 (1:3,1:3) ; 26: From 21C. ; From 38C center point would be (-2,0). DB 16, M0 ; (2, 0) Next: Vert 1 (1:3,0) DB 16, MHP1 ; (2, 1) Next: Vert 1 (1:3,1) DB 19, MHP2, ?, ? ; (2, 2) Next: Vert 1, Horz 1 (1:3,1:3) ; 27: From 22A. DB 28, M0 ; (0, 4) DB 28, MHN2 ; (0, 2) DB 28, MHP2, ?, ? ; (0, 6) ; 28: From 27. DB 20, M0 ; (0, 2/4/6) Next: Horz 1. (0,1:7) DB 20, MVP1 ; (1, 2/4/6) Next: Horz 1. (1,1:7) DB 20, MVP2, ?, ? ; (2, 2/4/6) Next: Horz 1. (2,1:7) ; 29: From 23A. DB 30, M0 ; (4, 0) DB 30, MVN2 ; (2, 0) DB 30, MVP2, ?, ? ; (6, 0) ; 30: From 29. DB 16, M0 ; (2/4/6, 0) Next: Vert 1. (1:7,0) DB 16, MHP1 ; (2/4/6, 1) Next: Vert 1. (1:7,1) DB 16, MHP2, ?, ? ; (2/4/6, 2) Next: Vert 1. (1:7,2) ; 31: From 3A. Upper Right. Try 2 left and 2 down. DB 33, M0 ; (0, 0) DB 25, MHN2 ; (0,-2) DB 34, MVP2, ?, ? ; (2, 0) ; 32: From 3C. ; From 6 center point would be (-4/0/4, 0) ; From 9C center point would be (-4, 0) DB 35, M0 ; (4, 0) DB 14, MHN2 ; (4,-2) Next: Vert2,Horz1,Vert1. (1:7,-1:-3) DB 17, MHN4, ?, ? ; (4,-4) Next: Vert2,Horz2,Vert1,Horz1. (1:7,-1:-7) ; 33: From 31A. Upper Right. Try 1 left and 1 down. DB 0, M0 ; (0, 0) DB 0, MHN1 ; (0,-1) DB 0, MVP1, ?, ? ; (1, 0) ; 34: From 31C. ; From 44C center point would be (-2, 0) DB 16, M0 ; (2, 0) Next: Vert 1 (1:3, 0) DB 16, MHN1 ; (2,-1) Next: Vert 1 (1:3,-1) DB 19, MHN2, ?, ? ; (2,-2) Next: Vert 1, Horz 1 (1:3,-1:-3) ; 35: From 32A. DB 36, M0 ; (4, 0) DB 36, MVN2 ; (2, 0) DB 36, MVP2, ?, ? ; (6, 0) ; 36: From 35. DB 16, M0 ; (2/4/6, 0) Next: Vert 1. (1:7, 0) DB 16, MHN1 ; (2/4/6,-1) Next: Vert 1. (1:7,-1) DB 16, MHN2, ?, ? ; (2/4/6,-2) Next: Vert 1. (1:7,-2) ; 37: From 5. DB 17, M0 ; (-4/0/4, 0) Next: Vert2,Horz2,Vert1,Horz1 (-7:7,-3: 3) DB 17, MHP4 ; (-4/0/4,-4) Next: Vert2,Horz2,Vert1,Horz1 (-7:7, 1: 7) DB 17, MHN4, ?, ? ; (-4/0/4, 4) Next: Vert2,Horz2,Vert1,Horz1 (-7:7,-7:-1) ; 38: From 7A. Lower Left. Try 2 right and 2 up. DB 42, M0 ; ( 0,0) DB 43, MHP2 ; ( 0,2) DB 26, MVN2, ?, ? ; (-2,0) ; 39: From 13B. ; From 14 center point would be (0,-4/0/4) ; From 16B center point would be (0,-4) DB 40, M0 ; ( 0,4) DB 18, MVN2 ; (-2,4) Next: Horz2,Vert1,Horz1. (-3:-1,1:7) DB 13, MVN4, ?, ? ; (-4,4) Next: Horz2,Vert2,Horz1,Vert1. (-7:-1,1:7) ; 40: From 39A. DB 41, M0 ; (0, 4) DB 41, MHN2 ; (0, 2) DB 41, MHP2, ?, ? ; (0, 6) ; 41: From 40. DB 20, M0 ; ( 0,2/4/6) Next: Horz 1. ( 0,1:7) DB 20, MVN1 ; (-1,2/4/6) Next: Horz 1. (-1,1:7) DB 20, MVN2, ?, ? ; (-2,2/4/6) Next: Horz 1. (-2,1:7) ; 42: From 38A. Lower Left. Try 1 right and 1 up. DB 0, M0 ; ( 0,0) DB 0, MHP1 ; ( 0,1) DB 0, MVN1, ?, ? ; (-1,0) ; 43: From 38B. ; From 44B center point would be (0,-2) DB 20, M0 ; ( 0,2) Next: Horz 1 ( 0,1:3) DB 20, MVN1 ; (-1,2) Next: Horz 1 (-1,1:3) DB 15, MVN2, ?, ? ; (-2,2) Next: Horz 1, Vert 1 (-1:-3,1:3) ; 44: From 9A. Lower Right. Try 2 left and 2 up. DB 45, M0 ; ( 0, 0) DB 43, MHN2 ; ( 0,-2) DB 34, MVN2, ?, ? ; (-2, 0) ; 45: From 44A. Lower Right. Try 1 left and 1 up. DB 0, M0 ; ( 0, 0) DB 0, MHN1 ; ( 0,-1) DB 0, MVN1, ?, ? ; (-1, 0) ; 46: From 17A. DB 0, M0 ; (0,0) DB 0, MHP1 ; (0,1) DB 0, MHP1, ?, ? ; (0,1) ; 47: From 10C. ; From 11 center point would be (0,4/0/-4) ; From 12C center point would be (0,-4) DB 48, M0 ; (0,4) DB 48, MHN2 ; (0,2) DB 48, MHP2, ?, ? ; (0,6) ; 48 From 10B. ; From 47 center point would be (0,2/4/6) ; From 12B center point would be (0,-2) DB 0, M0 ; (0,2) DB 0, MHN1 ; (0,1) DB 0, MHP1, ?, ? ; (0,3) ; 49 From 12A. DB 0, M0 ; (0, 0) DB 0, MHN1 ; (0,-1) DB 0, MHN1, ?, ? ; (0,-1) ; 50: Interior Macroblock. Explore 7 up and 7 down. DB 51, M0 ; ( 0,0) DB 51, MVN7 ; (-7,0) DB 51, MVP7, ?, ? ; ( 7,0) ; 51: Explore 7 left and 7 right. DB 5, M0 ; (-7|0|7, 0) DB 5, MHN7 ; (-7|0|7,-7) DB 5, MHP7, ?, ? ; (-7|0|7, 7) MulByNeg8 LABEL DWORD CNT = 0 REPEAT 128 DD WeightedDiff+CNT CNT = CNT - 8 ENDM ; The following treachery puts the numbers into byte 2 of each aligned DWORD. DB 0, 0 DD 193 DUP (255) DD 250,243,237,231,225,219,213,207,201,195,189,184,178,172,167,162,156 DD 151,146,141,135,130,126,121,116,111,107,102, 97, 93, 89, 84, 80, 76 DD 72, 68, 64, 61, 57, 53, 50, 46, 43, 40, 37, 34, 31, 28, 25, 22, 20 DD 18, 15, 13, 11, 9, 7, 6, 4, 3, 2, 1 DB 0, 0 WeightedDiff LABEL DWORD DB 0, 0 DD 0, 0, 1, 2, 3, 4, 6, 7, 9, 11, 13, 15, 18 DD 20, 22, 25, 28, 31, 34, 37, 40, 43, 46, 50, 53, 57, 61, 64, 68, 72 DD 76, 80, 84, 89, 93, 97,102,107,111,116,121,126,130,135,141,146,151 DD 156,162,167,172,178,184,189,195,201,207,213,219,225,231,237,243,250 DD 191 DUP (255) DB 255, 0 MotionOffsets DD 1*PITCH,0,?,? RemnantOfCacheLine DB 8 DUP (?) LocalStorage LABEL DWORD ; Local storage goes on the stack at addresses ; whose lower 12 bits match this address. .CODE ASSUME cs : FLAT ASSUME ds : FLAT ASSUME es : FLAT ASSUME fs : FLAT ASSUME gs : FLAT ASSUME ss : FLAT MOTIONESTIMATION proc C AMBAS: DWORD, ATargFrmBase: DWORD, APrevFrmBase: DWORD, AFiltFrmBase: DWORD, ADo15Search: DWORD, ADoHalfPelEst: DWORD, ADoBlkLvlVec: DWORD, ADoSpatialFilt: DWORD, AZeroVectorThresh: DWORD, ANonZeroMVDiff: DWORD, ABlockMVDiff: DWORD, AEmptyThresh: DWORD, AInterCodThresh: DWORD, AIntraCodDiff: DWORD, ASpatialFiltThresh: DWORD, ASpatialFiltDiff: DWORD, AIntraSWDTot: DWORD, AIntraSWDBlks: DWORD, AInterSWDTot: DWORD, AInterSWDBlks: DWORD LocalFrameSize = 128 + 168*4 + 32 ; 128 for locals; 168*4 for blocks; 32 for dummy block. RegStoSize = 16 ; Arguments: MBlockActionStream_arg = RegStoSize + 4 TargetFrameBaseAddress_arg = RegStoSize + 8 PreviousFrameBaseAddress_arg = RegStoSize + 12 FilteredFrameBaseAddress_arg = RegStoSize + 16 DoRadius15Search_arg = RegStoSize + 20 DoHalfPelEstimation_arg = RegStoSize + 24 DoBlockLevelVectors_arg = RegStoSize + 28 DoSpatialFiltering_arg = RegStoSize + 32 ZeroVectorThreshold_arg = RegStoSize + 36 NonZeroMVDifferential_arg = RegStoSize + 40 BlockMVDifferential_arg = RegStoSize + 44 EmptyThreshold_arg = RegStoSize + 48 InterCodingThreshold_arg = RegStoSize + 52 IntraCodingDifferential_arg = RegStoSize + 56 SpatialFiltThreshold_arg = RegStoSize + 60 SpatialFiltDifferential_arg = RegStoSize + 64 IntraSWDTotal_arg = RegStoSize + 68 IntraSWDBlocks_arg = RegStoSize + 72 InterSWDTotal_arg = RegStoSize + 76 InterSWDBlocks_arg = RegStoSize + 80 EndOfArgList = RegStoSize + 84 ; Locals (on local stack frame) MBlockActionStream EQU [esp+ 0] CurrSWDState EQU [esp+ 4] MotionOffsetsCursor EQU CurrSWDState HalfPelHorzSavings EQU CurrSWDState VertFilterDoneAddr EQU CurrSWDState IntraSWDTotal EQU [esp+ 8] IntraSWDBlocks EQU [esp+ 12] InterSWDTotal EQU [esp+ 16] InterSWDBlocks EQU [esp+ 20] MBCentralInterSWD EQU [esp+ 24] MBRef1InterSWD EQU [esp+ 28] MBRef2InterSWD EQU [esp+ 32] MBCentralInterSWD_BLS EQU [esp+ 36] MB0MVInterSWD EQU [esp+ 40] MBAddrCentralPoint EQU [esp+ 44] MBMotionVectors EQU [esp+ 48] DoHalfPelEstimation EQU [esp+ 52] DoBlockLevelVectors EQU [esp+ 56] DoSpatialFiltering EQU [esp+ 60] ZeroVectorThreshold EQU [esp+ 64] NonZeroMVDifferential EQU [esp+ 68] BlockMVDifferential EQU [esp+ 72] EmptyThreshold EQU [esp+ 76] InterCodingThreshold EQU [esp+ 80] IntraCodingDifferential EQU [esp+ 84] SpatialFiltThreshold EQU [esp+ 88] SpatialFiltDifferential EQU [esp+ 92] TargetMBAddr EQU [esp+ 96] TargetFrameBaseAddress EQU [esp+ 100] PreviousFrameBaseAddress EQU [esp+ 104] TargToRef EQU [esp+ 108] TargToSLF EQU [esp+ 112] DoRadius15Search EQU [esp+ 116] StashESP EQU [esp+ 120] BlockLen EQU 168 Block1 EQU [esp+ 128+40] ; "128" is for locals. "40" is so offsets range from -40 to 124. Block2 EQU Block1 + BlockLen Block3 EQU Block2 + BlockLen Block4 EQU Block3 + BlockLen BlockN EQU Block4 + BlockLen BlockNM1 EQU Block4 BlockNM2 EQU Block3 BlockNP1 EQU Block4 + BlockLen + BlockLen DummyBlock EQU Block4 + BlockLen Ref1Addr EQU -40 Ref2Addr EQU -36 AddrCentralPoint EQU -32 CentralInterSWD EQU -28 Ref1InterSWD EQU -24 Ref2InterSWD EQU -20 CentralInterSWD_BLS EQU -16 ; CentralInterSWD, when doing blk level search. CentralInterSWD_SLF EQU -16 ; CentralInterSWD, when doing spatial filter. HalfPelSavings EQU Ref2Addr ZeroMVInterSWD EQU -12 BlkHMV EQU -8 BlkVMV EQU -7 BlkMVs EQU -8 AccumTargetPels EQU -4 ; Offsets for Negated Quadrupled Target Pels: N8T00 EQU 0 N8T04 EQU 4 N8T02 EQU 8 N8T06 EQU 12 N8T20 EQU 16 N8T24 EQU 20 N8T22 EQU 24 N8T26 EQU 28 N8T40 EQU 32 N8T44 EQU 36 N8T42 EQU 40 N8T46 EQU 44 N8T60 EQU 48 N8T64 EQU 52 N8T62 EQU 56 N8T66 EQU 60 N8T11 EQU 64 N8T15 EQU 68 N8T13 EQU 72 N8T17 EQU 76 N8T31 EQU 80 N8T35 EQU 84 N8T33 EQU 88 N8T37 EQU 92 N8T51 EQU 96 N8T55 EQU 100 N8T53 EQU 104 N8T57 EQU 108 N8T71 EQU 112 N8T75 EQU 116 N8T73 EQU 120 N8T77 EQU 124 push esi push edi push ebp push ebx ; Adjust stack ptr so that local frame fits nicely in cache w.r.t. other data. mov esi,esp sub esp,000001000H mov eax,[esp] ; Cause system to commit page. sub esp,000001000H and esp,0FFFFF000H mov ebx,OFFSET LocalStorage+31 and ebx,000000FE0H mov edx,PD [esi+MBlockActionStream_arg] or esp,ebx mov eax,PD [esi+TargetFrameBaseAddress_arg] mov TargetFrameBaseAddress,eax mov ebx,PD [esi+PreviousFrameBaseAddress_arg] mov PreviousFrameBaseAddress,ebx sub ebx,eax mov ecx,PD [esi+FilteredFrameBaseAddress_arg] sub ecx,eax mov TargToRef,ebx mov TargToSLF,ecx mov eax,PD [esi+EmptyThreshold_arg] mov EmptyThreshold,eax mov eax,PD [esi+DoHalfPelEstimation_arg] mov DoHalfPelEstimation,eax mov eax,PD [esi+DoBlockLevelVectors_arg] mov DoBlockLevelVectors,eax mov eax,PD [esi+DoRadius15Search_arg] mov DoRadius15Search,eax mov eax,PD [esi+DoSpatialFiltering_arg] mov DoSpatialFiltering,eax mov eax,PD [esi+ZeroVectorThreshold_arg] mov ZeroVectorThreshold,eax mov eax,PD [esi+NonZeroMVDifferential_arg] mov NonZeroMVDifferential,eax mov eax,PD [esi+BlockMVDifferential_arg] mov BlockMVDifferential,eax mov eax,PD [esi+InterCodingThreshold_arg] mov InterCodingThreshold,eax mov eax,PD [esi+IntraCodingDifferential_arg] mov IntraCodingDifferential,eax mov eax,PD [esi+SpatialFiltThreshold_arg] mov SpatialFiltThreshold,eax mov eax,PD [esi+SpatialFiltDifferential_arg] mov SpatialFiltDifferential,eax xor ebx,ebx mov IntraSWDBlocks,ebx mov InterSWDBlocks,ebx mov IntraSWDTotal,ebx mov InterSWDTotal,ebx mov Block1.BlkMVs,ebx mov Block2.BlkMVs,ebx mov Block3.BlkMVs,ebx mov Block4.BlkMVs,ebx mov DummyBlock.Ref1Addr,esp mov DummyBlock.Ref2Addr,esp mov StashESP,esi jmp FirstMacroBlock ; Activity Details for this section of code (refer to flow diagram above): ; ; 1) To calculate an average value for the target match points of each ; block, we sum the 32 match points. The totals for each of the 4 ; blocks is output seperately. ; ; 2) Define each prepared match point in the target macroblock as the ; real match point times negative 8, with the base address of the ; WeightedDiff lookup table added. I.e. ; ; for (i = 0; i < 16; i += 2) ; for (j = 0; j < 16; j += 2) ; N8T[i][j] = ( -8 * Target[i][j]) + ((U32) WeightedDiff); ; ; Both the multiply and the add of the WeightedDiff array base are ; effected by a table lookup into the array MulByNeg8. ; ; Then the SWD of a reference macroblock can be calculated as follows: ; ; SWD = 0; ; for each match point (i,j) ; SWD += *((U32 *) (N8T[i][j] + 8 * Ref[i][j])); ; ; In assembly, the fetch of WeightedDiff array element amounts to this: ; ; mov edi,DWORD PTR N8T[i][j] ; Fetch N8T[i][j] ; mov dl,BYTE PTR Ref[i][j] ; Fetch Ref[i][j] ; mov edi,DWORD PTR[edi+edx*8] ; Fetch WeithtedDiff of target & ref. ; ; 3) We calculate the 0-motion SWD, as described just above. We use 32 ; match points per block, and write the result seperately for each ; block. The result is accumulated into the high half of ebp. ; ; 4) If the SWD for the 0-motion vector is below a threshold, we don't ; bother searching for other possibly better motion vectors. Presently, ; this threshold is set such that an average difference of less than ; three per match point causes the 0-motion vector to be accepted. ; ; Register usage for this section: ; ; Input of this section: ; ; edx -- MBlockActionStream ; ; Predominate usage for body of this section: ; ; esi -- Target block address. ; edi -- 0-motion reference block address. ; ebp[ 0:12] -- Accumulator for target pels. ; ebp[13:15] -- Loop control ; ebp[16:31] -- Accumulator for weighted diff between target and 0-MV ref. ; edx -- Address at which to store -8 times pels. ; ecx -- A reference pel. ; ebx -- A target pel. ; eax -- A target pel times -8; and a weighted difference. ; ; Expected Pentium (tm) microprocessor performance for section: ; ; Executed once per macroblock. ; ; 520 clocks for instruction execution ; 8 clocks for bank conflicts (64 dual mem ops with 1/8 chance of conflict) ; 80 clocks generously estimated for an average of 8 cache line fills for ; the target macroblock and 8 cache line fills for the reference area. ; ---- ; 608 clocks total time for this section. ; NextMacroBlock: mov bl,[edx].CodedBlocks add edx,SIZEOF T_MacroBlockActionDescr and ebx,000000040H ; Check for end-of-stream jne Done FirstMacroBlock: mov cl,[edx].CodedBlocks ; Init CBP for macroblock. mov ebp,TargetFrameBaseAddress mov bl,[edx].FirstMEState ; First State mov eax,DoRadius15Search ; Searching 15 full pels out, or just 7? neg al ; doing blk lvl => al=0, not => al=-1 or cl,03FH ; Indicate all 6 blocks are coded. and al,bl mov esi,[edx].BlkY1.BlkOffset ; Get address of next macroblock to do. cmp al,5 jne @f mov bl,50 ; Cause us to search +/- 15 if central ; ; block and willing to go that far. @@: mov edi,TargToRef add esi,ebp mov CurrSWDState,ebx ; Stash First State Number as current. add edi,esi xor ebp,ebp mov TargetMBAddr,esi ; Stash address of target macroblock. mov MBlockActionStream,edx ; Stash list ptr. mov [edx].CodedBlocks,cl mov ecx,INTER1MV ; Speculate INTER-coding, 1 motion vector. mov [edx].BlockType,cl lea edx,Block1 PrepMatchPointsNextBlock: mov bl,PB [esi+6] ; 06A -- Target Pel 00. add ebp,ebx ; 06B -- Accumulate target pels. mov cl,PB [edi+6] ; 06C -- Reference Pel 00. mov eax,MulByNeg8[ebx*4] ; 06D -- Target Pel 00 * -8. mov bl,PB [esi+4] ; 04A mov [edx].N8T06,eax ; 06E -- Store negated quadrupled Pel 00. add ebp,ebx ; 04B mov eax,PD [eax+ecx*8] ; 06F -- Weighted difference for Pel 00. mov cl,PB [edi+4] ; 04C add ebp,eax ; 06G -- Accumulate weighted difference. mov eax,MulByNeg8[ebx*4] ; 04D mov bl,PB [esi+2] ; 02A mov [edx].N8T04,eax ; 04E add ebp,ebx ; 02B mov eax,PD [eax+ecx*8] ; 04F mov cl,PB [edi+2] ; 02C add ebp,eax ; 04G mov eax,MulByNeg8[ebx*4] ; 02D mov bl,PB [esi] ; 00A mov [edx].N8T02,eax ; 02E add ebp,ebx ; 00B mov eax,PD [eax+ecx*8] ; 02F add esi,PITCH+1 mov cl,PB [edi] ; 00C add edi,PITCH+1 lea ebp,[ebp+eax+000004000H] ; 02G (plus loop control) mov eax,MulByNeg8[ebx*4] ; 00D mov bl,PB [esi+6] ; 17A mov [edx].N8T00,eax ; 00E add ebp,ebx ; 17B mov eax,PD [eax+ecx*8] ; 00F mov cl,PB [edi+6] ; 17C add ebp,eax ; 00G mov eax,MulByNeg8[ebx*4] ; 17D mov bl,PB [esi+4] ; 15A mov [edx].N8T17,eax ; 17E add ebp,ebx ; 15B mov eax,PD [eax+ecx*8] ; 17F mov cl,PB [edi+4] ; 15C add ebp,eax ; 17G mov eax,MulByNeg8[ebx*4] ; 15D mov bl,PB [esi+2] ; 13A mov [edx].N8T15,eax ; 15E add ebp,ebx ; 13B mov eax,PD [eax+ecx*8] ; 15F mov cl,PB [edi+2] ; 13C add ebp,eax ; 15G mov eax,MulByNeg8[ebx*4] ; 13D mov bl,PB [esi] ; 11A mov [edx].N8T13,eax ; 13E add ebp,ebx ; 11B mov eax,PD [eax+ecx*8] ; 13F add esi,PITCH-1 mov cl,PB [edi] ; 11C add edi,PITCH-1 add ebp,eax ; 13G mov eax,MulByNeg8[ebx*4] ; 11D mov bl,PB [esi+6] ; 26A mov [edx].N8T11,eax ; 11E add ebp,ebx ; 26B mov eax,PD [eax+ecx*8] ; 11F mov cl,PB [edi+6] ; 26C add ebp,eax ; 11G mov eax,MulByNeg8[ebx*4] ; 26D mov bl,PB [esi+4] ; 24A mov [edx].N8T26,eax ; 26E add ebp,ebx ; 24B mov eax,PD [eax+ecx*8] ; 26F mov cl,PB [edi+4] ; 24C add ebp,eax ; 26G mov eax,MulByNeg8[ebx*4] ; 24D mov bl,PB [esi+2] ; 22A mov [edx].N8T24,eax ; 24E add ebp,ebx ; 22B mov eax,PD [eax+ecx*8] ; 24F mov cl,PB [edi+2] ; 22C add ebp,eax ; 24G mov eax,MulByNeg8[ebx*4] ; 22D mov bl,PB [esi] ; 20A mov [edx].N8T22,eax ; 22E add ebp,ebx ; 20B mov eax,PD [eax+ecx*8] ; 22F add esi,PITCH+1 mov cl,PB [edi] ; 20C add edi,PITCH+1 add ebp,eax ; 22G mov eax,MulByNeg8[ebx*4] ; 20D mov bl,PB [esi+6] ; 37A mov [edx].N8T20,eax ; 20E add ebp,ebx ; 37B mov eax,PD [eax+ecx*8] ; 20F mov cl,PB [edi+6] ; 37C add ebp,eax ; 20G mov eax,MulByNeg8[ebx*4] ; 37D mov bl,PB [esi+4] ; 35A mov [edx].N8T37,eax ; 37E add ebp,ebx ; 35B mov eax,PD [eax+ecx*8] ; 37F mov cl,PB [edi+4] ; 35C add ebp,eax ; 37G mov eax,MulByNeg8[ebx*4] ; 35D mov bl,PB [esi+2] ; 33A mov [edx].N8T35,eax ; 35E add ebp,ebx ; 33B mov eax,PD [eax+ecx*8] ; 35F mov cl,PB [edi+2] ; 33C add ebp,eax ; 35G mov eax,MulByNeg8[ebx*4] ; 33D mov bl,PB [esi] ; 31A mov [edx].N8T33,eax ; 33E add ebp,ebx ; 31B mov eax,PD [eax+ecx*8] ; 33F add esi,PITCH-1 mov cl,PB [edi] ; 31C add edi,PITCH-1 add ebp,eax ; 33G mov eax,MulByNeg8[ebx*4] ; 31D mov bl,PB [esi+6] ; 46A mov [edx].N8T31,eax ; 31E add ebp,ebx ; 46B mov eax,PD [eax+ecx*8] ; 31F mov cl,PB [edi+6] ; 46C add ebp,eax ; 31G mov eax,MulByNeg8[ebx*4] ; 46D mov bl,PB [esi+4] ; 44A mov [edx].N8T46,eax ; 46E add ebp,ebx ; 44B mov eax,PD [eax+ecx*8] ; 46F mov cl,PB [edi+4] ; 44C add ebp,eax ; 46G mov eax,MulByNeg8[ebx*4] ; 44D mov bl,PB [esi+2] ; 42A mov [edx].N8T44,eax ; 44E add ebp,ebx ; 42B mov eax,PD [eax+ecx*8] ; 44F mov cl,PB [edi+2] ; 42C add ebp,eax ; 44G mov eax,MulByNeg8[ebx*4] ; 42D mov bl,PB [esi] ; 40A mov [edx].N8T42,eax ; 42E add ebp,ebx ; 40B mov eax,PD [eax+ecx*8] ; 42F add esi,PITCH+1 mov cl,PB [edi] ; 40C add edi,PITCH+1 add ebp,eax ; 42G mov eax,MulByNeg8[ebx*4] ; 40D mov bl,PB [esi+6] ; 57A mov [edx].N8T40,eax ; 40E add ebp,ebx ; 57B mov eax,PD [eax+ecx*8] ; 40F mov cl,PB [edi+6] ; 57C add ebp,eax ; 40G mov eax,MulByNeg8[ebx*4] ; 57D mov bl,PB [esi+4] ; 55A mov [edx].N8T57,eax ; 57E add ebp,ebx ; 55B mov eax,PD [eax+ecx*8] ; 57F mov cl,PB [edi+4] ; 55C add ebp,eax ; 57G mov eax,MulByNeg8[ebx*4] ; 55D mov bl,PB [esi+2] ; 53A mov [edx].N8T55,eax ; 55E add ebp,ebx ; 53B mov eax,PD [eax+ecx*8] ; 55F mov cl,PB [edi+2] ; 53C add ebp,eax ; 55G mov eax,MulByNeg8[ebx*4] ; 53D mov bl,PB [esi] ; 51A mov [edx].N8T53,eax ; 53E add ebp,ebx ; 51B mov eax,PD [eax+ecx*8] ; 53F add esi,PITCH-1 mov cl,PB [edi] ; 51C add edi,PITCH-1 add ebp,eax ; 53G mov eax,MulByNeg8[ebx*4] ; 51D mov bl,PB [esi+6] ; 66A mov [edx].N8T51,eax ; 51E add ebp,ebx ; 66B mov eax,PD [eax+ecx*8] ; 51F mov cl,PB [edi+6] ; 66C add ebp,eax ; 51G mov eax,MulByNeg8[ebx*4] ; 66D mov bl,PB [esi+4] ; 64A mov [edx].N8T66,eax ; 66E add ebp,ebx ; 64B mov eax,PD [eax+ecx*8] ; 66F mov cl,PB [edi+4] ; 64C add ebp,eax ; 66G mov eax,MulByNeg8[ebx*4] ; 64D mov bl,PB [esi+2] ; 62A mov [edx].N8T64,eax ; 64E add ebp,ebx ; 62B mov eax,PD [eax+ecx*8] ; 64F mov cl,PB [edi+2] ; 62C add ebp,eax ; 64G mov eax,MulByNeg8[ebx*4] ; 62D mov bl,PB [esi] ; 60A mov [edx].N8T62,eax ; 62E add ebp,ebx ; 60B mov eax,PD [eax+ecx*8] ; 62F add esi,PITCH+1 mov cl,PB [edi] ; 60C add edi,PITCH+1 add ebp,eax ; 62G mov eax,MulByNeg8[ebx*4] ; 60D mov bl,PB [esi+6] ; 77A mov [edx].N8T60,eax ; 60E add ebp,ebx ; 77B mov eax,PD [eax+ecx*8] ; 60F mov cl,PB [edi+6] ; 77C add ebp,eax ; 60G mov eax,MulByNeg8[ebx*4] ; 77D mov bl,PB [esi+4] ; 75A mov [edx].N8T77,eax ; 77E add ebp,ebx ; 75B mov eax,PD [eax+ecx*8] ; 77F mov cl,PB [edi+4] ; 75C add ebp,eax ; 77G mov eax,MulByNeg8[ebx*4] ; 75D mov bl,PB [esi+2] ; 73A mov [edx].N8T75,eax ; 75E add ebp,ebx ; 73B mov eax,PD [eax+ecx*8] ; 75F mov cl,PB [edi+2] ; 73C add ebp,eax ; 75G mov eax,MulByNeg8[ebx*4] ; 73D mov bl,PB [esi] ; 71A mov [edx].N8T73,eax ; 73E add ebp,ebx ; 71B mov eax,PD [eax+ecx*8] ; 73F mov cl,PB [edi] ; 71C add esi,PITCH-1-PITCH*8+8 add edi,PITCH-1-PITCH*8+8 add ebp,eax ; 73G mov eax,MulByNeg8[ebx*4] ; 71D mov ebx,ebp mov [edx].N8T71,eax ; 71E and ebx,000001FFFH ; Extract sum of target pels. add edx,BlockLen ; Move to next output block mov eax,PD [eax+ecx*8] ; 71F mov [edx-BlockLen].AccumTargetPels,ebx ; Store acc of target pels for block. add eax,ebp ; 71G and ebp,000006000H ; Extract loop control shr eax,16 ; Extract SWD; CF == 1 every second iter. mov ebx,ecx mov [edx-BlockLen].CentralInterSWD,eax ; Store SWD for 0-motion vector. jnc PrepMatchPointsNextBlock add esi,PITCH*8-16 ; Advance to block 3, or off end. add edi,PITCH*8-16 ; Advance to block 3, or off end. xor ebp,000002000H jne PrepMatchPointsNextBlock ; Jump if advancing to block 3. mov ebx,CurrSWDState ; Fetch First State Number for engine. mov edi,Block1.CentralInterSWD test bl,bl ; Test for INTRA-BY-DECREE. je IntraByDecree add eax,Block2.CentralInterSWD add edi,Block3.CentralInterSWD add eax,edi mov edx,ZeroVectorThreshold cmp eax,edx ; Compare 0-MV against ZeroVectorThresh jle BelowZeroThresh ; Jump if 0-MV is good enough. mov cl,PB SWDState[ebx*8+3] ; cl == Index of inc to apply to central ; ; point to get to ref1. mov bl,PB SWDState[ebx*8+5] ; bl == Same as cl, but for ref2. mov edx,TargToRef mov MB0MVInterSWD,eax ; Stash SWD for zero motion vector. mov edi,PD OffsetToRef[ebx] ; Get inc to apply to ctr to get to ref2. mov ebp,PD OffsetToRef[ecx] ; Get inc to apply to ctr to get to ref1. lea esi,[esi+edx-PITCH*16] ; Calculate address of 0-MV ref block. ; mov MBAddrCentralPoint,esi ; Set central point to 0-MV. mov MBCentralInterSWD,eax mov eax,Block1.CentralInterSWD ; Stash Zero MV SWD, in case we decide mov edx,Block2.CentralInterSWD ; the best non-zero MV isn't enough mov Block1.ZeroMVInterSWD,eax ; better than the zero MV. mov Block2.ZeroMVInterSWD,edx mov eax,Block3.CentralInterSWD mov edx,Block4.CentralInterSWD mov Block3.ZeroMVInterSWD,eax mov Block4.ZeroMVInterSWD,edx ; Activity Details for this section of code (refer to flow diagram above): ; ; 5) The SWD for two different reference macroblocks is calculated; ref1 ; into the high order 16 bits of ebp, and ref2 into the low 16 bits. ; This is performed for each iteration of the state engine. A normal, ; internal macroblock will perform 6 iterations, searching +/- 4 ; horizontally, then +/- 4 vertically, then +/- 2 horizontally, then ; +/- 2 vertically, then +/- 1 horizontally, then +/- 1 vertically. ; ; Register usage for this section: ; ; Input: ; ; esi -- Addr of 0-motion macroblock in ref frame. ; ebp -- Increment to apply to get to first ref1 macroblock. ; edi -- Increment to apply to get to first ref2 macroblock. ; ebx, ecx -- High order 24 bits are zero. ; ; Output: ; ; ebp -- SWD for the best-fit reference macroblock. ; ebx -- Index of increment to apply to get to best-fit reference MB. ; MBAddrCentralPoint -- the best-fit of the previous iteration; it is the ; value to which OffsetToRef[ebx] must be added. ; ; ; Expected performance for SWDLoop code: ; ; Execution frequency: Six times per block for which motion analysis is done ; beyond the 0-motion vector. ; ; Pentium (tm) microprocessor times per six iterations: ; 180 clocks for instruction execution setup to DoSWDLoop ; 2520 clocks for DoSWDLoop procedure, instruction execution. ; 192 clocks for bank conflicts in DoSWDLoop ; 30 clocks generously estimated for an average of 6 cache line fills for ; the reference area. ; ---- ; 2922 clocks total time for this section. MBFullPelMotionSearchLoop: lea edi,[esi+edi+PITCH*8+8] lea esi,[esi+ebp+PITCH*8+8] mov Block4.Ref1Addr,esi mov Block4.Ref2Addr,edi sub esi,8 sub edi,8 mov Block3.Ref1Addr,esi mov Block3.Ref2Addr,edi sub esi,PITCH*8-8 sub edi,PITCH*8-8 mov Block2.Ref1Addr,esi mov Block2.Ref2Addr,edi sub esi,8 sub edi,8 mov Block1.Ref1Addr,esi mov Block1.Ref2Addr,edi ; esi -- Points to ref1 ; edi -- Points to ref2 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero call DoSWDLoop ; ebp -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero mov esi,MBCentralInterSWD ; Get SWD for central point of these 3 refs xor eax,eax add ebp,Block1.Ref1InterSWD add edx,Block1.Ref2InterSWD add ebp,Block2.Ref1InterSWD add edx,Block2.Ref2InterSWD add ebp,Block3.Ref1InterSWD add edx,Block3.Ref2InterSWD cmp ebp,edx ; Carry flag == 1 iff ref1 SWD < ref2 SWD. mov edi,CurrSWDState ; Restore current state number. adc eax,eax ; eax == 1 iff ref1 SWD < ref2 SWD. cmp ebp,esi ; Carry flag == 1 iff ref1 SWD < central SWD. adc eax,eax ; cmp edx,esi ; Carry flag == 1 iff ref2 SWD < central SWD. adc eax,eax ; 0 --> Pick central point. ; ; 1 --> Pick ref2. ; ; 2 --> Not possible. ; ; 3 --> Pick ref2. ; ; 4 --> Pick central point. ; ; 5 --> Not possible. ; ; 6 --> Pick ref1. ; ; 7 --> Pick ref1. mov MBRef2InterSWD,edx mov MBRef1InterSWD,ebp xor edx,edx mov dl,PB PickPoint[eax] ; dl == 0: central pt; 2: ref1; 4: ref2 mov esi,MBAddrCentralPoint ; Reload address of central ref block. ; ; mov ebp,Block1.CentralInterSWD[edx*2] ; Get SWD for each block, picked pt. mov al,PB SWDState[edx+edi*8+1] ; al == Index of inc to apply to old central ; ; point to get new central point. mov Block1.CentralInterSWD,ebp ; Stash SWD for new central point. mov ebp,Block2.CentralInterSWD[edx*2] mov Block2.CentralInterSWD,ebp mov ebp,Block3.CentralInterSWD[edx*2] mov Block3.CentralInterSWD,ebp mov ebp,Block4.CentralInterSWD[edx*2] mov Block4.CentralInterSWD,ebp mov ebp,MBCentralInterSWD[edx*2]; Get the SWD for the point we picked. mov dl,PB SWDState[edx+edi*8] ; dl == New state number. mov MBCentralInterSWD,ebp ; Stash SWD for new central point. mov edi,PD OffsetToRef[eax] ; Get inc to apply to get to new central pt. mov CurrSWDState,edx ; Stash current state number. mov bl,PB SWDState[edx*8+3] ; bl == Index of inc to apply to central ; ; point to get to next ref1. mov cl,PB SWDState[edx*8+5] ; cl == Same as bl, but for ref2. add esi,edi ; Move to new central point. test dl,dl mov ebp,PD OffsetToRef[ebx] ; Get inc to apply to ctr to get to ref1. mov edi,PD OffsetToRef[ecx] ; Get inc to apply to ctr to get to ref2. mov MBAddrCentralPoint,esi ; Stash address of new central ref block. jne MBFullPelMotionSearchLoop ; Jump if not done searching. ;Done searching for integer motion vector for full macroblock IF PITCH-384 *** Error: The magic leaks out of the following code if PITCH isn't 384. ENDIF mov ecx,TargToRef ; To Linearize MV for winning ref blk. mov eax,esi ; Copy of ref macroblock addr. sub eax,ecx ; To Linearize MV for winning ref blk. mov ecx,TargetMBAddr sub eax,ecx mov edx,MBlockActionStream ; Fetch list ptr. mov ebx,eax mov ebp,DoHalfPelEstimation ; Are we doing half pel motion estimation? shl eax,25 ; Extract horz motion component. mov [edx].BlkY1.PastRef,esi ; Save address of reference MB selected. sar ebx,8 ; Hi 24 bits of linearized MV lookup vert MV. mov ecx,MBCentralInterSWD sar eax,24 ; Finish extract horz motion component. test ebp,ebp mov bl,PB UnlinearizedVertMV[ebx] ; Look up proper vert motion vector. mov [edx].BlkY1.PHMV,al ; Save winning horz motion vector. mov [edx].BlkY1.PVMV,bl ; Save winning vert motion vector. IFDEF H261 ELSE je SkipHalfPelSearch_1MV ;Search for half pel motion vector for full macroblock. mov Block1.AddrCentralPoint,esi lea ebp,[esi+8] mov Block2.AddrCentralPoint,ebp add ebp,PITCH*8-8 mov Block3.AddrCentralPoint,ebp xor ecx,ecx mov cl,[edx].FirstMEState add ebp,8 mov edi,esi mov Block4.AddrCentralPoint,ebp mov ebp,InitHalfPelSearchHorz[ecx*4-4] ; ebp -- Initialized to 0, except when can't search off left or right edge. ; edi -- Ref addr for block 1. Ref1 is .5 pel to left. Ref2 is .5 to right. call DoSWDHalfPelHorzLoop ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 mov esi,MBlockActionStream xor eax,eax ; Keep pairing happy add ecx,Block1.Ref1InterSWD add edx,Block1.Ref2InterSWD add ecx,Block2.Ref1InterSWD add edx,Block2.Ref2InterSWD add ecx,Block3.Ref1InterSWD add edx,Block3.Ref2InterSWD mov bl,[esi].FirstMEState mov edi,Block1.AddrCentralPoint cmp ecx,edx jl MBHorz_Ref1LTRef2 mov ebp,MBCentralInterSWD mov esi,MBlockActionStream sub ebp,edx jle MBHorz_CenterBest mov al,[esi].BlkY1.PHMV ; Half pel to the right is best. mov ecx,Block1.Ref2InterSWD mov Block1.CentralInterSWD_BLS,ecx mov ecx,Block3.Ref2InterSWD mov Block3.CentralInterSWD_BLS,ecx mov ecx,Block2.Ref2InterSWD mov Block2.CentralInterSWD_BLS,ecx mov ecx,Block4.Ref2InterSWD mov Block4.CentralInterSWD_BLS,ecx inc al mov [esi].BlkY1.PHMV,al jmp MBHorz_Done MBHorz_CenterBest: mov ecx,Block1.CentralInterSWD xor ebp,ebp mov Block1.CentralInterSWD_BLS,ecx mov ecx,Block2.CentralInterSWD mov Block2.CentralInterSWD_BLS,ecx mov ecx,Block3.CentralInterSWD mov Block3.CentralInterSWD_BLS,ecx mov ecx,Block4.CentralInterSWD mov Block4.CentralInterSWD_BLS,ecx jmp MBHorz_Done MBHorz_Ref1LTRef2: mov ebp,MBCentralInterSWD mov esi,MBlockActionStream sub ebp,ecx jle MBHorz_CenterBest mov al,[esi].BlkY1.PHMV ; Half pel to the left is best. mov edx,[esi].BlkY1.PastRef dec al mov ecx,Block1.Ref1InterSWD mov Block1.CentralInterSWD_BLS,ecx mov ecx,Block3.Ref1InterSWD mov Block3.CentralInterSWD_BLS,ecx mov ecx,Block2.Ref1InterSWD mov Block2.CentralInterSWD_BLS,ecx mov ecx,Block4.Ref1InterSWD mov Block4.CentralInterSWD_BLS,ecx dec edx mov [esi].BlkY1.PHMV,al mov [esi].BlkY1.PastRef,edx MBHorz_Done: mov HalfPelHorzSavings,ebp mov ebp,InitHalfPelSearchVert[ebx*4-4] ; ebp -- Initialized to 0, except when can't search off left or right edge. ; edi -- Ref addr for block 1. Ref1 is .5 pel above. Ref2 is .5 below. call DoSWDHalfPelVertLoop ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 add ecx,Block1.Ref1InterSWD add edx,Block1.Ref2InterSWD add ecx,Block2.Ref1InterSWD add edx,Block2.Ref2InterSWD add ecx,Block3.Ref1InterSWD add edx,Block3.Ref2InterSWD cmp ecx,edx jl MBVert_Ref1LTRef2 mov ebp,MBCentralInterSWD mov esi,MBlockActionStream sub ebp,edx jle MBVert_CenterBest mov ecx,Block1.CentralInterSWD mov edx,Block1.Ref2InterSWD sub ecx,edx mov edx,Block1.CentralInterSWD_BLS sub edx,ecx mov al,[esi].BlkY1.PVMV ; Half pel below is best. mov Block1.CentralInterSWD,edx inc al mov ecx,Block3.CentralInterSWD mov edx,Block3.Ref2InterSWD sub ecx,edx mov edx,Block3.CentralInterSWD_BLS sub edx,ecx mov ecx,Block2.CentralInterSWD mov Block3.CentralInterSWD,edx mov edx,Block2.Ref2InterSWD sub ecx,edx mov edx,Block2.CentralInterSWD_BLS sub edx,ecx mov ecx,Block4.CentralInterSWD mov Block2.CentralInterSWD,edx mov edx,Block4.Ref2InterSWD sub ecx,edx mov edx,Block4.CentralInterSWD_BLS sub edx,ecx mov [esi].BlkY1.PVMV,al mov Block4.CentralInterSWD,edx jmp MBVert_Done MBVert_CenterBest: mov ecx,Block1.CentralInterSWD_BLS xor ebp,ebp mov Block1.CentralInterSWD,ecx mov ecx,Block2.CentralInterSWD_BLS mov Block2.CentralInterSWD,ecx mov ecx,Block3.CentralInterSWD_BLS mov Block3.CentralInterSWD,ecx mov ecx,Block4.CentralInterSWD_BLS mov Block4.CentralInterSWD,ecx jmp MBVert_Done MBVert_Ref1LTRef2: mov ebp,MBCentralInterSWD mov esi,MBlockActionStream sub ebp,ecx jle MBVert_CenterBest mov ecx,Block1.CentralInterSWD mov edx,Block1.Ref1InterSWD sub ecx,edx mov edx,Block1.CentralInterSWD_BLS sub edx,ecx mov al,[esi].BlkY1.PVMV ; Half pel above is best. mov Block1.CentralInterSWD,edx dec al mov ecx,Block3.CentralInterSWD mov edx,Block3.Ref1InterSWD sub ecx,edx mov edx,Block3.CentralInterSWD_BLS sub edx,ecx mov ecx,Block2.CentralInterSWD mov Block3.CentralInterSWD,edx mov edx,Block2.Ref1InterSWD sub ecx,edx mov edx,Block2.CentralInterSWD_BLS sub edx,ecx mov ecx,Block4.CentralInterSWD mov Block2.CentralInterSWD,edx mov edx,Block4.Ref1InterSWD sub ecx,edx mov edx,Block4.CentralInterSWD_BLS sub edx,ecx mov ecx,[esi].BlkY1.PastRef mov Block4.CentralInterSWD,edx sub ecx,PITCH mov [esi].BlkY1.PVMV,al mov [esi].BlkY1.PastRef,ecx MBVert_Done: mov ecx,HalfPelHorzSavings mov edx,esi add ebp,ecx ; Savings for horz and vert half pel motion. mov ecx,MBCentralInterSWD ; Reload SWD for new central point. sub ecx,ebp ; Approx SWD for prescribed half pel motion. mov esi,[edx].BlkY1.PastRef ; Reload address of reference MB selected. mov MBCentralInterSWD,ecx SkipHalfPelSearch_1MV: ENDIF ; H263 mov ebp,[edx].BlkY1.MVs ; Load Motion Vectors add esi,8 mov [edx].BlkY2.PastRef,esi mov [edx].BlkY2.MVs,ebp lea edi,[esi+PITCH*8] add esi,PITCH*8-8 mov [edx].BlkY3.PastRef,esi mov [edx].BlkY3.MVs,ebp mov [edx].BlkY4.PastRef,edi mov [edx].BlkY4.MVs,ebp IFDEF H261 ELSE ; H263 mov MBMotionVectors,ebp ; Stash macroblock level motion vectors. mov ebp,640 ; ??? BlockMVDifferential cmp ecx,ebp jl NoBlockMotionVectors mov ecx,DoBlockLevelVectors test ecx,ecx ; Are we doing block level motion vectors? je NoBlockMotionVectors ; Activity Details for this section of code (refer to flow diagram above): ; ; The following search is done similarly to the searches done above, except ; these are block searches, instead of macroblock searches. ; ; Expected performance: ; ; Execution frequency: Six times per block for which motion analysis is done ; beyond the 0-motion vector. ; ; Pentium (tm) microprocessor times per six iterations: ; 180 clocks for instruction execution setup to DoSWDLoop ; 2520 clocks for DoSWDLoop procedure, instruction execution. ; 192 clocks for bank conflicts in DoSWDLoop ; 30 clocks generously estimated for an average of 6 cache line fills for ; the reference area. ; ---- ; 2922 clocks total time for this section. ; ; Set up for the "BlkFullPelSWDLoop_4blks" loop to follow. ; - Store the SWD values for blocks 4, 3, 2, 1. ; - Compute and store the address of the central reference ; point for blocks 1, 2, 3, 4. ; - Compute and store the first address for ref 1 (minus 4 ; pels horizontally) and ref 2 (plus 4 pels horizontally) ; for blocks 4, 3, 2, 1 (in that order). ; - Initialize MotionOffsetsCursor ; - On exit: ; esi = ref 1 address for block 1 ; edi = ref 2 address for block 1 ; mov esi,Block4.CentralInterSWD mov edi,Block3.CentralInterSWD mov Block4.CentralInterSWD_BLS,esi mov Block3.CentralInterSWD_BLS,edi mov esi,Block2.CentralInterSWD mov edi,Block1.CentralInterSWD mov Block2.CentralInterSWD_BLS,esi mov eax,MBAddrCentralPoint ; Reload addr of central, integer pel ref MB. mov Block1.CentralInterSWD_BLS,edi mov Block1.AddrCentralPoint,eax lea edi,[eax+PITCH*8+8+1] lea esi,[eax+PITCH*8+8-1] mov Block4.Ref1Addr,esi mov Block4.Ref2Addr,edi sub esi,8 add eax,8 mov Block2.AddrCentralPoint,eax add eax,PITCH*8-8 mov Block3.AddrCentralPoint,eax add eax,8 mov Block4.AddrCentralPoint,eax sub edi,8 mov Block3.Ref1Addr,esi mov Block3.Ref2Addr,edi sub esi,PITCH*8-8 sub edi,PITCH*8-8 mov Block2.Ref1Addr,esi mov Block2.Ref2Addr,edi sub esi,8 mov eax,OFFSET MotionOffsets mov MotionOffsetsCursor,eax sub edi,8 mov Block1.Ref1Addr,esi mov Block1.Ref2Addr,edi ; ; This loop will execute 6 times: ; +- 4 pels horizontally ; +- 4 pels vertically ; +- 2 pels horizontally ; +- 2 pels vertically ; +- 1 pel horizontally ; +- 1 pel vertically ; It terminates when ref1 = ref2. This simple termination ; condition is what forces unrestricted motion vectors (UMV) ; to be ON when advanced prediction (4MV) is ON. Otherwise ; we would need a state engine as above to distinguish edge ; pels. ; BlkFullPelSWDLoop_4blks: ; esi -- Points to ref1 ; edi -- Points to ref2 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero call DoSWDLoop ; ebp -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero mov eax,MotionOffsetsCursor BlkFullPelSWDLoop_1blk: xor esi,esi cmp ebp,edx ; CF == 1 iff ref1 SWD < ref2 SWD. mov edi,BlockNM1.CentralInterSWD_BLS; Get SWD for central pt of these 3 refs adc esi,esi ; esi == 1 iff ref1 SWD < ref2 SWD. cmp ebp,edi ; CF == 1 iff ref1 SWD < central SWD. mov ebp,BlockNM2.Ref1InterSWD ; Fetch next block's Ref1 SWD. adc esi,esi cmp edx,edi ; CF == 1 iff ref2 SWD < central SWD. adc esi,esi ; 0 --> Pick central point. ; ; 1 --> Pick ref2. ; ; 2 --> Not possible. ; ; 3 --> Pick ref2. ; ; 4 --> Pick central point. ; ; 5 --> Not possible. ; ; 6 --> Pick ref1. ; ; 7 --> Pick ref1. mov edx,BlockNM2.Ref2InterSWD ; Fetch next block's Ref2 SWD. sub esp,BlockLen ; Move ahead to next block. mov edi,[eax] ; Next ref2 motion vector offset. mov cl,PickPoint_BLS[esi] ; cl == 6: central pt; 2: ref1; 4: ref2 mov ebx,esp ; For testing completion. ; ; mov esi,BlockN.AddrCentralPoint[ecx*2-12] ; Get the addr for pt we picked. mov ecx,BlockN.CentralInterSWD[ecx*2] ; Get the SWD for point we picked. mov BlockN.AddrCentralPoint,esi ; Stash addr for new central point. sub esi,edi ; Compute next ref1 addr. mov BlockN.Ref1Addr,esi ; Stash next ref1 addr. mov BlockN.CentralInterSWD_BLS,ecx ; Stash the SWD for central point. lea edi,[esi+edi*2] ; Compute next ref2 addr. xor ecx,ecx mov BlockN.Ref2Addr,edi ; Stash next ref2 addr. and ebx,00000001FH ; Done when esp at 32-byte bound. jne BlkFullPelSWDLoop_1blk add esp,BlockLen*4 add eax,4 ; Advance MotionOffsets pointer. mov MotionOffsetsCursor,eax cmp esi,edi jne BlkFullPelSWDLoop_4blks IF PITCH-384 *** Error: The magic leaks out of the following code if PITCH isn't 384. ENDIF ; ; The following code has been modified to correctly decode the motion vectors ; The previous code was simply subtracting the target frame base address ; from the chosen (central) reference block address. ; What is now done is the begining reference macroblock address computed ; in ebp, then subtracted from the chosen (central) reference block address. ; Then, for blocks 2, 3, and 4, the distance from block 1 to that block ; is subtracted. Care was taken to preserve the original pairing. ; mov esi,Block1.AddrCentralPoint ; B1a Reload address of central ref block. mov ebp,TargetMBAddr ; **** CHANGE **** addr. of target MB mov edi,Block2.AddrCentralPoint ; B2a add ebp,TargToRef ; **** CHANGE **** add Reference - Target ; mov ebp,PreviousFrameBaseAddress **** CHANGE **** DELETED mov Block1.Ref1Addr,esi ; B1b Stash addr central ref block. sub esi,ebp ; B1c Addr of ref blk, but in target frame. mov Block2.Ref1Addr,edi ; B2b sub edi,ebp ; B2c sub edi,8 ; **** CHANGE **** Correct for block 2 mov eax,esi ; B1e Copy linearized MV. sar esi,8 ; B1f High 24 bits of lin MV lookup vert MV. mov ebx,edi ; B2e sar edi,8 ; B2f add eax,eax ; B1g Sign extend HMV; *2 (# of half pels). mov Block1.BlkHMV,al ; B1h Save winning horz motion vector. add ebx,ebx ; B2g mov Block2.BlkHMV,bl ; B2h mov al,UnlinearizedVertMV[esi] ; B1i Look up proper vert motion vector. mov Block1.BlkVMV,al ; B1j Save winning vert motion vector. mov al,UnlinearizedVertMV[edi] ; B2i mov esi,Block3.AddrCentralPoint ; B3a mov edi,Block4.AddrCentralPoint ; B4a mov Block3.Ref1Addr,esi ; B3b mov Block4.Ref1Addr,edi ; B4b mov Block2.BlkVMV,al ; B2j sub esi,ebp ; B3c sub esi,8*PITCH ; **** CHANGE **** Correct for block 3 sub edi,ebp ; B4c sub edi,8*PITCH+8 ; **** CHANGE **** Correct for block 4 mov eax,esi ; B3e sar esi,8 ; B3f mov ebx,edi ; B4e sar edi,8 ; B4f add eax,eax ; B3g mov Block3.BlkHMV,al ; B3h add ebx,ebx ; B4g mov Block4.BlkHMV,bl ; B4h mov al,UnlinearizedVertMV[esi] ; B3i mov Block3.BlkVMV,al ; B3j mov al,UnlinearizedVertMV[edi] ; B4i mov ebp,Block1.CentralInterSWD_BLS mov ebx,Block2.CentralInterSWD_BLS add ebp,Block3.CentralInterSWD_BLS add ebx,Block4.CentralInterSWD_BLS add ebx,ebp mov Block4.BlkVMV,al ; B4j mov ecx,DoHalfPelEstimation mov MBCentralInterSWD_BLS,ebx test ecx,ecx je NoHalfPelBlockLevelMVs HalfPelBlockLevelMotionSearch: mov edi,Block1.AddrCentralPoint xor ebp,ebp ; ebp -- Initialized to 0, implying can search both left and right. ; edi -- Ref addr for block 1. Ref1 is .5 pel to left. Ref2 is .5 to right. call DoSWDHalfPelHorzLoop ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 NextBlkHorz: mov ebx,BlockNM1.CentralInterSWD_BLS cmp ecx,edx mov BlockNM1.HalfPelSavings,ebp jl BlkHorz_Ref1LTRef2 mov al,BlockNM1.BlkHMV sub esp,BlockLen sub ebx,edx jle BlkHorz_CenterBest inc al mov BlockN.HalfPelSavings,ebx mov BlockN.BlkHMV,al jmp BlkHorz_Done BlkHorz_Ref1LTRef2: mov al,BlockNM1.BlkHMV sub esp,BlockLen sub ebx,ecx jle BlkHorz_CenterBest mov ecx,BlockN.Ref1Addr dec al mov BlockN.HalfPelSavings,ebx dec ecx mov BlockN.BlkHMV,al mov BlockN.Ref1Addr,ecx BlkHorz_CenterBest: BlkHorz_Done: mov ecx,BlockNM1.Ref1InterSWD mov edx,BlockNM1.Ref2InterSWD test esp,000000018H jne NextBlkHorz mov edi,BlockN.AddrCentralPoint add esp,BlockLen*4 ; ebp -- Initialized to 0, implying search both up and down is okay. ; edi -- Ref addr for block 1. Ref1 is .5 pel above. Ref2 is .5 below. call DoSWDHalfPelVertLoop ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 NextBlkVert: mov ebx,BlockNM1.CentralInterSWD_BLS cmp ecx,edx mov edi,BlockNM1.HalfPelSavings jl BlkVert_Ref1LTRef2 mov al,BlockNM1.BlkVMV sub esp,BlockLen sub edx,ebx jge BlkVert_CenterBest inc al sub edi,edx mov BlockN.BlkVMV,al jmp BlkVert_Done BlkVert_Ref1LTRef2: mov al,BlockNM1.BlkVMV sub esp,BlockLen sub ecx,ebx jge BlkVert_CenterBest sub edi,ecx mov ecx,BlockN.Ref1Addr dec al sub ecx,PITCH mov BlockN.BlkVMV,al mov BlockN.Ref1Addr,ecx BlkVert_CenterBest: BlkVert_Done: mov ecx,BlockNM1.Ref1InterSWD sub ebx,edi mov BlockN.CentralInterSWD_BLS,ebx mov edx,BlockNM1.Ref2InterSWD test esp,000000018H lea ebp,[ebp+edi] jne NextBlkVert mov ebx,MBCentralInterSWD_BLS+BlockLen*4 add esp,BlockLen*4 sub ebx,ebp xor eax,eax ; ??? Keep pairing happy NoHalfPelBlockLevelMVs: mov eax,MBCentralInterSWD mov ecx,BlockMVDifferential sub eax,ebx mov edi,MB0MVInterSWD cmp eax,ecx jle BlockMVNotBigEnoughGain sub edi,ebx mov ecx,NonZeroMVDifferential cmp edi,ecx jle NonZeroMVNotBigEnoughGain ; Block motion vectors are best. mov MBCentralInterSWD,ebx ; Set MBlock's SWD to sum of 4 blocks. mov edx,MBlockActionStream mov eax,Block1.CentralInterSWD_BLS ; Set each block's SWD. mov ebx,Block2.CentralInterSWD_BLS mov Block1.CentralInterSWD,eax mov Block2.CentralInterSWD,ebx mov eax,Block3.CentralInterSWD_BLS mov ebx,Block4.CentralInterSWD_BLS mov Block3.CentralInterSWD,eax mov Block4.CentralInterSWD,ebx mov eax,Block1.BlkMVs ; Set each block's motion vector. mov ebx,Block2.BlkMVs mov [edx].BlkY1.MVs,eax mov [edx].BlkY2.MVs,ebx mov eax,Block3.BlkMVs mov ebx,Block4.BlkMVs mov [edx].BlkY3.MVs,eax mov [edx].BlkY4.MVs,ebx mov eax,Block1.Ref1Addr ; Set each block's reference blk addr. mov ebx,Block2.Ref1Addr mov [edx].BlkY1.PastRef,eax mov [edx].BlkY2.PastRef,ebx mov eax,Block3.Ref1Addr mov ebx,Block4.Ref1Addr mov [edx].BlkY3.PastRef,eax mov eax,INTER4MV ; Set type for MB to INTER-coded, 4 MVs. mov [edx].BlkY4.PastRef,ebx mov [edx].BlockType,al jmp MotionVectorSettled NoBlockMotionVectors: ENDIF ; H263 mov edi,MB0MVInterSWD BlockMVNotBigEnoughGain: ; Try MB-level motion vector. mov eax,MBCentralInterSWD mov ecx,NonZeroMVDifferential sub edi,eax mov edx,MBlockActionStream cmp edi,ecx jg MotionVectorSettled NonZeroMVNotBigEnoughGain: ; Settle on zero MV. mov eax,Block1.ZeroMVInterSWD ; Restore Zero MV SWD. mov edx,Block2.ZeroMVInterSWD mov Block1.CentralInterSWD,eax mov Block2.CentralInterSWD,edx mov eax,Block3.ZeroMVInterSWD mov edx,Block4.ZeroMVInterSWD mov Block3.CentralInterSWD,eax mov Block4.CentralInterSWD,edx mov eax,MB0MVInterSWD ; Restore SWD for zero motion vector. BelowZeroThresh: mov edx,MBlockActionStream mov ebx,TargetMBAddr ; Get address of this target macroblock. mov MBCentralInterSWD,eax ; Save SWD. xor ebp,ebp add ebx,TargToRef mov [edx].BlkY1.MVs,ebp ; Set horz and vert MVs to 0 in all blks. mov [edx].BlkY1.PastRef,ebx ; Save address of ref block, all blks. add ebx,8 mov [edx].BlkY2.PastRef,ebx mov [edx].BlkY2.MVs,ebp lea ecx,[ebx+PITCH*8] add ebx,PITCH*8-8 mov [edx].BlkY3.PastRef,ebx mov [edx].BlkY3.MVs,ebp mov [edx].BlkY4.PastRef,ecx mov [edx].BlkY4.MVs,ebp ; Activity Details for this section of code (refer to flow diagram above): ; ; 6) We've settled on the motion vector that will be used if we do indeed ; code the macroblock with inter-coding. We need to determine if some ; or all of the blocks can be forced as empty (copy). ; blocks. If all the blocks can be forced empty, we force the whole ; macroblock to be empty. ; ; Expected Pentium (tm) microprocessor performance for this section: ; ; Execution frequency: Once per macroblock. ; ; 23 clocks. ; MotionVectorSettled: IFDEF H261 mov edi,MBCentralInterSWD mov eax,DoSpatialFiltering ; Are we doing spatial filtering? mov edi,TargetMBAddr test eax,eax je SkipSpatialFiltering mov ebx,MBCentralInterSWD mov esi,SpatialFiltThreshold cmp ebx,esi jle SkipSpatialFiltering add edi,TargToSLF ; Compute addr at which to put SLF prediction. xor ebx,ebx mov esi,[edx].BlkY1.PastRef xor edx,edx mov ebp,16 xor ecx,ecx SpatialFilterHorzLoop: mov dl,[edi] ; Pre-load cache line for output. mov bl,[esi+6] ; p6 mov al,[esi+7] ; p7 inc bl ; p6+1 mov cl,[esi+5] ; p5 mov [edi+7],al ; p7' = p7 add al,bl ; p7 + p6 + 1 add bl,cl ; p6 + p5 + 1 mov dl,[esi+4] ; p4 add eax,ebx ; p7 + 2p6 + p5 + 2 shr eax,2 ; p6' = (p7 + 2p6 + p5 + 2) / 4 inc dl ; p4 + 1 add cl,dl ; p5 + p4 + 1 mov [edi+6],al ; p6' mov al,[esi+3] ; p3 add ebx,ecx ; p6 + 2p5 + p4 + 2 shr ebx,2 ; p5' = (p6 + 2p5 + p4 + 2) / 4 add dl,al ; p4 + p3 + 1 mov [edi+5],bl ; p5' mov bl,[esi+2] ; p2 add ecx,edx ; p5 + 2p4 + p3 + 2 inc bl ; p2 + 1 shr ecx,2 ; p4' = (p5 + 2p4 + p3 + 2) / 4 add al,bl ; p3 + p2 + 1 mov [edi+4],cl ; p4' add edx,eax ; p4 + 2p3 + p2 + 2 shr edx,2 ; p3' = (p4 + 2p3 + p2 + 2) / 4 mov cl,[esi+1] ; p1 add bl,cl ; p2 + p1 + 1 mov [edi+3],dl ; p3' add eax,ebx ; p3 + 2p2 + p1 + 2 mov dl,[esi] ; p0 shr eax,2 ; p2' = (p3 + 2p2 + p1 + 2) / 4 inc ebx ; p2 + p1 + 2 mov [edi+2],al ; p2' add ebx,ecx ; p2 + 2p1 + 2 mov [edi],dl ; p0' = p0 add ebx,edx ; p2 + 2p1 + p0 + 2 shr ebx,2 ; p1' = (p2 + 2p1 + p0 + 2) / 4 mov al,[esi+7+8] mov [edi+1],bl ; p1' mov bl,[esi+6+8] inc bl mov cl,[esi+5+8] mov [edi+7+8],al add al,bl add bl,cl mov dl,[esi+4+8] add eax,ebx ; shr eax,2 inc dl add cl,dl mov [edi+6+8],al mov al,[esi+3+8] add ebx,ecx shr ebx,2 add dl,al mov [edi+5+8],bl mov bl,[esi+2+8] add ecx,edx inc bl shr ecx,2 add al,bl mov [edi+4+8],cl add edx,eax shr edx,2 mov cl,[esi+1+8] add bl,cl mov [edi+3+8],dl add eax,ebx mov dl,[esi+8] shr eax,2 inc ebx mov [edi+2+8],al add ebx,ecx mov [edi+8],dl add ebx,edx shr ebx,2 add esi,PITCH mov [edi+1+8],bl add edi,PITCH dec ebp ; Done? jne SpatialFilterHorzLoop mov VertFilterDoneAddr,edi sub edi,PITCH*16 SpatialFilterVertLoop: mov eax,[edi] ; p0 ; ; Bank conflict for sure. ; mov ebx,[edi+PITCH] ; p1 add eax,ebx ; p0+p1 mov ecx,[edi+PITCH*2] ; p2 add ebx,ecx ; p1+p2 mov edx,[edi+PITCH*3] ; p3 shr eax,1 ; (p0+p1)/2 dirty mov esi,[edi+PITCH*4] ; p4 add ecx,edx ; p2+p3 mov ebp,[edi+PITCH*5] ; p5 shr ebx,1 ; (p1+p2)/2 dirty add edx,esi ; p3+p4 and eax,07F7F7F7FH ; (p0+p1)/2 clean and ebx,07F7F7F7FH ; (p1+p2)/2 clean and ecx,0FEFEFEFEH ; p2+p3 pre-cleaned and edx,0FEFEFEFEH ; p3+p4 pre-cleaned shr ecx,1 ; (p2+p3)/2 clean add esi,ebp ; p4+p5 shr edx,1 ; (p3+p4)/2 clean lea eax,[eax+ebx+001010101H] ; (p0+p1)/2+(p1+p2)/2+1 shr esi,1 ; (p4+p5)/2 dirty ; and esi,07F7F7F7FH ; (p4+p5)/2 clean lea ebx,[ebx+ecx+001010101H] ; (p1+p2)/2+(p2+p3)/2+1 shr eax,1 ; p1' = ((p0+p1)/2+(p1+p2)/2+1)/2 dirty lea ecx,[ecx+edx+001010101H] ; (p2+p3)/2+(p3+p4)/2+1 shr ebx,1 ; p2' = ((p1+p2)/2+(p2+p3)/2+1)/2 dirty lea edx,[edx+esi+001010101H] ; (p3+p4)/2+(p4+p5)/2+1 and eax,07F7F7F7FH ; p1' clean and ebx,07F7F7F7FH ; p2' clean shr ecx,1 ; p3' = ((p2+p3)/2+(p3+p4)/2+1)/2 dirty mov [edi+PITCH],eax ; p1' shr edx,1 ; p4' = ((p3+p4)/2+(p4+p5)/2+1)/2 dirty mov eax,[edi+PITCH*6] ; p6 and ecx,07F7F7F7FH ; p3' clean and edx,07F7F7F7FH ; p4' clean mov [edi+PITCH*2],ebx ; p2' add ebp,eax ; p5+p6 shr ebp,1 ; (p5+p6)/2 dirty mov ebx,[edi+PITCH*7] ; p7 add eax,ebx ; p6+p7 and ebp,07F7F7F7FH ; (p5+p6)/2 clean mov [edi+PITCH*3],ecx ; p3' and eax,0FEFEFEFEH ; (p6+p7)/2 pre-cleaned shr eax,1 ; (p6+p7)/2 clean lea esi,[esi+ebp+001010101H] ; (p4+p5)/2+(p5+p6)/2+1 shr esi,1 ; p5' = ((p4+p5)/2+(p5+p6)/2+1)/2 dirty mov [edi+PITCH*4],edx ; p4' lea ebp,[ebp+eax+001010101H] ; (p5+p6)/2+(p6+p7)/2+1 and esi,07F7F7F7FH ; p5' clean shr ebp,1 ; p6' = ((p5+p6)/2+(p6+p7)/2+1)/2 dirty mov [edi+PITCH*5],esi ; p5' and ebp,07F7F7F7FH ; p6' clean add edi,4 test edi,00000000FH mov [edi+PITCH*6-4],ebp ; p6' jne SpatialFilterVertLoop add edi,PITCH*8-16 mov eax,VertFilterDoneAddr cmp eax,edi jne SpatialFilterVertLoop ; Activity Details for this section of code (refer to flow diagram above): ; ; 9) The SAD for the spatially filtered reference macroblock is calculated ; with half the pel differences accumulating into the low order half ; of ebp, and the other half into the high order half. ; ; Register usage for this section: ; ; Input of this section: ; ; edi -- Address of pel 0,0 of spatially filtered reference macroblock. ; ; Predominate usage for body of this section: ; ; edi -- Address of pel 0,0 of spatially filtered reference macroblock. ; esi, eax -- -8 times pel values from target macroblock. ; ebp[ 0:15] -- SAD Accumulator for half of the match points. ; ebp[16:31] -- SAD Accumulator for other half of the match points. ; edx[ 0: 7] -- Weighted difference for one pel. ; edx[ 8:15] -- Zero. ; edx[16:23] -- Weighted difference for another pel. ; edx[24:31] -- Zero. ; bl, cl -- Pel values from the spatially filtered reference macroblock. ; ; Expected Pentium (tm) microprocessor performance for this section: ; ; Execution frequency: Once per block for which motion analysis is done ; beyond the 0-motion vector. ; ; 146 clocks instruction execution (typically). ; 6 clocks for bank conflicts (1/8 chance with 48 dual mem ops). ; 0 clocks for new cache line fills. ; ---- ; 152 clocks total time for this section. ; SpatialFilterDone: sub edi,PITCH*8-8 ; Get to block 4. xor ebp,ebp xor ebx,ebx xor ecx,ecx SLFSWDLoop: mov eax,BlockNM1.N8T00 ; Get -8 times target Pel00. mov bl,[edi] ; Get Pel00 in spatially filtered reference. mov esi,BlockNM1.N8T04 mov cl,[edi+4] mov edx,[eax+ebx*8] ; Get abs diff for spatial filtered ref pel00. mov eax,BlockNM1.N8T02 mov dl,[esi+ecx*8+2] ; Get abs diff for spatial filtered ref pel04. mov bl,[edi+2] mov esi,BlockNM1.N8T06 mov cl,[edi+6] mov ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T11 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*1+1] mov cl,[edi+PITCH*1+5] mov esi,BlockNM1.N8T15 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T13 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*1+3] mov cl,[edi+PITCH*1+7] mov esi,BlockNM1.N8T17 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T20 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*2+0] mov cl,[edi+PITCH*2+4] mov esi,BlockNM1.N8T24 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T22 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*2+2] mov cl,[edi+PITCH*2+6] mov esi,BlockNM1.N8T26 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T31 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*3+1] mov cl,[edi+PITCH*3+5] mov esi,BlockNM1.N8T35 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T33 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*3+3] mov cl,[edi+PITCH*3+7] mov esi,BlockNM1.N8T37 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T40 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*4+0] mov cl,[edi+PITCH*4+4] mov esi,BlockNM1.N8T44 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T42 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*4+2] mov cl,[edi+PITCH*4+6] mov esi,BlockNM1.N8T46 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T51 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*5+1] mov cl,[edi+PITCH*5+5] mov esi,BlockNM1.N8T55 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T53 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*5+3] mov cl,[edi+PITCH*5+7] mov esi,BlockNM1.N8T57 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T60 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*6+0] mov cl,[edi+PITCH*6+4] mov esi,BlockNM1.N8T64 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T62 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*6+2] mov cl,[edi+PITCH*6+6] mov esi,BlockNM1.N8T66 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T71 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*7+1] mov cl,[edi+PITCH*7+5] mov esi,BlockNM1.N8T75 add ebp,edx mov edx,[eax+ebx*8] mov eax,BlockNM1.N8T73 mov dl,[esi+ecx*8+2] mov bl,[edi+PITCH*7+3] mov cl,[edi+PITCH*7+7] mov esi,BlockNM1.N8T77 add ebp,edx mov edx,[eax+ebx*8] add edx,ebp mov cl,[esi+ecx*8+2] shr edx,16 add ebp,ecx and ebp,0FFFFH sub esp,BlockLen add ebp,edx sub edi,8 test esp,000000008H mov BlockN.CentralInterSWD_SLF,ebp jne SLFSWDLoop test esp,000000010H lea edi,[edi-PITCH*8+16] jne SLFSWDLoop mov eax,Block2.CentralInterSWD_SLF+BlockLen*4 mov ebx,Block3.CentralInterSWD_SLF+BlockLen*4 mov ecx,Block4.CentralInterSWD_SLF+BlockLen*4 add esp,BlockLen*4 add ebp,ecx lea edx,[eax+ebx] add ebp,edx mov edx,SpatialFiltDifferential lea esi,[edi+PITCH*8-8] mov edi,MBCentralInterSWD sub edi,edx mov edx,MBlockActionStream cmp ebp,edi jge SpatialFilterNotAsGood mov MBCentralInterSWD,ebp ; Spatial filter was better. Stash mov ebp,Block1.CentralInterSWD_SLF ; pertinent calculations. mov Block2.CentralInterSWD,eax mov Block3.CentralInterSWD,ebx mov Block4.CentralInterSWD,ecx mov Block1.CentralInterSWD,ebp mov [edx].BlkY1.PastRef,esi mov al,INTERSLF mov [edx].BlockType,al SkipSpatialFiltering: SpatialFilterNotAsGood: ENDIF ; H261 mov al,[edx].CodedBlocks ; Fetch coded block pattern. mov edi,EmptyThreshold ; Get threshold for forcing block empty? mov ebp,MBCentralInterSWD mov esi,InterSWDBlocks mov ebx,Block4.CentralInterSWD ; Is SWD > threshold? cmp ebx,edi jg @f and al,0F7H ; If not, indicate block 4 is NOT coded. dec esi sub ebp,ebx @@: mov ebx,Block3.CentralInterSWD cmp ebx,edi jg @f and al,0FBH dec esi sub ebp,ebx @@: mov ebx,Block2.CentralInterSWD cmp ebx,edi jg @f and al,0FDH dec esi sub ebp,ebx @@: mov ebx,Block1.CentralInterSWD cmp ebx,edi jg @f and al,0FEH dec esi sub ebp,ebx @@: mov [edx].CodedBlocks,al ; Store coded block pattern. add esi,4 mov InterSWDBlocks,esi xor ebx,ebx and eax,00FH mov MBCentralInterSWD,ebp cmp al,00FH ; Are any blocks marked empty? jne InterBest ; If some blocks are empty, can't code as Intra cmp ebp,InterCodingThreshold ; Is InterSWD below inter-coding threshhold. lea esi,Block1+128 mov ebp,0 jae CalculateIntraSWD InterBest: mov ecx,InterSWDTotal mov ebp,MBCentralInterSWD add ecx,ebp ; Add to total for this macroblock class. mov PD [edx].SWD,ebp mov InterSWDTotal,ecx jmp NextMacroBlock ; Activity Details for this section of code (refer to flow diagram above): ; ; 11) The IntraSWD is calculated as two partial sums, one in the low order ; 16 bits of ebp and one in the high order 16 bits. An average pel ; value for each block will be calculated to the nearest half. ; ; Register usage for this section: ; ; Input of this section: ; ; None ; ; Predominate usage for body of this section: ; ; esi -- Address of target block 1 (3), plus 128. ; ebp[ 0:15] -- IntraSWD Accumulator for block 1 (3). ; ebp[16:31] -- IntraSWD Accumulator for block 2 (4). ; edi -- Block 2 (4) target pel, times -8, and with WeightedDiff added. ; edx -- Block 1 (3) target pel, times -8, and with WeightedDiff added. ; ecx[ 0: 7] -- Weighted difference for one pel in block 2 (4). ; ecx[ 8:15] -- Zero. ; ecx[16:23] -- Weighted difference for one pel in block 1 (3). ; ecx[24:31] -- Zero. ; ebx -- Average block 2 (4) target pel to nearest .5. ; eax -- Average block 1 (3) target pel to nearest .5. ; ; Output of this section: ; ; edi -- Scratch. ; ebp[ 0:15] -- IntraSWD. (Also written to MBlockActionStream.) ; ebp[16:31] -- garbage. ; ebx -- Zero. ; eax -- MBlockActionStream. ; ; Expected Pentium (tm) microprocessor performance for this section: ; ; Executed once per macroblock, (except for those for which one of more blocks ; are marked empty, or where the InterSWD is less than a threshold). ; ; 183 clocks for instruction execution ; 12 clocks for bank conflicts (94 dual mem ops with 1/8 chance of conflict) ; ---- ; 195 clocks total time for this section. IntraByDecree: mov eax,InterSWDBlocks ; Inc by 4, because we will undo it below. xor ebp,ebp mov MBMotionVectors,ebp ; Stash zero for MB level motion vectors. mov ebp,040000000H ; Set Inter SWD artificially high. lea esi,Block1+128 add eax,4 mov MBCentralInterSWD,ebp mov InterSWDBlocks,eax CalculateIntraSWD: CalculateIntraSWDLoop: mov eax,[esi-128].AccumTargetPels ; Fetch acc of target pels for 1st block. mov edx,[esi-128].N8T00 add eax,8 mov ebx,[esi-128+BlockLen].AccumTargetPels shr eax,4 ; Average block 1 target pel rounded to nearest .5. add ebx,8 shr ebx,4 mov edi,[esi-128+BlockLen].N8T00 mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T02 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T02 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T04 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T04 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T06 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T06 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T11 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T11 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T13 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T13 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T15 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T15 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T17 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T17 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T20 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T20 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T22 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T22 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T24 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T24 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T26 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T26 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T31 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T31 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T33 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T33 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T35 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T35 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T37 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T37 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T40 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T40 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T42 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T42 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T44 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T44 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T46 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T46 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T51 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T51 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T53 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T53 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T55 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T55 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T57 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T57 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T60 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T60 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T62 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T62 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T64 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T64 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T66 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T66 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T71 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T71 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T73 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T73 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T75 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T75 add ebp,ecx mov ecx,PD [edx+eax*4] mov edx,[esi-128].N8T77 mov cl,PB [edi+ebx*4+2] mov edi,[esi-128+BlockLen].N8T77 add ebp,ecx mov ecx,PD [edx+eax*4] mov cl,PB [edi+ebx*4+2] mov eax,000007FFFH add ebp,ecx add esi,BlockLen*2 and eax,ebp mov ecx,MBCentralInterSWD shr ebp,16 sub ecx,IntraCodingDifferential add ebp,eax mov edx,MBlockActionStream ; Reload list ptr. cmp ecx,ebp ; Is IntraSWD > InterSWD - differential? jl InterBest lea ecx,Block1+128+BlockLen*2 cmp ecx,esi je CalculateIntraSWDLoop ; ebp -- IntraSWD ; edx -- MBlockActionStream DoneCalcIntraSWD: IntraBest: mov ecx,IntraSWDTotal mov edi,IntraSWDBlocks add ecx,ebp ; Add to total for this macroblock class. add edi,4 ; Accumulate # of blocks for this type. mov IntraSWDBlocks,edi mov edi,InterSWDBlocks sub edi,4 mov IntraSWDTotal,ecx mov InterSWDBlocks,edi mov bl,INTRA mov PB [edx].BlockType,bl ; Indicate macroblock handling decision. IFDEF H261 xor ebx,ebx ELSE ; H263 mov ebx,MBMotionVectors ; Set MVs to best MB level motion vectors. ENDIF mov PD [edx].BlkY1.MVs,ebx mov PD [edx].BlkY2.MVs,ebx mov PD [edx].BlkY3.MVs,ebx mov PD [edx].BlkY4.MVs,ebx xor ebx,ebx mov PD [edx].SWD,ebp jmp NextMacroBlock ;============================================================================== ; Internal functions ;============================================================================== DoSWDLoop: ; Upon entry: ; esi -- Points to ref1 ; edi -- Points to ref2 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero mov bl,PB [esi] ; 00A -- Get Pel 00 in reference ref1. mov eax,Block1.N8T00+4 ; 00B -- Get -8 times target pel 00. mov cl,PB [edi] ; 00C -- Get Pel 00 in reference ref2. sub esp,BlockLen*4+28 SWDLoop: mov edx,PD [eax+ebx*8] ; 00D -- Get weighted diff for ref1 pel 00. mov bl,PB [esi+2] ; 02A mov dl,PB [eax+ecx*8+2] ; 00E -- Get weighted diff for ref2 pel 00. mov eax,BlockN.N8T02+32 ; 02B mov ebp,edx ; 00F -- Accum weighted diffs for pel 00. mov cl,PB [edi+2] ; 02C mov edx,PD [eax+ebx*8] ; 02D mov bl,PB [esi+4] ; 04A mov dl,PB [eax+ecx*8+2] ; 02E mov eax,BlockN.N8T04+32 ; 04B mov cl,PB [edi+4] ; 04C add ebp,edx ; 02F mov edx,PD [eax+ebx*8] ; 04D mov bl,PB [esi+6] mov dl,PB [eax+ecx*8+2] ; 04E mov eax,BlockN.N8T06+32 mov cl,PB [edi+6] add ebp,edx ; 04F mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*1+1] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T11+32 mov cl,PB [edi+PITCH*1+1] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*1+3] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T13+32 mov cl,PB [edi+PITCH*1+3] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*1+5] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T15+32 mov cl,PB [edi+PITCH*1+5] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*1+7] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T17+32 mov cl,PB [edi+PITCH*1+7] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*2+0] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T20+32 mov cl,PB [edi+PITCH*2+0] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*2+2] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T22+32 mov cl,PB [edi+PITCH*2+2] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*2+4] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T24+32 mov cl,PB [edi+PITCH*2+4] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*2+6] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T26+32 mov cl,PB [edi+PITCH*2+6] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*3+1] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T31+32 mov cl,PB [edi+PITCH*3+1] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*3+3] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T33+32 mov cl,PB [edi+PITCH*3+3] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*3+5] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T35+32 mov cl,PB [edi+PITCH*3+5] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*3+7] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T37+32 mov cl,PB [edi+PITCH*3+7] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*4+0] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T40+32 mov cl,PB [edi+PITCH*4+0] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*4+2] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T42+32 mov cl,PB [edi+PITCH*4+2] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*4+4] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T44+32 mov cl,PB [edi+PITCH*4+4] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*4+6] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T46+32 mov cl,PB [edi+PITCH*4+6] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*5+1] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T51+32 mov cl,PB [edi+PITCH*5+1] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*5+3] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T53+32 mov cl,PB [edi+PITCH*5+3] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*5+5] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T55+32 mov cl,PB [edi+PITCH*5+5] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*5+7] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T57+32 mov cl,PB [edi+PITCH*5+7] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*6+0] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T60+32 mov cl,PB [edi+PITCH*6+0] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*6+2] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T62+32 mov cl,PB [edi+PITCH*6+2] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*6+4] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T64+32 mov cl,PB [edi+PITCH*6+4] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*6+6] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T66+32 mov cl,PB [edi+PITCH*6+6] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*7+1] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T71+32 mov cl,PB [edi+PITCH*7+1] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*7+3] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T73+32 mov cl,PB [edi+PITCH*7+3] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*7+5] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T75+32 mov cl,PB [edi+PITCH*7+5] add ebp,edx mov edx,PD [eax+ebx*8] mov bl,PB [esi+PITCH*7+7] mov dl,PB [eax+ecx*8+2] mov eax,BlockN.N8T77+32 mov cl,PB [edi+PITCH*7+7] add ebp,edx mov edx,PD [eax+ebx*8] add esp,BlockLen mov dl,PB [eax+ecx*8+2] mov eax,ebp add ebp,edx add edx,eax shr ebp,16 ; Extract SWD for ref1. and edx,00000FFFFH ; Extract SWD for ref2. mov esi,BlockN.Ref1Addr+32 ; Get address of next ref1 block. mov edi,BlockN.Ref2Addr+32 ; Get address of next ref2 block. mov BlockNM1.Ref1InterSWD+32,ebp ; Store SWD for ref1. mov BlockNM1.Ref2InterSWD+32,edx ; Store SWD for ref2. mov bl,PB [esi] ; 00A -- Get Pel 02 in reference ref1. mov eax,BlockN.N8T00+32 ; 00B -- Get -8 times target pel 00. test esp,000000018H ; Done when esp is 32-byte aligned. mov cl,PB [edi] ; 00C -- Get Pel 02 in reference ref2. jne SWDLoop ; Output: ; ebp -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 ; ecx -- Upper 24 bits zero ; ebx -- Upper 24 bits zero add esp,28 ret IFDEF H261 ELSE ; H263 DoSWDHalfPelHorzLoop: ; ebp -- Initialized to 0, except when can't search off left or right edge. ; edi -- Ref addr for block 1. Ref1 is .5 pel to left. Ref2 is .5 to right. xor ecx,ecx sub esp,BlockLen*4+28 xor eax,eax xor ebx,ebx SWDHalfPelHorzLoop: mov al,[edi] ; 00A -- Fetch center ref pel 00. mov esi,BlockN.N8T00+32; 00B -- Target pel 00 (times -8). mov bl,[edi+2] ; 02A -- Fetch center ref pel 02. mov edx,BlockN.N8T02+32; 02B -- Target pel 02 (times -8). lea esi,[esi+eax*4] ; 00C -- Combine target pel 00 and center ref pel 00. mov al,[edi-1] ; 00D -- Get pel to left for match against pel 00. lea edx,[edx+ebx*4] ; 02C -- Combine target pel 02 and center ref pel 02. mov bl,[edi+1] ; 00E -- Get pel to right for match against pel 00, ; ; 02D -- and pel to left for match against pel 02. mov ecx,[esi+eax*4] ; 00F -- [16:23] weighted diff for left ref pel 00. mov al,[edi+3] ; 02E -- Get pel to right for match against pel 02. add ebp,ecx ; 00G -- Accumulate left ref pel 00. mov ecx,[edx+ebx*4] ; 02F -- [16:23] weighted diff for left ref pel 02. mov cl,[edx+eax*4+2] ; 02H -- [0:7] is weighted diff for right ref pel 02. mov al,[edi+4] ; 04A add ebp,ecx ; 02I -- Accumulate right ref pel 02, ; ; 02G -- Accumulate left ref pel 02. mov bl,[esi+ebx*4+2] ; 00H -- [0:7] is weighted diff for right ref pel 00. add ebp,ebx ; 00I -- Accumulate right ref pel 00. mov esi,BlockN.N8T04+32; 04B mov bl,[edi+6] ; 06A mov edx,BlockN.N8T06+32; 06B lea esi,[esi+eax*4] ; 04C mov al,[edi+3] ; 04D lea edx,[edx+ebx*4] ; 06C mov bl,[edi+5] ; 04E & 06D mov ecx,[esi+eax*4] ; 04F mov al,[edi+7] ; 06E add ebp,ecx ; 04G mov ecx,[edx+ebx*4] ; 06F mov cl,[edx+eax*4+2] ; 06H mov al,[edi+PITCH*1+1] ; 11A add ebp,ecx ; 04I & 06G mov bl,[esi+ebx*4+2] ; 04H add ebp,ebx ; 04I mov esi,BlockN.N8T11+32; 11B mov bl,[edi+PITCH*1+3] ; 13A mov edx,BlockN.N8T13+32; 13B lea esi,[esi+eax*4] ; 11C mov al,[edi+PITCH*1+0] ; 11D lea edx,[edx+ebx*4] ; 13C mov bl,[edi+PITCH*1+2] ; 11E & 13D mov ecx,[esi+eax*4] ; 11F mov al,[edi+PITCH*1+4] ; 13E add ebp,ecx ; 11G mov ecx,[edx+ebx*4] ; 13F mov cl,[edx+eax*4+2] ; 13H mov al,[edi+PITCH*1+5] ; 15A add ebp,ecx ; 11I & 13G mov bl,[esi+ebx*4+2] ; 11H add ebp,ebx ; 11I mov esi,BlockN.N8T15+32; 15B mov bl,[edi+PITCH*1+7] ; 17A mov edx,BlockN.N8T17+32; 17B lea esi,[esi+eax*4] ; 15C mov al,[edi+PITCH*1+4] ; 15D lea edx,[edx+ebx*4] ; 17C mov bl,[edi+PITCH*1+6] ; 15E & 17D mov ecx,[esi+eax*4] ; 15F mov al,[edi+PITCH*1+8] ; 17E add ebp,ecx ; 15G mov ecx,[edx+ebx*4] ; 17F mov cl,[edx+eax*4+2] ; 17H mov al,[edi+PITCH*2+0] ; 20A add ebp,ecx ; 15I & 17G mov bl,[esi+ebx*4+2] ; 15H add ebp,ebx ; 15I mov esi,BlockN.N8T20+32; 20B mov bl,[edi+PITCH*2+2] ; 22A mov edx,BlockN.N8T22+32; 22B lea esi,[esi+eax*4] ; 20C mov al,[edi+PITCH*2-1] ; 20D lea edx,[edx+ebx*4] ; 22C mov bl,[edi+PITCH*2+1] ; 20E & 22D mov ecx,[esi+eax*4] ; 20F mov al,[edi+PITCH*2+3] ; 22E add ebp,ecx ; 20G mov ecx,[edx+ebx*4] ; 22F mov cl,[edx+eax*4+2] ; 22H mov al,[edi+PITCH*2+4] ; 24A add ebp,ecx ; 20I & 22G mov bl,[esi+ebx*4+2] ; 20H add ebp,ebx ; 20I mov esi,BlockN.N8T24+32; 24B mov bl,[edi+PITCH*2+6] ; 26A mov edx,BlockN.N8T26+32; 26B lea esi,[esi+eax*4] ; 24C mov al,[edi+PITCH*2+3] ; 24D lea edx,[edx+ebx*4] ; 26C mov bl,[edi+PITCH*2+5] ; 24E & 26D mov ecx,[esi+eax*4] ; 24F mov al,[edi+PITCH*2+7] ; 26E add ebp,ecx ; 24G mov ecx,[edx+ebx*4] ; 26F mov cl,[edx+eax*4+2] ; 26H mov al,[edi+PITCH*3+1] ; 31A add ebp,ecx ; 24I & 26G mov bl,[esi+ebx*4+2] ; 24H add ebp,ebx ; 24I mov esi,BlockN.N8T31+32; 31B mov bl,[edi+PITCH*3+3] ; 33A mov edx,BlockN.N8T33+32; 33B lea esi,[esi+eax*4] ; 31C mov al,[edi+PITCH*3+0] ; 31D lea edx,[edx+ebx*4] ; 33C mov bl,[edi+PITCH*3+2] ; 31E & 33D mov ecx,[esi+eax*4] ; 31F mov al,[edi+PITCH*3+4] ; 33E add ebp,ecx ; 31G mov ecx,[edx+ebx*4] ; 33F mov cl,[edx+eax*4+2] ; 33H mov al,[edi+PITCH*3+5] ; 35A add ebp,ecx ; 31I & 33G mov bl,[esi+ebx*4+2] ; 31H add ebp,ebx ; 31I mov esi,BlockN.N8T35+32; 35B mov bl,[edi+PITCH*3+7] ; 37A mov edx,BlockN.N8T37+32; 37B lea esi,[esi+eax*4] ; 35C mov al,[edi+PITCH*3+4] ; 35D lea edx,[edx+ebx*4] ; 37C mov bl,[edi+PITCH*3+6] ; 35E & 37D mov ecx,[esi+eax*4] ; 35F mov al,[edi+PITCH*3+8] ; 37E add ebp,ecx ; 35G mov ecx,[edx+ebx*4] ; 37F mov cl,[edx+eax*4+2] ; 37H mov al,[edi+PITCH*4+0] ; 40A add ebp,ecx ; 35I & 37G mov bl,[esi+ebx*4+2] ; 35H add ebp,ebx ; 35I mov esi,BlockN.N8T40+32; 40B mov bl,[edi+PITCH*4+2] ; 42A mov edx,BlockN.N8T42+32; 42B lea esi,[esi+eax*4] ; 40C mov al,[edi+PITCH*4-1] ; 40D lea edx,[edx+ebx*4] ; 42C mov bl,[edi+PITCH*4+1] ; 40E & 42D mov ecx,[esi+eax*4] ; 40F mov al,[edi+PITCH*4+3] ; 42E add ebp,ecx ; 40G mov ecx,[edx+ebx*4] ; 42F mov cl,[edx+eax*4+2] ; 42H mov al,[edi+PITCH*4+4] ; 44A add ebp,ecx ; 40I & 42G mov bl,[esi+ebx*4+2] ; 40H add ebp,ebx ; 40I mov esi,BlockN.N8T44+32; 44B mov bl,[edi+PITCH*4+6] ; 46A mov edx,BlockN.N8T46+32; 46B lea esi,[esi+eax*4] ; 44C mov al,[edi+PITCH*4+3] ; 44D lea edx,[edx+ebx*4] ; 46C mov bl,[edi+PITCH*4+5] ; 44E & 46D mov ecx,[esi+eax*4] ; 44F mov al,[edi+PITCH*4+7] ; 46E add ebp,ecx ; 44G mov ecx,[edx+ebx*4] ; 46F mov cl,[edx+eax*4+2] ; 46H mov al,[edi+PITCH*5+1] ; 51A add ebp,ecx ; 44I & 46G mov bl,[esi+ebx*4+2] ; 44H add ebp,ebx ; 44I mov esi,BlockN.N8T51+32; 51B mov bl,[edi+PITCH*5+3] ; 53A mov edx,BlockN.N8T53+32; 53B lea esi,[esi+eax*4] ; 51C mov al,[edi+PITCH*5+0] ; 51D lea edx,[edx+ebx*4] ; 53C mov bl,[edi+PITCH*5+2] ; 51E & 53D mov ecx,[esi+eax*4] ; 51F mov al,[edi+PITCH*5+4] ; 53E add ebp,ecx ; 51G mov ecx,[edx+ebx*4] ; 53F mov cl,[edx+eax*4+2] ; 53H mov al,[edi+PITCH*5+5] ; 55A add ebp,ecx ; 51I & 53G mov bl,[esi+ebx*4+2] ; 51H add ebp,ebx ; 51I mov esi,BlockN.N8T55+32; 55B mov bl,[edi+PITCH*5+7] ; 57A mov edx,BlockN.N8T57+32; 57B lea esi,[esi+eax*4] ; 55C mov al,[edi+PITCH*5+4] ; 55D lea edx,[edx+ebx*4] ; 57C mov bl,[edi+PITCH*5+6] ; 55E & 57D mov ecx,[esi+eax*4] ; 55F mov al,[edi+PITCH*5+8] ; 57E add ebp,ecx ; 55G mov ecx,[edx+ebx*4] ; 57F mov cl,[edx+eax*4+2] ; 57H mov al,[edi+PITCH*6+0] ; 60A add ebp,ecx ; 55I & 57G mov bl,[esi+ebx*4+2] ; 55H add ebp,ebx ; 55I mov esi,BlockN.N8T60+32; 60B mov bl,[edi+PITCH*6+2] ; 62A mov edx,BlockN.N8T62+32; 62B lea esi,[esi+eax*4] ; 60C mov al,[edi+PITCH*6-1] ; 60D lea edx,[edx+ebx*4] ; 62C mov bl,[edi+PITCH*6+1] ; 60E & 62D mov ecx,[esi+eax*4] ; 60F mov al,[edi+PITCH*6+3] ; 62E add ebp,ecx ; 60G mov ecx,[edx+ebx*4] ; 62F mov cl,[edx+eax*4+2] ; 62H mov al,[edi+PITCH*6+4] ; 64A add ebp,ecx ; 60I & 62G mov bl,[esi+ebx*4+2] ; 60H add ebp,ebx ; 60I mov esi,BlockN.N8T64+32; 64B mov bl,[edi+PITCH*6+6] ; 66A mov edx,BlockN.N8T66+32; 66B lea esi,[esi+eax*4] ; 64C mov al,[edi+PITCH*6+3] ; 64D lea edx,[edx+ebx*4] ; 66C mov bl,[edi+PITCH*6+5] ; 64E & 66D mov ecx,[esi+eax*4] ; 64F mov al,[edi+PITCH*6+7] ; 66E add ebp,ecx ; 64G mov ecx,[edx+ebx*4] ; 66F mov cl,[edx+eax*4+2] ; 66H mov al,[edi+PITCH*7+1] ; 71A add ebp,ecx ; 64I & 66G mov bl,[esi+ebx*4+2] ; 64H add ebp,ebx ; 64I mov esi,BlockN.N8T71+32; 71B mov bl,[edi+PITCH*7+3] ; 73A mov edx,BlockN.N8T73+32; 73B lea esi,[esi+eax*4] ; 71C mov al,[edi+PITCH*7+0] ; 71D lea edx,[edx+ebx*4] ; 73C mov bl,[edi+PITCH*7+2] ; 71E & 73D mov ecx,[esi+eax*4] ; 71F mov al,[edi+PITCH*7+4] ; 73E add ebp,ecx ; 71G mov ecx,[edx+ebx*4] ; 73F mov cl,[edx+eax*4+2] ; 73H mov al,[edi+PITCH*7+5] ; 75A add ebp,ecx ; 71I & 73G mov bl,[esi+ebx*4+2] ; 71H add ebp,ebx ; 71I mov esi,BlockN.N8T75+32; 75B mov bl,[edi+PITCH*7+7] ; 77A mov edx,BlockN.N8T77+32; 77B lea esi,[esi+eax*4] ; 75C mov al,[edi+PITCH*7+4] ; 75D lea edx,[edx+ebx*4] ; 77C mov bl,[edi+PITCH*7+6] ; 75E & 77D mov ecx,[esi+eax*4] ; 75F mov al,[edi+PITCH*7+8] ; 77E add ebp,ecx ; 75G mov ecx,[edx+ebx*4] ; 77F mov cl,[edx+eax*4+2] ; 77H add esp,BlockLen add ecx,ebp ; 75I & 77G mov bl,[esi+ebx*4+2] ; 75H add ebx,ecx ; 75I mov edi,BlockN.AddrCentralPoint+32 ; Get address of next ref1 block. shr ecx,16 ; Extract SWD for ref1. and ebx,00000FFFFH ; Extract SWD for ref2. mov BlockNM1.Ref1InterSWD+32,ecx ; Store SWD for ref1. mov BlockNM1.Ref2InterSWD+32,ebx ; Store SWD for ref2. xor ebp,ebp mov edx,ebx test esp,000000018H mov ebx,ebp jne SWDHalfPelHorzLoop ; Output: ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 add esp,28 ret DoSWDHalfPelVertLoop: ; ebp -- Initialized to 0, except when can't search off left or right edge. ; edi -- Ref addr for block 1. Ref1 is .5 pel up. Ref2 is .5 down. xor ecx,ecx sub esp,BlockLen*4+28 xor eax,eax xor ebx,ebx SWDHalfPelVertLoop: mov al,[edi] mov esi,BlockN.N8T00+32 mov bl,[edi+2*PITCH] mov edx,BlockN.N8T20+32 lea esi,[esi+eax*4] mov al,[edi-1*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+1*PITCH] mov ecx,[esi+eax*4] mov al,[edi+3*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+4*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T40+32 mov bl,[edi+6*PITCH] mov edx,BlockN.N8T60+32 lea esi,[esi+eax*4] mov al,[edi+3*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+5*PITCH] mov ecx,[esi+eax*4] mov al,[edi+7*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+1+1*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T11+32 mov bl,[edi+1+3*PITCH] mov edx,BlockN.N8T31+32 lea esi,[esi+eax*4] mov al,[edi+1+0*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+1+2*PITCH] mov ecx,[esi+eax*4] mov al,[edi+1+4*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+1+5*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T51+32 mov bl,[edi+1+7*PITCH] mov edx,BlockN.N8T71+32 lea esi,[esi+eax*4] mov al,[edi+1+4*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+1+6*PITCH] mov ecx,[esi+eax*4] mov al,[edi+1+8*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+2+0*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T02+32 mov bl,[edi+2+2*PITCH] mov edx,BlockN.N8T22+32 lea esi,[esi+eax*4] mov al,[edi+2-1*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+2+1*PITCH] mov ecx,[esi+eax*4] mov al,[edi+2+3*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+2+4*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T42+32 mov bl,[edi+2+6*PITCH] mov edx,BlockN.N8T62+32 lea esi,[esi+eax*4] mov al,[edi+2+3*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+2+5*PITCH] mov ecx,[esi+eax*4] mov al,[edi+2+7*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+3+1*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T13+32 mov bl,[edi+3+3*PITCH] mov edx,BlockN.N8T33+32 lea esi,[esi+eax*4] mov al,[edi+3+0*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+3+2*PITCH] mov ecx,[esi+eax*4] mov al,[edi+3+4*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+3+5*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T53+32 mov bl,[edi+3+7*PITCH] mov edx,BlockN.N8T73+32 lea esi,[esi+eax*4] mov al,[edi+3+4*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+3+6*PITCH] mov ecx,[esi+eax*4] mov al,[edi+3+8*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+4+0*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T04+32 mov bl,[edi+4+2*PITCH] mov edx,BlockN.N8T24+32 lea esi,[esi+eax*4] mov al,[edi+4-1*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+4+1*PITCH] mov ecx,[esi+eax*4] mov al,[edi+4+3*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+4+4*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T44+32 mov bl,[edi+4+6*PITCH] mov edx,BlockN.N8T64+32 lea esi,[esi+eax*4] mov al,[edi+4+3*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+4+5*PITCH] mov ecx,[esi+eax*4] mov al,[edi+4+7*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+5+1*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T15+32 mov bl,[edi+5+3*PITCH] mov edx,BlockN.N8T35+32 lea esi,[esi+eax*4] mov al,[edi+5+0*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+5+2*PITCH] mov ecx,[esi+eax*4] mov al,[edi+5+4*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+5+5*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T55+32 mov bl,[edi+5+7*PITCH] mov edx,BlockN.N8T75+32 lea esi,[esi+eax*4] mov al,[edi+5+4*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+5+6*PITCH] mov ecx,[esi+eax*4] mov al,[edi+5+8*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+6+0*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T06+32 mov bl,[edi+6+2*PITCH] mov edx,BlockN.N8T26+32 lea esi,[esi+eax*4] mov al,[edi+6-1*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+6+1*PITCH] mov ecx,[esi+eax*4] mov al,[edi+6+3*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+6+4*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T46+32 mov bl,[edi+6+6*PITCH] mov edx,BlockN.N8T66+32 lea esi,[esi+eax*4] mov al,[edi+6+3*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+6+5*PITCH] mov ecx,[esi+eax*4] mov al,[edi+6+7*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+7+1*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T17+32 mov bl,[edi+7+3*PITCH] mov edx,BlockN.N8T37+32 lea esi,[esi+eax*4] mov al,[edi+7+0*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+7+2*PITCH] mov ecx,[esi+eax*4] mov al,[edi+7+4*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] mov al,[edi+7+5*PITCH] add ebp,ecx mov bl,[esi+ebx*4+2] add ebp,ebx mov esi,BlockN.N8T57+32 mov bl,[edi+7+7*PITCH] mov edx,BlockN.N8T77+32 lea esi,[esi+eax*4] mov al,[edi+7+4*PITCH] lea edx,[edx+ebx*4] mov bl,[edi+7+6*PITCH] mov ecx,[esi+eax*4] mov al,[edi+7+8*PITCH] add ebp,ecx mov ecx,[edx+ebx*4] mov cl,[edx+eax*4+2] add esp,BlockLen add ecx,ebp mov bl,[esi+ebx*4+2] add ebx,ecx mov edi,BlockN.AddrCentralPoint+32 shr ecx,16 and ebx,00000FFFFH mov BlockNM1.Ref1InterSWD+32,ecx mov BlockNM1.Ref2InterSWD+32,ebx xor ebp,ebp mov edx,ebx test esp,000000018H mov ebx,ebp jne SWDHalfPelVertLoop ; Output: ; ebp, ebx -- Zero ; ecx -- Ref1 SWD for block 4 ; edx -- Ref2 SWD for block 4 add esp,28 ret ENDIF ; H263 ; Performance for common macroblocks: ; 298 clocks: prepare target pels, compute avg target pel, compute 0-MV SWD. ; 90 clocks: compute IntraSWD. ; 1412 clocks: 6-level search for best SWD. ; 16 clocks: record best fit. ; 945 clocks: calculate spatial loop filtered prediction. ; 152 clocks: calculate SWD for spatially filtered prediction and classify. ; ---- ; 2913 clocks total ; ; Performance for macroblocks in which 0-motion vector is "good enough": ; 298 clocks: prepare target pels, compute avg target pel, compute 0-MV SWD. ; 90 clocks: compute IntraSWD. ; 16 clocks: record best fit. ; 58 clocks: extra cache fill burden on adjacent MB if SWD-search not done. ; 945 clocks: calculate spatial loop filtered prediction. ; 152 clocks: calculate SWD for spatially filtered prediction and classify. ; ---- ; 1559 clocks total ; ; Performance for macroblocks marked as intrablock by decree of caller: ; 298 clocks: prepare target pels, compute avg target pel, compute 0-MV SWD. ; 90 clocks: compute IntraSWD. ; 58 clocks: extra cache fill burden on adjacent MB if SWD-search not done. ; 20 clocks: classify (just weight the SWD for # of match points). ; ---- ; 476 clocks total ; ; 160*120 performance, generously estimated (assuming lots of motion): ; ; 2913 * 80 = 233000 clocks for luma. ; 2913 * 12 = 35000 clocks for chroma. ; 268000 clocks per frame * 15 = 4,020,000 clocks/sec. ; ; 160*120 performance, assuming typical motion: ; ; 2913 * 40 + 1559 * 40 = 179000 clocks for luma. ; 2913 * 8 + 1559 * 4 = 30000 clocks for chroma. ; 209000 clocks per frame * 15 = 3,135,000 clocks/sec. ; ; Add 10-20% to allow for initial cache-filling, and unfortunate cases where ; cache-filling policy preempts areas of the tables that are not locally "hot", ; instead of preempting macroblocks upon which the processing was just finished. Done: mov eax,IntraSWDTotal mov ebx,IntraSWDBlocks mov ecx,InterSWDTotal mov edx,InterSWDBlocks mov esp,StashESP mov edi,[esp+IntraSWDTotal_arg] mov [edi],eax mov edi,[esp+IntraSWDBlocks_arg] mov [edi],ebx mov edi,[esp+InterSWDTotal_arg] mov [edi],ecx mov edi,[esp+InterSWDBlocks_arg] mov [edi],edx pop ebx pop ebp pop edi pop esi rturn MOTIONESTIMATION endp END
; uchar esxdos_f_readdir(uchar handle, void *buf) INCLUDE "config_private.inc" SECTION code_clib SECTION code_esxdos PUBLIC asm_esxdos_f_readdir EXTERN __esxdos_error_zc asm_esxdos_f_readdir: ; F_READDIR: ; Read a dir entry to buffer pointed to by HL. A=handle. ; ; Buffer format: ; ; <asciiz> file/dirname ; <byte> attributes (like MSDOS) ; <dword> date ; <dword> filesize ; ; If opened with BASIC header bit, after the normal entry ; follows the BASIC header (with type=$ff if headerless) ; ; On return, if A=1 theres more entries, if=0 then it's end ; of dir. FIXME-A should return size of entry, 0 if end of dir. ; ; enter : a = uchar handle ; hl = void *buf ; ; exit : success ; ; l = non-zero if more entries ; carry reset ; ; error ; ; hl = 0 ; carry set, errno set ; ; uses : unknown IF __SDCC_IY push hl pop iy ELSE push hl pop ix ENDIF rst __ESXDOS_SYSCALL defb __ESXDOS_SYS_F_READDIR ld l,a ret nc jp __esxdos_error_zc
/* * @Author: py.wang * @Date: 2019-05-07 09:22:53 * @Last Modified by: py.wang * @Last Modified time: 2019-05-07 09:26:25 */ #include "src/base/CountDownLatch.h" using namespace slack; // initialize CountDownLatch::CountDownLatch(int count) : mutex_(), condition_(mutex_), count_(count) { } // 条件变量的正确使用 void CountDownLatch::wait() { MutexLockGuard lock(mutex_); // 避免假唤醒,用while while (count_ > 0) { condition_.wait(); } } void CountDownLatch::countDown() { MutexLockGuard lock(mutex_); --count_; // 通知 if (count_ == 0) { condition_.notifyAll(); } } int CountDownLatch::getCount() const { MutexLockGuard lock(mutex_); return count_; }
; A027480: a(n) = n*(n+1)*(n+2)/2. ; 0,3,12,30,60,105,168,252,360,495,660,858,1092,1365,1680,2040,2448,2907,3420,3990,4620,5313,6072,6900,7800,8775,9828,10962,12180,13485,14880,16368,17952,19635,21420,23310,25308,27417,29640,31980,34440,37023,39732,42570,45540,48645,51888,55272,58800,62475,66300,70278,74412,78705,83160,87780,92568,97527,102660,107970,113460,119133,124992,131040,137280,143715,150348,157182,164220,171465,178920,186588,194472,202575,210900,219450,228228,237237,246480,255960,265680,275643,285852,296310,307020,317985 add $0,2 bin $0,3 mul $0,3
; --------------------------------------------------------------------------- ; Animation script - Sonic ; --------------------------------------------------------------------------- Ani_Sonic: ptr_Walk: dc.w SonAni_Walk-Ani_Sonic ptr_Run: dc.w SonAni_Run-Ani_Sonic ptr_Roll: dc.w SonAni_Roll-Ani_Sonic ptr_Roll2: dc.w SonAni_Roll2-Ani_Sonic ptr_Push: dc.w SonAni_Push-Ani_Sonic ptr_Wait: dc.w SonAni_Wait-Ani_Sonic ptr_Balance: dc.w SonAni_Balance-Ani_Sonic ptr_LookUp: dc.w SonAni_LookUp-Ani_Sonic ptr_Duck: dc.w SonAni_Duck-Ani_Sonic ptr_Warp1: dc.w SonAni_Warp1-Ani_Sonic ptr_Warp2: dc.w SonAni_Warp2-Ani_Sonic ptr_Warp3: dc.w SonAni_Warp3-Ani_Sonic ptr_Warp4: dc.w SonAni_Warp4-Ani_Sonic ptr_Stop: dc.w SonAni_Stop-Ani_Sonic ptr_Float1: dc.w SonAni_Float1-Ani_Sonic ptr_Float2: dc.w SonAni_Float2-Ani_Sonic ptr_Spring: dc.w SonAni_Spring-Ani_Sonic ptr_Hang: dc.w SonAni_Hang-Ani_Sonic ptr_Leap1: dc.w SonAni_Leap1-Ani_Sonic ptr_Leap2: dc.w SonAni_Leap2-Ani_Sonic ptr_Surf: dc.w SonAni_Surf-Ani_Sonic ptr_GetAir: dc.w SonAni_GetAir-Ani_Sonic ptr_Burnt: dc.w SonAni_Burnt-Ani_Sonic ptr_Drown: dc.w SonAni_Drown-Ani_Sonic ptr_Death: dc.w SonAni_Death-Ani_Sonic ptr_Shrink: dc.w SonAni_Shrink-Ani_Sonic ptr_Hurt: dc.w SonAni_Hurt-Ani_Sonic ptr_WaterSlide: dc.w SonAni_WaterSlide-Ani_Sonic ptr_Null: dc.w SonAni_Null-Ani_Sonic ptr_Float3: dc.w SonAni_Float3-Ani_Sonic ptr_Float4: dc.w SonAni_Float4-Ani_Sonic ptr_Spindash: dc.w SonAni_SpinDash-Ani_Sonic ;1F SonAni_Walk: dc.b $FF, fr_walk13, fr_walk14, fr_walk15, fr_walk16, fr_walk11, fr_walk12, afEnd even SonAni_Run: dc.b $FF, fr_run11, fr_run12, fr_run13, fr_run14, afEnd, afEnd, afEnd even SonAni_Roll: dc.b $FE, fr_Roll1, fr_Roll2, fr_Roll3, fr_Roll4, fr_Roll5, afEnd, afEnd even SonAni_Roll2: dc.b $FE, fr_Roll1, fr_Roll2, fr_Roll5, fr_Roll3, fr_Roll4, fr_Roll5, afEnd even SonAni_Push: dc.b $FD, fr_push1, fr_push2, fr_push3, fr_push4, afEnd, afEnd, afEnd even SonAni_Wait: dc.b $17, fr_stand, fr_stand, fr_stand, fr_stand, fr_stand, fr_stand, fr_stand, fr_stand, fr_stand dc.b fr_stand, fr_stand, fr_stand, fr_wait2, fr_wait1, fr_wait1, fr_wait1, fr_wait2, fr_wait3, afBack, 2 even SonAni_Balance: dc.b $1F, fr_balance1, fr_balance2, afEnd even SonAni_LookUp: dc.b $3F, fr_lookup, afEnd even SonAni_Duck: dc.b $3F, fr_duck, afEnd even SonAni_Warp1: dc.b $3F, fr_warp1, afEnd even SonAni_Warp2: dc.b $3F, fr_warp2, afEnd even SonAni_Warp3: dc.b $3F, fr_warp3, afEnd even SonAni_Warp4: dc.b $3F, fr_warp4, afEnd even SonAni_Stop: dc.b 7, fr_stop1, fr_stop2, afEnd even SonAni_Float1: dc.b 7, fr_float1, fr_float4, afEnd even SonAni_Float2: dc.b 7, fr_float1, fr_float2, fr_float5, fr_float3, fr_float6, afEnd even SonAni_Spring: dc.b $2F, fr_spring, afChange, id_Walk even SonAni_Hang: dc.b 4, fr_hang1, fr_hang2, afEnd even SonAni_Leap1: dc.b $F, fr_leap1, fr_leap1, fr_leap1, afBack, 1 even SonAni_Leap2: dc.b $F, fr_leap1, fr_leap2, afBack, 1 even SonAni_Surf: dc.b $3F, fr_surf, afEnd even SonAni_GetAir: dc.b $B, fr_getair, fr_getair, fr_walk15, fr_walk16, afChange, id_Walk even SonAni_Burnt: dc.b $20, fr_burnt, afEnd even SonAni_Drown: dc.b $2F, fr_drown, afEnd even SonAni_Death: dc.b 3, fr_death, afEnd even SonAni_Shrink: dc.b 3, fr_shrink1, fr_shrink2, fr_shrink3, fr_shrink4, fr_shrink5, fr_null, afBack, 1 even SonAni_Hurt: dc.b 3, fr_injury, afEnd even SonAni_WaterSlide: dc.b 7, fr_injury, fr_waterslide, afEnd even SonAni_Null: dc.b $77, fr_null, afChange, id_Walk even SonAni_Float3: dc.b 3, fr_float1, fr_float2, fr_float5, fr_float3, fr_float6, afEnd even SonAni_Float4: dc.b 3, fr_float1, afChange, id_Walk even SonAni_SpinDash: dc.b 0, fr_Spindash1, fr_spindash2, fr_spindash1, fr_spindash3, fr_spindash1, fr_spindash4, fr_spindash1, fr_spindash5, fr_spindash1, fr_spindash6, afEnd even id_Walk: equ (ptr_Walk-Ani_Sonic)/2 ; 0 id_Run: equ (ptr_Run-Ani_Sonic)/2 ; 1 id_Roll: equ (ptr_Roll-Ani_Sonic)/2 ; 2 id_Roll2: equ (ptr_Roll2-Ani_Sonic)/2 ; 3 id_Push: equ (ptr_Push-Ani_Sonic)/2 ; 4 id_Wait: equ (ptr_Wait-Ani_Sonic)/2 ; 5 id_Balance: equ (ptr_Balance-Ani_Sonic)/2 ; 6 id_LookUp: equ (ptr_LookUp-Ani_Sonic)/2 ; 7 id_Duck: equ (ptr_Duck-Ani_Sonic)/2 ; 8 id_Warp1: equ (ptr_Warp1-Ani_Sonic)/2 ; 9 id_Warp2: equ (ptr_Warp2-Ani_Sonic)/2 ; $A id_Warp3: equ (ptr_Warp3-Ani_Sonic)/2 ; $B id_Warp4: equ (ptr_Warp4-Ani_Sonic)/2 ; $C id_Stop: equ (ptr_Stop-Ani_Sonic)/2 ; $D id_Float1: equ (ptr_Float1-Ani_Sonic)/2 ; $E id_Float2: equ (ptr_Float2-Ani_Sonic)/2 ; $F id_Spring: equ (ptr_Spring-Ani_Sonic)/2 ; $10 id_Hang: equ (ptr_Hang-Ani_Sonic)/2 ; $11 id_Leap1: equ (ptr_Leap1-Ani_Sonic)/2 ; $12 id_Leap2: equ (ptr_Leap2-Ani_Sonic)/2 ; $13 id_Surf: equ (ptr_Surf-Ani_Sonic)/2 ; $14 id_GetAir: equ (ptr_GetAir-Ani_Sonic)/2 ; $15 id_Burnt: equ (ptr_Burnt-Ani_Sonic)/2 ; $16 id_Drown: equ (ptr_Drown-Ani_Sonic)/2 ; $17 id_Death: equ (ptr_Death-Ani_Sonic)/2 ; $18 id_Shrink: equ (ptr_Shrink-Ani_Sonic)/2 ; $19 id_Hurt: equ (ptr_Hurt-Ani_Sonic)/2 ; $1A id_WaterSlide: equ (ptr_WaterSlide-Ani_Sonic)/2 ; $1B id_Null: equ (ptr_Null-Ani_Sonic)/2 ; $1C id_Float3: equ (ptr_Float3-Ani_Sonic)/2 ; $1D id_Float4: equ (ptr_Float4-Ani_Sonic)/2 ; $1E id_Spindash: equ (ptr_Spindash-Ani_Sonic)/2 ; $1F
//menu.hpp //Game starting menu //Chuluunbat Purev //2020-12-4 #ifndef MENU_HEADER #define MENU_HEADER #include "SFML/Graphics.hpp" #define MENU_ITEMS 2 class Menu { public: Menu(); //Scaling to window void start(int width, int height); //Keyboard inputs void moveUp(); void moveDown(); //Get seleceted menu item int getItemIndex(); //Draw the menu void run(sf::RenderWindow& window); private: int item; sf::Font font; sf::Text items[MENU_ITEMS]; sf::Sprite ttle; sf::Texture texture; }; #endif
; vim: ft=nasm ; summary: http://ascii-table.com/ansi-escape-sequences.php ; elaborate: http://ascii-table.com/ansi-escape-sequences-vt-100.php %include "./lib/signals.mac" ;%include "./lib/log.mac" extern ansi_cursor_hide extern ansi_cursor_position extern ansi_cursor_show extern ansi_term_clear extern sys_nanosleep extern sys_signal extern sys_write_stdout ; DRAW is turned off by default to allow debugging. ; To draw do: rm -f pong pong.o && PONG_DRAW=1 make && ./pong ; To debug do: rm -f pong pong.o && make && gdb pong %ifenv PONG_DRAW %define DRAW %endif %define ms 1000000 %define idle_ms 30 %define wall_ms 1 %define ratio 2 %define width 64 * ratio %define height 40 %define left_x 5 %define top_y 5 %define right_x left_x + width %define bottom_y top_y + height section .text cleanup: call ansi_cursor_show exit: mov eax, 1 mov ebx, 0 int 80H idle: push ecx xor ecx, ecx ; slow down the loop a bit call sys_nanosleep pop ecx ret ; draw_walls ; draws bottom and top row walls ; it does so with slight delay for that true arcade style ;) section .data hitleft: db "Hit left wall" .len: equ $-hitleft hitright: db "Hit right wall" .len: equ $-hitright hittop: db "Hit top wall" .len: equ $-hittop hitbottom: db "Hit bottom wall" .len: equ $-hitbottom section .text section .data horizontal_top_brick : db '▄' .len equ $-horizontal_top_brick horizontal_bottom_brick: db '▀' .len equ $-horizontal_bottom_brick section .text draw_walls: xor eax, eax mov ah, left_x - 1 ; top row mov al, top_y - 1 .draw_row_left_to_right: mov edx, wall_ms * ms call idle inc ah call ansi_cursor_position mov ecx, horizontal_top_brick mov edx, horizontal_top_brick.len call sys_write_stdout cmp ah, right_x jne .draw_row_left_to_right mov al, bottom_y + 1 ; bottom row .draw_row_right_to_left: mov edx, wall_ms * ms call idle dec ah call ansi_cursor_position mov ecx, horizontal_bottom_brick mov edx, horizontal_bottom_brick.len call sys_write_stdout cmp ah, left_x jne .draw_row_right_to_left ret ; draws left/right paddle around the given center ; center of paddle in ah:al = x:y ; modifies: ecx section .data paddle_block: db '▓' .len equ $-paddle_block section .text draw_left_paddle: xor eax, eax ; load current position mov esi, left_paddle lodsw jmp draw_paddle draw_right_paddle: xor eax, eax ; load current position mov esi, right_paddle lodsw draw_paddle: mov edx, paddle_block.len mov ecx, paddle_block xor ebx, ebx mov bl, al ; bl marks lower paddle end add bl, 3 sub al, 2 ; start drawing at top of paddle .loop: call ansi_cursor_position call sys_write_stdout inc al cmp bl, al jne .loop ret ; Determines which labels to jmp to next time ball's speed is applied to its position. ; Stores the appropriate function pointer in ball_dir.x and ball_dir.y respectively. ; This is then used to jmp in @see position_ball. ; modifies eax, ebx, esi adjust_direction: xor eax, eax ; load current position mov esi, ball_pos lodsw mov ebx, eax ; and copy into ebx .hit_left_wall?: ; if we hit left wall fly to the right cmp bh, left_x jne .hit_right_wall? mov eax, position_ball.right mov edi, ball_dir.x stosd jmp .hit_bottom_wall? .hit_right_wall?: ; if we hit right wall fly to the left cmp bh, right_x jne .hit_bottom_wall? mov eax, position_ball.left mov edi, ball_dir.x stosd mov dword [ ball_dir.x ], position_ball.left ; hit right .hit_bottom_wall?: ; if we hit bottom wall fly up cmp bl, bottom_y jne .hit_top_wall? mov eax, position_ball.up mov edi, ball_dir.y stosd jmp .done .hit_top_wall?: ; if we hit top wall fly down cmp bl, top_y jne .done mov eax, position_ball.down mov edi, ball_dir.y stosd .done: ret section .data positioning: db "Positioning Ball",0 section .text ; Applies ball speed vector (ball_speed) to its position (ball_pos). ; Either adds or substracts the magnitudes of the speed vector depending on ; which jmp address was stored in ball_dir by adjust_direction. ; Thus this simulates the direction of the vector's magnitude in an ; unsigned number world. ; modifies: ebx, esi, edi position_ball: cld xor eax, eax ; load current position mov esi, ball_pos lodsw ; ball_speed is right after ball_pos in memory, so esi now points at it mov ebx, eax ; load current speed lodsw xchg eax, ebx jmp [ ball_dir.x ] ; move ball right or left depending on its direction .right: add ah, bh jmp .x_done .left: sub ah, bh .x_done: jmp [ ball_dir.y ] ; move ball up or down depending on its direction .down: add al, bl jmp .done .up: sub al, bl .done: mov edi, ball_pos stosw ret global _start _start: nop mov ecx, cleanup ; ensure we get our cursor back mov ebx, SIGINT ; no matter how we exit call sys_signal mov ebx, SIGTERM call sys_signal mov ebx, SIGHUP call sys_signal %ifdef DRAW call ansi_cursor_hide call ansi_term_clear call draw_walls %else section .data msg: db "Running in debug mode, please run: 'rm -f pong pong.o && PONG_DRAW=1 make && ./pong', in order to see the ball ;)", 10 .len equ $-msg section .text mov ecx, msg mov edx, msg.len call sys_write_stdout %endif cld mov edi, ball_dir ; initial ball direction right x down mov eax, position_ball.down stosd mov eax, position_ball.right stosd %ifdef DRAW call draw_left_paddle call draw_right_paddle %endif game_loop: call adjust_direction call position_ball %ifdef DRAW ; draw ball call ansi_cursor_position mov ecx, ball mov edx, ball.len call sys_write_stdout mov edx, idle_ms * ms call idle ; clear ball call ansi_cursor_position mov ecx, space mov edx, space.len call sys_write_stdout %endif jmp game_loop section .data ; log_text ball: db "•" .len equ $-ball %ifenv PONG_TRAIL ; optionally follow the ball by a trail space: db '.' %else space: db ' ' %endif .len equ $-space section .data ball_pos: ; little endian, allow loading into ax in one shot .y: db top_y + (height / 2) ; al .x: db left_x + (width / 2) ; ah ball_speed: .y: db 1 .x: db 1 left_paddle: ; paddle positions .y: db top_y + (height / 2) ; al .x: db left_x - 1 ; ah right_paddle: .y: db top_y + (height / 2 ); al .x: db right_x + 1 ; ah section .bss ball_dir: ; addresses of labels to jmp to when applying speed vector to position .y: resd 1 ; position_ball.up or position_ball.down .x: resd 1 ; position_ball.left or position_ball.right section .text
; A131524: Number of possible palindromic rows (or columns) in an n X n crossword puzzle. ; 0,0,1,1,2,2,4,4,7,7,12,12,20,20,33,33,54,54,88,88,143,143,232,232,376,376,609,609,986,986,1596,1596,2583,2583,4180,4180,6764,6764,10945,10945,17710,17710,28656,28656,46367,46367,75024,75024,121392,121392,196417,196417,317810,317810,514228,514228,832039,832039,1346268,1346268,2178308,2178308,3524577,3524577,5702886,5702886,9227464,9227464,14930351,14930351,24157816,24157816,39088168,39088168,63245985,63245985,102334154,102334154,165580140,165580140,267914295,267914295,433494436,433494436,701408732,701408732,1134903169,1134903169,1836311902,1836311902,2971215072,2971215072,4807526975,4807526975,7778742048,7778742048,12586269024,12586269024,20365011073,20365011073 mov $1,1 mov $3,2 lpb $0 sub $0,2 mov $2,$1 mov $1,$3 add $3,$2 lpe sub $1,1 mov $0,$1