diff --git a/Desktop/48.rom b/Desktop/48.rom
new file mode 100644
index 0000000..4d6895e
Binary files /dev/null and b/Desktop/48.rom differ
diff --git a/Desktop/Desktop.csproj b/Desktop/Desktop.csproj
index 454196b..ca6f524 100644
--- a/Desktop/Desktop.csproj
+++ b/Desktop/Desktop.csproj
@@ -12,4 +12,10 @@
+
+
+ PreserveNewest
+
+
+
\ No newline at end of file
diff --git a/Desktop/Form1.cs b/Desktop/Form1.cs
index d5006e3..0af0e38 100644
--- a/Desktop/Form1.cs
+++ b/Desktop/Form1.cs
@@ -1,15 +1,44 @@
+using System;
+using System.Windows.Forms;
+using Core.Cpu;
+using Core.Memory;
+
namespace Desktop
{
public partial class Form1 : Form
{
+ private Z80 _cpu;
+ private MemoryBus _memoryBus;
+
public Form1()
{
InitializeComponent();
+ InitializeEmulator();
}
- private void Form1_Load(object sender, EventArgs e)
+ private void InitializeEmulator()
{
+ try
+ {
+ // 1. Initialize the memory bus
+ _memoryBus = new MemoryBus();
+ // 2. Load the ROM from disk
+ // Make sure "48.rom" matches the name of the file you added to your project
+ byte[] romData = RomLoader.Load("48.rom");
+
+ // 3. Inject the ROM into the memory bus
+ _memoryBus.LoadRom(romData);
+
+ // 4. Initialize the CPU with the populated memory
+ _cpu = new Z80(_memoryBus);
+
+ MessageBox.Show("ROM loaded and CPU initialized successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Failed to initialize emulator:\n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/Desktop/RomLoader.cs b/Desktop/RomLoader.cs
new file mode 100644
index 0000000..b8a0ecc
--- /dev/null
+++ b/Desktop/RomLoader.cs
@@ -0,0 +1,26 @@
+using System;
+using System.IO;
+
+namespace Desktop
+{
+ public static class RomLoader
+ {
+ public static byte[] Load(string filePath)
+ {
+ if (!File.Exists(filePath))
+ {
+ throw new FileNotFoundException($"Could not find the ROM file at: {filePath}");
+ }
+
+ byte[] romData = File.ReadAllBytes(filePath);
+
+ // The standard ZX Spectrum 48k ROM is exactly 16384 bytes (16KB)
+ if (romData.Length != 16384)
+ {
+ throw new InvalidDataException($"Invalid ROM size. Expected 16384 bytes, got {romData.Length} bytes.");
+ }
+
+ return romData;
+ }
+ }
+}
\ No newline at end of file