From 70ab70ab467a64ddaefeb7ba9afdde210647ae54 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 25 May 2020 13:58:53 +0200 Subject: [PATCH] fix cart detection for 512K ROMs add new event & hotkey for selecting previous multicart ROM --- docs/index.html | 8 +++++++- src/common/PKeyboardHandler.cxx | 1 + src/emucore/CartDetector.cxx | 19 +++++++++++++++---- src/emucore/Event.hxx | 2 +- src/emucore/EventHandler.cxx | 9 +++++++-- src/emucore/EventHandler.hxx | 2 +- src/emucore/OSystem.cxx | 6 ++++-- src/emucore/OSystem.hxx | 4 +++- 8 files changed, 39 insertions(+), 12 deletions(-) diff --git a/docs/index.html b/docs/index.html index cb5855c2b..368d16530 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1749,9 +1749,15 @@ Control + 1 + + Load previous game in ROM (multicart ROM, TIA mode) + Shift-Control + r + Shift-Control + r + + Reload current ROM (singlecart ROM, TIA mode)
- Load next game in ROM (multicart ROM, TIA mode) + Load next game in ROM (multicart ROM, TIA mode) Control + r Control + r diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 5f97b90a1..4408081d7 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -459,6 +459,7 @@ PhysicalKeyboardHandler::EventMappingArray PhysicalKeyboardHandler::DefaultCommo {Event::Quit, KBDK_Q, KBDM_CTRL}, #endif {Event::ReloadConsole, KBDK_R, KBDM_CTRL}, + {Event::PreviousMultiCartRom, KBDK_R, KBDM_SHIFT | KBDM_CTRL}, {Event::VidmodeDecrease, KBDK_MINUS, MOD3}, {Event::VidmodeIncrease, KBDK_EQUALS, MOD3}, diff --git a/src/emucore/CartDetector.cxx b/src/emucore/CartDetector.cxx index 2ff85803d..6b48e3469 100644 --- a/src/emucore/CartDetector.cxx +++ b/src/emucore/CartDetector.cxx @@ -218,6 +218,14 @@ CartDetector::createFromMultiCart(const ByteBuffer& image, size_t& size, { // Get a piece of the larger image uInt32 i = settings.getInt("romloadcount"); + + // Move to the next game + if(!settings.getBool("romloadprev")) + i = (i + 1) % numroms; + else + i = (i - 1) % numroms; + settings.setValue("romloadcount", i); + size /= numroms; ByteBuffer slice = make_unique(size); std::copy_n(image.get()+i*size, size, slice.get()); @@ -228,9 +236,6 @@ CartDetector::createFromMultiCart(const ByteBuffer& image, size_t& size, buf << " [G" << (i+1) << "]"; id = buf.str(); - // Move to the next game the next time this ROM is loaded - settings.setValue("romloadcount", (i+1)%numroms); - if(size <= 2_KB) type = Bankswitch::Type::_2K; else if(size == 4_KB) type = Bankswitch::Type::_4K; else if(size == 8_KB) type = Bankswitch::Type::_F8; @@ -529,7 +534,13 @@ Bankswitch::Type CartDetector::autodetectType(const ByteBuffer& image, size_t si } else if(size == 512_KB) { - if(isProbablyTVBoy(image, size)) + if(isProbably3EX(image, size)) + type = Bankswitch::Type::_3EX; + else if(isProbably3E(image, size)) + type = Bankswitch::Type::_3E; + else if(isProbably3F(image, size)) + type = Bankswitch::Type::_3F; + else if(isProbablyTVBoy(image, size)) type = Bankswitch::Type::_TVBOY; } else // what else can we do? diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index ddac653f3..9a6c16352 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -123,7 +123,7 @@ class Event ToggleFrameStats, ToggleSAPortOrder, ExitGame, // add new events from here to avoid that user remapped events get overwritten SettingDecrease, SettingIncrease, PreviousSetting, NextSetting, - ToggleAdaptRefresh, + ToggleAdaptRefresh, PreviousMultiCartRom, LastType }; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 2f26abc99..23a9c98ee 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -544,7 +544,11 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated) return; case Event::ReloadConsole: - if(pressed && !repeated) myOSystem.reloadConsole(); + if(pressed && !repeated) myOSystem.reloadConsole(true); + return; + + case Event::PreviousMultiCartRom: + if(pressed && !repeated) myOSystem.reloadConsole(false); return; case Event::VolumeDecrease: @@ -2172,6 +2176,7 @@ void EventHandler::exitEmulation(bool checkLauncher) EventHandler::EmulActionList EventHandler::ourEmulActionList = { { { Event::Quit, "Quit", "" }, { Event::ReloadConsole, "Reload current ROM/load next game", "" }, + { Event::PreviousMultiCartRom, "Load previous multicart game", "" }, { Event::ExitMode, "Exit current Stella menu/mode", "" }, { Event::OptionsMenuMode, "Enter Options menu UI", "" }, { Event::CmdMenuMode, "Toggle Commands menu UI", "" }, @@ -2409,7 +2414,7 @@ const Event::EventSet EventHandler::MiscEvents = { // Event::MouseAxisXMove, Event::MouseAxisYMove, // Event::MouseButtonLeftValue, Event::MouseButtonRightValue, Event::HandleMouseControl, Event::ToggleGrabMouse, - Event::ToggleSAPortOrder, + Event::ToggleSAPortOrder, Event::PreviousMultiCartRom }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 7d9dd235e..5d82e31b8 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -525,7 +525,7 @@ class EventHandler #else REFRESH_SIZE = 0, #endif - EMUL_ACTIONLIST_SIZE = 156 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE, + EMUL_ACTIONLIST_SIZE = 157 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE, MENU_ACTIONLIST_SIZE = 18 ; diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 9c84b4165..0ebefebf1 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -399,7 +399,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, // Each time a new console is loaded, we simulate a cart removal // Some carts need knowledge of this, as they behave differently // based on how many power-cycles they've been through since plugged in - mySettings->setValue("romloadcount", 0); + mySettings->setValue("romloadcount", -1); // we move to the next game initially } // Create an instance of the 2600 game console @@ -474,8 +474,10 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool OSystem::reloadConsole() +bool OSystem::reloadConsole(bool nextrom) { + mySettings->setValue("romloadprev", !nextrom); + return createConsole(myRomFile, myRomMD5, false) == EmptyString; } diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index 2bc5368c6..4958efead 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -345,9 +345,11 @@ class OSystem Reloads the current console (essentially deletes and re-creates it). This can be thought of as a real console off/on toggle. + @param nextrom If true select next multicart ROM, else previous one + @return True on successful creation, otherwise false */ - bool reloadConsole(); + bool reloadConsole(bool nextrom = true); /** Creates a new ROM launcher, to select a new ROM to emulate.