mirror of
https://github.com/FrancescoRigoni/Lib65816.git
synced 2024-12-21 04:29:40 +00:00
Merge pull request #1 from nick-less/master
emulation mode ADC, INC/DEC and ROL fixed
This commit is contained in:
commit
b08bfe7bbc
@ -47,6 +47,17 @@ class Cpu65816 {
|
||||
|
||||
// Temporary
|
||||
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:
|
||||
SystemBus &mSystemBus;
|
||||
@ -92,7 +103,6 @@ class Cpu65816 {
|
||||
Address getAddressOfOpCodeData(OpCode &);
|
||||
bool opCodeAddressingCrossesPageBoundary(OpCode &);
|
||||
|
||||
void setProgramAddress(const Address &);
|
||||
void addToCycles(int);
|
||||
void subtractFromCycles(int);
|
||||
void addToProgramAddress(int);
|
||||
|
@ -34,6 +34,40 @@ Cpu65816::Cpu65816(SystemBus &systemBus, EmulationModeInterrupts *emulationInter
|
||||
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.
|
||||
* */
|
||||
|
@ -157,11 +157,11 @@ void Cpu65816Debugger::logOpCode(OpCode &opCode) const {
|
||||
log.str(" [Direct Page Indirect Long]");
|
||||
break;
|
||||
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]");
|
||||
break;
|
||||
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]");
|
||||
break;
|
||||
case AddressingMode::DirectPageIndirectLongIndexedWithY:
|
||||
|
@ -135,137 +135,136 @@ void Cpu65816::executeADC(OpCode &opCode) {
|
||||
#endif
|
||||
|
||||
switch (opCode.getCode()) {
|
||||
switch (opCode.getCode()) {
|
||||
case (0x69): // ADC Immediate
|
||||
{
|
||||
if (accumulatorIs16BitWide()) {
|
||||
addToProgramAddress(1);
|
||||
}
|
||||
addToProgramAddress(2);
|
||||
addToCycles(2);
|
||||
break;
|
||||
case (0x69): // ADC Immediate
|
||||
{
|
||||
if (accumulatorIs16BitWide()) {
|
||||
addToProgramAddress(1);
|
||||
}
|
||||
case (0x6D): // ADC Absolute
|
||||
{
|
||||
addToProgramAddress(3);
|
||||
addToCycles(4);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(2);
|
||||
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);
|
||||
addToCycles(3);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(3);
|
||||
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);
|
||||
addToCycles(5);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(5);
|
||||
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);
|
||||
addToCycles(6);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(6);
|
||||
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);
|
||||
addToCycles(4);
|
||||
break;
|
||||
addToProgramAddress(3);
|
||||
addToCycles(4);
|
||||
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(4);
|
||||
addToCycles(5);
|
||||
break;
|
||||
addToProgramAddress(3);
|
||||
addToCycles(4);
|
||||
break;
|
||||
}
|
||||
case (0x75): // ADC Direct Page Indexed, X
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
case (0x79): // ADC Absolute Indexed Y
|
||||
{
|
||||
if (opCodeAddressingCrossesPageBoundary(opCode)) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddress(3);
|
||||
addToCycles(4);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(4);
|
||||
break;
|
||||
}
|
||||
case (0x61): // ADC Direct Page Indexed Indirect, X
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
case (0x75): // ADC Direct Page Indexed, X
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddress(2);
|
||||
addToCycles(4);
|
||||
break;
|
||||
addToProgramAddress(2);
|
||||
addToCycles(6);
|
||||
break;
|
||||
}
|
||||
case (0x71): // ADC Direct Page Indirect Indexed, Y
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
case (0x61): // ADC Direct Page Indexed Indirect, X
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddress(2);
|
||||
addToCycles(6);
|
||||
break;
|
||||
if (opCodeAddressingCrossesPageBoundary(opCode)) {
|
||||
addToCycles(1);
|
||||
}
|
||||
case (0x71): // ADC Direct Page Indirect Indexed, Y
|
||||
{
|
||||
if (Binary::lower8BitsOf(mD) != 0) {
|
||||
addToCycles(1);
|
||||
}
|
||||
if (opCodeAddressingCrossesPageBoundary(opCode)) {
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA);
|
||||
}
|
||||
addToProgramAddressAndCycles(1, 2);
|
||||
break;
|
||||
}
|
||||
case(0xEE): // INC Absolute
|
||||
{
|
||||
@ -81,6 +82,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(2);
|
||||
}
|
||||
addToProgramAddressAndCycles(3, 6);
|
||||
break;
|
||||
}
|
||||
case(0xE6): // INC Direct Page
|
||||
{
|
||||
@ -94,6 +96,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddressAndCycles(2, 5);
|
||||
break;
|
||||
}
|
||||
case(0xFE): // INC Absolute Indexed, X
|
||||
{
|
||||
@ -110,6 +113,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
#endif
|
||||
addToProgramAddressAndCycles(3, 7);
|
||||
}
|
||||
break;
|
||||
case(0xF6): // INC Direct Page Indexed, X
|
||||
{
|
||||
if (accumulatorIs8BitWide()) {
|
||||
@ -122,6 +126,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddressAndCycles(2, 6);
|
||||
break;
|
||||
}
|
||||
case(0x3A): // DEC Accumulator
|
||||
{
|
||||
@ -135,6 +140,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(mA);
|
||||
}
|
||||
addToProgramAddressAndCycles(1, 2);
|
||||
break;
|
||||
}
|
||||
case(0xCE): // DEC Absolute
|
||||
{
|
||||
@ -145,6 +151,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(2);
|
||||
}
|
||||
addToProgramAddressAndCycles(3, 6);
|
||||
break;
|
||||
}
|
||||
case(0xC6): // DEC Direct Page
|
||||
{
|
||||
@ -158,6 +165,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddressAndCycles(2, 5);
|
||||
break;
|
||||
}
|
||||
case(0xDE): // DEC Absolute Indexed, X
|
||||
{
|
||||
@ -173,6 +181,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
}
|
||||
#endif
|
||||
addToProgramAddressAndCycles(3, 7);
|
||||
break;
|
||||
}
|
||||
case(0xD6): // DEC Direct Page Indexed, X
|
||||
{
|
||||
@ -186,6 +195,7 @@ void Cpu65816::executeINCDEC(OpCode &opCode) {
|
||||
addToCycles(1);
|
||||
}
|
||||
addToProgramAddressAndCycles(2, 6);
|
||||
break;
|
||||
}
|
||||
case(0xC8): // INY
|
||||
{
|
||||
|
@ -29,7 +29,7 @@
|
||||
else Binary::clearBitIn8BitValue(&value, 0); \
|
||||
if (carryWillBeSet) mCpuStatus.setCarryFlag(); \
|
||||
else mCpuStatus.clearCarryFlag(); \
|
||||
mCpuStatus.updateSignAndZeroFlagFrom16BitValue(value); \
|
||||
mCpuStatus.updateSignAndZeroFlagFrom8BitValue(value); \
|
||||
}
|
||||
|
||||
#define DO_ROL_16_BIT(value) { \
|
||||
|
Loading…
Reference in New Issue
Block a user