Blob Blame History Raw
From 78d660da5571f29605dfdafe359527bf3c102823 Mon Sep 17 00:00:00 2001
From: Fabrizio Caruso <fabrizio_caruso@hotmail.com>
Date: Wed, 30 Oct 2019 09:14:17 +0100
Subject: [PATCH 084/170] kbhit checks KBEDG and getc resets KBEDG

---
 libsrc/lynx/cgetc.s | 16 ++++++++++------
 libsrc/lynx/kbhit.s |  4 +++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/libsrc/lynx/cgetc.s b/libsrc/lynx/cgetc.s
index 17943e2d..368a0e8d 100644
--- a/libsrc/lynx/cgetc.s
+++ b/libsrc/lynx/cgetc.s
@@ -20,6 +20,7 @@
 ; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
 
 _cgetc:
+        lda     KBEDG
         bne     _start     
         jsr     _kbhit          ; Check for char available
         beq     _cgetc
@@ -39,19 +40,19 @@ _start:
         bit     #$08
         beq     @L4                     ; Pause + Opt 2 = Flip
         lda     #'?'                    ; All buttons pressed
-        rts
+        bra     reset_and_exit
 @L2:
         lda     KBSTL           ; Pause alone was the last placed button
         and     #$0c
         bne     @L1
         lda     #'P'                    ; Pause pressed
-        rts
+        bra     reset_and_exit
 @L3:
         lda     #'R'                    ; Reset pressed
-        rts
+        bra     reset_and_exit
 @L4:
         lda     #'F'                    ; Flip pressed
-        rts
+        bra     reset_and_exit
 @L5:
         lda     KBEDG           ; No Pause pressed
         stz     KBEDG
@@ -61,10 +62,13 @@ _start:
         bit     #$04
         beq     @L6
         lda     #'3'                    ; opt 1 + opt 2 pressed
-        rts
+        bra     reset_and_exit
 @L6:
         lda     #'1'                    ; opt 1 pressed
-        rts
+        bra reset_and_exit
 @L7:
         lda     #'2'                    ; opt 2 pressed
+
+reset_and_exit:
+        stz     KBEDG
         rts
diff --git a/libsrc/lynx/kbhit.s b/libsrc/lynx/kbhit.s
index a5126a7d..a846c43e 100644
--- a/libsrc/lynx/kbhit.s
+++ b/libsrc/lynx/kbhit.s
@@ -29,6 +29,8 @@ KBNPR:          .byte   0
 
         .code
 _kbhit:
+        lda     KBEDG
+        bne     L1 
         lda     $FCB0           ; Read the Opt buttons
         and     #$0c
         sta     KBTMP
@@ -49,6 +51,6 @@ _kbhit:
         sta     KBNPR           ; inverted previous ones pressed
         stx     KBPRV
         lda     KBEDG
-@L1:    tax                     ; No new keys hit
+L1:     ldx     #$00                     
         rts
 
-- 
2.26.0