map: Fixed map load corrupting video memory
authorLukas Krickl <lukas@krickl.dev>
Sat, 5 Jul 2025 18:57:27 +0000 (20:57 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 5 Jul 2025 18:57:27 +0000 (20:57 +0200)
Map loads now always disable interrupts and the lcd.

In the future maybe we should only disable lcd if we are swapping out
 tilesets.
During a map load it would probably be enough to wait for blank
for each row of tiles loaded.

src/main.s
src/map.s

index 946003ea5ecac942668adea932a71d4438568849..1de729003281af36636de196221a1635d348758c 100644 (file)
@@ -23,12 +23,14 @@ entry:
   call video_init
   call audio_init
   
-  call map_init
 
   call lcd_on
   call vblank_wait
 
   call enableinterrupts
+  
+  ; init initial map
+  call map_init
 
   ; main for gameply
 #ifndef TEST_BUILD
index 76897f1c84685099b73392dd65d0201f8a58f228..a098b966b4ba36d28efbabe710e796bc7af6711c 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -6,7 +6,18 @@ map_init:
   ; loads a new map
   ; inputs:
   ;   hl: map ptr
+  ; disables and enables interrupts
+  ; and lcd
+  ; TODO: do not touch lcd or interrupts if 
+  ; they were not enabled!
 map_load:
+  ; disable interruts
+  ; wait for next blank
+  ; disable lcd
+  call disableinterrutpts
+  call next_vblank_wait 
+  call lcd_off
+  
   push hl
   call map_draw_area_title
   pop hl
@@ -33,6 +44,11 @@ map_load:
 
   call map_draw_all
 
+  ; restore lcd and interrupts
+  call lcd_on
+  call vblank_wait
+  call enableinterrupts
+
   ret
 
   ; draws map title to UI (SCRN1)