-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_main.asm
315 lines (258 loc) · 7.35 KB
/
_main.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
ENABLE_SKIP = 0
DMASET = DMAF_SETCLR!DMAF_MASTER!DMAF_RASTER!DMAF_COPPER!DMAF_BLITTER
INTSET = INTF_SETCLR!INTF_INTEN!INTF_VERTB
MAX_VPOS_FOR_BG_TASK = 308
include "_main.i"
_start:
include "PhotonsMiniWrapper1.04.i"
include "sequence.i"
********************************************************************************
Demo:
********************************************************************************
; Blank screen while precalcing
jsr WaitEOF
clr.l color00(a6)
clr.l color02(a6)
move.l #BlankCop,cop1lc(a6)
move.w #DMASET,dmacon(a6)
move.l #MainInterrupt,$6c(a4)
; Precalc
jsr Tables_Precalc
; Init sequence pos:
lea Sequence,a0
ifne TEST_PART
; Jump to part in sequence
lea Part_SIZEOF*TEST_PART(a0),a0
; Adjust music start pos
move.w -2(a0),d0
move.w d0,P61_InitPos
move.w d0,P61_Pos
endc
; call first precalc before starting
move.l (a0)+,d0
ifne TEST_PART
beq .noPre
move.l d0,a1
movem.l a0/a6,-(sp)
jsr (a1)
movem.l (sp)+,a0/a6
.noPre:
endif
move.l a0,SequencePos
; Start music
lea Module,a0
sub.l a1,a1
move.l a1,a2
moveq #0,d0
bsr P61_Init
; Start interrupt
move.w #INTSET,intena(a6)
;-------------------------------------------------------------------------------
; Effects sequence
.effect:
lea custom,a6
; Reset between effects:
; Blank copper
jsr WaitEOF
move.l #BlankCop,cop1lc(a6)
; Restore standard DMA and interrupt
move.w #DMAF_SPRITE!DMAF_BLITHOG,dmacon(a6)
move.w #INTF_COPER!INTF_BLIT,intena(a6)
move.w #DMASET,dmacon(a6)
move.w #INTSET,intena(a6)
clr.w copcon(a6) ; Copper danger off
clr.l VBlankInterrupt
clr.l BlitterInterrupt
move.l SequencePos(pc),a1
; Next effect routine?
move.l (a1)+,d0
beq .endDemo
move.w (a1)+,EndPos ; Set end position for PartOver
clr.l LocalFrame ; Reset local frame counter
; Standard registers on entry
move.l (a1)+,a0 ; Precalc for next part
move.l a1,SequencePos ; update position
; Call effect routine
move.l d0,a1
jsr (a1)
bra .effect
.endDemo:
rts
SkipPressed: dc.w 0
********************************************************************************
; Check if current part is over according to sequence timings
;-------------------------------------------------------------------------------
PartOver:
ifne ENABLE_SKIP
; mouse pressed
btst #CIAB_GAMEPORT0,ciaa
bne .noPressed
; already detected?
tst.w SkipPressed
bne .checkFrame
; skip to next part
lea custom,a6
move.w EndPos,d0
bsr P61_SetPosition
move.w #1,SkipPressed
tst.w P61_Pos
rts
.noPressed:
clr.w SkipPressed
.checkFrame:
endc
move.w P61_Pos,d0
cmp.w EndPos(pc),d0
rts
********************************************************************************
MainInterrupt:
; VBI?
btst.b #INTB_VERTB,intreqr+custom+1
beq .notVbi
;-------------------------------------------------------------------------------
; Background task?
; Check if we're currently in executing a background task and switch back to main:
tst.l MainUSP
beq .notBgTask
; Store background task state
move.l a6,-(sp) ; save a6, we need a spare register
move.l usp,a6 ; get USP
move.l 4+2(sp),-(a6) ; store PC
move.w 4(sp),-(a6) ; store SR
move.l (sp)+,-(a6) ; store a6 in stack frame
movem.l d0-a5,-(a6) ; store the rest of the registers
move.l a6,BgTaskUSP ; Store bg USP
; Restore main task
move.l MainUSP(pc),a0 ; primary USP from before
move.l (a0)+,2(sp) ; store return PC to exception frame (keep SR unchanged)
move.l a0,usp ; restore primary USP (now at position before calling the vblank wait)
clr.l MainUSP ; make sure we will not reload it until has been set again
.notBgTask:
;-------------------------------------------------------------------------------
; Regular VBI stuff:
movem.l d0-a6,-(sp)
; Increment frame counters:
lea Vars(pc),a5
addq.l #1,GlobalFrame-Vars(a5)
addq.l #1,LocalFrame-Vars(a5)
move.w LocalFrame+2,d0
mulu #$100000*BPM/3000,d0
add.l d0,d0
swap d0
move.w d0,BpmFrame-Vars(a5)
; Process active lerps
jsr LerpWordsStep
jsr LerpPalStep
jsr Commander_Process
move.l VBlankInterrupt(pc),d0
beq .noCustom
move.l d0,a0
jsr (a0)
.noCustom:
movem.l (sp)+,d0-a6
move.w #INTF_VERTB,intreq+custom
move.w #INTF_VERTB,intreq+custom
rte
.notVbi:
;-------------------------------------------------------------------------------
; Blitter interrupt?
btst.b #INTB_BLIT,intreqr+custom+1
beq .notBlit
move.w #INTF_BLIT,intreq+custom
; Jump to blitter interrupt routine without using any registers
move.l #.notBlit,-(sp)
move.l BlitterInterrupt(pc),-(sp)
rts
.notBlit:
rte
********************************************************************************
; Switch to background task until vbi
;-------------------------------------------------------------------------------
; Big thanks to Platon42 for this writeup:
; https://dump.platon42.de/hameager/
;-------------------------------------------------------------------------------
VSyncWithBgTask:
; Is bg task set?
move.l BgTaskUSP(pc),d1
beq VSync
; Is there enough time left on frame to switch?
move.l #$1ff00,d0
and.l vposr(a6),d0
cmp.l #MAX_VPOS_FOR_BG_TASK<<8,d0
bgt VSync
movem.l a5-a6,-(sp)
bsr .switch
movem.l (sp)+,a5-a6
rts
.switch:
; Switch to bg task
move.l sp,MainUSP ; Back up main SP
move.l d1,sp ; Restore BG task SP
movem.l (sp)+,d0-a6 ; Restore BG registers
rtr
********************************************************************************
; Sync with vbi
;-------------------------------------------------------------------------------
VSync:
; Wait for global frame to update
move.w GlobalFrame+2(pc),d0
.loop: cmp.w GlobalFrame+2(pc),d0
beq.s .loop
rts
********************************************************************************
CmdSetBgTask:
move.l (a5)+,a0
; fall through...
********************************************************************************
; Set background task
;-------------------------------------------------------------------------------
; a0 - Task
;-------------------------------------------------------------------------------
SetBgTask:
lea BgStackE(pc),a1
exg a1,sp ; temporarily swap stack pointers
pea .taskDone(pc) ; routine to call after RTS from backgroundtask
move.l a0,-(sp) ; background task to jump to
clr.w -(sp) ; initial ccr
movem.l d0-a6,-(sp) ; initial register dump from caller
move.l sp,BgTaskUSP
exg a1,sp
rts
.taskDone:
clr.l BgTaskUSP
.l:
bra .l
********************************************************************************
Vars:
********************************************************************************
SequencePos: dc.l 0
GlobalFrame: dc.l 0
LocalFrame: dc.l 0
BpmFrame: dc.w 0
EndPos: dc.w 0
MainUSP: dc.l 0
BgTaskUSP: dc.l 0
BgStack: ds.b 128
BgStackE:
VBlankInterrupt: dc.l 0
BlitterInterrupt: dc.l 0
; Fill bytes e.g. white palette
FillData: dcb.w 16,$fff
include include/p61settings.i
include "include/P6112-Play.i"
*******************************************************************************
data_c
*******************************************************************************
; Zeroed data for use as black palette, null sprite etc.
BlankData: ds.w 32
Module:
incbin "data/P61.tune"
even
;-------------------------------------------------------------------------------
; Initial Copperlist for blank screen
BlankCop:
dc.w fmode,0
dc.w diwstrt,$2c81
dc.w diwstop,$2cc1
dc.w bplcon0,$200
dc.l -2