Added ROM and RomLoader.cs. Updated Form1.cs to load ROM into memory
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user