video: wip bg update system
authorLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 07:52:14 +0000 (09:52 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 07:52:14 +0000 (09:52 +0200)
src/defs.s
src/video.s
src/wram.s

index 8c53e2e98ed9be1481df7d34a4ce4e3d0723a07e..94d597e0b692084b37dab7060c8335f08bbbe989 100644 (file)
   ; max bg updates per frame
 #define BG_UPDATE_MAX 8 
 
-  ; bg update entry 
+  ; bg update flags
+.se 1
+  ; sets a tile
+.de BGEF_TILE, 1
+  ; sets BGE address
+.de BGEF_ADDR, 2
+
+  ; bg update entry
 .se 0
-.de bge_tile_ptr, 2
+.de bge_flags, 1
 .de bge_new_tile, 1
-; unused byte
-; for alignment
-.de bge_unused, 1
+.de bge_addr, 2
 .de bge_size, 0
 
 #define MAP_BG_TILE_OFFSET 0
index 1cb077a88b32eab1aa326e34531147e7f171c91d..5ead42322ccf6a0299b860634aa395d878cba6d5 100644 (file)
@@ -229,111 +229,101 @@ tiles_load_bank9000:
   
 
   ; bg update queue 
-  ; this is called once during blank
-  ; it processess all tile updates 
-  ; until the bg_update_index is 0 
+  ; loads update_start tile address
+  ; and updates tiles until the STOP flag is read
+  ; of the loop countr is BGE_MAX
 bg_update_queue_process:
-  ; read index
-  ld a, [bg_update_index]
-  ld e, a
-  ld a, [bg_update_index+1]
-  ld d, a
+  ld de, bg_update_queue ; load initial entry 
   
+  ld b, BGE_MAX ; b == loop counter
+  ; hl = target address
 
-  ; skip if index is already 0
-  ld a, d
-  xor a, e
-  jp z, @done 
-
-  ld a, BG_UPDATE_MAX
 @loop:
-    push af
-    ; index--
-    ; sub length of an entry
-    dec de
-    dec de 
-    dec de
-    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, [de] ; load flags
+    ; thest big 1 (STOP)
+    cp a, 0 
+    jr z, @skip REL ; skip this entry 
     
-    ld a, [hl]
-    ld [bc], a
-
-
-    ; a--
-    pop af 
-    dec a
+      ; first test address set mode
+      bit 2, a 
+      jr z, @no_addr_set REL
+        push de
+        ; load addr from entry
+        inc de
+        inc de
+        ; get to addr
+        ld a, [de]
+        ld l, a
+        inc de
+        ld a, [de]
+        ld h, a 
+        ; hl = new target address
+
+        pop de
+@no_addr_set:
+      ; test tile set bit
+      bit 1, a 
+      jr z, @no_tile_wirte REL
+        inc de
+        
+        ; write new tile and inc hl
+        ld a, [de]
+        ld [hl+], a
+
+        dec de
     
-    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 
+@no_tile_wirte:
+@skip:
+    ; advance to next entry
+    inc de
+    inc de
+    inc de
+    inc de
+    dec b ; b--
+    jr nz, @loop REL
   
 
-@done:
-  ; write index
-  ld a, e
-  ld [bg_update_index], a
-  ld a, d
-  ld [bg_update_index+1], a
-
-  ret
-
+  ; advance to queue clear
   
   ; clears the bg update queue
   ; sets update index to 0
 bg_update_queue_clear:
+  xor a, a
+  ld [bg_update_index], a
   ret
 
-
   ; pushes a new bg update to the queue
   ; inputs:
-  ;   hl: ptr to tile 
-  ;    a: tile data
-  ;    b: unused (set to 0 it may be used eventually)
+  ;    b: tile data
+  ;    a: entry flags 
+  ;   de: address (unused unless in BGEF_ADDR mode)
+  ; returns:
+  ;   a == 1: if update was queued
+  ;   a == 0: if queue is full
 bg_update_queue_push:
-  push hl
-  pop bc ; move hl to bc
-  push af
-  ld hl, bg_update_queue
   ld a, [bg_update_index]
-  ld e, a
-  ld a, [bg_update_index+1]
-  ld d, a
-  add hl, de ; hl = update queue + current offset 
+  add a, a
+  add a, a
+  add a, a
+  add a, a
+  ; a * 4
+  ld b, 0
+  ld c, a ; de = index offset
 
-  inc de ; offset += bgu_size 
-  inc de 
-  inc de
+  ld hl, bg_update_queue
+  add hl, bc
 
-  ld a, e
-  ld [bg_update_index], a
-  ld a, d
-  ld [bg_update_index+1], a
-  
-  ; store ptr
-  ld a, c
+  ; write flags
   ld [hl+], a
-  ld a, b
+  ld b, a
+  ; write tile data
   ld [hl+], a
-  
-  ; store new tile 
-  pop af
+
+  ; write address
+  ld a, e
+  ld [hl+], a
+  ld a, d
   ld [hl], a
 
+  xor a, a ; queue was full
   ret
index 2c106fdcb6774897d934516eef3c6a7ae9635192..b6a895a8cf9c3f720e132e371425f977bc1e2638 100644 (file)
@@ -34,7 +34,7 @@ status_text: .adv 32
 demo_inputs: .adv 2
 
   ; offset into bg_update_queue 
-bg_update_index: .adv 1
+bg_update_index: .adv 1 ; current entry 
 bg_update_queue: .adv bge_size * BGE_MAX 
 
 draw_flags: .adv 1