summary refs log tree commit diff stats
path: root/src/main.asm
diff options
context:
space:
mode:
authorArne <78976058+4rneee@users.noreply.github.com>2024-11-24 17:58:19 +0100
committerGitHub <noreply@github.com>2024-11-24 17:58:19 +0100
commitcf09c58448023a44dcb452dc331efeadd8b1f27e (patch)
treea644d20118c873aa850a9d23aaf29101bf1070fb /src/main.asm
parent5100ff9dd79f0131064de0a5f2e777e7cd485ea5 (diff)
downloadx86_64-Snake-cf09c58448023a44dcb452dc331efeadd8b1f27e.tar.gz
x86_64-Snake-cf09c58448023a44dcb452dc331efeadd8b1f27e.zip
add interrupt handler (#2) HEAD main
Diffstat (limited to 'src/main.asm')
-rw-r--r--src/main.asm21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main.asm b/src/main.asm
index ff509ed..548aaac 100644
--- a/src/main.asm
+++ b/src/main.asm
@@ -18,6 +18,11 @@ section .data
     timespec dq 0 
              dq 250000000
 
+    sigaction dq 0  ; sa_handler
+              dq 0  ; sa_flags
+              dq 0  ; sa_restorer
+              dq 0  ; sa_mask
+
 section .rodata
     ; width and height of the playable area
     ; (without the borders)
@@ -227,8 +232,24 @@ _loop_through_snake:
 _loop_return:    
     ret
 
+_set_interrupt_handler:
+    ; set sa_handler and sa_flags
+    lea rax, [exit]
+    mov [sigaction], rax
+    mov qword [sigaction + 8], 0x04000000 ; SA_RESTORER
+
+    mov rax, 0xD    ; rt_sigaction
+    mov rdi, 2      ; SIGINT
+    lea rsi, [sigaction]
+    xor rdx, rdx
+    mov r10, 8      ; sizeof(sigset_t)
+    syscall
+
+    ret
+
 _start:
     call set_terminal_options
+    call _set_interrupt_handler
     call clear_screen
     call draw_border
     call hide_cursor