Compare commits
No commits in common. "c5e404f1dd05c005de747e7fbb198ce1ceee9af8" and "a2a5b4c9721f7bd5190ce705edd06981a1d6314a" have entirely different histories.
c5e404f1dd
...
a2a5b4c972
5
Makefile
5
Makefile
@ -7,11 +7,6 @@ LD_FLAGS := --strip-all
|
|||||||
DEBUG_LD_FLAGS := -g
|
DEBUG_LD_FLAGS := -g
|
||||||
DEBUG_NASM_FLAGS := -g -F dwarf
|
DEBUG_NASM_FLAGS := -g -F dwarf
|
||||||
|
|
||||||
# check for avx2 support
|
|
||||||
ifeq ($(shell grep -o 'avx512[^ ]*' /proc/cpuinfo | head -n 1),avx512)
|
|
||||||
NASM_FLAGS += -DAVX512
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
SRC_PATH := src
|
SRC_PATH := src
|
||||||
OBJ_PATH := build/obj
|
OBJ_PATH := build/obj
|
||||||
|
@ -7,7 +7,7 @@ section .text
|
|||||||
global init_alloc
|
global init_alloc
|
||||||
init_alloc:; initialize allocator, optionaly return brk pointer in rax
|
init_alloc:; initialize allocator, optionaly return brk pointer in rax
|
||||||
mov rax, SYS_BRK
|
mov rax, SYS_BRK
|
||||||
xor rdi, rdi
|
mov rdi, 0
|
||||||
syscall
|
syscall
|
||||||
mov [brk_pointer], rax
|
mov [brk_pointer], rax
|
||||||
ret
|
ret
|
||||||
@ -15,10 +15,9 @@ init_alloc:; initialize allocator, optionaly return brk pointer in rax
|
|||||||
global alloc
|
global alloc
|
||||||
alloc:; Takes lenght of data in rdi and returns pointer in rax
|
alloc:; Takes lenght of data in rdi and returns pointer in rax
|
||||||
mov rax, SYS_BRK
|
mov rax, SYS_BRK
|
||||||
mov qword rcx, [brk_pointer]
|
mov rcx, [brk_pointer]
|
||||||
push rcx
|
push rcx
|
||||||
add rdi, rcx; calculate new BRK address
|
syscall; size already in rdi
|
||||||
syscall
|
|
||||||
mov [brk_pointer], rax
|
mov [brk_pointer], rax
|
||||||
pop rax
|
pop rax
|
||||||
ret
|
ret
|
||||||
|
@ -1,76 +1,54 @@
|
|||||||
%include "symbols.asm"
|
%include "symbols.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
extern gameboard_ptr
|
extern gameboard_ptr
|
||||||
|
|
||||||
extern term_rows
|
extern term_rows
|
||||||
extern term_cols
|
extern term_cols
|
||||||
|
|
||||||
extern gameboard_size
|
section .data
|
||||||
|
|
||||||
simulation_running: RESB 1
|
|
||||||
|
|
||||||
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
|
statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell, p to simulation", 0
|
||||||
|
|
||||||
|
|
||||||
statusbar: db ESC_CHAR, "[30;100m", "Use arrow keys to move cursor, enter to invert cell h/j to change simulation speed, p to simulation", 0
|
|
||||||
START_STOP_pos: equ $-statusbar-16
|
|
||||||
|
|
||||||
|
|
||||||
start_str: db "START", 0
|
|
||||||
stop_str: db "STOP ", 0
|
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
extern print_str
|
extern print_str
|
||||||
extern string_copy
|
extern string_copy
|
||||||
extern memory_set
|
|
||||||
|
|
||||||
global init_gameboard
|
|
||||||
init_gameboard:
|
init_gameboard:
|
||||||
xor rax, rax
|
mov ax, [term_cols]
|
||||||
xor rcx, rcx
|
mov cx, [term_rows]
|
||||||
|
mul rcx
|
||||||
|
|
||||||
|
mov rdx, rax
|
||||||
|
sub rdx, rcx; get pointer to start of last line
|
||||||
|
|
||||||
mov rdi, [gameboard_ptr]
|
lea rdi, [gameboard_ptr]
|
||||||
push rdi
|
add rdi, rax; get end of gameboard
|
||||||
mov rsi, 0x20; set rsi to SPACE character
|
|
||||||
mov rdx, [gameboard_size]
|
sub rdi, 5; get space for reset sequence
|
||||||
push rdx
|
|
||||||
add rdx, ESC_chars_compensation_Len; I dont know how this work but it works so i wont touch it
|
|
||||||
call memory_set
|
|
||||||
|
|
||||||
|
|
||||||
pop rdx
|
|
||||||
pop rdi
|
|
||||||
add rdi, rdx; get pointer to last char on screen
|
|
||||||
push rdi
|
|
||||||
add rdi, ESC_chars_compensation_Len
|
|
||||||
lea rsi, [reset]
|
lea rsi, [reset]
|
||||||
|
|
||||||
|
push rdx
|
||||||
call string_copy
|
call string_copy
|
||||||
pop rdi
|
|
||||||
xor rax, rax
|
pop rdx
|
||||||
mov ax, [term_cols]
|
mov rdi, rdx
|
||||||
sub rdi, rax
|
|
||||||
lea rsi, [statusbar]
|
lea rsi, [statusbar]
|
||||||
call string_copy
|
call string_copy
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
global print_game_ui
|
|
||||||
print_game_ui:
|
print_game_ui:
|
||||||
lea rdi, [home_cursor]
|
lea rdi, [clear]
|
||||||
call print_str
|
|
||||||
|
|
||||||
mov qword rdi, [gameboard_ptr]
|
|
||||||
call print_str
|
call print_str
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
35
src/main.asm
35
src/main.asm
@ -1,37 +1,24 @@
|
|||||||
%include "symbols.asm"
|
%include "symbols.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
multipurpuse_buf: RESB 8
|
multipurpuse_buf: RESB 8
|
||||||
|
|
||||||
global term_rows
|
|
||||||
term_rows: RESW 1
|
|
||||||
global term_cols
|
|
||||||
term_cols: RESW 1
|
|
||||||
|
|
||||||
global gameboard_ptr
|
|
||||||
gameboard_ptr: RESQ 1
|
|
||||||
|
|
||||||
global gameboard_size
|
term_rows: RESW 1
|
||||||
gameboard_size: RESQ 1
|
term_cols: RESW 1
|
||||||
|
|
||||||
|
gameboard_ptr: RESQ 1
|
||||||
|
|
||||||
extern cursor_rows
|
extern cursor_rows
|
||||||
extern cursor_cols
|
extern cursor_cols
|
||||||
|
|
||||||
|
section .data
|
||||||
|
|
||||||
section .rodata
|
|
||||||
extern resetLen
|
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
extern print_str
|
extern print_str
|
||||||
extern unsigned_int_to_ascii
|
extern unsigned_int_to_ascii
|
||||||
extern init_alloc
|
extern init_alloc
|
||||||
extern alloc
|
extern alloc
|
||||||
|
|
||||||
extern init_gameboard
|
|
||||||
extern print_game_ui
|
|
||||||
|
|
||||||
global _start
|
global _start
|
||||||
_start:
|
_start:
|
||||||
; get terminal dimensions
|
; get terminal dimensions
|
||||||
@ -56,24 +43,12 @@ _start:
|
|||||||
|
|
||||||
call init_alloc
|
call init_alloc
|
||||||
|
|
||||||
xor rax, rax
|
|
||||||
xor rcx, rcx
|
|
||||||
|
|
||||||
mov ax, [term_rows]
|
mov ax, [term_rows]
|
||||||
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
|
|
||||||
lea rax, [resetLen]
|
|
||||||
add rdi, rax
|
|
||||||
add rdi, ESC_chars_compensation_Len
|
|
||||||
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 print_game_ui
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
79
src/str.asm
79
src/str.asm
@ -60,84 +60,15 @@ unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi D
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
global string_copy
|
|
||||||
string_copy:; takes pointer to destination in rdi and pointer to source in rsi
|
string_copy:; takes pointer to destination in rdi and pointer to source in rsi
|
||||||
|
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
xor rcx, rcx
|
|
||||||
.copy_next_byte:
|
.copy_next_byte:
|
||||||
mov byte cl, [rsi+rax]
|
mov byte al, [rdi+rax]
|
||||||
test cl, cl
|
mov [rsi+rax], al
|
||||||
jz .exit
|
|
||||||
mov [rdi+rax], cl
|
|
||||||
inc rax
|
inc rax
|
||||||
jmp .copy_next_byte
|
test rax,rax
|
||||||
|
jnz .copy_next_byte
|
||||||
.exit:
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
global memory_set:
|
|
||||||
memory_set:; takes destination in rdi, byte in sil and lenght in rdx
|
|
||||||
; first check if value is 16 byte alligned
|
|
||||||
|
|
||||||
mov r9, rdi; move destination to r9
|
|
||||||
|
|
||||||
mov r11, 0x0101010101010101; to extend across whoule register
|
|
||||||
movzx rsi, sil
|
|
||||||
imul r11, rsi; to extend across whoule register
|
|
||||||
|
|
||||||
cmp rdx, 16
|
|
||||||
jnl .write_16_or_more_bytes
|
|
||||||
mov rcx, rdx
|
|
||||||
jmp .write_less_than_16_bytes
|
|
||||||
.write_16_or_more_bytes:
|
|
||||||
mov rax, rdi; move destination to rax
|
|
||||||
and rax, 0xF; offset is stored in rax
|
|
||||||
|
|
||||||
|
|
||||||
test al, al; check if resault is 0
|
|
||||||
jz .addr_is_16_Byte_alligned
|
|
||||||
|
|
||||||
|
|
||||||
mov cl, 16
|
|
||||||
sub cl, al; now offset to first higher 16 byte alligned address is stored in r8
|
|
||||||
movzx rcx, cl; remove ani posible garbage
|
|
||||||
|
|
||||||
|
|
||||||
.write_less_than_16_bytes:
|
|
||||||
mov rax, r11
|
|
||||||
sub rdx, rcx; we will write these bytes now
|
|
||||||
|
|
||||||
rep stosb
|
|
||||||
|
|
||||||
.addr_is_16_Byte_alligned:
|
|
||||||
mov r10, rdx
|
|
||||||
shr r10, 4; set it to how many 128bit(16Byte) chunk we need
|
|
||||||
test r10, r10; check if we need to write aditional 16 bytes at all
|
|
||||||
jz .function_exit
|
|
||||||
|
|
||||||
%ifdef AVX512
|
|
||||||
vpbroadcastq xmm8, r11
|
|
||||||
%else
|
|
||||||
movq xmm8, r11
|
|
||||||
shufpd xmm8, xmm8, 0x00
|
|
||||||
%endif
|
|
||||||
|
|
||||||
.move_16_bytes:
|
|
||||||
movdqa [rdi], xmm8
|
|
||||||
add rdi, 16
|
|
||||||
sub rdx, 16
|
|
||||||
|
|
||||||
cmp rdx, 16; test if rdx is less than 16
|
|
||||||
jge .move_16_bytes
|
|
||||||
|
|
||||||
.function_exit:
|
|
||||||
|
|
||||||
test rdx, rdx; test if rdx is 0
|
|
||||||
jz .true_function_exit
|
|
||||||
mov cl, dl
|
|
||||||
jmp .write_less_than_16_bytes
|
|
||||||
|
|
||||||
.true_function_exit:
|
|
||||||
mov rax, r9; return pointer to memory area same as memset in libc
|
|
||||||
ret
|
|
||||||
|
@ -8,5 +8,3 @@ TIOCGWINSZ equ 0x5413
|
|||||||
|
|
||||||
ASCII_ZERO equ 48
|
ASCII_ZERO equ 48
|
||||||
ESC_CHAR equ 27
|
ESC_CHAR equ 27
|
||||||
|
|
||||||
ESC_chars_compensation_Len equ 9; i have to compensate for escape sequences that dont get printed why 11 exactly, I dont know
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user