aboutsummaryrefslogtreecommitdiff
path: root/modes
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-03-25 19:01:47 +0900
committerAstatin <[email protected]>2025-03-25 19:01:47 +0900
commitfb8e853fd0c6660696e762f67877b4d24a9f4c22 (patch)
tree4c2c69bd5e13bebfe02534541e4adcf2b67f335f /modes
parent2df3daa5128a27381fe5208fa4eac59ab10bdd9c (diff)
Separate modes VBlank functions
Diffstat (limited to 'modes')
-rw-r--r--modes/dialoguemenu.gbasm39
-rw-r--r--modes/dungeon.gbasm172
-rw-r--r--modes/dungeongeneration.gbasm93
-rw-r--r--modes/loading.gbasm36
-rw-r--r--modes/vblank_handler_list.gbasm32
5 files changed, 372 insertions, 0 deletions
diff --git a/modes/dialoguemenu.gbasm b/modes/dialoguemenu.gbasm
new file mode 100644
index 0000000..5138c40
--- /dev/null
+++ b/modes/dialoguemenu.gbasm
@@ -0,0 +1,39 @@
+Dialogue_VBLANK_Entrypoint:
+ .SET_WINDOW_LCDC_E
+ .ENABLE_TOP_BAR
+
+ LD A, $palette_bold_font
+ LD $reg_bg_palette, A
+
+ CALL $OAM_DMA_Transfer_routine
+
+ CALL =Dialogue_Arrow_Animation
+ CALL =Copy_Dialogue_Buffer
+ CALL =Display_dialogue_cursor
+
+ ; LYC
+ LD A, $0a
+ LD $reg_lyc, A
+ .ENABLE_LYC_INTERRUPT
+ .RESET_STAT_INTERRUPT
+ EI
+
+ CALL =Pad_Button_Check
+
+ CALL =Update_Blinking_Counter
+ CALL =Update_Animation_Steps
+ CALL =Open_dialogue_on_dungeon_menu_mode
+ CALL =Move_dialogue_cursor
+ CALL =Check_dialogue_action
+
+ LD A, $00
+ LD $mem_oam_buffer_low, A
+ CALL =Display_Animation_List
+ CALL =Display_Entities
+
+ LD A, $mem_loop_frame_timer
+ INC A
+ LD $mem_loop_frame_timer, A
+
+ .ENABLE_VBLANK_INTERRUPTS
+ RETI
diff --git a/modes/dungeon.gbasm b/modes/dungeon.gbasm
new file mode 100644
index 0000000..41fc11d
--- /dev/null
+++ b/modes/dungeon.gbasm
@@ -0,0 +1,172 @@
+Update_Blinking_Counter:
+ LD A, $mem_blinking_animation_counter
+ DEC A
+ CP $ff
+ RET Z
+ LD $mem_blinking_animation_counter, A
+ RET
+
+Update_Animation_Steps:
+ LD A, $mem_map_loading_flags
+ BIT 3, A
+ JR Z, =.update_mode
+
+ LD A, $mem_moving_animation_step
+ INC A
+ AND $0f
+ LD $mem_moving_animation_step, A
+
+ CP $00
+ JR NZ, =.end
+
+ LD A, $mem_map_loading_flags
+ RES 3, A
+ SET 1, A
+ LD $mem_map_loading_flags, A
+
+ .update_mode:
+
+ ; We need to make sure that the mode doesn't change to a mode with objects update while a dialogue box refresh is currently being done
+ LD A, $mem_current_mode
+ BIT 7, A
+ JR Z, =.set_current_mode
+ LD A, $mem_display_flag
+ AND 0b00010100
+ CP $00
+ JR NZ, =.end
+
+ .set_current_mode:
+ LD A, $mem_requested_mode
+ LD $mem_current_mode, A
+ CALL =Update_VBlank_Handler
+
+ .end:
+ LD A, $mem_bunny_health
+ CP $00
+ RET NZ
+ LD A, $mem_moving_animation_step
+ CP $00
+ RET NZ
+
+ .Dead_mode:
+
+ LD A, $20
+ LD $mem_bunny_direction, A
+
+ LD A, $enum_dead_mode
+ LD $mem_current_mode, A
+ CALL =Update_VBlank_Handler
+
+ .CLOSE_DIALOGUE
+
+ RET
+
+STAT_Entrypoint:
+ PUSH AF
+ PUSH DE
+ .SET_WINDOW_LCDC_E
+
+ LD A, $reg_lyc
+ CP $0a
+ JR Z, =.End_Top_Bar
+ CP $67
+ JR Z, =.Start_dialogue
+ .Thin_font:
+ LD A, $palette_thin_font
+ LD $reg_bg_palette, A
+ JR =.skip_dialogue
+
+ .Start_dialogue:
+ LD A, $mem_display_flag
+ BIT 0, A
+ JR Z, =.skip_dialogue
+ .ENABLE_DIALOGUE
+ LD A, $mem_display_flag
+ BIT 1, A
+ JR Z, =.Thin_font
+ LD A, $palette_bold_font
+ LD $reg_bg_palette, A
+ LD A, $77
+ LD $reg_lyc, A
+ .RESET_STAT_INTERRUPT
+ POP DE
+ POP AF
+ RETI
+
+ .skip_dialogue:
+ .DISABLE_LYC_INTERRUPT
+ POP DE
+ POP AF
+ RETI
+
+ .End_Top_Bar:
+ .DISABLE_DIALOGUE
+ LD A, $67
+ LD $reg_lyc, A
+ .RESET_STAT_INTERRUPT
+ POP DE
+ POP AF
+ RETI
+
+Dungeon_VBLANK_Entrypoint:
+ .SET_WINDOW_LCDC_E
+ .ENABLE_TOP_BAR
+
+ LD A, $palette_bold_font
+ LD $reg_bg_palette, A
+
+ CALL $OAM_DMA_Transfer_routine
+
+ LD A, $mem_current_mode
+ BIT 7, A
+ JR NZ, =Skip_VBlank_Dungeon_Update
+ LD HL, $9d60
+ LD A, $mem_bunny_health
+ CALL =Print_8bit
+
+ LD HL, $9d64
+ LD A, $mem_bunny_mana
+ CALL =Print_8bit
+
+ CALL =Display_Prepared_Blocks
+ CALL =Display_Object
+ Skip_VBlank_Dungeon_Update:
+
+ ; LYC
+ LD A, $0a
+ LD $reg_lyc, A
+ .ENABLE_LYC_INTERRUPT
+ .RESET_STAT_INTERRUPT
+ EI
+
+ CALL =Pad_Button_Check
+ CALL =Load_Additional_Block
+
+ LD A, $mem_current_mode
+ CP $enum_dungeon_mode
+ JR NZ, =Skip_Dungeon_Update
+
+ CALL =Entities_Actions
+ CALL =Object_Interactions_Check
+ CALL =Respawn_Entities
+ CALL =Prepare_Scrolling_Map
+
+ Skip_Dungeon_Update:
+ LD A, $mem_current_mode
+
+ CALL =Animation_Wait_Mode
+ CALL =Update_Blinking_Counter
+ CALL =Update_Animation_Steps
+ CALL =Check_Open_Menu_button
+
+ LD A, $00
+ LD $mem_oam_buffer_low, A
+ CALL =Display_Animation_List
+ CALL =Display_Entities
+
+ LD A, $mem_loop_frame_timer
+ INC A
+ LD $mem_loop_frame_timer, A
+
+ .ENABLE_VBLANK_INTERRUPTS
+ RETI
diff --git a/modes/dungeongeneration.gbasm b/modes/dungeongeneration.gbasm
new file mode 100644
index 0000000..9576e6d
--- /dev/null
+++ b/modes/dungeongeneration.gbasm
@@ -0,0 +1,93 @@
+; 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
+
+New_Dungeon:
+ LD SP, $fffe
+ 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
+
+ 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
+ CALL =Update_VBlank_Handler
+
+ ; Heart
+ LD A, $f0
+ LD ($9d62), A
+
+ ; Energy points
+ LD A, $f1
+ LD ($9d66), A
+
+ ; Floor
+ 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
+ CALL =Load_Objects
+
+ LD HL, $9d71
+ LD A, $mem_floor_count
+ CALL =Print_8bit
+
+ .SET_WINDOW_LCDC_E
+ .ENABLE_TOP_BAR
+ .ENABLE_VBLANK_INTERRUPTS
+ EI
+ Wait_for_Interrupt.loop:
+ HALT
+ EI
+ JP =Wait_for_Interrupt.loop
diff --git a/modes/loading.gbasm b/modes/loading.gbasm
new file mode 100644
index 0000000..dea6e89
--- /dev/null
+++ b/modes/loading.gbasm
@@ -0,0 +1,36 @@
+Loading_VBLANK_Entrypoint:
+ .SET_WINDOW_LCDC_E
+ .ENABLE_TOP_BAR
+
+ LD A, $palette_bold_font
+ LD $reg_bg_palette, A
+
+ CALL $OAM_DMA_Transfer_routine
+ CALL =Loading_Mode_VBlank
+
+ ; LYC
+ LD A, $0a
+ LD $reg_lyc, A
+ .ENABLE_LYC_INTERRUPT
+ .RESET_STAT_INTERRUPT
+ EI
+
+ CALL =Pad_Button_Check
+ CALL =Load_Additional_Block
+
+ CALL =Animation_Wait_Mode
+ CALL =Update_Blinking_Counter
+ CALL =Update_Animation_Steps
+ CALL =Loading_Mode_Regular
+
+ LD A, $00
+ LD $mem_oam_buffer_low, A
+ CALL =Display_Animation_List
+ CALL =Display_Entities
+
+ LD A, $mem_loop_frame_timer
+ INC A
+ LD $mem_loop_frame_timer, A
+
+ .ENABLE_VBLANK_INTERRUPTS
+ RETI
diff --git a/modes/vblank_handler_list.gbasm b/modes/vblank_handler_list.gbasm
new file mode 100644
index 0000000..61f0836
--- /dev/null
+++ b/modes/vblank_handler_list.gbasm
@@ -0,0 +1,32 @@
+Update_VBlank_Handler:
+ PUSH HL
+ LD A, $mem_current_mode
+ AND $0f
+ SLA A
+ LD HL, =VBlank_Handler_List
+ ADD L
+ LD L, A
+ LD A, $00
+ ADC H
+ LD H, A
+ LD A, (HL+)
+ LD ($mem_vblank_jump_destination+1), A
+ LD A, (HL)
+ LD ($mem_vblank_jump_destination), A
+ POP HL
+ RET
+
+VBlank_Handler_List:
+ ; 0 (dungeon, dead)
+ .DB =Dungeon_VBLANK_Entrypoint
+
+ ; 1 (dungeon dialogue, menu)
+ .DB =Dialogue_VBLANK_Entrypoint
+
+ ; 2 (loading, animation)
+ .DB =Loading_VBLANK_Entrypoint
+
+.INCLUDE "modes/dialoguemenu.gbasm"
+.INCLUDE "modes/dungeon.gbasm"
+.INCLUDE "modes/loading.gbasm"
+.INCLUDE "modes/dungeongeneration.gbasm"