Skip to content

Commit

Permalink
Fix RGB PPU default palette emphasis behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Jan 18, 2024
1 parent bce550f commit bc0da95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
50 changes: 32 additions & 18 deletions Core/NES/NesDefaultVideoFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,45 @@ NesDefaultVideoFilter::NesDefaultVideoFilter(Emulator* emu) : BaseVideoFilter(em
InitLookupTable();
}

void NesDefaultVideoFilter::GenerateFullColorPalette(uint32_t paletteBuffer[512])
void NesDefaultVideoFilter::GenerateFullColorPalette(uint32_t paletteBuffer[512], PpuModel model)
{
for(int i = 0; i < 64; i++) {
for(int j = 1; j < 8; j++) {
double redColor = (uint8_t)(paletteBuffer[i] >> 16);
double greenColor = (uint8_t)(paletteBuffer[i] >> 8);
double blueColor = (uint8_t)paletteBuffer[i];
if((i & 0x0F) <= 0x0D) {
//Emphasis doesn't affect columns $xE and $xF
if(j & 0x01) {
//Intensify red
greenColor *= 0.84;
blueColor *= 0.84;
}
if(j & 0x02) {
//Intensify green
redColor *= 0.84;
blueColor *= 0.84;
}
if(j & 0x04) {
//Intensify blue
redColor *= 0.84;
greenColor *= 0.84;
if(model == PpuModel::Ppu2C02) {
if((i & 0x0F) <= 0x0D) {
//Emphasis doesn't affect columns $xE and $xF
if(j & 0x01) {
//Intensify red
greenColor *= 0.84;
blueColor *= 0.84;
}
if(j & 0x02) {
//Intensify green
redColor *= 0.84;
blueColor *= 0.84;
}
if(j & 0x04) {
//Intensify blue
redColor *= 0.84;
greenColor *= 0.84;
}
}
}
else {
// RGB PPUs do emphasis in a different way
//Intensify red
if(j & 0x01)
redColor = 0xFF;
//Intensify green
if(j & 0x02)
greenColor = 0xFF;
//Intensify blue
if(j & 0x04)
blueColor = 0xFF;
}

uint8_t r = (uint8_t)(redColor > 255 ? 255 : redColor);
uint8_t g = (uint8_t)(greenColor > 255 ? 255 : greenColor);
Expand Down Expand Up @@ -98,7 +112,7 @@ void NesDefaultVideoFilter::GetFullPalette(uint32_t palette[512], NesConfig& nes
}
} else {
memcpy(palette, _ppuPaletteArgb[(int)model], sizeof(_ppuPaletteArgb[(int)_ppuModel]));
GenerateFullColorPalette(palette);
GenerateFullColorPalette(palette, model);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/NES/NesDefaultVideoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NesDefaultVideoFilter : public BaseVideoFilter

static void ApplyPalBorder(uint16_t* ppuOutputBuffer);

static void GenerateFullColorPalette(uint32_t paletteBuffer[512]);
static void GenerateFullColorPalette(uint32_t paletteBuffer[512], PpuModel model = PpuModel::Ppu2C02);
static void GetFullPalette(uint32_t palette[512], NesConfig& nesCfg, PpuModel model);

static uint32_t GetDefaultPixelBrightness(uint16_t colorIndex, PpuModel model);
Expand Down

0 comments on commit bc0da95

Please sign in to comment.