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.
.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
; 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
.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
@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
+
; updates HP UI
ui_redraw_hp:
+ ld hl, STR_TITLE
+ ld de, SCRN1 + 34
+ call bputs
+
ret
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]
; 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
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
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:
; 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
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
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