From 8a2ba6c1714f9230bf24883eaef4d3caa1e062f2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 7 May 2017 21:41:52 -0500 Subject: [PATCH] Cleanup format of GbaImageData --- build_rom.sh | 4 ++-- src/core/gba/gba.hpp | 12 ++++++++---- src/core/gba/gfx.cpp | 23 ++++++++++++++--------- src/tools/pack.cpp | 4 ++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/build_rom.sh b/build_rom.sh index a806294c..e9e5b6ec 100755 --- a/build_rom.sh +++ b/build_rom.sh @@ -4,8 +4,8 @@ set -e echo NOSTALGIA_MEDIA_HEADER_________ > media_header.txt -oxfs format 32 1m nostalgia_media.oxfs -./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 101 -tiles 40 -bpp 4 -c +./build/current/deps/ox/src/ox/fs/oxfs format 32 1k nostalgia_media.oxfs +./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 101 -tiles 40 -c ${DEVKITARM}/bin/padbin 32 build/gba-release/src/player/nostalgia.bin cat build/gba-release/src/player/nostalgia.bin media_header.txt nostalgia_media.oxfs > nostalgia.gba diff --git a/src/core/gba/gba.hpp b/src/core/gba/gba.hpp index 4c5d0e80..bcf5eed6 100644 --- a/src/core/gba/gba.hpp +++ b/src/core/gba/gba.hpp @@ -17,14 +17,18 @@ typedef struct { uint32_t data[8]; } __attribute__((aligned(4))) Tile, Tile4; // d-tile: double-sized tile (8bpp) typedef struct { uint32_t data[16]; } __attribute__((aligned(4))) Tile8; // tile block: 32x16 tiles, 16x16 d-tiles -typedef uint16_t Pallete[256]; +typedef uint16_t Palette[256]; typedef Tile CharBlock[512]; typedef Tile8 CharBlock8[256]; -struct __attribute__((packed)) GbaImageData { - Pallete pal; - uint16_t tileCount; +struct __attribute__((packed)) GbaImageDataHeader { uint8_t bpp; + uint16_t tileCount; +}; + +struct __attribute__((packed)) GbaImageData { + GbaImageDataHeader header; + Palette __attribute__((packed)) pal; uint8_t tiles[1]; }; diff --git a/src/core/gba/gfx.cpp b/src/core/gba/gfx.cpp index 9ff6c8d1..8069de1f 100644 --- a/src/core/gba/gfx.cpp +++ b/src/core/gba/gfx.cpp @@ -130,18 +130,23 @@ ox::Error initGfx() { void initConsole() { auto fs = (FileStore32*) findMedia(); - GbaImageData imgData; - fs->read(101, __builtin_offsetof(GbaImageData, tileCount), - sizeof(imgData.tileCount) + sizeof(imgData.bpp), - &imgData.tileCount, nullptr); + GbaImageDataHeader imgData; + fs->read(101, 0, sizeof(imgData), &imgData, nullptr); REG_BG0CNT = (28 << 8) | 1; - if (imgData.bpp == 8) { - REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel - } if (fs) { - fs->read(101, __builtin_offsetof(GbaImageData, tiles), 64 * 38, &TILE8_ADDR[0][1], nullptr); - fs->read(101, __builtin_offsetof(GbaImageData, pal), 512, &MEM_PALLETE_BG[0], nullptr); + // load palette + fs->read(101, sizeof(GbaImageDataHeader), + 512, (uint16_t*) &MEM_PALLETE_BG[0], nullptr); + + if (imgData.bpp == 4) { + fs->read(101, __builtin_offsetof(GbaImageData, tiles), + sizeof(Tile) * imgData.tileCount, (uint16_t*) &TILE_ADDR[0][1], nullptr); + } else { + REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel + fs->read(101, __builtin_offsetof(GbaImageData, tiles), + sizeof(Tile8) * imgData.tileCount, (uint16_t*) &TILE8_ADDR[0][1], nullptr); + } } } diff --git a/src/tools/pack.cpp b/src/tools/pack.cpp index 7de52069..d5e2e288 100644 --- a/src/tools/pack.cpp +++ b/src/tools/pack.cpp @@ -81,8 +81,8 @@ int run(ClArgs args) { uint8_t imgDataBuff[imgDataBuffSize]; memset(&imgDataBuff, 0, imgDataBuffSize); GbaImageData *id = (GbaImageData*) imgDataBuff; - id->bpp = argBpp; - id->tileCount = argTiles; + id->header.bpp = argBpp; + id->header.tileCount = argTiles; int colorId = 0; // copy pixels as color ids