Created a new and logical UI

This commit is contained in:
2026-05-11 21:58:27 +01:00
parent f4e279b9c8
commit 6f702a5866
7 changed files with 219 additions and 35 deletions

View File

@@ -14,6 +14,8 @@ namespace Desktop
private DebuggerForm _debugger;
private Bitmap _screenBitmap = new Bitmap(256, 192, PixelFormat.Format32bppArgb);
private Task _emulatorTask;
public bool IsRunning { get; private set; } = false;
@@ -27,6 +29,8 @@ namespace Desktop
{
InitializeComponent();
_machine = new SmsMachine();
PopulateIncludedRomsMenu();
}
private void DrawScreen()
@@ -44,9 +48,7 @@ namespace Desktop
{
if (IsRunning) return;
IsRunning = true;
// Fire off a background task so we don't freeze the Windows UI!
Task.Run(() =>
_emulatorTask = Task.Run(() =>
{
while (IsRunning)
{
@@ -65,7 +67,7 @@ namespace Desktop
else
{
// Only throttle the speed if we are actively running
Thread.Sleep(16);
Thread.Sleep(8);
}
}
});
@@ -82,22 +84,89 @@ namespace Desktop
_machine.StepMachine();
}
private void button1_Click(object sender, EventArgs e)
private async void LoadRomAndStart(string filePath)
{
// 1. Load a commercial Master System ROM!
byte[] rom = File.ReadAllBytes(@"C:\Parsons\Local Code Projects\ParsonsMasterSystem2026\Desktop\ROMS\Golden Axe Warrior.sms");
StopEmulator();
if (_emulatorTask != null)
{
await _emulatorTask;
}
// 2. Jam it into the Sega Mapper
_machine.LoadCartridge(rom);
// 2. Load the file
byte[] rom = File.ReadAllBytes(filePath);
// 3. Open the Debugger to look around
if (_debugger == null || _debugger.IsDisposed)
// 3. Jam it into the Sega Mapper
_machine.LoadCartridge(rom);
// 4. Update the Window title so it looks professional
this.Text = $"Parsons Master System 2026 - {Path.GetFileNameWithoutExtension(filePath)}";
// 5. Turn the power on!
StartEmulator();
}
private void PopulateIncludedRomsMenu()
{
// The folder you used for Golden Axe Warrior
string romsDirectory = @"C:\Parsons\Local Code Projects\ParsonsMasterSystem2026\Desktop\ROMS\";
if (Directory.Exists(romsDirectory))
{
string[] romFiles = Directory.GetFiles(romsDirectory, "*.sms");
foreach (string file in romFiles)
{
_debugger = new DebuggerForm(_machine.Cpu, _machine.MemoryBus, this);
_debugger.Show();
// Create a new dropdown item for each .sms file it finds
string romName = Path.GetFileNameWithoutExtension(file);
ToolStripMenuItem romMenuItem = new ToolStripMenuItem(romName);
// When clicked, pass the file path to our helper method
romMenuItem.Click += (sender, e) => LoadRomAndStart(file);
// Add it to the "Included" submenu (make sure the name matches your designer element!)
includedToolStripMenuItem.DropDownItems.Add(romMenuItem);
}
}
}
private void selectROMToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Select Master System ROM";
ofd.Filter = "SMS ROMs (*.sms)|*.sms|All Files (*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
LoadRomAndStart(ofd.FileName);
_machine.Reset();
}
}
}
private void resetToolStripMenuItem_Click(object sender, EventArgs e)
{
_machine.Reset();
}
private void debuggerToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_debugger == null || _debugger.IsDisposed)
{
_debugger = new DebuggerForm(_machine.Cpu, _machine.MemoryBus, this);
}
_debugger.Show();
}
private void includedToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
}
}