diff --git a/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.sln b/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.sln deleted file mode 100644 index afec1cc6ca..0000000000 --- a/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.sln +++ /dev/null @@ -1,20 +0,0 @@ -ïğż -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_nJoy_SDL", "Plugin_nJoy_SDL\Plugin_nJoy_SDL.vcproj", "{521498BE-6089-4780-8223-E67C22F4E068}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {521498BE-6089-4780-8223-E67C22F4E068}.Debug|Win32.ActiveCfg = Debug|Win32 - {521498BE-6089-4780-8223-E67C22F4E068}.Debug|Win32.Build.0 = Debug|Win32 - {521498BE-6089-4780-8223-E67C22F4E068}.Release|Win32.ActiveCfg = Release|Win32 - {521498BE-6089-4780-8223-E67C22F4E068}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj b/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj new file mode 100644 index 0000000000..fda17af388 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Plugin_nJoy_SDL.vcproj @@ -0,0 +1,559 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Plugins/Plugin_nJoy_SDL/Res/Plugin_nJoy_SDL.rc b/Source/Plugins/Plugin_nJoy_SDL/Res/Plugin_nJoy_SDL.rc new file mode 100644 index 0000000000..824e357d42 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Res/Plugin_nJoy_SDL.rc @@ -0,0 +1,158 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Dutch (Netherlands) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NLD) +#ifdef _WIN32 +LANGUAGE LANG_DUTCH, SUBLANG_DUTCH +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_CONFIG DIALOGEX 0, 0, 411, 282 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + COMBOBOX IDC_JOYNAME,8,18,317,30,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Controller:",IDC_STATIC,3,7,405,28 + CONTROL 102,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE | SS_SUNKEN,65,46,281,187 + CONTROL "Controller attached",IDC_JOYATTACH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,330,19,73,10 + PUSHBUTTON "",IDC_SHOULDERL,46,50,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_B,350,50,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_SHOULDERR,350,66,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_Z,350,90,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_Y,350,106,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_X,350,150,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_A,350,173,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_SX,351,217,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_START,197,236,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_DPAD,46,183,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_MX,46,135,15,10,0,WS_EX_STATICEDGE + CTEXT "",IDTEXT_SHOULDERL,4,49,40,12,WS_BORDER + CTEXT "",IDTEXT_B,368,49,40,12,WS_BORDER + CTEXT "",IDTEXT_SHOULDERR,368,65,40,12,WS_BORDER + CTEXT "",IDTEXT_Z,368,89,40,12,WS_BORDER + CTEXT "",IDTEXT_Y,368,105,40,12,WS_BORDER + CTEXT "",IDTEXT_X,368,149,40,12,WS_BORDER + CTEXT "",IDTEXT_A,368,172,40,12,WS_BORDER + CTEXT "",IDTEXT_MX,4,134,40,12,WS_BORDER + CTEXT "",IDTEXT_DPAD,4,182,40,12,WS_BORDER + CTEXT "",IDTEXT_START,185,248,40,12,WS_BORDER + CTEXT "",IDTEXT_MY,3,157,40,12,WS_BORDER + LTEXT "X-axis",IDC_STATIC,4,124,20,8 + LTEXT "Y-axis",IDC_STATIC,4,147,20,8 + CTEXT "",IDTEXT_SX,368,216,40,12,WS_BORDER + CTEXT "",IDTEXT_SY,367,239,40,12,WS_BORDER + LTEXT "X-axis",IDC_STATIC,368,206,20,8 + LTEXT "Y-axis",IDC_STATIC,368,229,20,8 + PUSHBUTTON "",IDC_SY,351,240,15,10,0,WS_EX_STATICEDGE + PUSHBUTTON "",IDC_MY,46,158,15,10,0,WS_EX_STATICEDGE + GROUPBOX "Extra settings",IDC_STATIC,3,236,95,43 + LTEXT "Deadzone",IDC_STATIC,11,248,33,8 + LTEXT "Half press",IDC_STATIC,11,263,33,8 + COMBOBOX IDC_DEADZONE,45,246,48,30,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_HALFPRESS,45,261,48,30,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP + LTEXT "www.multigesture.net",IDC_STATIC,336,271,72,8 +END + +IDD_ABOUT DIALOGEX 0, 0, 133, 227 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION +CAPTION "About: nJoy Input Plugin" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,75,209,50,14 + CONTROL 104,IDC_STATIC,"Static",SS_BITMAP,0,0,133,37 + GROUPBOX "Plugin info:",IDC_STATIC,7,39,120,42 + GROUPBOX "Special thanks to:",IDC_STATIC,7,84,120,24 + GROUPBOX "Greetings to:",IDC_STATIC,7,112,120,95 + LTEXT "",IDC_ABOUT_TEXT,13,51,108,24 + LTEXT "F|RES and ector.",IDC_STATIC,13,95,108,8 + LTEXT "Static",IDC_ABOUT_TEXT2,13,123,111,82 + LTEXT "BETA RELEASE",IDC_ABOUT_TEXT3,10,211,62,13 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_CONFIG, DIALOG + BEGIN + LEFTMARGIN, 3 + RIGHTMARGIN, 408 + TOPMARGIN, 7 + BOTTOMMARGIN, 279 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_BITMAP1 BITMAP "controller.bmp" +IDB_BITMAP2 BITMAP "njoy.bmp" +#endif // Dutch (Netherlands) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/Source/Plugins/Plugin_nJoy_SDL/Res/controller.bmp b/Source/Plugins/Plugin_nJoy_SDL/Res/controller.bmp new file mode 100644 index 0000000000..71af2c83b0 Binary files /dev/null and b/Source/Plugins/Plugin_nJoy_SDL/Res/controller.bmp differ diff --git a/Source/Plugins/Plugin_nJoy_SDL/Res/njoy.bmp b/Source/Plugins/Plugin_nJoy_SDL/Res/njoy.bmp new file mode 100644 index 0000000000..7720162f6b Binary files /dev/null and b/Source/Plugins/Plugin_nJoy_SDL/Res/njoy.bmp differ diff --git a/Source/Plugins/Plugin_nJoy_SDL/Res/resource.h b/Source/Plugins/Plugin_nJoy_SDL/Res/resource.h new file mode 100644 index 0000000000..02c72845d6 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Res/resource.h @@ -0,0 +1,60 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Plugin_nJoy_SDL.rc +// +#define IDD_CONFIG 101 +#define IDB_BITMAP1 102 +#define IDD_ABOUT 103 +#define IDB_BITMAP2 104 +#define IDC_JOYNAME 1001 +#define IDC_JOYATTACH 1002 + +#define IDC_SHOULDERL 1010 +#define IDC_SHOULDERR 1011 +#define IDC_A 1012 +#define IDC_B 1013 +#define IDC_X 1014 +#define IDC_Y 1015 +#define IDC_Z 1016 +#define IDC_START 1017 + +#define IDC_DPAD 1018 +#define IDC_MX 1019 +#define IDC_MY 1020 +#define IDC_SX 1021 +#define IDC_SY 1022 + +#define IDC_DEADZONE 1023 +#define IDC_HALFPRESS 1024 + +#define IDTEXT_SHOULDERL 2010 +#define IDTEXT_SHOULDERR 2011 +#define IDTEXT_A 2012 +#define IDTEXT_B 2013 +#define IDTEXT_X 2014 +#define IDTEXT_Y 2015 +#define IDTEXT_Z 2016 +#define IDTEXT_START 2017 + +#define IDTEXT_DPAD 2018 +#define IDTEXT_MX 2019 +#define IDTEXT_MY 2020 +#define IDTEXT_SX 2021 +#define IDTEXT_SY 2022 + + +#define IDC_ABOUT_TEXT 1032 +#define IDC_ABOUT_TEXT2 1033 +#define IDC_ABOUT_TEXT3 1034 + + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 105 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1036 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/config.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/config.cpp new file mode 100644 index 0000000000..24e2a9c121 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/config.cpp @@ -0,0 +1,520 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// Project description +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +// Name: nJoy +// Description: A Dolphin Compatible Input Plugin +// +// Author: Falcon4ever (nJoy@falcon4ever.com) +// Site: www.multigesture.net +// Copyright (C) 2003-2008 Dolphin Project. +// +////////////////////////////////////////////////////////////////////////////////////////// +// +// Licensetype: GNU General Public License (GPL) +// +// 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, version 2.0. +// +// 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 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// +////////////////////////////////////////////////////////////////////////////////////////// + +#include "nJoy.h" + +extern CONTROLLER_INFO *joyinfo; +extern CONTROLLER_MAPPING joysticks[4]; +extern bool emulator_running; + +// Create dialog and pages +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +int OpenConfig(HINSTANCE hInst, HWND _hParent) +{ + PROPSHEETPAGE psp[4]; + PROPSHEETHEADER psh; + + psp[0].dwSize = sizeof(PROPSHEETPAGE); + psp[0].dwFlags = PSP_USETITLE; + psp[0].hInstance = hInst; + psp[0].pszTemplate = MAKEINTRESOURCE(IDD_CONFIG); + psp[0].pszIcon = NULL; + psp[0].pfnDlgProc = (DLGPROC)ControllerTab1; + psp[0].pszTitle = "Controller 1"; + psp[0].lParam = 0; + + psp[1].dwSize = sizeof(PROPSHEETPAGE); + psp[1].dwFlags = PSP_USETITLE; + psp[1].hInstance = hInst; + psp[1].pszTemplate = MAKEINTRESOURCE(IDD_CONFIG); + psp[1].pszIcon = NULL; + psp[1].pfnDlgProc = (DLGPROC)ControllerTab2; + psp[1].pszTitle = "Controller 2"; + psp[1].lParam = 0; + + psp[2].dwSize = sizeof(PROPSHEETPAGE); + psp[2].dwFlags = PSP_USETITLE; + psp[2].hInstance = hInst; + psp[2].pszTemplate = MAKEINTRESOURCE(IDD_CONFIG); + psp[2].pszIcon = NULL; + psp[2].pfnDlgProc = (DLGPROC)ControllerTab3; + psp[2].pszTitle = "Controller 3"; + psp[2].lParam = 0; + + psp[3].dwSize = sizeof(PROPSHEETPAGE); + psp[3].dwFlags = PSP_USETITLE; + psp[3].hInstance = hInst; + psp[3].pszTemplate = MAKEINTRESOURCE(IDD_CONFIG); + psp[3].pszIcon = NULL; + psp[3].pfnDlgProc = (DLGPROC)ControllerTab4; + psp[3].pszTitle = "Controller 4"; + psp[3].lParam = 0; + + psh.dwSize = sizeof(PROPSHEETHEADER); + psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP; + psh.hwndParent = _hParent; + psh.hInstance = hInst; + psh.pszIcon = NULL; + #ifndef _DEBUG + psh.pszCaption = (LPSTR) "Configure: nJoy v"INPUT_VERSION " Input Plugin"; + #else + psh.pszCaption = (LPSTR) "Configure: nJoy v"INPUT_VERSION " (Debug) Input Plugin"; + #endif + psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE); + psh.ppsp = (LPCPROPSHEETPAGE) &psp; + + return (int)(PropertySheet(&psh)); +} + +// Create Tab +// ŻŻŻŻŻŻŻŻŻŻ +BOOL APIENTRY ControllerTab1(HWND hDlg, UINT message, UINT wParam, LONG lParam) +{ + return ControllerTab(hDlg, message, wParam, lParam, 0); +} + +BOOL APIENTRY ControllerTab2(HWND hDlg, UINT message, UINT wParam, LONG lParam) +{ + return ControllerTab(hDlg, message, wParam, lParam, 1); +} + +BOOL APIENTRY ControllerTab3(HWND hDlg, UINT message, UINT wParam, LONG lParam) +{ + return ControllerTab(hDlg, message, wParam, lParam, 2); +} + +BOOL APIENTRY ControllerTab4(HWND hDlg, UINT message, UINT wParam, LONG lParam) +{ + return ControllerTab(hDlg, message, wParam, lParam, 3); +} + +// Create Controller Tab +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +BOOL ControllerTab(HWND hDlg, UINT message, UINT wParam, LONG lParam, int controller) +{ + switch (message) + { + case WM_INITDIALOG: + // Prevent user from changing the joystick while emulation is running + if(emulator_running) + { + ComboBox_Enable(GetDlgItem(hDlg, IDC_JOYNAME), FALSE); + Button_Enable(GetDlgItem(hDlg, IDC_JOYATTACH), FALSE); + } + else + { + ComboBox_Enable(GetDlgItem(hDlg, IDC_JOYNAME), TRUE); + Button_Enable(GetDlgItem(hDlg, IDC_JOYATTACH), TRUE); + } + + // Search for devices and add the to the device list + if(Search_Devices()) + { + HWND CB = GetDlgItem(hDlg, IDC_JOYNAME); + for(int x = 0; x < SDL_NumJoysticks(); x++) + { + SendMessage(CB, CB_ADDSTRING, 0, reinterpret_cast((LPCTSTR)joyinfo[x].Name)); + } + + char buffer [8]; + CB = GetDlgItem(hDlg, IDC_DEADZONE); + SendMessage(CB, CB_RESETCONTENT, 0, 0); + for(int x = 1; x <= 100; x++) + { + sprintf (buffer, "%d %%", x); + SendMessage(CB, CB_ADDSTRING, 0, reinterpret_cast((LPCTSTR)buffer)); + } + + SetControllerAll(hDlg, controller); + return TRUE; + } + else + { + HWND CB = GetDlgItem(hDlg, IDC_JOYNAME); + SendMessage(CB, CB_ADDSTRING, 0, (LPARAM)"No Joystick detected!"); + SendMessage(CB, CB_SETCURSEL, 0, 0); + return FALSE; + } + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_JOYNAME: + { + // Selected a different joystick + if(HIWORD(wParam) == CBN_SELCHANGE) + { + joysticks[controller].ID = (int)SendMessage(GetDlgItem(hDlg, IDC_JOYNAME), CB_GETCURSEL, 0, 0); + } + return TRUE; + } + break; + + case IDC_SHOULDERL: + case IDC_SHOULDERR: + case IDC_A: + case IDC_B: + case IDC_X: + case IDC_Y: + case IDC_Z: + case IDC_START: + { + GetButtons(hDlg, LOWORD(wParam), controller); + return TRUE; + } + break; + + case IDC_DPAD: + { + GetHats(hDlg, LOWORD(wParam), controller); + return TRUE; + } + break; + + case IDC_SX: + case IDC_SY: + case IDC_MX: + case IDC_MY: + { + GetAxis(hDlg, LOWORD(wParam), controller); + return TRUE; + } + break; + } + break; + + case WM_DESTROY: + GetControllerAll(hDlg, controller); + break; + } + return FALSE; +} + +// Wait for button press +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +bool GetButtons(HWND hDlg, int buttonid, int controller) +{ + buttonid += 1000; + + SDL_Joystick *joy; + joy=SDL_JoystickOpen(joysticks[controller].ID); + + char format[128]; + int buttons = SDL_JoystickNumButtons(joy); + bool waiting = true; + bool succeed = false; + int pressed = 0; + + int counter1 = 0; + int counter2 = 10; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + while(waiting) + { + SDL_JoystickUpdate(); + for(int b = 0; b < buttons; b++) + { + if(SDL_JoystickGetButton(joy, b)) + { + pressed = b; + waiting = false; + succeed = true; + break; + } + } + + counter1++; + if(counter1==100) + { + counter1=0; + counter2--; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + if(counter2<0) + waiting = false; + } + Sleep(10); + } + + if(succeed) + sprintf(format, "%d", pressed); + else + sprintf(format, "-1", pressed); + SetDlgItemText(hDlg, buttonid, format); + + if(SDL_JoystickOpened(joysticks[controller].ID)) + SDL_JoystickClose(joy); + + return true; +} + +// Wait for D-Pad +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +bool GetHats(HWND hDlg, int buttonid, int controller) +{ + buttonid += 1000; + + SDL_Joystick *joy; + joy=SDL_JoystickOpen(joysticks[controller].ID); + + char format[128]; + int hats = SDL_JoystickNumHats(joy); + bool waiting = true; + bool succeed = false; + int pressed = 0; + + int counter1 = 0; + int counter2 = 10; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + while(waiting) + { + SDL_JoystickUpdate(); + for(int b = 0; b < hats; b++) + { + if(SDL_JoystickGetHat(joy, b)) + { + pressed = b; + waiting = false; + succeed = true; + break; + } + } + + counter1++; + if(counter1==100) + { + counter1=0; + counter2--; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + if(counter2<0) + waiting = false; + } + Sleep(10); + } + + if(succeed) + sprintf(format, "%d", pressed); + else + sprintf(format, "-1", pressed); + SetDlgItemText(hDlg, buttonid, format); + + if(SDL_JoystickOpened(joysticks[controller].ID)) + SDL_JoystickClose(joy); + + return true; +} + +// Wait for Analog +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +bool GetAxis(HWND hDlg, int buttonid, int controller) +{ + buttonid += 1000; + + SDL_Joystick *joy; + joy=SDL_JoystickOpen(joysticks[controller].ID); + + char format[128]; + int axes = SDL_JoystickNumAxes(joy); + bool waiting = true; + bool succeed = false; + int pressed = 0; + Sint16 value; + + int counter1 = 0; + int counter2 = 10; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + while(waiting) + { + SDL_JoystickUpdate(); + for(int b = 0; b < axes; b++) + { + value = SDL_JoystickGetAxis(joy, b); + if(value < -10000 || value > 10000) + { + pressed = b; + waiting = false; + succeed = true; + break; + } + } + + counter1++; + if(counter1==100) + { + counter1=0; + counter2--; + + sprintf(format, "[%d]", counter2); + SetDlgItemText(hDlg, buttonid, format); + + if(counter2<0) + waiting = false; + } + Sleep(10); + } + + if(succeed) + sprintf(format, "%d", pressed); + else + sprintf(format, "-1", pressed); + SetDlgItemText(hDlg, buttonid, format); + + if(SDL_JoystickOpened(joysticks[controller].ID)) + SDL_JoystickClose(joy); + + return true; +} + +// Set dialog items +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void SetControllerAll(HWND hDlg, int controller) +{ + SendMessage(GetDlgItem(hDlg, IDC_JOYNAME), CB_SETCURSEL, joysticks[controller].ID, 0); + + SetButton(hDlg, IDTEXT_SHOULDERL, joysticks[controller].buttons[CTL_L_SHOULDER]); + SetButton(hDlg, IDTEXT_SHOULDERR, joysticks[controller].buttons[CTL_R_SHOULDER]); + SetButton(hDlg, IDTEXT_A, joysticks[controller].buttons[CTL_A_BUTTON]); + SetButton(hDlg, IDTEXT_B, joysticks[controller].buttons[CTL_B_BUTTON]); + SetButton(hDlg, IDTEXT_X, joysticks[controller].buttons[CTL_X_BUTTON]); + SetButton(hDlg, IDTEXT_Y, joysticks[controller].buttons[CTL_Y_BUTTON]); + SetButton(hDlg, IDTEXT_Z, joysticks[controller].buttons[CTL_Z_TRIGGER]); + SetButton(hDlg, IDTEXT_START, joysticks[controller].buttons[CTL_START]); + + SetButton(hDlg, IDTEXT_DPAD, joysticks[controller].dpad); + + SetButton(hDlg, IDTEXT_MX, joysticks[controller].axis[CTL_MAIN_X]); + SetButton(hDlg, IDTEXT_MY, joysticks[controller].axis[CTL_MAIN_Y]); + SetButton(hDlg, IDTEXT_SX, joysticks[controller].axis[CTL_SUB_X]); + SetButton(hDlg, IDTEXT_SY, joysticks[controller].axis[CTL_SUB_Y]); + + SendDlgItemMessage(hDlg, IDC_JOYATTACH, BM_SETCHECK, joysticks[controller].enabled, 0); + + SendMessage(GetDlgItem(hDlg, IDC_DEADZONE), CB_SETCURSEL, joysticks[controller].deadzone, 0); +} + +// Get dialog items +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void GetControllerAll(HWND hDlg, int controller) +{ + joysticks[controller].ID = (int)SendMessage(GetDlgItem(hDlg, IDC_JOYNAME), CB_GETCURSEL, 0, 0); + + joysticks[controller].buttons[CTL_L_SHOULDER] = GetButton(hDlg, IDTEXT_SHOULDERL); + joysticks[controller].buttons[CTL_R_SHOULDER] = GetButton(hDlg, IDTEXT_SHOULDERR); + joysticks[controller].buttons[CTL_A_BUTTON] = GetButton(hDlg, IDTEXT_A); + joysticks[controller].buttons[CTL_B_BUTTON] = GetButton(hDlg, IDTEXT_B); + joysticks[controller].buttons[CTL_X_BUTTON] = GetButton(hDlg, IDTEXT_X); + joysticks[controller].buttons[CTL_Y_BUTTON] = GetButton(hDlg, IDTEXT_Y); + joysticks[controller].buttons[CTL_Z_TRIGGER] = GetButton(hDlg, IDTEXT_Z); + joysticks[controller].buttons[CTL_START] = GetButton(hDlg, IDTEXT_START); + + joysticks[controller].dpad = GetButton(hDlg, IDTEXT_DPAD); + + joysticks[controller].axis[CTL_MAIN_X] = GetButton(hDlg, IDTEXT_MX); + joysticks[controller].axis[CTL_MAIN_Y] = GetButton(hDlg, IDTEXT_MY); + joysticks[controller].axis[CTL_SUB_X] = GetButton(hDlg, IDTEXT_SX); + joysticks[controller].axis[CTL_SUB_Y] = GetButton(hDlg, IDTEXT_SY); + + joysticks[controller].enabled = (int)SendMessage(GetDlgItem(hDlg, IDC_JOYATTACH), BM_GETCHECK, 0, 0); + + joysticks[controller].deadzone = (int)SendMessage(GetDlgItem(hDlg, IDC_DEADZONE), CB_GETCURSEL, 0, 0); +} + +// Set text in static text item +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void SetButton(HWND hDlg, int item, int value) +{ + char format[8]; + sprintf(format, "%d", value); + SetDlgItemText(hDlg, item, format); +} + +// Get text from static text item +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +int GetButton(HWND hDlg, int item) +{ + char format[8]; + GetDlgItemText(hDlg, item, format, sizeof(format)); + return atoi(format); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// About dialog functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +void OpenAbout(HINSTANCE hInst, HWND _hParent) +{ + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), _hParent, (DLGPROC)AboutDlg); +} + +BOOL CALLBACK AboutDlg(HWND abouthWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + char format[0xFFF]; + + switch (message) + { + case WM_INITDIALOG: + sprintf(format,"nJoy v"INPUT_VERSION" by Falcon4ever\n" + "Release: "RELDAY"/"RELMONTH"/"RELYEAR"\n" + "www.multigesture.net"); + SetDlgItemText(abouthWnd,IDC_ABOUT_TEXT,format); + + sprintf(format, THANKYOU); + SetDlgItemText(abouthWnd,IDC_ABOUT_TEXT2,format); + + sprintf(format, INPUT_STATE); + SetDlgItemText(abouthWnd,IDC_ABOUT_TEXT3,format); + break; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK) + { + EndDialog(abouthWnd, LOWORD(wParam)); + return TRUE; + } + break; + } + + return FALSE; +} diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/config.h b/Source/Plugins/Plugin_nJoy_SDL/Src/config.h new file mode 100644 index 0000000000..784d75e98e --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/config.h @@ -0,0 +1,67 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// Project description +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +// Name: nJoy +// Description: A Dolphin Compatible Input Plugin +// +// Author: Falcon4ever (nJoy@falcon4ever.com) +// Site: www.multigesture.net +// Copyright (C) 2003-2008 Dolphin Project. +// +////////////////////////////////////////////////////////////////////////////////////////// +// +// Licensetype: GNU General Public License (GPL) +// +// 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, version 2.0. +// +// 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 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// +////////////////////////////////////////////////////////////////////////////////////////// + +#include // includes basic windows functionality +#include +#include +#include // includes the common control header + +#include "../Res/resource.h" // includes GUI IDs + +#pragma comment(lib, "comctl32.lib") + +////////////////////////////////////////////////////////////////////////////////////////// +// Config dialog functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +int OpenConfig(HINSTANCE hInst, HWND _hParent); +BOOL ControllerTab(HWND hDlg, UINT message, UINT wParam, LONG lParam, int controller); +BOOL APIENTRY ControllerTab1(HWND hDlg, UINT message, UINT wParam, LONG lParam); +BOOL APIENTRY ControllerTab2(HWND hDlg, UINT message, UINT wParam, LONG lParam); +BOOL APIENTRY ControllerTab3(HWND hDlg, UINT message, UINT wParam, LONG lParam); +BOOL APIENTRY ControllerTab4(HWND hDlg, UINT message, UINT wParam, LONG lParam); + +bool GetButtons(HWND hDlg, int buttonid, int controller); +bool GetHats(HWND hDlg, int buttonid, int controller); +bool GetAxis(HWND hDlg, int buttonid, int controller); + +void GetControllerAll(HWND hDlg, int controller); +void SetControllerAll(HWND hDlg, int controller); + +int GetButton(HWND hDlg, int item); +void SetButton(HWND hDlg, int item, int value); + +////////////////////////////////////////////////////////////////////////////////////////// +// About dialog functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +void OpenAbout(HINSTANCE hInst, HWND _hParent); +BOOL CALLBACK AboutDlg(HWND abouthWnd, UINT message, WPARAM wParam, LPARAM lParam); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp new file mode 100644 index 0000000000..4e7e7cf74d --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp @@ -0,0 +1,445 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// Project description +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +// Name: nJoy +// Description: A Dolphin Compatible Input Plugin +// +// Author: Falcon4ever (nJoy@falcon4ever.com) +// Site: www.multigesture.net +// Copyright (C) 2003-2008 Dolphin Project. +// +////////////////////////////////////////////////////////////////////////////////////////// +// +// Licensetype: GNU General Public License (GPL) +// +// 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, version 2.0. +// +// 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 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// +////////////////////////////////////////////////////////////////////////////////////////// + +#include "nJoy.h" + +////////////////////////////////////////////////////////////////////////////////////////// +// Variables +// ŻŻŻŻŻŻŻŻŻ + +FILE *pFile; +HINSTANCE nJoy_hInst = NULL; +CONTROLLER_INFO *joyinfo = 0; +CONTROLLER_STATE joystate[4]; +CONTROLLER_MAPPING joysticks[4]; +bool emulator_running = FALSE; + +////////////////////////////////////////////////////////////////////////////////////////// +// DllMain +// ŻŻŻŻŻŻŻ +BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle + DWORD dwReason, // reason called + LPVOID lpvReserved) // reserved +{ + InitCommonControls(); + + nJoy_hInst = hinstDLL; + return TRUE; +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Input Plugin Functions (from spec's) +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +// Get properties of plugin +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void GetDllInfo(PLUGIN_INFO* _PluginInfo) +{ + _PluginInfo->Version = 0x0100; + _PluginInfo->Type = PLUGIN_TYPE_PAD; + + #ifndef _DEBUG + sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION " by Falcon4ever"); + #else + sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (Debug) by Falcon4ever"); + #endif +} + +// Call about dialog +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void DllAbout(HWND _hParent) +{ + OpenAbout(nJoy_hInst, _hParent); +} + +// Call config dialog +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void DllConfig(HWND _hParent) +{ + if(SDL_Init(SDL_INIT_JOYSTICK ) < 0) + { + MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR); + return; + } + + LoadConfig(); + if(OpenConfig(nJoy_hInst, _hParent)) + SaveConfig(); +} + +// Init PAD (start emulation) +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void PAD_Initialize(SPADInitialize _PADInitialize) +{ + emulator_running = TRUE; + #ifdef _DEBUG + DEBUG_INIT(); + #endif + + if(SDL_Init(SDL_INIT_JOYSTICK ) < 0) + { + MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR); + return; + } + + LoadConfig(); // Load joystick mapping + + if(joysticks[0].enabled) + joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID); + if(joysticks[1].enabled) + joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID); + if(joysticks[2].enabled) + joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID); + if(joysticks[3].enabled) + joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID); +} + +// Shutdown PAD (stop emulation) +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void PAD_Shutdown() +{ + if(joysticks[0].enabled) + SDL_JoystickClose(joystate[0].joy); + if(joysticks[1].enabled) + SDL_JoystickClose(joystate[1].joy); + if(joysticks[2].enabled) + SDL_JoystickClose(joystate[2].joy); + if(joysticks[3].enabled) + SDL_JoystickClose(joystate[3].joy); + + SDL_Quit(); + + #ifdef _DEBUG + DEBUG_QUIT(); + #endif + + delete [] joyinfo; + + emulator_running = FALSE; +} + +// Set PAD status +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void PAD_GetStatus(BYTE _numPAD, SPADStatus* _pPADStatus) +{ + if(!joysticks[_numPAD].enabled) + return; + + // clear pad status + memset(_pPADStatus, 0, sizeof(SPADStatus)); + + // get pad status + GetJoyState(_numPAD); + + // Reset! + int base = 0x80; + _pPADStatus->stickY = base; + _pPADStatus->stickX = base; + _pPADStatus->substickX = base; + _pPADStatus->substickY = base; + _pPADStatus->button |= PAD_USE_ORIGIN; + + // Set analog controllers + // Set Deadzones perhaps out of function + int deadzone = ((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1); + int deadzone2 = ((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1); + + // Adjust range + // The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768) + // The value used for the gamecube controller is an unsigned char (0 to 255) + int main_stick_x = (joystate[_numPAD].axis[CTL_MAIN_X]>>8); + int main_stick_y = (joystate[_numPAD].axis[CTL_MAIN_Y]>>8); + int sub_stick_x = (joystate[_numPAD].axis[CTL_SUB_X]>>8); + int sub_stick_y = (joystate[_numPAD].axis[CTL_SUB_Y]>>8); + + // Quick fix + if(main_stick_x > 127) + main_stick_x = 127; + if(main_stick_y > 127) + main_stick_y = 127; + if(sub_stick_x > 127) + sub_stick_x = 127; + if(sub_stick_y > 127) + sub_stick_y = 127; + + if(main_stick_x < -128) + main_stick_x = -128; + if(main_stick_y < -128) + main_stick_y = -128; + if(sub_stick_x < -128) + sub_stick_x = -128; + if(sub_stick_y < -128) + sub_stick_y = -128; + + // Send values to Dolpin + if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX += main_stick_x; + if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY -= main_stick_y; + if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX += sub_stick_x; + if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY -= sub_stick_y; + + // Set buttons + if (joystate[_numPAD].buttons[CTL_L_SHOULDER]) _pPADStatus->button|=PAD_TRIGGER_L; + if (joystate[_numPAD].buttons[CTL_R_SHOULDER]) _pPADStatus->button|=PAD_TRIGGER_R; + if (joystate[_numPAD].buttons[CTL_A_BUTTON]) _pPADStatus->button|=PAD_BUTTON_A; + if (joystate[_numPAD].buttons[CTL_B_BUTTON]) _pPADStatus->button|=PAD_BUTTON_B; + if (joystate[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X; + if (joystate[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y; + if (joystate[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z; + if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START; + + // Set D-pad + if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP; + if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT; + if(joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN || joystate[_numPAD].dpad == SDL_HAT_DOWN || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN; + if(joystate[_numPAD].dpad == SDL_HAT_RIGHTUP || joystate[_numPAD].dpad == SDL_HAT_RIGHT || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT; + + _pPADStatus->err = PAD_ERR_NONE; +} + +// Set PAD rumble +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void PAD_Rumble(BYTE _numPAD, unsigned int _uType, unsigned int _uStrength) +{ + // not supported by SDL +} + +// Set PAD attached pads +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +unsigned int PAD_GetAttachedPads() +{ + unsigned int connected = 0; + + LoadConfig(); + + if(joysticks[0].enabled) + connected |= 1; + if(joysticks[1].enabled) + connected |= 2; + if(joysticks[2].enabled) + connected |= 4; + if(joysticks[3].enabled) + connected |= 8; + + return connected; +} + +// Savestates +// ŻŻŻŻŻŻŻŻŻŻ +unsigned int SaveLoadState(char *ptr, BOOL save) +{ + // not used + return 0; +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Custom Functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +// Request joystick state +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void GetJoyState(int controller) +{ + SDL_JoystickUpdate(); + + joystate[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_X]); + joystate[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_Y]); + joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]); + joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]); + + joystate[controller].buttons[CTL_L_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_L_SHOULDER]); + joystate[controller].buttons[CTL_R_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_R_SHOULDER]); + joystate[controller].buttons[CTL_A_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_A_BUTTON]); + joystate[controller].buttons[CTL_B_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_B_BUTTON]); + joystate[controller].buttons[CTL_X_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_X_BUTTON]); + joystate[controller].buttons[CTL_Y_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Y_BUTTON]); + joystate[controller].buttons[CTL_Z_TRIGGER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Z_TRIGGER]); + joystate[controller].buttons[CTL_START] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_START]); + + joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad); +} + +// Search attached devices +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +int Search_Devices() +{ + // load config + #ifdef _DEBUG + DEBUG_INIT(); + #endif + + int numjoy = SDL_NumJoysticks(); + + if(numjoy == 0) + { + MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING); + return 0; + } + + if(joyinfo) + { + delete [] joyinfo; + joyinfo = new CONTROLLER_INFO [numjoy]; + } + else + { + joyinfo = new CONTROLLER_INFO [numjoy]; + } + + #ifdef _DEBUG + fprintf(pFile, "Scanning for devices\n"); + fprintf(pFile, "ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ\n"); + #endif + + for(int i = 0; i < numjoy; i++ ) + { + joyinfo[i].joy = SDL_JoystickOpen(i); + joyinfo[i].ID = i; + joyinfo[i].NumAxes = SDL_JoystickNumAxes(joyinfo[i].joy); + joyinfo[i].NumButtons = SDL_JoystickNumButtons(joyinfo[i].joy); + joyinfo[i].NumBalls = SDL_JoystickNumBalls(joyinfo[i].joy); + joyinfo[i].NumHats = SDL_JoystickNumHats(joyinfo[i].joy); + joyinfo[i].Name = SDL_JoystickName(i); + + #ifdef _DEBUG + fprintf(pFile, "ID: %d\n", i); + fprintf(pFile, "Name: %s\n", joyinfo[i].Name); + fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons); + fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes); + fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats); + fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls); + #endif + + // Close if opened + if(SDL_JoystickOpened(i)) + SDL_JoystickClose(joyinfo[i].joy); + } + + return numjoy; +} + +// Enable output log +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void DEBUG_INIT() +{ + if(pFile) + return; + + char dateStr [9]; + _strdate( dateStr); + char timeStr [9]; + _strtime( timeStr ); + + pFile = fopen ("nJoy-debug.txt","wt"); + fprintf(pFile, "nJoy v"INPUT_VERSION" Debug\n"); + fprintf(pFile, "Date: %s\nTime: %s\n", dateStr, timeStr); + fprintf(pFile, "ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ\n"); +} + +// Disable output log +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void DEBUG_QUIT() +{ + if(!pFile) + return; + + char timeStr [9]; + _strtime(timeStr); + + fprintf(pFile, "_______________\n"); + fprintf(pFile, "Time: %s", timeStr); + fclose(pFile); +} + +// Save settings to file +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void SaveConfig() +{ + IniFile file; + file.Load("nJoy"); + + for (int i=0; i<4; i++) + { + char SectionName[32]; + sprintf(SectionName, "PAD%i", i+1); + + file.Set(SectionName, "l_shoulder", joysticks[i].buttons[CTL_L_SHOULDER]); + file.Set(SectionName, "r_shoulder", joysticks[i].buttons[CTL_R_SHOULDER]); + file.Set(SectionName, "a_button", joysticks[i].buttons[CTL_A_BUTTON]); + file.Set(SectionName, "b_button", joysticks[i].buttons[CTL_B_BUTTON]); + file.Set(SectionName, "x_button", joysticks[i].buttons[CTL_X_BUTTON]); + file.Set(SectionName, "y_button", joysticks[i].buttons[CTL_Y_BUTTON]); + file.Set(SectionName, "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]); + file.Set(SectionName, "start_button", joysticks[i].buttons[CTL_START]); + file.Set(SectionName, "dpad", joysticks[i].dpad); + file.Set(SectionName, "main_x", joysticks[i].axis[CTL_MAIN_X]); + file.Set(SectionName, "main_y", joysticks[i].axis[CTL_MAIN_Y]); + file.Set(SectionName, "sub_x", joysticks[i].axis[CTL_SUB_X]); + file.Set(SectionName, "sub_y", joysticks[i].axis[CTL_SUB_Y]); + file.Set(SectionName, "enabled", joysticks[i].enabled); + file.Set(SectionName, "deadzone", joysticks[i].deadzone); + file.Set(SectionName, "halfpress", joysticks[i].halfpress); + file.Set(SectionName, "joy_id", joysticks[i].ID); + } + + file.Save("nJoy"); +} + +// Load settings from file +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +void LoadConfig() +{ + IniFile file; + file.Load("nJoy"); + + for (int i=0; i<4; i++) + { + char SectionName[32]; + sprintf(SectionName, "PAD%i", i+1); + + file.Get(SectionName, "l_shoulder", &joysticks[i].buttons[CTL_L_SHOULDER], 4); + file.Get(SectionName, "r_shoulder", &joysticks[i].buttons[CTL_R_SHOULDER], 5); + file.Get(SectionName, "a_button", &joysticks[i].buttons[CTL_A_BUTTON], 0); + file.Get(SectionName, "b_button", &joysticks[i].buttons[CTL_B_BUTTON], 1); + file.Get(SectionName, "x_button", &joysticks[i].buttons[CTL_X_BUTTON], 3); + file.Get(SectionName, "y_button", &joysticks[i].buttons[CTL_Y_BUTTON], 2); + file.Get(SectionName, "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], 7); + file.Get(SectionName, "start_button", &joysticks[i].buttons[CTL_START], 9); + file.Get(SectionName, "dpad", &joysticks[i].dpad, 0); + file.Get(SectionName, "main_x", &joysticks[i].axis[CTL_MAIN_X], 0); + file.Get(SectionName, "main_y", &joysticks[i].axis[CTL_MAIN_Y], 1); + file.Get(SectionName, "sub_x", &joysticks[i].axis[CTL_SUB_X], 2); + file.Get(SectionName, "sub_y", &joysticks[i].axis[CTL_SUB_Y], 3); + file.Get(SectionName, "enabled", &joysticks[i].enabled, 1); + file.Get(SectionName, "deadzone", &joysticks[i].deadzone, 9); + file.Get(SectionName, "halfpress", &joysticks[i].halfpress, 0); + file.Get(SectionName, "joy_id", &joysticks[i].ID, 0); + } +} diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h new file mode 100644 index 0000000000..532957dbb4 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h @@ -0,0 +1,116 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// Project description +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +// Name: nJoy +// Description: A Dolphin Compatible Input Plugin +// +// Author: Falcon4ever (nJoy@falcon4ever.com) +// Site: www.multigesture.net +// Copyright (C) 2003-2008 Dolphin Project. +// +////////////////////////////////////////////////////////////////////////////////////////// +// +// Licensetype: GNU General Public License (GPL) +// +// 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, version 2.0. +// +// 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 2.0 for more details. +// +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ +// +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ +// +////////////////////////////////////////////////////////////////////////////////////////// + +#define _CRT_SECURE_NO_WARNINGS + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include // includes SDL + +#include "pluginspecs_pad.h" +#include "config.h" +#include "IniFile.h" + +#pragma comment(lib, "SDL.lib") +// #pragma comment(lib, "SDLmain.lib") + +////////////////////////////////////////////////////////////////////////////////////////// +// Define +// ŻŻŻŻŻŻ + +#define INPUT_VERSION "0.3" +#define INPUT_STATE "PUBLIC RELEASE" +#define RELDAY "21" +#define RELMONTH "07" +#define RELYEAR "2008" +#define THANKYOU "`plot`, Absolute0, Aprentice, Bositman, Brice, ChaosCode, CKemu, CoDeX, Dave2001, dn, drk||Raziel, Florin, Gent, Gigaherz, Hacktarux, JegHegy, Linker, Linuzappz, Martin64, Muad, Knuckles, Raziel, Refraction, Rudy_x, Shadowprince, Snake785, Saqib, vEX, yaz0r, Zilmar, Zenogais and ZeZu." + +struct CONTROLLER_STATE{ // GC PAD INFO/STATE + int buttons[8]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons + int dpad; // 1 HAT (8 directions + neutral) + int axis[4]; // 2 x 2 Axes (Main & Sub) + SDL_Joystick *joy; // SDL joystick device +}; + +struct CONTROLLER_MAPPING{ // GC PAD MAPPING + int buttons[8]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons + int dpad; // 1 HAT (8 directions + neutral) + int axis[4]; // 2 x 2 Axes (Main & Sub) + int enabled; // Pad attached? + int deadzone; // Deadzone... what else? + int halfpress; // Not implemented + int ID; // SDL joystick device ID +}; + +struct CONTROLLER_INFO{ // CONNECTED WINDOWS DEVICES INFO + int NumAxes; // Amount of Axes + int NumButtons; // Amount of Buttons + int NumBalls; // Amount of Balls + int NumHats; // Amount of Hats (POV) + const char *Name; // Joypad/stickname + int ID; // SDL joystick device ID + SDL_Joystick *joy; // SDL joystick device +}; + +enum +{ + CTL_MAIN_X = 0, + CTL_MAIN_Y, + CTL_SUB_X, + CTL_SUB_Y, +}; + +enum +{ + CTL_L_SHOULDER = 0, + CTL_R_SHOULDER, + CTL_A_BUTTON, + CTL_B_BUTTON, + CTL_X_BUTTON, + CTL_Y_BUTTON, + CTL_Z_TRIGGER, + CTL_START +}; + +////////////////////////////////////////////////////////////////////////////////////////// +// Custom Functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ + +void GetJoyState(int controller); +int Search_Devices(); +void DEBUG_INIT(); +void DEBUG_QUIT(); + +void SaveConfig(); +void LoadConfig(); \ No newline at end of file diff --git a/Source/Plugins/Plugin_nJoy_SDL/readme.txt b/Source/Plugins/Plugin_nJoy_SDL/readme.txt new file mode 100644 index 0000000000..099408bbb7 --- /dev/null +++ b/Source/Plugins/Plugin_nJoy_SDL/readme.txt @@ -0,0 +1,115 @@ +nJoy v0.3 by Falcon4ever 2008 +A Dolphin Compatible Input Plugin +Copyright (C) 2003-2008 Dolphin Project. + +Changelog +========================================================================== + +0.3: 3nd version of nJoy + - Release: July 2008 + - Support for four players + - Misc. improvements + +0.2: 2nd version of nJoy + - Release: 14th July 2005 + - Now using SDL instead of DirectInput9 + - Config/INI support + - Adjustable deadzone + - First public release + +0.1: First version of nJoy + - Private Release: january 2005 + - Using DirectInput9 + - Specially made for the Logitech Rumblepad 2, but other joypads work too + - Advanced debug window, activated during gameplay + - No deadzone configurable + - No config/Ini + +The Author +========================================================================== +* Falcon4ever (nJoy@falcon4ever.com) + +System and Software Requirements +========================================================================== +Dolphin + The latest Dolphin release, avaible at www.dolphin-emu.com + +SDL.dll (SDL-1.2.13) + (included with this release) + latest version avaible at www.libsdl.org + +A Joystick + A Windows 9x compatible input device + + +Plugin Information +========================================================================== +nJoy was written in C++, compiled with Microsoft Visual Studio 2005 Professional Edition. +nJoy uses SDL for joysticks, mouse and keyboard. +For the graphical interface plain Win32 code was used. + +How to install +========================================================================== +Just unzip the content of the zipfile to your dolphin plugin dir and place +sdl.dll in the root dir. + +example config: +[C:] + | + +-Dolphin Dir + +-DolphinWx.exe File + +-SDL.dll File + | + +-Plugins Dir + +-nJoy.dll File + + +FAQ +========================================================================== + +What's SDL??? + SDL is the Simple DirectMedia Layer written by Sam Lantinga. + It provides an API for audio, video, input ... + For more information go to http://www.libsdl.org/ + +Where can I download the latest releases??? + nJoy will be released @ www.multigesture.net + +Can I mirror this file??? + Sure, just don't forget to add a link to: + www.multigesture.net OR www.dolphin-emu.com + ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +Why should I use nJoy instead of the default input plugin??? + At this moment the default plugin only supports keyboard input. + nJoy supports Joysticks. And besides that, if you have an GC-adapter + you can use your original GC controllers with dolphin ! + +Could you add [insert feature here] please??? + no. + +But perhaps... + NO! + +Hmm... There is coming smoke out of my pc, wtf? + err, this plugin comes without any warranty, + use it at own risk :) + +What should I do if my question isn't listed here??? + Just panic, call 911 or leave a message on: + (1) Emutalk http://www.emutalk.net/forumdisplay.php?f=100 + (2) NGemu http://forums.ngemu.com/dolphin-discussion/ + +Thanks / Greetings +========================================================================== + +Special Thanks too: +F|RES & ector + +Greetings too: +`plot`, Absolute0, Aprentice, Bositman, Brice, ChaosCode, CKemu, +CoDeX, Dave2001, dn, drk||Raziel, Florin, Gent, Gigaherz, Hacktarux, +icepir8, JegHegy, Linker, Linuzappz, Martin64, Muad, Knuckles, Raziel, +Refraction, Rudy_x, Shadowprince, Snake785, Saqib, vEX, yaz0r, +Zilmar, Zenogais and ZeZu. + +AAaannd everyone else I forgot ;)...