summaryrefslogtreecommitdiff
path: root/Emulator/DisplayEngine.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-27 21:22:55 +1000
commit634681ce2bb36cd686943102a0f071cd6a09049f (patch)
tree6710047aa231d50f57114bdd54a27c559fb20a73 /Emulator/DisplayEngine.cs
parent94ddc02e03ab942d0c881e29053e8df3d2940c30 (diff)
fixed bugs and revolutionized the universe
Diffstat (limited to 'Emulator/DisplayEngine.cs')
-rw-r--r--Emulator/DisplayEngine.cs63
1 files changed, 44 insertions, 19 deletions
diff --git a/Emulator/DisplayEngine.cs b/Emulator/DisplayEngine.cs
index beb2bba..e5d508e 100644
--- a/Emulator/DisplayEngine.cs
+++ b/Emulator/DisplayEngine.cs
@@ -1,35 +1,46 @@
namespace Q1.Emulator;
using System;
+using System.Linq;
+using Chip;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
public class DisplayEngine : Game
{
- private readonly Action<Texture2D> _onScreenTextureLoaded;
- private readonly Action _requestUpdate;
- private readonly Func<bool> _checkAbort;
- private GraphicsDeviceManager _graphics;
- private SpriteBatch _spriteBatch;
+ private readonly HIDDevice _hid;
+ private readonly Action<Texture2D> _onScreenTextureLoaded;
+ private readonly Action _requestUpdate;
+ private readonly Func<bool> _checkAbort;
+ private GraphicsDeviceManager _graphics;
+ private SpriteBatch _spriteBatch;
private Texture2D _texture;
public int Scaling { get; }
public int Width { get; }
public int Height { get; }
- public DisplayEngine(int width, int height, int scaling, Action<Texture2D> onScreenTextureLoaded, Action requestUpdate, Func<bool> checkAbort)
+ public DisplayEngine(
+ int width,
+ int height,
+ int scaling,
+ HIDDevice hid,
+ Action<Texture2D> onScreenTextureLoaded,
+ Action requestUpdate,
+ Func<bool> checkAbort)
{
- this.Width = width;
- this.Height = height;
- this.Scaling = scaling;
+ this.Width = width;
+ this.Height = height;
+ this.Scaling = scaling;
+ this._hid = hid;
this._onScreenTextureLoaded = onScreenTextureLoaded;
- this._requestUpdate = requestUpdate;
- this._checkAbort = checkAbort;
+ this._requestUpdate = requestUpdate;
+ this._checkAbort = checkAbort;
- this._graphics = new GraphicsDeviceManager(this);
+ this._graphics = new GraphicsDeviceManager(this);
this.Content.RootDirectory = "Content";
- this.IsMouseVisible = true;
+ this.IsMouseVisible = true;
}
protected override void Initialize()
@@ -37,7 +48,7 @@ public class DisplayEngine : Game
this._texture = new Texture2D(this.GraphicsDevice, this.Width, this.Height);
this._onScreenTextureLoaded?.Invoke(this._texture);
// set window size
- this._graphics.PreferredBackBufferWidth = this.Width * this.Scaling;
+ this._graphics.PreferredBackBufferWidth = this.Width * this.Scaling;
this._graphics.PreferredBackBufferHeight = this.Height * this.Scaling;
this._graphics.ApplyChanges();
@@ -51,11 +62,20 @@ public class DisplayEngine : Game
protected override void Update(GameTime gameTime)
{
- var state = Keyboard.GetState();
+ var keyboard = Keyboard.GetState();
+ var mouse = Mouse.GetState();
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || state.IsKeyDown(Keys.Escape) || this._checkAbort())
+ u16 mousePos = (u16) (((mouse.Y / this.Scaling) * this.Width) + (mouse.X / this.Scaling));
+ this._hid.SetMouse(mousePos,
+ mouse.LeftButton == ButtonState.Pressed,
+ mouse.RightButton == ButtonState.Pressed,
+ mouse.MiddleButton == ButtonState.Pressed);
+
+ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed
+ || keyboard.IsKeyDown(Keys.Escape)
+ || this._checkAbort())
this.Exit();
-
+
base.Update(gameTime);
}
@@ -65,9 +85,14 @@ public class DisplayEngine : Game
this._requestUpdate();
- this._spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
+ this._spriteBatch.Begin(
+ SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp,
+ DepthStencilState.None, RasterizerState.CullNone);
// Draw the texture to the screen
- this._spriteBatch.Draw(this._texture, new Rectangle(0, 0, this.Width * this.Scaling, this.Height * this.Scaling), Color.White);
+ this._spriteBatch.Draw(
+ this._texture,
+ new Rectangle(0, 0, this.Width * this.Scaling, this.Height * this.Scaling),
+ Color.White);
this._spriteBatch.End();