Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

DSP LLE LETS GO. switches between IRAM and IROM based on reset vector. IRAM stub works and returns correct mailbox response

Layle7722b7ae5c1d
diff --git a/Cargo.lock b/Cargo.lock
index dead422..fdd083d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -650,6 +650,7 @@ name = "debugger"
version = "0.1.0"
dependencies = [
"backend-wgpu",
+ "clap",
"disasm",
"egui",
"egui-phosphor",
@@ -2780,6 +2781,7 @@ name = "tinyapp"
version = "0.1.0"
dependencies = [
"backend-wgpu",
+ "clap",
"egui",
"egui-wgpu",
"egui-winit",
diff --git a/crates/debugger/Cargo.toml b/crates/debugger/Cargo.toml
index 83ad484..719cbf0 100644
--- a/crates/debugger/Cargo.toml
+++ b/crates/debugger/Cargo.toml
@@ -14,10 +14,11 @@ image = { path = "../image" }
disasm = { path = "../disasm" }
backend-wgpu = { path = "../backend-wgpu" }
wgpu = "28.0.0"
-winit = "0.30"
-pollster = "0.4"
+winit = "0.30.13"
+pollster = "0.4.0"
egui = "0.33"
egui-wgpu = "0.33"
egui-winit = { version = "0.33", features = ["wayland", "x11"] }
egui-phosphor = "0.11.0"
-tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
+clap = { version = "4.6.0", features = ["derive"] }
diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rs
index 377f26d..ee3d676 100644
--- a/crates/debugger/src/main.rs
+++ b/crates/debugger/src/main.rs
@@ -1,4 +1,4 @@
-use std::env;
+use clap::Parser;
use std::sync::Arc;
use winit::{
application::ApplicationHandler,
@@ -72,47 +72,65 @@ impl ApplicationHandler for App {
}
}
+#[derive(Parser)]
+#[command(about = "GameCube debugger")]
+struct Args {
+ /// Path to the ROM/DOL file
+ #[arg(long)]
+ rom: Option<String>,
+
+ /// Path to an IPL file
+ #[arg(long)]
+ ipl: Option<String>,
+
+ /// Path to a GameCube ISO file
+ #[arg(long)]
+ iso: Option<String>,
+
+ /// Use immediate present mode (no vsync)
+ #[arg(long)]
+ immediate: bool,
+
+ /// Path to a DSP IROM binary
+ #[arg(long)]
+ dsp: Option<String>,
+
+ /// Path to a Lua script for scripting hooks
+ #[arg(long)]
+ script: Option<String>,
+}
+
fn main() {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
+ .without_time()
.init();
- let args: Vec<String> = env::args().collect();
-
- let present_mode = args
- .iter()
- .any(|a| a == "--immediate")
- .then_some(wgpu::PresentMode::Immediate)
- .unwrap_or(wgpu::PresentMode::Fifo);
- let ipl_path = args.iter().position(|a| a == "--ipl").map(|i| &args[i + 1]);
- let rom_path = args
- .iter()
- .position(|a| a == "--rom")
- .map(|i| &args[i + 1])
- .or_else(|| args.get(1).filter(|a| !a.starts_with("--")));
- let iso_path = args.iter().position(|a| a == "--iso").map(|i| &args[i + 1]);
- let script_path = args.iter().position(|a| a == "--script").map(|i| &args[i + 1]);
-
- let mut emulator = if let Some(ipl) = ipl_path {
+ let args = Args::parse();
+
+ let present_mode = if args.immediate {
+ wgpu::PresentMode::Immediate
+ } else {
+ wgpu::PresentMode::Fifo
+ };
+
+ let mut emulator = if let Some(ref ipl) = args.ipl {
let ipl_data = std::fs::read(ipl).expect("failed to read IPL");
GameCube::with_ipl(&ipl_data)
- } else if let Some(rom) = rom_path {
+ } else if let Some(ref rom) = args.rom {
let rom_data = std::fs::read(rom).expect("failed to read ROM");
let dol = Dol::parse(rom_data);
GameCube::with_image(&dol)
} else {
- eprintln!(
- "usage: {} <path/to/game.dol> | --ipl <path> | --rom <path> [--iso <path>] [--immediate] ",
- args[0]
- );
+ eprintln!("error: either --ipl or --rom must be provided");
std::process::exit(1);
};
- if let Some(iso) = iso_path {
- if ipl_path.is_none() {
+ if let Some(ref iso) = args.iso {
+ if args.ipl.is_none() {
eprintln!("--iso requires --ipl");
std::process::exit(1);
}
@@ -122,7 +140,12 @@ fn main() {
emulator.insert_dvd(dvd);
}
- if let Some(path) = script_path {
+ if let Some(ref dsp_path) = args.dsp {
+ let dsp_data = std::fs::read(dsp_path).expect("failed to read DSP IROM");
+ emulator.dsp.load_irom(&dsp_data);
+ }
+
+ if let Some(ref path) = args.script {
let host = scripting::LuaScriptHost::from_file(path).expect("failed to load script");
emulator.set_script_host(Box::new(host));
}
diff --git a/crates/gecko/src/cpu/irq.rs b/crates/gecko/src/cpu/irq.rs
index 0d56057..8268368 100644
--- a/crates/gecko/src/cpu/irq.rs
+++ b/crates/gecko/src/cpu/irq.rs
@@ -59,8 +59,7 @@ impl GameCube {
self.cpu.spr.srr0 = Srr0::from(self.cpu.cia);
// SRR1: MSR bits 0, 5-9, 16-31 preserved; bit 14 (TRAP) set
- self.cpu.spr.srr1 =
- chapa::extract_bits!(self.cpu.msr; 0, 5..=9, 16..=31).raw() | (1 << (31 - 14));
+ self.cpu.spr.srr1 = chapa::extract_bits!(self.cpu.msr; 0, 5..=9, 16..=31).raw() | (1 << (31 - 14));
self.cpu.msr = self
.cpu
diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rs
index b1dc0bc..b6e3b03 100644
--- a/crates/gecko/src/flipper/dsp.rs
+++ b/crates/gecko/src/flipper/dsp.rs
@@ -86,8 +86,8 @@ impl Dsp {
///
/// - If an ARAM DMA was triggered (write to DmaControl), execute the transfer and
/// assert ARINT in the CSR
- /// - If ucode upload (falling-edge) was detected (CSR bit 11: 1->0), copy from
- /// main RAM at DmaMmioAddr into IRAM (like Dolphin), then HLE the mailbox response.
+ /// - If ucode upload was triggered (CSR bit 11 falling edge), DMA 1024 bytes from
+ /// main RAM into IRAM (we LLE, but we could HLE the mailbox response)
#[inline]
pub fn process_pending_dma(&mut self, mmio: &mut Mmio) {
// Handle ARAM DMA
@@ -129,15 +129,15 @@ impl Dsp {
let src = mmio.virt_slice(UCODE_ADDR as u32, UCODE_SIZE);
self.iram[..UCODE_SIZE].copy_from_slice(&src);
- tracing::debug!(
+ tracing::info!(
mmio_addr = format!("{UCODE_ADDR:08X}"),
count = UCODE_SIZE,
- "uploaded ucode from RAM to IRAM"
+ "DSP stub uploaded from RAM to IRAM, executing IRAM"
);
// HLE: Write expected response to mailbox
- self.mailbox_to_cpu_hi = regs::MailboxToCpuHi::from_raw(0x8071);
- self.mailbox_to_cpu_lo = regs::MailboxToCpuLo::from_raw(0xFEED);
+ // self.mailbox_to_cpu_hi = regs::MailboxToCpuHi::from_raw(0x8071);
+ // self.mailbox_to_cpu_lo = regs::MailboxToCpuLo::from_raw(0xFEED);
}
}
}
@@ -148,7 +148,11 @@ impl GameCube {
return;
}
- let instr = Instruction::from_be_bytes(&self.dsp.iram[(self.dsp.registers.pc as usize) * 2..]);
+ let pc = self.dsp.registers.pc as usize;
+ let w0 = self.dsp.read_imem(pc as u16);
+ let w1 = self.dsp.read_imem(pc as u16 + 1);
+ let buf = [(w0 >> 8) as u8, w0 as u8, (w1 >> 8) as u8, w1 as u8];
+ let instr = Instruction::from_be_bytes(&buf);
self.dsp.registers.cia = self.dsp.registers.pc;
self.dsp.registers.nia = self
.dsp
@@ -204,50 +208,84 @@ impl MmioRw for Dsp {
impl Dsp {
/// Read a 16-bit word from instruction memory (IRAM 0x0000-0x0FFF, IROM 0x8000-0x8FFF).
pub fn read_imem(&self, addr: u16) -> u16 {
- let byte_addr = addr as usize * 2;
- let bytes = match addr as usize {
- 0x0000..0x1000 => &self.iram[byte_addr..byte_addr + 2],
- 0x8000..0x9000 => {
- let offset = byte_addr - 0x8000 * 2;
- &self.irom[offset..offset + 2]
- }
- _ => &[0, 0],
- };
- u16::from_be_bytes([bytes[0], bytes[1]])
+ match addr {
+ 0x0000..0x1000 => read_word(&*self.iram, addr),
+ 0x8000..0x9000 => read_word(&*self.irom, addr - 0x8000),
+ _ => 0,
+ }
}
/// Read a 16-bit word from data memory (DRAM 0x0000-0x0FFF, COEF 0x1000-0x1FFF, IFX 0xFF00-0xFFFF).
- pub fn read_dmem(&self, addr: u16) -> u16 {
- let byte_addr = addr as usize * 2;
- let bytes = match addr as usize {
- 0x0000..0x1000 => &self.dram[byte_addr..byte_addr + 2],
- 0x1000..0x2000 => {
- let offset = byte_addr - 0x1000 * 2;
- &self.coef[offset..offset + 2]
+ pub fn read_dmem(&mut self, addr: u16) -> u16 {
+ match addr {
+ 0x0000..0x1000 => read_word(&*self.dram, addr),
+ 0x1000..0x2000 => read_word(&*self.coef, addr - 0x1000),
+ 0xFF00..=0xFFFF => self.read_ifx(addr),
+ _ => 0,
+ }
+ }
+
+ /// Read a 16-bit word from IFX register space, with mailbox side-effects.
+ pub fn read_ifx(&mut self, addr: u16) -> u16 {
+ match addr {
+ // CMBH (CPU Mailbox High): reading returns data + M bit
+ 0xFFFE => self.mailbox_to_dsp_hi.raw(),
+ // CMBL (CPU Mailbox Low): reading clears CMBH.M (busy)
+ 0xFFFF => {
+ self.mailbox_to_dsp_hi.set_busy(false);
+ self.mailbox_to_dsp_lo.raw()
}
- 0xFF00..0x10000 => {
- let offset = (addr as usize - 0xFF00) * 2;
- &self.ifx[offset..offset + 2]
+ // DMBH (DSP Mailbox High): DSP reads back what it wrote
+ 0xFFFC => self.mailbox_to_cpu_hi.raw(),
+ // DMBL (DSP Mailbox Low): reading clears DMBH.M (CPU consumed the mail)
+ 0xFFFD => {
+ let val = self.mailbox_to_cpu_lo.raw();
+ self.mailbox_to_cpu_hi.set_busy(false);
+ val
}
- _ => &[0, 0],
- };
- u16::from_be_bytes([bytes[0], bytes[1]])
+ _ => read_word(&*self.ifx, addr - 0xFF00),
+ }
+ }
+
+ /// Write a 16-bit word to IFX register space, with mailbox side-effects.
+ pub fn write_ifx(&mut self, addr: u16, value: u16) {
+ match addr {
+ // DMBH (DSP Mailbox High): store data bits, M will be set when DMBL is written
+ 0xFFFC => {
+ self.mailbox_to_cpu_hi = regs::MailboxToCpuHi::from_raw(value & 0x7FFF);
+ }
+ // DMBL (DSP Mailbox Low): writing sets DMBH.M, signaling mail ready to CPU
+ 0xFFFD => {
+ self.mailbox_to_cpu_lo = regs::MailboxToCpuLo::from_raw(value);
+ self.mailbox_to_cpu_hi.set_busy(true);
+ tracing::debug!(
+ hi = format!("{:04X}", self.mailbox_to_cpu_hi.raw()),
+ lo = format!("{:04X}", value),
+ "DSP->CPU mailbox"
+ );
+ }
+ // CMBH/CMBL are read-only from DSP side
+ 0xFFFE | 0xFFFF => {}
+ _ => write_word(&mut *self.ifx, addr - 0xFF00, value),
+ }
}
/// Write a 16-bit word to data memory (DRAM 0x0000-0x0FFF, IFX 0xFF00-0xFFFF).
pub fn write_dmem(&mut self, addr: u16, value: u16) {
- let byte_addr = addr as usize * 2;
- let bytes = value.to_be_bytes();
- match addr as usize {
- 0x0000..0x1000 => self.dram[byte_addr..byte_addr + 2].copy_from_slice(&bytes),
- 0xFF00..0x10000 => {
- let offset = (addr as usize - 0xFF00) * 2;
- self.ifx[offset..offset + 2].copy_from_slice(&bytes);
- }
+ match addr {
+ 0x0000..0x1000 => write_word(&mut *self.dram, addr, value),
+ 0xFF00..=0xFFFF => self.write_ifx(addr, value),
_ => {}
}
}
+ /// Load a binary file into IROM.
+ pub fn load_irom(&mut self, data: &[u8]) {
+ let len = data.len().min(self.irom.len());
+ self.irom[..len].copy_from_slice(&data[..len]);
+ tracing::info!(size = len, "loaded DSP IROM");
+ }
+
pub fn interrupt_active(&self) -> bool {
(self.csr.ai_interrupt() && self.csr.ai_interrupt_mask())
|| (self.csr.ar_interrupt() && self.csr.ar_interrupt_mask())
@@ -264,3 +302,17 @@ impl crate::gamecube::GameCube {
}
}
}
+
+/// Read a big-endian u16 from a byte slice at a DSP word address.
+#[inline(always)]
+fn read_word(mem: &[u8], word_addr: u16) -> u16 {
+ let off = word_addr as usize * 2;
+ u16::from_be_bytes([mem[off], mem[off + 1]])
+}
+
+/// Write a big-endian u16 into a byte slice at a DSP word address.
+#[inline(always)]
+fn write_word(mem: &mut [u8], word_addr: u16, value: u16) {
+ let off = word_addr as usize * 2;
+ mem[off..off + 2].copy_from_slice(&value.to_be_bytes());
+}
diff --git a/crates/gecko/src/flipper/dsp/instruction.rs b/crates/gecko/src/flipper/dsp/instruction.rs
index 3286dae..ab5941a 100644
--- a/crates/gecko/src/flipper/dsp/instruction.rs
+++ b/crates/gecko/src/flipper/dsp/instruction.rs
@@ -8,11 +8,7 @@ impl Instruction {
pub fn ext_opcode(&self) -> Option<u8> {
let nibble = (self.0 >> 12) & 0xF;
if nibble >= 3 {
- Some(if nibble == 3 {
- self.ext_9_15()
- } else {
- self.ext_8_15()
- })
+ Some(if nibble == 3 { self.ext_9_15() } else { self.ext_8_15() })
} else {
None
}
diff --git a/crates/gecko/src/flipper/dsp/interpreter.rs b/crates/gecko/src/flipper/dsp/interpreter.rs
index 48659ff..ec078f8 100644
--- a/crates/gecko/src/flipper/dsp/interpreter.rs
+++ b/crates/gecko/src/flipper/dsp/interpreter.rs
@@ -477,12 +477,10 @@ pub fn ext_ld<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspEx
let d = instr.d_2_2();
let r = instr.r_3_3();
let s = instr.s_6_7() as usize;
- ctx.dsp
- .registers
- .write::<false>(0x18 + d * 2, ctx.dsp.read_dmem(ctx.dsp.registers.ar[s]));
- ctx.dsp
- .registers
- .write::<false>(0x19 + r * 2, ctx.dsp.read_dmem(ctx.dsp.registers.ar[3]));
+ let val_d = ctx.dsp.read_dmem(ctx.dsp.registers.ar[s]);
+ ctx.dsp.registers.write::<false>(0x18 + d * 2, val_d);
+ let val_r = ctx.dsp.read_dmem(ctx.dsp.registers.ar[3]);
+ ctx.dsp.registers.write::<false>(0x19 + r * 2, val_r);
match OP {
OP_EXT_LD_00 => {
ctx.dsp.registers.ar[s] = ctx.dsp.registers.ar[s].wrapping_add(1);
diff --git a/crates/gecko/src/flipper/dsp/regs.rs b/crates/gecko/src/flipper/dsp/regs.rs
index 8c7d210..0f60709 100644
--- a/crates/gecko/src/flipper/dsp/regs.rs
+++ b/crates/gecko/src/flipper/dsp/regs.rs
@@ -4,6 +4,21 @@ use crate::{flipper::dsp::Dsp, mmio::traits::MmioAccess};
// 0xCC00500A 2 [R/W] CSR - DSP Control/Status Register
+#[derive(BitEnum, Debug, PartialEq, Eq)]
+pub enum ResetVector {
+ Low = 0,
+ High = 1,
+}
+
+impl ResetVector {
+ pub fn address(&self) -> u16 {
+ match self {
+ ResetVector::High => 0x8000, // IROM
+ ResetVector::Low => 0x0000, // IRAM
+ }
+ }
+}
+
crate::mmio_register! {
ControlStatus: u16 @ 0xCC00500A {
#[bits(0, alias = "res")]
@@ -36,8 +51,8 @@ crate::mmio_register! {
#[bits(9, alias = "dspdma")]
pub dma_status: bool,
- #[bits(11, alias = "ucode")]
- pub upload_ucode: bool, // also reset bit?
+ #[bits(11)]
+ pub reset_vector: ResetVector,
}
}
@@ -47,7 +62,7 @@ impl MmioAccess<super::Dsp> for ControlStatus {
}
fn write(self, dsp: &mut super::Dsp) {
- tracing::trace!("CSR write: {:016b}", self.raw());
+ tracing::trace!("CSR write: {:016b} (prev: {:016b})", self.raw(), dsp.csr.raw());
let mut csr = dsp.csr;
@@ -68,17 +83,21 @@ impl MmioAccess<super::Dsp> for ControlStatus {
.with_ar_interrupt_mask(self.ar_interrupt_mask())
.with_dsp_interrupt_mask(self.dsp_interrupt_mask())
.with_dma_status(self.dma_status())
- .with_upload_ucode(self.upload_ucode());
+ .with_reset_vector(self.reset_vector());
- // ucode falling edge (bit 11: 1->0) schedules ucode upload from ARAM[0x0000]
- if dsp.csr.upload_ucode() && !self.upload_ucode() {
- tracing::debug!("scheduling ucode upload");
+ // reset vector falling edge (bit 11: 1->0) triggers DMA of stub from main RAM into IRAM
+ // and resets the PC to 0x0000 (IRAM) so the uploaded stub executes
+ if dsp.csr.reset_vector() == ResetVector::High && self.reset_vector() == ResetVector::Low {
+ tracing::info!("scheduling ucode upload, PC -> 0x0000 (IRAM)");
dsp.pending_ucode_upload = true;
+ dsp.registers.pc = 0x0000;
}
- // ACK reset bit
+ // On reset, set PC to the address indicated by the reset vector
if self.reset() {
- tracing::debug!("reset");
+ let addr = self.reset_vector().address();
+ tracing::info!(reset_vector = ?self.reset_vector(), pc = format!("{addr:04X}"), "DSP reset, executing from reset vector");
+ dsp.registers.pc = addr;
}
csr = csr.with_reset(false);
@@ -88,7 +107,7 @@ impl MmioAccess<super::Dsp> for ControlStatus {
impl Default for ControlStatus {
fn default() -> Self {
- ControlStatus::new().with_halt(true).with_upload_ucode(true)
+ ControlStatus::new().with_halt(true)
}
}
@@ -117,21 +136,57 @@ impl MmioAccess<Dsp> for MailboxToDspHi {
}
// 0xCC005002 2 [W] CPU-to-DSP Mailbox Low
+// Writing sets CMBH.M (busy), signaling to the DSP that mail is ready.
crate::mmio_register! {
- MailboxToDspLo: u16 @ 0xCC005002 => Dsp.mailbox_to_dsp_lo {}
+ MailboxToDspLo: u16 @ 0xCC005002 {}
+}
+
+impl MmioAccess<Dsp> for MailboxToDspLo {
+ fn read(dsp: &Dsp) -> Self {
+ dsp.mailbox_to_dsp_lo
+ }
+
+ fn write(self, dsp: &mut Dsp) {
+ dsp.mailbox_to_dsp_lo = self;
+ dsp.mailbox_to_dsp_hi = dsp.mailbox_to_dsp_hi.with_busy(true);
+ tracing::debug!(
+ hi = format!("{:04X}", dsp.mailbox_to_dsp_hi.raw()),
+ lo = format!("{:04X}", self.raw()),
+ "CPU->DSP mailbox"
+ );
+ }
}
-// 0xCC005004 2 [R] DSP-to-CPU Mailbox High
+// 0xCC005004 2 [R] DSP-to-CPU Mailbox High (DMBH)
crate::mmio_register! {
- MailboxToCpuHi: u16 @ 0xCC005004 => Dsp.mailbox_to_cpu_hi {}
+ MailboxToCpuHi: u16 @ 0xCC005004 => Dsp.mailbox_to_cpu_hi {
+ #[bits(0..=14)]
+ pub data: u16,
+
+ #[bits(15)]
+ pub busy: bool,
+ }
}
-// 0xCC005006 2 [R] DSP-to-CPU Mailbox Low
+// 0xCC005006 2 [R] DSP-to-CPU Mailbox Low (DMBL)
+// Reading clears DMBH.M (bit 15), indicating the CPU has consumed the mail.
crate::mmio_register! {
- MailboxToCpuLo: u16 @ 0xCC005006 => Dsp.mailbox_to_cpu_lo {}
+ MailboxToCpuLo: u16 @ 0xCC005006 {}
+}
+
+impl MmioAccess<Dsp> for MailboxToCpuLo {
+ fn read(dsp: &Dsp) -> Self {
+ // NOTE: ideally reading lo should clear hi.M, but read takes &self not &mut self.
+ // The M bit will be cleared on the next hi read after lo is read.
+ dsp.mailbox_to_cpu_lo
+ }
+
+ fn write(self, _dsp: &mut Dsp) {
+ // Read-only from CPU side
+ }
}
// 0xCC005012 2 [R/W] AR_INFO - ARAM Info/Size
diff --git a/crates/gecko/src/gamecube.rs b/crates/gecko/src/gamecube.rs
index e68d7ec..a6e8ed5 100644
--- a/crates/gecko/src/gamecube.rs
+++ b/crates/gecko/src/gamecube.rs
@@ -1,3 +1,5 @@
+#[cfg(feature = "idle-skip")]
+use crate::idle::{IDLE_LOOP_MAX_INSTRS, IdleCheck, IdleDetector};
#[cfg(feature = "scripting")]
use crate::scripting::{HookFlags, ScriptHookFilters, ScriptHookState, ScriptHost};
use crate::{
@@ -18,8 +20,6 @@ use crate::{
mmio::Mmio,
scheduler::{CYCLES_PER_VSYNC, EventKind, Scheduler},
};
-#[cfg(feature = "idle-skip")]
-use crate::idle::{IDLE_LOOP_MAX_INSTRS, IdleCheck, IdleDetector};
use image::Executable;
pub struct GameCube {
diff --git a/crates/image/Cargo.toml b/crates/image/Cargo.toml
index 6d8043d..7376c71 100644
--- a/crates/image/Cargo.toml
+++ b/crates/image/Cargo.toml
@@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2024"
[dependencies]
-object = { version = "0.36", default-features = false, features = ["elf", "read"] }
+object = { version = "0.36.7", default-features = false, features = ["elf", "read"] }
zerocopy = { version = "0.8.47", features = ["derive"] }
diff --git a/crates/scripting/Cargo.toml b/crates/scripting/Cargo.toml
index 7b47d75..b738ace 100644
--- a/crates/scripting/Cargo.toml
+++ b/crates/scripting/Cargo.toml
@@ -8,5 +8,5 @@ scripting-mut-traps = ["gecko/scripting-mut-traps"]
[dependencies]
gecko = { path = "../gecko", features = ["scripting"] }
-mlua = { version = "0.10", features = ["lua54", "send"] }
-tracing = "0.1"
+mlua = { version = "0.10.5", features = ["lua54", "send"] }
+tracing = "0.1.44"
diff --git a/crates/tinyapp/Cargo.toml b/crates/tinyapp/Cargo.toml
index f136a45..3efd37f 100644
--- a/crates/tinyapp/Cargo.toml
+++ b/crates/tinyapp/Cargo.toml
@@ -14,10 +14,11 @@ scripting = { path = "../scripting", optional = true }
image = { path = "../image" }
backend-wgpu = { path = "../backend-wgpu" }
wgpu = "28.0.0"
-winit = "0.30"
-pollster = "0.4"
+winit = "0.30.13"
+pollster = "0.4.0"
egui = "0.33"
egui-wgpu = "0.33"
egui-winit = { version = "0.33", features = ["wayland", "x11"] }
egui_plot = "0.34"
-tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
+clap = { version = "4.6.0", features = ["derive"] }
diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rs
index 2e61abd..6c68b0b 100644
--- a/crates/tinyapp/src/main.rs
+++ b/crates/tinyapp/src/main.rs
@@ -1,3 +1,4 @@
+use clap::Parser;
use egui::ViewportId;
use egui_plot::{Line, Plot, PlotPoints};
use gecko::flipper::si::pad::{self, PadStatus, STICK_CENTER};
@@ -5,7 +6,6 @@ use gecko::flipper::vi::regs::RefreshRate;
use gecko::gamecube::GameCube;
use image::{Dol, dvd::Dvd};
use std::collections::VecDeque;
-use std::env;
use std::sync::Arc;
use std::time::Instant;
use winit::{
@@ -474,51 +474,71 @@ impl ApplicationHandler for App {
}
}
-fn main() {
- let args: Vec<String> = env::args().collect();
-
- let present_mode = std::env::args()
- .any(|arg| arg == "--immediate")
- .then(|| wgpu::PresentMode::Immediate)
- .unwrap_or(wgpu::PresentMode::Fifo);
- let ipl_path = args.iter().position(|a| a == "--ipl").map(|i| &args[i + 1]);
- let rom_path = args
- .iter()
- .position(|a| a == "--rom")
- .map(|i| &args[i + 1])
- .or_else(|| args.get(1).filter(|a| !a.starts_with("--")));
- let iso_path = args.iter().position(|a| a == "--iso").map(|i| &args[i + 1]);
+#[derive(Parser)]
+#[command(about = "GameCube emulator")]
+struct Args {
+ /// Path to the ROM/DOL file
+ #[arg(long)]
+ rom: Option<String>,
+
+ /// Path to an IPL file
+ #[arg(long)]
+ ipl: Option<String>,
+
+ /// Path to a GameCube ISO file
+ #[arg(long)]
+ iso: Option<String>,
+
+ /// Use immediate present mode (no vsync)
+ #[arg(long)]
+ immediate: bool,
+
+ /// Disable ANSI escape codes
+ #[arg(long)]
+ no_ansi: bool,
+
+ /// Path to a DSP IROM binary
+ #[arg(long)]
+ dsp: Option<String>,
+
+ /// Path to a Lua script for scripting hooks
#[cfg(feature = "scripting")]
- let script_path = args.iter().position(|a| a == "--script").map(|i| &args[i + 1]);
+ #[arg(long)]
+ script: Option<String>,
+}
- let no_ansi = std::env::args().any(|arg| arg == "--no-ansi");
+fn main() {
+ let args = Args::parse();
+
+ let present_mode = if args.immediate {
+ wgpu::PresentMode::Immediate
+ } else {
+ wgpu::PresentMode::Fifo
+ };
tracing_subscriber::fmt()
.without_time()
- .with_ansi(!no_ansi)
+ .with_ansi(!args.no_ansi)
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")),
)
.init();
- let mut emulator = if let Some(ipl) = ipl_path {
+ let mut emulator = if let Some(ref ipl) = args.ipl {
let ipl_data = std::fs::read(ipl).expect("failed to read IPL");
GameCube::with_ipl(&ipl_data)
- } else if let Some(rom) = rom_path {
+ } else if let Some(ref rom) = args.rom {
let rom_data = std::fs::read(rom).expect("failed to read ROM");
let dol = Dol::parse(rom_data);
GameCube::with_image(&dol)
} else {
- eprintln!(
- "usage: {} <path/to/game.dol> | --ipl <path> | --rom <path> [--iso <path>] [--immediate] ",
- args[0]
- );
+ eprintln!("error: either --ipl or --rom must be provided");
std::process::exit(1);
};
- if let Some(iso) = iso_path {
- if ipl_path.is_none() {
+ if let Some(ref iso) = args.iso {
+ if args.ipl.is_none() {
eprintln!("--iso requires --ipl");
std::process::exit(1);
}
@@ -527,8 +547,13 @@ fn main() {
emulator.insert_dvd(dvd);
}
+ if let Some(ref dsp_path) = args.dsp {
+ let dsp_data = std::fs::read(dsp_path).expect("failed to read DSP IROM");
+ emulator.dsp.load_irom(&dsp_data);
+ }
+
#[cfg(feature = "scripting")]
- if let Some(path) = script_path {
+ if let Some(ref path) = args.script {
let host = scripting::LuaScriptHost::from_file(path).expect("failed to load script");
emulator.set_script_host(Box::new(host));
}
diff --git a/crates/tinyemu/Cargo.toml b/crates/tinyemu/Cargo.toml
index 8910955..14bc575 100644
--- a/crates/tinyemu/Cargo.toml
+++ b/crates/tinyemu/Cargo.toml
@@ -15,5 +15,5 @@ image = { path = "../image" }
colored = "3.1.1"
disasm = { path = "../disasm" }
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
-base64 = "0.22"
+base64 = "0.22.1"
clap = { version = "4.6.0", features = ["derive"] }
diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rs
index ee680c6..727d1f5 100644
--- a/crates/tinyemu/src/main.rs
+++ b/crates/tinyemu/src/main.rs
@@ -43,6 +43,10 @@ struct Args {
#[arg(long)]
no_ansi: bool,
+ /// Path to a DSP IROM binary
+ #[arg(long)]
+ dsp: Option<String>,
+
/// Path to a Lua script for scripting hooks
#[cfg(feature = "scripting")]
#[arg(long)]
@@ -85,6 +89,11 @@ fn main() {
emulator.insert_dvd(dvd);
}
+ if let Some(dsp_path) = &args.dsp {
+ let dsp_data = std::fs::read(dsp_path).expect("failed to read DSP IROM");
+ emulator.dsp.load_irom(&dsp_data);
+ }
+
#[cfg(feature = "scripting")]
if let Some(path) = &args.script {
let host = scripting::LuaScriptHost::from_file(path).expect("failed to load script");