aboutsummaryrefslogtreecommitdiffstats
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/gbos.h2
-rw-r--r--c/libc.c9
-rw-r--r--c/libc.s9
-rw-r--r--c/ping.c1
4 files changed, 20 insertions, 1 deletions
diff --git a/c/gbos.h b/c/gbos.h
index 6ecbd4a..390fe3a 100644
--- a/c/gbos.h
+++ b/c/gbos.h
@@ -18,6 +18,8 @@ unsigned char srecv(void); /* link-port: receive one byte (blocks)
int srecv_nb(void); /* link-port: receive, or -1 if none */
unsigned char pollin(void); /* poll OSK for a typed char, or 0 */
unsigned char sys_net(void *req); /* socket layer trap (see sock.h) */
+void gsleep(unsigned char units); /* delay units*(1/64)s (raw trap) */
+void msleep(unsigned int ms); /* delay ~ms milliseconds */
/* helpers (c/libc.c) */
void putu(unsigned int n); /* print decimal */
diff --git a/c/libc.c b/c/libc.c
index 9da63bc..a48a64c 100644
--- a/c/libc.c
+++ b/c/libc.c
@@ -1,6 +1,15 @@
/* gbos libc C helpers (compiled once, linked into every program). */
#include "gbos.h"
+/* sleep for approximately 'ms' milliseconds (cooperative; other procs run).
+ The kernel counts in 1/64-second units (~15.6 ms), so we round ms to that. */
+void msleep(unsigned int ms) {
+ unsigned int u = ms >> 4; /* ~ms/15.6, close enough for a delay */
+ if (u > 255) u = 255;
+ if (u == 0 && ms) u = 1;
+ gsleep((unsigned char)u);
+}
+
/* print an unsigned int in decimal */
void putu(unsigned int n) {
char buf[5];
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
diff --git a/c/ping.c b/c/ping.c
index c98f106..68c4c86 100644
--- a/c/ping.c
+++ b/c/ping.c
@@ -47,6 +47,7 @@ void main(void) {
} else {
puts(" seq="); putu(seq); puts(" timeout"); nl();
}
+ if (seq < 4) msleep(800); /* pace like real ping */
}
puts("-- "); putu(got); puts("/4 received"); nl();
net_close(s);