From 207170d0df87088e2bd2b08a543b77222b53eae0 Mon Sep 17 00:00:00 2001 From: Stefan Wessels Date: Fri, 7 Aug 2026 20:37:12 -0700 Subject: [PATCH] Fix plus4 cgetc() returning a phantom key in bitmap mode The bitmap-mode test added with the Plus/4 TGI driver (3bd4d05) branches past the wait loop as well as the cursor drawing, so in bitmap mode cgetc() never blocks: it calls KBDREAD with an empty buffer, and KBDREAD decrements KEY_COUNT past zero. Every later kbhit() then reports keys that were never typed. --- libsrc/plus4/cgetc.s | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libsrc/plus4/cgetc.s b/libsrc/plus4/cgetc.s index 8c8bb0082..2b286e5fd 100644 --- a/libsrc/plus4/cgetc.s +++ b/libsrc/plus4/cgetc.s @@ -18,16 +18,20 @@ _cgetc: lda KEY_COUNT ; Get number of characters ora FKEY_COUNT ; Or with number of function key chars bne L2 ; Jump if there are already chars waiting - lda #%00100000 - bit $FF06 - bne L2 ; always disable cursor if in bitmap mode - -; Switch on the cursor if needed +; Save the character under the cursor, wait for a key, then put it back. In +; bitmap mode there is no cursor to show, so the save and restore are +; effectively a no-op. ldy CURS_X lda (CRAM_PTR),y ; Get current char pha ; And save it + lda #%00100000 + bit $FF06 + bne L1 ; No cursor in bitmap mode + +; Switch on the cursor if needed + lda CHARCOLOR sta (CRAM_PTR),y