From 6db1effd5838c25032dbfb460193ab49dc49722b Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 13 Jul 2025 09:52:14 +0200 Subject: [PATCH] video: wip bg update system --- src/defs.s | 15 +++-- src/video.s | 156 ++++++++++++++++++++++++---------------------------- src/wram.s | 2 +- 3 files changed, 84 insertions(+), 89 deletions(-) diff --git a/src/defs.s b/src/defs.s index 8c53e2e..94d597e 100644 --- a/src/defs.s +++ b/src/defs.s @@ -233,13 +233,18 @@ ; 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 diff --git a/src/video.s b/src/video.s index 1cb077a..5ead423 100644 --- a/src/video.s +++ b/src/video.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 2c106fd..b6a895a 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 -- 2.30.2