diff --git a/src/alloc.asm b/src/alloc.asm index 912be80..81cc836 100644 --- a/src/alloc.asm +++ b/src/alloc.asm @@ -21,3 +21,4 @@ alloc:; Takes lenght of data in rdi and returns pointer in rax mov [brk_pointer], rax pop rax ret + diff --git a/src/drawing.asm b/src/drawing.asm new file mode 100644 index 0000000..4e1cd28 --- /dev/null +++ b/src/drawing.asm @@ -0,0 +1,54 @@ +%include "symbols.asm" + +section .bss + extern gameboard_ptr + + extern term_rows + extern term_cols + +section .data + clear: db ESC_CHAR, "[2J", 0 + reset: db ESC_CHAR, "[0m", 0 + + statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell, p to simulation", 0 + + + +section .text +extern print_str +extern string_copy + +init_gameboard: + mov ax, [term_cols] + mov cx, [term_rows] + mul rcx + + mov rdx, rax + sub rdx, rcx; get pointer to start of last line + + lea rdi, [gameboard_ptr] + add rdi, rax; get end of gameboard + + sub rdi, 5; get space for reset sequence + + lea rsi, [reset] + + push rdx + call string_copy + + pop rdx + mov rdi, rdx + lea rsi, [statusbar] + call string_copy + + ret + + +print_game_ui: + lea rdi, [clear] + call print_str + + + + + ret diff --git a/src/input.asm b/src/input.asm new file mode 100644 index 0000000..8dbf484 --- /dev/null +++ b/src/input.asm @@ -0,0 +1,12 @@ + +section .bss + cursor_rows: RESW 1 + cursor_cols: RESW 1 + +section .text + +global handle_user_input +handle_user_input: + + + diff --git a/src/main.asm b/src/main.asm index 3efccaf..6d7ea80 100644 --- a/src/main.asm +++ b/src/main.asm @@ -6,6 +6,11 @@ section .bss term_rows: RESW 1 term_cols: RESW 1 + gameboard_ptr: RESQ 1 + + extern cursor_rows + extern cursor_cols + section .data section .text @@ -39,12 +44,12 @@ _start: call init_alloc mov ax, [term_rows] - dec ax; one less than terminal size for statusbar mov cx, [term_cols] mul rcx mov rdi, rax call alloc - mov r15, rax; stores pointer to gameboard array + mov [gameboard_ptr], rax; stores pointer to gameboard array + diff --git a/src/str.asm b/src/str.asm index f338862..a36da8d 100644 --- a/src/str.asm +++ b/src/str.asm @@ -7,7 +7,7 @@ print_str: ; takes pointer to string in rdi and retuns in rax push rsi push rdx mov rsi, rdi - mov rdx, 0 + xor rdx, rdx .count_loop: cmp byte [rsi+rdx], 0 @@ -25,7 +25,7 @@ print_str: ; takes pointer to string in rdi and retuns in rax global unsigned_int_to_ascii unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi DOES NOT BOUNDS CHECK - mov r11, 0 + xor r11, r11 mov rcx, 10 mov rax, rsi @@ -41,7 +41,7 @@ unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi D .loop_count_exit: push rax - mov rcx, 0 + xor rcx, rcx .store_loop: ; basicly for loop cmp rcx, r11 @@ -60,3 +60,15 @@ unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi D ret +string_copy:; takes pointer to destination in rdi and pointer to source in rsi + + xor rax, rax + + .copy_next_byte: + mov byte al, [rdi+rax] + mov [rsi+rax], al + inc rax + test rax,rax + jnz .copy_next_byte + ret + diff --git a/src/symbols.asm b/src/symbols.asm index 873f593..8d46a2a 100644 --- a/src/symbols.asm +++ b/src/symbols.asm @@ -7,3 +7,4 @@ STDOUT equ 1 TIOCGWINSZ equ 0x5413 ASCII_ZERO equ 48 +ESC_CHAR equ 27