git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 844c3b8cd003759af0ade639004a9ee375353913
parent bf714255509f7a9a5a0a5212c1732c8fb7324096
Author: toxa <untoxa@mail.ru>
Date:   Tue,  3 Nov 2020 12:59:01 +0300

fill_bkg_rect(), fill_win_rect()

Diffstat:
Mgbdk-lib/include/gb/gb.h28++++++++++++++++++++++++----
Mgbdk-lib/libc/gb/Makefile1+
Agbdk-lib/libc/gb/fill_rect.s67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/libc/gb/fill_rect_bk.s22++++++++++++++++++++++
Agbdk-lib/libc/gb/fill_rect_wi.s22++++++++++++++++++++++
5 files changed, 136 insertions(+), 4 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -1145,23 +1145,43 @@ void get_tiles(UINT8 x, /* ************************************************************ */ - /** Initializes window tile table with c @param c Tile number */ -void init_win(char c) NONBANKED __preserves_regs(b, c); +void init_win(UINT8 c) NONBANKED __preserves_regs(b, c); /** Initializes background tile table with c @param c Tile number */ -void init_bkg(char c) NONBANKED __preserves_regs(b, c); +void init_bkg(UINT8 c) NONBANKED __preserves_regs(b, c); /** Fills the VRAM memory region s of size n with c @param s Start address @param c Value to fill with @param n Size of memory region */ -void vmemset (void *s, char c, size_t n) NONBANKED __preserves_regs(b, c); +void vmemset (void *s, UINT8 c, size_t n) NONBANKED __preserves_regs(b, c); + +/* ************************************************************ */ + +/** Fills a rectangular region of Tile Map entries for the Background layer with tile. + + @param x X Start position in Background Map tile coordinates. Range 0 - 31 + @param y Y Start position in Background Map tile coordinates. Range 0 - 31 + @param w Width of area to set in tiles. Range 0 - 31 + @param h Height of area to set in tiles. Range 0 - 31 + @param tile Fill value +*/ +void fill_bkg_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b, c); +/** Fills a rectangular region of Tile Map entries for the Window layer with tile. + + @param x X Start position in Window Map tile coordinates. Range 0 - 31 + @param y Y Start position in Window Map tile coordinates. Range 0 - 31 + @param w Width of area to set in tiles. Range 0 - 31 + @param h Height of area to set in tiles. Range 0 - 31 + @param tile Fill value +*/ +void fill_win_rect(UINT8 x, UINT8 y, UINT8 w, UINT8 h, UINT8 tile) NONBANKED __preserves_regs(b, c); #endif /* _GB_H */ diff --git a/gbdk-lib/libc/gb/Makefile b/gbdk-lib/libc/gb/Makefile @@ -26,6 +26,7 @@ ASSRC = cgb.s cpy_data.s drawing.s f_ibm_sh.s \ pad_ex.s \ mode.s clock.s \ set_t.s init_vram.s \ + fill_rect.s fill_rect_bk.s fill_rect_wi.s \ crt0.s ifeq ($(ASM),asxxxx) diff --git a/gbdk-lib/libc/gb/fill_rect.s b/gbdk-lib/libc/gb/fill_rect.s @@ -0,0 +1,66 @@ + .include "global.s" + + .area _BASE + +.fill_rect_wtt:: + PUSH HL + LDH A,(.LCDC) + BIT 6,A + JR Z,.is98 + JR .is9c + ;; Initialize background tile table with B +.fill_rect_btt:: + PUSH HL + LDH A,(.LCDC) + BIT 3,A + JR NZ,.is9c +.is98: + LD HL,#0x9800 ; HL = origin + JR .fill_rect +.is9c: + LD HL,#0x9C00 ; HL = origin + + ;; fills rect from HL; HW: stack; Fill: B +.fill_rect: + XOR A + OR E + LD A, B ; save tile in A + LD B, #0 + JR Z,2$ + + LD C,#0x20 ; One line is 20 tiles + SRL E + JR NC,0$ + ADD HL,BC +0$: + JR Z,2$ + SLA C +1$: + ADD HL,BC + DEC E + JR NZ,1$ +2$: + LD C,D + ADD HL,BC ; HL = HL + 0x20 * Y + X + + POP BC ; load height and width + LD D, #0 + LD E, B + LD B, A ; restore tile to B + + INC C + JR 4$ +3$: + PUSH DE + PUSH HL + CALL .init_vram + POP HL + POP DE + + LD A, #0x20 ; next row + ADD_A_REG16 H, L +4$: + DEC C + JR NZ, 3$ + + RET + diff --git a/gbdk-lib/libc/gb/fill_rect_bk.s b/gbdk-lib/libc/gb/fill_rect_bk.s @@ -0,0 +1,22 @@ + .include "global.s" + + .area _BASE + +_fill_bkg_rect:: + PUSH BC + + LDA HL,4(SP) ; Skip return address and registers + LD A,(HL+) ; D = x + LD D, A + LD E,(HL) ; E = y + LDA HL,8(SP) + LD A,(HL-) ; B = tile + LD B, A + LD A,(HL-) ; A = h + LD H,(HL) ; H = w + LD L,A ; L = h + + CALL .fill_rect_btt + + POP BC + RET diff --git a/gbdk-lib/libc/gb/fill_rect_wi.s b/gbdk-lib/libc/gb/fill_rect_wi.s @@ -0,0 +1,22 @@ + .include "global.s" + + .area _BASE + +_fill_win_rect:: + PUSH BC + + LDA HL,4(SP) ; Skip return address and registers + LD A,(HL+) ; D = x + LD D, A + LD E,(HL) ; E = y + LDA HL,8(SP) + LD A,(HL-) ; B = tile + LD B, A + LD A,(HL-) ; A = h + LD H,(HL) ; H = w + LD L,A ; L = h + + CALL .fill_rect_wtt + + POP BC + RET

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.