bg: Added tile update queue processing
authorLukas Krickl <lukas@krickl.dev>
Fri, 18 Apr 2025 07:56:55 +0000 (09:56 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 18 Apr 2025 07:56:55 +0000 (09:56 +0200)
src/defs.s
src/update.s

index 531c4883b77c198fbf6e00e1f817512b1be24ce5..c2b94d4f3b49ca5cd302c298811f745836092740 100644 (file)
 
 #define BGE_MAX 32
 
+  ; max bg updates per frame
+#define BG_UPDATE_MAX 8 
+
   ; bg update entry 
 .se 0
 .de bge_tile_ptr, 2
index 0ad16f7a332a5c8e9abf87312edc60cfc5d29c34..076d2d697865568b0bee6a42b7e345ca166d6a64 100644 (file)
@@ -33,12 +33,70 @@ update:
 
   ; bg update queue 
   ; this is called once during blank
-  ; and updates a fixed amount of tiles 
-  ; from a circular buffer
-  ; the buffer can hold up to 255 items and wraps around
+  ; it processess all tile updates 
+  ; until the bg_update_index is 0 
 bg_update_queue_process:
+  ld hl, bg_update_index
+
+  ; read index
+  ld a, [bg_update_index]
+  ld e, a
+  ld a, [bg_update_index+1]
+  ld d, a
+  
+
+  ; skip if index is already 0
+  ld a, d
+  xor a, e
+  jp z, @done 
+
+  ld a, BG_UPDATE_MAX
+@loop:
+    push af
+    ; index--
+    dec de
+
+    ; write to vram
+    ld hl, bg_update_queue 
+    add hl, de ; hl = next index to process
+
+    ld a, [hl+]
+    ld c, a
+    ld a, [hl+]
+    ld b, a
+    ; bc = vram address
+    
+    ld a, [hl]
+    ld [bc], a
+
+
+    ; a--
+    pop af 
+    dec a
+    
+    ld b, a ; save a for after 
+    cp a, 0
+    jr z, @done REL
+
+    ld a, d
+    xor a, e
+    jr z, @done REL
+
+    ld a, b ; restore a
+    jr @loop REL 
+  
+
+@done:
+  ; write index
+  ld a, e
+  ld [bg_update_index], a
+  ld a, d
+  ld [bg_update_index+1], a
+
   ret
 
+
+
   ; pushes a new bg update to the queue
   ; inputs:
   ;   hl: ptr to tile 
@@ -57,6 +115,7 @@ bg_update_queue_push:
   inc de ; offset += bgu_size 
   inc de 
   inc de
+
   ld a, e
   ld [bg_update_index], a
   ld a, d