diff options
| author | Christian Krinitsin <code@krinitsin.xyz> | 2024-11-21 14:51:27 +0100 |
|---|---|---|
| committer | Christian Krinitsin <code@krinitsin.xyz> | 2024-11-21 14:51:27 +0100 |
| commit | 3c90c7ab15aa276b6766f37d6b159a31fbe778bc (patch) | |
| tree | 8549c822158cc192e6103f0cd66c588b92006a51 /src/fruit.asm | |
| parent | b1ae885a7e701f69a8b18c2e3012329733c8e57c (diff) | |
| download | x86_64-Snake-3c90c7ab15aa276b6766f37d6b159a31fbe778bc.tar.gz x86_64-Snake-3c90c7ab15aa276b6766f37d6b159a31fbe778bc.zip | |
add fruit, which respawns when touched and snake with length 2
Diffstat (limited to 'src/fruit.asm')
| -rw-r--r-- | src/fruit.asm | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/fruit.asm b/src/fruit.asm new file mode 100644 index 0000000..31226af --- /dev/null +++ b/src/fruit.asm @@ -0,0 +1,54 @@ +section .data + + ; position of the fruit + global fruit_x + global fruit_y + fruit_x db 0 + fruit_y db 0 + +section .text + global draw_fruit + global spawn_fruit + extern width + extern height + extern reset_cursor + extern write_byte + extern move_cursor_right + extern move_cursor_down + +spawn_fruit: + + ; x position + rdtsc + shr ax, 5 + div byte [width] + mov byte [fruit_x], ah +;; TODO + rdtsc + shr ax, 5 + div byte [height] + mov byte [fruit_y], ah + + ret + +draw_fruit: + push rbx + call reset_cursor + mov bh, byte [fruit_x] + mov bl, byte [fruit_y] + +_30:call move_cursor_right + dec bh + cmp bh, 0 + jnz _30 +_31:call move_cursor_down + dec bl + cmp bl, 0 + jnz _31 + + mov rax, '*' + call write_byte + + pop rbx + call reset_cursor + ret |