-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinterrupts.asm
176 lines (145 loc) · 2.68 KB
/
interrupts.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
164
165
166
167
168
169
170
171
172
173
174
175
176
.macro WaitForHblank
.a8
.local L0
L0: lda f:REG_HVBJOY
bit #$40
beq L0
.endmacro
.macro ForceHaltGSU
.a8
lda f:GSU_SFR
and #$DF
sta f:GSU_SFR
.endmacro
;: lda GSU_SFR ; wait for GSU operation to finnish
; bit #$20
; bne :-
.bss
irq_flag: .res 2
.code
.scope Interrupts
SetupIRQ:
.a8
.i16
ldx #$0002 ; bottom irq
stx irq_flag
lda #$E0
sta REG_HTIMEL
lda #$CE
sta REG_VTIMEL
lda #$31 ; HV-IRQ and autojoy enabled
sta REG_NMITIMEN
rts
irqRoutinesTable:
.addr ScreenTopIRQ
.addr ScreenEndIRQ
irqPositionTable:
.word $00E0, $00CE ; bottom irq timing
.word $00E0, $000E ; top irq timing
ScreenTopIRQ:
sep #$30
ldx inidisp_mirror ; #$0F
WaitForHblank
;.repeat 5
;nop
;nop
;nop
;.endrep ; About this many cycles left in hblank at this point, doubt waitforhblank is necessary
stx REG_INIDISP
phk
plb
rep #$30
ldx irq_flag
lda irqPositionTable,x
sta f:REG_HTIMEL
lda irqPositionTable+2,x
sta f:REG_VTIMEL
ldx #$0002
stx irq_flag
rts
ScreenEndIRQ:
sep #$30
ldx #$8F
WaitForHblank
stx REG_INIDISP
rep #$30
lda irq_flag
asl
tax
lda irqPositionTable,x
sta f:REG_HTIMEL
lda irqPositionTable+2,x
sta f:REG_VTIMEL
ldx #$0000
stx irq_flag
sep #$20
inc <frame_counter
lda #$00
pha
plb
jsr ChugFramebuffers
lda f:parity ; Test our parity bit
and #$CA
lsr
stz $2121
sta $2122
sta $2122
rep #$20
lda bg2_x
inc a
inc a
sta bg2_x
sep #$20
sta REG_BG2HOFS
xba
sta REG_BG2HOFS
rts
NMIHandler:
; Using IRQ as an earlier NMI
IRQHandler:
rep #$30
pha
lda f:REG_RDNMI ; read both nmi and irq flag
bmi :+ ; See if IRQ was triggered by console
lda f:GSU_SFR ; else clear gsu irq and do nothing in particular
pla
rtl
: sei
phb
phx
phy
sep #$20
lda #$00
pha
plb
ldx irq_flag
jsr (irqRoutinesTable,x)
; lda #$40
;: bit HVBJOY
; beq :-
rep #$30
ply
plx
plb
pla
rtl
.endscope
.segment "BANK2"
;Interrupt vectors to be executed during 65816 operation in WRAM
DummyVectors:
nop ;cop
nop
nop ;brk
nop
stp ;abort
nop
bra :+ ;NMI
;nop
nop ;unused
nop
;IRQ
jsl $7E0000|.loword(Interrupts::IRQHandler)
rti
: jsl $7E0000|.loword(Interrupts::NMIHandler) ;nmi goes here
rti
DummyVectorsSize = * - DummyVectors