-
Notifications
You must be signed in to change notification settings - Fork 1
/
interrupt_handler.asm
163 lines (135 loc) · 4.94 KB
/
interrupt_handler.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
; Interrupt Handler
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
check_irq_bit .macro
LDA \1
AND #\2
CMP #\2
BNE END_CHECK
STA \1
JSR \3
END_CHECK
.endm
IRQ_HANDLER
; First Block of 8 Interrupts
.as
setdp 0
.as
LDA #0 ; set the data bank register to 0
PHA
PLB
LDA INT_PENDING_REG0
BEQ CHECK_PENDING_REG1
; Start of Frame
check_irq_bit INT_PENDING_REG0, FNX0_INT00_SOF, SOF_INTERRUPT
; Timer 0
check_irq_bit INT_PENDING_REG0, FNX0_INT02_TMR0, TIMER0_INTERRUPT
; FDC Interrupt
;check_irq_bit INT_PENDING_REG0, FNX0_INT06_FDC, FDC_INTERRUPT
; Mouse IRQ
;check_irq_bit INT_PENDING_REG0, FNX0_INT07_MOUSE, MOUSE_INTERRUPT
; Second Block of 8 Interrupts
CHECK_PENDING_REG1
setas
LDA INT_PENDING_REG1
BEQ CHECK_PENDING_REG2 ; BEQ EXIT_IRQ_HANDLE
; Keyboard Interrupt
check_irq_bit INT_PENDING_REG1, FNX1_INT00_KBD, KEYBOARD_INTERRUPT
; COM2 Interrupt
;check_irq_bit INT_PENDING_REG1, FNX1_INT03_COM2, COM2_INTERRUPT
; COM1 Interrupt
;check_irq_bit INT_PENDING_REG1, FNX1_INT04_COM1, COM1_INTERRUPT
; MPU401 - MIDI Interrupt
;check_irq_bit INT_PENDING_REG1, FNX1_INT05_MPU401, MPU401_INTERRUPT
; LPT Interrupt
;check_irq_bit INT_PENDING_REG1, FNX1_INT06_LPT, LPT1_INTERRUPT
; Third Block of 8 Interrupts
CHECK_PENDING_REG2
setas
LDA INT_PENDING_REG2
BEQ EXIT_IRQ_HANDLE
; OPL2 Right Interrupt
;check_irq_bit INT_PENDING_REG2, FNX2_INT00_OPL2R, OPL2R_INTERRUPT
; OPL2 Left Interrupt
;check_irq_bit INT_PENDING_REG2, FNX2_INT01_OPL2L, OPL2L_INTERRUPT
EXIT_IRQ_HANDLE
; Exit Interrupt Handler
RTL
; ****************************************************************
; ****************************************************************
;
; KEYBOARD_INTERRUPT
;
; ****************************************************************
; ****************************************************************
; * Todo: rewrite this to use indirect or indexed jumps
KEYBOARD_INTERRUPT
.as
LDA KBD_INPT_BUF ; Get Scan Code from KeyBoard
EOR KEYBOARD_SC_TMP ; if the scan code hasn't changed, skip
BEQ KBD_SKIP
LDA KBD_INPT_BUF
STA KEYBOARD_SC_TMP
CMP #$11 ; W key
BNE CHECK_A
LDA #$9E
BRA KBD_DONE
CHECK_A CMP #$1E
BNE CHECK_S
LDA #$9B
BRA KBD_DONE
CHECK_S CMP #$1F
BNE CHECK_D
LDA #$9D
BRA KBD_DONE
CHECK_D CMP #$20
BNE CHECK_SPACE
LDA #$97
BRA KBD_DONE
CHECK_SPACE
CMP #$39
BNE SKIP_KEY
LDA #$8F
BRA KBD_DONE
SKIP_KEY
LDA #$9F
JMP KBD_SKIP
KBD_DONE
JSR UPDATE_DISPLAY
KBD_SKIP
RTS
; ///////////////////////////////////////////////////////////////////
; ///
; /// Start of Frame Interrupt
; /// 60Hz, 16ms Cyclical Interrupt
; ///
; ///////////////////////////////////////////////////////////////////
SOF_INTERRUPT
.as
LDA JOYSTICK0
AND #$DF
EOR JOYSTICK_SC_TMP
BEQ SOF_CONTINUE
LDA JOYSTICK0
STA JOYSTICK_SC_TMP
BRA SOF_DISPLAY
SOF_CONTINUE
LDA #$DF
SOF_DISPLAY
JSR UPDATE_DISPLAY
RTS
; ///////////////////////////////////////////////////////////////////
; ///
; /// Timer0 interrupt
; /// Desc: Interrupt for playing VGM data
; ///
; ///////////////////////////////////////////////////////////////////
TIMER0_INTERRUPT .as
JSL VGM_WRITE_REGISTER
RTS
NMI_HANDLER
RTL