A GameCube/Wii emulator and debugger written in Rust.
very experimental idle skip and
Layle19a59f36c147
diff --git a/Cargo.toml b/Cargo.tomlindex 6c66e90..4240ff4 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -20,7 +20,7 @@ egui-winit = { git = "https://github.com/ioncodes/egui.git" }[profile.release]lto = "fat"-debug = true+#debug = true[profile.dev]opt-level = 3diff --git a/crates/gekko/src/flipper/gx/draw.rs b/crates/gekko/src/flipper/gx/draw.rsindex c62fb85..8c1c40e 100644--- a/crates/gekko/src/flipper/gx/draw.rs+++ b/crates/gekko/src/flipper/gx/draw.rs@@ -1,5 +1,5 @@-use chapa::BitEnum;use super::regs::{AlphaCompare, BlendMode, ZMode};+use chapa::BitEnum;#[derive(Debug)]pub enum Primitive {diff --git a/crates/gekko/src/gekko.rs b/crates/gekko/src/gekko.rsindex a4cda05..6def58a 100644--- a/crates/gekko/src/gekko.rs+++ b/crates/gekko/src/gekko.rs@@ -22,10 +22,11 @@ pub struct Gekko {pub dsp: Dsp,pub exi: Exi,pub gx: Gx,+ idle_skip: bool,}impl Gekko {- pub fn new(exe: &impl Executable) -> Self {+ pub fn new(exe: &impl Executable, idle_skip: bool) -> Self {let mut mmio = Mmio::new();let data = exe.data();@@ -64,6 +65,7 @@ impl Gekko {dsp: Dsp::new(),exi: Exi::dummy(),gx: Gx::new(),+ idle_skip,}}@@ -94,6 +96,14 @@ impl Gekko {cpu::lut::dispatch(self, instr);self.scheduler.cycles += 1;+ // Idle skip: if the instruction branches to itself, fast-forward to the next event+ // TODO: SUPER EXPERIMENTAL, trying stuff out cause of hazel and vxpm+ if self.idle_skip && self.cpu.nia == self.cpu.cia {+ if let Some(deadline) = self.scheduler.next_event_deadline() {+ self.scheduler.cycles = deadline;+ }+ }+self.cpu.pc = self.cpu.nia;}diff --git a/crates/gekko/src/scheduler.rs b/crates/gekko/src/scheduler.rsindex e5f70ee..df3545b 100644--- a/crates/gekko/src/scheduler.rs+++ b/crates/gekko/src/scheduler.rs@@ -34,4 +34,8 @@ impl Scheduler {None}}++ pub fn next_event_deadline(&self) -> Option<u64> {+ self.events.peek().map(|Reverse((d, _))| *d)+ }}diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rsindex e0a4a96..f537a54 100644--- a/crates/tinyapp/src/main.rs+++ b/crates/tinyapp/src/main.rs@@ -38,7 +38,7 @@ struct State {}impl State {- fn new(window: Arc<Window>, emulator: &Gekko) -> Self {+ fn new(window: Arc<Window>, emulator: &Gekko, present_mode: wgpu::PresentMode) -> Self {let (w, h) = emulator.frame_size();let (w, h) = (w as u32, h as u32);@@ -73,7 +73,7 @@ impl State {format: surface_format,width: size.width.max(1),height: size.height.max(1),- present_mode: wgpu::PresentMode::Immediate,+ present_mode,alpha_mode: surface_caps.alpha_modes[0],view_formats: vec![],desired_maximum_frame_latency: 2,@@ -230,7 +230,7 @@ impl State {.anchor(egui::Align2::RIGHT_TOP, [-8.0, 8.0]).frame(frame).show(&ctx, |ui| {- ui.label(egui::RichText::new(format!("{fps:.1} FPS {native_pct:.1}% native")).monospace());+ ui.label(egui::RichText::new(format!("{fps:.1} FPS {native_pct:.1}%")).monospace());Plot::new("fps_plot").height(60.0).width(180.0)@@ -425,6 +425,7 @@ struct App {emulator: Gekko,window: Option<Arc<Window>>,state: Option<State>,+ present_mode: wgpu::PresentMode,}impl ApplicationHandler for App {@@ -434,7 +435,8 @@ impl ApplicationHandler for App {.create_window(Window::default_attributes().with_title("Gekko")).unwrap(),);- let state = State::new(window.clone(), &self.emulator);++ let state = State::new(window.clone(), &self.emulator, self.present_mode);window.request_redraw();self.window = Some(window);self.state = Some(state);@@ -471,15 +473,23 @@ fn main() {std::process::exit(1);}+ let present_mode = std::env::args()+ .any(|arg| arg == "--immediate")+ .then(|| wgpu::PresentMode::Immediate)+ .unwrap_or(wgpu::PresentMode::Fifo);+ let idle_skip = std::env::args()+ .any(|arg| arg == "--idle-skip");+let rom_data = std::fs::read(&args[1]).expect("failed to read ROM");let dol = Dol::parse(rom_data);- let emulator = Gekko::new(&dol);+ let emulator = Gekko::new(&dol, idle_skip);let event_loop = EventLoop::new().unwrap();let mut app = App {emulator,window: None,state: None,+ present_mode,};event_loop.run_app(&mut app).unwrap();}diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rsindex 5e45f8a..fc69a89 100644--- a/crates/tinyemu/src/main.rs+++ b/crates/tinyemu/src/main.rs@@ -48,7 +48,7 @@ fn main() {let rom_data = std::fs::read(&args.rom).expect("failed to read ROM");let dol = image::Dol::parse(rom_data);- let mut gekko = gekko::gekko::Gekko::new(&dol);+ let mut gekko = gekko::gekko::Gekko::new(&dol, false);let symbols = args.elf.as_ref().map(|path| {let elf_data = std::fs::read(path).expect("failed to read ELF file");