Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

breakpoints

Layle4f3403cef039
diff --git a/crates/dbglib/src/lib.rs b/crates/dbglib/src/lib.rs
index 33fc4e5..967b0d1 100644
--- a/crates/dbglib/src/lib.rs
+++ b/crates/dbglib/src/lib.rs
@@ -23,8 +23,15 @@ pub enum EmulatorState {
RunUntilDsp,
}
+#[derive(Debug, Clone, Copy)]
+pub struct Breakpoint {
+ pub addr: u32,
+ pub enabled: bool,
+}
+
pub struct Debugger {
state: EmulatorState,
+ breakpoints: Vec<Breakpoint>,
#[cfg(not(target_arch = "wasm32"))]
trace_writer: Option<Box<dyn Write>>,
#[cfg(not(target_arch = "wasm32"))]
@@ -35,6 +42,7 @@ impl Debugger {
pub fn new() -> Self {
Debugger {
state: EmulatorState::Paused,
+ breakpoints: Vec::new(),
#[cfg(not(target_arch = "wasm32"))]
trace_writer: None,
#[cfg(not(target_arch = "wasm32"))]
@@ -42,6 +50,38 @@ impl Debugger {
}
}
+ pub fn breakpoints(&self) -> &[Breakpoint] {
+ &self.breakpoints
+ }
+
+ pub fn add_breakpoint(&mut self, addr: u32) {
+ if !self.breakpoints.iter().any(|b| b.addr == addr) {
+ self.breakpoints.push(Breakpoint { addr, enabled: true });
+ }
+ }
+
+ pub fn remove_breakpoint(&mut self, index: usize) {
+ if index < self.breakpoints.len() {
+ self.breakpoints.remove(index);
+ }
+ }
+
+ pub fn toggle_breakpoint(&mut self, index: usize) {
+ if let Some(bp) = self.breakpoints.get_mut(index) {
+ bp.enabled = !bp.enabled;
+ }
+ }
+
+ #[inline(always)]
+ fn breakpoint_hit(&self, pc: u32) -> bool {
+ self.breakpoints.iter().any(|b| b.enabled && b.addr == pc)
+ }
+
+ #[inline(always)]
+ fn has_active_breakpoints(&self) -> bool {
+ self.breakpoints.iter().any(|b| b.enabled)
+ }
+
pub fn state(&self) -> EmulatorState {
self.state
}
@@ -174,12 +214,16 @@ impl Debugger {
pub fn tick(&mut self, emulator: &mut GameCube) {
match self.state {
EmulatorState::Running => {
- if self.is_tracing() || self.is_dsp_tracing() {
+ if self.is_tracing() || self.is_dsp_tracing() || self.has_active_breakpoints() {
emulator.prepare_frame();
while !emulator.vsync_pending {
self.drain_events(emulator);
self.trace_step(emulator);
emulator.step_cpu();
+ if self.breakpoint_hit(emulator.cpu.pc) {
+ self.state = EmulatorState::Paused;
+ return;
+ }
}
} else {
emulator.run_until_vsync();
@@ -191,12 +235,16 @@ impl Debugger {
self.state = EmulatorState::Paused;
}
EmulatorState::RunUntilVsync => {
- if self.is_tracing() || self.is_dsp_tracing() {
+ if self.is_tracing() || self.is_dsp_tracing() || self.has_active_breakpoints() {
emulator.prepare_frame();
while !emulator.vsync_pending {
self.drain_events(emulator);
self.trace_step(emulator);
emulator.step_cpu();
+ if self.breakpoint_hit(emulator.cpu.pc) {
+ self.state = EmulatorState::Paused;
+ return;
+ }
}
} else {
emulator.run_until_vsync();
@@ -208,6 +256,10 @@ impl Debugger {
self.drain_events(emulator);
self.trace_step(emulator);
emulator.step_cpu();
+ if self.breakpoint_hit(emulator.cpu.pc) {
+ self.state = EmulatorState::Paused;
+ return;
+ }
}
self.state = EmulatorState::Paused;
}
@@ -219,6 +271,10 @@ impl Debugger {
}
self.trace_step(emulator);
emulator.step_cpu();
+ if self.breakpoint_hit(emulator.cpu.pc) {
+ self.state = EmulatorState::Paused;
+ return;
+ }
}
self.state = EmulatorState::Paused;
}
diff --git a/crates/dbglib/src/windows.rs b/crates/dbglib/src/windows.rs
index 9a3d9c4..7e903f4 100644
--- a/crates/dbglib/src/windows.rs
+++ b/crates/dbglib/src/windows.rs
@@ -1,3 +1,4 @@
+pub mod breakpoints;
pub mod callstack;
pub mod controls;
pub mod cpu;
diff --git a/crates/dbglib/src/windows/breakpoints.rs b/crates/dbglib/src/windows/breakpoints.rs
new file mode 100644
index 0000000..0ee4342
--- /dev/null
+++ b/crates/dbglib/src/windows/breakpoints.rs
@@ -0,0 +1,63 @@
+use egui::{Context, Grid, ScrollArea};
+use egui_phosphor::regular as icons;
+
+use crate::Debugger;
+
+pub fn show_breakpoints(ctx: &Context, open: &mut bool, debugger: &mut Debugger, addr_input: &mut String) {
+ egui::Window::new("Breakpoints").open(open).show(ctx, |ui| {
+ ui.horizontal(|ui| {
+ egui::TextEdit::singleline(addr_input)
+ .hint_text("address")
+ .desired_width(100.0)
+ .font(egui::TextStyle::Monospace)
+ .show(ui);
+
+ if ui.button(format!("{} Add", icons::PLUS)).clicked() {
+ let s = addr_input.trim().trim_start_matches("0x");
+ if let Ok(addr) = u32::from_str_radix(s, 16) {
+ debugger.add_breakpoint(addr);
+ addr_input.clear();
+ }
+ }
+ });
+
+ ui.separator();
+
+ if debugger.breakpoints().is_empty() {
+ ui.label("No breakpoints.");
+ return;
+ }
+
+ let mut toggle_index: Option<usize> = None;
+ let mut remove_index: Option<usize> = None;
+
+ ScrollArea::vertical().show(ui, |ui| {
+ Grid::new("breakpoint_list")
+ .num_columns(3)
+ .striped(true)
+ .show(ui, |ui| {
+ for (i, bp) in debugger.breakpoints().iter().enumerate() {
+ let mut enabled = bp.enabled;
+ if ui.checkbox(&mut enabled, "").changed() {
+ toggle_index = Some(i);
+ }
+
+ ui.monospace(format!("{:#010X}", bp.addr));
+
+ if ui.button(icons::TRASH).clicked() {
+ remove_index = Some(i);
+ }
+
+ ui.end_row();
+ }
+ });
+ });
+
+ if let Some(i) = toggle_index {
+ debugger.toggle_breakpoint(i);
+ }
+ if let Some(i) = remove_index {
+ debugger.remove_breakpoint(i);
+ }
+ });
+}
diff --git a/crates/dbglib/src/windows/cpu.rs b/crates/dbglib/src/windows/cpu.rs
index 039a5c0..dda01ee 100644
--- a/crates/dbglib/src/windows/cpu.rs
+++ b/crates/dbglib/src/windows/cpu.rs
@@ -4,13 +4,22 @@ use gecko::mmio::Mmio;
use image::symbols::SymbolTable;
use super::token_color;
-
-pub fn show_cpu(ctx: &Context, open: &mut bool, cpu: &Cpu, mmio: &Mmio, symbols: Option<&SymbolTable>) {
+use crate::Breakpoint;
+
+pub fn show_cpu(
+ ctx: &Context,
+ open: &mut bool,
+ cpu: &Cpu,
+ mmio: &Mmio,
+ symbols: Option<&SymbolTable>,
+ breakpoints: &[Breakpoint],
+) {
egui::Window::new("CPU").open(open).show(ctx, |ui| {
ui.horizontal_top(|ui| {
ui.vertical(|ui| {
ui.set_min_width(350.0);
ui.set_max_width(350.0);
+
Grid::new("special_regs").num_columns(5).striped(true).show(ui, |ui| {
ui.label("PC");
ui.monospace(format!("{:#010X}", cpu.pc));
@@ -102,15 +111,34 @@ pub fn show_cpu(ctx: &Context, open: &mut bool, cpu: &Cpu, mmio: &Mmio, symbols:
.unwrap_or_else(|| format!(".word {:#010X}", raw));
let is_pc = addr == pc;
+ let bp = breakpoints.iter().find(|b| b.addr == addr);
- if is_pc {
- ui.label(
- RichText::new(egui_phosphor::regular::PLAY)
- .color(Color32::from_rgb(120, 220, 120)),
- );
- } else {
- ui.label("");
- }
+ ui.horizontal(|ui| {
+ ui.spacing_mut().item_spacing.x = 2.0;
+ if let Some(bp) = bp {
+ let color = if bp.enabled {
+ Color32::from_rgb(220, 80, 80)
+ } else {
+ Color32::from_rgb(100, 60, 60)
+ };
+ let font_id = egui::FontId::new(
+ ui.style().text_styles[&egui::TextStyle::Body].size,
+ egui::FontFamily::Name("phosphor-fill".into()),
+ );
+ ui.label(
+ RichText::new(egui_phosphor::fill::CIRCLE).color(color).font(font_id),
+ );
+ }
+ if is_pc {
+ ui.label(
+ RichText::new(egui_phosphor::regular::PLAY)
+ .color(Color32::from_rgb(120, 220, 120)),
+ );
+ }
+ if bp.is_none() && !is_pc {
+ ui.label("");
+ }
+ });
ui.monospace(format!("{:#010X}", addr));
diff --git a/crates/debugger/Cargo.toml b/crates/debugger/Cargo.toml
index 4564f86..54c6e1e 100644
--- a/crates/debugger/Cargo.toml
+++ b/crates/debugger/Cargo.toml
@@ -20,6 +20,6 @@ pollster = "0.4.0"
egui = "0.33.3"
egui-wgpu = "0.33.3"
egui-winit = { version = "0.33.3", features = ["wayland", "x11"] }
-egui-phosphor = "0.11.0"
+egui-phosphor = { version = "0.11.0", features = ["fill"] }
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
clap = { version = "4.6.0", features = ["derive"] }
diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rs
index 9122d13..f2fe272 100644
--- a/crates/debugger/src/debugger.rs
+++ b/crates/debugger/src/debugger.rs
@@ -21,9 +21,11 @@ pub struct DebuggerUi {
pub show_controls: bool,
pub show_callstack: bool,
pub show_lua: bool,
+ pub show_breakpoints: bool,
pub memory_base: u32,
pub memory_addr_input: String,
pub run_until_addr_input: String,
+ pub breakpoint_addr_input: String,
pub dvd_cover_open: Option<bool>,
pub lua_source: String,
pub lua_log: Vec<String>,
@@ -45,9 +47,11 @@ impl Default for DebuggerUi {
show_irqs: false,
show_callstack: false,
show_lua: false,
+ show_breakpoints: false,
memory_base: 0x8000_0000,
memory_addr_input: "80000000".to_string(),
run_until_addr_input: String::new(),
+ breakpoint_addr_input: String::new(),
dvd_cover_open: None,
lua_source: DEFAULT_LUA_SCRIPT.to_string(),
lua_log: Vec::new(),
diff --git a/crates/debugger/src/render.rs b/crates/debugger/src/render.rs
index ff1d954..7b7a950 100644
--- a/crates/debugger/src/render.rs
+++ b/crates/debugger/src/render.rs
@@ -30,6 +30,13 @@ impl RenderState {
let egui_ctx = egui::Context::default();
let mut fonts = egui::FontDefinitions::default();
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
+ fonts
+ .font_data
+ .insert("phosphor-fill".into(), egui_phosphor::Variant::Fill.font_data().into());
+ fonts.families.insert(
+ egui::FontFamily::Name("phosphor-fill".into()),
+ vec!["phosphor-fill".into()],
+ );
egui_ctx.set_fonts(fonts);
egui_ctx.global_style_mut(|style| {
let f = &style.visuals.window_fill;
@@ -169,6 +176,7 @@ impl RenderState {
ui.checkbox(&mut debugger_ui.show_exi, "EXI");
ui.checkbox(&mut debugger_ui.show_irqs, "IRQ");
ui.checkbox(&mut debugger_ui.show_controls, "Controls");
+ ui.checkbox(&mut debugger_ui.show_breakpoints, "Breakpoints");
ui.checkbox(&mut debugger_ui.show_lua, "Lua");
});
});
@@ -181,6 +189,7 @@ impl RenderState {
cpu,
mmio,
debugger_ui.symbols.as_ref(),
+ debugger_ui.debugger.breakpoints(),
);
}
if debugger_ui.show_callstack {
@@ -251,6 +260,14 @@ impl RenderState {
if debugger_ui.show_irqs {
dbglib::windows::irq::show_irq(&ctx, &mut debugger_ui.show_irqs, &emulator.cpu, &emulator.pi);
}
+ if debugger_ui.show_breakpoints {
+ dbglib::windows::breakpoints::show_breakpoints(
+ &ctx,
+ &mut debugger_ui.show_breakpoints,
+ &mut debugger_ui.debugger,
+ &mut debugger_ui.breakpoint_addr_input,
+ );
+ }
if debugger_ui.show_lua {
let mut load_script = false;
let mut clear_log = false;
diff --git a/crates/dsptestrunner/src/bin/zayd.rs b/crates/dsptestrunner/src/bin/zayd.rs
index 281796a..013af38 100644
--- a/crates/dsptestrunner/src/bin/zayd.rs
+++ b/crates/dsptestrunner/src/bin/zayd.rs
@@ -556,7 +556,7 @@ fn main() {
println!();
println!("=====================================");
println!("Total: {total_pass} passed / {total_fail} failed");
-
+
if !files_with_failures.is_empty() {
println!("Files with failures: {}", files_with_failures.join(", "));
}
diff --git a/crates/web/Cargo.lock b/crates/web/Cargo.lock
index 42b591c..4a72369 100644
--- a/crates/web/Cargo.lock
+++ b/crates/web/Cargo.lock
@@ -160,6 +160,7 @@ dependencies = [
"encase",
"gecko",
"glam",
+ "rustc-hash 2.1.2",
"tracing",
"wesl",
"wgpu",
@@ -900,6 +901,8 @@ dependencies = [
"chipi-build",
"glam",
"image",
+ "multiversion",
+ "rustc-hash 2.1.2",
"tracing",
"twox-hash",
]
@@ -1557,6 +1560,28 @@ dependencies = [
"paste",
]
+[[package]]
+name = "multiversion"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7edb7f0ff51249dfda9ab96b5823695e15a052dc15074c9dbf3d118afaf2c201"
+dependencies = [
+ "multiversion-macros",
+ "target-features",
+]
+
+[[package]]
+name = "multiversion-macros"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b093064383341eb3271f42e381cb8f10a01459478446953953c75d24bd339fc0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "target-features",
+]
+
[[package]]
name = "naga"
version = "28.0.0"
@@ -2549,6 +2574,12 @@ dependencies = [
"syn",
]
+[[package]]
+name = "target-features"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1bbb9f3c5c463a01705937a24fdabc5047929ac764b2d5b9cf681c1f5041ed5"
+
[[package]]
name = "term"
version = "1.2.1"
diff --git a/crates/web/Cargo.toml b/crates/web/Cargo.toml
index fbf7d10..beda2ca 100644
--- a/crates/web/Cargo.toml
+++ b/crates/web/Cargo.toml
@@ -14,7 +14,7 @@ gecko = { path = "../gecko" }
image = { path = "../image", default-features = false }
backend-wgpu = { path = "../backend-wgpu" }
dbglib = { path = "../dbglib", optional = true }
-egui-phosphor = { version = "0.11.0", optional = true }
+egui-phosphor = { version = "0.11.0", optional = true, features = ["fill"] }
wgpu = "28.0.0"
winit = { version = "0.30.13", features = ["rwh_06"] }
egui = "0.33.3"
diff --git a/crates/web/src/debug_ui.rs b/crates/web/src/debug_ui.rs
index 3d8ac05..8f8c036 100644
--- a/crates/web/src/debug_ui.rs
+++ b/crates/web/src/debug_ui.rs
@@ -14,9 +14,11 @@ pub struct DebugState {
pub show_irqs: bool,
pub show_controls: bool,
pub show_callstack: bool,
+ pub show_breakpoints: bool,
pub memory_base: u32,
pub memory_addr_input: String,
pub run_until_addr_input: String,
+ pub breakpoint_addr_input: String,
pub dvd_cover_open: Option<bool>,
}
@@ -36,9 +38,11 @@ impl Default for DebugState {
show_exi: false,
show_irqs: false,
show_callstack: false,
+ show_breakpoints: false,
memory_base: 0x8000_0000,
memory_addr_input: "80000000".to_string(),
run_until_addr_input: String::new(),
+ breakpoint_addr_input: String::new(),
dvd_cover_open: None,
}
}
@@ -72,6 +76,7 @@ impl DebugState {
ui.checkbox(&mut self.show_dvd, "DVD");
ui.checkbox(&mut self.show_exi, "EXI");
ui.checkbox(&mut self.show_irqs, "IRQ");
+ ui.checkbox(&mut self.show_breakpoints, "Breakpoints");
});
});
@@ -82,6 +87,7 @@ impl DebugState {
&emulator.cpu,
&emulator.mmio,
self.symbols.as_ref(),
+ self.debugger.breakpoints(),
);
}
if self.show_callstack {
@@ -140,5 +146,13 @@ impl DebugState {
if self.show_irqs {
dbglib::windows::irq::show_irq(ctx, &mut self.show_irqs, &emulator.cpu, &emulator.pi);
}
+ if self.show_breakpoints {
+ dbglib::windows::breakpoints::show_breakpoints(
+ ctx,
+ &mut self.show_breakpoints,
+ &mut self.debugger,
+ &mut self.breakpoint_addr_input,
+ );
+ }
}
}
diff --git a/crates/web/src/lib.rs b/crates/web/src/lib.rs
index 329f5e4..f73ab5b 100644
--- a/crates/web/src/lib.rs
+++ b/crates/web/src/lib.rs
@@ -200,6 +200,14 @@ impl State {
{
let mut fonts = egui::FontDefinitions::default();
egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular);
+ fonts.font_data.insert(
+ "phosphor-fill".into(),
+ egui_phosphor::Variant::Fill.font_data().into(),
+ );
+ fonts.families.insert(
+ egui::FontFamily::Name("phosphor-fill".into()),
+ vec!["phosphor-fill".into()],
+ );
egui_ctx.set_fonts(fonts);
}
let egui_renderer = egui_wgpu::Renderer::new(&device, surface_format, egui_wgpu::RendererOptions::default());