From 208e7e30758ba6a75f7609b0751af1b60ac13390 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Fri, 1 Oct 2021 17:00:10 +0200 Subject: [PATCH] added PlusROM detection display simplified PlusROM id generation logic shortened QuadTari.name() --- src/emucore/CartDetector.cxx | 9 ++++++++ src/emucore/CartDetector.hxx | 5 +++++ src/emucore/OSystem.cxx | 1 + src/emucore/QuadTari.cxx | 2 +- src/gui/PlusRomsSetupDialog.cxx | 38 ++++++++++++++------------------- src/gui/RomInfoWidget.cxx | 4 ++++ 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/emucore/CartDetector.cxx b/src/emucore/CartDetector.cxx index 33d8fbc06..824054ea0 100644 --- a/src/emucore/CartDetector.cxx +++ b/src/emucore/CartDetector.cxx @@ -807,3 +807,12 @@ bool CartDetector::isProbablyX07(const ByteBuffer& image, size_t size) return false; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CartDetector::isProbablyPlusROM(const ByteBuffer& image, size_t size) +{ + // PlusCart uses this pattern to detect a PlusROM + uInt8 signature[3] = {0x8d, 0xf0, 0x1f}; // STA $1FF0 + + return searchForBytes(image, size, signature, 3); +} diff --git a/src/emucore/CartDetector.hxx b/src/emucore/CartDetector.hxx index dc9025c76..7c90d6a71 100644 --- a/src/emucore/CartDetector.hxx +++ b/src/emucore/CartDetector.hxx @@ -47,6 +47,11 @@ class CartDetector */ static size_t isProbablyMVC(const FilesystemNode& rom); + /** + Returns true if the image is probably a HSC PlusROM + */ + static bool isProbablyPlusROM(const ByteBuffer& image, size_t size); + private: /** Search the image for the specified byte signature diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 29394acd1..5db654622 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -505,6 +505,7 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, msg << myConsole->leftController().name() << "/" << myConsole->rightController().name() << " - " << myConsole->cartridge().detectedType() + << (myConsole->cartridge().isPlusROM() ? " PlusROM " : "") << " - " << myConsole->getFormatString(); myFrameBuffer->showTextMessage(msg.str()); } diff --git a/src/emucore/QuadTari.cxx b/src/emucore/QuadTari.cxx index 44f31cb2e..b241b2100 100644 --- a/src/emucore/QuadTari.cxx +++ b/src/emucore/QuadTari.cxx @@ -152,7 +152,7 @@ void QuadTari::update() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string QuadTari::name() const { - return "QuadTari (" + myFirstController->name() + "/" + mySecondController->name() + ")"; + return "QT(" + myFirstController->name() + "/" + mySecondController->name() + ")"; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/PlusRomsSetupDialog.cxx b/src/gui/PlusRomsSetupDialog.cxx index 68bf1c555..d99f02eda 100644 --- a/src/gui/PlusRomsSetupDialog.cxx +++ b/src/gui/PlusRomsSetupDialog.cxx @@ -39,33 +39,43 @@ PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& pare // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PlusRomsSetupDialog::loadConfig() { - setText(instance().settings().getString("plusroms.nick"), 0); + setText(instance().settings().getString("plusroms.nick")); + + // Make sure there always is an id + if(instance().settings().getString("plusroms.id") == EmptyString) + { + const char* HEX_DIGITS = "0123456789ABCDEF"; + char id_chr[ID_LEN]; + + srand(time(NULL)); + for(int i = 0; i < ID_LEN; i++) + id_chr[i] = HEX_DIGITS[(rand() % 16)]; + + std::string id_str(id_chr, ID_LEN); + instance().settings().setValue("plusroms.id", id_str); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PlusRomsSetupDialog::saveConfig() { - instance().settings().setValue("plusroms.nick", getResult(0)); + instance().settings().setValue("plusroms.nick", getResult()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) { - bool exit = false; - switch(cmd) { case GuiObject::kOKCmd: case EditableWidget::kAcceptCmd: saveConfig(); instance().eventHandler().leaveMenuMode(); - exit = true; break; case kCloseCmd: instance().eventHandler().leaveMenuMode(); - exit = true; break; case EditableWidget::kCancelCmd: @@ -75,20 +85,4 @@ void PlusRomsSetupDialog::handleCommand(CommandSender* sender, int cmd, InputTextDialog::handleCommand(sender, cmd, data, id); break; } - // Make sure there always is an id - if(exit) - { - if(instance().settings().getString("plusroms.id") == EmptyString) - { - const char* HEX_DIGITS = "0123456789ABCDEF"; - char id_chr[ID_LEN]; - - srand(time(NULL)); - for(int i = 0; i < ID_LEN; i++) - id_chr[i] = HEX_DIGITS[(rand() % 16)]; - - std::string id_str(id_chr, ID_LEN); - instance().settings().setValue("plusroms.id", id_str); - } - } } diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 352d0977b..0d19a0c3d 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -150,6 +150,7 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) Controller::Type leftType = Controller::getType(left); Controller::Type rightType = Controller::getType(right); string bsDetected = myProperties.get(PropType::Cart_Type); + bool isPlusCart = false; size_t size = 0; try { @@ -168,6 +169,8 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) instance().settings()); if (bsDetected == "AUTO") bsDetected = Bankswitch::typeToName(CartDetector::autodetectType(image, size)); + + isPlusCart = CartDetector::isProbablyPlusROM(image, size); } } catch(const runtime_error&) @@ -193,6 +196,7 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) buf << (std::round(size / float(1_KB))) << "K"; } myRomInfo.push_back("Type: " + Bankswitch::typeToDesc(Bankswitch::nameToType(bsDetected)) + + (isPlusCart ? " - PlusROM" : "") + buf.str()); } setDirty();