-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch.asm
1231 lines (1169 loc) · 51.3 KB
/
patch.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
hirom
org $c0d613 : fillbyte $ff
fill 2445
org $c0d613
;!DEBUG = ""
incsrc "aplib_inject.asm"
;===================================================================
; @ RAM Direct Page Map:
; Field:
; $5c : H-scroll value of BG1.
; $64 : H-scroll value of BG2.
; $6c : H-scroll value of BG3.
;
; $73 : x-movement direction offset (non-controller).
;
; $86 : BG1 Map Horizontal Clip.
; $87 : BG1 Map Vertical Clip.
; $88 : BG2 Map Horizontal Clip.
; $89 : BG2 Map Vertical Clip.
; $8A : BG3 Map Horizontal Clip.
; $8B : BG3 Map Vertical Clip.
;
; $91 : low byte of BG1 DMA buffer address for y-movement and fullscreen updates.
; $92 : high byte of BG1 DMA buffer address for y-movement and fullscreen updates.
; $93 : low byte of BG1 DMA buffer address for x-movement updates (column 1).
; $94 : high byte of BG1 DMA buffer address for x-movement updates (column 1).
; $95 : low byte of BG1 DMA buffer address for x-movement updates (column 2).
; $96 : high byte of BG1 DMA buffer address for x-movement updates (column 2).
;
; $97 : low byte of BG2 DMA buffer address for y-movement and fullscreen updates.
; $98 : high byte of BG2 DMA buffer address for y-movement and fullscreen updates.
;
; $99 : low byte of BG2 DMA buffer address for y-movement updates (column 1).
; $9a : high byte of BG2 DMA buffer address for x-movement updates (column 1).
; $9b : low byte of BG2 DMA buffer address for x-movement updates (column 2).
; $9c : high byte of BG2 DMA buffer address for x-movement updates (column 2).
;
; $9d : low byte of BG3 DMA buffer address for y-movement and fullscreen updates.
; $9e : high byte of BG3 DMA buffer address for y-movement and fullscreen updates.
;
; $9f : low byte of BG3 DMA buffer address for x-movement updates (column 1).
; $a0 : high byte of BG3 DMA buffer address for x-movement updates (column 1).
; $a1 : low byte of BG3 DMA buffer address for x-movement updates (column 2).
; $a2 : high byte of BG3 DMA buffer address for x-movement updates (column 2).
;
; @ RAM Indirect Map:
; Field:
; $0541 : BG1 current x-coordinate pivot.
; $0542 : BG1 current y-coordinate pivot.
;
; $0543 : BG2 current x-coordinate pivot.
; $0544 : BG2 current y-coordinate pivot.
;
; $0545 : BG3 current x-coordinate pivot.
; $0546 : BG3 current y-coordinate pivot.
;
; $055a : BG1 Fullscreen update index. 4: Buffer top-half-tiles, 3: Buffer bottom-half-tiles, 2: DMA Top-half-tiles, 1: DMA bottom-half-tiles, 0: do nothing.
; $055b : BG2 Fullscreen update index. 4: Buffer top-half-tiles, 3: Buffer bottom-half-tiles, 2: DMA Top-half-tiles, 1: DMA bottom-half-tiles, 0: do nothing.
; $055c : BG3 Fullscreen update index. 4: Buffer top-half-tiles, 3: Buffer bottom-half-tiles, 2: DMA Top-half-tiles, 1: DMA bottom-half-tiles, 0: do nothing.
;
; $058c : Current BG1 VRAM buffer address.
; $058e : Current BG2 VRAM buffer address.
; $0590 : Current BG3 VRAM buffer address.
;
; $0547 : Added to $73 -- dunno.
;
; $062c : X-Scroll start + Camera start?
;
; $0960 : exact character x-offset in pixels (not true in all areas).
; $0963 : exact character y-offset in pixels (not true in all areas).
;
; $0970 : character x position (not true in all areas).
; $0971 : character y position (not true in all areas).
;
; $0974 : current controller movement direction. 0 if controller isn't initiating movement (not true in all areas).
; $0975 : current controller movement direction (stored). 0 if controller isn't initiating movement (not true in all areas).
;
; @ ROM Code Map:
; Field:
; $c01cf3 - $c01d23 : Full Update Top-half DMA to VRAM | BG1.
; $c01d24 - $c01d5e : Full Update Bot-half DMA to VRAM | BG1.
; $c01d5f - $c01d8f : Full Update Top-half DMA to VRAM | BG2.
; $c01d90 - $c01dca : Full Update Bot-half DMA to VRAM | BG2.
; $c01dcb - $c01dfb : Full Update Top-half DMA to VRAM | BG3.
; $c01dfc - $c91e36 : Full Update Bot-half DMA to VRAM | BG3.
; $c01e37 - $c01ec3 : Full Update DMA check | BG1, BG2, BG3.
; $c01ec4 - $c01f07 : Full Update Map Data (e.g doors) | BG1, BG2, BG3.
; $c01f08 - $c01f13 : Full Update Check | BG1.
; $c01f14 - $c01fc1 : Full Update Buffering | BG1.
; $c01fc2 - $c01fcd : Full Update Check | BG2.
; $c01fce - $c02080 : Full Update Buffering | BG2.
; $c02081 - $c0208c : Full Update Check | BG3.
; $c0208d - $c02101 : Full Update Buffering | BG3.
; $c02102 - $c02153 : Row/Column Update Check | BG1, BG2, BG3.
; $c02154 - $c0220f : Row Update Buffering | BG1.
; $c02210 - $c022ce : Column Update Buffering | BG1.
; $c022cf - $c0238a : Row Update Buffering | BG2.
; $c0238b - $c0244d : Column Update Buffering | BG2.
; $c0244e - $c02499 : Row Update Pre-Buffering | BG3.
; $c0249a - $c02558 : Row Update Buffering | BG3.
; $c02559 - $c0265b : Column Update Buffering | BG3.
; $c0265c - $c0268c : Color Palette Load | BG1, BG2, BG3.
; $c0268d - $c026d7 : Tile Data DMA Check | BG1, BG2.
; $c026d8 - $c0285e : Tile Data DMA to VRAM | BG1, BG2.
; $c0275f - $c027d9 : Tile Data DMA to VRAM | BG3.
; $c027da - $c02882 : Tile Formation | BG1, BG2.
; $c02883 - $c0296a : Map Load | BG1, BG2.
; $c0296b - $c0297f : Map Load | BG3.
; $c02980 - $c02a46 : Map Decompression | BG1, BG2, BG3.
; $c02a47 - $c02a77 : Row Update DMA to VRAM | BG1.
; $c02a78 - $c02aC9 : Column Update DMA to VRAM | BG1.
; $c02aca - $c02afa : Row Update DMA to VRAM | BG2.
; $c02afb - $c02b4c : Column Update DMA to VRAM | BG2.
; $c02b4d - $c02b7d : Row Update DMA to VRAM | BG3.
; $c02b7e - $c02bcf : Column Update DMA to VRAM | BG3.
; @ WRAM Address Map:
; Original Field:
; $7e0500 : OAM buffer.
; $7e81b3 : location of buffer looping values (switches on hsync intervals?).
;
; $7fd840 - $7fd8bf: Partial BG1 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
; $7fd8c0 - $7fd93f: Partial BG2 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
; $7fd940 - $7fd9bf: Partial BG3 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
;
; $7fd9c0 - $7fda3f: Partial BG1 Map for Vertical Scrolling (128 bytes) (32 x 2 tiles, 2 bytes per 8x8 tile)
; $7fe1c0 - $7fe23f: Partial BG2 Map for Vertical Scrolling (128 bytes) (32 x 2 tiles, 2 bytes per 8x8 tile)
; $7fe9c0 - $7fea3f: Partial BG3 Map for Vertical Scrolling (128 bytes) (32 x 2 tiles, 2 bytes per 8x8 tile)
;
; $7fd9c0 - $7fe1bf: BG1 Map for Full Updates (2048 bytes) (32 x 32 tiles, 2 bytes per 8x8 tile)
; $7fe1c0 - $7fe9bf: BG2 Map for Full Updates (2048 bytes) (32 x 32 tiles, 2 bytes per 8x8 tile)
; $7fe9c0 - $7ff1bf: BG3 Map for Full Updates (2048 bytes) (32 x 32 tiles, 2 bytes per 8x8 tile)
;
; Widescreen Field:
; $7fd840 - $7fd8bf: Partial BG1 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
; $7fd8c0 - $7fd93f: Partial BG2 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
; $7fd940 - $7fd9bf: Partial BG3 Map for Horizontal Scrolling (128 bytes) (2 x 32 tiles, 2 bytes per 8x8 tile) (first column, second column)
;
; $3f6000 - $3f60ff: Partial BG1 Map for Vertical Scrolling (256 bytes) (64 x 2 tiles, 2 bytes per 8x8 tile)
; $3f7000 - $3f70ff: Partial BG2 Map for Vertical Scrolling (256 bytes) (64 x 2 tiles, 2 bytes per 8x8 tile)
; $7fd9c0 - $7fdabf: Partial BG3 Map for Vertical Scrolling (256 bytes) (64 x 2 tiles, 2 bytes per 8x8 tile)
;
; $3f6000 - $3f6fff: BG1 Map for Full Updates (4096 bytes) (64 x 32 tiles, 2 bytes per 8x8 tile)
; $3f7000 - $3f7fff: BG2 Map for Full Updates (4096 bytes) (64 x 32 tiles, 2 bytes per 8x8 tile)
; $7fd9c0 - $7fe9bf: BG3 Map for Full Updates (4096 bytes) (64 x 32 tiles, 2 bytes per 8x8 tile)
;
; World Map:
; 0x7e6b30 : OAM Table 1 start (in CPU memory).
; 0x7e6d30 : OAM Table 2 start (in CPU memory).
; 0x7eb5da : x-location of airship on-screen.
; 0x7eb5dc : y-location of airship on-screen.
;
; @ VRAM Address Map:
; Original (assuming 8-bit word size):
; $0000 - $5fff : Tile data (BG1 & BG2).
; $6000 - $7fff : Tile data (BG3).
; $8000 - $87ff : Message Borders (BG1).
; $8800 - $8fff : Message Text (BG3) (Top and bottom half are duplicates).
; $9000 - $97ff : Bottom Layer Tiles (BG1).
; $9800 - $9fff : Bottom Layer Tiles Alt (BG1).
; $a000 - $a7ff : Top Layer Tiles (BG2).
; $a800 - $afff : Top Layer Tiles Alt (BG2).
; $b000 - $b7ff : Effects (BG3).
; $b800 - $bfff : Effects Alt (BG3).
; $c000 - $dfff : Sprite Locations (OAM).
; $e000 - $ffff : Sprite Data (OAM).
;
; Wide-screen (assuming 8-bit word size):
; $0000 - $5fff : Tile data (BG1 & BG2).
; $6000 - $7fff : Tile data (BG3).
; $8000 - $87ff : Message Borders (BG1).
; $8800 - $8fff : Message Text (Top and bottom half are duplicates) (BG3).
; $9000 - $9fff : Ground Tiles (Expanded) (BG1).
; $a000 - $afff : Roof Tiles (Expanded) (BG2).
; $b000 - $bfff : Effects (Expanded) (BG3).
; $c000 - $dfff : Sprite Locations (OAM).
; $e000 - $ffff : Sprite Data (OAM).
;
; @ Reserved Memory Map:
; Wide-screen:
; $15ff : Configurable mini-map state byte.
;
; @ Cheat Codes:
; Walk through walls in Towns/Dungeons:
; Raw : C04E4E:EA+C04E4F:EA+C04E57:EA+C04E58:EA+C04E6A:EA+C04E6B:EA+C04E73:EA+C04E74:EA+C04E7E:EA+C04E7F:EA+C04E86:EA+C04E87:EA+C04E8D:EA+C04E8E:EA+C04EA9:80
; Game Genie : 3C00-8767+3C00-87A7+3C09-8FA7+3C09-84D7+3C01-8467+3C01-84A7+3C05-8DA7+3C05-8FD7+3C05-8767+3C05-87A7+3C06-8F67+3C06-8FA7+3C06-8707+3C06-8767+6D0C-8407
;
; Walk though walls in Overworld:
; Raw : EE1EE2:EA+EE1EE3:EA+EE1F30:EA+EE1F31:EA+EE1F7E:EA+EE1F7F:EA+EE1FCB:EA+EE1FCC:EA
; Game Genie : 3CF3-8688+3CF3-86E8+3CF7-E678+3CF7-E658+3CF5-E888+3CF5-E8E8+3CFA-ECE8+3CFA-E878
;
; Load a selected map in certain locations:
; Raw : C01AC0:A9XXXXEA where XXXX is the map ID.
;
;
; @ Tile Layout Fixes:
; Chocobo Stable: Exterior (WoB WoR) (BG1, BG2) : Expanded to 32x16.
; Duncan's / Sabin's House: Exterior (BG1, BG2) : Expanded to 32x16.
; Mt. Kolts: Entrance : Shift BG2 Background.
; Mt. Kolts: Exterior (BG1) : Bottom-right Mountain Fixes.
; Mt. Kolts: Vargas' Area (BG1, BG2) : Surrounding Mountain Fixes.
; Mountains Parallex (BG2) : Cloud Fixes.
; South Figaro: Docks (BG1, BG2, BG3) : Expanded map and enabled scrolling.
;
; @ Trigger Fixes:
; Chocobo Stable: Interior : Changed warp location on floor trigger.
; Duncan's House: interior : Changed warp location on floor trigger.
; Sabin's House: Interior : Changed warp location on exit house script and floor trigger (separate).
; South Figaro: Exterior (WoB, WoR) : Exterior : changed warp location on dock trigger.
;===================================================================
; Section:
; @ Generic Macros
;
macro cmp(loc, val)
org <loc> : cmp <val>
endmacro
macro cpx(loc, val)
org <loc> : cpx <val>
endmacro
macro cpy(loc, val)
org <loc> : cpy <val>
endmacro
macro eor_nop3(loc)
org <loc> : eor #$01 : nop #3
endmacro
macro jsl(loc, lbl)
org <loc> : jsl <lbl>
endmacro
macro jsl_nop(loc, lbl)
%jsl(<loc>, <lbl>) : nop
endmacro
macro jsl_nop2(loc, lbl)
%jsl(<loc>, <lbl>) : nop #2
endmacro
macro lda(loc, val)
org <loc> : lda <val>
endmacro
macro ldx(loc, val)
org <loc> : ldx <val>
endmacro
macro ldy(loc, val)
org <loc> : ldy <val>
endmacro
macro nop(loc)
org <loc> : nop
endmacro
macro nop2(loc)
org <loc> : nop #2
endmacro
macro nop3(loc)
org <loc> : nop #3
endmacro
macro nop4(loc)
org <loc> : nop #4
endmacro
;===================================================================
; Section:
; @ Cheats
;
; Description:
; Cheats.
;
; - Walk through Walls in Towns/Dungeons.
; - Walk through Walls in Overworld.
;
pushpc
{
; Towns/Dungeons
%nop2($c04e4e)
%nop2($c04e57)
%nop2($c04e6a)
%nop2($c04e73)
%nop2($c04e7e)
%nop2($c04e86)
%nop2($c04e8d)
org $c04ea9 : db $80 ; bra
; Overworld
%nop2($ee1ee2)
%nop2($ee1f30)
%nop2($ee1f7e)
%nop2($ee1fcb)
}
pullpc
;===================================================================
; Section:
; @ ROM Header
;
; Description:
; Rom header modifications.
;
; - Quadruple SRAM.
;
pushpc
{
org $00ffd8
db $05 ; $400<<5 (32768 Bytes)
}
pullpc
;===================================================================
; Section:
; @ Lookup Tables
;
; Description:
; Lookup tables.
;
; - OAM2 bitwise table for looking up the location of the 9th x-bit to set for a given sprite number.
;
oam2_bit_vals:
{
db $01,$04,$10,$40 ; bits: 00_00_00_01; 00_00_01_00, 00_01_00_00, 01_00_00_00
}
;===================================================================
; Section:
; @ Stack Setup
;
; Description:
; Stack modifications.
;
; - Reserve stack space for patch usage.
; - Ex-map state for displaying the mini-map in 4 locations.
;
pushpc
{
%ldx($c00020, #$15fe) ; Reserve stack space (originally #15ff)
%jsl_nop($c0002c,setup) ; Setup reserved variable state.
}
pullpc
setup:
{
lda #$01 ; Initial value of mini-map.
sta $15ff ; ex-map state.
lda #$01 ; Original code.
sta $420d ; Original code.
rtl
}
;===================================================================
; Section:
; @ OAM Sprite Boundaries
;
; Description:
; Sprite Drawing boundary expansion.
;
macro rm_ex_lrg_sprite_shft(dest)
; Subtract 8 from large sprite location.
sbc $5c
sec
sbc #$0008
sta <dest>
rtl
endmacro
exp_draw_bnds_reg_sprite:
{
; Checks if character sprite is on a negative boundary and overwrites OAM data. Negative
; boundaries could be on the right or left. Anywhere outside the center of the screen.
; Rather iffy considering it does it directly. For some reason the built in logic does
; not work for the main character sprite so they loop along the center normally? It
; remains to be seen whether the OAM locations are static for the main character or not.
pha
cpx #$0000 ; Check if character sprite apparently an X of zero here implies this?
bne .end ; Branch if not character sprite.
and #$ff00 ; Get high byte.
cmp #$0000 ; Check if subtraction was negative for orienting the sprite (-64 logic).
beq .end ; Branch if not negative.
sep #$20 ; Kick into 8-bit mode.
lda $050f ; Load current OAM value for sprite that represents the character.
ora #$10 ; Enable negative bit to place the sprite to the right of the OAM window.
sta $050f ; Store back.
lda $051b ; Load current OAM value for two other sprites the represent the character.
ora #$50 ; 0x10 | 0x40 Enable negative bits to place the sprite(s) to the right of the OAM window.
sta $051b ; Store back.
rep #$20 ; Kick into 16-bit mode.
.end:
pla
; Expands the normal sprites to appear in a wider area.
adc #$0050 ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
sep #$20 ; kick into 8-bit mode.
xba ; swap upper byte -- it uses it to check whether a sprite should be displayed (original code).
and #$fe ; Checking clipping to be an extra byte large from the original logic.
rtl
}
macro overworld_pos_inline()
;-------------------------------------------------------------------
; Modified Overworld Sprite positioning algorithm to work for
; widescreen. Uses 16-bit values to detect if sprites are outside of
; the 0-255 range and sets the OAM2 bit table for the given sprite.
org $ee4335
; Load and normalize the sprite x-offset to be positive.
tdc ; clear upper byte of a.
lda $95d0,y ; load sprite x-offset (from a lookup table).
clc ; clear carry.
adc #$10 ; normalize x-offset to get rid of overflow (some offsets are in the 0xF6+ range otherwise).
; Switch to 16-bit mode and add x-coord to overflow into the high-byte (used to detect the x-coord range).
rep #$21 ; Kick a into 16-bit mode and clear carry.
adc $58 ; add x-coord to sprite x-offset.
pha ; push a.
phx ; push x.
phy ; push y.
; Compute the sprite number, OAM2 byte, and OAM2 9th bit locations (needed to expand x-coords to 0-511).
sep #$30 ; Kick into 8-bit mode.
txa ; transfer sprite offset x->a.
lsr #2 ; normalize to get sprite number.
tay ; transfer sprite index a->y.
and #$03 ; AND to get current bit to modify.
tax ; transfer OAM BIT to modify a->x.
tya ; transfer sprite index y->a.
lsr #2 ; normalize to get OAM BYTE to modify.
tay ; transfer byte to modify a->y.
bank noassume
lda oam2_bit_vals, x ; load bitwise value using current bit as an offset.
bank auto
tax ; store OAM2 bit to set/clear in value a->x.
; Check if in positive range or not and set/clear the 9th bit accordingly.
xba ; exchange high byte to see if in negative range.
beq + ; branch if positive range (0x0).
; Negative range (-1 to -256):
txa ; store OAM2 bit to set/clear in x->a(set).
ora $6d30,y ; OR with current value in OAM2[byte to modify] to set bit.
bra ++ ; Branch to store-back.
+:
; positive range (0 to 255):
txa ; store OAM2 bit to set/clear in x->a (clear).
eor #$ff ; invert bits (all bits except the bit we want to clear should be set).
and $6d30,y ; and with current value in OAM2[byte to modify] to clear bit.
++:
sta $6d30,y ; store back in OAM2[byte to modify].
rep #$30 ; Kick into 16-bit mode.
ply ; restore x.
plx ; restore y.
pla ; restore a.
sep #$20
nop #2 ; nop to $ee4370 (original game code).
; Overworld - Character offset shift (subtracted by #$10 to compensate for the adjustment above).
org $ee482b
lda #$6e
; Overworld - Airship offset shift (subtracted by #$10 to compensate for the adjustment above).
org $ee4781
adc #$006e
endmacro
pushpc
{
; ----
; Shift removal code:
; ----
%nop4($c05bb2) ; Remove 8 pixel shift for regular sprites.
%nop3($c0c8c3) ; Remove 8 pixel shift for shadow clipping sprites.
%nop4($c06579) ; Remove 8 pixel shift for large esper sprites.
; Remove 8 pixel shift for extra large chocobo sprites.
%jsl($c060e0, rm_ex_lrg_sprite_shft_chocobo)
; Remove 8 pixel shift for extra large magitek armor sprites.
%jsl($c05d67, rm_ex_lrg_sprite_shft_magitek)
; ----
; Load expansion code:
; ----
; Expand draw bounds for regular sprites.
%nop($c05bee) ; xba that is now located in the jump.
%jsl_nop($c05bb9, exp_draw_bnds_reg_sprite)
; Expand draw bounds for large esper sprites.
%cpx($c065b6, #$ffa0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
%cpx($c065bb, #$01a0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
; Expand draw bounds for extra large chocobo sprites.
%cpy($c06112, #$01a0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
%cpy($c06117, #$ffa0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
; Expand draw bounds for extra large magitek armor sprites.
%cpy($c05d99, #$01a0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
%cpy($c05d9e, #$ffa0) ; shift the boundary to load/unload sprites directly at the wide-screen pivot location.
; Expand draw bounds for airship sprite.
%nop3($ee476e) ; Overworld: Remove x-coordinate clamping.
%cmp($ee4773, #$010a) ; check for displaying ship
%overworld_pos_inline() ; Modify overworld positoning algorithm.
;--------------------------------------------------------------------------------------------------
}
pullpc
rm_ex_lrg_sprite_shft_chocobo: %rm_ex_lrg_sprite_shft($20)
rm_ex_lrg_sprite_shft_magitek: %rm_ex_lrg_sprite_shft($1e)
;===================================================================
; Section:
; @ OAM Configurable Mini-map
;
; Description:
; Configurable mini-map logic for displaying the mini-map in 4 different possible locations. Implements
; logic for five different states. Byte $15FF as been reserved on the the stack to store the state.
;
; 0 - Mini-map not displayed.
; 1 - Mini-map displayed on the mid-right.
; 2 - Mini-map displayed on the far-right.
; 3 - Mini-map displayed on the mid-left.
; 4 - Mini-map displayed on the far-left.
;
mmap_set_cfg:
{
; Implements logic for setting up 5 different states to cycle through when the mini-map button toggle is
; hit. Modifies the original state bit logic accordingly. The map is open if $11f6 bit 0 is low and closed
; if bit 0 is high. However, the state logic here is inversed because the game inverses the currently
; reported state after this subroutine. This routine is called during mini-map toggle ON and OFF.
sep #$30 ; set 8-bit a,x,y mode.
lda $11f6 ; load state byte that contains map state bit.
ldx $15ff ; load current ex-map state (reserved stack space).
inx ; inc ex-map state.
cpx #$05 ; check if above max ex-map state.
bne +
; Roll around exmap-state (Disable map).
and #$fe ; report map as currently enabled.
ldx #$00 ; load 0 for ex-map state.
bra ++
+:
; Enable map.
ora #$01 ; Report map as currently disabled.
++:
sta $11f6 ; Store inverted map state bit.
stx $15ff ; Store ex-map state (reserved stack space).
rep #$20 ; clear 8-bit a,x,y mode.
bit #$0001 ; Check map state (for jump that follows this).
rtl
}
mmap_apply_cfg:
{
; Implements logic for loading the initial top-left location of the mini-map. The upper bit of the
; accumulator is set to 1 if the map begins outside of the 0-255 coordinate area (i.e. is negative).
; This will not be called if the ex-map state is 0 so it is not handled here. This routine is called
; only during mini-map toggle ON.
xba ; swap upper and lower byte so we can set the upper byte.
lda $15ff ; load the current ex-map state.
; State 1 - Mid-right.
cmp #$01 : bne + ; Check if state is 1.
lda #$00 ; high byte address of x coord (positive region).
ldy #$f0 : bra ++ ; Start map at x = 240
+:
; State 2 - Far-right.
cmp #$02 : bne + ; Check if state is 2.
lda #$01 ; high byte address of x coord (negative region).
ldy #$00 : bra ++ ; start map at x = -256
+:
; State 3 - Mid-left.
cmp #$03 : bne + ; Check if state is 3.
lda #$01 ; high byte address of x coord (negative region).
ldy #$d0 : bra ++ ; start map at x = -48
+:
; State 4 - Far-left.
cmp #$04 : bne ++ ; Check if state is 4.
lda #$01 ; high byte address of x coord (negative region).
ldy #$c0 ; start map at x = -64
++:
ldx #$00 ; Original instruction.
xba ; Swap high byte back to high location.
rtl
}
mmap_set_map_loc:
{
; Implements logic for incrementing the mini-map sprite coordinates. This extends the original logic
; to handle overflow (locations outside of 0-255) and sets the OAM2 table accordingly. Each call
; to this routine handles a column (4 sprites) of the map beginning from the left and increments
; the x-coordinate by 16. This routine is called only during mini-map toggle ON.
pha ; Push x-address value.
phx ; Push sprite index.
txa ; Transfer sprite index to x->a.
lsr #2 ; Normalize to get OAM bit to modify.
tax ; transfer OAM BIT to modify a->x.
bank noassume
lda oam2_bit_vals, x ; load bitwise value using current bit as an offset.
bank auto
; Check if in positive range or not and set/clear the 9th bit accordingly.
xba ; exchange high byte to see if in negative range.
cmp #$01
bne + ; branch if positive range (0x0).
; Negative range (-1 to -256):
xba ; store OAM2 bit to set/clear in x->a(set).
ora $6d31 ; OR with current value in OAM2 to set bit.
bra ++ ; Branch to store-back.
+:
; positive range (0 to 255):
xba ; store OAM2 bit to set/clear in x->a (clear).
eor #$ff ; invert bits (all bits except the bit we want to clear should be set).
and $6d31 ; AND with current value in OAM2[1] to clear bit.
++:
; Store back - this works because these are where map columns are stored.
sta $6d31 ; store back in OAM2[1].
sta $6d32 ; store back in OAM2[2].
sta $6d33 ; store back in OAM2[3].
sta $6d34 ; store back in OAM2[4].
plx ; Pop sprite offset.
pla ; Pop x-address.
; Add offset for next column of mini-map.
rep #$20 ; Set 16-bit mode for a.
clc ; Clear-carry.
adc #$0010 ; Add while accounting for overflow.
sep #$20 ; Set 8-bit mode for a.
; Do original logic.
tay ; Original code.
txa ; Original code.
clc ; Original code.
adc #$04 ; Original code.
rtl ; Original code.
}
mmap_set_marker_loc:
{
; Implements logic for offsetting the mini-map marker's x-coordinate depending on the current ex-map
; state. Internally, it also adjusts the OAM2 table for the marker when outside of the 0-255 coordinate
; region. This routine is called every frame.
sep #$10 ; set 8-bit x,y mode.
ldx $15ff ; load current ex-map state.
; State 1 - Mid-right.
cpx #$01 : bne + ; Check if state is 1.
sec : sbc #$0010 ; Orient marker.
bra ++
+:
; State 2 - Far-right.
cpx #$02 : bne + ; Check if state is 2.
bra ++ ; No need to orient marker.
+:
; State 3 - Mid-left.
cpx #$03 : bne + ; Check if state is 3.
clc : adc #$00d0 ; orient marker.
bra ++
+:
; State 4 - Far-left.
cpx #$04 : bne ++ ; Check if state is 4.
clc : adc #$00c0 ; orient marker.
++:
sep #$20 ; set 8-bit a mode.
pha ; push x-coordinate (can't transfer or it affects the negative flag).
bmi + ; Check if in negative range.
; Negative range (-1 to -256):
lda #$01 ; Load bit to set.
ora $6d30 ; OR with current value in OAM2 to set bit.
bra ++
+
; positive range (0 to 255):
lda #$fe ; Load bit to unset.
and $6d30 ; AND with current value in OAM2 to clear bit.
++
sta $6d30 ; store back in OAM2.
pla ; pop x-coordinate.
rep #$30 ; set 16-bit a,x,y mode.
rtl
}
pushpc
{
%jsl_nop2($ee202f, mmap_set_cfg) ; Cycles ex-map states.
%jsl($ee4153, mmap_apply_cfg) ; Loads initial mini-map offset based on current ex-map state.
%jsl_nop2($ee4164, mmap_set_map_loc) ; Sets map sprite x-address and OAM2 table entries.
%jsl($ee41c7, mmap_set_marker_loc) ; Sets marker x-address and OAM2 table entry.
}
pullpc
;===================================================================
; Section:
; @ BG Buffer Size
;
; Description:
; Buffer size modifications.
;
; - Increase buffer size.
; - Keep BG in 512x256 mode during full screen buffer updates.
; - Remove pixel masks for screen edges.
;
pushpc
{
; Modify buffers to be 512x256.
%lda($c005b7, #$49) ; BG1 - main
%lda($c03f1f, #$49) ; BG1 - main
%lda($c005bc, #$51) ; BG2 - main
%lda($c03f2d, #$51) ; BG2 - main
%lda($c005c1, #$59) ; BG3 - main
%lda($c03f49, #$59) ; BG3 - main
;%lda($c03f17, #$41) ; BG1 - msgbox
;%lda($c03f3b, #$45) ; BG2 - text
; Keep register size at 512x256 during disabled buffer swap by flipping the first bit high.
; Disable store back of "new" buffer address to a memory location used for address computations.
%eor_nop3($c03f63) ; BG1
%eor_nop3($c03f83) ; BG2
%eor_nop3($c03fa3) ; BG3
; Remove pixel masking along edges.
%lda($c005e7, #$00) ; left coordinate: town/dungeon.
%lda($c005ec, #$ff) ; right coordinate: town/dungeon.
%lda($ee9003, #$00) ; left coordinate: overworld.
%lda($ee9008, #$ff) ; right coordinate: overworld.
;%lda($d4cdc6, #$00) ; left coordinate: load menu.
;%lda($d4cdce, #$ff) ; right coordinate: load menu.
}
pullpc
;===================================================================
; Section:
; @ BG Scroll Registers
;
; Description:
; Scrolling modifications.
;
; - Remove 8-pixel shift on sprites.
; - Remove 8-pixel shift of scroll registers.
; - Start x-scrolling when character is 13 columns into the map.
; - Stop x-scrolling when character is 13 from the end of the map.
; - Change x-camera start to +16*4 coordinates.
;
pushpc
{
; Remove 8 pixel shift to left for x-scroll registers.
%nop4($c042e1) ; BG1
%nop4($c042ba) ; BG2
%nop4($c04317) ; BG2
%nop4($c0434d) ; BG3
; Changes tilemap x-scrolling to begin at 13 tiles in instead of 8.
org $c07e32 ; BG1, BG2, BG3
nop
cmp #$0c ; Switch comparison to 13.
; Changes tilemap x-scrolling to end 5 tiles sooner.
org $c017a3
sbc #$0c
; Change pivot on load
%lda($c0179a, #$0c)
}
pullpc
;===================================================================
; Section:
; @ BG Full Updates
;
; Description:
; Full buffer update modifications. Only used when needing to update
; on-screen elements in an existing buffer?
;
; - Disable buffer swapping during full screen buffer updates.
; - Modify tile data loaded for wrap around areas.
; - Modify DMA location depending on where character is located on the screen.
;
; FF6 uses a back-buffers normally for full-screen updates, but there isn't
; enough BRAM to house 512x256 front and back buffers without snes VRAM
; expansion (128KB). It is not-clear whether the back buffers are necessary.
;
; BG1 buffers: 0x4800 or 0x4c00 - swapped on opening doors and chests.
; BG2 buffers: 0x5000 or 0x5400 - swapped in cave?
; BG3 buffers: 0x5800 or 0x5c00 - swapped sometime?
;
; Entering an area resets buffer pointers to the first location.
;
macro full_tile_pivot_algo(addr)
; Modifies the pivot location. Zeros out if underflow due to the pivot being in the
; right half of the buffer so the first half just updates starting at 0x0. Computes
; a normalization factor to figure out when wrap-around occurs during tile buffering
; I.e. when shifting from the right side of the buffer back to the left side.
sbc #$0b ; -11 instead of -7.
bpl + ; Check for underflow (below 0)
lda #$00 ; Set to zero if underflow.
+:
and <addr> ; Original instruction.
tax
rep #$20 ; e220 ; set 16-bit accum mode.
and #$ffe0 ; clamp low-bits of tile start index (every 32).
sta $3f7ffe ; store wrap-around normalization factor.
sep #$20 ; e220 ; set 8-bit accum mode.
txa
rtl
endmacro
macro full_tile_pivot(loc, piv)
pushpc
{
org <loc>
jsl + ; Modify pivot.
skip +$07
nop #2 ; clobbers an eor #$04 buffer addr update.
skip +$09
and #$5f ; corrects dest start location.
}
pullpc
+: %full_tile_pivot_algo(<piv>)
endmacro
macro full_tile_ld_algo(src, dest)
; Buffers tiles for an entire 512x256 BG on a per tile basis. This
; is modified logic to account for storing data to two non-contigious
; buffers in VRAM (thanks SNES VRAM address space).
lda ($2a) ; load tile value.
rep #$20 ; clear 8-bit accum mode.
tyx ; transfer dest offset to x.
phx ; push dest offset.
asl ; compute y offset.
tay ; transfer src offset to y.
pha ; push tile index.
txa ; transfer dest offset to a.
bit #$0040 ; check if in left or right buffer (>#$64 offset).
beq + ; branch if in left buffer.
; Right buffer - shift offset.
clc ; in second buffer.
adc #$07c0 ; shift offset to second buffer.
tax ; transfer updated offset to x.
+: ; left buffer - no shift.
; Check wrap-around.
lda $2a ; load tile addr index.
sec ; set carry.
sbc $3f7ffe ; subtract pre-computed wrap-around normalization factor.
and #$0020 ; check if in wrap-around area.
beq + ; branch if NOT in wrap-around coord area.
txa ; transfer dest addr to accum.
sec ; set carry.
sbc #$0080 ; subtract 64 to shift dest up a row for wrap-around tiles.
tax ; transfer updated offset to x.
+:
; Store 16x16 tile values to buffer.
pla ; Pop tile value.
lda <src>, y
sta <dest>, x
lda <src>+512, y
sta <dest>+2, x
lda <src>+1024, y
sta <dest>+64, x
lda <src>+1536, y
sta <dest>+66, x
clc ; clear-carry otherwise math fails after return.
plx ; restore dest addr (before we modded it).
txa ; transfer dest addr to accum.
rtl ; return.
endmacro
macro full_tile_ld(loc, piv, src, dest)
; Row DMA for second half of BG buffers.
%full_tile_pivot(<loc>, <piv>)
pushpc
org <loc>+$16
and #$5f ; corrects dest start location.
skip +$1d
lda #$20 ; Double the amount of columns looped.
skip +$08
jsl ++ ; Modify column load locations.
bra +$1a ; Jump past old leftover load/store tile logic.
skip +$1d
nop #3 ; Remove destination clipping.
pullpc
++: %full_tile_ld_algo(<src>, <dest>)
endmacro
; BG1 full tile load mods.
%full_tile_ld($c01f2c, $86, $c000, $3d6000)
; BG2 full tile load mods.
%full_tile_ld($c01fe9, $88, $c800, $3d7000)
; BG3 full tile load mods (mostly uses the row update code).
%full_tile_pivot($c020a6, $8a)
;----
macro dma_cpy(src, dest, off)
; DMA for second half of BG buffers.
lda #$01 ; 1 -> a.
sta $420b ; Initiate DMA transfer.
stz $420b ; Clear DMA transfer flag.
stx $4305 ; set amount of bytes to transfer.
ldx <src> ; load second half of tile buffer.
stx $4302 ; set DMA src addr.
rep #$20 ; clear 8-bit accum mode.
lda <dest> ; load dest addr.
clc ; clear carry.
adc <off> ; add 0x400 (offset to 2nd half of buf).
sta $2116 ; set DMA dest addr.
lda #$0001 ; 1 -> a.
sep #$20 ; set 8-bit accum mode.
sta $420b ; Initiate DMA transfer.
rtl ; return.
endmacro
macro full_dma_cpy(loc, src, dest, bank)
; Row DMA for second half of BG buffers.
pushpc
org <loc>
ldx <src> ; Change src addr for DMA to new top buffer.
skip +$03
lda <bank> ; Change bank addr for DMA to new top buffer.
skip +$0c
jsl + ; Call a second DMA operation for top buf (right half).
nop
skip +$22
ldx <src>+$400 ; Change src addr for DMA to new bottom buffer.
skip +$03
lda <bank> ; Change bank addr for DMA to new bottom buffer.
skip +$0c
jsl ++ ; Call a second DMA operation for bottom buf (right half).
nop
pullpc
+: %dma_cpy(<src>+$800, <dest>, #$400)
++: %dma_cpy(<src>+$c00, <dest>, #$600)
endmacro
; BG1 DMA copy (not inline - requires a jump).
%full_dma_cpy($c01d0a, #$6000, $91, #$3d)
; BG2 DMA copy (not inline - requires a jump).
%full_dma_cpy($c01d76, #$7000, $97, #$3d)
; BG3 DMA copy (not inline - requires a jump).
%full_dma_cpy($c01de2, #$d9c0, $9d, #$7f)
;===================================================================
; Section:
; @ BG Y Movement Updates
;
; Description:
; Contains Row/Vertical/Y movement modifications (also used when entering new areas).
;
; - Change buffer locations to allow enough room for full copies.
; - Preload additional row tile data into spots of RAM located
; contigously below the originally loaded data.
; - Insert an additional DMA for writing second half of TileMaps to VRAM.
; - Adjust code where necessary for clamping and doubling interations.
; - Optimize tile loading algorithms to fit inline (no need for jmps).
; - DMA requires external subroutines (jmps required).
;
macro row_tile_ld_bg12(src, dest)
; Row load algorithm that adds support for buffering
; 64x2, 8 by 8 sized tiles for BG1 & BG2. Of note,
; this essentially adds 64 to the dest offset if the
; dest offset >= 0x40. This is due to the fact that
; the left and right sides of a 512x512 vram buffers
; do not have a contiguous address space on the snes.
; Additionally, this also utilizes 16-bit x&y mode to
; the remove unnecessary branching. It has been
; optimized to fit within the original algorithms
; size constraints so no jumps are necessary.
sbc #$0b ; pivot of -11 instead of -7.
skip +$06
and #$1f ; Clip store offset high bit for BG1, BG2, & BG3 buffers.
skip +$05
lda #$20 ; Double loop iterations for copying data to BG1, BG2, & BG3 internal buffers (Non-vram).
skip +$08
phy ; push original dest.
tyx ; transfer dest to y->x (so we can reorder y and x for long stas).
tay ; transfer src offset a->y.
txa ; transfer dest offset x -> a.
; Address shift check for right buffer.
cmp #$40 ; compare dest to 0x40.
bcc + ; jump if less than 0x40.
clc ; clear carry.
adc #$40 ; add 0x40 to shift to right buffer.
+
tax ; a -> x.
tya ; pop src offset.
rep #$30 ; set 16-bit accum mode.
asl ; lshift src offset (16-bit shift).
tay ; move src offset to x.
; Load / Store tile.
lda <src>, y
sta <dest>, x
lda <src>+512, y
sta <dest>+2, x
lda <src>+1024, y
sta <dest>+64, x
lda <src>+1536, y
sta <dest>+66, x
sep #$10 ; set x&y to 8-bit mode.
ply ; pop original dest.
bra +$1e
skip +$24
and #$7f ; Clip high bit for roll around of BG1, BG2 buffers addresses.
endmacro
row_tile_ld_bg3_shf:
; BG3 row load helper subroutine that contains the logic
; for shifting the buffer location to the right buffer
; and computing wrap around for full-loads. Necessary,
; This is necessary because full loads use the row logic
; for BG3. The original code worked without branching
; because the buffer was contiguous so bitwise operations
; worked.
pha ; Optimized from 2 byte instruction (sta).
and #$003f ; Original instruction.