From 8a74c4776e129a94de1e9a0f502dff792bb94014 Mon Sep 17 00:00:00 2001 From: stephena Date: Fri, 23 Dec 2005 20:48:50 +0000 Subject: [PATCH] Fixed segfault/false assert when the cartridge type is undefined. Stella will now either exit gracefully (when launching a ROM from the commandline), or continue running (when in ROM launcher mode) when attempting to use an undefined cartridge type. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@923 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/common/mainSDL.cxx | 11 +++++++---- stella/src/emucore/Cart.cxx | 10 ++++------ stella/src/emucore/CartAR.cxx | 21 +++++++++++++-------- stella/src/emucore/Console.cxx | 10 ++++++++-- stella/src/emucore/Console.hxx | 13 +++++++++++-- stella/src/emucore/OSystem.cxx | 34 ++++++++++++++++++++-------------- 6 files changed, 63 insertions(+), 36 deletions(-) diff --git a/stella/src/common/mainSDL.cxx b/stella/src/common/mainSDL.cxx index e86c57ecb..560dd6cf9 100644 --- a/stella/src/common/mainSDL.cxx +++ b/stella/src/common/mainSDL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: mainSDL.cxx,v 1.58 2005-12-18 18:37:02 stephena Exp $ +// $Id: mainSDL.cxx,v 1.59 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #include @@ -206,10 +206,8 @@ int main(int argc, char* argv[]) string romfile = argv[argc - 1]; if(argc == 1 || !FilesystemNode::fileExists(romfile)) theOSystem->createLauncher(); - else + else if(theOSystem->createConsole(romfile)) { - theOSystem->createConsole(romfile); - if(theOSystem->settings().getBool("holdreset")) theOSystem->eventHandler().handleEvent(Event::ConsoleReset, 1); @@ -236,6 +234,11 @@ int main(int argc, char* argv[]) handler.enterDebugMode(); #endif } + else + { + Cleanup(); + return 0; + } // Swallow any spurious events in the queue // These are normally caused by joystick/mouse jitter diff --git a/stella/src/emucore/Cart.cxx b/stella/src/emucore/Cart.cxx index c005a7e2c..b74092bf0 100644 --- a/stella/src/emucore/Cart.cxx +++ b/stella/src/emucore/Cart.cxx @@ -13,11 +13,12 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Cart.cxx,v 1.17 2005-10-13 02:05:36 stephena Exp $ +// $Id: Cart.cxx,v 1.18 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #include -#include + +#include "bspf.hxx" #include "Cart.hxx" #include "Cart2K.hxx" #include "Cart3E.hxx" @@ -97,10 +98,7 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size, else if(type == "UA") cartridge = new CartridgeUA(image); else - { - // TODO: At some point this should be handled in a better way... - assert(false); - } + cerr << "ERROR: Invalid cartridge type " << type << " ..." << endl; return cartridge; } diff --git a/stella/src/emucore/CartAR.cxx b/stella/src/emucore/CartAR.cxx index 0cc148fa7..5733ece62 100644 --- a/stella/src/emucore/CartAR.cxx +++ b/stella/src/emucore/CartAR.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: CartAR.cxx,v 1.13 2005-12-17 01:23:07 stephena Exp $ +// $Id: CartAR.cxx,v 1.14 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #include @@ -200,8 +200,8 @@ void CartridgeAR::poke(uInt16 addr, uInt8) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeAR::patch(uInt16 address, uInt8 value) { - // myImage[address & 0x0FFF] = value; - return false; + // myImage[address & 0x0FFF] = value; + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -298,19 +298,23 @@ void CartridgeAR::bankConfiguration(uInt8 configuration) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CartridgeAR::bank(uInt16 b) { - if(bankLocked) return; +void CartridgeAR::bank(uInt16 b) +{ + if(bankLocked) + return; bankConfiguration(b); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int CartridgeAR::bank() { +int CartridgeAR::bank() +{ return myCurrentBank; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int CartridgeAR::bankCount() { +int CartridgeAR::bankCount() +{ return 32; } @@ -584,7 +588,8 @@ bool CartridgeAR::load(Deserializer& in) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8* CartridgeAR::getImage(int& size) { +uInt8* CartridgeAR::getImage(int& size) +{ size = myNumberOfLoadImages * 8448; return &myLoadImages[0]; } diff --git a/stella/src/emucore/Console.cxx b/stella/src/emucore/Console.cxx index 381057640..f1f6fda09 100644 --- a/stella/src/emucore/Console.cxx +++ b/stella/src/emucore/Console.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Console.cxx,v 1.77 2005-11-27 22:37:24 stephena Exp $ +// $Id: Console.cxx,v 1.78 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #include @@ -62,7 +62,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Console::Console(const uInt8* image, uInt32 size, const string& md5, OSystem* osystem) - : myOSystem(osystem) + : myOSystem(osystem), + myIsInitializedFlag(false) { myControllers[0] = 0; myControllers[1] = 0; @@ -151,6 +152,8 @@ Console::Console(const uInt8* image, uInt32 size, const string& md5, TIA *tia = new TIA(*this, myOSystem->settings()); tia->setSound(myOSystem->sound()); Cartridge* cartridge = Cartridge::create(image, size, myProperties); + if(!cartridge) + return; mySystem->attach(m6502); mySystem->attach(m6532); @@ -215,6 +218,9 @@ Console::Console(const uInt8* image, uInt32 size, const string& md5, myOSystem->debugger().setConsole(this); myOSystem->debugger().initialize(); #endif + + // If we get this far, the console must be valid + myIsInitializedFlag = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/Console.hxx b/stella/src/emucore/Console.hxx index 6b2a5c3b3..0c1aa8146 100644 --- a/stella/src/emucore/Console.hxx +++ b/stella/src/emucore/Console.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Console.hxx,v 1.40 2005-10-19 00:59:51 stephena Exp $ +// $Id: Console.hxx,v 1.41 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #ifndef CONSOLE_HXX @@ -37,7 +37,7 @@ class System; This class represents the entire game console. @author Bradford W. Mott - @version $Id: Console.hxx,v 1.40 2005-10-19 00:59:51 stephena Exp $ + @version $Id: Console.hxx,v 1.41 2005-12-23 20:48:50 stephena Exp $ */ class Console { @@ -119,6 +119,11 @@ class Console */ M6532& riot() const { return *myRiot; } + /** + Determine whether the console was successfully created + */ + bool isInitialized() { return myIsInitializedFlag; } + public: /** Overloaded assignment operator @@ -257,6 +262,10 @@ class Console // Pointer to the 6532 (aka RIOT) (the debugger needs it) // A RIOT of my own! (...with apologies to The Clash...) M6532 *myRiot; + + // Indicates whether the console was correctly initialized + // We don't really care why it wasn't initialized ... + bool myIsInitializedFlag; }; #endif diff --git a/stella/src/emucore/OSystem.cxx b/stella/src/emucore/OSystem.cxx index c80a49ff2..c2c7e5258 100644 --- a/stella/src/emucore/OSystem.cxx +++ b/stella/src/emucore/OSystem.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: OSystem.cxx,v 1.50 2005-12-18 18:37:03 stephena Exp $ +// $Id: OSystem.cxx,v 1.51 2005-12-23 20:48:50 stephena Exp $ //============================================================================ #include @@ -296,23 +296,29 @@ bool OSystem::createConsole(const string& romfile) // Create an instance of the 2600 game console // The Console c'tor takes care of updating the eventhandler state myConsole = new Console(image, size, md5, this); -#ifdef CHEATCODE_SUPPORT - myCheatManager->loadCheats(md5); -#endif + if(myConsole->isInitialized()) + { + #ifdef CHEATCODE_SUPPORT + myCheatManager->loadCheats(md5); + #endif + if(showmessage) + myFrameBuffer->showMessage("New console created"); + if(mySettings->getBool("showinfo")) + cout << "Game console created: " << myRomFile << endl; - if(showmessage) - myFrameBuffer->showMessage("New console created"); - if(mySettings->getBool("showinfo")) - cout << "Game console created: " << myRomFile << endl; - - retval = true; - myEventHandler->reset(EventHandler::S_EMULATE); - myFrameBuffer->setCursorState(); + myEventHandler->reset(EventHandler::S_EMULATE); + myFrameBuffer->setCursorState(); + retval = true; + } + else + { + cerr << "ERROR: Couldn't create console for " << myRomFile << " ..." << endl; + retval = false; + } } else { - cerr << "ERROR: Couldn't open " << myRomFile << "..." << endl; -// myEventHandler->quit(); + cerr << "ERROR: Couldn't open " << myRomFile << " ..." << endl; retval = false; }