Compare commits
11
Commits
57987228b0
...
v1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82e55b3e1e | ||
|
|
6d3279f850 | ||
|
|
1820d4fdf8 | ||
|
|
81367baa99 | ||
|
|
33b6a82a42 | ||
|
|
755f9b9f06 | ||
|
|
c3563fcda1 | ||
|
|
719bc17fcd | ||
|
|
5c91ace69b | ||
|
|
872c842e7c | ||
|
|
a6a7debf2e |
@@ -1,5 +1,7 @@
|
||||
# AMD64 Assembly Game of life
|
||||
<img src="https://git.pupes.org/repo-avatars/e4ede9d30f070c9e191eace5a88dcaa40434b9cadf60204122fab5a83aec9a9f" alt="logo of ParaDocs" width="196"></img>
|
||||
[](https://git.pupes.org/PoliEcho/asm-game-of-life/actions?workflow=build_test.yaml)
|
||||
# AMD64 Assembly Game of life
|
||||
|
||||
|
||||
## Dependencies
|
||||
> AMD64 Linux Kernel
|
||||
@@ -9,9 +11,25 @@
|
||||
> make
|
||||
|
||||
## Download
|
||||
#### TODO: add releases link
|
||||
[releases](https://git.pupes.org/PoliEcho/asm-game-of-life/releases)
|
||||
|
||||
## Build
|
||||
```shell
|
||||
make
|
||||
```
|
||||
```
|
||||
|
||||
## Controls
|
||||
| key | action |
|
||||
|--------|-------------------------|
|
||||
| arrows | move cursor |
|
||||
| ENTER | invert cell |
|
||||
| j/k | change simulation speed |
|
||||
| p | start/stop simulation |
|
||||
| q | quit |
|
||||
|
||||
|
||||
## Warning
|
||||
delays in TTY may be broken
|
||||
|
||||
## Notes
|
||||
if screen does not clear properly after loading just move the cursor around a bit
|
||||
+2
-2
@@ -26,9 +26,9 @@ section .rodata
|
||||
|
||||
home_cursor: db ESC_CHAR, "[H", 0
|
||||
|
||||
statusbar: db ESC_CHAR, "[32;100m", "Use arrow keys to move cursor, enter to invert cell j/k to change simulation speed, p to simulation. SPEED:", 0
|
||||
statusbar: db ESC_CHAR, "[32;100m", "Use arrow keys to move cursor, enter to invert cell j/k to change simulation speed, p to simulation. Frame Delay multiplier:", 0
|
||||
statusbarLen: equ $-statusbar
|
||||
START_STOP_pos: equ statusbarLen-25
|
||||
START_STOP_pos: equ statusbarLen-42
|
||||
|
||||
|
||||
start_str: db "START", 0
|
||||
|
||||
+30
-2
@@ -12,6 +12,8 @@ section .bss
|
||||
extern gameboard_ptr
|
||||
|
||||
extern simulation_running
|
||||
|
||||
extern running_in_tty
|
||||
section .data
|
||||
cursor_rows: dw 1
|
||||
cursor_cols: dw 1
|
||||
@@ -49,6 +51,7 @@ global handle_user_input
|
||||
handle_user_input:; main loop of the program
|
||||
push r12
|
||||
push r13
|
||||
push r14
|
||||
|
||||
|
||||
lea r12, [multipurpuse_buf]
|
||||
@@ -72,12 +75,26 @@ handle_user_input:; main loop of the program
|
||||
movss xmm0, [speed_multiplier]
|
||||
movss xmm1, [simulation_speed]
|
||||
mulss xmm0, xmm1; callculate sleep lenght
|
||||
cvttss2si rdx, xmm0; truncate and copy to rdx
|
||||
cvttss2si rdx, xmm0; truncate and copy to rdx
|
||||
mov r14, rdx
|
||||
syscall
|
||||
|
||||
mov sil, [running_in_tty]
|
||||
test sil, sil
|
||||
jz .skip_tty_mul
|
||||
push rax
|
||||
mov rax, 2500; magic number
|
||||
xor rdx,rdx
|
||||
mul r14
|
||||
mov r14, rax
|
||||
pop rax
|
||||
|
||||
.skip_tty_mul:
|
||||
test rax, rax; SYS_POLL returns 0 when no change happens within timeout
|
||||
jz .no_input
|
||||
|
||||
.repeat_read:
|
||||
|
||||
xor rax, rax
|
||||
mov qword [r12], rax; zeroout the buffer
|
||||
|
||||
@@ -88,8 +105,18 @@ handle_user_input:; main loop of the program
|
||||
syscall; read user input
|
||||
|
||||
cmp rax, EAGAIN
|
||||
je .no_input
|
||||
jne .handle_input
|
||||
mov al, [running_in_tty]
|
||||
test al, al
|
||||
jz .no_input
|
||||
; this runs only if running in tty
|
||||
|
||||
test r14, r14
|
||||
jz .no_input; timeout
|
||||
dec r14
|
||||
jmp .repeat_read
|
||||
|
||||
.handle_input:
|
||||
mov rax, [r12]
|
||||
|
||||
cmp eax, 0x00415B1B; check if input is more than left arrow
|
||||
@@ -237,6 +264,7 @@ handle_user_input:; main loop of the program
|
||||
jmp .main_loop
|
||||
|
||||
.function_exit:
|
||||
pop r14
|
||||
pop r13
|
||||
pop r12
|
||||
ret
|
||||
|
||||
+46
-2
@@ -19,7 +19,9 @@ section .bss
|
||||
|
||||
extern cursor_rows
|
||||
extern cursor_cols
|
||||
|
||||
|
||||
global running_in_tty
|
||||
running_in_tty: RESB 1
|
||||
|
||||
section .rodata
|
||||
extern resetLen
|
||||
@@ -27,6 +29,8 @@ section .rodata
|
||||
hide_cursor: db ESC_CHAR, "[?25l", 0
|
||||
show_cursor: db ESC_CHAR, "[?25h", 0
|
||||
|
||||
help_text: db "asm-game-of-life [args]",0xA,"-h display this help menu",0xA,"Controls:",0xA,"use arrow keys to move around",0xA,"ENTER to invert cell",0xA,"p to START/STOP simulation",0xA,"k to increase simulation speed",0xA,"j to decrese simulation speed",0xA, 0
|
||||
|
||||
section .text
|
||||
extern print_str
|
||||
extern unsigned_int_to_ascii
|
||||
@@ -58,11 +62,50 @@ _start:
|
||||
|
||||
; handle args
|
||||
pop rcx; get argc (number of arguments)
|
||||
pop rax; get rid of program name arugument
|
||||
cmp rcx, 1
|
||||
jle .no_arguments_provided
|
||||
; TODO hanndle arguments
|
||||
dec rcx
|
||||
.handle_arg:
|
||||
pop rax
|
||||
mov word di, [rax]
|
||||
|
||||
cmp di, 0x682D; check if -h was passed
|
||||
jne .next_arg
|
||||
lea rdi, [help_text]
|
||||
call print_str
|
||||
jmp .exit_program
|
||||
|
||||
.next_arg:
|
||||
dec rcx
|
||||
test rcx, rcx
|
||||
jnz .handle_arg
|
||||
|
||||
.no_arguments_provided:
|
||||
|
||||
|
||||
pop rax; get rid of null termination of argv
|
||||
; handle enviroment vars
|
||||
|
||||
.handle_env:
|
||||
pop rax
|
||||
test rax, rax; test if we reached end of envs
|
||||
jz .no_envs
|
||||
|
||||
mov dword edi, [rax]
|
||||
cmp edi, 0x4D524554; check for "TERM" inverted becose endiannes
|
||||
jne .handle_env
|
||||
mov qword rdi, [rax+5]; remove the TERM= part this should never segfault since there sould allwas be other data behind enviroment vars and i dont mind garbage
|
||||
mov rsi, 0xffffffffff
|
||||
and rdi, rsi
|
||||
mov rsi, 0x78756e696c
|
||||
cmp rdi, rsi; check for "linux"
|
||||
jne .no_envs
|
||||
mov byte [running_in_tty], 1
|
||||
|
||||
.no_envs:
|
||||
|
||||
|
||||
call init_alloc
|
||||
|
||||
xor rax, rax
|
||||
@@ -104,6 +147,7 @@ _start:
|
||||
lea rdi, [show_cursor]
|
||||
call print_str
|
||||
|
||||
.exit_program:
|
||||
mov rax, SYS_EXIT
|
||||
mov rdi, 0 ; return code
|
||||
syscall
|
||||
|
||||
Reference in New Issue
Block a user