aboutsummaryrefslogtreecommitdiff
path: root/gui.gbasm
blob: 423c08116f754b92ad891c3256e7561db0e19aa8 (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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
.MACRODEF CLOSE_DIALOGUE
	LD A, $mem_display_flag
	AND $60
	OR $04
	LD $mem_display_flag, A

	LD HL, $dialogue_first_line
	LD BC, $12
	CALL =bzero

	LD HL, $dialogue_third_line
	LD BC, $12
	CALL =bzero
.END

Copy_Dialogue_Buffer:
	LD A, $mem_current_focused_attack_ep_cost
	LD HL, $9c43
	CALL =Print_8bit_Thin

	LD A, $mem_display_flag
	BIT 2, A
	JR Z, =Copy_Dialogue_Buffer_Part2
	RES 2, A
	SET 4, A
	LD $mem_display_flag, A
	LD HL, $9cb4
	LD DE, $dialogue_first_line
	LD C, $12
	JP =tilemap_memcpy

Copy_Dialogue_Buffer_Part2:
	BIT 4, A
	RET Z
	RES 4, A
	LD $mem_display_flag, A

	LD HL, $9cf4
	LD DE, $dialogue_third_line
	LD C, $12
	JP =tilemap_memcpy

Init_Attack_Menu:
	LD HL, $mem_bunny_attacks

	.MACRODEF SETUP_NEXT_ATTACK_MENU dialogue_buffer choice_routine ; Attack index pointer in (HL)
		PUSH HL

		; Getting Attack list pointer from index
		LD E, (HL)
		LD D, $00
		SLA E
		RL D
		SLA E
		RL D
		SLA E
		RL D

		LD HL, =Attack_List
		LD A, L
		ADD E
		LD L, A
		LD A, H
		ADC D
		LD H, A

		LD A, (HL+)
		.CHANGE_BANK_TO_A

		; Printing txt into dialogue buffer
		LD A, (HL+)
		LD B, A
		LD A, (HL+)
		LD C, A

		LD E, L
		LD D, H
		LD HL, $dialogue_buffer
		CALL =Print_str
		LD H, D
		LD L, E

		; Setting up choice routine
		LD A, (HL+)
		LD B, A
		LD A, (HL+)
		LD C, A

		LD D, H
		LD E, L
		LD HL, $choice_routine
		LD A, B
		LD (HL+), A
		LD A, C
		LD (HL), A

		POP HL
		INC HL
	.END

	.SETUP_NEXT_ATTACK_MENU $dialogue_menu_choice1, $dialogue_menu_choice1_routine
	.SETUP_NEXT_ATTACK_MENU $dialogue_menu_choice2, $dialogue_menu_choice2_routine
	.SETUP_NEXT_ATTACK_MENU $dialogue_menu_choice3, $dialogue_menu_choice3_routine
	.SETUP_NEXT_ATTACK_MENU $dialogue_menu_choice4, $dialogue_menu_choice4_routine

	LD A, $mem_number_of_attacks
	LD $mem_cursor_max_position, A
	RET

Nothing:
	RET

Exit_Menu:
	LD A, $enum_dungeon_mode
	LD $mem_requested_mode, A

	.CLOSE_DIALOGUE

	RET

Display_dialogue_cursor:
	LD A, $mem_current_mode
	CP $enum_dungeon_menu_mode
	RET NZ

	LD A, $mem_current_focused_attack_ep_cost
	LD B, A
	LD A, $mem_bunny_mana
	CP B
	LD H, $f2
	JR NC, =.Skip_Disable_cursor_setting
	LD H, $f3
	.Skip_Disable_cursor_setting:

	LD A, $mem_menu_cursor_position
	LD BC, $0000
	LD DE, $0000

	CP $00
	JR NZ, =.choice1_false
	LD B, H
	.choice1_false:

	CP $01
	JR NZ, =.choice2_false
	LD C, H
	.choice2_false:

	CP $02
	JR NZ, =.choice3_false
	LD D, H
	.choice3_false:

	CP $03
	JR NZ, =.choice4_false
	LD E, H
	.choice4_false:

	LD A, B
	LD $dialogue_menu_choice1_cursor, A
	LD A, C
	LD $dialogue_menu_choice2_cursor, A
	LD A, D
	LD $dialogue_menu_choice3_cursor, A
	LD A, E
	LD $dialogue_menu_choice4_cursor, A
	RET

Move_dialogue_cursor:
	LD A, $mem_current_mode
	CP $enum_dungeon_menu_mode
	RET NZ

	LD A, $mem_menu_cursor_position
	LD D, A
	LD A, $mem_cursor_max_position
	LD C, A
	LD A, $mem_last_button_direction
	LD B, A
	LD A, $mem_button_direction
	CP $00
	RET Z
	CP B
	RET Z

	DEC A
	BIT 1, A
	JR Z, =.Vertical_axis
	LD A, $mem_menu_cursor_position
	XOR $02
	CP C
	JR NC, =.Sound_effect
	LD $mem_menu_cursor_position, A
	JR =Reload_EP_Cost

	.Vertical_axis:
	LD A, $mem_menu_cursor_position
	XOR $01
	CP C
	JR NC, =.Sound_effect
	LD $mem_menu_cursor_position, A

	.Sound_effect:
	LD A, $mem_menu_cursor_position
	CP D
	JR NZ, =.moved_sound_effect
	.fail_move_sound_effect:
	.SET_SOUND_EFFECT =_sound_effect_Move_arrow_failed
	.moved_sound_effect:

Reload_EP_Cost:
	LD A, $mem_menu_cursor_position
	ADD low($mem_bunny_attacks)
	LD L, A
	LD A, high($mem_bunny_attacks)
	ADC $00
	LD H, A

	; Getting Attack list pointer from index
	LD E, (HL)
	LD D, $00
	SLA E
	RL D
	SLA E
	RL D
	SLA E
	RL D

	LD HL, =Attack_List
	LD A, L
	ADD E
	LD L, A
	LD A, H
	ADC D
	LD H, A

	LD A, L
	ADD $05
	LD L, A
	LD A, H
	ADC $00
	LD H, A

	LD A, (HL)
	LD $mem_current_focused_attack_ep_cost, A

	RET

Check_dialogue_action:
	LD A, $mem_display_flag
	AND 0b00010100
	CP $00
	RET NZ

	LD A, $mem_current_mode
	CP $enum_dungeon_menu_mode
	JR Z, =.Dungeon_Menu

	CP $enum_dungeon_dialogue_mode
	JR Z, =.Dialogue_Box

	LD A, $mem_button_action
	LD B, A
	LD A, $mem_last_button_action
	XOR B
	AND B
	CP $00
	RET Z
	; Wait for the music to stop to restart game when button pressed
	LD A, $mem_sound_flags
	BIT 0, A
	RET NZ
	JP =Start
	RET

	.Dialogue_Box:
	LD A, $mem_button_action
	LD B, A
	LD A, $mem_last_button_action
	XOR B
	AND B
	CP $00
	RET Z
	BIT 0, A
	RET Z
	.SET_SOUND_EFFECT =_sound_effect_Click
	JP =Dialogue_script_step

	.Dungeon_Menu:
	LD A, $mem_button_action
	LD B, A
	LD A, $mem_last_button_action
	XOR B
	AND B
	CP $00
	RET Z
	BIT 3, A
	JR Z, =.test_attack_chosen
	.SET_SOUND_EFFECT =_sound_effect_Menu_Close
	LD A, $69
	JP =Exit_Menu

	.test_attack_chosen:
	BIT 0, A
	RET Z

	LD A, $mem_current_focused_attack_ep_cost
	LD B, A
	LD A, $mem_bunny_mana
	CP B
	RET C
	SUB B
	DAA
	LD $mem_bunny_mana, A

	LD HL, $dialogue_menu_choice1_routine

	LD A, $mem_menu_cursor_position
	SLA A
	ADD L
	LD L, A

	.moved_sound_effect:
	LD A, (HL+)
	LD D, A
	LD A, (HL+)
	LD E, A

	.CALL_DE
	RET

Check_Open_Menu_button:
	LD A, $mem_dungeon_flags
	BIT 4, A
	RET Z
	LD A, $mem_current_mode
	CP $enum_dungeon_mode
	RET NZ

	LD A, $mem_requested_mode
	CP $enum_dungeon_mode
	RET NZ

	LD A, $mem_bunny_status
	BIT 0, A
	RET NZ

	LD A, $mem_last_button_action
	AND $08
	LD B, A
	LD A, $mem_button_action
	AND $08
	CP B
	RET Z
	BIT 3, A
	RET Z

	CALL =Init_Attack_Menu

	LD A, $enum_dungeon_menu_mode
	LD $mem_requested_mode, A
	RET

Open_dialogue_on_dungeon_menu_mode:
	LD A, $mem_current_mode
	CP $enum_dungeon_menu_mode
	RET NZ
	LD A, $mem_requested_mode
	CP $enum_dungeon_menu_mode
	RET NZ

	LD A, $mem_display_flag
	BIT 0, A
	RET NZ
	LD A, $mem_display_flag
	AND $40 ; Keeping object additional tile
	OR $0d
	LD $mem_display_flag, A
	.SET_SOUND_EFFECT =_sound_effect_Menu_Open

	RET

Dialogue_Arrow_Animation:
	LD A, $mem_display_flag
	BIT 0, A
	RET Z

	LD A, $mem_current_mode
	CP $enum_dungeon_dialogue_mode
	JR Z, =.dialogue

	LD A, $18
	LD ($9d05), A
	LD A, $14
	LD ($9d06), A
	RET

	.dialogue:
	LD A, $mem_loop_frame_timer
	AND $7f
	CP $4e
	JR C, =.normal
	CP $5a
	JR C, =.down
	CP $66
	JR C, =.normal
	CP $72
	JR C, =.down

	.normal:
	LD A, $19
	LD ($9d05), A
	LD A, $1a
	LD ($9d06), A
	RET

	.down:
	LD A, $1b
	LD ($9d05), A
	LD A, $1c
	LD ($9d06), A
	RET