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.
.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
STR_PANIC:
.str "PANIC"
+.db 0
+
+STR_TEST:
+.str "0123456789ABCDEF"
.db 0
; print a 0-terminated string to the screen
; updates HP UI
ui_redraw_hp:
- ld hl, STR_TITLE
+ ld hl, STR_TEST
ld de, SCRN1 + 34
call bputs
; 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: