From 45d1fe605f0f06860750fea2b8ee432a23cf2e89 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 3 Aug 2019 11:39:17 +0100 Subject: [PATCH] Mild refactoring of the keyboard IO to make the C++ and C# versions as close as possible. Signed-off-by: Adrian Conlon --- LR35902/src/IoRegisters.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/LR35902/src/IoRegisters.cpp b/LR35902/src/IoRegisters.cpp index 5b1cefd..fbf97ef 100644 --- a/LR35902/src/IoRegisters.cpp +++ b/LR35902/src/IoRegisters.cpp @@ -32,20 +32,17 @@ void EightBit::GameBoy::IoRegisters::Bus_ReadingByte(EightBit::EventArgs) { // Port/Mode Registers case P1: { - auto p14 = m_scanP14 && !m_p14; - auto p15 = m_scanP15 && !m_p15; - auto live = p14 || p15; - auto p10 = live && !m_p10; - auto p11 = live && !m_p11; - auto p12 = live && !m_p12; - auto p13 = live && !m_p13; - poke(port, - ((int)!p10) - | ((int)!p11 << 1) - | ((int)!p12 << 2) - | ((int)!p13 << 3) - | Chip::Bit4 | Chip::Bit5 - | Chip::Bit6 | Chip::Bit7); + auto directionKeys = m_scanP14 && !m_p14; + auto miscKeys = m_scanP15 && !m_p15; + auto live = directionKeys || miscKeys; + auto rightOrA = live && !m_p10; + auto leftOrB = live && !m_p11; + auto upOrSelect = live && !m_p12; + auto downOrStart = live && !m_p13; + auto lowNibble = ((int)!rightOrA) | ((int)!leftOrB << 1) | ((int)!upOrSelect << 2) | ((int)!downOrStart << 3); + auto highNibble = Chip::promoteNibble(Chip::Mask4); + auto value = lowNibble | highNibble; + poke(port, lowNibble | highNibble); } break; case SB: