2
2
; Title: BBC Basic for AGON - Interrupts
3
3
; Author: Dean Belfield
4
4
; Created: 06/05/2022
5
- ; Last Updated: 28 /03/2023
5
+ ; Last Updated: 30 /03/2023
6
6
;
7
7
; Modinfo:
8
8
; 23/03/2023: Added VBLANK_INIT and VBLANK_HANDLER
9
9
; 26/03/2023: Fixed bug - MB changing in interrupt
10
10
; 28/03/2023: Added VBLANK_STOP, removed MB bodge introduced in previous change
11
+ ; 30/03/2023: Tweaked DO_KEYBOARD
11
12
12
13
.ASSUME ADL = 0
13
14
24
25
XREF ESCSET
25
26
XREF KEYDOWN ; In ram.asm
26
27
XREF KEYASCII ; In ram.asm
28
+ XREF KEYCOUNT ; In ram.asm
27
29
28
30
; Hook into the MOS VBLANK interrupt
29
31
;
@@ -76,12 +78,24 @@ SET_AHL16: PUSH.LIL HL
76
78
; A safe LIS call to ESCSET
77
79
;
78
80
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
79
92
LD.LIL A , (IX + sysvar_vkeydown) ; Fetch key down value (1 = key down, 0 = key up)
80
- LD (KEYDOWN) , A ; Store locally
81
93
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
83
97
LD.LIL A , (IX + sysvar_keyascii) ; Fetch key ASCII value
84
- $$: LD (KEYASCII), A ; Store locally
98
+ LD (KEYASCII) , A ; Store locally
85
99
CP 1Bh ; Is it escape?
86
100
CALL Z , ESCSET ; Yes, so set the escape flags
87
101
RET .LIS ; Return to the interrupt handler
@@ -93,6 +107,7 @@ $$: LD (KEYASCII), A ; Store locally
93
107
94
108
VBLANK_HANDLER: DI
95
109
PUSH AF
110
+ PUSH HL
96
111
PUSH IX
97
112
LD A , MB
98
113
PUSH AF
@@ -102,6 +117,7 @@ VBLANK_HANDLER_MB: LD A, 0 ; This is self-modified by VBLANK_INIT
102
117
POP AF
103
118
LD MB , A
104
119
POP IX
120
+ POP HL
105
121
POP AF
106
122
;
107
123
; Finally jump to the MOS interrupt
0 commit comments