mirror of https://github.com/stella-emu/stella.git
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:
parent
0793c85b44
commit
91f1406ed4
|
@ -19,6 +19,7 @@
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
#include "Array.hxx"
|
#include "Array.hxx"
|
||||||
#include "System.hxx"
|
#include "System.hxx"
|
||||||
|
#include "DiStella.hxx"
|
||||||
#include "CartDebug.hxx"
|
#include "CartDebug.hxx"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -225,6 +226,14 @@ void CartDebug::disassemble(IntArray& addr, StringList& addrLabel,
|
||||||
while(start <= end);
|
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)
|
int CartDebug::disassemble(int address, string& result)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,8 @@ class CartDebug : public DebuggerSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct DisassemblyTag {
|
struct DisassemblyTag {
|
||||||
int address;
|
uInt16 address;
|
||||||
|
string label;
|
||||||
string disasm;
|
string disasm;
|
||||||
string bytes;
|
string bytes;
|
||||||
};
|
};
|
||||||
|
@ -97,6 +98,12 @@ class CartDebug : public DebuggerSystem
|
||||||
StringList& bytes, StringList& data,
|
StringList& bytes, StringList& data,
|
||||||
int start, int end);
|
int start, int end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Disassemble from the starting address, placing results into a
|
||||||
|
DisassemblyList.
|
||||||
|
*/
|
||||||
|
void disassemble(DisassemblyList& list, uInt16 start);
|
||||||
|
|
||||||
int getBank();
|
int getBank();
|
||||||
int bankCount();
|
int bankCount();
|
||||||
string getCartType();
|
string getCartType();
|
||||||
|
|
|
@ -21,12 +21,12 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
//#include "CartDebug.hxx"
|
|
||||||
#include "DiStella.hxx"
|
#include "DiStella.hxx"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
DiStella::DiStella()
|
DiStella::DiStella(System& system)
|
||||||
: mem(NULL), /* copied data from the file-- can be from 2K-48K bytes in size */
|
: 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 */
|
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,
|
uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
|
||||||
const char* datafile, bool autocode)
|
bool autocode)
|
||||||
{
|
{
|
||||||
myLineCount = 0;
|
myLineCount = 0;
|
||||||
while(!myAddressQueue.empty())
|
while(!myAddressQueue.empty())
|
||||||
|
@ -50,24 +50,17 @@ uInt32 DiStella::disassemble(DisassemblyList& list, uInt16 PC,
|
||||||
myAppData.end = 0x0FFF;
|
myAppData.end = 0x0FFF;
|
||||||
myAppData.disp_data = 0;
|
myAppData.disp_data = 0;
|
||||||
|
|
||||||
if (!file_load(datafile))
|
|
||||||
{
|
|
||||||
fprintf(stderr,"Unable to load %s\n", datafile);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*====================================*/
|
/*====================================*/
|
||||||
/* Allocate memory for "labels" variable */
|
/* Allocate memory for "labels" variable */
|
||||||
labels=(uInt8*) malloc(myAppData.length);
|
labels=(uInt8*) malloc(myAppData.length);
|
||||||
if (labels == NULL)
|
if (labels == NULL)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Malloc failed for 'labels' variable\n");
|
fprintf (stderr, "Malloc failed for 'labels' variable\n");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(labels,0,myAppData.length);
|
memset(labels,0,myAppData.length);
|
||||||
/*====================================*/
|
/*====================================*/
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------
|
/*-----------------------------------------------------
|
||||||
The last 3 words of a program are as follows:
|
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)
|
uInt16 DiStella::read_adr()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
uInt8 d1,d2;
|
uInt8 d1,d2;
|
||||||
|
|
||||||
d1 = mem[myPC++];
|
d1 = mySystem.peek(myPC++);
|
||||||
d2 = mem[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 HEX4 uppercase << hex << setw(4) << setfill('0')
|
||||||
#define HEX2 uppercase << hex << setw(2) << 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();
|
const string& line = myBuf.str();
|
||||||
DisassemblyTag tag;
|
CartDebug::DisassemblyTag tag;
|
||||||
|
|
||||||
if(line[0] == ' ')
|
if(line[0] == ' ')
|
||||||
tag.address = 0;
|
tag.address = 0;
|
||||||
|
|
|
@ -24,18 +24,9 @@
|
||||||
|
|
||||||
#include "Array.hxx"
|
#include "Array.hxx"
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
|
#include "System.hxx"
|
||||||
|
|
||||||
//#include "CartDebug.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;
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class is a wrapper around the Distella code. Much of the code remains
|
This class is a wrapper around the Distella code. Much of the code remains
|
||||||
|
@ -52,11 +43,21 @@
|
||||||
class DiStella
|
class DiStella
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DiStella();
|
DiStella(System& system);
|
||||||
~DiStella();
|
~DiStella();
|
||||||
|
|
||||||
public:
|
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:
|
private:
|
||||||
// Marked bits
|
// Marked bits
|
||||||
|
@ -75,18 +76,18 @@ class DiStella
|
||||||
// Indicate that a new line of disassembly has been completed
|
// Indicate that a new line of disassembly has been completed
|
||||||
// In the original Distella code, this indicated a new line to be printed
|
// In the original Distella code, this indicated a new line to be printed
|
||||||
// Here, we add a new entry to the DisassemblyList
|
// 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
|
// These functions are part of the original Distella code
|
||||||
uInt32 filesize(FILE *stream);
|
uInt16 read_adr();
|
||||||
uInt32 read_adr();
|
|
||||||
int file_load(const char* file);
|
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 mark(uInt32 address, MarkType bit);
|
||||||
int check_bit(uInt8 bitflags, int i);
|
int check_bit(uInt8 bitflags, int i);
|
||||||
void showgfx(uInt8 c);
|
void showgfx(uInt8 c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
System& mySystem;
|
||||||
stringstream myBuf;
|
stringstream myBuf;
|
||||||
queue<uInt16> myAddressQueue;
|
queue<uInt16> myAddressQueue;
|
||||||
uInt32 myOffset, myPC, myPCBeg, myPCEnd, myLineCount;
|
uInt32 myOffset, myPC, myPCBeg, myPCEnd, myLineCount;
|
||||||
|
|
Loading…
Reference in New Issue