summary refs log tree commit diff stats
path: root/src/input.asm
blob: 278b64005e63b4aaade69b7f88c4a0d92055f783 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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