switch over to libretro input code
authornotaz <notasas@gmail.com>
Wed, 13 Sep 2023 19:23:58 +0000 (22:23 +0300)
committernotaz <notasas@gmail.com>
Wed, 13 Sep 2023 21:41:27 +0000 (00:41 +0300)
too much trouble with 2 separate codebases

18 files changed:
Makefile
frontend/libretro.c
frontend/menu.c
frontend/pl_gun_ts.c
frontend/plugin.c
frontend/plugin_lib.c
include/psemu_plugin_defs.h
libpcsxcore/plugins.c
libpcsxcore/plugins.h
libpcsxcore/psxbios.c
libpcsxcore/sio.c
maemo/hildon.c
maemo/main.c
plugins/dfinput/externals.h [deleted file]
plugins/dfinput/guncon.c [deleted file]
plugins/dfinput/main.c [deleted file]
plugins/dfinput/main.h [deleted file]
plugins/dfinput/pad.c [deleted file]

index 8e5cb3e..ef4a1f7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -174,9 +174,6 @@ libchdr/src/%.o: CFLAGS += -Wno-unused -Ilibchdr/deps/lzma-19.00/include
 libchdr/deps/lzma-19.00/src/%.o: CFLAGS += -Wno-unused -D_7ZIP_ST -Ilibchdr/deps/lzma-19.00/include
 #endif
 
-# dfinput
-OBJS += plugins/dfinput/main.o plugins/dfinput/pad.o plugins/dfinput/guncon.o
-
 # frontend/gui
 OBJS += frontend/cspace.o
 ifeq "$(HAVE_NEON_ASM)" "1"
index f275ca3..8d6b5cc 100644 (file)
@@ -29,7 +29,6 @@
 #include "../libpcsxcore/r3000a.h"
 #include "../plugins/dfsound/out.h"
 #include "../plugins/dfsound/spu_config.h"
-#include "../plugins/dfinput/externals.h"
 #include "cspace.h"
 #include "main.h"
 #include "menu.h"
@@ -514,7 +513,7 @@ void plat_trigger_vibrate(int pad, int low, int high)
    }
 }
 
-void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
+void pl_gun_byte2(int port, unsigned char byte)
 {
 }
 
@@ -2468,17 +2467,19 @@ static void update_input_guncon(int port, int ret)
    //Mouse range is -32767 -> 32767
    //1% is about 655
    //Use the left analog stick field to store the absolute coordinates
-   //Fix cursor to top-left when gun is detected as "offscreen"
+
+   int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
+   int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
+
+   //Have the Libretro API let /libpcsxcore/plugins.c know when the lightgun is pointed offscreen
+   //Offscreen value is chosen to be well out of range of any possible scaling done via core options
    if (input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN) || input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_RELOAD))
    {
-      in_analog_left[port][0] = -32767;
-      in_analog_left[port][1] = -32767;
+      in_analog_left[port][0] = (65536 - 512) * 64;
+      in_analog_left[port][1] = (65536 - 512) * 64;
    }
    else
    {
-      int gunx = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X);
-      int guny = input_state_cb(port, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y);
-          
       in_analog_left[port][0] = (gunx * GunconAdjustRatioX) + (GunconAdjustX * 655);
       in_analog_left[port][1] = (guny * GunconAdjustRatioY) + (GunconAdjustY * 655);
    }
index ee60df6..8e7cd50 100644 (file)
@@ -36,7 +36,6 @@
 #include "../libpcsxcore/cdriso.h"
 #include "../libpcsxcore/cheat.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
-#include "../plugins/dfinput/externals.h"
 #include "../plugins/dfsound/spu_config.h"
 #include "psemu_plugin_defs.h"
 #include "arm_features.h"
@@ -2696,8 +2695,6 @@ void menu_prepare_emu(void)
                if (ret)
                        fprintf(stderr, "Warning: GPU_open returned %d\n", ret);
        }
-
-       dfinput_activate();
 }
 
 void menu_update_msg(const char *msg)
index 315c70c..6c05b7c 100644 (file)
@@ -15,8 +15,6 @@
 #include "plugin_lib.h"
 #include "pl_gun_ts.h"
 #include "menu.h"
-#include "../plugins/dfinput/externals.h"
-#include "../plugins/dfinput/main.h"
 
 #ifdef MAEMO
 #define N900_TSMAX_X 4096
@@ -57,9 +55,9 @@ int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p)
                        limit(gun_x, 0, 1023);
                        limit(gun_y, 0, 1023);
                        if (sp && !(g_opts & OPT_TSGUN_NOTRIGGER))
-                               gun_in |= GUNIN_TRIGGER;
+                               gun_in |= 1;
                        else
-                               gun_in &= ~GUNIN_TRIGGER;
+                               gun_in &= ~1;
                }
        }
 
index f77b6e1..2c95a67 100644 (file)
@@ -68,23 +68,65 @@ static long CALLBACK PADshutdown(void) { return 0; }
 static long CALLBACK PADclose(void) { return 0; }
 static void CALLBACK PADsetSensitive(int _) { return; }
 
-static long CALLBACK PADreadPort1(PadDataS *pad)
-{
-       pad->controllerType = in_type[0];
-       pad->buttonStatus = ~in_keystate[0];
-       if (in_type[0] == PSE_PAD_TYPE_ANALOGPAD) {
-               pad->leftJoyX = in_analog_left[0][0];
-               pad->leftJoyY = in_analog_left[0][1];
-               pad->rightJoyX = in_analog_right[0][0];
-               pad->rightJoyY = in_analog_right[0][1];
+static long CALLBACK PADreadPort1(PadDataS *pad) {
+       int pad_index = pad->requestPadIndex;
+
+       pad->controllerType = in_type[pad_index];
+       pad->buttonStatus = ~in_keystate[pad_index];
+
+       if (multitap1 == 1)
+               pad->portMultitap = 1;
+       else
+               pad->portMultitap = 0;
+
+       if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON)
+       {
+               pad->leftJoyX = in_analog_left[pad_index][0];
+               pad->leftJoyY = in_analog_left[pad_index][1];
+               pad->rightJoyX = in_analog_right[pad_index][0];
+               pad->rightJoyY = in_analog_right[pad_index][1];
+
+               pad->absoluteX = in_analog_left[pad_index][0];
+               pad->absoluteY = in_analog_left[pad_index][1];
+       }
+
+       if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
+       {
+               pad->moveX = in_mouse[pad_index][0];
+               pad->moveY = in_mouse[pad_index][1];
        }
+
        return 0;
 }
 
-static long CALLBACK PADreadPort2(PadDataS *pad)
-{
-       pad->controllerType = in_type[1];
-       pad->buttonStatus = ~in_keystate[0] >> 16;
+static long CALLBACK PADreadPort2(PadDataS *pad) {
+       int pad_index = pad->requestPadIndex;
+
+       pad->controllerType = in_type[pad_index];
+       pad->buttonStatus = ~in_keystate[pad_index];
+
+       if (multitap2 == 1)
+               pad->portMultitap = 2;
+       else
+               pad->portMultitap = 0;
+
+       if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON)
+       {
+               pad->leftJoyX = in_analog_left[pad_index][0];
+               pad->leftJoyY = in_analog_left[pad_index][1];
+               pad->rightJoyX = in_analog_right[pad_index][0];
+               pad->rightJoyY = in_analog_right[pad_index][1];
+
+               pad->absoluteX = in_analog_left[pad_index][0];
+               pad->absoluteY = in_analog_left[pad_index][1];
+       }
+
+       if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
+       {
+               pad->moveX = in_mouse[pad_index][0];
+               pad->moveY = in_mouse[pad_index][1];
+       }
+
        return 0;
 }
 
index bdf09c7..8a6b6ad 100644 (file)
@@ -33,7 +33,6 @@
 #include "psemu_plugin_defs.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #include "../libpcsxcore/psxmem_map.h"
-#include "../plugins/dfinput/externals.h"
 
 #define HUD_HEIGHT 10
 
@@ -620,18 +619,18 @@ static void update_input(void)
        emu_set_action(emu_act);
 
        in_keystate[0] = actions[IN_BINDTYPE_PLAYER12];
+
+       // fixme
+       //if (in_type[0] == PSE_PAD_TYPE_GUNCON && tsdev)
+       //      pl_gun_ts_update(tsdev, xn, yn, in);
+       //      in_analog_left[0][0] = xn
 }
 #else /* MAEMO */
 extern void update_input(void);
 #endif
 
-void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in)
+void pl_gun_byte2(int port, unsigned char byte)
 {
-       if (tsdev)
-               pl_gun_ts_update(tsdev, xn, yn, in);
-
-       *xres = psx_w;
-       *yres = psx_h;
 }
 
 #define MAX_LAG_FRAMES 3
index b855eac..2d688f2 100644 (file)
@@ -141,7 +141,7 @@ typedef struct
   long PADquery(void);
 
   unsigned char PADstartPoll(int);
-  unsigned char PADpoll(unsigned char);
+  unsigned char PADpoll(unsigned char, int *);
 
 */
 
@@ -222,7 +222,9 @@ typedef struct
        
        //configuration mode Request 0x43
        int configMode;
-       unsigned char reserved[87];
+
+       unsigned char txData[32];
+       unsigned char reserved[56];
        
        //Lightgun values 
        int absoluteX,absoluteY;
index a77c728..a34969f 100644 (file)
-/***************************************************************************\r
- *   Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team              *\r
- *                                                                         *\r
- *   This program is free software; you can redistribute it and/or modify  *\r
- *   it under the terms of the GNU General Public License as published by  *\r
- *   the Free Software Foundation; either version 2 of the License, or     *\r
- *   (at your option) any later version.                                   *\r
- *                                                                         *\r
- *   This program is distributed in the hope that it will be useful,       *\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\r
- *   GNU General Public License for more details.                          *\r
- *                                                                         *\r
- *   You should have received a copy of the GNU General Public License     *\r
- *   along with this program; if not, write to the                         *\r
- *   Free Software Foundation, Inc.,                                       *\r
- *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *\r
- ***************************************************************************/\r
-\r
-/*\r
-* Plugin library callback/access functions.\r
-*/\r
-\r
-#include "plugins.h"\r
-#include "cdriso.h"\r
-\r
-static char IsoFile[MAXPATHLEN] = "";\r
-static s64 cdOpenCaseTime = 0;\r
-\r
-GPUupdateLace         GPU_updateLace;\r
-GPUinit               GPU_init;\r
-GPUshutdown           GPU_shutdown; \r
-GPUconfigure          GPU_configure;\r
-GPUtest               GPU_test;\r
-GPUabout              GPU_about;\r
-GPUopen               GPU_open;\r
-GPUclose              GPU_close;\r
-GPUreadStatus         GPU_readStatus;\r
-GPUreadData           GPU_readData;\r
-GPUreadDataMem        GPU_readDataMem;\r
-GPUwriteStatus        GPU_writeStatus; \r
-GPUwriteData          GPU_writeData;\r
-GPUwriteDataMem       GPU_writeDataMem;\r
-GPUdmaChain           GPU_dmaChain;\r
-GPUkeypressed         GPU_keypressed;\r
-GPUdisplayText        GPU_displayText;\r
-GPUmakeSnapshot       GPU_makeSnapshot;\r
-GPUfreeze             GPU_freeze;\r
-GPUgetScreenPic       GPU_getScreenPic;\r
-GPUshowScreenPic      GPU_showScreenPic;\r
-GPUvBlank             GPU_vBlank;\r
-\r
-CDRinit               CDR_init;\r
-CDRshutdown           CDR_shutdown;\r
-CDRopen               CDR_open;\r
-CDRclose              CDR_close; \r
-CDRtest               CDR_test;\r
-CDRgetTN              CDR_getTN;\r
-CDRgetTD              CDR_getTD;\r
-CDRreadTrack          CDR_readTrack;\r
-CDRgetBuffer          CDR_getBuffer;\r
-CDRplay               CDR_play;\r
-CDRstop               CDR_stop;\r
-CDRgetStatus          CDR_getStatus;\r
-CDRgetDriveLetter     CDR_getDriveLetter;\r
-CDRgetBufferSub       CDR_getBufferSub;\r
-CDRconfigure          CDR_configure;\r
-CDRabout              CDR_about;\r
-CDRsetfilename        CDR_setfilename;\r
-CDRreadCDDA           CDR_readCDDA;\r
-CDRgetTE              CDR_getTE;\r
-\r
-SPUinit               SPU_init;\r
-SPUshutdown           SPU_shutdown;\r
-SPUopen               SPU_open;\r
-SPUclose              SPU_close;\r
-SPUwriteRegister      SPU_writeRegister;\r
-SPUreadRegister       SPU_readRegister;\r
-SPUwriteDMAMem        SPU_writeDMAMem;\r
-SPUreadDMAMem         SPU_readDMAMem;\r
-SPUplayADPCMchannel   SPU_playADPCMchannel;\r
-SPUfreeze             SPU_freeze;\r
-SPUregisterCallback   SPU_registerCallback;\r
-SPUregisterScheduleCb SPU_registerScheduleCb;\r
-SPUasync              SPU_async;\r
-SPUplayCDDAchannel    SPU_playCDDAchannel;\r
-\r
-PADconfigure          PAD1_configure;\r
-PADabout              PAD1_about;\r
-PADinit               PAD1_init;\r
-PADshutdown           PAD1_shutdown;\r
-PADtest               PAD1_test;\r
-PADopen               PAD1_open;\r
-PADclose              PAD1_close;\r
-PADquery              PAD1_query;\r
-PADreadPort1          PAD1_readPort1;\r
-PADkeypressed         PAD1_keypressed;\r
-PADstartPoll          PAD1_startPoll;\r
-PADpoll               PAD1_poll;\r
-PADsetSensitive       PAD1_setSensitive;\r
-\r
-PADconfigure          PAD2_configure;\r
-PADabout              PAD2_about;\r
-PADinit               PAD2_init;\r
-PADshutdown           PAD2_shutdown;\r
-PADtest               PAD2_test;\r
-PADopen               PAD2_open;\r
-PADclose              PAD2_close;\r
-PADquery              PAD2_query;\r
-PADreadPort2          PAD2_readPort2;\r
-PADkeypressed         PAD2_keypressed;\r
-PADstartPoll          PAD2_startPoll;\r
-PADpoll               PAD2_poll;\r
-PADsetSensitive       PAD2_setSensitive;\r
-\r
-NETinit               NET_init;\r
-NETshutdown           NET_shutdown;\r
-NETopen               NET_open;\r
-NETclose              NET_close; \r
-NETtest               NET_test;\r
-NETconfigure          NET_configure;\r
-NETabout              NET_about;\r
-NETpause              NET_pause;\r
-NETresume             NET_resume;\r
-NETqueryPlayer        NET_queryPlayer;\r
-NETsendData           NET_sendData;\r
-NETrecvData           NET_recvData;\r
-NETsendPadData        NET_sendPadData;\r
-NETrecvPadData        NET_recvPadData;\r
-NETsetInfo            NET_setInfo;\r
-NETkeypressed         NET_keypressed;\r
-\r
-#ifdef ENABLE_SIO1API\r
-\r
-SIO1init              SIO1_init;\r
-SIO1shutdown          SIO1_shutdown;\r
-SIO1open              SIO1_open;\r
-SIO1close             SIO1_close; \r
-SIO1test              SIO1_test;\r
-SIO1configure         SIO1_configure;\r
-SIO1about             SIO1_about;\r
-SIO1pause             SIO1_pause;\r
-SIO1resume            SIO1_resume;\r
-SIO1keypressed        SIO1_keypressed;\r
-SIO1writeData8        SIO1_writeData8;\r
-SIO1writeData16       SIO1_writeData16;\r
-SIO1writeData32       SIO1_writeData32;\r
-SIO1writeStat16       SIO1_writeStat16;\r
-SIO1writeStat32       SIO1_writeStat32;\r
-SIO1writeMode16       SIO1_writeMode16;\r
-SIO1writeMode32       SIO1_writeMode32;\r
-SIO1writeCtrl16       SIO1_writeCtrl16;\r
-SIO1writeCtrl32       SIO1_writeCtrl32;\r
-SIO1writeBaud16       SIO1_writeBaud16;\r
-SIO1writeBaud32       SIO1_writeBaud32;\r
-SIO1readData8         SIO1_readData8;\r
-SIO1readData16        SIO1_readData16;\r
-SIO1readData32        SIO1_readData32;\r
-SIO1readStat16        SIO1_readStat16;\r
-SIO1readStat32        SIO1_readStat32;\r
-SIO1readMode16        SIO1_readMode16;\r
-SIO1readMode32        SIO1_readMode32;\r
-SIO1readCtrl16        SIO1_readCtrl16;\r
-SIO1readCtrl32        SIO1_readCtrl32;\r
-SIO1readBaud16        SIO1_readBaud16;\r
-SIO1readBaud32        SIO1_readBaud32;\r
-SIO1registerCallback  SIO1_registerCallback;\r
-\r
-#endif\r
-\r
-static const char *err;\r
-\r
-#define CheckErr(func) { \\r
-       err = SysLibError(); \\r
-       if (err != NULL) { SysMessage(_("Error loading %s: %s"), func, err); return -1; } \\r
-}\r
-\r
-#define LoadSym(dest, src, name, checkerr) { \\r
-       dest = (src)SysLoadSym(drv, name); \\r
-       if (checkerr) { CheckErr(name); } else SysLibError(); \\r
-}\r
-\r
-void *hGPUDriver = NULL;\r
-\r
-void CALLBACK GPU__displayText(char *pText) {\r
-       SysPrintf("%s\n", pText);\r
-}\r
-\r
-long CALLBACK GPU__configure(void) { return 0; }\r
-long CALLBACK GPU__test(void) { return 0; }\r
-void CALLBACK GPU__about(void) {}\r
-void CALLBACK GPU__makeSnapshot(void) {}\r
-void CALLBACK GPU__keypressed(int key) {}\r
-long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; }\r
-long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; }\r
-void CALLBACK GPU__vBlank(int val) {}\r
-\r
-#define LoadGpuSym1(dest, name) \\r
-       LoadSym(GPU_##dest, GPU##dest, name, TRUE);\r
-\r
-#define LoadGpuSym0(dest, name) \\r
-       LoadSym(GPU_##dest, GPU##dest, name, FALSE); \\r
-       if (GPU_##dest == NULL) GPU_##dest = (GPU##dest) GPU__##dest;\r
-\r
-#define LoadGpuSymN(dest, name) \\r
-       LoadSym(GPU_##dest, GPU##dest, name, FALSE);\r
-\r
-static int LoadGPUplugin(const char *GPUdll) {\r
-       void *drv;\r
-\r
-       hGPUDriver = SysLoadLibrary(GPUdll);\r
-       if (hGPUDriver == NULL) { \r
-               GPU_configure = NULL;\r
-               SysMessage (_("Could not load GPU plugin %s!"), GPUdll); return -1; \r
-       }\r
-       drv = hGPUDriver;\r
-       LoadGpuSym1(init, "GPUinit");\r
-       LoadGpuSym1(shutdown, "GPUshutdown");\r
-       LoadGpuSym1(open, "GPUopen");\r
-       LoadGpuSym1(close, "GPUclose");\r
-       LoadGpuSym1(readData, "GPUreadData");\r
-       LoadGpuSym1(readDataMem, "GPUreadDataMem");\r
-       LoadGpuSym1(readStatus, "GPUreadStatus");\r
-       LoadGpuSym1(writeData, "GPUwriteData");\r
-       LoadGpuSym1(writeDataMem, "GPUwriteDataMem");\r
-       LoadGpuSym1(writeStatus, "GPUwriteStatus");\r
-       LoadGpuSym1(dmaChain, "GPUdmaChain");\r
-       LoadGpuSym1(updateLace, "GPUupdateLace");\r
-       LoadGpuSym0(keypressed, "GPUkeypressed");\r
-       LoadGpuSym0(displayText, "GPUdisplayText");\r
-       LoadGpuSym0(makeSnapshot, "GPUmakeSnapshot");\r
-       LoadGpuSym1(freeze, "GPUfreeze");\r
-       LoadGpuSym0(getScreenPic, "GPUgetScreenPic");\r
-       LoadGpuSym0(showScreenPic, "GPUshowScreenPic");\r
-    LoadGpuSym0(vBlank, "GPUvBlank");\r
-       LoadGpuSym0(configure, "GPUconfigure");\r
-       LoadGpuSym0(test, "GPUtest");\r
-       LoadGpuSym0(about, "GPUabout");\r
-\r
-       return 0;\r
-}\r
-\r
-void *hCDRDriver = NULL;\r
-\r
-long CALLBACK CDR__play(unsigned char *sector) { return 0; }\r
-long CALLBACK CDR__stop(void) { return 0; }\r
-\r
-long CALLBACK CDR__getStatus(struct CdrStat *stat) {\r
-       if (cdOpenCaseTime < 0 || cdOpenCaseTime > (s64)time(NULL))\r
-               stat->Status = 0x10;\r
-       else\r
-               stat->Status = 0;\r
-\r
-       return 0;\r
-}\r
-\r
-char* CALLBACK CDR__getDriveLetter(void) { return NULL; }\r
-long CALLBACK CDR__configure(void) { return 0; }\r
-long CALLBACK CDR__test(void) { return 0; }\r
-void CALLBACK CDR__about(void) {}\r
-long CALLBACK CDR__setfilename(char*filename) { return 0; }\r
-\r
-#define LoadCdrSym1(dest, name) \\r
-       LoadSym(CDR_##dest, CDR##dest, name, TRUE);\r
-\r
-#define LoadCdrSym0(dest, name) \\r
-       LoadSym(CDR_##dest, CDR##dest, name, FALSE); \\r
-       if (CDR_##dest == NULL) CDR_##dest = (CDR##dest) CDR__##dest;\r
-\r
-#define LoadCdrSymN(dest, name) \\r
-       LoadSym(CDR_##dest, CDR##dest, name, FALSE);\r
-\r
-static int LoadCDRplugin(const char *CDRdll) {\r
-       void *drv;\r
-\r
-       if (CDRdll == NULL) {\r
-               cdrIsoInit();\r
-               return 0;\r
-       }\r
-\r
-       hCDRDriver = SysLoadLibrary(CDRdll);\r
-       if (hCDRDriver == NULL) {\r
-               CDR_configure = NULL;\r
-               SysMessage (_("Could not load CD-ROM plugin %s!"), CDRdll);  return -1;\r
-       }\r
-       drv = hCDRDriver;\r
-       LoadCdrSym1(init, "CDRinit");\r
-       LoadCdrSym1(shutdown, "CDRshutdown");\r
-       LoadCdrSym1(open, "CDRopen");\r
-       LoadCdrSym1(close, "CDRclose");\r
-       LoadCdrSym1(getTN, "CDRgetTN");\r
-       LoadCdrSym1(getTD, "CDRgetTD");\r
-       LoadCdrSym1(readTrack, "CDRreadTrack");\r
-       LoadCdrSym1(getBuffer, "CDRgetBuffer");\r
-       LoadCdrSym1(getBufferSub, "CDRgetBufferSub");\r
-       LoadCdrSym0(play, "CDRplay");\r
-       LoadCdrSym0(stop, "CDRstop");\r
-       LoadCdrSym0(getStatus, "CDRgetStatus");\r
-       LoadCdrSym0(getDriveLetter, "CDRgetDriveLetter");\r
-       LoadCdrSym0(configure, "CDRconfigure");\r
-       LoadCdrSym0(test, "CDRtest");\r
-       LoadCdrSym0(about, "CDRabout");\r
-       LoadCdrSym0(setfilename, "CDRsetfilename");\r
-       LoadCdrSymN(readCDDA, "CDRreadCDDA");\r
-       LoadCdrSymN(getTE, "CDRgetTE");\r
-\r
-       return 0;\r
-}\r
-\r
+/***************************************************************************
+ *   Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team              *
+ *                                                                         *
+ *   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.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
+ ***************************************************************************/
+
+/*
+* Plugin library callback/access functions.
+*/
+
+#include "plugins.h"
+#include "cdriso.h"
+
+static char IsoFile[MAXPATHLEN] = "";
+static s64 cdOpenCaseTime = 0;
+
+GPUupdateLace         GPU_updateLace;
+GPUinit               GPU_init;
+GPUshutdown           GPU_shutdown;
+GPUconfigure          GPU_configure;
+GPUtest               GPU_test;
+GPUabout              GPU_about;
+GPUopen               GPU_open;
+GPUclose              GPU_close;
+GPUreadStatus         GPU_readStatus;
+GPUreadData           GPU_readData;
+GPUreadDataMem        GPU_readDataMem;
+GPUwriteStatus        GPU_writeStatus;
+GPUwriteData          GPU_writeData;
+GPUwriteDataMem       GPU_writeDataMem;
+GPUdmaChain           GPU_dmaChain;
+GPUkeypressed         GPU_keypressed;
+GPUdisplayText        GPU_displayText;
+GPUmakeSnapshot       GPU_makeSnapshot;
+GPUfreeze             GPU_freeze;
+GPUgetScreenPic       GPU_getScreenPic;
+GPUshowScreenPic      GPU_showScreenPic;
+GPUvBlank             GPU_vBlank;
+
+CDRinit               CDR_init;
+CDRshutdown           CDR_shutdown;
+CDRopen               CDR_open;
+CDRclose              CDR_close;
+CDRtest               CDR_test;
+CDRgetTN              CDR_getTN;
+CDRgetTD              CDR_getTD;
+CDRreadTrack          CDR_readTrack;
+CDRgetBuffer          CDR_getBuffer;
+CDRplay               CDR_play;
+CDRstop               CDR_stop;
+CDRgetStatus          CDR_getStatus;
+CDRgetDriveLetter     CDR_getDriveLetter;
+CDRgetBufferSub       CDR_getBufferSub;
+CDRconfigure          CDR_configure;
+CDRabout              CDR_about;
+CDRsetfilename        CDR_setfilename;
+CDRreadCDDA           CDR_readCDDA;
+CDRgetTE              CDR_getTE;
+
+SPUinit               SPU_init;
+SPUshutdown           SPU_shutdown;
+SPUopen               SPU_open;
+SPUclose              SPU_close;
+SPUwriteRegister      SPU_writeRegister;
+SPUreadRegister       SPU_readRegister;
+SPUwriteDMAMem        SPU_writeDMAMem;
+SPUreadDMAMem         SPU_readDMAMem;
+SPUplayADPCMchannel   SPU_playADPCMchannel;
+SPUfreeze             SPU_freeze;
+SPUregisterCallback   SPU_registerCallback;
+SPUregisterScheduleCb SPU_registerScheduleCb;
+SPUasync              SPU_async;
+SPUplayCDDAchannel    SPU_playCDDAchannel;
+
+PADconfigure          PAD1_configure;
+PADabout              PAD1_about;
+PADinit               PAD1_init;
+PADshutdown           PAD1_shutdown;
+PADtest               PAD1_test;
+PADopen               PAD1_open;
+PADclose              PAD1_close;
+PADquery              PAD1_query;
+PADreadPort1          PAD1_readPort1;
+PADkeypressed         PAD1_keypressed;
+PADstartPoll          PAD1_startPoll;
+PADpoll               PAD1_poll;
+PADsetSensitive       PAD1_setSensitive;
+
+PADconfigure          PAD2_configure;
+PADabout              PAD2_about;
+PADinit               PAD2_init;
+PADshutdown           PAD2_shutdown;
+PADtest               PAD2_test;
+PADopen               PAD2_open;
+PADclose              PAD2_close;
+PADquery              PAD2_query;
+PADreadPort2          PAD2_readPort2;
+PADkeypressed         PAD2_keypressed;
+PADstartPoll          PAD2_startPoll;
+PADpoll               PAD2_poll;
+PADsetSensitive       PAD2_setSensitive;
+
+NETinit               NET_init;
+NETshutdown           NET_shutdown;
+NETopen               NET_open;
+NETclose              NET_close;
+NETtest               NET_test;
+NETconfigure          NET_configure;
+NETabout              NET_about;
+NETpause              NET_pause;
+NETresume             NET_resume;
+NETqueryPlayer        NET_queryPlayer;
+NETsendData           NET_sendData;
+NETrecvData           NET_recvData;
+NETsendPadData        NET_sendPadData;
+NETrecvPadData        NET_recvPadData;
+NETsetInfo            NET_setInfo;
+NETkeypressed         NET_keypressed;
+
+#ifdef ENABLE_SIO1API
+
+SIO1init              SIO1_init;
+SIO1shutdown          SIO1_shutdown;
+SIO1open              SIO1_open;
+SIO1close             SIO1_close;
+SIO1test              SIO1_test;
+SIO1configure         SIO1_configure;
+SIO1about             SIO1_about;
+SIO1pause             SIO1_pause;
+SIO1resume            SIO1_resume;
+SIO1keypressed        SIO1_keypressed;
+SIO1writeData8        SIO1_writeData8;
+SIO1writeData16       SIO1_writeData16;
+SIO1writeData32       SIO1_writeData32;
+SIO1writeStat16       SIO1_writeStat16;
+SIO1writeStat32       SIO1_writeStat32;
+SIO1writeMode16       SIO1_writeMode16;
+SIO1writeMode32       SIO1_writeMode32;
+SIO1writeCtrl16       SIO1_writeCtrl16;
+SIO1writeCtrl32       SIO1_writeCtrl32;
+SIO1writeBaud16       SIO1_writeBaud16;
+SIO1writeBaud32       SIO1_writeBaud32;
+SIO1readData8         SIO1_readData8;
+SIO1readData16        SIO1_readData16;
+SIO1readData32        SIO1_readData32;
+SIO1readStat16        SIO1_readStat16;
+SIO1readStat32        SIO1_readStat32;
+SIO1readMode16        SIO1_readMode16;
+SIO1readMode32        SIO1_readMode32;
+SIO1readCtrl16        SIO1_readCtrl16;
+SIO1readCtrl32        SIO1_readCtrl32;
+SIO1readBaud16        SIO1_readBaud16;
+SIO1readBaud32        SIO1_readBaud32;
+SIO1registerCallback  SIO1_registerCallback;
+
+#endif
+
+static const char *err;
+
+#define CheckErr(func) { \
+       err = SysLibError(); \
+       if (err != NULL) { SysMessage(_("Error loading %s: %s"), func, err); return -1; } \
+}
+
+#define LoadSym(dest, src, name, checkerr) { \
+       dest = (src)SysLoadSym(drv, name); \
+       if (checkerr) { CheckErr(name); } else SysLibError(); \
+}
+
+void *hGPUDriver = NULL;
+
+void CALLBACK GPU__displayText(char *pText) {
+       SysPrintf("%s\n", pText);
+}
+
+long CALLBACK GPU__configure(void) { return 0; }
+long CALLBACK GPU__test(void) { return 0; }
+void CALLBACK GPU__about(void) {}
+void CALLBACK GPU__makeSnapshot(void) {}
+void CALLBACK GPU__keypressed(int key) {}
+long CALLBACK GPU__getScreenPic(unsigned char *pMem) { return -1; }
+long CALLBACK GPU__showScreenPic(unsigned char *pMem) { return -1; }
+void CALLBACK GPU__vBlank(int val) {}
+
+#define LoadGpuSym1(dest, name) \
+       LoadSym(GPU_##dest, GPU##dest, name, TRUE);
+
+#define LoadGpuSym0(dest, name) \
+       LoadSym(GPU_##dest, GPU##dest, name, FALSE); \
+       if (GPU_##dest == NULL) GPU_##dest = (GPU##dest) GPU__##dest;
+
+#define LoadGpuSymN(dest, name) \
+       LoadSym(GPU_##dest, GPU##dest, name, FALSE);
+
+static int LoadGPUplugin(const char *GPUdll) {
+       void *drv;
+
+       hGPUDriver = SysLoadLibrary(GPUdll);
+       if (hGPUDriver == NULL) {
+               GPU_configure = NULL;
+               SysMessage (_("Could not load GPU plugin %s!"), GPUdll); return -1;
+       }
+       drv = hGPUDriver;
+       LoadGpuSym1(init, "GPUinit");
+       LoadGpuSym1(shutdown, "GPUshutdown");
+       LoadGpuSym1(open, "GPUopen");
+       LoadGpuSym1(close, "GPUclose");
+       LoadGpuSym1(readData, "GPUreadData");
+       LoadGpuSym1(readDataMem, "GPUreadDataMem");
+       LoadGpuSym1(readStatus, "GPUreadStatus");
+       LoadGpuSym1(writeData, "GPUwriteData");
+       LoadGpuSym1(writeDataMem, "GPUwriteDataMem");
+       LoadGpuSym1(writeStatus, "GPUwriteStatus");
+       LoadGpuSym1(dmaChain, "GPUdmaChain");
+       LoadGpuSym1(updateLace, "GPUupdateLace");
+       LoadGpuSym0(keypressed, "GPUkeypressed");
+       LoadGpuSym0(displayText, "GPUdisplayText");
+       LoadGpuSym0(makeSnapshot, "GPUmakeSnapshot");
+       LoadGpuSym1(freeze, "GPUfreeze");
+       LoadGpuSym0(getScreenPic, "GPUgetScreenPic");
+       LoadGpuSym0(showScreenPic, "GPUshowScreenPic");
+       LoadGpuSym0(vBlank, "GPUvBlank");
+       LoadGpuSym0(configure, "GPUconfigure");
+       LoadGpuSym0(test, "GPUtest");
+       LoadGpuSym0(about, "GPUabout");
+
+       return 0;
+}
+
+void *hCDRDriver = NULL;
+
+long CALLBACK CDR__play(unsigned char *sector) { return 0; }
+long CALLBACK CDR__stop(void) { return 0; }
+
+long CALLBACK CDR__getStatus(struct CdrStat *stat) {
+       if (cdOpenCaseTime < 0 || cdOpenCaseTime > (s64)time(NULL))
+               stat->Status = 0x10;
+       else
+               stat->Status = 0;
+
+       return 0;
+}
+
+char* CALLBACK CDR__getDriveLetter(void) { return NULL; }
+long CALLBACK CDR__configure(void) { return 0; }
+long CALLBACK CDR__test(void) { return 0; }
+void CALLBACK CDR__about(void) {}
+long CALLBACK CDR__setfilename(char*filename) { return 0; }
+
+#define LoadCdrSym1(dest, name) \
+       LoadSym(CDR_##dest, CDR##dest, name, TRUE);
+
+#define LoadCdrSym0(dest, name) \
+       LoadSym(CDR_##dest, CDR##dest, name, FALSE); \
+       if (CDR_##dest == NULL) CDR_##dest = (CDR##dest) CDR__##dest;
+
+#define LoadCdrSymN(dest, name) \
+       LoadSym(CDR_##dest, CDR##dest, name, FALSE);
+
+static int LoadCDRplugin(const char *CDRdll) {
+       void *drv;
+
+       if (CDRdll == NULL) {
+               cdrIsoInit();
+               return 0;
+       }
+
+       hCDRDriver = SysLoadLibrary(CDRdll);
+       if (hCDRDriver == NULL) {
+               CDR_configure = NULL;
+               SysMessage (_("Could not load CD-ROM plugin %s!"), CDRdll);  return -1;
+       }
+       drv = hCDRDriver;
+       LoadCdrSym1(init, "CDRinit");
+       LoadCdrSym1(shutdown, "CDRshutdown");
+       LoadCdrSym1(open, "CDRopen");
+       LoadCdrSym1(close, "CDRclose");
+       LoadCdrSym1(getTN, "CDRgetTN");
+       LoadCdrSym1(getTD, "CDRgetTD");
+       LoadCdrSym1(readTrack, "CDRreadTrack");
+       LoadCdrSym1(getBuffer, "CDRgetBuffer");
+       LoadCdrSym1(getBufferSub, "CDRgetBufferSub");
+       LoadCdrSym0(play, "CDRplay");
+       LoadCdrSym0(stop, "CDRstop");
+       LoadCdrSym0(getStatus, "CDRgetStatus");
+       LoadCdrSym0(getDriveLetter, "CDRgetDriveLetter");
+       LoadCdrSym0(configure, "CDRconfigure");
+       LoadCdrSym0(test, "CDRtest");
+       LoadCdrSym0(about, "CDRabout");
+       LoadCdrSym0(setfilename, "CDRsetfilename");
+       LoadCdrSymN(readCDDA, "CDRreadCDDA");
+       LoadCdrSymN(getTE, "CDRgetTE");
+
+       return 0;
+}
+
 static void *hSPUDriver = NULL;\r
 static void CALLBACK SPU__registerScheduleCb(void (CALLBACK *cb)(unsigned int)) {}\r
-\r
-#define LoadSpuSym1(dest, name) \\r
-       LoadSym(SPU_##dest, SPU##dest, name, TRUE);\r
-\r
-#define LoadSpuSym0(dest, name) \\r
-       LoadSym(SPU_##dest, SPU##dest, name, FALSE); \\r
-       if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest;\r
-\r
-#define LoadSpuSymN(dest, name) \\r
-       LoadSym(SPU_##dest, SPU##dest, name, FALSE);\r
-\r
-static int LoadSPUplugin(const char *SPUdll) {\r
-       void *drv;\r
-\r
-       hSPUDriver = SysLoadLibrary(SPUdll);\r
-       if (hSPUDriver == NULL) {\r
-               SysMessage (_("Could not load SPU plugin %s!"), SPUdll); return -1;\r
-       }\r
-       drv = hSPUDriver;\r
-       LoadSpuSym1(init, "SPUinit");\r
-       LoadSpuSym1(shutdown, "SPUshutdown");\r
-       LoadSpuSym1(open, "SPUopen");\r
-       LoadSpuSym1(close, "SPUclose");\r
-       LoadSpuSym1(writeRegister, "SPUwriteRegister");\r
-       LoadSpuSym1(readRegister, "SPUreadRegister");           \r
-       LoadSpuSym1(writeDMAMem, "SPUwriteDMAMem");\r
-       LoadSpuSym1(readDMAMem, "SPUreadDMAMem");\r
-       LoadSpuSym1(playADPCMchannel, "SPUplayADPCMchannel");\r
-       LoadSpuSym1(freeze, "SPUfreeze");\r
-       LoadSpuSym1(registerCallback, "SPUregisterCallback");\r
-       LoadSpuSym0(registerScheduleCb, "SPUregisterScheduleCb");\r
-       LoadSpuSymN(async, "SPUasync");\r
-       LoadSpuSymN(playCDDAchannel, "SPUplayCDDAchannel");\r
-\r
-       return 0;\r
-}\r
-\r
-void *hPAD1Driver = NULL;\r
-void *hPAD2Driver = NULL;\r
-\r
-static unsigned char buf[256];\r
-unsigned char stdpar[10] = { 0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
-unsigned char mousepar[8] = { 0x00, 0x12, 0x5a, 0xff, 0xff, 0xff, 0xff };\r
-unsigned char analogpar[9] = { 0x00, 0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
-\r
-static int bufcount, bufc;\r
-\r
-PadDataS padd1, padd2;\r
-\r
-unsigned char _PADstartPoll(PadDataS *pad) {\r
-    bufc = 0;\r
-\r
-    switch (pad->controllerType) {\r
-        case PSE_PAD_TYPE_MOUSE:\r
-            mousepar[3] = pad->buttonStatus & 0xff;\r
-            mousepar[4] = pad->buttonStatus >> 8;\r
-            mousepar[5] = pad->moveX;\r
-            mousepar[6] = pad->moveY;\r
-\r
-            memcpy(buf, mousepar, 7);\r
-            bufcount = 6;\r
-            break;\r
-        case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069)\r
-            analogpar[1] = 0x23;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
-            break;\r
-        case PSE_PAD_TYPE_ANALOGPAD: // scph1150\r
-            analogpar[1] = 0x73;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
-            break;\r
-        case PSE_PAD_TYPE_ANALOGJOY: // scph1110\r
-            analogpar[1] = 0x53;\r
-            analogpar[3] = pad->buttonStatus & 0xff;\r
-            analogpar[4] = pad->buttonStatus >> 8;\r
-            analogpar[5] = pad->rightJoyX;\r
-            analogpar[6] = pad->rightJoyY;\r
-            analogpar[7] = pad->leftJoyX;\r
-            analogpar[8] = pad->leftJoyY;\r
-\r
-            memcpy(buf, analogpar, 9);\r
-            bufcount = 8;\r
-            break;\r
-        case PSE_PAD_TYPE_STANDARD:\r
-        default:\r
-            stdpar[3] = pad->buttonStatus & 0xff;\r
-            stdpar[4] = pad->buttonStatus >> 8;\r
-\r
-            memcpy(buf, stdpar, 5);\r
-            bufcount = 4;\r
-    }\r
-\r
-    return buf[bufc++];\r
-}\r
-\r
-unsigned char _PADpoll(unsigned char value) {\r
-    if (bufc > bufcount) return 0;\r
-    return buf[bufc++];\r
-}\r
-\r
-unsigned char CALLBACK PAD1__startPoll(int pad) {\r
-    PadDataS padd;\r
-\r
-    PAD1_readPort1(&padd);\r
-\r
-    return _PADstartPoll(&padd);\r
-}\r
-\r
-unsigned char CALLBACK PAD1__poll(unsigned char value) {\r
-    return _PADpoll(value);\r
-}\r
-\r
-long CALLBACK PAD1__configure(void) { return 0; }\r
-void CALLBACK PAD1__about(void) {}\r
-long CALLBACK PAD1__test(void) { return 0; }\r
-long CALLBACK PAD1__query(void) { return 3; }\r
-long CALLBACK PAD1__keypressed() { return 0; }\r
-\r
-#define LoadPad1Sym1(dest, name) \\r
-       LoadSym(PAD1_##dest, PAD##dest, name, TRUE);\r
-\r
-#define LoadPad1SymN(dest, name) \\r
-       LoadSym(PAD1_##dest, PAD##dest, name, FALSE);\r
-\r
-#define LoadPad1Sym0(dest, name) \\r
-       LoadSym(PAD1_##dest, PAD##dest, name, FALSE); \\r
-       if (PAD1_##dest == NULL) PAD1_##dest = (PAD##dest) PAD1__##dest;\r
-\r
-static int LoadPAD1plugin(const char *PAD1dll) {\r
-       void *drv;\r
-\r
-       hPAD1Driver = SysLoadLibrary(PAD1dll);\r
-       if (hPAD1Driver == NULL) {\r
-               PAD1_configure = NULL;\r
-               SysMessage (_("Could not load Controller 1 plugin %s!"), PAD1dll); return -1;\r
-       }\r
-       drv = hPAD1Driver;\r
-       LoadPad1Sym1(init, "PADinit");\r
-       LoadPad1Sym1(shutdown, "PADshutdown");\r
-       LoadPad1Sym1(open, "PADopen");\r
-       LoadPad1Sym1(close, "PADclose");\r
-       LoadPad1Sym0(query, "PADquery");\r
-       LoadPad1Sym1(readPort1, "PADreadPort1");\r
-       LoadPad1Sym0(configure, "PADconfigure");\r
-       LoadPad1Sym0(test, "PADtest");\r
-       LoadPad1Sym0(about, "PADabout");\r
-       LoadPad1Sym0(keypressed, "PADkeypressed");\r
-       LoadPad1Sym0(startPoll, "PADstartPoll");\r
-       LoadPad1Sym0(poll, "PADpoll");\r
-       LoadPad1SymN(setSensitive, "PADsetSensitive");\r
-\r
-       return 0;\r
-}\r
-\r
-unsigned char CALLBACK PAD2__startPoll(int pad) {\r
-       PadDataS padd;\r
-\r
-       PAD2_readPort2(&padd);\r
-    \r
-       return _PADstartPoll(&padd);\r
-}\r
-\r
-unsigned char CALLBACK PAD2__poll(unsigned char value) {\r
-       return _PADpoll(value);\r
-}\r
-\r
-long CALLBACK PAD2__configure(void) { return 0; }\r
-void CALLBACK PAD2__about(void) {}\r
-long CALLBACK PAD2__test(void) { return 0; }\r
-long CALLBACK PAD2__query(void) { return PSE_PAD_USE_PORT1 | PSE_PAD_USE_PORT2; }\r
-long CALLBACK PAD2__keypressed() { return 0; }\r
-\r
-#define LoadPad2Sym1(dest, name) \\r
-       LoadSym(PAD2_##dest, PAD##dest, name, TRUE);\r
-\r
-#define LoadPad2Sym0(dest, name) \\r
-       LoadSym(PAD2_##dest, PAD##dest, name, FALSE); \\r
-       if (PAD2_##dest == NULL) PAD2_##dest = (PAD##dest) PAD2__##dest;\r
-\r
-#define LoadPad2SymN(dest, name) \\r
-       LoadSym(PAD2_##dest, PAD##dest, name, FALSE);\r
-\r
-static int LoadPAD2plugin(const char *PAD2dll) {\r
-       void *drv;\r
-\r
-       hPAD2Driver = SysLoadLibrary(PAD2dll);\r
-       if (hPAD2Driver == NULL) {\r
-               PAD2_configure = NULL;\r
-               SysMessage (_("Could not load Controller 2 plugin %s!"), PAD2dll); return -1;\r
-       }\r
-       drv = hPAD2Driver;\r
-       LoadPad2Sym1(init, "PADinit");\r
-       LoadPad2Sym1(shutdown, "PADshutdown");\r
-       LoadPad2Sym1(open, "PADopen");\r
-       LoadPad2Sym1(close, "PADclose");\r
-       LoadPad2Sym0(query, "PADquery");\r
-       LoadPad2Sym1(readPort2, "PADreadPort2");\r
-       LoadPad2Sym0(configure, "PADconfigure");\r
-       LoadPad2Sym0(test, "PADtest");\r
-       LoadPad2Sym0(about, "PADabout");\r
-       LoadPad2Sym0(keypressed, "PADkeypressed");\r
-       LoadPad2Sym0(startPoll, "PADstartPoll");\r
-       LoadPad2Sym0(poll, "PADpoll");\r
-       LoadPad2SymN(setSensitive, "PADsetSensitive");\r
-\r
-       return 0;\r
-}\r
-\r
-void *hNETDriver = NULL;\r
-\r
-void CALLBACK NET__setInfo(netInfo *info) {}\r
-void CALLBACK NET__keypressed(int key) {}\r
-long CALLBACK NET__configure(void) { return 0; }\r
-long CALLBACK NET__test(void) { return 0; }\r
-void CALLBACK NET__about(void) {}\r
-\r
-#define LoadNetSym1(dest, name) \\r
-       LoadSym(NET_##dest, NET##dest, name, TRUE);\r
-\r
-#define LoadNetSymN(dest, name) \\r
-       LoadSym(NET_##dest, NET##dest, name, FALSE);\r
-\r
-#define LoadNetSym0(dest, name) \\r
-       LoadSym(NET_##dest, NET##dest, name, FALSE); \\r
-       if (NET_##dest == NULL) NET_##dest = (NET##dest) NET__##dest;\r
-\r
-static int LoadNETplugin(const char *NETdll) {\r
-       void *drv;\r
-\r
-       hNETDriver = SysLoadLibrary(NETdll);\r
-       if (hNETDriver == NULL) {\r
-               SysMessage (_("Could not load NetPlay plugin %s!"), NETdll); return -1;\r
-       }\r
-       drv = hNETDriver;\r
-       LoadNetSym1(init, "NETinit");\r
-       LoadNetSym1(shutdown, "NETshutdown");\r
-       LoadNetSym1(open, "NETopen");\r
-       LoadNetSym1(close, "NETclose");\r
-       LoadNetSymN(sendData, "NETsendData");\r
-       LoadNetSymN(recvData, "NETrecvData");\r
-       LoadNetSym1(sendPadData, "NETsendPadData");\r
-       LoadNetSym1(recvPadData, "NETrecvPadData");\r
-       LoadNetSym1(queryPlayer, "NETqueryPlayer");\r
-       LoadNetSym1(pause, "NETpause");\r
-       LoadNetSym1(resume, "NETresume");\r
-       LoadNetSym0(setInfo, "NETsetInfo");\r
-       LoadNetSym0(keypressed, "NETkeypressed");\r
-       LoadNetSym0(configure, "NETconfigure");\r
-       LoadNetSym0(test, "NETtest");\r
-       LoadNetSym0(about, "NETabout");\r
-\r
-       return 0;\r
-}\r
-\r
-#ifdef ENABLE_SIO1API\r
-\r
-void *hSIO1Driver = NULL;\r
-\r
-long CALLBACK SIO1__init(void) { return 0; }\r
-long CALLBACK SIO1__shutdown(void) { return 0; }\r
-long CALLBACK SIO1__open(void) { return 0; }\r
-long CALLBACK SIO1__close(void) { return 0; }\r
-long CALLBACK SIO1__configure(void) { return 0; }\r
-long CALLBACK SIO1__test(void) { return 0; }\r
-void CALLBACK SIO1__about(void) {}\r
-void CALLBACK SIO1__pause(void) {}\r
-void CALLBACK SIO1__resume(void) {}\r
-long CALLBACK SIO1__keypressed(int key) { return 0; }\r
-void CALLBACK SIO1__writeData8(unsigned char val) {}\r
-void CALLBACK SIO1__writeData16(unsigned short val) {}\r
-void CALLBACK SIO1__writeData32(unsigned long val) {}\r
-void CALLBACK SIO1__writeStat16(unsigned short val) {}\r
-void CALLBACK SIO1__writeStat32(unsigned long val) {}\r
-void CALLBACK SIO1__writeMode16(unsigned short val) {}\r
-void CALLBACK SIO1__writeMode32(unsigned long val) {}\r
-void CALLBACK SIO1__writeCtrl16(unsigned short val) {}\r
-void CALLBACK SIO1__writeCtrl32(unsigned long val) {}\r
-void CALLBACK SIO1__writeBaud16(unsigned short val) {}\r
-void CALLBACK SIO1__writeBaud32(unsigned long val) {}\r
-unsigned char CALLBACK SIO1__readData8(void) { return 0; }\r
-unsigned short CALLBACK SIO1__readData16(void) { return 0; }\r
-unsigned long CALLBACK SIO1__readData32(void) { return 0; }\r
-unsigned short CALLBACK SIO1__readStat16(void) { return 0; }\r
-unsigned long CALLBACK SIO1__readStat32(void) { return 0; }\r
-unsigned short CALLBACK SIO1__readMode16(void) { return 0; }\r
-unsigned long CALLBACK SIO1__readMode32(void) { return 0; }\r
-unsigned short CALLBACK SIO1__readCtrl16(void) { return 0; }\r
-unsigned long CALLBACK SIO1__readCtrl32(void) { return 0; }\r
-unsigned short CALLBACK SIO1__readBaud16(void) { return 0; }\r
-unsigned long CALLBACK SIO1__readBaud32(void) { return 0; }\r
-void CALLBACK SIO1__registerCallback(void (CALLBACK *callback)(void)) {};\r
-\r
-void CALLBACK SIO1irq(void) {\r
-    psxHu32ref(0x1070) |= SWAPu32(0x100);\r
-}\r
-\r
-#define LoadSio1Sym1(dest, name) \\r
-    LoadSym(SIO1_##dest, SIO1##dest, name, TRUE);\r
-\r
-#define LoadSio1SymN(dest, name) \\r
-    LoadSym(SIO1_##dest, SIO1##dest, name, FALSE);\r
-\r
-#define LoadSio1Sym0(dest, name) \\r
-    LoadSym(SIO1_##dest, SIO1##dest, name, FALSE); \\r
-    if (SIO1_##dest == NULL) SIO1_##dest = (SIO1##dest) SIO1__##dest;\r
-\r
-static int LoadSIO1plugin(const char *SIO1dll) {\r
-    void *drv;\r
-\r
-    hSIO1Driver = SysLoadLibrary(SIO1dll);\r
-    if (hSIO1Driver == NULL) {\r
-        SysMessage (_("Could not load SIO1 plugin %s!"), SIO1dll); return -1;\r
-    }\r
-    drv = hSIO1Driver;\r
-\r
-    LoadSio1Sym0(init, "SIO1init");\r
-    LoadSio1Sym0(shutdown, "SIO1shutdown");\r
-    LoadSio1Sym0(open, "SIO1open");\r
-    LoadSio1Sym0(close, "SIO1close");\r
-    LoadSio1Sym0(pause, "SIO1pause");\r
-    LoadSio1Sym0(resume, "SIO1resume");\r
-    LoadSio1Sym0(keypressed, "SIO1keypressed");\r
-    LoadSio1Sym0(configure, "SIO1configure");\r
-    LoadSio1Sym0(test, "SIO1test");\r
-    LoadSio1Sym0(about, "SIO1about");\r
-    LoadSio1Sym0(writeData8, "SIO1writeData8");\r
-    LoadSio1Sym0(writeData16, "SIO1writeData16");\r
-    LoadSio1Sym0(writeData32, "SIO1writeData32");\r
-    LoadSio1Sym0(writeStat16, "SIO1writeStat16");\r
-    LoadSio1Sym0(writeStat32, "SIO1writeStat32");\r
-    LoadSio1Sym0(writeMode16, "SIO1writeMode16");\r
-    LoadSio1Sym0(writeMode32, "SIO1writeMode32");\r
-    LoadSio1Sym0(writeCtrl16, "SIO1writeCtrl16");\r
-    LoadSio1Sym0(writeCtrl32, "SIO1writeCtrl32");\r
-    LoadSio1Sym0(writeBaud16, "SIO1writeBaud16");\r
-    LoadSio1Sym0(writeBaud32, "SIO1writeBaud32");\r
-    LoadSio1Sym0(readData16, "SIO1readData16");\r
-    LoadSio1Sym0(readData32, "SIO1readData32");\r
-    LoadSio1Sym0(readStat16, "SIO1readStat16");\r
-    LoadSio1Sym0(readStat32, "SIO1readStat32");\r
-    LoadSio1Sym0(readMode16, "SIO1readMode16");\r
-    LoadSio1Sym0(readMode32, "SIO1readMode32");\r
-    LoadSio1Sym0(readCtrl16, "SIO1readCtrl16");\r
-    LoadSio1Sym0(readCtrl32, "SIO1readCtrl32");\r
-    LoadSio1Sym0(readBaud16, "SIO1readBaud16");\r
-    LoadSio1Sym0(readBaud32, "SIO1readBaud32");\r
-    LoadSio1Sym0(registerCallback, "SIO1registerCallback");\r
-\r
-    return 0;\r
-}\r
-\r
-#endif\r
-\r
-int LoadPlugins() {\r
-       int ret;\r
-       char Plugin[MAXPATHLEN * 2];\r
-\r
-       ReleasePlugins();\r
-       SysLibError();\r
-\r
-       if (UsingIso()) {\r
-               LoadCDRplugin(NULL);\r
-       } else {\r
-               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr);\r
-               if (LoadCDRplugin(Plugin) == -1) return -1;\r
-       }\r
-\r
-       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Gpu);\r
-       if (LoadGPUplugin(Plugin) == -1) return -1;\r
-\r
-       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Spu);\r
-       if (LoadSPUplugin(Plugin) == -1) return -1;\r
-\r
-       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad1);\r
-       if (LoadPAD1plugin(Plugin) == -1) return -1;\r
-\r
-       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad2);\r
-       if (LoadPAD2plugin(Plugin) == -1) return -1;\r
-\r
-       if (strcmp("Disabled", Config.Net) == 0 || strcmp("", Config.Net) == 0)\r
-               Config.UseNet = FALSE;\r
-       else {\r
-               Config.UseNet = TRUE;\r
-               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Net);\r
-               if (LoadNETplugin(Plugin) == -1) Config.UseNet = FALSE;\r
-       }\r
-\r
-#ifdef ENABLE_SIO1API\r
-       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Sio1);\r
-       if (LoadSIO1plugin(Plugin) == -1) return -1;\r
-#endif\r
-\r
-       ret = CDR_init();\r
-       if (ret < 0) { SysMessage (_("Error initializing CD-ROM plugin: %d"), ret); return -1; }\r
-       ret = GPU_init();\r
-       if (ret < 0) { SysMessage (_("Error initializing GPU plugin: %d"), ret); return -1; }\r
-       ret = SPU_init();\r
-       if (ret < 0) { SysMessage (_("Error initializing SPU plugin: %d"), ret); return -1; }\r
-       ret = PAD1_init(1);\r
-       if (ret < 0) { SysMessage (_("Error initializing Controller 1 plugin: %d"), ret); return -1; }\r
-       ret = PAD2_init(2);\r
-       if (ret < 0) { SysMessage (_("Error initializing Controller 2 plugin: %d"), ret); return -1; }\r
-\r
-       if (Config.UseNet) {\r
-               ret = NET_init();\r
-               if (ret < 0) { SysMessage (_("Error initializing NetPlay plugin: %d"), ret); return -1; }\r
-       }\r
-\r
-#ifdef ENABLE_SIO1API\r
-       ret = SIO1_init();\r
-       if (ret < 0) { SysMessage (_("Error initializing SIO1 plugin: %d"), ret); return -1; }\r
-#endif\r
-\r
-       SysPrintf(_("Plugins loaded.\n"));\r
-       return 0;\r
-}\r
-\r
-void ReleasePlugins() {\r
-       if (Config.UseNet) {\r
-               int ret = NET_close();\r
-               if (ret < 0) Config.UseNet = FALSE;\r
-       }\r
-       NetOpened = FALSE;\r
-\r
-       if (hCDRDriver != NULL || cdrIsoActive()) CDR_shutdown();\r
-       if (hGPUDriver != NULL) GPU_shutdown();\r
-       if (hSPUDriver != NULL) SPU_shutdown();\r
-       if (hPAD1Driver != NULL) PAD1_shutdown();\r
-       if (hPAD2Driver != NULL) PAD2_shutdown();\r
-\r
-       if (Config.UseNet && hNETDriver != NULL) NET_shutdown(); \r
-\r
-       if (hCDRDriver != NULL) { SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; }\r
-       if (hGPUDriver != NULL) { SysCloseLibrary(hGPUDriver); hGPUDriver = NULL; }\r
-       if (hSPUDriver != NULL) { SysCloseLibrary(hSPUDriver); hSPUDriver = NULL; }\r
-       if (hPAD1Driver != NULL) { SysCloseLibrary(hPAD1Driver); hPAD1Driver = NULL; }\r
-       if (hPAD2Driver != NULL) { SysCloseLibrary(hPAD2Driver); hPAD2Driver = NULL; }\r
-\r
-       if (Config.UseNet && hNETDriver != NULL) {\r
-               SysCloseLibrary(hNETDriver); hNETDriver = NULL;\r
-       }\r
-\r
-#ifdef ENABLE_SIO1API\r
-       if (hSIO1Driver != NULL) {\r
-               SIO1_shutdown();\r
-               SysCloseLibrary(hSIO1Driver);\r
-               hSIO1Driver = NULL;\r
-       }\r
-#endif\r
-}\r
-\r
-// for CD swap\r
-int ReloadCdromPlugin()\r
-{\r
-       if (hCDRDriver != NULL || cdrIsoActive()) CDR_shutdown();\r
-       if (hCDRDriver != NULL) { SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; }\r
-\r
-       if (UsingIso()) {\r
-               LoadCDRplugin(NULL);\r
-       } else {\r
-               char Plugin[MAXPATHLEN * 2];\r
-               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr);\r
-               if (LoadCDRplugin(Plugin) == -1) return -1;\r
-       }\r
-\r
-       return CDR_init();\r
-}\r
-\r
-void SetIsoFile(const char *filename) {\r
-       if (filename == NULL) {\r
-               IsoFile[0] = '\0';\r
-               return;\r
-       }\r
-       strncpy(IsoFile, filename, MAXPATHLEN - 1);\r
-}\r
-\r
-const char *GetIsoFile(void) {\r
-       return IsoFile;\r
-}\r
-\r
-boolean UsingIso(void) {\r
-       return (IsoFile[0] != '\0');\r
-}\r
-\r
-void SetCdOpenCaseTime(s64 time) {\r
-       cdOpenCaseTime = time;\r
-}\r
+
+#define LoadSpuSym1(dest, name) \
+       LoadSym(SPU_##dest, SPU##dest, name, TRUE);
+
+#define LoadSpuSym0(dest, name) \
+       LoadSym(SPU_##dest, SPU##dest, name, FALSE); \
+       if (SPU_##dest == NULL) SPU_##dest = (SPU##dest) SPU__##dest;
+
+#define LoadSpuSymN(dest, name) \
+       LoadSym(SPU_##dest, SPU##dest, name, FALSE);
+
+static int LoadSPUplugin(const char *SPUdll) {
+       void *drv;
+
+       hSPUDriver = SysLoadLibrary(SPUdll);
+       if (hSPUDriver == NULL) {
+               SysMessage (_("Could not load SPU plugin %s!"), SPUdll); return -1;
+       }
+       drv = hSPUDriver;
+       LoadSpuSym1(init, "SPUinit");
+       LoadSpuSym1(shutdown, "SPUshutdown");
+       LoadSpuSym1(open, "SPUopen");
+       LoadSpuSym1(close, "SPUclose");
+       LoadSpuSym1(writeRegister, "SPUwriteRegister");
+       LoadSpuSym1(readRegister, "SPUreadRegister");
+       LoadSpuSym1(writeDMAMem, "SPUwriteDMAMem");
+       LoadSpuSym1(readDMAMem, "SPUreadDMAMem");
+       LoadSpuSym1(playADPCMchannel, "SPUplayADPCMchannel");
+       LoadSpuSym1(freeze, "SPUfreeze");
+       LoadSpuSym1(registerCallback, "SPUregisterCallback");
+       LoadSpuSym0(registerScheduleCb, "SPUregisterScheduleCb");
+       LoadSpuSymN(async, "SPUasync");
+       LoadSpuSymN(playCDDAchannel, "SPUplayCDDAchannel");
+
+       return 0;
+}
+
+extern int in_type[8];
+
+void *hPAD1Driver = NULL;
+void *hPAD2Driver = NULL;
+
+static int multitap1;
+static int multitap2;
+//Pad information, keystate, mode, config mode, vibration
+static PadDataS pad[8];
+
+static int reqPos, respSize;
+static int ledStateReq44[8];
+static int PadMode[8]; /* 0 : digital 1: analog */
+
+static unsigned char buf[256];
+static unsigned char bufMulti[34] = { 0x80, 0x5a,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+unsigned char stdpar[8] = { 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+unsigned char multitappar[34] = { 0x80, 0x5a,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+                                                                       0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+
+//response for request 44, 45, 46, 47, 4C, 4D
+static unsigned char resp45[8]    = {0xF3, 0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00};
+static unsigned char resp46_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A};
+static unsigned char resp46_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14};
+static unsigned char resp47[8]    = {0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00};
+static unsigned char resp4C_00[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00};
+static unsigned char resp4C_01[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00};
+static unsigned char resp4D[8]    = {0xF3, 0x5A, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF};
+
+//fixed reponse of request number 41, 48, 49, 4A, 4B, 4E, 4F
+static unsigned char resp40[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp41[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp43[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp44[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp49[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4A[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4B[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4E[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+static unsigned char resp4F[8] = {0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+// Resquest of psx core
+enum {
+       // REQUEST
+       // first call of this request for the pad, the pad is configured as an digital pad.
+       // 0x0X, 0x42, 0x0Y, 0xZZ, 0xAA, 0x00, 0x00, 0x00, 0x00
+       // X pad number (used for the multitap, first request response 0x00, 0x80, 0x5A, (8 bytes pad A), (8 bytes pad B), (8 bytes pad C), (8 bytes pad D)
+       // Y if 1 : psx request the full length response for the multitap, 3 bytes header and 4 block of 8 bytes per pad
+       // Y if 0 : psx request a pad key state
+       // ZZ rumble small motor 00-> OFF, 01 -> ON
+       // AA rumble large motor speed 0x00 -> 0xFF
+       // RESPONSE
+       // header 3 Bytes
+       // 0x00
+       // PadId -> 0x41 for digital pas, 0x73 for analog pad
+       // 0x5A mode has not change (no press on analog button on the center of pad), 0x00 the analog button have been pressed and the mode switch
+       // 6 Bytes for keystates
+       CMD_READ_DATA_AND_VIBRATE = 0x42,
+
+       // REQUEST
+       // Header
+       // 0x0N, 0x43, 0x00, XX, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // XX = 00 -> Normal mode : Seconde bytes of response = padId
+       // XX = 01 -> Configuration mode : Seconde bytes of response = 0xF3
+       // RESPONSE
+       // enter in config mode example :
+       // req : 01 43 00 01 00 00 00 00 00 00
+       // res : 00 41 5A buttons state, analog states
+       // exit config mode :
+       // req : 01 43 00 00 00 00 00 00 00 00
+       // res : 00 F3 5A buttons state, analog states
+       CMD_CONFIG_MODE = 0x43,
+
+       // Set led State
+       // REQUEST
+       // 0x0N, 0x44, 0x00, VAL, SEL, 0x00, 0x00, 0x00, 0x00
+       // If sel = 2 then
+       // VAL = 00 -> OFF
+       // VAL = 01 -> ON
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       CMD_SET_MODE_AND_LOCK = 0x44,
+
+       // Get Analog Led state
+       // REQUEST
+       // 0x0N, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x01, 0x02, VAL, 0x02, 0x01, 0x00
+       // VAL = 00 Led OFF
+       // VAL = 01 Led ON
+       CMD_QUERY_MODEL_AND_MODE = 0x45,
+
+       //Get Variable A
+       // REQUEST
+       // 0x0N, 0x46, 0x00, 0xXX, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // XX=00
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A
+       // XX=01
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14
+       CMD_QUERY_ACT = 0x46,
+
+       // REQUEST
+       // 0x0N, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00
+       CMD_QUERY_COMB = 0x47,
+
+       // REQUEST
+       // 0x0N, 0x4C, 0x00, 0xXX, 0x00, 0x00, 0x00, 0x00, 0x00
+       // RESPONSE
+       // XX = 0
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00
+       // XX = 1
+       // 0x00, 0xF3, 0x5A, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00
+       CMD_QUERY_MODE = 0x4C,
+
+       // REQUEST
+       // 0x0N, 0x4D, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
+       // RESPONSE
+       // 0x00, 0xF3, 0x5A, old value or
+       // AA = 01 unlock large motor (and swap VAL1 and VAL2)
+       // BB = 01 unlock large motor (default)
+       // CC, DD, EE, FF = all FF -> unlock small motor
+       //
+       // default repsonse for analog pad with 2 motor : 0x00 0xF3 0x5A 0x00 0x01 0xFF 0xFF 0xFF 0xFF
+       //
+       CMD_VIBRATION_TOGGLE = 0x4D,
+       REQ40 = 0x40,
+       REQ41 = 0x41,
+       REQ49 = 0x49,
+       REQ4A = 0x4A,
+       REQ4B = 0x4B,
+       REQ4E = 0x4E,
+       REQ4F = 0x4F
+};
+
+
+
+
+//NO MULTITAP
+
+void initBufForRequest(int padIndex, char value){
+       switch (value){
+               //Pad keystate already in buffer
+               //case CMD_READ_DATA_AND_VIBRATE :
+               //      break;
+               case CMD_CONFIG_MODE :
+                       if (pad[padIndex].configMode == 1) {
+                               memcpy(buf, resp43, 8);
+                               break;
+                       }
+                       //else, not in config mode, pad keystate return (already in the buffer)
+                       break;
+               case CMD_SET_MODE_AND_LOCK :
+                       memcpy(buf, resp44, 8);
+                       break;
+               case CMD_QUERY_MODEL_AND_MODE :
+                       memcpy(buf, resp45, 8);
+                       buf[4] = PadMode[padIndex];
+                       break;
+               case CMD_QUERY_ACT :
+                       memcpy(buf, resp46_00, 8);
+                       break;
+               case CMD_QUERY_COMB :
+                       memcpy(buf, resp47, 8);
+                       break;
+               case CMD_QUERY_MODE :
+                       memcpy(buf, resp4C_00, 8);
+                       break;
+               case CMD_VIBRATION_TOGGLE :
+                       memcpy(buf, resp4D, 8);
+                       break;
+               case REQ40 :
+                       memcpy(buf, resp40, 8);
+                       break;
+               case REQ41 :
+                       memcpy(buf, resp41, 8);
+                       break;
+               case REQ49 :
+                       memcpy(buf, resp49, 8);
+                       break;
+               case REQ4A :
+                       memcpy(buf, resp4A, 8);
+                       break;
+               case REQ4B :
+                       memcpy(buf, resp4B, 8);
+                       break;
+               case REQ4E :
+                       memcpy(buf, resp4E, 8);
+                       break;
+               case REQ4F :
+                       memcpy(buf, resp4F, 8);
+                       break;
+       }
+}
+
+
+
+
+static void reqIndex2Treatment(int padIndex, char value) {
+       switch (pad[padIndex].txData[0]) {
+               case CMD_CONFIG_MODE :
+                       //0x43
+                       if (value == 0) {
+                               pad[padIndex].configMode = 0;
+                       } else {
+                               pad[padIndex].configMode = 1;
+                       }
+                       break;
+               case CMD_SET_MODE_AND_LOCK :
+                       //0x44 store the led state for change mode if the next value = 0x02
+                       //0x01 analog ON
+                       //0x00 analog OFF
+                       ledStateReq44[padIndex] = value;
+                       PadMode[padIndex] = value;
+                       break;
+               case CMD_QUERY_ACT :
+                       //0x46
+                       if (value == 1) {
+                               memcpy(buf, resp46_01, 8);
+                       }
+                       break;
+               case CMD_QUERY_MODE :
+                       if (value == 1) {
+                               memcpy(buf, resp4C_01, 8);
+                       }
+                       break;
+               case CMD_VIBRATION_TOGGLE :
+                       //0x4D
+                       memcpy(buf, resp4D, 8);
+                       break;
+               case CMD_READ_DATA_AND_VIBRATE:
+                       //mem the vibration value for small motor;
+                       pad[padIndex].Vib[0] = value;
+                       break;
+       }
+}
+
+void vibrate(int padIndex){
+       if (pad[padIndex].Vib[0] != pad[padIndex].VibF[0] || pad[padIndex].Vib[1] != pad[padIndex].VibF[1]) {
+               //value is different update Value and call libretro for vibration
+               pad[padIndex].VibF[0] = pad[padIndex].Vib[0];
+               pad[padIndex].VibF[1] = pad[padIndex].Vib[1];
+               plat_trigger_vibrate(padIndex, pad[padIndex].VibF[0], pad[padIndex].VibF[1]);
+               //printf("vibration pad %i", padIndex);
+       }
+}
+
+
+
+
+//Build response for 0x42 request Pad in port
+void _PADstartPoll(PadDataS *pad) {
+       switch (pad->controllerType) {
+               case PSE_PAD_TYPE_MOUSE:
+                       stdpar[0] = 0x12;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       stdpar[4] = pad->moveX;
+                       stdpar[5] = pad->moveY;
+                       memcpy(buf, stdpar, 6);
+                       respSize = 6;
+                       break;
+               case PSE_PAD_TYPE_NEGCON: // npc101/npc104(slph00001/slph00069)
+                       stdpar[0] = 0x23;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       stdpar[4] = pad->rightJoyX;
+                       stdpar[5] = pad->rightJoyY;
+                       stdpar[6] = pad->leftJoyX;
+                       stdpar[7] = pad->leftJoyY;
+                       memcpy(buf, stdpar, 8);
+                       respSize = 8;
+                       break;
+               case PSE_PAD_TYPE_GUNCON: // GUNCON - gun controller SLPH-00034 from Namco
+                       stdpar[0] = 0x63;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+
+                       //This code assumes an X resolution of 256 and a Y resolution of 240
+                       int xres = 256;
+                       int yres = 240;
+
+                       //The code wants an input range for x and y of 0-1023 we passed in -32767 -> 32767
+                       int absX = (pad->absoluteX / 64) + 512;
+                       int absY = (pad->absoluteY / 64) + 512;
+
+                       if (absX == 65536 || absY == 65536) {
+                          stdpar[4] = 0x01;
+                          stdpar[5] = 0x00;
+                          stdpar[6] = 0x0A;
+                          stdpar[7] = 0x00;
+                       }
+                       else {
+                          stdpar[4] = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * absX >> 10);
+                          stdpar[5] = (0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * absX >> 10)) >> 8;
+                          stdpar[6] = 0x20 + (yres * absY >> 10);
+                          stdpar[7] = (0x20 + (yres * absY >> 10)) >> 8;
+                       }
+
+                       memcpy(buf, stdpar, 8);
+                       respSize = 8;
+                       break;
+               case PSE_PAD_TYPE_GUN: // GUN CONTROLLER - gun controller SLPH-00014 from Konami
+                       stdpar[0] = 0x31;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       memcpy(buf, stdpar, 4);
+                       respSize = 4;
+                       break;
+               case PSE_PAD_TYPE_ANALOGPAD: // scph1150
+                       stdpar[0] = 0x73;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       stdpar[4] = pad->rightJoyX;
+                       stdpar[5] = pad->rightJoyY;
+                       stdpar[6] = pad->leftJoyX;
+                       stdpar[7] = pad->leftJoyY;
+                       memcpy(buf, stdpar, 8);
+                       respSize = 8;
+                       break;
+               case PSE_PAD_TYPE_ANALOGJOY: // scph1110
+                       stdpar[0] = 0x53;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       stdpar[4] = pad->rightJoyX;
+                       stdpar[5] = pad->rightJoyY;
+                       stdpar[6] = pad->leftJoyX;
+                       stdpar[7] = pad->leftJoyY;
+                       memcpy(buf, stdpar, 8);
+                       respSize = 8;
+                       break;
+               case PSE_PAD_TYPE_STANDARD:
+                       stdpar[0] = 0x41;
+                       stdpar[1] = 0x5a;
+                       stdpar[2] = pad->buttonStatus & 0xff;
+                       stdpar[3] = pad->buttonStatus >> 8;
+                       memcpy(buf, stdpar, 4);
+                       respSize = 4;
+                       break;
+               default:
+                       respSize = 0;
+                       break;
+       }
+}
+
+
+//Build response for 0x42 request Multitap in port
+//Response header for multitap : 0x80, 0x5A, (Pad information port 1-2A), (Pad information port 1-2B), (Pad information port 1-2C), (Pad information port 1-2D)
+void _PADstartPollMultitap(PadDataS* padd) {
+       int i, offset;
+       for(i = 0; i < 4; i++) {
+               offset = 2 + (i * 8);
+       _PADstartPoll(&padd[i]);
+       memcpy(multitappar+offset, stdpar, 8);
+       }
+       memcpy(bufMulti, multitappar, 34);
+       respSize = 34;
+}
+
+static void PADpoll_dualshock(int port, unsigned char value)
+{
+       switch (reqPos) {
+               case 0:
+                       initBufForRequest(port, value);
+                       break;
+               case 2:
+                       reqIndex2Treatment(port, value);
+                       break;
+               case 3:
+                       if (pad[port].txData[0] == CMD_READ_DATA_AND_VIBRATE) {
+                               // vibration value for the Large motor
+                               pad[port].Vib[1] = value;
+
+                               vibrate(port);
+                       }
+                       break;
+       }
+}
+
+static unsigned char PADpoll_(int port, unsigned char value, int *more_data) {
+       if (reqPos < sizeof(pad[port].txData))
+               pad[port].txData[reqPos] = value;
+
+       if (reqPos == 0 && value != 0x42 && in_type[port] != PSE_PAD_TYPE_ANALOGPAD)
+               respSize = 1;
+
+       switch (in_type[port]) {
+               case PSE_PAD_TYPE_ANALOGPAD:
+                       PADpoll_dualshock(port, value);
+                       break;
+               case PSE_PAD_TYPE_GUN:
+                       if (reqPos == 2)
+                               pl_gun_byte2(port, value);
+                       break;
+       }
+
+       *more_data = reqPos < respSize - 1;
+       if (reqPos >= respSize)
+               return 0xff; // no response/HiZ
+
+       return buf[reqPos++];
+}
+
+static unsigned char PADpollMultitap(int port, unsigned char value, int *more_data) {
+       *more_data = reqPos < respSize - 1;
+       if (reqPos >= respSize) return 0xff;
+       return bufMulti[reqPos++];
+}
+
+
+// refresh the button state on port 1.
+// int pad is not needed.
+unsigned char CALLBACK PAD1__startPoll(int pad) {
+       reqPos = 0;
+       // first call the pad provide if a multitap is connected between the psx and himself
+       // just one pad is on port 1 : NO MULTITAP
+       if (multitap1 == 0) {
+               PadDataS padd;
+               padd.requestPadIndex = 0;
+               PAD1_readPort1(&padd);
+               _PADstartPoll(&padd);
+       } else {
+               // a multitap is plugged : refresh all pad.
+               int i;
+               PadDataS padd[4];
+               for(i = 0; i < 4; i++) {
+                       padd[i].requestPadIndex = i;
+                       PAD1_readPort1(&padd[i]);
+               }
+               _PADstartPollMultitap(padd);
+       }
+       //printf("\npad 1 : ");
+       return 0xff;
+}
+
+unsigned char CALLBACK PAD1__poll(unsigned char value, int *more_data) {
+       char tmp;
+       if (multitap1 == 1) {
+               tmp = PADpollMultitap(0, value, more_data);
+       } else {
+               tmp = PADpoll_(0, value, more_data);
+       }
+       //printf("%2x:%2x, ",value,tmp);
+       return tmp;
+
+}
+
+
+long CALLBACK PAD1__configure(void) { return 0; }
+void CALLBACK PAD1__about(void) {}
+long CALLBACK PAD1__test(void) { return 0; }
+long CALLBACK PAD1__query(void) { return 3; }
+long CALLBACK PAD1__keypressed() { return 0; }
+
+#define LoadPad1Sym1(dest, name) \
+       LoadSym(PAD1_##dest, PAD##dest, name, TRUE);
+
+#define LoadPad1SymN(dest, name) \
+       LoadSym(PAD1_##dest, PAD##dest, name, FALSE);
+
+#define LoadPad1Sym0(dest, name) \
+       LoadSym(PAD1_##dest, PAD##dest, name, FALSE); \
+       if (PAD1_##dest == NULL) PAD1_##dest = (PAD##dest) PAD1__##dest;
+
+static int LoadPAD1plugin(const char *PAD1dll) {
+       PadDataS padd;
+       void *drv;
+
+       hPAD1Driver = SysLoadLibrary(PAD1dll);
+       if (hPAD1Driver == NULL) {
+               PAD1_configure = NULL;
+               SysMessage (_("Could not load Controller 1 plugin %s!"), PAD1dll); return -1;
+       }
+       drv = hPAD1Driver;
+       LoadPad1Sym1(init, "PADinit");
+       LoadPad1Sym1(shutdown, "PADshutdown");
+       LoadPad1Sym1(open, "PADopen");
+       LoadPad1Sym1(close, "PADclose");
+       LoadPad1Sym0(query, "PADquery");
+       LoadPad1Sym1(readPort1, "PADreadPort1");
+       LoadPad1Sym0(configure, "PADconfigure");
+       LoadPad1Sym0(test, "PADtest");
+       LoadPad1Sym0(about, "PADabout");
+       LoadPad1Sym0(keypressed, "PADkeypressed");
+       LoadPad1Sym0(startPoll, "PADstartPoll");
+       LoadPad1Sym0(poll, "PADpoll");
+       LoadPad1SymN(setSensitive, "PADsetSensitive");
+
+       padd.requestPadIndex = 0;
+       PAD1_readPort1(&padd);
+       multitap1 = padd.portMultitap;
+
+       return 0;
+}
+
+unsigned char CALLBACK PAD2__startPoll(int pad) {
+       int pad_index;
+
+       reqPos = 0;
+       if (multitap1 == 0 && (multitap2 == 0 || multitap2 == 2)) {
+               pad_index = 1;
+       } else if(multitap1 == 1 && (multitap2 == 0 || multitap2 == 2)) {
+               pad_index = 4;
+       } else {
+               pad_index = 0;
+       }
+
+       // just one pad is on port 1 : NO MULTITAP
+       if (multitap2 == 0) {
+               PadDataS padd;
+               padd.requestPadIndex = pad_index;
+               PAD2_readPort2(&padd);
+               _PADstartPoll(&padd);
+       } else {
+               // a multitap is plugged : refresh all pad.
+               int i;
+               PadDataS padd[4];
+               for(i = 0; i < 4; i++) {
+                       padd[i].requestPadIndex = i+pad_index;
+                       PAD2_readPort2(&padd[i]);
+               }
+               _PADstartPollMultitap(padd);
+       }
+       //printf("\npad 2 : ");
+       return 0xff;
+}
+
+unsigned char CALLBACK PAD2__poll(unsigned char value, int *more_data) {
+       char tmp;
+       if (multitap2 == 2) {
+               tmp = PADpollMultitap(1, value, more_data);
+       } else {
+               tmp = PADpoll_(1, value, more_data);
+       }
+       //printf("%2x:%2x, ",value,tmp);
+       return tmp;
+}
+
+long CALLBACK PAD2__configure(void) { return 0; }
+void CALLBACK PAD2__about(void) {}
+long CALLBACK PAD2__test(void) { return 0; }
+long CALLBACK PAD2__query(void) { return PSE_PAD_USE_PORT1 | PSE_PAD_USE_PORT2; }
+long CALLBACK PAD2__keypressed() { return 0; }
+
+#define LoadPad2Sym1(dest, name) \
+       LoadSym(PAD2_##dest, PAD##dest, name, TRUE);
+
+#define LoadPad2Sym0(dest, name) \
+       LoadSym(PAD2_##dest, PAD##dest, name, FALSE); \
+       if (PAD2_##dest == NULL) PAD2_##dest = (PAD##dest) PAD2__##dest;
+
+#define LoadPad2SymN(dest, name) \
+       LoadSym(PAD2_##dest, PAD##dest, name, FALSE);
+
+static int LoadPAD2plugin(const char *PAD2dll) {
+       PadDataS padd;
+       void *drv;
+
+       hPAD2Driver = SysLoadLibrary(PAD2dll);
+       if (hPAD2Driver == NULL) {
+               PAD2_configure = NULL;
+               SysMessage (_("Could not load Controller 2 plugin %s!"), PAD2dll); return -1;
+       }
+       drv = hPAD2Driver;
+       LoadPad2Sym1(init, "PADinit");
+       LoadPad2Sym1(shutdown, "PADshutdown");
+       LoadPad2Sym1(open, "PADopen");
+       LoadPad2Sym1(close, "PADclose");
+       LoadPad2Sym0(query, "PADquery");
+       LoadPad2Sym1(readPort2, "PADreadPort2");
+       LoadPad2Sym0(configure, "PADconfigure");
+       LoadPad2Sym0(test, "PADtest");
+       LoadPad2Sym0(about, "PADabout");
+       LoadPad2Sym0(keypressed, "PADkeypressed");
+       LoadPad2Sym0(startPoll, "PADstartPoll");
+       LoadPad2Sym0(poll, "PADpoll");
+       LoadPad2SymN(setSensitive, "PADsetSensitive");
+
+       padd.requestPadIndex = 0;
+       PAD2_readPort2(&padd);
+       multitap2 = padd.portMultitap;
+
+       return 0;
+}
+
+void *hNETDriver = NULL;
+
+void CALLBACK NET__setInfo(netInfo *info) {}
+void CALLBACK NET__keypressed(int key) {}
+long CALLBACK NET__configure(void) { return 0; }
+long CALLBACK NET__test(void) { return 0; }
+void CALLBACK NET__about(void) {}
+
+#define LoadNetSym1(dest, name) \
+       LoadSym(NET_##dest, NET##dest, name, TRUE);
+
+#define LoadNetSymN(dest, name) \
+       LoadSym(NET_##dest, NET##dest, name, FALSE);
+
+#define LoadNetSym0(dest, name) \
+       LoadSym(NET_##dest, NET##dest, name, FALSE); \
+       if (NET_##dest == NULL) NET_##dest = (NET##dest) NET__##dest;
+
+static int LoadNETplugin(const char *NETdll) {
+       void *drv;
+
+       hNETDriver = SysLoadLibrary(NETdll);
+       if (hNETDriver == NULL) {
+               SysMessage (_("Could not load NetPlay plugin %s!"), NETdll); return -1;
+       }
+       drv = hNETDriver;
+       LoadNetSym1(init, "NETinit");
+       LoadNetSym1(shutdown, "NETshutdown");
+       LoadNetSym1(open, "NETopen");
+       LoadNetSym1(close, "NETclose");
+       LoadNetSymN(sendData, "NETsendData");
+       LoadNetSymN(recvData, "NETrecvData");
+       LoadNetSym1(sendPadData, "NETsendPadData");
+       LoadNetSym1(recvPadData, "NETrecvPadData");
+       LoadNetSym1(queryPlayer, "NETqueryPlayer");
+       LoadNetSym1(pause, "NETpause");
+       LoadNetSym1(resume, "NETresume");
+       LoadNetSym0(setInfo, "NETsetInfo");
+       LoadNetSym0(keypressed, "NETkeypressed");
+       LoadNetSym0(configure, "NETconfigure");
+       LoadNetSym0(test, "NETtest");
+       LoadNetSym0(about, "NETabout");
+
+       return 0;
+}
+
+#ifdef ENABLE_SIO1API
+
+void *hSIO1Driver = NULL;
+
+long CALLBACK SIO1__init(void) { return 0; }
+long CALLBACK SIO1__shutdown(void) { return 0; }
+long CALLBACK SIO1__open(void) { return 0; }
+long CALLBACK SIO1__close(void) { return 0; }
+long CALLBACK SIO1__configure(void) { return 0; }
+long CALLBACK SIO1__test(void) { return 0; }
+void CALLBACK SIO1__about(void) {}
+void CALLBACK SIO1__pause(void) {}
+void CALLBACK SIO1__resume(void) {}
+long CALLBACK SIO1__keypressed(int key) { return 0; }
+void CALLBACK SIO1__writeData8(unsigned char val) {}
+void CALLBACK SIO1__writeData16(unsigned short val) {}
+void CALLBACK SIO1__writeData32(unsigned long val) {}
+void CALLBACK SIO1__writeStat16(unsigned short val) {}
+void CALLBACK SIO1__writeStat32(unsigned long val) {}
+void CALLBACK SIO1__writeMode16(unsigned short val) {}
+void CALLBACK SIO1__writeMode32(unsigned long val) {}
+void CALLBACK SIO1__writeCtrl16(unsigned short val) {}
+void CALLBACK SIO1__writeCtrl32(unsigned long val) {}
+void CALLBACK SIO1__writeBaud16(unsigned short val) {}
+void CALLBACK SIO1__writeBaud32(unsigned long val) {}
+unsigned char CALLBACK SIO1__readData8(void) { return 0; }
+unsigned short CALLBACK SIO1__readData16(void) { return 0; }
+unsigned long CALLBACK SIO1__readData32(void) { return 0; }
+unsigned short CALLBACK SIO1__readStat16(void) { return 0; }
+unsigned long CALLBACK SIO1__readStat32(void) { return 0; }
+unsigned short CALLBACK SIO1__readMode16(void) { return 0; }
+unsigned long CALLBACK SIO1__readMode32(void) { return 0; }
+unsigned short CALLBACK SIO1__readCtrl16(void) { return 0; }
+unsigned long CALLBACK SIO1__readCtrl32(void) { return 0; }
+unsigned short CALLBACK SIO1__readBaud16(void) { return 0; }
+unsigned long CALLBACK SIO1__readBaud32(void) { return 0; }
+void CALLBACK SIO1__registerCallback(void (CALLBACK *callback)(void)) {};
+
+void CALLBACK SIO1irq(void) {
+       psxHu32ref(0x1070) |= SWAPu32(0x100);
+}
+
+#define LoadSio1Sym1(dest, name) \
+       LoadSym(SIO1_##dest, SIO1##dest, name, TRUE);
+
+#define LoadSio1SymN(dest, name) \
+       LoadSym(SIO1_##dest, SIO1##dest, name, FALSE);
+
+#define LoadSio1Sym0(dest, name) \
+       LoadSym(SIO1_##dest, SIO1##dest, name, FALSE); \
+       if (SIO1_##dest == NULL) SIO1_##dest = (SIO1##dest) SIO1__##dest;
+
+static int LoadSIO1plugin(const char *SIO1dll) {
+       void *drv;
+
+       hSIO1Driver = SysLoadLibrary(SIO1dll);
+       if (hSIO1Driver == NULL) {
+               SysMessage (_("Could not load SIO1 plugin %s!"), SIO1dll); return -1;
+       }
+       drv = hSIO1Driver;
+
+       LoadSio1Sym0(init, "SIO1init");
+       LoadSio1Sym0(shutdown, "SIO1shutdown");
+       LoadSio1Sym0(open, "SIO1open");
+       LoadSio1Sym0(close, "SIO1close");
+       LoadSio1Sym0(pause, "SIO1pause");
+       LoadSio1Sym0(resume, "SIO1resume");
+       LoadSio1Sym0(keypressed, "SIO1keypressed");
+       LoadSio1Sym0(configure, "SIO1configure");
+       LoadSio1Sym0(test, "SIO1test");
+       LoadSio1Sym0(about, "SIO1about");
+       LoadSio1Sym0(writeData8, "SIO1writeData8");
+       LoadSio1Sym0(writeData16, "SIO1writeData16");
+       LoadSio1Sym0(writeData32, "SIO1writeData32");
+       LoadSio1Sym0(writeStat16, "SIO1writeStat16");
+       LoadSio1Sym0(writeStat32, "SIO1writeStat32");
+       LoadSio1Sym0(writeMode16, "SIO1writeMode16");
+       LoadSio1Sym0(writeMode32, "SIO1writeMode32");
+       LoadSio1Sym0(writeCtrl16, "SIO1writeCtrl16");
+       LoadSio1Sym0(writeCtrl32, "SIO1writeCtrl32");
+       LoadSio1Sym0(writeBaud16, "SIO1writeBaud16");
+       LoadSio1Sym0(writeBaud32, "SIO1writeBaud32");
+       LoadSio1Sym0(readData16, "SIO1readData16");
+       LoadSio1Sym0(readData32, "SIO1readData32");
+       LoadSio1Sym0(readStat16, "SIO1readStat16");
+       LoadSio1Sym0(readStat32, "SIO1readStat32");
+       LoadSio1Sym0(readMode16, "SIO1readMode16");
+       LoadSio1Sym0(readMode32, "SIO1readMode32");
+       LoadSio1Sym0(readCtrl16, "SIO1readCtrl16");
+       LoadSio1Sym0(readCtrl32, "SIO1readCtrl32");
+       LoadSio1Sym0(readBaud16, "SIO1readBaud16");
+       LoadSio1Sym0(readBaud32, "SIO1readBaud32");
+       LoadSio1Sym0(registerCallback, "SIO1registerCallback");
+
+       return 0;
+}
+
+#endif
+
+int LoadPlugins() {
+       int ret;
+       char Plugin[MAXPATHLEN * 2];
+
+       ReleasePlugins();
+       SysLibError();
+
+       if (UsingIso()) {
+               LoadCDRplugin(NULL);
+       } else {
+               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr);
+               if (LoadCDRplugin(Plugin) == -1) return -1;
+       }
+
+       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Gpu);
+       if (LoadGPUplugin(Plugin) == -1) return -1;
+
+       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Spu);
+       if (LoadSPUplugin(Plugin) == -1) return -1;
+
+       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad1);
+       if (LoadPAD1plugin(Plugin) == -1) return -1;
+
+       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Pad2);
+       if (LoadPAD2plugin(Plugin) == -1) return -1;
+
+       if (strcmp("Disabled", Config.Net) == 0 || strcmp("", Config.Net) == 0)
+               Config.UseNet = FALSE;
+       else {
+               Config.UseNet = TRUE;
+               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Net);
+               if (LoadNETplugin(Plugin) == -1) Config.UseNet = FALSE;
+       }
+
+#ifdef ENABLE_SIO1API
+       sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Sio1);
+       if (LoadSIO1plugin(Plugin) == -1) return -1;
+#endif
+
+       ret = CDR_init();
+       if (ret < 0) { SysMessage (_("Error initializing CD-ROM plugin: %d"), ret); return -1; }
+       ret = GPU_init();
+       if (ret < 0) { SysMessage (_("Error initializing GPU plugin: %d"), ret); return -1; }
+       ret = SPU_init();
+       if (ret < 0) { SysMessage (_("Error initializing SPU plugin: %d"), ret); return -1; }
+       ret = PAD1_init(1);
+       if (ret < 0) { SysMessage (_("Error initializing Controller 1 plugin: %d"), ret); return -1; }
+       ret = PAD2_init(2);
+       if (ret < 0) { SysMessage (_("Error initializing Controller 2 plugin: %d"), ret); return -1; }
+
+       if (Config.UseNet) {
+               ret = NET_init();
+               if (ret < 0) { SysMessage (_("Error initializing NetPlay plugin: %d"), ret); return -1; }
+       }
+
+#ifdef ENABLE_SIO1API
+       ret = SIO1_init();
+       if (ret < 0) { SysMessage (_("Error initializing SIO1 plugin: %d"), ret); return -1; }
+#endif
+
+       SysPrintf(_("Plugins loaded.\n"));
+       return 0;
+}
+
+void ReleasePlugins() {
+       if (Config.UseNet) {
+               int ret = NET_close();
+               if (ret < 0) Config.UseNet = FALSE;
+       }
+       NetOpened = FALSE;
+
+       if (hCDRDriver != NULL || cdrIsoActive()) CDR_shutdown();
+       if (hGPUDriver != NULL) GPU_shutdown();
+       if (hSPUDriver != NULL) SPU_shutdown();
+       if (hPAD1Driver != NULL) PAD1_shutdown();
+       if (hPAD2Driver != NULL) PAD2_shutdown();
+
+       if (Config.UseNet && hNETDriver != NULL) NET_shutdown();
+
+       if (hCDRDriver != NULL) { SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; }
+       if (hGPUDriver != NULL) { SysCloseLibrary(hGPUDriver); hGPUDriver = NULL; }
+       if (hSPUDriver != NULL) { SysCloseLibrary(hSPUDriver); hSPUDriver = NULL; }
+       if (hPAD1Driver != NULL) { SysCloseLibrary(hPAD1Driver); hPAD1Driver = NULL; }
+       if (hPAD2Driver != NULL) { SysCloseLibrary(hPAD2Driver); hPAD2Driver = NULL; }
+
+       if (Config.UseNet && hNETDriver != NULL) {
+               SysCloseLibrary(hNETDriver); hNETDriver = NULL;
+       }
+
+#ifdef ENABLE_SIO1API
+       if (hSIO1Driver != NULL) {
+               SIO1_shutdown();
+               SysCloseLibrary(hSIO1Driver);
+               hSIO1Driver = NULL;
+       }
+#endif
+}
+
+// for CD swap
+int ReloadCdromPlugin()
+{
+       if (hCDRDriver != NULL || cdrIsoActive()) CDR_shutdown();
+       if (hCDRDriver != NULL) { SysCloseLibrary(hCDRDriver); hCDRDriver = NULL; }
+
+       if (UsingIso()) {
+               LoadCDRplugin(NULL);
+       } else {
+               char Plugin[MAXPATHLEN * 2];
+               sprintf(Plugin, "%s/%s", Config.PluginsDir, Config.Cdr);
+               if (LoadCDRplugin(Plugin) == -1) return -1;
+       }
+
+       return CDR_init();
+}
+
+void SetIsoFile(const char *filename) {
+       if (filename == NULL) {
+               IsoFile[0] = '\0';
+               return;
+       }
+       strncpy(IsoFile, filename, MAXPATHLEN - 1);
+}
+
+const char *GetIsoFile(void) {
+       return IsoFile;
+}
+
+boolean UsingIso(void) {
+       return (IsoFile[0] != '\0');
+}
+
+void SetCdOpenCaseTime(s64 time) {
+       cdOpenCaseTime = time;
+}
index f74489f..c5140cc 100644 (file)
@@ -216,7 +216,7 @@ typedef long (CALLBACK* PADreadPort1)(PadDataS*);
 typedef long (CALLBACK* PADreadPort2)(PadDataS*);\r
 typedef long (CALLBACK* PADkeypressed)(void);\r
 typedef unsigned char (CALLBACK* PADstartPoll)(int);\r
-typedef unsigned char (CALLBACK* PADpoll)(unsigned char);\r
+typedef unsigned char (CALLBACK* PADpoll)(unsigned char, int *);\r
 typedef void (CALLBACK* PADsetSensitive)(int);\r
 \r
 // PAD function pointers\r
@@ -379,6 +379,9 @@ const char *GetIsoFile(void);
 boolean UsingIso(void);\r
 void SetCdOpenCaseTime(s64 time);\r
 \r
+extern void pl_gun_byte2(int port, unsigned char byte);\r
+extern void plat_trigger_vibrate(int pad, int low, int high);\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif\r
index c5a439d..88f994f 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2019 Ryan Schultz, PCSX-df Team, PCSX team, gameblabla, *
- *      dmitrysmagin, senquack                                                                                            *
+ *   dmitrysmagin, senquack                                                *
  *                                                                         *
  *   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  *
@@ -3774,18 +3774,12 @@ void psxBiosCnfLoaded(u32 tcb_cnt, u32 evcb_cnt, u32 stack) {
 }
 
 #define psxBios_PADpoll(pad) { \
-       PAD##pad##_startPoll(pad); \
-       pad_buf##pad[0] = 0; \
-       pad_buf##pad[1] = PAD##pad##_poll(0x42); \
-       if (!(pad_buf##pad[1] & 0x0f)) { \
-               bufcount = 32; \
-       } else { \
-               bufcount = (pad_buf##pad[1] & 0x0f) * 2; \
-       } \
-       PAD##pad##_poll(0); \
+       int i, more_data = 0; \
+       pad_buf##pad[0] = PAD##pad##_startPoll(pad); \
+       pad_buf##pad[1] = PAD##pad##_poll(0x42, &more_data); \
        i = 2; \
-       while (bufcount--) { \
-               pad_buf##pad[i++] = PAD##pad##_poll(0); \
+       while (more_data) { \
+               pad_buf##pad[i++] = PAD##pad##_poll(0, &more_data); \
        } \
 }
 
@@ -3970,7 +3964,6 @@ void hleExcPadCard1(void)
        if (loadRam32(A_PAD_IRQR_ENA)) {
                u8 *pad_buf1 = loadRam8ptr(A_PAD_INBUF + 0);
                u8 *pad_buf2 = loadRam8ptr(A_PAD_INBUF + 4);
-               int i, bufcount;
 
                psxBios_PADpoll(1);
                psxBios_PADpoll(2);
index 7aa669b..ab6baa1 100644 (file)
@@ -84,60 +84,43 @@ char McdDisable[2];
 #define SIO_CYCLES             535
 
 void sioWrite8(unsigned char value) {
-#ifdef PAD_LOG
-       PAD_LOG("sio write8 %x\n", value);
+       int more_data = 0;
+#if 0
+       s32 framec = psxRegs.cycle - rcnts[3].cycleStart;
+       printf("%d:%03d sio write8 %04x %02x\n", frame_counter,
+               (s32)(framec / (PSXCLK / 60 / 263.0f)), CtrlReg, value);
 #endif
        switch (padst) {
-               case 1: SIO_INT(SIO_CYCLES);
+               case 1:
                        if ((value & 0x40) == 0x40) {
                                padst = 2; parp = 1;
-                               if (!Config.UseNet) {
-                                       switch (CtrlReg & 0x2002) {
-                                               case 0x0002:
-                                                       buf[parp] = PAD1_poll(value);
-                                                       break;
-                                               case 0x2002:
-                                                       buf[parp] = PAD2_poll(value);
-                                                       break;
-                                       }
-                               }/* else {
-//                                     SysPrintf("%x: %x, %x, %x, %x\n", CtrlReg&0x2002, buf[2], buf[3], buf[4], buf[5]);
-                               }*/
-
-                               if (!(buf[parp] & 0x0f)) {
-                                       bufcount = 2 + 32;
-                               } else {
-                                       bufcount = 2 + (buf[parp] & 0x0f) * 2;
+                               switch (CtrlReg & 0x2002) {
+                                       case 0x0002:
+                                               buf[parp] = PAD1_poll(value, &more_data);
+                                               break;
+                                       case 0x2002:
+                                               buf[parp] = PAD2_poll(value, &more_data);
+                                               break;
                                }
-                               if (buf[parp] == 0x41) {
-                                       switch (value) {
-                                               case 0x43:
-                                                       buf[1] = 0x43;
-                                                       break;
-                                               case 0x45:
-                                                       buf[1] = 0xf3;
-                                                       break;
-                                       }
+
+                               if (more_data) {
+                                       bufcount = parp + 1;
+                                       SIO_INT(SIO_CYCLES);
                                }
                        }
                        else padst = 0;
                        return;
                case 2:
                        parp++;
-/*                     if (buf[1] == 0x45) {
-                               buf[parp] = 0;
-                               SIO_INT(SIO_CYCLES);
-                               return;
-                       }*/
-                       if (!Config.UseNet) {
-                               switch (CtrlReg & 0x2002) {
-                                       case 0x0002: buf[parp] = PAD1_poll(value); break;
-                                       case 0x2002: buf[parp] = PAD2_poll(value); break;
-                               }
+                       switch (CtrlReg & 0x2002) {
+                               case 0x0002: buf[parp] = PAD1_poll(value, &more_data); break;
+                               case 0x2002: buf[parp] = PAD2_poll(value, &more_data); break;
                        }
 
-                       if (parp == bufcount) { padst = 0; return; }
-                       SIO_INT(SIO_CYCLES);
+                       if (more_data) {
+                               bufcount = parp + 1;
+                               SIO_INT(SIO_CYCLES);
+                       }
                        return;
        }
 
@@ -227,44 +210,11 @@ void sioWrite8(unsigned char value) {
                case 0x01: // start pad
                        StatReg |= RX_RDY;              // Transfer is Ready
 
-                       if (!Config.UseNet) {
-                               switch (CtrlReg & 0x2002) {
-                                       case 0x0002: buf[0] = PAD1_startPoll(1); break;
-                                       case 0x2002: buf[0] = PAD2_startPoll(2); break;
-                               }
-                       } else {
-                               if ((CtrlReg & 0x2002) == 0x0002) {
-                                       int i, j;
-
-                                       PAD1_startPoll(1);
-                                       buf[0] = 0;
-                                       buf[1] = PAD1_poll(0x42);
-                                       if (!(buf[1] & 0x0f)) {
-                                               bufcount = 32;
-                                       } else {
-                                               bufcount = (buf[1] & 0x0f) * 2;
-                                       }
-                                       buf[2] = PAD1_poll(0);
-                                       i = 3;
-                                       j = bufcount;
-                                       while (j--) {
-                                               buf[i++] = PAD1_poll(0);
-                                       }
-                                       bufcount+= 3;
-
-                                       if (NET_sendPadData(buf, bufcount) == -1)
-                                               netError();
-
-                                       if (NET_recvPadData(buf, 1) == -1)
-                                               netError();
-                                       if (NET_recvPadData(buf + 128, 2) == -1)
-                                               netError();
-                               } else {
-                                       memcpy(buf, buf + 128, 32);
-                               }
+                       switch (CtrlReg & 0x2002) {
+                               case 0x0002: buf[0] = PAD1_startPoll(1); break;
+                               case 0x2002: buf[0] = PAD2_startPoll(2); break;
                        }
-
-                       bufcount = 2;
+                       bufcount = 1;
                        parp = 0;
                        padst = 1;
                        SIO_INT(SIO_CYCLES);
@@ -351,8 +301,10 @@ unsigned char sioRead8() {
                }
        }
 
-#ifdef PAD_LOG
-       PAD_LOG("sio read8 ;ret = %x\n", ret);
+#if 0
+       s32 framec = psxRegs.cycle - rcnts[3].cycleStart;
+       printf("%d:%03d sio read8  %04x %02x\n", frame_counter,
+               (s32)((float)framec / (PSXCLK / 60 / 263.0f)), CtrlReg, ret);
 #endif
        return ret;
 }
index 7e9cd9f..81af5d8 100644 (file)
@@ -13,7 +13,6 @@
 #include "../include/psemu_plugin_defs.h"
 #include "../libpcsxcore/cdrom.h"
 #include "../libpcsxcore/cdriso.h"
-#include "../plugins/dfinput/main.h"
 #include "../frontend/libpicofe/readpng.h"
 #include "maemo_common.h"
 #include <libosso.h>
index 77dbcd6..44fec65 100644 (file)
@@ -17,7 +17,6 @@
 #include "../libpcsxcore/misc.h"
 #include "../libpcsxcore/cdriso.h"
 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
-#include "../plugins/dfinput/main.h"
 #include "../plugins/dfsound/spu_config.h"
 #include "maemo_common.h"
 
@@ -393,7 +392,6 @@ int main(int argc, char **argv)
        if (Config.HLE)
                printf("Note: running without BIOS, expect compatibility problems\n");
 
-       dfinput_activate();
        pl_timing_prepare(Config.PsxType);
 
        while (1)
diff --git a/plugins/dfinput/externals.h b/plugins/dfinput/externals.h
deleted file mode 100644 (file)
index 2e216fd..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __P_EXTERNALS_H__
-#define __P_EXTERNALS_H__
-
-void dfinput_activate(void);
-
-/* get gunstate from emu frontend,
- * xn, yn - layer position normalized to 0..1023 */
-#define GUNIN_TRIGGER  (1<<0)
-#define GUNIN_BTNA     (1<<1)
-#define GUNIN_BTNB     (1<<2)
-#define GUNIN_TRIGGER2 (1<<3)  /* offscreen trigger */
-extern void pl_update_gun(int *xn, int *yn, int *xres, int *yres, int *in);
-
-/* vibration trigger to frontend */
-extern int in_enable_vibration;
-extern void plat_trigger_vibrate(int pad, int low, int high);
-
-#endif /* __P_EXTERNALS_H__ */
diff --git a/plugins/dfinput/guncon.c b/plugins/dfinput/guncon.c
deleted file mode 100644 (file)
index 981a757..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2011
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include <string.h>
-#include "main.h"
-
-static unsigned char buf[8];
-
-unsigned char PADpoll_guncon(unsigned char value)
-{
-       if (CurByte == 0) {
-               CurCmd = value;
-               CurByte++;
-               return 0x63;    // regardless of cmd
-       }
-
-       if (CurCmd != 0x42 || CurByte >= 8)
-               return 0xff;    // verified
-
-       return buf[CurByte++];
-}
-
-unsigned char PADstartPoll_guncon(int pad)
-{
-       int x, y, xn = 0, yn = 0, in = 0, xres = 256, yres = 240;
-       CurByte = 0;
-
-       buf[2] = buf[3] = 0xff;
-       pl_update_gun(&xn, &yn, &xres, &yres, &in);
-
-       // while y = const + line counter, what is x?
-       // for 256 mode, hw dumped offsets x, y: 0x5a, 0x20
-       //x = 0x5a + (356 * xn >> 10);
-       x = 0x5a - (xres - 256) / 3 + (((xres - 256) / 3 + 356) * xn >> 10);
-       y = 0x20 + (yres * yn >> 10);
-
-       if (in & GUNIN_TRIGGER)
-               buf[3] &= ~0x20;
-       if (in & GUNIN_BTNA)
-               buf[2] &= ~0x08;
-       if (in & GUNIN_BTNB)
-               buf[3] &= ~0x40;
-       if (in & GUNIN_TRIGGER2) {
-               buf[3] &= ~0x20;
-               x = 1;
-               y = 10;
-       }
-       buf[4] = x;
-       buf[5] = x >> 8;
-       buf[6] = y;
-       buf[7] = y >> 8;
-
-       return 0xff;
-}
-
-void guncon_init(void)
-{
-       memset(buf, 0xff, sizeof(buf));
-       buf[1] = 0x5a;
-}
-
diff --git a/plugins/dfinput/main.c b/plugins/dfinput/main.c
deleted file mode 100644 (file)
index 4f1d03f..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * (C) Gražvydas "notaz" Ignotas, 2011
- *
- * This work is licensed under the terms of any of these licenses
- * (at your option):
- *  - GNU GPL, version 2 or later.
- *  - GNU LGPL, version 2.1 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include "main.h"
-
-unsigned char CurPad, CurByte, CurCmd, CmdLen;
-
-/* since this is not a proper plugin, so we'll hook emu internals in a hackish way like this */
-extern void *PAD1_startPoll, *PAD1_poll;
-extern void *PAD2_startPoll, *PAD2_poll;
-extern unsigned char CALLBACK PAD1__startPoll(int pad);
-extern unsigned char CALLBACK PAD2__startPoll(int pad);
-extern unsigned char CALLBACK PAD1__poll(unsigned char value);
-extern unsigned char CALLBACK PAD2__poll(unsigned char value);
-
-#ifndef HAVE_LIBRETRO
-
-static int old_controller_type1 = -1, old_controller_type2 = -1;
-
-#define select_pad(n) \
-       if (pad.controllerType != old_controller_type##n) \
-       { \
-               switch (pad.controllerType) \
-               { \
-               case PSE_PAD_TYPE_ANALOGPAD: \
-                       PAD##n##_startPoll = PADstartPoll_pad; \
-                       PAD##n##_poll = PADpoll_pad; \
-                       pad_init(); \
-                       break; \
-               case PSE_PAD_TYPE_GUNCON: \
-                       PAD##n##_startPoll = PADstartPoll_guncon; \
-                       PAD##n##_poll = PADpoll_guncon; \
-                       guncon_init(); \
-                       break; \
-               case PSE_PAD_TYPE_NEGCON: \
-               case PSE_PAD_TYPE_GUN: \
-               default: \
-                       PAD##n##_startPoll = PAD##n##__startPoll; \
-                       PAD##n##_poll = PAD##n##__poll; \
-                       break; \
-               } \
-       }
-
-void dfinput_activate(void)
-{
-       PadDataS pad;
-
-       pad.portMultitap = -1;
-       pad.requestPadIndex = 0;
-       PAD1_readPort1(&pad);
-       select_pad(1);
-
-       pad.requestPadIndex = 1;
-       PAD2_readPort2(&pad);
-       select_pad(2);
-}
-
-#else // use libretro's libpcsxcore/plugins.c code
-
-void dfinput_activate(void)
-{
-}
-
-#endif
diff --git a/plugins/dfinput/main.h b/plugins/dfinput/main.h
deleted file mode 100644 (file)
index 96cebfa..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef __P_MAIN_H__
-#define __P_MAIN_H__
-
-#include "psemu_plugin_defs.h"
-#include "externals.h"
-
-extern unsigned char CurPad, CurByte, CurCmd, CmdLen;
-
-/* analog pad */
-unsigned char PADpoll_pad(unsigned char value);
-unsigned char PADstartPoll_pad(int pad);
-void pad_init(void);
-
-/* GunCon */
-unsigned char PADpoll_guncon(unsigned char value);
-unsigned char PADstartPoll_guncon(int pad);
-void guncon_init(void);
-
-/* get button state and pad type from main emu */
-extern long (*PAD1_readPort1)(PadDataS *pad);
-extern long (*PAD2_readPort2)(PadDataS *pad);
-
-#endif /* __P_MAIN_H__ */
diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c
deleted file mode 100644 (file)
index 3e33366..0000000
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Copyright (c) 2009, Wei Mingzhi <whistler@openoffice.org>.
- * All Rights Reserved.
- *
- * 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, see <http://www.gnu.org/licenses>.
- *
- * this is only pure emulation code to handle analogs,
- * extracted from dfinput.
- */
-
-#include <stdint.h>
-
-#include "psemu_plugin_defs.h"
-#include "main.h"
-
-enum {
-       ANALOG_LEFT = 0,
-       ANALOG_RIGHT,
-
-       ANALOG_TOTAL
-};
-
-enum {
-       CMD_READ_DATA_AND_VIBRATE = 0x42,
-       CMD_CONFIG_MODE = 0x43,
-       CMD_SET_MODE_AND_LOCK = 0x44,
-       CMD_QUERY_MODEL_AND_MODE = 0x45,
-       CMD_QUERY_ACT = 0x46, // ??
-       CMD_QUERY_COMB = 0x47, // ??
-       CMD_QUERY_MODE = 0x4C, // QUERY_MODE ??
-       CMD_VIBRATION_TOGGLE = 0x4D,
-};
-
-#ifndef HAVE_LIBRETRO
-static struct {
-       uint8_t PadMode;
-       uint8_t PadID;
-       uint8_t ConfigMode;
-       PadDataS pad;
-} padstate[2];
-
-static uint8_t stdpar[2][8] = {
-       {0xFF, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80},
-       {0xFF, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80}
-};
-
-static uint8_t unk46[2][8] = {
-       {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
-       {0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}
-};
-
-static uint8_t unk47[2][8] = {
-       {0xFF, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00},
-       {0xFF, 0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}
-};
-
-static uint8_t unk4c[2][8] = {
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-};
-
-static uint8_t unk4d[2][8] = { 
-       {0xFF, 0x5A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
-       {0xFF, 0x5A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
-};
-
-static uint8_t stdcfg[2][8]   = { 
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-};
-
-static uint8_t stdmode[2][8]  = { 
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-       {0xFF, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-};
-
-static uint8_t stdmodel[2][8] = { 
-       {0xFF,
-        0x5A,
-        0x01, // 03 - dualshock2, 01 - dualshock
-        0x02, // number of modes
-        0x01, // current mode: 01 - analog, 00 - digital
-        0x02,
-        0x01,
-        0x00},
-       {0xFF, 
-        0x5A,
-        0x01, // 03 - dualshock2, 01 - dualshock
-        0x02, // number of modes
-        0x01, // current mode: 01 - analog, 00 - digital
-        0x02,
-        0x01,
-        0x00}
-};
-
-static uint8_t *buf;
-
-static uint8_t do_cmd(void)
-{
-       PadDataS *pad = &padstate[CurPad].pad;
-       int pad_num = CurPad;
-
-       CmdLen = 8;
-       switch (CurCmd) {
-               case CMD_SET_MODE_AND_LOCK:
-                       buf = stdmode[pad_num];
-                       return 0xF3;
-
-               case CMD_QUERY_MODEL_AND_MODE:
-                       buf = stdmodel[pad_num];
-                       buf[4] = padstate[pad_num].PadMode;
-                       return 0xF3;
-
-               case CMD_QUERY_ACT:
-                       buf = unk46[pad_num];
-                       return 0xF3;
-
-               case CMD_QUERY_COMB:
-                       buf = unk47[pad_num];
-                       return 0xF3;
-
-               case CMD_QUERY_MODE:
-                       buf = unk4c[pad_num];
-                       return 0xF3;
-
-               case CMD_VIBRATION_TOGGLE:
-                       buf = unk4d[pad_num];
-                       return 0xF3;
-
-               case CMD_CONFIG_MODE:
-                       if (padstate[pad_num].ConfigMode) {
-                               buf = stdcfg[pad_num];
-                               return 0xF3;
-                       }
-                       // else FALLTHROUGH
-
-               case CMD_READ_DATA_AND_VIBRATE:
-               default:
-                       buf = stdpar[pad_num];
-
-                       buf[2] = pad->buttonStatus;
-                       buf[3] = pad->buttonStatus >> 8;
-
-                       if (padstate[pad_num].PadMode == 1) {
-                               buf[4] = pad->rightJoyX;
-                               buf[5] = pad->rightJoyY;
-                               buf[6] = pad->leftJoyX;
-                               buf[7] = pad->leftJoyY;
-                       } else {
-                               CmdLen = 4;
-                       }
-
-                       return padstate[pad_num].PadID;
-       }
-}
-
-static void do_cmd2(unsigned char value)
-{
-       switch (CurCmd) {
-               case CMD_CONFIG_MODE:
-                       padstate[CurPad].ConfigMode = value;
-                       break;
-
-               case CMD_SET_MODE_AND_LOCK:
-                       padstate[CurPad].PadMode = value;
-                       padstate[CurPad].PadID = value ? 0x73 : 0x41;
-                       break;
-
-               case CMD_QUERY_ACT:
-                       switch (value) {
-                               case 0: // default
-                                       buf[5] = 0x02;
-                                       buf[6] = 0x00;
-                                       buf[7] = 0x0A;
-                                       break;
-
-                               case 1: // Param std conf change
-                                       buf[5] = 0x01;
-                                       buf[6] = 0x01;
-                                       buf[7] = 0x14;
-                                       break;
-                       }
-                       break;
-
-               case CMD_QUERY_MODE:
-                       switch (value) {
-                               case 0: // mode 0 - digital mode
-                                       buf[5] = PSE_PAD_TYPE_STANDARD;
-                                       break;
-
-                               case 1: // mode 1 - analog mode
-                                       buf[5] = PSE_PAD_TYPE_ANALOGPAD;
-                                       break;
-                       }
-                       break;
-       }
-}
-
-static void do_vibration(unsigned char value)
-{
-    int changed = 0;
-    int i;
-
-    switch (CurCmd) {
-        case CMD_READ_DATA_AND_VIBRATE:
-            for (i = 0; i < 2; i++) {
-                if (padstate[CurPad].pad.Vib[i] == CurByte
-                     && padstate[CurPad].pad.VibF[i] != value) {
-                    padstate[CurPad].pad.VibF[i] = value;
-                    changed = 1;
-                }
-            }
-
-            if (!in_enable_vibration || !changed)
-                break;
-
-            plat_trigger_vibrate(CurPad,
-                                 padstate[CurPad].pad.VibF[0],
-                                 padstate[CurPad].pad.VibF[1]);
-            break;
-        case CMD_VIBRATION_TOGGLE:
-            for (i = 0; i < 2; i++) {
-                if (padstate[CurPad].pad.Vib[i] == CurByte)
-                    buf[CurByte] = 0;
-            }
-            if (value < 2) {
-                padstate[CurPad].pad.Vib[value] = CurByte;
-                if((padstate[CurPad].PadID & 0x0f) < (CurByte - 1) / 2) {
-                    padstate[CurPad].PadID = (padstate[CurPad].PadID & 0xf0) + (CurByte - 1) / 2;
-                }
-            }
-            break;
-    }
-}
-#endif
-
-#if 0
-#include <stdio.h>
-unsigned char PADpoll_(unsigned char value);
-unsigned char PADpoll(unsigned char value) {
-       unsigned char b = CurByte, r = PADpoll_(value);
-       printf("poll[%d] %02x %02x\n", b, value, r);
-       return r;
-}
-#define PADpoll PADpoll_
-#endif
-
-#ifndef HAVE_LIBRETRO
-unsigned char PADpoll_pad(unsigned char value) {
-       if (CurByte == 0) {
-               CurCmd = value;
-               CurByte++;
-
-               // Don't enable Analog/Vibration for a standard pad
-               if (padstate[CurPad].pad.controllerType != PSE_PAD_TYPE_ANALOGPAD)
-                       CurCmd = CMD_READ_DATA_AND_VIBRATE;
-
-               return do_cmd();
-       }
-
-       if (CurByte >= CmdLen)
-               return 0xff;    // verified
-
-       if (CurByte == 2)
-               do_cmd2(value);
-
-       if (padstate[CurPad].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD)
-               do_vibration(value);
-
-       return buf[CurByte++];
-}
-
-unsigned char PADstartPoll_pad(int pad) {
-       CurPad = pad - 1;
-       CurByte = 0;
-
-       if (pad == 1)
-               PAD1_readPort1(&padstate[0].pad);
-       else
-               PAD2_readPort2(&padstate[1].pad);
-
-       return 0xFF;
-}
-
-void pad_init(void)
-{
-       int i;
-
-       PAD1_readPort1(&padstate[0].pad);
-       PAD2_readPort2(&padstate[1].pad);
-
-       for (i = 0; i < 2; i++) {
-               padstate[i].PadID = padstate[i].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD ? 0x73 : 0x41;
-               padstate[i].PadMode = padstate[i].pad.controllerType == PSE_PAD_TYPE_ANALOGPAD;
-       }
-}
-#endif