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
This commit is contained in:
stephena 2005-12-23 20:48:50 +00:00
parent 34c7c24e47
commit 8a74c4776e
6 changed files with 63 additions and 36 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <sstream> #include <sstream>
@ -206,10 +206,8 @@ int main(int argc, char* argv[])
string romfile = argv[argc - 1]; string romfile = argv[argc - 1];
if(argc == 1 || !FilesystemNode::fileExists(romfile)) if(argc == 1 || !FilesystemNode::fileExists(romfile))
theOSystem->createLauncher(); theOSystem->createLauncher();
else else if(theOSystem->createConsole(romfile))
{ {
theOSystem->createConsole(romfile);
if(theOSystem->settings().getBool("holdreset")) if(theOSystem->settings().getBool("holdreset"))
theOSystem->eventHandler().handleEvent(Event::ConsoleReset, 1); theOSystem->eventHandler().handleEvent(Event::ConsoleReset, 1);
@ -236,6 +234,11 @@ int main(int argc, char* argv[])
handler.enterDebugMode(); handler.enterDebugMode();
#endif #endif
} }
else
{
Cleanup();
return 0;
}
// Swallow any spurious events in the queue // Swallow any spurious events in the queue
// These are normally caused by joystick/mouse jitter // These are normally caused by joystick/mouse jitter

View File

@ -13,11 +13,12 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <assert.h> #include <assert.h>
#include <string.h>
#include "bspf.hxx"
#include "Cart.hxx" #include "Cart.hxx"
#include "Cart2K.hxx" #include "Cart2K.hxx"
#include "Cart3E.hxx" #include "Cart3E.hxx"
@ -97,10 +98,7 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size,
else if(type == "UA") else if(type == "UA")
cartridge = new CartridgeUA(image); cartridge = new CartridgeUA(image);
else else
{ cerr << "ERROR: Invalid cartridge type " << type << " ..." << endl;
// TODO: At some point this should be handled in a better way...
assert(false);
}
return cartridge; return cartridge;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <assert.h> #include <assert.h>
@ -200,8 +200,8 @@ void CartridgeAR::poke(uInt16 addr, uInt8)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeAR::patch(uInt16 address, uInt8 value) bool CartridgeAR::patch(uInt16 address, uInt8 value)
{ {
// myImage[address & 0x0FFF] = value; // myImage[address & 0x0FFF] = value;
return false; return false;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -298,19 +298,23 @@ void CartridgeAR::bankConfiguration(uInt8 configuration)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeAR::bank(uInt16 b) { void CartridgeAR::bank(uInt16 b)
if(bankLocked) return; {
if(bankLocked)
return;
bankConfiguration(b); bankConfiguration(b);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int CartridgeAR::bank() { int CartridgeAR::bank()
{
return myCurrentBank; return myCurrentBank;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int CartridgeAR::bankCount() { int CartridgeAR::bankCount()
{
return 32; return 32;
} }
@ -584,7 +588,8 @@ bool CartridgeAR::load(Deserializer& in)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8* CartridgeAR::getImage(int& size) { uInt8* CartridgeAR::getImage(int& size)
{
size = myNumberOfLoadImages * 8448; size = myNumberOfLoadImages * 8448;
return &myLoadImages[0]; return &myLoadImages[0];
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <assert.h> #include <assert.h>
@ -62,7 +62,8 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Console::Console(const uInt8* image, uInt32 size, const string& md5, Console::Console(const uInt8* image, uInt32 size, const string& md5,
OSystem* osystem) OSystem* osystem)
: myOSystem(osystem) : myOSystem(osystem),
myIsInitializedFlag(false)
{ {
myControllers[0] = 0; myControllers[0] = 0;
myControllers[1] = 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 *tia = new TIA(*this, myOSystem->settings());
tia->setSound(myOSystem->sound()); tia->setSound(myOSystem->sound());
Cartridge* cartridge = Cartridge::create(image, size, myProperties); Cartridge* cartridge = Cartridge::create(image, size, myProperties);
if(!cartridge)
return;
mySystem->attach(m6502); mySystem->attach(m6502);
mySystem->attach(m6532); mySystem->attach(m6532);
@ -215,6 +218,9 @@ Console::Console(const uInt8* image, uInt32 size, const string& md5,
myOSystem->debugger().setConsole(this); myOSystem->debugger().setConsole(this);
myOSystem->debugger().initialize(); myOSystem->debugger().initialize();
#endif #endif
// If we get this far, the console must be valid
myIsInitializedFlag = true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 #ifndef CONSOLE_HXX
@ -37,7 +37,7 @@ class System;
This class represents the entire game console. This class represents the entire game console.
@author Bradford W. Mott @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 class Console
{ {
@ -119,6 +119,11 @@ class Console
*/ */
M6532& riot() const { return *myRiot; } M6532& riot() const { return *myRiot; }
/**
Determine whether the console was successfully created
*/
bool isInitialized() { return myIsInitializedFlag; }
public: public:
/** /**
Overloaded assignment operator Overloaded assignment operator
@ -257,6 +262,10 @@ class Console
// Pointer to the 6532 (aka RIOT) (the debugger needs it) // Pointer to the 6532 (aka RIOT) (the debugger needs it)
// A RIOT of my own! (...with apologies to The Clash...) // A RIOT of my own! (...with apologies to The Clash...)
M6532 *myRiot; M6532 *myRiot;
// Indicates whether the console was correctly initialized
// We don't really care why it wasn't initialized ...
bool myIsInitializedFlag;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <cassert> #include <cassert>
@ -296,23 +296,29 @@ bool OSystem::createConsole(const string& romfile)
// Create an instance of the 2600 game console // Create an instance of the 2600 game console
// The Console c'tor takes care of updating the eventhandler state // The Console c'tor takes care of updating the eventhandler state
myConsole = new Console(image, size, md5, this); myConsole = new Console(image, size, md5, this);
#ifdef CHEATCODE_SUPPORT if(myConsole->isInitialized())
myCheatManager->loadCheats(md5); {
#endif #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) myEventHandler->reset(EventHandler::S_EMULATE);
myFrameBuffer->showMessage("New console created"); myFrameBuffer->setCursorState();
if(mySettings->getBool("showinfo")) retval = true;
cout << "Game console created: " << myRomFile << endl; }
else
retval = true; {
myEventHandler->reset(EventHandler::S_EMULATE); cerr << "ERROR: Couldn't create console for " << myRomFile << " ..." << endl;
myFrameBuffer->setCursorState(); retval = false;
}
} }
else else
{ {
cerr << "ERROR: Couldn't open " << myRomFile << "..." << endl; cerr << "ERROR: Couldn't open " << myRomFile << " ..." << endl;
// myEventHandler->quit();
retval = false; retval = false;
} }