aboutsummaryrefslogtreecommitdiffstats
path: root/c/libc.s
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 /c/libc.s
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 '')
-rw-r--r--c/libc.s9
1 files changed, 8 insertions, 1 deletions
diff --git a/c/libc.s b/c/libc.s
index 724fc3b..b413f3b 100644
--- a/c/libc.s
+++ b/c/libc.s
@@ -1,7 +1,7 @@
.module libc
.globl _writes, _putc, _puts, _nl, _strlen, _readc, _sexit, _getpid, _getargs
.globl _open, _close, _fgetc, _fputc, _flist, _fremove, _pipe, _ssend, _srecv, _srecv_nb, _pollin
- .globl _sys_net
+ .globl _sys_net, _gsleep
;; SDCC sm83 sdcccall(1): 1st arg -> A (byte) or DE (pointer); ret A / BC.
;; rst $30 (the trap) clobbers BC/DE/HL; SDCC treats them caller-saved, so
;; wrappers need not preserve them - but we compute cleanly regardless.
@@ -123,6 +123,13 @@ _sys_net:
rst #0x30
ret
+ ;; void gsleep(unsigned char units /*A*/) - delay units*(1/64)s
+_gsleep:
+ ld b, a
+ ld c, #34 ; SYS_SLEEP
+ rst #0x30
+ ret
+
;; unsigned char pollin(void) -> A (typed OSK char, or 0)
_pollin:
ld c, #32 ; SYS_POLLIN