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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
MainMenu:
; Check save file
call InitOptions
xor a
ld [wOptionsInitialized], a
inc a
ld [wSaveFileStatus], a
call CheckForPlayerNameInSRAM
jr nc, .mainMenuLoop
predef TryLoadSaveFile
; FASTBOOT: if the save loaded cleanly (status 2), skip the menu and continue
ld a, [wSaveFileStatus]
cp 2
jp z, SpecialEnterMap
.mainMenuLoop
ld c, 20
call DelayFrames
xor a ; LINK_STATE_NONE
ld [wLinkState], a
ld hl, wPartyAndBillsPCSavedMenuItem
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [wDefaultMap], a
ld hl, wStatusFlags4
res BIT_LINK_CONNECTED, [hl]
call ClearScreen
call RunDefaultPaletteCommand
call LoadTextBoxTilePatterns
call LoadFontTilePatterns
ld hl, wStatusFlags5
set BIT_NO_TEXT_DELAY, [hl]
ld a, [wSaveFileStatus]
cp 1
jr z, .noSaveFile
; there's a save file
hlcoord 0, 0
lb bc, 6, 13
call TextBoxBorder
hlcoord 2, 2
ld de, ContinueText
call PlaceString
jr .next2
.noSaveFile
hlcoord 0, 0
lb bc, 4, 13
call TextBoxBorder
hlcoord 2, 2
ld de, NewGameText
call PlaceString
.next2
ld hl, wStatusFlags5
res BIT_NO_TEXT_DELAY, [hl]
call UpdateSprites
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
inc a
ld [wTopMenuItemX], a
inc a
ld [wTopMenuItemY], a
ld a, PAD_A | PAD_B | PAD_START
ld [wMenuWatchedKeys], a
ld a, [wSaveFileStatus]
ld [wMaxMenuItem], a
call HandleMenuInput
bit B_PAD_B, a
jp nz, DisplayTitleScreen ; if so, go back to the title screen
ld c, 20
call DelayFrames
ld a, [wCurrentMenuItem]
ld b, a
ld a, [wSaveFileStatus]
cp 2
jp z, .skipInc
; If there's no save file, increment the current menu item so that the numbers
; are the same whether or not there's a save file.
inc b
.skipInc
ld a, b
and a
jr z, .choseContinue
cp 1
jp z, StartNewGame
call DisplayOptionMenu
ld a, TRUE
ld [wOptionsInitialized], a
jp .mainMenuLoop
.choseContinue
call DisplayContinueGameInfo
ld hl, wCurrentMapScriptFlags
set BIT_CUR_MAP_LOADED_1, [hl]
.inputLoop
xor a
ldh [hJoyPressed], a
ldh [hJoyReleased], a
ldh [hJoyHeld], a
call Joypad
ldh a, [hJoyHeld]
bit B_PAD_A, a
jr nz, .pressedA
bit B_PAD_B, a
jp nz, .mainMenuLoop
jr .inputLoop
.pressedA
call GBPalWhiteOutWithDelay3
call ClearScreen
ld a, PLAYER_DIR_DOWN
ld [wPlayerDirection], a
ld c, 10
call DelayFrames
ld a, [wNumHoFTeams]
and a
jp z, SpecialEnterMap
ld a, [wCurMap]
cp HALL_OF_FAME
jp nz, SpecialEnterMap
xor a
ld [wDestinationMap], a
ld hl, wStatusFlags6
set BIT_FLY_OR_DUNGEON_WARP, [hl]
call PrepareForSpecialWarp
jp SpecialEnterMap
InitOptions:
ld a, 1 << BIT_FAST_TEXT_DELAY
ld [wLetterPrintingDelayFlags], a
ld a, TEXT_DELAY_MEDIUM
ld [wOptions], a
ld a, 64 ; audio?
ld [wPrinterSettings], a
ret
Func_5cc1:
; unused?
ld a, $6d
cp $80
ret c ; will always be executed
ld hl, NotEnoughMemoryText
call PrintText
ret
NotEnoughMemoryText:
text_far _NotEnoughMemoryText
text_end
StartNewGame:
ld hl, wStatusFlags6
; Ensure debug mode is not used when starting a regular new game.
; Debug mode persists in saved games for both debug and non-debug builds, and is
; only reset here by the main menu.
res BIT_DEBUG_MODE, [hl]
; fallthrough
StartNewGameDebug:
call OakSpeech
ld a, $8
ld [wPlayerMovingDirection], a
ld c, 20
call DelayFrames
; enter map after using a special warp or loading the game from the main menu
SpecialEnterMap::
xor a
ldh [hJoyPressed], a
ldh [hJoyHeld], a
ldh [hJoy5], a
ld [wCableClubDestinationMap], a
ld hl, wStatusFlags6
set BIT_GAME_TIMER_COUNTING, [hl]
call ResetPlayerSpriteData
ld c, 20
call DelayFrames
call Func_5cc1
ld a, [wEnteringCableClub]
and a
ret nz
jp EnterMap
ContinueText:
db "CONTINUE"
next ""
; fallthrough
NewGameText:
db "NEW GAME"
next "OPTION@"
DisplayContinueGameInfo:
xor a
ldh [hAutoBGTransferEnabled], a
hlcoord 4, 7
lb bc, 8, 14
call TextBoxBorder
hlcoord 5, 9
ld de, SaveScreenInfoText
call PlaceString
hlcoord 12, 9
ld de, wPlayerName
call PlaceString
hlcoord 17, 11
call PrintNumBadges
hlcoord 16, 13
call PrintNumOwnedMons
hlcoord 13, 15
call PrintPlayTime
ld a, 1
ldh [hAutoBGTransferEnabled], a
ld c, 30
jp DelayFrames
PrintSaveScreenText:
xor a
ldh [hAutoBGTransferEnabled], a
hlcoord 4, 0
lb bc, 8, 14
call TextBoxBorder
call LoadTextBoxTilePatterns
call UpdateSprites
hlcoord 5, 2
ld de, SaveScreenInfoText
call PlaceString
hlcoord 12, 2
ld de, wPlayerName
call PlaceString
hlcoord 17, 4
call PrintNumBadges
hlcoord 16, 6
call PrintNumOwnedMons
hlcoord 13, 8
call PrintPlayTime
ld a, $1
ldh [hAutoBGTransferEnabled], a
ld c, 30
jp DelayFrames
PrintNumBadges:
push hl
ld hl, wObtainedBadges
ld b, $1
call CountSetBits
pop hl
ld de, wNumSetBits
lb bc, 1, 2
jp PrintNumber
PrintNumOwnedMons:
push hl
ld hl, wPokedexOwned
ld b, wPokedexOwnedEnd - wPokedexOwned
call CountSetBits
pop hl
ld de, wNumSetBits
lb bc, 1, 3
jp PrintNumber
PrintPlayTime:
ld de, wPlayTimeHours
lb bc, 1, 3
call PrintNumber
ld [hl], $6d
inc hl
ld de, wPlayTimeMinutes
lb bc, LEADING_ZEROES | 1, 2
jp PrintNumber
SaveScreenInfoText:
db "PLAYER"
next "BADGES "
next "#DEX "
next "TIME@"
DisplayOptionMenu:
callfar DisplayOptionMenu_
ret
CheckForPlayerNameInSRAM::
ld a, RAMG_SRAM_ENABLE
ld [rRAMG], a
ld a, BMODE_ADVANCED
ld [rBMODE], a
ASSERT BANK(sPlayerName) == BMODE_ADVANCED
ld [rRAMB], a
ld b, NAME_LENGTH
ld hl, sPlayerName
.loop
ld a, [hli]
cp '@'
jr z, .found
dec b
jr nz, .loop
xor a
ld [rRAMG], a
ld [rBMODE], a
and a
ret
.found
xor a
ld [rRAMG], a
ld [rBMODE], a
scf
ret
|