mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 00:29:47 +00:00
6502: Rotate and shift by value, not reference.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
4bd1a1eab1
commit
43573ac699
@ -372,7 +372,7 @@ namespace EightBit {
|
||||
case 0b011:
|
||||
case 0b101:
|
||||
case 0b111:
|
||||
setByte(MEMPTR(), value);
|
||||
setByte(value);
|
||||
break;
|
||||
case 0b000:
|
||||
case 0b100:
|
||||
@ -538,39 +538,33 @@ namespace EightBit {
|
||||
// Operations
|
||||
|
||||
void ASL(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
ASL(operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = ASL(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void ROL(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
ROL(operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = ROL(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void LSR(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
LSR(operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = LSR(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void ROR(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
ROR(operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = ROR(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void DEC(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
adjustNZ(--operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = DEC(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void INC(int bbb) {
|
||||
auto operand = AM_10(bbb);
|
||||
adjustNZ(++operand);
|
||||
AM_10(bbb, operand);
|
||||
const auto result = INC(AM_10(bbb));
|
||||
AM_10(bbb, result);
|
||||
}
|
||||
|
||||
void DCP(int bbb) {
|
||||
@ -585,15 +579,28 @@ namespace EightBit {
|
||||
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) {
|
||||
adjustNZ(A() |= value);
|
||||
}
|
||||
|
||||
void SLO(int bbb) {
|
||||
auto operand = AM_01(bbb);
|
||||
ASL(operand);
|
||||
setByte(operand);
|
||||
ORA(operand);
|
||||
const auto result = ASL(AM_01(bbb));
|
||||
setByte(result);
|
||||
ORA(result);
|
||||
}
|
||||
|
||||
void ANDA(uint8_t value) {
|
||||
@ -601,10 +608,9 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
void RLA(int bbb) {
|
||||
auto operand = AM_01(bbb);
|
||||
ROL(operand);
|
||||
setByte(operand);
|
||||
ANDA(operand);
|
||||
const auto result = ROL(AM_01(bbb));
|
||||
setByte(result);
|
||||
ANDA(result);
|
||||
}
|
||||
|
||||
void EORA(uint8_t value) {
|
||||
@ -612,28 +618,26 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
void SRE(int bbb) {
|
||||
auto operand = AM_01(bbb);
|
||||
LSR(operand);
|
||||
setByte(operand);
|
||||
EORA(operand);
|
||||
const auto result = LSR(AM_01(bbb));
|
||||
setByte(result);
|
||||
EORA(result);
|
||||
}
|
||||
|
||||
void RRA(int bbb) {
|
||||
auto operand = AM_01(bbb);
|
||||
ROR(operand);
|
||||
setByte(operand);
|
||||
A() = ADC(A(), operand);
|
||||
const auto result = ROR(AM_01(bbb));
|
||||
setByte(result);
|
||||
A() = ADC(A(), result);
|
||||
}
|
||||
|
||||
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 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);
|
||||
|
||||
|
@ -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;
|
||||
setFlag(P(), CF, output & CF);
|
||||
output = (output >> 1) | (carry << 7);
|
||||
adjustNZ(output);
|
||||
setFlag(P(), CF, value & CF);
|
||||
value = (value >> 1) | (carry << 7);
|
||||
adjustNZ(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::LSR(uint8_t& output) {
|
||||
setFlag(P(), CF, output & CF);
|
||||
adjustNZ(output >>= 1);
|
||||
uint8_t EightBit::MOS6502::LSR(uint8_t value) {
|
||||
setFlag(P(), CF, value & CF);
|
||||
adjustNZ(value >>= 1);
|
||||
return value;
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::BIT(uint8_t data) {
|
||||
@ -492,15 +494,17 @@ void EightBit::MOS6502::BIT(uint8_t data) {
|
||||
setFlag(P(), VF, data & VF);
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::ROL(uint8_t& output) {
|
||||
const uint8_t result = (output << 1) | (P() & CF);
|
||||
setFlag(P(), CF, output & Bit7);
|
||||
adjustNZ(output = result);
|
||||
uint8_t EightBit::MOS6502::ROL(uint8_t value) {
|
||||
const uint8_t result = (value << 1) | (P() & CF);
|
||||
setFlag(P(), CF, value & Bit7);
|
||||
adjustNZ(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void EightBit::MOS6502::ASL(uint8_t& output) {
|
||||
setFlag(P(), CF, (output & Bit7) >> 7);
|
||||
adjustNZ(output <<= 1);
|
||||
uint8_t EightBit::MOS6502::ASL(uint8_t value) {
|
||||
setFlag(P(), CF, (value & Bit7) >> 7);
|
||||
adjustNZ(value <<= 1);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t EightBit::MOS6502::SBC(const uint8_t operand, const uint8_t data) {
|
||||
|
Loading…
Reference in New Issue
Block a user