summaryrefslogtreecommitdiff
path: root/Emulator
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 12:35:24 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-28 12:35:24 +1000
commit7f96fc5e7f412a66d460dcaa82bbdbcaea08f360 (patch)
tree67ebd30bce45f8e5ffed73212f287b4152a5b71d /Emulator
parent634681ce2bb36cd686943102a0f071cd6a09049f (diff)
everything is finally at peace
Diffstat (limited to 'Emulator')
-rw-r--r--Emulator/Chip/HIDDevice.cs15
-rw-r--r--Emulator/DisplayEngine.cs17
-rw-r--r--Emulator/Program.cs2
3 files changed, 31 insertions, 3 deletions
diff --git a/Emulator/Chip/HIDDevice.cs b/Emulator/Chip/HIDDevice.cs
index 87bb2c3..c8a7d04 100644
--- a/Emulator/Chip/HIDDevice.cs
+++ b/Emulator/Chip/HIDDevice.cs
@@ -1,5 +1,7 @@
namespace Q1.Emulator.Chip;
+using System;
+
public class HIDDevice : RamDevice
{
public HIDDevice(u16 start) : base(start, HIDDevice.CalculateSize()) { }
@@ -24,7 +26,7 @@ public class HIDDevice : RamDevice
int bit = scanCode & 7; // keyCode % 8
ushort addr = (ushort) (4 + index);
- u8 value = this.Read(addr);
+ u8 value = this.Read((u16) (this.AddressableStart + addr));
if (pressed)
value |= (u8) (1 << bit);
@@ -33,4 +35,15 @@ public class HIDDevice : RamDevice
this.Write((u16) (this.AddressableStart + addr), value);
}
+
+ public bool GetKeyboard(int scanCode)
+ {
+ int index = scanCode >> 3;
+ int bit = scanCode & 7;
+
+ ushort addr = (ushort) (4 + index);
+ byte value = this.Read((u16) (this.AddressableStart + addr));
+
+ return (value & (1 << bit)) != 0;
+ }
} \ No newline at end of file
diff --git a/Emulator/DisplayEngine.cs b/Emulator/DisplayEngine.cs
index e5d508e..7aa8e2e 100644
--- a/Emulator/DisplayEngine.cs
+++ b/Emulator/DisplayEngine.cs
@@ -17,6 +17,7 @@ public class DisplayEngine : Game
private SpriteBatch _spriteBatch;
private Texture2D _texture;
+ private Keys[]? _oldKeys = null;
public int Scaling { get; }
public int Width { get; }
public int Height { get; }
@@ -66,11 +67,25 @@ public class DisplayEngine : Game
var mouse = Mouse.GetState();
u16 mousePos = (u16) (((mouse.Y / this.Scaling) * this.Width) + (mouse.X / this.Scaling));
- this._hid.SetMouse(mousePos,
+ this._hid.SetMouse(
+ mousePos,
mouse.LeftButton == ButtonState.Pressed,
mouse.RightButton == ButtonState.Pressed,
mouse.MiddleButton == ButtonState.Pressed);
+ Keys[] keys = keyboard.GetPressedKeys();
+ foreach (Keys newKey in keys.Except(this._oldKeys ?? []))
+ {
+ this._hid.SetKeyboard((u8) newKey, true);
+ }
+
+ foreach (Keys oldKey in this._oldKeys?.Except(keys) ?? [])
+ {
+ this._hid.SetKeyboard((u8) oldKey, false);
+ }
+
+ this._oldKeys = keys;
+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed
|| keyboard.IsKeyDown(Keys.Escape)
|| this._checkAbort())
diff --git a/Emulator/Program.cs b/Emulator/Program.cs
index 26f8c26..65bf068 100644
--- a/Emulator/Program.cs
+++ b/Emulator/Program.cs
@@ -74,7 +74,7 @@ public class Program
{
display.OutputTexture = tex;
Console.WriteLine("Display surface initialized.");
- }, () => display.Clock(), () => false);
+ }, () => display.Clock(), () => cpu.AbortRequested);
game.Run();
Console.WriteLine("Display surface closed. Waiting for CPU thread to finish...");