From 346b01be077b90dbe04f1318fdb1d607c2d5fd78 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 5 May 2017 18:54:13 -0500 Subject: [PATCH] Start on support for 4 bpp images This may be all that's needed, but there seems to be another issue causing the characters to look weird, though that's probably a filesystem issue. --- build_rom.sh | 4 ++-- src/core/gba/gfx.cpp | 15 +++++++++++---- src/tools/pack.cpp | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/build_rom.sh b/build_rom.sh index b6e1671d..a806294c 100755 --- a/build_rom.sh +++ b/build_rom.sh @@ -2,11 +2,11 @@ set -e -${DEVKITARM}/bin/padbin 32 build/gba-release/src/player/nostalgia.bin 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 1 -tiles 40 -c +./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 101 -tiles 40 -bpp 4 -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 ${DEVKITARM}/bin/gbafix nostalgia.gba diff --git a/src/core/gba/gfx.cpp b/src/core/gba/gfx.cpp index 69b981a7..9ff6c8d1 100644 --- a/src/core/gba/gfx.cpp +++ b/src/core/gba/gfx.cpp @@ -129,12 +129,19 @@ 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); + REG_BG0CNT = (28 << 8) | 1; - REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel + if (imgData.bpp == 8) { + REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel + } if (fs) { - FileStore32::FsSize_t readSize = 0; - fs->read(1, __builtin_offsetof(GbaImageData, tiles), 64 * 38, &TILE8_ADDR[0][1], nullptr); - fs->read(1, 0, 512, &MEM_PALLETE_BG[0], &readSize); + 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); } } diff --git a/src/tools/pack.cpp b/src/tools/pack.cpp index 60d09e46..7de52069 100644 --- a/src/tools/pack.cpp +++ b/src/tools/pack.cpp @@ -64,6 +64,7 @@ int run(ClArgs args) { QString argFsPath = args.getString("fs").c_str(); auto argCompact = args.getBool("c"); auto argTiles = args.getInt("tiles"); + auto argBpp = args.getInt("bpp"); QImage src(argInPath); @@ -71,13 +72,16 @@ int run(ClArgs args) { if (argTiles == 0) { argTiles = (src.width() * src.height()) / 64; } + if (argBpp != 4 && argBpp != 8) { + argBpp = 8; + } QMap colors; const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + argTiles * 64; uint8_t imgDataBuff[imgDataBuffSize]; memset(&imgDataBuff, 0, imgDataBuffSize); GbaImageData *id = (GbaImageData*) imgDataBuff; - id->bpp = 8; + id->bpp = argBpp; id->tileCount = argTiles; int colorId = 0; @@ -87,11 +91,21 @@ int run(ClArgs args) { auto destI = pointToIdx(src.width(), x, y); if (destI <= argTiles * 64) { auto c = src.pixel(x, y); + // assign color a color id for the palette if (!colors.contains(c)) { colors[c] = colorId; colorId++; } - id->tiles[destI] = colors[c]; + // set pixel color + if (argBpp == 4) { + if (destI % 2) { // is odd number pixel + id->tiles[destI / 2] |= colors[c] << 4; + } else { + id->tiles[destI / 2] |= colors[c]; + } + } else { + id->tiles[destI] = colors[c]; + } } } }