fix pointer aritmetic

This commit is contained in:
PoliEcho 2025-07-09 13:26:06 +02:00
parent 76093db3c9
commit c0bd3fcbc3
2 changed files with 29 additions and 21 deletions

View File

@ -6,16 +6,20 @@ section .bss
extern term_rows extern term_rows
extern term_cols extern term_cols
extern gameboard_size
simulation_running: RESB 1 simulation_running: RESB 1
section .rodata section .rodata
clear: db ESC_CHAR, "[2J", 0 clear: db ESC_CHAR, "[2J", 0
reset: db ESC_CHAR, "[0m", 0 reset: db ESC_CHAR, "[0m", 0
resetLen: equ $-reset-1
global resetLen
home_cursor: db ESC_CHAR, "[H", 0 home_cursor: db ESC_CHAR, "[H", 0
statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell h/j to change simulation speed, p to simulation", 0 statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell h/j to change simulation speed, p to simulation", 0
%define START_STOP_position $-statusbar-16 START_STOP_pos: equ $-statusbar-16
start_str: db "START", 0 start_str: db "START", 0
stop_str: db "STOP", 0 stop_str: db "STOP", 0
@ -30,36 +34,29 @@ init_gameboard:
xor rax, rax xor rax, rax
xor rcx, rcx xor rcx, rcx
mov ax, [term_cols]
mov cx, [term_rows]
mul rcx
push rax
push rcx
mov rdi, [gameboard_ptr] mov rdi, [gameboard_ptr]
push rdi
mov rsi, 0x20; set rsi to SPACE character mov rsi, 0x20; set rsi to SPACE character
mov rdx, rax mov rdx, [gameboard_size]
push rdx
call memory_set call memory_set
pop rcx
pop rax
mov rdx, rax pop rdx
sub rdx, rcx; get pointer to start of last line pop rdi
add rdi, rdx; get pointer to last char on screen
mov rdi, [gameboard_ptr] push rdi
add rdi, rax; get end of gameboard inc rdi; so there is not empty chagacter at the end of screen
sub rdi, 4; get space for reset sequence
lea rsi, [reset] lea rsi, [reset]
push rdx
call string_copy call string_copy
pop rdx pop rdi
mov rdi, rdx xor rax, rax
add rdi, [gameboard_ptr] mov ax, [term_cols]
sub rdi, rax
lea rsi, [statusbar] lea rsi, [statusbar]
call string_copy call string_copy

View File

@ -1,5 +1,7 @@
%include "symbols.asm" %include "symbols.asm"
section .bss section .bss
multipurpuse_buf: RESB 8 multipurpuse_buf: RESB 8
@ -11,10 +13,16 @@ section .bss
global gameboard_ptr global gameboard_ptr
gameboard_ptr: RESQ 1 gameboard_ptr: RESQ 1
global gameboard_size
gameboard_size: RESQ 1
extern cursor_rows extern cursor_rows
extern cursor_cols extern cursor_cols
section .rodata
extern resetLen
section .text section .text
extern print_str extern print_str
extern unsigned_int_to_ascii extern unsigned_int_to_ascii
@ -55,7 +63,10 @@ _start:
mov cx, [term_cols] mov cx, [term_cols]
mul rcx mul rcx
mov rdi, rax mov rdi, rax
mov qword [gameboard_size], rax
inc rdi; addition byte for NULL BYTE inc rdi; addition byte for NULL BYTE
lea rax, [resetLen]
add rdi, rax
call alloc call alloc
mov [gameboard_ptr], rax; stores pointer to gameboard array mov [gameboard_ptr], rax; stores pointer to gameboard array
call init_gameboard call init_gameboard