Converted M6502 class to use unique_ptr Expressions, and removed some dead code.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3074 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-11-16 00:28:39 +00:00
parent 526fbed5e6
commit c997fc3001
2 changed files with 8 additions and 83 deletions

View File

@ -17,9 +17,6 @@
// $Id$ // $Id$
//============================================================================ //============================================================================
//#define DEBUG_OUTPUT
#define debugStream cout
#ifdef DEBUGGER_SUPPORT #ifdef DEBUGGER_SUPPORT
#include "Debugger.hxx" #include "Debugger.hxx"
#include "Expression.hxx" #include "Expression.hxx"
@ -50,7 +47,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
M6502::M6502(const Settings& settings) M6502::M6502(const Settings& settings)
: myExecutionStatus(0), : myExecutionStatus(0),
mySystem(0), mySystem(nullptr),
mySettings(settings), mySettings(settings),
myLastAccessWasRead(true), myLastAccessWasRead(true),
myTotalInstructionCount(0), myTotalInstructionCount(0),
@ -72,28 +69,11 @@ M6502::M6502(const Settings& settings)
myJustHitTrapFlag = false; myJustHitTrapFlag = false;
#endif #endif
// Compute the System Cycle table
for(uInt32 t = 0; t < 256; ++t)
{
myInstructionSystemCycleTable[t] = ourInstructionCycleTable[t] *
SYSTEM_CYCLES_PER_CPU;
}
#ifdef DEBUG_OUTPUT
debugStream << "( Fm Ln Cyc Clk) ( P0 P1 M0 M1 BL) "
<< "flags A X Y SP Code Disasm" << endl
<< endl;
#endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
M6502::~M6502() M6502::~M6502()
{ {
#ifdef DEBUGGER_SUPPORT
myBreakConds.clear();
myBreakCondNames.clear();
#endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -213,14 +193,10 @@ bool M6502::execute(uInt32 number)
} }
} }
if(myBreakPoints != nullptr) if(myBreakPoints)
{
if(myBreakPoints->isSet(PC)) if(myBreakPoints->isSet(PC))
{
if(myDebugger && myDebugger->start("BP: ", PC)) if(myDebugger && myDebugger->start("BP: ", PC))
return true; return true;
}
}
int cond = evalCondBreaks(); int cond = evalCondBreaks();
if(cond > -1) if(cond > -1)
@ -229,7 +205,8 @@ bool M6502::execute(uInt32 number)
if(myDebugger && myDebugger->start(buf)) if(myDebugger && myDebugger->start(buf))
return true; return true;
} }
#endif #endif // DEBUGGER_SUPPORT
uInt16 operandAddress = 0, intermediateAddress = 0; uInt16 operandAddress = 0, intermediateAddress = 0;
uInt8 operand = 0; uInt8 operand = 0;
@ -239,23 +216,6 @@ bool M6502::execute(uInt32 number)
// Fetch instruction at the program counter // Fetch instruction at the program counter
IR = peek(PC++, DISASM_CODE); // This address represents a code section IR = peek(PC++, DISASM_CODE); // This address represents a code section
#ifdef DEBUG_OUTPUT
debugStream << ::hex << setw(2) << (int)A << " "
<< ::hex << setw(2) << (int)X << " "
<< ::hex << setw(2) << (int)Y << " "
<< ::hex << setw(2) << (int)SP << " "
<< setw(4) << (PC-1) << ": "
<< setw(2) << (int)IR << " "
// << "<" << ourAddressingModeTable[IR] << " ";
// debugStream << hex << setw(4) << operandAddress << " ";
// << setw(3) << ourInstructionMnemonicTable[IR]
// debugStream << "PS=" << ::hex << setw(2) << (int)PS() << " ";
// debugStream << "Cyc=" << dec << mySystem->cycles();
<< endl;
#endif
// Call code to execute the instruction // Call code to execute the instruction
switch(IR) switch(IR)
{ {
@ -434,7 +394,7 @@ void M6502::attach(Debugger& debugger)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 M6502::addCondBreak(Expression *e, const string& name) uInt32 M6502::addCondBreak(Expression *e, const string& name)
{ {
myBreakConds.push_back(e); myBreakConds.emplace_back(unique_ptr<Expression>(e));
myBreakCondNames.push_back(name); myBreakCondNames.push_back(name);
return (uInt32)myBreakConds.size() - 1; return (uInt32)myBreakConds.size() - 1;
} }
@ -444,7 +404,6 @@ void M6502::delCondBreak(uInt32 brk)
{ {
if(brk < myBreakConds.size()) if(brk < myBreakConds.size())
{ {
delete myBreakConds[brk];
Vec::removeAt(myBreakConds, brk); Vec::removeAt(myBreakConds, brk);
Vec::removeAt(myBreakCondNames, brk); Vec::removeAt(myBreakCondNames, brk);
} }
@ -453,9 +412,6 @@ void M6502::delCondBreak(uInt32 brk)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void M6502::clearCondBreaks() void M6502::clearCondBreaks()
{ {
for(uInt32 i = 0; i < myBreakConds.size(); i++)
delete myBreakConds[i];
myBreakConds.clear(); myBreakConds.clear();
myBreakCondNames.clear(); myBreakCondNames.clear();
} }
@ -488,25 +444,4 @@ void M6502::setTraps(PackedBitArray *read, PackedBitArray *write)
myReadTraps = read; myReadTraps = read;
myWriteTraps = write; myWriteTraps = write;
} }
#endif #endif // DEBUGGER_SUPPORT
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 M6502::ourInstructionCycleTable[256] = {
// 0 1 2 3 4 5 6 7 8 9 a b c d e f
7, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6, // 0
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 1
6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 4, 4, 6, 6, // 2
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 3
6, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 3, 4, 6, 6, // 4
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 5
6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 5, 4, 6, 6, // 6
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // 7
2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, // 8
2, 6, 2, 6, 4, 4, 4, 4, 2, 5, 2, 5, 5, 5, 5, 5, // 9
2, 6, 2, 6, 3, 3, 3, 4, 2, 2, 2, 2, 4, 4, 4, 4, // a
2, 5, 2, 5, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, // b
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, // c
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, // d
2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, // e
2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7 // f
};

View File

@ -31,7 +31,7 @@ class Settings;
#include "System.hxx" #include "System.hxx"
#include "Serializable.hxx" #include "Serializable.hxx"
typedef vector<Expression*> ExpressionList; typedef vector<unique_ptr<Expression>> ExpressionList;
/** /**
The 6502 is an 8-bit microprocessor that has a 64K addressing space. The 6502 is an 8-bit microprocessor that has a 64K addressing space.
@ -318,9 +318,6 @@ class M6502 : public Serializable
/// Reference to the settings /// Reference to the settings
const Settings& mySettings; const Settings& mySettings;
/// Table of system cycles for each instruction
uInt32 myInstructionSystemCycleTable[256];
/// Indicates if the last memory access was a read or not /// Indicates if the last memory access was a read or not
bool myLastAccessWasRead; bool myLastAccessWasRead;
@ -349,7 +346,7 @@ class M6502 : public Serializable
uInt16 myDataAddressForPoke; uInt16 myDataAddressForPoke;
/// Indicates the number of system cycles per processor cycle /// Indicates the number of system cycles per processor cycle
static const uInt32 SYSTEM_CYCLES_PER_CPU = 1; static constexpr uInt32 SYSTEM_CYCLES_PER_CPU = 1;
#ifdef DEBUGGER_SUPPORT #ifdef DEBUGGER_SUPPORT
/// Pointer to the debugger for this processor or the null pointer /// Pointer to the debugger for this processor or the null pointer
@ -370,13 +367,6 @@ class M6502 : public Serializable
StringList myBreakCondNames; StringList myBreakCondNames;
ExpressionList myBreakConds; ExpressionList myBreakConds;
#endif #endif
private:
/**
Table of instruction processor cycle times. In some cases additional
cycles will be added during the execution of an instruction.
*/
static uInt32 ourInstructionCycleTable[256];
}; };
#endif #endif