Added control pad to Kempston interface

This commit is contained in:
2026-04-29 16:27:13 +01:00
parent 96b06ffc4e
commit 952db4767b
5 changed files with 53 additions and 30 deletions

View File

@@ -6,7 +6,8 @@ namespace Core.Io
{
public class IO_Bus
{
public byte BorderColorIndex { get; set; } = 7;
public byte BorderColourIndex { get; set; } = 7;
public byte KempstonState { get; set; } = 0x00;
public bool BeeperState { get; private set; } = false;
public byte[] KeyboardRows = new byte[8] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
TapManager _tapManager = new TapManager();
@@ -18,14 +19,13 @@ namespace Core.Io
public byte ReadPort(ushort portAddress)
{
// The Spectrum ULA responds to any even port address (where the lowest bit is 0)
//ULA responds to any even port address (where the lowest bit is 0)
if ((portAddress & 0x01) == 0) //Port 0xFE)
{
byte highByte = (byte)(portAddress >> 8); // The B register!
byte highByte = (byte)(portAddress >> 8); // The B register
byte result = 0xFF; // Start assuming no keys are pressed
// The ROM pulls a specific bit low (0) in the high byte to request a row.
// Sometimes it pulls multiple bits low to scan multiple rows at once, so we AND the results.
if ((highByte & 0x01) == 0) result &= KeyboardRows[0]; // 0xFE: CAPS, Z, X, C, V
if ((highByte & 0x02) == 0) result &= KeyboardRows[1]; // 0xFD: A, S, D, F, G
if ((highByte & 0x04) == 0) result &= KeyboardRows[2]; // 0xFB: Q, W, E, R, T
@@ -36,20 +36,18 @@ namespace Core.Io
if ((highByte & 0x80) == 0) result &= KeyboardRows[7]; // 0x7F: SPACE, SYM, M, N, B
if (_tapManager.EarBit) result |= 0x40; // Set Bit 6 high
else result &= 0xBF; // Set Bit 6 low
//return result;
// The top 3 bits (5, 6, 7) are unused by the keyboard and usually return 1 on a real Spectrum
//The top 3 bits (5, 6, 7) are unused by the keyboard and usually return 1 on a real Spectrum
return (byte)(result | 0xA0);
}
// Kempston Joystick Port
//Kempston Joystick Port
if ((portAddress & 0xFF) == 0x1F)
{
return 0x00; // 0x00 means no joystick connected/no buttons pressed
return KempstonState;
}
// Return 0xFF for unhandled ports
//Return 0xFF for unhandled ports
return 0x00;
}
@@ -59,7 +57,7 @@ namespace Core.Io
if ((portAddress & 0x01) == 0)
{
// The bottom 3 bits (0-2) define the border color
BorderColorIndex = (byte)(portValue & 0x07);
BorderColourIndex = (byte)(portValue & 0x07);
// Bit 4 controls the speaker
BeeperState = (portValue & 0x10) != 0;

View File

@@ -17,7 +17,7 @@ namespace Core.Io
private int _ulaFrameCount = 0;
// The hardware color palette belongs to the ULA, not the Windows Form!
private readonly int[] SpectrumColors = new int[]
private readonly int[] SpectrumColours = new int[]
{
unchecked((int)0xFF000000), unchecked((int)0xFF0000D7),
unchecked((int)0xFFD70000), unchecked((int)0xFFD700D7),
@@ -59,7 +59,7 @@ namespace Core.Io
// 2. Calculate our visual Y coordinate (0 to 255) for the bitmap array
int renderY = scanline - 32;
int currentBorderColor = SpectrumColors[_simpleIoBus.BorderColorIndex];
int currentBorderColor = SpectrumColours[_simpleIoBus.BorderColourIndex];
// --- Are we in the Top or Bottom Border? ---
if (scanline < 64 || scanline > 255)
@@ -102,8 +102,8 @@ namespace Core.Io
int brightOffset = (attr & 0x40) != 0 ? 8 : 0;
bool isFlashSet = (attr & 0x80) != 0;
int inkColor = SpectrumColors[ink + brightOffset];
int paperColor = SpectrumColors[paper + brightOffset];
int inkColor = SpectrumColours[ink + brightOffset];
int paperColor = SpectrumColours[paper + brightOffset];
if (isFlashSet && invertFlashPhase)
{