Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

nunchuk as accessory, sideways/upright wiimote

Laylea0dd233679b0
diff --git a/README.md b/README.md
index 5604abe..fb2fbd1 100644
--- a/README.md
+++ b/README.md
@@ -161,6 +161,8 @@ Keyboard and player-window hotkeys are configurable the same way under `Settings
| `Space` | Start emulation from the splash screen (`--wait` flag) |
| `F5` | Save state (overwrites the game's existing state) |
| `F7` | Load state |
+| `F8` | Attach / detach Nunchuk (Wii only) |
+| `F9` | Switch Wiimote upright / sideways (Wii only) |
| `F10` | Trigger a RenderDoc capture (requires `renderdoc-capture` feature) |
| `F11` | Screenshot the full window |
| `F12` | Screenshot the emulated framebuffer only |
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 4eef0d1..ef43ac0 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -60,7 +60,10 @@ pub enum Message {
InputTick,
InputPointer(String),
InputSensitivity(f32),
- InputToggleSideways,
+ WiiPreset(crate::config::WiiPresetId),
+ WiiPresetReset,
+ InputToggleNunchuk,
+ InputToggleLeftStick,
InputToggleStickDpad,
InputToggleInvert(InvertTarget),
InputReset,
@@ -241,6 +244,7 @@ impl App {
Task::none()
}
Message::PlayerWindowOpened(id, game, state) => {
+ state.refresh_wii_input(&self.config);
tracing::info!(window = ?id, title = %game.title, "player window opened");
self.players.insert(
id,
@@ -514,9 +518,29 @@ impl App {
self.persist_config();
Task::none()
}
- Message::InputToggleSideways => {
- let current = self.config.input.wii.sideways.unwrap_or(false);
- self.config.input.wii.sideways = Some(!current);
+ Message::WiiPreset(id) => {
+ self.config.select_wii_preset(id);
+ self.input_capture = None;
+ self.key_capture = None;
+ self.persist_config();
+ Task::none()
+ }
+ Message::WiiPresetReset => {
+ self.config.reset_wii_preset();
+ self.input_capture = None;
+ self.key_capture = None;
+ self.persist_config();
+ Task::none()
+ }
+ Message::InputToggleNunchuk => {
+ let current = self.config.input.wii.nunchuk_attached.unwrap_or(true);
+ self.config.input.wii.nunchuk_attached = Some(!current);
+ self.persist_config();
+ Task::none()
+ }
+ Message::InputToggleLeftStick => {
+ let current = self.config.input.wii.left_stick_dpad.unwrap_or(false);
+ self.config.input.wii.left_stick_dpad = Some(!current);
self.persist_config();
Task::none()
}
@@ -533,7 +557,12 @@ impl App {
Task::none()
}
Message::InputReset => {
- self.config.input = hostinput::InputConfig::default();
+ match self.input_tab {
+ InputTab::Wii => {
+ self.config.input.wii = config::WiiPreset::defaults(self.config.active_wii_preset()).controller
+ }
+ InputTab::Gc => self.config.input.gc = Default::default(),
+ }
self.input_capture = None;
self.persist_config();
Task::none()
@@ -557,7 +586,13 @@ impl App {
Task::none()
}
Message::KeyboardReset => {
- self.config.keyboard = keybinds::KeyboardConfig::default();
+ match self.keyboard_tab {
+ KeyboardTab::Wii => {
+ self.config.keyboard.wii = config::WiiPreset::defaults(self.config.active_wii_preset()).keyboard
+ }
+ KeyboardTab::Gc => self.config.keyboard.gc = Default::default(),
+ KeyboardTab::Hotkeys => self.config.keyboard.hotkeys = Default::default(),
+ }
self.key_capture = None;
self.persist_config();
Task::none()
@@ -783,6 +818,7 @@ impl App {
self.input_tab,
self.input_capture,
self.input_pad_name.as_deref(),
+ self.config.active_wii_preset(),
)
]
.into();
@@ -790,7 +826,13 @@ impl App {
if self.keyboard_open {
root_element = stack![
root_element,
- input_settings::keyboard_overlay(palette, &self.config.keyboard, self.keyboard_tab, self.key_capture)
+ input_settings::keyboard_overlay(
+ palette,
+ &self.config.keyboard,
+ self.keyboard_tab,
+ self.key_capture,
+ self.config.active_wii_preset()
+ )
]
.into();
}
@@ -867,7 +909,11 @@ impl App {
roots
}
- fn persist_config(&self) {
+ fn persist_config(&mut self) {
+ self.config.store_wii_preset();
+ for player in self.players.values() {
+ player.state.refresh_wii_input(&self.config);
+ }
let path = config::config_path();
if let Err(err) = config::save(&path, &self.config) {
tracing::warn!(%err, path = %path.display(), "failed to persist config");
diff --git a/crates/app/src/config.rs b/crates/app/src/config.rs
index 0ba912c..f50cab8 100644
--- a/crates/app/src/config.rs
+++ b/crates/app/src/config.rs
@@ -26,6 +26,124 @@ pub struct Config {
pub sram_enabled: bool,
pub input: hostinput::InputConfig,
pub keyboard: KeyboardConfig,
+ #[serde(default)]
+ pub wii_presets: Option<WiiPresets>,
+}
+
+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum WiiPresetId {
+ #[default]
+ Upright,
+ Sideways,
+}
+
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct WiiPreset {
+ pub controller: hostinput::config::WiiConfig,
+ pub keyboard: crate::keybinds::WiiKeysConfig,
+}
+
+impl WiiPreset {
+ pub fn defaults(id: WiiPresetId) -> Self {
+ let mut preset = Self::default();
+ let sideways = id == WiiPresetId::Sideways;
+ preset.controller.sideways = Some(sideways);
+ preset.controller.nunchuk_attached = Some(!sideways);
+ if sideways {
+ preset.controller.left_stick_dpad = Some(true);
+ preset.controller.one = Some("west".into());
+ preset.controller.two = Some("south".into());
+ preset.controller.a = Some("north".into());
+ preset.keyboard.one = Some("z".into());
+ preset.keyboard.two = Some("x".into());
+ }
+ preset
+ }
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(default)]
+pub struct WiiPresets {
+ pub active: WiiPresetId,
+ pub upright: WiiPreset,
+ pub sideways: WiiPreset,
+}
+
+impl Default for WiiPresets {
+ fn default() -> Self {
+ Self {
+ active: WiiPresetId::Upright,
+ upright: WiiPreset::defaults(WiiPresetId::Upright),
+ sideways: WiiPreset::defaults(WiiPresetId::Sideways),
+ }
+ }
+}
+
+impl WiiPresets {
+ fn selected(&self) -> &WiiPreset {
+ match self.active {
+ WiiPresetId::Upright => &self.upright,
+ WiiPresetId::Sideways => &self.sideways,
+ }
+ }
+
+ fn selected_mut(&mut self) -> &mut WiiPreset {
+ match self.active {
+ WiiPresetId::Upright => &mut self.upright,
+ WiiPresetId::Sideways => &mut self.sideways,
+ }
+ }
+}
+
+impl Config {
+ pub fn active_wii_preset(&self) -> WiiPresetId {
+ self.wii_presets.as_ref().map(|p| p.active).unwrap_or_default()
+ }
+
+ pub fn store_wii_preset(&mut self) {
+ let presets = self.wii_presets.get_or_insert_with(WiiPresets::default);
+ self.input.wii.sideways = Some(presets.active == WiiPresetId::Sideways);
+ *presets.selected_mut() = WiiPreset {
+ controller: self.input.wii.clone(),
+ keyboard: self.keyboard.wii.clone(),
+ };
+ }
+
+ fn restore_wii_preset(&mut self) {
+ let presets = self.wii_presets.as_ref().unwrap();
+ self.input.wii = presets.selected().controller.clone();
+ self.input.wii.sideways = Some(presets.active == WiiPresetId::Sideways);
+ self.keyboard.wii = presets.selected().keyboard.clone();
+ }
+
+ pub fn select_wii_preset(&mut self, id: WiiPresetId) {
+ self.store_wii_preset();
+ self.wii_presets.as_mut().unwrap().active = id;
+ self.restore_wii_preset();
+ }
+
+ pub fn reset_wii_preset(&mut self) {
+ let id = self.active_wii_preset();
+ *self.wii_presets.as_mut().unwrap().selected_mut() = WiiPreset::defaults(id);
+ self.restore_wii_preset();
+ }
+
+ fn initialize_wii_presets(&mut self) {
+ if self.wii_presets.is_none() {
+ let mut presets = WiiPresets::default();
+ if self.input.wii.sideways.unwrap_or(false) {
+ presets.active = WiiPresetId::Sideways;
+ }
+ *presets.selected_mut() = WiiPreset {
+ controller: self.input.wii.clone(),
+ keyboard: self.keyboard.wii.clone(),
+ };
+ self.wii_presets = Some(presets);
+ }
+ self.restore_wii_preset();
+ }
}
fn default_skip_ipl() -> bool {
@@ -61,6 +179,7 @@ impl Default for Config {
sram_enabled: self::default_sram_enabled(),
input: hostinput::InputConfig::default(),
keyboard: KeyboardConfig::default(),
+ wii_presets: Some(WiiPresets::default()),
}
}
}
@@ -97,8 +216,11 @@ pub fn config_path() -> PathBuf {
pub fn load(path: &Path) -> Config {
match std::fs::read_to_string(path) {
- Ok(s) => match toml::from_str(&s) {
- Ok(cfg) => cfg,
+ Ok(s) => match toml::from_str::<Config>(&s) {
+ Ok(mut cfg) => {
+ cfg.initialize_wii_presets();
+ cfg
+ }
Err(err) => {
tracing::warn!(?err, path = %path.display(), "failed to parse config; using defaults");
Config::default()
diff --git a/crates/app/src/keybinds.rs b/crates/app/src/keybinds.rs
index ad39c47..8ef8cea 100644
--- a/crates/app/src/keybinds.rs
+++ b/crates/app/src/keybinds.rs
@@ -1,7 +1,7 @@
use iced::keyboard::key::Code;
use serde::{Deserialize, Serialize};
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct KeyboardConfig {
pub gc: GcKeysConfig,
@@ -9,7 +9,7 @@ pub struct KeyboardConfig {
pub hotkeys: HotkeysConfig,
}
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct GcKeysConfig {
pub stick_up: Option<String>,
@@ -30,7 +30,7 @@ pub struct GcKeysConfig {
pub dpad_right: Option<String>,
}
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct WiiKeysConfig {
pub one: Option<String>,
@@ -51,7 +51,7 @@ pub struct WiiKeysConfig {
pub nunchuk_c: Option<String>,
}
-#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct HotkeysConfig {
pub pause: Option<String>,
diff --git a/crates/app/src/player/emu_thread.rs b/crates/app/src/player/emu_thread.rs
index 7089c4c..b8eb3de 100644
--- a/crates/app/src/player/emu_thread.rs
+++ b/crates/app/src/player/emu_thread.rs
@@ -9,6 +9,7 @@ pub fn run<const SYSTEM: SystemId>(
mut emulator: System<SYSTEM>,
input: Arc<Mutex<HostInput>>,
input_config: hostinput::InputConfig,
+ input_updates: hostinput::manager::InputUpdates,
game_id: Option<String>,
throttle: Arc<AtomicBool>,
paused: Arc<AtomicBool>,
@@ -21,11 +22,9 @@ pub fn run<const SYSTEM: SystemId>(
let throttle_step = Duration::from_micros(5);
let pause_step = Duration::from_millis(10);
- emulator.set_input_sink(Box::new(hostinput::InputManager::new(
- SYSTEM,
- &input_config,
- input.clone(),
- )));
+ emulator.set_input_sink(Box::new(
+ hostinput::InputManager::new(SYSTEM, &input_config, input.clone()).with_updates(input_updates),
+ ));
while !shutdown.load(Ordering::Relaxed) {
if paused.load(Ordering::Relaxed) {
@@ -40,6 +39,7 @@ pub fn run<const SYSTEM: SystemId>(
sleeper.sleep(throttle_step);
}
+ emulator.sample_host_input();
emulator.run_until_vsync();
if save_state.swap(false, Ordering::Relaxed) {
@@ -51,7 +51,10 @@ pub fn run<const SYSTEM: SystemId>(
if load_state.swap(false, Ordering::Relaxed) {
match emulator.load_state_from_file(&savestate_path) {
- Ok(()) => tracing::info!(path = %savestate_path.display(), "savestate loaded"),
+ Ok(()) => {
+ emulator.sample_host_input();
+ tracing::info!(path = %savestate_path.display(), "savestate loaded");
+ }
Err(err) => tracing::error!(%err, "savestate load failed"),
}
}
diff --git a/crates/app/src/player/state.rs b/crates/app/src/player/state.rs
index 1373fc9..54f0a79 100644
--- a/crates/app/src/player/state.rs
+++ b/crates/app/src/player/state.rs
@@ -47,7 +47,9 @@ pub struct PlayerState {
aspect: TargetAspect,
upscale: u32,
input: Arc<Mutex<HostInput>>,
- keymap: Keymap,
+ keymap: Mutex<Keymap>,
+ input_updates: hostinput::manager::InputUpdates,
+ wii_config: Mutex<(hostinput::config::WiiConfig, crate::keybinds::WiiKeysConfig)>,
platform: Platform,
boot_error: Option<String>,
first_frame: Arc<AtomicBool>,
@@ -74,7 +76,10 @@ impl PlayerState {
Platform::Gcn => TargetAspect::Ratio(4.0 / 3.0),
};
let neutral = match game.platform {
- Platform::Wii => HostInput::wii_neutral(),
+ Platform::Wii => HostInput::wii_neutral().with_wii_options(
+ config.input.wii.nunchuk_attached.unwrap_or(true),
+ config.input.wii.sideways.unwrap_or(false),
+ ),
Platform::Gcn => HostInput::gc_connected(),
};
@@ -106,7 +111,9 @@ impl PlayerState {
aspect,
upscale: config.upscale,
input: Arc::new(Mutex::new(neutral)),
- keymap: config.keyboard.resolve(),
+ keymap: Mutex::new(config.keyboard.resolve()),
+ input_updates: Arc::new(Mutex::new(None)),
+ wii_config: Mutex::new((config.input.wii.clone(), config.keyboard.wii.clone())),
platform: game.platform,
boot_error,
first_frame: Arc::new(AtomicBool::new(false)),
@@ -153,10 +160,32 @@ impl PlayerState {
.expect("spawn player thread");
}
+ pub fn refresh_wii_input(&self, config: &Config) {
+ if self.platform != Platform::Wii {
+ return;
+ }
+
+ let mut current = self.wii_config.lock().unwrap();
+ if current.0 == config.input.wii && current.1 == config.keyboard.wii {
+ return;
+ }
+
+ let mut input = self.input.lock().unwrap();
+ *input = input.cleared().with_wii_options(
+ config.input.wii.nunchuk_attached.unwrap_or(true),
+ config.input.wii.sideways.unwrap_or(false),
+ );
+
+ self.keymap.lock().unwrap().wii = config.keyboard.resolve().wii;
+ *self.input_updates.lock().unwrap() = Some(config.input.clone());
+ *current = (config.input.wii.clone(), config.keyboard.wii.clone());
+ }
+
pub fn handle_keyboard(&self, key: Code, pressed: bool) {
let mut input_guard = self.input.lock().unwrap();
+ let keymap = self.keymap.lock().unwrap();
match &mut *input_guard {
- HostInput::Gc(pad) => input::update_pad(pad, &self.keymap.gc, key, pressed),
+ HostInput::Gc(pad) => input::update_pad(pad, &keymap.gc, key, pressed),
HostInput::Wii {
wiimote_buttons,
wiimote_shake,
@@ -165,13 +194,13 @@ impl PlayerState {
nunchuk_stick_y,
..
} => {
- input::update_wiimote_keys(wiimote_buttons, &self.keymap.wii, key, pressed);
- input::update_wiimote_motion_keys(wiimote_shake, &self.keymap.wii, key, pressed);
+ input::update_wiimote_keys(wiimote_buttons, &keymap.wii, key, pressed);
+ input::update_wiimote_motion_keys(wiimote_shake, &keymap.wii, key, pressed);
input::update_nunchuk_keys(
nunchuk_buttons,
nunchuk_stick_x,
nunchuk_stick_y,
- &self.keymap.wii,
+ &keymap.wii,
key,
pressed,
);
@@ -180,7 +209,7 @@ impl PlayerState {
}
pub fn hotkey(&self, key: Code) -> Option<Hotkey> {
- self.keymap.hotkeys.lookup(key)
+ self.keymap.lock().unwrap().hotkeys.lookup(key)
}
pub fn handle_mouse_button(&self, button: MouseButton, pressed: bool) {
@@ -326,7 +355,7 @@ fn finish_boot<const S: gecko::system::SystemId>(
game_id: String,
) {
self::configure_emu(&mut emu, &params, sink, state.fps.clone());
- emu.apply_host_input(&HostInput::neutral_for(S));
+ emu.apply_host_input(&*state.input.lock().unwrap());
let audio = self::install_audio_sink(&mut emu);
let _ = emu.load_jit_cache(&game_id);
@@ -338,6 +367,7 @@ fn finish_boot<const S: gecko::system::SystemId>(
emu,
state.input.clone(),
params.input_config,
+ state.input_updates.clone(),
Some(game_id),
state.throttle.clone(),
state.paused.clone(),
diff --git a/crates/app/src/widgets/input_settings.rs b/crates/app/src/widgets/input_settings.rs
index 1043917..b95e60b 100644
--- a/crates/app/src/widgets/input_settings.rs
+++ b/crates/app/src/widgets/input_settings.rs
@@ -2,7 +2,7 @@ use gecko::flipper::si::pad;
use gecko::hollywood::ipc::usb;
use hostinput::mapping::{GcProfile, WiiProfile};
use hostinput::{Button, InputConfig};
-use iced::widget::{button, column, container, pick_list, row, text};
+use iced::widget::{button, column, container, pick_list, row, scrollable, text};
use iced::{Alignment, Background, Border, Color, Element, Length, Padding};
use crate::app::Message;
@@ -212,6 +212,7 @@ pub fn overlay(
tab: InputTab,
capture: Option<BindTarget>,
pad: Option<&str>,
+ preset: crate::config::WiiPresetId,
) -> Element<'static, Message> {
let gc_profile = config.gc_profile();
let wii_profile = config.wii_profile();
@@ -235,6 +236,22 @@ pub fn overlay(
.spacing(6);
let mut body = column![].spacing(4);
+ if tab == InputTab::Wii {
+ let options = column![
+ preset_selector(palette, preset),
+ self::chip(
+ palette,
+ "Nunchuk attached",
+ Message::InputToggleNunchuk,
+ wii_profile.nunchuk_attached,
+ ),
+ ]
+ .spacing(4);
+ body = body.push(container(options).padding(Padding {
+ bottom: 16.0,
+ ..Padding::ZERO
+ }));
+ }
let targets: &[(BindTarget, &str)] = match tab {
InputTab::Gc => &GC_TARGETS,
@@ -341,10 +358,9 @@ pub fn overlay(
let toggles = row![
container(text("Options").size(13).color(palette.text_dim)).width(Length::Fixed(130.0)),
- self::chip(palette, "Sideways", Message::InputToggleSideways, wii_profile.sideways),
self::chip(
palette,
- "Stick D-Pad",
+ "Right stick D-pad",
Message::InputToggleStickDpad,
wii_profile.stick_dpad
),
@@ -352,15 +368,31 @@ pub fn overlay(
.spacing(6)
.align_y(Alignment::Center);
+ let left_stick = row![
+ container(text("Left stick").size(13).color(palette.text_dim)).width(Length::Fixed(130.0)),
+ self::chip(
+ palette,
+ if wii_profile.left_stick_dpad {
+ "D-pad"
+ } else {
+ "Nunchuk"
+ },
+ Message::InputToggleLeftStick,
+ wii_profile.left_stick_dpad
+ ),
+ ]
+ .spacing(6)
+ .align_y(Alignment::Center);
body = body
.push(self::separator(palette))
+ .push(left_stick)
.push(pointer_row)
.push(sensitivity_row)
.push(toggles)
.push(self::invert_row(
palette,
config,
- "Invert Nunchuk",
+ "Invert Left Stick",
InvertTarget::NunchukX,
InvertTarget::NunchukY,
))
@@ -387,6 +419,17 @@ pub fn overlay(
]
.align_y(Alignment::Center);
+ let body = scrollable(container(body).padding(Padding {
+ bottom: 12.0,
+ ..Padding::ZERO
+ }))
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .spacing(12);
+ let footer = container(footer).padding(Padding {
+ top: 8.0,
+ ..Padding::ZERO
+ });
let card_col = column![header, tabs, body, footer].spacing(14);
overlay::modal(palette, 360.0, 20.0, Message::InputClose, card_col.into())
@@ -397,6 +440,7 @@ pub fn keyboard_overlay(
keyboard: &KeyboardConfig,
tab: KeyboardTab,
capture: Option<KeyTarget>,
+ preset: crate::config::WiiPresetId,
) -> Element<'static, Message> {
let status = text("Click a binding, then press a key")
.size(11)
@@ -435,6 +479,12 @@ pub fn keyboard_overlay(
};
let mut body = column![].spacing(4);
+ if tab == KeyboardTab::Wii {
+ body = body.push(container(preset_selector(palette, preset)).padding(Padding {
+ bottom: 16.0,
+ ..Padding::ZERO
+ }));
+ }
for (target, label) in targets {
body = body.push(self::key_binding_row(palette, label, *target, &keymap, capture));
}
@@ -446,11 +496,43 @@ pub fn keyboard_overlay(
]
.align_y(Alignment::Center);
+ let body = scrollable(container(body).padding(Padding {
+ bottom: 12.0,
+ ..Padding::ZERO
+ }))
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .spacing(12);
+ let footer = container(footer).padding(Padding {
+ top: 8.0,
+ ..Padding::ZERO
+ });
let card_col = column![header, tabs, body, footer].spacing(14);
overlay::modal(palette, 360.0, 20.0, Message::KeyboardClose, card_col.into())
}
+fn preset_selector(palette: &Palette, selected: crate::config::WiiPresetId) -> Element<'static, Message> {
+ use crate::config::WiiPresetId;
+ row![
+ self::chip(
+ palette,
+ "Upright",
+ Message::WiiPreset(WiiPresetId::Upright),
+ selected == WiiPresetId::Upright
+ ),
+ self::chip(
+ palette,
+ "Sideways",
+ Message::WiiPreset(WiiPresetId::Sideways),
+ selected == WiiPresetId::Sideways
+ ),
+ self::chip(palette, "Reset preset", Message::WiiPresetReset, false),
+ ]
+ .spacing(6)
+ .into()
+}
+
fn key_binding_row(
palette: &Palette,
label: &'static str,
@@ -518,7 +600,7 @@ fn bind_row(
.width(Length::Fill)
.align_x(Alignment::Center),
)
- .width(Length::Fixed(180.0))
+ .width(Length::Fill)
.padding(Padding::from([4, 10]))
.on_press(on_press)
.style(self::control_style(
@@ -532,6 +614,7 @@ fn bind_row(
container(text(label.to_owned()).size(13).color(palette.text)).width(Length::Fixed(130.0)),
bind,
]
+ .width(Length::Fill)
.spacing(6)
.align_y(Alignment::Center)
.into()
diff --git a/crates/app/src/widgets/overlay.rs b/crates/app/src/widgets/overlay.rs
index 1563dd0..6700a09 100644
--- a/crates/app/src/widgets/overlay.rs
+++ b/crates/app/src/widgets/overlay.rs
@@ -32,6 +32,7 @@ pub fn modal(
let card = container(content)
.width(Length::Fixed(width))
+ .max_height(640.0)
.padding(padding)
.style(move |_| container::Style {
background: Some(Background::Color(bg)),
@@ -44,6 +45,7 @@ pub fn modal(
});
let centered = container(card)
+ .padding(24)
.width(Length::Fill)
.height(Length::Fill)
.center_x(Length::Fill)
diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rs
index 7958e87..e87e117 100644
--- a/crates/debugger/src/debugger.rs
+++ b/crates/debugger/src/debugger.rs
@@ -42,6 +42,7 @@ pub struct DebuggerUi {
pub save_state_requested: bool,
pub load_state_requested: bool,
pub savestate_last_result: String,
+ pub input_notice: Option<(std::time::Instant, &'static str)>,
}
impl Default for DebuggerUi {
@@ -80,6 +81,7 @@ impl Default for DebuggerUi {
save_state_requested: false,
load_state_requested: false,
savestate_last_result: String::new(),
+ input_notice: None,
}
}
}
diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rs
index b3d05f3..01af6fe 100644
--- a/crates/debugger/src/main.rs
+++ b/crates/debugger/src/main.rs
@@ -130,6 +130,7 @@ struct AppInit {
impl App {
/// Render one frame against whichever emulator variant is loaded.
fn render_frame(&mut self) {
+ self.apply_game_input();
let Some(state) = self.state.as_mut() else { return };
let Some(window) = self.window.as_ref() else { return };
@@ -150,20 +151,17 @@ impl App {
if self.ui.freecam.enabled != self.freecam_input_blocked {
self.freecam_input_blocked = self.ui.freecam.enabled;
-
- if self.freecam_input_blocked {
- let neutral = self.emulator.neutral_input();
- self.emulator.apply_host_input(&neutral);
- } else {
- self.emulator.apply_host_input(&self.input);
- }
+ self.apply_game_input();
}
}
fn apply_game_input(&mut self) {
- if !self.ui.freecam.enabled {
- self.emulator.apply_host_input(&self.input);
- }
+ let input = if self.ui.freecam.enabled {
+ self.input.cleared()
+ } else {
+ self.input
+ };
+ self.emulator.apply_host_input(&input);
}
}
@@ -261,6 +259,33 @@ impl ApplicationHandler<UserEvent> for App {
WindowEvent::KeyboardInput { event, .. } => {
let pressed = event.state.is_pressed();
if let PhysicalKey::Code(key) = event.physical_key {
+ if !egui_consumed && pressed && !event.repeat && matches!(key, KeyCode::F8 | KeyCode::F9) {
+ if let HostInput::Wii {
+ nunchuk_attached,
+ sideways,
+ ..
+ } = &mut self.input
+ {
+ let message = if key == KeyCode::F8 {
+ *nunchuk_attached = !*nunchuk_attached;
+ if *nunchuk_attached {
+ "Nunchuk attached"
+ } else {
+ "Nunchuk detached"
+ }
+ } else {
+ *sideways = !*sideways;
+ if *sideways {
+ "Wiimote sideways"
+ } else {
+ "Wiimote upright"
+ }
+ };
+ self.ui.input_notice = Some((std::time::Instant::now(), message));
+ self.apply_game_input();
+ }
+ return;
+ }
if pressed && !event.repeat {
if let Some(state) = &mut self.state {
match key {
@@ -412,6 +437,14 @@ struct Args {
#[arg(long, default_value = "auto")]
aspect: String,
+ /// Start with the Nunchuk detached (F8 toggles attachment)
+ #[arg(long)]
+ no_nunchuk: bool,
+
+ /// Hold the Wiimote sideways (F9 toggles orientation)
+ #[arg(long)]
+ sideways: bool,
+
/// Force interpreter dispatch for CPU/DSP/Vertex (default: JIT)
#[arg(long)]
interpreter: bool,
@@ -516,7 +549,9 @@ fn main() {
.as_ref()
.map(|path| image::loader::load_symbols(std::path::Path::new(path)).expect("failed to load symbols"));
- let input = emulator.neutral_input();
+ let input = emulator
+ .neutral_input()
+ .with_wii_options(!args.no_nunchuk, args.sideways);
emulator.apply_host_input(&input);
// Debugger always dumps to WAV file
@@ -572,6 +607,8 @@ fn main() {
}
}
+ emulator.apply_host_input(&input);
+
let event_loop = EventLoop::<UserEvent>::with_user_event().build().unwrap();
{
diff --git a/crates/debugger/src/render.rs b/crates/debugger/src/render.rs
index 5548d18..0d79ece 100644
--- a/crates/debugger/src/render.rs
+++ b/crates/debugger/src/render.rs
@@ -142,6 +142,19 @@ impl RenderState {
let raw_input = self.egui_winit.take_egui_input(window);
let full_output = self.egui_ctx.run_ui(raw_input, |ui| {
let ctx = ui.ctx().clone();
+ if let Some((_, message)) = debugger_ui
+ .input_notice
+ .filter(|(at, _)| at.elapsed() < std::time::Duration::from_secs(3))
+ {
+ egui::Window::new("Wii input")
+ .title_bar(false)
+ .resizable(false)
+ .movable(false)
+ .anchor(egui::Align2::CENTER_TOP, [0.0, 32.0])
+ .show(&ctx, |ui| {
+ ui.label(message);
+ });
+ }
egui::Panel::top("menu_bar").show_inside(ui, |ui| {
egui::MenuBar::new().ui(ui, |ui| {
diff --git a/crates/gecko/src/hollywood/ipc.rs b/crates/gecko/src/hollywood/ipc.rs
index e2ea659..479bd45 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_wiimote_options(&mut self, _attached: bool, _sideways: bool) {}
+
fn set_wiimote_accel(&mut self, _accel: Option<[f32; 3]>) {}
fn wiimote_rumble(&self) -> bool {
diff --git a/crates/gecko/src/hollywood/ipc/usb.rs b/crates/gecko/src/hollywood/ipc/usb.rs
index f77acca..c10b96e 100644
--- a/crates/gecko/src/hollywood/ipc/usb.rs
+++ b/crates/gecko/src/hollywood/ipc/usb.rs
@@ -67,6 +67,13 @@ impl IosDevice for Bluetooth {
Bluetooth::set_wiimote_shake(self, active)
}
+ fn set_wiimote_options(&mut self, attached: bool, sideways: bool) {
+ let attachment_changed = self.wiimote.set_options(attached, sideways);
+ if attachment_changed && self.host_hid_interrupt_cid.is_some() {
+ self.queue_hid_input_report(self.wiimote.make_status_report());
+ }
+ }
+
fn set_wiimote_accel(&mut self, accel: Option<[f32; 3]>) {
self.wiimote.set_accel(accel);
}
diff --git a/crates/gecko/src/hollywood/ipc/usb/wiimote.rs b/crates/gecko/src/hollywood/ipc/usb/wiimote.rs
index 990440f..be6b70b 100644
--- a/crates/gecko/src/hollywood/ipc/usb/wiimote.rs
+++ b/crates/gecko/src/hollywood/ipc/usb/wiimote.rs
@@ -144,6 +144,7 @@ fn encode_wiimote_g(g: f32) -> u8 {
#[derive(Debug, Clone)]
pub(super) struct WiimoteState {
buttons: u16,
+ sideways: bool,
report_mode: ReportMode,
continuous: bool,
leds: u8,
@@ -179,6 +180,7 @@ impl Default for WiimoteState {
Self {
buttons: 0,
+ sideways: false,
report_mode: ReportMode::Core,
continuous: false,
leds: 0,
@@ -205,6 +207,26 @@ impl Default for WiimoteState {
}
impl WiimoteState {
+ pub(super) fn set_options(&mut self, attached: bool, sideways: bool) -> bool {
+ self.dirty |= self.sideways != sideways;
+ self.sideways = sideways;
+
+ if self.nunchuk_attached == attached {
+ return false;
+ }
+
+ self.nunchuk_attached = attached;
+ self.nunchuk_buttons = 0;
+ self.nunchuk_stick_x = NUNCHUK_STICK_CENTER;
+ self.nunchuk_stick_y = NUNCHUK_STICK_CENTER;
+ self.nunchuk_key_buf = [0; NUNCHUK_KEY_LEN];
+ self.nunchuk_key_valid = 0;
+ self.nunchuk_cipher = Cipher::IDENTITY;
+ self.dirty = true;
+
+ true
+ }
+
pub(super) fn set_buttons(&mut self, buttons: u16) -> bool {
let changed = self.buttons != buttons;
self.buttons = buttons;
@@ -213,6 +235,10 @@ impl WiimoteState {
}
pub(super) fn set_nunchuk(&mut self, buttons: u8, stick_x: u8, stick_y: u8) -> bool {
+ if !self.nunchuk_attached {
+ return false;
+ }
+
let changed =
self.nunchuk_buttons != buttons || self.nunchuk_stick_x != stick_x || self.nunchuk_stick_y != stick_y;
self.nunchuk_buttons = buttons;
@@ -275,12 +301,34 @@ impl WiimoteState {
}
fn button_bytes(&self) -> [u8; 2] {
- self.buttons.to_be_bytes()
+ let mut buttons = self.buttons;
+ if self.sideways {
+ buttons &= !(BTN_UP | BTN_DOWN | BTN_LEFT | BTN_RIGHT);
+ for (from, to) in [
+ (BTN_UP, BTN_RIGHT),
+ (BTN_DOWN, BTN_LEFT),
+ (BTN_LEFT, BTN_UP),
+ (BTN_RIGHT, BTN_DOWN),
+ ] {
+ if self.buttons & from != 0 {
+ buttons |= to;
+ }
+ }
+ }
+ buttons.to_be_bytes()
}
pub(super) fn make_input_report(&self) -> Vec<u8> {
let [bb0, bb1] = self.button_bytes();
- let accel = self.accel;
+ let accel = if self.sideways {
+ [
+ (2 * WIIMOTE_ACCEL_ZERO_G - self.accel[2] as i32).clamp(0, 255) as u8,
+ self.accel[1],
+ self.accel[0],
+ ]
+ } else {
+ self.accel
+ };
let mode = self.report_mode;
let mut r = vec![HID_PREFIX_INPUT, mode as u8, bb0, bb1];
@@ -531,6 +579,10 @@ impl WiimoteState {
/// have arrived we derive `ft`/`sb` and switch our outgoing extension
/// bytes and register read responses to encrypted output.
fn observe_register_write(&mut self, address: u32, payload: &[u8]) {
+ if !self.nunchuk_attached {
+ return;
+ }
+
let reg = (address & 0xFF) as u8;
let Some(rel) = reg.checked_sub(NUNCHUK_KEY_REG_BASE) else {
return;
@@ -577,7 +629,7 @@ impl WiimoteState {
report
}
- fn make_status_report(&self) -> Vec<u8> {
+ pub(super) fn make_status_report(&self) -> Vec<u8> {
let [bb0, bb1] = self.button_bytes();
let ir_enabled = self.ir_enabled_pin1 && self.ir_enabled_pin2;
let mut flags = self.leds << 4;
diff --git a/crates/gecko/src/input.rs b/crates/gecko/src/input.rs
index 1c5f050..8c1731c 100644
--- a/crates/gecko/src/input.rs
+++ b/crates/gecko/src/input.rs
@@ -22,6 +22,8 @@ impl InputSink for Arc<Mutex<HostInput>> {
pub enum HostInput {
Gc(pad::PadStatus),
Wii {
+ nunchuk_attached: bool,
+ sideways: bool,
wiimote_buttons: u16,
wiimote_shake: bool,
nunchuk_buttons: u8,
@@ -61,6 +63,8 @@ impl HostInput {
pub fn wii_neutral() -> Self {
Self::Wii {
+ nunchuk_attached: true,
+ sideways: false,
wiimote_buttons: 0,
wiimote_shake: false,
nunchuk_buttons: 0,
@@ -71,6 +75,30 @@ impl HostInput {
}
}
+ pub fn cleared(self) -> Self {
+ match self {
+ Self::Wii {
+ nunchuk_attached,
+ sideways,
+ ..
+ } => Self::wii_neutral().with_wii_options(nunchuk_attached, sideways),
+ Self::Gc(_) => Self::gc_connected(),
+ }
+ }
+
+ pub fn with_wii_options(mut self, attached: bool, horizontal: bool) -> Self {
+ if let Self::Wii {
+ nunchuk_attached,
+ sideways,
+ ..
+ } = &mut self
+ {
+ *nunchuk_attached = attached;
+ *sideways = horizontal;
+ }
+ self
+ }
+
pub fn neutral_for(system: SystemId) -> Self {
match system {
WII => Self::wii_neutral(),
diff --git a/crates/gecko/src/starlet.rs b/crates/gecko/src/starlet.rs
index 65aed4d..a41f840 100644
--- a/crates/gecko/src/starlet.rs
+++ b/crates/gecko/src/starlet.rs
@@ -121,6 +121,12 @@ impl Starlet {
}
}
+ 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);
+ }
+ }
+
pub fn set_wiimote_accel(&mut self, accel: Option<[f32; 3]>) {
if let Some(dev) = self.devices.get_mut(WIIMOTE_DEVICE_PATH) {
dev.set_wiimote_accel(accel);
diff --git a/crates/gecko/src/system.rs b/crates/gecko/src/system.rs
index 1e64842..1a7a6be 100644
--- a/crates/gecko/src/system.rs
+++ b/crates/gecko/src/system.rs
@@ -834,6 +834,8 @@ impl<const SYSTEM: SystemId> System<SYSTEM> {
self.si.pad_state[0] = *pad;
}
HostInput::Wii {
+ nunchuk_attached,
+ sideways,
wiimote_buttons,
wiimote_shake,
nunchuk_buttons,
@@ -842,6 +844,7 @@ impl<const SYSTEM: SystemId> System<SYSTEM> {
ir_pointer,
accel,
} if SYSTEM == WII => {
+ self.starlet.set_wiimote_options(*nunchuk_attached, *sideways);
self.starlet.set_wiimote_buttons(*wiimote_buttons);
self.starlet.set_wiimote_shake(*wiimote_shake);
self.starlet
diff --git a/crates/hostinput/src/config.rs b/crates/hostinput/src/config.rs
index 6d5ac9b..2aad650 100644
--- a/crates/hostinput/src/config.rs
+++ b/crates/hostinput/src/config.rs
@@ -4,7 +4,7 @@ use gecko::flipper::si::pad;
use gecko::hollywood::ipc::usb;
use serde::{Deserialize, Serialize};
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct InputConfig {
pub gamepads: bool,
@@ -22,7 +22,7 @@ impl Default for InputConfig {
}
}
-#[derive(Clone, Debug, Default, Serialize, Deserialize)]
+#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct GcConfig {
pub a: Option<String>,
@@ -38,7 +38,7 @@ pub struct GcConfig {
pub deadzone: Option<f32>,
}
-#[derive(Clone, Debug, Default, Serialize, Deserialize)]
+#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct WiiConfig {
pub a: Option<String>,
@@ -55,6 +55,8 @@ pub struct WiiConfig {
pub pointer: Option<String>,
pub pointer_sensitivity: Option<f32>,
pub sideways: Option<bool>,
+ pub nunchuk_attached: Option<bool>,
+ pub left_stick_dpad: Option<bool>,
pub stick_dpad: Option<bool>,
pub invert_nunchuk_x: Option<bool>,
pub invert_nunchuk_y: Option<bool>,
@@ -194,6 +196,8 @@ impl InputConfig {
if let Some(sensitivity) = self.wii.pointer_sensitivity {
profile.sensitivity = sensitivity.clamp(0.1, 10.0);
}
+ profile.nunchuk_attached = self.wii.nunchuk_attached.unwrap_or(true);
+ profile.left_stick_dpad = self.wii.left_stick_dpad.unwrap_or(false);
if let Some(sideways) = self.wii.sideways {
profile.sideways = sideways;
}
diff --git a/crates/hostinput/src/manager.rs b/crates/hostinput/src/manager.rs
index f3f5b60..a672dcc 100644
--- a/crates/hostinput/src/manager.rs
+++ b/crates/hostinput/src/manager.rs
@@ -6,7 +6,10 @@ use gecko::{GC, HostInput, InputSink, SystemId, WII};
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
+pub type InputUpdates = Arc<Mutex<Option<InputConfig>>>;
+
pub struct InputManager {
+ updates: Option<InputUpdates>,
system: SystemId,
keyboard: Arc<Mutex<HostInput>>,
gc_profile: GcProfile,
@@ -19,24 +22,37 @@ impl InputManager {
let gc_profile = config.gc_profile();
let wii_profile = config.wii_profile();
- let service = config.gamepads.then(|| {
- let service = sdl::service();
-
- *service.motion.lock().unwrap() = sdl::MotionSettings {
- sensitivity: wii_profile.sensitivity,
- recenter: wii_profile.recenter,
- invert: (wii_profile.pointer_invert.x, wii_profile.pointer_invert.y),
- };
-
- service
- });
+ let service = config.gamepads.then(sdl::service);
- Self {
+ let manager = Self {
+ updates: None,
system,
keyboard,
gc_profile,
wii_profile,
service,
+ };
+ manager.sync_motion_settings();
+ manager
+ }
+
+ pub fn with_updates(mut self, updates: InputUpdates) -> Self {
+ self.updates = Some(updates);
+ self
+ }
+
+ fn refresh(&mut self, config: &InputConfig) {
+ self.wii_profile = config.wii_profile();
+ self.sync_motion_settings();
+ }
+
+ fn sync_motion_settings(&self) {
+ if let Some(service) = self.service {
+ *service.motion.lock().unwrap() = sdl::MotionSettings {
+ sensitivity: self.wii_profile.sensitivity,
+ recenter: self.wii_profile.recenter,
+ invert: (self.wii_profile.pointer_invert.x, self.wii_profile.pointer_invert.y),
+ };
}
}
}
@@ -52,7 +68,15 @@ fn resolve_pointer(profile: PointerSource, caps: &Capabilities) -> PointerSource
impl InputSink for InputManager {
fn sample(&mut self) -> HostInput {
- let kb = *self.keyboard.lock().unwrap();
+ let (kb, update) = {
+ let keyboard = self.keyboard.lock().unwrap();
+ let update = self.updates.as_ref().and_then(|updates| updates.lock().unwrap().take());
+ (*keyboard, update)
+ };
+
+ if let Some(config) = update {
+ self.refresh(&config);
+ }
let Some(service) = self.service else {
return kb;
diff --git a/crates/hostinput/src/mapping.rs b/crates/hostinput/src/mapping.rs
index 586e13e..6b58db2 100644
--- a/crates/hostinput/src/mapping.rs
+++ b/crates/hostinput/src/mapping.rs
@@ -64,6 +64,8 @@ pub struct WiiProfile {
pub pointer: PointerSource,
pub sensitivity: f32,
pub sideways: bool,
+ pub nunchuk_attached: bool,
+ pub left_stick_dpad: bool,
pub stick_dpad: bool,
pub nunchuk_invert: Invert,
pub stick_dpad_invert: Invert,
@@ -94,6 +96,8 @@ impl Default for WiiProfile {
pointer: PointerSource::Auto,
sensitivity: 1.0,
sideways: false,
+ nunchuk_attached: true,
+ left_stick_dpad: false,
stick_dpad: true,
nunchuk_invert: Invert::default(),
stick_dpad_invert: Invert::default(),
diff --git a/crates/hostinput/src/mapping/wii.rs b/crates/hostinput/src/mapping/wii.rs
index ece86cb..59b9d24 100644
--- a/crates/hostinput/src/mapping/wii.rs
+++ b/crates/hostinput/src/mapping/wii.rs
@@ -33,10 +33,6 @@ pub fn map(port: &PortInput, profile: &WiiProfile, source: PointerSource) -> Hos
}
}
- if profile.sideways {
- buttons = self::rotate_dpad(buttons);
- }
-
let mut nunchuk_buttons = 0u8;
if state.pressed(profile.nunchuk_c) {
nunchuk_buttons |= usb::NUNCHUK_BTN_C;
@@ -45,7 +41,23 @@ pub fn map(port: &PortInput, profile: &WiiProfile, source: PointerSource) -> Hos
nunchuk_buttons |= usb::NUNCHUK_BTN_Z;
}
- let (nx, ny) = mapping::radial(profile.nunchuk_invert.apply(state.left), profile.deadzone);
+ let (mut nx, mut ny) = mapping::radial(profile.nunchuk_invert.apply(state.left), profile.deadzone);
+
+ if profile.left_stick_dpad {
+ if nx < -STICK_DPAD_THRESHOLD {
+ buttons |= usb::BTN_LEFT;
+ }
+ if nx > STICK_DPAD_THRESHOLD {
+ buttons |= usb::BTN_RIGHT;
+ }
+ if ny < -STICK_DPAD_THRESHOLD {
+ buttons |= usb::BTN_DOWN;
+ }
+ if ny > STICK_DPAD_THRESHOLD {
+ buttons |= usb::BTN_UP;
+ }
+ (nx, ny) = (0.0, 0.0);
+ }
let ir_pointer = match source {
PointerSource::Gyro => port.pointer,
@@ -57,13 +69,11 @@ pub fn map(port: &PortInput, profile: &WiiProfile, source: PointerSource) -> Hos
_ => None,
};
- let mut accel = port.caps.accel.then(|| motion::map_accel(state.accel));
-
- if profile.sideways {
- accel = accel.map(|a| [-a[2], a[1], a[0]]);
- }
+ let accel = port.caps.accel.then(|| motion::map_accel(state.accel));
HostInput::Wii {
+ nunchuk_attached: profile.nunchuk_attached,
+ sideways: profile.sideways,
wiimote_buttons: buttons,
wiimote_shake: profile.shake.is_some_and(|button| state.pressed(button)) && accel.is_none(),
nunchuk_buttons,
@@ -73,24 +83,3 @@ pub fn map(port: &PortInput, profile: &WiiProfile, source: PointerSource) -> Hos
accel,
}
}
-
-fn rotate_dpad(buttons: u16) -> u16 {
- const DPAD: u16 = usb::BTN_UP | usb::BTN_DOWN | usb::BTN_LEFT | usb::BTN_RIGHT;
-
- let mut out = buttons & !DPAD;
-
- if buttons & usb::BTN_UP != 0 {
- out |= usb::BTN_RIGHT;
- }
- if buttons & usb::BTN_DOWN != 0 {
- out |= usb::BTN_LEFT;
- }
- if buttons & usb::BTN_LEFT != 0 {
- out |= usb::BTN_UP;
- }
- if buttons & usb::BTN_RIGHT != 0 {
- out |= usb::BTN_DOWN;
- }
-
- out
-}
diff --git a/crates/hostinput/src/merge.rs b/crates/hostinput/src/merge.rs
index 5d464b4..bac30db 100644
--- a/crates/hostinput/src/merge.rs
+++ b/crates/hostinput/src/merge.rs
@@ -27,12 +27,15 @@ pub fn wii(pad: HostInput, kb: HostInput) -> HostInput {
nunchuk_stick_y,
ir_pointer,
accel,
+ ..
} = pad
else {
return kb;
};
let HostInput::Wii {
+ nunchuk_attached,
+ sideways,
wiimote_buttons: kb_buttons,
wiimote_shake: kb_shake,
nunchuk_buttons: kb_nunchuk,
@@ -46,6 +49,8 @@ pub fn wii(pad: HostInput, kb: HostInput) -> HostInput {
};
HostInput::Wii {
+ nunchuk_attached,
+ sideways,
wiimote_buttons: wiimote_buttons | kb_buttons,
wiimote_shake: wiimote_shake || kb_shake,
nunchuk_buttons: nunchuk_buttons | kb_nunchuk,
diff --git a/crates/mcp/src/server.rs b/crates/mcp/src/server.rs
index 2c7008c..05f9cad 100644
--- a/crates/mcp/src/server.rs
+++ b/crates/mcp/src/server.rs
@@ -585,6 +585,8 @@ impl McpServer {
async fn set_wiimote(&self, Parameters(args): Parameters<SetWiimoteArgs>) -> Result<CallToolResult, McpError> {
require_loaded(&self.shared)?;
let input = gecko::HostInput::Wii {
+ nunchuk_attached: true,
+ sideways: false,
wiimote_buttons: args.buttons.unwrap_or(0),
wiimote_shake: args.shake.unwrap_or(false),
nunchuk_buttons: args.nunchuk_buttons.unwrap_or(0),
diff --git a/crates/tinyapp/src/app.rs b/crates/tinyapp/src/app.rs
index c6e183b..f4793e1 100644
--- a/crates/tinyapp/src/app.rs
+++ b/crates/tinyapp/src/app.rs
@@ -131,7 +131,7 @@ impl State {
self.surface.configure(&self.device, &self.surface_config);
}
- fn render(&mut self, window: &Window, waiting: bool) {
+ fn render(&mut self, window: &Window, waiting: bool, notice: Option<&str>) {
if !waiting && let Some(intended) = self.intended_present_time {
let target = intended + self.pacer_offset;
let now = Instant::now();
@@ -190,6 +190,16 @@ impl State {
let raw_input = self.egui_winit.take_egui_input(window);
let full_output = self.egui_ctx.run_ui(raw_input, |ui| {
let ctx = ui.ctx().clone();
+ if let Some(message) = notice {
+ egui::Window::new("Wii input")
+ .title_bar(false)
+ .resizable(false)
+ .movable(false)
+ .anchor(egui::Align2::CENTER_TOP, [0.0, 12.0])
+ .show(&ctx, |ui| {
+ ui.label(message);
+ });
+ }
if waiting {
let frame = egui::Frame::window(&ctx.global_style())
.fill(egui::Color32::from_rgba_unmultiplied(20, 20, 20, 220));
@@ -328,6 +338,7 @@ impl State {
pub struct App {
pub input: Arc<Mutex<HostInput>>,
+ pub wii_notice: Option<(Instant, &'static str)>,
pub window: Option<Arc<Window>>,
pub state: Option<State>,
pub present_mode: wgpu::PresentMode,
@@ -416,9 +427,10 @@ impl ApplicationHandler<crate::UserEvent> for App {
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
+ let mut egui_consumed = false;
// Forward events to egui first
if let (Some(state), Some(window)) = (&mut self.state, &self.window) {
- let _ = state.egui_winit.on_window_event(window, &event);
+ egui_consumed = state.egui_winit.on_window_event(window, &event).consumed;
}
match event {
@@ -434,6 +446,35 @@ impl ApplicationHandler<crate::UserEvent> for App {
WindowEvent::KeyboardInput { event, .. } => {
let pressed = event.state.is_pressed();
if let PhysicalKey::Code(key) = event.physical_key {
+ if !egui_consumed && pressed && !event.repeat && matches!(key, KeyCode::F8 | KeyCode::F9) {
+ if let HostInput::Wii {
+ nunchuk_attached,
+ sideways,
+ ..
+ } = &mut *self.input.lock().unwrap()
+ {
+ let message = if key == KeyCode::F8 {
+ *nunchuk_attached = !*nunchuk_attached;
+ if *nunchuk_attached {
+ "Nunchuk attached"
+ } else {
+ "Nunchuk detached"
+ }
+ } else {
+ *sideways = !*sideways;
+ if *sideways {
+ "Wiimote sideways"
+ } else {
+ "Wiimote upright"
+ }
+ };
+ self.wii_notice = Some((Instant::now(), message));
+ if let Some(window) = &self.window {
+ window.request_redraw();
+ }
+ }
+ return;
+ }
if self.waiting() {
if pressed && !event.repeat && key == KeyCode::Space {
self.start_gate.store(true, Ordering::Release);
@@ -538,7 +579,11 @@ impl ApplicationHandler<crate::UserEvent> for App {
WindowEvent::RedrawRequested => {
let waiting = self.waiting();
if let (Some(state), Some(window)) = (&mut self.state, &self.window) {
- state.render(window, waiting);
+ let notice = self
+ .wii_notice
+ .filter(|(at, _)| at.elapsed() < Duration::from_secs(3))
+ .map(|(_, text)| text);
+ state.render(window, waiting, notice);
}
}
_ => {}
diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rs
index 692afb0..68be23c 100644
--- a/crates/tinyapp/src/main.rs
+++ b/crates/tinyapp/src/main.rs
@@ -175,6 +175,14 @@ struct Args {
#[arg(long, default_value = "mouse")]
pointer: String,
+ /// Start with the Nunchuk detached (F8 toggles attachment)
+ #[arg(long)]
+ no_nunchuk: bool,
+
+ /// Hold the Wiimote sideways (F9 toggles orientation)
+ #[arg(long)]
+ sideways: bool,
+
/// Force interpreter dispatch for CPU/DSP/Vertex (default: JIT)
#[arg(long)]
interpreter: bool,
@@ -331,7 +339,7 @@ fn configure<const SYSTEM: SystemId>(emulator: &mut System<SYSTEM>, args: &Args)
}
}
- emulator.apply_host_input(&HostInput::neutral_for(SYSTEM));
+ emulator.apply_host_input(&HostInput::neutral_for(SYSTEM).with_wii_options(!args.no_nunchuk, args.sideways));
#[cfg(any(feature = "jit-stats", feature = "gx-stats"))]
{
@@ -398,7 +406,9 @@ fn run<const SYSTEM: SystemId>(
let _ = std::fs::write(path, "wall_secs,fps,native_pct,vsyncs\n");
}
- let input = Arc::new(Mutex::new(HostInput::neutral_for(SYSTEM)));
+ let input = Arc::new(Mutex::new(
+ HostInput::neutral_for(SYSTEM).with_wii_options(!args.no_nunchuk, args.sideways),
+ ));
let event_loop = EventLoop::<UserEvent>::with_user_event().build().unwrap();
let proxy = event_loop.create_proxy();
@@ -469,6 +479,8 @@ fn run<const SYSTEM: SystemId>(
let mut input_config = hostinput::InputConfig::default();
input_config.wii.pointer = Some(args.pointer.clone());
+ input_config.wii.nunchuk_attached = Some(!args.no_nunchuk);
+ input_config.wii.sideways = Some(args.sideways);
drop(proxy);
let emu_savestate_requests = savestate_requests.clone();
@@ -492,6 +504,7 @@ fn run<const SYSTEM: SystemId>(
let mut app = app::App {
input,
+ wii_notice: None,
window: None,
state: None,
present_mode,
diff --git a/crates/tinyapp/src/thread.rs b/crates/tinyapp/src/thread.rs
index f4eb1dc..6775cdc 100644
--- a/crates/tinyapp/src/thread.rs
+++ b/crates/tinyapp/src/thread.rs
@@ -47,6 +47,7 @@ pub fn emu_thread<const SYSTEM: SystemId>(
sleeper.sleep(throttle_step);
}
+ emulator.sample_host_input();
emulator.run_until_vsync();
if savestate_requests.save.swap(false, Ordering::Relaxed) {
@@ -58,7 +59,10 @@ pub fn emu_thread<const SYSTEM: SystemId>(
if savestate_requests.load.swap(false, Ordering::Relaxed) {
match emulator.load_state_from_file(&savestate_path) {
- Ok(()) => tracing::info!(path = %savestate_path.display(), "savestate loaded"),
+ Ok(()) => {
+ emulator.sample_host_input();
+ tracing::info!(path = %savestate_path.display(), "savestate loaded");
+ }
Err(err) => tracing::error!(%err, "savestate load failed"),
}
}
diff --git a/other/example.conf b/other/example.conf
index 03c9a29..d4a61f1 100644
--- a/other/example.conf
+++ b/other/example.conf
@@ -44,6 +44,8 @@ recenter = "r3"
pointer = "auto" # auto | gyro | stick | touchpad | mouse
pointer_sensitivity = 1.0
sideways = false
+nunchuk_attached = true
+left_stick_dpad = false # true: left stick drives the Wiimote D-pad
stick_dpad = true
invert_nunchuk_x = false
invert_nunchuk_y = false
@@ -105,3 +107,27 @@ uncapped = "tab"
fullscreen = "f10"
overlay = "f11"
screenshot = "f12"
+
+[wii_presets]
+active = "upright" # upright | sideways
+
+[wii_presets.upright.controller]
+sideways = false
+nunchuk_attached = true
+left_stick_dpad = false
+# Other controller options use the same names as input.wii above.
+
+[wii_presets.upright.keyboard]
+# Options use the same names as keyboard.wii above.
+
+[wii_presets.sideways.controller]
+sideways = true
+nunchuk_attached = false
+left_stick_dpad = true
+one = "west"
+two = "south"
+a = "north"
+
+[wii_presets.sideways.keyboard]
+one = "z"
+two = "x"