2009-02-09 21:15:56 +00:00
|
|
|
/* ZeroPAD - author: zerofrog(@gmail.com)
|
2009-05-03 12:19:58 +00:00
|
|
|
* Copyright (C) 2006-2007
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2009-05-29 06:33:56 +00:00
|
|
|
#include "win.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
extern u16 status[2];
|
|
|
|
|
|
|
|
extern string s_strIniPath;
|
2009-05-27 13:10:43 +00:00
|
|
|
WNDPROC GSwndProc = NULL;
|
|
|
|
HWND GShwnd = NULL;
|
2009-05-29 08:39:32 +00:00
|
|
|
HINSTANCE hInst = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
extern keyEvent event;
|
|
|
|
|
|
|
|
s32 _PADopen(void *pDsp)
|
|
|
|
{
|
2009-05-27 13:10:43 +00:00
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
if (GShwnd != NULL && GSwndProc != NULL)
|
|
|
|
{
|
|
|
|
// revert
|
|
|
|
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
|
|
|
|
}
|
|
|
|
|
|
|
|
GShwnd = (HWND) * (long*)pDsp;
|
|
|
|
GSwndProc = (WNDPROC)GetWindowLongPtr(GShwnd, GWLP_WNDPROC);
|
|
|
|
GSwndProc = ((WNDPROC)SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(PADwndProc)));
|
|
|
|
|
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _PADclose()
|
|
|
|
{
|
2009-05-27 13:10:43 +00:00
|
|
|
if (GShwnd != NULL && GSwndProc != NULL)
|
|
|
|
{
|
|
|
|
SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)(GSwndProc));
|
|
|
|
GSwndProc = NULL;
|
|
|
|
GShwnd = NULL;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-29 06:33:56 +00:00
|
|
|
// Yes, let's not do anything when pcsx2 asks for us for an update.
|
|
|
|
// We certainly don't want to update the gamepad information...
|
2009-02-09 21:15:56 +00:00
|
|
|
void CALLBACK PADupdate(int pad)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-05-29 06:33:56 +00:00
|
|
|
// Most of the values look off in here by either a factor of 10 or 100.
|
2009-02-09 21:15:56 +00:00
|
|
|
string GetKeyLabel(const int pad, const int index)
|
|
|
|
{
|
2009-05-27 13:10:43 +00:00
|
|
|
const int key = conf.keys[pad][index];
|
|
|
|
char buff[16] = "NONE)";
|
2009-05-29 06:33:56 +00:00
|
|
|
if (key < 0x100) //IS_KEYBOARD; should be 0x10000
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
|
|
|
if (key == 0)
|
|
|
|
strcpy(buff, "NONE");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (key >= 0x60 && key <= 0x69)
|
|
|
|
sprintf(buff, "NumPad %c", '0' + key - 0x60);
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-05-29 06:33:56 +00:00
|
|
|
sprintf(buff, "%c", key);
|
2009-05-27 13:10:43 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-29 06:33:56 +00:00
|
|
|
else if (key >= 0x1000 && key < 0x2000) //IS_JOYBUTTONS; 0x10000 - 0x20000
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
|
|
|
sprintf(buff, "J%d_%d", (key & 0xfff) / 0x100, (key & 0xff) + 1);
|
|
|
|
}
|
2009-05-29 06:33:56 +00:00
|
|
|
else if (key >= 0x2000 && key < 0x3000) // IS_JOYSTICK; 0x20000 - 0x30000
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
|
|
|
static const char name[][4] = { "MIN", "MAX" };
|
|
|
|
const int axis = (key & 0xff);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
sprintf(buff, "J%d_AXIS%d_%s", (key & 0xfff) / 0x100, axis / 2, name[axis % 2]);
|
2009-05-29 06:33:56 +00:00
|
|
|
if (index >= 17 && index <= 20) buff[strlen(buff) -4] = '\0';
|
2009-05-27 13:10:43 +00:00
|
|
|
}
|
2009-05-29 06:33:56 +00:00
|
|
|
else if (key >= 0x3000 && key < 0x4000) // IS_POV; 0x30000 - 0x50000
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
2009-05-29 08:39:32 +00:00
|
|
|
static const char name[][8] = { "FORWARD", "RIGHT", "BACK", "LEFT" };
|
2009-05-27 13:10:43 +00:00
|
|
|
const int pov = (key & 0xff);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
sprintf(buff, "J%d_POV%d_%s", (key & 0xfff) / 0x100, pov / 4, name[pov % 4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buff;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HWND hWC;
|
|
|
|
TCITEM tcI;
|
2009-05-29 08:39:32 +00:00
|
|
|
int i, key;
|
|
|
|
int numkeys;
|
|
|
|
//u8* pkeyboard;
|
2009-05-27 13:10:43 +00:00
|
|
|
static int disabled = 0;
|
|
|
|
static int padn = 0;
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
LoadConfig();
|
|
|
|
padn = 0;
|
2009-05-29 06:33:56 +00:00
|
|
|
if (conf.log) CheckDlgButton(hW, IDC_LOG, TRUE);
|
2009-05-27 13:10:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < PADKEYS; i++)
|
|
|
|
{
|
|
|
|
hWC = GetDlgItem(hW, IDC_L2 + i * 2);
|
|
|
|
Button_SetText(hWC, GetKeyLabel(padn, i).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
hWC = GetDlgItem(hW, IDC_TABC);
|
|
|
|
|
|
|
|
tcI.mask = TCIF_TEXT;
|
|
|
|
tcI.pszText = "PAD 1";
|
|
|
|
|
|
|
|
TabCtrl_InsertItem(hWC, 0, &tcI);
|
|
|
|
|
|
|
|
tcI.mask = TCIF_TEXT;
|
|
|
|
tcI.pszText = "PAD 2";
|
|
|
|
|
|
|
|
TabCtrl_InsertItem(hWC, 1, &tcI);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
if (disabled)
|
|
|
|
{
|
|
|
|
//pkeyboard = SDL_GetKeyState(&numkeys);
|
2009-05-29 08:39:32 +00:00
|
|
|
// Well, this doesn't exactly work either, but it's close...
|
|
|
|
numkeys = 256;
|
2009-05-27 13:10:43 +00:00
|
|
|
for (int i = 0; i < numkeys; ++i)
|
|
|
|
{
|
2009-05-29 08:39:32 +00:00
|
|
|
if (GetAsyncKeyState(i))
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
|
|
|
key = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-29 08:39:32 +00:00
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
if (key == 0)
|
|
|
|
{
|
|
|
|
// check joystick
|
|
|
|
}
|
2009-05-29 06:33:56 +00:00
|
|
|
else
|
2009-05-27 13:10:43 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
// Get rid of the expired timer, try to configure the keys, fail horribly,
|
2009-05-29 06:33:56 +00:00
|
|
|
// and either crash or don't register a keypress.
|
2009-05-27 13:10:43 +00:00
|
|
|
KillTimer(hW, 0x80);
|
|
|
|
hWC = GetDlgItem(hW, disabled);
|
|
|
|
conf.keys[padn][disabled-IDC_L2] = key;
|
|
|
|
Button_SetText(hWC, GetKeyLabel(padn, disabled - IDC_L2).c_str());
|
|
|
|
EnableWindow(hWC, TRUE);
|
|
|
|
disabled = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
for (i = IDC_L2; i <= IDC_LEFT; i += 2)
|
|
|
|
{
|
|
|
|
if (LOWORD(wParam) == i)
|
|
|
|
{
|
2009-05-29 06:33:56 +00:00
|
|
|
// A button was pressed
|
2009-05-27 13:10:43 +00:00
|
|
|
if (disabled)//change selection
|
|
|
|
EnableWindow(GetDlgItem(hW, disabled), TRUE);
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(hW, disabled = wParam), FALSE);
|
|
|
|
|
2009-05-29 08:39:32 +00:00
|
|
|
SetTimer(hW, 0x80, 2500, NULL);
|
2009-05-27 13:10:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDCANCEL:
|
|
|
|
KillTimer(hW, 0x80);
|
|
|
|
EndDialog(hW, TRUE);
|
|
|
|
return TRUE;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
case IDOK:
|
|
|
|
KillTimer(hW, 0x80);
|
|
|
|
if (IsDlgButtonChecked(hW, IDC_LOG))
|
|
|
|
conf.log = 1;
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-05-29 06:33:56 +00:00
|
|
|
conf.log = 0;
|
2009-05-27 13:10:43 +00:00
|
|
|
SaveConfig();
|
|
|
|
EndDialog(hW, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case IDC_TABC:
|
|
|
|
hWC = GetDlgItem(hW, IDC_TABC);
|
|
|
|
padn = TabCtrl_GetCurSel(hWC);
|
|
|
|
|
|
|
|
for (i = 0; i < PADKEYS; i++)
|
|
|
|
{
|
|
|
|
hWC = GetDlgItem(hW, IDC_EL3 + i);
|
|
|
|
Button_SetText(hWC, GetKeyLabel(padn, i).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
EndDialog(hW, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
void CALLBACK PADconfigure()
|
|
|
|
{
|
2009-05-29 08:39:32 +00:00
|
|
|
INT_PTR ret;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-29 08:39:32 +00:00
|
|
|
ret = DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DIALOG1),GetActiveWindow(),(DLGPROC)ConfigureDlgProc,1);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
void CALLBACK PADabout()
|
|
|
|
{
|
|
|
|
SysMessage("Author: zerofrog\nThanks to SSSPSXPad, TwinPAD, and PADwin plugins");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 13:10:43 +00:00
|
|
|
s32 CALLBACK PADtest()
|
|
|
|
{
|
|
|
|
return 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
|
2009-05-03 12:19:58 +00:00
|
|
|
DWORD dwReason,
|
2009-05-27 13:10:43 +00:00
|
|
|
LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
hInst = (HINSTANCE)hModule;
|
|
|
|
return TRUE; // very quick :)
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|