| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | #include "Classic.h" |
| 6 | |
| 7 | |
| 8 | namespace WiimoteEmu |
| 9 | { |
| 10 | |
| 11 | static const u8 classic_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x01, 0x01 }; |
| 12 | |
| 13 | static const u8 classic_calibration[] = |
| 14 | { |
| 15 | 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, |
| 16 | 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, |
| 17 | 0x00, 0x00, 0x51, 0xa6 |
| 18 | }; |
| 19 | |
| 20 | static const u16 classic_button_bitmasks[] = |
| 21 | { |
| 22 | Classic::BUTTON_A, |
| 23 | Classic::BUTTON_B, |
| 24 | Classic::BUTTON_X, |
| 25 | Classic::BUTTON_Y, |
| 26 | |
| 27 | Classic::BUTTON_ZL, |
| 28 | Classic::BUTTON_ZR, |
| 29 | |
| 30 | Classic::BUTTON_MINUS, |
| 31 | Classic::BUTTON_PLUS, |
| 32 | |
| 33 | Classic::BUTTON_HOME, |
| 34 | }; |
| 35 | |
| 36 | static const char* const classic_button_names[] = |
| 37 | { |
| 38 | "A","B","X","Y","ZL","ZR","-","+","Home", |
| 39 | }; |
| 40 | |
| 41 | static const u16 classic_trigger_bitmasks[] = |
| 42 | { |
| 43 | Classic::TRIGGER_L, Classic::TRIGGER_R, |
| 44 | }; |
| 45 | |
| 46 | static const char* const classic_trigger_names[] = |
| 47 | { |
| 48 | "L", "R", "L-Analog", "R-Analog" |
| 49 | }; |
| 50 | |
| 51 | static const u16 classic_dpad_bitmasks[] = |
| 52 | { |
| 53 | Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, Classic::PAD_RIGHT |
| 54 | }; |
| 55 | |
| 56 | Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic")"Classic", _reg) |
| 57 | { |
| 58 | |
| 59 | groups.push_back(m_buttons = new Buttons("Buttons")); |
| 60 | for (unsigned int i = 0; i < sizeof(classic_button_names)/sizeof(*classic_button_names); ++i) |
| 61 | m_buttons->controls.push_back(new ControlGroup::Input(classic_button_names[i])); |
| 62 | |
| 63 | |
| 64 | groups.push_back(m_left_stick = new AnalogStick(_trans("Left Stick")"Left Stick")); |
| 65 | groups.push_back(m_right_stick = new AnalogStick(_trans("Right Stick")"Right Stick")); |
| 66 | |
| 67 | |
| 68 | groups.push_back(m_triggers = new MixedTriggers("Triggers")); |
| 69 | for (unsigned int i=0; i < sizeof(classic_trigger_names)/sizeof(*classic_trigger_names); ++i) |
| 70 | m_triggers->controls.push_back(new ControlGroup::Input(classic_trigger_names[i])); |
| 71 | |
| 72 | |
| 73 | groups.push_back(m_dpad = new Buttons("D-Pad")); |
| 74 | for (unsigned int i=0; i < 4; ++i) |
| 75 | m_dpad->controls.push_back(new ControlGroup::Input(named_directions[i])); |
| 76 | |
| 77 | |
| 78 | |
| 79 | memcpy(&calibration, classic_calibration, sizeof(classic_calibration)); |
| 80 | |
| 81 | memcpy(&id, classic_id, sizeof(classic_id)); |
| 82 | } |
| 83 | |
| 84 | void Classic::GetState(u8* const data, const bool focus) |
| 85 | { |
| 86 | wm_classic_extension* const ccdata = (wm_classic_extension*)data; |
| 87 | ccdata->bt = 0; |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | { |
| 93 | u8 x, y; |
| 94 | m_left_stick->GetState(&x, &y, 0x20, focus ? 0x1F : 0); |
| |
| |
| 95 | |
| 96 | ccdata->lx = x; |
| 97 | ccdata->ly = y; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | { |
| 102 | u8 x, y; |
| 103 | m_right_stick->GetState(&x, &y, 0x10, focus ? 0x0F : 0); |
| |
| 104 | |
| 105 | ccdata->rx1 = x; |
| 106 | ccdata->rx2 = x >> 1; |
| 107 | ccdata->rx3 = x >> 3; |
| 108 | ccdata->ry = y; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | { |
| 113 | u8 trigs[2]; |
| 114 | m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs, focus ? 0x1F : 0); |
| |
| 115 | |
| 116 | ccdata->lt1 = trigs[0]; |
| 5 | | Assigned value is garbage or undefined |
|
| 117 | ccdata->lt2 = trigs[0] >> 3; |
| 118 | ccdata->rt = trigs[1]; |
| 119 | } |
| 120 | |
| 121 | if (focus) |
| 122 | { |
| 123 | |
| 124 | m_buttons->GetState(&ccdata->bt, classic_button_bitmasks); |
| 125 | |
| 126 | m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | ccdata->bt ^= 0xFFFF; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | } |