gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 53c5b27d38db92e730e48819fa8282de80e96eff parent 39ab4450fd2b96406e9b80438ddf231491fd23e7 Author: Toxa <untoxa@mail.ru> Date: Mon, 10 Jan 2022 17:27:59 +0300 set_*_based_tiles() / set_*_based_submap() Diffstat:
| M | gbdk-lib/include/gb/gb.h | 92 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | gbdk-lib/include/sms/hardware.h | 1 | - |
| M | gbdk-lib/include/sms/sms.h | 24 | ++++++++++++++++++++++++ |
| M | gbdk-lib/libc/targets/gbz80/set_tile_submap.s | 16 | +++++++++++++++- |
| M | gbdk-lib/libc/targets/gbz80/set_xy_t.s | 16 | +++++++++++++++- |
| M | gbdk-lib/libc/targets/z80/set_tile_map_xy_compat.s | 18 | ++++++++++++++++-- |
| M | gbdk-lib/libc/targets/z80/set_tile_submap_compat.s | 18 | ++++++++++++++++-- |
7 files changed, 178 insertions(+), 7 deletions(-)
diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -932,6 +932,15 @@ void set_bkg_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *ti #define set_tile_map set_bkg_tiles +extern uint8_t _map_tile_offset; + +inline void set_bkg_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles, uint8_t base_tile) { + _map_tile_offset = base_tile; + set_bkg_tiles(x, y, w, h, tiles); + _map_tile_offset = 0; +} + + /** Sets a rectangular area of the Background Tile Map using a sub-region from a source tile map. Useful for scrolling implementations of maps larger than 32 x 32 tiles. @@ -963,6 +972,45 @@ void set_bkg_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *ti void set_bkg_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) OLDCALL; #define set_tile_submap set_bkg_submap + +extern uint8_t _submap_tile_offset; + +/** Sets a rectangular area of the Background Tile Map using a sub-region + from a source tile map and base_tile tile ID offset. Useful for scrolling + implementations of maps larger than 32 x 32 tiles. + + @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 1 - 255 + @param h Height of area to set in tiles. Range 1 - 255 + @param map Pointer to source tile map data + @param map_w Width of source tile map in tiles. Range 1 - 255 + @param base_tile Offset each tile ID of submap by this value + + Entries are copied from __map__ to the Background Tile Map starting at + __x__, __y__ writing across for __w__ tiles and down for __h__ tiles, + using __map_w__ as the rowstride for the source tile map. + + Use this instead of @ref set_bkg_tiles when the source map is wider than + 32 tiles or when writing a width that does not match the source map width. + + One byte per source tile map entry. + + Writes that exceed coordinate 31 on the x or y axis will wrap around to + the Left and Top edges. + + See @ref set_bkg_tiles for setting CGB attribute maps with @ref VBK_REG. + + @see SHOW_BKG + @see set_bkg_data, set_bkg_tiles, set_win_submap, set_tiles +*/ +inline void set_bkg_based_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w, uint8_t base_tile) { + _submap_tile_offset = base_tile; + set_bkg_submap(x, y, w, h, map, map_w); + _submap_tile_offset = 0; +} + + /** Copies a rectangular region of Background Tile Map entries into a buffer. @param x X Start position in Background Map tile coordinates. Range 0 - 31 @@ -1119,6 +1167,12 @@ void get_win_data(uint8_t first_tile, uint8_t nb_tiles, uint8_t *data) OLDCALL P void set_win_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles) OLDCALL PRESERVES_REGS(b, c); +inline void set_win_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles, uint8_t base_tile) { + _map_tile_offset = base_tile; + set_win_tiles(x, y, w, h, tiles); + _map_tile_offset = 0; +} + /** Sets a rectangular area of the Window Tile Map using a sub-region from a source tile map. @@ -1152,6 +1206,44 @@ void set_win_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *ti void set_win_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) OLDCALL; +/** Sets a rectangular area of the Window Tile Map using a sub-region + from a source tile map and base_tile tile ID offset + + @param x X Start position in Window Map tile coordinates. Range 0 - 31 + @param y Y Start position in Wimdpw Map tile coordinates. Range 0 - 31 + @param w Width of area to set in tiles. Range 1 - 255 + @param h Height of area to set in tiles. Range 1 - 255 + @param map Pointer to source tile map data + @param map_w Width of source tile map in tiles. Range 1 - 255 + @param base_tile Offset each tile ID of submap by this value + + Entries are copied from __map__ to the Window Tile Map starting at + __x__, __y__ writing across for __w__ tiles and down for __h__ tiles, + using __map_w__ as the rowstride for the source tile map. + + Use this instead of @ref set_win_tiles when the source map is wider than + 32 tiles or when writing a width that does not match the source map width. + + One byte per source tile map entry. + + Writes that exceed coordinate 31 on the x or y axis will wrap around to + the Left and Top edges. + + GBC only: @ref VBK_REG determines whether Tile Numbers or Tile Attributes get set. + \li VBK_REG=0 Tile Numbers are written + \li VBK_REG=1 Tile Attributes are written + + See @ref set_bkg_tiles for details about CGB attribute maps with @ref VBK_REG. + + @see SHOW_WIN, HIDE_WIN, set_win_tiles, set_bkg_submap, set_bkg_tiles, set_bkg_data, set_tiles +**/ +inline void set_win_based_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w, uint8_t base_tile) { + _submap_tile_offset = base_tile; + set_win_submap(x, y, w, h, map, map_w); + _submap_tile_offset = 0; +} + + /** Copies a rectangular region of Window Tile Map entries into a buffer. @param x X Start position in Window Map tile coordinates. Range 0 - 31 diff --git a/gbdk-lib/include/sms/hardware.h b/gbdk-lib/include/sms/hardware.h @@ -35,7 +35,6 @@ static volatile SFR AT(0x7E) VCOUNTER; static volatile SFR AT(0x7F) PSG; #define PSG_LATCH 0x80 -#define PSG_DATA 0x40 #define PSG_CH0 0b00000000 #define PSG_CH1 0b00100000 diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -568,6 +568,18 @@ void set_tile_map_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8 #define set_bkg_tiles set_tile_map_compat #define set_win_tiles set_tile_map_compat +extern uint8_t _map_tile_offset; +inline void set_bkg_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles, uint8_t base_tile) { + _map_tile_offset = base_tile; + set_tile_map_compat(x, y, w, h, tiles); + _map_tile_offset = 0; +} +inline void set_win_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles, uint8_t base_tile) { + _map_tile_offset = base_tile; + set_tile_map_compat(x, y, w, h, tiles); + _map_tile_offset = 0; +} + void set_tile_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); void set_tile_submap_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); inline void set_bkg_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) { @@ -577,6 +589,18 @@ inline void set_win_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uin set_tile_submap_compat(x, y, w, h, map_w, map); } +extern uint8_t _submap_tile_offset; +inline void set_bkg_based_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w, uint8_t base_tile) { + _submap_tile_offset = base_tile; + set_tile_submap_compat(x, y, w, h, map_w, map); + _submap_tile_offset = 0; +} +inline void set_win_based_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w, uint8_t base_tile) { + _submap_tile_offset = base_tile; + set_tile_submap_compat(x, y, w, h, map_w, map); + _submap_tile_offset = 0; +} + void fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); void fill_rect_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); #define fill_bkg_rect fill_rect_compat diff --git a/gbdk-lib/libc/targets/gbz80/set_tile_submap.s b/gbdk-lib/libc/targets/gbz80/set_tile_submap.s @@ -1,10 +1,22 @@ .include "global.s" + .title "Set tile submap" + .module SetTileSubmap + .area _DATA .image_tile_width:: .ds 0x01 + .area _INITIALIZED + +__submap_tile_offset:: + .ds 0x01 + + .area _INITIALIZER + + .db 0x00 + .area _HOME _set_bkg_submap:: @@ -91,8 +103,10 @@ _set_bkg_submap:: push bc ; store dest 3$: ; copy w tiles WAIT_STAT - ld a, (hl+) + ld a, (__submap_tile_offset) + add (hl) ld (bc), a + inc hl ld a, c ; inc dest and wrap around and #0xe0 diff --git a/gbdk-lib/libc/targets/gbz80/set_xy_t.s b/gbdk-lib/libc/targets/gbz80/set_xy_t.s @@ -1,5 +1,17 @@ .include "global.s" + .title "Set tile map" + .module SetTileMap + + .area _INITIALIZED + +__map_tile_offset:: + .ds 0x01 + + .area _INITIALIZER + + .db 0x00 + .area _HOME ;; Set window tile table from BC at XY = DE of size WH = HL @@ -43,8 +55,10 @@ 3$: ; Copy W tiles WAIT_STAT - LD A, (HL+) + LD A, (__map_tile_offset) + ADD (HL) LD (BC), A + INC HL LD A, C ; inc dest and wrap around AND #0xE0 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 @@ -7,6 +7,15 @@ .ez80 + .area _INITIALIZED + +__map_tile_offset:: + .ds 0x01 + + .area _INITIALIZER + + .db 0x00 + .area _HOME ;; Set background tile table from (BC) at XY = DE of size WH = HL @@ -52,8 +61,13 @@ SMS_WRITE_VDP_CMD ixh, ixl ld c, #.VDP_DATA 2$: ; copy W tiles - outi - VDP_DELAY + ld a, (__map_tile_offset) + add (hl) + out (c), a + inc hl + dec b + jr 8$ ; delay +8$: in a, (c) ; skip next byte ld a, ixl diff --git a/gbdk-lib/libc/targets/z80/set_tile_submap_compat.s b/gbdk-lib/libc/targets/z80/set_tile_submap_compat.s @@ -10,6 +10,15 @@ .image_tile_width_compat:: .ds 0x01 + .area _INITIALIZED + +__submap_tile_offset:: + .ds 0x01 + + .area _INITIALIZER + + .db 0x00 + .area _HOME ; void set_tile_submap_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl); @@ -102,8 +111,13 @@ _set_tile_submap_compat:: SMS_WRITE_VDP_CMD ixh, ixl ld c, #.VDP_DATA 2$: ; copy W tiles - outi - VDP_DELAY + ld a, (__map_tile_offset) + add (hl) + out (c), a + inc hl + dec b + jr 8$ ; delay +8$: in a, (c) ; skip next byte ld a, ixl
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.