Cleaned up the 'string to value' and 'value to string' methods.

Added PC, SP, A, X, Y registers to the CpuWidget.  These registers
can now be changed and viewed while stepping/tracing.

Still TODO is add a ToggleBitWidget to enable toggling of the
individual bits in the Processor Flag register.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@534 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-06-20 21:01:37 +00:00
parent b20a2ffc32
commit 5433918ba7
11 changed files with 153 additions and 153 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: Debugger.cxx,v 1.20 2005-06-20 18:32:11 stephena Exp $
// $Id: Debugger.cxx,v 1.21 2005-06-20 21:01:37 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -130,6 +130,39 @@ const string Debugger::run(const string& command)
return myParser->run(command);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string Debugger::valueToString(int value, BaseFormat outputBase)
{
char rendered[32];
if(outputBase == kBASE_DEFAULT)
outputBase = myParser->base();
switch(outputBase)
{
case kBASE_2:
if(value < 0x100)
sprintf(rendered, Debugger::to_bin_8(value));
else
sprintf(rendered, Debugger::to_bin_16(value));
break;
case kBASE_10:
sprintf(rendered, "%d", value);
break;
case kBASE_16:
default:
if(value < 0x100)
sprintf(rendered, Debugger::to_hex_8(value));
else
sprintf(rendered, Debugger::to_hex_16(value));
break;
}
return string(rendered);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const string Debugger::state()
{

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.hxx,v 1.18 2005-06-20 18:32:11 stephena Exp $
// $Id: Debugger.hxx,v 1.19 2005-06-20 21:01:37 stephena Exp $
//============================================================================
#ifndef DEBUGGER_HXX
@ -50,7 +50,7 @@ enum {
for all debugging operations in Stella (parser, 6502 debugger, etc).
@author Stephen Anthony
@version $Id: Debugger.hxx,v 1.18 2005-06-20 18:32:11 stephena Exp $
@version $Id: Debugger.hxx,v 1.19 2005-06-20 21:01:37 stephena Exp $
*/
class Debugger : public DialogContainer
{
@ -124,16 +124,9 @@ class Debugger : public DialogContainer
return to_bin(dec, 16, buf);
}
bool parseArgument(string& arg, int *value, string& rendered,
BaseFormat outputBase)
{
return myParser->parseArgument(arg, value, rendered, outputBase);
}
string parseValue(int value, BaseFormat outputBase)
{
return myParser->parseValue(value, outputBase);
}
int stringToValue(const string& stringval)
{ return myParser->decipher_arg(stringval); }
const string valueToString(int value, BaseFormat outputBase);
void toggleBreakPoint(int bp);
bool breakPoint(int bp);

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: DebuggerParser.cxx,v 1.19 2005-06-20 18:32:11 stephena Exp $
// $Id: DebuggerParser.cxx,v 1.20 2005-06-20 21:01:37 stephena Exp $
//============================================================================
#include "bspf.hxx"
@ -50,14 +50,11 @@ int DebuggerParser::conv_hex_digit(char d) {
else return -1;
}
void DebuggerParser::setBase(BaseFormat base) {
defaultBase = base;
}
// Evaluate expression.
int DebuggerParser::decipher_arg(string &arg) {
int DebuggerParser::decipher_arg(const string &str) {
bool derefByte=false, derefWord=false, lobyte=false, hibyte=false, bin=false, dec=false;
int result;
string arg = str;
if(defaultBase == kBASE_2) {
bin=true; dec=false;
@ -160,53 +157,6 @@ int DebuggerParser::decipher_arg(string &arg) {
return result;
}
// The GUI uses this:
bool DebuggerParser::parseArgument(
string& arg, int *value, string& rendered, BaseFormat outputBase)
{
*value = decipher_arg(arg);
if(*value == -1 || *value > 0xffff) {
rendered = "error";
return false;
}
rendered = parseValue(*value, outputBase);
return true;
}
string DebuggerParser::parseValue(int value, BaseFormat outputBase)
{
char rendered[32];
if(outputBase == kBASE_DEFAULT)
outputBase = defaultBase;
switch(outputBase)
{
case kBASE_2:
if(value < 0x100)
sprintf(rendered, Debugger::to_bin_8(value));
else
sprintf(rendered, Debugger::to_bin_16(value));
break;
case kBASE_10:
sprintf(rendered, "%d", value);
break;
case kBASE_16:
default:
if(value < 0x100)
sprintf(rendered, Debugger::to_hex_8(value));
else
sprintf(rendered, Debugger::to_hex_16(value));
break;
}
return string(rendered);
}
bool DebuggerParser::getArgs(const string& command) {
int state = kIN_COMMAND;
string curArg = "";

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: DebuggerParser.hxx,v 1.11 2005-06-20 18:32:11 stephena Exp $
// $Id: DebuggerParser.hxx,v 1.12 2005-06-20 21:01:37 stephena Exp $
//============================================================================
#ifndef DEBUGGER_PARSER_HXX
@ -40,16 +40,15 @@ class DebuggerParser
~DebuggerParser();
string run(const string& command);
bool parseArgument(string& arg, int *value, string& rendered,
BaseFormat outputBase = kBASE_DEFAULT);
string parseValue(int value, BaseFormat outputBase);
void setBase(BaseFormat base);
int decipher_arg(const string &str);
void setBase(BaseFormat base) { defaultBase = base; }
BaseFormat base() { return defaultBase; }
private:
bool getArgs(const string& command);
int conv_hex_digit(char d);
bool subStringMatch(const string& needle, const string& haystack);
int decipher_arg(string &arg);
string disasm();
string listBreaks();
string eval();

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: AddrValueWidget.cxx,v 1.4 2005-06-16 00:55:59 stephena Exp $
// $Id: AddrValueWidget.cxx,v 1.5 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -30,9 +30,12 @@
#include "AddrValueWidget.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AddrValueWidget::AddrValueWidget(GuiObject* boss, int x, int y, int w, int h)
AddrValueWidget::AddrValueWidget(GuiObject* boss, int x, int y, int w, int h,
int range, BaseFormat base)
: EditableWidget(boss, x, y, w, h),
CommandSender(boss)
CommandSender(boss),
_range(range),
_base(base)
{
_w = w - kScrollBarWidth;
@ -40,7 +43,7 @@ AddrValueWidget::AddrValueWidget(GuiObject* boss, int x, int y, int w, int h)
WIDGET_TAB_NAVIGATE;
_type = kListWidget; // we're just a slightly modified listwidget
_editMode = false;
_numberingMode = kHexNumbering;
_entriesPerPage = (_h - 2) / kLineHeight;
_currentPos = 0;
_selectedItem = -1;
@ -78,12 +81,13 @@ void AddrValueWidget::setList(const AddrList& alist, const ValueList& vlist)
// An efficiency thing
char temp[10];
string str;
for(unsigned int i = 0; i < (unsigned int)size; ++i)
{
sprintf(temp, "%.4x:", _addrList[i]);
_addrStringList.push_back(temp);
sprintf(temp, "%3d", _valueList[i]);
_valueStringList.push_back(temp);
str = instance()->debugger().valueToString(_valueList[i], _base);
_valueStringList.push_back(str);
}
if (_currentPos >= size)
@ -410,16 +414,17 @@ void AddrValueWidget::endEditMode()
_editMode = false;
// Update the both the string representation and the real data
int value = atoi(_editString.c_str());
if(_editString.length() == 0 || value < 0 || value > 255)
int value = instance()->debugger().stringToValue(_editString);
if(value < 0 || value > _range)
{
abortEditMode();
return;
}
char temp[10];
sprintf(temp, "%3d", value);
_valueStringList[_selectedItem] = temp;
// Correctly format the data for viewing
_editString = instance()->debugger().valueToString(value, _base);
_valueStringList[_selectedItem] = _editString;
_valueList[_selectedItem] = value;
sendCommand(kAVItemDataChangedCmd, _selectedItem);
@ -436,10 +441,14 @@ void AddrValueWidget::abortEditMode()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AddrValueWidget::tryInsertChar(char c, int pos)
{
if (c >= '0' && c <= '9')
// 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 == '$')
{
_editString.insert(pos, 1, c);
return true;
}
return false;
else
return 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: AddrValueWidget.hxx,v 1.3 2005-06-16 00:55:59 stephena Exp $
// $Id: AddrValueWidget.hxx,v 1.4 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -25,6 +25,7 @@
#include "GuiObject.hxx"
#include "Widget.hxx"
#include "Command.hxx"
#include "Debugger.hxx"
#include "StringList.hxx"
#include "EditableWidget.hxx"
#include "Array.hxx"
@ -35,13 +36,6 @@ class ScrollBarWidget;
typedef GUI::Array<int> AddrList;
typedef GUI::Array<int> ValueList;
enum NumberingMode {
kHexNumbering,
kDecimalNumbering,
kBinaryNumbering
};
// Some special commands
enum {
kAVItemDoubleClickedCmd = 'AVdb',
kAVItemActivatedCmd = 'AVac',
@ -53,7 +47,8 @@ enum {
class AddrValueWidget : public EditableWidget, public CommandSender
{
public:
AddrValueWidget(GuiObject* boss, int x, int y, int w, int h);
AddrValueWidget(GuiObject* boss, int x, int y, int w, int h,
int range, BaseFormat base = kBASE_DEFAULT);
virtual ~AddrValueWidget();
void setList(const StringList& list);
@ -64,7 +59,6 @@ class AddrValueWidget : public EditableWidget, public CommandSender
bool isEditable() const { return _editable; }
void setEditable(bool editable) { _editable = editable; }
void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; }
void scrollTo(int item);
virtual void handleMouseDown(int x, int y, int button, int clickCount);
@ -100,9 +94,11 @@ class AddrValueWidget : public EditableWidget, public CommandSender
StringList _addrStringList;
StringList _valueStringList;
int _range;
BaseFormat _base;
bool _editable;
bool _editMode;
NumberingMode _numberingMode;
int _currentPos;
int _entriesPerPage;
int _selectedItem;

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: CheatWidget.cxx,v 1.9 2005-06-17 17:34:01 stephena Exp $
// $Id: CheatWidget.cxx,v 1.10 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -88,8 +88,7 @@ CheatWidget::CheatWidget(GuiObject* boss, int x, int y, int w, int h)
"Address Value", kTextAlignLeft);
ypos += kLineHeight;
myResultsList = new AddrValueWidget(boss, xpos, ypos, 100, 75);
myResultsList->setNumberingMode(kHexNumbering);
myResultsList = new AddrValueWidget(boss, xpos, ypos, 100, 75, 0xff);
myResultsList->setFont(instance()->consoleFont());
myResultsList->setTarget(this);
@ -147,7 +146,7 @@ void CheatWidget::doSearch()
return;
}
int searchVal = atoi(str.c_str());
int searchVal = instance()->debugger().stringToValue(str);
// Clear the search array of previous items
mySearchArray.clear();
@ -225,14 +224,14 @@ void CheatWidget::doCompare()
negative = true;
str.erase(0, 1); // remove the operator
searchVal = atoi(str.c_str());
searchVal = instance()->debugger().stringToValue(str);
if(negative)
searchVal = -searchVal;
comparitiveSearch = true;
}
else
searchVal = atoi(str.c_str());
searchVal = instance()->debugger().stringToValue(str);
AddrValueList tempList;

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: CpuWidget.cxx,v 1.1 2005-06-20 18:32:12 stephena Exp $
// $Id: CpuWidget.cxx,v 1.2 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -45,34 +45,30 @@ CpuWidget::CpuWidget(GuiObject* boss, int x, int y, int w, int h)
CommandSender(boss)
{
int xpos = 10;
int ypos = 20;
int lwidth = 30;
int ypos = 10;
int lwidth = 20;
const int vWidth = _w - kButtonWidth - 20, space = 6, buttonw = 24;
/*
// Create a 16x8 grid (16 x 8 = 128 RAM bytes) with labels
for(int row = 0; row < 8; ++row)
// Create a 1x5 grid with labels for the CPU registers
myCpuGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 1, 5, 8, 0xffff);
myCpuGrid->setTarget(this);
myActiveWidget = myCpuGrid;
string labels[5] = { "PC", "SP", "A", "X", "Y" };
for(int row = 0; row < 5; ++row)
{
StaticTextWidget* t = new StaticTextWidget(boss, xpos, ypos + row*kLineHeight + 2,
lwidth, kLineHeight,
Debugger::to_hex_16(row*16 + kRamStart) + string(":"),
labels[row] + string(":"),
kTextAlignLeft);
t->setFont(instance()->consoleFont());
}
for(int col = 0; col < 16; ++col)
{
StaticTextWidget* t = new StaticTextWidget(boss, xpos + col*kColWidth + lwidth + 12,
ypos - kLineHeight,
lwidth, kLineHeight,
Debugger::to_hex_4(col),
kTextAlignLeft);
t->setFont(instance()->consoleFont());
}
*/
myCpuGrid = new DataGridWidget(boss, xpos+lwidth + 5, ypos, 1, 5, 8,
0xffff);
myCpuGrid->setTarget(this);
myActiveWidget = myCpuGrid;
// Create a read-only textbox containing the current PC label
ypos = 10;
myPCLabel = new StaticTextWidget(boss, xpos + lwidth + myCpuGrid->colWidth() + 10,
ypos, 100, kLineHeight, "FIXME!",
kTextAlignLeft);
/*
// Add some buttons for common actions
@ -128,12 +124,31 @@ void CpuWidget::handleCommand(CommandSender* sender, int cmd, int data)
switch(cmd)
{
case kDGItemDataChangedCmd:
cerr << "info changed\n";
/*
addr = myRamGrid->getSelectedAddr() - kRamStart;
value = myRamGrid->getSelectedValue();
instance()->debugger().writeRAM(addr, value);
*/
addr = myCpuGrid->getSelectedAddr();
value = myCpuGrid->getSelectedValue();
switch(addr)
{
case kPCRegAddr:
instance()->debugger().setPC(value);
break;
case kSPRegAddr:
instance()->debugger().setS(value);
break;
case kARegAddr:
instance()->debugger().setA(value);
break;
case kXRegAddr:
instance()->debugger().setX(value);
break;
case kYRegAddr:
instance()->debugger().setY(value);
break;
}
break;
/*
@ -194,11 +209,21 @@ void CpuWidget::fillGrid()
AddrList alist;
ValueList vlist;
for(unsigned int i = 0; i < kNumRegs; i++)
{
alist.push_back(i*16);
vlist.push_back(i*16);//instance()->debugger().readRAM(i));
}
// We push the enumerated items as addresses, and deal with the real
// address in the callback (handleCommand)
alist.push_back(kPCRegAddr);
alist.push_back(kSPRegAddr);
alist.push_back(kARegAddr);
alist.push_back(kXRegAddr);
alist.push_back(kYRegAddr);
// And now fill the values
Debugger& dbg = instance()->debugger();
vlist.push_back(dbg.getPC());
vlist.push_back(dbg.getS());
vlist.push_back(dbg.getA());
vlist.push_back(dbg.getX());
vlist.push_back(dbg.getY());
myCpuGrid->setList(alist, vlist);
}

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: CpuWidget.hxx,v 1.1 2005-06-20 18:32:12 stephena Exp $
// $Id: CpuWidget.hxx,v 1.2 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -51,6 +51,7 @@ class CpuWidget : public Widget, public CommandSender
DataGridWidget* myCpuGrid;
// FIXME - add a ToggleBitWidget for processor status (ps) register
StaticTextWidget* myPCLabel;
};
#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: DataGridWidget.cxx,v 1.1 2005-06-20 18:32:12 stephena Exp $
// $Id: DataGridWidget.cxx,v 1.2 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -84,7 +84,7 @@ void DataGridWidget::setList(const AddrList& alist, const ValueList& vlist)
string temp;
for(unsigned int i = 0; i < (unsigned int)size; ++i)
{
temp = instance()->debugger().parseValue(_valueList[i], _base);
temp = instance()->debugger().valueToString(_valueList[i], _base);
_valueStringList.push_back(temp);
}
@ -95,7 +95,7 @@ void DataGridWidget::setList(const AddrList& alist, const ValueList& vlist)
void DataGridWidget::setSelectedValue(int value)
{
// Correctly format the data for viewing
_editString = instance()->debugger().parseValue(value, _base);
_editString = instance()->debugger().valueToString(value, _base);
_valueStringList[_selectedItem] = _editString;
_valueList[_selectedItem] = value;
@ -397,22 +397,14 @@ void DataGridWidget::endEditMode()
_editMode = false;
// Update the both the string representation and the real data
int value; string result;
bool converted = instance()->debugger().parseArgument(_editString, &value,
result, _base);
if(!converted || value < 0 || value > _range)
int value = instance()->debugger().stringToValue(_editString);
if(value < 0 || value > _range)
{
abortEditMode();
return;
}
// Correctly format the data for viewing
_editString = result;
_valueStringList[_selectedItem] = _editString;
_valueList[_selectedItem] = value;
sendCommand(kDGItemDataChangedCmd, _selectedItem);
setSelectedValue(value);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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: EditNumWidget.cxx,v 1.3 2005-06-17 17:34:01 stephena Exp $
// $Id: EditNumWidget.cxx,v 1.4 2005-06-20 21:01:37 stephena Exp $
//
// Based on code from ScummVM - Scumm Interpreter
// Copyright (C) 2002-2004 The ScummVM project
@ -45,13 +45,16 @@ void EditNumWidget::setEditString(const string& str)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EditNumWidget::tryInsertChar(char c, int pos)
{
// Only allow numbers (FIXME - maybe allow A .. F for hex?)
if(isprint(c) && ((c >= '0' && c <= '9') || c == '+' || c == '-'))
// 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;
}
return false;
else
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -