flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
r22 03 Aug 2009, 19:15
Your UP, DOWN, LEFT, RIGHT procs will look almost the same in ASM, since they just call a windows api from user32.dll
i.e. Code: down: invoke keybd_event,VK_DOWN, 0, 0, 0 invoke keybd_event,VK_DOWN, 0, KEYEVENTF_KEYUP, 0 ret 0 Your timer event handler can be ported a number of ways to ASM using the CreateThread api or actually creating a timer using the SetTimer api. Since you didn't provide any timer creation code I assume delphi does this for you (I recall it being similar to VB with a drag-N-drop IDE). For simplicity here is the time creation routine using CreateThread Code: .data timerDelayInMS dd 2000; every 2 seconds timerThreadID dd 0; this will holder the timer thread ID timerThreadHandle dd 0; the thread handle ... .code CreateTimer: invoke CreateThread, 0, 0, TimerProc, 0, 0, timerThreadID mov dword[timerThreadHandle],eax ret 0 And finally there's your Time1Timer proc because I'm simulating the timer with a thread there will be an outer loop representing the intervals. Code: TimerProc: ;referenced in the above code snippet for CreateThread push ebx esi edi .TimerLoop: ;infinitely loop with a delay invoke SleepEx, dword[timerDelayInMS],0 ;timerDelay referenced in above snippet ;SleepEx with suspend the thread for timerDelayInMS milliseconds mov ebx,0 ; g=0 .GLoop: ;while g<90 ;random(4) we can simulate this in ASM using RDTSC ;this will retrieve the processors internal tick counter ;while it is NOT random it is pseudo random enough for our use rdtsc ; a = rand(4); a will be our esi register mov esi,eax and esi,3 ;clamp result between 0 and 3 ;this is a shortcut because 4 is a power of two ;so 4-1 can be used as a clamping mask cmp esi,0 ; if a = 0 jne .skip0 call pravo .skip0: cmp esi,1 ; if a = 1 jne .skip1 call down .skip1: cmp esi,2 ; if a = 2 jne .skip2 call levo .skip2: cmp esi,3 ; if a = 3 jne .skip3 call up .skip3: add ebx,1 ;g = g + 1 cmp ebx,90 jl .GLoop ; while g < 90 continue looping jmp .TimerLoop pop edi esi ebx ret 4 The above was written in my browser window (it is NOT tested) so there may be errors. If you make an attempt to write the ASM yourself using the examples folder as a reference we can help you from there. *edited * good catch * to preserve "a" using the ESI register instead of EAX Last edited by r22 on 03 Aug 2009, 19:40; edited 1 time in total |
|||
![]() |
|
windwakr 03 Aug 2009, 19:35
Your call codes could possibly modify eax, and possibly make more than one of the button calls be taken. I know it's just an example to show how its basically done, but you don't want to start his assembly learning off with accidental bad code.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.