aboutsummaryrefslogtreecommitdiffstats
path: root/src/programs.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-22 17:12:52 +0200
committeruser <user@clank>2026-09-22 17:12:52 +0200
commit30e67fe0f4e66e2161ca61f870f8947d50287995 (patch)
treea04189f34687a4d600903100feca18aedc5d1604 /src/programs.asm
parentnet: passive open (listen/accept) + own sockets + close promptly (diff)
downloadgbos-30e67fe0f4e66e2161ca61f870f8947d50287995.tar.gz
gbos-30e67fe0f4e66e2161ca61f870f8947d50287995.tar.xz
gbos-30e67fe0f4e66e2161ca61f870f8947d50287995.zip
usr: httpd - the Game Boy serves its filesystem over HTTP
/# httpd & host$ curl http://10.0.0.2/ -> a listing of the cart RAM host$ curl http://10.0.0.2/readme -> the file, from battery-backed SRAM GET only. "/" serves /index.html if present, else a generated listing; any directory lists with every entry linked, so you can click around a 1997 handheld's disk from a browser. Content type from the extension. No Content-Length: HTTP/1.0 + Connection: close delimits the body by closing, which suits a stack with one in-flight segment. All output goes through one 200-byte buffer, so each net_send is a full segment instead of one tiny segment per string. It drains the whole request, not just the request line. That is not politeness: leaving the rest unread means those segments are never acknowledged, so the client retransmits headers for a minute, never sends its FIN, and its dead connection keeps arriving at port 80 long after we re-listen. One curl with 1.4 KB of headers stalled every following request for 30-120s. It deliberately does NOT read the keyboard either. Backgrounded - the useful way to run it - every key it polled would be a key stolen from the shell's prompt. It is a daemon: kill(1) stops it, and the kernel reclaims its socket. Verified with curl: index, byte-exact file bodies, nested paths, directory listings, 404, 501, a 1.4 KB request spanning segments, browser user-agents, three parallel clients (0.1/1.1/2.1s), the shell staying usable alongside it, and six kill/restart cycles - more than there are sockets.
Diffstat (limited to '')
-rw-r--r--src/programs.asm7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/programs.asm b/src/programs.asm
index a3bd680..31125a2 100644
--- a/src/programs.asm
+++ b/src/programs.asm
@@ -151,6 +151,9 @@ ProgCp:
SECTION "prog_nc", ROMX[$4000], BANK[38]
ProgNc:
INCBIN "build/usr/nc.bin"
+SECTION "prog_httpd", ROMX[$4000], BANK[39]
+ProgHttpd:
+ INCBIN "build/usr/httpd.bin"
; -----------------------------------------------------------------------------
; PROG_SH (bank 3) - the shell, now written in C (usr/sh.c): parses >/</| and
@@ -267,6 +270,8 @@ ProgramTable::
dw ProgCp
db LOW(BANK(ProgNc)), HIGH(BANK(ProgNc))
dw ProgNc
+ db LOW(BANK(ProgHttpd)), HIGH(BANK(ProgHttpd))
+ dw ProgHttpd
ProgramTableEnd::
; -----------------------------------------------------------------------------
@@ -348,4 +353,6 @@ NameTable::
db PROG_CP
db "nc", 0
db PROG_NC
+ db "httpd", 0
+ db PROG_HTTPD
db 0