gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 08ccffbf7ff31be4df264b4d682e1e17429dfacc parent 8327d7ebf0858631d383cbabb697d87d3b6be437 Author: Phidias618 <126189685+Phidias618@users.noreply.github.com> Date: Sun, 17 May 2026 15:41:33 +0200 refactor .fill_rect function for the sm83 Diffstat:
| M | gbdk-lib/libc/targets/sm83/fill_rect.s | 107 | +++++++++++++++++++++++++++++++++++-------------------------------------------- |
1 file changed, 48 insertions(+), 59 deletions(-)
diff --git a/gbdk-lib/libc/targets/sm83/fill_rect.s b/gbdk-lib/libc/targets/sm83/fill_rect.s @@ -15,71 +15,60 @@ AND #LCDCF_BG9C00 JR NZ,.is9c .is98: - LD HL,#0x9800 ; HL = origin + LD H, #0x98 ; HL = origin JR .fill_rect .is9c: - LD HL,#0x9C00 ; HL = origin + LD H, #0x9C ; HL = origin - ;; fills rectangle area with tile B at XY = DE, size WH on stack, to vram from address (HL) + ;; fills rectangle area with tile B at XY = DE, size WH on stack, to vram from address (H << 8) .fill_rect: - PUSH BC ; Store source - - SWAP E - RLC E - LD A,E - AND #0x03 - ADD H - LD B,A - LD A,#0xE0 - AND E - ADD D - LD C,A ; dest BC = HL + 0x20 * Y + X - - POP HL ; H = Tile - POP DE ; DE = WH - PUSH DE ; store WH - PUSH BC ; store dest - -3$: ; Copy W tiles - - WAIT_STAT - LD A, H - LD (BC), A + ld l, d + swap e + ld a, e + res 0, e + and #1 + ld d, a + add hl, de + add hl, de ; dest HL = (H << 8) + 0x20 * Y + X - LD A, C ; inc dest and wrap around - AND #0xE0 - LD E, A - LD A, C - INC A - AND #0x1F - OR E - LD C, A - - DEC D - JR NZ, 3$ - - POP BC - POP DE - - DEC E - RET Z - - PUSH DE - - LD A, B ; next row and wrap around - AND #0xFC - LD E, A ; save high bits + pop de ; DE = WH + ld c, d ; C = W +0$: + push hl ; store dest +1$: ; Copy W tiles + WAIT_STAT + ld (hl), b - LD A,#0x20 + ; inc dest and wrap around + inc l + ld a, l + and #0x1F + jr nz, 2$ + ld a, l + sub #0x20 + ld l, a +2$: + dec d + jr nz, 1$ + + pop hl - ADD C - LD C, A - ADC B - SUB C - AND #0x03 - OR E ; restore high bits - LD B, A + dec e + ret z - PUSH BC + ld d, c ; D = W + + ; next row and wrap around + ld a, l + add #0x20 + ld l, a + jr nc, 0$ + ld a, h + rrca + rrca + add #0x40 + rlca + rlca + ld h, a - JR 3$ + jr 0$
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.