Made vram access more secure when loading maps.
authorLukas Krickl <lukas@krickl.dev>
Tue, 24 Dec 2024 13:10:23 +0000 (14:10 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 24 Dec 2024 13:10:23 +0000 (14:10 +0100)
A row is now guaranteed to wait for the *next* vblank
before proceeding to draw.

Additionall we are now disabling objects when drawing a new room.

src/map.s
src/mem.s
src/video.s

index 9de9f4ddc3990cf1f372e0af28a261025978e864..874aab817b2b2d932d18b9f82bcf1bc91a055a7d 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -155,12 +155,15 @@ room_goto_player_pos:
   ;   curr_room_exits: ptr to exits table
   ;   a: direction EAST, WEST, NORTH, SOUTH, EXIT_SPECIAL
 room_goto:
+  ; TODO: save current tables back 
   ; save a for later
   push af
-
-  ; TODO: save current tables back 
   call disableinterrutpts
-  call vblank_wait
+
+  ; disable objects 
+  ld a, LCDCF_ON | LCDCF_BGON | LCDF_OBJ_SIZE
+  ld [RLCD], a
+
   ;call lcd_off
 
 
@@ -189,8 +192,15 @@ room_goto:
   ; its player's turn again
   ld a, WHO_PLAYER
   ld [who], a 
-  
-  ;call lcd_on
+  ; restore palette
+  ld a, BGP
+  ld [RBGP], a
+
+  ; clear soam 
+  call shadow_oam_clear
+
+  call lcd_on
   call enableinterrupts
 
   ret
@@ -246,7 +256,7 @@ room_row_draw:
   ; wait for vlbank for every row if the screen is not off
   ld a, [RLCD]
   cp a, 0
-  call nz, vblank_wait
+  call nz, next_vblank_wait
 
   ld b, ROOM_W
 
@@ -288,7 +298,7 @@ room_row_draw:
   ; wait for vlbank for every row if the screen is not off
   ld a, [RLCD]
   cp a, 0
-  call nz, vblank_wait
+  call nz, next_vblank_wait
 
   ; almost the same loop again
   ; for the second row
index 7ca3754d45a969f57be5eb7046693441a2b31cb8..fc66033e53e7c340ccffa928695130b2bcedaa9c 100644 (file)
--- a/src/mem.s
+++ b/src/mem.s
@@ -57,6 +57,12 @@ memset:
   jp nz, @loop
   ret
 
+shadow_oam_clear:
+  ld bc, OBJSMAX * oamsize
+  ld hl, shadow_oam
+  ld d, 0
+  jp memset
+
 
 ; dma shadow oam to oam
 ; registers:
index d80eb5d70426caaf197278efb0e8c58835ad2b62..a81f6bd57846afcc2c88eae15abe33b640d2a933 100644 (file)
@@ -59,6 +59,17 @@ vblank_wait:
   jp c, vblank_wait
   ret
 
+not_vblank_wait:
+  ld a, [RLY]
+  cp a, 1
+  jp nz, not_vblank_wait
+  ret
+
+next_vblank_wait:
+  call not_vblank_wait
+  jp vblank_wait
+  
+
   ; turns off the lcd
 lcd_off:
   ; *never* turn off LCD without waiting