-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirq.s
198 lines (147 loc) · 2.53 KB
/
irq.s
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "params.h"
.zero
_IrqCounter .dsb 1
_VblCounter .dsb 1
.text
_IrqSpeedMask .byt 1
_Sei
sei
rts
_Cli
cli
rts
; 1 second = 1000 ms
; 1 frame @50hz = 20ms
; 1 frame @100hz = 10ms
; 19966 = 50hz = 1 irq per frame
; 10000 = 100hz = 2 irq per frame (0x2710 is the original ROM value)
; 5000 = 200hz = 4 irq per frame
; 2500 = 400hz = 8 irq per frame
_System_InstallIRQ_SimpleVbl
//jmp _System_InstallIRQ_SimpleVbl
.(
sei
lda $306
sta VIA_Restore_Low+1
lda $307
sta VIA_Restore_High+1
lda $FFFE
sta IRQ_Restore_Low+1
lda $FFFF
sta IRQ_Restore_High+1
; Set the VIA parameters to get a 200hz IRQ
lda #<19966/4 ; 20000
sta $306
lda #>19966/4 ; 20000
sta $307
; Install interrupt (this works only if overlay ram is accessible)
lda #<InterruptHandler
sta $FFFE
lda #>InterruptHandler
sta $FFFF
lda #4
sta _IrqSpeedMask
sta _IrqCounter
lda #0
sta _VblCounter
cli
rts
.)
_System_RestoreIRQ_SimpleVbl
//jmp _System_RestoreIRQ_SimpleVbl
.(
sei
; Restore the VIA
+VIA_Restore_Low
lda #$12
sta $306
+VIA_Restore_High
lda #$12
sta $307
; Restore the IRQ handler
+IRQ_Restore_Low
lda #$12
sta $FFFE
+IRQ_Restore_High
lda #$23
sta $FFFF
cli
rts
.)
InterruptHandler
.(
bit $304
pha
txa
pha
tya
pha
; Call the Frequent IRQ handler
jsr IrqTasksHighSpeed
dec _IrqCounter
bne skip_50hz_task
lda _IrqSpeedMask
sta _IrqCounter
; Call the 50hz IRQ handler
inc _VblCounter
jsr IrqTasks50hz
; Call the loader "RGB flash" disk access indicator
jsr _LoaderApiLoadingAnimation
skip_50hz_task
; Restore regs and return
pla
tay
pla
tax
pla
rti
.)
; param0+0/param0+1=number of frames to wait
_WaitFramesAsm
.(
; Do we have a zero number of frames???
lda _param0+0
bne loop
lda _param0+1
bne loop
rts
loop
jsr _WaitIRQ ; Uses A register
dec _param0+0
bne loop
dec _param0+1
bpl loop
rts
.)
; Waits for the next IRQ
_VSync
_WaitIRQ
.(
lda _VblCounter
loop
cmp _VblCounter
beq loop
rts
.)
_Breakpoint
jmp _Breakpoint
_DoNothing
rts
; Stop the program while blinking the bottom right corner with psychedelic colors
_Panic
lda #16+1
sta $BFDF
lda #16+2
sta $BFDF
jmp _Panic
rts
_Temporize
ldy #1
temporize_outer
ldx #0
temporize_inner
dex
bne temporize_inner
dey
bne temporize_outer
rts