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
|
; VBlank: Write loading text, then wait for generation, then loading vram stuff
; When VBlank interrupts -> context switch
; When stat out of vblank interrupt -> context switch back to generation
.MACRODEF ENABLE_MODE_2_INTERRUPT
LD A, low(=Dungeon_generation_Out_Of_VBlank)
LD ($mem_stat_jump_destination), A
LD A, high(=Dungeon_generation_Out_Of_VBlank)
LD ($mem_stat_jump_destination+1), A
.RESET_INTERRUPTS
LD A, $20
LD $reg_lcd_status, A
LD A, $02
LD $reg_interrupt_enable, A
.END
.MACRODEF ENABLE_MUSIC_INTERRUPT
LD A, low(=Dungeon_1st_step_VBlank)
LD ($mem_vblank_jump_destination), A
LD A, high(=Dungeon_1st_step_VBlank)
LD ($mem_vblank_jump_destination+1), A
.RESET_INTERRUPTS
.ENABLE_VBLANK_INTERRUPTS
.END
.MACRODEF DISABLE_MODE_2_INTERRUPT
LD A, $00
LD $reg_lcd_status, A
LD A, $00
LD $reg_interrupt_enable, A
.END
New_Dungeon:
.LOAD_MUSIC =_music_Dungeon
CALL =Start_Music
LD A, $20
LD $mem_bunny_health, A
LD A, $30
LD $mem_bunny_mana, A
LD A, $01
LD $mem_floor_count, A
LD A, $00
LD $mem_floor_count_bin, A
LD A, ($mem_dungeon+1)
LD H, A
LD A, ($mem_dungeon+2)
LD L, A
LD A, ($mem_dungeon)
CALL =Load_Dungeon_Infos
New_Floor:
LD SP, $fffe
.ENABLE_MUSIC_INTERRUPT
EI
LD A, $00
LD $mem_display_flag, A
LD A, $00
LD $reg_viewport_x, A
LD A, $mem_dungeon_flags
BIT 1, A
JR Z, =.floor_count.disabled
.floor_count.enabled:
LD A, $70
LD $reg_viewport_y, A
LD A, $f4
LD ($9eeb), A
LD HL, $9ee9
LD A, $mem_floor_count
CALL =Print_8bit
JR =.floor_count.end
.floor_count.disabled:
LD A, $68
LD $reg_viewport_y, A
LD A, $00
LD ($9ee9), A
LD ($9eea), A
LD ($9eeb), A
.floor_count.end:
LD A, $07
LD $reg_bg_palette, A
LD A, $lcdc_guibg_tilemap
LD $reg_lcd_controller, A
CALL =Reset_Map
LD A, ($mem_dungeon+1)
LD H, A
LD A, ($mem_dungeon+2)
LD L, A
LD A, ($mem_dungeon)
CALL =Load_Dungeon_Spawn_patterns
LD A, $entity_questgoalbunny_index
LD $mem_loaded_special_entity_index, A
CALL =Reload_EP_Cost
LD A, $mem_dungeon_flags
BIT 0, A
JR Z, =.map.generation
.map.rom_loading:
LD A, ($mem_rom_collision_map_addr)
.CHANGE_BANK_TO_A
LD A, ($mem_rom_collision_map_addr+1)
LD D, A
LD A, ($mem_rom_collision_map_addr+2)
LD E, A
LD HL, $mem_dungeon_map
LD BC, $0080
CALL =memcpy
LD B, $0f
LD C, $0f
CALL =Initialize_Bunny
LD HL, $mem_entities_list
CALL =Center_viewport_around_entity
CALL =Load_Prepared_Map
LD A, $mem_map_loading_flags
OR $01
LD $mem_map_loading_flags, A
LD HL, $mem_object_list
LD BC, $0080
CALL =bff
JR =.map.end
.map.generation:
CALL =Dungeon_Generation
CALL =Initialize_Entities
CALL =Initialize_Objects
.map.end:
; Reset animations
LD HL, $mem_animation_list
LD BC, $1f
CALL =bzero
; Clear OAM buffer
LD HL, $mem_oam_buffer
LD BC, $00a0
CALL =bzero
LD A, $00
LD $mem_display_flag, A
LD $mem_moving_animation_step, A
LD $mem_animation_wait_frames, A
LD $mem_blinking_animation_counter, A
LD A, $mem_bunny_x
LD $mem_bunny_predicted_x, A
LD A, $mem_bunny_y
LD $mem_bunny_predicted_y, A
LD A, $mem_map_loading_flags
RES 3, A
LD $mem_map_loading_flags, A
LD A, $enum_dungeon_mode
LD $mem_current_mode, A
LD $mem_requested_mode, A
LD A, $00
LD $mem_oam_buffer_low, A
CALL =Display_Entities
CALL =Generation_Event_Execution
LD HL, $mem_entities_list
CALL =Center_viewport_around_entity
CALL =Load_Prepared_Map
CALL =VBlank_Wait
Dungeon_generation_VBlank:
.ENABLE_MODE_2_INTERRUPT
EI
; Heart
LD A, $f0
LD ($9d62), A
; Energy points
LD A, $f1
LD ($9d66), A
; Floor
LD A, $f4
LD ($9d73), A
LD B, B
CALL =Reload_Entities_Tile_Data
LD B, B
; Clear OAM
LD HL, $fe00
LD BC, $00a0
CALL =bzero
LD DE, $mem_map_loading_buffer
LD HL, $9800
LD BC, $0400
CALL =memcpy
CALL =Load_Objects
LD HL, $9d71
LD A, $mem_floor_count
CALL =Print_8bit
CALL =Reset_Entities_Collision_Map
LD A, $mem_loop_frame_timer
ADD $3c
LD B, A
.wait_1s.loop:
HALT
LD A, $mem_loop_frame_timer
CP B
JR NZ, =.wait_1s.loop
LD A, $mem_display_flag
RES 6, A
LD $mem_display_flag, A
LD A, $mem_map_loading_flags
RES 2, A
RES 0, A
LD $mem_map_loading_flags, A
LD A, $mem_sound_flags
CP $00
CALL Z, =Reset_Music_Channels
LD A, $01
LD $mem_sound_flags, A
DI
.DISABLE_MODE_2_INTERRUPT
CALL =Update_VBlank_Handler
.ENABLE_VBLANK_INTERRUPTS
EI
.Wait_for_Interrupt.loop:
LD A, $reg_lcd_status
HALT
JP =.Wait_for_Interrupt.loop
Dungeon_generation_Out_Of_VBlank:
PUSH AF
PUSH BC
PUSH DE
PUSH HL
LD A, $saved_rom_bank
PUSH AF
LD A, $mem_loop_frame_timer
INC A
LD $mem_loop_frame_timer, A
CALL =Play_Music
CALL =VBlank_Wait
.ENABLE_MODE_2_INTERRUPT
.RESET_INTERRUPTS
POP AF
.CHANGE_BANK_TO_A
POP HL
POP DE
POP BC
POP AF
RETI
Dungeon_1st_step_VBlank:
PUSH AF
PUSH BC
PUSH DE
PUSH HL
LD A, $saved_rom_bank
PUSH AF
CALL =Play_Music
.ENABLE_VBLANK_INTERRUPTS
.RESET_INTERRUPTS
POP AF
.CHANGE_BANK_TO_A
POP HL
POP DE
POP BC
POP AF
RETI
|