mirror of
https://github.com/FranLMSP/snes.git
synced 2026-08-03 08:30:01 -04:00
some refactors and showing cpu registers
This commit is contained in:
@@ -1,3 +1,17 @@
|
|||||||
|
pub struct MemoryMapControlOptions {
|
||||||
|
pub is_enabled: bool,
|
||||||
|
pub inputs: MemoryMapInputs,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MemoryMapControlOptions {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_enabled: true,
|
||||||
|
inputs: MemoryMapInputs::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MemoryMapInputs {
|
pub struct MemoryMapInputs {
|
||||||
pub page_start: String,
|
pub page_start: String,
|
||||||
pub page_end: String,
|
pub page_end: String,
|
||||||
@@ -16,11 +30,25 @@ impl MemoryMapInputs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct CPUDebugControlOptions {
|
||||||
|
pub is_enabled: bool,
|
||||||
|
pub show_registers: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CPUDebugControlOptions {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_enabled: true,
|
||||||
|
show_registers: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DebugOptions {
|
pub struct DebugOptions {
|
||||||
pub enable_debugging: bool,
|
pub enable_debugging: bool,
|
||||||
pub show_debug_options_window: bool,
|
pub show_debug_options_window: bool,
|
||||||
pub show_memory_map: bool,
|
pub memory_map_conrtrol_options: MemoryMapControlOptions,
|
||||||
pub memory_map_inputs: MemoryMapInputs,
|
pub cpu_debug_control_options: CPUDebugControlOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugOptions {
|
impl DebugOptions {
|
||||||
@@ -28,8 +56,8 @@ impl DebugOptions {
|
|||||||
Self {
|
Self {
|
||||||
enable_debugging: true,
|
enable_debugging: true,
|
||||||
show_debug_options_window: true,
|
show_debug_options_window: true,
|
||||||
show_memory_map: true,
|
memory_map_conrtrol_options: MemoryMapControlOptions::new(),
|
||||||
memory_map_inputs: MemoryMapInputs::new(),
|
cpu_debug_control_options: CPUDebugControlOptions::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
pub struct EmulationState {
|
||||||
|
pub is_paused: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EmulationState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_paused: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
pub mod debug_options;
|
pub mod debug_options;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
pub mod emulation;
|
||||||
pub use state::AppState;
|
pub use state::AppState;
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
use crate::emu_state::debug_options::DebugOptions;
|
use crate::emu_state::debug_options::DebugOptions;
|
||||||
|
use crate::emu_state::emulation::EmulationState;
|
||||||
|
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub debug_options: DebugOptions,
|
pub debug_options: DebugOptions,
|
||||||
|
pub emulation_state: EmulationState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
debug_options: DebugOptions::new(),
|
debug_options: DebugOptions::new(),
|
||||||
|
emulation_state: EmulationState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
use eframe::egui;
|
||||||
|
use snes_core::emulator::Emulator;
|
||||||
|
|
||||||
|
use crate::emu_state::{debug_options::CPUDebugControlOptions, emulation::EmulationState};
|
||||||
|
|
||||||
|
|
||||||
|
pub fn build_cpu_debug_controls(ctx: &egui::Context, cpu_debug_options: &mut CPUDebugControlOptions, emulation_state: &mut EmulationState, emulator: &mut Emulator) {
|
||||||
|
if !cpu_debug_options.is_enabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
egui::Window::new("CPU Debug Controls")
|
||||||
|
.auto_sized()
|
||||||
|
.max_width(125.0)
|
||||||
|
.open(&mut cpu_debug_options.is_enabled)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.monospace("Controls:");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
let pause_text = if emulation_state.is_paused {"Resume"} else {"Pause"};
|
||||||
|
if ui.button(pause_text).clicked() {
|
||||||
|
emulation_state.is_paused = !emulation_state.is_paused;
|
||||||
|
}
|
||||||
|
let tick_button = ui.add_enabled(emulation_state.is_paused, egui::Button::new("Tick"));
|
||||||
|
if tick_button.clicked() {
|
||||||
|
emulator.tick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.monospace("Vectors:");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Reset").clicked() {
|
||||||
|
emulator.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.separator();
|
||||||
|
if ui.selectable_label(
|
||||||
|
cpu_debug_options.show_registers,
|
||||||
|
"Show registers"
|
||||||
|
).clicked() {
|
||||||
|
cpu_debug_options.show_registers = !cpu_debug_options.show_registers;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
build_cpu_registers_window(ctx, cpu_debug_options, emulator);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_cpu_registers_window(ctx: &egui::Context, cpu_debug_options: &mut CPUDebugControlOptions, emulator: &Emulator) {
|
||||||
|
egui::Window::new("CPU Registers")
|
||||||
|
.auto_sized()
|
||||||
|
.max_width(125.0)
|
||||||
|
.open(&mut cpu_debug_options.show_registers)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
|
ui.monospace(format!("SP: | {:#06X}", emulator.cpu.registers.sp));
|
||||||
|
ui.monospace(format!("X: | {:#06X}", emulator.cpu.registers.x));
|
||||||
|
ui.monospace(format!("Y: | {:#06X}", emulator.cpu.registers.y));
|
||||||
|
ui.monospace(format!("A: | {:#06X}", emulator.cpu.registers.a));
|
||||||
|
ui.monospace(format!("P: | {:#04X}", emulator.cpu.registers.p));
|
||||||
|
ui.monospace(format!("D: | {:#06X}", emulator.cpu.registers.d));
|
||||||
|
ui.monospace(format!("PBR: | {:#04X}", emulator.cpu.registers.pbr));
|
||||||
|
ui.monospace(format!("DBR: | {:#04X}", emulator.cpu.registers.dbr));
|
||||||
|
ui.monospace(format!("PC: | {:#06X}", emulator.cpu.registers.pc));
|
||||||
|
ui.monospace(format!("EMU MODE: | {}", emulator.cpu.registers.emulation_mode));
|
||||||
|
ui.separator();
|
||||||
|
ui.monospace("Status flags:");
|
||||||
|
ui.monospace("NVMXDIZC");
|
||||||
|
ui.monospace(format!("{:08b}", emulator.cpu.registers.p));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,35 +1,45 @@
|
|||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use snes_core::emulator::Emulator;
|
use snes_core::emulator::Emulator;
|
||||||
|
|
||||||
use crate::emu_state::AppState;
|
use crate::emu_state::debug_options::DebugOptions;
|
||||||
|
use crate::emu_state::emulation::EmulationState;
|
||||||
|
|
||||||
use super::memory_map::build_memory_map_window;
|
use super::memory_map::build_memory_map_window;
|
||||||
|
use super::cpu::build_cpu_debug_controls;
|
||||||
|
|
||||||
|
|
||||||
fn build_debug_options_window(ctx: &egui::Context, app_state: &mut AppState) {
|
pub fn build_all_debug_options(ctx: &egui::Context, debug_options: &mut DebugOptions, emulation_state: &mut EmulationState, emulator: &mut Emulator) {
|
||||||
|
build_debug_options_window(ctx, debug_options);
|
||||||
|
|
||||||
|
if !debug_options.enable_debugging {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
build_memory_map_window(ctx, &mut debug_options.memory_map_conrtrol_options, emulator);
|
||||||
|
build_cpu_debug_controls(ctx, &mut debug_options.cpu_debug_control_options, emulation_state, emulator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn build_debug_options_window(ctx: &egui::Context, debug_options: &mut DebugOptions) {
|
||||||
egui::Window::new("Debug")
|
egui::Window::new("Debug")
|
||||||
.open(&mut app_state.debug_options.show_debug_options_window)
|
.open(&mut debug_options.show_debug_options_window)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.checkbox(
|
ui.checkbox(
|
||||||
&mut app_state.debug_options.enable_debugging,
|
&mut debug_options.enable_debugging,
|
||||||
"Enable debugging",
|
"Enable debugging",
|
||||||
);
|
);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if ui.selectable_label(
|
if ui.selectable_label(
|
||||||
app_state.debug_options.show_memory_map,
|
debug_options.memory_map_conrtrol_options.is_enabled,
|
||||||
"Show memory map"
|
"Show memory map"
|
||||||
).clicked() {
|
).clicked() {
|
||||||
app_state.debug_options.show_memory_map = !app_state.debug_options.show_memory_map;
|
debug_options.memory_map_conrtrol_options.is_enabled = !debug_options.memory_map_conrtrol_options.is_enabled;
|
||||||
|
}
|
||||||
|
if ui.selectable_label(
|
||||||
|
debug_options.cpu_debug_control_options.is_enabled,
|
||||||
|
"Show CPU Debug Controls"
|
||||||
|
).clicked() {
|
||||||
|
debug_options.cpu_debug_control_options.is_enabled = !debug_options.cpu_debug_control_options.is_enabled;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_all_debug_options(ctx: &egui::Context, app_state: &mut AppState, emulator: &Emulator) {
|
|
||||||
build_debug_options_window(ctx, app_state);
|
|
||||||
|
|
||||||
if !app_state.debug_options.enable_debugging {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
build_memory_map_window(ctx, app_state, emulator);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,24 +2,24 @@ use eframe::egui;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use snes_core::emulator::Emulator;
|
use snes_core::emulator::Emulator;
|
||||||
|
|
||||||
use crate::emu_state::{AppState, debug_options::MemoryMapInputs};
|
use crate::emu_state::debug_options::{MemoryMapInputs, MemoryMapControlOptions};
|
||||||
|
|
||||||
|
|
||||||
pub fn build_memory_map_window(ctx: &egui::Context, app_state: &mut AppState, emulator: &Emulator) {
|
pub fn build_memory_map_window(ctx: &egui::Context, memory_map_control_options: &mut MemoryMapControlOptions, emulator: &Emulator) {
|
||||||
if !app_state.debug_options.show_memory_map {
|
if !memory_map_control_options.is_enabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
egui::Window::new("Memory Map")
|
egui::Window::new("Memory Map")
|
||||||
.min_size([400.0, 400.0])
|
.min_size([400.0, 400.0])
|
||||||
.open(&mut app_state.debug_options.show_memory_map)
|
.open(&mut memory_map_control_options.is_enabled)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
build_inputs(ui, &mut app_state.debug_options.memory_map_inputs);
|
build_inputs(ui, &mut memory_map_control_options.inputs);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
egui::ScrollArea::both().show(ui, |ui| {
|
egui::ScrollArea::both().show(ui, |ui| {
|
||||||
build_memory_map_text(
|
build_memory_map_text(
|
||||||
ui,
|
ui,
|
||||||
&app_state.debug_options.memory_map_inputs,
|
&memory_map_control_options.inputs,
|
||||||
emulator,
|
emulator,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -88,4 +88,3 @@ fn build_memory_map_text(ui: &mut egui::Ui, input_values: &MemoryMapInputs, emul
|
|||||||
ui.monospace(address_row);
|
ui.monospace(address_row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod debug;
|
pub mod debug;
|
||||||
pub mod memory_map;
|
pub mod memory_map;
|
||||||
|
pub mod cpu;
|
||||||
|
|
||||||
pub use debug::build_all_debug_options;
|
pub use debug::build_all_debug_options;
|
||||||
@@ -24,7 +24,7 @@ impl eframe::App for SnesEmulatorApp {
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
// ui::game::build_game_window(ctx);
|
// ui::game::build_game_window(ctx);
|
||||||
});
|
});
|
||||||
emu_ui::debug::build_all_debug_options(ctx, &mut self.state, &self.emulator);
|
emu_ui::debug::build_all_debug_options(ctx, &mut self.state.debug_options, &mut self.state.emulation_state, &mut self.emulator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user