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
|
; _DebugRoom.MenuItems indexes
const_def
const DEBUGROOMMENU_PAGE_1 ; 0
const DEBUGROOMMENU_PAGE_2 ; 1
const DEBUGROOMMENU_PAGE_3 ; 2
DEBUGROOMMENU_NUM_PAGES EQU const_value
; _DebugRoom.Strings and _DebugRoom.Jumptable indexes
const_def
const DEBUGROOMMENUITEM_SP_CLEAR ; 00
const DEBUGROOMMENUITEM_WIN_WORK_CLR ; 01
const DEBUGROOMMENUITEM_POKEMON_GET ; 02
const DEBUGROOMMENUITEM_POKEDEX_COMP ; 03
const DEBUGROOMMENUITEM_TIMER_RESET ; 04
const DEBUGROOMMENUITEM_DECORATE_ALL ; 05
const DEBUGROOMMENUITEM_ITEM_GET ; 06
const DEBUGROOMMENUITEM_RTC_EDIT ; 07
const DEBUGROOMMENUITEM_NEXT ; 08
const DEBUGROOMMENUITEM_GB_ID_SET ; 09
const DEBUGROOMMENUITEM_BTL_REC_CLR ; 0a
const DEBUGROOMMENUITEM_POKEDEX_CLR ; 0b
const DEBUGROOMMENUITEM_HALT_CHK_CLR ; 0c
const DEBUGROOMMENUITEM_BATTLE_SKIP ; 0d
const DEBUGROOMMENUITEM_HOF_CLEAR ; 0e
const DEBUGROOMMENUITEM_ROM_CHECKSUM ; 0f
const DEBUGROOMMENUITEM_TEL_DEBUG ; 10
const DEBUGROOMMENUITEM_SUM_RECALC ; 11
const DEBUGROOMMENUITEM_RAM_FLAG_CLR ; 12
const DEBUGROOMMENUITEM_CHANGE_SEX ; 13
const DEBUGROOMMENUITEM_BT_BUG_POKE ; 14
_DebugRoom:
ldh a, [hJoyDown]
and SELECT | START
cp SELECT | START
ret nz
ldh a, [hDebugRoomMenuPage]
push af
xor a
ldh [hDebugRoomMenuPage], a
.loop
ld hl, wTilemap
ld bc, wTilemapEnd - wTilemap
ld a, " "
call ByteFill
call DebugRoom_PrintStackBottomTop
call DebugRoom_PrintWindowStackBottomTop
call DebugRoom_PrintRTCHaltChk
call DebugRoom_PrintBattleSkip
call DebugRoom_PrintTelDebug
call DebugRoom_PrintRAMFlag
call DebugRoom_PrintGender
ldh a, [hDebugRoomMenuPage]
ld [wWhichIndexSet], a
ld hl, .MenuHeader
call LoadMenuHeader
call SetUpMenu
.wait
call GetScrollingMenuJoypad
ld a, [wMenuJoypad]
and A_BUTTON | B_BUTTON
jr z, .wait
call CloseWindow
cp B_BUTTON
jr z, .done
ld a, [wMenuSelection]
ld hl, .Jumptable
rst JumpTable
jr .loop
.done
pop af
ldh [hDebugRoomMenuPage], a
ret
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, 15, SCREEN_HEIGHT - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR ; flags
db 0 ; items
dw .MenuItems
dw PlaceMenuStrings
dw .Strings
.Strings:
; entries correspond to DEBUGROOMMENUITEM_* constants
db "SP CLEAR@"
db "WIN WORK CLR@"
db "#MON GET!@"
db "#DEX COMP@"
db "TIMER RESET@"
db "DECORATE ALL@"
db "ITEM GET!@"
db "RTC EDIT@"
db "NEXT@"
db "GB ID SET@"
db "BTL REC CLR@"
db "#DEX CLR@"
db "HALT CHK CLR@"
db "BATTLE SKIP@"
db "HOF CLEAR@"
db "ROM CHECKSUM@"
db "TEL DEBUG@"
db "SUM RECALC@"
db "RAM FLAG CLR@"
db "CHANGE SEX@"
db "BT BUG POKE@"
.Jumptable:
; entries correspond to DEBUGROOMMENUITEM_* constants
dw DebugRoomMenu_SpClear
dw DebugRoomMenu_WinWorkClr
dw DebugRoomMenu_PokemonGet
dw DebugRoomMenu_PokedexComp
dw DebugRoomMenu_TimerReset
dw DebugRoomMenu_DecorateAll
dw DebugRoomMenu_ItemGet
dw DebugRoomMenu_RTCEdit
dw DebugRoomMenu_Next
dw DebugRoomMenu_GBIDSet
dw DebugRoomMenu_BtlRecClr
dw DebugRoomMenu_PokedexClr
dw DebugRoomMenu_HaltChkClr
dw DebugRoomMenu_BattleSkip
dw DebugRoomMenu_HOFClear
dw DebugRoomMenu_ROMChecksum
dw DebugRoomMenu_TelDebug
dw DebugRoomMenu_SumRecalc
dw DebugRoomMenu_RAMFlagClr
dw DebugRoomMenu_ChangeSex
dw DebugRoomMenu_BTBugPoke
.MenuItems:
; entries correspond to DEBUGROOMMENU_* constants
; DEBUGROOMMENU_PAGE_1
db 8
db DEBUGROOMMENUITEM_SP_CLEAR
db DEBUGROOMMENUITEM_BATTLE_SKIP
db DEBUGROOMMENUITEM_RTC_EDIT
db DEBUGROOMMENUITEM_TIMER_RESET
db DEBUGROOMMENUITEM_HALT_CHK_CLR
db DEBUGROOMMENUITEM_GB_ID_SET
db DEBUGROOMMENUITEM_BTL_REC_CLR
db DEBUGROOMMENUITEM_NEXT
db -1
; DEBUGROOMMENU_PAGE_2
db 8
db DEBUGROOMMENUITEM_POKEMON_GET
db DEBUGROOMMENUITEM_ITEM_GET
db DEBUGROOMMENUITEM_POKEDEX_COMP
db DEBUGROOMMENUITEM_POKEDEX_CLR
db DEBUGROOMMENUITEM_DECORATE_ALL
db DEBUGROOMMENUITEM_HOF_CLEAR
db DEBUGROOMMENUITEM_ROM_CHECKSUM
db DEBUGROOMMENUITEM_NEXT
db -1
; DEBUGROOMMENU_PAGE_3
db 6
db DEBUGROOMMENUITEM_TEL_DEBUG
db DEBUGROOMMENUITEM_SUM_RECALC
db DEBUGROOMMENUITEM_RAM_FLAG_CLR
db DEBUGROOMMENUITEM_CHANGE_SEX
db DEBUGROOMMENUITEM_BT_BUG_POKE
db DEBUGROOMMENUITEM_NEXT
db -1
DebugRoomMenu_Next:
ldh a, [hDebugRoomMenuPage]
inc a
cp DEBUGROOMMENU_NUM_PAGES
jr c, .got_page
xor a ; DEBUGROOMMENU_PAGE_1
.got_page
ldh [hDebugRoomMenuPage], a
ret
DebugRoom_SaveChecksum:
ld a, BANK(sGameData)
call OpenSRAM
ld bc, sGameDataEnd - sGameData
ld de, 0
ld hl, sGameData
.loop
ld a, [hli]
add e
ld e, a
ld a, d
adc 0
ld d, a
dec bc
ld a, b
or c
jr nz, .loop
ld a, e
ld [sChecksum + 0], a
ld a, d
ld [sChecksum + 1], a
call CloseSRAM
ret
DebugRoomMenu_SpClear:
call YesNoBox
ret c
ld a, BANK(sStackTop)
call OpenSRAM
xor a
ld hl, sStackTop
ld [hli], a
ld [hl], a
call CloseSRAM
call DebugRoom_PrintStackBottomTop
ret
DebugRoom_PrintStackBottomTop:
ld a, BANK(sStackTop)
call OpenSRAM
hlcoord 16, 14
ld de, sStackTop + 1
ld c, 1
call PrintHexNumber
ld de, sStackTop + 0
ld c, 1
call PrintHexNumber
call CloseSRAM
hlcoord 16, 12
ld de, .SPString
call PlaceString
ld d, LOW(wStackBottom)
ld e, HIGH(wStackBottom)
push de
ld hl, sp+0
ld d, h
ld e, l
hlcoord 16, 13
ld c, 2
call PrintHexNumber
pop de
ret
.SPString:
db "SP:@"
DebugRoomMenu_WinWorkClr:
call YesNoBox
ret c
ld a, [wWindowStackPointer]
ld l, a
ld a, [wWindowStackPointer + 1]
ld h, a
inc hl
ld a, l
sub LOW(wWindowStack)
ld a, h
sbc HIGH(wWindowStack)
ret c
ld a, $00
call OpenSRAM
ld bc, -wWindowStack + $10000
add hl, bc
ld b, h
ld c, l
ld hl, wWindowStack
xor a
call ByteFill
call CloseSRAM
ret
DebugRoom_PrintWindowStackBottomTop:
ret ; stubbed out
ld a, $00
call OpenSRAM
ld hl, wWindowStack
.loop
ld a, h
cp $c0
jr z, .ok
ld a, [hl]
or a
jr nz, .ok
inc hl
jr .loop
.ok
call CloseSRAM
ld a, h
ld h, l
ld l, a
push hl
ld hl, sp+0
ld d, h
ld e, l
hlcoord 16, 17
ld c, 2
call PrintHexNumber
pop hl
ld d, LOW(wWindowStack)
ld e, HIGH(wWindowStack)
push de
ld hl, sp+0
ld d, h
ld e, l
hlcoord 16, 16
ld c, 2
call PrintHexNumber
pop de
hlcoord 16, 15
ld de, .WSPString
call PlaceString
ret
.WSPString:
db "WSP:@"
DebugRoomMenu_PokedexComp:
call YesNoBox
ret c
ld a, BANK(sGameData) ; aka BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wPokedexCaught - wPlayerData)
ld b, wEndPokedexSeen - wPokedexCaught
ld a, %11111111
.loop1
ld [hli], a
dec b
jr nz, .loop1
ld a, (1 << (NUM_POKEMON % 8)) - 1 ; %00000111
ld [sPlayerData + (wEndPokedexCaught - 1 - wPlayerData)], a
ld [sPlayerData + (wEndPokedexSeen - 1 - wPlayerData)], a
ld hl, sPlayerData + (wStatusFlags - wPlayerData)
set STATUSFLAGS_UNOWN_DEX_F, [hl]
ld a, UNOWN_A
ld [sGameData + (wFirstUnownSeen - wGameData)], a
ld hl, sGameData + (wUnownDex - wGameData)
ld b, NUM_UNOWN
.loop2
ld [hli], a
inc a
dec b
jr nz, .loop2
call CloseSRAM
call DebugRoom_SaveChecksum
ret
DebugRoomMenu_PokedexClr:
call YesNoBox
ret c
ld a, BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wStatusFlags - wPlayerData)
res STATUSFLAGS_UNOWN_DEX_F, [hl]
ld hl, sPlayerData + (wPokedexCaught - wPlayerData)
ld bc, wEndPokedexSeen - wPokedexCaught
xor a
call ByteFill
ld hl, sGameData + (wUnownDex - wGameData)
ld bc, NUM_UNOWN
xor a
call ByteFill
call CloseSRAM
call DebugRoom_SaveChecksum
ret
DebugRoomMenu_TimerReset:
call YesNoBox
ret c
ld a, BANK(sRTCStatusFlags)
call OpenSRAM
ld hl, sRTCStatusFlags
set 7, [hl]
call CloseSRAM
ret
DebugRoomMenu_BattleSkip:
ld a, BANK(sSkipBattle)
call OpenSRAM
ld a, [sSkipBattle]
inc a
and 1
ld [sSkipBattle], a
call CloseSRAM
ret
DebugRoom_PrintBattleSkip:
hlcoord 16, 6
ld de, .BTLString
call PlaceString
ld a, BANK(sSkipBattle)
call OpenSRAM
ld a, [sSkipBattle]
call CloseSRAM
hlcoord 16, 7
ld de, .DoString
or a
jr z, .ok
ld de, .SkipString
.ok
call PlaceString
ret
.BTLString:
db "BTL:@"
.DoString:
db " DO@"
.SkipString:
db "SKIP@"
DebugRoomMenu_ChangeSex:
ld a, BANK(sCrystalData)
call OpenSRAM
ld a, [sCrystalData + (wPlayerGender - wCrystalData)]
inc a
and 1
ld [sCrystalData + (wPlayerGender - wCrystalData)], a
call CloseSRAM
ret
DebugRoom_PrintGender:
hlcoord 16, 0
ld de, .SexString
call PlaceString
ld a, BANK(sCrystalData)
call OpenSRAM
ld a, [sCrystalData + (wPlayerGender - wCrystalData)]
call CloseSRAM
or a
ld a, "♂"
jr z, .ok
ld a, "♀"
.ok
hlcoord 19, 1
ld [hl], a
ret
.SexString:
db "SEX:@"
DebugRoomMenu_TelDebug:
ld a, BANK(sDebugTimeCyclesSinceLastCall)
call OpenSRAM
ld a, [sDebugTimeCyclesSinceLastCall]
inc a
cp 3
jr c, .ok
xor a
.ok
ld [sDebugTimeCyclesSinceLastCall], a
call CloseSRAM
ret
DebugRoom_PrintTelDebug:
hlcoord 16, 16
ld de, .TelString
call PlaceString
ld a, BANK(sDebugTimeCyclesSinceLastCall)
call OpenSRAM
ld a, [sDebugTimeCyclesSinceLastCall]
call CloseSRAM
hlcoord 16, 17
ld de, .BusyString
dec a
jr z, .ok
ld de, .HardString
dec a
jr z, .ok
ld de, .OffString
.ok
call PlaceString
ret
.TelString:
db "TEL:@"
.OffString:
db " OFF@"
.BusyString:
db "BUSY@"
.HardString:
db "HARD@"
DebugRoomMenu_RAMFlagClr:
call YesNoBox
ret c
ld a, BANK(sOpenedInvalidSRAM)
call OpenSRAM
xor a
ld [sOpenedInvalidSRAM], a
call CloseSRAM
ret
DebugRoom_PrintRAMFlag:
ld a, BANK(sOpenedInvalidSRAM)
call OpenSRAM
ld de, sOpenedInvalidSRAM
hlcoord 18, 4
ld c, 1
call PrintHexNumber
call CloseSRAM
hlcoord 16, 3
ld de, .RamString
call PlaceString
ret
.RamString:
db "RAM:@"
DebugRoomMenu_SumRecalc:
call YesNoBox
ret c
call DebugRoom_SaveChecksum
ret
DebugRoomMenu_DecorateAll:
call YesNoBox
ret c
ld a, BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wEventFlags - wPlayerData)
ld de, EVENT_DECO_BED_1 ; the first EVENT_DECO_* constant
ld b, SET_FLAG
ld c, EVENT_DECO_BIG_LAPRAS_DOLL - EVENT_DECO_BED_1 + 1
.loop
push bc
push de
push hl
call FlagAction
pop hl
pop de
pop bc
inc de
dec c
jr nz, .loop
call CloseSRAM
call DebugRoom_SaveChecksum
ret
paged_value: MACRO
dw \1 ; value address
db \2 ; min value
db \3 ; max value
db \4 ; initial value
dw \5 ; label string
dw \6 ; value name function
db \7 ; is hex value?
ENDM
PAGED_VALUE_SIZE EQU 10
DebugRoom_EditPagedValues:
xor a
ld [wDebugRoomCurPage], a
ld [wDebugRoomCurValue], a
ld a, [hli]
ld [wDebugRoomAFunction], a
ld a, [hli]
ld [wDebugRoomAFunction+1], a
ld a, [hli]
ld [wDebugRoomSelectFunction], a
ld a, [hli]
ld [wDebugRoomSelectFunction+1], a
ld a, [hli]
ld [wDebugRoomStartFunction], a
ld a, [hli]
ld [wDebugRoomStartFunction+1], a
ld a, [hli]
ld [wDebugRoomAutoFunction], a
ld a, [hli]
ld [wDebugRoomAutoFunction+1], a
ld a, [hli]
ld [wDebugRoomPageCount], a
ld a, l
ld [wDebugRoomPagedValuesPtr], a
ld a, h
ld [wDebugRoomPagedValuesPtr+1], a
ld hl, hInMenu
ld a, [hl]
push af
ld [hl], TRUE
call ClearBGPalettes
hlcoord 0, 0
ld b, SCREEN_HEIGHT - 2
ld c, SCREEN_WIDTH - 2
call Textbox
hlcoord 8, 17
ld de, DebugRoom_PageString
call PlaceString
call DebugRoom_InitializePagedValues
xor a
call DebugRoom_PrintPage
ld a, "▶"
call DebugRoom_ShowHideCursor
xor a
ldh [hJoyLast], a
xor a
ld [wDebugRoomCurPage], a
inc a
ldh [hBGMapMode], a
call WaitBGMap
ld b, SCGB_DIPLOMA
call GetSGBLayout
call SetPalettes
.resume
call DelayFrame
call JoyTextDelay
ldh a, [hJoyLast]
bit 1, a
jr nz, .done
ld hl, .continue
push hl
rra ; A_BUTTON_F?
jr c, DebugRoom_PagedValuePressedA
rra ; skip B_BUTTON_F
rra ; SELECT_F?
jr c, DebugRoom_PagedValuePressedSelect
rra ; START_F?
jr c, DebugRoom_PagedValuePressedStart
rra ; D_RIGHT_F?
jp c, DebugRoom_IncrementPagedValue
rra ; D_LEFT_F?
jp c, DebugRoom_DecrementPagedValue
rra ; D_UP_F?
jp c, DebugRoom_PrevPagedValue
rra ; D_DOWN_F?
jp c, DebugRoom_NextPagedValue
pop hl
.continue
; call wDebugRoomAutoFunction if it's not null, then jump to .resume
ld hl, .resume
push hl
ld a, [wDebugRoomAutoFunction]
ld l, a
ld a, [wDebugRoomAutoFunction+1]
ld h, a
or l
ret z
jp hl
.done
pop af
ldh [hInMenu], a
scf
ret
DebugRoom_PagedValuePressedA:
ld hl, wDebugRoomAFunction
jr _CallNonNullPointer
DebugRoom_PagedValuePressedSelect:
ld hl, wDebugRoomSelectFunction
jr _CallNonNullPointer
DebugRoom_PagedValuePressedStart:
ld hl, wDebugRoomStartFunction
; fallthrough
_CallNonNullPointer:
ld a, [hli]
ld h, [hl]
ld l, a
or h
ret z
jp hl
DebugRoom_PageString:
db " P @"
DebugRoom_IncrementPagedValue:
call DebugRoom_GetCurPagedValuePtr
ld e, [hl] ; de = value address
inc hl
ld d, [hl]
inc hl
inc hl
ld a, [de] ; a = max value
cp [hl]
ret z
inc a
ld [de], a
call DebugRoom_PrintPageBValueC
ret
DebugRoom_DecrementPagedValue:
call DebugRoom_GetCurPagedValuePtr
ld e, [hl] ; de = value address
inc hl
ld d, [hl]
inc hl
ld a, [de] ; a = min value
cp [hl]
ret z
dec a
ld [de], a
call DebugRoom_PrintPageBValueC
ret
DebugRoom_NextPage:
ld a, [wDebugRoomPageCount]
ld c, a
ld a, [wDebugRoomCurPage]
inc a
cp c
jr c, .ok
xor a
.ok
ld [wDebugRoomCurPage], a
call DebugRoom_PrintPage
ld a, [wDebugRoomCurPage]
call DebugRoom_GetNthPagePtr
ld a, [wDebugRoomCurValue]
cp [hl]
jr c, .skip
ld a, [hl]
dec a
ld [wDebugRoomCurValue], a
.skip
ld a, "▶"
call DebugRoom_ShowHideCursor
ret
DebugRoom_PrevPage:
ld a, [wDebugRoomCurPage]
or a
jr nz, .ok
ld a, [wDebugRoomPageCount]
.ok
dec a
ld [wDebugRoomCurPage], a
call DebugRoom_PrintPage
ld a, [wDebugRoomCurPage]
call DebugRoom_GetNthPagePtr
ld a, [wDebugRoomCurValue]
cp [hl]
jr c, .skip
ld a, [hl]
dec a
ld [wDebugRoomCurValue], a
.skip
ld a, "▶"
call DebugRoom_ShowHideCursor
ret
DebugRoom_NextPagedValue:
ld a, " "
call DebugRoom_ShowHideCursor
ld a, [wDebugRoomCurPage]
call DebugRoom_GetNthPagePtr
ld a, [wDebugRoomCurValue]
inc a
cp [hl] ; incremented value < paged_value count?
jr c, DebugRoom_UpdateValueCursor
xor a
ld [wDebugRoomCurValue], a
jr DebugRoom_NextPage
DebugRoom_UpdateValueCursor:
ld [wDebugRoomCurValue], a
ld a, "▶"
call DebugRoom_ShowHideCursor
ret
DebugRoom_PrevPagedValue:
ld a, " "
call DebugRoom_ShowHideCursor
ld a, [wDebugRoomCurValue]
or a ; pre-decremented value > 0?
jr nz, .decrement
ld a, -1
ld [wDebugRoomCurValue], a
jr DebugRoom_PrevPage
.decrement:
dec a
jr DebugRoom_UpdateValueCursor
DebugRoom_GetNthPagePtr:
; Input: a = page index
; Output: hl = pointer to paged_data list
ld h, 0
ld l, a
add hl, hl
ld a, [wDebugRoomPagedValuesPtr]
ld e, a
ld a, [wDebugRoomPagedValuesPtr+1]
ld d, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ret
_DebugRoom_GetPageBValueCPtr:
push bc
ld a, b
call DebugRoom_GetNthPagePtr
pop bc
inc hl
ld a, c
ld bc, PAGED_VALUE_SIZE
call AddNTimes
ret
DebugRoom_GetCurPagedValuePtr:
ld a, [wDebugRoomCurPage]
ld b, a
ld a, [wDebugRoomCurValue]
ld c, a
jr _DebugRoom_GetPageBValueCPtr
DebugRoom_ShowHideCursor:
push af
hlcoord 1, 1
ld bc, SCREEN_WIDTH * 2
ld a, [wDebugRoomCurValue]
call AddNTimes
pop af
ld [hl], a
ret
DebugRoom_InitializePagedValues:
; Load the initial values for all pages of the current paged value header
ld a, [wDebugRoomPageCount]
.page_loop
dec a
push af
call .InitializePage
pop af
jr nz, .page_loop
ret
.InitializePage:
; Load the initial values for page a
ld b, a
ld h, 0
ld l, a
add hl, hl
ld a, [wDebugRoomPagedValuesPtr]
ld e, a
ld a, [wDebugRoomPagedValuesPtr+1]
ld d, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld c, [hl] ; c = paged_value count
.value_loop
push bc
dec c
call .InitializeValue
pop bc
dec c
jr nz, .value_loop
ret
.InitializeValue:
; Load the initial value for page b, value c
ld h, 0
ld l, b
add hl, hl
ld a, [wDebugRoomPagedValuesPtr]
ld e, a
ld a, [wDebugRoomPagedValuesPtr+1]
ld d, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
inc hl ; skip the paged_value count
ld a, c
push bc
ld bc, PAGED_VALUE_SIZE
call AddNTimes
pop bc
ld e, [hl] ; de = value address
inc hl
ld d, [hl]
inc hl
inc hl
inc hl
ld a, [hl] ; a = initial value
ld [de], a
ret
DebugRoom_PrintPage:
push af
hlcoord 10, 17
add "1"
ld [hl], a
hlcoord 1, 1
lb bc, SCREEN_HEIGHT - 2, SCREEN_WIDTH - 2
call ClearBox
pop af
ld b, a
ld h, 0
ld l, a
add hl, hl
ld a, [wDebugRoomPagedValuesPtr]
ld e, a
ld a, [wDebugRoomPagedValuesPtr+1]
ld d, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld c, [hl] ; c = paged_value count
.loop
push bc
dec c
call DebugRoom_PrintPagedValue
pop bc
dec c
jr nz, .loop
ret
DebugRoom_PrintPageBValueC:
ld a, [wDebugRoomCurPage]
ld b, a
ld a, [wDebugRoomCurValue]
ld c, a
jr DebugRoom_PrintPagedValue
DebugRoom_PrintPagedValue:
; Print the value for page b, value c
ld h, 0
ld l, b
add hl, hl
ld a, [wDebugRoomPagedValuesPtr]
ld e, a
ld a, [wDebugRoomPagedValuesPtr+1]
ld d, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
inc hl ; skip the paged_value count
ld a, c
push bc
ld bc, PAGED_VALUE_SIZE
call AddNTimes
pop bc
ld e, [hl] ; de = value address
inc hl
ld d, [hl]
inc hl
push de
inc hl
inc hl
inc hl
ld e, [hl] ; de = label string
inc hl
ld d, [hl]
inc hl
push hl
hlcoord 2, 1
ld a, c
ld bc, SCREEN_WIDTH * 2
call AddNTimes
push hl
call PlaceString
pop hl
ld bc, SCREEN_WIDTH - 7
add hl, bc
pop bc ; pushed hl
pop de
push de
push bc
inc bc
inc bc
ld a, [bc] ; a = is hex value?
or a
jr nz, .hex
lb bc, PRINTNUM_LEADINGZEROS | 1, 3
call PrintNum
jr .printed
.hex
ld c, 1
call PrintHexNumber
ld [hl], "H"
inc hl
.printed
ld bc, 6
add hl, bc
ld b, h
ld c, l
pop hl
pop de
ld a, [hli] ; hl = value name function
ld h, [hl]
ld l, a
or h
ret z
ld a, [de]
jp hl
DebugRoom_JoyWaitABSelect:
.loop
call GetJoypad
ldh a, [hJoyPressed]
and A_BUTTON | B_BUTTON | SELECT
jr z, .loop
ret
DebugRoomMenu_ItemGet:
ld hl, .PagedValuesHeader
call DebugRoom_EditPagedValues
ret
.PagedValuesHeader:
dw NULL ; A function
dw NULL ; Select function
dw DebugRoom_SaveItem ; Start function
dw NULL ; Auto function
db 1 ; # pages
dw DebugRoomMenu_ItemGet_Page1Values
DebugRoom_SaveItem:
call YesNoBox
ret c
ld a, BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wPCItems - wPlayerData)
ld a, [wDebugRoomItemID]
ld c, a
.loop1
ld a, [hl]
cp c
jr z, .found
cp -1
jr z, .not_found
inc hl
inc hl
jr .loop1
.found
inc hl
ld a, [wDebugRoomItemQuantity]
add [hl]
cp MAX_ITEM_STACK + 1
jr c, .max
ld a, MAX_ITEM_STACK
.max
ld [hl], a
ld hl, .ItemNumberAddedText
jr .done
.not_found
ld a, [sPlayerData + (wNumPCItems - wPlayerData)]
cp MAX_PC_ITEMS
jr nc, .full
inc a
ld [sPlayerData + (wNumPCItems - wPlayerData)], a
ld a, [wDebugRoomItemID]
ld [hli], a
ld a, [wDebugRoomItemQuantity]
ld [hli], a
ld [hl], -1 ; terminator
ld hl, .CreatedNewItemText
jr .done
.full
ld hl, .StockFullText
.done
call CloseSRAM
call MenuTextbox
call DebugRoom_JoyWaitABSelect
call CloseWindow
call DebugRoom_SaveChecksum
ret
.ItemNumberAddedText:
text "Item number added!"
done
.CreatedNewItemText:
text "Created new item!"
done
.StockFullText:
text "Stock full!!"
done
DebugRoom_PrintItemName:
ld [wNamedObjectIndexBuffer], a
push bc
call GetItemName
pop hl
push hl
lb bc, 1, 12
call ClearBox
pop hl
ld de, wStringBuffer1
call PlaceString
ret
DebugRoomMenu_ItemGet_Page1Values:
db 2
paged_value wDebugRoomItemID, 1, NUM_POKEMON, MASTER_BALL, .ItemNameString, DebugRoom_PrintItemName, FALSE
paged_value wDebugRoomItemQuantity, 1, 99, 1, .NumberString, NULL, FALSE
.ItemNameString: db "ITEM NAME@"
.NumberString: db "NUMBER@"
DebugRoomMenu_PokemonGet:
ld hl, .PagedValuesHeader
call DebugRoom_EditPagedValues
ret
.PagedValuesHeader:
dw NULL ; A function
dw NULL ; Select function
dw DebugRoom_SavePokemon ; Start function
dw NULL ; Auto function
db 4 ; # pages
dw DebugRoomMenu_PokemonGet_Page1Values
dw DebugRoomMenu_PokemonGet_Page2Values
dw DebugRoomMenu_PokemonGet_Page3Values
dw DebugRoomMenu_PokemonGet_Page4Values
DebugRoom_SavePokemon:
call YesNoBox
ret c
call DebugRoom_UpdateExpForLevel
ld a, [wDebugRoomMonBox]
dec a
ld b, a
add a
add b
ld h, 0
ld l, a
ld de, DebugRoom_BoxAddresses
add hl, de
ld a, [hli]
call OpenSRAM
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [hl]
cp MONS_PER_BOX
jr nc, .full
; update count and species list
push hl
inc [hl]
inc hl
ld d, 0
ld e, a
add hl, de
ld a, [wDebugRoomMonSpecies]
ld [hli], a
ld [hl], -1
pop hl
; skip count and species list
ld bc, 2 + MONS_PER_BOX
add hl, bc
; update Nth box mon
push de
push hl
ld a, e
ld bc, BOXMON_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, wDebugRoomMon
ld bc, BOXMON_STRUCT_LENGTH
call CopyBytes
pop hl
pop de
; skip box mons
ld bc, BOXMON_STRUCT_LENGTH * MONS_PER_BOX
add hl, bc
; update Nth OT name
push de
push hl
ld a, e
ld bc, NAME_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, .OTString
ld bc, NAME_LENGTH
call CopyBytes
pop hl
pop de
; skip OT names
ld bc, NAME_LENGTH * MONS_PER_BOX
add hl, bc
; update Nth nickname
push de
push hl
ld a, e
ld bc, MON_NAME_LENGTH
call AddNTimes
ld d, h
ld e, l
ld hl, .NicknameString
ld bc, MON_NAME_LENGTH
call CopyBytes
pop hl
pop de
call CloseSRAM
ld hl, .CompletedText
call MenuTextbox
call DebugRoom_JoyWaitABSelect
call CloseWindow
ret
.full
call CloseSRAM
ld hl, .BoxIsFullText
call MenuTextbox
call DebugRoom_JoyWaitABSelect
call CloseWindow
ret
.OTString:
db "DEBUG▶OT@"
.NicknameString:
db "DEBUG▶<PK><MN>@"
.CompletedText:
text "COMPLETED!"
done
.BoxIsFullText:
text "BOX IS FULL!"
done
DebugRoom_PrintPokemonName:
ld [wNamedObjectIndexBuffer], a
push bc
call GetPokemonName
jr _DebugRoom_FinishGetName
DebugRoom_PrintItemName2:
ld [wNamedObjectIndexBuffer], a
push bc
call GetItemName
jr _DebugRoom_FinishGetName
DebugRoom_PrintMoveName:
ld [wNamedObjectIndexBuffer], a
push bc
call GetMoveName
jr _DebugRoom_FinishGetName
_DebugRoom_FinishGetName:
pop hl
push hl
lb bc, 1, 12
call ClearBox
pop hl
ld de, wStringBuffer1
call PlaceString
ret
DebugRoom_UpdateExpForLevel:
ld hl, BaseData + BASE_GROWTH_RATE
ld bc, BASE_DATA_SIZE
ld a, [wDebugRoomMonSpecies]
dec a
call AddNTimes
ld a, BANK(BaseData)
call GetFarByte
ld [wBaseGrowthRate], a
ld a, [wDebugRoomMonLevel]
ld d, a
farcall CalcExpAtLevel
ld hl, wDebugRoomMonExp
ldh a, [hProduct + 1]
ld [hli], a
ldh a, [hProduct + 2]
ld [hli], a
ldh a, [hProduct + 3]
ld [hl], a
ret
DebugRoomMenu_PokemonGet_Page1Values:
db 8
paged_value wDebugRoomMonSpecies, 1, NUM_POKEMON, BULBASAUR, DebugRoom_BoxStructStrings.Pokemon, DebugRoom_PrintPokemonName, FALSE
paged_value wDebugRoomMonItem, 1, $ff, MASTER_BALL, DebugRoom_BoxStructStrings.Item, DebugRoom_PrintItemName2, FALSE
paged_value wDebugRoomMonMoves+0, 1, NUM_ATTACKS, POUND, DebugRoom_BoxStructStrings.Move1, DebugRoom_PrintMoveName, FALSE
paged_value wDebugRoomMonMoves+1, 1, NUM_ATTACKS, POUND, DebugRoom_BoxStructStrings.Move2, DebugRoom_PrintMoveName, FALSE
paged_value wDebugRoomMonMoves+2, 1, NUM_ATTACKS, POUND, DebugRoom_BoxStructStrings.Move3, DebugRoom_PrintMoveName, FALSE
paged_value wDebugRoomMonMoves+3, 1, NUM_ATTACKS, POUND, DebugRoom_BoxStructStrings.Move4, DebugRoom_PrintMoveName, FALSE
paged_value wDebugRoomMonID+0, $00, $ff, HIGH(1234), DebugRoom_BoxStructStrings.ID0, NULL, FALSE
paged_value wDebugRoomMonID+1, $00, $ff, LOW(1234), DebugRoom_BoxStructStrings.ID1, NULL, FALSE
DebugRoomMenu_PokemonGet_Page2Values:
db 8
paged_value wDebugRoomMonHPExp+0, $00, $ff, $00, DebugRoom_BoxStructStrings.HPExp0, NULL, FALSE
paged_value wDebugRoomMonHPExp+1, $00, $ff, $00, DebugRoom_BoxStructStrings.HPExp1, NULL, FALSE
paged_value wDebugRoomMonAtkExp+0, $00, $ff, $00, DebugRoom_BoxStructStrings.AttkExp0, NULL, FALSE
paged_value wDebugRoomMonAtkExp+1, $00, $ff, $00, DebugRoom_BoxStructStrings.AttkExp1, NULL, FALSE
paged_value wDebugRoomMonDefExp+0, $00, $ff, $00, DebugRoom_BoxStructStrings.DfnsExp0, NULL, FALSE
paged_value wDebugRoomMonDefExp+1, $00, $ff, $00, DebugRoom_BoxStructStrings.DfnsExp1, NULL, FALSE
paged_value wDebugRoomMonSpdExp+0, $00, $ff, $00, DebugRoom_BoxStructStrings.SpeedExp0, NULL, FALSE
paged_value wDebugRoomMonSpdExp+1, $00, $ff, $00, DebugRoom_BoxStructStrings.SpeedExp1, NULL, FALSE
DebugRoomMenu_PokemonGet_Page3Values:
db 8
paged_value wDebugRoomMonSpcExp+0, $00, $ff, $00, DebugRoom_BoxStructStrings.SpclExp0, NULL, FALSE
paged_value wDebugRoomMonSpcExp+1, $00, $ff, $00, DebugRoom_BoxStructStrings.SpclExp1, NULL, FALSE
paged_value wDebugRoomMonDVs+0, $00, $ff, $00, DebugRoom_BoxStructStrings.PowerRnd0, NULL, TRUE
paged_value wDebugRoomMonDVs+1, $00, $ff, $00, DebugRoom_BoxStructStrings.PowerRnd1, NULL, TRUE
paged_value wDebugRoomMonPP+0, $00, $ff, $00, DebugRoom_BoxStructStrings.PP1, NULL, FALSE
paged_value wDebugRoomMonPP+1, $00, $ff, $00, DebugRoom_BoxStructStrings.PP2, NULL, FALSE
paged_value wDebugRoomMonPP+2, $00, $ff, $00, DebugRoom_BoxStructStrings.PP3, NULL, FALSE
paged_value wDebugRoomMonPP+3, $00, $ff, $00, DebugRoom_BoxStructStrings.PP4, NULL, FALSE
DebugRoomMenu_PokemonGet_Page4Values:
db 6
paged_value wDebugRoomMonHappiness, $00, $ff, BASE_HAPPINESS, DebugRoom_BoxStructStrings.Friend, NULL, FALSE
paged_value wDebugRoomMonPokerusStatus, $00, $ff, $00, DebugRoom_BoxStructStrings.Pokerus, NULL, TRUE
paged_value wDebugRoomMonCaughtData+0, $00, $ff, $00, DebugRoom_BoxStructStrings.NoUse0, NULL, FALSE
paged_value wDebugRoomMonCaughtData+1, $00, $ff, $00, DebugRoom_BoxStructStrings.NoUse1, NULL, FALSE
paged_value wDebugRoomMonLevel, 1, MAX_LEVEL, $05, DebugRoom_BoxStructStrings.Level, NULL, FALSE
paged_value wDebugRoomMonBox, 1, NUM_BOXES, $0e, DebugRoom_BoxStructStrings.SendBox, NULL, FALSE
DebugRoom_BoxStructStrings:
.Pokemon: db "#MON@"
.Item: db "ITEM@"
.Move1: db "MOVE 1@"
.Move2: db "MOVE 2@"
.Move3: db "MOVE 3@"
.Move4: db "MOVE 4@"
.ID0: db "ID[0]@"
.ID1: db "ID[1]@"
.BaseExp0: db "BASE EXP[0]@"
.BaseExp1: db "BASE EXP[1]@"
.BaseExp2: db "BASE EXP[2]@"
.HPExp0: db "HP EXP[0]@"
.HPExp1: db "HP EXP[1]@"
.AttkExp0: db "ATTK EXP[0]@"
.AttkExp1: db "ATTK EXP[1]@"
.DfnsExp0: db "DFNS EXP[0]@"
.DfnsExp1: db "DFNS EXP[1]@"
.SpeedExp0: db "SPEED EXP[0]@"
.SpeedExp1: db "SPEED EXP[1]@"
.SpclExp0: db "SPCL EXP[0]@"
.SpclExp1: db "SPCL EXP[1]@"
.PowerRnd0: db "POWER RND[0]<LF> RARE:--1-1010@"
.PowerRnd1: db "POWER RND[1]<LF> RARE:10101010@"
.PP1: db "PP 1@"
.PP2: db "PP 2@"
.PP3: db "PP 3@"
.PP4: db "PP 4@"
.Friend: db "FRIEND@"
.Pokerus: db "#RUS@"
.NoUse0: db "NO USE[0]@"
.NoUse1: db "NO USE[1]@"
.Level: db "LEVEL@"
.SendBox: db "SEND BOX@"
DebugRoom_BoxAddresses:
dba sBox1
dba sBox2
dba sBox3
dba sBox4
dba sBox5
dba sBox6
dba sBox7
dba sBox8
dba sBox9
dba sBox10
dba sBox11
dba sBox12
dba sBox13
dba sBox14
DebugRoomMenu_RTCEdit:
ld hl, .PagedValuesHeader
call DebugRoom_EditPagedValues
ret
.PagedValuesHeader:
dw NULL ; A function
dw NULL ; Select function
dw DebugRoom_SaveRTC ; Start function
dw DebugRoomMenu_RTCEdit_UpdateClock ; Auto function
db 1 ; # pages
dw DebugRoomMenu_RTCEdit_Page1Values
DebugRoom_SaveRTC:
call YesNoBox
ret c
ld hl, wDebugRoomRTCSec
call DebugRoom_SetClock
ret
DebugRoomMenu_RTCEdit_UpdateClock:
ld hl, wDebugRoomRTCCurSec
call DebugRoom_GetClock
ld de, DebugRoom_DayHTimeString
hlcoord 3, 14
call PlaceString
ld a, [wDebugRoomRTCCurDay + 0]
ld h, a
ld a, [wDebugRoomRTCCurDay + 1]
ld l, a
push hl
ld hl, sp+0
ld d, h
ld e, l
hlcoord 7, 14
ld c, 2
call PrintHexNumber
pop hl
hlcoord 8, 15
ld de, wDebugRoomRTCCurHour
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ld [hl], ":"
inc hl
ld de, wDebugRoomRTCCurMin
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ld [hl], ":"
inc hl
ld de, wDebugRoomRTCCurSec
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
ret
DebugRoom_DayHTimeString:
db "DAY H<LF>TIME@"
DebugRoom_GetClock:
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
xor a
ld [MBC3LatchClock], a
inc a
ld [MBC3LatchClock], a
ld b, RTC_DH - RTC_S + 1
ld c, RTC_S
.loop
ld a, c
ld [MBC3SRamBank], a
ld a, [MBC3RTC]
ld [hli], a
inc c
dec b
jr nz, .loop
call CloseSRAM
ret
DebugRoom_SetClock:
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
ld b, RTC_DH - RTC_S + 1
ld c, RTC_S
.loop
ld a, c
ld [MBC3SRamBank], a
ld a, [hli]
ld [MBC3RTC], a
inc c
dec b
jr nz, .loop
call CloseSRAM
ret
DebugRoomMenu_RTCEdit_Page1Values:
db 5
paged_value wDebugRoomRTCSec, 0, 60 - 1, 0, .SecondString, NULL, FALSE
paged_value wDebugRoomRTCMin, 0, 60 - 1, 0, .MinuteString, NULL, FALSE
paged_value wDebugRoomRTCHour, 0, 24 - 1, 0, .HourString, NULL, FALSE
paged_value wDebugRoomRTCDay+0, $00, $ff, 0, .DayLString, NULL, TRUE
paged_value wDebugRoomRTCDay+1, $00, $ff, 0, .DayHString, NULL, TRUE
.SecondString: db "SECOND@"
.MinuteString: db "MINUTE@"
.HourString: db "HOUR@"
.DayLString: db "DAY L@"
.DayHString: db "DAY H<LF> BIT0:DAY MSB<LF> BIT6:HALT<LF> BIT7:DAY CARRY@"
DebugRoomMenu_HaltChkClr:
call YesNoBox
ret c
ld a, BANK(sRTCHaltCheckValue)
call OpenSRAM
xor a
ld hl, sRTCHaltCheckValue
ld [hli], a
ld [hl], a
call CloseSRAM
call DebugRoom_PrintRTCHaltChk
ret
DebugRoom_PrintRTCHaltChk:
hlcoord 16, 9
ld de, .RTCString
call PlaceString
ld a, BANK(sRTCHaltCheckValue)
ld hl, sRTCHaltCheckValue
call OpenSRAM
ld a, [hli]
ld h, [hl]
ld l, a
call CloseSRAM
ld de, .HaltString
ld a, h
cp HIGH(RTC_HALT_VALUE)
jr nz, .ok
ld a, l
cp LOW(RTC_HALT_VALUE)
jr z, .done
.ok
ld de, .OKString
.done
hlcoord 16, 10
call PlaceString
ret
.RTCString:
db "RTC:@"
.OKString:
db " OK@"
.HaltString:
db "HALT@"
DebugRoomMenu_GBIDSet:
ld hl, .PagedValuesHeader
call DebugRoom_EditPagedValues
ret
.PagedValuesHeader:
dw NULL ; A function
dw NULL ; Select function
dw DebugRoom_SaveGBID ; Start function
dw NULL ; Auto function
db 1 ; # pages
dw DebugRoomMenu_GBIDSet_Page1Values
DebugRoom_SaveGBID:
call YesNoBox
ret c
ld a, BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wPlayerID - wPlayerData)
ld a, [wDebugRoomGBID + 0]
ld [hli], a
ld a, [wDebugRoomGBID + 1]
ld [hli], a
call CloseSRAM
call DebugRoom_SaveChecksum
ret
DebugRoomMenu_GBIDSet_Page1Values:
db 2
paged_value wDebugRoomGBID+0, $00, $ff, $00, .GBID0String, NULL, TRUE
paged_value wDebugRoomGBID+1, $00, $ff, $00, .GBID1String, NULL, TRUE
.GBID0String: db "GB ID [0]@"
.GBID1String: db "GB ID [1]@"
DebugRoomMenu_BtlRecClr:
call YesNoBox
ret c
ld a, BANK(sLinkBattleStats)
call OpenSRAM
xor a
ld hl, sLinkBattleStats
ld bc, sLinkBattleStatsEnd - sLinkBattleStats
call ByteFill
call CloseSRAM
ret
DebugRoomMenu_HOFClear:
call YesNoBox
ret c
ld a, BANK(sPlayerData)
call OpenSRAM
ld hl, sPlayerData + (wHallOfFameCount - wPlayerData)
ld [hl], 0
xor a
ld hl, sHallOfFame
ld bc, sHallOfFameEnd - sHallOfFame
call ByteFill
call CloseSRAM
call DebugRoom_SaveChecksum
ret
ComputeROMChecksum:
ld de, 0
call .ComputeROM0Checksum
ld c, $01 ; first bank
.loop:
push bc
push de
ld a, c
cpl
inc a
add $80
ld de, wDebugRoomCurChecksumBank
ld [de], a
hlcoord 16, 16
ld c, 1
call PrintHexNumber
ld [hl], "h"
pop de
pop bc
call ComputeROMXChecksum
inc c
ld a, c
cp $80 ; number of banks
jr c, .loop
ld a, d
ld [wDebugRoomROMChecksum + 0], a
ld a, e
ld [wDebugRoomROMChecksum + 1], a
ret
.AddAtoDE:
add e
ld e, a
ld a, d
adc 0
ld d, a
ret
.ComputeROM0Checksum:
ld hl, $0000 ; ROM0 start
.rom0_loop
ld a, [hli]
call .AddAtoDE
ld a, h
cp $40 ; HIGH(ROM0 end)
jr c, .rom0_loop
ret
.ComputeROMXChecksum: ; unreferenced
ld hl, $4000 ; ROMX start
.romx_loop
ld a, c
call GetFarByte
inc hl
call .AddAtoDE
ld a, h
cp $80 ; HIGH(ROMX end)
jr c, .romx_loop
ret
DebugRoom_PrintROMChecksum: ; unreferenced
hlcoord 16, 0
ld de, .SumString
call PlaceString
hlcoord 16, 1
ld de, wDebugRoomROMChecksum
ld c, 2
call PrintHexNumber
ret
.SumString:
db "SUM:@"
DebugRoomMenu_ROMChecksum:
ld hl, .WaitText
call MenuTextbox
call ComputeROMChecksum
call CloseWindow
ld hl, .ROMChecksumText
call MenuTextbox
hlcoord 14, 14
ld de, wDebugRoomROMChecksum
ld c, 2
call PrintHexNumber
ld [hl], "h"
call DebugRoom_JoyWaitABSelect
call CloseWindow
ret
.WaitText:
text "Wait..."
done
.ROMChecksumText:
text "ROM CHECKSUM:"
next ""
done
DebugRoomMenu_BTBugPoke:
ld a, BANK(sIsBugMon)
call OpenSRAM
ld a, [sIsBugMon]
call CloseSRAM
or a
jr nz, .bug_mon
ld hl, .NoBugMonText
call MenuTextbox
call DebugRoom_JoyWaitABSelect
call CloseWindow
ret
.NoBugMonText:
text "No bug #MON."
done
.bug_mon:
ld hl, .ItsBugMonText
call MenuTextbox
ld a, BANK(sIsBugMon)
call OpenSRAM
hlcoord 4, 16
ld de, sIsBugMon
ld c, 1
call PrintHexNumber
ld [hl], "h"
call YesNoBox
jr c, .done
xor a
ld [sIsBugMon], a
.done
call CloseSRAM
call CloseWindow
ret
.ItsBugMonText:
text "It'", "s bug #MON!"
next "No. Clear flag?"
done
PrintHexNumber:
; Print the c-byte value from de to hl as hexadecimal digits.
.loop
push bc
call .HandleByte
pop bc
dec c
jr nz, .loop
ret
.HandleByte:
ld a, [de]
swap a
and $f
call .PrintDigit
ld [hli], a
ld a, [de]
and $f
call .PrintDigit
ld [hli], a
inc de
ret
.PrintDigit:
ld bc, .HexDigits
add c
ld c, a
ld a, 0
adc b
ld b, a
ld a, [bc]
ret
.HexDigits:
db "0123456789ABCDEF"
|