Add a higher/lower nibble mask

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-05-25 22:36:10 +01:00
parent ae177b9b92
commit 116f9961c4
3 changed files with 10 additions and 7 deletions

View File

@ -31,7 +31,7 @@ namespace EightBit {
}
virtual register16_t& AF() final {
af.low &= 0xf0;
af.low = higherNibble(af.low);
return af;
}

View File

@ -602,7 +602,7 @@ void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) {
++MEMPTR().word;
const auto memory = BUS().read();
BUS().write(promoteNibble(a) | highNibble(memory));
a = (a & 0xf0) | lowNibble(memory);
a = higherNibble(a) | lowerNibble(memory);
adjustSZPXY<Z80>(f, a);
clearFlag(f, NF | HC);
}
@ -612,7 +612,7 @@ void EightBit::Z80::rld(uint8_t& a, uint8_t& f) {
++MEMPTR().word;
const auto memory = BUS().read();
BUS().write(promoteNibble(memory) | lowNibble(a));
a = (a & 0xf0) | highNibble(memory);
a = higherNibble(a) | highNibble(memory);
adjustSZPXY<Z80>(f, a);
clearFlag(f, NF | HC);
}
@ -709,16 +709,16 @@ int EightBit::Z80::execute(const uint8_t opcode) {
auto& a = af.high;
auto& f = af.low;
auto prefixed = m_prefixCB || m_prefixED;
if (UNLIKELY(prefixed)) {
const auto prefixed = m_prefixCB || m_prefixED;
if (LIKELY(!prefixed)) {
executeOther(a, f, x, y, z, p, q);
} else {
if (m_prefixCB)
executeCB(a, f, x, y, z);
else if (m_prefixED)
executeED(a, f, x, y, z, p, q);
else
UNREACHABLE;
} else {
executeOther(a, f, x, y, z, p, q);
}
ASSUME(cycles() > 0);

View File

@ -61,6 +61,9 @@ namespace EightBit {
static int highNibble(const int value) { return value >> 4; }
static int lowNibble(const int value) { return value & Mask4; }
static int higherNibble(const int value) { return value & 0xf0; }
static int lowerNibble(const int value) { return lowNibble(value); }
static int promoteNibble(const int value) { return value << 4; }
static int demoteNibble(const int value) { return highNibble(value); }