summaryrefslogtreecommitdiff
path: root/engine/debug
diff options
context:
space:
mode:
Diffstat (limited to 'engine/debug')
-rw-r--r--engine/debug/color_picker.asm1453
-rw-r--r--engine/debug/debug_room.asm1391
2 files changed, 2844 insertions, 0 deletions
diff --git a/engine/debug/color_picker.asm b/engine/debug/color_picker.asm
new file mode 100644
index 00000000..204703d9
--- /dev/null
+++ b/engine/debug/color_picker.asm
@@ -0,0 +1,1453 @@
+ const_def $6a
+ const DEBUGTEST_TICKS_1 ; $6a
+ const DEBUGTEST_TICKS_2 ; $6b
+ const DEBUGTEST_WHITE ; $6c
+ const DEBUGTEST_LIGHT ; $6d
+ const DEBUGTEST_DARK ; $6e
+ const DEBUGTEST_BLACK ; $6f
+ const DEBUGTEST_0 ; $70
+ const DEBUGTEST_1 ; $71
+ const DEBUGTEST_2 ; $72
+ const DEBUGTEST_3 ; $73
+ const DEBUGTEST_4 ; $74
+ const DEBUGTEST_5 ; $75
+ const DEBUGTEST_6 ; $76
+ const DEBUGTEST_7 ; $77
+ const DEBUGTEST_8 ; $78
+ const DEBUGTEST_9 ; $79
+ const DEBUGTEST_A ; $7a
+ const DEBUGTEST_B ; $7b
+ const DEBUGTEST_C ; $7c
+ const DEBUGTEST_D ; $7d
+ const DEBUGTEST_E ; $7e
+ const DEBUGTEST_F ; $7f
+
+DebugColorPicker:
+; A debug menu to test monster and trainer palettes at runtime.
+
+ ldh a, [hCGB]
+ and a
+ jr nz, .set
+ ldh a, [hSGB]
+ and a
+ ret z
+
+.set
+ ldh a, [hInMenu]
+ push af
+ ld a, 1
+ ldh [hInMenu], a
+ call DisableLCD
+ call DebugColor_InitVRAM
+ call DebugColor_LoadGFX
+ call DebugColor_InitPalettes
+ call DebugColor_InitMonColor
+ call EnableLCD
+ ld de, MUSIC_NONE
+ call PlayMusic
+ xor a
+ ld [wJumptableIndex], a
+ ld [wce66], a
+ ld [wceee], a
+.loop
+ ld a, [wJumptableIndex]
+ bit 7, a
+ jr nz, .exit
+ call DebugColorMain
+ call DebugColor_PlaceCursor
+ call DelayFrame
+ jr .loop
+
+.exit
+ pop af
+ ldh [hInMenu], a
+ ret
+
+DebugColor_InitMonColor:
+ ld a, [wceed]
+ and a
+ jr nz, DebugColor_InitTrainerColor
+ ld hl, PokemonPalettes
+
+DebugColor_InitMonColor2:
+ ld de, wOverworldMapBlocks
+ ld c, NUM_POKEMON + 1
+.loop
+ push bc
+ push hl
+ call DebugColor_InitColor
+ pop hl
+ ld bc, 8
+ add hl, bc
+ pop bc
+ dec c
+ jr nz, .loop
+ ret
+
+DebugColor_InitTrainerColor:
+ ld hl, TrainerPalettes
+ ld de, wOverworldMapBlocks
+ ld c, NUM_TRAINER_CLASSES
+.loop
+ push bc
+ push hl
+ call DebugColor_InitColor
+ pop hl
+ ld bc, 4
+ add hl, bc
+ pop bc
+ dec c
+ jr nz, .loop
+ ret
+
+DebugColor_InitColor:
+ ld a, BANK(PokemonPalettes) ; aka BANK(TrainerPalettes)
+ call GetFarByte
+ ld [de], a
+ inc de
+ inc hl
+
+ ld a, BANK(PokemonPalettes) ; aka BANK(TrainerPalettes)
+ call GetFarByte
+ ld [de], a
+ inc de
+ inc hl
+
+ ld a, BANK(PokemonPalettes) ; aka BANK(TrainerPalettes)
+ call GetFarByte
+ ld [de], a
+ inc de
+ inc hl
+
+ ld a, BANK(PokemonPalettes) ; aka BANK(TrainerPalettes)
+ call GetFarByte
+ ld [de], a
+ inc de
+ ret
+
+DebugColor_InitVRAM:
+ ld a, 1
+ ldh [rVBK], a
+ ld hl, vTiles0
+ ld bc, sScratch - vTiles0
+ xor a
+ call ByteFill
+
+ ld a, 0
+ ldh [rVBK], a
+ ld hl, vTiles0
+ ld bc, sScratch - vTiles0
+ xor a
+ call ByteFill
+
+ hlcoord 0, 0, wAttrmap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ xor a
+ call ByteFill
+
+ hlcoord 0, 0
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ xor a
+ call ByteFill
+
+ call ClearSprites
+ ret
+
+DebugColor_LoadGFX:
+ ld hl, DebugColor_GFX
+ ld de, vTiles2 tile DEBUGTEST_TICKS_1
+ ld bc, 22 tiles
+ call CopyBytes
+ ld hl, DebugColor_UpArrowGFX
+ ld de, vTiles0
+ ld bc, 1 tiles
+ call CopyBytes
+ call LoadStandardFont
+ ld hl, vTiles1
+ lb bc, 8, 0
+.loop
+ ld a, [hl]
+ xor $ff
+ ld [hli], a
+ dec bc
+ ld a, c
+ or b
+ jr nz, .loop
+ ret
+
+DebugColor_InitPalettes:
+ ldh a, [hCGB]
+ and a
+ ret z
+ ld hl, Palette_DebugBG
+ ld de, wBGPals2
+ ld bc, 16 palettes
+ call CopyBytes
+ ld a, 1 << rBGPI_AUTO_INCREMENT
+ ldh [rBGPI], a
+ ld hl, Palette_DebugBG
+ ld c, 8 palettes
+ xor a
+.loop1
+ ldh [rBGPD], a
+ dec c
+ jr nz, .loop1
+
+ ld a, 1 << rOBPI_AUTO_INCREMENT
+ ldh [rOBPI], a
+ ld hl, Palette_DebugOB
+ ld c, 8 palettes
+.loop2
+ ld a, [hli]
+ ldh [rOBPD], a
+ dec c
+ jr nz, .loop2
+
+ ld a, $94
+ ld [wc508], a
+ ld a, $52
+ ld [wc508 + 1], a
+ ld a, $4a
+ ld [wc508 + 2], a
+ ld a, $29
+ ld [wc508 + 3], a
+ ret
+
+Palette_DebugBG:
+INCLUDE "gfx/debug/bg.pal"
+
+Palette_DebugOB:
+INCLUDE "gfx/debug/ob.pal"
+
+DebugColorMain:
+ call JoyTextDelay
+ ld a, [wJumptableIndex]
+ cp 4
+ jr nc, .asm_fd49e
+ ld hl, hJoyLast
+ ld a, [hl]
+ and SELECT
+ jr nz, .NextMon
+ ld a, [hl]
+ and START
+ jr nz, .PreviousMon
+
+.asm_fd49e
+ jumptable Jumptable_fd4e2, wJumptableIndex
+
+.NextMon:
+ call DebugColor_BackupSpriteColors
+ call DebugColor_SetMaxNum
+ ld e, a
+ ld a, [wce66]
+ inc a
+ cp e
+ jr c, .SwitchMon
+ xor a
+ jr .SwitchMon
+
+.PreviousMon:
+ call DebugColor_BackupSpriteColors
+ ld a, [wce66]
+ dec a
+ cp -1
+ jr nz, .SwitchMon
+ call DebugColor_SetMaxNum
+ dec a
+
+.SwitchMon:
+ ld [wce66], a
+ ld a, 0 ; ScreenInitNo
+ ld [wJumptableIndex], a
+ ret
+
+DebugColor_SetMaxNum:
+ ld a, [wceed]
+ and a
+ jr nz, .trainer
+; .mon
+ ld a, NUM_POKEMON
+ ret
+.trainer
+ ld a, NUM_TRAINER_CLASSES - 1
+ ret
+
+Jumptable_fd4e2:
+ dw DebugColor_InitScreen
+ dw Functionfd62b
+ dw Functionfd646
+ dw Functionfd6cb
+ dw Functionfd797
+ dw Functionfd7b8
+
+DebugColor_InitScreen:
+ xor a
+ ldh [hBGMapMode], a
+ hlcoord 0, 0
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, DEBUGTEST_BLACK
+ call ByteFill
+ hlcoord 1, 3
+ lb bc, 7, 18
+ ld a, DEBUGTEST_WHITE
+ call DebugColor_FillBoxWithByte
+ hlcoord 11, 0
+ lb bc, 2, 3
+ ld a, DEBUGTEST_LIGHT
+ call DebugColor_FillBoxWithByte
+ hlcoord 16, 0
+ lb bc, 2, 3
+ ld a, DEBUGTEST_DARK
+ call DebugColor_FillBoxWithByte
+ call DebugColor_LoadRGBMeter
+ call DebugColor_SetRGBMeter
+ ld a, [wce66]
+ inc a
+ ld [wCurPartySpecies], a
+ ld [wDeciramBuffer], a
+ hlcoord 0, 1
+ ld de, wDeciramBuffer
+ lb bc, PRINTNUM_LEADINGZEROS | 1, 3
+ call PrintNum
+ ld a, [wceed]
+ and a
+ jr nz, .Trainer
+
+.MonSpriteViewer:
+ ld a, 1
+ ld [wUnownLetter], a
+ call GetPokemonName
+ hlcoord 4, 1
+ call PlaceString
+ xor a
+ ld [wBoxAlignment], a
+ hlcoord 2, 3
+ call _PrepMonFrontpic
+ ld de, vTiles2 tile $31
+ predef GetMonBackpic
+ ld a, $31
+ ldh [hGraphicStartTile], a
+ hlcoord 12, 4
+ lb bc, 6, 6
+ predef PlaceGraphic
+ ld a, [wceee]
+ and a
+ jr z, .load_normal_text
+
+.load_shiny_text
+ ld de, DebugColor_ShinyText
+ jr .place_switch_text
+
+.load_normal_text
+ ld de, DebugColor_NormalText
+
+.place_switch_text
+ hlcoord 7, 17
+ call PlaceString
+ hlcoord 0, 17
+ ld de, DebugColor_SwitchText
+ call PlaceString
+ jr .asm_fd5bc
+
+.Trainer:
+ ld a, [wDeciramBuffer]
+ ld [wTrainerClass], a
+ callfar GetTrainerAttributes
+ ld de, wStringBuffer1
+ hlcoord 4, 1
+ call PlaceString
+ ld de, vTiles2
+ callfar GetTrainerPic
+ xor a
+ ld [wTempEnemyMonSpecies], a
+ ldh [hGraphicStartTile], a
+ hlcoord 2, 3
+ lb bc, 7, 7
+ predef PlaceGraphic
+
+.asm_fd5bc
+ ld a, 1
+ ld [wJumptableIndex], a
+ ret
+
+DebugColor_ShinyText:
+ db "レア", DEBUGTEST_BLACK, DEBUGTEST_BLACK, "@" ; Rare (shiny)
+
+DebugColor_NormalText:
+ db "ノーマル@" ; Normal
+
+DebugColor_SwitchText:
+ db DEBUGTEST_A, "きりかえ▶@" ; Switch
+
+DebugColor_LoadRGBMeter:
+ decoord 0, 11, wAttrmap
+ hlcoord 2, 11
+ ld a, 1
+ call Functionfd5f1
+ decoord 0, 13, wAttrmap
+ hlcoord 2, 13
+ ld a, 2
+ call Functionfd5f1
+ decoord 0, 15, wAttrmap
+ hlcoord 2, 15
+ ld a, 3
+
+Functionfd5f1:
+ push af
+ ld a, DEBUGTEST_TICKS_1
+ ld [hli], a
+ ld bc, 15
+ ld a, DEBUGTEST_TICKS_2
+ call ByteFill
+ ld l, e
+ ld h, d
+ pop af
+ ld bc, 20 * 2
+ call ByteFill
+ ret
+
+DebugColor_SetRGBMeter:
+ ld a, [wce66]
+ inc a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ ld de, wOverworldMapBlocks
+ add hl, de
+ ld de, wc508
+ ld bc, 4
+ call CopyBytes
+ xor a
+ ld [wce64], a
+ ld [wce65], a
+ ld de, wc508
+ call DebugColor_CalculateRGB
+ ret
+
+Functionfd62b:
+ ldh a, [hCGB]
+ and a
+ jr z, .asm_fd63d
+ ld a, 2
+ ldh [hBGMapMode], a
+ call DelayFrame
+ call DelayFrame
+ call DelayFrame
+
+.asm_fd63d
+ call WaitBGMap
+ ld a, 2
+ ld [wJumptableIndex], a
+ ret
+
+Functionfd646:
+ ldh a, [hCGB]
+ and a
+ jr z, .sgb
+
+.cgb
+ ld hl, wBGPals2
+ ld de, wc508
+ ld c, 1
+ call Functionfd8ec
+ hlcoord 10, 2
+ ld de, wc508
+ call Functionfd6b0
+ hlcoord 15, 2
+ ld de, wc508 + 2
+ call Functionfd6b0
+ ld a, 1
+ ldh [hCGBPalUpdate], a
+ ld a, 3
+ ld [wJumptableIndex], a
+ ret
+
+.sgb
+ ld hl, wSGBPals
+ ld a, 1
+ ld [hli], a
+ ld a, LOW(PALRGB_WHITE)
+ ld [hli], a
+ ld a, HIGH(PALRGB_WHITE)
+ ld [hli], a
+ ld a, [wc508]
+ ld [hli], a
+ ld a, [wc508 + 1]
+ ld [hli], a
+ ld a, [wc508 + 2]
+ ld [hli], a
+ ld a, [wc508 + 3]
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hli], a
+ ld [hl], a
+ ld hl, wSGBPals
+ call Functionfd915
+ hlcoord 10, 2
+ ld de, wc508
+ call Functionfd6b0
+ hlcoord 15, 2
+ ld de, wc508 + 2
+ call Functionfd6b0
+ ld a, 3
+ ld [wJumptableIndex], a
+ ret
+
+Functionfd6b0:
+ inc hl
+ inc hl
+ inc hl
+ ld a, [de]
+ call Functionfd6c5
+ ld a, [de]
+ swap a
+ call Functionfd6c5
+ inc de
+ ld a, [de]
+ call Functionfd6c5
+ ld a, [de]
+ swap a
+
+Functionfd6c5:
+ and $f
+ add DEBUGTEST_0
+ ld [hld], a
+ ret
+
+Functionfd6cb:
+ ldh a, [hJoyLast]
+ and B_BUTTON
+ jr nz, .asm_fd6e8
+ ldh a, [hJoyLast]
+ and A_BUTTON
+ jr nz, .asm_fd6ee
+ ld a, [wce64]
+ and 3
+ ld e, a
+ ld d, 0
+ ld hl, Jumptable_fd70b
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+.asm_fd6e8
+ ld a, 4
+ ld [wJumptableIndex], a
+ ret
+
+.asm_fd6ee
+ ld a, [wceed]
+ and a
+ ret nz
+ ld a, [wceee]
+ xor 4
+ ld [wceee], a
+ ld c, a
+ ld b, 0
+ ld hl, PokemonPalettes
+ add hl, bc
+ call DebugColor_InitMonColor2
+ ld a, 0
+ ld [wJumptableIndex], a
+ ret
+
+Jumptable_fd70b:
+ dw DebugColor_SelectColorBox
+ dw DebugColor_ChangeRedValue
+ dw DebugColor_ChangeGreenValue
+ dw DebugColor_ChangeBlueValue
+
+DebugColor_SelectColorBox:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, DebugColor_NextRGBColor
+ ld a, [hl]
+ and D_LEFT
+ jr nz, .lightcolor
+ ld a, [hl]
+ and D_RIGHT
+ jr nz, .darkcolor
+ ret
+
+.lightcolor:
+ xor a
+ ld [wce65], a
+ ld de, wc508
+ call DebugColor_CalculateRGB
+ ret
+
+.darkcolor:
+ ld a, 1
+ ld [wce65], a
+ ld de, wc508 + 2
+ call DebugColor_CalculateRGB
+ ret
+
+DebugColor_ChangeRedValue:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, DebugColor_NextRGBColor
+ ld a, [hl]
+ and D_UP
+ jr nz, DebugColor_PreviousRGBColor
+ ld hl, wc508 + 10
+ jr DebugColor_UpdateSpriteColor
+
+DebugColor_ChangeGreenValue:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, DebugColor_NextRGBColor
+ ld a, [hl]
+ and D_UP
+ jr nz, DebugColor_PreviousRGBColor
+ ld hl, wc508 + 11
+ jr DebugColor_UpdateSpriteColor
+
+DebugColor_ChangeBlueValue:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_UP
+ jr nz, DebugColor_PreviousRGBColor
+ ld hl, wc508 + 12
+
+DebugColor_UpdateSpriteColor:
+ ldh a, [hJoyLast]
+ and D_RIGHT
+ jr nz, .increment_color_value
+ ldh a, [hJoyLast]
+ and D_LEFT
+ jr nz, .decrement_color_value
+ ret
+
+.increment_color_value
+ ld a, [hl]
+ cp $1f
+ ret nc
+ inc [hl]
+ jr .asm_fd784
+
+.decrement_color_value
+ ld a, [hl]
+ and a
+ ret z
+ dec [hl]
+
+.asm_fd784
+ call DebugColor_CalculatePalette
+ ld a, 2
+ ld [wJumptableIndex], a
+ ret
+
+DebugColor_PreviousRGBColor:
+ ld hl, wce64
+ dec [hl]
+ ret
+
+DebugColor_NextRGBColor:
+ ld hl, wce64
+ inc [hl]
+ ret
+
+Functionfd797:
+ hlcoord 0, 10
+ ld bc, 20 * 8
+ ld a, DEBUGTEST_BLACK
+ call ByteFill
+ hlcoord 2, 12
+ ld de, String_fd9d6
+ call PlaceString
+ xor a
+ ld [wceef], a
+ call Functionfd7fd
+ ld a, 5
+ ld [wJumptableIndex], a
+ ret
+
+Functionfd7b8:
+ ld hl, hJoyPressed
+ ld a, [hl]
+ and B_BUTTON
+ jr nz, .cancel
+; ld a,(hl)
+; and A_BUTTON
+; jr nz, .exit
+ call DebugColor_TMHMJoypad
+ ret
+
+.cancel
+ ld a, 0
+ ld [wJumptableIndex], a
+ ret
+
+.exit
+ ld hl, wJumptableIndex
+ set 7, [hl]
+ ret
+
+DebugColor_TMHMJoypad:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_UP
+ jr nz, .asm_fd7de
+ ld a, [hl]
+ and D_DOWN
+ jr nz, .asm_fd7eb
+ ret
+
+.asm_fd7de
+ ld a, [wceef]
+ cp 56
+ jr z, .asm_fd7e8
+ inc a
+ jr .asm_fd7f6
+
+.asm_fd7e8
+ xor a
+ jr .asm_fd7f6
+
+.asm_fd7eb
+ ld a, [wceef]
+ and a
+ jr z, .asm_fd7f4
+ dec a
+ jr .asm_fd7f6
+
+.asm_fd7f4
+ ld a, 56
+
+.asm_fd7f6
+ ld [wceef], a
+ call Functionfd7fd
+ ret
+
+Functionfd7fd:
+ hlcoord 10, 11
+ call Functionfd867
+ hlcoord 10, 12
+ call Functionfd867
+ hlcoord 10, 13
+ call Functionfd867
+ hlcoord 10, 14
+ call Functionfd867
+ ld a, [wceef]
+ inc a
+ ld [wTempTMHM], a
+ predef GetTMHMMove
+ ld a, [wTempTMHM]
+ ld [wPutativeTMHMMove], a
+ call GetMoveName
+ hlcoord 10, 12
+ call PlaceString
+ ld a, [wceef]
+ call Functionfd85e
+ ld [wCurItem], a
+ predef CanLearnTMHMMove
+ ld a, c
+ and a
+ ld de, DebugColor_AbleText
+ jr nz, .place_string
+ ld de, DebugColor_NotAbleText
+
+.place_string
+ hlcoord 10, 14
+ call PlaceString
+ ret
+
+DebugColor_AbleText:
+ db "おぼえられる@" ; Learnable
+
+DebugColor_NotAbleText:
+ db "おぼえられない@" ; Not learnable
+
+Functionfd85e:
+ cp NUM_TMS
+ jr c, .tm
+.hm
+ inc a
+ inc a
+.tm
+ add TM01
+ ret
+
+Functionfd867:
+ ld bc, 10
+ ld a, DEBUGTEST_BLACK
+ call ByteFill
+ ret
+
+DebugColor_CalculatePalette:
+ ld a, [wc508 + 10]
+ and %00011111
+ ld e, a
+ ld a, [wc508 + 11]
+ and %00000111
+ sla a
+ swap a
+ or e
+ ld e, a
+ ld a, [wc508 + 11]
+ and %00011000
+ sla a
+ swap a
+ ld d, a
+ ld a, [wc508 + 12]
+ and %00011111
+ sla a
+ sla a
+ or d
+ ld d, a
+ ld a, [wce65]
+ and a
+ jr z, .LightPalette
+
+.DarkPalette
+ ld a, e
+ ld [wc508 + 2], a
+ ld a, d
+ ld [wc508 + 3], a
+ ret
+
+.LightPalette
+ ld a, e
+ ld [wc508], a
+ ld a, d
+ ld [wc508 + 1], a
+ ret
+
+DebugColor_CalculateRGB:
+ ld a, [de]
+ and $1f
+ ld [wc508 + 10], a
+ ld a, [de]
+ and $e0
+ swap a
+ srl a
+ ld b, a
+ inc de
+ ld a, [de]
+ and 3
+ swap a
+ srl a
+ or b
+ ld [wc508 + 11], a
+ ld a, [de]
+ and $7c
+ srl a
+ srl a
+ ld [wc508 + 12], a
+ ret
+
+DebugColor_BackupSpriteColors:
+ ld a, [wce66]
+ inc a
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ ld de, wOverworldMapBlocks ; MonPalette
+ add hl, de
+ ld e, l
+ ld d, h
+ ld hl, wc508
+ ld bc, 4
+ call CopyBytes
+ ret
+
+Functionfd8ec:
+; Set palette buffer
+.loop
+ ld a, LOW(PALRGB_WHITE)
+ ld [hli], a
+ ld a, HIGH(PALRGB_WHITE)
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ ld a, [de]
+ inc de
+ ld [hli], a
+ xor a
+ ld [hli], a
+ ld [hli], a
+ dec c
+ jr nz, .loop
+ ret
+
+DebugColor_FillBoxWithByte:
+; For some reason, we have another copy of FillBoxWithByte here
+.row
+ push bc
+ push hl
+.col
+ ld [hli], a
+ dec c
+ jr nz, .col
+ pop hl
+ ld bc, SCREEN_WIDTH
+ add hl, bc
+ pop bc
+ dec b
+ jr nz, .row
+ ret
+
+Functionfd915:
+; SGB Related
+
+ ld a, [wd8ba]
+ push af
+ set 7, a
+ ld [wd8ba], a
+ call Functionfd926
+ pop af
+ ld [wd8ba], a
+ ret
+
+Functionfd926:
+ ld a, [hl]
+ and 7
+ ret z
+ ld b, a
+.asm_fd92b
+ push bc
+ xor a
+ ldh [rJOYP], a
+ ld a, $30
+ ldh [rJOYP], a
+ ld b, $10
+.asm_fd935
+ ld e, 8
+ ld a, [hli]
+ ld d, a
+.asm_fd939
+ bit 0, d
+ ld a, $10
+ jr nz, .asm_fd941
+ ld a, $20
+.asm_fd941
+ ldh [rJOYP], a
+ ld a, $30
+ ldh [rJOYP], a
+ rr d
+ dec e
+ jr nz, .asm_fd939
+ dec b
+ jr nz, .asm_fd935
+ ld a, $20
+ ldh [rJOYP], a
+ ld a, $30
+ ldh [rJOYP], a
+ ld de, 7000
+.wait
+ nop
+ nop
+ nop
+ dec de
+ ld a, d
+ or e
+ jr nz, .wait
+ pop bc
+ dec b
+ jr nz, .asm_fd92b
+ ret
+
+DebugColor_PlaceCursor:
+ ld a, DEBUGTEST_BLACK
+ hlcoord 10, 0
+ ld [hl], a
+ hlcoord 15, 0
+ ld [hl], a
+ hlcoord 1, 11
+ ld [hl], a
+ hlcoord 1, 13
+ ld [hl], a
+ hlcoord 1, 15
+ ld [hl], a
+ ld a, [wJumptableIndex]
+ cp 3
+ jr nz, .clearsprites
+ ld a, [wce64]
+ and a
+ jr z, .asm_fd996
+ dec a
+ hlcoord 1, 11
+ ld bc, 2 * SCREEN_WIDTH
+ call AddNTimes
+ ld [hl], "▶"
+
+.asm_fd996
+ ld a, [wce65]
+ and a
+ jr z, .lightcolor
+
+.darkcolor
+ hlcoord 15, 0
+ jr .place
+
+.lightcolor
+ hlcoord 10, 0
+
+.place
+ ld [hl], "▶"
+ ld b, $70
+ ld c, 5
+ ld hl, wVirtualOAM
+ ld de, wc508 + 10
+ call .PlaceSprites
+ ld de, wc508 + 11
+ call .PlaceSprites
+ ld de, wc508 + 12
+ call .PlaceSprites
+ ret
+
+.PlaceSprites:
+ ld a, b
+ ld [hli], a ; y
+ ld a, [de]
+ add a
+ add a
+ add 3 * TILE_WIDTH
+ ld [hli], a ; x
+ xor a
+ ld [hli], a ; tile id
+ ld a, c
+ ld [hli], a ; attributes
+ ld a, 2 * TILE_WIDTH
+ add b
+ ld b, a
+ inc c
+ ret
+
+.clearsprites
+ call ClearSprites
+ ret
+
+String_fd9d6:
+ db "おわりますか?" ; Are you finished?
+ next "はい<DOT><DOT><DOT>", DEBUGTEST_A ; YES...(A)
+ next "いいえ<DOT><DOT>", DEBUGTEST_B ; NO..(B)
+ db "@"
+
+DebugColor_UpArrowGFX:
+INCBIN "gfx/debug/up_arrow.2bpp"
+
+DebugColor_GFX:
+INCBIN "gfx/debug/color_test.2bpp"
+
+TilesetColorTest:
+ ret
+; dummied out
+ xor a
+ ld [wJumptableIndex], a
+ ld [wce64], a
+ ld [wce65], a
+ ld [wce66], a
+ ldh [hMapAnims], a
+ call ClearSprites
+ call OverworldTextModeSwitch
+ call WaitBGMap2
+ xor a
+ ldh [hBGMapMode], a
+ ld de, DebugColor_GFX
+ ld hl, vTiles2 tile DEBUGTEST_TICKS_1
+ lb bc, BANK(DebugColor_GFX), 22
+ call Request2bpp
+ ld de, DebugColor_UpArrowGFX
+ ld hl, vTiles1
+ lb bc, BANK(DebugColor_UpArrowGFX), 1
+ call Request2bpp
+ ld a, HIGH(vBGMap1)
+ ldh [hBGMapAddress + 1], a
+ hlcoord 0, 0
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, DEBUGTEST_BLACK
+ call ByteFill
+ hlcoord 0, 0, wAttrmap
+ ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
+ ld a, 7
+ call ByteFill
+ ld de, $15
+ ld a, DEBUGTEST_WHITE
+ call Functionfdbdb
+ ld de, $1a
+ ld a, DEBUGTEST_LIGHT
+ call Functionfdbdb
+ ld de, $1f
+ ld a, DEBUGTEST_DARK
+ call Functionfdbdb
+ ld de, $24
+ ld a, DEBUGTEST_BLACK
+ call Functionfdbdb
+ call Functionfdbfd
+ call Functionfdc18
+ call WaitBGMap2
+ ld [wJumptableIndex], a
+ ld a, $40
+ ldh [hWY], a
+ ret
+
+Functionfdbdb:
+ hlcoord 0, 0
+ call Functionfdbe7
+
+Functionfdbe1:
+ ld a, [wce64]
+ hlcoord 0, 0, wAttrmap
+
+Functionfdbe7:
+ add hl, de
+rept 4
+ ld [hli], a
+endr
+ ld bc, $10
+ add hl, bc
+rept 4
+ ld [hli], a
+endr
+ ld bc, $10
+ add hl, bc
+rept 4
+ ld [hli], a
+endr
+ ret
+
+Functionfdbfd:
+ hlcoord 2, 4
+ call .Place
+ hlcoord 2, 6
+ call .Place
+ hlcoord 2, 8
+
+.Place:
+ ld a, DEBUGTEST_TICKS_1
+ ld [hli], a
+ ld bc, $10 - 1
+ ld a, DEBUGTEST_TICKS_2
+ call ByteFill
+ ret
+
+Functionfdc18:
+ ld a, [wce64]
+ ld l, a
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ add hl, hl
+ ld de, wBGPals1
+ add hl, de
+ ld de, wc508
+ ld bc, 8
+ call CopyBytes
+ ld de, wc508
+ call DebugColor_CalculateRGB
+ ret
+
+DebugColorMain2:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and SELECT
+ jr nz, .loop7
+ ld a, [hl]
+ and B_BUTTON
+ jr nz, .asm_fdc8e
+ call Functionfdcdb
+ ret
+
+.loop7
+ ld hl, wce64
+ ld a, [hl]
+ inc a
+ and 7
+ cp 7
+ jr nz, .asm_fdc52
+ xor a
+
+.asm_fdc52
+ ld [hl], a
+ ld de, $15
+ call Functionfdbe1
+ ld de, $1a
+ call Functionfdbe1
+ ld de, $1f
+ call Functionfdbe1
+ ld de, $24
+ call Functionfdbe1
+ ld hl, wBGPals2
+ ld a, [wce64]
+ ld bc, 1 palettes
+ call AddNTimes
+ ld de, wc508
+ ld bc, 1 palettes
+ call CopyBytes
+ ld a, 2
+ ldh [hBGMapMode], a
+ ld c, 3
+ call DelayFrames
+ ld a, 1
+ ldh [hBGMapMode], a
+ ret
+
+.asm_fdc8e
+ call ClearSprites
+ ldh a, [hWY]
+ xor $d0
+ ldh [hWY], a
+ ret
+
+Functionfdc98:
+ ld hl, wBGPals2
+ ld a, [wce64]
+ ld bc, 1 palettes
+ call AddNTimes
+ ld e, l
+ ld d, h
+ ld hl, wc508
+ ld bc, 1 palettes
+ call CopyBytes
+ hlcoord 1, 0
+ ld de, wc508
+ call Functionfd6b0
+ hlcoord 6, 0
+ ld de, wc508 + 2
+ call Functionfd6b0
+ hlcoord 11, 0
+ ld de, wc508 + 4
+ call Functionfd6b0
+ hlcoord 16, 0
+ ld de, wc508 + 6
+ call Functionfd6b0
+ ld a, 1
+ ldh [hCGBPalUpdate], a
+ call DelayFrame
+ ret
+
+Functionfdcdb:
+ ld a, [wce65]
+ and 3
+ ld e, a
+ ld d, 0
+ ld hl, .PointerTable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+.PointerTable:
+ dw DebugColor_SelectColorBox2
+ dw Functionfdd24 ; Red
+ dw Functionfdd36 ; Green
+ dw Functionfdd48 ; Blue
+
+DebugColor_SelectColorBox2:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, Functionfdd77
+ ld a, [hl]
+ and D_LEFT
+ jr nz, .asm_fdd07
+ ld a, [hl]
+ and D_RIGHT
+ jr nz, .asm_fdd0d
+ ret
+
+.asm_fdd07
+ ld a, [wce66]
+ dec a
+ jr .asm_fdd11
+
+.asm_fdd0d
+ ld a, [wce66]
+ inc a
+
+.asm_fdd11
+ and 3
+ ld [wce66], a
+ ld e, a
+ ld d, 0
+ ld hl, wc508
+ add hl, de
+ add hl, de
+ ld e, l
+ ld d, h
+ call DebugColor_CalculateRGB
+ ret
+
+Functionfdd24:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, Functionfdd77
+ ld a, [hl]
+ and D_UP
+ jr nz, Functionfdd72
+ ld hl, wc508 + 10
+ jr Functionfdd53
+
+Functionfdd36:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_DOWN
+ jr nz, Functionfdd77
+ ld a, [hl]
+ and D_UP
+ jr nz, Functionfdd72
+ ld hl, wc508 + 11
+ jr Functionfdd53
+
+Functionfdd48:
+ ld hl, hJoyLast
+ ld a, [hl]
+ and D_UP
+ jr nz, Functionfdd72
+ ld hl, wc508 + 12
+
+Functionfdd53:
+ ldh a, [hJoyLast]
+ and D_RIGHT
+ jr nz, .asm_fdd60
+ ldh a, [hJoyLast]
+ and D_LEFT
+ jr nz, .asm_fdd67
+ ret
+
+.asm_fdd60
+ ld a, [hl]
+ cp $1f
+ ret nc
+ inc [hl]
+ jr .asm_fdd6b
+
+.asm_fdd67
+ ld a, [hl]
+ and a
+ ret z
+ dec [hl]
+
+.asm_fdd6b
+ call Functionfdd7c
+ call Functionfdc98
+ ret
+
+Functionfdd72:
+ ld hl, wce65
+ dec [hl]
+ ret
+
+Functionfdd77:
+ ld hl, wce65
+ inc [hl]
+ ret
+
+Functionfdd7c:
+ ld a, [wc508 + 10]
+ and $1f
+ ld e, a
+ ld a, [wc508 + 11]
+ and 7
+ sla a
+ swap a
+ or e
+ ld e, a
+ ld a, [wc508 + 11]
+ and $18
+ sla a
+ swap a
+ ld d, a
+ ld a, [wc508 + 12]
+ and $1f
+ sla a
+ sla a
+ or d
+ ld d, a
+ ld a, [wce66]
+ ld c, a
+ ld b, 0
+ ld hl, wc508
+ add hl, bc
+ add hl, bc
+ ld a, e
+ ld [hli], a
+ ld [hl], d
+ ret
+
+DebugColor_PlaceCursor2:
+ ld a, DEBUGTEST_BLACK
+ hlcoord 0, 4
+ ld [hl], a
+ hlcoord 0, 6
+ ld [hl], a
+ hlcoord 0, 8
+ ld [hl], a
+ hlcoord 0, 2
+ ld [hl], a
+ hlcoord 5, 2
+ ld [hl], a
+ hlcoord 10, 2
+ ld [hl], a
+ hlcoord 15, 2
+ ld [hl], a
+ ld a, [wce65]
+ and a
+ jr z, .asm_fdde1
+ dec a
+ hlcoord 0, 4
+ ld bc, 2 * SCREEN_WIDTH
+ call AddNTimes
+ ld [hl], "▶"
+
+.asm_fdde1
+ ld a, [wce66]
+ hlcoord 0, 2
+ ld bc, 5
+ call AddNTimes
+ ld [hl], "▶"
+ ld b, $78
+ ld hl, wVirtualOAM
+ ld de, wc508 + 10
+ call .PlaceSprites
+ ld de, wc508 + 11
+ call .PlaceSprites
+ ld de, wc508 + 12
+ call .PlaceSprites
+ ret
+
+.PlaceSprites:
+ ld a, b
+ ld [hli], a ; y
+ ld a, [de]
+ add a
+ add a
+ add 3 * TILE_WIDTH
+ ld [hli], a ; x
+ ld a, 16 * TILE_WIDTH
+ ld [hli], a ; tile id
+ ld a, 5
+ ld [hli], a ; attributes
+ ld a, 2 * TILE_WIDTH
+ add b
+ ld b, a
+ inc c
+ ret
+
+; unused
+ call ClearSprites
+ ret
+
+; unused
+ ret
diff --git a/engine/debug/debug_room.asm b/engine/debug/debug_room.asm
new file mode 100644
index 00000000..12259ce9
--- /dev/null
+++ b/engine/debug/debug_room.asm
@@ -0,0 +1,1391 @@
+ ; _DebugRoom.MenuItems indexes
+ const_def
+ const DEBUGROOMMENU_PAGE_1 ; 0
+ const DEBUGROOMMENU_PAGE_2 ; 1
+DEBUGROOMMENU_NUM_PAGES EQU const_value
+
+ ; _DebugRoom.Strings and _DebugRoom.Jumptable indexes
+ const_def
+ const DEBUGROOMMENUITEM_SP_CLEAR ; 0
+ const DEBUGROOMMENUITEM_WIN_WORK_CLR ; 1
+ const DEBUGROOMMENUITEM_POKEMON_GET ; 2
+ const DEBUGROOMMENUITEM_POKEDEX_COMP ; 3
+ const DEBUGROOMMENUITEM_TIMER_RESET ; 4
+ const DEBUGROOMMENUITEM_DECORATE_ALL ; 5
+ const DEBUGROOMMENUITEM_ITEM_GET ; 6
+ const DEBUGROOMMENUITEM_RTC_EDIT ; 7
+ const DEBUGROOMMENUITEM_NEXT ; 8
+ const DEBUGROOMMENUITEM_GB_ID_SET ; 9
+ const DEBUGROOMMENUITEM_BTL_REC_CLR ; a
+ const DEBUGROOMMENUITEM_POKEDEX_CLR ; b
+ const DEBUGROOMMENUITEM_HALT_CHK_CLR ; c
+
+_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
+ 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@"
+
+.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
+
+.MenuItems:
+; entries correspond to DEBUGROOMMENU_* constants
+
+ ; DEBUGROOMMENU_PAGE_1
+ db 8
+ db DEBUGROOMMENUITEM_SP_CLEAR
+ db DEBUGROOMMENUITEM_WIN_WORK_CLR
+ 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 6
+ db DEBUGROOMMENUITEM_POKEMON_GET
+ db DEBUGROOMMENUITEM_ITEM_GET
+ db DEBUGROOMMENUITEM_POKEDEX_COMP
+ db DEBUGROOMMENUITEM_POKEDEX_CLR
+ db DEBUGROOMMENUITEM_DECORATE_ALL
+ 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, 13
+ ld de, sStackTop + 1
+ ld c, 1
+ call PrintHexNumber
+ ld de, sStackTop + 0
+ ld c, 1
+ call PrintHexNumber
+ call CloseSRAM
+ hlcoord 16, 11
+ 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, 12
+ 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(sWindowStackBottom)
+ ld a, h
+ sbc HIGH(sWindowStackBottom)
+ ret c
+ ld a, BANK(sWindowStackBottom)
+ call OpenSRAM
+ ld bc, -sWindowStackBottom + $10000
+ add hl, bc
+ ld b, h
+ ld c, l
+ ld hl, sWindowStackBottom
+ xor a
+ call ByteFill
+ call CloseSRAM
+ ret
+
+DebugRoom_PrintWindowStackBottomTop:
+ ld a, BANK(sWindowStackBottom)
+ call OpenSRAM
+ ld hl, sWindowStackBottom
+.loop
+ ld a, h
+ cp HIGH(sWindowStackTop) + 1
+ 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(sWindowStackBottom)
+ ld e, HIGH(sWindowStackBottom)
+ 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(sPlayerData3)
+ call OpenSRAM
+ ld hl, sPlayerData3 + (wPokedexCaught - wPlayerData3)
+ 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 [sPlayerData3 + (wEndPokedexCaught - 1 - wPlayerData3)], a
+ ld [sPlayerData3 + (wEndPokedexSeen - 1 - wPlayerData3)], a
+ ld hl, sPlayerData3 + (wStatusFlags - wPlayerData3)
+ 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(sPlayerData3)
+ call OpenSRAM
+ ld hl, sPlayerData3 + (wStatusFlags - wPlayerData3)
+ res STATUSFLAGS_UNOWN_DEX_F, [hl]
+ ld hl, sPlayerData3 + (wPokedexCaught - wPlayerData3)
+ 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_DecorateAll:
+ call YesNoBox
+ ret c
+ ld a, BANK(sPlayerData3)
+ call OpenSRAM
+ ld hl, sPlayerData3 + (wEventFlags - wPlayerData3)
+ 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(sPlayerData3)
+ call OpenSRAM
+ ld hl, sPlayerData3 + (wPCItems - wPlayerData3)
+ 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, [sPlayerData3 + (wNumPCItems - wPlayerData3)]
+ cp MAX_PC_ITEMS
+ jr nc, .full
+ inc a
+ ld [sPlayerData3 + (wNumPCItems - wPlayerData3)], 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 wDebugRoomMonUnused1, $00, $ff, $00, DebugRoom_BoxStructStrings.NoUse0, NULL, FALSE
+ paged_value wDebugRoomMonUnused2, $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, 8
+ 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, 9
+ 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