mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-30 09:08:43 +00:00
Implementing ROR
This commit is contained in:
@@ -176,4 +176,46 @@ namespace ComSquare::CPU
|
||||
}
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int CPU::ROR(uint24_t valueAddr, AddressingMode mode)
|
||||
{
|
||||
this->_registers.p.n = false;
|
||||
bool oldCarry = this->_registers.p.c;
|
||||
unsigned highByteIndex = this->_registers.p.m ? 7 : 15;
|
||||
|
||||
if (mode == Implied) {
|
||||
this->_registers.p.c = this->_registers.a & 1u;
|
||||
this->_registers.a >>= 1u;
|
||||
this->_registers.a |= oldCarry << highByteIndex;
|
||||
this->_registers.p.z = this->_registers.a == 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t value = this->_bus->read(valueAddr);
|
||||
if (!this->_registers.p.m)
|
||||
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||
|
||||
this->_registers.p.c = value & 1u;
|
||||
value >>= 1u;
|
||||
value |= oldCarry << highByteIndex;
|
||||
this->_registers.p.z = value == 0;
|
||||
|
||||
this->_bus->write(valueAddr, value);
|
||||
if (!this->_registers.p.m)
|
||||
this->_bus->write(valueAddr + 1, value >> 8u);
|
||||
|
||||
int cycles = 2 * !this->_registers.p.m;
|
||||
switch (mode) {
|
||||
case DirectPage:
|
||||
case DirectPageIndexedByX:
|
||||
cycles += this->_registers.dl != 0;
|
||||
break;
|
||||
case AbsoluteIndexedByX:
|
||||
cycles += this->_hasIndexCrossedPageBoundary;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return cycles;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user