Skip to content

Commit

Permalink
GB Video: Increment BCPS/OCPS even in mode 3 (fixes #1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Jun 24, 2019
1 parent fb72b70 commit 06d407f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -27,6 +27,7 @@ Emulation fixes:
- GBA Memory: Fix STM to VRAM (fixes mgba.io/i/1430)
- GB Audio: Only reset channel 3 sample in DMG mode
- GB Audio: Sample inactive channels (fixes mgba.io/i/1455, mgba.io/i/1456)
- GB Video: Increment BCPS/OCPS even in mode 3 (fixes mgba.io/i/1462)
Other fixes:
- Qt: Fix some Qt display driver race conditions
- Core: Improved lockstep driver reliability (Le Hoang Quyen)
Expand Down
4 changes: 2 additions & 2 deletions src/gb/io.c
Expand Up @@ -499,8 +499,8 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
case REG_BCPD:
if (gb->video.mode != 3) {
GBVideoProcessDots(&gb->video, 0);
GBVideoWritePalette(&gb->video, address, value);
}
GBVideoWritePalette(&gb->video, address, value);
return;
case REG_OCPS:
gb->video.ocpIndex = value & 0x3F;
Expand All @@ -510,8 +510,8 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
case REG_OCPD:
if (gb->video.mode != 3) {
GBVideoProcessDots(&gb->video, 0);
GBVideoWritePalette(&gb->video, address, value);
}
GBVideoWritePalette(&gb->video, address, value);
return;
case REG_SVBK:
GBMemorySwitchWramBank(&gb->memory, value);
Expand Down
32 changes: 18 additions & 14 deletions src/gb/video.c
Expand Up @@ -505,14 +505,16 @@ void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value)
} else {
switch (address) {
case REG_BCPD:
if (video->bcpIndex & 1) {
video->palette[video->bcpIndex >> 1] &= 0x00FF;
video->palette[video->bcpIndex >> 1] |= value << 8;
} else {
video->palette[video->bcpIndex >> 1] &= 0xFF00;
video->palette[video->bcpIndex >> 1] |= value;
if (video->mode != 3) {
if (video->bcpIndex & 1) {
video->palette[video->bcpIndex >> 1] &= 0x00FF;
video->palette[video->bcpIndex >> 1] |= value << 8;
} else {
video->palette[video->bcpIndex >> 1] &= 0xFF00;
video->palette[video->bcpIndex >> 1] |= value;
}
video->renderer->writePalette(video->renderer, video->bcpIndex >> 1, video->palette[video->bcpIndex >> 1]);
}
video->renderer->writePalette(video->renderer, video->bcpIndex >> 1, video->palette[video->bcpIndex >> 1]);
if (video->bcpIncrement) {
++video->bcpIndex;
video->bcpIndex &= 0x3F;
Expand All @@ -522,14 +524,16 @@ void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value)
video->p->memory.io[REG_BCPD] = video->palette[video->bcpIndex >> 1] >> (8 * (video->bcpIndex & 1));
break;
case REG_OCPD:
if (video->ocpIndex & 1) {
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0x00FF;
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value << 8;
} else {
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0xFF00;
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value;
if (video->mode != 3) {
if (video->ocpIndex & 1) {
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0x00FF;
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value << 8;
} else {
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0xFF00;
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value;
}
video->renderer->writePalette(video->renderer, 8 * 4 + (video->ocpIndex >> 1), video->palette[8 * 4 + (video->ocpIndex >> 1)]);
}
video->renderer->writePalette(video->renderer, 8 * 4 + (video->ocpIndex >> 1), video->palette[8 * 4 + (video->ocpIndex >> 1)]);
if (video->ocpIncrement) {
++video->ocpIndex;
video->ocpIndex &= 0x3F;
Expand Down

0 comments on commit 06d407f

Please sign in to comment.