mirror of https://github.com/stella-emu/stella.git
Implemented symbol file loading. There are still some rough edges, but
it does work. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@498 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
3af4b74147
commit
ab9e047d49
|
@ -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.5 2005-06-14 03:11:03 urchlay Exp $
|
||||
// $Id: Debugger.cxx,v 1.6 2005-06-15 04:30:33 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
@ -336,3 +336,8 @@ void Debugger::toggleV() {
|
|||
void Debugger::toggleN() {
|
||||
myDebugger->ps( myDebugger->ps() ^ 0x80 );
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Debugger::setEquateList(EquateList *l) {
|
||||
myDebugger->setEquateList(l);
|
||||
}
|
||||
|
|
|
@ -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.2 2005-06-13 02:47:44 urchlay Exp $
|
||||
// $Id: Debugger.hxx,v 1.3 2005-06-15 04:30:35 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef DEBUGGER_HXX
|
||||
|
@ -28,6 +28,7 @@ class D6502;
|
|||
|
||||
#include "DialogContainer.hxx"
|
||||
#include "M6502.hxx"
|
||||
#include "EquateList.hxx"
|
||||
#include "bspf.hxx"
|
||||
|
||||
enum {
|
||||
|
@ -46,7 +47,7 @@ enum {
|
|||
for all debugging operations in Stella (parser, 6502 debugger, etc).
|
||||
|
||||
@author Stephen Anthony
|
||||
@version $Id: Debugger.hxx,v 1.2 2005-06-13 02:47:44 urchlay Exp $
|
||||
@version $Id: Debugger.hxx,v 1.3 2005-06-15 04:30:35 urchlay Exp $
|
||||
*/
|
||||
class Debugger : public DialogContainer
|
||||
{
|
||||
|
@ -135,6 +136,7 @@ class Debugger : public DialogContainer
|
|||
void reset();
|
||||
|
||||
void formatFlags(int f, char *out);
|
||||
void setEquateList(EquateList *l);
|
||||
|
||||
protected:
|
||||
Console* myConsole;
|
||||
|
|
|
@ -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.3 2005-06-14 03:11:03 urchlay Exp $
|
||||
// $Id: DebuggerParser.cxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
@ -175,6 +175,15 @@ bool DebuggerParser::subStringMatch(const string& needle, const string& haystack
|
|||
string DebuggerParser::run(const string& command) {
|
||||
string result;
|
||||
|
||||
// special case command, takes a filename instead of an address:
|
||||
if(subStringMatch("loadsym ", command)) {
|
||||
result = command;
|
||||
result.erase(0, 8);
|
||||
result = equateList->loadFile(result);
|
||||
debugger->setEquateList(equateList);
|
||||
return result;
|
||||
}
|
||||
|
||||
if(!getArgs(command))
|
||||
return "invalid label or address";
|
||||
|
||||
|
@ -268,6 +277,7 @@ string DebuggerParser::run(const string& command) {
|
|||
// "break xx - Set/clear breakpoint at address xx\n"
|
||||
"c - Toggle Carry Flag\n"
|
||||
"d - Toggle Decimal Flag\n"
|
||||
"loadsym f - Load DASM symbols from file f\n"
|
||||
"n - Toggle Negative Flag\n"
|
||||
"pc xx - Set Program Counter to xx\n"
|
||||
"ram - Show RIOT RAM contents\n"
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "Equate.hxx"
|
||||
#include "EquateList.hxx"
|
||||
|
||||
// built in labels
|
||||
static struct Equate ourVcsEquates[] = {
|
||||
static struct Equate hardCodedEquates[] = {
|
||||
{ "VSYNC", 0x00 },
|
||||
{ "VBLANK", 0x01 },
|
||||
{ "WSYNC", 0x02 },
|
||||
|
@ -78,6 +82,19 @@ static struct Equate ourVcsEquates[] = {
|
|||
};
|
||||
|
||||
EquateList::EquateList() {
|
||||
cerr << sizeof(hardCodedEquates)/sizeof(struct Equate) << endl;
|
||||
ourVcsEquates = new Equate[ sizeof(hardCodedEquates)/sizeof(struct Equate) ];
|
||||
for(int i=0; hardCodedEquates[i].label != NULL; i++)
|
||||
ourVcsEquates[i] = hardCodedEquates[i];
|
||||
calcSize();
|
||||
}
|
||||
|
||||
int EquateList::calcSize() {
|
||||
currentSize = 0;
|
||||
for(int i=0; ourVcsEquates[i].label != NULL; i++)
|
||||
currentSize++;
|
||||
|
||||
return currentSize;
|
||||
}
|
||||
|
||||
// FIXME: use something smarter than a linear search in the future.
|
||||
|
@ -109,3 +126,106 @@ int EquateList::getAddress(const char *label) {
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
string EquateList::loadFile(string file) {
|
||||
int lines = 0;
|
||||
string curLabel;
|
||||
int curVal;
|
||||
// string::size_type p;
|
||||
char buffer[256]; // FIXME: static buffers suck
|
||||
|
||||
// cerr << "loading file " << file << endl;
|
||||
|
||||
ifstream in(file.c_str());
|
||||
if(!in.is_open())
|
||||
return "Unable to read symbols from " + file;
|
||||
|
||||
long start = in.tellg(); // save pointer to beginning of file
|
||||
|
||||
// iterate over file, count lines
|
||||
while( !in.eof() ) {
|
||||
in.getline(buffer, 255);
|
||||
lines++;
|
||||
}
|
||||
|
||||
// cerr << "total lines " << lines << endl;
|
||||
|
||||
// allocate enough storage for all the lines
|
||||
// FIXME: decide whether to keep the hard-coded symbols or throw them out
|
||||
// (currently allocating space for them, but throwing them away anyway)
|
||||
Equate *newEquates = new Equate[lines + currentSize + 1];
|
||||
lines = 0;
|
||||
|
||||
// start over, now that we've allocated enough entries.
|
||||
in.clear();
|
||||
in.seekg(start);
|
||||
|
||||
while( !in.eof() ) {
|
||||
curVal = 0;
|
||||
curLabel = "";
|
||||
|
||||
if(!in.getline(buffer, 255))
|
||||
break;
|
||||
|
||||
if(buffer[0] != '-') {
|
||||
curLabel = getLabel(buffer);
|
||||
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;
|
||||
|
||||
// cerr << "label: " << curLabel << ", address: " << curVal << endl;
|
||||
// cerr << buffer;
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
struct Equate *e = new struct Equate;
|
||||
newEquates[lines] = *e;
|
||||
newEquates[lines].label = NULL;
|
||||
newEquates[lines].address = 0;
|
||||
|
||||
calcSize();
|
||||
delete ourVcsEquates;
|
||||
ourVcsEquates = newEquates;
|
||||
|
||||
// dumpAll();
|
||||
return "loaded " + file + " OK";
|
||||
}
|
||||
|
||||
int EquateList::parse4hex(char *c) {
|
||||
int ret = 0;
|
||||
for(int i=0; i<4; i++) {
|
||||
if(*c >= '0' && *c <= '9')
|
||||
ret = (ret << 4) + (*c) - '0';
|
||||
else if(*c >= 'a' && *c <= 'f')
|
||||
ret = (ret << 4) + (*c) - 'a' + 10;
|
||||
else
|
||||
return -1;
|
||||
c++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
string EquateList::getLabel(char *c) {
|
||||
string l = "";
|
||||
while(*c != ' ')
|
||||
l += *c++;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void EquateList::dumpAll() {
|
||||
for(int i=0; ourVcsEquates[i].label != NULL; i++)
|
||||
cerr << i << ": " << "label==" << ourVcsEquates[i].label << ", address==" << ourVcsEquates[i].address << endl;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,24 @@
|
|||
#ifndef EQUATELIST_HXX
|
||||
#define EQUATELIST_HXX
|
||||
|
||||
#include <string>
|
||||
|
||||
class EquateList {
|
||||
public:
|
||||
EquateList();
|
||||
char *getLabel(int addr);
|
||||
char *EquateList::getFormatted(int addr, int places);
|
||||
int getAddress(const char *label);
|
||||
string loadFile(string file);
|
||||
|
||||
private:
|
||||
int calcSize();
|
||||
int parse4hex(char *c);
|
||||
string EquateList::getLabel(char *c);
|
||||
void dumpAll();
|
||||
|
||||
struct Equate *ourVcsEquates;
|
||||
int currentSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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: D6502.cxx,v 1.4 2005-06-14 01:55:52 urchlay Exp $
|
||||
// $Id: D6502.cxx,v 1.5 2005-06-15 04:30:35 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -32,7 +32,7 @@ D6502::D6502(System* system)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
D6502::~D6502()
|
||||
{
|
||||
delete equateList;
|
||||
// delete equateList;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -207,3 +207,8 @@ void D6502::y(uInt8 value)
|
|||
mySystem->m6502().Y = value;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void D6502::setEquateList(EquateList *el)
|
||||
{
|
||||
equateList = el;
|
||||
}
|
||||
|
|
|
@ -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: D6502.hxx,v 1.3 2005-06-14 01:55:52 urchlay Exp $
|
||||
// $Id: D6502.hxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef D6502_HXX
|
||||
|
@ -31,7 +31,7 @@ class System;
|
|||
basic functionality needed for interactive debuggers.
|
||||
|
||||
@author Bradford W. Mott
|
||||
@version $Id: D6502.hxx,v 1.3 2005-06-14 01:55:52 urchlay Exp $
|
||||
@version $Id: D6502.hxx,v 1.4 2005-06-15 04:30:35 urchlay Exp $
|
||||
*/
|
||||
class D6502
|
||||
{
|
||||
|
@ -145,7 +145,9 @@ class D6502
|
|||
*/
|
||||
void y(uInt8 value);
|
||||
|
||||
uInt16 D6502::dPeek(uInt16 address);
|
||||
uInt16 dPeek(uInt16 address);
|
||||
|
||||
void setEquateList(EquateList *el);
|
||||
|
||||
protected:
|
||||
// Pointer to the system I'm debugging
|
||||
|
|
Loading…
Reference in New Issue