Implementing a SBC without decimal mode

This commit is contained in:
Anonymus Raccoon
2020-02-27 23:37:52 +01:00
parent a421ef693f
commit 4394c7625e
7 changed files with 157 additions and 4 deletions
@@ -29,6 +29,21 @@ namespace ComSquare::CPU
void CPU::SBC(uint24_t valueAddr)
{
unsigned negativeMask = this->_isEmulationMode ? 0x80u : 0x8000u;
unsigned value = this->_bus->read(valueAddr);
if (this->_registers.p.m)
value += this->_bus->read(valueAddr + 1) << 8u;
bool oldCarry = this->_registers.p.c;
this->_registers.p.c = this->_registers.a >= value;
if ((this->_registers.a & negativeMask) == (value & negativeMask))
this->_registers.p.v = (this->_registers.a & negativeMask) != ((this->_registers.a + value) & negativeMask);
else
this->_registers.p.v = false;
this->_registers.a += ~value + oldCarry;
if (this->_isEmulationMode)
this->_registers.a %= 0x100;
this->_registers.p.z = this->_registers.a == 0;
this->_registers.p.n = this->_registers.a & negativeMask;
}
}