From f42186e0ef4e484da818b1125c9045ca24ec5708 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sun, 8 Mar 2009 08:59:29 +0000 Subject: [PATCH] Add nunchuk support (Aaron Morris) --- CHANGES.WII | 4 ++++ Src/Display_SDL.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/CHANGES.WII b/CHANGES.WII index 94a6ffd..b706db7 100644 --- a/CHANGES.WII +++ b/CHANGES.WII @@ -5,7 +5,11 @@ TODO: Crash on + in "Other" menu + TODO: Handle Run/Stop in virtual keyboard (?) + version 8: + * Make it possible to control the game with the Nunchuk (Aaron Morris) + * Correct binding of shifted keys (thanks to Bob Forgan) * Fix binding keys without the classic controller (plus etc were missing) diff --git a/Src/Display_SDL.h b/Src/Display_SDL.h index fc7133c..3cec662 100644 --- a/Src/Display_SDL.h +++ b/Src/Display_SDL.h @@ -660,6 +660,46 @@ uint8 C64::poll_joystick(int port) extra_keys[WIIMOTE_MINUS] = (held_classic & CLASSIC_CTRL_BUTTON_MINUS) | held & WPAD_BUTTON_MINUS; + // nunchuck .. just map to the d-pad! + if (wpad->exp.type == EXP_NUNCHUK) + { + held_nunchuck = 1; + + // left + if((wpad->exp.nunchuk.js.ang>=270-45 && wpad->exp.nunchuk.js.ang<=270+45) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_LEFT] = held_nunchuck; + + // right + if((wpad->exp.nunchuk.js.ang>=90-45 && wpad->exp.nunchuk.js.ang<=90+45) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_RIGHT] = held_nunchuck; + + // up + if((wpad->exp.nunchuk.js.ang>=360-45 || wpad->exp.nunchuk.js.ang<=45) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_UP] = held_nunchuck; + + // down + if((wpad->exp.nunchuk.js.ang>=180-45 && wpad->exp.nunchuk.js.ang<=180+45) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_DOWN] = held_nunchuck; + + // up/left + if((wpad->exp.nunchuk.js.ang>=315-20 && wpad->exp.nunchuk.js.ang<=315+20) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_LEFT] = extra_keys[WIIMOTE_UP] = held_nunchuck; + + //up/right + if((wpad->exp.nunchuk.js.ang>=45-20 && wpad->exp.nunchuk.js.ang<=45+20) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_RIGHT] = extra_keys[WIIMOTE_UP] = held_nunchuck; + + //down/right + if((wpad->exp.nunchuk.js.ang>=135-20 && wpad->exp.nunchuk.js.ang<=135+20) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_RIGHT] = extra_keys[WIIMOTE_DOWN] = held_nunchuck; + + //down/left + if((wpad->exp.nunchuk.js.ang>=225-20 && wpad->exp.nunchuk.js.ang<=225+20) && wpad->exp.nunchuk.js.mag>=0.9) + extra_keys[WIIMOTE_LEFT] = extra_keys[WIIMOTE_DOWN] = held_nunchuck; + + } + // eof nunchuck + /* Merge common keys */ int active_binded_keys[N_WIIMOTE_BINDINGS]; memcpy(active_binded_keys, ThePrefs.JoystickKeyBinding, sizeof(active_binded_keys));