summaryrefslogtreecommitdiff
path: root/engine/menu/start_menu.asm
blob: 3eeb1c073a36874ed5e027669b190ff9460a53c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
DisplayStartMenu:: ; 29d1 (0:29d1)
	switchbank StartMenu_Pokedex ; also bank for other functions
	ld a, [wWalkBikeSurfState] ; walking/biking/surfing
	ld [wWalkBikeSurfStateCopy], a
	ld a, $8f ; (SFX_02_3f - SFX_Headers_02) / 3 ; Start menu sound
	call PlaySound

RedisplayStartMenu:: ; 29e1 (0:29e1)
	callba DrawStartMenu
RedisplayStartMenu_DoNotDrawStartMenu: ; 29e9 (0:29e9)
	callba PrintSafariZoneSteps ; print Safari Zone info, if in Safari Zone
	call UpdateSprites
.loop
	call HandleMenuInput
	ld b, a
.checkIfUpPressed
	bit 6, a ; was Up pressed?
	jr z, .checkIfDownPressed
	ld a, [wCurrentMenuItem] ; menu selection
	and a
	jr nz, .loop
	ld a, [wLastMenuItem]
	and a
	jr nz, .loop
; if the player pressed tried to go past the top item, wrap around to the bottom
	CheckEvent EVENT_GOT_POKEDEX ; does the player have the pokedex?
	ld a, 6 ; there are 7 menu items with the pokedex, so the max index is 6
	jr nz, .wrapMenuItemId
	dec a ; there are only 6 menu items without the pokedex
.wrapMenuItemId
	ld [wCurrentMenuItem], a
	call EraseMenuCursor
	jr .loop
.checkIfDownPressed
	bit 7, a
	jr z, .buttonPressed
; if the player pressed tried to go past the bottom item, wrap around to the top
	CheckEvent EVENT_GOT_POKEDEX ; does the player have the pokedex?
	ld a, [wCurrentMenuItem]
	ld c, 7 ; there are 7 menu items with the pokedex
	jr nz, .checkIfPastBottom
	dec c ; there are only 6 menu items without the pokedex
.checkIfPastBottom
	cp c
	jr nz, .loop
; the player went past the bottom, so wrap to the top
	xor a
	ld [wCurrentMenuItem], a
	call EraseMenuCursor
	jr .loop
.buttonPressed ; A, B, or Start button pressed
	call PlaceUnfilledArrowMenuCursor
	ld a, [wCurrentMenuItem]
	ld [wBattleAndStartSavedMenuItem], a ; save current menu selection
	ld a, b
	and a, %00001010 ; was the Start button or B button pressed?
	jp nz, CloseStartMenu
	call SaveScreenTilesToBuffer2 ; copy background from wTileMap to wTileMapBackup2
	CheckEvent EVENT_GOT_POKEDEX ; does the player have the pokedex?
	ld a, [wCurrentMenuItem]
	jr nz, .displayMenuItem
	inc a ; adjust position to account for missing pokedex menu item
.displayMenuItem
	cp a, 0
	jp z, StartMenu_Pokedex
	cp a, 1
	jp z, StartMenu_Pokemon
	cp a, 2
	jp z, StartMenu_Item
	cp a, 3
	jp z, StartMenu_TrainerInfo
	cp a, 4
	jp z, StartMenu_SaveReset
	cp a, 5
	jp z, StartMenu_Option

; EXIT falls through to here
CloseStartMenu:: ; 2a72 (0:2a72)
	call Joypad
	ld a, [hJoyPressed]
	bit 0, a ; was A button newly pressed?
	jr nz, CloseStartMenu
	call LoadTextBoxTilePatterns
	jp CloseTextDisplay