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
// 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>
@ -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

View File

@ -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 <assert.h>
#include <string.h>
#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;
}

View File

@ -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 <assert.h>
@ -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];
}

View File

@ -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 <assert.h>
@ -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;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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

View File

@ -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 <cassert>
@ -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
if(myConsole->isInitialized())
{
#ifdef CHEATCODE_SUPPORT
myCheatManager->loadCheats(md5);
#endif
#endif
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();
retval = true;
}
else
{
cerr << "ERROR: Couldn't open " << myRomFile << "..." << endl;
// myEventHandler->quit();
cerr << "ERROR: Couldn't create console for " << myRomFile << " ..." << endl;
retval = false;
}
}
else
{
cerr << "ERROR: Couldn't open " << myRomFile << " ..." << endl;
retval = false;
}