From fb8fd2ae900922f600c58aff3d817c8c259f6b24 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Fri, 1 Dec 2017 15:34:47 +0000 Subject: [PATCH] Fixed input detection --- .../Machine/SpectrumBase.Port.cs | 56 ++++++++----------- .../Machine/ZXSpectrum48K/ZX48.Keyboard.cs | 12 +--- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs index d42f7301f9..b5d0b8bdee 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Port.cs @@ -30,8 +30,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // Technically the ULA should respond to every even I/O address bool lowBitReset = (port & 0x0001) == 0; - ContendPort((ushort)port); - + ContendPort((ushort)port); // Kempston Joystick if (port == 0x1f) @@ -48,27 +47,31 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum 0xfdfe A, S, D, F, G 0xdffe P, O, I, U, Y 0xfbfe Q, W, E, R, T 0xbffe ENTER, L, K, J, H 0xf7fe 1, 2, 3, 4, 5 0x7ffe SPACE, SYM SHFT, M, N, B - */ + */ - result &= KeyboardDevice.GetLineStatus((byte)(port >> 8)); - /* - if (high == 0xfe) - result &= KeyboardDevice.KeyLine[0]; - if (high == 0xfd) - result &= KeyboardDevice.KeyLine[1]; - if (high == 0xfb) - result &= KeyboardDevice.KeyLine[2]; - if (high == 0xf7) - result &= KeyboardDevice.KeyLine[3]; - if (high == 0xef) - result &= KeyboardDevice.KeyLine[4]; - if (high == 0xdf) - result &= KeyboardDevice.KeyLine[5]; - if (high == 0xbf) - result &= KeyboardDevice.KeyLine[6]; - if (high == 0x7f) + if ((port & 0x8000) == 0) result &= KeyboardDevice.KeyLine[7]; -*/ + + if ((port & 0x4000) == 0) + result &= KeyboardDevice.KeyLine[6]; + + if ((port & 0x2000) == 0) + result &= KeyboardDevice.KeyLine[5]; + + if ((port & 0x1000) == 0) + result &= KeyboardDevice.KeyLine[4]; + + if ((port & 0x800) == 0) + result &= KeyboardDevice.KeyLine[3]; + + if ((port & 0x400) == 0) + result &= KeyboardDevice.KeyLine[2]; + + if ((port & 0x200) == 0) + result &= KeyboardDevice.KeyLine[1]; + + if ((port & 0x100) == 0) + result &= KeyboardDevice.KeyLine[0]; result = result & 0x1f; //mask out lower 4 bits result = result | 0xa0; //set bit 5 & 7 to 1 @@ -110,17 +113,6 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } } } - /* - // read keyboard input - if (high != 0) - result &= KeyboardDevice.GetLineStatus((byte)high); - - var ear = TapeDevice.GetEarBit(CPU.TotalExecutedCycles); - if (!ear) - { - result = (byte)(result & Convert.ToInt32("10111111", 2)); - } - */ } else diff --git a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Keyboard.cs b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Keyboard.cs index afa886675a..e04eedc217 100644 --- a/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Keyboard.cs +++ b/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/ZXSpectrum48K/ZX48.Keyboard.cs @@ -77,21 +77,13 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum LineStatus = new byte[8]; _keyLine = new int[] { 255, 255, 255, 255, 255, 255, 255, 255 }; - IsIssue2Keyboard = false; + IsIssue2Keyboard = true; } public void SetKeyStatus(string key, bool isPressed) { int k = GetByteFromKeyMatrix(key); - - /* - byte keyByte = GetByteFromKeyMatrix(key); - var lineIndex = keyByte / 5; - var lineMask = 1 << keyByte % 5; - - LineStatus[lineIndex] = isPressed ? (byte)(LineStatus[lineIndex] | lineMask) - : (byte)(LineStatus[lineIndex] & ~lineMask); - */ + if (k != 255) { var lineIndex = k / 5;