-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinterrupt_handler.asm
153 lines (129 loc) · 4.98 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
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////////
; 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
setas
LDA INT_PENDING_REG0
BEQ CHECK_PENDING_REG1
; Start of Frame (display), timer 0 (music), mouse (ignored)
;check_irq_bit INT_PENDING_REG0, FNX0_INT00_SOF, SOF_INTERRUPT
check_irq_bit INT_PENDING_REG0, FNX0_INT02_TMR0, TIMER0_INTERRUPT
;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
; Keyboard Interrupt
;check_irq_bit INT_PENDING_REG1, FNX1_INT00_KBD, KEYBOARD_INTERRUPT
; Third Block of 8 Interrupts
CHECK_PENDING_REG2
setas
LDA INT_PENDING_REG2
BEQ CHECK_PENDING_REG3
; Fourth Block of 8 Interrupts
CHECK_PENDING_REG3
setas
LDA INT_PENDING_REG3
BEQ EXIT_IRQ_HANDLE
;check_irq_bit INT_PENDING_REG3, FNX3_INT01_OPM, OPM_INTERRUPT
EXIT_IRQ_HANDLE
; Exit Interrupt Handler
RTL
; ****************************************************************
; ****************************************************************
;
; KEYBOARD_INTERRUPT
;
; ****************************************************************
; ****************************************************************
; * The only keys accepted are Left Arrow, Right Arrow, Down Arrow and Space (to rotate)
; * Alias ASD keys to arrows?
KEYBOARD_INTERRUPT
.as
LDA #0 ; clear B
XBA
LDA KBD_INPT_BUF ; Get Scan Code from KeyBoard
STA KEYBOARD_SC_TMP ; Save Code Immediately
;TAX
;LDA ScanCode_Press_Set1,X
DONT_REACT
RTS
OPM_INTERRUPT
.as
RTS
; ****************************************************************
; ****************************************************************
; * Start of Frame Interrupt
; * 60Hz, 16ms Cyclical Interrupt
; ****************************************************************
; ****************************************************************
SOF_INTERRUPT
.as
; uncomment this to debug in the IDE
; JSR VGM_WRITE_REGISTER
RTS
; ****************************************************************
; ****************************************************************
; * Play VGM files
; ****************************************************************
; ****************************************************************
TIMER0_INTERRUPT
.as
JSR VGM_WRITE_REGISTER
RTS
; ****************************************************************
; ****************************************************************
; * Mouse Interrupt
; * We still need to service the mouse interrupts, even
; * though we don't use it.
; ****************************************************************
; ****************************************************************
MOUSE_INTERRUPT .as
setas
LDA @lINT_PENDING_REG0
AND #FNX0_INT07_MOUSE
STA @lINT_PENDING_REG0
LDA KBD_INPT_BUF
LDX #$0000
setxs
LDX MOUSE_PTR
STA @lMOUSE_PTR_BYTE0, X
INX
CPX #$03
BNE EXIT_FOR_NEXT_VALUE
; Create Absolute Count from Relative Input
LDA @lMOUSE_PTR_X_POS_L
STA MOUSE_POS_X_LO
LDA @lMOUSE_PTR_X_POS_H
STA MOUSE_POS_X_HI
LDA @lMOUSE_PTR_Y_POS_L
STA MOUSE_POS_Y_LO
LDA @lMOUSE_PTR_Y_POS_H
STA MOUSE_POS_Y_HI
setas
LDX #$00
EXIT_FOR_NEXT_VALUE
STX MOUSE_PTR
setxl
RTS