From a7dbbbe578606a5d35d043d81512ef21827dff35 Mon Sep 17 00:00:00 2001 From: Colton Pawielski Date: Fri, 22 Sep 2023 02:10:44 -0700 Subject: [PATCH] Add Dreamcast 32MB RAM Mod (#1198) --- core/cfg/option.cpp | 1 + core/cfg/option.h | 1 + core/emulator.cpp | 2 +- core/rend/gui.cpp | 5 +++++ core/serialize.h | 14 +++++++++++++- shell/libretro/libretro_core_options.h | 14 ++++++++++++++ shell/libretro/option.cpp | 1 + tests/src/serialize_test.cpp | 2 +- 8 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/cfg/option.cpp b/core/cfg/option.cpp index 5d3e40028e..095f97f487 100644 --- a/core/cfg/option.cpp +++ b/core/cfg/option.cpp @@ -121,6 +121,7 @@ Option GDBPort("Debug.GDBPort", debugger::DEFAULT_PORT); Option GDBWaitForConnection("Debug.GDBWaitForConnection"); Option UseReios("UseReios"); Option FastGDRomLoad("FastGDRomLoad", false); +Option RamMod32MB("Dreamcast.RamMod32MB", false); Option OpenGlChecks("OpenGlChecks", false, "validate"); diff --git a/core/cfg/option.h b/core/cfg/option.h index a4d784894b..5a14874864 100644 --- a/core/cfg/option.h +++ b/core/cfg/option.h @@ -480,6 +480,7 @@ extern Option GDBPort; extern Option GDBWaitForConnection; extern Option UseReios; extern Option FastGDRomLoad; +extern Option RamMod32MB; extern Option OpenGlChecks; diff --git a/core/emulator.cpp b/core/emulator.cpp index 0aefb9d84c..cbbc0f65a1 100644 --- a/core/emulator.cpp +++ b/core/emulator.cpp @@ -420,7 +420,7 @@ static void setPlatform(int platform) switch (platform) { case DC_PLATFORM_DREAMCAST: - settings.platform.ram_size = 16_MB; + settings.platform.ram_size = config::RamMod32MB ? 32_MB : 16_MB; settings.platform.vram_size = 8_MB; settings.platform.aram_size = 2_MB; settings.platform.bios_size = 2_MB; diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index f12aeb6ee5..4be8d0bcf2 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -2423,6 +2423,11 @@ static void gui_display_settings() OptionCheckbox("Serial Console", config::SerialConsole, "Dump the Dreamcast serial console to stdout"); #endif + { + DisabledScope scope(game_started); + OptionCheckbox("Dreamcast 32MB RAM Mod", config::RamMod32MB, + "Enables 32MB RAM Mod for Dreamcast. May affect compatibility"); + } OptionCheckbox("Dump Textures", config::DumpTextures, "Dump all textures into data/texdump/"); diff --git a/core/serialize.h b/core/serialize.h index 795a9693f2..f364630bef 100644 --- a/core/serialize.h +++ b/core/serialize.h @@ -67,7 +67,8 @@ class SerializeBase V39, V40, V41, - Current = V41, + V42, + Current = V42, Next = Current + 1, }; @@ -101,6 +102,15 @@ class Deserializer : public SerializeBase throw Exception("Unsupported version"); if (_version > Current) throw Exception("Version too recent"); + + if(_version >= V42 && settings.platform.isConsole()) + { + u32 ramSize; + deserialize(ramSize); + if (ramSize != settings.platform.ram_size) { + throw Exception("Selected RAM Size doesn't match Save State"); + } + } } template @@ -162,6 +172,8 @@ class Serializer : public SerializeBase { Version v = Current; serialize(v); + if (settings.platform.isConsole()) + serialize(settings.platform.ram_size); } template diff --git a/shell/libretro/libretro_core_options.h b/shell/libretro/libretro_core_options.h index c5664cd02e..2e1a927d17 100644 --- a/shell/libretro/libretro_core_options.h +++ b/shell/libretro/libretro_core_options.h @@ -689,6 +689,20 @@ struct retro_core_option_v2_definition option_defs_us[] = { "disabled", #endif }, + { + CORE_OPTION_NAME "_dc_32mb_mod", + "Dreamcast 32MB RAM Mod", + NULL, + "Enables 32MB RAM Mod for Dreamcast. May affect compatibility", + NULL, + "hacks", + { + { "disabled", NULL }, + { "enabled", NULL }, + { NULL, NULL }, + }, + "disabled", + }, { CORE_OPTION_NAME "_sh4clock", "SH4 CPU under/overclock", diff --git a/shell/libretro/option.cpp b/shell/libretro/option.cpp index 066e635733..f593db076a 100644 --- a/shell/libretro/option.cpp +++ b/shell/libretro/option.cpp @@ -101,6 +101,7 @@ Option UseReios(CORE_OPTION_NAME "_hle_bios"); Option OpenGlChecks("", false); Option FastGDRomLoad(CORE_OPTION_NAME "_gdrom_fast_loading", false); +Option RamMod32MB(CORE_OPTION_NAME "_dc_32mb_mod", false); //Option, false> ContentPath(""); //Option HideLegacyNaomiRoms("", true); diff --git a/tests/src/serialize_test.cpp b/tests/src/serialize_test.cpp index 47e5a7a0b1..16ad3d8837 100644 --- a/tests/src/serialize_test.cpp +++ b/tests/src/serialize_test.cpp @@ -32,7 +32,7 @@ TEST_F(SerializeTest, SizeTest) std::vector data(30000000); Serializer ser(data.data(), data.size()); dc_serialize(ser); - ASSERT_EQ(28191378u, ser.size()); + ASSERT_EQ(28191382u, ser.size()); }