From a3e2a558d332e4fcb1d10df2c516b401649543f8 Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Sun, 20 Feb 2022 23:58:50 +0500 Subject: [PATCH] Store update count in a register --- snake.asm | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/snake.asm b/snake.asm index 7e42a8d..5a467dd 100644 --- a/snake.asm +++ b/snake.asm @@ -84,7 +84,6 @@ DEF_STR_DATA cell_sym, CELL_TEXT ; Some global vars status db STATUS_RUN -update_count dq 0 MAP_BUFFER map @@ -459,37 +458,44 @@ place_apple: ret run: - mov rax, input - call poll + push rbx - call handle_key + ; update count + mov rbx, 0 - cmp byte [status], STATUS_EXIT - je .exit + .loop: + mov rax, input + call poll - cmp byte [status], STATUS_DIE - je .die + call handle_key - cmp qword [update_count], MOVE_EVERY_TICK - je .update + cmp byte [status], STATUS_EXIT + je .exit - inc qword [update_count] + cmp byte [status], STATUS_DIE + je .die - mov rax, UPD_DEL_SEC - mov rdx, UPD_DEL_NANO - call sleep + cmp rbx, MOVE_EVERY_TICK + je .update - jmp run + inc rbx + + mov rax, UPD_DEL_SEC + mov rdx, UPD_DEL_NANO + call sleep + + jmp .loop .update: call update - mov qword [update_count], 0 - jmp run + mov rbx, 0 + jmp .loop .die: PRINT_STR_DATA text_game_over .exit: + pop rbx ret init: