From d5c06116d3d1257b46c476cf73b634cf089bcb82 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:31:27 +0200 Subject: wip: sys_read + serial console shell (read-store bug under investigation) - sys_read (SYS_READ): blocking console input via external-clock serial poll; yields while waiting. Verified working (direct-echo cat: 'hi' -> 'hi'). - shell (PROG_SH): prompt/read/parse/fork+exec+wait; worker+hello programs; StrEqual/SkipName helpers; command table. - init now execs the shell. - KNOWN BUG: storing the typed char to the line buffer at $A000 (cart RAM of an exec'd program) corrupts the following sys_read; sys_write reading $A000 also returns $3E. Kernel syscalls themselves are correct; isolating the cart-RAM / exec RAM-bank interaction next. --- src/syscall.asm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/syscall.asm') diff --git a/src/syscall.asm b/src/syscall.asm index 4b8771c..bf75865 100644 --- a/src/syscall.asm +++ b/src/syscall.asm @@ -36,7 +36,7 @@ SyscallTrap:: SyscallTable: dw sys_exit ; 0 dw sys_fork ; 1 FORK - dw sys_nosys ; 2 READ (TODO) + dw sys_read ; 2 READ dw sys_write ; 3 WRITE dw sys_nosys ; 4 OPEN (TODO) dw sys_nosys ; 5 CLOSE (TODO) @@ -70,6 +70,25 @@ sys_write: ld a, b ; return len ret +; ----------------------------------------------------------------------------- +; sys_read() -> A = one input byte from the console (blocking). +; Uses an external-clock serial transfer as a clean RX: it completes only when +; the host has a byte (no stdout echo). While waiting we yield so other procs +; run. Preserves BC/DE/HL (the context switch saves/restores them). +; ----------------------------------------------------------------------------- +sys_read: +.poll + ld a, $80 + ld [rSC], a ; request a byte (external clock) + ld a, [rSC] + bit 7, a + jr z, .got ; bit7 clear => transfer completed + call SchedYield ; nothing yet: let others run, then retry + jr .poll +.got + ld a, [rSB] + ret + ; ----------------------------------------------------------------------------- ; sys_getpid() -> A = current pid ; ----------------------------------------------------------------------------- -- cgit v1.3.1-sl0p