MainDebugOptions:
	ld hl, .menu_data_header
	call LoadMenuDataHeader
	call VerticalMenu
	call CloseWindow
	ret c
	ld a, [wMenuCursorY]
	dec a
	jp z, ResetClock
	dec a
	jp z, DeleteSaveData
	dec a
	jp z, FixBuildNumber
	ret

.menu_data_header
	db $40 ;flags
	db 0, 0 ;initial y, x
	db 9, 19 ;final y, x
	dw .options
	db 4 ;default option
.options
	db $a0 ;flags
	db 4 ;option count
	db "Reset clock@"
	db "Erase saved data@"
	db "Fix build number@"
	db "Back@"

DeleteSaveData:
	ld hl, TextBoxFlags
	ld a, [hl]
	push af
	ld [hl], %10
	ld hl, DeleteSaveDataWarning1Text
	call MainDebugOptions_PlaceMessage
	call DeleteSaveData_ButtonSound
	ld de, DeleteSaveDataWarning2Text
	coord hl, 2, 7
	call PlaceText
	pop af
	ld [TextBoxFlags], a
	ld c, 20
	call DelayFrames
	call MainDebugOptions_DisplayButtonsAndWait
	ret nc
	callba EmptyAllSRAMBanks
	jr MainDebugOptions_DisplayDoneAndReboot

ResetClock:
	ld hl, ResetClockWarningText
	call MainDebugOptions_PlaceMessage_ClearBGMapMode
	call MainDebugOptions_DisplayButtonsAndWait
	ret nc
	sbk BANK(sRTCStatusFlags)
	ld hl, sRTCStatusFlags
	set 7, [hl]
	jr MainDebugOptions_DisplayDoneAndReboot

FixBuildNumber:
	ld hl, FixBuildNumberWarningText
	call MainDebugOptions_PlaceMessage_ClearBGMapMode
	call MainDebugOptions_DisplayButtonsAndWait
	ret nc
	sbk BANK(sBuildNumber)
	ld hl, sBuildNumber
	ld [hl], BUILD_NUMBER & $ff
	inc hl
	ld [hl], BUILD_NUMBER >> 8

; fallthrough
MainDebugOptions_DisplayDoneAndReboot:
	scls
	hlcoord 0, 15
	ld bc, 2 * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	ld de, DebugOptionsDoneText
	hlcoord 7, 16
	call PlaceText
	ld de, SFX_TRANSACTION
	call PlayWaitSFX
	ld c, 40
	call DelayFrames
	jp Init

MainDebugOptions_PlaceMessage_ClearBGMapMode:
	xor a
	ld [hBGMapMode], a

; fallthrough
MainDebugOptions_PlaceMessage:
	push hl
	call ClearTileMapNoDelay
	call Delay2
	hlcoord 1, 1
	pop de
	jp PlaceText

MainDebugOptions_DisplayButtonsAndWait:
	; returns carry if confirmed, or nc if nope
	ld de, DebugOptionsButtonChoicesString
	hlcoord 2, 15
	call PlaceText
	call ApplyTilemap
.loop
	call DelayFrame
	call GetJoypad
	ld a, [hJoyDown]
	bit B_BUTTON_F, a
	ret nz
	and A_BUTTON | SELECT
	cp A_BUTTON | SELECT
	jr nz, .loop
	scf
	ret

DeleteSaveData_ButtonSound:
	call DelayFrame
	call .DeleteSaveData_BlinkCursor
	call CheckIfAOrBPressed
	jr z, DeleteSaveData_ButtonSound
	ld de, SFX_READ_TEXT_2
	call PlaySFX
	jr .clearCursor

.DeleteSaveData_BlinkCursor:
	ld a, [hVBlankCounter]
	bit 4, a
	ld a, "▼"
	jr nz, .cursorOn
.clearCursor
	ld a, " "
.cursorOn
	ldcoord_a 18, 06
	ret

ResetClockWarningText:
	db TX_COMPRESSED, $85, $24, $68, $95, $0f, $bd, $8b, $34, $1d
	db $89, $ac, $0e, $d2, $71, $9e, $85, $95, $2c, $51, $96, $96, $b3, $25
	db $89, $ac, $0e, $44, $1d, $d8, $c9, $ca, $3f, $34, $99
	db $13, $58, $18, $85, $85, $f1, $17, $01, $05, $a9, $61, $88, $3b
	db $13, $58, $18, $ee, $6f, $3a, $32, $4a, $92, $64, $80, $82
	db $d0, $9a, $c0, $e4, $48, $ee, $36, $84, $96, $32, $34, $7e
	db $13, $58
	db $18, $9a, $c0, $e4, $ad, $67, $01, $05, $a8, $86, $96, $74
	db $b4, $d0

DeleteSaveDataWarning1Text:
	db TX_COMPRESSED, $72, $85, $a5, $c6, $5a, $5a, $cc, $97, $11, $a0, $c7
	db $91, $35, $81, $c9, $33, $b7, $b2, $a1, $f7, $b1, $59
	db $89, $ac, $0e, $64, $fa, $76, $79, $98, $05, $66, $0c, $6b
	db $f0, $9a, $c0, $ca, $62, $e9, $44, $ad, $b4, $a7, $4e, $c1, $f1, $b6, $b0, $78, $3d, $d9
	db $42, $6b, $03, $92, $41, $21, $74, $73, $83, $f8, $1d, $83, $c5, $de
	db $a6, $80

DeleteSaveDataWarning2Text:
	db TX_COMPRESSED, $ad, $67, $01, $05, $a8, $86, $96, $70, $10, $5a
	db $13, $58, $1d, $43, $42, $65, $86, $32, $12, $58, $c8, $d1, $d2
	db $d3, $40

FixBuildNumberWarningText:
	text_jump _FixBuildNumberWarningText

DebugOptionsButtonChoicesString:
	db TX_COMPRESSED, $ac, $4d, $67, $0a, $05, $d8, $e2, $e6, $d2, $9c, $63, $21, $26, $03, $5b
	db $e2, $6b, $03, $82, $4e, $31, $5e, $b2, $a5, $2c, $31, $f3, $23
	db $54, $d0

DebugOptionsDoneText:
	text "Done!"
	done
