From f6d40c47000729e67bda17b3bdeee40eb61364f1 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 21 Jun 2005 18:46:34 +0000 Subject: [PATCH] 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 --- stella/src/build/makefile | 3 +- stella/src/common/FrameBufferSoft.cxx | 9 ++-- stella/src/common/SoundSDL.cxx | 3 +- stella/src/common/SoundSDL.hxx | 20 ++++---- stella/src/debugger/Debugger.cxx | 9 +++- stella/src/debugger/Equate.hxx | 4 +- stella/src/debugger/EquateList.cxx | 59 ++++++++++-------------- stella/src/debugger/EquateList.hxx | 16 +++++-- stella/src/debugger/PackedBitArray.cxx | 2 +- stella/src/gui/LauncherDialog.cxx | 26 +++++++---- stella/src/gui/LauncherDialog.hxx | 13 +++++- stella/src/gui/LauncherOptionsDialog.cxx | 14 ++---- stella/src/gui/LauncherOptionsDialog.hxx | 7 ++- 13 files changed, 104 insertions(+), 81 deletions(-) diff --git a/stella/src/build/makefile b/stella/src/build/makefile index 0219ddedf..08b7ae97d 100644 --- a/stella/src/build/makefile +++ b/stella/src/build/makefile @@ -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 diff --git a/stella/src/common/FrameBufferSoft.cxx b/stella/src/common/FrameBufferSoft.cxx index bcdda0aaa..7097b5a08 100644 --- a/stella/src/common/FrameBufferSoft.cxx +++ b/stella/src/common/FrameBufferSoft.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: 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 @@ -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) { diff --git a/stella/src/common/SoundSDL.cxx b/stella/src/common/SoundSDL.cxx index b46ab82e2..eca419a5e 100644 --- a/stella/src/common/SoundSDL.cxx +++ b/stella/src/common/SoundSDL.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: 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 @@ -35,6 +35,7 @@ SoundSDL::SoundSDL(OSystem* osystem) : Sound(osystem), myIsEnabled(osystem->settings().getBool("sound")), + myIsInitializedFlag(false), myFragmentSizeLogBase2(0), myIsMuted(false) { diff --git a/stella/src/common/SoundSDL.hxx b/stella/src/common/SoundSDL.hxx index 80a7d8f81..8ab355e57 100644 --- a/stella/src/common/SoundSDL.hxx +++ b/stella/src/common/SoundSDL.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: 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; diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index ad5d8390c..f9acd8876 100644 --- a/stella/src/debugger/Debugger.cxx +++ b/stella/src/debugger/Debugger.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: 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); diff --git a/stella/src/debugger/Equate.hxx b/stella/src/debugger/Equate.hxx index 429413152..b83a8d710 100644 --- a/stella/src/debugger/Equate.hxx +++ b/stella/src/debugger/Equate.hxx @@ -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; diff --git a/stella/src/debugger/EquateList.cxx b/stella/src/debugger/EquateList.cxx index 538bab835..b79a778c3 100644 --- a/stella/src/debugger/EquateList.cxx +++ b/stella/src/debugger/EquateList.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: 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 @@ -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 +#include "bspf.hxx" +#include "Equate.hxx" +#include "Array.hxx" + +typedef GUI::Array 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; }; diff --git a/stella/src/debugger/PackedBitArray.cxx b/stella/src/debugger/PackedBitArray.cxx index 600fe1108..0c9355b30 100644 --- a/stella/src/debugger/PackedBitArray.cxx +++ b/stella/src/debugger/PackedBitArray.cxx @@ -14,7 +14,7 @@ PackedBitArray::PackedBitArray(int length) { } PackedBitArray::~PackedBitArray() { - delete bits; + delete[] bits; } int PackedBitArray::isSet(unsigned int bit) { diff --git a/stella/src/gui/LauncherDialog.cxx b/stella/src/gui/LauncherDialog.cxx index d3b826dbf..0fb835f64 100644 --- a/stella/src/gui/LauncherDialog.cxx +++ b/stella/src/gui/LauncherDialog.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: 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); } diff --git a/stella/src/gui/LauncherDialog.hxx b/stella/src/gui/LauncherDialog.hxx index 706cdc0d9..0342ee319 100644 --- a/stella/src/gui/LauncherDialog.hxx +++ b/stella/src/gui/LauncherDialog.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: 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: diff --git a/stella/src/gui/LauncherOptionsDialog.cxx b/stella/src/gui/LauncherOptionsDialog.cxx index 03b92e0c8..b300b7b76 100644 --- a/stella/src/gui/LauncherOptionsDialog.cxx +++ b/stella/src/gui/LauncherOptionsDialog.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: 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: diff --git a/stella/src/gui/LauncherOptionsDialog.hxx b/stella/src/gui/LauncherOptionsDialog.hxx index 8ccfcfedc..d842f86c1 100644 --- a/stella/src/gui/LauncherOptionsDialog.hxx +++ b/stella/src/gui/LauncherOptionsDialog.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: 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();