From a086acde87cb4d4bab78675bf9e5da63d68b7451 Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 7 May 2018 19:52:56 -0400 Subject: [PATCH] Libretro: Added "raw" palette option --- Core/Core.vcxproj | 2 ++ Core/Core.vcxproj.filters | 6 ++++++ Core/EmulationSettings.h | 1 + Core/RawVideoFilter.cpp | 34 ++++++++++++++++++++++++++++++++++ Core/RawVideoFilter.h | 16 ++++++++++++++++ Core/VideoDecoder.cpp | 2 ++ Libretro/Makefile.common | 1 + Libretro/libretro.cpp | 5 ++++- 8 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Core/RawVideoFilter.cpp create mode 100644 Core/RawVideoFilter.h diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 28de948d..754d7b4f 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -529,6 +529,7 @@ + @@ -941,6 +942,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index f36bad07..7f061606 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1366,6 +1366,9 @@ Debugger\Scripting\DebugHud + + VideoDecoder + @@ -1629,5 +1632,8 @@ VideoDecoder + + VideoDecoder + \ No newline at end of file diff --git a/Core/EmulationSettings.h b/Core/EmulationSettings.h index 2e628a32..b214f8c1 100644 --- a/Core/EmulationSettings.h +++ b/Core/EmulationSettings.h @@ -147,6 +147,7 @@ enum class VideoFilterType Prescale6x = 22, Prescale8x = 23, Prescale10x = 24, + Raw = 25, HdPack = 999 }; diff --git a/Core/RawVideoFilter.cpp b/Core/RawVideoFilter.cpp new file mode 100644 index 00000000..3ca7b59c --- /dev/null +++ b/Core/RawVideoFilter.cpp @@ -0,0 +1,34 @@ +#include "stdafx.h" +#include "RawVideoFilter.h" +#include "PPU.h" + +RawVideoFilter::RawVideoFilter() +{ + //Use the same raw output as the Nestopia core + for(int i = 0; i < 512; i++) { + _rawPalette[i] = ( + (((i & 0x0F) * 255 / 15) << 16) | + ((((i >> 4) & 0x03) * 255 / 3) << 8) | + (((i >> 6) & 0x07) * 255 / 7) + ); + } +} + +void RawVideoFilter::ApplyFilter(uint16_t * ppuOutputBuffer) +{ + //Do nothing - return 9-bit values (6-bit Palette + 3-bit emphasis) + OverscanDimensions overscan = GetOverscan(); + uint32_t* out = (uint32_t*)GetOutputBuffer(); + for(uint32_t i = overscan.Top, iMax = 240 - overscan.Bottom; i < iMax; i++) { + for(uint32_t j = overscan.Left, jMax = 256 - overscan.Right; j < jMax; j++) { + *out = _rawPalette[ppuOutputBuffer[i * 256 + j]]; + out++; + } + } +} + +FrameInfo RawVideoFilter::GetFrameInfo() +{ + OverscanDimensions overscan = GetOverscan(); + return { overscan.GetScreenWidth(), overscan.GetScreenHeight(), PPU::ScreenWidth, PPU::ScreenHeight, 4 }; +} diff --git a/Core/RawVideoFilter.h b/Core/RawVideoFilter.h new file mode 100644 index 00000000..20f9fab5 --- /dev/null +++ b/Core/RawVideoFilter.h @@ -0,0 +1,16 @@ +#pragma once + +#include "stdafx.h" +#include "BaseVideoFilter.h" + +class RawVideoFilter : public BaseVideoFilter +{ +private: + uint32_t _rawPalette[512]; + +public: + RawVideoFilter(); + + void ApplyFilter(uint16_t *ppuOutputBuffer); + FrameInfo GetFrameInfo(); +}; \ No newline at end of file diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 615fbc9a..bb1bf92f 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -3,6 +3,7 @@ #include "VideoDecoder.h" #include "EmulationSettings.h" #include "DefaultVideoFilter.h" +#include "RawVideoFilter.h" #include "BisqwitNtscFilter.h" #include "NtscFilter.h" #include "HdVideoFilter.h" @@ -84,6 +85,7 @@ void VideoDecoder::UpdateVideoFilter() case VideoFilterType::BisqwitNtsc: _videoFilter.reset(new BisqwitNtscFilter(1)); break; case VideoFilterType::BisqwitNtscHalfRes: _videoFilter.reset(new BisqwitNtscFilter(2)); break; case VideoFilterType::BisqwitNtscQuarterRes: _videoFilter.reset(new BisqwitNtscFilter(4)); break; + case VideoFilterType::Raw: _videoFilter.reset(new RawVideoFilter()); break; default: _scaleFilter = ScaleFilter::GetScaleFilter(_videoFilterType); break; } diff --git a/Libretro/Makefile.common b/Libretro/Makefile.common index cab772c6..1a3b0514 100644 --- a/Libretro/Makefile.common +++ b/Libretro/Makefile.common @@ -44,6 +44,7 @@ SOURCES_CXX := $(LIBRETRO_DIR)/libretro.cpp \ $(CORE_DIR)/Debugger.cpp \ $(CORE_DIR)/DebugHud.cpp \ $(CORE_DIR)/DefaultVideoFilter.cpp \ + $(CORE_DIR)/RawVideoFilter.cpp \ $(CORE_DIR)/DeltaModulationChannel.cpp \ $(CORE_DIR)/Disassembler.cpp \ $(CORE_DIR)/DisassemblyInfo.cpp \ diff --git a/Libretro/libretro.cpp b/Libretro/libretro.cpp index cdff56d5..748101f2 100644 --- a/Libretro/libretro.cpp +++ b/Libretro/libretro.cpp @@ -140,7 +140,7 @@ extern "C" { static const struct retro_variable vars[] = { { MesenNtscFilter, "NTSC filter; Disabled|Composite (Blargg)|S-Video (Blargg)|RGB (Blargg)|Monochrome (Blargg)|Bisqwit 2x|Bisqwit 4x|Bisqwit 8x" }, - { MesenPalette, "Palette; Default|Composite Direct (by FirebrandX)|Nes Classic|Nestopia (RGB)|Original Hardware (by FirebrandX)|PVM Style (by FirebrandX)|Sony CXA2025AS|Unsaturated v6 (by FirebrandX)|YUV v3 (by FirebrandX)|Custom" }, + { MesenPalette, "Palette; Default|Composite Direct (by FirebrandX)|Nes Classic|Nestopia (RGB)|Original Hardware (by FirebrandX)|PVM Style (by FirebrandX)|Sony CXA2025AS|Unsaturated v6 (by FirebrandX)|YUV v3 (by FirebrandX)|Custom|Raw" }, { MesenOverclock, "Overclock; None|Low|Medium|High|Very High" }, { MesenOverclockType, "Overclock Type; Before NMI (Recommended)|After NMI" }, { MesenRegion, "Region; Auto|NTSC|PAL|Dendy" }, @@ -374,6 +374,9 @@ extern "C" { EmulationSettings::SetRgbPalette(yuvPalette); } else if(value == "Custom") { load_custom_palette(); + } else if(value == "Raw") { + //Using the raw palette replaces the NTSC filters, if one is selected + EmulationSettings::SetVideoFilterType(VideoFilterType::Raw); } }