From 7b906e824f9177d7bcecfb54cff59d67346ac9b2 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Fri, 5 Aug 2022 18:57:11 +0200 Subject: [PATCH] added bankswitching type to displayed multi cart information --- src/emucore/CartCreator.cxx | 113 +++++++++++++++--------------------- src/emucore/CartCreator.hxx | 2 +- src/gui/GameInfoDialog.cxx | 2 +- 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/emucore/CartCreator.cxx b/src/emucore/CartCreator.cxx index 7ee630c56..8afdc6149 100644 --- a/src/emucore/CartCreator.cxx +++ b/src/emucore/CartCreator.cxx @@ -105,97 +105,50 @@ unique_ptr CartCreator::create(const FSNode& file, buf << Bankswitch::typeToName(type); // Check for multicart first; if found, get the correct part of the image + bool validMultiSize = true; + int numRoms = 0; switch(type) { case Bankswitch::Type::_2IN1: + numRoms = 2; // Make sure we have a valid sized image - if(size == 2*2_KB || size == 2*4_KB || size == 2*8_KB || size == 2*16_KB || size == 2*32_KB) - { - cartridge = - createFromMultiCart(image, size, 2, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 2 * 2_KB || size == 2 * 4_KB || size == 2 * 8_KB || size == 2 * 16_KB || size == 2 * 32_KB); break; case Bankswitch::Type::_4IN1: + numRoms = 4; // Make sure we have a valid sized image - if(size == 4*2_KB || size == 4*4_KB || size == 4*8_KB || size == 4*16_KB) - { - cartridge = - createFromMultiCart(image, size, 4, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 4 * 2_KB || size == 4 * 4_KB || size == 4 * 8_KB || size == 4 * 16_KB); break; case Bankswitch::Type::_8IN1: + numRoms = 8; // Make sure we have a valid sized image - if(size == 8*2_KB || size == 8*4_KB || size == 8*8_KB) - { - cartridge = - createFromMultiCart(image, size, 8, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 8 * 2_KB || size == 8 * 4_KB || size == 8 * 8_KB); break; case Bankswitch::Type::_16IN1: + numRoms = 16; // Make sure we have a valid sized image - if(size == 16*2_KB || size == 16*4_KB || size == 16*8_KB) - { - cartridge = - createFromMultiCart(image, size, 16, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 16 * 2_KB || size == 16 * 4_KB || size == 16 * 8_KB); break; case Bankswitch::Type::_32IN1: + numRoms = 32; // Make sure we have a valid sized image - if(size == 32*2_KB || size == 32*4_KB) - { - cartridge = - createFromMultiCart(image, size, 32, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 32 * 2_KB || size == 32 * 4_KB); break; case Bankswitch::Type::_64IN1: + numRoms = 64; // Make sure we have a valid sized image - if(size == 64*2_KB || size == 64*4_KB) - { - cartridge = - createFromMultiCart(image, size, 64, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 64 * 2_KB || size == 64 * 4_KB); break; case Bankswitch::Type::_128IN1: + numRoms = 128; // Make sure we have a valid sized image - if(size == 128*2_KB || size == 128*4_KB) - { - cartridge = - createFromMultiCart(image, size, 128, md5, detectedType, id, settings); - buf << id; - } - else - throw runtime_error("Invalid cart size for type '" + - Bankswitch::typeToName(type) + "'"); + validMultiSize = (size == 128 * 2_KB || size == 128 * 4_KB); break; case Bankswitch::Type::_MVC: @@ -207,10 +160,37 @@ unique_ptr CartCreator::create(const FSNode& file, break; } + bool isMulti = false; + switch(type) + { + case Bankswitch::Type::_2IN1: + case Bankswitch::Type::_4IN1: + case Bankswitch::Type::_8IN1: + case Bankswitch::Type::_16IN1: + case Bankswitch::Type::_32IN1: + case Bankswitch::Type::_64IN1: + case Bankswitch::Type::_128IN1: + isMulti = true; + if(validMultiSize) + cartridge = createFromMultiCart(image, size, numRoms, md5, detectedType, id, settings); + else + throw runtime_error("Invalid cart size for type '" + Bankswitch::typeToName(type) + "'"); + + //type = detectedType; + buf << id; + break; + + default: + break; + } + if(size < 1_KB) - buf << " (" << size << "B) "; + buf << " (" << size << "B"; else - buf << " (" << (size/1_KB) << "K) "; + buf << " (" << (size/1_KB) << "K"; + if(isMulti && detectedType != Bankswitch::Type::_2K && detectedType != Bankswitch::Type::_4K) + buf << " " << Bankswitch::typeToName(detectedType); + buf << ") "; cartridge->setAbout(buf.str(), Bankswitch::typeToName(type), id); @@ -220,7 +200,7 @@ unique_ptr CartCreator::create(const FSNode& file, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - unique_ptr CartCreator::createFromMultiCart(const ByteBuffer& image, size_t& size, - uInt32 numroms, string& md5, Bankswitch::Type type, string& id, Settings& settings) + uInt32 numroms, string& md5, Bankswitch::Type& type, string& id, Settings& settings) { // Get a piece of the larger image uInt32 i = settings.getInt("romloadcount"); @@ -242,6 +222,7 @@ CartCreator::createFromMultiCart(const ByteBuffer& image, size_t& size, buf << " [G" << (i+1) << "]"; id = buf.str(); + // TODO: allow using ROM properties instead of autodetect only if(size <= 2_KB) type = Bankswitch::Type::_2K; else if(size == 4_KB) diff --git a/src/emucore/CartCreator.hxx b/src/emucore/CartCreator.hxx index 10a2f457d..f7ce4a956 100644 --- a/src/emucore/CartCreator.hxx +++ b/src/emucore/CartCreator.hxx @@ -66,7 +66,7 @@ class CartCreator */ static unique_ptr createFromMultiCart(const ByteBuffer& image, size_t& size, - uInt32 numroms, string& md5, Bankswitch::Type type, string& id, + uInt32 numroms, string& md5, Bankswitch::Type& type, string& id, Settings& settings); /** diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index 566771c4c..b050f2ff1 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -1147,7 +1147,7 @@ void GameInfoDialog::updateMultiCart() // en/disable Emulation tab widgets myBSTypeLabel->setEnabled(!isInMulti); - myBSType->setEnabled(!isInMulti); + myBSType->setEnabled(!isInMulti); // TODO: currently only auto-detected, add using properties myBSFilter->setEnabled(!isInMulti); myStartBank->setEnabled(!isMulti && instance().hasConsole()); myFormat->setEnabled(!isMulti);