From 2538b138946128cc5ff473e14ba9bde564aef2e9 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:37:09 +0200 Subject: shell working: fix syscall ABI (trap clobbers HL) + document - root cause of the read/echo corruption: SyscallTrap uses HL to index the dispatch table, so HL is clobbered across a syscall; the shell then wrote its buffer pointer's garbage into the $0000-$7FFF MBC register region, corrupting the mapper. fix: userland saves HL around sys_read (push/pop). - shell now runs commands end to end: $ hello -> hello world!, $ worker -> worker!, $ foo -> ? - README: document that syscalls clobber BC/DE/HL (return in A, B for wait); add read + shell to the syscall table. --- src/programs.asm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/programs.asm') diff --git a/src/programs.asm b/src/programs.asm index df2b98d..d4ae89f 100644 --- a/src/programs.asm +++ b/src/programs.asm @@ -59,8 +59,10 @@ ProgSh: ; read a line into SH_LINEBUF, echoing as we go ld hl, SH_LINEBUF .rd + push hl ; syscalls clobber HL (trap uses it to dispatch) ld c, SYS_READ rst $30 ; A = input byte + pop hl cp $0D jr z, .eol cp $0A @@ -70,7 +72,9 @@ ProgSh: ld [$FF01], a ; echo the char straight to serial ld a, $81 ld [$FF02], a - jr .rd + ld a, l + cp LOW(SH_LINEBUF) + SH_MAXLINE - 1 + jr c, .rd ; keep reading unless the buffer is full .eol ld [hl], 0 ; NUL-terminate -- cgit v1.3.1-sl0p