gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 0b45cdea99a2c15bfa3f9b00c34f80032d254b3b parent c8c0d1048d5abd7a2aebf48f5942f14d41b07d07 Author: Toxa <untoxa@mail.ru> Date: Fri, 1 Mar 2024 19:44:39 +0300 GB: add clamping and use the new calling convention in set_bkg_tile_xy()/set_win_tile_xy() Diffstat:
| M | gbdk-lib/include/gb/gb.h | 4 | ++-- |
| M | gbdk-lib/libc/targets/sm83/set_tile.s | 51 | ++++++++++++++++++++++++++++----------------------- |
2 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -1359,7 +1359,7 @@ void get_bkg_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t *tiles) O @return returns the address of tile, so you may use faster set_vram_byte() later */ -uint8_t * set_bkg_tile_xy(uint8_t x, uint8_t y, uint8_t t) OLDCALL PRESERVES_REGS(b, c); +uint8_t * set_bkg_tile_xy(uint8_t x, uint8_t y, uint8_t t); #define set_tile_xy set_bkg_tile_xy /** Set single attribute data a on background layer at x,y @@ -1659,7 +1659,7 @@ void get_win_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t *tiles) O * @param t tile index * @return returns the address of tile, so you may use faster set_vram_byte() later */ -uint8_t * set_win_tile_xy(uint8_t x, uint8_t y, uint8_t t) OLDCALL PRESERVES_REGS(b, c); +uint8_t * set_win_tile_xy(uint8_t x, uint8_t y, uint8_t t); /** diff --git a/gbdk-lib/libc/targets/sm83/set_tile.s b/gbdk-lib/libc/targets/sm83/set_tile.s @@ -10,43 +10,48 @@ _set_vram_byte:: ret _set_win_tile_xy:: - ldh a,(.LCDC) + ld d, a + ldh a, (.LCDC) and #LCDCF_WIN9C00 - jr z,.is98 + jr z, .is98 jr .is9c + _set_bkg_tile_xy:: - ldh a,(.LCDC) + ld d, a + ldh a, (.LCDC) and #LCDCF_BG9C00 - jr nz,.is9c + jr nz, .is9c .is98: - ld d,#0x98 ; DE = origin + ld b, #0x98 jr .set_tile_xy .is9c: - ld d,#0x9C ; DE = origin + ld b,#0x9C -.set_tile_xy: - push bc - ldhl sp,#4 - - ld a, (hl+) - ld b, a - ld a, (hl+) +.set_tile_xy: ; DE = XY; B = origin + ld l, #0x1f + ld a, d + and l + ld d, a + ld a, e + and l - ld e, d + ld c, b swap a rlca - ld c, a + ld e, a and #0x03 - add e - ld d, a + add c + ld b, a ld a, #0xE0 - and c - add b - ld e, a ; dest DE = BASE + 0x20 * Y + X + and e + add d + ld c, a ; dest BC = (BASE << 8) + 0x20 * Y + X + ldhl sp, #2 WAIT_STAT ld a, (hl) - ld (de), a + ld (bc), a ; return BC as result - pop bc - ret + pop hl + inc sp + jp (hl)
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.