-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
credits.asm
712 lines (567 loc) · 11.6 KB
/
credits.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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
; asmsyntax=ca65
CLEAR_TILE_ID = 0
CR_T2_SPEED = 8 ; color cycle speed (in frames) for the tier two names
Credits_Init:
; - Clear backgound for both nametables
; - Update palettes
inc SkipNMI
jsr MMC1_Setup_Horiz
jsr MMC1_Page1
jsr MMC1_Pattern1
lda #$00
sta $2001
lda #<Credits_Palette
sta PaletteAddr
lda #>Credits_Palette
sta PaletteAddr+1
; Set frame and NMI pointers
lda #<Credits_Frame
sta DoFramePointer
lda #>Credits_Frame
sta DoFramePointer+1
lda #<Credits_NMI
sta DoNMIPointer
lda #>Credits_NMI
sta DoNMIPointer+1
jsr LoadPalettes
jsr WritePalettes
lda #$00
jsr FillNametable0
lda #$00
jsr FillNametable2
jsr ClearAttrTable0
jsr ClearAttrTable2
jsr ClearSprites
lda #0
sta cr_currentAttrOffset
sta cr_AttrSecondWrite
sta cr_AttrTmp
sta cr_AttributeReady
sta cr_UpdateReady
;sta cr_chunkCurrent
sta cr_currentPPULine
sta cr_scroll
sta cr_tileBufferOffset
sta cr_AttributeAddress+1
lda #<credits_data_chunks
sta cr_chunkAddress
lda #>credits_data_chunks
sta cr_chunkAddress+1
lda #$23
sta cr_AttributeAddress
; Fill the screen with names
lda #30
sta TmpX
@loop:
jsr Credits_LoadChunk
jsr Credits_WriteBuffer
dec TmpX
bne @loop
lda #CR_SCROLL_WAIT
sta cr_scrollWait
lda #32
sta cr_nextChunkWait
lda #$21
sta TitleColor
lda #0
sta TitleColor2
lda #CR_T2_SPEED
sta cr_t2Count
; reset scroll
bit $2001
lda #$00
sta $2005
sta $2005
lda #CR_TOP
sta cr_scroll_table
rts
Credits_WriteAttr:
lda #0
sta cr_AttributeReady
lda cr_AttributeAddress
sta $2006
lda cr_AttributeAddress+1
sta $2006
ldx #8
lda cr_AttributeByte
@loop:
sta $2007
dex
bne @loop
lda #0
sta cr_AttributeByte
lda cr_AttributeAddress+1
cmp #$F8
beq :+
rts
: lda cr_AttributeAddress
cmp #$23
bne @firstNT
jmp @secondNT
@firstNT:
lda #$23
sta cr_AttributeAddress
jmp @done
@secondNT:
lda #$2B
sta cr_AttributeAddress
@done:
rts
; Write the TileBuffer to the PPU
Credits_WriteBuffer:
lda #0
sta cr_UpdateReady
lda cr_currentPPULine
cmp #30
bcc @noWrap
lda #0
sta cr_currentPPULine
@noWrap:
tax
inc cr_currentPPULine
lda PPU_RowStartLookup_High, x
sta $2006
lda PPU_RowStartLookup_Low, x
sta $2006
ldx #0
ldy #64
@loop:
lda TileBuffer, x
sta $2007
inx
dey
bne @loop
; increment and rollover the count
;inc cr_chunkCurrent
;lda cr_chunkCurrent
;cmp #Credits_NameCount
;bcc @noRollover
;lda #0
;sta cr_chunkCurrent
;@noRollover:
;dec cr_nextAttrWait
;bne @noAttr
;lda #3
;sta cr_nextAttrWait
bit cr_AttributeReady
bvc @noAttr
jmp Credits_WriteAttr
@noAttr:
rts
; Two byte increment
cr_Decode_Opcode_IncAddr:
;lda cr_chunkAddress
clc
adc cr_chunkAddress
sta cr_chunkAddress
lda cr_chunkAddress+1
adc #0
sta cr_chunkAddress+1
rts
cr_OPCodes:
.word cr_op_EndOfChunk
.word cr_op_ClearRow
.word cr_op_IncrementByte
.word cr_op_RunLength
.word cr_op_ByteList
.word cr_op_Attr
.word cr_op_Name
.word cr_op_EndOfData
; Call this with a JSR
Credits_LoadChunk:
lda #CR_UPDATE_TILE
sta cr_UpdateReady
lda #0
sta cr_tileBufferOffset
;lda cr_chunkCurrent
asl a
tax
;lda credits_data_chunks, x
;sta cr_chunkAddress
;lda credits_data_chunks+1, x
;sta cr_chunkAddress+1
;jmp cr_Decode_Opcode
; Before this is called, figure out the credits_data_chunk_## address
cr_Decode_Opcode:
ldy #0
lda (cr_chunkAddress), y
asl a
tax
; load address of op code subroutine
lda cr_OPCodes, x
sta TmpAddr
lda cr_OPCodes+1, x
sta TmpAddr+1
; jump to it
jmp (TmpAddr)
cr_ClearRow:
ldx cr_tileBufferOffset
ldy #32
lda #CLEAR_TILE_ID
@loop:
sta TileBuffer, x
inx
dey
bne @loop
lda cr_tileBufferOffset
clc
adc #32
sta cr_tileBufferOffset
lda #1
jmp cr_Decode_Opcode_IncAddr
; Add 32 bytes of Spaces to the tile buffer
cr_op_ClearRow:
jsr cr_ClearRow
jmp cr_Decode_Opcode
; Start at the given byte and increment N times
cr_op_IncrementByte:
; increment past OP code
lda #1
jsr cr_Decode_Opcode_IncAddr
ldy #0
; number of bytes to write
lda (cr_chunkAddress), y
tax
lda #1
jsr cr_Decode_Opcode_IncAddr
; Data to start at
lda (cr_chunkAddress), y
sta cr_tmpByte
; move length from X to Y
txa
tay
ldx cr_tileBufferOffset
@loop:
lda cr_tmpByte
sta TileBuffer, x
inc cr_tmpByte
inx
dey
bne @loop
; store the buffer offset
stx cr_tileBufferOffset
lda #1
jsr cr_Decode_Opcode_IncAddr
jmp cr_Decode_Opcode
; Repeat a byte N times
cr_op_RunLength:
; increment past OP code
lda #1
jsr cr_Decode_Opcode_IncAddr
ldy #0
; number of bytes to write
lda (cr_chunkAddress), y
sta cr_chunkLength
;inc cr_chunkLength
lda #1
jsr cr_Decode_Opcode_IncAddr
; data byte
lda (cr_chunkAddress), y
ldy cr_chunkLength
ldx cr_tileBufferOffset
@loop:
sta TileBuffer, x
inx
dey
bne @loop
; Update buffer offset
lda cr_tileBufferOffset
clc
adc cr_chunkLength
sta cr_tileBufferOffset
lda #1
jsr cr_Decode_Opcode_IncAddr
jmp cr_Decode_Opcode
; Dump a list of bytes to the buffer
cr_op_ByteList:
jsr cr_ByteList
jmp cr_Decode_Opcode
cr_ByteList:
lda #1
jsr cr_Decode_Opcode_IncAddr
ldx cr_tileBufferOffset
ldy #0
sty cr_tmpByte
@loop:
lda (cr_chunkAddress), y
beq @done
sta TileBuffer, x
inx
inc cr_tmpByte
iny
jmp @loop
@done:
lda cr_tmpByte
clc
adc cr_tileBufferOffset
sta cr_tileBufferOffset
inc cr_tmpByte
lda cr_tmpByte
jsr cr_Decode_Opcode_IncAddr
rts
cr_op_Attr:
; don't increment if coming from cr_op_Name
bit cr_AttrTmp
bmi :+
lda #1
jsr cr_Decode_Opcode_IncAddr
: lda cr_AttrSecondWrite
bne @secondWrite
lda cr_currentAttrOffset
cmp #7
beq @lastRow
lda cr_AttrTmp
bmi @notChunkA
ldy #0
lda (cr_chunkAddress), y
jmp @notChunkADone
@notChunkA:
and #$0F
@notChunkADone:
sta cr_AttributeByte
lda #0
sta cr_AttrTmp
inc cr_AttrSecondWrite
jmp cr_op_EndOfChunk
@secondWrite:
lda cr_AttrTmp
bmi @notChunkB
lda (cr_chunkAddress), y
jmp @notChunkBDone
@notChunkB:
and #$0F
@notChunkBDone:
asl A
asl A
asl A
asl A
ora cr_AttributeByte
sta cr_AttributeByte
ldx cr_currentAttrOffset
inc cr_currentAttrOffset
lda PPU_AttrLookup_Low, x
sta cr_AttributeAddress+1
lda #$FF
sta cr_AttributeReady
lda #0
sta cr_AttrSecondWrite
sta cr_AttrTmp
jmp cr_op_EndOfChunk
@lastRow:
lda cr_AttrTmp
bmi @notChunkC
ldy #0
lda (cr_chunkAddress), y
jmp @notChunkCDone
@notChunkC:
and #$0F
; Last row stuff
@notChunkCDone:
sta cr_AttributeByte
asl A
asl A
asl A
asl A
ora cr_AttributeByte
sta cr_AttributeByte
ldx cr_currentAttrOffset
lda PPU_AttrLookup_Low, x
sta cr_AttributeAddress+1
; wrap to the next nametable
lda #0
sta cr_currentAttrOffset
sta cr_AttrTmp
lda #$FF
sta cr_AttributeReady
cr_op_EndOfChunk:
lda #1
jmp cr_Decode_Opcode_IncAddr
cr_op_EndOfData:
lda #<credits_data_chunks
sta cr_chunkAddress
lda #>credits_data_chunks
sta cr_chunkAddress+1
jmp Credits_LoadChunk
cr_op_Name:
; Clear the row, prefix spaces, suffix spaces, attribute, name data
jsr cr_ClearRow
; Metadata byte. bits 7-6 are attribute, rest are length.
ldy #0
lda (cr_chunkAddress), y
and #$3F
sta cr_nameLength
lda (cr_chunkAddress), y
and #$C0 ; get Attribute bits
; Rotate bits 7-6 to bits 1-0
clc
rol a
rol a
rol a
sta cr_AttrTmp
; fill the nibble
asl a
asl a
ora cr_AttrTmp
ora #$80
sta cr_AttrTmp
; write attribute stuff
jsr cr_op_Attr
; Length
lda cr_nameLength
lsr a ; divide by two
sta TmpY
lda #16
sec
sbc TmpY ; the amount of padding
sta cr_loopCounter
ldy #0
lda #CR_PADDING
ldx cr_tileBufferOffset
: sta TileBuffer, x
inx
iny
cpy cr_loopCounter
bne :-
ldy #0
lda cr_nameLength
sta cr_loopCounter
sta TmpY
; Loop through data for the given length
: lda (cr_chunkAddress), y
sta TileBuffer, x
iny
inx
dec TmpY
bne :-
; suffix padding
lda #CR_PADDING
: sta TileBuffer, x
inx
cpx #64 ; 32 is end of row, 64 is end of second row.
bne :-
lda cr_nameLength
jmp cr_Decode_Opcode_IncAddr
; padding to fix the dissassembly in the debugger
.byte $EA, $EA
cr_colors_T2:
.byte $00
cr_colors_T3:
.byte $00
cr_TierColors:
lda cr_t2Count
bne @t3check
lda #CR_T2_SPEED
sta cr_t2Count
; Tier two color
inc TitleColor2
ldx TitleColor2
cpx #6
bne :+
ldx #0
stx TitleColor2
:
lda Credits_Tier2, x
sta PaletteRAM+26
@t3check:
dec cr_t2Count
lda frame_odd
bne :+
lda #1
sta frame_odd
rts
: lda #0
sta frame_odd
; Tier three color
inc TitleColor
lda TitleColor
cmp #$2C
bne :+
lda #$21
sta TitleColor
:
lda TitleColor
sta PaletteRAM+22
rts
Credits_Frame:
jsr cr_TierColors
; This is for the actual rom. CRDEBUG is defined in the
; credits dev makefile.
.ifndef CRDEBUG
lda #BUTTON_START
jsr ButtonPressedP1
beq @nobutton
lda #STATES::GS_TITLE
sta current_gamestate
inc gamestate_changed
@nobutton:
.endif
lda cr_scrollWait
bne @notYet
lda #CR_SCROLL_SPEED
sta cr_scrollWait
inc cr_scroll
; Do we need to draw the next name?
dec cr_nextChunkWait
bne @noChunk
lda #16
sta cr_nextChunkWait
jsr Credits_LoadChunk
@noChunk:
lda cr_scroll
cmp #$F0
bcs @rollOver
jmp WaitFrame
@notYet:
dec cr_scrollWait
jmp WaitFrame
@rollOver:
lda #0
sta cr_scroll
lda cr_scroll_table
cmp #CR_TOP
beq @gotoBottom
lda #CR_TOP
sta cr_scroll_table
jmp WaitFrame
@gotoBottom:
lda #CR_BOTTOM
sta cr_scroll_table
jmp WaitFrame
Credits_NMI:
jsr WritePalettes
jsr WriteSprites
bit cr_UpdateReady
bpl @noUpdate
jsr Credits_WriteBuffer
@noUpdate:
; Scroll
bit $2002
; X
lda #0
sta $2005
; Y
lda cr_scroll
sta $2005
; Name table
lda cr_scroll_table
sta $2000
jmp NMI_Finished
; start of row addresses - 30 total rows
PPU_RowStartLookup_High:
.byte $20, $20, $20, $20, $21, $21, $21, $21
.byte $22, $22, $22, $22, $23, $23, $23
.byte $28, $28, $28, $28, $29, $29, $29, $29
.byte $2A, $2A, $2A, $2A, $2B, $2B, $2B
PPU_RowStartLookup_Low:
.byte $00, $40, $80, $C0, $00, $40, $80, $C0
.byte $00, $40, $80, $C0, $00, $40, $80
.byte $00, $40, $80, $C0, $00, $40, $80, $C0
.byte $00, $40, $80, $C0, $00, $40, $80
; low byte of attribute table - 8 total rows
PPU_AttrLookup_Low:
.byte $C0, $C8, $D0, $D8, $E0, $E8, $F0, $F8
Credits_Palette:
.byte $0F,$30,$13,$23, $0F,$05,$15,$0F, $0F,$0A,$1A,$0F, $0F,$11,$21,$0F
.byte $0F,$30,$13,$0F, $0F,$05,$15,$0F, $0F,$0A,$1A,$0F, $0F,$11,$21,$0F
Credits_Tier2:
.byte $03, $13, $23, $33, $23, $13