00001 #include "MercuryInputEE.h"
00002 #include <libpad.h>
00003 #include "MercuryUtil.h"
00004 #include "MercuryLog.h"
00005 #include <sifrpc.h>
00006 #include <loadfile.h>
00007 #define ROM_PADMAN
00008
00009 CursorDevice * DefaultCursorDevice = new SimPadMouse;
00010
00011 bool EE_PAD1Responce = AutoInputDeviceTracker.AddDevice( "EEPAD1", new DeviceEEPAD );
00012
00013
00014
00015
00016 bool bInit = false;
00017
00018 int iMouseXBase = 127;
00019 int iMouseYBase = 127;
00020
00021 char buf[256] __attribute__((aligned(64)));
00022 struct padButtonStatus data;
00023
00024 void DeviceEEPAD::Init( MString Name )
00025 {
00026 int ret;
00027 LOG.Log( "Pad driver under Free Academic License 2.0 Help from Pukko and Gustavo" );
00028
00029 if ( !bInit )
00030 {
00031 LOG.Log("Loading one-time-only modules for input." );
00032 SifInitRpc(0);
00033 ret = SifLoadModule( "rom0:SIO2MAN", 0, NULL );
00034 if( ret < 0 )
00035 {
00036 LOG.Warn( ssprintf( "COULD NOT LOAD SIO! ERROR CODE: %d", ret ) );
00037 return;
00038 }
00039 ret = SifLoadModule( "rom0:PADMAN", 0, NULL );
00040 if( ret < 0 )
00041 {
00042 LOG.Warn( ssprintf( "COULD NOT LOAD PADMAN! ERROR CODE: %d", ret ) );
00043 return;
00044 }
00045 LOG.Log("Done loading one-time-only modules for input." );
00046
00047 ret = padInit(0);
00048
00049 LOG.Log(ssprintf("Received pad init code %d",ret));
00050 }
00051 if ( Name.length() < 6 )
00052 {
00053 LOG.Warn("Could not deduce proper name for input driver \""+Name+"\".");
00054 return;
00055 }
00056 m_iDeviceNumber = atoi( Name.substr(5).c_str() );
00057 LOG.Log( ssprintf( "Setting up PAD device %d.",m_iDeviceNumber) );
00058 ret = padPortOpen( 0, m_iDeviceNumber-1, buf );
00059 LOG.Log( ssprintf( "Got port open code: %d.", ret ) );
00060 ret = padRead( 0, m_iDeviceNumber-1, &data );
00061 LOG.Log( ssprintf( "First pad read Responce: %d", ret ) );
00062 m_iAllKeys = data.btns;
00063 LOG.Log( ssprintf( "Pad Init() complete, first code: %d",m_iAllKeys) );
00064 }
00065
00066 bool DeviceEEPAD::IsButtonDown( int ButtonNumber )
00067 {
00068 if ( ( ButtonNumber > 15 ) || ( ButtonNumber < 0 ) )
00069 return false;
00070
00071 return !((m_iAllKeys>>ButtonNumber)&1);
00072 }
00073
00074 int DeviceEEPAD::NumButtons()
00075 {
00076 return 16;
00077 }
00078
00079 void DeviceEEPAD::Update( )
00080 {
00081 padRead( 0, m_iDeviceNumber-1, &data );
00082 unsigned long iCurKeys = data.btns;
00083 for ( int j = 0; j < 16; j++ )
00084 if ( ((m_iAllKeys>>j)&1) != ((iCurKeys>>j)&1) )
00085 {
00086 if ( (iCurKeys>>j)&1 )
00087 {
00088 InputEvent ie = InputEvent( 0, j, IET_DOWN );
00089 m_sEvents.push( ie );
00090 } else {
00091 InputEvent ie = InputEvent( 0, j, IET_RELEASE );
00092 m_sEvents.push( ie );
00093 }
00094 }
00095 m_iAllKeys = data.btns;
00096 iMouseXBase = data.rjoy_h;
00097 iMouseYBase = data.rjoy_v;
00098 }
00099
00100 InputEvent DeviceEEPAD::PopLastEvent()
00101 {
00102 if ( m_sEvents.empty() )
00103 return InputEvent( 0,0,IET_NONE);
00104 InputEvent ret = m_sEvents.top();
00105 m_sEvents.pop();
00106 return ret;
00107 }
00108
00109 SimPadMouse::SimPadMouse( )
00110 {
00111 m_x = 0;
00112 m_y = 0;
00113 }
00114
00115 SimPadMouse::~SimPadMouse( )
00116 {
00117 }
00118
00119 void SimPadMouse::GetPosition( int &x, int &y )
00120 {
00121 x=m_x;y=m_y;
00122 }
00123
00124 void SimPadMouse::Update( )
00125 {
00126 m_x += (iMouseXBase - 127)/5;
00127 m_y += (iMouseYBase - 127)/5;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157