Checking in WIP of converting DiStella to use the System class

from within Stella (vs. reading ROM data from a file).
Compilation is currently broken.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1931 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2010-02-01 20:00:50 +00:00
parent 0793c85b44
commit 91f1406ed4
4 changed files with 48 additions and 50 deletions

View File

@ -19,6 +19,7 @@
#include "bspf.hxx"
#include "Array.hxx"
#include "System.hxx"
#include "DiStella.hxx"
#include "CartDebug.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -225,6 +226,14 @@ void CartDebug::disassemble(IntArray& addr, StringList& addrLabel,
while(start <= end);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartDebug::disassemble(DisassemblyList& list, uInt16 start, bool autocode)
{
DiStella distella(mySystem);
distella.disassemble(list, start, autocode);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int CartDebug::disassemble(int address, string& result)
{

View File

@ -44,7 +44,8 @@ class CartDebug : public DebuggerSystem
{
public:
struct DisassemblyTag {
int address;
uInt16 address;
string label;
string disasm;
string bytes;
};
@ -97,6 +98,12 @@ class CartDebug : public DebuggerSystem
StringList& bytes, StringList& data,
int start, int end);
/**
Disassemble from the starting address, placing results into a
DisassemblyList.
*/
void disassemble(DisassemblyList& list, uInt16 start);
int getBank();
int bankCount();
string getCartType();

View File

@ -21,12 +21,12 @@
#include <cstring>
#include "bspf.hxx"
//#include "CartDebug.hxx"
#include "DiStella.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DiStella::DiStella()
: mem(NULL), /* copied data from the file-- can be from 2K-48K bytes in size */
DiStella::DiStella(System& system)
: mySystem(system),
mem(NULL), /* copied data from the file-- can be from 2K-48K bytes in size */
labels(NULL) /* array of information about addresses-- can be from 2K-48K bytes in size */
{
}
@ -37,8 +37,8 @@ DiStella::~DiStella()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 DiStella::disassemble(DisassemblyList& list, uInt16 PC,
const char* datafile, bool autocode)
uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
bool autocode)
{
myLineCount = 0;
while(!myAddressQueue.empty())
@ -50,24 +50,17 @@ uInt32 DiStella::disassemble(DisassemblyList& list, uInt16 PC,
myAppData.end = 0x0FFF;
myAppData.disp_data = 0;
if (!file_load(datafile))
{
fprintf(stderr,"Unable to load %s\n", datafile);
return -1;
}
/*====================================*/
/* Allocate memory for "labels" variable */
labels=(uInt8*) malloc(myAppData.length);
if (labels == NULL)
{
fprintf (stderr, "Malloc failed for 'labels' variable\n");
return -1;
return 0;
}
memset(labels,0,myAppData.length);
/*====================================*/
/*-----------------------------------------------------
The last 3 words of a program are as follows:
@ -160,26 +153,14 @@ uInt32 DiStella::disassemble(DisassemblyList& list, uInt16 PC,
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 DiStella::filesize(FILE *stream)
{
uInt32 curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 DiStella::read_adr()
uInt16 DiStella::read_adr()
{
uInt8 d1,d2;
d1 = mem[myPC++];
d2 = mem[myPC++];
d1 = mySystem.peek(myPC++);
d2 = mySystem.peek(myPC++);
return (uInt32) ((d2 << 8)+d1);
return (uInt16) ((d2 << 8)+d1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -229,7 +210,7 @@ int DiStella::file_load(const char* file)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DiStella::disasm(DisassemblyList& list, uInt32 distart, int pass)
void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass)
{
#define HEX4 uppercase << hex << setw(4) << setfill('0')
#define HEX2 uppercase << hex << setw(2) << setfill('0')
@ -930,10 +911,10 @@ void DiStella::showgfx(uInt8 c)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DiStella::addEntry(DisassemblyList& list)
void DiStella::addEntry(CartDebug::DisassemblyList& list)
{
const string& line = myBuf.str();
DisassemblyTag tag;
CartDebug::DisassemblyTag tag;
if(line[0] == ' ')
tag.address = 0;

View File

@ -24,18 +24,9 @@
#include "Array.hxx"
#include "bspf.hxx"
#include "System.hxx"
//#include "CartDebug.hxx"
//// The following will go in CartDebug
struct DisassemblyTag {
uInt16 address;
string label;
string disasm;
string bytes;
};
typedef Common::Array<DisassemblyTag> DisassemblyList;
//////////////////////////////////////////////////////////////
#include "CartDebug.hxx"
/**
This class is a wrapper around the Distella code. Much of the code remains
@ -52,11 +43,21 @@
class DiStella
{
public:
DiStella();
DiStella(System& system);
~DiStella();
public:
uInt32 disassemble(DisassemblyList& list, uInt16 PC, const char* datafile, bool autocode = true);
/**
Disassemble the current state of the System from the given start address.
@param list The results of the disassembly are placed here
@param start The start address for disassembly
@param autocode If enabled, try to determine code vs. data sections
@return The number of lines that were disassembled
*/
uInt32 disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
bool autocode = true);
private:
// Marked bits
@ -75,18 +76,18 @@ class DiStella
// Indicate that a new line of disassembly has been completed
// In the original Distella code, this indicated a new line to be printed
// Here, we add a new entry to the DisassemblyList
void addEntry(DisassemblyList& list);
void addEntry(CartDebug::DisassemblyList& list);
// These functions are part of the original Distella code
uInt32 filesize(FILE *stream);
uInt32 read_adr();
uInt16 read_adr();
int file_load(const char* file);
void disasm(DisassemblyList& list, uInt32 distart, int pass);
void disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass);
int mark(uInt32 address, MarkType bit);
int check_bit(uInt8 bitflags, int i);
void showgfx(uInt8 c);
private:
System& mySystem;
stringstream myBuf;
queue<uInt16> myAddressQueue;
uInt32 myOffset, myPC, myPCBeg, myPCEnd, myLineCount;