From bc0da95808ccc8b107e1ba448a65bff611ed6138 Mon Sep 17 00:00:00 2001 From: Persune Date: Mon, 11 Dec 2023 15:51:42 +0800 Subject: [PATCH] Fix RGB PPU default palette emphasis behavior --- Core/NES/NesDefaultVideoFilter.cpp | 50 +++++++++++++++++++----------- Core/NES/NesDefaultVideoFilter.h | 2 +- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/Core/NES/NesDefaultVideoFilter.cpp b/Core/NES/NesDefaultVideoFilter.cpp index 229997986..3924a66ba 100644 --- a/Core/NES/NesDefaultVideoFilter.cpp +++ b/Core/NES/NesDefaultVideoFilter.cpp @@ -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); @@ -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); } } } diff --git a/Core/NES/NesDefaultVideoFilter.h b/Core/NES/NesDefaultVideoFilter.h index f5b083e81..36b6074e3 100644 --- a/Core/NES/NesDefaultVideoFilter.h +++ b/Core/NES/NesDefaultVideoFilter.h @@ -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);