pokecrystal/engine/menus/scrolling_menu.asm

520 lines
7.9 KiB
NASM
Raw Normal View History

2018-06-24 14:09:41 +00:00
_InitScrollingMenu::
2015-12-18 03:31:16 +00:00
xor a
ld [wMenuJoypad], a
ldh [hBGMapMode], a
2015-12-18 03:31:16 +00:00
inc a
ldh [hInMenu], a
2015-12-18 03:31:16 +00:00
call InitScrollingMenuCursor
call ScrollingMenu_InitFlags
call ScrollingMenu_ValidateSwitchItem
call ScrollingMenu_InitDisplay
call ApplyTilemap
xor a
ldh [hBGMapMode], a
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
_ScrollingMenu::
2015-12-18 03:31:16 +00:00
.loop
call ScrollingMenuJoyAction
jp c, .exit
call z, .zero
jr .loop
2018-06-24 14:09:41 +00:00
.exit
2015-12-18 03:31:16 +00:00
call MenuClickSound
ld [wMenuJoypad], a
ld a, 0
ldh [hInMenu], a
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
.zero
2015-12-18 03:31:16 +00:00
call ScrollingMenu_InitDisplay
ld a, 1
ldh [hBGMapMode], a
2015-12-18 03:31:16 +00:00
ld c, 3
call DelayFrames
xor a
ldh [hBGMapMode], a
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_InitDisplay:
2015-12-18 03:31:16 +00:00
xor a
ldh [hBGMapMode], a
2018-01-23 22:39:09 +00:00
ld hl, wOptions
2015-12-18 03:31:16 +00:00
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
call ScrollingMenu_UpdateDisplay
call ScrollingMenu_PlaceCursor
call ScrollingMenu_CheckCallFunction3
pop af
2018-01-23 22:39:09 +00:00
ld [wOptions], a
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
ScrollingMenuJoyAction:
2015-12-18 03:31:16 +00:00
.loop
call ScrollingMenuJoypad
ldh a, [hJoyLast]
2015-12-18 03:31:16 +00:00
and D_PAD
ld b, a
ldh a, [hJoyPressed]
2015-12-18 03:31:16 +00:00
and BUTTONS
or b
2017-12-30 17:35:50 +00:00
bit A_BUTTON_F, a
2015-12-18 03:31:16 +00:00
jp nz, .a_button
2017-12-30 17:35:50 +00:00
bit B_BUTTON_F, a
2015-12-18 03:31:16 +00:00
jp nz, .b_button
2017-12-30 17:35:50 +00:00
bit SELECT_F, a
2015-12-18 03:31:16 +00:00
jp nz, .select
2017-12-30 17:35:50 +00:00
bit START_F, a
2015-12-18 03:31:16 +00:00
jp nz, .start
2017-12-30 17:35:50 +00:00
bit D_RIGHT_F, a
2015-12-18 03:31:16 +00:00
jp nz, .d_right
2017-12-30 17:35:50 +00:00
bit D_LEFT_F, a
2015-12-18 03:31:16 +00:00
jp nz, .d_left
2017-12-30 17:35:50 +00:00
bit D_UP_F, a
2015-12-18 03:31:16 +00:00
jp nz, .d_up
2017-12-30 17:35:50 +00:00
bit D_DOWN_F, a
2015-12-18 03:31:16 +00:00
jp nz, .d_down
jr .loop
.no_zero_no_carry ; unreferenced
2015-12-18 03:31:16 +00:00
ld a, -1
and a
ret
2018-06-24 14:09:41 +00:00
.a_button
2015-12-18 03:31:16 +00:00
call PlaceHollowCursor
ld a, [wMenuCursorY]
dec a
call ScrollingMenu_GetListItemCoordAndFunctionArgs
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
ld [wCurItem], a
ld a, [wMenuSelectionQuantity]
2015-12-18 03:31:16 +00:00
ld [wItemQuantityBuffer], a
call ScrollingMenu_GetCursorPosition
dec a
ld [wScrollingMenuCursorPosition], a
2018-01-23 22:39:09 +00:00
ld [wCurItemQuantity], a
ld a, [wMenuSelection]
2015-12-18 03:31:16 +00:00
cp -1
jr z, .b_button
ld a, A_BUTTON
scf
ret
2018-06-24 14:09:41 +00:00
.b_button
2015-12-18 03:31:16 +00:00
ld a, B_BUTTON
scf
ret
2018-06-24 14:09:41 +00:00
.select
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 7, a
jp z, xor_a_dec_a
ld a, [wMenuCursorY]
dec a
call ScrollingMenu_GetListItemCoordAndFunctionArgs
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-12-18 03:31:16 +00:00
cp -1
jp z, xor_a_dec_a
call ScrollingMenu_GetCursorPosition
dec a
ld [wScrollingMenuCursorPosition], a
ld a, SELECT
scf
ret
2018-06-24 14:09:41 +00:00
.start
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 6, a
jp z, xor_a_dec_a
ld a, START
scf
ret
2018-06-24 14:09:41 +00:00
.d_left
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags2
bit 7, [hl]
jp z, xor_a_dec_a
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 3, a
jp z, xor_a_dec_a
ld a, D_LEFT
scf
ret
2018-06-24 14:09:41 +00:00
.d_right
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags2
bit 7, [hl]
jp z, xor_a_dec_a
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 2, a
jp z, xor_a_dec_a
ld a, D_RIGHT
scf
ret
2018-06-24 14:09:41 +00:00
.d_up
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags2
bit 7, [hl]
jp z, xor_a
ld hl, wMenuScrollPosition
ld a, [hl]
and a
jr z, .xor_dec_up
dec [hl]
jp xor_a
.xor_dec_up
jp xor_a_dec_a
2018-06-24 14:09:41 +00:00
.d_down
2015-12-18 03:31:16 +00:00
ld hl, w2DMenuFlags2
bit 7, [hl]
jp z, xor_a
ld hl, wMenuScrollPosition
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
add [hl]
ld b, a
ld a, [wScrollingMenuListSize]
cp b
jr c, .xor_dec_down
inc [hl]
jp xor_a
.xor_dec_down
jp xor_a_dec_a
2018-06-24 14:09:41 +00:00
ScrollingMenu_GetCursorPosition:
2015-12-18 03:31:16 +00:00
ld a, [wMenuScrollPosition]
ld c, a
ld a, [wMenuCursorY]
add c
ld c, a
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_ClearLeftColumn:
2015-12-18 03:31:16 +00:00
call MenuBoxCoord2Tile
ld de, SCREEN_WIDTH
add hl, de
ld de, 2 * SCREEN_WIDTH
ld a, [wMenuData_ScrollingMenuHeight]
2016-03-02 03:31:21 +00:00
.loop
2015-12-18 03:31:16 +00:00
ld [hl], " "
add hl, de
dec a
2016-03-02 03:31:21 +00:00
jr nz, .loop
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
InitScrollingMenuCursor:
ld hl, wMenuData_ItemsPointerAddr
2015-12-18 03:31:16 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wMenuData_ItemsPointerBank]
2015-12-18 03:31:16 +00:00
call GetFarByte
ld [wScrollingMenuListSize], a
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
ld c, a
ld a, [wMenuScrollPosition]
add c
ld c, a
ld a, [wScrollingMenuListSize]
inc a
cp c
jr nc, .skip
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
ld c, a
ld a, [wScrollingMenuListSize]
inc a
sub c
jr nc, .store
xor a
.store
ld [wMenuScrollPosition], a
.skip
ld a, [wMenuScrollPosition]
ld c, a
ld a, [wMenuCursorBuffer]
add c
ld b, a
ld a, [wScrollingMenuListSize]
inc a
cp b
jr c, .wrap
jr nc, .done
2015-12-18 03:31:16 +00:00
.wrap
2015-12-18 03:31:16 +00:00
xor a
ld [wMenuScrollPosition], a
ld a, $1
ld [wMenuCursorBuffer], a
.done
2015-12-18 03:31:16 +00:00
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_InitFlags:
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
ld c, a
ld a, [wScrollingMenuListSize]
ld b, a
ld a, [wMenuBorderTopCoord]
add 1
2015-12-18 03:31:16 +00:00
ld [w2DMenuCursorInitY], a
ld a, [wMenuBorderLeftCoord]
add 0
2015-12-18 03:31:16 +00:00
ld [w2DMenuCursorInitX], a
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
cp b
jr c, .no_extra_row
jr z, .no_extra_row
2015-12-18 03:31:16 +00:00
ld a, b
inc a
.no_extra_row
2015-12-18 03:31:16 +00:00
ld [w2DMenuNumRows], a
ld a, 1
2015-12-18 03:31:16 +00:00
ld [w2DMenuNumCols], a
ld a, $8c
bit 2, c
jr z, .skip_set_0
2015-12-18 03:31:16 +00:00
set 0, a
.skip_set_0
2015-12-18 03:31:16 +00:00
bit 3, c
jr z, .skip_set_1
2015-12-18 03:31:16 +00:00
set 1, a
.skip_set_1
2015-12-18 03:31:16 +00:00
ld [w2DMenuFlags1], a
xor a
ld [w2DMenuFlags2], a
ld a, $20
2015-12-21 19:10:16 +00:00
ld [w2DMenuCursorOffsets], a
ld a, A_BUTTON | B_BUTTON | D_UP | D_DOWN
2015-12-18 03:31:16 +00:00
bit 7, c
jr z, .disallow_select
add SELECT
2015-12-18 03:31:16 +00:00
.disallow_select
2015-12-18 03:31:16 +00:00
bit 6, c
jr z, .disallow_start
add START
2015-12-18 03:31:16 +00:00
.disallow_start
ld [wMenuJoypadFilter], a
2015-12-18 03:31:16 +00:00
ld a, [w2DMenuNumRows]
ld b, a
ld a, [wMenuCursorBuffer]
and a
jr z, .reset_cursor
2015-12-18 03:31:16 +00:00
cp b
jr z, .cursor_okay
jr c, .cursor_okay
2015-12-18 03:31:16 +00:00
.reset_cursor
ld a, 1
2015-12-18 03:31:16 +00:00
.cursor_okay
2015-12-18 03:31:16 +00:00
ld [wMenuCursorY], a
ld a, 1
2015-12-18 03:31:16 +00:00
ld [wMenuCursorX], a
xor a
ld [wCursorCurrentTile], a
ld [wCursorCurrentTile + 1], a
ld [wCursorOffCharacter], a
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_ValidateSwitchItem:
2015-12-18 03:31:16 +00:00
ld a, [wScrollingMenuListSize]
ld c, a
ld a, [wSwitchItem]
and a
jr z, .done
dec a
cp c
jr c, .done
xor a
ld [wSwitchItem], a
.done
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_UpdateDisplay:
2015-12-18 03:31:16 +00:00
call ClearWholeMenuBox
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 4, a ; place arrows
jr z, .okay
ld a, [wMenuScrollPosition]
and a
jr z, .okay
ld a, [wMenuBorderTopCoord]
ld b, a
ld a, [wMenuBorderRightCoord]
ld c, a
call Coord2Tile
ld [hl], "▲"
.okay
call MenuBoxCoord2Tile
ld bc, SCREEN_WIDTH + 1
add hl, bc
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
ld b, a
ld c, $0
.loop
ld a, [wMenuScrollPosition]
add c
ld [wScrollingMenuCursorPosition], a
ld a, c
call ScrollingMenu_GetListItemCoordAndFunctionArgs
2018-01-23 22:39:09 +00:00
ld a, [wMenuSelection]
2015-12-18 03:31:16 +00:00
cp -1
jr z, .cancel
push bc
push hl
call ScrollingMenu_CallFunctions1and2
pop hl
ld bc, 2 * SCREEN_WIDTH
add hl, bc
pop bc
inc c
ld a, c
cp b
jr nz, .loop
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 4, a ; place arrows
jr z, .done
ld a, [wMenuBorderBottomCoord]
ld b, a
ld a, [wMenuBorderRightCoord]
ld c, a
call Coord2Tile
ld [hl], "▼"
.done
ret
.cancel
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 0, a ; call function on cancel
jr nz, .call_function
ld de, .CancelString
2015-12-18 03:31:16 +00:00
call PlaceString
ret
.CancelString
2015-12-18 03:31:16 +00:00
db "CANCEL@"
.call_function
ld d, h
ld e, l
ld hl, wMenuData_ScrollingMenuFunction1
2015-12-18 03:31:16 +00:00
jp CallPointerAt
2018-06-24 14:09:41 +00:00
ScrollingMenu_CallFunctions1and2:
2015-12-18 03:31:16 +00:00
push hl
ld d, h
ld e, l
ld hl, wMenuData_ScrollingMenuFunction1
2015-12-18 03:31:16 +00:00
call CallPointerAt
pop hl
ld a, [wMenuData_ScrollingMenuWidth]
2015-12-18 03:31:16 +00:00
and a
jr z, .done
ld e, a
ld d, $0
add hl, de
ld d, h
ld e, l
ld hl, wMenuData_ScrollingMenuFunction2
2015-12-18 03:31:16 +00:00
call CallPointerAt
.done
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_PlaceCursor:
2015-12-18 03:31:16 +00:00
ld a, [wSwitchItem]
and a
jr z, .done
ld b, a
ld a, [wMenuScrollPosition]
cp b
jr nc, .done
ld c, a
ld a, [wMenuData_ScrollingMenuHeight]
2015-12-18 03:31:16 +00:00
add c
cp b
jr c, .done
ld a, b
sub c
dec a
add a
add $1
ld c, a
ld a, [wMenuBorderTopCoord]
add c
ld b, a
ld a, [wMenuBorderLeftCoord]
add $0
ld c, a
call Coord2Tile
ld [hl], "▷"
.done
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_CheckCallFunction3:
ld a, [wMenuDataFlags]
2015-12-18 03:31:16 +00:00
bit 5, a ; call function 3
ret z
bit 1, a ; call function 3 if not switching items
jr z, .call
ld a, [wSwitchItem]
and a
ret nz
.call
ld a, [wMenuCursorY]
dec a
call ScrollingMenu_GetListItemCoordAndFunctionArgs
ld hl, wMenuData_ScrollingMenuFunction3
2015-12-18 03:31:16 +00:00
call CallPointerAt
ret
2018-06-24 14:09:41 +00:00
ScrollingMenu_GetListItemCoordAndFunctionArgs:
2015-12-18 03:31:16 +00:00
push de
push hl
ld e, a
ld a, [wMenuScrollPosition]
add e
ld e, a
ld d, $0
ld hl, wMenuData_ItemsPointerAddr
2015-12-18 03:31:16 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
inc hl ; items
ld a, [wMenuData_ScrollingMenuItemFormat]
cp SCROLLINGMENU_ITEMS_NORMAL
2015-12-18 03:31:16 +00:00
jr z, .got_spacing
cp SCROLLINGMENU_ITEMS_QUANTITY
2015-12-18 03:31:16 +00:00
jr z, .pointless_jump
.pointless_jump
add hl, de
.got_spacing
add hl, de
ld a, [wMenuData_ItemsPointerBank]
2015-12-18 03:31:16 +00:00
call GetFarByte
2018-01-23 22:39:09 +00:00
ld [wMenuSelection], a
ld [wCurItem], a
2015-12-18 03:31:16 +00:00
inc hl
ld a, [wMenuData_ItemsPointerBank]
2015-12-18 03:31:16 +00:00
call GetFarByte
2018-01-23 22:39:09 +00:00
ld [wMenuSelectionQuantity], a
2015-12-18 03:31:16 +00:00
pop hl
pop de
ret