A GameCube/Wii emulator and debugger written in Rust.
propagate aspect ratio to SYSCONF for Wii. fixes alignment issues in games like Epic Mickey
Layle744dd379924a
diff --git a/.gitignore b/.gitignoreindex 57877cd..683aba6 100644--- a/.gitignore+++ b/.gitignore@@ -14,4 +14,9 @@ textures/screenshotdb/dump.wavprofile-dumps/-/cache/\ No newline at end of file+/cache/+config.toml+system/+*.sram+*.dff+docs/*.md\ No newline at end of filediff --git a/crates/app/src/app.rs b/crates/app/src/app.rsindex ef43ac0..a03b2a2 100644--- a/crates/app/src/app.rs+++ b/crates/app/src/app.rs@@ -11,7 +11,7 @@ use iced::{Background, Border, Color, Element, Length, Padding, Subscription, Tause crate::cache::{self, LibraryCache};use crate::config::{self, Config};-use crate::game::{CpuMode, Format, Game, Platform, ThemePreference};+use crate::game::{AspectMode, CpuMode, Format, Game, Platform, ThemePreference};use crate::keybinds::{self, KeyTarget};use crate::library::{self, ScanProgress};use crate::player::{self, PlayerState, PlayerStatus};@@ -50,6 +50,7 @@ pub enum Message {MenuToggleSram,MenuSetTheme(ThemePreference),MenuSetUpscale(u32),+ MenuSetAspect(AspectMode),MenuAbout,AboutClose,MenuInputSettings,@@ -441,6 +442,11 @@ impl App {self.persist_config();Task::none()}+ Message::MenuSetAspect(aspect) => {+ self.config.aspect = aspect;+ self.persist_config();+ Task::none()+ }Message::MenuAbout => {self.about_open = true;Task::none()@@ -782,6 +788,7 @@ impl App {self.config.theme,self.config.skip_ipl,self.config.upscale,+ self.config.aspect,self.config.memcard_enabled,self.config.sram_enabled,),diff --git a/crates/app/src/config.rs b/crates/app/src/config.rsindex 0184014..582da50 100644--- a/crates/app/src/config.rs+++ b/crates/app/src/config.rs@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};use serde::{Deserialize, Serialize};-use crate::game::{CpuMode, ThemePreference};+use crate::game::{AspectMode, CpuMode, ThemePreference};use crate::keybinds::KeyboardConfig;#[derive(Debug, Clone, Serialize, Deserialize)]@@ -20,6 +20,7 @@ pub struct Config {pub skip_ipl: bool,#[serde(default = "self::default_upscale")]pub upscale: u32,+ pub aspect: AspectMode,#[serde(default = "self::default_memcard_enabled")]pub memcard_enabled: bool,#[serde(default = "self::default_sram_enabled")]@@ -175,6 +176,7 @@ impl Default for Config {ipl: None,skip_ipl: self::default_skip_ipl(),upscale: self::default_upscale(),+ aspect: AspectMode::default(),memcard_enabled: self::default_memcard_enabled(),sram_enabled: self::default_sram_enabled(),input: hostinput::InputConfig::default(),diff --git a/crates/app/src/game.rs b/crates/app/src/game.rsindex 9171164..c433c8d 100644--- a/crates/app/src/game.rs+++ b/crates/app/src/game.rs@@ -1,6 +1,7 @@use std::path::{Path, PathBuf};use std::sync::{Arc, OnceLock};+use backend_wgpu::sink::TargetAspect;use iced::widget::image::Handle;use image::Dvd;use serde::{Deserialize, Serialize};@@ -127,6 +128,26 @@ impl From<CpuMode> for gecko::ExecutionMode {}}+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]+#[serde(rename_all = "snake_case")]+pub enum AspectMode {+ #[default]+ Auto,+ Standard,+ Widescreen,+ Stretch,+}++impl AspectMode {+ pub fn target(self, platform: Platform) -> TargetAspect {+ match (self, platform) {+ (AspectMode::Auto, Platform::Wii) | (AspectMode::Widescreen, _) => TargetAspect::Ratio(16.0 / 9.0),+ (AspectMode::Auto, Platform::Gcn) | (AspectMode::Standard, _) => TargetAspect::Ratio(4.0 / 3.0),+ (AspectMode::Stretch, _) => TargetAspect::Stretch,+ }+ }+}+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]#[serde(rename_all = "lowercase")]pub enum ThemePreference {diff --git a/crates/app/src/player/state.rs b/crates/app/src/player/state.rsindex ef85793..b97bc3b 100644--- a/crates/app/src/player/state.rs+++ b/crates/app/src/player/state.rs@@ -71,10 +71,7 @@ impl std::fmt::Debug for PlayerState {impl PlayerState {pub fn new(game: &Game, config: &Config) -> Arc<Self> {- let aspect = match game.platform {- Platform::Wii => TargetAspect::Ratio(16.0 / 9.0),- Platform::Gcn => TargetAspect::Ratio(4.0 / 3.0),- };+ let aspect = config.aspect.target(game.platform);let neutral = match game.platform {Platform::Wii => HostInput::wii_neutral().with_wii_options(config.input.wii.nunchuk_attached.unwrap_or(true),@@ -355,6 +352,9 @@ fn finish_boot<const S: gecko::system::SystemId>(game_id: String,) {self::configure_emu(&mut emu, ¶ms, sink, state.fps.clone());+ if S == system::WII {+ emu.starlet.set_widescreen(state.aspect.is_widescreen());+ }emu.apply_host_input(&*state.input.lock().unwrap());let audio = self::install_audio_sink(&mut emu);diff --git a/crates/app/src/widgets/menubar.rs b/crates/app/src/widgets/menubar.rsindex afc9b18..2230fd6 100644--- a/crates/app/src/widgets/menubar.rs+++ b/crates/app/src/widgets/menubar.rs@@ -1,9 +1,9 @@-use iced::widget::{button, container, row, text};+use iced::widget::{Space, button, container, row, text};use iced::{Background, Border, Color, Element, Length, Padding};use iced_aw::menu::{self, Item, Menu, MenuBar};use crate::app::Message;-use crate::game::{CpuMode, Platform, ThemePreference};+use crate::game::{AspectMode, CpuMode, Platform, ThemePreference};use crate::theme::Palette;const COMMUNITY_COMPAT_URL: &str = "https://gecko.layle.dev/compat";@@ -16,6 +16,7 @@ pub fn menubar(theme_pref: ThemePreference,skip_ipl: bool,upscale: u32,+ aspect: AspectMode,memcard_enabled: bool,sram_enabled: bool,) -> Element<'static, Message> {@@ -33,6 +34,7 @@ pub fn menubar(theme_pref,skip_ipl,upscale,+ aspect,memcard_enabled,sram_enabled,),@@ -234,91 +236,93 @@ fn settings_menu(theme_pref: ThemePreference,skip_ipl: bool,upscale: u32,+ aspect: AspectMode,memcard_enabled: bool,sram_enabled: bool,) -> Menu<'static, Message, iced::Theme, iced::Renderer> {+ let check = |label: &'static str, msg: Message, on: bool| Item::new(self::menu_item(palette, label, msg, Some(on)));+Menu::new(vec![- Item::new(self::section_header(palette, "Execution Engine")),- Item::new(self::menu_item(- palette,- "JIT (Recompiler)",- Message::MenuToggleCpu(CpuMode::Jit),- Some(cpu == CpuMode::Jit),- )),- Item::new(self::menu_item(- palette,- "Interpreter",- Message::MenuToggleCpu(CpuMode::Interpreter),- Some(cpu == CpuMode::Interpreter),- )),- Item::new(self::separator(palette)),- Item::new(self::section_header(palette, "Boot")),- Item::new(self::menu_item(- palette,- "Skip IPL (GameCube)",- Message::MenuToggleSkipIpl,- Some(skip_ipl),- )),- Item::new(self::menu_item(- palette,- "Memory Card (Slot A)",- Message::MenuToggleMemoryCard,- Some(memcard_enabled),- )),- Item::new(self::menu_item(- palette,- "Persist SRAM",- Message::MenuToggleSram,- Some(sram_enabled),- )),- Item::new(self::separator(palette)),- Item::new(self::section_header(palette, "Internal Resolution")),- Item::new(self::menu_item(- palette,- "1x (Native)",- Message::MenuSetUpscale(1),- Some(upscale == 1),- )),- Item::new(self::menu_item(- palette,- "2x",- Message::MenuSetUpscale(2),- Some(upscale == 2),- )),- Item::new(self::menu_item(- palette,- "3x",- Message::MenuSetUpscale(3),- Some(upscale == 3),- )),- Item::new(self::menu_item(+ self::submenu(palette,- "4x",- Message::MenuSetUpscale(4),- Some(upscale == 4),- )),- Item::new(self::separator(palette)),- Item::new(self::section_header(palette, "Theme")),- Item::new(self::menu_item(+ "Execution Engine",+ vec![+ check(+ "JIT (Recompiler)",+ Message::MenuToggleCpu(CpuMode::Jit),+ cpu == CpuMode::Jit,+ ),+ check(+ "Interpreter",+ Message::MenuToggleCpu(CpuMode::Interpreter),+ cpu == CpuMode::Interpreter,+ ),+ ],+ ),+ self::submenu(palette,- "System",- Message::MenuSetTheme(ThemePreference::System),- Some(theme_pref == ThemePreference::System),- )),- Item::new(self::menu_item(+ "Boot",+ vec![+ check("Skip IPL (GameCube)", Message::MenuToggleSkipIpl, skip_ipl),+ check("Memory Card (Slot A)", Message::MenuToggleMemoryCard, memcard_enabled),+ check("Persist SRAM", Message::MenuToggleSram, sram_enabled),+ ],+ ),+ self::submenu(palette,- "Light",- Message::MenuSetTheme(ThemePreference::Light),- Some(theme_pref == ThemePreference::Light),- )),- Item::new(self::menu_item(+ "Graphics",+ vec![+ Item::new(self::section_header(palette, "Internal Resolution")),+ check("1x (Native)", Message::MenuSetUpscale(1), upscale == 1),+ check("2x", Message::MenuSetUpscale(2), upscale == 2),+ check("3x", Message::MenuSetUpscale(3), upscale == 3),+ check("4x", Message::MenuSetUpscale(4), upscale == 4),+ Item::new(self::separator(palette)),+ Item::new(self::section_header(palette, "Aspect Ratio")),+ check(+ "Auto (16:9 Wii, 4:3 GC)",+ Message::MenuSetAspect(AspectMode::Auto),+ aspect == AspectMode::Auto,+ ),+ check(+ "4:3",+ Message::MenuSetAspect(AspectMode::Standard),+ aspect == AspectMode::Standard,+ ),+ check(+ "16:9",+ Message::MenuSetAspect(AspectMode::Widescreen),+ aspect == AspectMode::Widescreen,+ ),+ check(+ "Stretch",+ Message::MenuSetAspect(AspectMode::Stretch),+ aspect == AspectMode::Stretch,+ ),+ ],+ ),+ self::submenu(palette,- "Dark",- Message::MenuSetTheme(ThemePreference::Dark),- Some(theme_pref == ThemePreference::Dark),- )),+ "Theme",+ vec![+ check(+ "System",+ Message::MenuSetTheme(ThemePreference::System),+ theme_pref == ThemePreference::System,+ ),+ check(+ "Light",+ Message::MenuSetTheme(ThemePreference::Light),+ theme_pref == ThemePreference::Light,+ ),+ check(+ "Dark",+ Message::MenuSetTheme(ThemePreference::Dark),+ theme_pref == ThemePreference::Dark,+ ),+ ],+ ),Item::new(self::separator(palette)),- Item::new(self::section_header(palette, "Input")),Item::new(self::menu_item(palette,"Controller Bindings",@@ -337,6 +341,34 @@ fn settings_menu(.spacing(2.0)}+fn submenu(+ palette: &Palette,+ label: &'static str,+ items: Vec<Item<'static, Message, iced::Theme, iced::Renderer>>,+) -> Item<'static, Message, iced::Theme, iced::Renderer> {+ let text_color = palette.text;+ let hover = palette.surface_2;+ let content = row![+ text(label).size(13).color(text_color),+ Space::new().width(Length::Fill),+ text("›").size(13).color(palette.text_dim),+ ]+ .align_y(iced::Alignment::Center);++ let header = button(content)+ .width(Length::Fill)+ .padding(Padding {+ top: 6.0,+ right: 10.0,+ bottom: 6.0,+ left: 14.0,+ })+ .on_press(Message::Noop)+ .style(move |_, status| self::menu_item_style(status, hover, text_color));++ Item::with_menu(header, Menu::new(items).max_width(220.0).offset(6.0).spacing(2.0))+}+fn compatibility_menu(palette: &Palette) -> Menu<'static, Message, iced::Theme, iced::Renderer> {Menu::new(vec![Item::new(self::menu_item(diff --git a/crates/backend-wgpu/src/sink.rs b/crates/backend-wgpu/src/sink.rsindex 02df5fd..e9cee33 100644--- a/crates/backend-wgpu/src/sink.rs+++ b/crates/backend-wgpu/src/sink.rs@@ -54,6 +54,13 @@ impl TargetAspect {other => panic!("--aspect must be auto|4:3|16:9|stretch, got {other:?}"),}}++ pub fn is_widescreen(self) -> bool {+ match self {+ TargetAspect::Ratio(ratio) => ratio > 4.0 / 3.0,+ TargetAspect::Stretch => true,+ }+ }}#[cfg(not(target_arch = "wasm32"))]diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rsindex 01af6fe..3737032 100644--- a/crates/debugger/src/main.rs+++ b/crates/debugger/src/main.rs@@ -433,7 +433,8 @@ struct Args {#[arg(long)]script: Option<String>,- /// Display aspect ratio: auto (16:9 Wii / 4:3 GC), 4:3, 16:9, stretch+ /// Display aspect ratio: auto (16:9 Wii / 4:3 GC), 4:3, 16:9, stretch.+ /// On Wii this also sets the console's widescreen setting (SYSCONF IPL.AR).#[arg(long, default_value = "auto")]aspect: String,@@ -536,6 +537,11 @@ fn main() {emulator.load_dsp_coef(&coef_data);}+ if let EmulatorVariant::Wii(emu) = &mut emulator {+ let widescreen = TargetAspect::from_arg(&args.aspect, true).is_widescreen();+ emu.starlet.set_widescreen(widescreen);+ }+if let Some(ref path) = args.script {let host = scripting::LuaHost::from_file(path).expect("failed to load script");match &mut emulator {diff --git a/crates/gecko/src/hollywood/ipc.rs b/crates/gecko/src/hollywood/ipc.rsindex 479bd45..a84f441 100644--- a/crates/gecko/src/hollywood/ipc.rs+++ b/crates/gecko/src/hollywood/ipc.rs@@ -109,6 +109,8 @@ pub trait IosDevice: Send {fn set_wiimote_shake(&mut self, _active: bool) {}+ fn set_widescreen(&mut self, _widescreen: bool) {}+fn set_wiimote_options(&mut self, _attached: bool, _sideways: bool) {}fn set_wiimote_accel(&mut self, _accel: Option<[f32; 3]>) {}diff --git a/crates/gecko/src/hollywood/ipc/sysconf.rs b/crates/gecko/src/hollywood/ipc/sysconf.rsindex 826ae21..65949ca 100644--- a/crates/gecko/src/hollywood/ipc/sysconf.rs+++ b/crates/gecko/src/hollywood/ipc/sysconf.rs@@ -63,6 +63,12 @@ impl IosDevice for SysConf {Ok(())}+ fn set_widescreen(&mut self, widescreen: bool) {+ if let Some(offset) = self::entry_data_offset(&self.blob, b"IPL.AR") {+ self.blob[offset] = u8::from(widescreen);+ }+ }+fn read(&mut self, ctx: &mut super::DeviceContext<'_>, out_ptr: u32, out_len: u32) -> i32 {let start = self.pos as usize;let n = (out_len as usize).min(self.blob.len().saturating_sub(start));@@ -173,7 +179,7 @@ fn build_blob(language: u8) -> Vec<u8> {(b"BT.BAR", EntryData::Byte(1)),(b"BT.SPKV", EntryData::Byte(0x58)),(b"IPL.LNG", EntryData::Byte(language)),- (b"IPL.AR", EntryData::Byte(0)),+ (b"IPL.AR", EntryData::Byte(1)),(b"IPL.E60", EntryData::Bool(false)),(b"IPL.PGS", EntryData::Bool(false)),(b"IPL.SND", EntryData::Byte(1)),@@ -205,6 +211,19 @@ fn build_blob(language: u8) -> Vec<u8> {blob}+fn entry_data_offset(blob: &[u8], name: &[u8]) -> Option<usize> {+ let count = u16::from_be_bytes([blob[4], blob[5]]) as usize;++ (0..count).find_map(|i| {+ let dir_pos = 0x06 + i * 2;+ let entry_off = u16::from_be_bytes([blob[dir_pos], blob[dir_pos + 1]]) as usize;+ let name_len = (blob[entry_off] & 0x1F) as usize + 1;+ let name_start = entry_off + 1;++ (blob.get(name_start..name_start + name_len)? == name).then_some(name_start + name_len)+ })+}+fn encode_type_namelen(type_code: u8, name_len: usize) -> u8 {(type_code << 5) | ((name_len - 1) as u8 & 0x1F)}diff --git a/crates/gecko/src/starlet.rs b/crates/gecko/src/starlet.rsindex a41f840..9fe5805 100644--- a/crates/gecko/src/starlet.rs+++ b/crates/gecko/src/starlet.rs@@ -121,6 +121,12 @@ impl Starlet {}}+ pub fn set_widescreen(&mut self, widescreen: bool) {+ if let Some(dev) = self.devices.get_mut("/shared2/sys/SYSCONF") {+ dev.set_widescreen(widescreen);+ }+ }+pub fn set_wiimote_options(&mut self, attached: bool, sideways: bool) {if let Some(dev) = self.devices.get_mut(WIIMOTE_DEVICE_PATH) {dev.set_wiimote_options(attached, sideways);diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rsindex 332b9e9..686e3c2 100644--- a/crates/tinyapp/src/main.rs+++ b/crates/tinyapp/src/main.rs@@ -105,7 +105,8 @@ struct Args {#[arg(long)]script: Option<String>,- /// Display aspect ratio: auto (16:9 Wii / 4:3 GC), 4:3, 16:9, stretch+ /// Display aspect ratio: auto (16:9 Wii / 4:3 GC), 4:3, 16:9, stretch.+ /// On Wii this also sets the console's widescreen setting (SYSCONF IPL.AR).#[arg(long, default_value = "auto")]aspect: String,@@ -314,6 +315,11 @@ fn configure<const SYSTEM: SystemId>(emulator: &mut System<SYSTEM>, args: &Args)gecko::ExecutionMode::Jit});+ if SYSTEM == system::WII {+ let widescreen = TargetAspect::from_arg(&args.aspect, true).is_widescreen();+ emulator.starlet.set_widescreen(widescreen);+ }+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);