From a5557c75767f7201d5df8c6f95c162044072ef10 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 16:07:01 +0200 Subject: osk: toggle-able on-screen keyboard on the window layer A joypad-driven keyboard that costs zero permanent screen space: it lives on the GB window layer, so SELECT just flips LCDC bit 5 (window enable) and the terminal's background layer underneath is never disturbed. - src/joypad.asm: read $FF00 with edge detection (wPadCur/Prev/New). - src/osk.asm: 3x20 key grid (letters, digits, space, punctuation, plus Enter/Backspace) built once into spare bank-1 VRAM tiles (104+) and laid out on the $9C00 window map, docked to the bottom 3 rows. The highlighted key is a palette swap on its window attribute byte (CGB BG palette 1 = inverted), so moving the cursor is 1-2 attribute writes with no tile rebuilding. SELECT toggles, d-pad moves, A types. - KGetc's console poll loop now polls the joypad and osk_handle each iteration; a key press returns its byte to the reader exactly like a serial byte, so the shell is oblivious to the input source. Verified in the emulator (via --keys): SELECT shows the keyboard, the highlight tracks the d-pad, and typing "ls"+Enter runs the command and lists the files; a second SELECT hides it and reclaims the full 18 rows. Known limitation: the OSK overlays the bottom 3 terminal rows, so if the prompt has scrolled to the very bottom the current input line can be hidden. A follow-up can add a scroll region (terminal uses rows 0-14 while the OSK is up). Input over serial still works unchanged. --- src/syscall.asm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/syscall.asm') diff --git a/src/syscall.asm b/src/syscall.asm index 870a2ff..cb2c996 100644 --- a/src/syscall.asm +++ b/src/syscall.asm @@ -122,17 +122,21 @@ KGetc:: jp sys_getb ; B=fd -> A=byte, CF=EOF .console .poll + call pad_poll ; poll joypad; drive the on-screen keyboard + call osk_handle ; CF set + A = byte if a key was typed + jr c, .done ld a, $80 ld [rSC], a ld a, [rSC] bit 7, a - jr z, .got + jr nz, .yield + ld a, [rSB] ; A = serial byte +.done + and a ; CF = 0 (not EOF) + ret +.yield call SchedYield jr .poll -.got - ld a, [rSB] - and a ; CF = 0 - ret ; ----------------------------------------------------------------------------- ; KPutc(E = byte) - write to this process's stdout (console/file). -- cgit v1.3.1-sl0p