aboutsummaryrefslogtreecommitdiffstats
path: root/c/netlib.h
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-17 01:31:38 +0200
committeruser <user@clank>2026-07-17 01:31:38 +0200
commit62171c761c72f7bc515b20361d043bfd239f71c9 (patch)
tree4a3f1046403cd58177c4d9fa64d4af8ca066cac2 /c/netlib.h
parentnet: SLIP framing over the link port + a host gateway (echo round-trip) (diff)
downloadgbos-62171c761c72f7bc515b20361d043bfd239f71c9.tar.gz
gbos-62171c761c72f7bc515b20361d043bfd239f71c9.tar.xz
gbos-62171c761c72f7bc515b20361d043bfd239f71c9.zip
net: wget - real HTTP over the link port via the gateway
Grow the link-port demo from echo to actual network access. The Game Boy still only does SLIP framing + display; the host gateway does DNS/TCP/HTTP. - c/netlib.h: SLIP framing factored out (header-only, per-program copy). necho.c now uses it too. - c/wget.c: `wget URL` frames the URL, then prints the reply body. The gateway streams the body back as typed frames: 'D'<chunk> ... 'E'. - tools/gateway.py: add --mode http (urlopen the frame as a URL, cap the body, chunk it) alongside --mode echo; --cmd runs any gbos command. Verified: `wget example.com` streams back the full Example Domain HTML onto the terminal; `wget sl0p.foo` fetches the real page. A Game Boy on the web, over the link cable.
Diffstat (limited to 'c/netlib.h')
-rw-r--r--c/netlib.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/c/netlib.h b/c/netlib.h
new file mode 100644
index 0000000..ec98eac
--- /dev/null
+++ b/c/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