pokecrystal/home/menu.asm

540 lines
7.7 KiB
NASM
Raw Normal View History

; Functions used in displaying and handling menus.
LoadMenuHeader::
call CopyMenuHeader
2015-12-23 03:19:33 +00:00
call PushWindow
ret
CopyMenuHeader::
ld de, wMenuHeader
ld bc, wMenuHeaderEnd - wMenuHeader
call CopyBytes
ld a, [hROMBank]
ld [wMenuDataBank], a
ret
2018-06-24 14:09:41 +00:00
StoreTo_wMenuCursorBuffer::
2015-11-01 17:44:30 +00:00
ld [wMenuCursorBuffer], a
ret
2018-06-24 14:09:41 +00:00
MenuTextBox::
push hl
call LoadMenuTextBox
pop hl
jp PrintText
2018-01-02 15:04:21 +00:00
; unused
ret
2018-06-24 14:09:41 +00:00
LoadMenuTextBox::
ld hl, .MenuHeader
call LoadMenuHeader
ret
2018-06-24 14:09:41 +00:00
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 12, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
2017-12-28 12:32:33 +00:00
dw vTiles0
db 0 ; default option
2018-06-24 14:09:41 +00:00
MenuTextBoxBackup::
call MenuTextBox
call CloseWindow
ret
2018-06-24 14:09:41 +00:00
LoadStandardMenuHeader::
ld hl, .MenuHeader
call LoadMenuHeader
ret
2018-06-24 14:09:41 +00:00
.MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1
2015-11-02 19:37:02 +00:00
dw 0
db 1 ; default option
2018-06-24 14:09:41 +00:00
Call_ExitMenu::
call ExitMenu
ret
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 CopyMenuData
ld a, [wMenuDataFlags]
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
2018-06-24 14:09:41 +00:00
GetMenu2::
call LoadMenuHeader
2015-12-15 23:59:49 +00:00
call VerticalMenu
call CloseWindow
2015-12-15 23:59:49 +00:00
ld a, [wMenuCursorY]
ret
CopyNameFromMenu::
push hl
push bc
push af
ld hl, wMenuDataPointer
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
2016-01-05 13:46:37 +00:00
inc hl
pop af
call GetNthString
ld d, h
ld e, l
call CopyName1
pop bc
pop hl
ret
2018-06-24 14:09:41 +00:00
YesNoBox::
lb bc, SCREEN_WIDTH - 6, 7
2018-06-24 14:09:41 +00:00
PlaceYesNoBox::
2013-12-04 07:49:12 +00:00
jr _YesNoBox
2018-06-24 14:09:41 +00:00
PlaceGenericTwoOptionBox::
call LoadMenuHeader
2015-10-17 21:18:52 +00:00
jr InterpretTwoOptionMenu
2018-06-24 14:09:41 +00:00
_YesNoBox::
2013-12-04 07:49:12 +00:00
; Return nc (yes) or c (no).
push bc
ld hl, YesNoMenuHeader
call CopyMenuHeader
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
2015-12-23 03:19:33 +00:00
call PushWindow
2018-06-24 14:09:41 +00:00
InterpretTwoOptionMenu::
2015-12-15 23:59:49 +00:00
call VerticalMenu
push af
ld c, $f
call DelayFrames
call CloseWindow
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
2018-06-24 14:09:41 +00:00
YesNoMenuHeader::
db MENU_BACKUP_TILES ; flags
menu_coords 10, 5, 15, 9
dw .MenuData
db 1 ; default option
2018-06-24 14:09:41 +00:00
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 2
db "YES@"
db "NO@"
2018-06-24 14:09:41 +00:00
OffsetMenuHeader::
call _OffsetMenuHeader
2015-12-23 03:19:33 +00:00
call PushWindow
ret
2018-06-24 14:09:41 +00:00
_OffsetMenuHeader::
push de
call CopyMenuHeader
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
2018-06-24 14:09:41 +00:00
DoNthMenu::
call DrawVariableLengthMenuBox
call MenuWriteText
call InitMenuCursorAndButtonPermissions
2016-03-02 03:31:21 +00:00
call GetStaticMenuJoypad
2015-12-15 23:59:49 +00:00
call GetMenuJoypad
call MenuClickSound
ret
2018-06-24 14:09:41 +00:00
SetUpMenu::
call DrawVariableLengthMenuBox ; ???
call MenuWriteText
call InitMenuCursorAndButtonPermissions ; set up selection pointer
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags1
set 7, [hl]
ret
DrawVariableLengthMenuBox::
call CopyMenuData
2015-12-19 01:07:09 +00:00
call GetMenuIndexSet
call AutomaticGetMenuBottomCoord
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 RunMenuItemPrintingFunction ; actually write it
call SafeUpdateSprites
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
2018-06-24 14:09:41 +00:00
AutomaticGetMenuBottomCoord::
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
ld a, [wMenuDataItems]
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
2018-06-24 14:09:41 +00:00
GetMenuIndexSet::
ld hl, wMenuDataIndicesPointer
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]
ld [wMenuDataItems], a
ret
2018-06-24 14:09:41 +00:00
RunMenuItemPrintingFunction::
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
2018-01-23 22:39:09 +00:00
ld [wMenuSelection], a
push de
push hl
ld d, h
ld e, l
ld hl, wMenuDataDisplayFunctionPointer
call ._hl_
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
2018-06-24 14:09:41 +00:00
._hl_
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2018-06-24 14:09:41 +00:00
InitMenuCursorAndButtonPermissions::
2015-12-15 23:59:49 +00:00
call InitVerticalMenuCursor
ld hl, wMenuJoypadFilter
ld a, [wMenuDataFlags]
bit 3, a
jr z, .disallow_select
set START_F, [hl]
.disallow_select
ld a, [wMenuDataFlags]
bit 2, a
jr z, .disallow_left_right
set D_LEFT_F, [hl]
set D_RIGHT_F, [hl]
.disallow_left_right
ret
2018-06-24 14:09:41 +00:00
GetScrollingMenuJoypad::
2015-12-15 23:59:49 +00:00
call ScrollingMenuJoypad
ld hl, wMenuJoypadFilter
and [hl]
2016-03-02 03:31:21 +00:00
jr ContinueGettingMenuJoypad
2018-06-24 14:09:41 +00:00
GetStaticMenuJoypad::
xor a
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
call StaticMenuJoypad
2016-03-02 03:31:21 +00:00
ContinueGettingMenuJoypad:
bit A_BUTTON_F, a
jr nz, .a_button
bit B_BUTTON_F, a
jr nz, .b_start
bit START_F, a
jr nz, .b_start
bit D_RIGHT_F, a
jr nz, .d_right
bit D_LEFT_F, a
jr nz, .d_left
xor a
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .done
.d_right
ld a, D_RIGHT
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .done
.d_left
ld a, D_LEFT
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
jr .done
.a_button
ld a, A_BUTTON
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
.done
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]
2018-01-23 22:39:09 +00:00
ld [wMenuSelection], 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
.b_start
ld a, B_BUTTON
2015-12-15 23:59:49 +00:00
ld [wMenuJoypad], a
ld a, -1
2018-01-23 22:39:09 +00:00
ld [wMenuSelection], a
scf
ret
2018-06-24 14:09:41 +00:00
PlaceMenuStrings::
push de
ld hl, wMenuDataPointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
call GetNthString
ld d, h
ld e, l
pop hl
call PlaceString
ret
2018-06-24 14:09:41 +00:00
PlaceNthMenuStrings::
push de
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-12-13 19:15:16 +00:00
call GetMenuDataPointerTableEntry
inc hl
2016-01-05 13:46:37 +00:00
inc hl
ld a, [hli]
ld d, [hl]
ld e, a
pop hl
call PlaceString
ret
2018-06-24 14:09:41 +00:00
Unreferenced_Function1f9e::
2015-12-13 19:15:16 +00:00
call GetMenuDataPointerTableEntry
inc hl
2016-01-05 13:46:37 +00:00
inc hl
ld a, [hli]
ld d, [hl]
ld e, a
ret
2018-06-24 14:09:41 +00:00
MenuJumptable::
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-12-13 19:15:16 +00:00
call GetMenuDataPointerTableEntry
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2018-06-24 14:09:41 +00:00
GetMenuDataPointerTableEntry::
ld e, a
ld d, $0
ld hl, wMenuDataPointerTableAddr
ld a, [hli]
ld h, [hl]
ld l, a
add hl, de
2016-01-05 13:46:37 +00:00
add hl, de
add hl, de
add hl, de
ret
2018-06-24 14:09:41 +00:00
ClearWindowData::
2015-12-15 23:59:49 +00:00
ld hl, wWindowStackPointer
call .bytefill
ld hl, wMenuHeader
call .bytefill
ld hl, wMenuDataFlags
call .bytefill
ld hl, w2DMenuCursorInitY
call .bytefill
ld a, [rSVBK]
push af
ld a, BANK(wWindowStack)
ld [rSVBK], a
xor a
2015-12-15 23:59:49 +00:00
ld hl, wWindowStackBottom
ld [hld], a
2016-01-05 13:46:37 +00:00
ld [hld], a
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
2018-06-24 14:09:41 +00:00
.bytefill
2018-01-09 20:39:48 +00:00
ld bc, $10
xor a
call ByteFill
ret
2018-06-24 14:09:41 +00:00
MenuClickSound::
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
2018-06-24 14:09:41 +00:00
PlayClickSFX::
push de
ld de, SFX_READ_TEXT_2
2013-10-08 17:10:36 +00:00
call PlaySFX
pop de
ret
2018-06-24 14:09:41 +00:00
MenuTextBoxWaitButton::
call MenuTextBox
2015-11-25 15:16:29 +00:00
call WaitButton
call ExitMenu
ret
2018-06-24 14:09:41 +00:00
Place2DMenuItemName::
ld [hBuffer], a
ld a, [hROMBank]
push af
ld a, [hBuffer]
rst Bankswitch
call PlaceString
pop af
rst Bankswitch
ret
2018-06-24 14:09:41 +00:00
_2DMenu::
ld a, [hROMBank]
ld [wMenuData_2DMenuItemStringsBank], a
2017-12-24 17:47:30 +00:00
farcall _2DMenu_
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret
2018-06-24 14:09:41 +00:00
InterpretBattleMenu::
ld a, [hROMBank]
ld [wMenuData_2DMenuItemStringsBank], a
2017-12-24 17:47:30 +00:00
farcall _InterpretBattleMenu
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret
2018-06-24 14:09:41 +00:00
InterpretMobileMenu::
ld a, [hROMBank]
ld [wMenuData_2DMenuItemStringsBank], a
2017-12-24 17:47:30 +00:00
farcall _InterpretMobileMenu
2015-11-01 17:44:30 +00:00
ld a, [wMenuCursorBuffer]
ret