git.y1.nz

gbdk-2020

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

commit 8df189301c0b9187ff2daa85a7a28a9ea241ab3e
parent d2387e6fcd33237e2b010e917b195138e71391d2
Author: bbbbbr <bbbbbr@users.noreply.github.com>
Date:   Sun, 25 Aug 2024 03:07:35 -0700

Merge pull request #713 from bbbbbr/png2asset/gbc_512_tile_maps

png2asset: support 512 tiles via alternate tile bank on GBC
Diffstat:
Mgbdk-support/png2asset/map_attributes.h22++++++++++++++++++++--
Mgbdk-support/png2asset/maps.cpp37++++++++++++++++++++++++++++++-------
2 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/gbdk-support/png2asset/map_attributes.h b/gbdk-support/png2asset/map_attributes.h @@ -7,4 +7,22 @@ unsigned char GetMapAttribute(size_t x, size_t y); void ReduceMapAttributes2x2(PNG2AssetData* assetData); void AlignMapAttributes(PNG2AssetData* assetData); void PackMapAttributes(PNG2AssetData* assetData); -void HandleMapAttributes( PNG2AssetData* assetData); - +void HandleMapAttributes( PNG2AssetData* assetData); + + + enum { + CGB_BKGF_PRI = 0b10000000, /**< Background CGB BG and Window over Sprite priority Enabled */ + CGB_BKGF_YFLIP = 0b01000000, /**< Background CGB Y axis flip: Vertically mirrored */ + CGB_BKGF_XFLIP = 0b00100000, /**< Background CGB X axis flip: Horizontally mirrored */ + CGB_BKGF_BANK0 = 0b00000000, /**< Background CGB Tile VRAM-Bank: Use Bank 0 (CGB Mode Only) */ + CGB_BKGF_BANK1 = 0b00001000, /**< Background CGB Tile VRAM-Bank: Use Bank 1 (CGB Mode Only) */ + + CGB_BKGF_CGB_PAL0 = 0b00000000, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL1 = 0b00000001, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL2 = 0b00000010, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL3 = 0b00000011, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL4 = 0b00000100, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL5 = 0b00000101, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL6 = 0b00000110, /**< Background CGB Palette number (CGB Mode Only) */ + CGB_BKGF_CGB_PAL7 = 0b00000111, /**< Background CGB Palette number (CGB Mode Only) */ +}; + diff --git a/gbdk-support/png2asset/maps.cpp b/gbdk-support/png2asset/maps.cpp @@ -47,6 +47,31 @@ void ExtractTileset(PNG2AssetData* assetData, vector< Tile > & tileset, bool kee } +static void checkWarnMapTileLimits(PNG2AssetData* assetData) { + + unsigned int maxUsedTileCount = (assetData->tiles.size() + assetData->args->tile_origin); + unsigned int maxTilesWarnLimit = 256; // 256 is default for GB, NES + + // GB + Map Attributes implies GBC which has a secondary tile bank + if (((assetData->args->pack_mode == Tile::GB) && assetData->args->use_map_attributes) || + (assetData->args->pack_mode == Tile::SMS)) { + maxTilesWarnLimit = 512; + } + + if (maxUsedTileCount > maxTilesWarnLimit) { + printf("Warning: Tile count (%d) + tile origin (%d) = %d exceeds limit %d\n", + (unsigned int)assetData->tiles.size(), (unsigned int)assetData->args->tile_origin, + maxUsedTileCount, maxTilesWarnLimit); + } + + // If using GBC, notify user about extra requirements to use > 256 tiles + if ((maxUsedTileCount > 256) && ((assetData->args->pack_mode == Tile::GB) && assetData->args->use_map_attributes)) { + printf("Warning: On GBC more then 256 tiles may require use of alternate tile bank. Tile count (%d) + tile origin (%d) = %d\n", + (unsigned int)assetData->tiles.size(), (unsigned int)assetData->args->tile_origin, maxUsedTileCount); + } +} + + void GetMap(PNG2AssetData* assetData) { for(int y = 0; y < (int)assetData->image.h; y += assetData->image.tile_h) @@ -88,12 +113,6 @@ void GetMap(PNG2AssetData* assetData) assetData->tiles.push_back(tile); idx = assetData->tiles.size() - 1; props = assetData->args->props_default; - - if(assetData->tiles.size() > 256 && assetData->args->pack_mode != Tile::SMS) - printf("Warning: found more than 256 tiles on x:%d,y:%d\n", x, y); - - if(((assetData->tiles.size() + assetData->args->tile_origin) > 256) && (assetData->args->pack_mode != Tile::SMS)) - printf("Warning: tile count (%d) + tile origin (%d) exceeds 256 at x:%d,y:%d\n", (unsigned int)assetData->tiles.size(), assetData->args->tile_origin, x, y); } } @@ -120,12 +139,16 @@ void GetMap(PNG2AssetData* assetData) else { props |= pal_idx; + // If GBC and more than 256 tiles then add in tile bank num + if ((idx > 255) && (assetData->args->pack_mode == Tile::GB)) + props |= CGB_BKGF_BANK1; assetData->map_attributes.push_back(props); } } } } - HandleMapAttributes( assetData); + checkWarnMapTileLimits(assetData); + HandleMapAttributes(assetData); }

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