git.y1.nz

gbdk-2020

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

commit a19eebc8d858454f6863ceefc52c5a7124deb1a1
parent ff84156ec329827ae0ff0d8cee1d4ad57144dd36
Author: Toxa <untoxa@mail.ru>
Date:   Wed, 25 Aug 2021 15:01:06 +0300

SMS/GG: wrapping of tilemaps; todo: set_tile_submap()

Diffstat:
Mgbdk-lib/examples/gg/smoke/smoketest.c47+++++++++++++++++++++++++++++++++++++++++------
Mgbdk-lib/examples/sms/smoke/smoketest.c3+++
Mgbdk-lib/libc/targets/z80/set_tile_map_xy.s77+++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Mgbdk-lib/libc/targets/z80/set_tile_map_xy_compat.s83+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
4 files changed, 143 insertions(+), 67 deletions(-)

diff --git a/gbdk-lib/examples/gg/smoke/smoketest.c b/gbdk-lib/examples/gg/smoke/smoketest.c @@ -7,38 +7,73 @@ BANKREF_EXTERN(earth_data_size) extern const unsigned int earth_data_size; const uint8_t tilemap[] = {2, 4, 6, 8, 3, 5, 7, 9}; +const uint16_t tilemapw[] = {2, 4, 6, 8, 3, 5, 7, 9}; uint16_t banked_func(uint8_t be, uint8_t ef) __banked; +int16_t x = 8 << 4, y = 0; +int8_t xspd = 0, yspd = 0; + +uint8_t anim = 0, tick = 0; + joypads_t joy; void main() { + HIDE_LEFT_COLUMN; + SPRITES_8x16; DISPLAY_ON; -// vmemcpy(0x4000, earth_data, sizeof(earth_data)); +// vmemcpy(0x4000, earth_data, sizeof(earth_data)); SWITCH_ROM(BANK(earth_data)); if (banked_func(0xBE, 0xEF) == 0xBEEF) { set_bkg_2bpp_data(2, earth_data_size >> 4, earth_data); + set_sprite_2bpp_data(0, earth_data_size >> 4, earth_data); + set_sprite_tile(0, 0); + set_sprite_tile(1, 2); } set_bkg_tiles(4, 10, 4, 2, tilemap); + set_tile_map(4, 16, 4, 2, tilemapw); + joypad_init(2, &joy); while(TRUE) { joypad_ex(&joy); - if (joy.joy0 & J_LEFT) { - scroll_bkg(-1, 0); + if (joy.joy0 & J_LEFT) { + if (xspd > -32) xspd -= 2; } else if (joy.joy0 & J_RIGHT) { - scroll_bkg(1, 0); + if (xspd < 32) xspd += 2; + } else { + if (xspd < 0) xspd++; else if (xspd > 0) xspd--; } + if (joy.joy0 & J_UP) { - scroll_bkg(0, -1); + if (yspd > -32) yspd -= 2; } else if (joy.joy0 & J_DOWN) { - scroll_bkg(0, 1); + if (yspd < 32) yspd += 2; + } else { + if (yspd < 0) yspd++; else if (yspd > 0) yspd--; } + x += xspd; + if (x < (8 << 4)) x = 8 << 4; else if (x > (30 * 8) << 4) x = (30 * 8) << 4; + + + y += yspd; + if (y < 0) y = 0; else if (y > (22 * 8) << 4) y = (22 * 8) << 4; + + tick++; tick &= 7; + if (!tick) { + anim++; if (anim == 7) anim = 0; + set_sprite_tile(0, anim << 2); + set_sprite_tile(1, (anim << 2) + 2); + } + + move_sprite(0, x >> 4, y >> 4); + move_sprite(1, (x >> 4) + 8, y >> 4); + if (joy.joy1 & J_LEFT) { scroll_bkg(-1, 0); } else if (joy.joy1 & J_RIGHT) { diff --git a/gbdk-lib/examples/sms/smoke/smoketest.c b/gbdk-lib/examples/sms/smoke/smoketest.c @@ -7,6 +7,7 @@ BANKREF_EXTERN(earth_data_size) extern const unsigned int earth_data_size; const uint8_t tilemap[] = {2, 4, 6, 8, 3, 5, 7, 9}; +const uint16_t tilemapw[] = {2, 4, 6, 8, 3, 5, 7, 9}; uint16_t banked_func(uint8_t be, uint8_t ef) __banked; @@ -33,6 +34,8 @@ void main() { set_bkg_tiles(4, 10, 4, 2, tilemap); + set_tile_map(4, 16, 4, 2, tilemapw); + joypad_init(2, &joy); while(TRUE) { diff --git a/gbdk-lib/libc/targets/z80/set_tile_map_xy.s b/gbdk-lib/libc/targets/z80/set_tile_map_xy.s @@ -2,6 +2,9 @@ .title "VRAM utilities" .module VRAMUtils + + .ez80 + .area _HOME ;; Set background tile table from (BC) at XY = DE of size WH = HL @@ -11,7 +14,7 @@ ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) .set_tile_map_xy_tt:: - push bc ; Store source + push bc ; Store source ld a, d rlca @@ -28,53 +31,71 @@ and d sla e add e - ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) + ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) ld a, b cp #>(.VDP_TILEMAP+0x0700) jr c, 5$ ld b, #>.VDP_TILEMAP 5$: + pop hl ; HL = source + pop de ; DE = HW + push ix ; save IX + push de ; store HW - pop hl ; HL = source - pop de ; DE = HW - sla e - push de ; store HW - push bc ; store dest + ld ixh, b + ld ixl, c + push ix ; store dest - DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT + DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT -1$: ; copy H rows - SMS_WRITE_VDP_CMD b, c +1$: ; copy H rows + SMS_WRITE_VDP_CMD ixh, ixl ld c, #.VDP_DATA - ld b, e -2$: ; copy W tiles +2$: ; copy W tiles outi - jr 3$ -3$: + VDP_DELAY outi - jr nz, 2$ - pop bc + ld a, ixl + and #0x3F + inc a + inc a + bit 6, a + jp z, 3$ + and #0x3F + ld b, a + ld a, ixl + and #0xC0 + or b + ld ixl, a + SMS_WRITE_VDP_CMD ixh, ixl + dec e + jp nz, 2$ +3$: + inc ixl + inc ixl + dec e + jp nz, 2$ + + pop ix pop de + dec d jr z, 6$ push de - ld a, #0x40 - add c - ld c, a - adc b - sub c - ld b, a - + ld bc, #0x40 + add ix, bc + ld a, ixh cp #>(.VDP_TILEMAP+0x0700) - jr c, 4$ - ld b, #>.VDP_TILEMAP + jp c, 4$ + ld ixh, #>.VDP_TILEMAP 4$: - push bc - jr 1$ + push ix + jp 1$ 6$: - ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + pop ix ; restore IX ret diff --git a/gbdk-lib/libc/targets/z80/set_tile_map_xy_compat.s b/gbdk-lib/libc/targets/z80/set_tile_map_xy_compat.s @@ -4,6 +4,9 @@ .title "VRAM utilities" .module VRAMUtils + + .ez80 + .area _HOME ;; Set background tile table from (BC) at XY = DE of size WH = HL @@ -13,7 +16,7 @@ ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) .set_tile_map_xy_tt_compat:: - push bc ; Store source + push bc ; Store source ld a, d rlca @@ -32,56 +35,70 @@ add e ld hl, #.vdp_shift add (hl) - ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) + ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) ld a, b cp #>(.VDP_TILEMAP+0x0700) jr c, 5$ ld b, #>.VDP_TILEMAP 5$: - dec bc - - pop hl ; HL = source - pop de ; DE = HW - push de ; store HW - push bc ; store dest + pop hl ; HL = source + pop de ; DE = HW + push ix ; save IX + push de ; store HW + ld ixh, b + ld ixl, c + push ix ; store dest - DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT + DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT -1$: ; copy H rows - SMS_WRITE_VDP_CMD b, c +1$: ; copy H rows + SMS_WRITE_VDP_CMD ixh, ixl ld c, #.VDP_DATA - ld b, e -2$: ; copy W tiles - in a, (c) ; skip next byte - nop - jr 3$ -3$: +2$: ; copy W tiles outi - nop - jr nz, 2$ + VDP_DELAY + in a, (c) ; skip next byte + + ld a, ixl + and #0x3F + inc a + inc a + bit 6, a + jp z, 3$ + and #0x3F + ld b, a + ld a, ixl + and #0xC0 + or b + ld ixl, a + SMS_WRITE_VDP_CMD ixh, ixl + dec e + jp nz, 2$ +3$: + inc ixl + inc ixl + dec e + jp nz, 2$ - pop bc + pop ix pop de + dec d jr z, 6$ push de - ld a, #0x40 - add c - ld c, a - adc b - sub c - ld b, a - + ld bc, #0x40 + add ix, bc + ld a, ixh cp #>(.VDP_TILEMAP+0x0700) - jr c, 4$ - ld b, #>.VDP_TILEMAP + jp c, 4$ + ld ixh, #>.VDP_TILEMAP 4$: - push bc - jr 1$ + push ix + jp 1$ 6$: - ENABLE_VBLANK_COPY ; switch ON copy shadow SAT - + ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + pop ix ; restore IX 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.