SYS_EXIT equ 1 SYS_READ equ 3 SYS_WRITE equ 4 STDIN equ 0 STDOUT equ 1 SYS_IOCTL equ 54 SYS_TIMER_FD_CREATE equ 0x142 SYS_TIMER_FD_SETTIME equ 0x145 section .bss sz RESB 4 ; 4 byte for window size num resb 4 ;4 byte for ascii numbers srow resb 1 ;screen rows scol resb 1 ;screen columns tof resb 1 ; 1 byte store top offstet tmp resb 1 section .data ;num to ascii variables ha db 0 ;hundreds ta db 0 ;tens ;graphics layout rcount db 0; lb db 0xa; linebrak lof db 0; ; left offset gh db 42; ; game height gw db 102; ; game width scrst db 'Score: 000' ; score string scrstln equ $ - scrst ; sore string length scrlof equ 5 ;score lfet offset scrfll equ 85 ;score lfet offset pls db 0x2b ;plus for corner hl db 0x2d ;horizontal line | vl db 0x7c ;vertical line - ;error txt_error_term_dim db 'Error terminal got wrong dimensions' txt_error_term_dim edu 35 ;timer tfd RESB 4 ;file descriptro itimer RESQ 2 ;timer init struct tval RESB 8 ;variable to store triggercount when reading timmerfd ;dino1 ; __ ; / _) ; .-^^^-/ / ; __/ / ;<__.|_|-|_| dino11 db ' __ ' dino12 db ' / _)' dino13 db ' .-^^^-/ / ' dino14 db ' __/ / ' dino15 db '<__.|_|-|_| ' ;dino2 ; __ ; | _) ; .-^^^-| | ; __/ / ;<__./_/-\_\ dino21 db ' __ ' dino22 db ' | _) ' dino23 db ' .-^^^-| | ' dino24 db ' __/ / ' dino25 db '<__./_/-\_\ ' dinolen equ 15 section .text global _start _start: ;create timer mov eax, SYS_TIMER_FD_CREATE mov ebx, 1 mov ecx, 0 int 0x80 ;store fd adress mov [tfd], eax ; get windwo size mov eax, SYS_IOCTL ; syscall ioctl mov ebx, STDOUT ; stdout for something? mov ecx, 0x5413 ; get windowsize command TIOCGWINSZ mov edx, sz ; target struct int 0x80 ; call kernel ;print fullscreen ;save window size mov al, [sz] mov [srow], al mov al, [sz+2] mov [scol], al ;calc offset ;top xor eax, eax xor bx, bx movzx ax, [srow] ;move one byte fill rest with zero ;and ax, 0xFF ; bitmask so that only srow (1byte) is inside ax (2byte) else it is scol+srow ;mov bx, [gh] ;and bx, 0xFF sub ax, [gh] ;screenrows - geameheight mov bl, 2 div bl mov al, 0x6 mov [tof], al ;jmp exit ;left movxz ax, [scol] ;and ax, 0xFF ;mov bx, [gw] ;and bx, 0xFF sub ax, [gw] mov bl, 0x2 div bl mov [lof], al ;print terminal print: jmp topoffset emptyterminal: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, lb mov edx, 1 ;int 0x80 inc byte [rcount] mov al, [rcount] ;cmp [srow], al cmp al, [srow] jl emptyterminal topoffset: mov [rcount], byte 0x0 mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, lb mov edx, 1 ;int 0x80 inc byte [rcount] mov al, [rcount] cmp al, [tof] jle topoffset toprow: tlcorner: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, pls mov edx, 1 int 0x80 tr_start: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, hl mov edx, 1 int 0x80 inc byte [rcount] mov al, [rcount] cmp al, scrlof jl tr_start mov al, 0 mov [rcount], al tr_score: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, scrst mov edx, scrstln int 0x80 tr_fill: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, hl mov edx, 1 int 0x80 inc byte [rcount] mov al, [rcount] cmp al, scrfll jl tr_fill trcorner: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, pls mov edx, 1 int 0x80 linebreak: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, lb mov edx, 1 int 0x80 exit: ;exit mov eax, 1 mov ebx, 0 int 0x80 ; print rows mov ecx, 0 mov cl, [sz] ;rows in ecx hundreds: mov ebx, 100 cmp ecx, ebx ;check if above 100 js bla jae inchundred ;jump to increment hundreds if needed bla: mov eax,[ha] ;hundred count to eax add eax, '0' ;convert to ascii mov [num+0], eax ;move to first byte of num string tens: cmp ecx, 0xa ;check if above 10 jge inctens ;jump to increment tens if needed mov eax,[ta] add eax, '0' mov [num+1], eax mov eax, ecx add eax, '0' mov [num+2], eax mov [num+3], byte 0xa ;linebreak mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, num mov edx, 4 int 0x80 ;print hundreds ;mov eax, [ha] ;add eax, '0' ;mov[ha], eax ;mov eax, SYS_WRITE ;mov ebx, STDOUT ;mov ecx, ha ;mov edx, 1 ;int 0x80 ; print cols ;mov eax, SYS_WRITE ;mov ebx, STDOUT ;mov ecx, sz+2 ;mov edx, 3 ;int 0x80 inchundred: inc byte [ha] ;increment hundreds sub ecx, 0x64 jmp hundreds inctens: inc byte [ta] ;increment tens sub ecx, 0xa jmp tens ;read from timerfd blocking system till timer triggers fd_wait: mov eax, SYS_READ mov ebx, [tfd] mov ecx, tval mov edx, 0x20 int 0x80 ret error_term_dim: mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, txt_error_term_dim mov edx, txt_error_term_dim_size int 0x80 jmp exit