Zeropad: Clean up the code so that if I have to go back into it, it's easier to read.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1127 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-05-03 12:19:58 +00:00
parent 5f35cf1376
commit ee3eca5b34
5 changed files with 1222 additions and 1007 deletions

File diff suppressed because it is too large Load Diff

View File

@ -59,7 +59,7 @@
#define IDC_SR2 1063 #define IDC_SR2 1063
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 114 #define _APS_NEXT_RESOURCE_VALUE 114

View File

@ -1,5 +1,5 @@
/* ZeroPAD - author: zerofrog(@gmail.com) /* ZeroPAD - author: zerofrog(@gmail.com)
* Copyright (C) 2006-2007 * Copyright (C) 2006-2007
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,100 +29,106 @@
using namespace std; using namespace std;
HINSTANCE hInst=NULL; HINSTANCE hInst = NULL;
static pthread_spinlock_t s_mutexStatus; static pthread_spinlock_t s_mutexStatus;
static u32 s_keyPress[2], s_keyRelease[2]; static u32 s_keyPress[2], s_keyRelease[2];
extern u16 status[2]; extern u16 status[2];
extern string s_strIniPath; extern string s_strIniPath;
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
WNDPROC GSwndProc=NULL; WNDPROC GSwndProc = NULL;
HWND GShwnd=NULL; HWND GShwnd = NULL;
extern keyEvent event; extern keyEvent event;
void SaveConfig() void SaveConfig()
{ {
char *szTemp;
char szIniFile[256], szValue[256], szProf[256];
int i, j;
GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256);
szTemp = strrchr(szIniFile, '\\');
if(!szTemp) return;
strcpy(szTemp, "\\inis\\zeropad.ini");
for (j=0; j<2 * PADSUBKEYS; j++) {
for (i=0; i<PADKEYS; i++) {
sprintf(szProf, "%d_%d", j, i);
sprintf(szValue, "%d", conf.keys[j][i]);
WritePrivateProfileString("Interface", szProf,szValue,szIniFile);
}
}
sprintf(szValue,"%u",conf.log);
WritePrivateProfileString("Interface", "Logging",szValue,szIniFile);
}
void LoadConfig()
{
FILE *fp;
char *szTemp; char *szTemp;
char szIniFile[256], szValue[256], szProf[256]; char szIniFile[256], szValue[256], szProf[256];
int i, j; int i, j;
memset(&conf, 0, sizeof(conf)); GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256);
szTemp = strrchr(szIniFile, '\\');
if (!szTemp) return;
strcpy(szTemp, "\\inis\\zeropad.ini");
for (j = 0; j < 2 * PADSUBKEYS; j++)
{
for (i = 0; i < PADKEYS; i++)
{
sprintf(szProf, "%d_%d", j, i);
sprintf(szValue, "%d", conf.keys[j][i]);
WritePrivateProfileString("Interface", szProf, szValue, szIniFile);
}
}
sprintf(szValue, "%u", conf.log);
WritePrivateProfileString("Interface", "Logging", szValue, szIniFile);
}
void LoadConfig()
{
FILE *fp;
char *szTemp;
char szIniFile[256], szValue[256], szProf[256];
int i, j;
memset(&conf, 0, sizeof(conf));
#ifdef _WIN32 #ifdef _WIN32
conf.keys[0][0] = 'W'; // L2 conf.keys[0][0] = 'W'; // L2
conf.keys[0][1] = 'O'; // R2 conf.keys[0][1] = 'O'; // R2
conf.keys[0][2] = 'A'; // L1 conf.keys[0][2] = 'A'; // L1
conf.keys[0][3] = ';'; // R1 conf.keys[0][3] = ';'; // R1
conf.keys[0][4] = 'I'; // TRIANGLE conf.keys[0][4] = 'I'; // TRIANGLE
conf.keys[0][5] = 'L'; // CIRCLE conf.keys[0][5] = 'L'; // CIRCLE
conf.keys[0][6] = 'K'; // CROSS conf.keys[0][6] = 'K'; // CROSS
conf.keys[0][7] = 'J'; // SQUARE conf.keys[0][7] = 'J'; // SQUARE
conf.keys[0][8] = 'V'; // SELECT conf.keys[0][8] = 'V'; // SELECT
conf.keys[0][11] = 'N'; // START conf.keys[0][11] = 'N'; // START
conf.keys[0][12] = 'E'; // UP conf.keys[0][12] = 'E'; // UP
conf.keys[0][13] = 'F'; // RIGHT conf.keys[0][13] = 'F'; // RIGHT
conf.keys[0][14] = 'D'; // DOWN conf.keys[0][14] = 'D'; // DOWN
conf.keys[0][15] = 'S'; // LEFT conf.keys[0][15] = 'S'; // LEFT
#endif #endif
conf.log = 0; conf.log = 0;
GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256);
szTemp = strrchr(szIniFile, '\\'); szTemp = strrchr(szIniFile, '\\');
if(!szTemp) return ; if (!szTemp) return ;
strcpy(szTemp, "\\inis\\zeropad.ini"); strcpy(szTemp, "\\inis\\zeropad.ini");
fp=fopen("inis\\zeropad.ini","rt");//check if usbnull.ini really exists fp = fopen("inis\\zeropad.ini", "rt");//check if usbnull.ini really exists
if (!fp) { if (!fp)
CreateDirectory("inis",NULL); {
SaveConfig();//save and return CreateDirectory("inis", NULL);
SaveConfig();//save and return
return ; return ;
} }
fclose(fp); fclose(fp);
for (j=0; j<2 * PADSUBKEYS; j++) { for (j = 0; j < 2 * PADSUBKEYS; j++)
for (i=0; i<PADKEYS; i++) { {
sprintf(szProf, "%d_%d", j, i); for (i = 0; i < PADKEYS; i++)
GetPrivateProfileString("Interface", szProf, NULL, szValue, 20, szIniFile); {
conf.keys[j][i] = strtoul(szValue, NULL, 10); sprintf(szProf, "%d_%d", j, i);
GetPrivateProfileString("Interface", szProf, NULL, szValue, 20, szIniFile);
conf.keys[j][i] = strtoul(szValue, NULL, 10);
} }
} }
GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile);
conf.log = strtoul(szValue, NULL, 10); conf.log = strtoul(szValue, NULL, 10);
} }
void SysMessage(char *fmt, ...) { void SysMessage(char *fmt, ...)
{
va_list list; va_list list;
char tmp[512]; char tmp[512];
va_start(list,fmt); va_start(list, fmt);
vsprintf(tmp,fmt,list); vsprintf(tmp, fmt, list);
va_end(list); va_end(list);
MessageBox(0, tmp, "PADwinKeyb Msg", 0); MessageBox(0, tmp, "PADwinKeyb Msg", 0);
} }
@ -131,40 +137,42 @@ s32 _PADopen(void *pDsp)
{ {
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
LoadConfig(); LoadConfig();
pthread_spin_init(&s_mutexStatus, PTHREAD_PROCESS_PRIVATE); pthread_spin_init(&s_mutexStatus, PTHREAD_PROCESS_PRIVATE);
s_keyPress[0] = s_keyPress[1] = 0; s_keyPress[0] = s_keyPress[1] = 0;
s_keyRelease[0] = s_keyRelease[1] = 0; s_keyRelease[0] = s_keyRelease[1] = 0;
if( GShwnd != NULL && GSwndProc != NULL ) {
// revert
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
}
GShwnd = (HWND)*(long*)pDsp; if (GShwnd != NULL && GSwndProc != NULL)
GSwndProc = (WNDPROC)GetWindowLongPtr(GShwnd, GWLP_WNDPROC); {
GSwndProc = ((WNDPROC)SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(PADwndProc))); // revert
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
}
return 0; GShwnd = (HWND) * (long*)pDsp;
GSwndProc = (WNDPROC)GetWindowLongPtr(GShwnd, GWLP_WNDPROC);
GSwndProc = ((WNDPROC)SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(PADwndProc)));
return 0;
} }
void _PADclose() void _PADclose()
{ {
if( GShwnd != NULL && GSwndProc != NULL ) { if (GShwnd != NULL && GSwndProc != NULL)
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc)); {
GSwndProc = NULL; SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
GShwnd = NULL; GSwndProc = NULL;
} GShwnd = NULL;
pthread_spin_destroy(&s_mutexStatus); }
pthread_spin_destroy(&s_mutexStatus);
} }
void _PADupdate(int pad) void _PADupdate(int pad)
{ {
pthread_spin_lock(&s_mutexStatus); pthread_spin_lock(&s_mutexStatus);
status[pad] |= s_keyRelease[pad]; status[pad] |= s_keyRelease[pad];
status[pad] &= ~s_keyPress[pad]; status[pad] &= ~s_keyPress[pad];
s_keyRelease[pad] = 0; s_keyRelease[pad] = 0;
s_keyPress[pad] = 0; s_keyPress[pad] = 0;
pthread_spin_unlock(&s_mutexStatus); pthread_spin_unlock(&s_mutexStatus);
} }
void CALLBACK PADupdate(int pad) void CALLBACK PADupdate(int pad)
@ -173,27 +181,28 @@ void CALLBACK PADupdate(int pad)
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
int i,pad,keyPress[2]={0},keyRelease[2]={0}; int i, pad, keyPress[2] = {0}, keyRelease[2] = {0};
static bool lbutton=false,rbutton=false; static bool lbutton = false, rbutton = false;
switch (msg) { switch (msg)
{
case WM_KEYDOWN: case WM_KEYDOWN:
if (lParam & 0x40000000) if (lParam & 0x40000000)
return TRUE; return TRUE;
i = FindKey(wparam, pad); i = FindKey(wparam, pad);
keyPress[pad] |=(1<<i); keyPress[pad] |= (1 << i);
keyRelease[pad] &=~(1<<i); keyRelease[pad] &= ~(1 << i);
event.evt = KEYPRESS; event.evt = KEYPRESS;
event.key = wParam; event.key = wParam;
break; break;
case WM_KEYUP: case WM_KEYUP:
i = FindKey(wparam, pad); i = FindKey(wparam, pad);
keyPress[pad] &=~(1<<i); keyPress[pad] &= ~(1 << i);
keyRelease[pad] |= (1<<i); keyRelease[pad] |= (1 << i);
event.evt = KEYRELEASE; event.evt = KEYRELEASE;
event.key = wParam; event.key = wParam;
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
@ -203,7 +212,7 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONUP: case WM_LBUTTONUP:
g_lanalog[0].x = 0x80; g_lanalog[0].x = 0x80;
g_lanalog[0].y = 0x80; g_lanalog[0].y = 0x80;
g_lanalog[1].x = 0x80; g_lanalog[1].x = 0x80;
g_lanalog[1].y = 0x80; g_lanalog[1].y = 0x80;
lbutton = false; lbutton = false;
break; break;
@ -215,24 +224,24 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONUP: case WM_RBUTTONUP:
g_ranalog[0].x = 0x80; g_ranalog[0].x = 0x80;
g_ranalog[0].y = 0x80; g_ranalog[0].y = 0x80;
g_ranalog[1].x = 0x80; g_ranalog[1].x = 0x80;
g_ranalog[1].y = 0x80; g_ranalog[1].y = 0x80;
rbutton = false; rbutton = false;
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
if(lbutton) if (lbutton)
{ {
g_lanalog[0].x = LOWORD(lParam) & 254; g_lanalog[0].x = LOWORD(lParam) & 254;
g_lanalog[0].y = HIWORD(lParam) & 254; g_lanalog[0].y = HIWORD(lParam) & 254;
g_lanalog[1].x = LOWORD(lParam) & 254; g_lanalog[1].x = LOWORD(lParam) & 254;
g_lanalog[1].y = HIWORD(lParam) & 254; g_lanalog[1].y = HIWORD(lParam) & 254;
} }
if(rbutton) if (rbutton)
{ {
g_ranalog[0].x = LOWORD(lParam) & 254; g_ranalog[0].x = LOWORD(lParam) & 254;
g_ranalog[0].y = HIWORD(lParam) & 254; g_ranalog[0].y = HIWORD(lParam) & 254;
g_ranalog[1].x = LOWORD(lParam) & 254; g_ranalog[1].x = LOWORD(lParam) & 254;
g_ranalog[1].y = HIWORD(lParam) & 254; g_ranalog[1].y = HIWORD(lParam) & 254;
} }
break; break;
@ -241,20 +250,21 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_QUIT: case WM_QUIT:
event.evt = KEYPRESS; event.evt = KEYPRESS;
event.key = VK_ESCAPE; event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam); return GSwndProc(hWnd, msg, wParam, lParam);
default: default:
return GSwndProc(hWnd, msg, wParam, lParam); return GSwndProc(hWnd, msg, wParam, lParam);
} }
pthread_spin_lock(&s_mutexStatus); pthread_spin_lock(&s_mutexStatus);
for(pad = 0; pad < 2; ++pad ) { for (pad = 0; pad < 2; ++pad)
s_keyPress[pad] |= keyPress[pad]; {
s_keyPress[pad] &= ~keyRelease[pad]; s_keyPress[pad] |= keyPress[pad];
s_keyRelease[pad] |= keyRelease[pad]; s_keyPress[pad] &= ~keyRelease[pad];
s_keyRelease[pad] &= ~keyPress[pad]; s_keyRelease[pad] |= keyRelease[pad];
} s_keyRelease[pad] &= ~keyPress[pad];
pthread_spin_unlock(&s_mutexStatus); }
pthread_spin_unlock(&s_mutexStatus);
return TRUE; return TRUE;
} }
@ -262,56 +272,61 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
string GetKeyLabel(const int pad, const int index) string GetKeyLabel(const int pad, const int index)
{ {
const int key = conf.keys[pad][index]; const int key = conf.keys[pad][index];
char buff[16]="NONE)"; char buff[16] = "NONE)";
if (key < 0x100) if (key < 0x100)
{ {
if (key == 0) if (key == 0)
strcpy (buff, "NONE"); strcpy(buff, "NONE");
else { else
if(key>=0x60 && key<=0x69) { {
if (key >= 0x60 && key <= 0x69)
sprintf(buff, "NumPad %c", '0' + key - 0x60); sprintf(buff, "NumPad %c", '0' + key - 0x60);
} else
else sprintf(buff, "%c", key); sprintf(buff, "%c", key);
} }
} }
else if (key >= 0x1000 && key < 0x2000) else if (key >= 0x1000 && key < 0x2000)
{ {
sprintf (buff, "J%d_%d", (key & 0xfff) / 0x100, (key & 0xff) + 1); sprintf(buff, "J%d_%d", (key & 0xfff) / 0x100, (key & 0xff) + 1);
} }
else if (key >= 0x2000 && key < 0x3000) else if (key >= 0x2000 && key < 0x3000)
{ {
static const char name[][4] = { "MIN", "MAX" }; static const char name[][4] = { "MIN", "MAX" };
const int axis = (key & 0xff); const int axis = (key & 0xff);
sprintf (buff, "J%d_AXIS%d_%s", (key & 0xfff) / 0x100, axis / 2, name[axis % 2]);
if (index >= 17 && index <= 20) sprintf(buff, "J%d_AXIS%d_%s", (key & 0xfff) / 0x100, axis / 2, name[axis % 2]);
buff[strlen (buff) -4] = '\0'; if (index >= 17 && index <= 20) buff[strlen(buff) -4] = '\0';
} }
else if (key >= 0x3000 && key < 0x4000) else if (key >= 0x3000 && key < 0x4000)
{ {
static const char name[][7] = { "FOWARD", "RIGHT", "BACK", "LEFT" }; static const char name[][7] = { "FOWARD", "RIGHT", "BACK", "LEFT" };
const int pov = (key & 0xff); const int pov = (key & 0xff);
sprintf (buff, "J%d_POV%d_%s", (key & 0xfff) / 0x100, pov /4, name[pov % 4]); sprintf(buff, "J%d_POV%d_%s", (key & 0xfff) / 0x100, pov / 4, name[pov % 4]);
} }
return buff; return buff;
} }
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hWC; HWND hWC;
TCITEM tcI; TCITEM tcI;
int i,key, numkeys; int i, key, numkeys;
u8* pkeyboard; u8* pkeyboard;
static int disabled=0; static int disabled = 0;
static int padn=0; static int padn = 0;
switch(uMsg) { switch (uMsg)
{
case WM_INITDIALOG: case WM_INITDIALOG:
LoadConfig(); LoadConfig();
padn = 0; padn = 0;
if (conf.log) CheckDlgButton(hW, IDC_LOG, TRUE); if (conf.log) CheckDlgButton(hW, IDC_LOG, TRUE);
for (i=0; i<PADKEYS; i++) { for (i = 0; i < PADKEYS; i++)
hWC = GetDlgItem(hW, IDC_L2 + i*2); {
hWC = GetDlgItem(hW, IDC_L2 + i * 2);
Button_SetText(hWC, GetKeyLabel(padn, i).c_str()); Button_SetText(hWC, GetKeyLabel(padn, i).c_str());
} }
@ -329,73 +344,85 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return TRUE; return TRUE;
case WM_TIMER: case WM_TIMER:
if (disabled){ if (disabled)
key = 0; {
//pkeyboard = SDL_GetKeyState(&numkeys); key = 0;
for (int i = 0; i < numkeys; ++i) { //pkeyboard = SDL_GetKeyState(&numkeys);
if( pkeyboard[i] ) { for (int i = 0; i < numkeys; ++i)
key = i; {
break; if (pkeyboard[i])
} {
key = i;
break;
}
} }
if( key == 0 ) { if (key == 0)
// check joystick {
} // check joystick
}
if (key != 0){
if (key != 0)
{
KillTimer(hW, 0x80); KillTimer(hW, 0x80);
hWC = GetDlgItem(hW, disabled); hWC = GetDlgItem(hW, disabled);
conf.keys[padn][disabled-IDC_L2] = key; conf.keys[padn][disabled-IDC_L2] = key;
Button_SetText(hWC, GetKeyLabel(padn, disabled-IDC_L2).c_str()); Button_SetText(hWC, GetKeyLabel(padn, disabled - IDC_L2).c_str());
EnableWindow(hWC, TRUE); EnableWindow(hWC, TRUE);
disabled=0; disabled = 0;
return TRUE; return TRUE;
} }
} }
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
for(i = IDC_L2; i <= IDC_LEFT; i+=2) for (i = IDC_L2; i <= IDC_LEFT; i += 2)
{ {
if(LOWORD(wParam) == i) if (LOWORD(wParam) == i)
{ {
if (disabled)//change selection if (disabled)//change selection
EnableWindow(GetDlgItem(hW, disabled), TRUE); EnableWindow(GetDlgItem(hW, disabled), TRUE);
EnableWindow(GetDlgItem(hW, disabled=wParam), FALSE); EnableWindow(GetDlgItem(hW, disabled = wParam), FALSE);
SetTimer(hW, 0x80, 250, NULL); SetTimer(hW, 0x80, 250, NULL);
return TRUE; return TRUE;
} }
} }
switch(LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDCANCEL: case IDCANCEL:
KillTimer(hW, 0x80); KillTimer(hW, 0x80);
EndDialog(hW, TRUE); EndDialog(hW, TRUE);
return TRUE; return TRUE;
case IDOK: case IDOK:
KillTimer(hW, 0x80); KillTimer(hW, 0x80);
if (IsDlgButtonChecked(hW, IDC_LOG)) if (IsDlgButtonChecked(hW, IDC_LOG))
conf.log = 1; conf.log = 1;
else conf.log = 0; else
conf.log = 0;
SaveConfig(); SaveConfig();
EndDialog(hW, FALSE); EndDialog(hW, FALSE);
return TRUE; return TRUE;
} }
break; break;
case WM_NOTIFY: case WM_NOTIFY:
switch (wParam) { switch (wParam)
{
case IDC_TABC: case IDC_TABC:
hWC = GetDlgItem(hW, IDC_TABC); hWC = GetDlgItem(hW, IDC_TABC);
padn = TabCtrl_GetCurSel(hWC); padn = TabCtrl_GetCurSel(hWC);
for (i=0; i<PADKEYS; i++) { for (i = 0; i < PADKEYS; i++)
{
hWC = GetDlgItem(hW, IDC_EL3 + i); hWC = GetDlgItem(hW, IDC_EL3 + i);
Button_SetText(hWC, GetKeyLabel(padn, i).c_str()); Button_SetText(hWC, GetKeyLabel(padn, i).c_str());
} }
return TRUE; return TRUE;
@ -405,13 +432,16 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE; return FALSE;
} }
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch(uMsg) { {
switch (uMsg)
{
case WM_INITDIALOG: case WM_INITDIALOG:
return TRUE; return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch(LOWORD(wParam)) { switch (LOWORD(wParam))
{
case IDOK: case IDOK:
EndDialog(hW, FALSE); EndDialog(hW, FALSE);
return TRUE; return TRUE;
@ -420,24 +450,28 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return FALSE; return FALSE;
} }
void CALLBACK PADconfigure() { void CALLBACK PADconfigure()
DialogBox(hInst, {
MAKEINTRESOURCE(IDD_DIALOG1), DialogBox(hInst,
GetActiveWindow(), MAKEINTRESOURCE(IDD_DIALOG1),
(DLGPROC)ConfigureDlgProc); GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
} }
void CALLBACK PADabout() { void CALLBACK PADabout()
{
SysMessage("Author: zerofrog\nThanks to SSSPSXPad, TwinPAD, and PADwin plugins"); SysMessage("Author: zerofrog\nThanks to SSSPSXPad, TwinPAD, and PADwin plugins");
} }
s32 CALLBACK PADtest() { s32 CALLBACK PADtest()
{
return 0; return 0;
} }
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason, DWORD dwReason,
LPVOID lpReserved) { LPVOID lpReserved)
{
hInst = (HINSTANCE)hModule; hInst = (HINSTANCE)hModule;
return TRUE; // very quick :) return TRUE; // very quick :)
} }

View File

@ -1,5 +1,5 @@
/* ZeroPAD - author: zerofrog(@gmail.com) /* ZeroPAD - author: zerofrog(@gmail.com)
* Copyright (C) 2006-2007 * Copyright (C) 2006-2007
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -40,7 +40,7 @@ keyEvent event;
u16 status[2]; u16 status[2];
int pressure; int pressure;
string s_strIniPath="inis/zeropad.ini"; string s_strIniPath = "inis/zeropad.ini";
const unsigned char version = PS2E_PAD_VERSION; const unsigned char version = PS2E_PAD_VERSION;
const unsigned char revision = 0; const unsigned char revision = 0;
@ -48,45 +48,69 @@ const unsigned char build = 2; // increase that with each version
int PadEnum[2][2] = {{0, 2}, {1, 3}}; int PadEnum[2][2] = {{0, 2}, {1, 3}};
u32 pads=0; u32 pads = 0;
u8 stdpar[2][20] = { {0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, u8 stdpar[2][20] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00}, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
{0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00},
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00}}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
u8 cmd40[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a}, 0x00, 0x00, 0x00, 0x00}
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a}}; };
u8 cmd41[2][8] = { {0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a}, u8 cmd40[2][8] = {
{0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a}}; {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a},
u8 unk46[2][8] = { {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}, {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a}
{0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}}; };
u8 unk47[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}, u8 cmd41[2][8] = {
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}}; {0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a},
u8 unk4c[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a}
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; };
u8 unk4d[2][8] = { {0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, u8 unk46[2][8] = {
{0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
u8 cmd4f[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a}, {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a}}; };
u8 stdcfg[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, u8 unk47[2][8] = {
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; // 2 & 3 = 0 {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00},
u8 stdmode[2][8] = { {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; };
u8 stdmodel[2][8] = { {0xff, 0x5a, u8 unk4c[2][8] = {
0x03, // 03 - dualshock2, 01 - dualshock {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
0x02, // number of modes {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
0x01, // current mode: 01 - analog, 00 - digital };
0x02, u8 unk4d[2][8] = {
0x01, {0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
0x00}, {0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
{0xff, 0x5a, };
0x03, // 03 - dualshock2, 01 - dualshock u8 cmd4f[2][8] = {
0x02, // number of modes {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a},
0x01, // current mode: 01 - analog, 00 - digital {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a}
0x02, };
0x01, u8 stdcfg[2][8] = {
0x00}}; {0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
}; // 2 & 3 = 0
u8 stdmode[2][8] = {
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
};
u8 stdmodel[2][8] = {
{0xff,
0x5a,
0x03, // 03 - dualshock2, 01 - dualshock
0x02, // number of modes
0x01, // current mode: 01 - analog, 00 - digital
0x02,
0x01,
0x00},
{0xff,
0x5a,
0x03, // 03 - dualshock2, 01 - dualshock
0x02, // number of modes
0x01, // current mode: 01 - analog, 00 - digital
0x02,
0x01,
0x00}
};
u8 *buf; u8 *buf;
int padID[2]; int padID[2];
@ -98,12 +122,13 @@ int cmdLen;
int ds2mode = 0; // DS Mode at start int ds2mode = 0; // DS Mode at start
FILE *padLog = NULL; FILE *padLog = NULL;
int POV(u32 direction, u32 angle){ int POV(u32 direction, u32 angle)
if ((direction==0) && (angle>= 0) && (angle< 4500)) return 1;//forward {
if ((direction==2) && (angle>= 4500) && (angle<13500)) return 1;//right if ((direction == 0) && (angle >= 0) && (angle < 4500)) return 1;//forward
if ((direction==1) && (angle>=13500) && (angle<22500)) return 1;//backward if ((direction == 2) && (angle >= 4500) && (angle < 13500)) return 1;//right
if ((direction==3) && (angle>=22500) && (angle<31500)) return 1;//left if ((direction == 1) && (angle >= 13500) && (angle < 22500)) return 1;//backward
if ((direction==0) && (angle>=31500) && (angle<36000)) return 1;//forward if ((direction == 3) && (angle >= 22500) && (angle < 31500)) return 1;//left
if ((direction == 0) && (angle >= 31500) && (angle < 36000)) return 1;//forward
return 0; return 0;
} }
@ -111,12 +136,15 @@ void _KeyPress(int pad, u32 key)
{ {
int i; int i;
for (int p=0; p <PADSUBKEYS; p++) { for (int p = 0; p < PADSUBKEYS; p++)
for (i=0; i<PADKEYS; i++) { {
if (key == conf.keys[PadEnum[pad][p]][i]) { for (i = 0; i < PADKEYS; i++)
status[pad]&=~(1<<i); {
return; if (key == conf.keys[PadEnum[pad][p]][i])
} {
status[pad] &= ~(1 << i);
return;
}
} }
} }
@ -127,11 +155,14 @@ void _KeyPress(int pad, u32 key)
void _KeyRelease(int pad, u32 key) void _KeyRelease(int pad, u32 key)
{ {
int i; int i;
for (int p=0; p <PADSUBKEYS; p++) { for (int p = 0; p < PADSUBKEYS; p++)
for (i=0; i<PADKEYS; i++) { {
if (key == conf.keys[PadEnum[pad][p]][i]) { for (i = 0; i < PADKEYS; i++)
status[pad]|= (1<<i); {
if (key == conf.keys[PadEnum[pad][p]][i])
{
status[pad] |= (1 << i);
return; return;
} }
} }
@ -149,7 +180,7 @@ static void InitLibraryName()
// Public Release! // Public Release!
// Output a simplified string that's just our name: // Output a simplified string that's just our name:
strcpy( libraryName, "ZeroPAD" ); strcpy(libraryName, "ZeroPAD");
# elif defined( SVN_REV_UNKNOWN ) # elif defined( SVN_REV_UNKNOWN )
@ -157,124 +188,139 @@ static void InitLibraryName()
// Output a name that includes devbuild status but not // Output a name that includes devbuild status but not
// subversion revision tags: // subversion revision tags:
strcpy( libraryName, "ZeroPAD" strcpy(libraryName, "ZeroPAD"
# ifdef _DEBUG # ifdef _DEBUG
"-Debug" "-Debug"
# endif # endif
); );
# else # else
// Use TortoiseSVN's SubWCRev utility's output // Use TortoiseSVN's SubWCRev utility's output
// to label the specific revision: // to label the specific revision:
sprintf_s( libraryName, "ZeroPAD r%d%s" sprintf_s(libraryName, "ZeroPAD r%d%s"
# ifdef _DEBUG # ifdef _DEBUG
"-Debug" "-Debug"
# else # else
"-Dev" "-Dev"
# endif # endif
,SVN_REV, , SVN_REV,
SVN_MODS ? "m" : "" SVN_MODS ? "m" : ""
); );
# endif # endif
#else #else
// I'll fix up SVN support later. --arcum42 // I'll fix up SVN support later. --arcum42
strcpy( libraryName, "ZeroPAD" strcpy(libraryName, "ZeroPAD"
# ifdef _DEBUG # ifdef _DEBUG
"-Debug" "-Debug"
# endif # endif
); );
#endif #endif
} }
u32 CALLBACK PS2EgetLibType() { u32 CALLBACK PS2EgetLibType()
{
return PS2E_LT_PAD; return PS2E_LT_PAD;
} }
char* CALLBACK PS2EgetLibName() { char* CALLBACK PS2EgetLibName()
{
InitLibraryName(); InitLibraryName();
return libraryName; return libraryName;
} }
u32 CALLBACK PS2EgetLibVersion2(u32 type) { u32 CALLBACK PS2EgetLibVersion2(u32 type)
return (version<<16)|(revision<<8)|build; {
return (version << 16) | (revision << 8) | build;
} }
void __Log(char *fmt, ...) { void __Log(char *fmt, ...)
{
va_list list; va_list list;
if (!conf.log || padLog == NULL) return; if (!conf.log || padLog == NULL) return;
va_start(list, fmt); va_start(list, fmt);
vfprintf(padLog, fmt, list); vfprintf(padLog, fmt, list);
va_end(list); va_end(list);
} }
s32 CALLBACK PADinit(u32 flags) { s32 CALLBACK PADinit(u32 flags)
{
#ifdef PAD_LOG #ifdef PAD_LOG
if (padLog == NULL) { if (padLog == NULL)
{
padLog = fopen("logs/padLog.txt", "w"); padLog = fopen("logs/padLog.txt", "w");
if (padLog) setvbuf(padLog, NULL, _IONBF, 0); if (padLog) setvbuf(padLog, NULL, _IONBF, 0);
} }
PAD_LOG("PADinit\n"); PAD_LOG("PADinit\n");
#endif #endif
pads|= flags; pads |= flags;
status[0] = 0xffff; status[0] = 0xffff;
status[1] = 0xffff; status[1] = 0xffff;
#ifdef __LINUX__ #ifdef __LINUX__
char strcurdir[256]; char strcurdir[256];
getcwd(strcurdir, 256); getcwd(strcurdir, 256);
s_strIniPath = strcurdir; s_strIniPath = strcurdir;
s_strIniPath += "/inis/zeropad.ini"; s_strIniPath += "/inis/zeropad.ini";
#endif #endif
LoadConfig(); LoadConfig();
PADsetMode(0, 0); PADsetMode(0, 0);
PADsetMode(1, 0); PADsetMode(1, 0);
pressure = 100; pressure = 100;
for(int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i)
g_ranalog[i].x = 0x80; {
g_ranalog[i].y = 0x80; g_ranalog[i].x = 0x80;
g_lanalog[i].x = 0x80; g_ranalog[i].y = 0x80;
g_lanalog[i].y = 0x80; g_lanalog[i].x = 0x80;
} g_lanalog[i].y = 0x80;
}
return 0; return 0;
} }
void CALLBACK PADshutdown() { void CALLBACK PADshutdown()
{
#ifdef PAD_LOG #ifdef PAD_LOG
if( padLog != NULL ) { if (padLog != NULL)
fclose(padLog); {
padLog = NULL; fclose(padLog);
} padLog = NULL;
}
#endif #endif
} }
s32 CALLBACK PADopen(void *pDsp) { s32 CALLBACK PADopen(void *pDsp)
{
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
return _PADopen(pDsp); return _PADopen(pDsp);
} }
void CALLBACK PADclose() { void CALLBACK PADclose()
{
_PADclose(); _PADclose();
} }
u32 CALLBACK PADquery() { u32 CALLBACK PADquery()
{
return 3; // both return 3; // both
} }
void PADsetMode(int pad, int mode) { void PADsetMode(int pad, int mode)
{
padMode[pad] = mode; padMode[pad] = mode;
switch(ds2mode) { switch (ds2mode)
{
case 0: // dualshock case 0: // dualshock
switch (mode) { switch (mode)
{
case 0: // digital case 0: // digital
padID[pad] = 0x41; padID[pad] = 0x41;
break; break;
@ -285,7 +331,8 @@ void PADsetMode(int pad, int mode) {
} }
break; break;
case 1: // dualshock2 case 1: // dualshock2
switch (mode) { switch (mode)
{
case 0: // digital case 0: // digital
padID[pad] = 0x41; padID[pad] = 0x41;
break; break;
@ -298,28 +345,30 @@ void PADsetMode(int pad, int mode) {
} }
} }
u8 CALLBACK PADstartPoll(int pad) { u8 CALLBACK PADstartPoll(int pad)
#ifdef PAD_LOG {
PAD_LOG("PADstartPoll: %d\n", pad); PAD_LOG("PADstartPoll: %d\n", pad);
#endif
curPad = pad-1; curPad = pad - 1;
curByte = 0; curByte = 0;
return 0xff; return 0xff;
} }
u8 _PADpoll(u8 value) { u8 _PADpoll(u8 value)
{
u8 button_check = 0, button_check2 = 0; u8 button_check = 0, button_check2 = 0;
if (curByte == 0) { if (curByte == 0)
{
curByte++; curByte++;
#ifdef PAD_LOG
PAD_LOG("PADpoll: cmd: %x\n", value); PAD_LOG("PADpoll: cmd: %x\n", value);
#endif
curCmd = value; curCmd = value;
switch (value) { switch (value)
case 0x40: // DUALSHOCK2 ENABLER {
case 0x40: // DUALSHOCK2 ENABLER
cmdLen = 8; cmdLen = 8;
buf = cmd40[curPad]; buf = cmd40[curPad];
return 0xf3; return 0xf3;
@ -331,74 +380,78 @@ u8 _PADpoll(u8 value) {
case 0x42: // READ_DATA case 0x42: // READ_DATA
_PADupdate(curPad); _PADupdate(curPad);
stdpar[curPad][2] = status[curPad] >> 8; stdpar[curPad][2] = status[curPad] >> 8;
stdpar[curPad][3] = status[curPad] & 0xff; stdpar[curPad][3] = status[curPad] & 0xff;
stdpar[curPad][4] = g_ranalog[curPad].x; stdpar[curPad][4] = g_ranalog[curPad].x;
stdpar[curPad][5] = g_ranalog[curPad].y; stdpar[curPad][5] = g_ranalog[curPad].y;
stdpar[curPad][6] = g_lanalog[curPad].x; stdpar[curPad][6] = g_lanalog[curPad].x;
stdpar[curPad][7] = g_lanalog[curPad].y; stdpar[curPad][7] = g_lanalog[curPad].y;
if (padMode[curPad] == 1) cmdLen = 20;
else cmdLen = 4; if (padMode[curPad] == 1)
cmdLen = 20;
else
cmdLen = 4;
button_check2 = stdpar[curPad][2] >> 4; button_check2 = stdpar[curPad][2] >> 4;
switch(stdpar[curPad][3]) switch (stdpar[curPad][3])
{ {
case 0xBF: // X case 0xBF: // X
stdpar[curPad][14] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][16])); stdpar[curPad][14] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][16]));
break; break;
case 0xDF: // Circle case 0xDF: // Circle
stdpar[curPad][13] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][17])); stdpar[curPad][13] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][17]));
break; break;
case 0xEF: // Triangle case 0xEF: // Triangle
stdpar[curPad][12] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][19])); stdpar[curPad][12] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][19]));
break; break;
case 0x7F: // Square case 0x7F: // Square
stdpar[curPad][15] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][18])); stdpar[curPad][15] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][18]));
break; break;
case 0xFB: // L1 case 0xFB: // L1
stdpar[curPad][16] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][26])); stdpar[curPad][16] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][26]));
break; break;
case 0xF7: // R1 case 0xF7: // R1
stdpar[curPad][17] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][28])); stdpar[curPad][17] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][28]));
break; break;
case 0xFE: // L2 case 0xFE: // L2
stdpar[curPad][18] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][27])); stdpar[curPad][18] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][27]));
break; break;
case 0xFD: // R2 case 0xFD: // R2
stdpar[curPad][19] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][29])); stdpar[curPad][19] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][29]));
break; break;
default: default:
stdpar[curPad][14] = 0x00; // Not pressed stdpar[curPad][14] = 0x00; // Not pressed
stdpar[curPad][13] = 0x00; // Not pressed stdpar[curPad][13] = 0x00; // Not pressed
stdpar[curPad][12] = 0x00; // Not pressed stdpar[curPad][12] = 0x00; // Not pressed
stdpar[curPad][15] = 0x00; // Not pressed stdpar[curPad][15] = 0x00; // Not pressed
stdpar[curPad][16] = 0x00; // Not pressed stdpar[curPad][16] = 0x00; // Not pressed
stdpar[curPad][17] = 0x00; // Not pressed stdpar[curPad][17] = 0x00; // Not pressed
stdpar[curPad][18] = 0x00; // Not pressed stdpar[curPad][18] = 0x00; // Not pressed
stdpar[curPad][19] = 0x00; // Not pressed stdpar[curPad][19] = 0x00; // Not pressed
break; break;
} }
switch(button_check2) switch (button_check2)
{ {
case 0xE: // UP case 0xE: // UP
stdpar[curPad][10] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][21])); stdpar[curPad][10] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][21]));
break; break;
case 0xB: // DOWN case 0xB: // DOWN
stdpar[curPad][11] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][22])); stdpar[curPad][11] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][22]));
break; break;
case 0x7: // LEFT case 0x7: // LEFT
stdpar[curPad][9] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][23])); stdpar[curPad][9] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][23]));
break; break;
case 0xD: // RIGHT case 0xD: // RIGHT
stdpar[curPad][8] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][24])); stdpar[curPad][8] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][24]));
break; break;
default: default:
stdpar[curPad][8] = 0x00; // Not pressed stdpar[curPad][8] = 0x00; // Not pressed
stdpar[curPad][9] = 0x00; // Not pressed stdpar[curPad][9] = 0x00; // Not pressed
stdpar[curPad][10] = 0x00; // Not pressed stdpar[curPad][10] = 0x00; // Not pressed
stdpar[curPad][11] = 0x00; // Not pressed stdpar[curPad][11] = 0x00; // Not pressed
break; break;
} }
buf = stdpar[curPad]; buf = stdpar[curPad];
return padID[curPad]; return padID[curPad];
@ -435,7 +488,7 @@ u8 _PADpoll(u8 value) {
buf = unk4c[curPad]; buf = unk4c[curPad];
return 0xf3; return 0xf3;
case 0x4d: case 0x4d:
cmdLen = 8; cmdLen = 8;
buf = unk4d[curPad]; buf = unk4d[curPad];
return 0xf3; return 0xf3;
@ -455,49 +508,56 @@ u8 _PADpoll(u8 value) {
} }
} }
switch (curCmd) { switch (curCmd)
case 0x43: {
if(curByte == 2) case 0x43:
if (curByte == 2)
{ {
switch(value){ switch (value)
case 0: {
buf[2] = 0; case 0:
buf[3] = 0; buf[2] = 0;
break; buf[3] = 0;
case 1: break;
buf[2] = 0xff; case 1:
buf[3] = 0xff; buf[2] = 0xff;
break; buf[3] = 0xff;
break;
} }
} }
break; break;
case 0x44: case 0x44:
if (curByte == 2) { if (curByte == 2)
{
PADsetMode(curPad, value); PADsetMode(curPad, value);
} }
break; break;
case 0x46: case 0x46:
if(curByte == 2) { if (curByte == 2)
switch(value) { {
case 0: // default switch (value)
buf[5] = 0x2; {
buf[6] = 0x0; case 0: // default
buf[7] = 0xA; buf[5] = 0x2;
break; buf[6] = 0x0;
case 1: // Param std conf change buf[7] = 0xA;
buf[5] = 0x1; break;
buf[6] = 0x1; case 1: // Param std conf change
buf[7] = 0x14; buf[5] = 0x1;
break; buf[6] = 0x1;
buf[7] = 0x14;
break;
} }
} }
break; break;
case 0x4c: case 0x4c:
if (curByte == 2) { if (curByte == 2)
switch (value) { {
switch (value)
{
case 0: // mode 0 - digital mode case 0: // mode 0 - digital mode
buf[5] = 0x4; buf[5] = 0x4;
break; break;
@ -517,10 +577,9 @@ u8 _PADpoll(u8 value) {
u8 CALLBACK PADpoll(u8 value) u8 CALLBACK PADpoll(u8 value)
{ {
u8 ret; u8 ret;
ret = _PADpoll(value); ret = _PADpoll(value);
#ifdef PAD_LOG
PAD_LOG("PADpoll: %x (%d: %x)\n", value, curByte, ret); PAD_LOG("PADpoll: %x (%d: %x)\n", value, curByte, ret);
#endif
return ret; return ret;
} }
@ -528,7 +587,7 @@ u8 CALLBACK PADpoll(u8 value)
static keyEvent s_event; static keyEvent s_event;
keyEvent* CALLBACK PADkeyEvent() keyEvent* CALLBACK PADkeyEvent()
{ {
s_event = event; s_event = event;
event.evt = 0; event.evt = 0;
return &s_event; return &s_event;
} }

View File

@ -40,7 +40,8 @@
using namespace std; using namespace std;
#define PADdefs #define PADdefs
extern "C" { extern "C"
{
#include "PS2Edefs.h" #include "PS2Edefs.h"
} }
@ -48,20 +49,20 @@ extern char libraryName[256];
#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); (it)++) #define FORIT(it, v) for(it = (v).begin(); it != (v).end(); (it)++)
#define IS_KEYBOARD(key) (key<0x10000) #define IS_KEYBOARD(key) (key < 0x10000)
#define IS_JOYBUTTONS(key) (key>=0x10000 && key<0x20000) // buttons #define IS_JOYBUTTONS(key) (key >= 0x10000 && key < 0x20000) // buttons
#define IS_JOYSTICK(key) (key>=0x20000&&key<0x30000) // analog #define IS_JOYSTICK(key) (key >= 0x20000 && key < 0x30000) // analog
#define IS_POV(key) (key>=0x30000&&key<0x40000) // uses analog as buttons (cares about sign) #define IS_POV(key) (key >= 0x30000 && key < 0x40000) // uses analog as buttons (cares about sign)
#define IS_MOUSE(key) (key>=0x40000&&key<0x50000) // mouse #define IS_MOUSE(key) (key >= 0x40000 && key < 0x50000) // mouse
#define PAD_GETKEY(key) ((key)&0xffff) #define PAD_GETKEY(key) ((key) & 0xffff)
#define PAD_GETJOYID(key) (((key)&0xf000)>>12) #define PAD_GETJOYID(key) (((key) & 0xf000) >> 12)
#define PAD_GETJOYBUTTON(key) ((key)&0xff) #define PAD_GETJOYBUTTON(key) ((key) & 0xff)
#define PAD_GETJOYSTICK_AXIS(key) ((key)&0xff) #define PAD_GETJOYSTICK_AXIS(key) ((key) & 0xff)
#define PAD_JOYBUTTON(joyid, buttonid) (0x10000|((joyid)<<12)|(buttonid)) #define PAD_JOYBUTTON(joyid, buttonid) (0x10000 | ((joyid) << 12) | (buttonid))
#define PAD_JOYSTICK(joyid, axisid) (0x20000|((joyid)<<12)|(axisid)) #define PAD_JOYSTICK(joyid, axisid) (0x20000 | ((joyid) << 12) | (axisid))
#define PAD_POV(joyid, sign, axisid) (0x30000|((joyid)<<12)|((sign)<<8)|(axisid)) #define PAD_POV(joyid, sign, axisid) (0x30000 | ((joyid) << 12) | ((sign) << 8) | (axisid))
#define PAD_GETPOVSIGN(key) (((key)&0x100)>>8) #define PAD_GETPOVSIGN(key) (((key) & 0x100) >> 8)
#define PADKEYS 20 #define PADKEYS 20
@ -74,14 +75,16 @@ extern char libraryName[256];
#define PADSUBKEYS 2 #define PADSUBKEYS 2
extern int PadEnum[2][2]; extern int PadEnum[2][2];
typedef struct { typedef struct
{
unsigned long keys[2 * PADSUBKEYS][PADKEYS]; unsigned long keys[2 * PADSUBKEYS][PADKEYS];
int log; int log;
int options; // upper 16 bits are for pad2 int options; // upper 16 bits are for pad2
} PADconf; } PADconf;
typedef struct { typedef struct
u8 x,y; {
u8 x, y;
} PADAnalog; } PADAnalog;
extern PADconf conf; extern PADconf conf;
@ -90,28 +93,31 @@ extern PADAnalog g_lanalog[2], g_ranalog[2];
extern FILE *padLog; extern FILE *padLog;
#define PAD_LOG __Log #define PAD_LOG __Log
#define PAD_RY 19 enum gamePadValues
#define PAD_LY 18 {
#define PAD_RX 17 PAD_RY = 19,
#define PAD_LX 16 PAD_LY = 18,
#define PAD_LEFT 15 PAD_RX = 17,
#define PAD_DOWN 14 PAD_LX = 16,
#define PAD_RIGHT 13 PAD_LEFT = 15,
#define PAD_UP 12 PAD_DOWN = 14,
#define PAD_START 11 PAD_RIGHT = 13,
#define PAD_R3 10 PAD_UP = 12,
#define PAD_L3 9 PAD_START = 11,
#define PAD_SELECT 8 PAD_R3 = 10,
#define PAD_SQUARE 7 PAD_L3 = 9,
#define PAD_CROSS 6 PAD_SELECT = 8,
#define PAD_CIRCLE 5 PAD_SQUARE = 7,
#define PAD_TRIANGLE 4 PAD_CROSS = 6,
#define PAD_R1 3 PAD_CIRCLE = 5,
#define PAD_L1 2 PAD_TRIANGLE = 4,
#define PAD_R2 1 PAD_R1 = 3,
#define PAD_L2 0 PAD_L1 = 2,
PAD_R2 = 1,
PAD_L2 = 0
};
// Put in the code for bolche's analog contols hack, ifdeffed out, so I don't forget to // Put in the code for bolche's analog contols hack, ifdeffed out, so I don't forget to
// add a gui some day and activate it. // add a gui some day and activate it.
//#define ANALOG_CONTROLS_HACK //#define ANALOG_CONTROLS_HACK
// The various KEY_PAD_xxx definitions are defined as the value of whatever key is pressed. // The various KEY_PAD_xxx definitions are defined as the value of whatever key is pressed.
@ -151,11 +157,11 @@ void SaveConfig();
void SysMessage(char *fmt, ...); void SysMessage(char *fmt, ...);
inline int FindKey(int key, int pad) { inline int FindKey(int key, int pad)
for (int p=0; p < PADSUBKEYS; p++) {
for (int i=0; i<PADKEYS; i++) for (int p = 0; p < PADSUBKEYS; p++)
if (key == conf.keys[(PadEnum[pad][p])][i]) for (int i = 0; i < PADKEYS; i++)
return i; if (key == conf.keys[(PadEnum[pad][p])][i]) return i;
} }
#endif #endif