aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2024-08-29 16:14:35 +0900
committerAstatin <astatin@redacted>2024-08-29 16:14:35 +0900
commit522bde7b7e7d70fc86a5dac2042b7b20e05c197b (patch)
tree01d3f81170c91debdf0784fa5c6255955730cd80
parent4a4ff1db8fe026ced0530f8c2531033da43164e6 (diff)
Fix issues related to VBlank wait in sameboy + Add stairs interactions
-rw-r--r--bunny.gbasm6
-rw-r--r--definitions.gbasm1
-rw-r--r--init.gbasm9
-rw-r--r--main.gbasm5
-rw-r--r--map/loading.gbasm61
-rw-r--r--map/objects.gbasm77
-rw-r--r--utils.gbasm14
7 files changed, 141 insertions, 32 deletions
diff --git a/bunny.gbasm b/bunny.gbasm
index 9ba996b..b76c9fa 100644
--- a/bunny.gbasm
+++ b/bunny.gbasm
@@ -57,7 +57,7 @@ Fix_Bunny_screen:
RET
Move_Bunny:
- LD C, $00 ; (bit 0 = has_scrolled)
+ LD C, $00 ; (bit 0 = has_scrolled, bit 1 = has ended movement)
LD A, $mem_moving_sprite_direction
CP $00
JR NZ, =Move_Bunny.check_direction
@@ -155,6 +155,7 @@ Move_Bunny:
AND $0f
LD $mem_moving_animation_step, A
JR NZ, =Move_Bunny.end
+ SET 1, C
LD $mem_moving_sprite_direction, A
LD A, $mem_sprite_direction
DEC A
@@ -168,7 +169,6 @@ Move_Bunny:
LD A, $mem_viewport_x
ADD B
LD $mem_viewport_x, A
- CALL =Load_Column
Move_Bunny.horizontal_tile_move.move_viewport_end:
LD A, $mem_bunny_x
ADD B
@@ -181,7 +181,6 @@ Move_Bunny:
LD A, $mem_viewport_y
ADD B
LD $mem_viewport_y, A
- CALL =Load_Row
Move_Bunny.vertical_tile_move.move_viewport_end:
LD A, $mem_bunny_y
ADD B
@@ -250,6 +249,7 @@ Display_Bunny:
; First OBJ (left)
LD HL, $FE00
LD A, C
+ CALL =VBlank_Wait
LD (HL+), A
LD A, B
LD (HL+), A
diff --git a/definitions.gbasm b/definitions.gbasm
index 745136a..d2f9b8b 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -28,6 +28,7 @@
.DEFINE mem_map_loading_flags ($c00c)
; bit 0: if the object should be reloaded (scroll or first load)
+; bit 1: if the interactions should be checked (at the end of a movement)
.DEFINE next_free_head_higher_bytes $c7
.DEFINE mem_next_free_head_lower_bytes ($c6ff)
diff --git a/init.gbasm b/init.gbasm
index ac9b67b..e160727 100644
--- a/init.gbasm
+++ b/init.gbasm
@@ -21,6 +21,9 @@ Checksum: ; The bytes 0x134-0x14d need to add up to 0xe7 (= 0xff - 0x19)
.DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$e7
Initialize_RAM:
+; Disable Interrupts
+LD A, $00
+LD $reg_interrupt_enable, A
Empty_WRAM:
LD HL, $C000
Empty_WRAM.loop:
@@ -30,11 +33,7 @@ Empty_WRAM:
CP h
JR NZ, =Empty_WRAM.loop
-Wait_VBlank:
- LD A, $reg_lcd_status
- AND $03
- CP $01
- JR NZ, =Wait_VBlank
+ CALL =VBlank_Wait
; LCDC
XOR A
diff --git a/main.gbasm b/main.gbasm
index 7fc2cd1..4fe24a0 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -3,6 +3,8 @@
Entrypoint:
CALL =Initialize_RNG
+New_Dungeon:
+ LD SP, $fffe
CALL =Dungeon_Generation
CALL =Initialize_Bunny
CALL =Initialize_Objects
@@ -20,8 +22,11 @@ Entrypoint:
VBLANK_Entrypoint:
CALL =Display_Bunny
+ CALL =Display_Scrolling_Map
CALL =Display_Objects
+ CALL =Object_Interactions_Check
+
CALL =Pad_Button_Check
CALL =Move_Bunny
diff --git a/map/loading.gbasm b/map/loading.gbasm
index bb3410b..a7783c8 100644
--- a/map/loading.gbasm
+++ b/map/loading.gbasm
@@ -48,17 +48,14 @@ Load_Row: ; (+1/-1 direction in B)
LD A, $mem_viewport_x
SUB $03
LD D, A
+ LD A, $mem_moving_animation_step
+ ADD D
+ LD D, A
LD A, $mem_viewport_x
ADD $0D
LD E, A
- Load_Row.For_X:
- LD A, D
- CALL =Load_Block
-
- INC D
- LD A, D
- CP E
- JR NZ, =Load_Row.For_X
+ LD A, D
+ CALL =Load_Block
POP DE
POP BC
@@ -90,20 +87,44 @@ Load_Column: ; (+1/-1 direction in B)
LD A, $mem_viewport_y
ADD $0D
LD E, A
- Load_Column.For_Y:
- LD A, D
- CALL =Load_Block
-
- INC B
- LD A, B
- CP E
- JR NZ, =Load_Column.For_Y
+ LD A, $mem_moving_animation_step
+ ADD B
+ LD B, A
+ LD A, D
+ CALL =Load_Block
POP DE
POP BC
POP AF
RET
+Display_Scrolling_Map:
+ LD A, $mem_map_loading_flags
+ BIT 0, A
+ JR Z, =Display_Scrolling_Map.End
+
+ LD A, $mem_moving_sprite_direction
+ DEC A
+ AND $01
+ SLA A
+ DEC A
+ LD B, A
+ LD A, $mem_moving_sprite_direction
+ DEC A
+
+ BIT 1, A
+ JR NZ, =Display_Scrolling_Map.vertical
+
+ Display_Scrolling_Map.horizontal:
+ CALL =Load_Column
+ JP =Display_Scrolling_Map.End
+
+ Display_Scrolling_Map.vertical:
+ CALL =Load_Row
+
+ Display_Scrolling_Map.End:
+ RET
+
Construct_Tile_Address: ; Construct Tile Map address from A and B in DE
PUSH AF
PUSH BC
@@ -197,41 +218,49 @@ Load_Block: ; X in A, Y in B
JR Z, =Load_Block.Empty
Load_Block.Solid:
LD A, C
+ CALL =VBlank_Wait
LD (DE), A
LD A, E
OR $20
LD E, A
LD A, C
OR $02
+ CALL =VBlank_Wait
LD (DE), A
INC E
LD A, C
OR $03
+ CALL =VBlank_Wait
LD (DE), A
LD A, E
AND $DF
LD E, A
LD A, C
OR $01
+ CALL =VBlank_Wait
LD (DE), A
JR =Load_Block.End
Load_Block.Empty:
LD A, $00
+ CALL =VBlank_Wait
LD (DE), A
LD A, E
OR $20
LD E, A
LD A, $00
+ CALL =VBlank_Wait
LD (DE), A
INC E
LD A, $00
+ CALL =VBlank_Wait
LD (DE), A
LD A, E
AND $DF
LD E, A
LD A, $00
+ CALL =VBlank_Wait
LD (DE), A
Load_Block.End:
diff --git a/map/objects.gbasm b/map/objects.gbasm
index da80118..bfaa903 100644
--- a/map/objects.gbasm
+++ b/map/objects.gbasm
@@ -45,17 +45,25 @@ Initialize_Objects:
RET
Stairs_action:
- LD A, $00
- LD $mem_bunny_x, A
- LD A, $00
- LD $mem_bunny_y, A
- CALL =Fix_Bunny_screen
- RET
+ Stairs_action.Wait_VBlank:
+ LD A, $reg_lcd_status
+ AND $03
+ CP $01
+ JR NZ, =Stairs_action.Wait_VBlank
+
+ ; LCDC
+ XOR A
+ LD $reg_lcd_controller, A
+
+ JP =New_Dungeon
Display_Objects:
LD A, $mem_map_loading_flags
BIT 0, A
JR Z, =Display_Objects.End
+ LD A, $mem_moving_animation_step
+ CP $00
+ JR NZ, =Display_Objects.End
LD HL, $mem_object_list
Display_Objects.loop:
LD A, (HL+)
@@ -63,34 +71,44 @@ Display_Objects:
JR Z, =Display_Objects.next
LD C, A
LD A, (HL+)
+ ADD $80
LD D, A
LD A, $mem_viewport_x
- SUB $03
+ SUB $83
CP D
JR NC, =Display_Objects.next
ADD $10
CP D
JR C, =Display_Objects.next
+ LD A, D
+ SUB $80
+ LD D, A
LD A, (HL+)
+ ADD $80
LD B, A
LD A, $mem_viewport_y
- SUB $03
+ SUB $83
CP B
JR NC, =Display_Objects.next
ADD $10
CP B
JR C, =Display_Objects.next
+ LD A, B
+ SUB $80
+ LD B, A
LD A, D
CALL =Construct_Tile_Address
+ CALL =VBlank_Wait
LD A, C
LD (DE), A
INC E
INC C
+ CALL =VBlank_Wait
LD A, C
LD (DE), A
@@ -100,12 +118,14 @@ Display_Objects:
XOR $21
LD E, A
+ CALL =VBlank_Wait
LD A, C
LD (DE), A
INC C
INC E
+ CALL =VBlank_Wait
LD A, C
LD (DE), A
@@ -118,3 +138,44 @@ Display_Objects:
JR NZ, =Display_Objects.loop
Display_Objects.End:
RET
+
+Object_Interactions_Check:
+ LD A, $mem_map_loading_flags
+ BIT 1, A
+ JR Z, =Object_Interactions_Check.End
+ LD HL, $mem_object_list
+ LD A, $mem_bunny_x
+ LD C, A
+ LD A, $mem_bunny_y
+ LD B, A
+ Object_Interactions_Check.loop:
+ LD A, (HL+)
+ CP $00
+ JR Z, =Object_Interactions_Check.next
+
+ LD A, (HL+)
+ CP C
+ JR NZ, =Object_Interactions_Check.next
+
+ LD A, (HL+)
+ CP B
+ JR NZ, =Object_Interactions_Check.next
+
+ LD A, (HL+)
+ LD D, A
+ LD A, (HL+)
+ LD E, A
+
+ PUSH DE
+ RET
+
+ Object_Interactions_Check.next:
+ LD A, L
+ AND $f8
+ ADD $08
+ LD L, A
+ CP $80
+ JR NZ, =Object_Interactions_Check.loop
+
+ Object_Interactions_Check.End:
+ RET
diff --git a/utils.gbasm b/utils.gbasm
index babf7da..0f80ce8 100644
--- a/utils.gbasm
+++ b/utils.gbasm
@@ -95,3 +95,17 @@ MUL: ; B x C => EA
ADD C
MUL.bit0:
RET
+
+VBlank_Wait:
+ PUSH AF
+ LD A, $reg_lcd_controller
+ BIT 7, A
+ JR Z, =VBlank_Wait.End
+ VBlank_Wait.loop:
+ LD A, $reg_lcd_status
+ AND $03
+ CP $01
+ JR NZ, =VBlank_Wait.loop
+ VBlank_Wait.End:
+ POP AF
+ RET