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
|
; 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_STAT_INTERRUPT
LD A, $20
LD $reg_lcd_status, A
LD A, $02
LD $reg_interrupt_enable, A
.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:
LD SP, $fffe
LD A, $00
LD $reg_viewport_x, A
LD A, $68
LD $reg_viewport_y, A
LD A, $00
LD $mem_display_flag, A
LD HL, =Dungeon_Name_1_Txt
CALL =strlen
LD B, A
LD A, $14
SUB B
SRA A
LD HL, $9e80
ADD L
LD L, A
LD A, H
ADC $00
LD H, A
LD BC, =Dungeon_Name_1_Txt
CALL =Print_str
LD HL, $9ec9
LD A, $mem_floor_count
CALL =Print_8bit
LD A, $f4
LD ($9ecb), A
LD A, $07
LD $reg_bg_palette, A
LD A, $lcdc_guibg_tilemap
LD $reg_lcd_controller, A
CALL =Reset_Map
LD HL, $mem_loaded_enemies_indices
LD A, $02
LD (HL+), A
LD (HL+), A
LD A, $00
LD (HL+), A
LD A, $03
LD (HL+), A
LD A, $06
LD $mem_loaded_special_entity_index, A
LD HL, $mem_bunny_attacks
LD A, $00
LD (HL+), A
INC A
LD (HL+), A
INC A
LD (HL+), A
INC A
LD (HL+), A
CALL =Reload_EP_Cost
CALL =Dungeon_Generation
CALL =Initialize_Entities
CALL =Initialize_Objects
; 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
CALL =Load_Prepared_Map
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
CALL =Reload_Entities_Tile_Data
; 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 =Update_VBlank_Handler
DI
.DISABLE_MODE_2_INTERRUPT
CALL =Reset_Entities_Collision_Map
.SET_WINDOW_LCDC_E
.ENABLE_VBLANK_INTERRUPTS
.RESET_STAT_INTERRUPT
LD A, $00
LD $reg_interrupt_flags, A
EI
Wait_for_Interrupt.loop:
HALT
JP =Wait_for_Interrupt.loop
Dungeon_generation_Out_Of_VBlank:
PUSH AF
CALL =VBlank_Wait
.ENABLE_MODE_2_INTERRUPT
POP AF
RETI
|