From 8a107d7ecd12822c046ccbdc0309bb27e1cb41d4 Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 8 Jan 2018 20:36:05 -0500 Subject: [PATCH] Libretro: Allow custom palettes via MesenPalette.pal file --- Core/MessageManager.cpp | 2 +- Libretro/libretro.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index 4c56be5d..e5ba9a01 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -188,7 +188,7 @@ std::unordered_map MessageManager::_jaResources = { { "CouldNotLoadFile", u8"ファイルをロードできませんでした: %1" }, { "EmulationMaximumSpeed", u8"最高速度" }, { "EmulationSpeedPercent", u8"%1%" }, - { "FdsDiskInserted", u8"ディスク%1、%2面。" }, + { "FdsDiskInserted", u8"ディスク%1%2。" }, { "Frame", u8"フレーム" }, { "GameCrash", u8"ゲームは停止しました (%1)" }, { "KeyboardModeDisabled", u8"キーボードモードを無効にしました。" }, diff --git a/Libretro/libretro.cpp b/Libretro/libretro.cpp index cf8f75d0..5020ad6d 100644 --- a/Libretro/libretro.cpp +++ b/Libretro/libretro.cpp @@ -119,7 +119,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" }, { MesenNtscVerticalBlend, "NTSC filter: Vertical blending; disabled|enabled" }, - { 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)" }, + { 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" }, { MesenOverclock, "Overclock; None|Low|Medium|High|Very High" }, { MesenOverclockType, "Overclock Type; Before NMI (Recommended)|After NMI" }, { MesenRegion, "Region; Auto|NTSC|PAL|Dendy" }, @@ -191,6 +191,30 @@ extern "C" { } } + void load_custom_palette() + { + //Setup default palette in case we can't load the custom one + EmulationSettings::SetRgbPalette(defaultPalette); + + //Try to load the custom palette from the MesenPalette.pal file + string palettePath = FolderUtilities::CombinePath(FolderUtilities::GetHomeFolder(), "MesenPalette.pal"); + uint8_t fileData[64 * 3] = {}; + ifstream palette(palettePath, ios::binary || ios::in); + if(palette) { + palette.seekg(0, ios::end); + std::streampos fileSize = palette.tellg(); + palette.seekg(0, ios::beg); + if(fileSize >= 64 * 3) { + palette.read((char*)fileData, 64 * 3); + uint32_t customPalette[64]; + for(int i = 0; i < 64; i++) { + customPalette[i] = 0xFF000000 | fileData[i * 3 + 2] | (fileData[i * 3 + 1] << 8) | (fileData[i * 3] << 16); + } + EmulationSettings::SetRgbPalette(customPalette); + } + } + } + void update_settings() { struct retro_variable var = { }; @@ -278,6 +302,8 @@ extern "C" { EmulationSettings::SetRgbPalette(unsaturatedPalette); } else if(value == "YUV v3 (by FirebrandX)") { EmulationSettings::SetRgbPalette(yuvPalette); + } else if(value == "Custom") { + load_custom_palette(); } }