Can now be called tetris

This commit is contained in:
2024-12-18 17:12:33 +01:00
parent ffdb9e2b0e
commit a97406c31f

View File

@@ -21,6 +21,7 @@ EndPaint PROTO
GetClientRect PROTO GetClientRect PROTO
GetTickCount PROTO GetTickCount PROTO
PlaySoundA PROTO PlaySoundA PROTO
Sleep PROTO
RECT struct RECT struct
left dd ? left dd ?
@@ -154,8 +155,7 @@ main PROC
mov byte ptr [playerPosX], 0 mov byte ptr [playerPosX], 0
mov byte ptr [playerPosY], 0 mov byte ptr [playerPosY], 0
; Get Module handle ; Get Module handle
mov rax, GetModuleHandleA(0) mov rax, GetModuleHandleA(0)
mov [moduleHandle], rax mov [moduleHandle], rax
@@ -992,12 +992,61 @@ _loop_break:
ret ret
CheckIfRowFull ENDP CheckIfRowFull ENDP
; (in) rcx: base row ; (in) rcx: base row. row above will get copied
MoveRowDown PROC MoveRowDown PROC
push rdx
push r8
push r9
xor rdx, rdx
_loop:
cmp rdx, GRID_SIZE_X
je _loop_break
; read state
push rcx ; rn Y
dec rcx ; rn Y-1
push rdx ; rn X
xchg rcx, rdx
; rcx->X
; rdx->Y-1
call GetFieldState
mov r8, rax
pop rdx
pop rcx
; to copy is now in r8
push rcx
push rdx
xchg rcx, rdx
call SetFieldState
pop rdx
pop rcx
inc rdx
jmp _loop
_loop_break:
pop r9
pop r8
pop rdx
ret ret
MoveRowDown ENDP MoveRowDown ENDP
; (in) rcx: base row to start
MoveAllRowsDown PROC
push rcx
_loop:
test rcx, rcx
jz _loop_break
call MoveRowDown
dec rcx
jmp _loop
_loop_break:
pop rcx
ret
MoveAllRowsDown ENDP
; (in) rcx row to clear ; (in) rcx row to clear
ClearRow PROC ClearRow PROC
push r8 push r8
@@ -1042,7 +1091,7 @@ innerloop:
jz loop_continue jz loop_continue
inc r8 inc r8
call ClearRow call ClearRow
call MoveRowDown call MoveAllRowsDown
jmp innerloop jmp innerloop
loop_continue: loop_continue:
@@ -1282,8 +1331,8 @@ cleanup:
ret ret
MovePlayerDown ENDP MovePlayerDown ENDP
TryRotateCCW PROC TryRotateCW PROC
call RotateTetroCCW call RotateTetroCW
call IsPlayerJammed call IsPlayerJammed
test rax, rax test rax, rax
jz doReturn jz doReturn
@@ -1291,14 +1340,14 @@ TryRotateCCW PROC
doReturn: doReturn:
ret ret
TryRotateCCW ENDP TryRotateCW ENDP
; (in) rcx keycode ; (in) rcx keycode
OnKeyDown PROC OnKeyDown PROC
and ecx, 00FFFFFFh ; Remove repeat-count and ecx, 00FFFFFFh ; Remove repeat-count
cmp ecx, VK_W cmp ecx, VK_W
je rotateCCW je rotateCW
cmp ecx, VK_S cmp ecx, VK_S
je goDown je goDown
cmp ecx, VK_A cmp ecx, VK_A
@@ -1328,8 +1377,8 @@ goRight:
goRight_cleanup: goRight_cleanup:
call RequestPaint call RequestPaint
jmp cleanup jmp cleanup
rotateCCW: rotateCW:
call TryRotateCCW call TryRotateCW
call RequestPaint call RequestPaint
jmp cleanup jmp cleanup
goDown: goDown: