6502: Rotate and shift by value, not reference.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-01-14 21:03:29 +00:00
parent 4bd1a1eab1
commit 43573ac699
2 changed files with 61 additions and 53 deletions

View File

@ -372,7 +372,7 @@ namespace EightBit {
case 0b011: case 0b011:
case 0b101: case 0b101:
case 0b111: case 0b111:
setByte(MEMPTR(), value); setByte(value);
break; break;
case 0b000: case 0b000:
case 0b100: case 0b100:
@ -538,39 +538,33 @@ namespace EightBit {
// Operations // Operations
void ASL(int bbb) { void ASL(int bbb) {
auto operand = AM_10(bbb); const auto result = ASL(AM_10(bbb));
ASL(operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void ROL(int bbb) { void ROL(int bbb) {
auto operand = AM_10(bbb); const auto result = ROL(AM_10(bbb));
ROL(operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void LSR(int bbb) { void LSR(int bbb) {
auto operand = AM_10(bbb); const auto result = LSR(AM_10(bbb));
LSR(operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void ROR(int bbb) { void ROR(int bbb) {
auto operand = AM_10(bbb); const auto result = ROR(AM_10(bbb));
ROR(operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void DEC(int bbb) { void DEC(int bbb) {
auto operand = AM_10(bbb); const auto result = DEC(AM_10(bbb));
adjustNZ(--operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void INC(int bbb) { void INC(int bbb) {
auto operand = AM_10(bbb); const auto result = INC(AM_10(bbb));
adjustNZ(++operand); AM_10(bbb, result);
AM_10(bbb, operand);
} }
void DCP(int bbb) { void DCP(int bbb) {
@ -585,15 +579,28 @@ namespace EightBit {
A() = SBC(A(), operand); A() = SBC(A(), operand);
} }
//
uint8_t DEC(uint8_t value) {
const auto result = --value;
adjustNZ(result);
return result;
}
uint8_t INC(uint8_t value) {
const auto result = ++value;
adjustNZ(result);
return result;
}
void ORA(uint8_t value) { void ORA(uint8_t value) {
adjustNZ(A() |= value); adjustNZ(A() |= value);
} }
void SLO(int bbb) { void SLO(int bbb) {
auto operand = AM_01(bbb); const auto result = ASL(AM_01(bbb));
ASL(operand); setByte(result);
setByte(operand); ORA(result);
ORA(operand);
} }
void ANDA(uint8_t value) { void ANDA(uint8_t value) {
@ -601,10 +608,9 @@ namespace EightBit {
} }
void RLA(int bbb) { void RLA(int bbb) {
auto operand = AM_01(bbb); const auto result = ROL(AM_01(bbb));
ROL(operand); setByte(result);
setByte(operand); ANDA(result);
ANDA(operand);
} }
void EORA(uint8_t value) { void EORA(uint8_t value) {
@ -612,28 +618,26 @@ namespace EightBit {
} }
void SRE(int bbb) { void SRE(int bbb) {
auto operand = AM_01(bbb); const auto result = LSR(AM_01(bbb));
LSR(operand); setByte(result);
setByte(operand); EORA(result);
EORA(operand);
} }
void RRA(int bbb) { void RRA(int bbb) {
auto operand = AM_01(bbb); const auto result = ROR(AM_01(bbb));
ROR(operand); setByte(result);
setByte(operand); A() = ADC(A(), result);
A() = ADC(A(), operand);
} }
void ROR(uint8_t& output); uint8_t ROR(uint8_t value);
void LSR(uint8_t& output); uint8_t LSR(uint8_t value);
void BIT(uint8_t data); void BIT(uint8_t data);
void ROL(uint8_t& output); uint8_t ROL(uint8_t value);
void ASL(uint8_t& output); uint8_t ASL(uint8_t value);
void CMP(uint8_t first, uint8_t second); void CMP(uint8_t first, uint8_t second);

View File

@ -474,16 +474,18 @@ uint8_t EightBit::MOS6502::pop() {
//// ////
void EightBit::MOS6502::ROR(uint8_t& output) { uint8_t EightBit::MOS6502::ROR(uint8_t value) {
const auto carry = P() & CF; const auto carry = P() & CF;
setFlag(P(), CF, output & CF); setFlag(P(), CF, value & CF);
output = (output >> 1) | (carry << 7); value = (value >> 1) | (carry << 7);
adjustNZ(output); adjustNZ(value);
return value;
} }
void EightBit::MOS6502::LSR(uint8_t& output) { uint8_t EightBit::MOS6502::LSR(uint8_t value) {
setFlag(P(), CF, output & CF); setFlag(P(), CF, value & CF);
adjustNZ(output >>= 1); adjustNZ(value >>= 1);
return value;
} }
void EightBit::MOS6502::BIT(uint8_t data) { void EightBit::MOS6502::BIT(uint8_t data) {
@ -492,15 +494,17 @@ void EightBit::MOS6502::BIT(uint8_t data) {
setFlag(P(), VF, data & VF); setFlag(P(), VF, data & VF);
} }
void EightBit::MOS6502::ROL(uint8_t& output) { uint8_t EightBit::MOS6502::ROL(uint8_t value) {
const uint8_t result = (output << 1) | (P() & CF); const uint8_t result = (value << 1) | (P() & CF);
setFlag(P(), CF, output & Bit7); setFlag(P(), CF, value & Bit7);
adjustNZ(output = result); adjustNZ(result);
return result;
} }
void EightBit::MOS6502::ASL(uint8_t& output) { uint8_t EightBit::MOS6502::ASL(uint8_t value) {
setFlag(P(), CF, (output & Bit7) >> 7); setFlag(P(), CF, (value & Bit7) >> 7);
adjustNZ(output <<= 1); adjustNZ(value <<= 1);
return value;
} }
uint8_t EightBit::MOS6502::SBC(const uint8_t operand, const uint8_t data) { uint8_t EightBit::MOS6502::SBC(const uint8_t operand, const uint8_t data) {