Bug Summary

File:Source/Core/Core/Src/HW/WiimoteEmu/Attachment/Classic.cpp
Location:line 118, column 2
Description:Assigned value is garbage or undefined

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "Classic.h"
6
7
8namespace WiimoteEmu
9{
10
11static const u8 classic_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x01, 0x01 };
12/* Classic Controller calibration */
13static 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
20static 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
36static const char* const classic_button_names[] =
37{
38 "A","B","X","Y","ZL","ZR","-","+","Home",
39};
40
41static const u16 classic_trigger_bitmasks[] =
42{
43 Classic::TRIGGER_L, Classic::TRIGGER_R,
44};
45
46static const char* const classic_trigger_names[] =
47{
48 "L", "R", "L-Analog", "R-Analog"
49};
50
51static const u16 classic_dpad_bitmasks[] =
52{
53 Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, Classic::PAD_RIGHT
54};
55
56Classic::Classic() : Attachment(_trans("Classic")"Classic")
57{
58 // buttons
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 // sticks
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 // triggers
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 // dpad
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 // set up register
78 // calibration
79 memcpy(&reg[0x20], classic_calibration, sizeof(classic_calibration));
80 // id
81 memcpy(&reg[0xfa], classic_id, sizeof(classic_id));
82}
83
84void 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 // not using calibration data, o well
90
91 // left stick
92 {
93 u8 x, y;
94 m_left_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
1
Assuming 'focus' is 0
2
'?' condition is false
95
96 ccdata->lx = x;
97 ccdata->ly = y;
98 }
99
100 // right stick
101 {
102 u8 x, y;
103 m_right_stick->GetState(&x, &y, 0x10, focus ? 0x0F /*0x0C*/ : 0);
3
'?' condition is false
104
105 ccdata->rx1 = x;
106 ccdata->rx2 = x >> 1;
107 ccdata->rx3 = x >> 3;
108 ccdata->ry = y;
109 }
110
111 //triggers
112 {
113 u8 trigs[2];
114 m_triggers->GetState(&ccdata->bt, classic_trigger_bitmasks, trigs, focus ? 0x1F : 0);
4
'?' condition is false
115
116 ccdata->lt1 = trigs[0];
117 ccdata->lt2 = trigs[0] >> 3;
118 ccdata->rt = trigs[1];
5
Assigned value is garbage or undefined
119 }
120
121 if (focus)
122 {
123 // buttons
124 m_buttons->GetState(&ccdata->bt, classic_button_bitmasks);
125 // dpad
126 m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks);
127 }
128
129 // flip button bits
130 ccdata->bt ^= 0xFFFF;
131}
132
133
134}