aboutsummaryrefslogtreecommitdiffstats
path: root/usr/netlib.h
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-18 00:38:38 +0200
committeruser <user@clank>2026-07-18 00:38:38 +0200
commitba2d7ae1d7b319645b10aaa31a7f664f9f80c25c (patch)
treee01e6c7c710a661defe2515ff9657f08cddcb283 /usr/netlib.h
parenttools: gbtype prints hub errors to stderr and exits 1 (diff)
downloadgbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.gz
gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.xz
gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.zip
refactor: c/ -> usr/, compiled program blobs out of the source tree
Userland sources live in usr/ (fits the Unix theme better than 'c'). SDCC output .bin blobs land in build/usr/ with the other build artifacts instead of littering the source dir; programs.asm INCBINs them from there. Byte-identical ROM.
Diffstat (limited to 'usr/netlib.h')
-rw-r--r--usr/netlib.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr/netlib.h b/usr/netlib.h
new file mode 100644
index 0000000..ec98eac
--- /dev/null
+++ b/usr/netlib.h
@@ -0,0 +1,39 @@
+#ifndef NETLIB_H
+#define NETLIB_H
+/* SLIP (RFC 1055) framing over the link port. Header-only so each program gets
+ its own copy (the C build links one translation unit per program). */
+#include "gbos.h"
+
+#define SLIP_END 0xC0
+#define SLIP_ESC 0xDB
+#define SLIP_ESC_END 0xDC
+#define SLIP_ESC_ESC 0xDD
+
+/* send a framed packet (len up to 255) */
+static void slip_send(const char *buf, unsigned char len) {
+ unsigned char i, c;
+ ssend(SLIP_END);
+ for (i = 0; i < len; i++) {
+ c = (unsigned char)buf[i];
+ if (c == SLIP_END) { ssend(SLIP_ESC); ssend(SLIP_ESC_END); }
+ else if (c == SLIP_ESC) { ssend(SLIP_ESC); ssend(SLIP_ESC_ESC); }
+ else ssend(c);
+ }
+ ssend(SLIP_END);
+}
+
+/* receive one framed packet into buf (max), returns its length */
+static unsigned char slip_recv(char *buf, unsigned char max) {
+ unsigned char len = 0, c;
+ for (;;) {
+ c = srecv();
+ if (c == SLIP_END) { if (len) return len; continue; }
+ if (c == SLIP_ESC) {
+ c = srecv();
+ if (c == SLIP_ESC_END) c = SLIP_END;
+ else if (c == SLIP_ESC_ESC) c = SLIP_ESC;
+ }
+ if (len < max) buf[len++] = (char)c;
+ }
+}
+#endif