From 1103f1dfbb7fd455d59a2c286f880aa8ee04dc4e Mon Sep 17 00:00:00 2001 From: stephena Date: Sat, 3 Apr 2010 17:11:23 +0000 Subject: [PATCH] Some cleanups to various classes, removing some debug print statements. Partial cleanup of the debugger 'help' command, making the output line up a little nicer. More work is required in this area. Fixed bug in EditableWidget; setEditString now implies that editing will be started (if it's been enabled). git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1987 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/debugger/CartDebug.cxx | 5 --- src/debugger/Debugger.cxx | 58 ++++++++++++++++++------------- src/debugger/DebuggerParser.cxx | 41 +++++++++++++--------- src/debugger/gui/PromptWidget.cxx | 1 - src/debugger/gui/RomWidget.cxx | 3 +- src/gui/EditableWidget.cxx | 5 ++- src/gui/EditableWidget.hxx | 6 ++-- src/yacc/YaccParser.cxx | 1 - src/yacc/stella.y | 2 +- src/yacc/y.tab.c | 2 +- 10 files changed, 69 insertions(+), 55 deletions(-) diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index bf8e38d40..b46af0169 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -264,9 +264,6 @@ bool CartDebug::fillDisassemblyList(uInt16 start, bool autocode, uInt16 search) if(tag.address == search) found = true; } - - // TODO - look at list, extract address to label mappings - // we need these for label support in the UI and promptwidget } return found; } @@ -418,8 +415,6 @@ string CartDebug::loadSymbolFile(const string& f) else file += ".sym"; -cerr << "loadSymbolFile: " << file << endl; - int pos = 0, lines = 0, curVal; string curLabel; char line[1024]; diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 68c740ece..5cd0e1195 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -26,6 +26,7 @@ #include "Version.hxx" #include "OSystem.hxx" #include "FrameBuffer.hxx" +#include "FSNode.hxx" #include "Settings.hxx" #include "DebuggerDialog.hxx" #include "DebuggerParser.hxx" @@ -319,7 +320,9 @@ void Debugger::autoExec() // autoexec.stella is always run const string& autoexec = myOSystem->baseDir() + BSPF_PATH_SEPARATOR + "autoexec.stella"; - myPrompt->print("autoExec():\n" + myParser->exec(autoexec) + "\n"); + FilesystemNode autoexec_node(autoexec); + if(autoexec_node.exists()) + myPrompt->print("autoExec():\n" + myParser->exec(autoexec) + "\n"); // Also, "romname.stella" if present string file = myOSystem->romFile(); @@ -330,20 +333,18 @@ void Debugger::autoExec() else file += ".stella"; - myPrompt->print("autoExec():\n" + myParser->exec(file) + "\n"); - myPrompt->printPrompt(); + FilesystemNode romname_node(file); + if(romname_node.exists()) + myPrompt->print("autoExec():\n" + myParser->exec(file) + "\n"); // Init builtins for(int i = 0; builtin_functions[i][0] != ""; i++) { // TODO - check this for memory leaks int res = YaccParser::parse(builtin_functions[i][1].c_str()); - if(res != 0) - { - cerr << "ERROR in builtin function!" << endl; - Expression* exp = YaccParser::getResult(); - addFunction(builtin_functions[i][0], builtin_functions[i][1], exp, true); - } + if(res != 0) cerr << "ERROR in builtin function!" << endl; + Expression* exp = YaccParser::getResult(); + addFunction(builtin_functions[i][0], builtin_functions[i][1], exp, true); } } @@ -806,29 +807,38 @@ const FunctionDefMap Debugger::getFunctionDefMap() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const string Debugger::builtinHelp() const { - string result; + ostringstream buf; + uInt16 len, c_maxlen = 0, i_maxlen = 0; - for(int i=0; builtin_functions[i][0] != ""; i++) + // Get column widths for aligned output + for(int i = 0; builtin_functions[i][0] != ""; ++i) { - result += builtin_functions[i][0]; - result += " {"; - result += builtin_functions[i][1]; - result += "}\n"; - result += " "; - result += builtin_functions[i][2]; - result += "\n"; + len = builtin_functions[i][0].length(); + if(len > c_maxlen) c_maxlen = len; + len = builtin_functions[i][1].length(); + if(len > i_maxlen) i_maxlen = len; } - return result; + + for(int i = 0; builtin_functions[i][0] != ""; ++i) + { + buf << setw(c_maxlen) << left << builtin_functions[i][0] + << setw(2) << right << "{" + << setw(i_maxlen) << left << builtin_functions[i][1] + << setw(4) << "}" + << builtin_functions[i][2] + << endl; + } + return buf.str(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Debugger::saveROM(const string& filename) const { - // TODO: error checking - ofstream *out = new ofstream(filename.c_str(), ios::out | ios::binary); - bool res = myConsole->cartridge().save(*out); - delete out; - return res; + ofstream out(filename.c_str(), ios::out | ios::binary); + if(out.is_open()) + return myConsole->cartridge().save(out); + else + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/DebuggerParser.cxx b/src/debugger/DebuggerParser.cxx index b6297ed6d..458a7ea58 100644 --- a/src/debugger/DebuggerParser.cxx +++ b/src/debugger/DebuggerParser.cxx @@ -919,25 +919,34 @@ void DebuggerParser::executeExec() // "help" void DebuggerParser::executeHelp() { - static char buf[256]; + ostringstream buf; + + // Find length of longest command + uInt16 clen = 0; for(int i = 0; i < kNumCommands; ++i) { - BSPF_snprintf(buf, 255, "%13s - %s\n", - commands[i].cmdString.c_str(), - commands[i].description.c_str()); - - commandResult += buf; + uInt16 len = commands[i].cmdString.length(); + if(len > clen) clen = len; } - commandResult += "\nBuilt-in functions:\n"; - commandResult += debugger->builtinHelp(); - commandResult += "\nPseudo-registers:\n"; - commandResult += "_bank Currently selected bank\n"; - commandResult += "_rwport Read from a write port was triggered\n"; - commandResult += "_scan Current scanline count\n"; - commandResult += "_fcount Number of frames since emulation started\n"; - commandResult += "_cclocks Color clocks on current scanline\n"; - commandResult += "_vsync Whether vertical sync is enabled (1 or 0)\n"; - commandResult += "_vblank Whether vertical blank is enabled (1 or 0)\n"; + + // TODO - add wraparound for text longer than the output area bounds + for(int i = 0; i < kNumCommands; ++i) + buf << setw(clen) << right << commands[i].cmdString << " - " << commands[i].description << endl; + + buf << endl + << "\nPseudo-registers:" << endl + << "_bank Currently selected bank" << endl + << "_rwport Address at which a read from a write port occurred" << endl + << "_scan Current scanline count" << endl + << "_fcount Number of frames since emulation started" << endl + << "_cclocks Color clocks on current scanline" << endl + << "_vsync Whether vertical sync is enabled (1 or 0)" << endl + << "_vblank Whether vertical blank is enabled (1 or 0)" << endl + << endl + << "Built-in functions:" << endl + << debugger->builtinHelp(); + + commandResult = buf.str(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 719d544f9..15405b5f8 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -507,7 +507,6 @@ void PromptWidget::loadConfig() // Display greetings & prompt string version = string("Stella ") + STELLA_VERSION + "\n"; print(version.c_str()); - print("Debugger is ready\n"); print(PROMPT); _promptStartPos = _promptEndPos = _currentPos; diff --git a/src/debugger/gui/RomWidget.cxx b/src/debugger/gui/RomWidget.cxx index 47dbc36ea..a07da3a89 100644 --- a/src/debugger/gui/RomWidget.cxx +++ b/src/debugger/gui/RomWidget.cxx @@ -123,14 +123,12 @@ void RomWidget::loadConfig() myListIsDirty |= cart.disassemble(myAutocode->getSelectedTag(), myListIsDirty); if(myListIsDirty) { -cerr << "list is dirty, re-disassembled\n"; myRomList->setList(cart.disassemblyList(), dbg.breakpoints()); myListIsDirty = false; } // Update romlist to point to current PC int pcline = cart.addressToLine(dbg.cpuDebug().pc()); -cerr << "PC = " << hex << dbg.cpuDebug().pc() << ", line = " << dec << pcline << endl; if(pcline >= 0) myRomList->setHighlighted(pcline); @@ -166,6 +164,7 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) if(rmb == "saverom") { mySaveRom->show(_x + 50, _y + 80); + mySaveRom->setEditString(""); mySaveRom->setTitle(""); mySaveRom->setEmitSignal(kRomNameEntered); } diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index 7c7ad4344..d83a44f9e 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -32,7 +32,7 @@ EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font, { _caretVisible = false; _caretTime = 0; - _caretPos = 0; // FIXME + _caretPos = 0; _caretInverse = false; @@ -61,6 +61,9 @@ void EditableWidget::setEditString(const string& str) if (_editScrollOffset < 0) _editScrollOffset = 0; + if(_editable) + startEditMode(); + // Make sure the new string is seen onscreen setDirty(); draw(); } diff --git a/src/gui/EditableWidget.hxx b/src/gui/EditableWidget.hxx index 254516bb2..a265aea17 100644 --- a/src/gui/EditableWidget.hxx +++ b/src/gui/EditableWidget.hxx @@ -54,9 +54,9 @@ class EditableWidget : public Widget, public CommandSender virtual bool wantsFocus() { return _editable; } protected: - virtual void startEditMode() { setFlags(WIDGET_WANTS_RAWDATA); _editString = ""; } - virtual void endEditMode() { clearFlags(WIDGET_WANTS_RAWDATA); _editString = ""; } - virtual void abortEditMode() { clearFlags(WIDGET_WANTS_RAWDATA); _editString = ""; } + virtual void startEditMode() { setFlags(WIDGET_WANTS_RAWDATA); } + virtual void endEditMode() { clearFlags(WIDGET_WANTS_RAWDATA); } + virtual void abortEditMode() { clearFlags(WIDGET_WANTS_RAWDATA); } virtual GUI::Rect getEditRect() const = 0; virtual int getCaretOffset() const; diff --git a/src/yacc/YaccParser.cxx b/src/yacc/YaccParser.cxx index 5c89f1bc8..dfe334937 100644 --- a/src/yacc/YaccParser.cxx +++ b/src/yacc/YaccParser.cxx @@ -76,7 +76,6 @@ int parse(const char *in) lastExp = 0; errMsg = "(no error)"; setInput(in); -cerr << "PARSE: " << in << endl; return yyparse(); } diff --git a/src/yacc/stella.y b/src/yacc/stella.y index 98c4bee79..7864bacd7 100644 --- a/src/yacc/stella.y +++ b/src/yacc/stella.y @@ -6,7 +6,7 @@ Expression* lastExp = 0; #define YYERROR_VERBOSE 1 /* dump Expression stack during parsing? */ -#define DEBUG_EXP 1 +#define DEBUG_EXP 0 int yylex(); char *yytext; diff --git a/src/yacc/y.tab.c b/src/yacc/y.tab.c index 04adb8315..a22d95256 100644 --- a/src/yacc/y.tab.c +++ b/src/yacc/y.tab.c @@ -77,7 +77,7 @@ Expression* lastExp = 0; #define YYERROR_VERBOSE 1 /* dump Expression stack during parsing? */ -#define DEBUG_EXP 1 +#define DEBUG_EXP 0 int yylex(); char *yytext;