<feed xmlns='http://www.w3.org/2005/Atom'>
<title>gbos.git/c/gbos.h, branch master</title>
<subtitle>gbos - a tiny Unix-flavored OS for the Game Boy Color (kernel, shell, coreutils in C, RAM filesystem)</subtitle>
<id>https://git.sl0p.foo/gbos.git/atom/c/gbos.h?h=master</id>
<link rel='self' href='https://git.sl0p.foo/gbos.git/atom/c/gbos.h?h=master'/>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/'/>
<updated>2026-07-17T22:38:38Z</updated>
<entry>
<title>refactor: c/ -&gt; usr/, compiled program blobs out of the source tree</title>
<updated>2026-07-17T22:38:38Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-17T22:38:38Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c'/>
<id>urn:sha1:ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>net: SYS_POLLCON + larger console ring for link-injected input</title>
<updated>2026-07-17T18:22:34Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-17T18:22:34Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=bf647581fbad727ad22021d345d3955abf44c2f3'/>
<id>urn:sha1:bf647581fbad727ad22021d345d3955abf44c2f3</id>
<content type='text'>
Programs that own their main loop (the IRC client) need to poll for
typed input without blocking. pollin() only sees the on-screen keyboard;
bytes injected over the link (gbhub 'type', for scripted/hub-driven
sessions) land in the kernel console ring, previously only drained by the
blocking KGetc path. Add SYS_POLLCON: a non-blocking con_pop for
userland.

Also enlarge that console ring 16 -&gt; 64. One net_pump drains an entire
serial burst into the ring at once, so a whole injected command line has
to fit or bytes are dropped and lines merge (a 20-char command came out
truncated and glued to the next). 64 covers a full line; mask stays a
power of two.
</content>
</entry>
<entry>
<title>kernel: sys_sleep - a cooperative delay off the DIV timer (+ ping pacing)</title>
<updated>2026-07-17T11:43:10Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-17T11:43:10Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=b52f37602968768901d2dd83ccf966d953a532f0'/>
<id>urn:sha1:b52f37602968768901d2dd83ccf966d953a532f0</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>net: proper socket API in the kernel (SYS_NET) - no more SLIP in userland</title>
<updated>2026-07-17T10:39:01Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-17T10:39:01Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=09ae37313a8b6d567a05a3ae886de78e88cd1afe'/>
<id>urn:sha1:09ae37313a8b6d567a05a3ae886de78e88cd1afe</id>
<content type='text'>
The network stack moves into the kernel. src/socket.asm owns SLIP framing,
IPv4, RFC1071 checksums, and ICMP; programs now speak a socket API through one
syscall (SYS_NET, DE=&amp;netreq dispatched by op): net_socket/connect/send/recv/
close/poll (c/sock.h). No program touches SLIP, IP headers, or checksums.

- Socket table (4 sockets) + tx/rx buffers in WRAM0; our IP = 10.0.0.2.
- net_pump: drains the link, reassembles SLIP frames, demuxes IPv4. Inbound
  ICMP echo requests are auto-answered in-kernel, so the GB replies to pings
  whenever any process pumps RX.
- ICMP sockets: send() emits an echo request to the connected peer; recv()
  returns the matching reply (with a spin/yield timeout).

ping.c is now a ~15-line socket client; netd.c is just `for(;;){net_poll();
yield();}`. Verified over tunbridge:
    /# ping 1.1.1.1     -&gt; replies from the real internet (kernel builds it all)
    host# ping 10.0.0.2 -&gt; 4/4, 0% loss (kernel auto-answers)

Gotchas recorded: gbos.inc isn't a make dep (touch asm after editing); this
crt0 doesn't copy initializers (fill arrays at runtime); and the arg string at
0xA000 overlaps _DATA, so parse targets must sit past it (big buffer first).
UDP and TCP sockets build on this same core next.
</content>
</entry>
<entry>
<title>net: chat client - async receive + OSK send over the link port</title>
<updated>2026-07-16T23:39:29Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T23:39:29Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=c4b9a1b1c4f8c211f765a089b34b66a2d046f3be'/>
<id>urn:sha1:c4b9a1b1c4f8c211f765a089b34b66a2d046f3be</id>
<content type='text'>
The application layer of the link-port demo, and it ties the whole system
together: the LCD terminal displays, the on-screen keyboard types, and the
link port carries a live chat.

Kernel: sys_srecv_nb (non-blocking link receive; A=byte, CF=none) and
sys_pollin (poll the OSK for a typed char without blocking) - syscalls
31/32. Both are what a poll loop needs to receive and type at once.

Userland: c/chat.c runs a poll loop - it feeds non-blocking bytes through a
SLIP receive state machine and prints whole incoming frames as messages,
while pollin() drives the on-screen keyboard; SELECT shows the keys, type a
line, START sends it as a frame. libc srecv_nb()/pollin().

Host: tools/gateway.py --mode chat is a simple bot peer (echoes each GB
message and injects a few async ones); --keys can drive the OSK for tests.

Verified: the gateway pushes 'welcome', '&lt;alice&gt; hey gameboy!', '&lt;bob&gt; nice
link cable' unprompted and the GB displays all three (async receive); typing
'hi' on the OSK echoes it and emits the SLIP frame \xC0hi\xC0 (send). A Game
Boy in the chat, keyboard on screen, over the link cable.
</content>
</entry>
<entry>
<title>net: SLIP framing over the link port + a host gateway (echo round-trip)</title>
<updated>2026-07-16T23:28:23Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T23:28:23Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=b5544e84232b80351e7c58501c1632080a354d12'/>
<id>urn:sha1:b5544e84232b80351e7c58501c1632080a354d12</id>
<content type='text'>
First step of link-port networking. The LCD terminal + OSK freed the serial
port from console duty, so it can be the network link.

Kernel (src/net.asm): raw link-port serial that bypasses the console/
terminal - sys_ssend (transmit, GB drives the clock) and sys_srecv (receive,
GB slave, blocks by yielding). Syscalls 29/30.

Userland: libc ssend()/srecv(); c/necho.c does SLIP (RFC 1055) framing over
them - send a packet, receive the reply, print it.

Host: tools/gateway.py wraps the emulator, owns its link serial, speaks SLIP,
and (for now) echoes every frame back - the "link cable adapter". Console
(ASCII) bytes on the same channel are printed for visibility.

Verified: `necho` sends a SLIP frame, the gateway decodes+echoes it, and gbos
prints the reply - a real framed round-trip over the Game Boy link port.
Next: swap the echo for actual network ops (DNS/HTTP or IRC/chat).
</content>
</entry>
<entry>
<title>kernel+sh: real anonymous pipes (concurrent, streaming, SIGPIPE)</title>
<updated>2026-07-16T23:04:16Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T23:04:16Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=73295e7acc1e5ec3ee8814fd4ccc45f7cee63392'/>
<id>urn:sha1:73295e7acc1e5ec3ee8814fd4ccc45f7cee63392</id>
<content type='text'>
Replace the shell's temp-file pipe hack with proper in-kernel FIFOs.

Kernel (src/pipe.asm, new):
- A small pool of bounded ring buffers (PIPE_MAX=2, 64 B each) with
  writers/readers refcounts. Pipe fds are $F0+idx*2 (read) / +1 (write);
  $FF stays "console".
- SYS_PIPE allocates one (writers=readers=1) and returns the read fd
  (write = read+1). getb/putb/close dispatch pipe fds here; sys_exit drops
  the refcounts held as PROC_STDIN/PROC_STDOUT.
- Blocking with SchedYield, which is the flow control: read blocks while
  empty with a writer (EOF once writers hit 0), write blocks while full
  with a reader, and if the last reader is gone the writer is killed
  (SIGPIPE -&gt; exit 141). Cooperative-scheduler friendly.

Shell (c/sh.c):
- run_pipeline(): split on '|', make a pipe between adjacent stages, and
  fork ALL stages concurrently (no wait between), wiring stdin/stdout;
  then wait for all. Per-stage &gt;/&lt; still honored; orphaned pipe ends are
  closed on a lookup miss so EOF/EPIPE propagate.
- Drop the __pipe temp file and its 2 KB / serialized limits.

libc: pipe(). New c/ptest.c exercises the FIFO (write, read back, EOF).

Now works (old version couldn't): multi-stage a|b|c; streaming beyond 2 KB
(count 120 | wc = 3372 bytes through a 64 B buffer); early-exit SIGPIPE
(count 200 | true kills count instead of hanging/overflowing a file).
</content>
</entry>
<entry>
<title>fs: reject open()/read() on a directory (EISDIR)</title>
<updated>2026-07-16T11:07:28Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T11:07:28Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=fc6f690727aac2b5c9bd368f9b13188fb0ba36a7'/>
<id>urn:sha1:fc6f690727aac2b5c9bd368f9b13188fb0ba36a7</id>
<content type='text'>
open() now checks the target's inode type: opening a directory as a file
returns $FE (EISDIR) instead of a valid fd, so 'cat docs' no longer streams the
raw directory block as bytes. cat reports 'is a directory'; wc/head/save treat
any invalid fd (&gt;3) as an open failure. (ls is unaffected - it uses the
structural opendir/list path, not open/getb.)
</content>
</entry>
<entry>
<title>fs rewrite stage 3: nested directories, paths, cwd (cd/mkdir/ls)</title>
<updated>2026-07-16T10:49:19Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T10:49:19Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=5fefd233769a56caefdb2ffecaa9fb8b9ec6db86'/>
<id>urn:sha1:5fefd233769a56caefdb2ffecaa9fb8b9ec6db86</id>
<content type='text'>
- directories generalized: dir_find/dir_add/dir_remove take any dir inode;
  every dir carries '.'/'..'. Path resolution (resolve / resolve_parent) walks
  absolute or cwd-relative paths; open/mkdir/chdir/remove/opendir take paths.
- per-process cwd: PROC_CWD in the PCB (root by default, inherited on fork);
  sys_chdir sets it, sys_opendir points ls at any directory.
- shell: 'cd' builtin + cwd-aware prompt; 'mkdir'/'ls &lt;dir&gt;' tools; 'exit'/'quit'
  and EOF call poweroff() (clean shutdown via the $ED opcode -&gt; reliable save).
- three HL/buffer-clobber bugs fixed along the way: resolve didn't preserve the
  path cursor across dir_find; cur_cwd clobbered HL; resolve_parent set the final
  name before resolve() overwrote wFsNameBuf (now copied after).
- verified: nested mkdir/cd/save, multi-level paths (cat docs/sub/b), and the
  whole tree persists across a reboot.
- README: document directories + the poweroff opcode.
</content>
</entry>
<entry>
<title>fs rewrite stage 2: inodes + root directory (block-based, persistent)</title>
<updated>2026-07-16T10:20:57Z</updated>
<author>
<name>user</name>
<email>user@clank</email>
</author>
<published>2026-07-16T10:20:57Z</published>
<link rel='alternate' type='text/html' href='https://git.sl0p.foo/gbos.git/commit/?id=4f2d40ca35e0e39886dc881d06256fc25ba27a77'/>
<id>urn:sha1:4f2d40ca35e0e39886dc881d06256fc25ba27a77</id>
<content type='text'>
- fs.asm: a real block filesystem on the persistent block device - superblock,
  block/inode bitmaps, a 32-entry inode table (type, size, 8 direct block
  pointers -&gt; files up to 2 KiB), and a root directory of 16-byte entries.
  Metadata cached in WRAMX; one-block data cache streams file/dir blocks.
- same syscall interface (open/getb/putb/list/remove) -&gt; tools unchanged;
  ls now enumerates until flist() runs out (16 files, was hardcoded 8).
- old 8-slot WRAM FS removed; cart RAM partitioned: process banks 0-7, disk 8-11.
- two register-clobber bugs fixed: alloc_block/alloc_inode returned the
  bitmap-block number (write_bitmap clobbers C); db_use loaded the wrong block
  on a transition (db_flush-&gt;write_block clobbers C) -&gt; multi-block files broke.
- verified: 10+ files, multi-block (300-byte) files, delete, and persistence
  across reboots. Debug 'blk' disk tool retained (fill/peek).
- README: document the block filesystem.
</content>
</entry>
</feed>
