aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gb.c8
1 files changed, 7 insertions, 1 deletions
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;