Skip to content

Commit 7cdd375

Browse files
Tweaked DO_KEYBOARD
1 parent 70d111e commit 7cdd375

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

interrupts.asm

+20-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
; Title: BBC Basic for AGON - Interrupts
33
; Author: Dean Belfield
44
; Created: 06/05/2022
5-
; Last Updated: 28/03/2023
5+
; Last Updated: 30/03/2023
66
;
77
; Modinfo:
88
; 23/03/2023: Added VBLANK_INIT and VBLANK_HANDLER
99
; 26/03/2023: Fixed bug - MB changing in interrupt
1010
; 28/03/2023: Added VBLANK_STOP, removed MB bodge introduced in previous change
11+
; 30/03/2023: Tweaked DO_KEYBOARD
1112

1213
.ASSUME ADL = 0
1314
@@ -24,6 +25,7 @@
2425
XREF ESCSET
2526
XREF KEYDOWN ; In ram.asm
2627
XREF KEYASCII ; In ram.asm
28+
XREF KEYCOUNT ; In ram.asm
2729

2830
; Hook into the MOS VBLANK interrupt
2931
;
@@ -76,12 +78,24 @@ SET_AHL16: PUSH.LIL HL
7678
; A safe LIS call to ESCSET
7779
;
7880
DO_KEYBOARD: MOSCALL mos_sysvars ; Get the system variables
81+
LD HL, KEYCOUNT ; Check whether the keycount has changed
82+
LD.LIL A, (IX + sysvar_vkeycount) ; by comparing the MOS copy
83+
CP (HL) ; with our local copy
84+
JR NZ, DO_KEYBOARD_1 ; Yes it has, so jump to the next bit
85+
;
86+
DO_KEYBOARD_0: XOR A ; Clear the keyboard values
87+
LD (KEYASCII), A
88+
LD (KEYDOWN), A
89+
RET.LIL ; And return
90+
;
91+
DO_KEYBOARD_1: LD (HL), A ; Store the updated local copy of keycount
7992
LD.LIL A, (IX + sysvar_vkeydown) ; Fetch key down value (1 = key down, 0 = key up)
80-
LD (KEYDOWN), A ; Store locally
8193
OR A
82-
JR Z, $F ; If it is key up, then skip to next bit
94+
JR Z, DO_KEYBOARD_0 ; If it is key up, then clear the keyboard values
95+
;
96+
LD (KEYDOWN), A ; Store the keydown value
8397
LD.LIL A, (IX + sysvar_keyascii) ; Fetch key ASCII value
84-
$$: LD (KEYASCII), A ; Store locally
98+
LD (KEYASCII), A ; Store locally
8599
CP 1Bh ; Is it escape?
86100
CALL Z, ESCSET ; Yes, so set the escape flags
87101
RET.LIS ; Return to the interrupt handler
@@ -93,6 +107,7 @@ $$: LD (KEYASCII), A ; Store locally
93107

94108
VBLANK_HANDLER: DI
95109
PUSH AF
110+
PUSH HL
96111
PUSH IX
97112
LD A, MB
98113
PUSH AF
@@ -102,6 +117,7 @@ VBLANK_HANDLER_MB: LD A, 0 ; This is self-modified by VBLANK_INIT
102117
POP AF
103118
LD MB, A
104119
POP IX
120+
POP HL
105121
POP AF
106122
;
107123
; Finally jump to the MOS interrupt

0 commit comments

Comments
 (0)