Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/menus/naming_screen.asm
2024 views
1
AskName:
2
call SaveScreenTilesToBuffer1
3
call GetPredefRegisters
4
push hl
5
ld a, [wIsInBattle]
6
dec a
7
hlcoord 0, 0
8
ld b, 4
9
ld c, 11
10
call z, ClearScreenArea ; only if in wild battle
11
ld a, [wCurPartySpecies]
12
ld [wNamedObjectIndex], a
13
call GetMonName
14
ld hl, DoYouWantToNicknameText
15
call PrintText
16
hlcoord 14, 7
17
lb bc, 8, 15
18
ld a, TWO_OPTION_MENU
19
ld [wTextBoxID], a
20
call DisplayTextBoxID
21
pop hl
22
ld a, [wCurrentMenuItem]
23
and a
24
jr nz, .declinedNickname
25
ld a, [wUpdateSpritesEnabled]
26
push af
27
xor a
28
ld [wUpdateSpritesEnabled], a
29
push hl
30
ld a, NAME_MON_SCREEN
31
ld [wNamingScreenType], a
32
call DisplayNamingScreen
33
ld a, [wIsInBattle]
34
and a
35
jr nz, .inBattle
36
call ReloadMapSpriteTilePatterns
37
.inBattle
38
call LoadScreenTilesFromBuffer1
39
pop hl
40
pop af
41
ld [wUpdateSpritesEnabled], a
42
ld a, [wStringBuffer]
43
cp '@'
44
ret nz
45
.declinedNickname
46
ld d, h
47
ld e, l
48
ld hl, wNameBuffer
49
ld bc, NAME_LENGTH
50
jp CopyData
51
52
DoYouWantToNicknameText:
53
text_far _DoYouWantToNicknameText
54
text_end
55
56
DisplayNameRaterScreen::
57
ld hl, wBuffer
58
xor a
59
ld [wUpdateSpritesEnabled], a
60
ld a, NAME_MON_SCREEN
61
ld [wNamingScreenType], a
62
call DisplayNamingScreen
63
call GBPalWhiteOutWithDelay3
64
call RestoreScreenTilesAndReloadTilePatterns
65
call LoadGBPal
66
ld a, [wStringBuffer]
67
cp '@'
68
jr z, .playerCancelled
69
ld hl, wPartyMonNicks
70
ld bc, NAME_LENGTH
71
ld a, [wWhichPokemon]
72
call AddNTimes
73
ld e, l
74
ld d, h
75
ld hl, wBuffer
76
ld bc, NAME_LENGTH
77
call CopyData
78
and a
79
ret
80
.playerCancelled
81
scf
82
ret
83
84
DisplayNamingScreen:
85
push hl
86
ld hl, wStatusFlags5
87
set BIT_NO_TEXT_DELAY, [hl]
88
call GBPalWhiteOutWithDelay3
89
call ClearScreen
90
call UpdateSprites
91
ld b, SET_PAL_GENERIC
92
call RunPaletteCommand
93
call LoadHpBarAndStatusTilePatterns
94
call LoadEDTile
95
farcall LoadMonPartySpriteGfx
96
hlcoord 0, 4
97
ld b, 9
98
ld c, 18
99
call TextBoxBorder
100
call PrintNamingText
101
ld a, 3
102
ld [wTopMenuItemY], a
103
ld a, 1
104
ld [wTopMenuItemX], a
105
ld [wLastMenuItem], a
106
ld [wCurrentMenuItem], a
107
ld a, $ff
108
ld [wMenuWatchedKeys], a
109
ld a, 7
110
ld [wMaxMenuItem], a
111
ld a, '@'
112
ld [wStringBuffer], a
113
xor a
114
ld hl, wNamingScreenSubmitName
115
ld [hli], a
116
ld [hli], a
117
ld [wAnimCounter], a
118
.selectReturnPoint
119
call PrintAlphabet
120
call GBPalNormal
121
.ABStartReturnPoint
122
ld a, [wNamingScreenSubmitName]
123
and a
124
jr nz, .submitNickname
125
call PrintNicknameAndUnderscores
126
.dPadReturnPoint
127
call PlaceMenuCursor
128
.inputLoop
129
ld a, [wCurrentMenuItem]
130
push af
131
farcall AnimatePartyMon_ForceSpeed1
132
pop af
133
ld [wCurrentMenuItem], a
134
call JoypadLowSensitivity
135
ldh a, [hJoyPressed]
136
and a
137
jr z, .inputLoop
138
ld hl, .namingScreenButtonFunctions
139
.checkForPressedButton
140
sla a
141
jr c, .foundPressedButton
142
inc hl
143
inc hl
144
inc hl
145
inc hl
146
jr .checkForPressedButton
147
.foundPressedButton
148
ld a, [hli]
149
ld e, a
150
ld a, [hli]
151
ld d, a
152
ld a, [hli]
153
ld h, [hl]
154
ld l, a
155
push de
156
jp hl
157
158
.submitNickname
159
pop de
160
ld hl, wStringBuffer
161
ld bc, NAME_LENGTH
162
call CopyData
163
call GBPalWhiteOutWithDelay3
164
call ClearScreen
165
call ClearSprites
166
call RunDefaultPaletteCommand
167
call GBPalNormal
168
xor a
169
ld [wAnimCounter], a
170
ld hl, wStatusFlags5
171
res BIT_NO_TEXT_DELAY, [hl]
172
ld a, [wIsInBattle]
173
and a
174
jp z, LoadTextBoxTilePatterns
175
jpfar LoadHudTilePatterns
176
177
.namingScreenButtonFunctions
178
dw .dPadReturnPoint
179
dw .pressedDown
180
dw .dPadReturnPoint
181
dw .pressedUp
182
dw .dPadReturnPoint
183
dw .pressedLeft
184
dw .dPadReturnPoint
185
dw .pressedRight
186
dw .ABStartReturnPoint
187
dw .pressedStart
188
dw .selectReturnPoint
189
dw .pressedSelect
190
dw .ABStartReturnPoint
191
dw .pressedB
192
dw .ABStartReturnPoint
193
dw .pressedA
194
195
.pressedA_changedCase
196
pop de
197
ld de, .selectReturnPoint
198
push de
199
.pressedSelect
200
ld a, [wAlphabetCase]
201
xor $1
202
ld [wAlphabetCase], a
203
ret
204
205
.pressedStart
206
ld a, 1
207
ld [wNamingScreenSubmitName], a
208
ret
209
210
.pressedA
211
ld a, [wCurrentMenuItem]
212
cp $5 ; "ED" row
213
jr nz, .didNotPressED
214
ld a, [wTopMenuItemX]
215
cp $11 ; "ED" column
216
jr z, .pressedStart
217
.didNotPressED
218
ld a, [wCurrentMenuItem]
219
cp $6 ; case switch row
220
jr nz, .didNotPressCaseSwitch
221
ld a, [wTopMenuItemX]
222
cp $1 ; case switch column
223
jr z, .pressedA_changedCase
224
.didNotPressCaseSwitch
225
ld hl, wMenuCursorLocation
226
ld a, [hli]
227
ld h, [hl]
228
ld l, a
229
inc hl
230
ld a, [hl]
231
ld [wNamingScreenLetter], a
232
call CalcStringLength
233
ld a, [wNamingScreenLetter]
234
cp ''
235
ld de, Dakutens
236
jr z, .dakutensAndHandakutens
237
cp ''
238
ld de, Handakutens
239
jr z, .dakutensAndHandakutens
240
ld a, [wNamingScreenType]
241
cp NAME_MON_SCREEN
242
jr nc, .checkMonNameLength
243
ld a, [wNamingScreenNameLength]
244
cp PLAYER_NAME_LENGTH - 1
245
jr .checkNameLength
246
.checkMonNameLength
247
ld a, [wNamingScreenNameLength]
248
cp NAME_LENGTH - 1
249
.checkNameLength
250
jr c, .addLetter
251
ret
252
253
.dakutensAndHandakutens
254
push hl
255
call DakutensAndHandakutens
256
pop hl
257
ret nc
258
dec hl
259
.addLetter
260
ld a, [wNamingScreenLetter]
261
ld [hli], a
262
ld [hl], '@'
263
ld a, SFX_PRESS_AB
264
call PlaySound
265
ret
266
.pressedB
267
ld a, [wNamingScreenNameLength]
268
and a
269
ret z
270
call CalcStringLength
271
dec hl
272
ld [hl], '@'
273
ret
274
.pressedRight
275
ld a, [wCurrentMenuItem]
276
cp $6
277
ret z ; can't scroll right on bottom row
278
ld a, [wTopMenuItemX]
279
cp $11 ; max
280
jp z, .wrapToFirstColumn
281
inc a
282
inc a
283
jr .done
284
.wrapToFirstColumn
285
ld a, $1
286
jr .done
287
.pressedLeft
288
ld a, [wCurrentMenuItem]
289
cp $6
290
ret z ; can't scroll right on bottom row
291
ld a, [wTopMenuItemX]
292
dec a
293
jp z, .wrapToLastColumn
294
dec a
295
jr .done
296
.wrapToLastColumn
297
ld a, $11 ; max
298
jr .done
299
.pressedUp
300
ld a, [wCurrentMenuItem]
301
dec a
302
ld [wCurrentMenuItem], a
303
and a
304
ret nz
305
ld a, $6 ; wrap to bottom row
306
ld [wCurrentMenuItem], a
307
ld a, $1 ; force left column
308
jr .done
309
.pressedDown
310
ld a, [wCurrentMenuItem]
311
inc a
312
ld [wCurrentMenuItem], a
313
cp $7
314
jr nz, .wrapToTopRow
315
ld a, $1
316
ld [wCurrentMenuItem], a
317
jr .done
318
.wrapToTopRow
319
cp $6
320
ret nz
321
ld a, $1
322
.done
323
ld [wTopMenuItemX], a
324
jp EraseMenuCursor
325
326
LoadEDTile:
327
ld de, ED_Tile
328
ld hl, vFont tile $70
329
; BUG: BANK("Home") should be BANK(ED_Tile), although it coincidentally works as-is
330
lb bc, BANK("Home"), (ED_TileEnd - ED_Tile) / TILE_1BPP_SIZE
331
jp CopyVideoDataDouble
332
333
ED_Tile:
334
INCBIN "gfx/font/ED.1bpp"
335
ED_TileEnd:
336
337
PrintAlphabet:
338
xor a
339
ldh [hAutoBGTransferEnabled], a
340
ld a, [wAlphabetCase]
341
and a
342
ld de, LowerCaseAlphabet
343
jr nz, .lowercase
344
ld de, UpperCaseAlphabet
345
.lowercase
346
hlcoord 2, 5
347
lb bc, 5, 9 ; 5 rows, 9 columns
348
.outerLoop
349
push bc
350
.innerLoop
351
ld a, [de]
352
ld [hli], a
353
inc hl
354
inc de
355
dec c
356
jr nz, .innerLoop
357
ld bc, SCREEN_WIDTH + 2
358
add hl, bc
359
pop bc
360
dec b
361
jr nz, .outerLoop
362
call PlaceString
363
ld a, $1
364
ldh [hAutoBGTransferEnabled], a
365
jp Delay3
366
367
INCLUDE "data/text/alphabets.asm"
368
369
PrintNicknameAndUnderscores:
370
call CalcStringLength
371
ld a, c
372
ld [wNamingScreenNameLength], a
373
hlcoord 10, 2
374
lb bc, 1, 10
375
call ClearScreenArea
376
hlcoord 10, 2
377
ld de, wStringBuffer
378
call PlaceString
379
hlcoord 10, 3
380
ld a, [wNamingScreenType]
381
cp NAME_MON_SCREEN
382
jr nc, .pokemon
383
; player or rival
384
ld b, PLAYER_NAME_LENGTH - 1
385
jr .gotUnderscoreCount
386
.pokemon
387
ld b, NAME_LENGTH - 1
388
.gotUnderscoreCount
389
ld a, $76 ; underscore tile id
390
.placeUnderscoreLoop
391
ld [hli], a
392
dec b
393
jr nz, .placeUnderscoreLoop
394
ld a, [wNamingScreenType]
395
cp NAME_MON_SCREEN
396
ld a, [wNamingScreenNameLength]
397
jr nc, .pokemon2
398
; player or rival
399
cp PLAYER_NAME_LENGTH - 1
400
jr .checkEmptySpaces
401
.pokemon2
402
cp NAME_LENGTH - 1
403
.checkEmptySpaces
404
jr nz, .placeRaisedUnderscore ; jump if empty spaces remain
405
; when all spaces are filled, force the cursor onto the ED tile,
406
; and keep the last underscore raised
407
call EraseMenuCursor
408
ld a, $11 ; "ED" x coord
409
ld [wTopMenuItemX], a
410
ld a, $5 ; "ED" y coord
411
ld [wCurrentMenuItem], a
412
ld a, [wNamingScreenType]
413
cp NAME_MON_SCREEN
414
ld a, NAME_LENGTH - 2
415
jr nc, .placeRaisedUnderscore
416
ld a, PLAYER_NAME_LENGTH - 2
417
.placeRaisedUnderscore
418
ld c, a
419
ld b, $0
420
hlcoord 10, 3
421
add hl, bc
422
ld [hl], $77 ; raised underscore tile id
423
ret
424
425
DakutensAndHandakutens:
426
push de
427
call CalcStringLength
428
dec hl
429
ld a, [hl]
430
pop hl
431
ld de, $2
432
call IsInArray
433
ret nc
434
inc hl
435
ld a, [hl]
436
ld [wNamingScreenLetter], a
437
ret
438
439
INCLUDE "data/text/dakutens.asm"
440
441
; calculates the length of the string at wStringBuffer and stores it in c
442
CalcStringLength:
443
ld hl, wStringBuffer
444
ld c, $0
445
.loop
446
ld a, [hl]
447
cp '@'
448
ret z
449
inc hl
450
inc c
451
jr .loop
452
453
PrintNamingText:
454
hlcoord 0, 1
455
ld a, [wNamingScreenType]
456
ld de, YourTextString
457
and a
458
jr z, .notNickname
459
ld de, RivalsTextString
460
dec a
461
jr z, .notNickname
462
ld a, [wCurPartySpecies]
463
ld [wMonPartySpriteSpecies], a
464
push af
465
farcall WriteMonPartySpriteOAMBySpecies
466
pop af
467
ld [wNamedObjectIndex], a
468
call GetMonName
469
hlcoord 4, 1
470
call PlaceString
471
ld hl, $1
472
add hl, bc
473
ld [hl], '' ; leftover from Japanese version; blank tile $c9 in English
474
hlcoord 1, 3
475
ld de, NicknameTextString
476
jr .placeString
477
.notNickname
478
call PlaceString
479
ld l, c
480
ld h, b
481
ld de, NameTextString
482
.placeString
483
jp PlaceString
484
485
YourTextString:
486
db "YOUR @"
487
488
RivalsTextString:
489
db "RIVAL's @"
490
491
NameTextString:
492
db "NAME?@"
493
494
NicknameTextString:
495
db "NICKNAME?@"
496
497