GB: refactor get_bkg_xy_addr()/get_win_xy_addr()

This commit is contained in:
Toxa
2025-11-23 02:11:19 +03:00
parent ae027eea57
commit 0f5160316f
2 changed files with 15 additions and 16 deletions

View File

@@ -995,7 +995,7 @@ uint8_t get_vram_byte(uint8_t * addr) PRESERVES_REGS(b, c, h, l);
/**
* Get address of X,Y tile of background map
*/
uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) OLDCALL PRESERVES_REGS(b, c);
uint8_t * get_bkg_xy_addr(uint8_t x, uint8_t y) PRESERVES_REGS(h, l);
#define COMPAT_PALETTE(C0,C1,C2,C3) ((uint8_t)(((C3) << 6) | ((C2) << 4) | ((C1) << 2) | (C0)))
@@ -1480,7 +1480,7 @@ inline void scroll_bkg(int8_t x, int8_t y) {
/**
* Get address of X,Y tile of window map
*/
uint8_t * get_win_xy_addr(uint8_t x, uint8_t y) OLDCALL PRESERVES_REGS(b, c);
uint8_t * get_win_xy_addr(uint8_t x, uint8_t y) PRESERVES_REGS(h, l);
/** Sets VRAM Tile Pattern data for the Window / Background

View File

@@ -3,37 +3,36 @@
.area _CODE
_get_win_xy_addr::
and #0x1f
ld d, a
ldh a, (.LCDC)
and #LCDCF_WIN9C00
jr z, .is98
jr .is9c
_get_bkg_xy_addr::
and #0x1f
ld d, a
ldh a, (.LCDC)
and #LCDCF_BG9C00
jr nz, .is9c
.is98:
ld d, #0x98 ; DE = origin
ld b, #0x98 ; B = origin
jr .calculate_ofs
.is9c:
ld d, #0x9C ; DE = origin
ld b, #0x9C ; B = origin
.calculate_ofs:
ldhl sp, #3
ld a, (hl-)
ld l, (hl)
ld e, d
ld a, e
swap a
rlca
ld h, a
ld c, a
and #0x03
add e
ld d, a
or b
ld b, a
ld a, #0xE0
and h
add l
ld e, a ; dest DE = BASE + 0x20 * Y + X
and c
or d
ld c, a ; BC = (B << 8) + 0x20 * Y + X
ret