From 81d975214add1618b5d619f908312d4661b33c47 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 13 Jul 2025 16:53:53 +0200 Subject: [PATCH] video: updated background update queue to a more simple system. 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 | 3 ++- src/strings.s | 43 ++++++++++++++++++++++++++++++++++++++++++- src/ui.s | 4 ++++ src/video.s | 44 +++++++++++++++++++++++++++++++++++--------- 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/defs.s b/src/defs.s index 94d597e..9cdea2b 100644 --- a/src/defs.s +++ b/src/defs.s @@ -228,7 +228,7 @@ .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 @@ -242,6 +242,7 @@ ; 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 diff --git a/src/strings.s b/src/strings.s index b914eac..b737d26 100644 --- a/src/strings.s +++ b/src/strings.s @@ -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 + diff --git a/src/ui.s b/src/ui.s index d4582e6..fe10268 100644 --- 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 diff --git a/src/video.s b/src/video.s index 4dea699..635c4b2 100644 --- a/src/video.s +++ b/src/video.s @@ -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 -- 2.30.2