aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-04-08 13:13:21 +0200
committerAstatin <[email protected]>2025-04-08 13:13:21 +0200
commit85c478d0c2368c0a38fa3e6aa4d4e9070ea63fc3 (patch)
treebebf24df46c6520f27f70c2fc932bc132d252e63
parentfb8e853fd0c6660696e762f67877b4d24a9f4c22 (diff)
Add loading screen with the floor count on dungeon generation
-rw-r--r--definitions.gbasm7
-rw-r--r--main.gbasm7
-rw-r--r--map/loading.gbasm6
-rw-r--r--map/objects.gbasm19
-rw-r--r--modes/dungeongeneration.gbasm108
-rw-r--r--modes/vblank_handler_list.gbasm3
-rw-r--r--text.gbasm2
-rw-r--r--text.gbtxt2
-rw-r--r--utils.gbasm15
9 files changed, 141 insertions, 28 deletions
diff --git a/definitions.gbasm b/definitions.gbasm
index 3bb4c60..7c22ec2 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -72,13 +72,13 @@
.DEFINE mem_current_mode ($c014)
.DEFINE mem_requested_mode ($c015)
; bit 0-3: which vblank handler group
-; bit 7: setp if map, objects and gui update are frozen
.DEFINE enum_dungeon_mode $00
.DEFINE enum_dead_mode $10
.DEFINE enum_dungeon_menu_mode $01
.DEFINE enum_dungeon_dialogue_mode $11
.DEFINE enum_loading_mode $02
.DEFINE enum_animation_wait_mode $12
+.DEFINE enum_dungeon_generation_mode $03
.DEFINE mem_menu_cursor_position ($c016)
.DEFINE mem_last_button_direction ($c017)
@@ -138,6 +138,9 @@
.DEFINE mem_stat_jump_instruction $c044 ; takes from c044 to c046
.DEFINE mem_stat_jump_destination $c045 ; takes from c045 to c046
+; ## 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
+
.DEFINE mem_next_free_head_lower_bytes ($c6ff)
.DEFINE mem_dungeon_generation_heads $c700 ; Takes the memory from c700 to c717
@@ -150,6 +153,8 @@
; a bit of 1 is equivalent to an entity being on the tile
.DEFINE mem_entities_collisions $c780 ; Takes the memory from c780 to c7ff
+; ## END OF THE LOADING MAP FUNCTION
+
; a bit of 1 is equivalent to the tile being free
.DEFINE mem_dungeon_map $c800 ; Takes the memory from c800 to c87f
diff --git a/main.gbasm b/main.gbasm
index a8a28ce..21b9420 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -84,10 +84,10 @@
LD A, high(=STAT_Entrypoint)
LD ($mem_stat_jump_destination+1), A
.RESET_STAT_INTERRUPT
- LD A, $02
- LD $reg_interrupt_enable, A
LD A, $40
LD $reg_lcd_status, A
+ LD A, $02
+ LD $reg_interrupt_enable, A
.END
.MACRODEF DISABLE_LYC_INTERRUPT
@@ -106,8 +106,9 @@ Entrypoint:
LD $mem_floor_count, A
CALL =Init_DemoQuest_Event
+ CALL =Load_Tile
+
JP =New_Dungeon
-
.INCLUDE "tiles.gbasm"
.INCLUDE "rng.gbasm"
diff --git a/map/loading.gbasm b/map/loading.gbasm
index 505bc53..878d0e1 100644
--- a/map/loading.gbasm
+++ b/map/loading.gbasm
@@ -1,4 +1,4 @@
-Load_Map:
+Load_Prepared_Map:
LD A, $mem_viewport_x
SUB $02
LD C, A
@@ -13,6 +13,10 @@ Load_Map:
.For_X:
LD A, C
CALL =Load_Block
+ LD A, $mem_prepared_block_position_1
+ SUB $98
+ ADD $c4
+ LD $mem_prepared_block_position_1, A
CALL =Display_Main_Prepared_Block
INC C
diff --git a/map/objects.gbasm b/map/objects.gbasm
index 80832a7..ae2b60f 100644
--- a/map/objects.gbasm
+++ b/map/objects.gbasm
@@ -142,18 +142,10 @@ Object_Interaction_Jump_table:
JP =Restore_EP_Action
Stairs_Action:
- DI
- LD A, $00
- LD $reg_interrupt_flags, A
- .Wait_VBlank:
- LD A, $reg_lcd_status
- AND $03
- CP $01
- JR NZ, =.Wait_VBlank
-
- ; LCDC
- XOR A
- LD $reg_lcd_controller, A
+ LD A, $enum_dungeon_generation_mode
+ LD $mem_current_mode, A
+ LD $mem_requested_mode, A
+ CALL =Update_VBlank_Handler
LD A, $mem_floor_count
INC A
@@ -163,8 +155,7 @@ Stairs_Action:
LD $mem_floor_count, A
.skip_update_floor_count:
- CALL =Reset_Map
- JP =New_Dungeon
+ RET
Heal_Action:
LD A, $mem_bunny_health
diff --git a/modes/dungeongeneration.gbasm b/modes/dungeongeneration.gbasm
index 9576e6d..1588e81 100644
--- a/modes/dungeongeneration.gbasm
+++ b/modes/dungeongeneration.gbasm
@@ -2,8 +2,68 @@
; 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
@@ -33,6 +93,11 @@ New_Dungeon:
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
@@ -51,7 +116,18 @@ New_Dungeon:
LD A, $enum_dungeon_mode
LD $mem_current_mode, A
LD $mem_requested_mode, A
- CALL =Update_VBlank_Handler
+
+ 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
@@ -65,29 +141,43 @@ New_Dungeon:
LD A, $f4
LD ($9d73), A
- CALL =Generation_Event_Execution
-
CALL =Reload_Entities_Tile_Data
- CALL =Reset_Entities_Collision_Map
-
; Clear OAM
LD HL, $fe00
LD BC, $00a0
CALL =bzero
- CALL =Load_Tile
- CALL =Load_Map
+ 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_TOP_BAR
.ENABLE_VBLANK_INTERRUPTS
+ .RESET_STAT_INTERRUPT
+ LD A, $00
+ LD $reg_interrupt_flags, A
EI
+
Wait_for_Interrupt.loop:
HALT
- EI
JP =Wait_for_Interrupt.loop
+
+Dungeon_generation_Out_Of_VBlank:
+ PUSH AF
+ CALL =VBlank_Wait
+ .ENABLE_MODE_2_INTERRUPT
+ POP AF
+ RETI
diff --git a/modes/vblank_handler_list.gbasm b/modes/vblank_handler_list.gbasm
index 61f0836..768147f 100644
--- a/modes/vblank_handler_list.gbasm
+++ b/modes/vblank_handler_list.gbasm
@@ -26,6 +26,9 @@ VBlank_Handler_List:
; 2 (loading, animation)
.DB =Loading_VBLANK_Entrypoint
+ ; 3 (new dungeon)
+ .DB =New_Dungeon
+
.INCLUDE "modes/dialoguemenu.gbasm"
.INCLUDE "modes/dungeon.gbasm"
.INCLUDE "modes/loading.gbasm"
diff --git a/text.gbasm b/text.gbasm
index 22ce9d2..358dbf9 100644
--- a/text.gbasm
+++ b/text.gbasm
@@ -6,3 +6,5 @@ Freeze_Attack_Menu_Txt:
.DB 0x8f, 0x9b, 0x8e, 0x8e, 0xa3, 0x8e, 0xff
Earcoptr_Attack_Menu_Txt:
.DB 0x8e, 0x8a, 0x9b, 0x8c, 0x98, 0x99, 0x9d, 0x9b, 0xff
+Dungeon_Name_1_Txt:
+.DB 0x96, 0x98, 0x9b, 0x97, 0x92, 0x97, 0x90, 0x0, 0x8f, 0x98, 0x9b, 0x8e, 0x9c, 0x9d, 0xff
diff --git a/text.gbtxt b/text.gbtxt
index 546b64f..1dfad52 100644
--- a/text.gbtxt
+++ b/text.gbtxt
@@ -2,3 +2,5 @@ Hop_Attack_Menu_Txt: Hop
Heal_Attack_Menu_Txt: Heal
Freeze_Attack_Menu_Txt: Freeze
Earcoptr_Attack_Menu_Txt: Earcoptr
+
+Dungeon_Name_1_Txt: Morning Forest
diff --git a/utils.gbasm b/utils.gbasm
index fe03152..ba808bd 100644
--- a/utils.gbasm
+++ b/utils.gbasm
@@ -217,6 +217,21 @@ Print_str: ; Memory Tilemap position in HL, Text address in BC, FF ended
POP AF
RET
+strlen: ; Text address in HL, FF ended. Result in A
+ PUSH HL
+ PUSH BC
+ .loop:
+ LD A, (HL+)
+ CP $FF
+ JR Z, =.end
+ INC B
+ JR =.loop
+ .end:
+ LD A, B
+ POP BC
+ POP HL
+ RET
+
MUL: ; B x C => EA
XOR A
LD E, $00