From: Lukas Krickl Date: Fri, 18 Apr 2025 07:56:55 +0000 (+0200) Subject: bg: Added tile update queue processing X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=cdb0b3a8f6c154b95d8da813d3017ffdaffd0792;p=gbrg%2F.git bg: Added tile update queue processing --- diff --git a/src/defs.s b/src/defs.s index 531c488..c2b94d4 100644 --- a/src/defs.s +++ b/src/defs.s @@ -115,6 +115,9 @@ #define BGE_MAX 32 + ; max bg updates per frame +#define BG_UPDATE_MAX 8 + ; bg update entry .se 0 .de bge_tile_ptr, 2 diff --git a/src/update.s b/src/update.s index 0ad16f7..076d2d6 100644 --- a/src/update.s +++ b/src/update.s @@ -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