add guncon support
[pcsx_rearmed.git] / frontend / plugin.c
index d6aca8a..fa4cf21 100644 (file)
@@ -9,17 +9,16 @@
 #include <string.h>
 #include <stdint.h>
 
 #include <string.h>
 #include <stdint.h>
 
+#include "plugin_lib.h"
 #include "plugin.h"
 #include "plugin.h"
+#include "../libpcsxcore/psemu_plugin_defs.h"
+#include "../libpcsxcore/system.h"
+#include "../plugins/cdrcimg/cdrcimg.h"
 
 static int dummy_func() {
        return 0;
 }
 
 
 static int dummy_func() {
        return 0;
 }
 
-static long CDRreadTrack(unsigned char *time) {
-       fprintf(stderr, "CDRreadTrack\n");
-       return -1;
-}
-
 /* SPU */
 extern long SPUopen(void);
 extern long SPUinit(void);
 /* SPU */
 extern long SPUopen(void);
 extern long SPUinit(void);
@@ -42,18 +41,24 @@ extern void SPUasync(unsigned int);
 extern void SPUplayCDDAchannel(short *, int);
 
 /* PAD */
 extern void SPUplayCDDAchannel(short *, int);
 
 /* PAD */
-static uint8_t CurByte;
-
-static unsigned char PADstartPoll(int pad) {
-       CurByte = 0;
-       return 0xFF;
+static long PADreadPort1(PadDataS *pad)
+{
+       pad->controllerType = in_type1;
+       pad->buttonStatus = ~in_keystate;
+       if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) {
+               pad->leftJoyX = in_a1[0];
+               pad->leftJoyY = in_a1[1];
+               pad->rightJoyX = in_a2[0];
+               pad->rightJoyY = in_a2[1];
+       }
+       return 0;
 }
 
 }
 
-static unsigned char PADpoll(unsigned char value) {
-       static uint8_t buf[] = {0x41, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80};
-       if (CurByte >= 4)
-               return 0;
-       return buf[CurByte++];
+static long PADreadPort2(PadDataS *pad)
+{
+       pad->controllerType = in_type2;
+       pad->buttonStatus = ~in_keystate >> 16;
+       return 0;
 }
 
 /* GPU */
 }
 
 /* GPU */
@@ -69,17 +74,9 @@ extern uint32_t GPUreadData(void);
 extern void GPUreadDataMem(uint32_t *, int);
 extern long GPUdmaChain(uint32_t *,uint32_t);
 extern void GPUupdateLace(void);
 extern void GPUreadDataMem(uint32_t *, int);
 extern long GPUdmaChain(uint32_t *,uint32_t);
 extern void GPUupdateLace(void);
-extern long GPUconfigure(void);
-extern long GPUtest(void);
-extern void GPUabout(void);
-extern void GPUmakeSnapshot(void);
-extern void GPUkeypressed(int);
-extern void GPUdisplayText(char *);
 extern long GPUfreeze(uint32_t, void *);
 extern long GPUfreeze(uint32_t, void *);
-extern long GPUgetScreenPic(unsigned char *);
-extern long GPUshowScreenPic(unsigned char *);
-extern void GPUclearDynarec(void (*callback)(void));
-extern void GPUvBlank(int);
+extern void GPUvBlank(int, uint32_t *);
+extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
 
 
 #define DUMMY(id, name) \
 
 
 #define DUMMY(id, name) \
@@ -88,6 +85,7 @@ extern void GPUvBlank(int);
 #define DIRECT(id, name) \
        { id, #name, name }
 
 #define DIRECT(id, name) \
        { id, #name, name }
 
+#define DUMMY_GPU(name)  DUMMY(PLUGIN_GPU, name)
 #define DUMMY_CDR(name)  DUMMY(PLUGIN_CDR, name)
 #define DUMMY_PAD(name)  DUMMY(PLUGIN_PAD, name)
 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
 #define DUMMY_CDR(name)  DUMMY(PLUGIN_CDR, name)
 #define DUMMY_PAD(name)  DUMMY(PLUGIN_PAD, name)
 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
@@ -119,7 +117,6 @@ static const struct {
        DUMMY_CDR(CDRsetfilename),
        DUMMY_CDR(CDRreadCDDA),
        DUMMY_CDR(CDRgetTE),
        DUMMY_CDR(CDRsetfilename),
        DUMMY_CDR(CDRreadCDDA),
        DUMMY_CDR(CDRgetTE),
-       DIRECT(PLUGIN_CDR, CDRreadTrack),
        /* SPU */
        DIRECT_SPU(SPUconfigure),
        DIRECT_SPU(SPUabout),
        /* SPU */
        DIRECT_SPU(SPUconfigure),
        DIRECT_SPU(SPUabout),
@@ -141,27 +138,26 @@ static const struct {
        DIRECT_SPU(SPUasync),
        DIRECT_SPU(SPUplayCDDAchannel),
        /* PAD */
        DIRECT_SPU(SPUasync),
        DIRECT_SPU(SPUplayCDDAchannel),
        /* PAD */
-       DUMMY_PAD(PADconfigure),
-       DUMMY_PAD(PADabout),
        DUMMY_PAD(PADinit),
        DUMMY_PAD(PADshutdown),
        DUMMY_PAD(PADinit),
        DUMMY_PAD(PADshutdown),
-       DUMMY_PAD(PADtest),
        DUMMY_PAD(PADopen),
        DUMMY_PAD(PADclose),
        DUMMY_PAD(PADopen),
        DUMMY_PAD(PADclose),
+       DUMMY_PAD(PADsetSensitive),
+       DIRECT_PAD(PADreadPort1),
+       DIRECT_PAD(PADreadPort2),
+/*
        DUMMY_PAD(PADquery),
        DUMMY_PAD(PADquery),
-       DUMMY_PAD(PADreadPort1),
-       DUMMY_PAD(PADreadPort2),
+       DUMMY_PAD(PADconfigure),
+       DUMMY_PAD(PADtest),
+       DUMMY_PAD(PADabout),
        DUMMY_PAD(PADkeypressed),
        DUMMY_PAD(PADkeypressed),
-       DUMMY_PAD(PADsetSensitive),
-       DIRECT_PAD(PADstartPoll),
-       DIRECT_PAD(PADpoll),
+       DUMMY_PAD(PADstartPoll),
+       DUMMY_PAD(PADpoll),
+*/
        /* GPU */
        DIRECT_GPU(GPUupdateLace),
        DIRECT_GPU(GPUinit),
        DIRECT_GPU(GPUshutdown),
        /* GPU */
        DIRECT_GPU(GPUupdateLace),
        DIRECT_GPU(GPUinit),
        DIRECT_GPU(GPUshutdown),
-       DIRECT_GPU(GPUconfigure),
-       DIRECT_GPU(GPUtest),
-       DIRECT_GPU(GPUabout),
        DIRECT_GPU(GPUopen),
        DIRECT_GPU(GPUclose),
        DIRECT_GPU(GPUreadStatus),
        DIRECT_GPU(GPUopen),
        DIRECT_GPU(GPUclose),
        DIRECT_GPU(GPUreadStatus),
@@ -171,20 +167,30 @@ static const struct {
        DIRECT_GPU(GPUwriteData),
        DIRECT_GPU(GPUwriteDataMem),
        DIRECT_GPU(GPUdmaChain),
        DIRECT_GPU(GPUwriteData),
        DIRECT_GPU(GPUwriteDataMem),
        DIRECT_GPU(GPUdmaChain),
+       DIRECT_GPU(GPUfreeze),
+       DIRECT_GPU(GPUvBlank),
+       DIRECT_GPU(GPUrearmedCallbacks),
+
+       DUMMY_GPU(GPUdisplayText),
+/*
        DIRECT_GPU(GPUkeypressed),
        DIRECT_GPU(GPUkeypressed),
-       DIRECT_GPU(GPUdisplayText),
        DIRECT_GPU(GPUmakeSnapshot),
        DIRECT_GPU(GPUmakeSnapshot),
-       DIRECT_GPU(GPUfreeze),
+       DIRECT_GPU(GPUconfigure),
+       DIRECT_GPU(GPUtest),
+       DIRECT_GPU(GPUabout),
        DIRECT_GPU(GPUgetScreenPic),
        DIRECT_GPU(GPUshowScreenPic),
        DIRECT_GPU(GPUgetScreenPic),
        DIRECT_GPU(GPUshowScreenPic),
+*/
 //     DIRECT_GPU(GPUclearDynarec),
 //     DIRECT_GPU(GPUclearDynarec),
-//     DIRECT_GPU(GPUvBlank),
 };
 
 void *plugin_link(enum builtint_plugins_e id, const char *sym)
 {
        int i;
 
 };
 
 void *plugin_link(enum builtint_plugins_e id, const char *sym)
 {
        int i;
 
+       if (id == PLUGIN_CDRCIMG)
+               return cdrcimg_get_sym(sym);
+
        for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
                if (id != plugin_funcs[i].id)
                        continue;
        for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
                if (id != plugin_funcs[i].id)
                        continue;
@@ -195,10 +201,22 @@ void *plugin_link(enum builtint_plugins_e id, const char *sym)
                return plugin_funcs[i].func;
        }
 
                return plugin_funcs[i].func;
        }
 
-       fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
+       //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
        return NULL;
 }
 
        return NULL;
 }
 
+void plugin_call_rearmed_cbs(void)
+{
+       extern void *hGPUDriver;
+       void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
+
+       rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
+       if (rearmed_set_cbs != NULL)
+               rearmed_set_cbs(&pl_rearmed_cbs);
+}
+
+#ifdef PCNT
+
 /* basic profile stuff */
 #include "pcnt.h"
 
 /* basic profile stuff */
 #include "pcnt.h"
 
@@ -253,6 +271,8 @@ pc_hook_func              (SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), P
 
 void pcnt_hook_plugins(void)
 {
 
 void pcnt_hook_plugins(void)
 {
+       pcnt_init();
+
        hook_it(GPU_writeStatus);
        hook_it(GPU_writeData);
        hook_it(GPU_writeDataMem);
        hook_it(GPU_writeStatus);
        hook_it(GPU_writeData);
        hook_it(GPU_writeDataMem);
@@ -272,3 +292,4 @@ void pcnt_hook_plugins(void)
        hook_it(SPU_playCDDAchannel);
 }
 
        hook_it(SPU_playCDDAchannel);
 }
 
+#endif