Skip to content

Commit f46db37

Browse files
authored
Thoroughly document debug code (pret#410)
1 parent d001ced commit f46db37

File tree

18 files changed

+128
-109
lines changed

18 files changed

+128
-109
lines changed

‎constants/item_constants.asm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
const POKE_BALL ; $04
1414
const TOWN_MAP ; $05
1515
const BICYCLE ; $06
16-
const SURFBOARD ; $07 buggy?
16+
const SURFBOARD ; $07
1717
const SAFARI_BALL ; $08
1818
const POKEDEX ; $09
1919
const MOON_STONE ; $0A

‎constants/misc_constants.asm‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ DEF TEXT_DELAY_SLOW EQU %101 ; 5
1616
const_def 6
1717
const BIT_BATTLE_SHIFT ; 6
1818
const BIT_BATTLE_ANIMATION ; 7
19+
20+
; wd732 flags
21+
DEF BIT_DEBUG_MODE EQU 1

‎data/maps/special_warps.asm‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ MACRO special_warp_spec
4444
db \4
4545
ENDM
4646

47-
FirstMapSpec:
47+
NewGameWarp:
4848
special_warp_spec REDS_HOUSE_2F, 3, 6, REDS_HOUSE_2
49-
TradeCenterSpec1:
49+
TradeCenterPlayerWarp:
5050
special_warp_spec TRADE_CENTER, 3, 4, CLUB
51-
TradeCenterSpec2:
51+
TradeCenterFriendWarp:
5252
special_warp_spec TRADE_CENTER, 6, 4, CLUB
53-
ColosseumSpec1:
53+
ColosseumPlayerWarp:
5454
special_warp_spec COLOSSEUM, 3, 4, CLUB
55-
ColosseumSpec2:
55+
ColosseumFriendWarp:
5656
special_warp_spec COLOSSEUM, 6, 4, CLUB
5757

5858

‎engine/battle/core.asm‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,9 +2493,9 @@ MoveSelectionMenu:
24932493
; so it is necessary to put the di ei block to not cause tearing
24942494
call TextBoxBorder
24952495
hlcoord 4, 12
2496-
ld [hl], $7a
2496+
ld [hl], "─"
24972497
hlcoord 10, 12
2498-
ld [hl], $7e
2498+
ld [hl], "┘"
24992499
ei
25002500
hlcoord 6, 13
25012501
call .writemoves
@@ -2557,11 +2557,12 @@ MoveSelectionMenu:
25572557
ld a, [wLinkState]
25582558
cp LINK_STATE_BATTLING
25592559
jr z, .matchedkeyspicked
2560+
; Disable left, right, and START buttons in regular battles.
25602561
ld a, [wFlags_D733]
25612562
bit BIT_TEST_BATTLE, a
25622563
ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT
25632564
jr z, .matchedkeyspicked
2564-
ld b, $ff
2565+
ld b, D_UP | D_DOWN | D_LEFT | D_RIGHT | A_BUTTON | B_BUTTON | SELECT | START
25652566
.matchedkeyspicked
25662567
ld a, b
25672568
ld [hli], a ; wMenuWatchedKeys
@@ -2585,8 +2586,12 @@ SelectMenuItem:
25852586
call PlaceString
25862587
jr .select
25872588
.battleselect
2589+
; Hide move swap cursor in TestBattle.
25882590
ld a, [wFlags_D733]
25892591
bit BIT_TEST_BATTLE, a
2592+
; This causes PrintMenuItem to not run in TestBattle.
2593+
; MoveSelectionMenu still draws part of its window, an issue
2594+
; which did not seem to exist in the Japanese versions.
25902595
jr nz, .select
25912596
call PrintMenuItem
25922597
ld a, [wMenuItemToSwap]
@@ -2648,8 +2653,9 @@ SelectMenuItem:
26482653
jr z, .disabled
26492654
ld a, [wPlayerBattleStatus3]
26502655
bit 3, a ; transformed
2651-
jr nz, .dummy ; game freak derp
2652-
.dummy
2656+
jr nz, .transformedMoveSelected
2657+
.transformedMoveSelected ; pointless
2658+
; Allow moves copied by Transform to be used.
26532659
ld a, [wCurrentMenuItem]
26542660
ld hl, wBattleMonMoves
26552661
ld c, a
@@ -6085,6 +6091,7 @@ GetCurrentMove:
60856091
jr .selected
60866092
.player
60876093
ld de, wPlayerMoveNum
6094+
; Apply InitBattleVariables to TestBattle.
60886095
ld a, [wFlags_D733]
60896096
bit BIT_TEST_BATTLE, a
60906097
ld a, [wTestBattlePlayerSelectedMove]
@@ -6768,12 +6775,12 @@ InitOpponent:
67686775

67696776
DetermineWildOpponent:
67706777
ld a, [wd732]
6771-
bit 1, a
6772-
jr z, .notDebug
6778+
bit BIT_DEBUG_MODE, a
6779+
jr z, .notDebugMode
67736780
ldh a, [hJoyHeld]
6774-
bit BIT_B_BUTTON, a
6781+
bit BIT_B_BUTTON, a ; disable wild encounters
67756782
ret nz
6776-
.notDebug
6783+
.notDebugMode
67776784
ld a, [wNumberOfNoRandomBattleStepsLeft]
67786785
and a
67796786
ret nz

‎engine/battle/init_battle_variables.asm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ InitBattleVariables:
2020
ld [hli], a ; wPlayerHPBarColor
2121
ld [hl], a ; wEnemyHPBarColor
2222
ld hl, wCanEvolveFlags
23-
ld b, $3c
23+
ld b, wMiscBattleDataEnd - wMiscBattleData
2424
.loop
2525
ld [hli], a
2626
dec b

‎engine/debug/debug_menu.asm‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ IF DEF(_DEBUG)
5656

5757
; DEBUG
5858
ld hl, wd732
59-
set 1, [hl]
59+
set BIT_DEBUG_MODE, [hl]
6060
jp StartNewGameDebug
6161

6262
DebugBattlePlayerName:
@@ -72,27 +72,31 @@ ELSE
7272
ret
7373
ENDC
7474

75-
TestBattle:
75+
TestBattle: ; unreferenced except in _DEBUG
7676
.loop
7777
call GBPalNormal
7878

79-
; Don't mess around
80-
; with obedience.
79+
; Don't mess around with obedience.
8180
ld a, 1 << BIT_EARTHBADGE
8281
ld [wObtainedBadges], a
8382

8483
ld hl, wFlags_D733
8584
set BIT_TEST_BATTLE, [hl]
8685

86+
; wNumBagItems and wBagItems are not initialized here,
87+
; and their garbage values happen to act as if EXP_ALL
88+
; is in the bag at the end of the test battle.
89+
; pokeyellow fixes this by initializing them with a
90+
; list of items.
91+
8792
; Reset the party.
8893
ld hl, wPartyCount
8994
xor a
9095
ld [hli], a
9196
dec a
9297
ld [hl], a
9398

94-
; Give the player a
95-
; level 20 Rhydon.
99+
; Give the player a level 20 Rhydon.
96100
ld a, RHYDON
97101
ld [wcf91], a
98102
ld a, 20
@@ -102,15 +106,14 @@ TestBattle:
102106
ld [wCurMap], a
103107
call AddPartyMon
104108

105-
; Fight against a
106-
; level 20 Rhydon.
109+
; Fight against a level 20 Rhydon.
107110
ld a, RHYDON
108111
ld [wCurOpponent], a
109112

110113
predef InitOpponent
111114

112-
; When the battle ends,
113-
; do it all again.
115+
; When the battle ends, do it all again.
116+
; There are some graphical quirks in SGB mode.
114117
ld a, 1
115118
ld [wUpdateSpritesEnabled], a
116119
ldh [hAutoBGTransferEnabled], a

‎engine/debug/debug_party.asm‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
; This function is a debugging feature to give the player Tsunekazu Ishihara's
2-
; favorite Pokemon. This is indicated by the overpowered Exeggutor, which
3-
; Ishihara (president of Creatures Inc.) said was his favorite Pokemon in an ABC
4-
; interview on February 8, 2000.
5-
; "Exeggutor is my favorite. That's because I was always using this character
6-
; while I was debugging the program."
7-
; http://www.ign.com/articles/2000/02/09/abc-news-pokamon-chat-transcript
8-
9-
SetIshiharaTeam:
10-
ld de, IshiharaTeam
1+
SetDebugNewGameParty: ; unreferenced except in _DEBUG
2+
ld de, DebugNewGameParty
113
.loop
124
ld a, [de]
135
cp -1
@@ -20,7 +12,11 @@ SetIshiharaTeam:
2012
call AddPartyMon
2113
jr .loop
2214

23-
IshiharaTeam:
15+
DebugNewGameParty: ; unreferenced except in _DEBUG
16+
; Exeggutor is the only debug party member shared with Red, Green, and Japanese Blue.
17+
; "Tsunekazu Ishihara: Exeggutor is my favorite. That's because I was
18+
; always using this character while I was debugging the program."
19+
; From https://web.archive.org/web/20000607152840/http://pocket.ign.com/news/14973.html
2420
db EXEGGUTOR, 90
2521
IF DEF(_DEBUG)
2622
db MEW, 5
@@ -35,21 +31,21 @@ IF DEF(_DEBUG)
3531
ENDC
3632
db -1 ; end
3733

38-
DebugStart:
34+
PrepareNewGameDebug: ; dummy except in _DEBUG
3935
IF DEF(_DEBUG)
4036
xor a ; PLAYER_PARTY_DATA
4137
ld [wMonDataLocation], a
4238

4339
; Fly anywhere.
44-
dec a ; $ff
40+
dec a ; $ff (all bits)
4541
ld [wTownVisitedFlag], a
4642
ld [wTownVisitedFlag + 1], a
4743

4844
; Get all badges except Earth Badge.
4945
ld a, ~(1 << BIT_EARTHBADGE)
5046
ld [wObtainedBadges], a
5147

52-
call SetIshiharaTeam
48+
call SetDebugNewGameParty
5349

5450
; Exeggutor gets four HM moves.
5551
ld hl, wPartyMon1Moves

‎engine/menus/main_menu.asm‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ MainMenu:
121121
ld [wDestinationMap], a
122122
ld hl, wd732
123123
set 2, [hl] ; fly warp or dungeon warp
124-
call SpecialWarpIn
124+
call PrepareForSpecialWarp
125125
jp SpecialEnterMap
126126

127127
InitOptions:
@@ -268,10 +268,10 @@ LinkMenu:
268268
ld c, 50
269269
call DelayFrames
270270
ld hl, wd732
271-
res 1, [hl]
271+
res BIT_DEBUG_MODE, [hl]
272272
ld a, [wDefaultMap]
273273
ld [wDestinationMap], a
274-
call SpecialWarpIn
274+
call PrepareForSpecialWarp
275275
ld c, 20
276276
call DelayFrames
277277
xor a
@@ -308,7 +308,12 @@ LinkCanceledText:
308308

309309
StartNewGame:
310310
ld hl, wd732
311-
res 1, [hl]
311+
; Ensure debug mode is not used when
312+
; starting a regular new game.
313+
; Debug mode persists in saved games for
314+
; both debug and non-debug builds, and is
315+
; only reset here by the main menu.
316+
res BIT_DEBUG_MODE, [hl]
312317
; fallthrough
313318
StartNewGameDebug:
314319
call OakSpeech

‎engine/movie/oak_speech/oak_speech.asm‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ PrepareOakSpeech:
33
push af
44
ld a, [wOptions]
55
push af
6+
; Retrieve BIT_DEBUG_MODE set in DebugMenu for StartNewGameDebug.
7+
; BUG: StartNewGame carries over bit 5 from previous save files,
8+
; which causes CheckForceBikeOrSurf to not return.
9+
; To fix this in debug builds, reset bit 5 here or in StartNewGame.
10+
; In non-debug builds, the instructions can be removed.
611
ld a, [wd732]
712
push af
813
ld hl, wPlayerName
@@ -24,6 +29,7 @@ PrepareOakSpeech:
2429
call z, InitOptions
2530
; These debug names are used for StartNewGameDebug.
2631
; TestBattle uses the debug names from DebugMenu.
32+
; A variant of this process is performed in PrepareTitleScreen.
2733
ld hl, DebugNewGamePlayerName
2834
ld de, wPlayerName
2935
ld bc, NAME_LENGTH
@@ -49,15 +55,15 @@ OakSpeech:
4955
ld [wcf91], a
5056
ld a, 1
5157
ld [wItemQuantity], a
52-
call AddItemToInventory ; give one potion
58+
call AddItemToInventory
5359
ld a, [wDefaultMap]
5460
ld [wDestinationMap], a
55-
call SpecialWarpIn
61+
call PrepareForSpecialWarp
5662
xor a
5763
ldh [hTileAnimations], a
5864
ld a, [wd732]
59-
bit 1, a ; possibly a debug mode bit
60-
jp nz, .skipChoosingNames
65+
bit BIT_DEBUG_MODE, a
66+
jp nz, .skipSpeech
6167
ld de, ProfOakPic
6268
lb bc, BANK(ProfOakPic), $00
6369
call IntroDisplayPicCenteredOrUpperRight
@@ -93,7 +99,7 @@ OakSpeech:
9399
ld hl, IntroduceRivalText
94100
call PrintText
95101
call ChooseRivalName
96-
.skipChoosingNames
102+
.skipSpeech
97103
call GBFadeOutToWhite
98104
call ClearScreen
99105
ld de, RedPicFront
@@ -159,6 +165,7 @@ OakSpeechText1:
159165
text_end
160166
OakSpeechText2:
161167
text_far _OakSpeechText2A
168+
; BUG: The cry played does not match the sprite displayed.
162169
sound_cry_nidorina
163170
text_far _OakSpeechText2B
164171
text_end

‎engine/movie/title.asm‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CopyDebugName:
1+
CopyDebugName: ; unused
22
ld bc, NAME_LENGTH
33
jp CopyData
44

@@ -42,10 +42,10 @@ DisplayTitleScreen:
4242
ld bc, 5 tiles
4343
ld a, BANK(NintendoCopyrightLogoGraphics)
4444
call FarCopyData2
45-
ld hl, GamefreakLogoGraphics
45+
ld hl, GameFreakLogoGraphics
4646
ld de, vTitleLogo2 tile (16 + 5)
4747
ld bc, 9 tiles
48-
ld a, BANK(GamefreakLogoGraphics)
48+
ld a, BANK(GameFreakLogoGraphics)
4949
call FarCopyData2
5050
ld hl, PokemonLogoGraphics
5151
ld de, vTitleLogo
@@ -378,7 +378,7 @@ LoadCopyrightAndTextBoxTiles:
378378
LoadCopyrightTiles:
379379
ld de, NintendoCopyrightLogoGraphics
380380
ld hl, vChars2 tile $60
381-
lb bc, BANK(NintendoCopyrightLogoGraphics), (GamefreakLogoGraphicsEnd - NintendoCopyrightLogoGraphics) / $10
381+
lb bc, BANK(NintendoCopyrightLogoGraphics), (GameFreakLogoGraphicsEnd - NintendoCopyrightLogoGraphics) / $10
382382
call CopyVideoData
383383
hlcoord 2, 7
384384
ld de, CopyrightTextString

0 commit comments

Comments
 (0)