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
362
363
364
365
|
JoypadInt:: ; 8df (0:08df)
reti
ClearJoypad::
xor a
ld [hJoyPressed], a
ld [hJoyDown], a
ret
Joypad:: ; 8e6 (0:08e6)
ld a, [wd8ba]
and $d0
ret nz
ld a, [wGameLogicPaused]
and a
ret nz
ld a, $20
ld [rJOYP], a
ld a, [rJOYP]
ld a, [rJOYP]
cpl
and $f
swap a
ld b, a
ld a, $10
ld [rJOYP], a
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
ld a, [rJOYP]
cpl
and $f
or b
ld b, a
ld a, $30
ld [rJOYP], a
ld a, [hJoypadDown]
ld e, a
xor b
ld d, a
and e
ld [hJoypadReleased], a
ld a, d
and b
ld [hJoypadPressed], a
ld c, a
ld a, [hJoypadSum]
or c
ld [hJoypadSum], a
ld a, b
ld [hJoypadDown], a
and $f
cp $f
jp z, Reset
ret
GetJoypad:: ; 935 (0:0935)
push af
push hl
push de
push bc
ld a, [wInputType]
cp $ff
jr z, .auto
ld a, [hJoypadDown]
ld b, a
ld a, [hJoyDown]
ld e, a
xor b
ld d, a
and e
ld [hJoyReleased], a
ld a, d
and b
ld [hJoyPressed], a
ld c, a
ld a, b
ld [hJoyDown], a
.quit
pop bc
pop de
pop hl
pop af
ret
.auto
ld a, [hROMBank]
push af
ld a, [wAutoInputBank]
rst Bankswitch
ld hl, wAutoInputAddress
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wAutoInputLength]
and a
jr z, .updateauto
dec a
ld [wAutoInputLength], a
pop af
rst Bankswitch
jr .quit
.updateauto
ld a, [hli]
cp $ff
jr z, .stopauto
ld b, a
ld a, [hli]
ld [wAutoInputLength], a
cp $ff
jr nz, .next
dec hl
dec hl
ld b, $0
jr .finishauto
.next
ld a, l
ld [wAutoInputAddress], a
ld a, h
ld [wAutoInputAddress + 1], a
jr .finishauto
.stopauto
call StopAutoInput
ld b, $0
.finishauto
pop af
rst Bankswitch
ld a, b
ld [hJoyPressed], a
ld [hJoyDown], a
jr .quit
StartAutoInput::
ld [wAutoInputBank], a
ld a, l
ld [wAutoInputAddress], a
ld a, h
ld [wAutoInputAddress + 1], a
xor a
ld [wAutoInputLength], a
xor a
ld [hJoyPressed], a
ld [hJoyReleased], a
ld [hJoyDown], a
ld a, $ff
ld [wInputType], a
ret
StopAutoInput:: ; 9bb (0:09bb)
xor a
ld [wAutoInputBank], a
ld [wAutoInputAddress], a
ld [wAutoInputAddress + 1], a
ld [wAutoInputLength], a
ld [wInputType], a
ret
JoyTitleScreenInput::
.loop
call DelayFrame
push bc
call JoyTextDelay
pop bc
ld a, [hJoyDown]
cp D_UP | SELECT | B_BUTTON
jr z, .keycombo
ld a, [hJoyLast]
and START | A_BUTTON
jr nz, .keycombo
dec c
jr nz, .loop
and a
ret
.keycombo
scf
ret
JoyWaitAorB::
call DelayFrame
call GetJoypad
ld a, [hJoyPressed]
and A_BUTTON | B_BUTTON
ret nz
call RTC
jr JoyWaitAorB
WaitButton::
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call WaitBGMap
call JoyWaitAorB
pop af
ld [hOAMUpdate], a
ret
JoyTextDelay:: ; a08 (0:0a08)
call GetJoypad
ld a, [hInMenu]
and a
ld a, [hJoyPressed]
jr z, .ok
ld a, [hJoyDown]
.ok
ld [hJoyLast], a
ld a, [hJoyPressed]
and a
jr z, .checkframedelay
ld a, 15
ld [wTextDelayFrames], a
ret
.checkframedelay
ld a, [wTextDelayFrames]
and a
jr z, .restartframedelay
xor a
ld [hJoyLast], a
ret
.restartframedelay
ld a, 5
ld [wTextDelayFrames], a
ret
WaitPressAorB_BlinkCursor::
ld a, [hMapObjectIndexBuffer]
push af
ld a, [hObjectStructIndexBuffer]
push af
xor a
ld [hMapObjectIndexBuffer], a
ld a, $6
ld [hObjectStructIndexBuffer], a
.loop
push hl
hlcoord 18, 17
call BlinkCursor
pop hl
call JoyTextDelay
ld a, [hJoyLast]
and A_BUTTON | B_BUTTON
jr z, .loop
pop af
ld [hObjectStructIndexBuffer], a
pop af
ld [hMapObjectIndexBuffer], a
ret
SimpleWaitPressAorB::
.loop
call JoyTextDelay
ld a, [hJoyLast]
and A_BUTTON | B_BUTTON
jr z, .loop
ret
ButtonSound::
ld a, [wLinkMode]
and a
jr nz, .link_delay
call JoyWaitInput
push de
ld de, SFX_READ_TEXT_2
call PlaySFX
pop de
ret
.link_delay
ld c, 65
jp DelayFrames
JoyWaitInput:: ; a77 (0:0a77)
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [wInputType]
or a
jr z, .wait_loop
farcall DudeAutoInput_A
.wait_loop
call JoyBlinkCursor
call JoyTextDelay
ld a, [hJoyPressed]
and A_BUTTON | B_BUTTON
jr nz, .received_input
call RTC
ld a, $1
ld [hBGMapMode], a
call DelayFrame
jr .wait_loop
.received_input
pop af
ld [hOAMUpdate], a
ret
JoyBlinkCursor:: ; aa6 (0:0aa6)
ld a, [hVBlankCounter]
and $10
jr z, .cursor_off
ld a, "▼"
jr .load_cursor_state
.cursor_off
ld a, "─"
.load_cursor_state
ldcoord_a 18, 17
ret
BlinkCursor:: ; ab6 (0:0ab6)
push bc
ld a, [hl]
ld b, a
ld a, "▼"
cp b
pop bc
jr nz, .place_arrow
ld a, [hMapObjectIndexBuffer]
dec a
ld [hMapObjectIndexBuffer], a
ret nz
ld a, [hObjectStructIndexBuffer]
dec a
ld [hObjectStructIndexBuffer], a
ret nz
ld a, "─"
ld [hl], a
ld a, -1
ld [hMapObjectIndexBuffer], a
ld a, 6
ld [hObjectStructIndexBuffer], a
ret
.place_arrow
ld a, [hMapObjectIndexBuffer]
and a
ret z
dec a
ld [hMapObjectIndexBuffer], a
ret nz
dec a
ld [hMapObjectIndexBuffer], a
ld a, [hObjectStructIndexBuffer]
dec a
ld [hObjectStructIndexBuffer], a
ret nz
ld a, 6
ld [hObjectStructIndexBuffer], a
ld a, "▼"
ld [hl], a
ret
|