pokecrystal/home/menu.asm

595 lines
8.1 KiB
NASM
Raw Normal View History

; Functions used in displaying and handling menus.
2015-10-24 14:34:19 +00:00
LoadMenuDataHeader::
call CopyMenuDataHeader
2015-10-24 14:34:19 +00:00
call BackUpTiles
ret
2015-10-24 14:34:19 +00:00
CopyMenuDataHeader::
ld de, wMenuDataHeader
ld bc, wMenuDataHeaderEnd - wMenuDataHeader
call CopyBytes
ld a, [hROMBank]
ld [wMenuDataBank], a
ret
; 0x1d4b
2015-12-16 17:32:08 +00:00
StoreTo_wMenuCursorBuffer:: ; 1d4b
2015-11-01 17:44:30 +00:00
ld [wMenuCursorBuffer], a
ret
; 1d4f
MenuTextBox:: ; 1d4f
push hl
call LoadMenuTextBox
pop hl
jp PrintText
; 1d57
2015-12-13 19:15:16 +00:00
ret_1d57:: ; 1d57
; unreferenced
ret
; 1d58
LoadMenuTextBox:: ; 1d58
2015-12-18 03:31:16 +00:00
ld hl, .MenuDataHeader
call LoadMenuDataHeader
ret
; 1d5f
2015-12-18 03:31:16 +00:00
.MenuDataHeader ; 1d5f
db $40 ; tile backup
db 12, 0 ; start coords
db 17, 19 ; end coords
dw VTiles0
db 0 ; default option
; 1d67
MenuTextBoxBackup:: ; 1d67
call MenuTextBox
call WriteBackup
ret
; 1d6e
2015-11-11 21:11:08 +00:00
LoadStandardMenuDataHeader:: ; 1d6e
2015-12-18 03:31:16 +00:00
ld hl, .MenuDataHeader
call LoadMenuDataHeader
ret
; 1d75
2015-12-18 03:31:16 +00:00
.MenuDataHeader ; 1d75
db $40 ; tile backup
db 0, 0 ; start coords
db 17, 19 ; end coords
2015-11-02 19:37:02 +00:00
dw 0
db 1 ; default option
; 1d7d
2015-09-09 23:27:07 +00:00
Call_ExitMenu:: ; 1d7d
call ExitMenu
ret
; 1d81
2015-12-15 23:59:49 +00:00
VerticalMenu::
xor a
ld [hBGMapMode], a
2015-11-04 19:02:11 +00:00
call MenuBox
call UpdateSprites
2015-12-15 23:59:49 +00:00
call PlaceVerticalMenuItems
2015-11-25 15:16:29 +00:00
call ApplyTilemap
call CopyMenuData2
2015-11-04 19:02:11 +00:00
ld a, [wMenuData2Flags]
bit 7, a
2015-10-24 14:34:19 +00:00
jr z, .cancel
2015-12-15 23:59:49 +00:00
call InitVerticalMenuCursor
call StaticMenuJoypad
call MenuClickSound
bit 1, a
2015-10-24 14:34:19 +00:00
jr z, .okay
2015-10-16 17:35:43 +00:00
.cancel
scf
ret
2015-12-15 23:59:49 +00:00
2015-10-16 17:35:43 +00:00
.okay
and a
ret
; 0x1dab
GetMenu2:: ; 1dab
call LoadMenuDataHeader
2015-12-15 23:59:49 +00:00
call VerticalMenu
call WriteBackup
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
ret
; 1db8
CopyNameFromMenu::
push hl
push bc
push af
ld hl, wMenuData2Pointer
ld a, [hli]
ld h, [hl]
ld l, a
2015-07-21 02:18:18 +00:00
rept 2
inc hl
2015-07-21 02:18:18 +00:00
endr
pop af
call GetNthString
ld d, h
ld e, l
call CopyName1
pop bc
pop hl
ret
; 0x1dcf
YesNoBox:: ; 1dcf
lb bc, SCREEN_WIDTH - 6, 7
PlaceYesNoBox:: ; 1dd2
2013-12-04 07:49:12 +00:00
jr _YesNoBox
2015-10-17 21:18:52 +00:00
PlaceGenericTwoOptionBox:: ; 1dd4
call LoadMenuDataHeader
2015-10-17 21:18:52 +00:00
jr InterpretTwoOptionMenu
_YesNoBox:: ; 1dd9
2013-12-04 07:49:12 +00:00
; Return nc (yes) or c (no).
push bc
2013-12-04 07:49:12 +00:00
ld hl, YesNoMenuDataHeader
call CopyMenuDataHeader
pop bc
2015-10-17 21:18:52 +00:00
; This seems to be an overflow prevention, but
; it was coded wrong.
ld a, b
2015-10-17 21:18:52 +00:00
cp SCREEN_WIDTH - 6
jr nz, .okay ; should this be "jr nc"?
ld a, SCREEN_WIDTH - 6
ld b, a
2015-10-17 21:18:52 +00:00
.okay
ld a, b
2015-10-24 14:34:19 +00:00
ld [wMenuBorderLeftCoord], a
add 5
2015-10-24 14:34:19 +00:00
ld [wMenuBorderRightCoord], a
ld a, c
2015-10-24 14:34:19 +00:00
ld [wMenuBorderTopCoord], a
add 4
2015-10-24 14:34:19 +00:00
ld [wMenuBorderBottomCoord], a
call BackUpTiles
2015-10-17 21:18:52 +00:00
InterpretTwoOptionMenu:: ; 1dfe
2015-12-15 23:59:49 +00:00
call VerticalMenu
push af
ld c, $f
call DelayFrames
call WriteBackup
pop af
2015-10-16 17:35:43 +00:00
jr c, .no
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
2013-12-04 07:49:12 +00:00
cp 2 ; no
2015-10-16 17:35:43 +00:00
jr z, .no
and a
ret
2015-10-16 17:35:43 +00:00
.no
ld a, 2
2015-12-15 23:59:49 +00:00
ld [wMenuCursorY], a
scf
ret
; 1e1d
YesNoMenuDataHeader:: ; 1e1d
db $40 ; tile backup
db 5, 10 ; start coords
db 9, 15 ; end coords
2015-12-18 03:31:16 +00:00
dw .MenuData2
db 1 ; default option
; 1e25
2015-12-18 03:31:16 +00:00
.MenuData2 ; 1e25
db $c0 ; flags
db 2
db "YES@"
db "NO@"
; 1e2e
2015-12-18 03:31:16 +00:00
OffsetMenuDataHeader:: ; 1e2e
call _OffsetMenuDataHeader
2015-10-24 14:34:19 +00:00
call BackUpTiles
ret
; 1e35
2015-12-18 03:31:16 +00:00
_OffsetMenuDataHeader:: ; 1e35
push de
call CopyMenuDataHeader
pop de
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderLeftCoord]
ld h, a
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderRightCoord]
sub h
ld h, a
ld a, d
2015-10-24 14:34:19 +00:00
ld [wMenuBorderLeftCoord], a
add h
2015-10-24 14:34:19 +00:00
ld [wMenuBorderRightCoord], a
ld a, [wMenuBorderTopCoord]
ld l, a
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderBottomCoord]
sub l
ld l, a
ld a, e
2015-10-24 14:34:19 +00:00
ld [wMenuBorderTopCoord], a
add l
2015-10-24 14:34:19 +00:00
ld [wMenuBorderBottomCoord], a
ret
; 1e5d
2015-11-17 02:46:36 +00:00
DoNthMenu:: ; 1e5d
call MenuFunc_1e7f
call MenuWriteText
call Function1eff
call Function1f23
2015-12-15 23:59:49 +00:00
call GetMenuJoypad
call MenuClickSound
ret
; 1e70
SetUpMenu:: ; 1e70
call MenuFunc_1e7f ; ???
call MenuWriteText
call Function1eff ; set up selection pointer
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags1
set 7, [hl]
ret
2015-10-24 14:34:19 +00:00
MenuFunc_1e7f::
call CopyMenuData2
2015-12-19 01:07:09 +00:00
call GetMenuIndexSet
call Function1ea6
2015-11-04 19:02:11 +00:00
call MenuBox
ret
2015-10-24 14:34:19 +00:00
MenuWriteText::
xor a
ld [hBGMapMode], a
2015-12-19 01:07:09 +00:00
call GetMenuIndexSet ; sort out the text
call Function1eda ; actually write it
call Function2e31
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
2015-11-25 15:16:29 +00:00
call ApplyTilemap
pop af
ld [hOAMUpdate], a
ret
; 0x1ea6
Function1ea6:: ; 1ea6
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderLeftCoord]
ld c, a
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderRightCoord]
sub c
ld c, a
2015-11-04 19:02:11 +00:00
ld a, [wMenuData2Items]
add a
inc a
ld b, a
2015-10-24 14:34:19 +00:00
ld a, [wMenuBorderTopCoord]
add b
2015-10-24 14:34:19 +00:00
ld [wMenuBorderBottomCoord], a
ret
; 1ebd
2015-12-19 01:07:09 +00:00
GetMenuIndexSet:: ; 1ebd
2015-12-18 03:31:16 +00:00
ld hl, wMenuData2IndicesPointer
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-19 01:07:09 +00:00
ld a, [wWhichIndexSet]
and a
2015-12-18 03:31:16 +00:00
jr z, .skip
ld b, a
2015-12-18 03:31:16 +00:00
ld c, -1
.loop
ld a, [hli]
cp c
2015-12-18 03:31:16 +00:00
jr nz, .loop
dec b
2015-12-18 03:31:16 +00:00
jr nz, .loop
2015-12-18 03:31:16 +00:00
.skip
ld d, h
ld e, l
ld a, [hl]
2015-11-04 19:02:11 +00:00
ld [wMenuData2Items], a
ret
; 1eda
Function1eda:: ; 1eda
call MenuBoxCoord2Tile
2015-12-18 03:31:16 +00:00
ld bc, 2 * SCREEN_WIDTH + 2
add hl, bc
2015-12-18 03:31:16 +00:00
.loop
inc de
ld a, [de]
2015-12-18 03:31:16 +00:00
cp -1
ret z
ld [MenuSelection], a
push de
push hl
ld d, h
ld e, l
2015-12-18 03:31:16 +00:00
ld hl, wMenuData2DisplayFunctionPointer
call .__wMenuData2DisplayFunction__
pop hl
2015-12-18 03:31:16 +00:00
ld de, 2 * SCREEN_WIDTH
add hl, de
pop de
2015-12-18 03:31:16 +00:00
jr .loop
; 1efb
2015-12-18 03:31:16 +00:00
.__wMenuData2DisplayFunction__ ; 1efb
ld a, [hli]
ld h, [hl]
ld l, a
jp [hl]
; 1eff
Function1eff:: ; 1eff
2015-12-15 23:59:49 +00:00
call InitVerticalMenuCursor
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags4
2015-11-04 19:02:11 +00:00
ld a, [wMenuData2Flags]
bit 3, a
2015-12-18 03:31:16 +00:00
jr z, .skip3
set 3, [hl]
2015-12-18 03:31:16 +00:00
.skip3
2015-11-04 19:02:11 +00:00
ld a, [wMenuData2Flags]
bit 2, a
2015-12-18 03:31:16 +00:00
jr z, .skip4_5
set 5, [hl]
set 4, [hl]
2015-12-18 03:31:16 +00:00
.skip4_5
ret
; 1f1a
Function1f1a:: ; 1f1a
2015-12-15 23:59:49 +00:00
call ScrollingMenuJoypad
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags4
and [hl]
jr Function1f2a
; 1f23
Function1f23:: ; 1f23
xor a
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
call StaticMenuJoypad
; 1f2a
Function1f2a:: ; 1f2a
bit 0, a
jr nz, .asm_1f52
bit 1, a
jr nz, .asm_1f6d
bit 3, a
jr nz, .asm_1f6d
bit 4, a
jr nz, .asm_1f44
bit 5, a
jr nz, .asm_1f4b
xor a
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .asm_1f57
.asm_1f44
ld a, $10
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .asm_1f57
.asm_1f4b
ld a, $20
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .asm_1f57
.asm_1f52
ld a, $1
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
.asm_1f57
2015-12-19 01:07:09 +00:00
call GetMenuIndexSet
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
ld l, a
ld h, $0
add hl, de
ld a, [hl]
ld [MenuSelection], a
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
2015-11-01 17:44:30 +00:00
ld [wMenuCursorBuffer], a
and a
ret
.asm_1f6d
ld a, $2
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
ld a, $ff
ld [MenuSelection], a
scf
ret
; 1f79
2015-12-13 19:15:16 +00:00
PlaceMenuStrings:: ; 1f79
push de
2015-12-13 19:15:16 +00:00
ld hl, wMenuData2PointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [MenuSelection]
call GetNthString
ld d, h
ld e, l
pop hl
call PlaceString
ret
; 1f8d
2015-11-17 02:46:36 +00:00
PlaceNthMenuStrings:: ; 1f8d
push de
ld a, [MenuSelection]
2015-12-13 19:15:16 +00:00
call GetMenuDataPointerTableEntry
2015-07-21 02:18:18 +00:00
rept 2
inc hl
2015-07-21 02:18:18 +00:00
endr
ld a, [hli]
ld d, [hl]
ld e, a
pop hl
call PlaceString
ret
; 1f9e
Function1f9e:: ; 1f9e
2015-12-13 19:15:16 +00:00
; unreferenced
call GetMenuDataPointerTableEntry
2015-07-21 02:18:18 +00:00
rept 2
inc hl
2015-07-21 02:18:18 +00:00
endr
ld a, [hli]
ld d, [hl]
ld e, a
ret
; 1fa7
2015-11-17 02:46:36 +00:00
MenuJumptable:: ; 1fa7
ld a, [MenuSelection]
2015-12-13 19:15:16 +00:00
call GetMenuDataPointerTableEntry
ld a, [hli]
ld h, [hl]
ld l, a
jp [hl]
; 1fb1
2015-12-13 19:15:16 +00:00
GetMenuDataPointerTableEntry:: ; 1fb1
ld e, a
ld d, $0
2015-12-13 19:15:16 +00:00
ld hl, wMenuData2PointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
2015-07-21 02:18:18 +00:00
rept 4
add hl, de
2015-07-21 02:18:18 +00:00
endr
ret
; 1fbf
ResetTextRelatedRAM:: ; 1fbf
2015-12-15 23:59:49 +00:00
ld hl, wWindowStackPointer
call .bytefill
ld hl, wMenuDataHeader
call .bytefill
2015-11-04 19:02:11 +00:00
ld hl, wMenuData2Flags
call .bytefill
2015-02-10 23:14:41 +00:00
ld hl, wcfa1
call .bytefill
ld a, [rSVBK]
push af
ld a, $7
ld [rSVBK], a
xor a
2015-12-15 23:59:49 +00:00
ld hl, wWindowStackBottom
2015-07-21 02:18:18 +00:00
rept 2
ld [hld], a
2015-07-21 02:18:18 +00:00
endr
ld a, l
2015-12-15 23:59:49 +00:00
ld [wWindowStackPointer], a
ld a, h
2015-12-15 23:59:49 +00:00
ld [wWindowStackPointer + 1], a
pop af
ld [rSVBK], a
ret
; 1ff0
.bytefill: ; 1ff0
ld bc, $0010
xor a
call ByteFill
ret
; 1ff8
2015-12-15 23:59:49 +00:00
MenuClickSound:: ; 1ff8
push af
2015-12-15 23:59:49 +00:00
and A_BUTTON | B_BUTTON
2015-10-16 17:35:43 +00:00
jr z, .nosound
ld hl, wMenuFlags
bit 3, [hl]
2015-10-16 17:35:43 +00:00
jr nz, .nosound
call PlayClickSFX
2015-10-16 17:35:43 +00:00
.nosound
pop af
ret
; 2009
PlayClickSFX:: ; 2009
push de
ld de, SFX_READ_TEXT_2
2013-10-08 17:10:36 +00:00
call PlaySFX
pop de
ret
; 0x2012
MenuTextBoxWaitButton:: ; 2012
call MenuTextBox
2015-11-25 15:16:29 +00:00
call WaitButton
call ExitMenu
ret
; 201c
2015-12-15 23:59:49 +00:00
Place2DMenuItemName:: ; 201c
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call PlaceString
pop af
rst Bankswitch
ret
; 202a
2015-12-15 23:59:49 +00:00
_2DMenu:: ; 202a
ld a, [hROMBank]
2015-12-15 23:59:49 +00:00
ld [wMenuData2_2DMenuItemStringsBank], a
callba _2DMenu_
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret
; 2039
2015-12-15 23:59:49 +00:00
InterpretBattleMenu:: ; 2039
ld a, [hROMBank]
2015-12-15 23:59:49 +00:00
ld [wMenuData2_2DMenuItemStringsBank], a
callba _InterpretBattleMenu
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret
; 2048
2015-12-15 23:59:49 +00:00
InterpretMobileMenu:: ; 2048
ld a, [hROMBank]
2015-12-15 23:59:49 +00:00
ld [wMenuData2_2DMenuItemStringsBank], a
callba _InterpretMobileMenu
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret
; 2057