aboutsummaryrefslogtreecommitdiffstats
path: root/include/gbos.inc
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-17 13:43:10 +0200
committeruser <user@clank>2026-07-17 13:43:10 +0200
commitb52f37602968768901d2dd83ccf966d953a532f0 (patch)
treed497c52bf672291d1cd9cf0579b6191155cb56d4 /include/gbos.inc
parentnet: keep network packets out of the console (fixes shell garbage on netboot) (diff)
downloadgbos-b52f37602968768901d2dd83ccf966d953a532f0.tar.gz
gbos-b52f37602968768901d2dd83ccf966d953a532f0.tar.xz
gbos-b52f37602968768901d2dd83ccf966d953a532f0.zip
kernel: sys_sleep - a cooperative delay off the DIV timer (+ ping pacing)
There was no time source at all (IRQ vectors just reti; scheduler is purely cooperative). The DIV register (FF04) free-runs at 16384 Hz regardless of interrupts, so sys_sleep accumulates DIV deltas across SchedYields (other procs keep running) until the requested number of 1/64-second units elapse. - SYS_SLEEP(34): B = 1/64s units; libc gsleep(units) / msleep(ms) wrappers. - ping now msleep(800) between echoes, so it paces like real ping instead of blasting all four at once. Verified real-time (capped emulator): replies land ~0.85s apart. In --uncapped runs the delay is GB-time (fast wall-clock), as expected.
Diffstat (limited to 'include/gbos.inc')
-rw-r--r--include/gbos.inc4
1 files changed, 3 insertions, 1 deletions
diff --git a/include/gbos.inc b/include/gbos.inc
index 74eee8e..049a4bc 100644
--- a/include/gbos.inc
+++ b/include/gbos.inc
@@ -10,6 +10,7 @@ DEF GBOS_INC EQU 1
; -----------------------------------------------------------------------------
DEF rIF EQU $FF0F ; interrupt flags
DEF rIE EQU $FFFF ; interrupt enable
+DEF rDIV EQU $FF04 ; divider register: free-running 8-bit @ 16384 Hz
DEF rSVBK EQU $FF70 ; CGB WRAM bank select ($D000-$DFFF): 1..7
DEF wCurMask EQU $D589 ; term/osk: cursor underline bits OR'd into a tile's last row
DEF OSK_DOCK EQU 3 ; on-screen keyboard height in rows (dock at the bottom)
@@ -131,7 +132,8 @@ DEF SYS_SRECV EQU 30 ; link-port: receive one byte (-> A=byte, blocks)
DEF SYS_SRECVNB EQU 31 ; link-port: receive, non-blocking (-> A=byte, CF=none)
DEF SYS_POLLIN EQU 32 ; poll OSK for a typed char (-> A=char or 0)
DEF SYS_NET EQU 33 ; socket layer (DE=&netreq -> A=result)
-DEF SYS_MAX EQU 34
+DEF SYS_SLEEP EQU 34 ; cooperative delay (B = 1/64-second units)
+DEF SYS_MAX EQU 35
; ---- socket layer (SYS_NET) --------------------------------------------------
; netreq struct (in caller RAM; DE points to it):