2009-07-03 11:45:47 +00:00
|
|
|
/* OnePAD - author: arcum42(@gmail.com)
|
|
|
|
* Copyright (C) 2009
|
|
|
|
*
|
|
|
|
* Based on ZeroPAD, author zerofrog@gmail.com
|
|
|
|
* Copyright (C) 2006-2007
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
#include "analog.h"
|
|
|
|
PADAnalog g_lanalog[NUM_OF_PADS], g_ranalog[NUM_OF_PADS];
|
|
|
|
|
|
|
|
namespace Analog
|
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
u8 Pad(int pad, u8 index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
switch (index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_LX:
|
2009-07-11 17:21:23 +00:00
|
|
|
return g_lanalog[pad].x;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RX:
|
2009-07-11 17:21:23 +00:00
|
|
|
return g_ranalog[pad].x;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_LY:
|
2009-07-11 17:21:23 +00:00
|
|
|
return g_lanalog[pad].y;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RY:
|
2009-07-11 17:21:23 +00:00
|
|
|
return g_ranalog[pad].y;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
void SetPad(u8 pad, int index, u8 value)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
switch (index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_LX:
|
2009-07-11 17:21:23 +00:00
|
|
|
g_lanalog[pad].x = value;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RX:
|
2009-07-11 17:21:23 +00:00
|
|
|
g_ranalog[ pad].x = value;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_LY:
|
2009-07-11 17:21:23 +00:00
|
|
|
g_lanalog[ pad].y = value;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RY:
|
2009-07-11 17:21:23 +00:00
|
|
|
g_ranalog[pad].y = value;
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
void InvertPad(u8 pad, int key)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
SetPad(pad, key, -Pad(pad, key));
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
void ResetPad( u8 pad, int key)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
SetPad(pad, key, 0x80);
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
void Init()
|
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
for (u8 pad = 0; pad < 2; ++pad)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
ResetPad(pad, PAD_LX);
|
|
|
|
ResetPad(pad, PAD_LY);
|
|
|
|
ResetPad(pad, PAD_RX);
|
|
|
|
ResetPad(pad, PAD_RY);
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-05 11:03:12 +00:00
|
|
|
bool ReversePad(u8 index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
switch (index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_LX:
|
2010-06-05 11:03:12 +00:00
|
|
|
return ((conf.options & PADOPTION_REVERSELX) != 0);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RX:
|
2010-06-05 11:03:12 +00:00
|
|
|
return ((conf.options & PADOPTION_REVERSERX) != 0);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_LY:
|
2010-06-05 11:03:12 +00:00
|
|
|
return ((conf.options & PADOPTION_REVERSELY) != 0);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case PAD_RY:
|
2010-06-05 11:03:12 +00:00
|
|
|
return ((conf.options & PADOPTION_REVERSERY) != 0);
|
2009-07-03 11:45:47 +00:00
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
void ConfigurePad( u8 pad, int index, int value)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-11-14 09:02:10 +00:00
|
|
|
Pad(pad, index);
|
2009-07-11 17:21:23 +00:00
|
|
|
SetPad(pad, index, value / 256);
|
2010-06-05 11:03:12 +00:00
|
|
|
if (ReversePad(index)) InvertPad(pad,index);
|
2009-07-11 17:21:23 +00:00
|
|
|
SetPad(pad, index, Pad(pad, index) + 0x80);
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-11 17:21:23 +00:00
|
|
|
int AnalogToPad(int index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2009-07-11 17:21:23 +00:00
|
|
|
switch (index)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
case PAD_R_LEFT:
|
|
|
|
return PAD_RX;
|
|
|
|
break;
|
|
|
|
case PAD_R_UP:
|
|
|
|
return PAD_RY;
|
|
|
|
break;
|
|
|
|
case PAD_L_LEFT:
|
|
|
|
return PAD_LX;
|
|
|
|
break;
|
|
|
|
case PAD_L_UP:
|
|
|
|
return PAD_LY;
|
|
|
|
break;
|
|
|
|
case PAD_R_DOWN:
|
|
|
|
return PAD_RY;
|
|
|
|
break;
|
|
|
|
case PAD_R_RIGHT:
|
|
|
|
return PAD_RX;
|
|
|
|
break;
|
|
|
|
case PAD_L_DOWN:
|
|
|
|
return PAD_LY;
|
|
|
|
break;
|
|
|
|
case PAD_L_RIGHT:
|
|
|
|
return PAD_LX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|