aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-07-01 15:20:38 +0200
committerAstatin <[email protected]>2025-07-01 15:20:38 +0200
commitbcc4605c06e2b36698ae05eeda1f9078bfbcd2c7 (patch)
tree5c312652e6659ed8c5cc292590f4d4a0e3937133
parentfe3bd75e5844c90a0d82c32d7c08782d5bf32f52 (diff)
Load tilemap or generation depending on dungeon flags
-rw-r--r--definitions.gbasm3
-rw-r--r--map/dungeons/morningforest.gbasm5
-rw-r--r--map/loading/dungeoninfos.gbasm73
-rw-r--r--map/loading/dungeontiles.gbasm7
-rw-r--r--map/loading/romtiles.gbasm18
-rw-r--r--modes/dungeongeneration.gbasm55
-rw-r--r--modes/maploading.gbasm183
-rw-r--r--modes/vblank_handler_list.gbasm4
8 files changed, 111 insertions, 237 deletions
diff --git a/definitions.gbasm b/definitions.gbasm
index d4695f9..60fcf2b 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -167,6 +167,9 @@
.DEFINE mem_prepared_block_tile $c05f ; Takes $c05f-$c062
.DEFINE mem_dungeon $c063 ; Takes $c063-$c065
+.DEFINE mem_dungeon_flags ($c066)
+
+.DEFINE mem_rom_collision_map_addr $c067 ; Takes $c067 to $c069 (bank + ptr)
; ## WARNING THE SPACE BETWEEN $c400 and $c800 is used as a buffer for the loading map function during dungeon generation
.DEFINE mem_map_loading_buffer $c400
diff --git a/map/dungeons/morningforest.gbasm b/map/dungeons/morningforest.gbasm
index 893ac57..3ee08e3 100644
--- a/map/dungeons/morningforest.gbasm
+++ b/map/dungeons/morningforest.gbasm
@@ -5,7 +5,10 @@ Morning_Forest:
.flag: .DB 0b00011110
- .tilemap_padding: .PADTO =.tilemap_padding+3
+ .tilemap_padding:
+ .DB bank(=_map_Test)
+ .DB ptr(=_map_Test)
+ ; .PADTO =.tilemap_padding+3
.generation_events.size:
.DB low(=.generation_events.end-=.generation_events)
diff --git a/map/loading/dungeoninfos.gbasm b/map/loading/dungeoninfos.gbasm
index 2b8fceb..c43a20b 100644
--- a/map/loading/dungeoninfos.gbasm
+++ b/map/loading/dungeoninfos.gbasm
@@ -1,4 +1,6 @@
-Load_Dungeon_Txt: ; pointer to Dungeon struct in HL, bank in A
+Load_Dungeon_Infos: ; pointer to Dungeon struct in HL, bank in A
+ ; Load_Dungeon_Txt
+ LD D, A
.CHANGE_BANK_TO_A
LD A, (HL+)
@@ -10,6 +12,7 @@ Load_Dungeon_Txt: ; pointer to Dungeon struct in HL, bank in A
LD A, E
.CHANGE_BANK_TO_A
+ PUSH HL
PUSH BC
LD H, B
LD L, C
@@ -29,6 +32,48 @@ Load_Dungeon_Txt: ; pointer to Dungeon struct in HL, bank in A
LD H, A
POP BC
CALL =Print_str
+ POP HL
+
+ LD A, D
+ .CHANGE_BANK_TO_A
+
+ ; Load dungeon flags
+ LD A, (HL+)
+ LD $mem_dungeon_flags, A
+
+ ; Load tilemap
+ LD A, (HL+)
+ LD ($mem_rom_tilemap_addr), A
+ LD ($mem_rom_collision_map_addr), A
+ LD A, (HL+)
+ LD B, A
+ LD A, (HL+)
+ LD ($mem_rom_collision_map_addr+2), A
+ ADD $80
+ LD ($mem_rom_tilemap_addr+2), A
+ LD A, B
+ LD ($mem_rom_collision_map_addr+1), A
+ ADC $00
+ LD ($mem_rom_tilemap_addr+1), A
+
+ ; Load_Generation_Events
+ LD A, D
+ .CHANGE_BANK_TO_A
+ LD B, $00
+ LD C, (HL)
+ INC HL
+ LD D, H
+ LD E, L
+ LD HL, $mem_dungeon_generation_events
+ CALL =memcpy
+
+ LD A, C
+ CPL
+ INC A
+ ADD $80
+ LD C, A
+
+ CALL =bzero
RET
@@ -104,29 +149,3 @@ Load_Dungeon_Spawn_patterns: ; pointer to Dungeon struct in HL bank in A
LD $mem_entity_spawning_pattern, A
RET
-
-Load_Generation_Events: ; bank in A, dungeon ptr in HL
- .CHANGE_BANK_TO_A
- LD A, L
- ADD $07
- LD L, A
- LD A, H
- ADC $00
- LD H, A
- LD B, $00
- LD C, (HL)
- INC HL
- LD D, H
- LD E, L
- LD HL, $mem_dungeon_generation_events
- CALL =memcpy
-
- LD A, C
- CPL
- INC A
- ADD $80
- LD C, A
-
- CALL =bzero
-
- RET
diff --git a/map/loading/dungeontiles.gbasm b/map/loading/dungeontiles.gbasm
index 5f91197..ad02ff1 100644
--- a/map/loading/dungeontiles.gbasm
+++ b/map/loading/dungeontiles.gbasm
@@ -166,11 +166,10 @@ Construct_Tile_Address: ; Construct Tile Map address from A and B in DE
RET
-Load_Block:
Load_Block_From_Solid: ; X in A, Y in B
- PUSH BC
- PUSH AF
- .After_AF_BC_Push:
+ .AF_AF_BC_Push:
+ POP AF
+ .AF_BC_Push:
PUSH DE
diff --git a/map/loading/romtiles.gbasm b/map/loading/romtiles.gbasm
index 989a201..e35a1e5 100644
--- a/map/loading/romtiles.gbasm
+++ b/map/loading/romtiles.gbasm
@@ -1,9 +1,17 @@
-Load_ROM_Block: ; X in A, Y in B
+Load_Block:
PUSH BC
PUSH AF
+ PUSH AF
+ LD A, $mem_dungeon_flags
+ AND $01
+ JP Z, =Load_Block_From_Solid.AF_AF_BC_Push
+ POP AF
+
+ .After_AF_BC_Push:
+
CP $20
- JP NC, =Load_Block_From_Solid.After_AF_BC_Push
+ JP NC, =Load_Block_From_Solid.AF_BC_Push
PUSH BC
LD C, A
@@ -11,14 +19,14 @@ Load_ROM_Block: ; X in A, Y in B
CP $20
LD A, C
POP BC
- JP NC, =Load_Block_From_Solid.After_AF_BC_Push
+ JP NC, =Load_Block_From_Solid.AF_BC_Push
+Load_ROM_Block: ; X in A, Y in B
PUSH DE
PUSH HL
LD C, A
-
CALL =Construct_Tile_Address
LD A, $mem_map_loading_flags
@@ -42,8 +50,6 @@ Load_ROM_Block: ; X in A, Y in B
OR C
LD C, A
- DBG
-
LD A, L
ADD C
LD L, A
diff --git a/modes/dungeongeneration.gbasm b/modes/dungeongeneration.gbasm
index b9d40ef..522ab1a 100644
--- a/modes/dungeongeneration.gbasm
+++ b/modes/dungeongeneration.gbasm
@@ -36,14 +36,7 @@ New_Dungeon:
LD A, ($mem_dungeon+2)
LD L, A
LD A, ($mem_dungeon)
- CALL =Load_Dungeon_Txt
-
- LD A, ($mem_dungeon+1)
- LD H, A
- LD A, ($mem_dungeon+2)
- LD L, A
- LD A, ($mem_dungeon)
- CALL =Load_Generation_Events
+ CALL =Load_Dungeon_Infos
New_Floor:
LD SP, $fffe
@@ -81,9 +74,47 @@ New_Floor:
LD $mem_loaded_special_entity_index, A
CALL =Reload_EP_Cost
- CALL =Dungeon_Generation
- CALL =Initialize_Entities
- CALL =Initialize_Objects
+
+ 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
@@ -178,7 +209,7 @@ Dungeon_generation_VBlank:
Dungeon_generation_Out_Of_VBlank:
PUSH AF
- CALL =VBlank_Wait
+ CALL =VBlank_Wait
.ENABLE_MODE_2_INTERRUPT
.RESET_INTERRUPTS
POP AF
diff --git a/modes/maploading.gbasm b/modes/maploading.gbasm
deleted file mode 100644
index ab8ecbe..0000000
--- a/modes/maploading.gbasm
+++ /dev/null
@@ -1,183 +0,0 @@
-; 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(=Map_Loading_Out_Of_VBlank)
- LD ($mem_stat_jump_destination), A
- LD A, high(=Map_Loading_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 DISABLE_MODE_2_INTERRUPT
- LD A, $00
- LD $reg_lcd_status, A
- LD A, $00
- LD $reg_interrupt_enable, A
-.END
-
-Map_Loading:
- 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 A, ($mem_dungeon+1)
- LD H, A
- LD A, ($mem_dungeon+2)
- LD L, A
- LD A, ($mem_dungeon)
- CALL =Load_Dungeon_Txt
-
- LD A, $f4
- LD ($9ecb), A
-
- LD HL, $9ec9
- LD A, $mem_floor_count
- CALL =Print_8bit
-
- LD A, $07
- LD $reg_bg_palette, A
-
- LD A, $lcdc_guibg_tilemap
- LD $reg_lcd_controller, A
-
- CALL =Reset_Map
-
- .LOAD_BANK_OF =_map_Test
- LD HL, $mem_dungeon_map
- LD BC, $0080
- LD DE, ptr(=_map_Test)
- CALL =memcpy
-
- 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 B, $0f
- LD C, $0f
- CALL =Initialize_Bunny
-
- LD HL, $mem_entities_list
- CALL =Center_viewport_around_entity
-
- LD A, $mem_map_loading_flags
- OR $01
- LD $mem_map_loading_flags, A
-
- LD HL, $mem_object_list
- LD BC, $0080
- CALL =bff
-
- ; 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
-
- CALL =VBlank_Wait
-
-Map_Loading_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 =Update_VBlank_Handler
-
- DI
- .DISABLE_MODE_2_INTERRUPT
-
- CALL =Reset_Entities_Collision_Map
-
- .ENABLE_VBLANK_INTERRUPTS
- .RESET_INTERRUPTS
- EI
-
- .Wait_for_Interrupt.loop:
- LD A, $reg_lcd_status
- HALT
- JP =.Wait_for_Interrupt.loop
-
-Map_Loading_Out_Of_VBlank:
- PUSH AF
- CALL =VBlank_Wait
- .ENABLE_MODE_2_INTERRUPT
- .RESET_INTERRUPTS
- POP AF
- RETI
diff --git a/modes/vblank_handler_list.gbasm b/modes/vblank_handler_list.gbasm
index 004c782..cacbdf7 100644
--- a/modes/vblank_handler_list.gbasm
+++ b/modes/vblank_handler_list.gbasm
@@ -29,11 +29,7 @@ VBlank_Handler_List:
; 3 (new floor)
.DB =New_Floor
- ; 4 (pregenerated map loading)
- .DB =Map_Loading
-
.INCLUDE "modes/dialoguemenu.gbasm"
.INCLUDE "modes/dungeon.gbasm"
.INCLUDE "modes/loading.gbasm"
.INCLUDE "modes/dungeongeneration.gbasm"
-.INCLUDE "modes/maploading.gbasm"