From a65299286196fdf7a97c990b177a760364e74edc Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Mon, 16 Jan 2023 18:27:33 +0100 Subject: [PATCH] Remapped interrupt to CTRL + ALT + C. Added reboot keycombo by pressing CTRL + ALT + INS --- Capy64/BIOS/RuntimeInputEvents.cs | 54 +++++++++++++++++++++++++++---- Capy64/Eventing/InputManager.cs | 6 ++++ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Capy64/BIOS/RuntimeInputEvents.cs b/Capy64/BIOS/RuntimeInputEvents.cs index 691f25a..e2aba8d 100644 --- a/Capy64/BIOS/RuntimeInputEvents.cs +++ b/Capy64/BIOS/RuntimeInputEvents.cs @@ -3,6 +3,8 @@ using Capy64.Eventing; using Capy64.Eventing.Events; using Capy64.LuaRuntime; using Microsoft.Xna.Framework.Input; +using System.Linq; +using static Capy64.Eventing.InputManager; namespace Capy64.BIOS; @@ -10,6 +12,8 @@ internal class RuntimeInputEvents { private EventEmitter _eventEmitter; private Runtime _runtime; + private const int rebootDelay = 30; + private int heldReboot = 0; public RuntimeInputEvents(EventEmitter eventEmitter, Runtime runtime) { @@ -27,6 +31,8 @@ internal class RuntimeInputEvents _eventEmitter.OnKeyUp += OnKeyUp; _eventEmitter.OnKeyDown += OnKeyDown; _eventEmitter.OnChar += OnChar; + + _eventEmitter.OnTick += OnTick; } public void Unregister() @@ -39,6 +45,37 @@ internal class RuntimeInputEvents _eventEmitter.OnKeyUp -= OnKeyUp; _eventEmitter.OnKeyDown -= OnKeyDown; _eventEmitter.OnChar -= OnChar; + + _eventEmitter.OnTick -= OnTick; + } + + private static Keys[] rebootKeys = new[] + { + Keys.Insert, + Keys.LeftAlt, Keys.RightAlt, + Keys.LeftControl, Keys.RightControl, + }; + private void OnTick(object sender, TickEvent e) + { + var keyState = Keyboard.GetState(); + var pressedKeys = keyState.GetPressedKeys(); + + if ((pressedKeys.Contains(Keys.LeftControl) || pressedKeys.Contains(Keys.RightControl)) + && (pressedKeys.Contains(Keys.LeftAlt) || pressedKeys.Contains(Keys.RightAlt)) + && pressedKeys.Contains(Keys.Insert)) + { + heldReboot++; + } + else + { + heldReboot = 0; + } + + if (heldReboot >= rebootDelay) + { + heldReboot = 0; + Bios.Reboot(); + } } private void OnMouseUp(object sender, MouseButtonEvent e) @@ -99,16 +136,19 @@ internal class RuntimeInputEvents e.IsHeld, }); - if (e.Mods.HasFlag(InputManager.Modifiers.LCtrl) || (e.Mods.HasFlag(InputManager.Modifiers.RCtrl) && !e.IsHeld)) + if ((e.Mods & Modifiers.Ctrl) != Modifiers.None && !e.IsHeld) { - if (e.Key == Keys.C) + if ((e.Mods & Modifiers.Alt) != Modifiers.None) { - _runtime.PushEvent(new LuaEvent() + if (e.Key == Keys.C) { - Name = "interrupt", - Parameters = { }, - BypassFilter = true, - }); + _runtime.PushEvent(new LuaEvent() + { + Name = "interrupt", + Parameters = { }, + BypassFilter = true, + }); + } } else if (e.Key == Keys.V) { diff --git a/Capy64/Eventing/InputManager.cs b/Capy64/Eventing/InputManager.cs index d68bb29..f74f286 100644 --- a/Capy64/Eventing/InputManager.cs +++ b/Capy64/Eventing/InputManager.cs @@ -21,6 +21,8 @@ public class InputManager [Flags] public enum Modifiers { + None = 0, + LShift = 1, RShift = 2, @@ -29,6 +31,10 @@ public class InputManager LCtrl = 16, RCtrl = 32, + + Shift = LShift | RShift, + Alt = LAlt | RAlt, + Ctrl = LCtrl | RCtrl, } private static Keys[] IgnoredTextInputKeys =