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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
|
const_def
const BGSQUARE_SIX
const BGSQUARE_FOUR
const BGSQUARE_TWO
const BGSQUARE_SEVEN
const BGSQUARE_FIVE
const BGSQUARE_THREE
; BG effects for use in battle animations.
ExecuteBGEffects:
ld hl, wActiveBGEffects
ld e, NUM_BG_EFFECTS
.loop
ld a, [hl]
and a
jr z, .next
ld c, l
ld b, h
push hl
push de
call DoBattleBGEffectFunction
pop de
pop hl
.next
ld bc, BG_EFFECT_STRUCT_LENGTH
add hl, bc
dec e
jr nz, .loop
ret
QueueBGEffect:
ld hl, wActiveBGEffects
ld e, NUM_BG_EFFECTS
.loop
ld a, [hl]
and a
jr z, .load
ld bc, BG_EFFECT_STRUCT_LENGTH
add hl, bc
dec e
jr nz, .loop
scf
ret
.load
ld c, l
ld b, h
ld hl, BG_EFFECT_STRUCT_FUNCTION
add hl, bc
ld a, [wBattleBGEffectTempID]
ld [hli], a
ld a, [wBattleBGEffectTempJumptableIndex]
ld [hli], a
ld a, [wBattleBGEffectTempTurn]
ld [hli], a
ld a, [wBattleBGEffectTempParam]
ld [hl], a
ret
EndBattleBGEffect:
ld hl, BG_EFFECT_STRUCT_FUNCTION
add hl, bc
ld [hl], 0
ret
DoBattleBGEffectFunction:
ld hl, BG_EFFECT_STRUCT_FUNCTION
add hl, bc
ld e, [hl]
ld d, 0
ld hl, BattleBGEffects
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
BattleBGEffects:
; entries correspond to ANIM_BG_* constants
dw BattleBGEffect_End
dw BattleBGEffect_FlashInverted
dw BattleBGEffect_FlashWhite
dw BattleBGEffect_WhiteHues
dw BattleBGEffect_BlackHues
dw BattleBGEffect_AlternateHues
dw BattleBGEffect_CycleOBPalsGrayAndYellow
dw BattleBGEffect_CycleMidOBPalsGrayAndYellow
dw BattleBGEffect_CycleBGPals_Inverted
dw BattleBGEffect_HideMon
dw BattleBGEffect_ShowMon
dw BattleBGEffect_EnterMon
dw BattleBGEffect_ReturnMon
dw BattleBGEffect_Surf
dw BattleBGEffect_Whirlpool
dw BattleBGEffect_Teleport
dw BattleBGEffect_NightShade
dw BattleBGEffect_BattlerObj_1Row
dw BattleBGEffect_BattlerObj_2Row
dw BattleBGEffect_DoubleTeam
dw BattleBGEffect_AcidArmor
dw BattleBGEffect_RapidFlash
dw BattleBGEffect_FadeMonToLight
dw BattleBGEffect_FadeMonToBlack
dw BattleBGEffect_FadeMonToLightRepeating
dw BattleBGEffect_FadeMonToBlackRepeating
dw BattleBGEffect_CycleMonLightDarkRepeating
dw BattleBGEffect_FlashMonRepeating
dw BattleBGEffect_FadeMonsToBlackRepeating
dw BattleBGEffect_FadeMonToWhiteWaitFadeBack
dw BattleBGEffect_FadeMonFromWhite
dw BattleBGEffect_ShakeScreenX
dw BattleBGEffect_ShakeScreenY
dw BattleBGEffect_Withdraw
dw BattleBGEffect_BounceDown
dw BattleBGEffect_Dig
dw BattleBGEffect_Tackle
dw BattleBGEffect_BodySlam
dw BattleBGEffect_WobbleMon
dw BattleBGEffect_RemoveMon
dw BattleBGEffect_WaveDeformMon
dw BattleBGEffect_Psychic
dw BattleBGEffect_BetaSendOutMon1
dw BattleBGEffect_BetaSendOutMon2
dw BattleBGEffect_Flail
dw BattleBGEffect_BetaPursuit
dw BattleBGEffect_Rollout
dw BattleBGEffect_VitalThrow
dw BattleBGEffect_StartWater
dw BattleBGEffect_Water
dw BattleBGEffect_EndWater
dw BattleBGEffect_VibrateMon
dw BattleBGEffect_WobblePlayer
dw BattleBGEffect_WobbleScreen
BattleBGEffect_End:
call EndBattleBGEffect
ret
BatttleBGEffects_GetNamedJumptablePointer:
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld l, [hl]
ld h, 0
add hl, hl
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ret
BattleBGEffects_AnonJumptable:
pop de
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld l, [hl]
ld h, 0
add hl, hl
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
BattleBGEffects_IncAnonJumptableIndex:
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
inc [hl]
ret
BattleBGEffect_FlashInverted:
ld de, .inverted
jp BattleBGEffect_FlashContinue
.inverted
dc 3, 2, 1, 0
dc 0, 1, 2, 3
BattleBGEffect_FlashWhite:
ld de, .white
jp BattleBGEffect_FlashContinue
.white
dc 3, 2, 1, 0
dc 0, 0, 0, 0
BattleBGEffect_FlashContinue:
; current timer, flash duration, number of flashes
ld a, $1
ld [wBattleBGEffectTempID], a ; unused?
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld a, [hl]
and a
jr z, .init
dec [hl]
ret
.init
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld [hl], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr nz, .apply_pal
call EndBattleBGEffect
ret
.apply_pal
dec a
ld [hl], a
and 1
ld l, a
ld h, 0
add hl, de
ld a, [hl]
ld [wBGP], a
ret
BattleBGEffect_WhiteHues:
ld de, .Pals
call BattleBGEffect_GetNthDMGPal
jr c, .quit
ld [wBGP], a
ret
.quit
call EndBattleBGEffect
ret
.Pals:
dc 3, 2, 1, 0
dc 3, 2, 0, 0
dc 3, 1, 0, 0
db -1
BattleBGEffect_BlackHues:
ld de, .Pals
call BattleBGEffect_GetNthDMGPal
jr c, .quit
ld [wBGP], a
ret
.quit
call EndBattleBGEffect
ret
.Pals:
dc 3, 2, 1, 0
dc 3, 3, 1, 0
dc 3, 3, 2, 0
db -1
BattleBGEffect_AlternateHues:
ld de, .Pals
call BattleBGEffect_GetNthDMGPal
jr c, .quit
ld [wBGP], a
ld [wOBP1], a
ret
.quit
call EndBattleBGEffect
ret
.Pals:
dc 3, 2, 1, 0
dc 3, 3, 2, 0
dc 3, 3, 3, 0
dc 3, 3, 2, 0
dc 3, 2, 1, 0
dc 2, 1, 0, 0
dc 1, 0, 0, 0
dc 2, 1, 0, 0
db -2
BattleBGEffect_CycleOBPalsGrayAndYellow:
call BattleBGEffects_CheckSGB
jr nz, .sgb
ld de, .PalsCGB
jr .okay
.sgb
ld de, .PalsSGB
.okay
call BattleBGEffect_GetNthDMGPal
ld [wOBP0], a
ret
.PalsCGB:
dc 3, 2, 1, 0
dc 2, 1, 0, 0
db -2
.PalsSGB:
dc 3, 3, 0, 0
dc 3, 0, 0, 0
db -2
BattleBGEffect_CycleMidOBPalsGrayAndYellow:
call BattleBGEffects_CheckSGB
jr nz, .sgb
ld de, .PalsCGB
jr .okay
.sgb
ld de, .PalsSGB
.okay
call BattleBGEffect_GetNthDMGPal
ld [wOBP0], a
ret
.PalsCGB:
dc 3, 2, 1, 0
dc 3, 1, 2, 0
db -2
.PalsSGB:
dc 3, 3, 0, 0
dc 3, 0, 3, 0
db -2
BattleBGEffect_CycleBGPals_Inverted:
ld de, .Pals
call BattleBGEffect_GetNthDMGPal
ld [wBGP], a
ret
.Pals:
dc 0, 1, 2, 3
dc 1, 2, 0, 3
dc 2, 0, 1, 3
db -2
BattleBGEffect_HideMon:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw .four
.zero
call BattleBGEffects_IncAnonJumptableIndex
push bc
call BGEffect_CheckBattleTurn
jr nz, .player_side
hlcoord 12, 0
lb bc, 7, 7
jr .got_pointer
.player_side
hlcoord 2, 6
lb bc, 6, 6
.got_pointer
call ClearBox
pop bc
xor a
ldh [hBGMapThird], a
ld a, $1
ldh [hBGMapMode], a
ret
.four
xor a
ldh [hBGMapMode], a
call EndBattleBGEffect
ret
BattleBGEffect_ShowMon:
call BGEffect_CheckFlyDigStatus
jr z, .not_flying
call EndBattleBGEffect
ret
.not_flying
call BGEffect_CheckBattleTurn
jr nz, .player_side
ld de, .EnemyData
jr .got_pointer
.player_side
ld de, .PlayerData
.got_pointer
ld a, e
ld [wBattlePicResizeTempPointer], a
ld a, d
ld [wBattlePicResizeTempPointer + 1], a
call BattleBGEffect_RunPicResizeScript
ret
.PlayerData:
db 0, $31, 0
db -1
.EnemyData:
db 3, $00, 3
db -1
BattleBGEffect_BattlerObj_1Row:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw .five
.zero
call BGEffect_CheckFlyDigStatus
jr z, .not_flying_digging
ld hl, wLastAnimObjectIndex
inc [hl]
call EndBattleBGEffect
ret
.not_flying_digging
call BattleBGEffects_IncAnonJumptableIndex
push bc
call BGEffect_CheckBattleTurn
jr nz, .player_side
ld a, ANIM_OBJ_ENEMYFEET_1ROW
ld [wBattleObjectTempID], a
ld a, 16 * TILE_WIDTH + 4
jr .okay
.player_side
ld a, ANIM_OBJ_PLAYERHEAD_1ROW
ld [wBattleObjectTempID], a
ld a, 6 * TILE_WIDTH
.okay
ld [wBattleObjectTempXCoord], a
ld a, 8 * TILE_WIDTH
ld [wBattleObjectTempYCoord], a
xor a
ld [wBattleObjectTempParam], a
call _QueueBattleAnimation
pop bc
ret
.one
call BattleBGEffects_IncAnonJumptableIndex
push bc
call BGEffect_CheckBattleTurn
jr nz, .player_side_2
hlcoord 12, 6
lb bc, 1, 7
jr .okay2
.player_side_2
hlcoord 2, 6
lb bc, 1, 6
.okay2
call ClearBox
ld a, $1
ldh [hBGMapMode], a
pop bc
ret
.five
xor a
ldh [hBGMapMode], a
call EndBattleBGEffect
ret
BattleBGEffect_BattlerObj_2Row:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw .five
.zero
call BGEffect_CheckFlyDigStatus
jr z, .not_flying_digging
ld hl, wLastAnimObjectIndex
inc [hl]
call EndBattleBGEffect
ret
.not_flying_digging
call BattleBGEffects_IncAnonJumptableIndex
push bc
call BGEffect_CheckBattleTurn
jr nz, .player_side
ld a, ANIM_OBJ_ENEMYFEET_2ROW
ld [wBattleObjectTempID], a
ld a, 16 * TILE_WIDTH + 4
jr .okay
.player_side
ld a, ANIM_OBJ_PLAYERHEAD_2ROW
ld [wBattleObjectTempID], a
ld a, 6 * TILE_WIDTH
.okay
ld [wBattleObjectTempXCoord], a
ld a, 8 * TILE_WIDTH
ld [wBattleObjectTempYCoord], a
xor a
ld [wBattleObjectTempParam], a
call _QueueBattleAnimation
pop bc
ret
.one
call BattleBGEffects_IncAnonJumptableIndex
push bc
call BGEffect_CheckBattleTurn
jr nz, .player_side_2
hlcoord 12, 5
lb bc, 2, 7
jr .okay2
.player_side_2
hlcoord 2, 6
lb bc, 2, 6
.okay2
call ClearBox
ld a, $1
ldh [hBGMapMode], a
pop bc
ret
.five
xor a
ldh [hBGMapMode], a
call EndBattleBGEffect
ret
_QueueBattleAnimation:
callfar QueueBattleAnimation
ret
BattleBGEffect_RemoveMon:
; Slides mon out of screen
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw .four
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BGEffect_CheckBattleTurn
ld [hl], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and a
jr z, .user
ld a, $9
jr .okay
.user
ld a, $8
.okay
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], a
ret
.one
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and a
jr z, .user_2
hlcoord 0, 6
lb de, 8, 6
.row1
push de
push hl
.col1
inc hl
ld a, [hld]
ld [hli], a
dec d
jr nz, .col1
pop hl
ld de, SCREEN_WIDTH
add hl, de
pop de
dec e
jr nz, .row1
jr .okay2
.user_2
hlcoord 19, 0
lb de, 8, 7
.row2
push de
push hl
.col2
dec hl
ld a, [hli]
ld [hld], a
dec d
jr nz, .col2
pop hl
ld de, SCREEN_WIDTH
add hl, de
pop de
dec e
jr nz, .row2
.okay2
xor a
ldh [hBGMapThird], a
ld a, $1
ldh [hBGMapMode], a
call BattleBGEffects_IncAnonJumptableIndex
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
dec [hl]
ret
.four
xor a
ldh [hBGMapMode], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr z, .done
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld [hl], $1
ret
.done
call EndBattleBGEffect
ret
BattleBGEffect_EnterMon:
call BGEffect_CheckBattleTurn
jr nz, .player_turn
ld de, .EnemyData
jr .okay
.player_turn
ld de, .PlayerData
.okay
ld a, e
ld [wBattlePicResizeTempPointer], a
ld a, d
ld [wBattlePicResizeTempPointer + 1], a
call BattleBGEffect_RunPicResizeScript
ret
.PlayerData:
db 2, $31, 2
db 1, $31, 1
db 0, $31, 0
db -1
.EnemyData:
db 5, $00, 5
db 4, $00, 4
db 3, $00, 3
db -1
BattleBGEffect_ReturnMon:
call BGEffect_CheckBattleTurn
jr nz, .player_turn
ld de, .EnemyData
jr .okay
.player_turn
ld de, .PlayerData
.okay
ld a, e
ld [wBattlePicResizeTempPointer], a
ld a, d
ld [wBattlePicResizeTempPointer + 1], a
call BattleBGEffect_RunPicResizeScript
ret
.PlayerData:
db 0, $31, 0
db -2, $66, 0
db 1, $31, 1
db -2, $44, 1
db 2, $31, 2
db -2, $22, 2
db -3, $00, 0
db -1
.EnemyData:
db 3, $00, 3
db -2, $77, 3
db 4, $00, 4
db -2, $55, 4
db 5, $00, 5
db -2, $33, 5
db -3, $00, 0
db -1
BattleBGEffect_RunPicResizeScript:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw BattleBGEffects_IncAnonJumptableIndex
dw BattleBGEffects_IncAnonJumptableIndex
dw .restart
dw .end
.zero
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld e, [hl]
ld d, $0
inc [hl]
ld a, [wBattlePicResizeTempPointer]
ld l, a
ld a, [wBattlePicResizeTempPointer + 1]
ld h, a
add hl, de
add hl, de
add hl, de
ld a, [hl]
cp -1
jr z, .end
cp -2
jr z, .clear
cp -3
jr z, .skip
call .PlaceGraphic
.skip
call BattleBGEffects_IncAnonJumptableIndex
ld a, $1
ldh [hBGMapMode], a
ret
.clear
call .ClearBox
jr .zero
.restart
xor a
ldh [hBGMapMode], a
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld [hl], $0
ret
.end
xor a
ldh [hBGMapMode], a
call EndBattleBGEffect
ret
.ClearBox:
; get dims
push bc
inc hl
ld a, [hli]
ld b, a
and $f
ld c, a
ld a, b
swap a
and $f
ld b, a
; get coords
ld e, [hl]
ld d, 0
ld hl, .Coords
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
call ClearBox
pop bc
ret
.PlaceGraphic:
; get dims
push bc
push hl
ld e, [hl]
ld d, 0
ld hl, .BGSquares
add hl, de
add hl, de
add hl, de
ld a, [hli]
ld b, a
and $f
ld c, a
ld a, b
swap a
and $f
ld b, a
; store pointer
ld e, [hl]
inc hl
ld d, [hl]
; get byte
pop hl
inc hl
ld a, [hli]
ld [wBattlePicResizeTempBaseTileID], a
; get coord
push de
ld e, [hl]
ld d, 0
ld hl, .Coords
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
pop de
; fill box
.row
push bc
push hl
ld a, [wBattlePicResizeTempBaseTileID]
ld b, a
.col
ld a, [de]
add b
ld [hli], a
inc de
dec c
jr nz, .col
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
pop bc
dec b
jr nz, .row
pop bc
ret
.Coords:
dwcoord 2, 6
dwcoord 3, 8
dwcoord 4, 10
dwcoord 12, 0
dwcoord 13, 2
dwcoord 14, 4
.BGSquares:
bgsquare: MACRO
dn \1, \2
dw \3
ENDM
bgsquare 6, 6, .SixBySix
bgsquare 4, 4, .FourByFour
bgsquare 2, 2, .TwoByTwo
bgsquare 7, 7, .SevenBySeven
bgsquare 5, 5, .FiveByFive
bgsquare 3, 3, .ThreeByThree
.SixBySix:
db $00, $06, $0c, $12, $18, $1e
db $01, $07, $0d, $13, $19, $1f
db $02, $08, $0e, $14, $1a, $20
db $03, $09, $0f, $15, $1b, $21
db $04, $0a, $10, $16, $1c, $22
db $05, $0b, $11, $17, $1d, $23
.FourByFour:
db $00, $0c, $12, $1e
db $02, $0e, $14, $20
db $03, $0f, $15, $21
db $05, $11, $17, $23
.TwoByTwo:
db $00, $1e
db $05, $23
.SevenBySeven:
db $00, $07, $0e, $15, $1c, $23, $2a
db $01, $08, $0f, $16, $1d, $24, $2b
db $02, $09, $10, $17, $1e, $25, $2c
db $03, $0a, $11, $18, $1f, $26, $2d
db $04, $0b, $12, $19, $20, $27, $2e
db $05, $0c, $13, $1a, $21, $28, $2f
db $06, $0d, $14, $1b, $22, $29, $30
.FiveByFive:
db $00, $07, $15, $23, $2a
db $01, $08, $16, $24, $2b
db $03, $0a, $18, $26, $2d
db $05, $0c, $1a, $28, $2f
db $06, $0d, $1b, $29, $30
.ThreeByThree:
db $00, $15, $2a
db $03, $18, $2d
db $06, $1b, $30
BattleBGEffect_Surf:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
lb de, 2, 2
call InitSurfWaves
.one
ldh a, [hLCDCPointer]
and a
ret z
push bc
call .RotatewSurfWaveBGEffect
pop bc
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
.RotatewSurfWaveBGEffect:
ld hl, wSurfWaveBGEffect
ld de, wSurfWaveBGEffect + 1
ld c, wSurfWaveBGEffectEnd - wSurfWaveBGEffect - 1
ld a, [hl]
push af
.loop
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .loop
pop af
ld [hl], a
ld de, wLYOverridesBackup
ld hl, wSurfWaveBGEffect
ld bc, $0
.loop2
ldh a, [hLYOverrideStart]
cp e
jr nc, .load_zero
push hl
add hl, bc
ld a, [hl]
pop hl
jr .okay
.load_zero
xor a
.okay
ld [de], a
ld a, c
inc a
and $3f
ld c, a
inc de
ld a, e
cp $5f
jr c, .loop2
ret
BattleBGEffect_Whirlpool:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
ldh [hLCDCPointer], a
xor a
ldh [hLYOverrideStart], a
ld a, $5e
ldh [hLYOverrideEnd], a
lb de, 2, 2
call DeformScreen
ret
.one
call BattleBGEffect_WavyScreenFX
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_StartWater:
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms1
call EndBattleBGEffect
ret
BattleBGEffect_Water:
; BG_EFFECT_STRUCT_JT_INDEX: defines Y position of deformation
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld e, a
add $4
ld [hl], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and $f0
swap a
xor $ff
add $4
ld d, a
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld a, [hl]
ld [wBattleSineWaveTempProgress], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
cp $20
jr nc, .done
inc [hl]
inc [hl]
call DeformWater
ret
.done
call BattleBGEffects_ClearLYOverrides
call EndBattleBGEffect
ret
BattleBGEffect_EndWater:
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Psychic:
; Hardcoded to always affect opponent
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
ldh [hLCDCPointer], a
xor a
ldh [hLYOverrideStart], a
ld a, $5f
ldh [hLYOverrideEnd], a
lb de, 6, 5
call DeformScreen
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
inc [hl]
and $3
ret nz
call BattleBGEffect_WavyScreenFX
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Teleport:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
lb de, 6, 5
call DeformScreen
ret
.one
call BattleBGEffect_WavyScreenFX
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_NightShade:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms1
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld e, [hl]
ld d, 2
call DeformScreen
ret
.one
call BattleBGEffect_WavyScreenFX
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_DoubleTeam:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
dw .three
dw .four
dw .five
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $0
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp $10
jr nc, .next
inc [hl]
call .UpdateLYOverrides
ret
.three
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp $ff
jr z, .next
dec [hl]
call .UpdateLYOverrides
ret
.next
call BattleBGEffects_IncAnonJumptableIndex
ret
.two
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
ld d, $2
call BattleBGEffects_Sine
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
add [hl]
call .UpdateLYOverrides
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
add $4
ld [hl], a
.four
ret
.UpdateLYOverrides:
ld e, a
xor $ff
inc a
ld d, a
ld h, HIGH(wLYOverridesBackup)
ldh a, [hLYOverrideStart]
ld l, a
ldh a, [hLYOverrideEnd]
sub l
srl a
push af
.loop
ld [hl], e
inc hl
ld [hl], d
inc hl
dec a
jr nz, .loop
pop af
ret nc
ld [hl], e
ret
.five
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_AcidArmor:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms1
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld e, [hl]
ld d, 2
call DeformScreen
ld h, HIGH(wLYOverridesBackup)
ldh a, [hLYOverrideEnd]
ld l, a
ld [hl], $0
dec l
ld [hl], $0
ret
.one
ldh a, [hLYOverrideEnd]
ld l, a
ld h, HIGH(wLYOverridesBackup)
ld e, l
ld d, h
dec de
.loop
ld a, [de]
dec de
ld [hld], a
ldh a, [hLYOverrideStart]
cp l
jr nz, .loop
ld [hl], $90
ldh a, [hLYOverrideEnd]
ld l, a
ld a, [hl]
cp $1
jr c, .okay
cp $90
jr z, .okay
ld [hl], $0
.okay
dec l
ld a, [hl]
cp $2
ret c
cp $90
ret z
ld [hl], $0
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Withdraw:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $1
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and $3f
ld d, a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
cp d
ret nc
call BGEffect_DisplaceLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
rlca
rlca
and $3
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
add [hl]
ld [hl], a
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Dig:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
dw .three
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $2
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr z, .next
dec [hl]
ret
.next
ld [hl], $10
call BattleBGEffects_IncAnonJumptableIndex
.two
ldh a, [hLYOverrideStart]
ld l, a
ldh a, [hLYOverrideEnd]
sub l
dec a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
cp [hl]
ret c
ld a, [hl]
push af
and $7
jr nz, .skip
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
dec [hl]
.skip
pop af
call BGEffect_DisplaceLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
inc [hl]
inc [hl]
ret
.three
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Tackle:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw Tackle_MoveForward
dw Tackle_ReturnMove
dw .three
.zero
; Prepares mon to move forward (player moves right, enemy moves left)
; BG_EFFECT_STRUCT_PARAM will keep track of distance moved, so it's reset to 0 here
; BG_EFFECT_STRUCT_BATTLE_TURN is set to 2 or -2 depending on target
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], 0
call BGEffect_CheckBattleTurn
jr nz, .player_side
ld a, 2
jr .okay
.player_side
ld a, -2
.okay
ld [hl], a
ret
.three
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_BodySlam:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw Tackle_MoveForward
dw Tackle_ReturnMove
dw .three
.zero
; Prepares mon to move forward (player moves right, enemy moves left)
; BG_EFFECT_STRUCT_PARAM will keep track of distance moved, so it's reset to 0 here
; BG_EFFECT_STRUCT_BATTLE_TURN is set to 2 or -2 depending on target
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms2
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], 0
call BGEffect_CheckBattleTurn
jr nz, .player_side
ld a, 2
jr .okay
.player_side
ld a, -2
.okay
ld [hl], a
ret
.three
call BattleAnim_ResetLCDStatCustom
ret
Tackle_MoveForward:
; Moves user horizontally in a direction that can be positive or negative. When the limit is reached (8 pixels) we move to the next function in the jumptable (Tackle_ReturnMove)
; BG_EFFECT_STRUCT_BATTLE_TURN: speed and direction
; BG_EFFECT_STRUCT_PARAM: keeps track of distance moved
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp -8
jr z, .reached_limit
cp 8
jr nz, .finish
.reached_limit
call BattleBGEffects_IncAnonJumptableIndex
.finish
call Rollout_FillLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
add [hl]
ld [hl], a
ret
Tackle_ReturnMove:
; Move user horizontally back to initial position. When we back to position 0, we move to the next function in the jumptable
; BG_EFFECT_STRUCT_BATTLE_TURN: is turned into a negative number (this number is not saved to preserve the initial number)
; BG_EFFECT_STRUCT_PARAM: keeps track of distance moved
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr nz, .move_back
call BattleBGEffects_IncAnonJumptableIndex
.move_back
call Rollout_FillLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
xor $ff
inc a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
add [hl]
ld [hl], a
ret
Rollout_FillLYOverridesBackup:
push af
ld a, [wFXAnimID + 1]
or a
jr nz, .not_rollout
ld a, [wFXAnimID]
cp ROLLOUT
jr z, .rollout
.not_rollout
pop af
jp BGEffect_FillLYOverridesBackup
.rollout
ldh a, [hLYOverrideStart]
ld d, a
ldh a, [hLYOverrideEnd]
sub d
ld d, a
ld h, HIGH(wLYOverridesBackup)
ldh a, [hSCY]
or a
jr nz, .skip1
ldh a, [hLYOverrideStart]
or a
jr z, .skip2
dec a
ld l, a
ld [hl], $0
jr .skip2
.skip1
ldh a, [hLYOverrideEnd]
dec a
ld l, a
ld [hl], $0
.skip2
ldh a, [hSCY]
ld l, a
ldh a, [hLYOverrideStart]
sub l
jr nc, .skip3
xor a
dec d
.skip3
ld l, a
pop af
.loop
ld [hli], a
dec d
jr nz, .loop
ret
BattleBGEffect_BetaPursuit: ; unused
call BattleBGEffects_AnonJumptable
.anon_dw
dw VitalThrow_MoveBackwards
dw Tackle_MoveForward
dw Tackle_ReturnMove
dw .three
.three
call BattleAnim_ResetLCDStatCustom
ret
VitalThrow_MoveBackwards:
; Prepares mon to move back back (player moves left, enemy moves right)
; BG_EFFECT_STRUCT_PARAM: keeps track of distance moved, so it's reset to 0 here
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
call BGEffect_CheckBattleTurn
jr nz, .player_turn
ld a, -2
jr .okay
.player_turn
ld a, 2
.okay
ld [hl], a
ret
BattleBGEffect_VitalThrow:
call BattleBGEffects_AnonJumptable
.anon_dw
dw VitalThrow_MoveBackwards
dw Tackle_MoveForward
dw .two
dw Tackle_ReturnMove
dw .four
.four
call BattleAnim_ResetLCDStatCustom
.two
ret
BattleBGEffect_WobbleMon:
; Similar to BattleBGEffect_WobblePlayer, except it can affect either side and the sine movement has a radius of 8 instead of 6 and it moves at twice the rate
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld d, $8
call BattleBGEffects_Sine
call BGEffect_FillLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
add $4
ld [hl], a
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Flail:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
xor a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hli], a
ld [hl], a
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld d, $6
call BattleBGEffects_Sine
push af
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
ld d, $2
call BattleBGEffects_Sine
ld e, a
pop af
add e
call BGEffect_FillLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
add $8
ld [hl], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
add $2
ld [hl], a
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_WaveDeformMon:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp $20
ret nc
inc [hl]
ld d, a
ld e, 4
call DeformScreen
ret
.two
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr z, .reset
dec [hl]
ld d, a
ld e, 4
call DeformScreen
ret
.reset
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_BounceDown:
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCY)
call BattleBGEffect_SetLCDStatCustoms2
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $1
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $20
ret
.one
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
cp $38
ret nc
push af
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld d, $10
call BattleBGEffects_Cosine
add $10
ld d, a
pop af
add d
call BGEffect_DisplaceLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
inc [hl]
inc [hl]
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_BetaSendOutMon1: ; unused
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
dw .three
dw .four
dw .five
.zero
call BattleBGEffects_IncAnonJumptableIndex
ld a, $e4
call BattleBGEffects_SetLYOverrides
ld a, $47
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ldh a, [hLYOverrideStart]
ld l, a
ld h, HIGH(wLYOverridesBackup)
.loop
ldh a, [hLYOverrideEnd]
cp l
jr z, .done
xor a
ld [hli], a
jr .loop
.done
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
.one
.four
ret
.two
call .GetLYOverride
jr nc, .next
call .SetLYOverridesBackup
ret
.next
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ldh a, [hLYOverrideStart]
inc a
ldh [hLYOverrideStart], a
call BattleBGEffects_IncAnonJumptableIndex
ret
.three
call .GetLYOverride
jr nc, .finish
call .SetLYOverridesBackup
ldh a, [hLYOverrideEnd]
dec a
ld l, a
ld [hl], e
ret
.finish
call BattleBGEffects_IncAnonJumptableIndex
ret
.SetLYOverridesBackup:
ld e, a
ldh a, [hLYOverrideStart]
ld l, a
ldh a, [hLYOverrideEnd]
sub l
srl a
ld h, HIGH(wLYOverridesBackup)
.loop2
ld [hl], e
inc hl
inc hl
dec a
jr nz, .loop2
ret
.five
call BattleBGEffects_ResetVideoHRAM
ret
.GetLYOverride:
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
inc [hl]
srl a
srl a
srl a
ld e, a
ld d, 0
ld hl, .data
add hl, de
ld a, [hl]
cp $ff
ret
.data
db $00, $40, $90, $e4
db -1
BattleBGEffect_BetaSendOutMon2: ; unused
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $40
ret
.one
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and a
jr z, .done
dec [hl]
srl a
srl a
srl a
and $f
ld d, a
ld e, a
call DeformScreen
ret
.done
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_FadeMonsToBlackRepeating:
ldh a, [hCGB]
and a
jr nz, .cgb
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
ld a, $e4
call BattleBGEffects_SetLYOverrides
ld a, LOW(rBGP)
ldh [hLCDCPointer], a
xor a
ldh [hLYOverrideStart], a
ld a, $60
ldh [hLYOverrideEnd], a
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
inc [hl]
ld e, a
and $7
ret nz
ld a, e
and $18
sla a
swap a
sla a
ld e, a
ld d, 0
push bc
call BGEffect_CheckBattleTurn
jr nz, .player
ld hl, .CGB_DMGEnemyData
add hl, de
ld a, [hli]
ld [wOBP1], a
ld d, a
ld e, [hl]
lb bc, $2f, $30
jr .okay
.player
ld hl, .DMG_PlayerData
add hl, de
ld d, [hl]
inc hl
ld a, [hl]
ld [wOBP1], a
ld e, a
lb bc, $37, $28
.okay
call .DMG_LYOverrideLoads
pop bc
ret
.two
call BattleBGEffects_ResetVideoHRAM
ld a, $e4
ld [wBGP], a
ld [wOBP1], a
ret
.DMG_LYOverrideLoads:
ld hl, wLYOverridesBackup
.loop1
ld [hl], d
inc hl
dec b
jr nz, .loop1
.loop2
ld [hl], e
inc hl
dec c
jr nz, .loop2
ret
.cgb
ld de, .Jumptable
call BatttleBGEffects_GetNamedJumptablePointer
jp hl
.Jumptable:
dw .cgb_zero
dw .cgb_one
dw .cgb_two
.cgb_zero
call BattleBGEffects_IncAnonJumptableIndex
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ret
.cgb_one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
inc [hl]
ld e, a
and $7
ret nz
ld a, e
and $18
sla a
swap a
sla a
ld e, a
ld d, 0
call BGEffect_CheckBattleTurn
jr nz, .player_2
ld hl, .CGB_DMGEnemyData
add hl, de
ld a, [hli]
push hl
call BGEffects_LoadBGPal1_OBPal0
pop hl
ld a, [hl]
call BGEffects_LoadBGPal0_OBPal1
ret
.player_2
ld hl, .CGB_DMGEnemyData
add hl, de
ld a, [hli]
push hl
call BGEffects_LoadBGPal0_OBPal1
pop hl
ld a, [hl]
call BGEffects_LoadBGPal1_OBPal0
ret
.cgb_two
ld a, $e4
call BGEffects_LoadBGPal0_OBPal1
ld a, $e4
call BGEffects_LoadBGPal1_OBPal0
call EndBattleBGEffect
ret
.CGB_DMGEnemyData:
db $e4, $e4
db $f8, $90
db $fc, $40
db $f8, $90
.DMG_PlayerData:
db $e4, $e4
db $90, $f8
db $40, $fc
db $90, $f8
BattleBGEffect_RapidFlash: ; unused
ld de, .FlashPals
call BGEffect_RapidCyclePals
ret
.FlashPals:
db $e4, $6c, $fe
BattleBGEffect_FadeMonToLight:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $90, $40, $ff
BattleBGEffect_FadeMonToBlack:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $f8, $fc, $ff
BattleBGEffect_FadeMonToLightRepeating:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $90, $40, $90, $fe
BattleBGEffect_FadeMonToBlackRepeating:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $f8, $fc, $f8, $fe
BattleBGEffect_CycleMonLightDarkRepeating:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $f8, $fc, $f8, $e4, $90, $40, $90, $fe
BattleBGEffect_FlashMonRepeating: ; unused
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $fc, $e4, $00, $fe
BattleBGEffect_FadeMonToWhiteWaitFadeBack:
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $e4, $90, $40, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $40, $90, $e4, $ff
BattleBGEffect_FadeMonFromWhite: ; unused
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
ld de, .Pals
call BGEffect_RapidCyclePals
ret
.Pals:
db $00, $40, $90, $e4, $ff
BattleBGEffect_VibrateMon:
; Moves mon back and forth sideways for $20 frames
; BG_EFFECT_STRUCT_BATTLE_TURN = BG_EFFECT_TARGET or BG_EFFECT_USER
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], $1
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $20
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and a
jr z, .finish
dec [hl]
and $1
ret nz
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
xor $ff
inc a
ld [hl], a
call BGEffect_FillLYOverridesBackup
ret
.finish
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_WobblePlayer:
; Always affects the player
call BattleBGEffects_AnonJumptable
.anon_dw
dw .zero
dw .one
dw .two
.zero
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_ClearLYOverrides
ld a, LOW(rSCX)
ldh [hLCDCPointer], a
xor a
ldh [hLYOverrideStart], a
ld a, $37
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
ret
.one
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp $40
jr nc, .two
ld d, $6
call BattleBGEffects_Sine
call BGEffect_FillLYOverridesBackup
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
add $2
ld [hl], a
ret
.two
call BattleAnim_ResetLCDStatCustom
ret
BattleBGEffect_Rollout:
call BattleBGEffects_GetShakeAmount
jr c, .xor_a
bit 7, a
jr z, .okay
.xor_a
xor a
.okay
push af
call DelayFrame
pop af
ldh [hSCY], a
xor $ff
inc a
ld [wAnimObject1YOffset], a
ret
BattleBGEffect_ShakeScreenX:
call BattleBGEffects_GetShakeAmount
jr nc, .skip
xor a
.skip
ldh [hSCX], a
ret
BattleBGEffect_ShakeScreenY:
call BattleBGEffects_GetShakeAmount
jr nc, .skip
xor a
.skip
ldh [hSCY], a
ret
BattleBGEffects_GetShakeAmount:
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld a, [hl]
and a
jr nz, .okay
call EndBattleBGEffect
scf
ret
.okay
dec [hl]
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
and $f
jr z, .every_16_frames
dec [hl]
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and a
ret
.every_16_frames
ld a, [hl]
swap a
or [hl]
ld [hl], a
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
xor $ff
inc a
ld [hl], a
and a
ret
BattleBGEffect_WobbleScreen:
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
cp $40
jr nc, .finish
ld d, $6
call BattleBGEffects_Sine
ldh [hSCX], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
add $2
ld [hl], a
ret
.finish
xor a
ldh [hSCX], a
ret
BattleBGEffect_GetNthDMGPal:
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld a, [hl]
and a
jr z, .zero
dec [hl]
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
call BattleBGEffect_GetNextDMGPal
ret
.zero
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
ld hl, BG_EFFECT_STRUCT_JT_INDEX
add hl, bc
ld [hl], a
call BattleBGEffect_GetFirstDMGPal
ret
BGEffect_RapidCyclePals:
; Last index in DE: $fe signals a loop, $ff signals end
ldh a, [hCGB]
and a
jr nz, .cgb
push de
ld de, .Jumptable_DMG
call BatttleBGEffects_GetNamedJumptablePointer
pop de
jp hl
.Jumptable_DMG:
dw .zero_dmg
dw .one_dmg
dw .two_dmg
.zero_dmg
call BattleBGEffects_IncAnonJumptableIndex
ld a, $e4
call BattleBGEffects_SetLYOverrides
ld a, $47
call BattleBGEffect_SetLCDStatCustoms1
ldh a, [hLYOverrideEnd]
inc a
ldh [hLYOverrideEnd], a
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld [hl], $0
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], a
ret
.one_dmg
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and $f
jr z, .okay_1_dmg
dec [hl]
ret
.okay_1_dmg
ld a, [hl]
swap a
or [hl]
ld [hl], a
call BattleBGEffect_GetFirstDMGPal
jr c, .okay_2_dmg
call BGEffect_FillLYOverridesBackup
ret
.okay_2_dmg
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
dec [hl]
ret
.two_dmg
call BattleBGEffects_ResetVideoHRAM
ld a, %11100100
ldh [rBGP], a
call EndBattleBGEffect
ret
.cgb
push de
ld de, .Jumptable_CGB
call BatttleBGEffects_GetNamedJumptablePointer
pop de
jp hl
.Jumptable_CGB:
dw .zero_cgb
dw .one_cgb
dw .two_cgb
dw .three_cgb
dw .four_cgb
.zero_cgb
call BGEffect_CheckBattleTurn
jr nz, .player_turn_cgb
call BattleBGEffects_IncAnonJumptableIndex
call BattleBGEffects_IncAnonJumptableIndex
.player_turn_cgb
call BattleBGEffects_IncAnonJumptableIndex
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
ld [hl], $0
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld [hl], a
ret
.one_cgb
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and $f
jr z, .okay_1_cgb
dec [hl]
ret
.okay_1_cgb
ld a, [hl]
swap a
or [hl]
ld [hl], a
call BattleBGEffect_GetFirstDMGPal
jr c, .okay_2_cgb
call BGEffects_LoadBGPal0_OBPal1
ret
.okay_2_cgb
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
dec [hl]
ret
.two_cgb
ld a, $e4
call BGEffects_LoadBGPal0_OBPal1
call EndBattleBGEffect
ret
.three_cgb
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ld a, [hl]
and $f
jr z, .okay_3_cgb
dec [hl]
ret
.okay_3_cgb
ld a, [hl]
swap a
or [hl]
ld [hl], a
call BattleBGEffect_GetFirstDMGPal
jr c, .okay_4_cgb
call BGEffects_LoadBGPal1_OBPal0
ret
.okay_4_cgb
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
dec [hl]
ret
.four_cgb
ld a, $e4
call BGEffects_LoadBGPal1_OBPal0
call EndBattleBGEffect
ret
BGEffects_LoadBGPal0_OBPal1:
ld h, a
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
ld a, h
push bc
push af
ld hl, wBGPals2
ld de, wBGPals1
ld b, a
ld c, $1
call CopyPals
ld hl, wOBPals2 palette 1
ld de, wOBPals1 palette 1
pop af
ld b, a
ld c, $1
call CopyPals
pop bc
pop af
ldh [rSVBK], a
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
BGEffects_LoadBGPal1_OBPal0:
ld h, a
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ldh [rSVBK], a
ld a, h
push bc
push af
ld hl, wBGPals2 palette 1
ld de, wBGPals1 palette 1
ld b, a
ld c, $1
call CopyPals
ld hl, wOBPals2
ld de, wOBPals1
pop af
ld b, a
ld c, $1
call CopyPals
pop bc
pop af
ldh [rSVBK], a
ld a, TRUE
ldh [hCGBPalUpdate], a
ret
BattleBGEffect_GetFirstDMGPal:
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld a, [hl]
inc [hl]
BattleBGEffect_GetNextDMGPal:
ld l, a
ld h, 0
add hl, de
ld a, [hl]
cp -1
jr z, .quit
cp -2
jr nz, .repeat
ld a, [de]
ld hl, BG_EFFECT_STRUCT_PARAM
add hl, bc
ld [hl], $0
.repeat
and a
ret
.quit
scf
ret
BattleBGEffects_ClearLYOverrides:
xor a
BattleBGEffects_SetLYOverrides:
ld hl, wLYOverrides
ld e, $99
.loop1
ld [hli], a
dec e
jr nz, .loop1
ld hl, wLYOverridesBackup
ld e, $91
.loop2
ld [hli], a
dec e
jr nz, .loop2
ret
BattleBGEffect_SetLCDStatCustoms1:
ldh [hLCDCPointer], a
call BGEffect_CheckBattleTurn
jr nz, .player_turn
lb de, $00, $36
jr .okay
.player_turn
lb de, $2f, $5e
.okay
ld a, d
ldh [hLYOverrideStart], a
ld a, e
ldh [hLYOverrideEnd], a
ret
BattleBGEffect_SetLCDStatCustoms2:
ldh [hLCDCPointer], a
call BGEffect_CheckBattleTurn
jr nz, .player_turn
lb de, $00, $36
jr .okay
.player_turn
lb de, $2d, $5e
.okay
ld a, d
ldh [hLYOverrideStart], a
ld a, e
ldh [hLYOverrideEnd], a
ret
BattleAnim_ResetLCDStatCustom:
xor a
ldh [hLYOverrideStart], a
ldh [hLYOverrideEnd], a
call BattleBGEffects_ClearLYOverrides
xor a
ldh [hLCDCPointer], a
call EndBattleBGEffect
ret
BattleBGEffects_ResetVideoHRAM:
xor a
ldh [hLCDCPointer], a
ld a, %11100100
ldh [rBGP], a
ld [wBGP], a
ld [wOBP1], a
ldh [hLYOverrideStart], a
ldh [hLYOverrideEnd], a
call BattleBGEffects_ClearLYOverrides
ret
DeformScreen:
push bc
xor a
ld [wBattleSineWaveTempProgress], a
ld a, e
ld [wBattleSineWaveTempOffset], a
ld a, d
ld [wBattleSineWaveTempAmplitude], a
ld a, $80
ld [wBattleSineWaveTempTimer], a
ld bc, wLYOverridesBackup
.loop
ldh a, [hLYOverrideStart]
cp c
jr nc, .next
ldh a, [hLYOverrideEnd]
cp c
jr c, .next
ld a, [wBattleSineWaveTempAmplitude]
ld d, a
ld a, [wBattleSineWaveTempProgress]
call BattleBGEffects_Sine
ld [bc], a
.next
inc bc
ld a, [wBattleSineWaveTempOffset]
ld hl, wBattleSineWaveTempProgress
add [hl]
ld [hl], a
ld hl, wBattleSineWaveTempTimer
dec [hl]
jr nz, .loop
pop bc
ret
InitSurfWaves:
push bc
xor a
ld [wBattleSineWaveTempProgress], a
ld a, e
ld [wBattleSineWaveTempOffset], a
ld a, d
ld [wBattleSineWaveTempAmplitude], a
ld a, $40
ld [wBattleSineWaveTempTimer], a
ld bc, wSurfWaveBGEffect
.loop
ld a, [wBattleSineWaveTempAmplitude]
ld d, a
ld a, [wBattleSineWaveTempProgress]
call BattleBGEffects_Sine
ld [bc], a
inc bc
ld a, [wBattleSineWaveTempOffset]
ld hl, wBattleSineWaveTempProgress
add [hl]
ld [hl], a
ld hl, wBattleSineWaveTempTimer
dec [hl]
jr nz, .loop
pop bc
ret
DeformWater:
push bc
ld [wBattleSineWaveTempTimer], a
ld a, e
ld [wBattleSineWaveTempOffset], a
ld a, d
ld [wBattleSineWaveTempAmplitude], a
call .GetLYOverrideBackupAddrOffset
ld hl, wLYOverridesBackup
add hl, de
ld c, l
ld b, h
.loop
ld a, [wBattleSineWaveTempTimer]
and a
jr z, .done
dec a
ld [wBattleSineWaveTempTimer], a
push af
ld a, [wBattleSineWaveTempAmplitude]
ld d, a
ld a, [wBattleSineWaveTempOffset]
push hl
call BattleBGEffects_Sine
ld e, a
pop hl
ldh a, [hLYOverrideEnd]
cp c
jr c, .skip1
ld a, e
ld [bc], a
inc bc
.skip1
ldh a, [hLYOverrideStart]
cp l
jr nc, .skip2
ld [hl], e
dec hl
.skip2
ld a, [wBattleSineWaveTempOffset]
add $4
ld [wBattleSineWaveTempOffset], a
pop af
jr .loop
.done
pop bc
and a
ret
.GetLYOverrideBackupAddrOffset:
ldh a, [hLYOverrideStart]
ld e, a
ld a, [wBattleSineWaveTempProgress]
add e
ld e, a
ld d, 0
ret
BattleBGEffect_WavyScreenFX:
push bc
ldh a, [hLYOverrideStart]
ld l, a
inc a
ld e, a
ld h, HIGH(wLYOverridesBackup)
ld d, h
ldh a, [hLYOverrideEnd]
sub l
and a
jr z, .done
ld c, a
ld a, [hl]
push af
.loop
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .loop
pop af
ld [hl], a
.done
pop bc
ret
BGEffect_FillLYOverridesBackup:
push af
ld h, HIGH(wLYOverridesBackup)
ldh a, [hLYOverrideStart]
ld l, a
ldh a, [hLYOverrideEnd]
sub l
ld d, a
pop af
.loop
ld [hli], a
dec d
jr nz, .loop
ret
BGEffect_DisplaceLYOverridesBackup:
; e = a
; d = [hLYOverrideEnd] - [hLYOverrideStart] - a
push af
ld e, a
ldh a, [hLYOverrideStart]
ld l, a
ldh a, [hLYOverrideEnd]
sub l
sub e
ld d, a
ld h, HIGH(wLYOverridesBackup)
ldh a, [hLYOverrideStart]
ld l, a
ld a, $90
.loop
ld [hli], a
dec e
jr nz, .loop
pop af
xor $ff
.loop2
ld [hli], a
dec d
jr nz, .loop2
ret
BGEffect_CheckBattleTurn:
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ldh a, [hBattleTurn]
and $1
xor [hl]
ret
BGEffect_CheckFlyDigStatus:
ld hl, BG_EFFECT_STRUCT_BATTLE_TURN
add hl, bc
ldh a, [hBattleTurn]
and $1
xor [hl]
jr nz, .player
ld a, [wEnemySubStatus3] ; EnemySubStatus3
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret
.player
ld a, [wPlayerSubStatus3] ; PlayerSubStatus3
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret
BattleBGEffects_CheckSGB:
ldh a, [hSGB]
and a
ret
BattleBGEffects_Sine:
ld e, a
callfar BattleAnim_Sine_e
ld a, e
ret
BattleBGEffects_Cosine:
ld e, a
callfar BattleAnim_Cosine_e
ld a, e
ret
|