in atari_py/ale_interface/src/emucore/m6502/src/M6502Hi.cxx [98:207]
bool M6502High::execute(uInt32 number)
{
// Clear all of the execution status bits except for the fatal error bit
myExecutionStatus &= FatalErrorBit;
// Loop until execution is stopped or a fatal error occurs
for(;;)
{
for(; !myExecutionStatus && (number != 0); --number)
{
uInt16 operandAddress = 0;
uInt8 operand = 0;
#ifdef DEBUGGER_SUPPORT
if(myJustHitTrapFlag)
{
if(myDebugger->start(myHitTrapInfo.message, myHitTrapInfo.address))
{
myJustHitTrapFlag = false;
return true;
}
}
if(myBreakPoints != NULL)
{
if(myBreakPoints->isSet(PC))
{
if(myDebugger->start("Breakpoint hit: ", PC))
return true;
}
}
int cond = evalCondBreaks();
if(cond > -1)
{
string buf = "CBP: " + myBreakCondNames[cond];
if(myDebugger->start(buf))
return true;
}
#endif
#ifdef DEBUG
debugStream << "PC=" << hex << setw(4) << PC << " ";
#endif
// Fetch instruction at the program counter
IR = peek(PC++);
#ifdef DEBUG
debugStream << "IR=" << hex << setw(2) << (int)IR << " ";
debugStream << "<" << ourAddressingModeTable[IR] << " ";
#endif
// Call code to execute the instruction
switch(IR)
{
// 6502 instruction emulation is generated by an M4 macro file
#include "M6502Hi.ins"
default:
// Oops, illegal instruction executed so set fatal error flag
myExecutionStatus |= FatalErrorBit;
}
myTotalInstructionCount++;
#ifdef DEBUG
debugStream << hex << setw(4) << operandAddress << " ";
debugStream << setw(4) << ourInstructionMnemonicTable[IR];
debugStream << "> ";
debugStream << "A=" << ::hex << setw(2) << (int)A << " ";
debugStream << "X=" << ::hex << setw(2) << (int)X << " ";
debugStream << "Y=" << ::hex << setw(2) << (int)Y << " ";
debugStream << "PS=" << ::hex << setw(2) << (int)PS() << " ";
debugStream << "SP=" << ::hex << setw(2) << (int)SP << " ";
debugStream << "Cyc=" << dec << mySystem->cycles();
debugStream << endl;
#endif
}
// See if we need to handle an interrupt
if((myExecutionStatus & MaskableInterruptBit) ||
(myExecutionStatus & NonmaskableInterruptBit))
{
// Yes, so handle the interrupt
interruptHandler();
}
// See if execution has been stopped
if(myExecutionStatus & StopExecutionBit)
{
// Yes, so answer that everything finished fine
return true;
}
// See if a fatal error has occured
if(myExecutionStatus & FatalErrorBit)
{
// Yes, so answer that something when wrong
return false;
}
// See if we've executed the specified number of instructions
if(number == 0)
{
// Yes, so answer that everything finished fine
return true;
}
}
}