From cb69baa5dfbaf1697d55f46340b666c256165fe3 Mon Sep 17 00:00:00 2001 From: Mikhail Osipov Date: Fri, 24 Sep 2021 21:21:09 +0300 Subject: fix sleep time --- main.s | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/main.s b/main.s index 14b10a2..99a9609 100644 --- a/main.s +++ b/main.s @@ -62,6 +62,10 @@ movsb .endm +.macro syscall + int $0x80 +.endm + DRAWCELL_ARGLEN = 8 + BYTES_PER_PIXEL .equ EV_REL, 1 @@ -483,16 +487,42 @@ life_start: # calc new generation, redraw display on fly + call synctime + life_loop: movb (event), %al testb %al, %al jnz event_handler - movl $SYS_NANOSLEEP, %eax - movl $timespec, %ebx - movl $0, %ecx - int $0x80 + movl $now, %esi + movl $sleeptime, %edi + movsl + movsl + + call synctime + + movl (timespec), %eax + addl %eax, (sleeptime) + movl (timespec + 4), %eax + addl %eax, (sleeptime + 4) + addl $1000000000, (sleeptime + 4) + + movl (now), %eax + subl %eax, (sleeptime) + movl (now + 4), %eax + subl %eax, (sleeptime + 4) + + movl (sleeptime + 4), %eax + xorl %edx, %edx + movl $1000000000, %ebx + divl %ebx + addl %eax, (sleeptime) + movl %edx, (sleeptime + 4) + decl (sleeptime) + + call sleep + call synctime movb (event), %al testb %al, %al @@ -851,6 +881,25 @@ poll_loop: 1: jmp poll_loop +sleep: + movl $SYS_NANOSLEEP, %eax + movl $sleeptime, %ebx + movl $0, %ecx + syscall + ret + +synctime: + movl $SYS_CLOCK_GETTIME, %eax + xorl %ebx, %ebx + movl $now, %ecx + xorl %edx, %edx + syscall + + testl %eax, %eax + jnz gettime_error + + ret + # some functions to output error message open_error: @@ -889,6 +938,10 @@ stat_error: pushl $str_stat jmp sys_error +gettime_error: + pushl $str_gettime + jmp sys_error + mmap_error: pushl $str_mmap @@ -1035,6 +1088,7 @@ str_clone: .asciz "clone" str_access: .asciz "access" str_stat: .asciz "stat" str_fcntl: .asciz "fcntl" +str_gettime: .asciz "clock_gettime" sig_die_set: .byte SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGBUS, SIGTERM, SIGSEGV, 0 @@ -1063,3 +1117,5 @@ timespec: .comm child_pid, 4 .comm pause, 4 .comm binary, 4 +.comm now, 8 +.comm sleeptime, 8 -- cgit v1.2.3-70-g09d2