GB: Support CGB lockout
Vicki Pfau vi@endrift.com
Tue, 26 Sep 2017 18:22:09 -0700
3 files changed,
22 insertions(+),
0 deletions(-)
M
include/mgba/internal/gb/video.h
→
include/mgba/internal/gb/video.h
@@ -167,6 +167,7 @@ void GBVideoWriteLYC(struct GBVideo* video, uint8_t value);
void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value); void GBVideoSwitchBank(struct GBVideo* video, uint8_t value); +void GBVideoDisableCGB(struct GBVideo* video); void GBVideoSetPalette(struct GBVideo* video, unsigned index, uint32_t color); void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data);
M
src/gb/io.c
→
src/gb/io.c
@@ -424,6 +424,10 @@ if (gb->memory.romBase < gb->memory.rom || gb->memory.romBase > &gb->memory.rom[gb->memory.romSize - 1]) {
free(gb->memory.romBase); gb->memory.romBase = gb->memory.rom; } + if (gb->model >= GB_MODEL_CGB && gb->memory.io[0x6C]) { + gb->model = GB_MODEL_DMG; + GBVideoDisableCGB(&gb->video); + } break; case REG_IE: gb->memory.ie = value;
M
src/gb/video.c
→
src/gb/video.c
@@ -561,6 +561,23 @@ }
video->dmgPalette[index] = M_RGB8_TO_RGB5(color); } +void GBVideoDisableCGB(struct GBVideo* video) { + video->dmgPalette[0] = video->palette[0]; + video->dmgPalette[1] = video->palette[1]; + video->dmgPalette[2] = video->palette[2]; + video->dmgPalette[3] = video->palette[3]; + video->dmgPalette[4] = video->palette[8 * 4 + 0]; + video->dmgPalette[5] = video->palette[8 * 4 + 1]; + video->dmgPalette[6] = video->palette[8 * 4 + 2]; + video->dmgPalette[7] = video->palette[8 * 4 + 3]; + video->dmgPalette[8] = video->palette[9 * 4 + 0]; + video->dmgPalette[9] = video->palette[9 * 4 + 1]; + video->dmgPalette[10] = video->palette[9 * 4 + 2]; + video->dmgPalette[11] = video->palette[9 * 4 + 3]; + video->renderer->deinit(video->renderer); + video->renderer->init(video->renderer, video->p->model, video->sgbBorders); +} + void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) { int i; if (!(video->sgbCommandHeader & 7)) {