forked from gameboyadvancesp/understanding-pokemon-red
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoak_speech.asm
361 lines (311 loc) · 8.71 KB
/
oak_speech.asm
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
; ゲームに関する変数を初期化した後で、プレイヤーとライバルの名前にデフォルトネーム(NINTEN, SONY)を設定する
SetDefaultNames:
; [wLetterPrintingDelayFlags], [wOptions], [wd732]を退避
ld a, [wLetterPrintingDelayFlags]
push af
ld a, [wOptions]
push af
ld a, [wd732]
push af
; wPlayerName から wBoxDataEnd までを0クリア
ld hl, wPlayerName
ld bc, wBoxDataEnd - wPlayerName
xor a
call FillMemory
; スプライトデータをクリア
ld hl, wSpriteStateData1
ld bc, $200 ; wSpriteStateData1の始まりからwSpriteStateData2の終わりまで
xor a
call FillMemory
; 関数の最初で退避した[wLetterPrintingDelayFlags], [wOptions], [wd732]を復帰
pop af
ld [wd732], a
pop af
ld [wOptions], a
pop af
ld [wLetterPrintingDelayFlags], a
; [wOptionsInitialized] == 0 -> InitOptions
ld a, [wOptionsInitialized]
and a
call z, InitOptions
; 自分の名前を NINTEN にする
ld hl, NintenText
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData
; ライバルの名前を SONY にする
ld hl, SonyText
ld de, wRivalName
ld bc, NAME_LENGTH
jp CopyData
; **OakSpeech**
; オーキド博士のスピーチを行う
; - - -
; 『さいしょからはじめる』をスタートメニューで押した後から、スピーチが終わる(主人公の2階からゲーム開始)までをこの関数が担当する
; 特にINPUT, OUTPUTは無し
OakSpeech:
ld a, $FF
call PlaySound ; BGMを止める
; オーキドのスピーチのBGMを再生
ld a, BANK(Music_Routes2)
ld c, a
ld a, MUSIC_ROUTES2
call PlayMusic
; 画面描画の準備
call ClearScreen
call LoadTextBoxTilePatterns
; プレイヤーデータを初期化
call SetDefaultNames
predef InitPlayerData2
; プレイヤーのPCBoxに『キズぐすり』を1つ入れておく
ld hl, wNumBoxItems
ld a, POTION
ld [wcf91], a
ld a, 1
ld [wItemQuantity], a
call AddItemToInventory ; give one potion
; [wDefaultMap](FirstMapSpec, 主人公の家の2階)へ主人公をwarpさせておく
ld a, [wDefaultMap]
ld [wDestinationMap], a
call SpecialWarpIn
xor a
ld [hTilesetType], a
; デバッグモード -> .skipChoosingNames
ld a, [wd732]
bit 1, a ; possibly a debug mode bit
jp nz, .skipChoosingNames
; ここからオーキド博士のスピーチが始まり、主人公とライバルの名前を入力してもらう処理を行う
; オーキド博士のグラを画面真ん中に配置
ld de, ProfOakPic
lb bc, Bank(ProfOakPic), $00
call IntroDisplayPicCenteredOrUpperRight
; オーキド博士のグラをフェードイン
call FadeInIntroPic
; OakSpeechText1 を表示
ld hl, OakSpeechText1
call PrintText
; 画面を真っ白にする
call GBFadeOutToWhite
call ClearScreen
; ニドリーノを左からスライドさせてくる
ld a, NIDORINO
ld [wd0b5], a
ld [wcf91], a
call GetMonHeader
coord hl, 6, 4
call LoadFlippedFrontSpriteByMonIndex
call MovePicLeft ; ニドリーノはウィンドウとして描画されている?
; OakSpeechText2 を表示
ld hl, OakSpeechText2
call PrintText
; 画面を真っ白にする
call GBFadeOutToWhite
call ClearScreen
; 主人公を左からスライドさせてくる
ld de, RedPicFront
lb bc, Bank(RedPicFront), $00
call IntroDisplayPicCenteredOrUpperRight
call MovePicLeft
; 主人公の名前選択
ld hl, IntroducePlayerText
call PrintText
call ChoosePlayerName ; [wPlayerName] = 主人公の名前
call GBFadeOutToWhite
call ClearScreen
; 次にライバルのグラを表示
ld de, Rival1Pic
lb bc, Bank(Rival1Pic), $00
call IntroDisplayPicCenteredOrUpperRight
call FadeInIntroPic
; ライバルの名前選択
ld hl, IntroduceRivalText
call PrintText
call ChooseRivalName ; [wRivalName] = ライバルの名前
.skipChoosingNames
; 主人公のグラを表示
call GBFadeOutToWhite
call ClearScreen
ld de, RedPicFront
lb bc, Bank(RedPicFront), $00
call IntroDisplayPicCenteredOrUpperRight
call GBFadeInFromWhite
ld a, [wd72d]
and a
jr nz, .next
ld hl, OakSpeechText3
call PrintText
.next
; ここから主人公のグラをアイコンサイズに縮ませる処理
; 縮むSE
ld a, [H_LOADEDROMBANK]
push af
ld a, SFX_SHRINK
call PlaySound
pop af
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
ld c, 4
call DelayFrames
; 縮んだ後のRedSprite(主人公の16*16pxのアイコン)をVRAMに
ld de, RedSprite
ld hl, vSprites
lb bc, BANK(RedSprite), $0C
call CopyVideoData
; 収縮途中のスプライト1 を表示
ld de, ShrinkPic1
lb bc, BANK(ShrinkPic1), $00
call IntroDisplayPicCenteredOrUpperRight
ld c, 4
call DelayFrames
; 収縮途中のスプライト2 を表示
ld de, ShrinkPic2
lb bc, BANK(ShrinkPic2), $00
call IntroDisplayPicCenteredOrUpperRight
call ResetPlayerSpriteData
; マサラタウンのBGMを再生する準備
ld a, [H_LOADEDROMBANK]
push af
ld a, BANK(Music_PalletTown)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, 10
ld [wAudioFadeOutControl], a
ld a, $FF
ld [wNewSoundID], a
call PlaySound ; stop music
pop af
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
ld c, 20
call DelayFrames
; 画面をクリアしてreturn
coord hl, 6, 5
ld b, 7
ld c, 7
call ClearScreenArea
call LoadTextBoxTilePatterns
ld a, 1
ld [wUpdateSpritesEnabled], a
ld c, 50
call DelayFrames
call GBFadeOutToWhite
jp ClearScreen ; return
; "Hello there! Welcome to the world of #MON!"
; "My name is OAK! People call me the #MON PROF!"
OakSpeechText1:
TX_FAR _OakSpeechText1
db "@"
; "This world is inhabited by creatures called #MON!@@"
; 『ニドリーナの鳴き声』
; "For some people, #MON are pets."
; "Others use them for fights."
; "Myself... I study #MON as a profession."
OakSpeechText2:
TX_FAR _OakSpeechText2A
TX_CRY_NIDORINA
TX_FAR _OakSpeechText2B
db "@"
; "First, what is your name?"
IntroducePlayerText:
TX_FAR _IntroducePlayerText
db "@"
; "This is my grand-son. He's been your rival since you were a baby."
; "...Erm, what is his name again?"
IntroduceRivalText:
TX_FAR _IntroduceRivalText
db "@"
; "\<PLAYER\>!"
; "Your very own #MON legend is about to unfold!"
; "A world of dreams and adventures with #MON awaits!"
; "Let's go!"
OakSpeechText3:
TX_FAR _OakSpeechText3
db "@"
; **FadeInIntroPic**
; イントロのグラのフェードイン処理
; - - -
; 10フレームごとに BGPパレットを 以下のように変更する
;
; 0-10: %01010100
; 10-20: %10101000
; 20-30: %11111100
; 30-40: %11111000
; 40-50: %11110100
; 50-60: %11100100
FadeInIntroPic:
ld hl, IntroFadePalettes
ld b, 6
.next
ld a, [hli]
ld [rBGP], a
ld c, 10
call DelayFrames
dec b
jr nz, .next
ret
IntroFadePalettes:
db %01010100
db %10101000
db %11111100
db %11111000
db %11110100
db %11100100
; **MovePicLeft**
; グラフィックを左に動かす
; WXを徐々に減らす、つまりウィンドウを左に動かすことで実現している
MovePicLeft:
ld a, 119
ld [rWX], a
call DelayFrame
; BGP = [3, 2, 1, 0]
ld a, %11100100
ld [rBGP], a
.next
call DelayFrame
ld a, [rWX]
sub 8
cp $FF
ret z
ld [rWX], a
jr .next
; **DisplayPicCenteredOrUpperRight**
; 引数で指定したpicを画面の真ん中か右上に配置する
; - - -
; IntroDisplayPicCenteredOrUpperRightをfarcallで呼び出したい場合にこれをpredefで呼び出す
; b = 圧縮されたpicのあるバンク番号
; c = 0 (真ん中) or 0以外(右上)
; de = 圧縮されたpicのアドレス
DisplayPicCenteredOrUpperRight:
call GetPredefRegisters
; **IntroDisplayPicCenteredOrUpperRight**
; 引数で指定したpicを画面の真ん中か右上に配置する
; - - -
; b = バンク番号
; c = 0 (真ん中) or 0以外(右上)
; de = 圧縮されたpicのアドレス
IntroDisplayPicCenteredOrUpperRight:
; 圧縮されたpicデータを解凍
push bc
ld a, b
call UncompressSpriteFromDE ; DisplayPicCenteredOrUpperRightで解凍するpicは sSpriteBuffer1に解凍結果が入ることになっている
; 解凍結果の入った sSpriteBuffer1 から sSpriteBuffer0 に 784バイト コピー
ld hl, sSpriteBuffer1
ld de, sSpriteBuffer0
ld bc, $310 ; 784 => 49 * 16 = 2bppで 49タイル分のグラフィックデータ
call CopyData
; sSpriteBuffer0 と sSpriteBuffer1 の1bppのデータを 2bppとして vFrontPicに配置
; 今回は sSpriteBuffer1 を sSpriteBuffer0 にコピーしているので実質 1bpp
ld de, vFrontPic
call InterlaceMergeSpriteBuffers
; hl = (15, 1)(右上) or (6, 4)(真ん中)
pop bc
ld a, c
and a
coord hl, 15, 1
jr nz, .next
coord hl, 6, 4
; Uncompressedされたグラフィックデータ(7*7タイル)を hl のアドレスにコピーすることで描画
.next
xor a
ld [hStartTileID], a
predef_jump CopyUncompressedPicToTilemap