-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbattle_hacks.asm
4663 lines (3859 loc) · 137 KB
/
battle_hacks.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
battle_hacks:
//===========================================================================================
// Modifies the GetAddressofGlyphBitmap for mostly battle text stuff. The main reason for
// having this hack is that the routine uses it to load both 16x16 and 8x8 fonts, depending
// on inputs. But because of changes to our 16x16 stuff, the original code wouldn't work for
// both font sets. So we're gonna do a cheap fix for it. Basically, if it's gonna load a
// 16x16 font, we do new code, otherwise we jump to a carbon copy of the original routine's
// code.
//===========================================================================================
.get_glyph_address:
push {lr}
cmp r2,#0x08 // if r2 == 8, load the 8x8 font instead
beq +
mov r0,#0x20 // if we're running this code, we're loading 16x16 stuff
add r1,r5,#0
mov r1,r5
mul r1,r0
ldr r0,[r4,#0x04]
add r0,r0,r1
pop {pc} // return
+
asr r0,r0,#3 // if we're running this code, we're loading 8x8 stuff
add r0,#1
mul r0,r2
add r0,#2
mov r1,r5
mul r1,r0
ldr r0,[r4,#0x04]
add r0,r0,r1
add r0,#2
pop {pc} // return
//===========================================================================================
// this routine determines the number of tiles to be cleared when text in battle menus needs
// to be deleted. Normally, it assumes the # of tiles to be deleted = the # of letters in
// the current string. But with our VWF, this is no longer a valid assumption.
//
// The battle menu VWF has been modified so that the total VWF width of the current string
// can be found at the byte 0x2014300.
//
// We'll use this value, divide it by 10 (10 pixels wide per tile) and then round up. This
// will give us the total # of tiles to be cleared away.
//
// This final value needs to be in r0 when the routine ends. This value is stored by the
// game at the instruction at 806EBBE,
//===========================================================================================
.get_number_of_tiles_to_clear:
push {lr}
ldr r1,=#0x2014300 // get the total width of the current string, stored here previously
ldrb r0,[r1,#0] // r0 now has the width of the string
mov r1,#10
swi #6 // now divide the total width by 10
cmp r1,#0 // r1 has the remainder, if it's non-zero,
beq + // then we need to include the partial tile too
add r0,r0,#0x01 // this includes the partial tile
+
cmp r0,#0x16 // 0x16 is the highest possible, any higher and other stuff gets erased
bls +
mov r0,#0x16
+
pop {pc} // end of routine! r0 now has the correct # of tiles to erase
//===========================================================================================
// Replaces the printing routine for mostly battle text stuff.
// In r8 we have the Y. We need to print 0xB rows of our characters (apparently).
// In r3 we have the current VRAM base address.
// In r6 we have the current colour.
// In SP,#0x10 + (current_stack_size) we have the glyph.
// In SP,#0x3C + (current_stack_size) we have the current letter.
// In SP,#0x0C + (current_stack_size) we have the info for our X and our Y.
//===========================================================================================
.fast_printing:
push {lr}
add sp,#-8
ldr r0,[sp,#0x24]
ldr r1,[sp,#0x14]
bl $8088E58 // clobbered code
mov r2,r6
mov r6,r8
mov r0,#7
and r6,r0 // get the initial row # in the tiles
ldr r7,[sp,#0x18]
mov r1,#0
ldsh r7,[r7,r1] // get the X
cmp r7,#0
bge +
add r7,#7
+
and r7,r0 // get the subtile X
mov r9,r3
ldr r0,=#{main_font_width}
ldr r1,[sp,#0x48]
lsl r1,r1,#0x10
lsr r1,r1,#0x10
ldr r3,=#0xFF22
ldrb r0,[r0,r1] // get the letter's width
add r0,r0,#7
lsr r0,r0,#3 // get the number of tiles to print
cmp r3,r1 // is this the E symbol?
bne +
mov r0,#1 // the E symbol is only 1 tile wide
+
cmp r0,#2
blt +
mov r0,#2 // limit the number of tiles
+
mov r10,r0
mov r4,#0xFF
lsr r4,r7 // get the valid left-tile positions
lsl r4,r4,#0x18
lsr r5,r4,#8
orr r4,r5
lsr r5,r4,#0x10
orr r4,r5
mvn r5,r4 // get the inverted version
str r4,[sp,#0] // save our masks
str r5,[sp,#4]
lsl r5,r2,#0x1C
lsr r5,r5,#0x1C // get the colour
lsl r5,r5,#0x10
lsr r5,r5,#0x6
ldr r0,=#0x8CDF9F8 // get the 1bpp > 4bpp conversion table
add r5,r5,r0
-
ldr r2,[sp,#0x1C] // load the current glyph
ldr r2,[r2,#0] // load the first 4 rows
mov r3,r2
lsr r2,r7 // shift them by curr_x
mov r0,#8
sub r0,r7,r0
neg r0,r0
lsl r3,r0
ldr r4,[sp,#0]
and r2,r4 // left side
ldr r4,[sp,#4]
and r3,r4 // right side
lsl r0,r6,#2
mov r4,r9
add r4,r4,r0 // get the current position
// ONE - LEFT
lsl r0,r2,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// ONE - RIGHT
lsl r0,r3,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// TWO - LEFT
lsl r0,r2,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// TWO - RIGHT
lsl r0,r3,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// THREE - LEFT
lsl r0,r2,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// THREE - RIGHT
lsl r0,r3,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// FOUR - LEFT
lsr r0,r2,#0x18 // Get only one byte
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// FOUR - RIGHT
lsr r0,r3,#0x18 // Get only one byte
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
ldr r2,[sp,#0x1C] // load the current glyph
ldr r2,[r2,#4] // load the second 4 rows
mov r3,r2
lsr r2,r7 // shift them by curr_x
mov r0,#8
sub r0,r7,r0
neg r0,r0
lsl r3,r0
ldr r4,[sp,#0]
and r2,r4 // left side
ldr r4,[sp,#4]
and r3,r4 // right side
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// FIVE - LEFT
lsl r0,r2,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// FIVE - RIGHT
lsl r0,r3,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// SIX - LEFT
lsl r0,r2,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// SIX - RIGHT
lsl r0,r3,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// SEVEN - LEFT
lsl r0,r2,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// SEVEN - RIGHT
lsl r0,r3,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// EIGHT - LEFT
lsr r0,r2,#0x18 // Get only one byte
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// EIGHT - RIGHT
lsr r0,r3,#0x18 // Get only one byte
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
ldr r2,[sp,#0x1C] // load the current glyph
ldr r2,[r2,#0x10] // load the third 4 rows
mov r3,r2
lsr r2,r7 // shift them by curr_x
mov r0,#8
sub r0,r7,r0
neg r0,r0
lsl r3,r0
ldr r4,[sp,#0]
and r2,r4 // left side
ldr r4,[sp,#4]
and r3,r4 // right side
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// NINE - LEFT
lsl r0,r2,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// NINE - RIGHT
lsl r0,r3,#0x18 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// TEN - LEFT
lsl r0,r2,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// TEN - RIGHT
lsl r0,r3,#0x10 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
add r6,#1
mov r1,#7
and r1,r6
lsl r1,r1,#2 // get the subtile part
lsr r0,r6,#3 // get the Y part
lsl r0,r0,#0xA
mov r4,r9 // add it all together
add r4,r4,r0
add r4,r4,r1
// ELEVEN - LEFT
lsl r0,r2,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
ldr r1,[r4,#0] // load what's in the current row
orr r1,r0 // OR them together
str r1,[r4,#0] // and now store it back
// ELEVEN - RIGHT
lsl r0,r3,#0x8 // Get only one byte
lsr r0,r0,#0x18
lsl r0,r0,#2 // now multiply by four
ldr r0,[r5,r0] // r0 now has the converted 4bpp version
str r0,[r4,#0x20] // now store it
mov r0,r10
sub r0,#1
cmp r0,#0
ble +
mov r10,r0 // increase the counter
ldr r0,[sp,#0x1C]
add r0,#8 // increase the glyph's address
str r0,[sp,#0x1C]
sub r6,#0xA // get r6 back to its initial value
mov r3,r9
add r3,#0x20 // go one tile to the right
mov r9,r3
b -
+
add sp,#8
pop {pc} // return
//===========================================================================================
// this centers various text that appears in the sound player and also does the custom
// control code text parsing for battle text. What a weird combination!
//
// r1 has the address of the current string
// we'll also need to re-perform some code that we clobbered
//
// Link to this from 8088E00.
//===========================================================================================
.prepare_custom_cc:
// Time to do some shuffling. This will get lr back with it's original value
push {r5,lr} // We're going to use r5, so we need to keep it in
ldr r5,[sp,#0x08] // Load r5 with our former LR value?
mov r14,r5 // Move the former LR value back into LR
ldr r5,[sp,#0x04] // Grab the LR value for THIS function
str r5,[sp,#0x08] // Store it over the previous one
pop {r5} // Get back r5
add sp,#0x04 // Get the un-needed value off the stack
push {r0-r3,r6}
//-------------------------------------------------------------------------------------------
ldr r6,=#{main_font_width} // r2 contains 08D1CE78, the width table's address
mov r0,#0x0 // initialize the total width counter
ldr r3,=#0xFEFF // r3 has the [END] code
//-------------------------------------------------------------------------------------------
-
ldrh r2,[r1,#0] // load the current character
cmp r2,r3 // check for [END]
bgt + // if encountered, exit the subroutine
add r2,r6,r2 // get address of current character's width
ldrb r2,[r2,#0] // load current char's width
add r0,r0,r2 // add current width to the total
add r1,r1,#0x02 // move to next character
b - // do the loop over again
//-------------------------------------------------------------------------------------------
+
ldr r6,=#0x2014300 // we're gonna store the final width here temporarily
strh r0,[r6,#0]
pop {r0-r3,r6} // restore registers now that we've done our stuff
ldrh r2,[r2,#0x2] // original code we overwrote
lsl r2,r2,#1 // multiply the pointer/offset by two
sub r2,r2,r0
lsr r2,r2,#0x1
sub r2,#1
//==================================================================================
// it turns out r2 above calculates the length of the string, and this is used
// to allocate the correct amount of RAM to copy the string to. We need to modify
// this to take our custom battle control codes into account, so this hack has
// turned from mainly a sound player text centering hack to a string count hack.
//
// r2 now has the normal string length, we need to compensate for EF codes now.
//
// r1 has the string address at this point
//==================================================================================
push {r0}
push {r1}
push {r3}
push {r4}
ldr r3,=#0xFFFF // load r3 with the [END] code
//--------------------------------------------------------------------------------------------
-
ldrb r0,[r1,#1] // load the high byte of the current character
cmp r0,#0xEF // see if this is a custom control code
beq .custom_cc // if so, jump to our special code to calculate its length unpacked
ldrh r0,[r1,#0] // otherwise, load the current character
cmp r0,r3 // check if it's an [END] code
beq + // if it is, then jump to the end of the routine
mov r0,#0 // this was a non-custom CC, so we're not gonna increment the count
.main_loop_next:
add r2,r2,r0 // increment the letter count
add r1,#2 // increment the read count
b - // do another loop iteration
//--------------------------------------------------------------------------------------------
+
pop {r4}
pop {r3}
pop {r1}
pop {r0}
pop {pc}
//--------------------------------------------------------------------------------------------
.custom_cc:
sub r2,#1 // need to subtract 1 to counter the raw custom control code itself
ldrb r4,[r1,#0] // load the current low byte of the custom control code
mov r0,#0x1F
and r0,r4 // Load the first 5 bits of the custom codes
cmp r0,#0x00 // check for 0xEF00, which will print the current enemy's name
bne +
b .cc_enemy_name
+
cmp r4,#0x21 // check for 0xEF21, which will print the pigmask's article
bne +
b .cc_en_articles
+
cmp r0,#0x01 // check for 0xEF01, which will print the cohorts string
bne +
b .cc_cohorts
+
cmp r0,#0x02 // check for 0xEF02, which will print an initial uppercase article if need be
bne +
b .cc_en_articles
+
cmp r0,#0x03 // check for 0xEF03, which will print an initial lowercase article if need be
bne +
b .cc_en_articles
+
cmp r0,#0x04 // check for 0xEF04, which will print an uppercase article if need be
bne +
b .cc_en_articles
+
cmp r0,#0x05 // check for 0xEF05, which will print a lowercase article if need be
bne +
b .cc_en_articles
+
cmp r0,#0x06 // check for 0xEF06, which will print a lowercase possessive if need be
bne +
b .cc_en_articles
+
cmp r0,#0x10 // check for 0xEF10, which will print an initial uppercase article for items
bne +
b .cc_it_articles
+
cmp r0,#0x11 // check for 0xEF11, which will print an initial lowercase article for items
bne +
b .cc_it_articles
+
cmp r0,#0x12 // check for 0xEF12, which will print an uppercase article for items
bne +
b .cc_it_articles
+
cmp r0,#0x13 // check for 0xEF13, which will print a lowercase article for items
bne +
b .cc_it_articles
+
cmp r0,#0x16 // check for 0xEF16, which will print a lowercase pronoun for items
bne +
b .cc_it_articles
+
cmp r0,#0x17 // check for 0xEF17, which will print a lowercase past-tense verb for items
bne +
b .cc_it_articles
+
mov r0,#0 // if this executes, it's an unknown control code, so treat it normally
b .main_loop_next // jump back to the part of the main loop that increments and such
//--------------------------------------------------------------------------------------------
.cc_it_articles:
push {r1-r2}
sub r0,#0x10
mov r2,r0 // r2 will be an offset into the extra item data slot
ldr r0,=#0x2014324 // this is where the current item # will be saved by another hack
cmp r4,#0x20 // check if this is EF 30 or more
blt +
ldr r0,=#0x2014724 // then load the second last item for the extra data, this location is used by another hack to save the second last item's id
+
ldrh r0,[r0,#0] // load the current item #
lsl r0,r0,#3 // offset = item ID * 8 bytes
ldr r1,=#{item_extras_address} // this is the base address of our extra item data table in ROM
add r0,r0,r1 // r0 now has the proper address of the current item's data slot
ldrb r0,[r0,r2] // load the proper line # to use from custom_text.bin
mov r1,#40
mul r0,r1 // calculate the offset into custom_text.bin
ldr r1,=#{custom_text_address} // load r1 with the base address of our custom text array in ROM
add r0,r0,r1 // r0 now has the address of the string we want
pop {r1-r2}
bl custom_strlen // count the length of our special string, store its length in r2
b .main_loop_next // now jump back to the part of the main loop that increments and such
//--------------------------------------------------------------------------------------------
.cc_enemy_name:
push {r1-r2}
ldr r0,=#0x2014320 // this is where current_enemy_save.asm saves the current enemy's ID #
ldrh r0,[r0,#0] // load the current #
cmp r4,#0x20 // is this the pigmask code?
bne +
cmp r0,#6 // is the actor the Pork Tank?
bne +
mov r0,#149 // if it is, then change it to the Pigmask
+
ldr r2,=#0x149
cmp r0,r2 // If the actor id is > 0x149, it's going to be a character. Let's call them properly
blt +
ldr r1,=#0x2004110 // Character data address
sub r0,r0,r2 // Remove 0x149 to get their ID
mov r2,#0x6C
mul r0,r2 // Multiply it by 0x6C, each character's data length
add r0,#2 // Add 2 to get their name
add r0,r0,r1 // r0 now has the address of the character's name
pop {r1-r2}
bl custom_strlen_party // count the length of our special string, store its length in r2, this is special because party member can have non 0xFFFF terminated names
b .end_cc_enemy_name
+
mov r1,#50
mul r0,r1 // offset = enemy ID * 50 bytes
ldr r1,=#{enemynames_address}+4 // this is the base address of the enemy name array in ROM
add r0,r0,r1 // r0 now has the address of the enemy's name
pop {r1-r2}
.count_and_inc:
bl custom_strlen // count the length of our special string, store its length in r2
.end_cc_enemy_name:
b .main_loop_next // now jump back to the part of the main loop that increments and such
//--------------------------------------------------------------------------------------------
.cc_cohorts:
push {r1-r3}
mov r3,#0 // r3 will be our total # of bytes changed
ldr r0,=#0x2014322 // load the # of enemies
ldrb r0,[r0,#0]
cmp r0,#1
beq .cc_cohorts_end // don't print anything if there's only one enemy
mov r0,#3
mov r2,#40
mul r0,r2
ldr r2,=#{custom_text_address}
add r0,r0,r2 // r0 now has " and "
bl custom_strlen // count the length of our special string, store its length in r2
add r3,r3,r0
ldr r0,=#0x2014320 // load our current enemy #
ldrb r0,[r0,#0]
mov r2,#5
mul r0,r2
ldr r2,=#{enemy_extras_address}
add r0,r0,r2
ldrb r0,[r0,#0x4] // load the line # for this enemy's possessive pronoun
mov r2,#40
mul r0,r2
ldr r2,=#{custom_text_address}
add r0,r0,r2 // r0 now has the address to the appropriate possessive pronoun string
bl custom_strlen // count the length of our special string, store its length in r2
add r3,r3,r0
ldr r0,=#0x2014322 // load the # of enemies
ldrb r0,[r0,#0]
sub r0,#1 // subtract one for ease of use
push {r1}
ldr r1,=#{custom_text_address} // load r1 with the base address of our custom text array in ROM
mov r2,#40
mul r0,r2
add r0,r0,r1 // r0 now has the address of the proper cohorts string
pop {r1} // restore r1 with the target address
bl custom_strlen // count the length of our special string, store its length in r2
add r3,r3,r0 // update special string length
.cc_cohorts_end:
mov r0,r3 // r0 now has the total # of bytes we added
pop {r1-r3}
b .main_loop_next // now jump back to the part of the main loop that increments and such
//--------------------------------------------------------------------------------------------
.cc_en_articles:
push {r1-r2}
sub r2,r0,#2 // r2 will be an offset into the extra enemy data slot
// this is a quicker method of doing a bunch of related codes at once
// we take the low byte of the current CC and subtract 2, and that'll
// be our offset
sub r4,r4,#2
mov r1,r4
lsr r4,r4,#5
lsl r4,r4,#5
ldr r0,=#0x2014320 // this is where the routines save the other ID #
add r0,r0,r4
ldrh r0,[r0,#0] // load the current #
mov r4,r1
cmp r4,#0x1F // is this the pigmask's article code?
bne +
mov r2,#2 // Change the code so it makes sense
cmp r0,#6 // is the actor the Pork Tank?
bne +
mov r0,#149 // if it is, then change it to the Pigmask
+
mov r1,r0
lsl r0,r0,#2
add r0,r0,r1 // offset = enemy ID * 5 bytes
ldr r1,=#{enemy_extras_address} // this is the base address of our extra enemy data table in ROM
add r0,r0,r1 // r0 now has address of this enemy's extra data entry
ldrb r0,[r0,r2] // r0 now has the proper line # to use from custom_text.bin
mov r1,#40
mul r0,r1 // calculate the offset into custom_text.bin
ldr r1,=#{custom_text_address} // load r1 with the base address of our custom text array in ROM
add r0,r0,r1 // r0 now has the address of the string we want
pop {r1-r2}
bl custom_strlen // count the length of our special string, store its length in r2
b .main_loop_next // now jump back to the part of the main loop that increments and such
//===========================================================================================
// This code applies a VWF to battle menus and other stuff. It doesn't apply to battle text.
// It basically replaces these three lines of code:
//
// ldrh r1,[r6]
// add r0,r0,r1
// strh r0,[r6]
//
// At [r6] is the current X position the last character was drawn to.
// At [r6]-4 is the character we've just drawn.
// We need to blank out the 2nd half of r0, look up [r6]-4 in a table, add it's width to r0.
// Then do what the original code does.
//===========================================================================================
.menu_vwf:
push {r4,r7,lr}
mov r4,#0 // r4 will be 0 if 16x16 font, #0x100 if 8x8 font
ldr r7,=#0x2014300 // r7 will be our custom address in RAM to store the total width
cmp r5,#0 // if r5 is 0, we're starting on a new string
bne + // in which case, let's see set the curr total width to 0
mov r3,#0
strb r3,[r7,#0] // initialize the total width as 0
//-------------------------------------------------------------------------------------------
+
ldrb r3,[r7,#0] // load the current total width
lsr r1,r1,#0x10
cmp r1,#8
bne +
ldr r4,=#0x100 // set r4 to 0x100 so we'll load from the right width table later
//-------------------------------------------------------------------------------------------
+
push {r2,r5,r6}
ldrh r1,[r6,#0] // Load our old X position into r1
lsr r0,r0,#8
lsl r0,r0,#8 // Blank out the width of the current character
add r0,r0,r1 // Add the old X position to r0
sub r6,#4 // Move the pointer back some for now
ldr r5,[r6,#0] // Load r5 with our current character
ldr r6,=#{main_font_width} // r6 = address of 16x16 font width table
add r6,r6,r4 // add r4 to r6, it'll be 8D1CF78 if the 8x8 font is being used
ldr r4,=#0x1FF // see if the letter is in the normal text range
cmp r5,r4 // if it is, go and load the width from the width table
ble +
mov r5,#0 // otherwise, use the width of Character 0, which is 10
// this mainly applies to things like the (E) icon by equipment
//-------------------------------------------------------------------------------------------
+
ldrb r5,[r6,r5] // r5 = width of current letter
add r0,r0,r5 // add width to the X coordinate
add r3,r3,r5 // now add to the total width, r3 will have this after the hack too
strb r3,[r7,#0] // store the new total width back to our custom RAM spot
pop {r2,r5,r6} // restore the registers we used
pop {r4,r7,pc} // restore other registers and return
//===========================================================================================
//===========================================================================================
// This is the first part of a hack to make battle text work right.
//
// This routine should be linked to from 80840D2.
//
// This first part takes the place of the place in the game's code where it loads the current
// character right before doing control code checks. Later on in the code, the game will load
// the character again if it wasn't a control code. This later part will be handled by
// battle_vwf2.asm. We're doing things this way so that control codes like [WAIT] will work
// as intended.
//
// Basically, this part of the hack will prep a special block of RAM for battle_vwf2.asm
// and then perform the code we overwrote.
//===========================================================================================
//--------------------------------------------------------------------------------------------
//
// We're going to need to use a few bytes of RAM, starting from 0x2014300
//
// 2014300 byte DO NOT USE!
// 2014301 byte init_flag -- If this is 0, we know we need to initialize everything
// 2014302 hword current letter/character/control code
// 2014303 ...
// 2014304 word current x and y coordinates
// 2014305 ...
// 2014306 ...
// 2014307 ...
// 2014308 word base address of the current string
// 2014309 ...
// 201430A ...
// 201430B ...
// 201430C hword current position in the string
// 201430D ...
// 201430E hword total length of the current string
// 201430F ...
// 2014310 hword current line # we're on
// 2014311 ...
// 2014312 byte newline_encountered flag -- 0 if no, non-zero if yes
//
//--------------------------------------------------------------------------------------------
// Coming into this, the registers are as follows:
//
// r0 = current address (so when this is first called, it's the start of the string)
// r1 = current position in the current string
// r2 = ???
// r3 = ???
// r4 = ???
// r5 = ???
// r6 = ??? (seems to be pretty important though)
// r7 = current string/tile counter (this is the key to making our hack run long enough)
// r8 = not sure, but (r8 + 6) is where the total string length is stored
// r9 = ???
// r10 = ???
// r11 = ???
// r12 = ???
//===========================================================================================
// This is some routine initialization stuff
.main_vwf1:
push {r5,lr} // We're going to use r5, so we need to keep it in
ldr r5,[sp,#0x08] // Load r5 with our former LR value?
mov lr,r5 // Move the former LR value back into LR
ldr r5,[sp,#0x04] // Grab the LR value for THIS function
str r5,[sp,#0x08] // Store it over the previous one
pop {r5} // Get back r5
add sp,#0x04 // Get the un-needed value off the stack
//-----------------
push {r5,r7} // this is unrelated to this hack really
ldr r7,=#0x2014320 // it's used to clear the enemy value each line of text
mov r5,#0 // this is the easiest way to do it, so never mind this stuff
strh r5,[r7,#0] // clears current enemy value, sets to 0
pop {r5,r7}
//-----------------
lsl r1,r1,#1 // this is code we clobbered while linking here
ldr r0,[r0,#0]
add r0,r0,r1