From e3b40d1933fd33cb97c1a169e3351efa58cbb578 Mon Sep 17 00:00:00 2001
From: mattmenke <mattmenke@96395faa-99c1-11dd-bbfe-3dabce05a288>
Date: Sun, 29 Mar 2009 06:14:59 +0000
Subject: [PATCH] LilyPad, Plugin APIs:  Slightly changed how multitap API
 additions work.  Now enabling is handled completely by the pad plugin.  If
 anyone ever really feels like adding support for more memcards, can move it
 over to PCSX2 itself.

Also add some documentation to PadApi.h.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@853 96395faa-99c1-11dd-bbfe-3dabce05a288
---
 common/include/PS2Edefs.h        |  8 +++++++-
 common/include/PluginCallbacks.h |  2 ++
 common/include/api/PadApi.h      | 20 ++++++++++++++++----
 plugins/LilyPad/Global.h         |  3 ++-
 plugins/LilyPad/LilyPad.cpp      | 12 ++++++++----
 plugins/LilyPad/LilyPad.def      |  1 +
 6 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/common/include/PS2Edefs.h b/common/include/PS2Edefs.h
index f5825d654a..edee168d9e 100644
--- a/common/include/PS2Edefs.h
+++ b/common/include/PS2Edefs.h
@@ -548,7 +548,9 @@ typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info);
 typedef void (CALLBACK* _PADconfigure)();
 typedef s32  (CALLBACK* _PADtest)();
 typedef void (CALLBACK* _PADabout)();
-typedef int (CALLBACK* _PADfreeze)(int mode, freezeData *data);
+typedef int  (CALLBACK* _PADfreeze)(int mode, freezeData *data);
+typedef s32  (CALLBACK* _PADsetSlot)(u8 port, u8 slot);
+typedef s32  (CALLBACK* _PADqueryMtap)(u8 port);
 
 // SIO
 typedef s32  (CALLBACK* _SIOinit)(u32 port, u32 slot, SIOchangeSlotCB f);
@@ -734,6 +736,8 @@ extern _PADconfigure      PAD1configure;
 extern _PADtest           PAD1test;
 extern _PADabout          PAD1about;
 extern _PADfreeze         PAD1freeze;
+extern _PADsetSlot        PAD1setSlot;
+extern _PADqueryMtap      PAD1queryMtap;
 
 // PAD2
 extern _PADinit           PAD2init;
@@ -751,6 +755,8 @@ extern _PADconfigure      PAD2configure;
 extern _PADtest           PAD2test;
 extern _PADabout          PAD2about;
 extern _PADfreeze         PAD2freeze;
+extern _PADsetSlot        PAD2setSlot;
+extern _PADqueryMtap      PAD2queryMtap;
 
 // SIO[2]
 extern _SIOinit           SIOinit[2][9];
diff --git a/common/include/PluginCallbacks.h b/common/include/PluginCallbacks.h
index 133bd4159a..e7334820ee 100644
--- a/common/include/PluginCallbacks.h
+++ b/common/include/PluginCallbacks.h
@@ -83,6 +83,8 @@ typedef s32  (CALLBACK* _PADfreeze)(u8 mode, freezeData *data);
 typedef void (CALLBACK* _PADconfigure)();
 typedef s32  (CALLBACK* _PADtest)();
 typedef void (CALLBACK* _PADabout)();
+typedef s32  (CALLBACK* _PADsetSlot)(u8 port, u8 slot);
+typedef s32  (CALLBACK* _PADqueryMtap)(u8 port);
 
 // SIO
 typedef s32  (CALLBACK* _SIOinit)(int types, SIOchangeSlotCB f);
diff --git a/common/include/api/PadApi.h b/common/include/api/PadApi.h
index 34eafada87..51b8821721 100644
--- a/common/include/api/PadApi.h
+++ b/common/include/api/PadApi.h
@@ -15,8 +15,8 @@
  *  along with this program; if not, write to the Free Software
  *	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
- 
- 
+
+
 #ifndef __PADAPI_H__
 #define __PADAPI_H__
 
@@ -28,7 +28,7 @@
  *          shadowpcsx2@yahoo.gr,
  *          and florinsasu@hotmail.com
  */
- 
+
 #include "Pcsx2Api.h"
 
 /* PAD plugin API  */
@@ -60,7 +60,19 @@ EXPORT_C_(void) PADupdate(u8 pad);
 
 // Extended functions
 EXPORT_C_(void) PADgsDriverInfo(GSdriverInfo *info);
-EXPORT_C_(s32) PADfreeze(u8 mode, freezeData *data);
+EXPORT_C_(s32)  PADfreeze(u8 mode, freezeData *data);
+
+// Returns 1 if the pad plugin wants a multitap on the specified port.
+// 0 otherwise.
+EXPORT_C_(s32)  PADqueryMtap(u8 port);
+
+// Sets the active pad slot for the specified port.
+// Both numbers are 1-based indices.  Should return 0 if there's no
+// pad on the specified slot.  Even if PADqueryMtap(port) returns 0,
+// should handle this properly for slot != 1, to so PCSX2 can allow
+// Multitap to be enabled/disabled elsewhere.
+EXPORT_C_(s32)  PADsetSlot(u8 port, u8 slot);
+
 EXPORT_C_(void) PADconfigure();
 EXPORT_C_(void) PADabout();
 EXPORT_C_(s32)  PADtest();
diff --git a/plugins/LilyPad/Global.h b/plugins/LilyPad/Global.h
index c1a0eaf6ec..92543f5aae 100644
--- a/plugins/LilyPad/Global.h
+++ b/plugins/LilyPad/Global.h
@@ -63,7 +63,8 @@ EXPORT_C_(u32) PSEgetLibType();
 EXPORT_C_(u32) PSEgetLibVersion();
 EXPORT_C_(void) PADconfigure();
 EXPORT_C_(s32) PADfreeze(int mode, freezeData *data);
-EXPORT_C_(s32) PADsetSlot(int port, int slot);
+EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot);
+EXPORT_C_(s32) PADqueryMtap(u8 port);
 
 #ifdef NO_CRT
 inline void * malloc(size_t size) {
diff --git a/plugins/LilyPad/LilyPad.cpp b/plugins/LilyPad/LilyPad.cpp
index 8233003327..d609d2a266 100644
--- a/plugins/LilyPad/LilyPad.cpp
+++ b/plugins/LilyPad/LilyPad.cpp
@@ -1378,10 +1378,14 @@ extern "C" long _cdecl _ftol2() {
 }
 #endif
 
-s32 CALLBACK PADsetSlot(int port, int slot) {
-	port --;
-	slot --;
-	if ((unsigned int)port > 1 || (unsigned int)slot > 3) return 0;
+s32 CALLBACK PADqueryMtap(u8 port) {
+	return config.multitap[port];
+}
+
+s32 CALLBACK PADsetSlot(u8 port, u8 slot) {
+	port--;
+	slot--;
+	if (port > 1 || slot > 3) return 0;
 	// Even if no pad there, record the slot, as it is the active slot regardless.
 	slots[port] = slot;
 	return pads[port][slot].enabled;
diff --git a/plugins/LilyPad/LilyPad.def b/plugins/LilyPad/LilyPad.def
index 4cb03fd34d..43ea74abed 100644
--- a/plugins/LilyPad/LilyPad.def
+++ b/plugins/LilyPad/LilyPad.def
@@ -21,3 +21,4 @@ EXPORTS
 	PADupdate
 	PADfreeze
 	PADsetSlot
+	PADqueryMtap