diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-27 21:22:55 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-27 21:22:55 +1000 |
| commit | 634681ce2bb36cd686943102a0f071cd6a09049f (patch) | |
| tree | 6710047aa231d50f57114bdd54a27c559fb20a73 /Emulator/Chip/HIDDevice.cs | |
| parent | 94ddc02e03ab942d0c881e29053e8df3d2940c30 (diff) | |
fixed bugs and revolutionized the universe
Diffstat (limited to 'Emulator/Chip/HIDDevice.cs')
| -rw-r--r-- | Emulator/Chip/HIDDevice.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Emulator/Chip/HIDDevice.cs b/Emulator/Chip/HIDDevice.cs new file mode 100644 index 0000000..87bb2c3 --- /dev/null +++ b/Emulator/Chip/HIDDevice.cs @@ -0,0 +1,36 @@ +namespace Q1.Emulator.Chip; + +public class HIDDevice : RamDevice +{ + public HIDDevice(u16 start) : base(start, HIDDevice.CalculateSize()) { } + + public static u16 CalculateSize() + { + return 4 + 256; + } + + public void SetMouse(u16 positionalIndex, bool leftDown, bool rightDown, bool middleDown) + { + this.WriteWord(this.AddressableStart, positionalIndex); + u16 buttons = (u16) ((leftDown ? 1 : 0) + | ((rightDown ? 1 : 0) << 1) + | ((middleDown ? 1 : 0) << 2)); + this.WriteWord((u16) (this.AddressableStart + 2), buttons); + } + + public void SetKeyboard(u8 scanCode, bool pressed) + { + int index = scanCode >> 3; // keyCode / 8 + int bit = scanCode & 7; // keyCode % 8 + + ushort addr = (ushort) (4 + index); + u8 value = this.Read(addr); + + if (pressed) + value |= (u8) (1 << bit); + else + value &= (u8) ~(1 << bit); + + this.Write((u16) (this.AddressableStart + addr), value); + } +}
\ No newline at end of file |
