diff options
| author | gbc dev <gbc@localhost> | 2026-07-16 07:21:40 +0200 |
|---|---|---|
| committer | gbc dev <gbc@localhost> | 2026-07-16 07:21:40 +0200 |
| commit | 1f90c9415b2960a349adfc82805b27e5290033e7 (patch) | |
| tree | 65a30526ed45179ad739c75c43b3723eebf1778a /src | |
| parent | serial: clean RX path for headless console (diff) | |
| download | sl0pboy-1f90c9415b2960a349adfc82805b27e5290033e7.tar.gz sl0pboy-1f90c9415b2960a349adfc82805b27e5290033e7.tar.xz sl0pboy-1f90c9415b2960a349adfc82805b27e5290033e7.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gb.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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; |
