diff options
| author | Christian Krinitsin <code@krinitsin.xyz> | 2024-11-21 11:14:01 +0100 |
|---|---|---|
| committer | Christian Krinitsin <code@krinitsin.xyz> | 2024-11-21 11:14:01 +0100 |
| commit | b1ae885a7e701f69a8b18c2e3012329733c8e57c (patch) | |
| tree | 6e576ecbfa4a9266106870c8d39fca65f119fd92 /src/input.asm | |
| parent | 0532d16d65c09494ff21b7e1a9cd3005058be8fc (diff) | |
| download | x86_64-Snake-b1ae885a7e701f69a8b18c2e3012329733c8e57c.tar.gz x86_64-Snake-b1ae885a7e701f69a8b18c2e3012329733c8e57c.zip | |
move into src/ and provide shell files to set the right input properties
Diffstat (limited to 'src/input.asm')
| -rw-r--r-- | src/input.asm | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/input.asm b/src/input.asm new file mode 100644 index 0000000..278b640 --- /dev/null +++ b/src/input.asm @@ -0,0 +1,47 @@ +section .bss + input_buffer resb 1 + +section .text + global input + extern direction + extern exit + +input: + call read_input + call handle_input + ret + +handle_input: + mov al, byte [input_buffer] + cmp al, 'w' + je _input_up + cmp al, 's' + je _input_down + cmp al, 'a' + je _input_left + cmp al, 'd' + je _input_right + cmp al, 27 ; escape + je exit + ret + +_input_up: + mov byte [direction], 3 + ret +_input_down: + mov byte [direction], 1 + ret +_input_left: + mov byte [direction], 2 + ret +_input_right: + mov byte [direction], 0 + ret + +read_input: + mov rax, 0 + mov rdi, 0 + mov rsi, input_buffer + mov rdx, 250 + syscall + ret |