-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBank00.asm
9190 lines (5749 loc) · 212 KB
/
Bank00.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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; <-- This tab is being kept prisoner in case I need to search for other
; tabs.
; Zelda III Source Code
; Courtesy of MathOnNapkins
lorom
; ==============================================================================
; $000000-$000060
Vector_Reset:
{
SEI ; Set interrupt disable bits
STZ $4200 ; Disables the NMI and various other things
STZ $420C ; HDMA and DMA is disabled
STZ $420B
STZ $2140 ; Clear SPC locations
STZ $2141
STZ $2142
STZ $2143
; Set brightness to zero and enable force blank (forced V-Blank all the time)
LDA.b #$80 : STA $2100
; Switch to native mode
CLC : XCE
; Reset M and D flags
REP #$28
; Direct page is at $0000
LDA.w #$0000 : TCD
; Stack is located at $01FF
LDA.w #$01FF : TCS
SEP #$30 ; M and X are 8 bit
JSR Sound_LoadIntroSongBank
JSR Startup_InitializeMemory
; Bit 7 enables NMI interrupt.
; This register tracks whether NMI is enabled.
LDA.b #$81 : STA $4200
.nmi_wait_loop
; This loop doesn't normally exit unless NMI is enabled!
LDA $12 : BEQ .nmi_wait_loop
CLI ; Clear the interrupt disable bit.
BRA .do_frame
; Inaccessible code, used for debug if assembled in.
; NOP out the above BRA to activate this code
.frameStepDebugCode
LDA $F6 : AND.b #$20 : BEQ .L_ButtonDown ; If the L button is down, then...
INC $0FD7
.L_ButtonDown
; If the R button is down, then...
LDA $F6 : AND.b #$10 : BNE .R_ButtonDown
LDA $0FD7 : AND.b #$01 : BNE .skip_frame
.R_ButtonDown
.do_frame
INC $1A ; frame counter. See ZeldaRAM.rtf for more variable listings.
JSR ClearOamBuffer
JSL Module_MainRouting
.skip_frame
JSR Main_PrepSpritesForNmi
; Start the NMI Wait loop again
STZ $12
BRA .nmi_wait_loop
}
; ==============================================================================
; $0061-$00B4 JUMP TABLE FOR SR$0085
pool Module_MainRouting:
{
; \task Figure out how to express this interleavededly... gah.
interleave
{
; Note: there are 28 distinct modes here (0x1C)
; This jump table is interlaced, sadly enough
.modules
dl Module_Intro ; 0x00 - Triforce / Zelda startup screens
dl Module_SelectFile ; 0x01 - File Select screen
dl Module_CopyFile ; 0x02 - Copy Player Mode
dl Module_EraseFile ; 0x03 - Erase Player Mode
dl Module_NamePlayer ; 0x04 - Name Player Mode
dl Module_LoadFile ; 0x05 - Loading Game Mode
dl Module_PreDungeon ; 0x06 - Pre Dungeon Mode
dl Module_Dungeon ; 0x07 - Dungeon Mode
dl Module_PreOverworld ; 0x08 - Pre Overworld Mode
dl Module_Overworld ; 0x09 - Overworld Mode
dl Module_PreOverworld ; 0x0A - Pre Overworld Mode (special overworld)
dl Module_Overworld ; 0x0B - Overworld Mode (special overworld)
dl Module_Unknown0 ; 0x0C - ???? I think we can declare this one unused, almost with complete certainty.
dl Module_Unknown1 ; 0x0D - Blank Screen
dl Module_Messaging ; 0x0E - Text Mode/Item Screen/Map
dl Module_CloseSpotlight ; 0x0F - Closing Spotlight
dl Module_OpenSpotlight ; 0x10 - Opening Spotlight
dl Module_HoleToDungeon ; 0x11 - Happens when you fall into a hole from the OW.
dl Module_Death ; 0x12 - Death Mode
dl Module_GanonVictory ; 0x13 - Boss Victory Mode (refills stats)
dl Module_Attract ; 0x14 - Attract Mode
dl Module_Mirror ; 0x15 - Module for Magic Mirror
dl Module_Victory ; 0x16 - Module for refilling stats after boss.
dl Module_Quit ; 0x17 - Quitting mode (save and quit)
dl Module_GanonEmerges ; 0x18 - Ganon exits from Agahnim's body. Chase Mode.
dl Module_TriforceRoom ; 0x19 - Triforce Room scene
dl Module_EndSequence ; 0x1A - End sequence
dl Module_LocationMenu ; 0x1B - Screen to select where to start from (House, sanctuary, etc.)
{ modules long i } => { lowers byte i },
{ middles byte i >> 8 },
{ banks byte i >> 16 }
}
}
; ==============================================================================
; *$00B5-$00C8 LONG
Module_MainRouting:
{
; This variable determines which module we're in.
LDY $10
LDA .lowers, Y : STA $03
LDA .middles, Y : STA $04
LDA .banks, Y : STA $05
; Jump to a main module depending on addr $7E0010 in ram
JMP [$0003]
}
; ==============================================================================
; *$0000C9-$00022C NMI Interrupt Subroutine (NMI Vector)
Vector_NMI:
{
; Ensures this interrupt isn't interrupted by an IRQ
SEI
; Resets M and X flags
REP #$30
; Pushes 16 bit registers to the stack
PHA : PHX : PHY : PHD : PHB
; Sets DP to $0000
LDA.w #$0000 : TCD
; Equate Program and Data banks
PHK : PLB
SEP #$30
; This register needs to be read each time NMI is called.
; It apparently resets a latch so that the next NMI can trigger?
LDA $4210
; Used to select a musical track.
LDA $012C : BNE .nonzeroMusicInput
LDA $2140 : CMP $0133 : BNE .handleAmbientSfxInput
; If they were the same, put 0 in $2140
STZ $2140
BRA .handleAmbientSfxInput
.nonzeroMusicInput
CMP $0133 : BEQ .handleAmbientSfxInput
; The song has changed...
STA $2140 : STA $0133 : CMP.b #$F2 : BCS .volumeOrTransferCommand
STA $0130
.volumeOrTransferCommand
STZ $012C
.handleAmbientSfxInput
LDA $012D : BNE .nonzeroAmbientSfxInput
; Compare the values
LDA $2141 : CMP $0131 : BNE .writeSfx
STZ $2141 ; If equal, zero out $2141
BRA .writeSfx
.nonzeroAmbientSfxInput
STA $0131 : STA $2141
STZ $012D
.writeSfx
; Addresses will hold SPC memory locations
LDA $012E : STA $2142
LDA $012F : STA $2143
STZ $012E
STZ $012F
; Bring the screen into forceblank (forced vblank)
LDA.b #$80 : STA $2100
; Disable all DMA transfers
STZ $420C
; Checks to see if we're still in the infinite loop in the main routine
; If $12 is not 0, it shows that the infinite loop isn't running.
LDA $12 : BNE .normalFrameNotFinished
; This would happen if NMI had been called from the wait loop.
INC $12
JSR NMI_DoUpdates
JSR NMI_ReadJoypads
.normalFrameNotFinished
LDA $012A : BEQ .helperThreadInactive
JMP NMI_SwitchThread
.helperThreadInactive
; Sets background clipping...
LDA $96 : STA $2123
LDA $97 : STA $2124
LDA $98 : STA $2125
; Sets color / sprite windowing registers
LDA $99 : STA $2130
LDA $9A : STA $2131
; Possibly a register that must be written 3 times (internal pointer)
LDA $9C : STA $2132
LDA $9D : STA $2132
LDA $9E : STA $2132
; Main / Subscreen designation registers
LDA $1C : STA $212C
LDA $1D : STA $212D
; Window designations...
LDA $1E : STA $212E
LDA $1F : STA $212F
; Are these word addresses?
LDA $0120 : STA $210D
LDA $0121 : STA $210D
LDA $0124 : STA $210E
LDA $0125 : STA $210E
LDA $011E : STA $210F
LDA $011F : STA $210F
LDA $0122 : STA $2110
LDA $0123 : STA $2110
LDA $E4 : STA $2111
LDA $E5 : STA $2111
; All BG registers
LDA $EA : STA $2112
LDA $EB : STA $2112
; MOSAIC and BGMODE register mirrors
LDA $95 : STA $2106
LDA $94 : STA $2105
; Check to see if we're in mode 7
AND.b #$07 : CMP.b #$07 : BNE .notInMode7
STZ $211C : STZ $211C
STZ $211D : STZ $211D
LDA $0638 : STA $211F
LDA $0639 : STA $211F
LDA $063A : STA $2120
LDA $063B : STA $2120
.notInMode7
LDA $0128 : BEQ .irqInactive
; Clear the IRQ line if one is pending? (reset latch)
LDA $4211
; Set vertical irq trigger position to 128, which is a tad
; bit past the middle of the screen, vertically
LDA.b #$80 : STA $4209 : STZ $420A
; Set horizontal irq trigger position to 0.
; (Will not be used anyways)
STZ $4207 : STZ $4208
; Will enable NMI, and Joypad, and vertical IRQ trigger
LDA.b #$A1 : STA $4200 ; #$A1 = #%10100001
.irqInactive
; $13 holds the screen state
LDA $13 : STA $2100
LDA $9B : STA $420C
REP #$30
PLB : PLD : PLY : PLX : PLA
.return
RTI
}
; ==============================================================================
; $22D-$2D7 JUMP LOCATION
NMI_SwitchThread:
{
JSR NMI_UpdateIrqGfx
LDA $FF : STA $4209 : STZ $420A
; A = #%10100001, which means activate NMI, V-IRQ, and Joypad
LDA.b #$A1 : STA $4200
LDA $96 : STA $2123
LDA $97 : STA $2124
LDA $98 : STA $2125
LDA $99 : STA $2130
LDA $9A : STA $2131
LDA $9C : STA $2132
LDA $9D : STA $2132
LDA $9E : STA $2132
LDA $1C : STA $212C
LDA $1D : STA $212D
LDA $1E : STA $212E
LDA $1F : STA $212F
LDA $0120 : STA $210D
LDA $0121 : STA $210D
LDA $0124 : STA $210E
LDA $0125 : STA $210E
LDA $011E : STA $210F
LDA $011F : STA $210F
LDA $0122 : STA $2110
LDA $0123 : STA $2110
LDA $E4 : STA $2111
LDA $E5 : STA $2111
LDA $EA : STA $2112
LDA $EB : STA $2112
LDA $13 : STA $2100
LDA $9B : STA $420C
REP #$30
; This is very tricksy.
; X = S; (apparently they did't know about the TSX instruction)
TSC : TAX
; S = $1F0A
; $1F0A = X
LDA $1F0A : TCS : STX $1F0A
; Expect to end up at $09F81D after the RTI ;)
PLB : PLD : PLY : PLX : PLA
RTI
}
; *$2D8-$332 IRQ INTERRUPT
Vector_IRQ:
{
SEI
REP #$30
PHA : PHX : PHY : PHD
PHB : PHK : PLB
SEP #$30
LDA $012A : BNE BRANCH_3
; Only d7 is significant in this register. If set, h/v counter has latched.
LDA $4211 : BPL BRANCH_2 ; So in other words, branch if the timer has NOT counted down.
; Not sure what this does...
LDA $0128 : BEQ BRANCH_2
BRANCH_1:
BIT $4212 : BVC BRANCH_1 ; Wait for hBlank
LDA $0630 : STA $2111
LDA $0631 : STA $2111
STZ $2112 : STZ $2112
LDA $0128 : BPL BRANCH_2
STZ $0128
LDA.b #$81 : STA $4200
BRANCH_2:
; h/v timer didn't count down yet, so we do NOTHING :).
REP #$30
PLB : PLD : PLY : PLX : PLA
RTI
BRANCH_3:
LDA $4211
REP #$30
; X = S
TSC : TAX
; Transfer A -> S
LDA $1F0A : TCS : STX $1F0A
PLB : PLD : PLY : PLX : PLA
RTI
}
; $0333-$3D0 LONG
Vram_EraseTilemaps:
{
; this routine might be optimizable
.triforce ; for use with the title screen and the credits sequence
!fillBg_1_2 = $00
!fillBg_3 = $02
REP #$20
LDA.w #$00A9 : STA !fillBg_3
LDA.w #$007F
BRA .fillTilemaps
; $033F ALTERNATE ENTRY POINT
.palaceMap
REP #$20
LDA.w #$007F : STA !fillBg_3
LDA.w #$0003
BRA .fillTilemaps
; $034B ALTERNATE ENTRY POINT
.normal
; Performs a tilemap blanking (filling with transparent tiles) for BG1, BG2, and BG3
REP #$20
; $01EC indicates "blank" tiles
LDA.w #$007F : STA !fillBg_3
LDA.w #$01EC
.fillTilemaps
; Could be any number of values.
STA !fillBg_1_2
; vram target address updates on writes to $2118
STZ $2115
; The vram target address is $0000 (word address)
STZ $2116
; target register is $2118, write one register once mode, with fixed source address
LDA.w #$1808 : STA $4310
; dma source address is $000000
STZ $4314
LDA.w #$0000 : STA $4312
; will write 0x2000 bytes. since we're only writing to the low byte of each vram word address,
; we will technically cover 0x4000 bytes worth of address space, but in terms of vram addresses it's
; still only vram address $0000 to $1FFF
LDA.w #$2000 : STA $4315
; transfer the data on channel 1
LDY.b #$02 : STY $420B
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; increment vram address when $2119 is written
LDX.b #$80 : STX $2115
; Reinitialize vram target address to $0000 (word)
STZ $2116
; Again write 0x2000 bytes
STA $4315
; dma target register is $2119, write one register once mode, with fixed address
LDA.w #$1908 : STA $4310
; The DMA source address will now be $000001
LDA.w #$0001 : STA $4312
; transfer data on channel 1
STY $420B
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; This value was saved earliest in the routine.
LDA !fillBg_3 : STA !fillBg_1_2
; increment on writes to $2118 again
STZ $2115
; write to vram address $6000 (word)
LDA.w #$6000 : STA $2116
; Write to $2118, Non incrementally
LDA.w #$1808 : STA $4310
; $DMA source address is $000000
LDA.w #$0000 : STA $4312
; Write $00 #$800 times to Vram.
LDA.w #$0800 : STA $4315
; transfer data on channel 1
STY $420B
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
; increment on writes to $2119 again
STX $2115
; Reset the byte amount to 0x800 bytes
STA $4315
; Reset vram target address to $6000 (word)
LDA.w #$6000 : STA $2116
; write to $2119, write one register once mode, fixed source address
LDA.w #$1908 : STA $4310
; DMA source address is $000001
LDA.w #$0001 : STA $4312
; transfer data on channel 1
STY $420B
SEP #$20
RTL
}
; *$3D1 - $41D LOCAL
NMI_ReadJoypads:
{
!disableJoypad2 = "RTS"
!enableJoypad2 = "NOP"
!joypad2_action = !disableJoypad2
; Probably indicates that we're not using the old style joypad reading.
STZ $4016
; Storing the state of Joypad 1 to $00-$01
LDA $4218 : STA $00
LDA $4219 : STA $01
; $F2 has the pure joypad data
LDA $00 : STA $F2 : TAY
; $FA at this point contains the joypad data from the last frame.
; This is intended to avoid flooding in processing commands.
; Send this "button masked" reading here.
; Hence $F2 and $FA contain pure joypad readings from this frame now.
EOR $FA : AND $F2 : STA $F6 : STY $FA
; Essentially the same procedure as above, but for the other half of JP1.
LDA $01 : STA $F0 : TAY
EOR $F8 : AND $F0 : STA $F4 : STY $F8
!joypad2_action
; If it wasn't obvious, please note that the original game, coded this way,
; never reaches this section. Yes folks, there is no love for Joypad2 in
; Zelda 3.
LDA $421A : STA $00
LDA $421B : STA $01
LDA $00 : STA $F3 : TAY
EOR $FB : AND $F3 : STA $F7 : STY $FB
LDA $01 : STA $F1 : TAY
EOR $F9 : AND $F1 : STA $F5 : STY $F9
RTS
}
; ==============================================================================
; *$41E-$489 LOCAL
ClearOamBuffer:
{
; Gets rid of old sprites by moving them off screen, basically.
; E.g., when you kill a soldier, his sprite has to disappear, right?
; Any sprites that are still in the game engine will be moved back on screen
; before VRAM
; is written to again.
LDX.b #$60
.loop
LDA.b #$F0
STA $0801, X : STA $0805, X : STA $0809, X : STA $080D, X
STA $0811, X : STA $0815, X : STA $0819, X : STA $081D, X
STA $0881, X : STA $0885, X : STA $0889, X : STA $088D, X
STA $0891, X : STA $0895, X : STA $0899, X : STA $089D, X
STA $0901, X : STA $0905, X : STA $0909, X : STA $090D, X
STA $0911, X : STA $0915, X : STA $0919, X : STA $091D, X
STA $0981, X : STA $0985, X : STA $0989, X : STA $098D, X
STA $0991, X : STA $0995, X : STA $0999, X : STA $099D, X
; X -= 0x20
TXA : SUB.b #$20 : TAX : BPL .loop
RTS
}
; $48A-$5FB DATA
{
dw $0000, $0000
dw $0500, $0A00
dw $0F00
; $494
dw $A480
dw $A4C0, $A500
dw $A540
; $49C
dw $9000, $9020, $9060, $91E0, $90A0, $90C0, $9100, $9140
; $4AC
dw $9300, $9340, $9380, $9480, $94C0, $94E0, $95C0, $9500
dw $9520
dw $9540, $9480
dw $9640, $9680
dw $96A0, $9780
dw $96C0, $96E0
dw $9700, $9480
dw $9800, $9840
dw $98A0, $9480
dw $9480, $9480
dw $9480, $9480
dw $9AC0, $9B00
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9BC0, $9C00
dw $9C40, $9C80
dw $9CC0, $9D00
dw $9D40, $9480
dw $9F40, $9F80
dw $9FC0, $9FE0
dw $A000, $9480
dw $9480, $9480
dw $A100, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $98C0, $9900
dw $99C0, $99E0
dw $9A00, $9A20
dw $9A40, $9A60
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9A80, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
dw $9480, $9480
}
; ==============================================================================
; *$05FC-$0780 LOCAL
Main_PrepSpritesForNmi:
{
; Writes some extra data for the OAM memory
; The data is written to $0A00 to $0A1F,
; And the data that is written is formed from
; The addresses $0A20 through $0A9F
LDY.b #$1C
.buildHighOamTable
; Y = 0x1C, X = 0x70
TYA : ASL #2 : TAX
; Start at $0A93?
LDA $0A23, X : ASL #2
ORA $0A22, X : ASL #2
ORA $0A21, X : ASL #2
ORA $0A20, X : STA $0A00, Y
LDA $0A27, X : ASL #2
ORA $0A26, X : ASL #2
ORA $0A25, X : ASL #2
ORA $0A24, X : STA $0A01, Y
LDA $0A2B, X : ASL #2
ORA $0A2A, X : ASL #2
ORA $0A29, X : ASL #2
ORA $0A28, X : STA $0A02, Y
LDA $0A2F, X : ASL #2
ORA $0A2E, X : ASL #2
ORA $0A2D, X : ASL #2
ORA $0A2C, X : STA $0A03, Y
DEY #4 : BPL .buildHighOamTable
REP #$31
LDX $0100
LDA $9396, X : STA $0ACC : ADC.w #$0200 : STA $0ACE
LDA $95F4, X : STA $0AD0 : ADD.w #$0200 : STA $0AD2
LDX $0102 : LDA $9852, X : STA $0AD4
LDX $0104 : LDA $9852, X : STA $0AD6
SEP #$10
LDX $0107 : LDA $849C, X : STA $0AC0 : ADD.w #$0180 : STA $0AC2
LDX $0108 : LDA $84AC, X : STA $0AC4 : ADD.w #$00C0 : STA $0AC6
LDA $0109 : AND.w #$00F8 : LSR #2 : TAY
LDA $0109 : ASL A : TAX
LDA $84B2, X : STA $0AC8
CLC : TYX : ADC $85B2, X : STA $0ACA
LDA $02C3 : AND.w #$0003 : ASL A : TAX
LDA $8494, X : STA $0AD8 : ADD.w #$0100 : STA $0ADA
LDA $7EC00D : DEC A : STA $7EC00D : BNE .ignoreTileAnimation
; Reset the counter for tile animation
LDA.w #$0009
LDX $8C : CPX.b #$B5 : BEQ BRANCH_1A
CPX.b #$BC : BNE BRANCH_1B
BRANCH_1A:
LDA.w #$0017
BRANCH_1B:
STA $7EC00D
LDA $7EC00F : ADD.w #$0400 : CMP.w #$0C00 : BNE BRANCH_1C
LDA.w #$0000
BRANCH_1C:
STA $7EC00F : ADD.w #$A680 : STA $0ADC
.ignoreTileAnimation
LDA $7EC013 : DEC A : STA $7EC013 : BNE .ignoreSpriteAnimation
LDA $7EC015 : TAX
INX #2 : CPX.b #$0C : BNE .spriteAnimationLoopIncomplete
LDX.b #$00
.spriteAnimationLoopIncomplete
TXA : STA $7EC015
LDA $85D2, X : STA $7EC013
LDA.w #$B280 : ADD $85DE, X : STA $0AE0
ADD.w #$0060 : STA $0AE2
.ignoreSpriteAnimation
; setup tagalong sprite for dma transfer
LDA $0AE8 : ASL A
ADC.w #$B940 : STA $0AEC
ADC.w #$0200 : STA $0AEE
; setup tagalong sprite's other component for dma transfer?
LDA $0AEA : ASL A
ADC.w #$B940 : STA $0AF0
ADC.w #$0200 : STA $0AF2
; setup dma transfer for bird's sprite slot
LDA $0AF4 : ASL A
ADC.w #$B540 : STA $0AF6
ADC.w #$0200 : STA $0AF8
SEP #$20
RTS
}
; ==============================================================================
; *$000781-$00079B LONG
UseImplicitRegIndexedLocalJumpTable:
{
; Parameters: Stack, A
; save current Y
STY $03
; Pull return PCL to Y
PLY : STY $00
REP #$30
; Ensures offset is a Multiple of two
AND.w #$00FF : ASL A : TAY
; Pull the rest of the return address onto A
; Since this is a 16 bit value this ensures that the jump address is
; in the same bank as the return address
PLA : STA $01
INY
LDA [$00], Y : STA $00
SEP #$30
; restore Y
LDY $03
JML [$0000]
}
; ==============================================================================
; *$79C-$7BF LONG( A, STACK)
UseImplicitRegIndexedLongJumpTable:
{
STY $05
; load Y with lower return PC from the stack
PLY : STY $02
REP #$30
AND.w #$00FF : STA $03
; shift bits left = multiply by two, since bit 15 will NOT be set.
; Add the original number. Essentially, this is 2N + N = 3N
; // In other words, Y is indexed as 3 times the value that A had.
ASL A : ADC $03 : TAY
; Pull the upper return PC and return PB from the Stack.
PLA : STA $03
INY ; Pushes Y past the edge of the original PC
; Look up a new address in a table
LDA [$02], Y : STA $00 : INY
; Note that the first STA overlapped this one.
LDA [$02], Y : STA $01
; The idea was to retrieve a 3-byte address from a jump table
SEP #$30
LDY $05 ; Restore Y's earlier value.
JML [$0000]
}
; ==============================================================================
; *$07C0-$082D LOCAL
Startup_InitializeMemory:
{
; Zeroes out $7e0000-$7e1FFF, and checks some values in SRAM
REP #$30
; Save the return location of this subroutine
; But why do this, why not something like "TSX : TXY"?
LDY.w $01FE
; Counter for the loop.
LDX.w #$03FE
; The value to write.
LDA.w #$0000
.erase
; Zero out $0000-$1FFF
STA $0000, X : STA $0400, X : STA $0800, X : STA $0C00, X
STA $1000, X : STA $1400, X : STA $1800, X : STA $1C00, X
DEX #2 : BNE .erase
STA $7EC500 : STA $701FFE ; Sets it so we have no memory of opening a save file.
; Checks the checksum for the first save file.
LDA $7003E5 : CMP.w #$55AA : BEQ .validSlot1Sram
; Effectively sends the program the message to delete this file.
LDA.w #$0000 : STA $7003E5
.validSlot1Sram
; repeat this for slots 2 and 3
LDA $7008E5 : CMP.w #$55AA : BEQ .validSlot2Sram
LDA.w #$0000 : STA $7008E5