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.
This commit is contained in:
parent
411a3fe65d
commit
346b01be07
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<QRgb, int> 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user