gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit bbf636cadb7c30dbf110393b0c8962428eb40186 parent 4abe9ca5a2d8ddac34d270de27545d95a88c0afb Author: Toxa <untoxa@mail.ru> Date: Fri, 27 Aug 2021 14:15:57 +0300 SMS/GG: set_vram_byte(), set_tile_xy(), set_attributed_tile_xy() Diffstat:
| M | gbdk-lib/include/gb/gb.h | 2 | +- |
| M | gbdk-lib/include/sms/sms.h | 27 | +++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/gg/Makefile | 1 | + |
| A | gbdk-lib/libc/targets/z80/set_tile.s | 94 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/z80/set_tile_map.s | 3 | +++ |
| M | gbdk-lib/libc/targets/z80/set_tile_map_compat.s | 3 | +++ |
| M | gbdk-lib/libc/targets/z80/sms/Makefile | 1 | + |
7 files changed, 130 insertions(+), 1 deletion(-)
diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -914,7 +914,7 @@ void get_bkg_tiles(uint8_t x, * @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) __preserves_regs(b, c); - +#define set_tile_xy set_bkg_tile_xy /** * Get single tile t on background layer at x,y diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -511,5 +511,32 @@ inline void hide_sprite(uint8_t nb) { shadow_OAM[nb] = 0xC0; } +/** + * Set byte in vram at given memory location + * + * @param addr address to write to + * @param v value + */ +void set_vram_byte(uint8_t * addr, uint8_t v) __z88dk_callee __preserves_regs(iyh, iyl); + +/** + * Set single tile t with attributes on background layer at x,y + * @param x X-coordinate + * @param y Y-coordinate + * @param t tile index + * @return returns the address of tile, so you may use faster set_vram_byte() later + */ +uint8_t * set_attributed_tile_xy(uint8_t x, uint8_t y, uint16_t t) __z88dk_callee __preserves_regs(iyh, iyl); + +/** + * Set single tile t on background layer at x,y + * @param x X-coordinate + * @param y Y-coordinate + * @param t tile index + * @return returns the address of tile, so you may use faster set_vram_byte() later + */ +uint8_t * set_tile_xy(uint8_t x, uint8_t y, uint8_t t) __z88dk_callee __preserves_regs(iyh, iyl); +#define set_bkg_tile_xy set_tile_xy +#define set_win_tile_xy set_tile_xy #endif /* _SMS_H */ diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -11,6 +11,7 @@ ASSRC = outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ + set_tile.s \ fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ diff --git a/gbdk-lib/libc/targets/z80/set_tile.s b/gbdk-lib/libc/targets/z80/set_tile.s @@ -0,0 +1,94 @@ + .include "global.s" + + .area _HOME + +; void set_vram_byte(uint8_t * addr, uint8_t v) __z88dk_callee __preserves_regs(iyh, iyl); +_set_vram_byte:: + pop de + pop hl + DISABLE_VBLANK_COPY + WRITE_VDP_CMD_HL + ex de, hl + dec sp + ex (sp), hl + ld a, h + out (.VDP_DATA), a + ENABLE_VBLANK_COPY + ret + +; translate coords in DE and given base in BC into address in DE +.coords_to_address: + add #.SCREEN_Y_OFS + ld d, a + xor a + FAST_MOD8 d #28 + ld d, a + + ld a, e + add #.SCREEN_X_OFS + and #0x1f + ld e, a + + ld a, d + rrca ; rrca(2) == rlca(6) + rrca + ld d, a + and #0x07 + add b + ld b, a + ld a, #0xC0 + and d + sla e + add e + ld e, a + ld d, b ; dest DE = BC + ((0x20 * Y) * 2) + (X * 2) + + ret + +; uint8_t * set_attributed_tile_xy(uint8_t x, uint8_t y, uint16_t t) __z88dk_callee __preserves_regs(iyh, iyl); +_set_attributed_tile_xy:: + pop hl ; HL = ret + pop de ; DE = YX + ex (sp), hl ; HL = data + + ld a, d + + ld bc, #.VDP_TILEMAP + call .coords_to_address + ex de, hl + + DISABLE_VBLANK_COPY + WRITE_VDP_CMD_HL + + ld c, #.VDP_DATA + out (c), e + VDP_DELAY + out (c), d + + ENABLE_VBLANK_COPY + ret + +; uint8_t * set_tile_xy(uint8_t x, uint8_t y, uint8_t t) __z88dk_callee __preserves_regs(iyh, iyl); +_set_tile_xy:: + pop hl ; HL = ret + pop de ; DE = YX + dec sp + ex (sp), hl ; HL = data + + ld a, d + + ld bc, #.VDP_TILEMAP + call .coords_to_address + ex de, hl + + ld a, (.vdp_shift) + ADD_A_REG16 h, l + + DISABLE_VBLANK_COPY + WRITE_VDP_CMD_HL + + ld a, d + out (.VDP_DATA), a + + ENABLE_VBLANK_COPY + ret diff --git a/gbdk-lib/libc/targets/z80/set_tile_map.s b/gbdk-lib/libc/targets/z80/set_tile_map.s @@ -1,5 +1,8 @@ .include "global.s" + .title "VRAM utilities" + .module VRAMUtils + .globl .set_tile_map_xy .area _HOME diff --git a/gbdk-lib/libc/targets/z80/set_tile_map_compat.s b/gbdk-lib/libc/targets/z80/set_tile_map_compat.s @@ -1,5 +1,8 @@ .include "global.s" + .title "VRAM utilities" + .module VRAMUtils + .globl .set_tile_map_xy .area _HOME diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -11,6 +11,7 @@ ASSRC = outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ + set_tile.s \ fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.