# HG changeset patch # User William Astle # Date 1676931749 25200 # Node ID 1190f66329ab7dcc1b39e87f387ea5d138237481 # Parent 9bed204d99b94cdd29f7d8c2bb6aed5fbd564e98 Change BREAK check to probe keyboard directly It turns out relying on BREAK in the buffer isn't reliable. Since BREAK MUST work even if the buffer is full, actually probe the keyboard matrix for the BREAK key. Then wait for a an interrupt so the keyboard gets scanned and then empty the buffer. Waiting for the interrupt ensures the make for the BREAK key is noticed and suppresses a spurious BREAK when returning to immediate mode. diff -r 9bed204d99b9 -r 1190f66329ab src/lwbasic.s --- a/src/lwbasic.s Sun Feb 19 22:06:19 2023 -0700 +++ b/src/lwbasic.s Mon Feb 20 15:22:29 2023 -0700 @@ -1236,21 +1236,21 @@ clr contstmt+1 jmp ,x ; return to caller ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Check for BREAK; this needs to check the keyboard buffer directly instead of just using the usual key fetching -; routine so we don't interfere with keyboard buffering if BREAK isn't pressed. However, if BREAK is pressed, we -; need to react immediately in which case we clear everything up to and including the BREAK from the buffer. -breakcheck ldx keyb_buffr ; get keyboard ring buffer pointer -breakcheck0 cmpx keyb_buffw ; is the buffer empty? - beq breakcheck2 ; brif so (C clear here) - lda ,x+ ; is there a BREAK in the buffer? - cmpx #keyb_buff+keyb_bufflen ; do we need to wrap to start of buffer? - bne breakcheck1 ; brif not - ldx #keyb_buff ; reset to start of buffer -breakcheck1 cmpa #3 - bne breakcheck0 ; brif not BREAK - stx keyb_buffr ; clear buffer up to and including the BREAK - coma ; set C for BREAK pressed -breakcheck2 rts +; Check for BREAK; this needs to check the keyboard directly instead of just using the usual key fetching routine so +; we don't interfere with keyboard buffering if BREAK isn't pressed. We also need to scan the keyboard directly for this +; so we react even if the keyboard buffer is full. If BREAK is pressed, the keyboard buffer is emptied. +breakcheck lda #0xfb ; strobe column for BREAK + sta PIA0.DB + clra ; clear carry for no BREAK + lda PIA0 ; read rows + bita #0x40 ; is BREAK down? + bne breakcheck0 ; brif not - just return + sync ; wait for interrupt to scan keyboard + ldx #keyb_buff ; reset keyboard buffer + stx keyb_buffr + stx keyb_buffw + coma ; flag BREAK +breakcheck0 rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Main interpretation loop ;