all repos — mgba @ b11171c6f1144ff00d5094454662f3ad4e4f5b4f

mGBA Game Boy Advance Emulator

GB Video: Expand custom palettes to separate BG/OBJ palettes
Vicki Pfau vi@endrift.com
Tue, 26 Sep 2017 18:21:51 -0700
commit

b11171c6f1144ff00d5094454662f3ad4e4f5b4f

parent

431ee76c1a362188012ec1ddbf6213422f82dfb4

M include/mgba/internal/gb/overrides.hinclude/mgba/internal/gb/overrides.h

@@ -17,7 +17,7 @@ int headerCrc32;

enum GBModel model; enum GBMemoryBankControllerType mbc; - uint32_t gbColors[4]; + uint32_t gbColors[12]; }; struct Configuration;
M include/mgba/internal/gb/video.hinclude/mgba/internal/gb/video.h

@@ -145,7 +145,7 @@ int ocpIndex;

bool ocpIncrement; uint8_t sgbCommandHeader; - uint16_t dmgPalette[4]; + uint16_t dmgPalette[12]; uint16_t palette[64]; bool sgbBorders;
M src/gb/core.csrc/gb/core.c

@@ -179,6 +179,30 @@ }

if (mCoreConfigGetIntValue(config, "gb.pal[3]", &color)) { GBVideoSetPalette(&gb->video, 3, color); } + if (mCoreConfigGetIntValue(config, "gb.pal[4]", &color)) { + GBVideoSetPalette(&gb->video, 4, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[5]", &color)) { + GBVideoSetPalette(&gb->video, 5, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[6]", &color)) { + GBVideoSetPalette(&gb->video, 6, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[7]", &color)) { + GBVideoSetPalette(&gb->video, 7, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[8]", &color)) { + GBVideoSetPalette(&gb->video, 8, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[9]", &color)) { + GBVideoSetPalette(&gb->video, 9, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[10]", &color)) { + GBVideoSetPalette(&gb->video, 10, color); + } + if (mCoreConfigGetIntValue(config, "gb.pal[11]", &color)) { + GBVideoSetPalette(&gb->video, 11, color); + } mCoreConfigCopyValue(&core->config, config, "gb.bios"); mCoreConfigCopyValue(&core->config, config, "sgb.bios");
M src/gb/overrides.csrc/gb/overrides.c

@@ -19,6 +19,7 @@

bool GBOverrideFind(const struct Configuration* config, struct GBCartridgeOverride* override) { override->model = GB_MODEL_AUTODETECT; override->mbc = GB_MBC_AUTODETECT; + memset(override->gbColors, 0, sizeof(override->gbColors)); bool found = false; int i;

@@ -35,11 +36,19 @@ char sectionName[24] = "";

snprintf(sectionName, sizeof(sectionName), "gb.override.%08X", override->headerCrc32); const char* model = ConfigurationGetValue(config, sectionName, "model"); const char* mbc = ConfigurationGetValue(config, sectionName, "mbc"); - const char* pal[4] = { + const char* pal[12] = { ConfigurationGetValue(config, sectionName, "pal[0]"), ConfigurationGetValue(config, sectionName, "pal[1]"), ConfigurationGetValue(config, sectionName, "pal[2]"), - ConfigurationGetValue(config, sectionName, "pal[3]") + ConfigurationGetValue(config, sectionName, "pal[3]"), + ConfigurationGetValue(config, sectionName, "pal[4]"), + ConfigurationGetValue(config, sectionName, "pal[5]"), + ConfigurationGetValue(config, sectionName, "pal[6]"), + ConfigurationGetValue(config, sectionName, "pal[7]"), + ConfigurationGetValue(config, sectionName, "pal[8]"), + ConfigurationGetValue(config, sectionName, "pal[9]"), + ConfigurationGetValue(config, sectionName, "pal[10]"), + ConfigurationGetValue(config, sectionName, "pal[11]") }; if (model) {

@@ -56,18 +65,25 @@ found = true;

} } - if (pal[0] && pal[1] && pal[2] && pal[3]) { - int i; - for (i = 0; i < 4; ++i) { - char* end; - unsigned long value = strtoul(pal[i], &end, 10); - if (end == &pal[i][1] && *end == 'x') { - value = strtoul(pal[i], &end, 16); - } - if (*end) { - continue; - } - override->gbColors[i] = value; + for (i = 0; i < 12; ++i) { + if (!pal[i]) { + continue; + } + char* end; + unsigned long value = strtoul(pal[i], &end, 10); + if (end == &pal[i][1] && *end == 'x') { + value = strtoul(pal[i], &end, 16); + } + if (*end) { + continue; + } + value |= 0xFF000000; + override->gbColors[i] = value; + if (i < 8) { + override->gbColors[i + 4] = value; + } + if (i < 4) { + override->gbColors[i + 8] = value; } } }

@@ -80,12 +96,43 @@ snprintf(sectionName, sizeof(sectionName), "gb.override.%08X", override->headerCrc32);

const char* model = GBModelToName(override->model); ConfigurationSetValue(config, sectionName, "model", model); - if (override->gbColors[0] | override->gbColors[1] | override->gbColors[2] | override->gbColors[3]) { - ConfigurationSetIntValue(config, sectionName, "pal[0]", override->gbColors[0]); - ConfigurationSetIntValue(config, sectionName, "pal[1]", override->gbColors[1]); - ConfigurationSetIntValue(config, sectionName, "pal[2]", override->gbColors[2]); - ConfigurationSetIntValue(config, sectionName, "pal[3]", override->gbColors[3]); + if (override->gbColors[0] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[0]", override->gbColors[0] & ~0xFF000000); } + if (override->gbColors[1] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[1]", override->gbColors[1] & ~0xFF000000); + } + if (override->gbColors[2] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[2]", override->gbColors[2] & ~0xFF000000); + } + if (override->gbColors[3] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[3]", override->gbColors[3] & ~0xFF000000); + } + if (override->gbColors[4] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[4]", override->gbColors[4] & ~0xFF000000); + } + if (override->gbColors[5] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[5]", override->gbColors[5] & ~0xFF000000); + } + if (override->gbColors[6] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[6]", override->gbColors[6] & ~0xFF000000); + } + if (override->gbColors[7] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[7]", override->gbColors[7] & ~0xFF000000); + } + if (override->gbColors[8] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[8]", override->gbColors[8] & ~0xFF000000); + } + if (override->gbColors[9] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[9]", override->gbColors[9] & ~0xFF000000); + } + if (override->gbColors[10] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[10]", override->gbColors[10] & ~0xFF000000); + } + if (override->gbColors[11] & 0xFF000000) { + ConfigurationSetIntValue(config, sectionName, "pal[11]", override->gbColors[11] & ~0xFF000000); + } + if (override->mbc != GB_MBC_AUTODETECT) { ConfigurationSetIntValue(config, sectionName, "mbc", override->mbc); } else {

@@ -103,11 +150,18 @@ gb->memory.mbcType = override->mbc;

GBMBCInit(gb); } - if (override->gbColors[0] | override->gbColors[1] | override->gbColors[2] | override->gbColors[3]) { - GBVideoSetPalette(&gb->video, 0, override->gbColors[0]); - GBVideoSetPalette(&gb->video, 1, override->gbColors[1]); - GBVideoSetPalette(&gb->video, 2, override->gbColors[2]); - GBVideoSetPalette(&gb->video, 3, override->gbColors[3]); + int i; + for (i = 0; i < 12; ++i) { + if (!(override->gbColors[i] & 0xFF000000)) { + continue; + } + GBVideoSetPalette(&gb->video, i, override->gbColors[i]); + if (i < 8) { + GBVideoSetPalette(&gb->video, i + 4, override->gbColors[i]); + } + if (i < 4) { + GBVideoSetPalette(&gb->video, i + 8, override->gbColors[i]); + } } }
M src/gb/video.csrc/gb/video.c

@@ -72,6 +72,14 @@ video->dmgPalette[0] = 0x7FFF;

video->dmgPalette[1] = 0x56B5; video->dmgPalette[2] = 0x294A; video->dmgPalette[3] = 0x0000; + video->dmgPalette[4] = 0x7FFF; + video->dmgPalette[5] = 0x56B5; + video->dmgPalette[6] = 0x294A; + video->dmgPalette[7] = 0x0000; + video->dmgPalette[8] = 0x7FFF; + video->dmgPalette[9] = 0x56B5; + video->dmgPalette[10] = 0x294A; + video->dmgPalette[11] = 0x0000; video->sgbBorders = true;

@@ -115,14 +123,14 @@ video->palette[0] = video->dmgPalette[0];

video->palette[1] = video->dmgPalette[1]; video->palette[2] = video->dmgPalette[2]; video->palette[3] = video->dmgPalette[3]; - video->palette[8 * 4 + 0] = video->dmgPalette[0]; - video->palette[8 * 4 + 1] = video->dmgPalette[1]; - video->palette[8 * 4 + 2] = video->dmgPalette[2]; - video->palette[8 * 4 + 3] = video->dmgPalette[3]; - video->palette[9 * 4 + 0] = video->dmgPalette[0]; - video->palette[9 * 4 + 1] = video->dmgPalette[1]; - video->palette[9 * 4 + 2] = video->dmgPalette[2]; - video->palette[9 * 4 + 3] = video->dmgPalette[3]; + video->palette[8 * 4 + 0] = video->dmgPalette[4]; + video->palette[8 * 4 + 1] = video->dmgPalette[5]; + video->palette[8 * 4 + 2] = video->dmgPalette[6]; + video->palette[8 * 4 + 3] = video->dmgPalette[7]; + video->palette[9 * 4 + 0] = video->dmgPalette[8]; + video->palette[9 * 4 + 1] = video->dmgPalette[9]; + video->palette[9 * 4 + 2] = video->dmgPalette[10]; + video->palette[9 * 4 + 3] = video->dmgPalette[11]; video->renderer->deinit(video->renderer); video->renderer->init(video->renderer, video->p->model, video->sgbBorders);

@@ -478,20 +486,20 @@ video->renderer->writePalette(video->renderer, 2, video->palette[2]);

video->renderer->writePalette(video->renderer, 3, video->palette[3]); break; case REG_OBP0: - video->palette[8 * 4 + 0] = video->dmgPalette[value & 3]; - video->palette[8 * 4 + 1] = video->dmgPalette[(value >> 2) & 3]; - video->palette[8 * 4 + 2] = video->dmgPalette[(value >> 4) & 3]; - video->palette[8 * 4 + 3] = video->dmgPalette[(value >> 6) & 3]; + video->palette[8 * 4 + 0] = video->dmgPalette[(value & 3) + 4]; + video->palette[8 * 4 + 1] = video->dmgPalette[((value >> 2) & 3) + 4]; + video->palette[8 * 4 + 2] = video->dmgPalette[((value >> 4) & 3) + 4]; + video->palette[8 * 4 + 3] = video->dmgPalette[((value >> 6) & 3) + 4]; video->renderer->writePalette(video->renderer, 8 * 4 + 0, video->palette[8 * 4 + 0]); video->renderer->writePalette(video->renderer, 8 * 4 + 1, video->palette[8 * 4 + 1]); video->renderer->writePalette(video->renderer, 8 * 4 + 2, video->palette[8 * 4 + 2]); video->renderer->writePalette(video->renderer, 8 * 4 + 3, video->palette[8 * 4 + 3]); break; case REG_OBP1: - video->palette[9 * 4 + 0] = video->dmgPalette[value & 3]; - video->palette[9 * 4 + 1] = video->dmgPalette[(value >> 2) & 3]; - video->palette[9 * 4 + 2] = video->dmgPalette[(value >> 4) & 3]; - video->palette[9 * 4 + 3] = video->dmgPalette[(value >> 6) & 3]; + video->palette[9 * 4 + 0] = video->dmgPalette[(value & 3) + 8]; + video->palette[9 * 4 + 1] = video->dmgPalette[((value >> 2) & 3) + 8]; + video->palette[9 * 4 + 2] = video->dmgPalette[((value >> 4) & 3) + 8]; + video->palette[9 * 4 + 3] = video->dmgPalette[((value >> 6) & 3) + 8]; video->renderer->writePalette(video->renderer, 9 * 4 + 0, video->palette[9 * 4 + 0]); video->renderer->writePalette(video->renderer, 9 * 4 + 1, video->palette[9 * 4 + 1]); video->renderer->writePalette(video->renderer, 9 * 4 + 2, video->palette[9 * 4 + 2]);

@@ -547,7 +555,7 @@ video->vramCurrentBank = value;

} void GBVideoSetPalette(struct GBVideo* video, unsigned index, uint32_t color) { - if (index >= 4) { + if (index >= 12) { return; } video->dmgPalette[index] = M_RGB8_TO_RGB5(color);