Fixed some Valgrind errors, mostly non-initialized data.

Fixed some memory leaks in EquateList, and moved to using a dynamic array.
This greatly simplifies the code and abstracts away all new/delete
operations.  More cleanup can still be done, since the symfile no longer has
to be scanned for # of lines.  Still TODO is similar code for the watchlist
stuff, so all memleaks can be eliminated.

Changed launcher so that if Stella is started with no romdir specified
(maybe first time it's been used), the launcher options are shown so
you can select the romdir.  Thanks to Brad for the advice.

Updated LauncherOptionsDialog to send a signal when a romdir has been
set.  When that happens, the launcher automatically reloads the rom listing.
Again, thanks to Brad for the advice.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@539 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-06-21 18:46:34 +00:00
parent 88108e44f0
commit f6d40c4700
13 changed files with 104 additions and 81 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: makefile,v 1.103 2005-06-21 04:30:49 urchlay Exp $
## $Id: makefile,v 1.104 2005-06-21 18:46:32 stephena Exp $
##============================================================================
##============================================================================
@ -179,7 +179,6 @@ CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
stella: $(CORE_OBJS) $(OBJS)
$(LD) -o $(EXE_NAME) $(CORE_OBJS) $(OBJS) $(LDFLAGS) $(LDLIBS)
strip $(EXE_NAME)
M6502Low.ins: $(CORE)/m6502/src/M6502Low.m4 $(CORE)/m6502/src/M6502.m4
m4 $(CORE)/m6502/src/M6502Low.m4 $(CORE)/m6502/src/M6502.m4 > $(CORE)/m6502/src/M6502Low.ins

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: FrameBufferSoft.cxx,v 1.26 2005-06-16 00:55:56 stephena Exp $
// $Id: FrameBufferSoft.cxx,v 1.27 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#include <SDL.h>
@ -31,15 +31,15 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferSoft::FrameBufferSoft(OSystem* osystem)
: FrameBuffer(osystem)
: FrameBuffer(osystem),
myRectList(NULL)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferSoft::~FrameBufferSoft()
{
if(myRectList)
delete myRectList;
delete myRectList;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -48,6 +48,7 @@ bool FrameBufferSoft::initSubsystem()
mySDLFlags |= SDL_SWSURFACE;
// Set up the rectangle list to be used in the dirty update
delete myRectList;
myRectList = new RectList();
if(!myRectList)
{

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: SoundSDL.cxx,v 1.17 2005-06-16 00:55:56 stephena Exp $
// $Id: SoundSDL.cxx,v 1.18 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#include <sstream>
@ -35,6 +35,7 @@
SoundSDL::SoundSDL(OSystem* osystem)
: Sound(osystem),
myIsEnabled(osystem->settings().getBool("sound")),
myIsInitializedFlag(false),
myFragmentSizeLogBase2(0),
myIsMuted(false)
{

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: SoundSDL.hxx,v 1.11 2005-06-16 00:55:56 stephena Exp $
// $Id: SoundSDL.hxx,v 1.12 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#ifndef SOUND_SDL_HXX
@ -31,7 +31,7 @@ class OSystem;
This class implements the sound API for SDL.
@author Stephen Anthony and Bradford W. Mott
@version $Id: SoundSDL.hxx,v 1.11 2005-06-16 00:55:56 stephena Exp $
@version $Id: SoundSDL.hxx,v 1.12 2005-06-21 18:46:33 stephena Exp $
*/
class SoundSDL : public Sound
{
@ -226,17 +226,17 @@ class SoundSDL : public Sound
};
private:
// Indicates if the sound subsystem is to be initialized
bool myIsEnabled;
// Indicates if the sound subsystem is to be initialized
bool myIsEnabled;
// Indicates if the sound device was successfully initialized
bool myIsInitializedFlag;
// Indicates if the sound device was successfully initialized
bool myIsInitializedFlag;
// Indicates the cycle when a sound register was last set
Int32 myLastRegisterSetCycle;
// Indicates the cycle when a sound register was last set
Int32 myLastRegisterSetCycle;
// Indicates the base framerate depending on whether the ROM is NTSC or PAL
uInt32 myDisplayFrameRate;
// Indicates the base framerate depending on whether the ROM is NTSC or PAL
uInt32 myDisplayFrameRate;
// Log base 2 of the selected fragment size
double myFragmentSizeLogBase2;

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: Debugger.cxx,v 1.24 2005-06-21 05:00:45 urchlay Exp $
// $Id: Debugger.cxx,v 1.25 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -41,7 +41,12 @@ Debugger::Debugger(OSystem* osystem)
myConsole(NULL),
mySystem(NULL),
myParser(NULL),
myDebugger(NULL)
myDebugger(NULL),
equateList(NULL),
breakPoints(NULL),
readTraps(NULL),
writeTraps(NULL),
myTIAdebug(NULL)
{
// Init parser
myParser = new DebuggerParser(this);

View File

@ -13,12 +13,14 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: Equate.hxx,v 1.2 2005-06-16 00:20:11 stephena Exp $
// $Id: Equate.hxx,v 1.3 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#ifndef EQUATE_HXX
#define EQUATE_HXX
#include "bspf.hxx"
struct Equate {
char *label;
int address;

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: EquateList.cxx,v 1.10 2005-06-21 04:30:49 urchlay Exp $
// $Id: EquateList.cxx,v 1.11 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#include <string>
@ -25,7 +25,7 @@
#include "EquateList.hxx"
// built in labels
static struct Equate hardCodedEquates[] = {
static Equate hardCodedEquates[] = {
{ "VSYNC", 0x00 },
{ "VBLANK", 0x01 },
{ "WSYNC", 0x02 },
@ -94,32 +94,32 @@ static struct Equate hardCodedEquates[] = {
{ "TIM1T", 0x0294 },
{ "TIM8T", 0x0295 },
{ "TIM64T", 0x0296 },
{ "TIM1024T", 0x0297 },
{ NULL, 0 }
{ "TIM1024T", 0x0297 }
};
EquateList::EquateList() {
// cerr << sizeof(hardCodedEquates)/sizeof(struct Equate) << endl;
int size = sizeof(hardCodedEquates)/sizeof(struct Equate) + 1;
ourVcsEquates = new Equate[ size ];
// for(int i=0; hardCodedEquates[i].label != NULL; i++)
int size = sizeof(hardCodedEquates)/sizeof(struct Equate);
for(int i=0; i<size; i++)
ourVcsEquates[i] = hardCodedEquates[i];
ourVcsEquates.push_back(hardCodedEquates[i]);
calcSize();
}
int EquateList::calcSize() {
currentSize = 0;
for(int i=0; ourVcsEquates[i].label != NULL; i++)
currentSize++;
EquateList::~EquateList() {
cerr << "EquateList::~EquateList()\n";
ourVcsEquates.clear();
}
int EquateList::calcSize() {
currentSize = ourVcsEquates.size();
return currentSize;
}
// FIXME: use something smarter than a linear search in the future.
char *EquateList::getLabel(int addr) {
// cerr << "getLabel(" << addr << ")" << endl;
for(int i=0; ourVcsEquates[i].label != NULL; i++) {
for(int i=0; i<currentSize; i++) {
// cerr << "Checking ourVcsEquates[" << i << "] (" << ourVcsEquates[i].label << ")" << endl;
if(ourVcsEquates[i].address == addr) {
// cerr << "Found label " << ourVcsEquates[i].label << endl;
@ -148,7 +148,7 @@ int EquateList::getAddress(const char *lbl) {
// cerr << "getAddress(" << lbl << ")" << endl;
// cerr << ourVcsEquates[0].label << endl;
// cerr << "shit" << endl;
for(int i=0; ourVcsEquates[i].label != NULL; i++) {
for(int i=0; i<currentSize; i++) {
// cerr << "Looking at " << ourVcsEquates[i].label << endl;
if( STR_CASE_CMP(ourVcsEquates[i].label, lbl) == 0 )
return ourVcsEquates[i].address;
@ -172,6 +172,7 @@ string EquateList::loadFile(string file) {
long start = in.tellg(); // save pointer to beginning of file
// FIXME - we no longer need # of lines, so this can probably be removed
// iterate over file, count lines
while( !in.eof() ) {
in.getline(buffer, 255);
@ -182,13 +183,13 @@ string EquateList::loadFile(string file) {
// allocate enough storage for all the lines plus the
// hard-coded symbols
int hardSize = sizeof(hardCodedEquates)/sizeof(struct Equate) - 1;
Equate *newEquates = new Equate[lines + hardSize + 1];
int hardSize = sizeof(hardCodedEquates)/sizeof(struct Equate);
lines = hardSize;
// Make sure the hard-coded equates show up first
ourVcsEquates.clear();
for(int i=0; i<hardSize; i++) {
newEquates[i] = hardCodedEquates[i];
ourVcsEquates.push_back(hardCodedEquates[i]);
}
// start over, now that we've allocated enough entries.
@ -207,15 +208,12 @@ string EquateList::loadFile(string file) {
if((curVal = parse4hex(buffer+25)) < 0)
return "invalid symbol file";
struct Equate *e = new struct Equate;
// FIXME: this is cumbersome...
// I shouldn't have to use sprintf() here.
// also, is this a memory leak? I miss malloc() and free()...
newEquates[lines] = *e;
newEquates[lines].label = new char[curLabel.length() + 1];
sprintf(newEquates[lines].label, "%s", curLabel.c_str());
newEquates[lines].address = curVal;
// FIXME - this is a memleak and *must* be fixed
// ideally, the Equate class should hold a string, not a char*
Equate e;
e.label = strdup(curLabel.c_str());
e.address = curVal;
ourVcsEquates.push_back(e);
// cerr << "label: " << curLabel << ", address: " << curVal << endl;
// cerr << buffer;
@ -224,13 +222,6 @@ string EquateList::loadFile(string file) {
}
in.close();
struct Equate *e = new struct Equate;
newEquates[lines] = *e;
newEquates[lines].label = NULL;
newEquates[lines].address = 0;
delete ourVcsEquates;
ourVcsEquates = newEquates;
calcSize();
// dumpAll();
@ -261,6 +252,6 @@ string EquateList::getLabel(char *c) {
}
void EquateList::dumpAll() {
for(int i=0; ourVcsEquates[i].label != NULL; i++)
for(int i=0; i<currentSize; i++)
cerr << i << ": " << "label==" << ourVcsEquates[i].label << ", address==" << ourVcsEquates[i].address << endl;
}

View File

@ -13,19 +13,24 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: EquateList.hxx,v 1.5 2005-06-16 00:20:11 stephena Exp $
// $Id: EquateList.hxx,v 1.6 2005-06-21 18:46:33 stephena Exp $
//============================================================================
#ifndef EQUATELIST_HXX
#define EQUATELIST_HXX
#include <string>
#include "bspf.hxx"
#include "Equate.hxx"
#include "Array.hxx"
typedef GUI::Array<Equate> Equates;
class EquateList {
public:
EquateList();
~EquateList();
char *getLabel(int addr);
char *EquateList::getFormatted(int addr, int places);
char *getFormatted(int addr, int places);
int getAddress(const char *label);
string loadFile(string file);
void dumpAll();
@ -33,9 +38,10 @@ class EquateList {
private:
int calcSize();
int parse4hex(char *c);
string EquateList::getLabel(char *c);
string getLabel(char *c);
struct Equate *ourVcsEquates;
private:
Equates ourVcsEquates;
int currentSize;
};

View File

@ -14,7 +14,7 @@ PackedBitArray::PackedBitArray(int length) {
}
PackedBitArray::~PackedBitArray() {
delete bits;
delete[] bits;
}
int PackedBitArray::isSet(unsigned int bit) {

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: LauncherDialog.cxx,v 1.23 2005-06-20 18:32:12 stephena Exp $
// $Id: LauncherDialog.cxx,v 1.24 2005-06-21 18:46:33 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -40,13 +40,6 @@
#include "bspf.hxx"
enum {
kStartCmd = 'STRT',
kOptionsCmd = 'OPTI',
kReloadCmd = 'RELO',
kQuitCmd = 'QUIT'
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
int x, int y, int w, int h)
@ -106,7 +99,8 @@ LauncherDialog::LauncherDialog(OSystem* osystem, DialogContainer* parent,
// Create the launcher options dialog, where you can change ROM
// and snapshot paths
myOptions = new LauncherOptionsDialog(osystem, parent, 20, 60, _w - 40, _h - 120);
myOptions = new LauncherOptionsDialog(osystem, parent, this,
20, 60, _w - 40, _h - 120);
// Create a game list, which contains all the information about a ROM that
// the launcher needs
@ -155,6 +149,16 @@ void LauncherDialog::updateListing(bool fullReload)
string romdir = instance()->settings().getString("romdir");
string cacheFile = instance()->cacheFile();
// If this is the first time using Stella, the romdir won't be set.
// In that case, display the options dialog, and don't let Stella proceed
// until the options are set.
if(romdir == "")
{
myOptionsButton->setEnabled(true);
parent()->addDialog(myOptions);
return;
}
// Figure out if the ROM dir has changed since we last accessed it.
// If so, we do a full reload from disk (takes quite some time).
// Otherwise, we can use the cache file (which is much faster).
@ -383,6 +387,10 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, int data)
instance()->eventHandler().quit();
break;
case kRomDirChosenCmd:
updateListing();
break;
default:
Dialog::handleCommand(sender, cmd, data);
}

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: LauncherDialog.hxx,v 1.9 2005-06-16 00:55:59 stephena Exp $
// $Id: LauncherDialog.hxx,v 1.10 2005-06-21 18:46:33 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -35,6 +35,17 @@ class OSystem;
#include "GameList.hxx"
#include "bspf.hxx"
enum {
kStartCmd = 'STRT',
kOptionsCmd = 'OPTI',
kReloadCmd = 'RELO',
kQuitCmd = 'QUIT',
kChooseRomDirCmd = 'roms', // rom select
kChooseSnapDirCmd = 'snps', // snap select
kRomDirChosenCmd = 'romc', // rom chosen
kSnapDirChosenCmd = 'snpc' // snap chosen
};
class LauncherDialog : public Dialog
{
public:

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: LauncherOptionsDialog.cxx,v 1.5 2005-06-16 00:55:59 stephena Exp $
// $Id: LauncherOptionsDialog.cxx,v 1.6 2005-06-21 18:46:33 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -25,20 +25,15 @@
#include "TabWidget.hxx"
#include "FSNode.hxx"
#include "bspf.hxx"
#include "LauncherDialog.hxx"
#include "LauncherOptionsDialog.hxx"
enum {
kChooseRomDirCmd = 'roms', // rom select
kChooseSnapDirCmd = 'snps', // snap select
kRomDirChosenCmd = 'romc', // rom chosen
kSnapDirChosenCmd = 'snpc' // snap chosen
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LauncherOptionsDialog::LauncherOptionsDialog(
OSystem* osystem, DialogContainer* parent,
OSystem* osystem, DialogContainer* parent, GuiObject* boss,
int x, int y, int w, int h)
: Dialog(osystem, parent, x, y, w, h),
CommandSender(boss),
myBrowser(NULL)
{
const int vBorder = 4;
@ -177,6 +172,7 @@ void LauncherOptionsDialog::handleCommand(CommandSender* sender, int cmd, int da
case kOKCmd:
saveConfig();
close();
sendCommand(kRomDirChosenCmd, 0); // Let the boss know romdir has changed
break;
case kChooseRomDirCmd:

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: LauncherOptionsDialog.hxx,v 1.4 2005-06-16 00:55:59 stephena Exp $
// $Id: LauncherOptionsDialog.hxx,v 1.5 2005-06-21 18:46:34 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -23,6 +23,7 @@
#define LAUNCHER_OPTIONS_DIALOG_HXX
class OSystem;
class GuiObject;
class DialogContainer;
class BrowserDialog;
class CheckboxWidget;
@ -30,11 +31,13 @@ class PopUpWidget;
class StaticTextWidget;
#include "Dialog.hxx"
#include "Command.hxx"
class LauncherOptionsDialog : public Dialog
class LauncherOptionsDialog : public Dialog, public CommandSender
{
public:
LauncherOptionsDialog(OSystem* osystem, DialogContainer* parent,
GuiObject* boss,
int x, int y, int w, int h);
~LauncherOptionsDialog();