video: vblank and not vblank wait not correctly disable interrpts
authorLukas Krickl <lukas@krickl.dev>
Mon, 14 Jul 2025 03:53:13 +0000 (05:53 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 14 Jul 2025 03:53:13 +0000 (05:53 +0200)
They ensure to restore IE as it was before they were called.
This makes sure the vblank handler does not cause the wait loop to miss
its condition. This resulted in an infinite loop under certain
conditions.

src/defs.s
src/strings.s
src/ui.s
src/video.s

index 9cdea2b6a09b5f94edbb61e01201620b5c8a2c92..515964cfcf74a2cd8a7f9ffcbfd48f8cc84e10a8 100644 (file)
 .de act_size, 0
   
   ; max bge queue size
-#define BGE_MAX 10
+#define BGE_MAX 16
 
   ; max bg updates per frame
 #define BG_UPDATE_MAX 8 
index b737d26b928656084e738687dc03d12d4a29e3e1..25db42ca4e271a665ffcfe93858ba44c5bd032eb 100644 (file)
@@ -23,6 +23,10 @@ STR_GAME_OVER:
 
 STR_PANIC:
 .str "PANIC"
+.db 0
+
+STR_TEST:
+.str "0123456789ABCDEF"
 .db 0
 
   ; print a 0-terminated string to the screen 
index fe10268e94a3fba91c2d2b59536cb89911c974e7..029505aa086fb97aa5216ca0ed675f407b330186 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -14,7 +14,7 @@ ui_init:
   
   ; updates HP UI
 ui_redraw_hp:
-  ld hl, STR_TITLE
+  ld hl, STR_TEST
   ld de, SCRN1 + 34
   call bputs
 
index 635c4b20537038d023489c39ebc8b500debacf0d..b17e8134b607531d2783cd72cbd136930fbf3ada 100644 (file)
@@ -49,15 +49,39 @@ scroll_write:
 
   ; wait for next vblank
 vblank_wait:
+  ; disable interrupts
+  ld a, [IE]
+  push af
+  xor a, a
+  ld [IE], a
+
+@wait:
   ld a, [RLY] 
   cp a, 144
-  jp c, vblank_wait
+  jp c, @wait 
+
+  ; restore interrupts
+  pop af
+  ld [IE], a
+
   ret
 
 not_vblank_wait:
+  ; disable interrupts
+  ld a, [IE]
+  push af
+  xor a, a
+  ld [IE], a
+
+@wait:
   ld a, [RLY]
   cp a, 1
-  jp nz, not_vblank_wait
+  jp nz, @wait
+
+  ; restore interrupts
+  pop af
+  ld [IE], a
+
   ret
 
 next_vblank_wait: