mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-06 19:32:18 +00:00
Adding 8-bit Shift Rotation Operations
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user