added some gameboard initialization
This commit is contained in:
parent
51ffd98872
commit
a2a5b4c972
@ -21,3 +21,4 @@ alloc:; Takes lenght of data in rdi and returns pointer in rax
|
||||
mov [brk_pointer], rax
|
||||
pop rax
|
||||
ret
|
||||
|
||||
|
54
src/drawing.asm
Normal file
54
src/drawing.asm
Normal file
@ -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
|
12
src/input.asm
Normal file
12
src/input.asm
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
section .bss
|
||||
cursor_rows: RESW 1
|
||||
cursor_cols: RESW 1
|
||||
|
||||
section .text
|
||||
|
||||
global handle_user_input
|
||||
handle_user_input:
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
18
src/str.asm
18
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
|
||||
|
||||
|
@ -7,3 +7,4 @@ STDOUT equ 1
|
||||
TIOCGWINSZ equ 0x5413
|
||||
|
||||
ASCII_ZERO equ 48
|
||||
ESC_CHAR equ 27
|
||||
|
Loading…
x
Reference in New Issue
Block a user