summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rwxr-xr-xset.sh1
-rw-r--r--src/border.asm (renamed from border.asm)0
-rw-r--r--src/input.asm (renamed from input.asm)0
-rw-r--r--src/main.asm (renamed from main.asm)44
-rw-r--r--src/utils.asm (renamed from utils.asm)0
-rwxr-xr-xunset.sh1
7 files changed, 52 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 981bed2..3e674fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
-main: main.asm border.asm utils.asm
+main: src/main.asm src/border.asm src/utils.asm
 	mkdir -p build/
-	nasm -f elf64 -g main.asm -o build/main.o
-	nasm -f elf64 -g border.asm -o build/border.o
-	nasm -f elf64 -g utils.asm -o build/utils.o
-	nasm -f elf64 -g input.asm -o build/input.o
+	nasm -f elf64 -g src/main.asm -o build/main.o
+	nasm -f elf64 -g src/border.asm -o build/border.o
+	nasm -f elf64 -g src/utils.asm -o build/utils.o
+	nasm -f elf64 -g src/input.asm -o build/input.o
 	ld build/main.o build/border.o build/utils.o build/input.o -o main
 
+.PHONY:
 clean:
 	rm -r main build/
diff --git a/set.sh b/set.sh
new file mode 100755
index 0000000..74b1a48
--- /dev/null
+++ b/set.sh
@@ -0,0 +1 @@
+stty -icanon -echo min 0
diff --git a/border.asm b/src/border.asm
index 12774b6..12774b6 100644
--- a/border.asm
+++ b/src/border.asm
diff --git a/input.asm b/src/input.asm
index 278b640..278b640 100644
--- a/input.asm
+++ b/src/input.asm
diff --git a/main.asm b/src/main.asm
index 4828b35..170f6a2 100644
--- a/main.asm
+++ b/src/main.asm
@@ -10,6 +10,11 @@ section .data
     ; x head is at snake[0]
     ; y head is at snake[1]
     snake TIMES 1000 db 0
+    snake_length dw 1
+
+    ; position of the fruit
+    fruit_x db 0
+    fruit_y db 0
 
     ; direction of the snake:
     ;   3
@@ -88,15 +93,54 @@ _move_up:
     dec byte [snake+1]
     ret
 
+fruit_position:
+
+    ; 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
+
 _start:
     call hide_cursor
     mov byte [snake], 5
     mov byte [snake+1], 5
+    call fruit_position
 
 main_loop:
     call clear_screen
     call draw_border
     call draw_snake
+    call draw_fruit
 
     mov rax, 35            
     lea rdi, [timespec]   
diff --git a/utils.asm b/src/utils.asm
index 9281ed2..9281ed2 100644
--- a/utils.asm
+++ b/src/utils.asm
diff --git a/unset.sh b/unset.sh
new file mode 100755
index 0000000..b4e3475
--- /dev/null
+++ b/unset.sh
@@ -0,0 +1 @@
+stty sane