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
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
|
BattleCore:
; Core components of the battle engine.
Function3c000: ; 3c000
xor a
ld [$c664], a
ld [$c6fc], a
ld [$d0ec], a
ld [BattleEnded], a
inc a
ld [$d264], a
ld hl, OTPartyMon1HP
ld bc, $002f
ld d, $3
.asm_3c019
inc d
ld a, [hli]
or [hl]
jr nz, .asm_3c021
add hl, bc
jr .asm_3c019
.asm_3c021
ld a, d
ld [$d430], a
ld a, [InLinkBattle]
and a
jr z, .asm_3c031
ld a, [$ffcb]
cp $2
jr z, .asm_3c04c
.asm_3c031
ld a, [IsInBattle]
dec a
jr z, .asm_3c047
xor a
ld [$c718], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
call Function3d4e1
.asm_3c047
ld c, 40
call DelayFrames
.asm_3c04c
call Function309d
call Function3d873
ld a, d
and a
jp z, LostBattle
call Function30b4
ld a, [BattleType]
cp $2
jp z, Function3c0e2
cp $3
jp z, Function3c0e2
xor a
ld [CurPartyMon], a
.asm_3c06b
call Function3d887
jr nz, .asm_3c076
ld hl, CurPartyMon
inc [hl]
jr .asm_3c06b
.asm_3c076
ld a, [CurBattleMon]
ld [$c71a], a
ld a, [CurPartyMon]
ld [CurBattleMon], a
inc a
ld hl, PartyCount
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
ld [CurPartySpecies], a
ld [TempBattleMonSpecies], a
ld hl, $c505
ld a, $9
call Function3d490
call Function309d
call Function3d57a
call Function3da0d
call ResetPlayerStatLevels
call Function3f26d
call NewBattleMonStatus
call BreakAttraction
call Function3db5f
call EmptyBattleTextBox
call Function309d
call SetPlayerTurn
call SpikesDamage
ld a, [InLinkBattle]
and a
jr z, .asm_3c0df
ld a, [$ffcb]
cp $2
jr nz, .asm_3c0df
xor a
ld [$c718], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
call Function3d4e1
call SetEnemyTurn
call SpikesDamage
.asm_3c0df
jp Function3c12f
; 3c0e2
Function3c0e2: ; 3c0e2
jp Function3e139
; 3c0e5
Function3c0e5: ; 3c0e5
call Function30b4
ld a, [$d0ee]
and $c0
add $2
ld [$d0ee], a
ld a, [InLinkBattle]
and a
ld hl, BattleText_0x807bd
jr z, .asm_3c115
ld a, [$d0ee]
and $c0
ld [$d0ee], a
ld hl, BattleText_0x807cf
call Function3d2e0
jr nc, .asm_3c115
ld hl, $cd2a
bit 4, [hl]
jr nz, .asm_3c118
ld hl, BattleText_0x81863
.asm_3c115
call StdBattleTextBox
.asm_3c118
call Function3ceec
call Function3d2e0
jr c, .asm_3c126
ld de, SFX_RUN
call PlaySFX
.asm_3c126
call SetPlayerTurn
ld a, 1
ld [BattleEnded], a
ret
; 3c12f
Function3c12f: ; 3c12f
call Function3c1bf
call Function3c3f5
jp c, .asm_3c1be
xor a
ld [$c710], a
ld [$c711], a
ld [$d264], a
ld [$c73f], a
ld [$c740], a
ld [CurDamage], a
ld [$d257], a
call Function3c27c
call UpdateBattleMonInParty
callba AIChooseMove
call Function3d2f1
jr nz, .asm_3c174
callba Function100da5
callba Function100641
callba Function100dd8
jp c, .asm_3c1be
.asm_3c174
call Function3c410
jr c, .asm_3c18a
.asm_3c179
call Function3e139
jr c, .asm_3c1be
ld a, [BattleEnded]
and a
jr nz, .asm_3c1be
ld a, [$d232]
and a
jr nz, .asm_3c1be
.asm_3c18a
call Function3c434
jr nz, .asm_3c179
call Function3c300
jr c, .asm_3c1be
call Function3c314
jr c, .asm_3c19e
call Function3c5fe
jr .asm_3c1a1
.asm_3c19e
call Function3c664
.asm_3c1a1
call Function3d2e0
jr c, .asm_3c1be
ld a, [$d232]
and a
jr nz, .asm_3c1be
ld a, [BattleEnded]
and a
jr nz, .asm_3c1be
call Function3c1d6
ld a, [BattleEnded]
and a
jr nz, .asm_3c1be
jp Function3c12f
.asm_3c1be
ret
; 3c1bf
Function3c1bf: ; 3c1bf
ret
; 3c1c0
Function3c1c0: ; 3c1c0
ld a, $5
call GetSRAMBank
ld hl, $a89b
inc [hl]
jr nz, .asm_3c1d2
dec hl
inc [hl]
jr nz, .asm_3c1d2
dec [hl]
inc hl
dec [hl]
.asm_3c1d2
call CloseSRAM
ret
; 3c1d6
Function3c1d6: ; 3c1d6
ld a, [$ffcb]
cp $1
jr z, .asm_3c1fe
call Function3c23c
ret c
call Function3ca26
call Function3c23c
ret c
call HandleWeather
call Function3c23c
ret c
call Function3c874
call Function3c23c
ret c
call Function3c801
call Function3c23c
ret c
jr .asm_3c21e
.asm_3c1fe
call Function3c25c
ret c
call Function3ca26
call Function3c25c
ret c
call HandleWeather
call Function3c25c
ret c
call Function3c874
call Function3c25c
ret c
call Function3c801
call Function3c25c
ret c
.asm_3c21e
call Function3c8eb
call Function3c93c
call Function3ca8f
call Function3cafb
call Function3cb36
call Function3de97
call Function3dcf9
call UpdateBattleMonInParty
call Function309d
jp Function3c4df
; 3c23c
Function3c23c: ; 3c23c
call Function3c710
jr nz, .asm_3c24a
call Function3d14e
ld a, [BattleEnded]
and a
jr nz, .asm_3c25a
.asm_3c24a
call Function3c70b
jr nz, .asm_3c258
call Function3cd55
ld a, [BattleEnded]
and a
jr nz, .asm_3c25a
.asm_3c258
and a
ret
.asm_3c25a
scf
ret
; 3c25c
Function3c25c: ; 3c25c
call Function3c70b
jr nz, .asm_3c26a
call Function3cd55
ld a, [BattleEnded]
and a
jr nz, .asm_3c27a
.asm_3c26a
call Function3c710
jr nz, .asm_3c278
call Function3d14e
ld a, [BattleEnded]
and a
jr nz, .asm_3c27a
.asm_3c278
and a
ret
.asm_3c27a
scf
ret
; 3c27c
Function3c27c: ; 3c27c
ld a, [$ffcb]
cp $1
jr z, .reverse
call .player
jr .enemy
.reverse
call .enemy
; jr .player
.player
call SetPlayerTurn
ld de, PartyMon1Item
ld a, [CurBattleMon]
ld b, a
jr .go
.enemy
call SetEnemyTurn
ld de, OTPartyMon1Item
ld a, [CurOTMon]
ld b, a
; jr .go
.go
push de
push bc
callab GetUserItem
ld a, [hl]
ld [$d265], a
sub BERSERK_GENE
pop bc
pop de
ret nz
ld [hl], a
ld h, d
ld l, e
ld a, b
call GetPartyLocation
xor a
ld [hl], a
ld a, BATTLE_VARS_SUBSTATUS3
call _GetBattleVar
push af
set SUBSTATUS_CONFUSED, [hl]
ld a, BATTLE_VARS_MOVE_ANIM
call _GetBattleVar
push hl
push af
xor a
ld [hl], a
ld [AttackMissed], a
ld [EffectFailed], a
callba BattleCommand77
pop af
pop hl
ld [hl], a
call GetItemName
ld hl, BattleText_0x80bde
call StdBattleTextBox
callab BattleCommand8c
pop af
bit SUBSTATUS_CONFUSED, a
ret nz
xor a
ld [$cfca], a
ld de, $0103
call Function3ee0f
call Function3c8e4
ld hl, BecameConfusedText
jp StdBattleTextBox
; 3c300
Function3c300: ; 3c300
ld a, [InLinkBattle]
and a
jr z, .asm_3c30d
ld a, [$d430]
cp $f
jr z, .asm_3c30f
.asm_3c30d
and a
ret
.asm_3c30f
call Function3c0e5
scf
ret
; 3c314
Function3c314: ; 3c314
ld a, [InLinkBattle]
and a
jr z, .asm_3c35b
ld a, [$d430]
cp $e
jr z, .asm_3c35b
cp $d
jr z, .asm_3c35b
sub $4
jr c, .asm_3c35b
ld a, [$d0ec]
cp $2
jr nz, .asm_3c34c
ld a, [$ffcb]
cp $2
jr z, .asm_3c341
call BattleRandom
cp $80
jp c, .asm_3c3f1
jp Function3c3f3
.asm_3c341
call BattleRandom
cp $80
jp c, Function3c3f3
jp .asm_3c3f1
.asm_3c34c
callab Function3846c
call SetEnemyTurn
call SpikesDamage
jp Function3c3f3
.asm_3c35b
ld a, [$d0ec]
and a
jp nz, .asm_3c3f1
call CompareMovePriority
jr z, .asm_3c36d
jp c, .asm_3c3f1
jp Function3c3f3
.asm_3c36d
call SetPlayerTurn
callab GetUserItem
push bc
callab GetOpponentItem
pop de
ld a, d
cp $4a
jr nz, .asm_3c391
ld a, b
cp $4a
jr z, .asm_3c39f
call BattleRandom
cp e
jr nc, .asm_3c3c5
jp .asm_3c3f1
.asm_3c391
ld a, b
cp $4a
jr nz, .asm_3c3c5
call BattleRandom
cp c
jr nc, .asm_3c3c5
jp Function3c3f3
.asm_3c39f
ld a, [$ffcb]
cp $2
jr z, .asm_3c3b5
call BattleRandom
cp c
jp c, Function3c3f3
call BattleRandom
cp e
jp c, .asm_3c3f1
jr .asm_3c3c5
.asm_3c3b5
call BattleRandom
cp e
jp c, .asm_3c3f1
call BattleRandom
cp c
jp c, Function3c3f3
jr .asm_3c3c5
.asm_3c3c5
ld de, BattleMonSpd
ld hl, EnemyMonSpd
ld c, $2
call StringCmp
jr z, .asm_3c3d8
jp nc, .asm_3c3f1
jp Function3c3f3
.asm_3c3d8
ld a, [$ffcb]
cp $2
jr z, .asm_3c3e9
call BattleRandom
cp $80
jp c, .asm_3c3f1
jp Function3c3f3
.asm_3c3e9
call BattleRandom
cp $80
jp c, Function3c3f3
.asm_3c3f1
scf
ret
; 3c3f3
Function3c3f3: ; 3c3f3
and a
ret
; 3c3f5
Function3c3f5: ; 3c3f5
ld a, [BattleType]
cp $6
jr nz, .asm_3c40e
ld a, [$dc79]
and a
jr nz, .asm_3c40e
ld a, [$d0ee]
and $c0
add $2
ld [$d0ee], a
scf
ret
.asm_3c40e
and a
ret
; 3c410
Function3c410: ; 3c410
ld a, [PlayerSubStatus4]
and $20
jp nz, Function3c432
ld hl, EnemySubStatus3
res 3, [hl]
ld hl, PlayerSubStatus3
res 3, [hl]
ld a, [hl]
and $12
jp nz, Function3c432
ld hl, PlayerSubStatus1
bit 6, [hl]
jp nz, Function3c432
and a
ret
; 3c432
Function3c432: ; 3c432
scf
ret
; 3c434
Function3c434: ; 3c434
call Function3c410
jp c, .asm_3c4ba
ld hl, PlayerSubStatus5
bit 4, [hl]
jr z, .asm_3c449
ld a, [LastPlayerMove]
ld [CurPlayerMove], a
jr .asm_3c47c
.asm_3c449
ld a, [$d0ec]
cp $2
jr z, .asm_3c4ce
and a
jr nz, .asm_3c4b5
ld a, [PlayerSubStatus3]
and $1
jr nz, .asm_3c4ba
xor a
ld [$d235], a
inc a
ld [FXAnimIDLo], a
call Function3e4bc
push af
call Function30b4
call UpdateBattleHuds
ld a, [CurPlayerMove]
cp $a5
jr z, .asm_3c476
call PlayClickSFX
.asm_3c476
ld a, $1
ld [hBGMapMode], a
pop af
ret nz
.asm_3c47c
call SetPlayerTurn
callab UpdateMoveData
xor a
ld [$c732], a
ld a, [PlayerMoveEffect]
cp $77
jr z, .asm_3c494
xor a
ld [PlayerFuryCutterCount], a
.asm_3c494
ld a, [PlayerMoveEffect]
cp $51
jr z, .asm_3c4a4
ld hl, PlayerSubStatus4
res 6, [hl]
xor a
ld [$c72b], a
.asm_3c4a4
ld a, [PlayerMoveEffect]
cp $6f
jr z, .asm_3c4c9
cp $74
jr z, .asm_3c4c9
xor a
ld [PlayerProtectCount], a
jr .asm_3c4c9
.asm_3c4b5
ld hl, PlayerSubStatus3
res 0, [hl]
.asm_3c4ba
xor a
ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a
ld [$c72b], a
ld hl, PlayerSubStatus4
res 6, [hl]
.asm_3c4c9
call Function3e7c1
xor a
ret
.asm_3c4ce
xor a
ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a
ld [$c72b], a
ld hl, PlayerSubStatus4
res 6, [hl]
xor a
ret
; 3c4df
Function3c4df: ; 3c4df
ld a, [$ffcb]
cp $1
jr z, .asm_3c4ea
call .asm_3c4ed
jr .asm_3c518
.asm_3c4ea
call .asm_3c518
.asm_3c4ed
ld hl, PlayerSubStatus5
bit 4, [hl]
ret z
ld a, [PlayerEncoreCount]
dec a
ld [PlayerEncoreCount], a
jr z, .asm_3c50a
ld hl, BattleMonPPMove1
ld a, [CurMoveNum]
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
and $3f
ret nz
.asm_3c50a
ld hl, PlayerSubStatus5
res 4, [hl]
call SetEnemyTurn
ld hl, BattleText_0x80c8a
jp StdBattleTextBox
.asm_3c518
ld hl, EnemySubStatus5
bit 4, [hl]
ret z
ld a, [EnemyEncoreCount]
dec a
ld [EnemyEncoreCount], a
jr z, .asm_3c535
ld hl, EnemyMonPPMove1
ld a, [CurEnemyMoveNum]
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
and $3f
ret nz
.asm_3c535
ld hl, EnemySubStatus5
res 4, [hl]
call SetPlayerTurn
ld hl, BattleText_0x80c8a
jp StdBattleTextBox
; 3c543
Function3c543: ; 3c543
ld a, [IsInBattle]
dec a
jr nz, .Stay
ld a, [PlayerSubStatus5]
bit 7, a
jr nz, .Stay
ld a, [$c731]
and a
jr nz, .Stay
ld a, [EnemyMonStatus]
and 1 << FRZ | SLP
jr nz, .Stay
ld a, [TempEnemyMonSpecies]
ld de, 1
ld hl, AlwaysFleeMons
call IsInArray
jr c, .Flee
call BattleRandom
ld b, a
cp $80
jr nc, .Stay
push bc
ld a, [TempEnemyMonSpecies]
ld de, 1
ld hl, OftenFleeMons
call IsInArray
pop bc
jr c, .Flee
ld a, b
cp $1a
jr nc, .Stay
ld a, [TempEnemyMonSpecies]
ld de, 1
ld hl, SometimesFleeMons
call IsInArray
jr c, .Flee
.Stay
and a
ret
.Flee
scf
ret
; 3c59a
FleeMons:
SometimesFleeMons: ; 3c59a
db MAGNEMITE
db GRIMER
db TANGELA
db MR__MIME
db EEVEE
db PORYGON
db DRATINI
db DRAGONAIR
db TOGETIC
db UMBREON
db UNOWN
db SNUBBULL
db HERACROSS
db -1
OftenFleeMons: ; 3c5a8
db CUBONE
db ARTICUNO
db ZAPDOS
db MOLTRES
db QUAGSIRE
db DELIBIRD
db PHANPY
db TEDDIURSA
db -1
AlwaysFleeMons: ; 3c5b1
db RAIKOU
db ENTEI
; db SUICUNE
db -1
; 3c5b4
CompareMovePriority: ; 3c5b4
; Compare the priority of the player and enemy's moves.
; Return carry if the player goes first, or z if they match.
ld a, [CurPlayerMove]
call GetMovePriority
ld b, a
push bc
ld a, [CurEnemyMove]
call GetMovePriority
pop bc
cp b
ret
; 3c5c5
GetMovePriority: ; 3c5c5
; Return the priority (0-3) of move a.
ld b, a
; Vital throw goes last.
cp VITAL_THROW
ld a, 0
ret z
call GetMoveEffect
ld hl, MoveEffectPriorities
.loop
ld a, [hli]
cp b
jr z, .done
inc hl
cp -1
jr nz, .loop
ld a, 1
ret
.done
ld a, [hl]
ret
; 3c5df
MoveEffectPriorities: ; 3c5df
db EFFECT_PROTECT, 3
db EFFECT_ENDURE, 3
db EFFECT_PRIORITY_HIT, 2
db EFFECT_WHIRLWIND, 0
db EFFECT_COUNTER, 0
db EFFECT_MIRROR_COAT, 0
db -1
; 3c5ec
GetMoveEffect: ; 3c5ec
ld a, b
dec a
ld hl, Moves + MOVE_EFFECT
ld bc, Move2 - Move1
call AddNTimes
ld a, BANK(Moves)
call GetFarByte
ld b, a
ret
; 3c5fe
Function3c5fe: ; 3c5fe
call Function309d
call Function3c543
jp c, Function3c0e5
call SetEnemyTurn
ld a, $1
ld [$c70f], a
callab Function38000
jr c, .asm_3c62f
call Function3c6de
call Function3d2e0
ret c
ld a, [$d232]
and a
ret nz
call Function3c710
jp z, Function3d14e
call Function3c70b
jp z, Function3cd55
.asm_3c62f
call SetEnemyTurn
call Function3c716
jp z, Function3cd55
call RefreshBattleHuds
call Function3c6cf
call Function3d2e0
ret c
ld a, [$d232]
and a
ret nz
call Function3c70b
jp z, Function3cd55
call Function3c710
jp z, Function3d14e
call SetPlayerTurn
call Function3c716
jp z, Function3d14e
call RefreshBattleHuds
xor a
ld [$d0ec], a
ret
; 3c664
Function3c664: ; 3c664
xor a
ld [$c70f], a
call SetEnemyTurn
callab Function38000
push af
call Function3c6cf
pop bc
ld a, [$d232]
and a
ret nz
call Function3d2e0
ret c
call Function3c70b
jp z, Function3cd55
call Function3c710
jp z, Function3d14e
push bc
call SetPlayerTurn
call Function3c716
pop bc
jp z, Function3d14e
push bc
call RefreshBattleHuds
pop af
jr c, .asm_3c6be
call Function309d
call Function3c543
jp c, Function3c0e5
call Function3c6de
call Function3d2e0
ret c
ld a, [$d232]
and a
ret nz
call Function3c710
jp z, Function3d14e
call Function3c70b
jp z, Function3cd55
.asm_3c6be
call SetEnemyTurn
call Function3c716
jp z, Function3cd55
call RefreshBattleHuds
xor a
ld [$d0ec], a
ret
; 3c6cf
Function3c6cf: ; 3c6cf
call SetPlayerTurn
call Function3c6fe
callab DoPlayerTurn
jp Function3c6ed
; 3c6de
Function3c6de: ; 3c6de
call SetEnemyTurn
call Function3c6fe
callab DoEnemyTurn
jp Function3c6ed
; 3c6ed
Function3c6ed: ; 3c6ed
ld a, $5
call _GetBattleVar
res 2, [hl]
res 5, [hl]
ld a, $9
call _GetBattleVar
res 6, [hl]
ret
; 3c6fe
Function3c6fe: ; 3c6fe
ld a, $4
call _GetBattleVar
res 6, [hl]
ret
; 3c706
Function3c706: ; 3c706
ld a, [hBattleTurn]
and a
jr z, Function3c710
Function3c70b: ; 3c70b
ld hl, EnemyMonHPHi
jr Function3c713
Function3c710: ; 3c710
ld hl, BattleMonHP
Function3c713: ; 3c713
ld a, [hli]
or [hl]
ret
; 3c716
Function3c716: ; 3c716
call Function3c706
ret z
ld a, $a
call GetBattleVar
and $18
jr z, .asm_3c768
ld hl, BattleText_0x807e2
ld de, $0106
and $10
jr z, .asm_3c733
ld hl, BattleText_0x807f8
ld de, $0105
.asm_3c733
push de
call StdBattleTextBox
pop de
xor a
ld [$cfca], a
call Function3ee0f
call GetEighthMaxHP
ld de, $c674
ld a, [hBattleTurn]
and a
jr z, .asm_3c74d
ld de, $c67c
.asm_3c74d
ld a, $4
call GetBattleVar
bit 0, a
jr z, .asm_3c765
call Function3cc76
ld a, [de]
inc a
ld [de], a
ld hl, $0000
.asm_3c75f
add hl, bc
dec a
jr nz, .asm_3c75f
ld b, h
ld c, l
.asm_3c765
call Function3cc3f
.asm_3c768
call Function3c706
jp z, .asm_3c7f7
ld a, $3
call _GetBattleVar
bit 7, [hl]
jr z, .asm_3c7a1
call Function3c8e4
xor a
ld [$cfca], a
ld de, $0107
ld a, $7
call GetBattleVar
and $60
call z, Function3ee0f
call Function3c8e4
call GetEighthMaxHP
call Function3cc3f
ld a, $1
ld [hBGMapMode], a
call Function3ccef
ld hl, BattleText_0x8080e
call StdBattleTextBox
.asm_3c7a1
call Function3c706
jr z, .asm_3c7f7
ld a, $0
call _GetBattleVar
bit 0, [hl]
jr z, .asm_3c7c5
xor a
ld [$cfca], a
ld de, $010c
call Function3ee0f
call GetQuarterMaxHP
call Function3cc3f
ld hl, BattleText_0x80822
call StdBattleTextBox
.asm_3c7c5
call Function3c706
jr z, .asm_3c7f7
ld a, $0
call _GetBattleVar
bit 1, [hl]
jr z, .asm_3c7e9
xor a
ld [$cfca], a
ld de, $010c
call Function3ee0f
call GetQuarterMaxHP
call Function3cc3f
ld hl, BattleText_0x80836
call StdBattleTextBox
.asm_3c7e9
ld hl, BattleMonHP
ld a, [hBattleTurn]
and a
jr z, .asm_3c7f4
ld hl, EnemyMonHPHi
.asm_3c7f4
ld a, [hli]
or [hl]
ret nz
.asm_3c7f7
call RefreshBattleHuds
ld c, $14
call DelayFrames
xor a
ret
; 3c801
Function3c801: ; 3c801
ld a, [$ffcb]
cp $1
jr z, .asm_3c813
call SetPlayerTurn
call .asm_3c81c
call SetEnemyTurn
jp .asm_3c81c
.asm_3c813
call SetEnemyTurn
call .asm_3c81c
call SetPlayerTurn
.asm_3c81c
ld hl, PlayerPerishCount
ld a, [hBattleTurn]
and a
jr z, .asm_3c827
ld hl, EnemyPerishCount
.asm_3c827
ld a, $0
call GetBattleVar
bit 4, a
ret z
dec [hl]
ld a, [hl]
ld [$d265], a
push af
ld hl, BattleText_0x80864
call StdBattleTextBox
pop af
ret nz
ld a, $0
call _GetBattleVar
res 4, [hl]
ld a, [hBattleTurn]
and a
jr nz, .asm_3c85c
ld hl, BattleMonHP
xor a
ld [hli], a
ld [hl], a
ld hl, PartyMon1HP
ld a, [CurBattleMon]
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
ret
.asm_3c85c
ld hl, EnemyMonHPHi
xor a
ld [hli], a
ld [hl], a
ld a, [IsInBattle]
dec a
ret z
ld hl, OTPartyMon1HP
ld a, [CurOTMon]
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
ret
; 3c874
Function3c874: ; 3c874
ld a, [$ffcb]
cp $1
jr z, .asm_3c886
call SetPlayerTurn
call .asm_3c88f
call SetEnemyTurn
jp .asm_3c88f
.asm_3c886
call SetEnemyTurn
call .asm_3c88f
call SetPlayerTurn
.asm_3c88f
ld hl, $c730
ld de, $c72e
ld a, [hBattleTurn]
and a
jr z, .asm_3c8a0
ld hl, $c731
ld de, $c72f
.asm_3c8a0
ld a, [hl]
and a
ret z
ld a, $3
call GetBattleVar
bit 4, a
ret nz
ld a, [de]
ld [$d265], a
ld [FXAnimIDLo], a
call GetMoveName
dec [hl]
jr z, .asm_3c8de
ld a, $2
call GetBattleVar
and $60
jr nz, .asm_3c8d3
call Function3c8e4
xor a
ld [$cfca], a
ld [FXAnimIDHi], a
ld a, $37
call Predef
call Function3c8e4
.asm_3c8d3
call Function3cc76
call Function3cc3f
ld hl, BattleText_0x80de2
jr .asm_3c8e1
.asm_3c8de
ld hl, BattleText_0x80df5
.asm_3c8e1
jp StdBattleTextBox
; 3c8e4
Function3c8e4: ; 3c8e4
ld a, [hBattleTurn]
xor $1
ld [hBattleTurn], a
ret
; 3c8eb
Function3c8eb: ; 3c8eb
ld a, [$ffcb]
cp $1
jr z, .asm_3c8fd
call SetPlayerTurn
call .asm_3c906
call SetEnemyTurn
jp .asm_3c906
.asm_3c8fd
call SetEnemyTurn
call .asm_3c906
call SetPlayerTurn
.asm_3c906
callab GetUserItem
ld a, [hl]
ld [$d265], a
call GetItemName
ld a, b
cp HELD_LEFTOVERS
ret nz
ld hl, BattleMonHP
ld a, [hBattleTurn]
and a
jr z, .asm_3c922
ld hl, EnemyMonHPHi
.asm_3c922
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
ld a, [hli]
cp b
jr nz, .asm_3c92d
ld a, [hl]
cp c
ret z
.asm_3c92d
call Function3cc76
call Function3c8e4
call Function3ccef
ld hl, BattleText_0x80880
jp StdBattleTextBox
; 3c93c
Function3c93c: ; 3c93c
ld a, [$ffcb]
cp $1
jr z, .asm_3c94e
call SetPlayerTurn
call .asm_3c957
call SetEnemyTurn
jp .asm_3c957
.asm_3c94e
call SetEnemyTurn
call .asm_3c957
call SetPlayerTurn
.asm_3c957
callab GetUserItem
ld a, b
cp $6
jr nz, .asm_3c9ae
ld hl, PartyMon1PP
ld a, [CurBattleMon]
call GetPartyLocation
ld d, h
ld e, l
ld hl, PartyMon1Move1
ld a, [CurBattleMon]
call GetPartyLocation
ld a, [hBattleTurn]
and a
jr z, .asm_3c99b
ld de, $c739
ld hl, $c735
ld a, [IsInBattle]
dec a
jr z, .asm_3c99b
ld hl, OTPartyMon1PPMove1
ld a, [CurOTMon]
call GetPartyLocation
ld d, h
ld e, l
ld hl, OTPartyMon1Move1
ld a, [CurOTMon]
call GetPartyLocation
.asm_3c99b
ld c, $0
.asm_3c99d
ld a, [hl]
and a
jr z, .asm_3c9ae
ld a, [de]
and $3f
jr z, .asm_3c9af
inc hl
inc de
inc c
ld a, c
cp $4
jr nz, .asm_3c99d
.asm_3c9ae
ret
.asm_3c9af
ld a, [hl]
cp $a6
ld b, $1
jr z, .asm_3c9b8
ld b, $5
.asm_3c9b8
ld a, [de]
add b
ld [de], a
push bc
push bc
ld a, [hl]
ld [$d265], a
ld de, BattleMonItem
ld hl, BattleMonPPMove1
ld a, [hBattleTurn]
and a
jr z, .asm_3c9d2
ld de, EnemyMonItem
ld hl, EnemyMonPPMove1
.asm_3c9d2
inc de
pop bc
ld b, $0
add hl, bc
push hl
ld h, d
ld l, e
add hl, bc
pop de
pop bc
ld a, [$d265]
cp [hl]
jr nz, .asm_3c9f5
ld a, [hBattleTurn]
and a
ld a, [PlayerSubStatus5]
jr z, .asm_3c9ee
ld a, [EnemySubStatus5]
.asm_3c9ee
bit 3, a
jr nz, .asm_3c9f5
ld a, [de]
add b
ld [de], a
.asm_3c9f5
callab GetUserItem
ld a, [hl]
ld [$d265], a
xor a
ld [hl], a
call Function3df12
ld a, [hBattleTurn]
and a
jr z, .asm_3ca12
ld a, [IsInBattle]
dec a
jr z, .asm_3ca14
call Function3df1f
.asm_3ca12
xor a
ld [hl], a
.asm_3ca14
call GetItemName
call Function3c8e4
call Function3ddc8
call Function3c8e4
ld hl, BattleText_0x80899
jp StdBattleTextBox
; 3ca26
Function3ca26: ; 3ca26
ld a, [$ffcb]
cp $1
jr z, .asm_3ca38
call SetPlayerTurn
call .asm_3ca41
call SetEnemyTurn
jp .asm_3ca41
.asm_3ca38
call SetEnemyTurn
call .asm_3ca41
call SetPlayerTurn
.asm_3ca41
ld hl, $c71d
ld a, [hBattleTurn]
and a
jr z, .asm_3ca4c
ld hl, $c71e
.asm_3ca4c
ld a, [hl]
and a
ret z
dec a
ld [hl], a
cp $1
ret nz
ld hl, BattleText_0x808b6
call StdBattleTextBox
ld a, $10
call _GetBattleVar
push af
ld a, $f8
ld [hl], a
callab UpdateMoveData
xor a
ld [AttackMissed], a
ld [AlreadyDisobeyed], a
ld a, $a
ld [TypeModifier], a
callab DoMove
xor a
ld [CurDamage], a
ld [$d257], a
ld a, $10
call _GetBattleVar
pop af
ld [hl], a
call UpdateBattleMonInParty
jp UpdateEnemyMonInParty
; 3ca8f
Function3ca8f: ; 3ca8f
ld a, [$ffcb]
cp $1
jr z, .asm_3ca9a
call .asm_3ca9d
jr .asm_3cac9
.asm_3ca9a
call .asm_3cac9
.asm_3ca9d
ld a, [BattleMonStatus]
bit 5, a
ret z
ld a, [$c73f]
and a
ret nz
call BattleRandom
cp $19
ret nc
xor a
ld [BattleMonStatus], a
ld a, [CurBattleMon]
ld hl, PartyMon1Status
call GetPartyLocation
ld [hl], $0
call UpdateBattleHuds
call SetEnemyTurn
ld hl, DefrostedOpponentText
jp StdBattleTextBox
.asm_3cac9
ld a, [EnemyMonStatus]
bit 5, a
ret z
ld a, [$c740]
and a
ret nz
call BattleRandom
cp $19
ret nc
xor a
ld [EnemyMonStatus], a
ld a, [IsInBattle]
dec a
jr z, .asm_3caef
ld a, [CurOTMon]
ld hl, OTPartyMon1Status
call GetPartyLocation
ld [hl], $0
.asm_3caef
call UpdateBattleHuds
call SetPlayerTurn
ld hl, DefrostedOpponentText
jp StdBattleTextBox
; 3cafb
Function3cafb: ; 3cafb
ld a, [$ffcb]
cp $1
jr z, .asm_3cb06
call .asm_3cb09
jr .asm_3cb1c
.asm_3cb06
call .asm_3cb1c
.asm_3cb09
ld a, [PlayerScreens]
bit 2, a
ret z
ld hl, $c701
dec [hl]
ret nz
res 2, a
ld [PlayerScreens], a
xor a
jr .asm_3cb2e
.asm_3cb1c
ld a, [EnemyScreens]
bit 2, a
ret z
ld hl, $c705
dec [hl]
ret nz
res 2, a
ld [EnemyScreens], a
ld a, $1
.asm_3cb2e
ld [hBattleTurn], a
ld hl, BattleText_0x808d2
jp StdBattleTextBox
; 3cb36
Function3cb36: ; 3cb36
ld a, [$ffcb]
cp 1
jr z, .Both
call .CheckPlayer
jr .CheckEnemy
.Both
call .CheckEnemy
.CheckPlayer
call SetPlayerTurn
ld de, .Your
call .asm_3cb6f
ld hl, PlayerScreens
ld de, PlayerLightScreenCount
jr .FadeScreens
.CheckEnemy
call SetEnemyTurn
ld de, .Enemy
call .asm_3cb6f
ld hl, EnemyScreens
ld de, EnemyLightScreenCount
.FadeScreens
bit SCREENS_LIGHT_SCREEN, [hl]
call nz, FadeLightScreen
bit SCREENS_REFLECT, [hl]
call nz, FadeReflect
ret
.asm_3cb6f
ld hl, StringBuffer1
jp CopyName2
; 3cb75
.Your
db "Your@"
.Enemy
db "Enemy@"
; 3cb80
FadeLightScreen: ; 3cb80
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_LIGHT_SCREEN, [hl]
push hl
push de
ld hl, BattleText_0x808e7
call StdBattleTextBox
pop de
pop hl
ret
; 3cb91
FadeReflect: ; 3cb91
inc de
ld a, [de]
dec a
ld [de], a
ret nz
res SCREENS_REFLECT, [hl]
ld hl, BattleText_0x80905
jp StdBattleTextBox
; 3cb9e
HandleWeather: ; 3cb9e
ld a, [Weather]
cp 0
ret z
ld hl, WeatherCount
dec [hl]
jr z, .asm_3cc13
ld hl, .WeatherMessages
call .asm_3cc1e
ld a, [Weather]
cp WEATHER_SANDSTORM
ret nz
ld a, [$ffcb]
cp 1
jr z, .asm_3cbc7
; Player first
call SetPlayerTurn
call .asm_3cbd0
call SetEnemyTurn
jr .asm_3cbd0
.asm_3cbc7
; Enemy first
call SetEnemyTurn
call .asm_3cbd0
call SetPlayerTurn
.asm_3cbd0
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
bit SUBSTATUS_UNDERGROUND, a
ret nz
ld hl, BattleMonType1
ld a, [hBattleTurn]
and a
jr z, .asm_3cbe3
ld hl, EnemyMonType1
.asm_3cbe3
ld a, [hli]
cp ROCK
ret z
cp GROUND
ret z
cp STEEL
ret z
ld a, [hl]
cp ROCK
ret z
cp GROUND
ret z
cp STEEL
ret z
call Function3c8e4
xor a
ld [$cfca], a
ld de, $010b
call Function3ee17
call Function3c8e4
call GetEighthMaxHP
call Function3cc3f
ld hl, BattleText_0x8084d
jp StdBattleTextBox
.asm_3cc13
ld hl, .WeatherEndedMessages
call .asm_3cc1e
xor a
ld [Weather], a
ret
.asm_3cc1e
ld a, [Weather]
dec a
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp StdBattleTextBox
; 3cc2d
.WeatherMessages
dw BattleText_0x8091f
dw BattleText_0x80938
dw BattleText_0x80951
.WeatherEndedMessages
dw BattleText_0x80967
dw BattleText_0x8097a
dw BattleText_0x8098f
; 3cc39
Function3cc39: ; 3cc39
call Function3cc45
jp Function3cd3c
; 3cc3f
Function3cc3f: ; 3cc3f
call Function3cc45
jp Function3cd36
; 3cc45
Function3cc45: ; 3cc45
ld hl, BattleMonHP
ld a, [hBattleTurn]
and a
jr z, .asm_3cc50
ld hl, EnemyMonHPHi
.asm_3cc50
inc hl
ld a, [hl]
ld [$d1ec], a
sub c
ld [hld], a
ld [$d1ee], a
ld a, [hl]
ld [$d1ed], a
sbc b
ld [hl], a
ld [$d1ef], a
ret nc
ld a, [$d1ec]
ld c, a
ld a, [$d1ed]
ld b, a
xor a
ld [hli], a
ld [hl], a
ld [$d1ee], a
ld [$d1ef], a
ret
; 3cc76
Function3cc76: ; 3cc76
call GetQuarterMaxHP
srl c
srl c
ld a, c
and a
jr nz, .asm_3cc82
inc c
.asm_3cc82
ret
; 3cc83
GetEighthMaxHP: ; 3cc83
; output: bc
call GetQuarterMaxHP
; assumes nothing can have 1024 or more hp
; halve result
srl c
; round up
ld a, c
and a
jr nz, .end
inc c
.end
ret
; 3cc8e
GetQuarterMaxHP: ; 3cc8e
; output: bc
call GetMaxHP
; quarter result
srl b
rr c
srl b
rr c
; assumes nothing can have 1024 or more hp
; round up
ld a, c
and a
jr nz, .end
inc c
.end
ret
; 3cc9f
GetHalfMaxHP: ; 3cc9f
; output: bc
call GetMaxHP
; halve reslut
srl b
rr c
; floor = 1
ld a, c
or b
jr nz, .end
inc c
.end
ret
; 3ccac
GetMaxHP: ; 3ccac
; output: bc, Buffer1-2
; player
ld hl, BattleMonMaxHP
; whose turn?
ld a, [hBattleTurn]
and a
jr z, .gethp
; enemy
ld hl, EnemyMonMaxHP
.gethp
ld a, [hli]
ld [Buffer2], a
ld b, a
ld a, [hl]
ld [Buffer1], a
ld c, a
ret
; 3ccc2
Function3ccc2: ; 3ccc2
ld hl, BattleMonHP
ld a, [hBattleTurn]
and a
jr z, .asm_3cccd
ld hl, EnemyMonHP
.asm_3cccd
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
srl b
rr c
ld a, [hli]
ld [Buffer2], a
ld a, [hl]
ld [Buffer1], a
ret
; 3ccde
Function3ccde: ; 3ccde
ld hl, BattleMonHP + 1
ld a, [hBattleTurn]
and a
jr z, .asm_3cce9
ld hl, EnemyMonHP + 1
.asm_3cce9
ld a, c
sub [hl]
dec hl
ld a, b
sbc [hl]
ret
; 3ccef
Function3ccef: ; 3ccef
ld hl, EnemyMonMaxHP
ld a, [hBattleTurn]
and a
jr z, .asm_3ccfa
ld hl, BattleMonMaxHP
.asm_3ccfa
ld a, [hli]
ld [Buffer2], a
ld a, [hld]
ld [Buffer1], a
dec hl
ld a, [hl]
ld [$d1ec], a
add c
ld [hld], a
ld [$d1ee], a
ld a, [hl]
ld [$d1ed], a
adc b
ld [hli], a
ld [$d1ef], a
ld a, [Buffer1]
ld c, a
ld a, [hld]
sub c
ld a, [Buffer2]
ld b, a
ld a, [hl]
sbc b
jr c, .asm_3cd2d
ld a, b
ld [hli], a
ld [$d1ef], a
ld a, c
ld [hl], a
ld [$d1ee], a
.asm_3cd2d
call Function3c8e4
call Function3cd36
jp Function3c8e4
; 3cd36
Function3cd36: ; 3cd36
call Function3cd3c
jp UpdateBattleHuds
; 3cd3c
Function3cd3c: ; 3cd3c
ld hl, $c55e
ld a, [hBattleTurn]
and a
ld a, $1
jr z, .asm_3cd4a
ld hl, $c4ca
xor a
.asm_3cd4a
push bc
ld [$d10a], a
ld a, $b
call Predef
pop bc
ret
; 3cd55
Function3cd55: ; 3cd55
call Function3cf14
ld hl, BattleMonHP
ld a, [hli]
or [hl]
call z, Function3cef1
xor a
ld [$c6f7], a
call Function3ce01
call Function3d873
ld a, d
and a
jp z, LostBattle
ld hl, BattleMonHP
ld a, [hli]
or [hl]
call nz, Function3df48
ld a, $1
ld [hBGMapMode], a
ld c, $3c
call DelayFrames
ld a, [IsInBattle]
dec a
jr nz, .asm_3cd8c
ld a, $1
ld [BattleEnded], a
ret
.asm_3cd8c
call Function3cf35
jp z, Function3cfa4
ld hl, BattleMonHP
ld a, [hli]
or [hl]
jr nz, .asm_3cdba
call Function3d1f8
jr nc, .asm_3cda4
ld a, $1
ld [BattleEnded], a
ret
.asm_3cda4
call Function3d227
call Function3d2e0
jp c, Function3c0e5
ld a, $1
ld [$d0ec], a
call Function3cf4a
jp z, Function3c0e5
jr Function3cdca
.asm_3cdba
ld a, $1
ld [$d0ec], a
call Function3cf4a
jp z, Function3c0e5
xor a
ld [$d0ec], a
ret
; 3cdca
Function3cdca: ; 3cdca
ld a, [$ffcb]
cp $1
jr z, .asm_3cde6
call ClearSprites
ld hl, $c4a1
ld bc, $040a
call ClearBox
call Function3d2b3
ld a, $1
call EnemyPartyMonEntrance
jr .asm_3cdfc
.asm_3cde6
ld a, [CurPartyMon]
push af
ld a, $1
call EnemyPartyMonEntrance
call ClearSprites
call Function309d
pop af
ld [CurPartyMon], a
call Function3d2b3
.asm_3cdfc
xor a
ld [$d0ec], a
ret
; 3ce01
Function3ce01: ; 3ce01
call UpdateBattleMonInParty
ld a, [IsInBattle]
dec a
jr z, .asm_3ce16
ld a, [CurOTMon]
ld hl, OTPartyMon1HP
call GetPartyLocation
xor a
ld [hli], a
ld [hl], a
.asm_3ce16
ld hl, PlayerSubStatus3
res 2, [hl]
xor a
ld hl, EnemyDamageTaken
ld [hli], a
ld [hl], a
call NewEnemyMonStatus
call BreakAttraction
ld a, [IsInBattle]
dec a
jr z, .asm_3ce2f
jr .asm_3ce37
.asm_3ce2f
call Function3ceec
ld a, $1
ld [$c6fd], a
.asm_3ce37
ld hl, BattleMonHP
ld a, [hli]
or [hl]
jr nz, .asm_3ce47
ld a, [$c6f7]
and a
jr nz, .asm_3ce47
call Function3d1aa
.asm_3ce47
call Function3d873
ld a, d
and a
ret z
ld a, [IsInBattle]
dec a
call z, Function3d0ea
call EmptyBattleTextBox
call Function309d
ld a, [$d0ee]
and $c0
ld [$d0ee], a
call Function3ceaa
jr z, .asm_3ce72
ld hl, EnemyMonBaseStats
ld b, $7
.asm_3ce6c
srl [hl]
inc hl
dec b
jr nz, .asm_3ce6c
.asm_3ce72
ld hl, EnemyMonBaseStats
ld de, $c720
ld bc, $0007
call CopyBytes
xor a
ld [$c71f], a
call Function3ee3b
call Function3ceaa
ret z
ld a, [$c664]
push af
ld a, d
ld [$c664], a
ld hl, $c720
ld de, EnemyMonBaseStats
ld bc, $0007
call CopyBytes
ld a, $1
ld [$c71f], a
call Function3ee3b
pop af
ld [$c664], a
ret
; 3ceaa
Function3ceaa: ; 3ceaa
ld a, [PartyCount]
ld b, a
ld hl, PartyMon1Species
ld c, $1
ld d, $0
.asm_3ceb5
push hl
push bc
ld bc, $0022
add hl, bc
ld a, [hli]
or [hl]
pop bc
pop hl
jr z, .asm_3ced1
push hl
push bc
ld bc, $0001
add hl, bc
pop bc
ld a, [hl]
pop hl
cp $39
jr nz, .asm_3ced1
ld a, d
or c
ld d, a
.asm_3ced1
sla c
push de
ld de, $0030
add hl, de
pop de
dec b
jr nz, .asm_3ceb5
ld a, d
ld e, $0
ld b, $6
.asm_3cee1
srl a
jr nc, .asm_3cee6
inc e
.asm_3cee6
dec b
jr nz, .asm_3cee1
ld a, e
and a
ret
; 3ceec
Function3ceec: ; 3ceec
xor a
ld [Danger], a
ret
; 3cef1
Function3cef1: ; 3cef1
call Function3ceec
call WaitSFX
ld a, $f0
ld [CryTracks], a
ld a, [BattleMonSpecies]
call Function37b6
call Function3d43b
ld hl, $c535
ld bc, $050b
call ClearBox
ld hl, BattleText_0x80a75
jp StdBattleTextBox
; 3cf14
Function3cf14: ; 3cf14
call WaitSFX
ld de, SFX_KINESIS
call PlaySFX
call Function3d432
ld de, SFX_UNKNOWN_2A
call PlaySFX
hlcoord 1, 0
ld bc, $040a
call ClearBox
ld hl, BattleText_0x809a8
jp StdBattleTextBox
; 3cf35
Function3cf35: ; 3cf35
ld a, [OTPartyCount]
ld b, a
xor a
ld hl, OTPartyMon1HP
ld de, $0030
.asm_3cf40
or [hl]
inc hl
or [hl]
dec hl
add hl, de
dec b
jr nz, .asm_3cf40
and a
ret
; 3cf4a
Function3cf4a: ; 3cf4a
ld hl, EnemyHPPal
ld e, $30
call Function3e12e
call WaitBGMap
callba Function2c012
ld a, [InLinkBattle]
and a
jr z, .asm_3cf6d
call Function3e8e4
ld a, [$d430]
cp $f
ret z
call Function30b4
.asm_3cf6d
ld hl, BattleMonHP
ld a, [hli]
or [hl]
ld a, $0
jr nz, EnemyPartyMonEntrance
inc a
ret
; 3cf78
EnemyPartyMonEntrance: ; 3cf78
push af
xor a
ld [$c718], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
pop af
and a
jr nz, .asm_3cf8f
call Function3d4e1
jr .asm_3cf92
.asm_3cf8f
call Function3d517
.asm_3cf92
call Function3d57a
call SetEnemyTurn
call SpikesDamage
xor a
ld [EnemyMoveAnimation], a
ld [$d0ec], a
inc a
ret
; 3cfa4
Function3cfa4: ; 3cfa4
call Function3ceec
ld a, $1
ld [$c6fd], a
ld [BattleEnded], a
ld a, [InLinkBattle]
and a
ld a, b
call z, Function3d0ea
callab Function39939
ld hl, BattleText_0x809da
call StdBattleTextBox
call Function3d2f1
jr z, .asm_3cff5
ld a, [InLinkBattle]
and a
ret nz
ld a, [$cfc0]
bit 0, a
jr nz, .asm_3d006
call Function3ebd8
ld c, $28
call DelayFrames
ld a, [BattleType]
cp $1
jr nz, .asm_3cfe8
ld a, $2
call Predef
.asm_3cfe8
ld a, [$c2cc]
bit 0, a
jr nz, .asm_3cff2
call Function3718
.asm_3cff2
jp Function3d02b
.asm_3cff5
call Function3ebd8
ld c, $28
call DelayFrames
ld c, $4
callba Function4ea0a
ret
.asm_3d006
call Function3ebd8
ld c, $28
call DelayFrames
call EmptyBattleTextBox
ld c, $3
callba Function11c000
call Functiona80
ld hl, $c6ec
ld a, [hli]
or [hl]
inc hl
or [hl]
ret nz
call ClearTileMap
call WhiteBGMap
ret
; 3d02b
Function3d02b: ; 3d02b
ld a, [$c73d]
and a
call nz, Function3d099
call Function3d0b1
push af
ld a, $0
jr nc, .asm_3d044
ld a, [$d854]
and $7
cp $3
jr nz, .asm_3d044
inc a
.asm_3d044
ld b, a
ld c, $4
.asm_3d047
ld a, b
and a
jr z, .asm_3d052
call Function3d081
dec c
dec b
jr .asm_3d047
.asm_3d052
ld a, c
and a
jr z, .asm_3d05c
call Function3d08d
dec c
jr .asm_3d052
.asm_3d05c
call Function3d099
call Function3d099
pop af
jr nc, .asm_3d07b
ld a, [$d854]
and $7
jr z, .asm_3d07b
ld hl, SentToMomTexts
dec a
ld c, a
ld b, 0
add hl, bc
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp StdBattleTextBox
.asm_3d07b
ld hl, BattleText_0x809be
jp StdBattleTextBox
; 3d081
Function3d081: ; 3d081
push bc
ld hl, $c688
ld de, $d853
call Function3d0be
pop bc
ret
; 3d08d
Function3d08d: ; 3d08d
push bc
ld hl, $c688
ld de, $d850
call Function3d0be
pop bc
ret
; 3d099
Function3d099: ; 3d099
ld hl, $c688
sla [hl]
dec hl
rl [hl]
dec hl
rl [hl]
ret nc
ld a, $ff
ld [hli], a
ld [hli], a
ld [hl], a
ret
; 3d0ab
SentToMomTexts: ; 3d0ab
dw BattleText_0x809fc
dw BattleText_0x80a2a
dw BattleText_0x80a3d
; 3d0b1
Function3d0b1: ; 3d0b1
ld hl, $d853
ld a, [hld]
cp $3f
ld a, [hld]
sbc $42
ld a, [hl]
sbc $f
ret
; 3d0be
Function3d0be: ; 3d0be
ld c, $3
and a
push de
push hl
push bc
ld b, h
ld c, l
callba Function106008
pop bc
pop hl
.asm_3d0ce
ld a, [de]
adc [hl]
ld [de], a
dec de
dec hl
dec c
jr nz, .asm_3d0ce
pop hl
ld a, [hld]
cp $3f
ld a, [hld]
sbc $42
ld a, [hl]
sbc $f
ret c
ld [hl], $f
inc hl
ld [hl], $42
inc hl
ld [hl], $3f
ret
; 3d0ea
Function3d0ea: ; 3d0ea
push de
ld de, MUSIC_NONE
call PlayMusic
call DelayFrame
ld de, MUSIC_WILD_VICTORY
ld a, [IsInBattle]
dec a
jr nz, .asm_3d113
push de
call Function3ceaa
pop de
jr nz, .asm_3d11e
ld hl, $c6ec
ld a, [hli]
or [hl]
jr nz, .asm_3d11e
ld a, [$c664]
and a
jr z, .asm_3d121
jr .asm_3d11e
.asm_3d113
ld de, MUSIC_GYM_VICTORY
call IsJohtoGymLeader
jr c, .asm_3d11e
ld de, MUSIC_TRAINER_VICTORY
.asm_3d11e
call PlayMusic
.asm_3d121
pop de
ret
; 3d123
; These functions check if the current opponent is a gym leader or one of a
; few other special trainers.
; Note: KantoGymLeaders is a subset of JohtoGymLeaders. If you wish to
; differentiate between the two, call IsKantoGymLeader first.
; The Lance and Red entries are unused for music checks; those trainers are
; accounted for elsewhere.
IsKantoGymLeader: ; 0x3d123
ld hl, KantoGymLeaders
jr IsGymLeaderCommon
IsJohtoGymLeader: ; 0x3d128
ld hl, JohtoGymLeaders
IsGymLeaderCommon:
push de
ld a, [OtherTrainerClass]
ld de, $0001
call IsInArray
pop de
ret
; 0x3d137
JohtoGymLeaders:
db FALKNER
db WHITNEY
db BUGSY
db MORTY
db PRYCE
db JASMINE
db CHUCK
db CLAIR
db WILL
db BRUNO
db KAREN
db KOGA
; fallthrough
; these two entries are unused
db CHAMPION
db RED
; fallthrough
KantoGymLeaders:
db BROCK
db MISTY
db LT_SURGE
db ERIKA
db JANINE
db SABRINA
db BLAINE
db BLUE
db $ff
Function3d14e: ; 3d14e
call Function3cef1
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
call z, Function3cf14
ld a, $1
ld [$c6f7], a
call Function3d1aa
call Function3d873
ld a, d
and a
jp z, LostBattle
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
jr nz, .asm_3d185
call Function3ce01
ld a, [IsInBattle]
dec a
jr nz, .asm_3d17f
ld a, $1
ld [BattleEnded], a
ret
.asm_3d17f
call Function3cf35
jp z, Function3cfa4
.asm_3d185
call Function3d1f8
jr nc, .asm_3d190
ld a, $1
ld [BattleEnded], a
ret
.asm_3d190
call Function3d227
call Function3d2e0
jp c, Function3c0e5
ld a, c
and a
ret nz
ld a, $1
ld [$d0ec], a
call Function3cf4a
jp z, Function3c0e5
jp Function3cdca
; 3d1aa
Function3d1aa: ; 3d1aa
ld a, [CurBattleMon]
ld c, a
ld hl, $c664
ld b, $0
ld a, $3
call Predef
ld hl, EnemySubStatus3
res 2, [hl]
xor a
ld [Danger], a
ld hl, PlayerDamageTaken
ld [hli], a
ld [hl], a
ld [BattleMonStatus], a
call UpdateBattleMonInParty
ld c, $6
ld a, [BattleMonLevel]
add $1e
ld b, a
ld a, [EnemyMonLevel]
cp b
jr c, .asm_3d1dc
ld c, $8
.asm_3d1dc
ld a, [CurBattleMon]
ld [CurPartyMon], a
callab ChangeHappiness
ld a, [$d0ee]
and $c0
add $1
ld [$d0ee], a
ld a, [$c6f7]
and a
ret z
ret
; 3d1f8
Function3d1f8: ; 3d1f8
call EmptyBattleTextBox
call Function309d
ld a, [IsInBattle]
and a
dec a
ret nz
ld hl, BattleText_0x80a83
call StdBattleTextBox
.asm_3d20a
lb bc, 1, 7
call PlaceYesNoBox
ld a, [$cfa9]
jr c, .asm_3d217
and a
ret
.asm_3d217
ld a, [$cfa9]
cp $1
jr z, .asm_3d20a
ld hl, PartyMon1Speed
ld de, EnemyMonSpd
jp Function3d8b3
; 3d227
Function3d227: ; 3d227
call EmptyBattleTextBox
call Function1d6e
call Function3d2f7
call ForcePickPartyMonInBattle
ld a, [InLinkBattle]
and a
jr z, .asm_3d241
ld a, $1
ld [$d0ec], a
call Function3e8e4
.asm_3d241
xor a
ld [$d0ec], a
call Function3d2e0
jr c, .asm_3d251
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
jr nz, .asm_3d26c
.asm_3d251
call ClearSprites
call WhiteBGMap
call Function3eda6
call Function1c07
call Function309d
call WaitBGMap
call ClearSGB
call Function32f9
xor a
ld c, a
ret
.asm_3d26c
call ClearSprites
ld a, [CurBattleMon]
ld [$c71a], a
ld a, [CurPartyMon]
ld [CurBattleMon], a
call Function3d581
call Function3da0d
call ResetPlayerStatLevels
call ClearPalettes
call DelayFrame
call Function3eda6
call Function1c17
call ClearSGB
call Function32f9
call Function3f26d
call NewBattleMonStatus
call BreakAttraction
call Function3db5f
call EmptyBattleTextBox
call Function309d
call SetPlayerTurn
call SpikesDamage
ld a, $1
and a
ld c, a
ret
; 3d2b3
Function3d2b3: ; 3d2b3
ld a, [CurBattleMon]
ld [$c71a], a
ld a, [CurPartyMon]
ld [CurBattleMon], a
call Function3d581
call Function3da0d
call ResetPlayerStatLevels
call Function3f26d
call NewBattleMonStatus
call BreakAttraction
call Function3db5f
call EmptyBattleTextBox
call Function309d
call SetPlayerTurn
jp SpikesDamage
; 3d2e0
Function3d2e0: ; 3d2e0
ld a, [InLinkBattle]
cp $4
jr nz, .asm_3d2ef
ld a, [$cd2b]
and a
jr z, .asm_3d2ef
scf
ret
.asm_3d2ef
xor a
ret
; 3d2f1
Function3d2f1: ; 3d2f1
ld a, [InLinkBattle]
cp $4
ret
; 3d2f7
Function3d2f7: ; 3d2f7
call WhiteBGMap
Function3d2fa: ; 3d2fa
callba Function5004f
callba Function50405
callba Function8e85
callba Function503e0
ret
; 3d313
Function3d313: ; 3d313
callba WritePartyMenuTilemap
callba PrintPartyMenuText
call WaitBGMap
call Function32f9
call DelayFrame
ret
; 3d329
Function3d329: ; 3d329
call Function3d2f1
jr z, .asm_3d335
callba PartyMenuSelect
ret
.asm_3d335
callba Function100cb5
ret
; 3d33c
PickPartyMonInBattle: ; 3d33c
.asm_3d33c
ld a, $2 ; Which PKMN?
ld [PartyMenuActionText], a
call Function3d313
call Function3d329
ret c
call Function3d887
jr z, .asm_3d33c
xor a
ret
; 3d34f
SwitchMonAlreadyOut: ; 3d34f
ld hl, CurBattleMon
ld a, [CurPartyMon]
cp [hl]
jr nz, .notout
ld hl, BattleText_0x80c0d
call StdBattleTextBox
scf
ret
.notout
xor a
ret
; 3d362
ForcePickPartyMonInBattle: ; 3d362
; Can't back out.
.pick
call PickPartyMonInBattle
ret nc
call Function3d2e0
ret c
ld de, SFX_WRONG
call PlaySFX
call WaitSFX
jr .pick
; 3d375
PickSwitchMonInBattle: ; 3d375
.pick
call PickPartyMonInBattle
ret c
call SwitchMonAlreadyOut
jr c, .pick
xor a
ret
; 3d380
ForcePickSwitchMonInBattle: ; 3d380
; Can't back out.
.pick
call ForcePickPartyMonInBattle
call Function3d2e0
ret c
call SwitchMonAlreadyOut
jr c, .pick
xor a
ret
; 3d38e
LostBattle: ; 3d38e
ld a, 1
ld [BattleEnded], a
ld a, [$cfc0]
bit 0, a
jr nz, .asm_3d3bd
ld a, [BattleType]
cp BATTLETYPE_CANLOSE
jr nz, .asm_3d3e3
; Remove the enemy from the screen.
hlcoord 0, 0
ld bc, $0815
call ClearBox
call Function3ebd8
ld c, 40
call DelayFrames
ld a, [$c2cc]
bit 0, a
jr nz, .asm_3d3bc
call Function3718
.asm_3d3bc
ret
.asm_3d3bd
; Remove the enemy from the screen.
hlcoord 0, 0
ld bc, $0815
call ClearBox
call Function3ebd8
ld c, 40
call DelayFrames
call EmptyBattleTextBox
ld c, 2
callba Function11c000
call Functiona80
call ClearTileMap
call WhiteBGMap
ret
.asm_3d3e3
ld a, [InLinkBattle]
and a
jr nz, .LostLinkBattle
; Greyscale
ld b, 0
call GetSGBLayout
call Function32f9
jr .end
.LostLinkBattle
call UpdateEnemyMonInParty
call Function3cf35
jr nz, .asm_3d40a
ld hl, TiedAgainstText
ld a, [$d0ee]
and $c0
add 2
ld [$d0ee], a
jr .asm_3d412
.asm_3d40a
ld hl, LostAgainstText
call Function3d2f1
jr z, .asm_3d417
.asm_3d412
call StdBattleTextBox
.end
scf
ret
.asm_3d417
; Remove the enemy from the screen.
hlcoord 0, 0
ld bc, $0815
call ClearBox
call Function3ebd8
ld c, 40
call DelayFrames
ld c, $3
callba Function4ea0a
scf
ret
; 3d432
Function3d432: ; 3d432
ld hl, $c510
ld de, $c524
jp Function3d444
; 3d43b
Function3d43b: ; 3d43b
ld hl, $c569
ld de, $c57d
jp Function3d444
; 3d444
Function3d444: ; 3d444
ld a, [$cfbe]
push af
set 6, a
ld [$cfbe], a
ld b, $7
.asm_3d44f
push bc
push de
push hl
ld b, $6
.asm_3d454
push bc
push hl
push de
ld bc, $0007
call CopyBytes
pop de
pop hl
ld bc, -20
add hl, bc
push hl
ld h, d
ld l, e
add hl, bc
ld d, h
ld e, l
pop hl
pop bc
dec b
jr nz, .asm_3d454
ld bc, 20
add hl, bc
ld de, .Spaces
call PlaceString
ld c, 2
call DelayFrames
pop hl
pop de
pop bc
dec b
jr nz, .asm_3d44f
pop af
ld [$cfbe], a
ret
; 3d488
.Spaces
db " @"
; 3d490
Function3d490: ; 3d490
ld [hConnectionStripLength], a
ld c, a
.asm_3d493
push bc
push hl
ld b, $7
.asm_3d497
push hl
call Function3d4ae
pop hl
ld de, 20
add hl, de
dec b
jr nz, .asm_3d497
ld c, 2
call DelayFrames
pop hl
pop bc
dec c
jr nz, .asm_3d493
ret
; 3d4ae
Function3d4ae: ; 3d4ae
ld a, [hConnectionStripLength]
ld c, a
cp $8
jr nz, .asm_3d4bc
.asm_3d4b5
ld a, [hli]
ld [hld], a
dec hl
dec c
jr nz, .asm_3d4b5
ret
.asm_3d4bc
ld a, [hld]
ld [hli], a
inc hl
dec c
jr nz, .asm_3d4bc
ret
; 3d4c3
Function3d4c3: ; 3d4c3
call Function3d557
ld a, [$c718]
dec a
ld b, a
call Function3d6ca
call Function3d7a0
call NewEnemyMonStatus
call ResetEnemyStatLevels
call Function3d7c7
call BreakAttraction
call Function3d57a
ret
; 3d4e1
Function3d4e1: ; 3d4e1
call Function3d714
jr nc, Function3d517
call Function3d557
call Function3d533
jr c, .asm_3d4f1
call Function3d599
.asm_3d4f1
call Function3d6ca
call Function3d74b
push af
call Function3d7a0
call Function3d7b8
call Function3d7c7
pop af
ret c
xor a
ld [$c664], a
ld [$c6fc], a
ld [$d0ec], a
inc a
ld [$c711], a
call Function309d
jp Function3e3ad
; 3d517
Function3d517: ; 3d517
call Function3d557
call Function3d533
jr c, .asm_3d522
call Function3d599
.asm_3d522
call Function3d6ca
ld a, $1
ld [$c711], a
call Function3d7a0
call Function3d7b8
jp Function3d7c7
; 3d533
Function3d533: ; 3d533
ld a, [InLinkBattle]
and a
jr z, .asm_3d541
ld a, [$d430]
sub $4
ld b, a
jr .asm_3d555
.asm_3d541
ld a, [$c718]
and a
jr z, .asm_3d54b
dec a
ld b, a
jr .asm_3d555
.asm_3d54b
ld a, [$d264]
and a
ld b, $0
jr nz, .asm_3d555
and a
ret
.asm_3d555
scf
ret
; 3d557
Function3d557: ; 3d557
xor a
ld [LastEnemyCounterMove], a
ld [LastPlayerCounterMove], a
ld [LastEnemyMove], a
ld [CurEnemyMove], a
dec a
ld [$c6e6], a
xor a
ld [$c730], a
ld hl, $c4b2
ld a, $8
call Function3d490
call EmptyBattleTextBox
jp Function1d6e
; 3d57a
Function3d57a: ; 3d57a
xor a
ld [$c664], a
ld [$c6fc], a
Function3d581: ; 3d581
ld a, [CurBattleMon]
ld c, a
ld hl, $c664
ld b, $1
push bc
ld a, $3
call Predef
pop bc
ld hl, $c6fc
ld a, $3
jp Predef
; 3d599
Function3d599: ; 3d599
ld b, $ff
ld a, $1
ld [Buffer1], a
ld [Buffer2], a
.asm_3d5a3
ld hl, Buffer1
sla [hl]
inc hl
sla [hl]
inc b
ld a, [OTPartyCount]
cp b
jp z, Function3d672
ld a, [CurOTMon]
cp b
jr z, .asm_3d5d0
ld hl, OTPartyMon1HP
push bc
ld a, b
call GetPartyLocation
ld a, [hli]
ld c, a
ld a, [hl]
or c
pop bc
jr z, .asm_3d5d0
call Function3d5d7
call Function3d618
jr .asm_3d5a3
.asm_3d5d0
ld hl, Buffer2
set 0, [hl]
jr .asm_3d5a3
; 3d5d7
Function3d5d7: ; 3d5d7
push bc
ld hl, OTPartyMon1Move1
ld a, b
call GetPartyLocation
pop bc
ld e, $5
.asm_3d5e2
dec e
jr z, .asm_3d617
ld a, [hli]
and a
jr z, .asm_3d617
push hl
push de
push bc
dec a
ld hl, Moves + MOVE_ANIM
ld bc, Move2 - Move1
call AddNTimes
ld de, EnemyMoveAnimation
ld a, BANK(Moves)
call FarCopyBytes
call SetEnemyTurn
callab Function347c8
pop bc
pop de
pop hl
ld a, [$d265]
cp $b
jr c, .asm_3d5e2
ld hl, Buffer1
set 0, [hl]
ret
.asm_3d617
ret
; 3d618
Function3d618: ; 3d618
push bc
ld hl, OTPartyCount
ld a, b
inc a
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
dec a
ld hl, BaseData + 7 ; type
ld bc, $20
call AddNTimes
ld de, EnemyMonType1
ld bc, 2
ld a, BANK(BaseData)
call FarCopyBytes
ld a, [BattleMonType1]
ld [PlayerMoveType], a
call SetPlayerTurn
callab Function347c8
ld a, [$d265]
cp $b
jr nc, .asm_3d663
ld a, [BattleMonType2]
ld [PlayerMoveType], a
callab Function347c8
ld a, [$d265]
cp $b
jr nc, .asm_3d663
pop bc
ret
.asm_3d663
pop bc
ld hl, Buffer1
bit 0, [hl]
jr nz, .asm_3d66f
inc hl
set 0, [hl]
ret
.asm_3d66f
res 0, [hl]
ret
; 3d672
Function3d672: ; 3d672
.asm_3d672
ld hl, Buffer1
sla [hl]
inc hl
sla [hl]
jr nc, .asm_3d672
ld a, [OTPartyCount]
ld b, a
ld c, [hl]
.asm_3d681
sla c
jr nc, .asm_3d68a
dec b
jr z, .asm_3d6a7
jr .asm_3d681
.asm_3d68a
ld a, [Buffer1]
and a
jr z, .asm_3d69a
ld b, $ff
ld c, a
.asm_3d693
inc b
sla c
jr nc, .asm_3d693
jr .asm_3d6c9
.asm_3d69a
ld b, $ff
ld a, [Buffer2]
ld c, a
.asm_3d6a0
inc b
sla c
jr c, .asm_3d6a0
jr .asm_3d6c9
.asm_3d6a7
ld a, [OTPartyCount]
ld b, a
call BattleRandom
and $7
cp b
jr nc, .asm_3d6a7
ld b, a
ld a, [CurOTMon]
cp b
jr z, .asm_3d6a7
ld hl, OTPartyMon1HP
push bc
ld a, b
call GetPartyLocation
pop bc
ld a, [hli]
ld c, a
ld a, [hl]
or c
jr z, .asm_3d6a7
.asm_3d6c9
ret
; 3d6ca
Function3d6ca: ; 3d6ca
ld a, b
ld [CurPartyMon], a
ld hl, OTPartyMon1Level
call GetPartyLocation
ld a, [hl]
ld [CurPartyLevel], a
ld a, [CurPartyMon]
inc a
ld hl, OTPartyCount
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
ld [TempEnemyMonSpecies], a
ld [CurPartySpecies], a
call LoadEnemyMon
ld a, [CurPartySpecies]
cp UNOWN
jr nz, .asm_3d708
ld a, [$def4]
and a
jr nz, .asm_3d708
ld hl, EnemyMonAtkDefDV
ld a, $2d
call Predef
ld a, [UnownLetter]
ld [$def4], a
.asm_3d708
ld hl, EnemyMonHPHi
ld a, [hli]
ld [$c6ea], a
ld a, [hl]
ld [$c6eb], a
ret
; 3d714
Function3d714: ; 3d714
ld a, [$d264]
dec a
jp z, .asm_3d749
ld a, [PartyCount]
dec a
jp z, .asm_3d749
ld a, [InLinkBattle]
and a
jp nz, .asm_3d749
ld a, [Options]
bit 6, a
jr nz, .asm_3d749
ld a, [CurPartyMon]
push af
ld a, [CurBattleMon]
ld [CurPartyMon], a
callba Functione538
pop bc
ld a, b
ld [CurPartyMon], a
jr c, .asm_3d749
scf
ret
.asm_3d749
and a
ret
; 3d74b
Function3d74b: ; 3d74b
ld a, [CurPartyMon]
push af
callab Function39939
ld hl, BattleText_0x80aca
call StdBattleTextBox
lb bc, 1, 7
call PlaceYesNoBox
ld a, [$cfa9]
dec a
jr nz, .asm_3d79a
call Function3d2f7
call PickSwitchMonInBattle
jr c, .asm_3d791
ld a, [CurBattleMon]
ld [$c71a], a
ld a, [CurPartyMon]
ld [CurBattleMon], a
call ClearPalettes
call DelayFrame
call Function3eda6
pop af
ld [CurPartyMon], a
xor a
ld [CurEnemyMove], a
ld [CurPlayerMove], a
and a
ret
.asm_3d791
call ClearPalettes
call DelayFrame
call Function3eda6
.asm_3d79a
pop af
ld [CurPartyMon], a
scf
ret
; 3d7a0
Function3d7a0: ; 3d7a0
xor a
ld [hBGMapMode], a
call Function1c07
call ClearSprites
ld hl, $c4a1
ld bc, $040a
call ClearBox
call WaitBGMap
jp Function3ee27
; 3d7b8
Function3d7b8: ; 3d7b8
callab Function39939
ld hl, BattleText_0x80af8
call StdBattleTextBox
jp WaitBGMap
; 3d7c7
Function3d7c7: ; 3d7c7
ld a, [TempEnemyMonSpecies]
ld [CurPartySpecies], a
ld [CurSpecies], a
call GetBaseData
ld a, $1
ld [MonType], a
ld a, $1f
call Predef
call Function3f47c
xor a
ld [$cfca], a
ld [$c689], a
call SetEnemyTurn
ld de, $0101
call Function3ee17
call Function3da79
jr nc, .asm_3d800
ld a, $1
ld [$c689], a
ld de, $0101
call Function3ee17
.asm_3d800
ld bc, TempMonSpecies
callba Function4e53f
jr c, .asm_3d82c
callba CheckBattleScene
jr c, .asm_3d821
ld hl, $c4ac
ld d, $0
ld e, $0
ld a, $47
call Predef
jr .asm_3d82c
.asm_3d821
ld a, $f
ld [CryTracks], a
ld a, [TempEnemyMonSpecies]
call Function37b6
.asm_3d82c
call Function3e036
ld a, $1
ld [hBGMapMode], a
ret
; 3d834
NewEnemyMonStatus: ; 3d834
xor a
ld [LastEnemyCounterMove], a
ld [LastPlayerCounterMove], a
ld [LastEnemyMove], a
ld hl, EnemySubStatus1
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [EnemyDisableCount], a
ld [EnemyFuryCutterCount], a
ld [$c681], a
ld [$c72c], a
ld [EnemyDisabledMove], a
ld [$c6fa], a
ld [$c730], a
ld [$c731], a
ld [EnemyTurnsTaken], a
ld hl, PlayerSubStatus5
res 7, [hl]
ret
; 3d867
ResetEnemyStatLevels: ; 3d867
ld a, 7
ld b, 8
ld hl, EnemyStatLevels
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 3d873
Function3d873: ; 3d873
ld a, [PartyCount]
ld e, a
xor a
ld hl, PartyMon1HP
ld bc, $002f
.asm_3d87e
or [hl]
inc hl
or [hl]
add hl, bc
dec e
jr nz, .asm_3d87e
ld d, a
ret
; 3d887
Function3d887: ; 3d887
ld a, [CurPartyMon]
ld hl, PartyMon1HP
call GetPartyLocation
ld a, [hli]
or [hl]
ret nz
ld a, [$d264]
and a
jr nz, .asm_3d8b1
ld hl, PartySpecies
ld a, [CurPartyMon]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
cp EGG
ld hl, BattleText_0x80b26
jr z, .asm_3d8ae
ld hl, BattleText_0x80b0b
.asm_3d8ae
call StdBattleTextBox
.asm_3d8b1
xor a
ret
; 3d8b3
Function3d8b3: ; 3d8b3
ld a, [BattleType]
cp $2
jp z, .asm_3d9a2
cp $6
jp z, .asm_3d9a2
cp $9
jp z, .asm_3d98d
cp $b
jp z, .asm_3d98d
cp $7
jp z, .asm_3d98d
cp $c
jp z, .asm_3d98d
ld a, [InLinkBattle]
and a
jp nz, .asm_3d9a2
ld a, [IsInBattle]
dec a
jp nz, .asm_3d992
ld a, [EnemySubStatus5]
bit 7, a
jp nz, .asm_3d98d
ld a, [$c730]
and a
jp nz, .asm_3d98d
push hl
push de
ld a, [BattleMonItem]
ld [$d265], a
ld b, a
callab GetItem
ld a, b
cp $48
pop de
pop hl
jr nz, .asm_3d916
call SetPlayerTurn
call GetItemName
ld hl, BattleText_0x80b89
call StdBattleTextBox
jp .asm_3d9a2
.asm_3d916
ld a, [$d267]
inc a
ld [$d267], a
ld a, [hli]
ld [$ffb5], a
ld a, [hl]
ld [$ffb6], a
ld a, [de]
inc de
ld [$ffb1], a
ld a, [de]
ld [$ffb2], a
call Function30b4
ld de, $ffb5
ld hl, $ffb1
ld c, $2
call StringCmp
jr nc, .asm_3d9a2
xor a
ld [hMultiplicand], a
ld a, $20
ld [hMultiplier], a
call Multiply
ld a, [$ffb5]
ld [hProduct], a
ld a, [$ffb6]
ld [hMultiplicand], a
ld a, [$ffb1]
ld b, a
ld a, [$ffb2]
srl b
rr a
srl b
rr a
and a
jr z, .asm_3d9a2
ld [hMultiplier], a
ld b, $2
call Divide
ld a, [$ffb5]
and a
jr nz, .asm_3d9a2
ld a, [$d267]
ld c, a
.asm_3d96c
dec c
jr z, .asm_3d97a
ld b, $1e
ld a, [$ffb6]
add b
ld [$ffb6], a
jr c, .asm_3d9a2
jr .asm_3d96c
.asm_3d97a
call BattleRandom
ld b, a
ld a, [$ffb6]
cp b
jr nc, .asm_3d9a2
ld a, $1
ld [$d0ec], a
ld hl, BattleText_0x80b3b
jr .asm_3d995
.asm_3d98d
ld hl, BattleText_0x80ba0
jr .asm_3d995
.asm_3d992
ld hl, BattleText_0x80b49
.asm_3d995
call StdBattleTextBox
ld a, $1
ld [$d266], a
call Function309d
and a
ret
.asm_3d9a2
ld a, [InLinkBattle]
and a
ld a, $2
jr z, .asm_3d9cf
call Function309d
xor a
ld [$d0ec], a
ld a, $f
ld [CurMoveNum], a
xor a
ld [CurPlayerMove], a
call Function3e8e4
call Function30b4
call Function3d2e0
jr c, .asm_3d9f5
; Got away safely
ld a, [$d430]
cp $f
ld a, $2
jr z, .asm_3d9cf
dec a
.asm_3d9cf
ld b, a
ld a, [$d0ee]
and $c0
add b
ld [$d0ee], a
call Function3ceec
push de
ld de, SFX_RUN
call WaitPlaySFX
pop de
call WaitSFX
ld hl, BattleText_0x80b77
call StdBattleTextBox
call WaitSFX
call Function309d
scf
ret
.asm_3d9f5
call Function3ceec
ld hl, $cd2a
bit 4, [hl]
jr nz, .asm_3da05
ld hl, BattleText_0x81863
call StdBattleTextBox
.asm_3da05
call WaitSFX
call Function309d
scf
ret
; 3da0d
Function3da0d: ; 3da0d
ld a, $0
call GetPartyParamLocation
ld de, BattleMonSpecies
ld bc, $0006
call CopyBytes
ld bc, $000f
add hl, bc
ld de, BattleMonAtkDefDV
ld bc, $0007
call CopyBytes
inc hl
inc hl
inc hl
ld de, BattleMonLevel
ld bc, $0011
call CopyBytes
ld a, [BattleMonSpecies]
ld [TempBattleMonSpecies], a
ld [CurPartySpecies], a
ld [CurSpecies], a
call GetBaseData
ld a, [BaseType1]
ld [BattleMonType1], a
ld a, [BaseType2]
ld [BattleMonType2], a
ld hl, PartyMon1Nickname
ld a, [CurBattleMon]
call SkipNames
ld de, BattleMonNick
ld bc, $000b
call CopyBytes
ld hl, BattleMonAtk
ld de, PlayerStats
ld bc, $000a
call CopyBytes
call Function3ec2c
call BadgeStatBoosts
ret
; 3da74
Function3da74: ; 3da74
call Function3da85
jr Function3da7c
Function3da79: ; 3da79
call Function3da97
Function3da7c: ; 3da7c
ld b, h
ld c, l
callab CheckShininess
ret
; 3da85
Function3da85: ; 3da85
ld hl, BattleMonAtkDefDV
ld a, [PlayerSubStatus5]
bit 3, a
ret z
ld hl, PartyMon1DVs
ld a, [CurBattleMon]
jp GetPartyLocation
; 3da97
Function3da97: ; 3da97
ld hl, EnemyMonAtkDefDV
ld a, [EnemySubStatus5]
bit 3, a
ret z
ld hl, $c6f2
ld a, [IsInBattle]
dec a
ret z
ld hl, OTPartyMon1AtkDefDV
ld a, [CurOTMon]
jp GetPartyLocation
; 3dab1
ResetPlayerStatLevels: ; 3dab1
ld a, 7
ld b, 8
ld hl, PlayerStatLevels
.loop
ld [hli], a
dec b
jr nz, .loop
ret
; 3dabd
Function3dabd: ; 3dabd
ld a, [CurPartyMon]
ld hl, OTPartyMon1Species
call GetPartyLocation
ld de, EnemyMonSpecies
ld bc, $0006
call CopyBytes
ld bc, $000f
add hl, bc
ld de, EnemyMonAtkDefDV
ld bc, $0007
call CopyBytes
inc hl
inc hl
inc hl
ld de, EnemyMonLevel
ld bc, $0011
call CopyBytes
ld a, [EnemyMonSpecies]
ld [CurSpecies], a
call GetBaseData
ld hl, OTPartyMon1Nickname
ld a, [CurPartyMon]
call SkipNames
ld de, EnemyMonNick
ld bc, $000b
call CopyBytes
ld hl, EnemyMonAtk
ld de, EnemyStats
ld bc, $000a
call CopyBytes
call Function3ec30
ld hl, BaseType1
ld de, EnemyMonType1
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
ld hl, BaseHP
ld de, EnemyMonBaseStats
ld b, $5
.asm_3db25
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .asm_3db25
ld a, [CurPartyMon]
ld [CurOTMon], a
ret
; 3db32
Function3db32: ; 3db32
call ClearSprites
ld a, [CurBattleMon]
ld [$c71a], a
ld a, [CurPartyMon]
ld [CurBattleMon], a
call Function3d581
call Function3da0d
call ResetPlayerStatLevels
call NewBattleMonStatus
call BreakAttraction
call Function3db5f
call EmptyBattleTextBox
call Function309d
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
ret
; 3db5f
Function3db5f: ; 3db5f
ld hl, BattleMonAtkDefDV
ld a, $2d
call Predef
ld hl, $c505
ld b, $7
ld c, $8
call ClearBox
call WaitBGMap
xor a
ld [hBGMapMode], a
call Function3f43d
xor a
ld [$ffad], a
ld [$d0d2], a
ld [CurMoveNum], a
ld [TypeModifier], a
ld [PlayerMoveAnimation], a
ld [LastEnemyCounterMove], a
ld [LastPlayerCounterMove], a
ld [LastPlayerMove], a
call Function3e4a8
call Function3ee27
xor a
ld [$c731], a
call SetPlayerTurn
xor a
ld [$cfca], a
ld [$c689], a
ld de, $0101
call Function3ee17
call Function3da74
jr nc, .asm_3dbbc
ld a, $1
ld [$c689], a
ld de, $0101
call Function3ee17
.asm_3dbbc
ld a, $0
call GetPartyParamLocation
ld b, h
ld c, l
callba Function4e53f
jr c, .asm_3dbd6
ld a, $f0
ld [CryTracks], a
ld a, [CurPartySpecies]
call Function37b6
.asm_3dbd6
call Function3df48
ld a, $1
ld [hBGMapMode], a
ret
; 3dbde
NewBattleMonStatus: ; 3dbde
xor a
ld [LastEnemyCounterMove], a
ld [LastPlayerCounterMove], a
ld [LastPlayerMove], a
ld hl, PlayerSubStatus1
ld [hli], a
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld hl, PlayerUsedMoves
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [PlayerDisableCount], a
ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a
ld [$c72b], a
ld [DisabledMove], a
ld [$c6fe], a
ld [$c731], a
ld [$c730], a
ld [PlayerTurnsTaken], a
ld hl, EnemySubStatus5
res SUBSTATUS_CANT_RUN, [hl]
ret
; 3dc18
BreakAttraction: ; 3dc18
ld hl, PlayerSubStatus1
res SUBSTATUS_IN_LOVE, [hl]
ld hl, EnemySubStatus1
res SUBSTATUS_IN_LOVE, [hl]
ret
; 3dc23
SpikesDamage: ; 3dc23
ld hl, PlayerScreens
ld de, BattleMonType1
ld bc, Function3df48
ld a, [hBattleTurn]
and a
jr z, .ok
ld hl, EnemyScreens
ld de, EnemyMonType1
ld bc, Function3e036
.ok
bit SCREENS_SPIKES, [hl]
ret z
; Flying-types aren't affected by Spikes.
ld a, [de]
cp FLYING
ret z
inc de
ld a, [de]
cp FLYING
ret z
push bc
ld hl, BattleText_0x80bae ; "hurt by SPIKES!"
call StdBattleTextBox
call GetEighthMaxHP
call Function3cc39
pop hl
call .hl
jp WaitBGMap
.hl
jp [hl]
; 3dc5b
Function3dc5b: ; 3dc5b
ld a, $10
call GetBattleVar
ld b, a
call GetMoveEffect
ld a, b
cp $80
jr nz, .asm_3dce4
ld a, [CurBattleMon]
push af
ld hl, DoPlayerTurn
ld a, [hBattleTurn]
and a
jr z, .asm_3dc7e
ld hl, DoEnemyTurn
ld a, [$c71a]
ld [CurBattleMon], a
.asm_3dc7e
ld a, BANK(DoPlayerTurn)
rst FarCall
ld a, $10
call _GetBattleVar
ld a, $ff
ld [hl], a
pop af
ld [CurBattleMon], a
ld a, [hBattleTurn]
and a
jr z, .asm_3dcc0
ld a, [$c71a]
call Function399f
ld hl, BattleMonHP
ld a, [hli]
or [hl]
jr nz, .asm_3dce4
ld a, $f0
ld [CryTracks], a
ld a, [BattleMonSpecies]
call Function37b6
ld a, [$c71a]
ld c, a
ld hl, $c664
ld b, $0
ld a, $3
call Predef
call Function3d43b
ld hl, BattleText_0x80a75
jr .asm_3dcdf
.asm_3dcc0
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
jr nz, .asm_3dce4
ld de, SFX_KINESIS
call PlaySFX
call WaitSFX
ld de, SFX_UNKNOWN_2A
call PlaySFX
call WaitSFX
call Function3d432
ld hl, BattleText_0x809a8
.asm_3dcdf
call StdBattleTextBox
scf
ret
.asm_3dce4
and a
ret
; 3dce6
Function3dce6: ; 3dce6
ld a, [hBattleTurn]
push af
xor a
ld [hBattleTurn], a
ld [$cfca], a
ld de, $0102
call Function3ee17
pop af
ld [hBattleTurn], a
ret
; 3dcf9
Function3dcf9: ; 3dcf9
ld a, [$ffcb]
cp $1
jr z, .asm_3dd17
call SetPlayerTurn
call Function3dd2f
call Function3dde9
call Function3de51
call SetEnemyTurn
call Function3dd2f
call Function3dde9
jp Function3de51
.asm_3dd17
call SetEnemyTurn
call Function3dd2f
call Function3dde9
call Function3de51
call SetPlayerTurn
call Function3dd2f
call Function3dde9
jp Function3de51
; 3dd2f
Function3dd2f: ; 3dd2f
callab GetOpponentItem
ld a, b
cp $1
ret nz
ld de, EnemyMonHPLo
ld hl, EnemyMonMaxHPHi
ld a, [hBattleTurn]
and a
jr z, .asm_3dd4a
ld de, $c63d
ld hl, BattleMonMaxHP
.asm_3dd4a
push bc
ld a, [de]
ld [$d1ec], a
add a
ld c, a
dec de
ld a, [de]
inc de
ld [$d1ed], a
adc a
ld b, a
ld a, b
cp [hl]
ld a, c
pop bc
jr z, .asm_3dd62
jr c, .asm_3dd66
ret
.asm_3dd62
inc hl
cp [hl]
dec hl
ret nc
.asm_3dd66
call Function3ddc8
ld a, [hli]
ld [Buffer2], a
ld a, [hl]
ld [Buffer1], a
ld a, [de]
add c
ld [$d1ee], a
ld c, a
dec de
ld a, [de]
adc $0
ld [$d1ef], a
ld b, a
ld a, [hld]
cp c
ld a, [hl]
sbc b
jr nc, .asm_3dd8d
ld a, [hli]
ld [$d1ef], a
ld a, [hl]
ld [$d1ee], a
.asm_3dd8d
ld a, [$d1ef]
ld [de], a
inc de
ld a, [$d1ee]
ld [de], a
ld a, [hBattleTurn]
ld [$d10a], a
and a
ld hl, $c4ca
jr z, .asm_3dda4
ld hl, $c55e
.asm_3dda4
ld [$d10a], a
ld a, $b
call Predef
Function3ddac:
call RefreshBattleHuds
callab GetOpponentItem
ld a, [hl]
ld [$d265], a
call GetItemName
callab Function27192
ld hl, RecoveredUsingText
jp StdBattleTextBox
; 3ddc8
Function3ddc8: ; 3ddc8
push hl
push de
push bc
call EmptyBattleTextBox
ld a, $69
ld [FXAnimIDLo], a
call Function3c8e4
xor a
ld [$cfca], a
ld [FXAnimIDHi], a
ld a, $37
call Predef
call Function3c8e4
pop bc
pop de
pop hl
ret
; 3dde9
Function3dde9: ; 3dde9
callab GetOpponentItem
ld hl, .Statuses
.asm_3ddf2
ld a, [hli]
cp $ff
ret z
inc hl
cp b
jr nz, .asm_3ddf2
dec hl
ld b, [hl]
ld a, $b
call _GetBattleVar
and b
ret z
xor a
ld [hl], a
push bc
call UpdateOpponentInParty
pop bc
ld a, $9
call _GetBattleVar
and [hl]
res 0, [hl]
ld a, $5
call _GetBattleVar
and [hl]
res 0, [hl]
ld a, b
cp $7f
jr nz, .asm_3de26
ld a, $7
call _GetBattleVar
res 7, [hl]
.asm_3de26
ld hl, Function365fd
ld a, [hBattleTurn]
and a
jr z, .asm_3de31
ld hl, Function365d7
.asm_3de31
call Function3c8e4
ld a, BANK(Function365fd)
rst FarCall
call Function3c8e4
call Function3ddc8
call Function3ddac
ld a, $1
and a
ret
; 3de44
.Statuses ; 3de44
db HELD_HEAL_POISON, 1 << PSN
db HELD_HEAL_FREEZE, 1 << FRZ
db HELD_HEAL_BURN, 1 << BRN
db HELD_HEAL_SLEEP, SLP
db HELD_HEAL_PARALYZE, 1 << PAR
db HELD_HEAL_STATUS, 1 << PSN | 1 << FRZ | 1 << BRN | SLP | 1 << PAR
db $ff
; 3de51
Function3de51: ; 3de51
ld a, $7
call GetBattleVar
bit 7, a
ret z
callab GetOpponentItem
ld a, b
cp $10
jr z, .asm_3de67
cp $f
ret nz
.asm_3de67
ld a, [hl]
ld [$d265], a
ld a, $7
call _GetBattleVar
res 7, [hl]
call GetItemName
call Function3ddc8
ld hl, BattleText_0x80dab
call StdBattleTextBox
ld a, [hBattleTurn]
and a
jr nz, .asm_3de90
call Function3df1f
xor a
ld [bc], a
ld a, [IsInBattle]
dec a
ret z
ld [hl], $0
ret
.asm_3de90
call Function3df12
xor a
ld [bc], a
ld [hl], a
ret
; 3de97
Function3de97: ; 3de97
ld a, [$ffcb]
cp $1
jr z, .asm_3dea3
call Function3dea9
jp Function3deb1
.asm_3dea3
call Function3deb1
jp Function3dea9
; 3dea9
Function3dea9: ; 3dea9
call Function3df12
ld a, $0
jp Function3deb6
; 3deb1
Function3deb1: ; 3deb1
call Function3df1f
ld a, $1
Function3deb6: ; 3deb6
ld [hBattleTurn], a
ld d, h
ld e, l
push de
push bc
ld a, [bc]
ld b, a
callab GetItem
ld hl, .data_3defc
.asm_3dec7
ld a, [hli]
cp $ff
jr z, .asm_3def9
inc hl
inc hl
cp b
jr nz, .asm_3dec7
pop bc
ld a, [bc]
ld [$d265], a
push bc
dec hl
dec hl
ld a, [hli]
ld h, [hl]
ld l, a
ld a, BANK(BattleCommand70)
rst FarCall
pop bc
pop de
ld a, [FailedMessage]
and a
ret nz
xor a
ld [bc], a
ld [de], a
call GetItemName
ld hl, BattleText_0x80bde
call StdBattleTextBox
callab BattleCommand8c
ret
.asm_3def9
pop bc
pop de
ret
; 3defc
.data_3defc
dbw $1f, BattleCommand70
dbw $20, BattleCommand71
dbw $21, BattleCommand72
dbw $22, BattleCommand73
dbw $23, BattleCommand74
dbw $24, BattleCommand75
dbw $25, BattleCommand76
db $ff
; 3df12
Function3df12: ; 3df12
ld hl, PartyMon1Item
ld a, [CurBattleMon]
call GetPartyLocation
ld bc, BattleMonItem
ret
; 3df1f
Function3df1f: ; 3df1f
ld hl, OTPartyMon1Item
ld a, [CurOTMon]
call GetPartyLocation
ld bc, EnemyMonItem
ret
; 3df2c
Function3df2c: ; 3df2c
push hl
push de
push bc
call DrawPlayerHUD
ld hl, PlayerHPPal
call SetHPPal
call CheckDanger
call Function3e043
ld hl, EnemyHPPal
call SetHPPal
pop bc
pop de
pop hl
ret
; 3df48
Function3df48:: ; 3df48
push hl
push de
push bc
call DrawPlayerHUD
call UpdatePlayerHPPal
call CheckDanger
pop bc
pop de
pop hl
ret
; 3df58
DrawPlayerHUD: ; 3df58
xor a
ld [hBGMapMode], a
; Clear the area
hlcoord 9, 7
ld bc, $050b
call ClearBox
callba DrawPlayerExpBar
hlcoord 18, 9
ld [hl], $73 ; vertical bar
call PrintPlayerHUD
; HP bar
hlcoord 10, 9
ld b, OTPARTYMON
xor a
ld [MonType], a
ld a, PREDEF_DRAW_PLAYER_HP
call Predef
; Exp bar
push de
ld a, [CurBattleMon]
ld hl, PartyMon1Exp + 2
call GetPartyLocation
ld d, h
ld e, l
hlcoord 10, 11
ld a, [TempMonLevel]
ld b, a
call FillInExpBar
pop de
ret
; 3df98
UpdatePlayerHPPal: ; 3df98
ld hl, PlayerHPPal
jp Function3e12e
; 3df9e
CheckDanger: ; 3df9e
ld hl, BattleMonHP
ld a, [hli]
or [hl]
jr z, .asm_3dfb2
ld a, [$c6fd]
and a
jr nz, .asm_3dfbe
ld a, [PlayerHPPal]
cp $2
jr z, .asm_3dfb9
.asm_3dfb2
ld hl, Danger
res 7, [hl]
jr .asm_3dfbe
.asm_3dfb9
ld hl, Danger
set 7, [hl]
.asm_3dfbe
ret
; 3dfbf
PrintPlayerHUD: ; 3dfbf
ld de, BattleMonNick
hlcoord 10, 7
call Function3e138
call PlaceString
push bc
ld a, [CurBattleMon]
ld hl, PartyMon1DVs
call GetPartyLocation
ld de, TempMonDVs
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
ld hl, BattleMonLevel
ld de, TempMonLevel
ld bc, $0011
call CopyBytes
ld a, [CurBattleMon]
ld hl, PartyMon1Species
call GetPartyLocation
ld a, [hl]
ld [CurPartySpecies], a
ld [CurSpecies], a
call GetBaseData
pop hl
dec hl
ld a, $3
ld [MonType], a
callab GetGender
ld a, $7f
jr c, .asm_3e013
ld a, $ef
jr nz, .asm_3e013
ld a, $f5
.asm_3e013
ld hl, $c551
ld [hl], a
ld hl, $c54e
push af
push hl
ld de, BattleMonStatus
ld a, $21
call Predef
pop hl
pop bc
ret nz
ld a, b
cp $7f
jr nz, .asm_3e02d
dec hl
.asm_3e02d
ld a, [BattleMonLevel]
ld [TempMonLevel], a
jp PrintLevel
; 3e036
Function3e036:: ; 3e036
push hl
push de
push bc
call Function3e043
call Function3e127
pop bc
pop de
pop hl
ret
; 3e043
Function3e043: ; 3e043
xor a
ld [hBGMapMode], a
ld hl, $c4a1
ld bc, $040b
call ClearBox
callba Function2c0c5
ld a, [TempEnemyMonSpecies]
ld [CurSpecies], a
ld [CurPartySpecies], a
call GetBaseData
ld de, EnemyMonNick
ld hl, $c4a1
call Function3e138
call PlaceString
ld h, b
ld l, c
dec hl
ld hl, EnemyMonAtkDefDV
ld de, TempMonDVs
ld a, [EnemySubStatus5]
bit 3, a
jr z, .asm_3e080
ld hl, $c6f2
.asm_3e080
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
ld a, $3
ld [MonType], a
callab GetGender
ld a, $7f
jr c, .asm_3e09a
ld a, $ef
jr nz, .asm_3e09a
ld a, $f5
.asm_3e09a
ld hl, $c4bd
ld [hl], a
ld hl, $c4ba
push af
push hl
ld de, EnemyMonStatus
ld a, $21
call Predef
pop hl
pop bc
jr nz, .asm_3e0be
ld a, b
cp $7f
jr nz, .asm_3e0b5
dec hl
.asm_3e0b5
ld a, [EnemyMonLevel]
ld [TempMonLevel], a
call PrintLevel
.asm_3e0be
ld hl, EnemyMonHPHi
ld a, [hli]
ld [$ffb5], a
ld a, [hld]
ld [$ffb6], a
or [hl]
jr nz, .asm_3e0d1
ld c, a
ld e, a
ld d, $6
jp .asm_3e11a
.asm_3e0d1
xor a
ld [hMultiplicand], a
ld a, $30
ld [hMultiplier], a
call Multiply
ld hl, EnemyMonMaxHPHi
ld a, [hli]
ld b, a
ld a, [hl]
ld [hMultiplier], a
ld a, b
and a
jr z, .asm_3e105
ld a, [hMultiplier]
srl b
rr a
srl b
rr a
ld [hMultiplier], a
ld a, [$ffb5]
ld b, a
srl b
ld a, [$ffb6]
rr a
srl b
rr a
ld [$ffb6], a
ld a, b
ld [$ffb5], a
.asm_3e105
ld a, [$ffb5]
ld [hProduct], a
ld a, [$ffb6]
ld [hMultiplicand], a
ld a, $2
ld b, a
call Divide
ld a, [$ffb6]
ld e, a
ld a, $6
ld d, a
ld c, a
.asm_3e11a
xor a
ld [$d10a], a
ld hl, $c4ca
ld b, $0
call DrawHPBar
ret
; 3e127
Function3e127: ; 3e127
ld hl, EnemyHPPal
call Function3e12e
ret
; 3e12e
Function3e12e: ; 3e12e
ld b, [hl]
call SetHPPal
ld a, [hl]
cp b
ret z
jp Function3ee27
; 3e138
Function3e138: ; 3e138
ret
; 3e139
Function3e139: ; 3e139
xor a
ld [hBGMapMode], a
call Function30bf
ld a, [BattleType]
cp $2
jr z, .asm_3e156
cp $3
jr z, .asm_3e156
call EmptyBattleTextBox
call UpdateBattleHuds
call EmptyBattleTextBox
call Function309d
.asm_3e156
ld a, [BattleType]
cp $6
jr nz, .asm_3e165
callba Function24f13
jr .asm_3e175
.asm_3e165
ld a, [InputType]
or a
jr z, .asm_3e171
callba Function1de294
.asm_3e171
call Function3e19b
ret c
.asm_3e175
ld a, $1
ld [hBGMapMode], a
ld a, [$d0d2]
cp $1
jp z, Function3e192
cp $3
jp z, Function3e1c7
cp $2
jp z, Function3e28d
cp $4
jp z, Function3e489
jr .asm_3e156
; 3e192
Function3e192: ; 3e192
xor a
ld [$d267], a
call Function30b4
and a
ret
; 3e19b
Function3e19b: ; 3e19b
call Function3d2f1
jr z, .asm_3e1a8
callba LoadBattleMenuDataHeader
and a
ret
.asm_3e1a8
callba Function100b12
ld a, [$cd2b]
and a
ret z
ld hl, $cd2a
bit 4, [hl]
jr nz, .asm_3e1c5
ld hl, BattleText_0x81863
call StdBattleTextBox
ld c, $3c
call DelayFrames
.asm_3e1c5
scf
ret
; 3e1c7
Function3e1c7: ; 3e1c7
ld a, [InLinkBattle]
and a
jp nz, Function3e22b
ld a, [$cfc0]
and a
jp nz, Function3e22b
call Function1d6e
ld a, [BattleType]
cp $3
jr z, .asm_3e1f1
cp $6
jr z, .asm_3e201
callba Function10493
ld a, [$d0ec]
and a
jr z, .asm_3e20d
jr .asm_3e209
.asm_3e1f1
callba Function107bb
ld a, $5
ld [CurItem], a
call DoItemEffect
jr .asm_3e209
.asm_3e201
ld a, $b1
ld [CurItem], a
call DoItemEffect
.asm_3e209
call Function3e234
ret
.asm_3e20d
call ClearPalettes
call DelayFrame
call Function3ed9f
call Function3f43d
call Function3f47c
call Function1c07
call WaitBGMap
call Function3ee27
call Function309d
jp Function3e139
; 3e22b
Function3e22b: ; 3e22b
ld hl, BattleText_0x80bf3
call StdBattleTextBox
jp Function3e139
; 3e234
Function3e234: ; 3e234
ld a, [$c64e]
and a
jr nz, .asm_3e279
callab CheckItemPocket
ld a, [$d142]
cp $3
jr z, .asm_3e24a
call WhiteBGMap
.asm_3e24a
xor a
ld [hBGMapMode], a
call Function3ed9f
call ClearSprites
ld a, [BattleType]
cp $3
jr z, .asm_3e25d
call Function3f43d
.asm_3e25d
call Function3f47c
ld a, $1
ld [$cfa9], a
call Function1c07
call Function3df2c
call WaitBGMap
call Function309d
call Function1fbf
call Function3ee27
and a
ret
.asm_3e279
xor a
ld [$c64e], a
ld a, [$d0ee]
and $c0
ld [$d0ee], a
call Function1fbf
call Function32f9
scf
ret
; 3e28d
Function3e28d: ; 3e28d
call Function1d6e
Function3e290:
call Function1c07
call Function1d6e
call WhiteBGMap
Function3e299:
call Function3d2fa
xor a
ld [PartyMenuActionText], a
call Function3d313
call Function3d329
jr c, .asm_3e2da
.asm_3e2a8
callba Function8ea4a
call Function3e2f5
jr c, .asm_3e2c8
call Function1bee
ld a, [$cfa9]
cp $1
jp z, Function3e358
cp $2
jr z, .asm_3e2cf
cp $3
jr z, .asm_3e2da
jr .asm_3e2a8
.asm_3e2c8
call Function3d2e0
jr c, .asm_3e2da
jr Function3e299
.asm_3e2cf
call Function3e308
call Function3d2e0
jr c, .asm_3e2da
jp Function3e290
.asm_3e2da
call ClearSprites
call ClearPalettes
call DelayFrame
call Function3eda6
call Function1c17
call Function309d
call ClearSGB
call Function32f9
jp Function3e139
; 3e2f5
Function3e2f5: ; 3e2f5
call Function3d2f1
jr z, .asm_3e301
callba Function24e99
ret
.asm_3e301
callba Function100d22
ret
; 3e308
Function3e308: ; 3e308
call DisableLCD
ld hl, $9310
ld de, VTiles0
ld bc, $0110
call CopyBytes
ld hl, VTiles2
ld de, $8110
ld bc, $0310
call CopyBytes
call EnableLCD
call ClearSprites
call LowVolume
xor a
ld [MonType], a
callba Function4dc7b
call MaxVolume
call DisableLCD
ld hl, VTiles0
ld de, $9310
ld bc, $0110
call CopyBytes
ld hl, $8110
ld de, VTiles2
ld bc, $0310
call CopyBytes
call EnableLCD
ret
; 3e358
Function3e358: ; 3e358
ld a, [CurBattleMon]
ld d, a
ld a, [CurPartyMon]
cp d
jr nz, .asm_3e36b
ld hl, BattleText_0x80c0d
call StdBattleTextBox
jp Function3e299
.asm_3e36b
ld a, [$c730]
and a
jr nz, .asm_3e378
ld a, [EnemySubStatus5]
bit 7, a
jr z, .asm_3e381
.asm_3e378
ld hl, BattleText_0x80c22
call StdBattleTextBox
jp Function3e299
.asm_3e381
call Function3d887
jp z, Function3e299
ld a, [CurBattleMon]
ld [$c71a], a
ld a, $2
ld [$d0ec], a
call ClearPalettes
call DelayFrame
call ClearSprites
call Function3eda6
call Function1c17
call ClearSGB
call Function32f9
ld a, [CurPartyMon]
ld [CurBattleMon], a
; fallthrough
; 3e3ad
Function3e3ad: ; 3e3ad
ld a, $1
ld [$c710], a
ld a, [InLinkBattle]
and a
jr z, .asm_3e3c1
call Function1d6e
call Function3e8e4
call Function1c17
.asm_3e3c1
call Function3e7c1
ld a, [InLinkBattle]
and a
jr nz, .asm_3e3cf
.asm_3e3ca
call BattleMonEntrance
and a
ret
.asm_3e3cf
ld a, [$d430]
cp $e
jp z, .asm_3e3ca
cp $d
jp z, .asm_3e3ca
cp $4
jp c, .asm_3e3ca
cp $f
jr nz, .asm_3e3e9
call Function3c0e5
ret
.asm_3e3e9
ld a, [$ffcb]
cp $1
jr z, .asm_3e3f7
call BattleMonEntrance
call Function3e3ff
and a
ret
.asm_3e3f7
call Function3e3ff
call BattleMonEntrance
and a
ret
; 3e3ff
Function3e3ff: ; 3e3ff
callab Function3846c
call SetEnemyTurn
jp SpikesDamage
; 3e40b
BattleMonEntrance: ; 3e40b
call Function3f2f4
ld c, 50
call DelayFrames
ld hl, PlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
call SetEnemyTurn
call Function3dc5b
jr c, .asm_3e423
call Function3dce6
.asm_3e423
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
ld a, [CurBattleMon]
ld [CurPartyMon], a
call Function3d581
call Function3da0d
call ResetPlayerStatLevels
call Function3f26d
call NewBattleMonStatus
call BreakAttraction
call Function3db5f
call EmptyBattleTextBox
call Function309d
call SetPlayerTurn
call SpikesDamage
ld a, $2
ld [$cfa9], a
ret
; 3e459
PassedBattleMonEntrance: ; 3e459
ld c, 50
call DelayFrames
hlcoord 9, 7
lb bc, 5, 11
call ClearBox
ld a, [CurPartyMon]
ld [CurBattleMon], a
call Function3d581
call Function3da0d
xor a
ld [$d265], a
call Function3ecab
call Function3db5f
call EmptyBattleTextBox
call Function309d
call SetPlayerTurn
jp SpikesDamage
; 3e489
Function3e489: ; 3e489
call Function30b4
ld a, $3
ld [$cfa9], a
ld hl, BattleMonSpd
ld de, EnemyMonSpd
call Function3d8b3
ld a, $0
ld [$d266], a
ret c
ld a, [$d0ec]
and a
ret nz
jp Function3e139
; 3e4a8
Function3e4a8: ; 3e4a8
ld a, [BattleMonItem]
ld b, a
callab GetItem
ld a, b
cp $4c
ret nz
ld a, $1
ld [$c73d], a
ret
; 3e4bc
Function3e4bc: ; 3e4bc
call Function3d2f1
jr nz, .asm_3e4c8
callba Function100b9f
ret
.asm_3e4c8
ld hl, EnemyMonMove1
ld a, [$d235]
dec a
jr z, .asm_3e4e2
dec a
jr z, .asm_3e4dd
call Function3e786
ret z
ld hl, BattleMonMove1
jr .asm_3e4e2
.asm_3e4dd
ld a, $2
call GetPartyParamLocation
.asm_3e4e2
ld de, $d25e
ld bc, $0004
call CopyBytes
xor a
ld [hBGMapMode], a
ld hl, $c594
ld b, $4
ld c, $e
ld a, [$d235]
cp $2
jr nz, .asm_3e503
ld hl, $c544
ld b, $4
ld c, $e
.asm_3e503
call TextBox
ld hl, $c5aa
ld a, [$d235]
cp $2
jr nz, .asm_3e513
ld hl, $c55a
.asm_3e513
ld a, $14
ld [Buffer1], a
ld a, $20
call Predef
ld b, $5
ld a, [$d235]
cp $2
ld a, $d
jr nz, .asm_3e52c
ld b, $5
ld a, $9
.asm_3e52c
ld [$cfa1], a
ld a, b
ld [$cfa2], a
ld a, [$d235]
cp $1
jr z, .asm_3e53e
ld a, [CurMoveNum]
inc a
.asm_3e53e
ld [$cfa9], a
ld a, $1
ld [$cfaa], a
ld a, [$d0eb]
inc a
ld [$cfa3], a
ld a, $1
ld [$cfa4], a
ld c, $2c
ld a, [$d235]
dec a
ld b, $c1
jr z, .asm_3e569
dec a
ld b, $c3
jr z, .asm_3e569
ld a, [InLinkBattle]
and a
jr nz, .asm_3e569
ld b, $c7
.asm_3e569
ld a, b
ld [$cfa8], a
ld a, c
ld [$cfa5], a
xor a
ld [$cfa6], a
ld a, $10
ld [$cfa7], a
.asm_3e57a
ld a, [$d235]
and a
jr z, .asm_3e58e
dec a
jr nz, .asm_3e5a3
ld hl, $c5c3
ld de, .string_3e61c
call PlaceString
jr .asm_3e5a3
.asm_3e58e
call MoveInfoBox
ld a, [$d0e3]
and a
jr z, .asm_3e5a3
ld hl, $c5a9
ld bc, $0014
dec a
call AddNTimes
ld [hl], $ec
.asm_3e5a3
ld a, $1
ld [hBGMapMode], a
call Function1bd3
bit 6, a
jp nz, .asm_3e61d
bit 7, a
jp nz, .asm_3e62e
bit 2, a
jp nz, Function3e643
bit 1, a
push af
xor a
ld [$d0e3], a
ld a, [$cfa9]
dec a
ld [$cfa9], a
ld b, a
ld a, [$d235]
dec a
jr nz, .asm_3e5d0
pop af
ret
.asm_3e5d0
dec a
ld a, b
ld [CurMoveNum], a
jr nz, .asm_3e5d9
pop af
ret
.asm_3e5d9
pop af
ret nz
ld hl, BattleMonPPMove1
ld a, [$cfa9]
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
and $3f
jr z, .asm_3e610
ld a, [PlayerDisableCount]
swap a
and $f
dec a
cp c
jr z, .asm_3e60b
ld a, [$c6e1]
and a
jr nz, .asm_3e606
ld a, [$cfa9]
ld hl, BattleMonMove1
ld c, a
ld b, $0
add hl, bc
ld a, [hl]
.asm_3e606
ld [CurPlayerMove], a
xor a
ret
.asm_3e60b
ld hl, BattleText_0x80c5b
jr .asm_3e613
.asm_3e610
ld hl, Function3cc39
.asm_3e613
call StdBattleTextBox
call Function30b4
jp Function3e4bc
; 3e61c
.string_3e61c ; 3e61c
db "@"
; 3e61d
.asm_3e61d
ld a, [$cfa9]
and a
jp nz, .asm_3e57a
ld a, [$d0eb]
inc a
ld [$cfa9], a
jp .asm_3e57a
; 3e62e
.asm_3e62e: ; 3e62e
ld a, [$cfa9]
ld b, a
ld a, [$d0eb]
inc a
inc a
cp b
jp nz, .asm_3e57a
ld a, $1
ld [$cfa9], a
jp .asm_3e57a
; 3e643
Function3e643: ; 3e643
ld a, [$d0e3]
and a
jr z, .asm_3e6bf
ld hl, BattleMonMoves
call .asm_3e6a5
ld hl, BattleMonPP
call .asm_3e6a5
ld hl, PlayerDisableCount
ld a, [hl]
swap a
and $f
ld b, a
ld a, [$cfa9]
cp b
jr nz, .asm_3e671
ld a, [hl]
and $f
ld b, a
ld a, [$d0e3]
swap a
add b
ld [hl], a
jr .asm_3e682
.asm_3e671
ld a, [$d0e3]
cp b
jr nz, .asm_3e682
ld a, [hl]
and $f
ld b, a
ld a, [$cfa9]
swap a
add b
ld [hl], a
.asm_3e682
ld a, [PlayerSubStatus5]
bit 3, a
jr nz, .asm_3e69e
ld hl, PartyMon1Moves
ld a, [CurBattleMon]
call GetPartyLocation
push hl
call .asm_3e6a5
pop hl
ld bc, $0015
add hl, bc
call .asm_3e6a5
.asm_3e69e
xor a
ld [$d0e3], a
jp Function3e4bc
.asm_3e6a5
push hl
ld a, [$d0e3]
dec a
ld c, a
ld b, 0
add hl, bc
ld d, h
ld e, l
pop hl
ld a, [$cfa9]
dec a
ld c, a
ld b, 0
add hl, bc
ld a, [de]
ld b, [hl]
ld [hl], a
ld a, b
ld [de], a
ret
.asm_3e6bf
ld a, [$cfa9]
ld [$d0e3], a
jp Function3e4bc
; 3e6c8
MoveInfoBox: ; 3e6c8
xor a
ld [hBGMapMode], a
hlcoord 0, 8
ld b, 3
ld c, 9
call TextBox
call MobileTextBorder
ld a, [PlayerDisableCount]
and a
jr z, .asm_3e6f4
swap a
and $f
ld b, a
ld a, [$cfa9]
cp b
jr nz, .asm_3e6f4
hlcoord 1, 10
ld de, .Disabled
call PlaceString
jr .done
.asm_3e6f4
ld hl, $cfa9
dec [hl]
call SetPlayerTurn
ld hl, BattleMonMoves
ld a, [$cfa9]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
ld [CurPlayerMove], a
ld a, [CurBattleMon]
ld [CurPartyMon], a
ld a, WILDMON
ld [MonType], a
callab Functionf8ec
ld hl, $cfa9
ld c, [hl]
inc [hl]
ld b, 0
ld hl, BattleMonPP
add hl, bc
ld a, [hl]
and $3f
ld [StringBuffer1], a
call Function3e75f
hlcoord 1, 9
ld de, .Type
call PlaceString
hlcoord 7, 11
ld [hl], "/"
callab UpdateMoveData
ld a, [PlayerMoveAnimation]
ld b, a
hlcoord 2, 10
ld a, PREDEF_PRINT_MOVE_TYPE
call Predef
.done
ret
; 3e74f
.Disabled
db "Disabled!@"
.Type
db "TYPE/@"
; 3e75f
Function3e75f: ; 3e75f
hlcoord 5, 11
ld a, [InLinkBattle]
cp $4
jr c, .asm_3e76c
hlcoord 5, 11
.asm_3e76c
push hl
ld de, StringBuffer1
ld bc, $0102
call PrintNum
pop hl
inc hl
inc hl
ld [hl], "/"
inc hl
ld de, $d265
ld bc, $0102
call PrintNum
ret
; 3e786
Function3e786: ; 3e786
ld a, STRUGGLE
ld [CurPlayerMove], a
ld a, [PlayerDisableCount]
and a
ld hl, BattleMonPP
jr nz, .asm_3e79f
ld a, [hli]
or [hl]
inc hl
or [hl]
inc hl
or [hl]
and $3f
ret nz
jr .asm_3e7b4
.asm_3e79f
swap a
and $f
ld b, a
ld d, $5
xor a
.asm_3e7a7
dec d
jr z, .asm_3e7b2
ld c, [hl]
inc hl
dec b
jr z, .asm_3e7a7
or c
jr .asm_3e7a7
.asm_3e7b2
and a
ret nz
.asm_3e7b4
ld hl, BattleText_0x80c72
call StdBattleTextBox
ld c, 60
call DelayFrames
xor a
ret
; 3e7c1
Function3e7c1: ; 3e7c1
ld a, [$c711]
and a
ret nz
ld a, [InLinkBattle]
and a
jr z, .asm_3e817
call EmptyBattleTextBox
call Function309d
ld a, [$d0ec]
and a
call z, Function3e8e4
call Function30b4
ld a, [$d430]
cp $e
jp z, .asm_3e8bd
cp $d
jp z, .asm_3e82c
cp $4
jp nc, Function3e8c1
ld [CurEnemyMoveNum], a
ld c, a
ld a, [EnemySubStatus1]
bit 6, a
jp nz, .asm_3e882
ld a, [EnemySubStatus3]
and $13
jp nz, .asm_3e882
ld hl, EnemySubStatus5
bit 4, [hl]
ld a, [LastEnemyMove]
jp nz, .asm_3e87f
ld hl, EnemyMonMove1
ld b, $0
add hl, bc
ld a, [hl]
jp .asm_3e87f
.asm_3e817
ld hl, EnemySubStatus5
bit 4, [hl]
jr z, .asm_3e824
ld a, [LastEnemyMove]
jp .asm_3e87f
.asm_3e824
call Function3e8d1
jp nz, Function3e8c1
jr .asm_3e830
.asm_3e82c
ld a, $ff
jr .asm_3e87f
.asm_3e830
ld hl, EnemyMonMove1
ld de, EnemyMonPPMove1
ld b, $4
.asm_3e838
ld a, [hl]
and a
jp z, .asm_3e8bd
ld a, [EnemyDisabledMove]
cp [hl]
jr z, .asm_3e848
ld a, [de]
and $3f
jr nz, .asm_3e84f
.asm_3e848
inc hl
inc de
dec b
jr nz, .asm_3e838
jr .asm_3e8bd
.asm_3e84f
ld a, [IsInBattle]
dec a
jr nz, .asm_3e882
.asm_3e855
ld hl, EnemyMonMove1
call BattleRandom
and $3
ld c, a
ld b, $0
add hl, bc
ld a, [EnemyDisableCount]
swap a
and $f
dec a
cp c
jr z, .asm_3e855
ld a, [hl]
and a
jr z, .asm_3e855
ld hl, EnemyMonPPMove1
add hl, bc
ld b, a
ld a, [hl]
and $3f
jr z, .asm_3e855
ld a, c
ld [CurEnemyMoveNum], a
ld a, b
.asm_3e87f
ld [CurEnemyMove], a
.asm_3e882
call SetEnemyTurn
callab UpdateMoveData
call Function3e8d1
jr nz, .asm_3e894
xor a
ld [$c733], a
.asm_3e894
ld a, [EnemyMoveEffect]
cp $77
jr z, .asm_3e89f
xor a
ld [EnemyFuryCutterCount], a
.asm_3e89f
ld a, [EnemyMoveEffect]
cp $51
jr z, .asm_3e8af
ld hl, EnemySubStatus4
res 6, [hl]
xor a
ld [$c72c], a
.asm_3e8af
ld a, [EnemyMoveEffect]
cp $6f
ret z
cp $74
ret z
xor a
ld [$c681], a
ret
.asm_3e8bd
ld a, $a5
jr .asm_3e87f
; 3e8c1
Function3e8c1: ; 3e8c1
xor a
ld [EnemyFuryCutterCount], a
ld [$c681], a
ld [$c72c], a
ld hl, EnemySubStatus4
res 6, [hl]
ret
; 3e8d1
Function3e8d1: ; 3e8d1
ld a, [EnemySubStatus4]
and $20
ret nz
ld hl, EnemySubStatus3
ld a, [hl]
and $13
ret nz
ld hl, EnemySubStatus1
bit 6, [hl]
ret
; 3e8e4
Function3e8e4: ; 3e8e4
callba Function100a09
ret
; 3e8eb
LoadEnemyMon: ; 3e8eb
; Initialize enemy monster parameters
; To do this we pull the species from TempEnemyMonSpecies
; Notes:
; BattleRandom is used to ensure sync between Game Boys
; Clear the whole EnemyMon struct
xor a
ld hl, EnemyMonSpecies
ld bc, EnemyMonEnd - EnemyMon
call ByteFill
; We don't need to be here if we're in a link battle
ld a, [InLinkBattle]
and a
jp nz, Function3dabd
ld a, [$cfc0] ; ????
bit 0, a
jp nz, Function3dabd
; Make sure everything knows what species we're working with
ld a, [TempEnemyMonSpecies]
ld [EnemyMonSpecies], a
ld [CurSpecies], a
ld [CurPartySpecies], a
; Grab the BaseData for this species
call GetBaseData
; Let's get the item:
; Is the item predetermined?
ld a, [IsInBattle]
dec a
jr z, .WildItem
; If we're in a trainer battle, the item is in the party struct
ld a, [CurPartyMon]
ld hl, OTPartyMon1Item
call GetPartyLocation ; bc = PartyMon[CurPartyMon] - PartyMons
ld a, [hl]
jr .UpdateItem
.WildItem
; In a wild battle, we pull from the item slots in BaseData
; Force Item1
; Used for Ho-Oh, Lugia and Snorlax encounters
ld a, [BattleType]
cp BATTLETYPE_FORCEITEM
ld a, [BaseItems]
jr z, .UpdateItem
; Failing that, it's all up to chance
; Effective chances:
; 75% None
; 23% Item1
; 2% Item2
; 25% chance of getting an item
call BattleRandom
cp a, $c0
ld a, NO_ITEM
jr c, .UpdateItem
; From there, an 8% chance for Item2
call BattleRandom
cp a, $14 ; 8% of 25% = 2% Item2
ld a, [BaseItems]
jr nc, .UpdateItem
ld a, [BaseItems+1]
.UpdateItem
ld [EnemyMonItem], a
; Initialize DVs
; If we're in a trainer battle, DVs are predetermined
ld a, [IsInBattle]
and a
jr z, .InitDVs
; ????
ld a, [EnemySubStatus5]
bit 3, a
jr z, .InitDVs
; Unknown
ld hl, $c6f2
ld de, EnemyMonDVs
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
jp .Happiness
.InitDVs
; Trainer DVs
; All trainers have preset DVs, determined by class
; See GetTrainerDVs for more on that
callba GetTrainerDVs
; These are the DVs we'll use if we're actually in a trainer battle
ld a, [IsInBattle]
dec a
jr nz, .UpdateDVs
; Wild DVs
; Here's where the fun starts
; Roaming monsters (Entei, Raikou) work differently
; They have their own structs, which are shorter than normal
ld a, [BattleType]
cp a, BATTLETYPE_ROAMING
jr nz, .NotRoaming
; Grab HP
call GetRoamMonHP
ld a, [hl]
; Check if the HP has been initialized
and a
; We'll do something with the result in a minute
push af
; Grab DVs
call GetRoamMonDVs
inc hl
ld a, [hld]
ld c, a
ld b, [hl]
; Get back the result of our check
pop af
; If the RoamMon struct has already been initialized, we're done
jr nz, .UpdateDVs
; If it hasn't, we need to initialize the DVs
; (HP is initialized at the end of the battle)
call GetRoamMonDVs
inc hl
call BattleRandom
ld [hld], a
ld c, a
call BattleRandom
ld [hl], a
ld b, a
; We're done with DVs
jr .UpdateDVs
.NotRoaming
; Register a contains BattleType
; Forced shiny battle type
; Used by Red Gyarados at Lake of Rage
cp a, BATTLETYPE_SHINY
jr nz, .GenerateDVs
ld b, ATKDEFDV_SHINY ; $ea
ld c, SPDSPCDV_SHINY ; $aa
jr .UpdateDVs
.GenerateDVs
; Generate new random DVs
call BattleRandom
ld b, a
call BattleRandom
ld c, a
.UpdateDVs
; Input DVs in register bc
ld hl, EnemyMonDVs
ld a, b
ld [hli], a
ld [hl], c
; We've still got more to do if we're dealing with a wild monster
ld a, [IsInBattle]
dec a
jr nz, .Happiness
; Species-specfic:
; Unown
ld a, [TempEnemyMonSpecies]
cp a, UNOWN
jr nz, .Magikarp
; Get letter based on DVs
ld hl, EnemyMonDVs
ld a, PREDEF_GET_UNOWN_LETTER
call Predef
; Can't use any letters that haven't been unlocked
; If combined with forced shiny battletype, causes an infinite loop
call CheckUnownLetter
jr c, .GenerateDVs ; try again
.Magikarp
; Skimming this part recommended
ld a, [TempEnemyMonSpecies]
cp a, MAGIKARP
jr nz, .Happiness
; Get Magikarp's length
ld de, EnemyMonDVs
ld bc, PlayerID
callab CalcMagikarpLength
; We're clear if the length is < 1536
ld a, [MagikarpLength]
cp a, $06 ; $600 = 1536
jr nz, .CheckMagikarpArea
; 5% chance of skipping size checks
call Random
cp a, $0c ; / $100
jr c, .CheckMagikarpArea
; Try again if > 1614
ld a, [MagikarpLength + 1]
cp a, $50
jr nc, .GenerateDVs
; 20% chance of skipping this check
call Random
cp a, $32 ; / $100
jr c, .CheckMagikarpArea
; Try again if > 1598
ld a, [MagikarpLength + 1]
cp a, $40
jr nc, .GenerateDVs
.CheckMagikarpArea
; The z checks are supposed to be nz
; Instead, all maps in GROUP_LAKE_OF_RAGE (mahogany area)
; and routes 20 and 44 are treated as Lake of Rage
; This also means Lake of Rage Magikarp can be smaller than ones
; caught elsewhere rather than the other way around
; Intended behavior enforces a minimum size at Lake of Rage
; The real behavior prevents size flooring in the Lake of Rage area
ld a, [MapGroup]
cp a, GROUP_LAKE_OF_RAGE
jr z, .Happiness
ld a, [MapNumber]
cp a, MAP_LAKE_OF_RAGE
jr z, .Happiness
; 40% chance of not flooring
call Random
cp a, $64 ; / $100
jr c, .Happiness
; Floor at length 1024
ld a, [MagikarpLength]
cp a, 1024 >> 8
jr c, .GenerateDVs ; try again
; Finally done with DVs
.Happiness
; Set happiness
ld a, BASE_HAPPINESS
ld [EnemyMonHappiness], a
; Set level
ld a, [CurPartyLevel]
ld [EnemyMonLevel], a
; Fill stats
ld de, EnemyMonMaxHP
ld b, $00
ld hl, $d201 ; ?
ld a, PREDEF_FILLSTATS
call Predef
; If we're in a trainer battle,
; get the rest of the parameters from the party struct
ld a, [IsInBattle]
cp a, TRAINER_BATTLE
jr z, .OpponentParty
; If we're in a wild battle, check wild-specific stuff
and a
jr z, .TreeMon
; ????
ld a, [EnemySubStatus5]
bit 3, a
jp nz, .Moves
.TreeMon
; If we're headbutting trees, some monsters enter battle asleep
call CheckSleepingTreeMon
ld a, 7 ; Asleep for 7 turns
jr c, .UpdateStatus
; Otherwise, no status
xor a
.UpdateStatus
ld hl, EnemyMonStatus
ld [hli], a
; Unused byte
xor a
ld [hli], a
; Full HP...
ld a, [EnemyMonMaxHPHi]
ld [hli], a
ld a, [EnemyMonMaxHPLo]
ld [hl], a
; ...unless it's a RoamMon
ld a, [BattleType]
cp a, BATTLETYPE_ROAMING
jr nz, .Moves
; Grab HP
call GetRoamMonHP
ld a, [hl]
; Check if it's been initialized again
and a
jr z, .InitRoamHP
; Update from the struct if it has
ld a, [hl]
ld [EnemyMonHPLo], a
jr .Moves
.InitRoamHP
; HP only uses the lo byte in the RoamMon struct since
; Raikou/Entei/Suicune will have < 256 hp at level 40
ld a, [EnemyMonHPLo]
ld [hl], a
jr .Moves
.OpponentParty
; Get HP from the party struct
ld hl, (OTPartyMon1HP + 1)
ld a, [CurPartyMon]
call GetPartyLocation
ld a, [hld]
ld [EnemyMonHPLo], a
ld a, [hld]
ld [EnemyMonHPHi], a
; Make sure everything knows which monster the opponent is using
ld a, [CurPartyMon]
ld [CurOTMon], a
; Get status from the party struct
dec hl
ld a, [hl] ; OTPartyMonStatus
ld [EnemyMonStatus], a
.Moves
; ????
ld hl, BaseType1
ld de, EnemyMonType1
ld a, [hli]
ld [de], a
inc de
ld a, [hl]
ld [de], a
; Get moves
ld de, EnemyMonMoves
; Are we in a trainer battle?
ld a, [IsInBattle]
cp a, TRAINER_BATTLE
jr nz, .WildMoves
; Then copy moves from the party struct
ld hl, OTPartyMon1Moves
ld a, [CurPartyMon]
call GetPartyLocation
ld bc, NUM_MOVES
call CopyBytes
jr .PP
.WildMoves
; Clear EnemyMonMoves
xor a
ld h, d
ld l, e
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
; Make sure the predef knows this isn't a partymon
ld [MagikarpLength], a
; Fill moves based on level
ld a, PREDEF_FILLMOVES
call Predef
.PP
; Trainer battle?
ld a, [IsInBattle]
cp a, TRAINER_BATTLE
jr z, .TrainerPP
; Fill wild PP
ld hl, EnemyMonMoves
ld de, EnemyMonPP
ld a, PREDEF_FILLPP
call Predef
jr .Finish
.TrainerPP
; Copy PP from the party struct
ld hl, OTPartyMon1PP
ld a, [CurPartyMon]
call GetPartyLocation
ld de, EnemyMonPP
ld bc, NUM_MOVES
call CopyBytes
.Finish
; Only the first five base stats are copied...
ld hl, BaseStats
ld de, EnemyMonBaseStats
ld b, BaseSpecialDefense - BaseStats
.loop
ld a, [hli]
ld [de], a
inc de
dec b
jr nz, .loop
ld a, [BaseCatchRate]
ld [de], a
inc de
ld a, [BaseExp]
ld [de], a
ld a, [TempEnemyMonSpecies]
ld [$d265], a
call GetPokemonName
; Did we catch it?
ld a, [IsInBattle]
and a
ret z
; Update enemy nick
ld hl, StringBuffer1
ld de, EnemyMonNick
ld bc, PKMN_NAME_LENGTH
call CopyBytes
; Caught this mon
ld a, [TempEnemyMonSpecies]
dec a
ld c, a
ld b, 1 ; set
ld hl, PokedexSeen
ld a, PREDEF_FLAG
call Predef
ld hl, EnemyMonStats
ld de, EnemyStats
ld bc, EnemyMonStatsEnd - EnemyMonStats
call CopyBytes
ret
; 3eb38
CheckSleepingTreeMon: ; 3eb38
; Return carry if species is in the list
; for the current time of day
; Don't do anything if this isn't a tree encounter
ld a, [BattleType]
cp a, BATTLETYPE_TREE
jr nz, .NotSleeping
; Get list for the time of day
ld hl, .Morn
ld a, [TimeOfDay]
cp a, DAY
jr c, .Check
ld hl, .Day
jr z, .Check
ld hl, .Nite
.Check
ld a, [TempEnemyMonSpecies]
ld de, 1 ; length of species id
call IsInArray
; If it's a match, the opponent is asleep
ret c
.NotSleeping
and a
ret
.Nite
db CATERPIE
db METAPOD
db BUTTERFREE
db WEEDLE
db KAKUNA
db BEEDRILL
db SPEAROW
db EKANS
db EXEGGCUTE
db LEDYBA
db AIPOM
db $ff ; end
.Day
db VENONAT
db HOOTHOOT
db NOCTOWL
db SPINARAK
db HERACROSS
db $ff ; end
.Morn
db VENONAT
db HOOTHOOT
db NOCTOWL
db SPINARAK
db HERACROSS
db $ff ; end
; 3eb75
CheckUnownLetter: ; 3eb75
; Return carry if the Unown letter hasn't been unlocked yet
ld a, [UnlockedUnowns]
ld c, a
ld de, 0
.loop
; Don't check this set unless it's been unlocked
srl c
jr nc, .next
; Is our letter in the set?
ld hl, .LetterSets
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
push de
ld a, [UnownLetter]
ld de, 1
push bc
call IsInArray
pop bc
pop de
jr c, .match
.next
; Make sure we haven't gone past the end of the table
inc e
inc e
ld a, e
cp a, .Set1 - .LetterSets
jr c, .loop
; Hasn't been unlocked, or the letter is invalid
scf
ret
.match
; Valid letter
and a
ret
.LetterSets
dw .Set1
dw .Set2
dw .Set3
dw .Set4
.Set1
; A B C D E F G H I J K
db 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, $ff
.Set2
; L M N O P Q R
db 12, 13, 14, 15, 16, 17, 18, $ff
.Set3
; S T U V W
db 19, 20, 21, 22, 23, $ff
.Set4
; X Y Z
db 24, 25, 26, $ff
; 3ebc7
Function3ebc7: ; 3ebc7
push bc
ld a, [BattleMonLevel]
ld b, a
ld a, [EnemyMonLevel]
ld [BattleMonLevel], a
ld a, b
ld [EnemyMonLevel], a
pop bc
ret
; 3ebd8
Function3ebd8: ; 3ebd8
xor a
ld [TempEnemyMonSpecies], a
call Function3ee27
ld a, [OtherTrainerClass]
ld [TrainerClass], a
ld de, VTiles2
callab Function5120d
ld hl, $c4b3
ld c, $0
.asm_3ebf3
inc c
ld a, c
cp $7
ret z
xor a
ld [hBGMapMode], a
ld [hBGMapThird], a
ld d, $0
push bc
push hl
.asm_3ec01
call Function3ec1a
inc hl
ld a, $7
add d
ld d, a
dec c
jr nz, .asm_3ec01
ld a, $1
ld [hBGMapMode], a
ld c, $4
call DelayFrames
pop hl
pop bc
dec hl
jr .asm_3ebf3
; 3ec1a
Function3ec1a: ; 3ec1a
push hl
push de
push bc
ld e, $7
.asm_3ec1f
ld [hl], d
ld bc, $0014
add hl, bc
inc d
dec e
jr nz, .asm_3ec1f
pop bc
pop de
pop hl
ret
; 3ec2c
Function3ec2c: ; 3ec2c
ld a, 1
jr Function3ec31
; 3ec30
Function3ec30: ; 3ec30
xor a
; 3ec31
Function3ec31: ; 3ec31
ld [hBattleTurn], a
call Function3ec39
jp Function3ec76
; 3ec39
Function3ec39: ; 3ec39
ld a, [hBattleTurn]
and a
jr z, .asm_3ec5a
ld a, [BattleMonStatus]
and $40
ret z
ld hl, $c645
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
srl a
rr b
ld [hli], a
or b
jr nz, .asm_3ec58
ld b, $1
.asm_3ec58
ld [hl], b
ret
.asm_3ec5a
ld a, [EnemyMonStatus]
and $40
ret z
ld hl, $d21f
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
srl a
rr b
ld [hli], a
or b
jr nz, .asm_3ec74
ld b, $1
.asm_3ec74
ld [hl], b
ret
; 3ec76
Function3ec76: ; 3ec76
ld a, [hBattleTurn]
and a
jr z, .asm_3ec93
ld a, [BattleMonStatus]
and $10
ret z
ld hl, $c641
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
ld [hli], a
or b
jr nz, .asm_3ec91
ld b, $1
.asm_3ec91
ld [hl], b
ret
.asm_3ec93
ld a, [EnemyMonStatus]
and $10
ret z
ld hl, $d21b
ld a, [hld]
ld b, a
ld a, [hl]
srl a
rr b
ld [hli], a
or b
jr nz, .asm_3eca9
ld b, $1
.asm_3eca9
ld [hl], b
ret
; 3ecab
Function3ecab: ; 3ecab
ld c, 0
.asm_3ecad
call Function3ecb7
inc c
ld a, c
cp 5
jr nz, .asm_3ecad
ret
; 3ecb7
Function3ecb7: ; 3ecb7
push bc
push bc
ld a, [$d265]
and a
ld a, c
ld hl, BattleMonAtk
ld de, PlayerStats
ld bc, PlayerAtkLevel
jr z, .asm_3ecd2
ld hl, EnemyMonAtk
ld de, EnemyStats
ld bc, EnemyAtkLevel
.asm_3ecd2
add c
ld c, a
jr nc, .asm_3ecd7
inc b
.asm_3ecd7
ld a, [bc]
pop bc
ld b, a
push bc
sla c
ld b, 0
add hl, bc
ld a, c
add e
ld e, a
jr nc, .asm_3ece6
inc d
.asm_3ece6
pop bc
push hl
ld hl, .StatLevelMultipliers
dec b
sla b
ld c, b
ld b, 0
add hl, bc
xor a
ld [hMultiplicand], a
ld a, [de]
ld [$ffb5], a
inc de
ld a, [de]
ld [$ffb6], a
ld a, [hli]
ld [hMultiplier], a
call Multiply
ld a, [hl]
ld [hMultiplier], a
ld b, $4
call Divide
pop hl
; Cap at 999.
ld a, [$ffb6]
sub 999 % $100
ld a, [$ffb5]
sbc 999 / $100
jp c, .asm_3ed1e
ld a, 999 / $100
ld [$ffb5], a
ld a, 999 % $100
ld [$ffb6], a
.asm_3ed1e
ld a, [$ffb5]
ld [hli], a
ld b, a
ld a, [$ffb6]
ld [hl], a
or b
jr nz, .asm_3ed29
inc [hl]
.asm_3ed29
pop bc
ret
; 3ed2b
.StatLevelMultipliers
; /
db 25, 100 ; 25%
db 28, 100 ; 28%
db 33, 100 ; 33%
db 40, 100 ; 40%
db 50, 100 ; 50%
db 66, 100 ; 66%
db 1, 1 ; 100%
db 15, 10 ; 150%
db 2, 1 ; 200%
db 25, 10 ; 250%
db 3, 1 ; 300%
db 35, 10 ; 350%
db 4, 1 ; 400%
; 3ed45
BadgeStatBoosts: ; 3ed45
; Raise BattleMon stats depending on which badges have been obtained.
; Every other badge boosts a stat, starting from the first.
; ZephyrBadge: Attack
; PlainBadge: Speed
; MineralBadge: Defense
; GlacierBadge: Special Attack
; RisingBadge: Special Defense
; The boosted stats are in order, except PlainBadge and MineralBadge's boosts are swapped.
ld a, [InLinkBattle]
and a
ret nz
ld a, [$cfc0]
and a
ret nz
ld a, [JohtoBadges]
; Swap badges 3 (PlainBadge) and 5 (MineralBadge).
ld d, a
and %00000100
add a
add a
ld b, a
ld a, d
and %00010000
rrca
rrca
ld c, a
ld a, d
and %11101011
or b
or c
ld b, a
ld hl, BattleMonAtk
ld c, 4
.CheckBadge
ld a, b
srl b
call c, BoostStat
inc hl
inc hl
; Check every other badge.
srl b
dec c
jr nz, .CheckBadge
; And the last one (RisingBadge) too.
srl a
call c, BoostStat
ret
; 3ed7c
BoostStat: ; 3ed7c
; Raise stat at hl by 1/8.
ld a, [hli]
ld d, a
ld e, [hl]
srl d
rr e
srl d
rr e
srl d
rr e
ld a, [hl]
add e
ld [hld], a
ld a, [hl]
adc d
ld [hli], a
; Cap at 999.
ld a, [hld]
sub 999 % $100
ld a, [hl]
sbc 999 / $100
ret c
ld a, 999 / $100
ld [hli], a
ld a, 999 % $100
ld [hld], a
ret
; 3ed9f
Function3ed9f: ; 3ed9f
callab Functionfb4f2
ret
; 3eda6
Function3eda6: ; 3eda6
callab Functionfb50d
ret
; 3edad
Function3edad: ; 3edad
ld de, GFX_f8ac0
ld hl, $96c0
lb bc, BANK(GFX_f8ac0), 4
call Get1bpp
ld de, GFX_f8ae0
ld hl, $9730
lb bc, BANK(GFX_f8ae0), 6
call Get1bpp
ld de, GFX_f8b10
ld hl, $9550
lb bc, BANK(GFX_f8b10), 8
jp Get2bpp
; 3edd1
EmptyBattleTextBox: ; 3edd1
ld hl, .empty
jp BattleTextBox
.empty
db "@"
; 3edd8
_BattleRandom:: ; 3edd8
; If the normal RNG is used in a link battle it'll desync.
; To circumvent this a shared PRNG is used instead.
; But if we're in a non-link battle we're safe to use it
ld a, [InLinkBattle]
and a
jp z, Random
; The PRNG operates in streams of 10 values.
; Which value are we trying to pull?
push hl
push bc
ld a, [LinkBattleRNCount]
ld c, a
ld b, 0
ld hl, LinkBattleRNs
add hl, bc
inc a
ld [LinkBattleRNCount], a
; If we haven't hit the end yet, we're good
cp 10 - 1 ; Exclude last value. See the closing comment
ld a, [hl]
pop bc
pop hl
ret c
; If we have, we have to generate new pseudorandom data
; Instead of having multiple PRNGs, ten seeds are used
push hl
push bc
push af
; Reset count to 0
xor a
ld [LinkBattleRNCount], a
ld hl, LinkBattleRNs
ld b, 10 ; number of seeds
; Generate next number in the sequence for each seed
; The algorithm takes the form *5 + 1 % 256
.loop
; get last #
ld a, [hl]
; a * 5 + 1
ld c, a
add a
add a
add c
inc a
; update #
ld [hli], a
dec b
jr nz, .loop
; This has the side effect of pulling the last value first,
; then wrapping around. As a result, when we check to see if
; we've reached the end, we check the one before it.
pop af
pop bc
pop hl
ret
; 3ee0f
Function3ee0f: ; 3ee0f
ld a, BATTLE_VARS_SUBSTATUS3
call GetBattleVar
and 1 << SUBSTATUS_FLYING | 1 << SUBSTATUS_UNDERGROUND
ret nz
; 3ee17
Function3ee17: ; 3ee17
ld a, e
ld [FXAnimIDLo], a
ld a, d
ld [FXAnimIDHi], a
call WaitBGMap
ld a, $37
jp Predef
; 3ee27
Function3ee27: ; 3ee27
push af
push bc
push de
push hl
ld b, $1
call GetSGBLayout
call Function32f9
call DelayFrame
pop hl
pop de
pop bc
pop af
ret
; 3ee3b
Function3ee3b: ; 3ee3b
ld a, [InLinkBattle]
and a
ret nz
ld a, [$cfc0]
bit 0, a
ret nz
call Function3f0d4
xor a
ld [CurPartyMon], a
ld bc, PartyMon1Species
.asm_3ee50
ld hl, $0022
add hl, bc
ld a, [hli]
or [hl]
jp z, .asm_3f0b9
push bc
ld hl, $c664
ld a, [CurPartyMon]
ld c, a
ld b, $2
ld d, $0
ld a, $3
call Predef
ld a, c
and a
pop bc
jp z, .asm_3f0b9
ld hl, $000c
add hl, bc
ld d, h
ld e, l
ld hl, EnemyMonType2
push bc
ld c, $5
.asm_3ee7c
inc hl
ld a, [de]
add [hl]
ld [de], a
jr nc, .asm_3ee89
dec de
ld a, [de]
inc a
jr z, .asm_3eea4
ld [de], a
inc de
.asm_3ee89
push hl
push bc
ld a, $1c
call GetPartyParamLocation
ld a, [hl]
and a
pop bc
pop hl
jr z, .asm_3eea9
ld a, [de]
add [hl]
ld [de], a
jr nc, .asm_3eea9
dec de
ld a, [de]
inc a
jr z, .asm_3eea4
ld [de], a
inc de
jr .asm_3eea9
.asm_3eea4
ld a, $ff
ld [de], a
inc de
ld [de], a
.asm_3eea9
inc de
inc de
dec c
jr nz, .asm_3ee7c
xor a
ld [hMultiplicand], a
ld [$ffb5], a
ld a, [EnemyMonBaseExp]
ld [$ffb6], a
ld a, [EnemyMonLevel]
ld [hMultiplier], a
call Multiply
ld a, $7
ld [hMultiplier], a
ld b, $4
call Divide
pop bc
ld hl, $0006
add hl, bc
ld a, [PlayerID]
cp [hl]
jr nz, .asm_3eedd
inc hl
ld a, [$d47c]
cp [hl]
ld a, $0
jr z, .asm_3eee2
.asm_3eedd
call Function3f106
ld a, $1
.asm_3eee2
ld [$d088], a
ld a, [IsInBattle]
dec a
call nz, Function3f106
push bc
ld a, $1
call GetPartyParamLocation
ld a, [hl]
cp $7e
call z, Function3f106
ld a, [$ffb6]
ld [$d087], a
ld a, [$ffb5]
ld [StringBuffer2], a
ld a, [CurPartyMon]
ld hl, PartyMon1Nickname
call GetNick
ld hl, UnknownText_0x3f11b
call BattleTextBox
ld a, [$d087]
ld [$ffb6], a
ld a, [StringBuffer2]
ld [$ffb5], a
pop bc
call Function3f136
push bc
call Function309d
pop bc
ld hl, $000a
add hl, bc
ld d, [hl]
ld a, [$ffb6]
add d
ld [hld], a
ld d, [hl]
ld a, [$ffb5]
adc d
ld [hl], a
jr nc, .asm_3ef3d
dec hl
inc [hl]
jr nz, .asm_3ef3d
ld a, $ff
ld [hli], a
ld [hli], a
ld [hl], a
.asm_3ef3d
ld a, [CurPartyMon]
ld e, a
ld d, $0
ld hl, PartySpecies
add hl, de
ld a, [hl]
ld [CurSpecies], a
call GetBaseData
push bc
ld d, $64
callab Function50e47
pop bc
ld hl, $000a
add hl, bc
push bc
ld a, [hMultiplicand]
ld b, a
ld a, [$ffb5]
ld c, a
ld a, [$ffb6]
ld d, a
ld a, [hld]
sub d
ld a, [hld]
sbc c
ld a, [hl]
sbc b
jr c, .asm_3ef74
ld a, b
ld [hli], a
ld a, c
ld [hli], a
ld a, d
ld [hld], a
.asm_3ef74
xor a
ld [MonType], a
ld a, $1f
call Predef
callab Function50e1b
pop bc
ld hl, $001f
add hl, bc
ld a, [hl]
cp $64
jp nc, .asm_3f0b9
cp d
jp z, .asm_3f0b9
ld [$c719], a
ld a, [CurPartyLevel]
push af
ld a, d
ld [CurPartyLevel], a
ld [hl], a
ld hl, $0000
add hl, bc
ld a, [hl]
ld [CurSpecies], a
ld [$d265], a
call GetBaseData
ld hl, $0025
add hl, bc
ld a, [hld]
ld e, a
ld d, [hl]
push de
ld hl, $0024
add hl, bc
ld d, h
ld e, l
ld hl, $000a
add hl, bc
push bc
ld b, $1
ld a, $c
call Predef
pop bc
pop de
ld hl, $0025
add hl, bc
ld a, [hld]
sub e
ld e, a
ld a, [hl]
sbc d
ld d, a
dec hl
ld a, [hl]
add e
ld [hld], a
ld a, [hl]
adc d
ld [hl], a
ld a, [CurBattleMon]
ld d, a
ld a, [CurPartyMon]
cp d
jr nz, .asm_3f035
ld de, BattleMonHP
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
ld de, BattleMonMaxHP
push bc
ld bc, $000c
call CopyBytes
pop bc
ld hl, $001f
add hl, bc
ld a, [hl]
ld [BattleMonLevel], a
ld a, [PlayerSubStatus5]
bit 3, a
jr nz, .asm_3f012
ld hl, $0026
add hl, bc
ld de, PlayerStats
ld bc, $000a
call CopyBytes
.asm_3f012
xor a
ld [$d265], a
call Function3ecab
callab Function3ec2c
callab BadgeStatBoosts
callab Function3df48
call EmptyBattleTextBox
call Function309d
ld a, $1
ld [hBGMapMode], a
.asm_3f035
callba Function2709e
ld a, [CurBattleMon]
ld b, a
ld a, [CurPartyMon]
cp b
jr z, .asm_3f057
ld de, SFX_HIT_END_OF_EXP_BAR
call PlaySFX
call WaitSFX
ld hl, BattleText_0x80c9c
call StdBattleTextBox
call Function309d
.asm_3f057
xor a
ld [MonType], a
ld a, $1f
call Predef
ld hl, $c4a9
ld b, $a
ld c, $9
call TextBox
ld hl, $c4bf
ld bc, $0004
ld a, $28
call Predef
ld c, $1e
call DelayFrames
call Functiona80
call Function30b4
xor a
ld [MonType], a
ld a, [CurSpecies]
ld [$d265], a
ld a, [CurPartyLevel]
push af
ld c, a
ld a, [$c719]
ld b, a
.asm_3f093
inc b
ld a, b
ld [CurPartyLevel], a
push bc
ld a, $1a
call Predef
pop bc
ld a, b
cp c
jr nz, .asm_3f093
pop af
ld [CurPartyLevel], a
ld hl, EvolvableFlags
ld a, [CurPartyMon]
ld c, a
ld b, $1
ld a, $3
call Predef
pop af
ld [CurPartyLevel], a
.asm_3f0b9
ld a, [PartyCount]
ld b, a
ld a, [CurPartyMon]
inc a
cp b
jr z, .asm_3f0d1
ld [CurPartyMon], a
ld a, $0
call GetPartyParamLocation
ld b, h
ld c, l
jp .asm_3ee50
.asm_3f0d1
jp Function3d57a
; 3f0d4
Function3f0d4: ; 3f0d4
ld a, [$c664]
ld b, a
ld c, $6
ld d, $0
.asm_3f0dc
xor a
srl b
adc d
ld d, a
dec c
jr nz, .asm_3f0dc
cp $2
ret c
ld [$d265], a
ld hl, EnemyMonBaseStats
ld c, $7
.asm_3f0ef
xor a
ld [hProduct], a
ld a, [hl]
ld [hMultiplicand], a
ld a, [$d265]
ld [hMultiplier], a
ld b, $2
call Divide
ld a, [$ffb6]
ld [hli], a
dec c
jr nz, .asm_3f0ef
ret
; 3f106
Function3f106: ; 3f106
push bc
ld a, [$ffb5]
ld b, a
ld a, [$ffb6]
ld c, a
srl b
rr c
add c
ld [$ffb6], a
ld a, [$ffb5]
adc b
ld [$ffb5], a
pop bc
ret
; 3f11b
UnknownText_0x3f11b: ; 3f11b
text_jump UnknownText_0x1c029c
start_asm
ld hl, UnknownText_0x3f131
ld a, [$d088] ; IsTradedMon
and a
ret z
ld hl, UnknownText_0x3f12c
ret
; 3f12c
UnknownText_0x3f12c: ; 3f12c
text_jump UnknownText_0x1c02a9
db "@"
; 3f131
UnknownText_0x3f131: ; 3f131
text_jump UnknownText_0x1c02c9
db "@"
; 3f136
Function3f136: ; 3f136
push bc
ld hl, CurPartyMon
ld a, [CurBattleMon]
cp [hl]
jp nz, .asm_3f219
ld a, [BattleMonLevel]
cp MAX_LEVEL
jp nc, .asm_3f219
ld a, [$ffb6]
ld [$d004], a
push af
ld a, [$ffb5]
ld [$d003], a
push af
xor a
ld [DefaultFlypoint], a
xor a
ld [MonType], a
ld a, $1f
call Predef
ld a, [TempMonLevel]
ld b, a
ld e, a
push de
ld de, $d118
call Function3f39c
push bc
ld hl, $d118
ld a, [$d004]
add [hl]
ld [hld], a
ld a, [$d003]
adc [hl]
ld [hld], a
jr nc, .asm_3f186
inc [hl]
jr nz, .asm_3f186
ld a, $ff
ld [hli], a
ld [hli], a
ld [hl], a
.asm_3f186
ld d, $64
callab Function50e47
ld a, [hMultiplicand]
ld b, a
ld a, [$ffb5]
ld c, a
ld a, [$ffb6]
ld d, a
ld hl, $d118
ld a, [hld]
sub d
ld a, [hld]
sbc c
ld a, [hl]
sbc b
jr c, .asm_3f1a8
ld a, b
ld [hli], a
ld a, c
ld [hli], a
ld a, d
ld [hld], a
.asm_3f1a8
callab Function50e1b
ld a, d
pop bc
pop de
ld d, a
cp e
jr nc, .asm_3f1b7
ld a, e
ld d, a
.asm_3f1b7
ld a, e
cp MAX_LEVEL
jr nc, .asm_3f1ff
cp d
jr z, .asm_3f1ff
inc a
ld [TempMonLevel], a
ld [CurPartyLevel], a
ld [BattleMonLevel], a
push de
call Function3f21b
ld c, $40
call Function3f22c
call PrintPlayerHUD
ld hl, BattleMonNick
ld de, StringBuffer1
ld bc, $000b
call CopyBytes
call Function3dfe
ld de, SFX_HIT_END_OF_EXP_BAR
call PlaySFX
callba Function8e79d
call WaitSFX
ld hl, BattleText_0x80c9c
call StdBattleTextBox
pop de
inc e
ld b, $0
jr .asm_3f1b7
.asm_3f1ff
push bc
ld b, d
ld de, $d118
call Function3f39c
ld a, b
pop bc
ld c, a
call Function3f21b
call Function3f22c
call Function3dfe
pop af
ld [$ffb5], a
pop af
ld [$ffb6], a
.asm_3f219
pop bc
ret
; 3f21b
Function3f21b: ; 3f21b
push bc
call WaitSFX
ld de, SFX_EXP_BAR
call PlaySFX
ld c, 10
call DelayFrames
pop bc
ret
; 3f22c
Function3f22c: ; 3f22c
ld d, $3
dec b
.asm_3f22f
inc b
push bc
push de
ld hl, $c58d
call Function3f41c
pop de
ld a, $1
ld [hBGMapMode], a
ld c, d
call DelayFrames
xor a
ld [hBGMapMode], a
pop bc
ld a, c
cp b
jr z, .asm_3f268
inc b
push bc
push de
ld hl, $c58d
call Function3f41c
pop de
ld a, $1
ld [hBGMapMode], a
ld c, d
call DelayFrames
xor a
ld [hBGMapMode], a
dec d
jr nz, .asm_3f263
ld d, $1
.asm_3f263
pop bc
ld a, c
cp b
jr nz, .asm_3f22f
.asm_3f268
ld a, $1
ld [hBGMapMode], a
ret
; 3f26d
Function3f26d: ; 3f26d
; SendOutMonText?
ld a, [InLinkBattle]
and a
jr z, .asm_3f27c
ld hl, UnknownText_0x3f2d1
ld a, [$d264]
and a
jr nz, .asm_3f2ce
.asm_3f27c
ld hl, EnemyMonHPHi
ld a, [hli]
or [hl]
ld hl, UnknownText_0x3f2d1
jr z, .asm_3f2ce
xor a
ld [hMultiplicand], a
ld hl, EnemyMonHPHi
ld a, [hli]
ld [$c6ea], a
ld [$ffb5], a
ld a, [hl]
ld [$c6eb], a
ld [$ffb6], a
ld a, $19
ld [hMultiplier], a
call Multiply
ld hl, EnemyMonMaxHPHi
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, $4
ld [hMultiplier], a
call Divide
ld a, [$ffb6]
ld hl, UnknownText_0x3f2d1
cp $46
jr nc, .asm_3f2ce
ld hl, UnknownText_0x3f2d8
cp $28
jr nc, .asm_3f2ce
ld hl, UnknownText_0x3f2df
cp $a
jr nc, .asm_3f2ce
ld hl, UnknownText_0x3f2e6
.asm_3f2ce
jp BattleTextBox
; 3f2d1
UnknownText_0x3f2d1: ; 3f2d1
text_jump UnknownText_0x1c02df
start_asm
jr Function3f2eb
; 3f2d6
UnknownText_0x3f2d8: ; 3f2d8
text_jump UnknownText_0x1c02e6
start_asm
jr Function3f2eb
; 3f2dd
UnknownText_0x3f2df: ; 3f2df
text_jump UnknownText_0x1c02f0
start_asm
jr Function3f2eb
; 3f2e4
UnknownText_0x3f2e6: ; 3f2e6
text_jump UnknownText_0x1c02fe
start_asm
; 3f2eb
Function3f2eb: ; 3f2eb
ld hl, UnknownText_0x3f2ef
ret
; 3f2ef
UnknownText_0x3f2ef: ; 3f2ef
text_jump UnknownText_0x1c0317
db "@"
; 3f2f4
Function3f2f4: ; 3f2f4
ld hl, UnknownText_0x3f2fa
jp BattleTextBox
; 3f2fa
UnknownText_0x3f2fa: ; 3f2fa
text_jump UnknownText_0x1c031d
start_asm
; 3f2ff
Function3f2ff: ; 3f2ff
push de
push bc
ld hl, EnemyMonHPLo
ld de, $c6eb
ld b, [hl]
dec hl
ld a, [de]
sub b
ld [$ffb6], a
dec de
ld b, [hl]
ld a, [de]
sbc b
ld [$ffb5], a
ld a, $19
ld [hMultiplier], a
call Multiply
ld hl, EnemyMonMaxHPHi
ld a, [hli]
ld b, [hl]
srl a
rr b
srl a
rr b
ld a, b
ld b, $4
ld [hMultiplier], a
call Divide
pop bc
pop de
ld a, [$ffb6]
ld hl, UnknownText_0x3f348
and a
ret z
ld hl, UnknownText_0x3f35b
cp $1e
ret c
ld hl, UnknownText_0x3f34d
cp $46
ret c
ld hl, UnknownText_0x3f352
ret
; 3f348
UnknownText_0x3f348: ; 3f348
text_jump UnknownText_0x1c0324
db "@"
; 3f34d
UnknownText_0x3f34d: ; 3f34d
text_jump UnknownText_0x1c0340
db "@"
; 3f352
UnknownText_0x3f352: ; 3f352
text_jump UnknownText_0x1c0352
db "@"
; 3f357
Function3f357: ; 3f357
ld hl, UnknownText_0x3f35b
ret
; 3f35b
UnknownText_0x3f35b: ; 3f35b
text_jump UnknownText_0x1c0366
db "@"
; 3f360
Function3f360: ; 3f360
ld hl, $c6f0
ld a, [hl]
and a
jr z, .asm_3f36d
dec [hl]
ld hl, BattleText_0x80cba
jr .asm_3f388
.asm_3f36d
dec hl
ld a, [hl]
and a
ret z
dec [hl]
ld hl, BattleText_0x80cd1
jr nz, .asm_3f388
push hl
ld a, [EnemyMonSpecies]
ld [CurSpecies], a
call GetBaseData
ld a, [BaseCatchRate]
ld [EnemyMonCatchRate], a
pop hl
.asm_3f388
push hl
call Function30b4
pop hl
jp StdBattleTextBox
; 3f390
FillInExpBar: ; 3f390
push hl
call Function3f39c
pop hl
ld de, $0007
add hl, de
jp Function3f41c
; 3f39c
Function3f39c: ; 3f39c
push de
ld d, b
push de
callab Function50e47
pop de
ld hl, hMultiplicand
ld a, [hli]
push af
ld a, [hli]
push af
ld a, [hl]
push af
inc d
callab Function50e47
ld hl, $ffb6
ld a, [hl]
ld [$ffba], a
pop bc
sub b
ld [hld], a
ld a, [hl]
ld [$ffb9], a
pop bc
sbc b
ld [hld], a
ld a, [hl]
ld [hMathBuffer], a
pop bc
sbc b
ld [hl], a
pop de
ld hl, $ffb5
ld a, [hli]
push af
ld a, [hl]
push af
ld a, [de]
dec de
ld c, a
ld a, [$ffba]
sub c
ld [hld], a
ld a, [de]
dec de
ld b, a
ld a, [$ffb9]
sbc b
ld [hld], a
ld a, [de]
ld c, a
ld a, [hMathBuffer]
sbc c
ld [hld], a
xor a
ld [hl], a
ld a, $40
ld [hMultiplier], a
call Multiply
pop af
ld c, a
pop af
ld b, a
.asm_3f3f4
ld a, b
and a
jr z, .asm_3f40c
srl b
rr c
ld hl, hProduct
srl [hl]
inc hl
rr [hl]
inc hl
rr [hl]
inc hl
rr [hl]
jr .asm_3f3f4
.asm_3f40c
ld a, c
ld [hMultiplier], a
ld b, $4
call Divide
ld a, [$ffb6]
ld b, a
ld a, $40
sub b
ld b, a
ret
; 3f41c
Function3f41c: ; 3f41c
ld c, $8
.asm_3f41e
ld a, b
sub $8
jr c, .asm_3f42c
ld b, a
ld a, $6a
ld [hld], a
dec c
jr z, .asm_3f43c
jr .asm_3f41e
.asm_3f42c
add $8
jr z, .asm_3f434
add $54
jr .asm_3f436
.asm_3f434
ld a, $62
.asm_3f436
ld [hld], a
ld a, $62
dec c
jr nz, .asm_3f434
.asm_3f43c
ret
; 3f43d
Function3f43d: ; 3f43d
ld a, [PlayerSubStatus4]
bit 4, a
ld hl, BattleAnimCmd_DD
jr nz, Function3f46f
Function3f447: ; 3f447
ld a, [$c6fe]
and a
ld hl, BattleAnimCmd_E2
jr nz, Function3f46f
ld a, [CurPartySpecies]
push af
ld a, [BattleMonSpecies]
ld [CurPartySpecies], a
ld hl, BattleMonAtkDefDV
ld a, $2d
call Predef
ld de, $9310
ld a, $3d
call Predef
pop af
ld [CurPartySpecies], a
ret
; 3f46f
Function3f46f: ; 3f46f
ld a, [hBattleTurn]
push af
xor a
ld [hBattleTurn], a
ld a, BANK(BattleAnimCommands)
rst FarCall
pop af
ld [hBattleTurn], a
ret
; 3f47c
Function3f47c: ; 3f47c
ld a, [EnemySubStatus4]
bit 4, a
ld hl, BattleAnimCmd_DD
jr nz, Function3f4b4
Function3f486: ; 3f486
ld a, [$c6fa]
and a
ld hl, BattleAnimCmd_E2
jr nz, Function3f4b4
ld a, [CurPartySpecies]
push af
ld a, [EnemyMonSpecies]
ld [CurSpecies], a
ld [CurPartySpecies], a
call GetBaseData
ld hl, EnemyMonAtkDefDV
ld a, $2d
call Predef
ld de, VTiles2
ld a, $3e
call Predef
pop af
ld [CurPartySpecies], a
ret
; 3f4b4
Function3f4b4: ; 3f4b4
ld a, [hBattleTurn]
push af
call SetEnemyTurn
ld a, BANK(BattleAnimCommands)
rst FarCall
pop af
ld [hBattleTurn], a
ret
; 3f4c1
StartBattle: ; 3f4c1
ld a, [PartyCount]
and a
ret z
ld a, [TimeOfDayPal]
push af
call Function3f4dd
call Function3c000
call Function3f69e
pop af
ld [TimeOfDayPal], a
scf
ret
; 3f4d9
Function3f4d9: ; 3f4d9
call Function3c000
ret
; 3f4dd
Function3f4dd: ; 3f4dd
callba Function106050
call Function3f54e
xor a
ld [TempBattleMonSpecies], a
ld [$d0d2], a
xor a
ld [$ffde], a
callba PlayBattleMusic
callba Function2ee18
callba Function2ee2f
call Function2ed3
callba ClearBattleRAM
call Function3f55e
call Function3f568
ld b, $0
call GetSGBLayout
ld hl, rLCDC
res 6, [hl]
call Function3fb6c
call BattleStartMessage
ld hl, rLCDC
set 6, [hl]
xor a
ld [hBGMapMode], a
call EmptyBattleTextBox
hlcoord 9, 7
ld bc, 5 << 8 + 11
call ClearBox
hlcoord 1, 0
ld bc, 4 << 8 + 10
call ClearBox
call ClearSprites
ld a, [IsInBattle]
cp $1
call z, Function3e036
ld a, $1
ld [hBGMapMode], a
ret
; 3f54e
Function3f54e: ; 3f54e
ld a, [OtherTrainerClass]
and a
jr nz, .asm_3f55a
ld a, [$d22e]
ld [CurPartySpecies], a
.asm_3f55a
ld [TempEnemyMonSpecies], a
ret
; 3f55e
Function3f55e: ; 3f55e
ld a, [OtherTrainerClass]
and a
jp nz, Function3f594
jp Function3f607
; 3f568
Function3f568: ; 3f568
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
ld hl, $d000
ld bc, VBlank5
ld a, $2
call ByteFill
ld a, [rVBK]
push af
ld a, $1
ld [rVBK], a
ld de, $d000
ld hl, VBGMap0
ld bc, $0f40
call Request2bpp
pop af
ld [rVBK], a
pop af
ld [rSVBK], a
ret
; 3f594
Function3f594: ; 3f594
ld [TrainerClass], a
callba Function10606a
xor a
ld [TempEnemyMonSpecies], a
callab Function3957b
callab Function39771
ld a, [TrainerClass]
cp $9
jr nz, .asm_3f5b8
xor a
ld [OTPartyMon1Item], a
.asm_3f5b8
ld de, VTiles2
callab Function5120d
xor a
ld [$ffad], a
dec a
ld [$c6e6], a
ld hl, $c4ac
ld bc, $0707
ld a, $13
call Predef
ld a, $ff
ld [CurOTMon], a
ld a, $2
ld [IsInBattle], a
call IsJohtoGymLeader
jr nc, .asm_3f606
xor a
ld [CurPartyMon], a
ld a, [PartyCount]
ld b, a
.asm_3f5ea
push bc
ld a, $22
call GetPartyParamLocation
ld a, [hli]
or [hl]
jr z, .asm_3f5fc
ld c, $4
callab ChangeHappiness
.asm_3f5fc
pop bc
dec b
jr z, .asm_3f606
ld hl, CurPartyMon
inc [hl]
jr .asm_3f5ea
.asm_3f606
ret
; 3f607
Function3f607: ; 3f607
ld a, $1
ld [IsInBattle], a
callba Function10605d
call LoadEnemyMon
ld hl, EnemyMonMove1
ld de, $c735
ld bc, $0004
call CopyBytes
ld hl, EnemyMonPPMove1
ld de, $c739
ld bc, $0004
call CopyBytes
ld hl, EnemyMonAtkDefDV
ld a, $2d
call Predef
ld a, [CurPartySpecies]
cp $c9
jr nz, .asm_3f648
ld a, [$def4]
and a
jr nz, .asm_3f648
ld a, [UnownLetter]
ld [$def4], a
.asm_3f648
ld de, VTiles2
ld a, $3e
call Predef
xor a
ld [TrainerClass], a
ld [$ffad], a
ld hl, $c4ac
ld bc, $0707
ld a, $13
call Predef
ret
; 3f662
Function3f662: ; 3f662
ld hl, EnemyMonMove1
ld de, $d25e
ld b, 4
.loop
ld a, [de]
inc de
ld [hli], a
and a
jr z, .clearpp
push bc
push hl
push hl
dec a
ld hl, Moves + MOVE_PP
ld bc, Move2 - Move1
call AddNTimes
ld a, BANK(Moves)
call GetFarByte
pop hl
ld bc, EnemyMonPP - (EnemyMonMoves + 1)
add hl, bc
ld [hl], a
pop hl
pop bc
dec b
jr nz, .loop
ret
.clear
xor a
ld [hli], a
.clearpp
push bc
push hl
ld bc, EnemyMonPP - (EnemyMonMoves + 1)
add hl, bc
xor a
ld [hl], a
pop hl
pop bc
dec b
jr nz, .clear
ret
; 3f69e
Function3f69e: ; 3f69e
call Function3f6a5
call Function3f6d0
ret
; 3f6a5
Function3f6a5: ; 3f6a5
ld a, [InLinkBattle]
and a
jr z, .asm_3f6b7
call Function3f759
ld c, $96
call DelayFrames
call Function3f77c
ret
.asm_3f6b7
ld a, [$d0ee]
and $f
ret nz
call Function3f71d
xor a
ld [$d1e9], a
ld a, $1c
call Predef
callba Function2ed44
ret
; 3f6d0
Function3f6d0: ; 3f6d0
call Function3f998
xor a
ld [Danger], a
ld [IsInBattle], a
ld [BattleType], a
ld [AttackMissed], a
ld [$d22e], a
ld [OtherTrainerClass], a
ld [$d266], a
ld [$d267], a
ld [$d232], a
ld [$d0d8], a
ld [$d0da], a
ld [$d0d9], a
ld [$d0d2], a
ld [CurMoveNum], a
ld [$d0db], a
ld [$d0d6], a
ld [$d0e4], a
ld [$d0e0], a
ld [$d0df], a
ld [$d0e1], a
ld hl, PlayerSubStatus1
ld b, $18
.asm_3f715
ld [hli], a
dec b
jr nz, .asm_3f715
call WaitSFX
ret
; 3f71d
Function3f71d: ; 3f71d
ld hl, $c6ec
ld a, [hli]
or [hl]
inc hl
or [hl]
ret z
ld a, [$c73d]
and a
jr z, .asm_3f73d
ld hl, $c6ee
sla [hl]
dec hl
rl [hl]
dec hl
rl [hl]
jr nc, .asm_3f73d
ld a, $ff
ld [hli], a
ld [hli], a
ld [hl], a
.asm_3f73d
ld hl, $c6ee
ld de, $d850
call Function3d0be
ld hl, BattleText_0x80730
call StdBattleTextBox
ld a, [$cfc0]
bit 0, a
ret z
call ClearTileMap
call WhiteBGMap
ret
; 3f759
Function3f759: ; 3f759
callba Function1060df
callba Function106187
ld a, [CurOTMon]
ld hl, OTPartyMon1Status
call GetPartyLocation
ld a, [EnemyMonStatus]
ld [hl], a
call ClearTileMap
callba Function2c1b2
ret
; 3f77c
Function3f77c: ; 3f77c
callba Function3d2e0
jp c, Function3f80f
call Function3f830
jr nz, .asm_3f797
ld hl, $cd2a
bit 4, [hl]
jr z, .asm_3f797
callba Function2b930
.asm_3f797
ld a, [$d0ee]
and $f
cp $1
jr c, .asm_3f7ad
jr z, .asm_3f7b8
callba Function106107
ld de, .Draw
jr .asm_3f7c3
.asm_3f7ad
callba Function1060fb
ld de, .Win
jr .asm_3f7c3
.asm_3f7b8
callba Function106101
ld de, .Lose
jr .asm_3f7c3
.asm_3f7c3
ld hl, $c546
call PlaceString
callba Function106187
ld c, $c8
call DelayFrames
ld a, $1
call GetSRAMBank
call Function3fa42
call Function3f85f
call CloseSRAM
call Function3f830
jr z, .asm_3f7ee
call Functiona80
call ClearTileMap
ret
.asm_3f7ee
ld c, $c8
call DelayFrames
call ClearTileMap
ret
; 3f7f7
.Win
db "YOU WIN@"
.Lose
db "YOU LOSE@"
.Draw
db " DRAW@"
; 3f80f
Function3f80f: ; 3f80f
ld hl, $c546
ld de, .Invalid
call PlaceString
ld c, $c8
call DelayFrames
call ClearTileMap
ret
; 3f821
.Invalid
db "INVALID BATTLE@"
; 3f830
Function3f830: ; 3f830
ld a, [InLinkBattle]
cp $4
ret
; 3f836
Function3f836: ; 3f836
ld a, $1
call GetSRAMBank
call Function3f85f
call CloseSRAM
ld hl, AttrMap
xor a
ld bc, $0168
call ByteFill
call Function3200
ld b, $8
call GetSGBLayout
call Function32f9
ld c, $8
call DelayFrames
call Functiona80
ret
; 3f85f
Function3f85f: ; 3f85f
call ClearTileMap
call ClearSprites
call .asm_3f8e0
ld hl, $c540
ld b, $5
ld de, $b268
.asm_3f870
push bc
push hl
push de
ld a, [de]
and a
jr z, .asm_3f8c9
ld a, [$d4b4]
and a
jr z, .asm_3f8c9
push hl
push hl
ld h, d
ld l, e
ld de, DefaultFlypoint
ld bc, $000a
call CopyBytes
ld a, $50
ld [de], a
inc de
ld bc, $0006
call CopyBytes
ld de, DefaultFlypoint
pop hl
call PlaceString
pop hl
ld de, $001a
add hl, de
push hl
ld de, $d00d
ld bc, $0204
call PrintNum
pop hl
ld de, $0005
add hl, de
push hl
ld de, $d00f
ld bc, $0204
call PrintNum
pop hl
ld de, $0005
add hl, de
ld de, $d011
ld bc, $0204
call PrintNum
jr .asm_3f8cf
.asm_3f8c9
ld de, .Format
call PlaceString
.asm_3f8cf
pop hl
ld bc, $0012
add hl, bc
ld d, h
ld e, l
pop hl
ld bc, $0028
add hl, bc
pop bc
dec b
jr nz, .asm_3f870
ret
.asm_3f8e0
ld hl, $c4a1
ld de, .Record
call PlaceString
ld hl, $c518
ld de, .Result
call PlaceString
ld hl, $c4c8
ld de, .Total
call PlaceString
ld hl, $c4f6
ld de, $b260
call .asm_3f92b
jr c, .asm_3f92a
ld bc, $0204
call PrintNum
ld hl, $c4fb
ld de, $b262
call .asm_3f92b
ld bc, $0204
call PrintNum
ld hl, $c500
ld de, $b264
call .asm_3f92b
ld bc, $0204
call PrintNum
.asm_3f92a
ret
.asm_3f92b
ld a, [$d4b4]
and a
ret nz
ld de, .Scores
call PlaceString
scf
ret
; 3f938
.Scores
db " 0 0 0@"
; 3f947
.Format ; 3f947
db " --- ", $22, " - - -@"
.Record ; 3f964
db $52, "'s RECORD@"
.Result ; 3f96e
db "RESULT WIN LOSE DRAW@"
.Total ; 3f983
db "TOTAL WIN LOSE DRAW@"
; 3f998
Function3f998: ; 3f998
ld a, [BattleType]
cp BATTLETYPE_ROAMING
jr nz, .asm_3f9c4
ld a, [$d0ee]
and $f
jr z, .asm_3f9af
call GetRoamMonHP
ld a, [EnemyMonHPLo]
ld [hl], a
jr .asm_3f9ca
.asm_3f9af
call GetRoamMonHP
ld [hl], $0
call GetRoamMonMapGroup
ld [hl], $ff
call GetRoamMonMapNumber
ld [hl], $ff
call GetRoamMonSpecies
ld [hl], $0
ret
.asm_3f9c4
call BattleRandom
and $f
ret nz
.asm_3f9ca
callab Function2a30d
ret
; 3f9d1
GetRoamMonMapGroup: ; 3f9d1
ld a, [TempEnemyMonSpecies]
ld b, a
ld a, [RoamMon1Species]
cp b
ld hl, RoamMon1MapGroup
ret z
ld a, [RoamMon2Species]
cp b
ld hl, RoamMon2MapGroup
ret z
ld hl, RoamMon3MapGroup
ret
; 3f9e9
GetRoamMonMapNumber: ; 3f9e9
ld a, [TempEnemyMonSpecies]
ld b, a
ld a, [RoamMon1Species]
cp b
ld hl, RoamMon1MapNumber
ret z
ld a, [RoamMon2Species]
cp b
ld hl, RoamMon2MapNumber
ret z
ld hl, RoamMon3MapNumber
ret
; 3fa01
GetRoamMonHP: ; 3fa01
; output: hl = RoamMonHP
ld a, [TempEnemyMonSpecies]
ld b, a
ld a, [RoamMon1Species]
cp b
ld hl, RoamMon1HP
ret z
ld a, [RoamMon2Species]
cp b
ld hl, RoamMon2HP
ret z
ld hl, RoamMon3HP
ret
; 3fa19
GetRoamMonDVs: ; 3fa19
; output: hl = RoamMonDVs
ld a, [TempEnemyMonSpecies]
ld b, a
ld a, [RoamMon1Species]
cp b
ld hl, RoamMon1DVs
ret z
ld a, [RoamMon2Species]
cp b
ld hl, RoamMon2DVs
ret z
ld hl, RoamMon3DVs
ret
; 3fa31
GetRoamMonSpecies: ; 3fa31
ld a, [TempEnemyMonSpecies]
ld hl, RoamMon1Species
cp [hl]
ret z
ld hl, RoamMon2Species
cp [hl]
ret z
ld hl, RoamMon3Species
ret
; 3fa42
Function3fa42: ; 3fa42
ld hl, $d276
ld de, StringBuffer1
ld bc, $0002
call CopyBytes
ld hl, $d26b
ld bc, $000a
call CopyBytes
ld hl, $b254
call Function3faa0
ld hl, $b266
ld d, $5
.asm_3fa62
push hl
inc hl
inc hl
ld a, [hl]
dec hl
dec hl
and a
jr z, .asm_3fa85
push de
ld bc, $000c
ld de, StringBuffer1
call CompareLong
pop de
pop hl
jr c, .asm_3fa99
ld bc, $0012
add hl, bc
dec d
jr nz, .asm_3fa62
ld bc, $ffee
add hl, bc
push hl
.asm_3fa85
ld d, h
ld e, l
ld hl, StringBuffer1
ld bc, $000c
call CopyBytes
ld b, $6
xor a
.asm_3fa93
ld [de], a
inc de
dec b
jr nz, .asm_3fa93
pop hl
.asm_3fa99
call Function3faa0
call Function3fac8
ret
; 3faa0
Function3faa0: ; 3faa0
ld a, [$d0ee]
and $f
cp $1
ld bc, $000d
jr c, .asm_3fab4
ld bc, $000f
jr z, .asm_3fab4
ld bc, $0011
.asm_3fab4
add hl, bc
call Function3fabe
ret nc
inc [hl]
ret nz
dec hl
inc [hl]
ret
; 3fabe
Function3fabe: ; 3fabe
dec hl
ld a, [hl]
inc hl
cp $27
ret c
ld a, [hl]
cp $f
ret
; 3fac8
Function3fac8: ; 3fac8
ld b, $5
ld hl, $b277
ld de, DefaultFlypoint
.asm_3fad0
push bc
push de
push hl
call Function3fb54
pop hl
ld a, e
pop de
ld [de], a
inc de
ld a, b
ld [de], a
inc de
ld a, c
ld [de], a
inc de
ld bc, $0012
add hl, bc
pop bc
dec b
jr nz, .asm_3fad0
ld b, $0
ld c, $1
.asm_3faed
ld a, b
add b
add b
ld e, a
ld d, $0
ld hl, DefaultFlypoint
add hl, de
push hl
ld a, c
add c
add c
ld e, a
ld d, $0
ld hl, DefaultFlypoint
add hl, de
ld d, h
ld e, l
pop hl
push bc
ld c, $3
call StringCmp
pop bc
jr z, .asm_3fb10
jr nc, .asm_3fb1f
.asm_3fb10
inc c
ld a, c
cp $5
jr nz, .asm_3faed
inc b
ld c, b
inc c
ld a, b
cp $4
jr nz, .asm_3faed
ret
.asm_3fb1f
push bc
ld a, b
ld bc, $0012
ld hl, $b266
call AddNTimes
push hl
ld de, DefaultFlypoint
ld bc, $0012
call CopyBytes
pop hl
pop bc
push hl
ld a, c
ld bc, $0012
ld hl, $b266
call AddNTimes
pop de
push hl
ld bc, $0012
call CopyBytes
ld hl, DefaultFlypoint
ld bc, $0012
pop de
call CopyBytes
ret
; 3fb54
Function3fb54: ; 3fb54
ld e, $0
ld a, [hld]
ld c, a
ld a, [hld]
ld b, a
ld a, [hld]
add c
ld c, a
ld a, [hld]
adc b
ld b, a
jr nc, .asm_3fb63
inc e
.asm_3fb63
ld a, [hld]
add c
ld c, a
ld a, [hl]
adc b
ld b, a
ret nc
inc e
ret
; 3fb6c
Function3fb6c: ; 3fb6c
call Function3fbf8
ld hl, $c590
ld b, $4
ld c, $12
call TextBox
callba MobileTextBorder
ld hl, $c505
ld bc, $0307
call ClearBox
call Functione51
call Function3ed9f
call Function3fbd6
xor a
ld [$ffde], a
ld [hSCY], a
ld a, $90
ld [hWY], a
ld [rWY], a
call WaitBGMap
xor a
ld [hBGMapMode], a
callba Function4e980
ld a, $1
ld [hBGMapMode], a
ld a, $31
ld [$ffad], a
ld hl, $c51a
ld bc, $0606
ld a, $13
call Predef
xor a
ld [hWY], a
ld [rWY], a
call WaitBGMap
call HideSprites
ld b, $1
call GetSGBLayout
call Function32f9
ld a, $90
ld [hWY], a
xor a
ld [hSCX], a
ret
; 3fbd6
Function3fbd6: ; 3fbd6
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
ld hl, $d000
ld bc, VBlank5
ld a, $7f
call ByteFill
ld de, $d000
ld hl, VBGMap0
ld bc, $0f40
call Request2bpp
pop af
ld [rSVBK], a
ret
; 3fbf8
Function3fbf8: ; 3fbf8
call GetBattleBackpic
call Function3fc30
ret
; 3fbff
GetBattleBackpic: ; 3fbff
; Load the player character's backpic (6x6) into VRAM starting from $9310.
; Special exception for Dude.
ld b, BANK(DudeBackpic)
ld hl, DudeBackpic
ld a, [BattleType]
cp BATTLETYPE_TUTORIAL
jr z, .Decompress
; What gender are we?
ld a, [$d45b]
bit 2, a
jr nz, .Chris
ld a, [PlayerGender]
bit 0, a
jr z, .Chris
; It's a girl.
callba GetKrisBackpic
ret
.Chris
; It's a boy.
ld b, BANK(ChrisBackpic)
ld hl, ChrisBackpic
.Decompress
ld de, $9310
ld c, $31
ld a, PREDEF_DECOMPRESS
call Predef
ret
; 3fc30
Function3fc30: ; 3fc30
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
ld hl, VTiles0
ld de, $9310
ld a, [hROMBank]
ld b, a
ld c, $31
call Get2bpp
pop af
ld [rSVBK], a
call Function3fc5b
ld a, $31
ld [$ffad], a
ld hl, $c51a
ld bc, $0606
ld a, $13
call Predef
ret
; 3fc5b
Function3fc5b: ; 3fc5b
ld hl, Sprites
xor a
ld [hConnectionStripLength], a
ld b, $6
ld e, $a8
.asm_3fc65
ld c, $3
ld d, $40
.asm_3fc69
ld [hl], d
inc hl
ld [hl], e
inc hl
ld a, [hConnectionStripLength]
ld [hli], a
inc a
ld [hConnectionStripLength], a
ld a, $1
ld [hli], a
ld a, d
add $8
ld d, a
dec c
jr nz, .asm_3fc69
ld a, [hConnectionStripLength]
add $3
ld [hConnectionStripLength], a
ld a, e
add $8
ld e, a
dec b
jr nz, .asm_3fc65
ret
; 3fc8b
BattleStartMessage: ; 3fc8b
ld a, [IsInBattle]
dec a
jr z, .asm_3fcaa
ld de, SFX_SHINE
call PlaySFX
call WaitSFX
ld c, 20
call DelayFrames
callba Function39939
ld hl, WantsToBattleText
jr .asm_3fd0e
.asm_3fcaa
call Function3da79
jr nc, .asm_3fcc2
xor a
ld [$cfca], a
ld a, 1
ld [hBattleTurn], a
ld a, 1
ld [$c689], a
ld de, $0101
call Function3ee17
.asm_3fcc2
callba CheckSleepingTreeMon
jr c, .asm_3fceb
callba CheckBattleScene
jr c, .asm_3fce0
hlcoord 12, 0
ld d, $0
ld e, $1
ld a, $47
call Predef
jr .asm_3fceb
.asm_3fce0
ld a, $0f
ld [CryTracks], a
ld a, [TempEnemyMonSpecies]
call Function37b6
.asm_3fceb
ld a, [BattleType]
cp BATTLETYPE_FISH
jr nz, .asm_3fcfd
callba Function106086
ld hl, HookedPokemonAttackedText
jr .asm_3fd0e
.asm_3fcfd
ld hl, PokemonFellFromTreeText
cp BATTLETYPE_TREE
jr z, .asm_3fd0e
ld hl, WildPokemonAppearedText2
cp $b
jr z, .asm_3fd0e
ld hl, WildPokemonAppearedText
.asm_3fd0e
push hl
callba Function2c000
pop hl
call StdBattleTextBox
call Function3f830
ret nz
ld c, $2
callba Function4ea0a
ret
; 3fd26
|