More DiStella cleanups; the disassembly now properly uses peek() and dpeek()

methods from Debugger directly.  As well, the start address is now passed
into DiStella::disassemble() directly; decision to start from the reset
vector is done outside DiStella.  This is in preparation for starting
the disassembly from any valid address.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1933 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2010-02-02 22:21:03 +00:00
parent deedb04709
commit 03191759ab
6 changed files with 33 additions and 69 deletions

View File

@ -229,9 +229,10 @@ void CartDebug::disassemble(IntArray& addr, StringList& addrLabel,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartDebug::disassemble(DisassemblyList& list, uInt16 start, bool autocode)
{
DiStella distella(mySystem);
DiStella distella;
distella.disassemble(list, start, autocode);
// TODO - look at list, extract address to label mappings
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -99,8 +99,8 @@ class CartDebug : public DebuggerSystem
int start, int end);
/**
Disassemble from the starting address, placing results into a
DisassemblyList. If enabled, try to determine code vs. data.
Disassemble from the given address using the Distella disassembler
Address-to-label mappings (and vice-versa) are also determined here
*/
void disassemble(DisassemblyList& list, uInt16 start, bool autocode);

View File

@ -259,7 +259,7 @@ class Debugger : public DialogContainer
everywhere, but I feel it's better to place it here then in
YaccParser (which technically isn't related to it at all).
*/
static Debugger& debugger() { return *myStaticDebugger; }
inline static Debugger& debugger() { return *myStaticDebugger; }
/**
Get the dimensions of the various debugger dialog areas

View File

@ -21,12 +21,12 @@
#include <cstring>
#include "bspf.hxx"
#include "Debugger.hxx"
#include "DiStella.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DiStella::DiStella(System& system)
: mySystem(system),
labels(NULL) /* array of information about addresses-- can be from 2K-48K bytes in size */
DiStella::DiStella()
: labels(NULL) /* array of information about addresses-- can be from 2K-48K bytes in size */
{
}
@ -36,7 +36,7 @@ DiStella::~DiStella()
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 start,
bool autocode)
{
while(!myAddressQueue.empty())
@ -56,20 +56,6 @@ uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
}
memset(labels,0,myAppData.length);
/*-----------------------------------------------------
The last 3 words of a program are as follows:
.word INTERRUPT (isr_adr)
.word START (start_adr)
.word BRKroutine (brk_adr)
Since we always process START, move the Program
Counter 3 bytes back from the final byte.
-----------------------------------------------------*/
myPC = PC;
uInt16 start_adr = dpeek();
/*============================================
The offset is the address where the code segment
starts. For a 4K game, it is usually 0xf000,
@ -87,9 +73,9 @@ uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
Offset to code = $D000
Code range = $D000-$DFFF
=============================================*/
myOffset = (start_adr - (start_adr % 0x1000));
myOffset = (start - (start % 0x1000));
myAddressQueue.push(start_adr);
myAddressQueue.push(start);
if(autocode)
{
@ -121,21 +107,6 @@ uInt32 DiStella::disassemble(CartDebug::DisassemblyList& list, uInt16 PC,
return list.size();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt16 DiStella::dpeek()
{
uInt8 d1 = mySystem.peek(myPC++ | 0x1000);
uInt8 d2 = mySystem.peek(myPC++ | 0x1000);
return (uInt16) ((d2 << 8)+d1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt8 DiStella::peek()
{
return mySystem.peek(myPC | 0x1000);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass)
{
@ -168,8 +139,8 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
else
myBuf << HEX4 << myPC+myOffset << "' '";
myBuf << ".byte $" << HEX2 << (int)peek() << " ; ";
showgfx(peek());
myBuf << ".byte $" << HEX2 << (int)Debugger::debugger().peek(myPC|0x1000) << " ; ";
showgfx(Debugger::debugger().peek(myPC|0x1000));
myBuf << " $" << HEX4 << myPC+myOffset;
addEntry(list);
}
@ -183,7 +154,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
{
bytes = 1;
myBuf << HEX4 << myPC+myOffset << "'L" << myPC+myOffset << "'.byte "
<< "$" << HEX2 << (int)peek();
<< "$" << HEX2 << (int)Debugger::debugger().peek(myPC|0x1000);
}
myPC++;
@ -196,11 +167,11 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
if (bytes == 17)
{
addEntry(list);
myBuf << " ' '.byte $" << HEX2 << (int)peek();
myBuf << " ' '.byte $" << HEX2 << (int)Debugger::debugger().peek(myPC|0x1000);
bytes = 1;
}
else
myBuf << ",$" << HEX2 << (int)peek();
myBuf << ",$" << HEX2 << (int)Debugger::debugger().peek(myPC|0x1000);
}
myPC++;
}
@ -214,7 +185,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
}
else
{
op = peek();
op = Debugger::debugger().peek(myPC|0x1000);
/* version 2.1 bug fix */
if (pass == 2)
mark(myPC+myOffset, VALID_ENTRY);
@ -283,7 +254,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
else
myBuf << HEX4 << myPC+myOffset << "' '";
op = peek(); myPC++;
op = Debugger::debugger().peek(myPC|0x1000); myPC++;
myBuf << ".byte $" << HEX2 << (int)op;
addEntry(list);
}
@ -350,7 +321,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ABSOLUTE:
{
ad = dpeek();
ad = Debugger::debugger().dpeek(myPC|0x1000); myPC+=2;
labfound = mark(ad, REFERENCED);
if (pass == 1)
{
@ -409,7 +380,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ZERO_PAGE:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
labfound = mark(d1, REFERENCED);
if (pass == 3)
{
@ -431,7 +402,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case IMMEDIATE:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
if (pass == 3)
{
sprintf(linebuff," #$%.2X ",d1);
@ -444,7 +415,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ABSOLUTE_X:
{
ad = dpeek();
ad = Debugger::debugger().dpeek(myPC|0x1000); myPC+=2;
labfound = mark(ad, REFERENCED);
if (pass == 3)
{
@ -494,7 +465,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ABSOLUTE_Y:
{
ad = dpeek();
ad = Debugger::debugger().dpeek(myPC|0x1000); myPC+=2;
labfound = mark(ad, REFERENCED);
if (pass == 3)
{
@ -543,7 +514,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case INDIRECT_X:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
if (pass == 3)
{
sprintf(linebuff," ($%.2X,X)",d1);
@ -556,7 +527,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case INDIRECT_Y:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
if (pass == 3)
{
sprintf(linebuff," ($%.2X),Y",d1);
@ -569,7 +540,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ZERO_PAGE_X:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
labfound = mark(d1, REFERENCED);
if (pass == 3)
{
@ -591,7 +562,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ZERO_PAGE_Y:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
labfound = mark(d1,REFERENCED);
if (pass == 3)
{
@ -613,7 +584,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case RELATIVE:
{
d1 = peek(); myPC++;
d1 = Debugger::debugger().peek(myPC|0x1000); myPC++;
ad = d1;
if (d1 >= 128)
ad = d1 - 256;
@ -649,7 +620,7 @@ void DiStella::disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass
case ABS_INDIRECT:
{
ad = dpeek();
ad = Debugger::debugger().dpeek(myPC|0x1000); myPC+=2;
labfound = mark(ad, REFERENCED);
if (pass == 3)
{

View File

@ -24,7 +24,6 @@
#include "Array.hxx"
#include "bspf.hxx"
#include "System.hxx"
#include "CartDebug.hxx"
@ -43,7 +42,7 @@
class DiStella
{
public:
DiStella(System& system);
DiStella();
~DiStella();
public:
@ -51,12 +50,12 @@ class DiStella
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 start The address at which to start 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,
uInt32 disassemble(CartDebug::DisassemblyList& list, uInt16 start,
bool autocode = true);
private:
@ -78,12 +77,6 @@ class DiStella
// Here, we add a new entry to the DisassemblyList
void addEntry(CartDebug::DisassemblyList& list);
// Get a word and byte, respectively, from the System
// We use functions for this since Distella assumes that ROM starts
// at address 0, whereas the System class starts above $1000 instead
inline uInt16 dpeek();
inline uInt8 peek();
// These functions are part of the original Distella code
void disasm(CartDebug::DisassemblyList& list, uInt32 distart, int pass);
int mark(uInt32 address, MarkType bit);
@ -91,7 +84,6 @@ class DiStella
void showgfx(uInt8 c);
private:
System& mySystem;
stringstream myBuf;
queue<uInt16> myAddressQueue;
uInt32 myOffset, myPC, myPCBeg, myPCEnd;

View File

@ -200,7 +200,7 @@ void RomWidget::loadConfig()
*/
CartDebug::DisassemblyList list;
cart.disassemble(list, 0xfffc, true);
cart.disassemble(list, dbg.dpeek(0xfffc), true);
for(uInt32 i = 0; i < list.size(); ++i)
{