Restart emulation as soon as a ROM is loaded

This commit is contained in:
2024-11-06 21:22:13 -05:00
parent d8c8867937
commit 442cf5748b
3 changed files with 15 additions and 4 deletions
+6 -1
View File
@@ -34,9 +34,14 @@ impl Emulator {
} }
} }
pub fn reset(&mut self) { pub fn reset_vector(&mut self) {
self.cpu.reset_vector(&mut self.bus); self.cpu.reset_vector(&mut self.bus);
} }
pub fn hard_reset(&mut self) {
self.cpu = CPU::new();
self.bus = Bus::new();
}
} }
impl Default for Emulator { impl Default for Emulator {
+1 -1
View File
@@ -34,7 +34,7 @@ pub fn build_cpu_debug_controls(ctx: &egui::Context, cpu_debug_options: &mut CPU
ui.monospace("Vectors:"); ui.monospace("Vectors:");
ui.horizontal(|ui| { ui.horizontal(|ui| {
if ui.button("Reset").clicked() { if ui.button("Reset").clicked() {
emulator.reset(); emulator.reset_vector();
} }
}); });
ui.separator(); ui.separator();
+8 -2
View File
@@ -11,9 +11,15 @@ pub fn build_menu_bar(emulator: &mut Emulator, ui: &mut egui::Ui, state: &mut Ap
if let Some(path) = rfd::FileDialog::new().pick_file() { if let Some(path) = rfd::FileDialog::new().pick_file() {
let picked_path = path.display().to_string(); let picked_path = path.display().to_string();
match emulator.bus.rom.load(&picked_path) { match emulator.bus.rom.load(&picked_path) {
Ok(_) => println!("Loaded ROM"), Ok(_) => {
emulator.hard_reset();
state.emulation_state.is_paused = false;
state.emulation_state.one_tick_per_frame = false;
emulator.reset_vector();
println!("Loaded ROM");
},
Err(err) => println!("Error loading the ROM: {}", err), Err(err) => println!("Error loading the ROM: {}", err),
} };
} }
} }
}); });