From 96c9918b8b1069ba44e02a9c8ead388d0172ee61 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 14 Jul 2025 05:53:13 +0200 Subject: [PATCH] video: vblank and not vblank wait not correctly disable interrpts 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 | 2 +- src/strings.s | 4 ++++ src/ui.s | 2 +- src/video.s | 28 ++++++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/defs.s b/src/defs.s index 9cdea2b..515964c 100644 --- a/src/defs.s +++ b/src/defs.s @@ -228,7 +228,7 @@ .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 diff --git a/src/strings.s b/src/strings.s index b737d26..25db42c 100644 --- a/src/strings.s +++ b/src/strings.s @@ -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 diff --git a/src/ui.s b/src/ui.s index fe10268..029505a 100644 --- 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 diff --git a/src/video.s b/src/video.s index 635c4b2..b17e813 100644 --- a/src/video.s +++ b/src/video.s @@ -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: -- 2.30.2