mirror of
https://github.com/FranLMSP/snes.git
synced 2026-08-03 08:30:01 -04:00
show upcoming instruction
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
use crate::cpu::CPU;
|
||||
use crate::cpu::bus::Bus;
|
||||
use crate::rom::ROM;
|
||||
use crate::rom::lo_rom::LoROM;
|
||||
|
||||
pub struct Emulator {
|
||||
pub cpu: CPU,
|
||||
pub bus: Bus,
|
||||
pub rom: Box<dyn ROM>,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
@@ -14,7 +11,6 @@ impl Emulator {
|
||||
Self {
|
||||
cpu: CPU::new(),
|
||||
bus: Bus::new(),
|
||||
rom: Box::new(LoROM::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ impl DebugOptions {
|
||||
pub struct MemoryMapControlOptions {
|
||||
pub is_enabled: bool,
|
||||
pub inputs: MemoryMapInputs,
|
||||
pub inputs_result: MemoryMapInputs,
|
||||
}
|
||||
|
||||
impl MemoryMapControlOptions {
|
||||
@@ -34,6 +35,7 @@ impl MemoryMapControlOptions {
|
||||
Self {
|
||||
is_enabled: true,
|
||||
inputs: MemoryMapInputs::new(),
|
||||
inputs_result: MemoryMapInputs::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +61,7 @@ impl MemoryMapInputs {
|
||||
pub struct CPUDebugControlOptions {
|
||||
pub is_enabled: bool,
|
||||
pub show_registers: bool,
|
||||
pub show_upcoming_instruction: bool,
|
||||
}
|
||||
|
||||
impl CPUDebugControlOptions {
|
||||
@@ -66,6 +69,7 @@ impl CPUDebugControlOptions {
|
||||
Self {
|
||||
is_enabled: true,
|
||||
show_registers: true,
|
||||
show_upcoming_instruction: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use eframe::egui;
|
||||
use snes_core::emulator::Emulator;
|
||||
use snes_core::{emulator::Emulator, cpu::instructions::mapper::map_opcode_to_instruction};
|
||||
|
||||
use crate::emu_state::{debug_options::CPUDebugControlOptions, emulation::EmulationState};
|
||||
|
||||
@@ -32,15 +32,24 @@ pub fn build_cpu_debug_controls(ctx: &egui::Context, cpu_debug_options: &mut CPU
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
if ui.selectable_label(
|
||||
cpu_debug_options.show_registers,
|
||||
"Show registers"
|
||||
).clicked() {
|
||||
cpu_debug_options.show_registers = !cpu_debug_options.show_registers;
|
||||
}
|
||||
if ui.selectable_label(
|
||||
cpu_debug_options.show_upcoming_instruction,
|
||||
"Show upcoming instruction"
|
||||
).clicked() {
|
||||
cpu_debug_options.show_upcoming_instruction = !cpu_debug_options.show_upcoming_instruction;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
build_cpu_registers_window(ctx, cpu_debug_options, emulator);
|
||||
build_upcoming_instruction_window(ctx, cpu_debug_options, emulator);
|
||||
}
|
||||
|
||||
fn build_cpu_registers_window(ctx: &egui::Context, cpu_debug_options: &mut CPUDebugControlOptions, emulator: &Emulator) {
|
||||
@@ -67,3 +76,17 @@ fn build_cpu_registers_window(ctx: &egui::Context, cpu_debug_options: &mut CPUDe
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn build_upcoming_instruction_window(ctx: &egui::Context, cpu_debug_options: &mut CPUDebugControlOptions, emulator: &Emulator) {
|
||||
egui::Window::new("Upcoming CPU Instruction")
|
||||
.auto_sized()
|
||||
.min_width(150.0)
|
||||
.open(&mut cpu_debug_options.show_upcoming_instruction)
|
||||
.show(ctx, |ui| {
|
||||
let opcode = emulator.bus.read_external(emulator.cpu.registers.get_pc_address());
|
||||
let instruction = map_opcode_to_instruction(opcode);
|
||||
ui.monospace(
|
||||
instruction.mnemonic(&emulator.cpu.registers, &emulator.bus, opcode)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,19 +14,23 @@ pub fn build_memory_map_window(ctx: &egui::Context, memory_map_control_options:
|
||||
.min_size([400.0, 400.0])
|
||||
.open(&mut memory_map_control_options.is_enabled)
|
||||
.show(ctx, |ui| {
|
||||
build_inputs(ui, &mut memory_map_control_options.inputs);
|
||||
build_inputs(
|
||||
ui,
|
||||
&mut memory_map_control_options.inputs,
|
||||
&mut memory_map_control_options.inputs_result,
|
||||
);
|
||||
ui.separator();
|
||||
egui::ScrollArea::both().show(ui, |ui| {
|
||||
build_memory_map_text(
|
||||
ui,
|
||||
&memory_map_control_options.inputs,
|
||||
&memory_map_control_options.inputs_result,
|
||||
emulator,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn build_inputs(ui: &mut egui::Ui, input_values: &mut MemoryMapInputs) {
|
||||
fn build_inputs(ui: &mut egui::Ui, input_values: &mut MemoryMapInputs, input_result: &mut MemoryMapInputs) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Page Start: ");
|
||||
ui.text_edit_singleline(&mut input_values.page_start);
|
||||
@@ -48,6 +52,10 @@ fn build_inputs(ui: &mut egui::Ui, input_values: &mut MemoryMapInputs) {
|
||||
sanitize_input(&mut input_values.page_end, true);
|
||||
sanitize_input(&mut input_values.address_start, false);
|
||||
sanitize_input(&mut input_values.address_end, false);
|
||||
input_result.page_start = format!("{}", input_values.page_start);
|
||||
input_result.page_end = format!("{}", input_values.page_end);
|
||||
input_result.address_start = format!("{}", input_values.address_start);
|
||||
input_result.address_end = format!("{}", input_values.address_end);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ pub fn build_menu_bar(emulator: &mut Emulator, ui: &mut egui::Ui, state: &mut Ap
|
||||
if ui.button("Load ROM file").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||
let picked_path = path.display().to_string();
|
||||
match emulator.rom.load(&picked_path) {
|
||||
match emulator.bus.rom.load(&picked_path) {
|
||||
Ok(_) => println!("Loaded ROM"),
|
||||
Err(err) => println!("Error loading the ROM: {}", err),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user