Some minor changes and playing about

This commit is contained in:
2026-04-16 14:40:05 +01:00
parent 92625498bf
commit 968141056b
9 changed files with 135 additions and 46 deletions

View File

@@ -13,7 +13,7 @@ namespace Desktop
{
private Z80 _cpu = null!;
private MemoryBus _memoryBus = null!;
private SimpleIoBus _simpleIoBus = null!;
private IO_Bus _simpleIoBus = null!;
// The 16 physical colors of the ZX Spectrum (ARGB format)
private readonly int[] SpectrumColors = new int[]
@@ -50,7 +50,7 @@ namespace Desktop
try
{
_memoryBus = new MemoryBus();
_simpleIoBus = new SimpleIoBus();
_simpleIoBus = new IO_Bus();
_memoryBus.CrapRAMData();
byte[] romData = RomLoader.Load("48.rom");
@@ -120,5 +120,67 @@ namespace Desktop
if (picScreen.Image != null) picScreen.Image.Dispose();
picScreen.Image = bmp;
}
// Helper method to update the IO Bus state
private void UpdateMatrix(int row, int col, bool isPressed)
{
if (isPressed)
{
// Clear the bit to 0 (Active-Low = Pressed)
_simpleIoBus.KeyboardRows[row] &= (byte)~(1 << col);
}
else
{
// Set the bit back to 1 (Unpressed)
_simpleIoBus.KeyboardRows[row] |= (byte)(1 << col);
}
}
// Hook this to Form1's KeyDown event
protected override void OnKeyDown(KeyEventArgs e)
{
HandleKey(e.KeyCode, true);
base.OnKeyDown(e);
}
// Hook this to Form1's KeyUp event
protected override void OnKeyUp(KeyEventArgs e)
{
HandleKey(e.KeyCode, false);
base.OnKeyUp(e);
}
private void HandleKey(Keys key, bool isPressed)
{
switch (key)
{
// Row 6: ENTER, L, K, J, H
case Keys.Enter: UpdateMatrix(6, 0, isPressed); break;
case Keys.L: UpdateMatrix(6, 1, isPressed); break;
case Keys.K: UpdateMatrix(6, 2, isPressed); break;
case Keys.J: UpdateMatrix(6, 3, isPressed); break;
case Keys.H: UpdateMatrix(6, 4, isPressed); break;
// Row 7: SPACE, SYM SHIFT, M, N, B
case Keys.Space: UpdateMatrix(7, 0, isPressed); break;
case Keys.M: UpdateMatrix(7, 2, isPressed); break;
case Keys.N: UpdateMatrix(7, 3, isPressed); break;
case Keys.B: UpdateMatrix(7, 4, isPressed); break;
// Row 1: A, S, D, F, G
case Keys.A: UpdateMatrix(1, 0, isPressed); break;
case Keys.S: UpdateMatrix(1, 1, isPressed); break;
case Keys.D: UpdateMatrix(1, 2, isPressed); break;
case Keys.F: UpdateMatrix(1, 3, isPressed); break;
case Keys.G: UpdateMatrix(1, 4, isPressed); break;
// Map the rest of the alphabet and numbers here as you need them!
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
}
}
}