From 116f9961c4ddf54eb3707f0595c585881d32ee68 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 25 May 2018 22:36:10 +0100 Subject: [PATCH] Add a higher/lower nibble mask Signed-off-by: Adrian Conlon --- LR35902/inc/LR35902.h | 2 +- Z80/src/Z80.cpp | 12 ++++++------ inc/Processor.h | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 9a70ab6..ca42282 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -31,7 +31,7 @@ namespace EightBit { } virtual register16_t& AF() final { - af.low &= 0xf0; + af.low = higherNibble(af.low); return af; } diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index b58603a..4dd9d37 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -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(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(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); diff --git a/inc/Processor.h b/inc/Processor.h index 3b8dc53..053a249 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -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); }