diff options
| author | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-06 22:36:34 +1000 |
|---|---|---|
| committer | Melodi <62381002+Melodi17@users.noreply.github.com> | 2025-08-06 22:36:34 +1000 |
| commit | 7a8d2bcd75d88a5429937bf551878c55e1dcf0fd (patch) | |
| tree | 81bc1f259fb8678513aa8b214df4ef72720bb585 /Emulator/DisplayEngine.cs | |
| parent | 16f3cb74564cf7c19da6e13666c98aca36094716 (diff) | |
moved everything to seperate projects, and started compiler work + push and pop instructions added
Diffstat (limited to 'Emulator/DisplayEngine.cs')
| -rw-r--r-- | Emulator/DisplayEngine.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Emulator/DisplayEngine.cs b/Emulator/DisplayEngine.cs new file mode 100644 index 0000000..beb2bba --- /dev/null +++ b/Emulator/DisplayEngine.cs @@ -0,0 +1,76 @@ +namespace Q1.Emulator; + +using System; +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 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) + { + this.Width = width; + this.Height = height; + this.Scaling = scaling; + this._onScreenTextureLoaded = onScreenTextureLoaded; + this._requestUpdate = requestUpdate; + this._checkAbort = checkAbort; + + this._graphics = new GraphicsDeviceManager(this); + this.Content.RootDirectory = "Content"; + this.IsMouseVisible = true; + } + + protected override void Initialize() + { + 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.PreferredBackBufferHeight = this.Height * this.Scaling; + this._graphics.ApplyChanges(); + + base.Initialize(); + } + + protected override void LoadContent() + { + this._spriteBatch = new SpriteBatch(this.GraphicsDevice); + } + + protected override void Update(GameTime gameTime) + { + var state = Keyboard.GetState(); + + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || state.IsKeyDown(Keys.Escape) || this._checkAbort()) + this.Exit(); + + base.Update(gameTime); + } + + protected override void Draw(GameTime gameTime) + { + // GraphicsDevice.Clear(Color.CornflowerBlue); + + this._requestUpdate(); + + 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.End(); + + base.Draw(gameTime); + } +}
\ No newline at end of file |
