From db8ad5ad5be24ca8e59016da70b4bea7bad5779f Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 3 Aug 2019 11:34:12 +0100 Subject: [PATCH 1/2] First stab at getting the GbNet keyboard working properly. Better, but not perfect... Signed-off-by: Adrian Conlon --- LR35902/IoRegisters.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/LR35902/IoRegisters.cs b/LR35902/IoRegisters.cs index b0f2ad9..8c06b1f 100644 --- a/LR35902/IoRegisters.cs +++ b/LR35902/IoRegisters.cs @@ -335,16 +335,17 @@ namespace EightBit.GameBoy // Port/Mode Registers case P1: { - var p14 = this.scanP14 && !this.p14; - var p15 = this.scanP15 && !this.p15; - var live = p14 || p15; - var p10 = live && this.p10 ? 1 : 0; - var p11 = live && this.p11 ? 1 : 0; - var p12 = live && this.p12 ? 1 : 0; - var p13 = live && this.p13 ? 1 : 0; - this.Poke( - port, - (byte)(p10 | (p11 << 1) | (p12 << 2) | (p13 << 3) | (int)(Bits.Bit4 | Bits.Bit5 | Bits.Bit6 | Bits.Bit7))); + var directionKeys = this.scanP14 && !this.p14; + var miscKeys = this.scanP15 && !this.p15; + var live = directionKeys || miscKeys; + var rightOrA = live && this.p10 ? 0 : 1; + var leftOrB = live && this.p11 ? 0 : 1; + var upOrSelect = live && this.p12 ? 0 : 1; + var downOrStart = live && this.p13 ? 0 : 1; + var lowNibble = (byte)(rightOrA | (leftOrB << 1) | (upOrSelect << 2) | (downOrStart << 3)); + var highNibble = (byte)Chip.PromoteNibble((byte)Mask.Mask4); + var value = (byte)(lowNibble | highNibble); + this.Poke(port, value); } break; From cd80935470ad2b3f57b111080abcb8e732a0e56f Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 3 Aug 2019 17:47:06 +0100 Subject: [PATCH 2/2] Finally, a working keyboard scanner for GbNet Signed-off-by: Adrian Conlon --- LR35902/IoRegisters.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LR35902/IoRegisters.cs b/LR35902/IoRegisters.cs index 8c06b1f..3a69bef 100644 --- a/LR35902/IoRegisters.cs +++ b/LR35902/IoRegisters.cs @@ -338,11 +338,11 @@ namespace EightBit.GameBoy var directionKeys = this.scanP14 && !this.p14; var miscKeys = this.scanP15 && !this.p15; var live = directionKeys || miscKeys; - var rightOrA = live && this.p10 ? 0 : 1; - var leftOrB = live && this.p11 ? 0 : 1; - var upOrSelect = live && this.p12 ? 0 : 1; - var downOrStart = live && this.p13 ? 0 : 1; - var lowNibble = (byte)(rightOrA | (leftOrB << 1) | (upOrSelect << 2) | (downOrStart << 3)); + var rightOrA = (live && !this.p10) ? 0 : Bits.Bit0; + var leftOrB = (live && !this.p11) ? 0 : Bits.Bit1; + var upOrSelect = (live && !this.p12) ? 0 : Bits.Bit2; + var downOrStart = (live && !this.p13) ? 0 : Bits.Bit3; + var lowNibble = (byte)(rightOrA | leftOrB | upOrSelect | downOrStart); var highNibble = (byte)Chip.PromoteNibble((byte)Mask.Mask4); var value = (byte)(lowNibble | highNibble); this.Poke(port, value);