From 1f90c9415b2960a349adfc82805b27e5290033e7 Mon Sep 17 00:00:00 2001 From: gbc dev Date: Thu, 16 Jul 2026 07:21:40 +0200 Subject: serial: deliver EOF (0x04) on stdin end for headless console read()==0 completes the external-clock transfer with SB=0x04 (EOT), so a gbos program's readc() sees EOF instead of polling forever. Enables cat/wc-style tools and lets the shell exit on Ctrl-D / pipe end. --- src/gb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gb.c b/src/gb.c index 7e6771b..3caa986 100644 --- a/src/gb.c +++ b/src/gb.c @@ -134,11 +134,17 @@ void gb_write(GB *gb, u16 addr, u8 val) { // junk. Stays pending (bit7 set) while stdin has nothing. if (gb->serial_in_fd >= 0) { unsigned char c; - if (read(gb->serial_in_fd, &c, 1) == 1) { + ssize_t n = read(gb->serial_in_fd, &c, 1); + if (n == 1) { gb->sb = c; gb->sc &= ~0x80; gb_request_interrupt(gb, INT_SERIAL); + } else if (n == 0) { + gb->sb = 0x04; // EOF -> EOT (Ctrl-D) + gb->sc &= ~0x80; + gb_request_interrupt(gb, INT_SERIAL); } + // n < 0 (EAGAIN on a live tty): stay pending, poll again } } return; -- cgit v1.3.1-sl0p