Adding 8-bit Shift Rotation Operations

This commit is contained in:
Melefo
2020-02-25 20:42:33 +01:00
parent 9928eb721d
commit 5033b949f9
5 changed files with 241 additions and 7 deletions
@@ -0,0 +1,76 @@
//
// Created by Melefo on 25/02/2020.
//
#include "../APU.hpp"
namespace ComSquare::APU
{
int APU::ASL(uint24_t operand, int cycles, bool accumulator)
{
uint8_t value = accumulator ? operand : this->_internalRead(operand);
this->_internalRegisters.c = value & 0x80u;
value <<= 1u;
if (accumulator)
this->_internalRegisters.a = value;
else
this->_internalWrite(operand, value);
this->_internalRegisters.n = value & 0x80u;
this->_internalRegisters.z = !value;
return cycles;
}
int APU::LSR(uint24_t operand, int cycles, bool accumulator)
{
uint8_t value = accumulator ? operand : this->_internalRead(operand);
this->_internalRegisters.c = value & 0x01u;
value >>= 1u;
if (accumulator)
this->_internalRegisters.a = value;
else
this->_internalWrite(operand, value);
this->_internalRegisters.n = value & 0x01u;
this->_internalRegisters.z = !value;
return cycles;
}
int APU::ROL(uint24_t operand, int cycles, bool accumulator)
{
uint8_t value = accumulator ? operand : this->_internalRead(operand);
uint8_t result = (value << 1u) + this->_internalRegisters.c;
this->_internalRegisters.c = value & 0x80u;
if (accumulator)
this->_internalRegisters.a = result;
else
this->_internalWrite(operand, result);
this->_internalRegisters.n = result & 0x80u;
this->_internalRegisters.z = !result;
return cycles;
}
int APU::ROR(uint24_t operand, int cycles, bool accumulator)
{
uint8_t value = accumulator ? operand : this->_internalRead(operand);
uint8_t result = (value >> 1u) + this->_internalRegisters.c;
this->_internalRegisters.c = value & 0x01u;
if (accumulator)
this->_internalRegisters.a = result;
else
this->_internalWrite(operand, result);
this->_internalRegisters.n = result & 0x01u;
this->_internalRegisters.z = !result;
return cycles;
}
int APU::XCN()
{
this->_internalRegisters.a = (this->_internalRegisters.a >> 4u) | (this->_internalRegisters.a << 4u);
this->_internalRegisters.n = this->_internalRegisters.a & 0x80u;
this->_internalRegisters.z = !this->_internalRegisters.a;
return 5;
}
}