git.y1.nz

gbdk-2020

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

commit b48cde5d07788ba41e1f587e1aae04fcb91e01c8
parent b40505e3fba4c2871b8f4ef709c866c78c1fd809
Author: Toxa <56631470+untoxa@users.noreply.github.com>
Date:   Wed, 20 May 2026 14:44:16 +0300

add set_win_submap_attributes() function for consistency
Diffstat:
Mgbdk-lib/include/gb/gb.h55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/include/nes/nes.h21+++++++++++++++++++++
Mgbdk-lib/include/sms/sms.h6++++++
Mgbdk-lib/libc/targets/mos6502/nes/set_tile_submap_attributes.s24++++++++++++++++++++----
4 files changed, 102 insertions(+), 4 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -1647,6 +1647,61 @@ inline void set_win_based_tiles(uint8_t x, uint8_t y, uint8_t w, uint8_t h, cons 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 Attributes using a sub-region + from a source tile attribute map. Useful for scrolling implementations of maps + larger than 32 x 32 tiles. + + @param x X Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255 + @param y Y Start position in both the Source Tile Map and hardware Window Map tile coordinates. Range 0 - 255 + @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 attribute data + @param map_w Width of source tile map in tiles. Range 1 - 255 + + 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. + + The __x__ and __y__ parameters are in Source Tile Map tile + coordinates. The location tiles will be written to on the + hardware Window Map is derived from those, but only uses + the lower 5 bits of each axis, for range of 0-31 (they are + bit-masked: `x & 0x1F` and `y & 0x1F`). As a result the two + coordinate systems are aligned together. + + In order to transfer tile map data in a way where the + coordinate systems are not aligned, an offset from the + Source Tile Map pointer can be passed in: + `(map_ptr + x + (y * map_width))`. + + For example, if you want the tile id at `1,2` from the source map to + show up at `0,0` on the hardware Window Map (instead of at `1,2`) + then modify the pointer address that is passed in: + `map_ptr + 1 + (2 * map_width)` + + 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. + + See @ref set_win_tiles for setting CGB attribute maps with @ref VBK_REG. + + @see SHOW_BKG + @see set_win_data, set_win_attributes, set_bkg_submap, set_tiles + + @note On the Game Boy this is only usable in Game Boy Color mode +*/ +inline void set_win_submap_attributes(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) +{ + VBK_REG = VBK_ATTRIBUTES; + set_win_submap(x, y, w, h, map, map_w); + VBK_REG = VBK_TILES; +} + + /** Sets a rectangular area of the Window Tile Map using a sub-region from a source tile map. The offset value in __base_tile__ is added to the tile ID for each map entry. diff --git a/gbdk-lib/include/nes/nes.h b/gbdk-lib/include/nes/nes.h @@ -1242,6 +1242,27 @@ void set_win_based_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint #define set_win_based_submap set_bkg_based_submap #endif +/** Sets a rectangular area of the Window Tile Map attributes using + a sub-region from a source tile map. Useful for scrolling implementations + of maps larger than 32 x 30 tiles. + + Please note that this is just a wrapper function for set_win_submap_attributes_nes16x16() + and divides the coordinates and dimensions by 2 to achieve this. + It is intended to make code more portable by using the same coordinate system + that systems with the much more common 8x8 attribute resolution would use. + + @see SHOW_BKG + @see set_win_data, set_win_tiles, set_bkg_submap, set_tiles +*/ +#if defined(NES_WINDOW_LAYER) +inline void set_win_submap_attributes(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *attributes, uint8_t map_w) +{ + set_win_submap_attributes_nes16x16(x >> 1, y >> 1, (w + 1) >> 1, (h + 1) >> 1, attributes, (map_w + 1) >> 1); +} +#else +#define set_win_submap_attributes set_bkg_submap_attributes +#endif + /** * Set single tile t on window layer at x,y * @param x X-coordinate diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -721,6 +721,12 @@ inline void set_bkg_submap_attributes(uint8_t x, uint8_t y, uint8_t w, uint8_t h VBK_REG = VBK_TILES; } +inline void set_win_submap_attributes(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) { + VBK_REG = VBK_ATTRIBUTES; + set_tile_submap_compat(x, y, w, h, map, map_w); + VBK_REG = VBK_TILES; +} + void fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE; void fill_rect_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) Z88DK_CALLEE; #define fill_bkg_rect fill_rect_compat diff --git a/gbdk-lib/libc/targets/mos6502/nes/set_tile_submap_attributes.s b/gbdk-lib/libc/targets/mos6502/nes/set_tile_submap_attributes.s @@ -1,10 +1,14 @@ .include "global.s" .area GBDKOVR (PAG, OVR) - _set_bkg_submap_attributes_nes16x16_PARM_3:: .ds 1 - _set_bkg_submap_attributes_nes16x16_PARM_4:: .ds 1 - _set_bkg_submap_attributes_nes16x16_PARM_5:: .ds 2 - _set_bkg_submap_attributes_nes16x16_PARM_6:: .ds 1 + _set_bkg_submap_attributes_nes16x16_PARM_3:: + _set_win_submap_attributes_nes16x16_PARM_3:: .ds 1 + _set_bkg_submap_attributes_nes16x16_PARM_4:: + _set_win_submap_attributes_nes16x16_PARM_4:: .ds 1 + _set_bkg_submap_attributes_nes16x16_PARM_5:: + _set_win_submap_attributes_nes16x16_PARM_5:: .ds 2 + _set_bkg_submap_attributes_nes16x16_PARM_6:: + _set_win_submap_attributes_nes16x16_PARM_6:: .ds 1 .xpos: .ds 1 .ypos: .ds 1 .num_rows: .ds 1 @@ -125,6 +129,18 @@ lbl: .endif .endm +.ifdef NES_WINDOW_LAYER +_set_win_submap_attributes_nes16x16:: + lda *__current_vram_cfg_write + pha + ora #MAPPER_CFG_NT_MASK + sta *__current_vram_cfg_write + jsr _set_bkg_submap_attributes_nes16x16 + pla + sta *__current_vram_cfg_write + rts +.endif + _set_bkg_submap_attributes_nes16x16:: .define .width "_set_bkg_submap_attributes_nes16x16_PARM_3" .define .height "_set_bkg_submap_attributes_nes16x16_PARM_4"

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.