Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

starlet leaves IPC mask on, looks like libogc depends on that

Laylee51f4ec7c4c7
diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rs
index f410d00..64f48c2 100644
--- a/crates/debugger/src/main.rs
+++ b/crates/debugger/src/main.rs
@@ -424,12 +424,18 @@ fn resolve_aspect(arg: &str, is_wii: bool) -> TargetAspect {
}
fn main() {
+ let env_filter = tracing_subscriber::EnvFilter::try_from_default_env()
+ .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"))
+ .add_directive("cranelift_jit=warn".parse().unwrap())
+ .add_directive("cranelift_codegen=warn".parse().unwrap())
+ .add_directive("cranelift_frontend=warn".parse().unwrap())
+ .add_directive("regalloc2=warn".parse().unwrap())
+ .add_directive("wgpu_core=warn".parse().unwrap())
+ .add_directive("wgpu_hal=warn".parse().unwrap())
+ .add_directive("naga=warn".parse().unwrap());
+
tracing_subscriber::fmt()
- .with_env_filter(
- tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
- tracing_subscriber::EnvFilter::new("info,cranelift_jit=warn,cranelift_codegen=warn")
- }),
- )
+ .with_env_filter(env_filter)
.without_time()
.init();
diff --git a/crates/gecko/src/wii.rs b/crates/gecko/src/wii.rs
index 4816111..8e63b19 100644
--- a/crates/gecko/src/wii.rs
+++ b/crates/gecko/src/wii.rs
@@ -45,6 +45,7 @@ impl Wii {
Self::setup_msr_hid(&mut emu);
// No disc / TMD available: default to IOS56, TODO
Self::setup_low_memory_common(&mut emu, ios::ios56());
+ Self::setup_post_ios_handoff(&mut emu);
emu.load_image(exe);
emu
}
@@ -75,6 +76,7 @@ impl Wii {
Self::setup_bats(&mut emu);
Self::setup_msr_hid(&mut emu);
Self::setup_low_memory(&mut emu, dvd.as_ref());
+ Self::setup_post_ios_handoff(&mut emu);
let apploader = *dvd.apploader();
let apploader_entry = apploader.entrypoint.get();
@@ -139,6 +141,11 @@ impl Wii {
emu.gekko.spr.hid4 = 0x8390_0000;
}
+ fn setup_post_ios_handoff(emu: &mut Wii) {
+ // Seems to be required for libogc? I guess Starlet leaves IPC mask on.
+ emu.hollywood.irq.mask = crate::hollywood::regs::Mask::from_raw(0).with_ipc(true);
+ }
+
// Cross referenced with beanwii and Dolphin!!
fn setup_low_memory_common(emu: &mut Wii, imv: &ios::MemoryValues) {
// Ripped from the apploader.
diff --git a/crates/mcp/src/boot.rs b/crates/mcp/src/boot.rs
index 63903fe..3ded10a 100644
--- a/crates/mcp/src/boot.rs
+++ b/crates/mcp/src/boot.rs
@@ -4,6 +4,7 @@ use backend_wgpu::GxRenderer;
use gecko::HostInput;
use gecko::gamecube::GameCube;
use gecko::wii::Wii;
+use image::Dol;
use crate::sink::{Introspection, McpSink};
use crate::state::Backend;
@@ -14,6 +15,36 @@ pub struct BootResult {
pub game_code: String,
}
+fn make_sink(
+ gx: Arc<Mutex<GxRenderer>>,
+ device: wgpu::Device,
+ queue: wgpu::Queue,
+ introspect: Arc<Mutex<Introspection>>,
+) -> Box<McpSink> {
+ Box::new(McpSink {
+ gx,
+ device,
+ queue,
+ introspect,
+ })
+}
+
+fn finalize_wii(mut emu: Wii, dsp_rom: &[u8], coef_rom: &[u8], sink: Box<McpSink>) -> Wii {
+ emu.dsp.load_irom(dsp_rom);
+ emu.dsp.load_coef(coef_rom);
+ emu.render_sink = sink;
+ emu.apply_host_input(&HostInput::wii_neutral());
+ emu
+}
+
+fn finalize_gc(mut emu: GameCube, dsp_rom: &[u8], coef_rom: &[u8], sink: Box<McpSink>) -> GameCube {
+ emu.dsp.load_irom(dsp_rom);
+ emu.dsp.load_coef(coef_rom);
+ emu.render_sink = sink;
+ emu.apply_host_input(&HostInput::gc_connected());
+ emu
+}
+
pub fn boot(
disc_bytes: Vec<u8>,
ipl: &[u8],
@@ -33,26 +64,12 @@ pub fn boot(
.trim_end_matches('\0')
.to_owned();
- let sink = Box::new(McpSink {
- gx,
- device,
- queue,
- introspect,
- });
+ let sink = make_sink(gx, device, queue, introspect);
let backend = if dvd.header().is_wii() {
- let mut emu = Wii::apploader_hle(dvd).build();
- emu.dsp.load_irom(dsp_rom);
- emu.dsp.load_coef(coef_rom);
- emu.render_sink = sink;
- emu.apply_host_input(&HostInput::wii_neutral());
- Backend::Wii(emu)
+ Backend::Wii(finalize_wii(Wii::apploader_hle(dvd).build(), dsp_rom, coef_rom, sink))
} else {
- let mut emu = GameCube::with_ipl(ipl, true);
- emu.dsp.load_irom(dsp_rom);
- emu.dsp.load_coef(coef_rom);
- emu.render_sink = sink;
- emu.apply_host_input(&HostInput::gc_connected());
+ let mut emu = finalize_gc(GameCube::with_ipl(ipl, true), dsp_rom, coef_rom, sink);
emu.insert_dvd(dvd);
Backend::Gc(emu)
};
@@ -63,3 +80,29 @@ pub fn boot(
game_code,
}
}
+
+pub fn boot_dol(
+ dol_bytes: Vec<u8>,
+ wii: bool,
+ dsp_rom: &[u8],
+ coef_rom: &[u8],
+ gx: Arc<Mutex<GxRenderer>>,
+ device: wgpu::Device,
+ queue: wgpu::Queue,
+ introspect: Arc<Mutex<Introspection>>,
+) -> BootResult {
+ let dol = Dol::parse(dol_bytes);
+ let sink = make_sink(gx, device, queue, introspect);
+
+ let backend = if wii {
+ Backend::Wii(finalize_wii(Wii::with_image(&dol), dsp_rom, coef_rom, sink))
+ } else {
+ Backend::Gc(finalize_gc(GameCube::with_image(&dol), dsp_rom, coef_rom, sink))
+ };
+
+ BootResult {
+ backend,
+ game_name: String::new(),
+ game_code: String::new(),
+ }
+}
diff --git a/crates/mcp/src/main.rs b/crates/mcp/src/main.rs
index 9e67e26..5cdcfba 100644
--- a/crates/mcp/src/main.rs
+++ b/crates/mcp/src/main.rs
@@ -16,9 +16,24 @@ use mcp::{boot, worker};
#[derive(Parser, Debug)]
#[command(name = "mcp", about = "MCP server exposing the gecko GameCube/Wii emulator to LLMs")]
struct Cli {
- #[arg(long, value_name = "PATH", help = "Disc image to load on startup (ISO/RVZ/ZIP)")]
+ #[arg(
+ long,
+ value_name = "PATH",
+ help = "Disc image to load on startup (ISO/RVZ/ZIP)",
+ conflicts_with = "dol"
+ )]
dvd: Option<PathBuf>,
+ #[arg(long, value_name = "PATH", help = "DOL homebrew to load on startup")]
+ dol: Option<PathBuf>,
+
+ #[arg(
+ long,
+ help = "Boot the DOL as a Wii executable instead of GameCube",
+ requires = "dol"
+ )]
+ wii: bool,
+
#[arg(long, value_name = "PATH", help = "Override the embedded GameCube IPL")]
ipl: Option<PathBuf>,
@@ -89,9 +104,21 @@ fn main() -> Result<()> {
coef_rom,
});
- if let Some(dvd_path) = cli.dvd.as_ref() {
+ let initial = if let Some(dol_path) = cli.dol.as_ref() {
+ let bytes = std::fs::read(dol_path).with_context(|| format!("read DOL {dol_path:?}"))?;
+ Some(boot::boot_dol(
+ bytes,
+ cli.wii,
+ &shared.dsp_rom,
+ &shared.coef_rom,
+ shared.gx.clone(),
+ shared.device.clone(),
+ shared.queue.clone(),
+ shared.introspect.clone(),
+ ))
+ } else if let Some(dvd_path) = cli.dvd.as_ref() {
let bytes = std::fs::read(dvd_path).with_context(|| format!("read DVD {dvd_path:?}"))?;
- let result = boot::boot(
+ Some(boot::boot(
bytes,
&shared.ipl,
&shared.dsp_rom,
@@ -100,8 +127,12 @@ fn main() -> Result<()> {
shared.device.clone(),
shared.queue.clone(),
shared.introspect.clone(),
- );
+ ))
+ } else {
+ None
+ };
+ if let Some(result) = initial {
let mut s = shared.state.lock().unwrap();
s.backend = Some(result.backend);
s.game_name = result.game_name;