summaryrefslogtreecommitdiff
path: root/Emulator/Program.cs
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2026-03-17 20:49:22 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2026-03-17 20:49:22 +1000
commit18868128e18d38b706e7df14e8e683e1a9739c17 (patch)
tree6f0e0e5eee646f10cbad9c0c89c24d330bc58cc6 /Emulator/Program.cs
parentd87ab8af4c86a3fc6ee237444e372d87e536e3ef (diff)
chore: Initial commit
Diffstat (limited to 'Emulator/Program.cs')
-rw-r--r--Emulator/Program.cs98
1 files changed, 0 insertions, 98 deletions
diff --git a/Emulator/Program.cs b/Emulator/Program.cs
deleted file mode 100644
index f6fa932..0000000
--- a/Emulator/Program.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-namespace Q1.Emulator;
-
-using System;
-using System.IO;
-using System.Threading;
-using Chip;
-using CommandLine;
-using Microsoft.Xna.Framework;
-
-public class Program
-{
- public static void Main(string[] args)
- {
- Parser.Default.ParseArguments<EmulatorOptions>(args).WithParsed(Program.Main);
- }
-
- public static void Main(EmulatorOptions emulatorOptions)
- {
- Q1Cpu cpu = new();
- Bus bus = new(u16.MinValue, u16.MaxValue);
- RamDevice rom = new(Q1Layout.Rom.start, Q1Layout.Rom.size);
- File.ReadAllBytes(emulatorOptions.InputFile).CopyTo(rom.Memory, 0);
-
- DisplayDevice display = new(Q1Layout.DisplayPaletteSize, Q1Layout.DisplayWidth, Q1Layout.DisplayHeight, Q1Layout.Display.start);
- display.SetPalette([
- Color.Red,
- Color.Green,
- Color.Blue,
- Color.Yellow,
- Color.Cyan,
- Color.Magenta,
- Color.White,
- Color.Black,
- Color.Gray,
- Color.Orange,
- Color.Purple,
- Color.Brown,
- Color.LightGray,
- Color.DarkGray,
- Color.LightBlue,
- Color.LightGreen
- ]);
-
- HIDDevice hid = new(Q1Layout.Hid.start);
-
- RamDevice memory = new(Q1Layout.Memory.start, Q1Layout.Memory.size);
-
- cpu.Bus = bus;
- rom.AttachToBus(bus);
- display.AttachToBus(bus);
- memory.AttachToBus(bus);
- hid.AttachToBus(bus);
-
- Thread t = new(() =>
- {
- cpu.Reset();
- while (!cpu.AbortRequested)
- {
- // for (int i = 0; i < 64; i++)
- // cpu.Clock();
- //
- // Thread.Sleep(1);
- //
- cpu.Clock();
- }
- Console.WriteLine($"Exit code: 0x{cpu.V[0]:X4}");
- MemoryDump(memory, Q1Layout.FreeMemoryStart, (u16) (Q1Layout.Memory.start + Q1Layout.Memory.size - 1));
- });
- t.IsBackground = true;
- t.Start();
-
- using DisplayEngine game = new(Q1Layout.DisplayWidth, Q1Layout.DisplayHeight, 5,
- hid,
- tex =>
- {
- display.OutputTexture = tex;
- Console.WriteLine("Display surface initialized.");
- }, () => display.Clock(), () => cpu.AbortRequested);
- game.Run();
-
- Console.WriteLine("Display surface closed. Waiting for CPU thread to finish...");
- t.Join();
- }
-
- private static void MemoryDump(RamDevice memory, u16 start, u16 end)
- {
- for (u16 addr = start; addr <= end; addr += 16)
- {
- Console.Write($"0x{addr:X4}: ");
- for (u16 offset = 0; offset < 16; offset++)
- {
- if (addr + offset > end) break;
- Console.Write($"{memory.Read((u16) (addr + offset)):X2} ");
- }
- Console.WriteLine();
- }
- }
-} \ No newline at end of file