-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtitle_trans.asm
461 lines (372 loc) · 8.9 KB
/
title_trans.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
; asmsyntax=ca65
;;;;;;;;;;;;;;;;;;;
;; Transition stuff
;;;;;;;;;;;;;;;;;;;
; Start of the transition, ends in a frame handler.
Title_GameTrans:
lda #95
sta TitleScroll
lda #0
sta framesub_index
lda #$FF
sta framesub_next
lda #16
sta TmpX
sta meta_last_buffer
lda #15
sta meta_last_gen
jsr LoadFrameSubPointer
lda #PPU_CTRL_HORIZ
sta TitlePPUCtrl
jmp (DoFramePointer)
Title_Trans_NMI_End:
bit $2002
lda #0
sta $2005
lda TitleScroll
sta $2005
lda TitlePPUCtrl
sta $2000
jsr LoadFrameSubPointer
jmp NMI_Finished
; Frame 00
; Clear sprites and set scroll to the second
; nametable. Scrolling starts there and wraps
; around to the first nametable.
ttrans_frame_clear_00:
jsr ClearSprites
; Select the third nametable (02)
; This is written during NMI
lda TitlePPUCtrl
ora #$02
sta TitlePPUCtrl
dec framesub_next
jmp WaitFrame
; NMI 00
; Write sprites and palettes
ttrans_nmi_clear_00:
jsr WriteSprites
jsr WritePalettes
jmp Title_Trans_NMI_End
; Frame 01
; Load BG palette IDs 1 and 2
; Load sprite palette ID 0
; Load start address for first meta tile row
ttrans_frame_scrolling:
lda #<PalBG1
sta TmpAddr
lda #>PalBG1
sta TmpAddr+1
jsr LoadPaletteBG1
lda #<PalBG2
sta TmpAddr
lda #>PalBG2
sta TmpAddr+1
jsr LoadPaletteBG2
lda #<PalSP0
sta TmpAddr
lda #>PalSP0
sta TmpAddr+1
jsr LoadPaletteSP0
lda #<PalSP1
sta TmpAddr
lda #>PalSP1
sta TmpAddr+1
jsr LoadPaletteSP1
; Load start address for first meta tile row.
; Used in ttrans_write_meta_row
lda #$21
sta TmpAddr
lda #$80
sta TmpAddr+1
; Tile to write with ttrans_write_meta_row
lda #<Meta_Sky
sta meta_tile_addr
lda #>Meta_Sky
sta meta_tile_addr+1
dec framesub_next
jmp ttrans_frame_done
; NMI 01
; Draw two meta tile rows, as well as the attributes for
; the first nametable.
ttrans_nmi_meta_attr:
jsr ttrans_write_meta_row
; Get PPU address for second meta tile row
lda TmpAddr+1
clc
adc #$40 ; add 64 for next PPU address
sta TmpAddr+1
bcc :+ ; check for overflow
inc TmpAddr+0
:
jsr ttrans_write_meta_row
jsr WritePalettes
; Draw attribute data for the playfield
lda #$23
sta $2006
lda #$D8
sta $2006
; Above ground
lda Meta_Sky+4
.repeat 8
sta $2007
.endrepeat
; Ground
lda Meta_Ground+4
.repeat 8
sta $2007
.endrepeat
; Status bar
lda #$AA
.repeat 16
sta $2007
.endrepeat
jmp Title_Trans_NMI_End
; Frame 02
; Prepare the ground meta tile for drawing
ttrans_frame_00b:
; Third meta tile row
lda #$22
sta TmpAddr
lda #$00
sta TmpAddr+1
lda #<Meta_Ground
sta meta_tile_addr
lda #>Meta_Ground
sta meta_tile_addr+1
dec framesub_next
jmp ttrans_frame_done
; NMI 02
; Draw the ground meta row
ttrans_nmi_draw_meta_row_ground:
jsr ttrans_write_meta_row
; Get PPU address for fourth meta tile row
lda TmpAddr+1
clc
adc #$40
sta TmpAddr+1
bcc :+
inc TmpAddr+0
:
lda #<Meta_Ground2
sta meta_tile_addr
lda #>Meta_Ground2
sta meta_tile_addr+1
jsr ttrans_write_meta_row
jmp Title_Trans_NMI_End
; Frame 03
; Just wait. This frame is all drawing, no prep.
ttrans_frame_statusbar:
dec framesub_next
jmp ttrans_frame_done
; NMI 03
; Draw the status bar stuff
ttrans_nmi_draw_statusbar:
jsr game_ClearStatusBar
jmp Title_Trans_NMI_End
; Frame 04
; Start redrawing the skyline on the third nametable.
; The third nametable will become the second one when
; the mirroring mode is changed to vertical.
ttrans_frame_nt2:
lda #BackgroundThemes::City
sta BGTheme
; Draw to the third nametable ($2800), not the second.
lda #$28
sta BGNametable
lda #$00
sta BGYStart
; Setup some internal values for drawing two tile
; columns of the skyline
lda #0
sta bg_current_column
lda #16
sta TmpY
lda #2 ; tile column index to stop before
sta bg_drawcolumn_cmp
dec framesub_next
jmp ttrans_frame_done
; NMI 04, 05
; Draw a few columns, defined from the frame code earlier.
ttrans_nmi_draw_nt2:
jsr bg_drawOneScreen
jmp Title_Trans_NMI_End
; Frame 05
; Check if the skyline is finished drawing.
; Advance the animation step if so.
ttrans_frame_skylinecheck:
inc bg_drawcolumn_cmp
inc bg_drawcolumn_cmp
lda bg_drawcolumn_cmp
cmp #32
bne :+
dec framesub_next
: jmp ttrans_frame_done
; Frame 06 (uses same NMI as 05)
; Wait until the screen is scrolled far enough to
; start drawing the second (currently third) nametable's
; playfield meta columns.
ttrans_frame_waitforcolumndraw:
dec TmpX
bne :+
dec framesub_next
; Set number of columns to generate
lda #2
sta TmpZ
sta obs_countdown ; init the obstacle countdown
: jmp ttrans_frame_done
; Frame 07
; Generate and buffer a playfield meta column
ttrans_frame_columnbuffer:
jsr generate_column
jsr Buffer_Column
dec TmpZ ; number of columns to generate
bne :+
dec framesub_next
; Correct the address for the attribute write. The
; second nametable is on the bottom during the transition.
lda #$2B
sta attr_address+1
lda #$D8
sta attr_address
:
jmp ttrans_frame_done
; NMI 07
; Write the playfield meta column buffer to the PPU
ttrans_nmi_drawbuffer:
lda #$29 ; Correct the nametable address for the third nametable.
sta tile_column_addr_high
jsr Draw_Column
lda #$25 ; Set it back to not break things.
sta tile_column_addr_high
; Piggyback off of this variable to deterimne the
; second write. Draw the attributes after the second
; meta column is drawn.
bit framesub_next
bvc :+
lda #$AA
sta attr_buffer
; The lower byte isn't always correct. Make it correct.
lda #$55
sta attr_buffer+1
jsr Draw_Attribute
: jmp Title_Trans_NMI_End
; Frame 08 (plus all the others)
; Increment the scroll value, and check to see if we have
; finished scrollilng to the playfield yet. If so, trigger
; loading the game.
ttrans_frame_done:
inc TitleScroll
inc TitleScroll
lda TitleScroll
cmp #$EF
bcc :+
dec framesub_next
lda #0
sta TitleScroll
lda #PPU_CTRL_HORIZ
;ora #$02
sta TitlePPUCtrl
lda #$E0
sta SPZ_Y
: jmp WaitFrame
; Frame 09 (the last one)
; Initialize some variables and trigger a gamestate switch.
ttrans_frame_load:
; These two values cannot be the same
lda #18
sta meta_last_buffer
lda #17
sta meta_last_gen
lda #0
sta column_ready
inc gamestate_changed
jmp WaitFrame
; Write a row of meta tiles (64 tiles long, two tile rows)
; Start address is in TmpAddr
ttrans_write_meta_row:
; Write address for first tile row
bit $2002
lda TmpAddr
sta $2006
lda TmpAddr+1
sta $2006
; Write first tile row, alternating between tiles 00 and 01
; of the meta tile.
ldy #0
lda (meta_tile_addr), y
tax
iny
iny
lda (meta_tile_addr), y
ldy #8
@rowALoop:
stx $2007 ; tile 00
sta $2007 ; tile 01
stx $2007 ; and again
sta $2007
dey
bne @rowALoop
; Write second tile row, alternating between tiles 02 and 03
; of the meta tile.
ldy #1
lda (meta_tile_addr), y
tax
iny
iny
lda (meta_tile_addr), y
ldy #8
@rowBLoop:
stx $2007 ; tile 02
sta $2007 ; tile 03
stx $2007 ; and again
sta $2007
dey
bne @rowBLoop
rts
; Advance to the next frame and NMI handlers
; Called only from Title_Trans_NMI_End
LoadFrameSubPointer:
bit framesub_next
bvs :+
rts
: lda #0
sta framesub_next
lda framesub_index
asl a
tax
lda FrameSubHandlers, x
sta DoFramePointer
lda NMISubHandlers, x
sta DoNMIPointer
inx
lda FrameSubHandlers, x
sta DoFramePointer+1
lda NMISubHandlers, x
sta DoNMIPointer+1
inc framesub_index
rts
FrameSubHandlers:
.word ttrans_frame_clear_00
.word ttrans_frame_scrolling
.word ttrans_frame_00b
;.word ttrans_frame_00c
.word ttrans_frame_statusbar
.word ttrans_frame_nt2 ; setup skyline
.word ttrans_frame_skylinecheck ; check for complete skyline
.word ttrans_frame_waitforcolumndraw ; waiting
.word ttrans_frame_columnbuffer ; buffer
.word ttrans_frame_done
.word ttrans_frame_load
NMISubHandlers:
.word ttrans_nmi_clear_00
.word ttrans_nmi_meta_attr
.word ttrans_nmi_draw_meta_row_ground
;.word ttrans_nmi_draw_meta_row
.word ttrans_nmi_draw_statusbar
.word ttrans_nmi_draw_nt2 ; draw skyline
.word ttrans_nmi_draw_nt2 ; still drawing skyline
;.word ttrans_nmi_skylinedraw
.word Title_Trans_NMI_End ; waiting
.word ttrans_nmi_drawbuffer ; drawing
.word Title_Trans_NMI_End