A GameCube/Wii emulator and debugger written in Rust.
dvd cover control in debugger + some lua scripts from yesterday
Layle3f9fc504dbdf
diff --git a/Cargo.lock b/Cargo.lockindex 701deaa..edef5df 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -652,6 +652,7 @@ dependencies = ["image 0.1.0","pollster","scripting",+ "tracing-subscriber","wgpu","winit",]diff --git a/crates/debugger/Cargo.toml b/crates/debugger/Cargo.tomlindex 1c21791..26512da 100644--- a/crates/debugger/Cargo.toml+++ b/crates/debugger/Cargo.toml@@ -19,3 +19,4 @@ egui = "0.33"egui-wgpu = "0.33"egui-winit = { version = "0.33", features = ["wayland", "x11"] }egui_material_icons = "0.5.0"+tracing-subscriber = { version = "0.3", features = ["env-filter"] }diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rsindex aeab261..34071c9 100644--- a/crates/debugger/src/debugger.rs+++ b/crates/debugger/src/debugger.rs@@ -18,6 +18,7 @@ pub struct DebuggerUi {pub memory_base: u32,pub memory_addr_input: String,pub run_until_addr_input: String,+ pub dvd_cover_open: Option<bool>,}impl Default for DebuggerUi {@@ -33,6 +34,7 @@ impl Default for DebuggerUi {memory_base: 0x8000_0000,memory_addr_input: "80000000".to_string(),run_until_addr_input: String::new(),+ dvd_cover_open: None,}}}diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rsindex 17248dd..e4c2dc6 100644--- a/crates/debugger/src/main.rs+++ b/crates/debugger/src/main.rs@@ -73,6 +73,13 @@ impl ApplicationHandler for App {}fn main() {+ tracing_subscriber::fmt()+ .with_env_filter(+ tracing_subscriber::EnvFilter::try_from_default_env()+ .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),+ )+ .init();+let args: Vec<String> = env::args().collect();let present_mode = argsdiff --git a/crates/debugger/src/render.rs b/crates/debugger/src/render.rsindex fefc0b8..47c9da3 100644--- a/crates/debugger/src/render.rs+++ b/crates/debugger/src/render.rs@@ -174,6 +174,14 @@ impl RenderState {}pub fn render(&mut self, emulator: &mut Gekko, debugger_ui: &mut DebuggerUi, window: &Window) {+ if let Some(open) = debugger_ui.dvd_cover_open.take() {+ if open {+ emulator.open_cover();+ } else {+ emulator.close_cover();+ }+ }+match debugger_ui.emulator_state {EmulatorState::Running => emulator.run_until_vsync(),EmulatorState::Step => {@@ -277,6 +285,7 @@ impl RenderState {&mut debugger_ui.show_controls,&mut debugger_ui.emulator_state,&mut debugger_ui.run_until_addr_input,+ &mut debugger_ui.dvd_cover_open,);}if debugger_ui.show_gx_state {diff --git a/crates/debugger/src/windows/controls.rs b/crates/debugger/src/windows/controls.rsindex 9782472..0e93b08 100644--- a/crates/debugger/src/windows/controls.rs+++ b/crates/debugger/src/windows/controls.rs@@ -3,7 +3,13 @@ use egui_material_icons::icons;use crate::debugger::EmulatorState;-pub fn show_controls(ctx: &Context, open: &mut bool, state: &mut EmulatorState, run_until_addr_input: &mut String) {+pub fn show_controls(+ ctx: &Context,+ open: &mut bool,+ state: &mut EmulatorState,+ run_until_addr_input: &mut String,+ dvd_cover_open: &mut Option<bool>,+) {egui::Window::new("Controls").open(open).resizable(false)@@ -72,5 +78,21 @@ pub fn show_controls(ctx: &Context, open: &mut bool, state: &mut EmulatorState,}}});++ ui.separator();++ if ui+ .add(egui::Button::new(format!("{} Open Cover", icons::ICON_EJECT)).min_size(btn_size))+ .clicked()+ {+ *dvd_cover_open = Some(true);+ }++ if ui+ .add(egui::Button::new(format!("{} Close Cover", icons::ICON_DISC_FULL)).min_size(btn_size))+ .clicked()+ {+ *dvd_cover_open = Some(false);+ }});}diff --git a/crates/gekko/src/flipper/di.rs b/crates/gekko/src/flipper/di.rsindex 98ad330..64a2789 100644--- a/crates/gekko/src/flipper/di.rs+++ b/crates/gekko/src/flipper/di.rs@@ -79,4 +79,10 @@ impl crate::gekko::Gekko {self.di.cover = self.di.cover.with_cover_interrupt(true).with_cover_status(true);self.check_di_interrupts();}++ pub fn close_cover(&mut self) {+ tracing::debug!("DVD drive cover closed");+ self.di.cover = self.di.cover.with_cover_status(false);+ self.check_di_interrupts();+ }}diff --git a/crates/gekko/src/flipper/pi/regs.rs b/crates/gekko/src/flipper/pi/regs.rsindex 14813e3..86e3525 100644--- a/crates/gekko/src/flipper/pi/regs.rs+++ b/crates/gekko/src/flipper/pi/regs.rs@@ -131,7 +131,7 @@ impl crate::mmio::traits::MmioAccess<Pi> for ResetCode {}fn write(self, _pi: &mut Pi) {- tracing::warn!("resetting console???");+ tracing::warn!("TODO: reset DVD");}}diff --git a/scripts/dvd_timecheck.lua b/scripts/dvd_timecheck.luanew file mode 100644index 0000000..1f46e37--- /dev/null+++ b/scripts/dvd_timecheck.lua@@ -0,0 +1,14 @@+local function timebase_log(emu)+ local r3 = emu:gpr(3)+ local r4 = emu:gpr(4)+ local r9 = emu:gpr(9)+ local r10 = emu:gpr(10)+ log(string.format("[timebase] result=%08X time=%08X ref1=%08X ref2=%08X taken=%s",+ r3, r4, r9, r10, r3 ~= 0 and "yes" or "no"))+end++traps = {+ cpu_pre = {+ [0x81300BD8] = timebase_log,+ }+}\ No newline at end of filediff --git a/scripts/example.lua b/scripts/example.luanew file mode 100644index 0000000..eb1c349--- /dev/null+++ b/scripts/example.lua@@ -0,0 +1,11 @@+local function on_os_get_system_time(emu)+ local tbu = emu:gpr(3)+ local tbl = emu:gpr(4)+ log(string.format("[OSGetSystemTime] tbu=%08X tbl=%08X", tbu, tbl))+end++traps = {+ cpu_pre = {+ [0x8133949C] = on_os_get_system_time,+ },+}\ No newline at end of filediff --git a/scripts/template.lua b/scripts/template.luanew file mode 100644index 0000000..6b7cea3--- /dev/null+++ b/scripts/template.lua@@ -0,0 +1,70 @@+local function on_cpu_pre(emu)+ -- inspect CPU state+end++local function on_cpu_post(emu)+ -- inspect results after instruction+end++local function on_bus_read_pre(emu, virt_addr, phys_addr, size)+ -- inspect read request+ -- return nil to keep the normal read+ -- return 0x12345678 to override the read value+ return nil+end++local function on_bus_read_post(emu, virt_addr, phys_addr, size, value)+ -- inspect completed read+end++local function on_bus_write_pre(emu, virt_addr, phys_addr, size, value)+ -- inspect write request+ -- return value to keep it unchanged+ -- return another integer to override it+ return value+end++local function on_bus_write_post(emu, virt_addr, phys_addr, size, value)+ -- inspect completed write+end++traps = {+ cpu_pre = {+ [0x00000000] = on_cpu_pre,+ },+ cpu_post = {+ [0x00000000] = on_cpu_post,+ },+ bus_read_pre = {+ virt = {+ [0x00000000] = on_bus_read_pre,+ },+ phys = {+ [0x00000000] = on_bus_read_pre,+ },+ },+ bus_read_post = {+ virt = {+ [0x00000000] = on_bus_read_post,+ },+ phys = {+ [0x00000000] = on_bus_read_post,+ },+ },+ bus_write_pre = {+ virt = {+ [0x00000000] = on_bus_write_pre,+ },+ phys = {+ [0x00000000] = on_bus_write_pre,+ },+ },+ bus_write_post = {+ virt = {+ [0x00000000] = on_bus_write_post,+ },+ phys = {+ [0x00000000] = on_bus_write_post,+ },+ },+}