Merge pull request #1 from nick-less/master

emulation mode ADC, INC/DEC and ROL fixed
This commit is contained in:
Francesco Rigoni 2018-12-19 20:47:59 +01:00 committed by GitHub
commit b08bfe7bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 173 additions and 120 deletions

View File

@ -47,6 +47,17 @@ class Cpu65816 {
// Temporary // Temporary
bool executeNextInstruction(); bool executeNextInstruction();
void setXL(uint8_t x);
void setYL(uint8_t y);
void setX(uint16_t x);
void setY(uint16_t y);
void setA(uint16_t a);
uint16_t getA();
Address getProgramAddress();
void setProgramAddress(const Address &);
Stack *getStack();
CpuStatus *getCpuStatus();
private: private:
SystemBus &mSystemBus; SystemBus &mSystemBus;
@ -92,7 +103,6 @@ class Cpu65816 {
Address getAddressOfOpCodeData(OpCode &); Address getAddressOfOpCodeData(OpCode &);
bool opCodeAddressingCrossesPageBoundary(OpCode &); bool opCodeAddressingCrossesPageBoundary(OpCode &);
void setProgramAddress(const Address &);
void addToCycles(int); void addToCycles(int);
void subtractFromCycles(int); void subtractFromCycles(int);
void addToProgramAddress(int); void addToProgramAddress(int);

View File

@ -34,6 +34,40 @@ Cpu65816::Cpu65816(SystemBus &systemBus, EmulationModeInterrupts *emulationInter
mStack(&mSystemBus) { mStack(&mSystemBus) {
} }
void Cpu65816::setXL(uint8_t x) {
mX = x;
}
void Cpu65816::setYL(uint8_t y) {
mY = y;
}
void Cpu65816::setX(uint16_t x) {
mX = x;
}
void Cpu65816::setY(uint16_t y) {
mY = y;
}
void Cpu65816::setA(uint16_t a) {
mA = a;
}
uint16_t Cpu65816::getA() {
return mA;
}
Address Cpu65816::getProgramAddress() {
return mProgramAddress;
}
Stack *Cpu65816::getStack() {
return &mStack;
}
CpuStatus *Cpu65816::getCpuStatus() {
return &mCpuStatus;
}
/** /**
* Resets the cpu to its initial state. * Resets the cpu to its initial state.
* */ * */

View File

@ -157,11 +157,11 @@ void Cpu65816Debugger::logOpCode(OpCode &opCode) const {
log.str(" [Direct Page Indirect Long]"); log.str(" [Direct Page Indirect Long]");
break; break;
case AddressingMode::DirectPageIndexedIndirectWithX: case AddressingMode::DirectPageIndexedIndirectWithX:
log.str("(").hex(mCpu.mSystemBus.readByte(mCpu.getAddressOfOpCodeData(opCode)), 2).str(", X)").sp(); log.str("(").hex(mCpu.mSystemBus.readByte(Address(mCpu.mProgramAddress.getBank(),mCpu.mProgramAddress.getOffset()+1)), 2).str(", X)").sp();
log.str(" [Direct Page Indexed Indirect, X]"); log.str(" [Direct Page Indexed Indirect, X]");
break; break;
case AddressingMode::DirectPageIndirectIndexedWithY: case AddressingMode::DirectPageIndirectIndexedWithY:
log.str("(").hex(mCpu.mSystemBus.readByte(mCpu.getAddressOfOpCodeData(opCode)), 2).str("), Y").sp(); log.str("(").hex(mCpu.mSystemBus.readByte(Address(mCpu.mProgramAddress.getBank(),mCpu.mProgramAddress.getOffset()+1)), 2).str("), Y").sp();
log.str(" [Direct Page Indirect Indexed, Y]"); log.str(" [Direct Page Indirect Indexed, Y]");
break; break;
case AddressingMode::DirectPageIndirectLongIndexedWithY: case AddressingMode::DirectPageIndirectLongIndexedWithY:

View File

@ -135,137 +135,136 @@ void Cpu65816::executeADC(OpCode &opCode) {
#endif #endif
switch (opCode.getCode()) { switch (opCode.getCode()) {
switch (opCode.getCode()) { case (0x69): // ADC Immediate
case (0x69): // ADC Immediate {
{ if (accumulatorIs16BitWide()) {
if (accumulatorIs16BitWide()) { addToProgramAddress(1);
addToProgramAddress(1);
}
addToProgramAddress(2);
addToCycles(2);
break;
} }
case (0x6D): // ADC Absolute addToProgramAddress(2);
{ addToCycles(2);
addToProgramAddress(3); break;
addToCycles(4); }
break; case (0x6D): // ADC Absolute
{
addToProgramAddress(3);
addToCycles(4);
break;
}
case (0x6F): // ADC Absolute Long
{
addToProgramAddress(4);
addToCycles(5);
break;
}
case (0x65): // ADC Direct Page
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
} }
case (0x6F): // ADC Absolute Long
{
addToProgramAddress(4);
addToCycles(5);
break;
}
case (0x65): // ADC Direct Page
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
}
addToProgramAddress(2); addToProgramAddress(2);
addToCycles(3); addToCycles(3);
break; break;
}
case (0x72): // ADC Direct Page Indirect
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
} }
case (0x72): // ADC Direct Page Indirect
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
}
addToProgramAddress(2); addToProgramAddress(2);
addToCycles(5); addToCycles(5);
break; break;
}
case (0x67): // ADC Direct Page Indirect Long
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
} }
case (0x67): // ADC Direct Page Indirect Long
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
}
addToProgramAddress(2); addToProgramAddress(2);
addToCycles(6); addToCycles(6);
break; break;
}
case (0x7D): // ADC Absolute Indexed, X
{
if (opCodeAddressingCrossesPageBoundary(opCode)) {
addToCycles(1);
} }
case (0x7D): // ADC Absolute Indexed, X
{
if (opCodeAddressingCrossesPageBoundary(opCode)) {
addToCycles(1);
}
addToProgramAddress(3); addToProgramAddress(3);
addToCycles(4); addToCycles(4);
break; break;
}
case (0x7F): // ADC Absolute Long Indexed, X
{
addToProgramAddress(4);
addToCycles(5);
break;
}
case (0x79): // ADC Absolute Indexed Y
{
if (opCodeAddressingCrossesPageBoundary(opCode)) {
addToCycles(1);
} }
case (0x7F): // ADC Absolute Long Indexed, X addToProgramAddress(3);
{ addToCycles(4);
addToProgramAddress(4); break;
addToCycles(5); }
break; case (0x75): // ADC Direct Page Indexed, X
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
} }
case (0x79): // ADC Absolute Indexed Y addToProgramAddress(2);
{ addToCycles(4);
if (opCodeAddressingCrossesPageBoundary(opCode)) { break;
addToCycles(1); }
} case (0x61): // ADC Direct Page Indexed Indirect, X
addToProgramAddress(3); {
addToCycles(4); if (Binary::lower8BitsOf(mD) != 0) {
break; addToCycles(1);
} }
case (0x75): // ADC Direct Page Indexed, X addToProgramAddress(2);
{ addToCycles(6);
if (Binary::lower8BitsOf(mD) != 0) { break;
addToCycles(1); }
} case (0x71): // ADC Direct Page Indirect Indexed, Y
addToProgramAddress(2); {
addToCycles(4); if (Binary::lower8BitsOf(mD) != 0) {
break; addToCycles(1);
} }
case (0x61): // ADC Direct Page Indexed Indirect, X if (opCodeAddressingCrossesPageBoundary(opCode)) {
{ addToCycles(1);
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
}
addToProgramAddress(2);
addToCycles(6);
break;
} }
case (0x71): // ADC Direct Page Indirect Indexed, Y addToProgramAddress(2);
{ addToCycles(5);
if (Binary::lower8BitsOf(mD) != 0) { break;
addToCycles(1); }
} case (0x77): // ADC Direct Page Indirect Long Indexed, Y
if (opCodeAddressingCrossesPageBoundary(opCode)) { {
addToCycles(1); if (Binary::lower8BitsOf(mD) != 0) {
} addToCycles(1);
addToProgramAddress(2);
addToCycles(5);
break;
}
case (0x77): // ADC Direct Page Indirect Long Indexed, Y
{
if (Binary::lower8BitsOf(mD) != 0) {
addToCycles(1);
}
addToProgramAddress(2);
addToCycles(6);
break;
}
case (0x63): // ADC Stack Relative
{
addToProgramAddress(2);
addToCycles(4);
break;
}
case (0x73): // ADC Stack Relative Indirect Indexed, Y
{
addToProgramAddress(2);
addToCycles(7);
break;
}
default: {
LOG_UNEXPECTED_OPCODE(opCode);
} }
addToProgramAddress(2);
addToCycles(6);
break;
}
case (0x63): // ADC Stack Relative
{
addToProgramAddress(2);
addToCycles(4);
break;
}
case (0x73): // ADC Stack Relative Indirect Indexed, Y
{
addToProgramAddress(2);
addToCycles(7);
break;
}
default: {
LOG_UNEXPECTED_OPCODE(opCode);
} }
} }
} }

View File

@ -71,6 +71,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA); mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA);
} }
addToProgramAddressAndCycles(1, 2); addToProgramAddressAndCycles(1, 2);
break;
} }
case(0xEE): // INC Absolute case(0xEE): // INC Absolute
{ {
@ -81,6 +82,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(2); addToCycles(2);
} }
addToProgramAddressAndCycles(3, 6); addToProgramAddressAndCycles(3, 6);
break;
} }
case(0xE6): // INC Direct Page case(0xE6): // INC Direct Page
{ {
@ -94,6 +96,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(1); addToCycles(1);
} }
addToProgramAddressAndCycles(2, 5); addToProgramAddressAndCycles(2, 5);
break;
} }
case(0xFE): // INC Absolute Indexed, X case(0xFE): // INC Absolute Indexed, X
{ {
@ -110,6 +113,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
#endif #endif
addToProgramAddressAndCycles(3, 7); addToProgramAddressAndCycles(3, 7);
} }
break;
case(0xF6): // INC Direct Page Indexed, X case(0xF6): // INC Direct Page Indexed, X
{ {
if (accumulatorIs8BitWide()) { if (accumulatorIs8BitWide()) {
@ -122,6 +126,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(1); addToCycles(1);
} }
addToProgramAddressAndCycles(2, 6); addToProgramAddressAndCycles(2, 6);
break;
} }
case(0x3A): // DEC Accumulator case(0x3A): // DEC Accumulator
{ {
@ -135,6 +140,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA); mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA);
} }
addToProgramAddressAndCycles(1, 2); addToProgramAddressAndCycles(1, 2);
break;
} }
case(0xCE): // DEC Absolute case(0xCE): // DEC Absolute
{ {
@ -145,6 +151,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(2); addToCycles(2);
} }
addToProgramAddressAndCycles(3, 6); addToProgramAddressAndCycles(3, 6);
break;
} }
case(0xC6): // DEC Direct Page case(0xC6): // DEC Direct Page
{ {
@ -158,6 +165,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(1); addToCycles(1);
} }
addToProgramAddressAndCycles(2, 5); addToProgramAddressAndCycles(2, 5);
break;
} }
case(0xDE): // DEC Absolute Indexed, X case(0xDE): // DEC Absolute Indexed, X
{ {
@ -173,6 +181,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
} }
#endif #endif
addToProgramAddressAndCycles(3, 7); addToProgramAddressAndCycles(3, 7);
break;
} }
case(0xD6): // DEC Direct Page Indexed, X case(0xD6): // DEC Direct Page Indexed, X
{ {
@ -186,6 +195,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
addToCycles(1); addToCycles(1);
} }
addToProgramAddressAndCycles(2, 6); addToProgramAddressAndCycles(2, 6);
break;
} }
case(0xC8): // INY case(0xC8): // INY
{ {

View File

@ -29,7 +29,7 @@
else Binary::clearBitIn8BitValue(&value, 0); \ else Binary::clearBitIn8BitValue(&value, 0); \
if (carryWillBeSet) mCpuStatus.setCarryFlag(); \ if (carryWillBeSet) mCpuStatus.setCarryFlag(); \
else mCpuStatus.clearCarryFlag(); \ else mCpuStatus.clearCarryFlag(); \
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(value); \ mCpuStatus.updateSignAndZeroFlagFrom8BitValue(value); \
} }
#define DO_ROL_16_BIT(value) { \ #define DO_ROL_16_BIT(value) { \