changeset 60:1190f66329ab

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.
author William Astle <lost@l-w.ca>
date Mon, 20 Feb 2023 15:22:29 -0700
parents 9bed204d99b9
children a0f7c8768867
files src/lwbasic.s
diffstat 1 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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
 ;