all repos — mgba @ 97e94610e6e8a2e4b38f77224f5702a8f93edcfe

mGBA Game Boy Advance Emulator

GB Video: Fix SGB palettes on load state
Vicki Pfau vi@endrift.com
Mon, 02 Apr 2018 12:20:52 -0700
commit

97e94610e6e8a2e4b38f77224f5702a8f93edcfe

parent

c9f50b2c5a644355b4190d44c290032561d1ff33

2 files changed, 10 insertions(+), 7 deletions(-)

jump to
M src/gb/renderers/software.csrc/gb/renderers/software.c

@@ -359,6 +359,9 @@

static void GBVideoSoftwareRendererWritePalette(struct GBVideoRenderer* renderer, int index, uint16_t value) { struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer; color_t color = mColorFrom555(value); + if (softwareRenderer->model == GB_MODEL_SGB && index < 0x10 && index && !(index & 3)) { + color = softwareRenderer->palette[0]; + } softwareRenderer->palette[index] = color; if (renderer->cache) { mCacheSetWritePalette(renderer->cache, index, color);
M src/gb/video.csrc/gb/video.c

@@ -606,12 +606,12 @@ video->renderer->writePalette(video->renderer, 0, video->palette[0]);

video->renderer->writePalette(video->renderer, 1, video->palette[1]); video->renderer->writePalette(video->renderer, 2, video->palette[2]); video->renderer->writePalette(video->renderer, 3, video->palette[3]); - video->renderer->writePalette(video->renderer, 4, video->palette[0]); + video->renderer->writePalette(video->renderer, 4, video->palette[4]); video->renderer->writePalette(video->renderer, 5, video->palette[5]); video->renderer->writePalette(video->renderer, 6, video->palette[6]); video->renderer->writePalette(video->renderer, 7, video->palette[7]); - video->renderer->writePalette(video->renderer, 8, video->palette[0]); - video->renderer->writePalette(video->renderer, 12, video->palette[0]); + video->renderer->writePalette(video->renderer, 8, video->palette[8]); + video->renderer->writePalette(video->renderer, 12, video->palette[12]); break; case SGB_PAL23: video->palette[9] = data[3] | (data[4] << 8);

@@ -645,9 +645,9 @@ video->renderer->writePalette(video->renderer, 0, video->palette[0]);

video->renderer->writePalette(video->renderer, 1, video->palette[1]); video->renderer->writePalette(video->renderer, 2, video->palette[2]); video->renderer->writePalette(video->renderer, 3, video->palette[3]); - video->renderer->writePalette(video->renderer, 4, video->palette[0]); - video->renderer->writePalette(video->renderer, 8, video->palette[0]); - video->renderer->writePalette(video->renderer, 12, video->palette[0]); + video->renderer->writePalette(video->renderer, 4, video->palette[4]); + video->renderer->writePalette(video->renderer, 8, video->palette[8]); + video->renderer->writePalette(video->renderer, 12, video->palette[12]); video->renderer->writePalette(video->renderer, 13, video->palette[13]); video->renderer->writePalette(video->renderer, 14, video->palette[14]); video->renderer->writePalette(video->renderer, 15, video->palette[15]);

@@ -675,7 +675,7 @@ mLOG(GB, STUB, "Unimplemented SGB palette overflow: %03X", entry);

continue; } LOAD_16LE(video->palette[i * 4 + 0], entry * 8 + 0, video->renderer->sgbPalRam); - video->renderer->writePalette(video->renderer, i * 4 + 0, video->palette[0]); + video->renderer->writePalette(video->renderer, i * 4 + 0, video->palette[i * 4 + 0]); LOAD_16LE(video->palette[i * 4 + 1], entry * 8 + 2, video->renderer->sgbPalRam); video->renderer->writePalette(video->renderer, i * 4 + 1, video->palette[i * 4 + 1]); LOAD_16LE(video->palette[i * 4 + 2], entry * 8 + 4, video->renderer->sgbPalRam);