video: updated background update queue to a more simple system.
authorLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 14:53:53 +0000 (16:53 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 14:53:53 +0000 (16:53 +0200)
Background updates now happen every frame for up to 10 tiles.
Tiles can have flags set to either set the base address, write a tile or
both. This works on SCRN0 or SCRN1.

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

index 94d597e0b692084b37dab7060c8335f08bbbe989..9cdea2b6a09b5f94edbb61e01201620b5c8a2c92 100644 (file)
 .de act_size, 0
   
   ; max bge queue size
-#define BGE_MAX 64
+#define BGE_MAX 10
 
   ; max bg updates per frame
 #define BG_UPDATE_MAX 8 
 
   ; bg update entry
 .se 0
+  ; if flags is 00 the entry is skipped
 .de bge_flags, 1
 .de bge_new_tile, 1
 .de bge_addr, 2
index b914eacf7d39bd494417ba26544dec08933c8296..b737d26b928656084e738687dc03d12d4a29e3e1 100644 (file)
@@ -25,7 +25,7 @@ STR_PANIC:
 .str "PANIC"
 .db 0
 
-  ; print a string 0-terminated to the screen 
+  ; print a 0-terminated string to the screen 
   ; can only be called during blank!
   ; inputs:
   ;   hl: the string
@@ -44,3 +44,44 @@ puts:
 @done:
   ret
 
+  ; prints a 0-terminated string to the update buffer
+  ; can be called outside of blank
+  ; inputs:
+  ;   hl: the string
+  ;   de: tile location
+bputs:
+  ; the first char is special
+  ld a, [hl+]
+  cp a, 0
+  jr z, @done REL ; if its 0 already skip
+
+  ; if its not 0 write the address to the 
+  ; bg update queue
+  add a, FONT_OFFSET
+  ld b, a ; b = tile data for text
+  ld a, BGEF_TILE | BGEF_ADDR
+  ; de = tile address already 
+  push hl
+  call bg_update_queue_push
+  pop hl
+
+@loop:
+  
+    ; now we just push tiles
+    ; with BGEF_TILE
+    ld a, [hl+]
+    cp a, 0 ; terminator?
+    jr z, @done REL
+
+    push hl
+    add a, FONT_OFFSET
+    ld b, a ; b = tile
+    ld a, BGEF_TILE ; tile only mode
+    ; no need to set location
+    call bg_update_queue_push
+    pop hl
+    
+    jr @loop REL
+@done:
+  ret
+
index d4582e63158103ce86ff4ee98a016436d81cd64c..fe10268e94a3fba91c2d2b59536cb89911c974e7 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -14,4 +14,8 @@ ui_init:
   
   ; updates HP UI
 ui_redraw_hp:
+  ld hl, STR_TITLE
+  ld de, SCRN1 + 34
+  call bputs
+
   ret
index 4dea6999d06aea77ca84a23f2262e708063b4c24..635c4b20537038d023489c39ebc8b500debacf0d 100644 (file)
@@ -18,7 +18,7 @@ vblank:
   call poll_inputs
 
   call scroll_write
-  call bg_update_queue_process
+  call bg_update_queue_process
 
   ; cycle bg tiles for animations
   ld a, [frame_count]
@@ -243,11 +243,14 @@ bg_update_queue_process:
     ; thest big 1 (STOP)
     cp a, 0 
     jr z, @skip REL ; skip this entry 
-    
+      
       ; first test address set mode
-      bit 2, a 
+      bit 1, a 
       jr z, @no_addr_set REL
+
         push de
+        push af
+
         ; load addr from entry
         inc de
         inc de
@@ -258,12 +261,14 @@ bg_update_queue_process:
         ld a, [de]
         ld h, a 
         ; hl = new target address
-
+        
+        pop af
         pop de
 @no_addr_set:
       ; test tile set bit
-      bit 1, a 
+      bit 0, a 
       jr z, @no_tile_wirte REL
+
         inc de
         
         ; write new tile and inc hl
@@ -290,7 +295,12 @@ bg_update_queue_process:
 bg_update_queue_clear:
   xor a, a
   ld [bg_update_index], a
-  ret
+  
+  ; clear all entries
+  ld hl, bg_update_queue 
+  ld bc, bge_size * BGE_MAX
+  ld d, a ; d = 0
+  jp memset
 
   ; pushes a new bg update to the queue
   ; inputs:
@@ -301,9 +311,14 @@ bg_update_queue_clear:
   ;   a == 1: if update was queued
   ;   a == 0: if queue is full
 bg_update_queue_push:
+  push af
+  push bc
+
+  ; first calculate address in queue
   ld a, [bg_update_index]
-  add a, a
-  add a, a
+  cp a, BGE_MAX
+  jp z, @full
+
   add a, a
   add a, a
   ; a * 4
@@ -313,9 +328,12 @@ bg_update_queue_push:
   ld hl, bg_update_queue
   add hl, bc
 
+  pop bc
+  pop af
+
   ; write flags
   ld [hl+], a
-  ld b, a
+  ld a, b 
   ; write tile data
   ld [hl+], a
 
@@ -324,6 +342,14 @@ bg_update_queue_push:
   ld [hl+], a
   ld a, d
   ld [hl], a
+  
+  ; index++
+  ld a, [bg_update_index]
+  inc a
+  ld [bg_update_index], a
 
+  ld a, 1
+  ret
+@full:
   xor a, a ; queue was full
   ret