diff --git a/stella/src/debugger/Debugger.cxx b/stella/src/debugger/Debugger.cxx index 1b156d079..2a3281582 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.95 2005-09-23 23:35:02 stephena Exp $ +// $Id: Debugger.cxx,v 1.96 2005-10-06 17:28:54 stephena Exp $ //============================================================================ #include "bspf.hxx" @@ -1110,7 +1110,8 @@ const string Debugger::builtinHelp() { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Debugger::saveROM(string filename) { +bool Debugger::saveROM(string filename) +{ // TODO: error checking ofstream *out = new ofstream(filename.c_str(), ios::out | ios::binary); bool res = myConsole->cartridge().save(*out); diff --git a/stella/src/debugger/DebuggerParser.cxx b/stella/src/debugger/DebuggerParser.cxx index 468b92fb0..f8bc69191 100644 --- a/stella/src/debugger/DebuggerParser.cxx +++ b/stella/src/debugger/DebuggerParser.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: DebuggerParser.cxx,v 1.83 2005-10-02 01:15:53 stephena Exp $ +// $Id: DebuggerParser.cxx,v 1.84 2005-10-06 17:28:54 stephena Exp $ //============================================================================ #include "bspf.hxx" @@ -1673,7 +1673,7 @@ void DebuggerParser::executeSave() { // "saverom" void DebuggerParser::executeSaverom() { if(debugger->saveROM(argStrings[0])) - commandResult = "saved ROM"; + commandResult = "saved ROM as " + argStrings[0]; else commandResult = red("failed to save ROM"); } diff --git a/stella/src/debugger/gui/ContextMenu.cxx b/stella/src/debugger/gui/ContextMenu.cxx index 46159c075..715e8f836 100644 --- a/stella/src/debugger/gui/ContextMenu.cxx +++ b/stella/src/debugger/gui/ContextMenu.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: ContextMenu.cxx,v 1.3 2005-09-23 23:35:02 stephena Exp $ +// $Id: ContextMenu.cxx,v 1.4 2005-10-06 17:28:55 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -157,10 +157,10 @@ void ContextMenu::setSelection(int item) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ContextMenu::sendSelection() { - sendCommand(kCMenuItemSelectedCmd, _selectedItem, -1); - // We remove the dialog when the user has selected an item parent()->removeDialog(); + + sendCommand(kCMenuItemSelectedCmd, _selectedItem, -1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/debugger/gui/RomWidget.cxx b/stella/src/debugger/gui/RomWidget.cxx index ac0e7630b..7facd7119 100644 --- a/stella/src/debugger/gui/RomWidget.cxx +++ b/stella/src/debugger/gui/RomWidget.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: RomWidget.cxx,v 1.7 2005-09-23 23:35:02 stephena Exp $ +// $Id: RomWidget.cxx,v 1.8 2005-10-06 17:28:55 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -26,10 +26,15 @@ #include "CpuDebug.hxx" #include "PackedBitArray.hxx" #include "GuiObject.hxx" +#include "InputTextDialog.hxx" #include "ContextMenu.hxx" #include "RomListWidget.hxx" #include "RomWidget.hxx" +enum { + kRomNameEntered = 'RWrn' +}; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y) : Widget(boss, x, y, 16, 16), @@ -50,6 +55,10 @@ RomWidget::RomWidget(GuiObject* boss, const GUI::Font& font, int x, int y) // Calculate real dimensions _w = myRomList->getWidth(); _h = myRomList->getHeight(); + + // Create dialog box for save ROM (get name) + mySaveRom = new InputTextDialog(boss, font, _x + 50, _y + 80); + mySaveRom->setTarget(this); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -81,12 +90,29 @@ void RomWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) const string& rmb = myRomList->myMenu->getSelectedString(); if(rmb == "Save ROM") - saveROM(); + { + mySaveRom->setTitle(""); + mySaveRom->setEmitSignal(kRomNameEntered); + parent()->addDialog(mySaveRom); + } else if(rmb == "Set PC") setPC(myRomList->getSelected()); break; } + + case kRomNameEntered: + { + const string& rom = mySaveRom->getResult(); + if(rom == "") + mySaveRom->setTitle("Invalid name"); + else + { + saveROM(rom); + parent()->removeDialog(); + } + break; + } } } @@ -193,7 +219,9 @@ void RomWidget::patchROM(int data, const string& bytes) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void RomWidget::saveROM() +void RomWidget::saveROM(const string& rom) { -cerr << "save ROM\n"; + ostringstream command; + command << "saverom " << rom; + instance()->debugger().run(command.str()); } diff --git a/stella/src/debugger/gui/RomWidget.hxx b/stella/src/debugger/gui/RomWidget.hxx index bb25107fc..e50a71c6c 100644 --- a/stella/src/debugger/gui/RomWidget.hxx +++ b/stella/src/debugger/gui/RomWidget.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: RomWidget.hxx,v 1.5 2005-09-23 17:38:27 stephena Exp $ +// $Id: RomWidget.hxx,v 1.6 2005-10-06 17:28:55 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -23,6 +23,7 @@ #define ROM_WIDGET_HXX class GuiObject; +class InputTextDialog; class RomListWidget; class StringList; @@ -53,7 +54,7 @@ class RomWidget : public Widget, public CommandSender void setBreak(int data); void setPC(int data); void patchROM(int data, const string& bytes); - void saveROM(); + void saveROM(const string& rom); private: RomListWidget* myRomList; @@ -64,6 +65,8 @@ class RomWidget : public Widget, public CommandSender /** List of line numbers indexed by address */ AddrToLine myLineList; + InputTextDialog* mySaveRom; + bool myListIsDirty; bool mySourceAvailable; int myCurrentBank; diff --git a/stella/src/gui/EditNumWidget.cxx b/stella/src/gui/EditNumWidget.cxx deleted file mode 100644 index 6f13703a1..000000000 --- a/stella/src/gui/EditNumWidget.cxx +++ /dev/null @@ -1,129 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team -// -// See the file "license" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -// -// $Id: EditNumWidget.cxx,v 1.8 2005-08-10 12:23:42 stephena Exp $ -// -// Based on code from ScummVM - Scumm Interpreter -// Copyright (C) 2002-2004 The ScummVM project -//============================================================================ - -#include "OSystem.hxx" -#include "FrameBuffer.hxx" -#include "Dialog.hxx" -#include "EditNumWidget.hxx" - - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -EditNumWidget::EditNumWidget(GuiObject* boss, int x, int y, int w, int h, - const string& text) - : EditableWidget(boss, x, y, w, h) -{ - _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; - _type = kEditTextWidget; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::setEditString(const string& str) -{ - EditableWidget::setEditString(str); - _backupString = str; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool EditNumWidget::tryInsertChar(char c, int pos) -{ - // Not sure how efficient this is, or should we even care? - c = tolower(c); - if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || - c == '%' || c == '#' || c == '$' || c == '+' || c == '-') - { - _editString.insert(pos, 1, c); - return true; - } - else - return false; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::handleMouseDown(int x, int y, int button, int clickCount) -{ - x += _editScrollOffset; - - int width = 0; - unsigned int i; - - for (i = 0; i < _editString.size(); ++i) - { - width += _font->getCharWidth(_editString[i]); - if (width >= x) - break; - } - - setCaretPos(i); - setDirty(); draw(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::drawWidget(bool hilite) -{ -cerr << "EditNumWidget::drawWidget\n"; - FrameBuffer& fb = _boss->instance()->frameBuffer(); - - // Draw a thin frame around us. - fb.hLine(_x, _y, _x + _w - 1, kColor); - fb.hLine(_x, _y + _h - 1, _x +_w - 1, kShadowColor); - fb.vLine(_x, _y, _y + _h - 1, kColor); - fb.vLine(_x + _w - 1, _y, _y + _h - 1, kShadowColor); - - // Draw the text - adjustOffset(); - fb.drawString(_font, _editString, _x + 2, _y + 2, getEditRect().width(), - kTextColor, kTextAlignLeft, -_editScrollOffset, false); - - // Draw the caret - drawCaret(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -GUI::Rect EditNumWidget::getEditRect() const -{ - GUI::Rect r(2, 0, _w - 2, _h - 1); - return r; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::lostFocusWidget() -{ - // If we loose focus, 'commit' the user changes - _backupString = _editString; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::startEditMode() -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::endEditMode() -{ - releaseFocus(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void EditNumWidget::abortEditMode() -{ - setEditString(_backupString); - releaseFocus(); -} diff --git a/stella/src/gui/EditNumWidget.hxx b/stella/src/gui/EditNumWidget.hxx deleted file mode 100644 index a5a71eb1d..000000000 --- a/stella/src/gui/EditNumWidget.hxx +++ /dev/null @@ -1,55 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team -// -// See the file "license" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -// -// $Id: EditNumWidget.hxx,v 1.3 2005-06-30 00:08:01 stephena Exp $ -// -// Based on code from ScummVM - Scumm Interpreter -// Copyright (C) 2002-2004 The ScummVM project -//============================================================================ - -#ifndef EDIT_NUM_WIDGET_HXX -#define EDIT_NUM_WIDGET_HXX - -#include "Rect.hxx" -#include "EditableWidget.hxx" - - -/* EditNumWidget */ -class EditNumWidget : public EditableWidget -{ - public: - EditNumWidget(GuiObject* boss, int x, int y, int w, int h, const string& text); - - void setEditString(const string& str); - - virtual void handleMouseDown(int x, int y, int button, int clickCount); - - protected: - void drawWidget(bool hilite); - void lostFocusWidget(); - - void startEditMode(); - void endEditMode(); - void abortEditMode(); - - bool tryInsertChar(char c, int pos); - - GUI::Rect getEditRect() const; - - protected: - string _backupString; -}; - -#endif diff --git a/stella/src/gui/InputTextDialog.cxx b/stella/src/gui/InputTextDialog.cxx index afaff6aac..c6765e4b2 100644 --- a/stella/src/gui/InputTextDialog.cxx +++ b/stella/src/gui/InputTextDialog.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: InputTextDialog.cxx,v 1.5 2005-09-26 19:10:37 stephena Exp $ +// $Id: InputTextDialog.cxx,v 1.6 2005-10-06 17:28:55 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -37,7 +37,8 @@ enum { InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, int x, int y) : Dialog(boss->instance(), boss->parent(), x, y, 16, 16), - CommandSender(boss) + CommandSender(boss), + _errorFlag(false) { const int fontWidth = font.getMaxCharWidth(), fontHeight = font.getFontHeight(), @@ -77,6 +78,13 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& font, #endif } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void InputTextDialog::setTitle(const string& title) +{ + _title->setLabel(title); + _errorFlag = true; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputTextDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) @@ -96,10 +104,20 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd, break; } + case kEditChangedCmd: + // Erase the invalid message once editing is restarted + if(_errorFlag) + { + _title->setLabel(""); + _errorFlag = false; + } + break; + case kEditCancelCmd: Dialog::handleCommand(sender, kCloseCmd, data, id); break; + default: Dialog::handleCommand(sender, cmd, data, id); break; diff --git a/stella/src/gui/InputTextDialog.hxx b/stella/src/gui/InputTextDialog.hxx index c61bc8333..60b8b27b2 100644 --- a/stella/src/gui/InputTextDialog.hxx +++ b/stella/src/gui/InputTextDialog.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: InputTextDialog.hxx,v 1.2 2005-08-11 19:12:39 stephena Exp $ +// $Id: InputTextDialog.hxx,v 1.3 2005-10-06 17:28:55 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -37,8 +37,8 @@ class InputTextDialog : public Dialog, public CommandSender const string& getResult() { return _input->getEditString(); } void setEditString(const string& str) { _input->setEditString(str); } - void setTitle(const string& title) { _title->setLabel(title); } void setEmitSignal(int cmd) { _cmd = cmd; } + void setTitle(const string& title); protected: virtual void handleCommand(CommandSender* sender, int cmd, int data, int id); @@ -48,6 +48,7 @@ class InputTextDialog : public Dialog, public CommandSender EditTextWidget* _input; int _cmd; + bool _errorFlag; }; #endif