4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
12 #include "plugin_lib.h"
14 #include "../libpcsxcore/psemu_plugin_defs.h"
15 #include "../libpcsxcore/system.h"
16 #include "../plugins/cdrcimg/cdrcimg.h"
18 static int dummy_func() {
23 extern long SPUopen(void);
24 extern long SPUinit(void);
25 extern long SPUshutdown(void);
26 extern long SPUclose(void);
27 extern void SPUplaySample(unsigned char);
28 extern void SPUwriteRegister(unsigned long, unsigned short);
29 extern unsigned short SPUreadRegister(unsigned long);
30 extern void SPUwriteDMA(unsigned short);
31 extern unsigned short SPUreadDMA(void);
32 extern void SPUwriteDMAMem(unsigned short *, int);
33 extern void SPUreadDMAMem(unsigned short *, int);
34 extern void SPUplayADPCMchannel(void *);
35 extern void SPUregisterCallback(void (*callback)(void));
36 extern long SPUconfigure(void);
37 extern long SPUtest(void);
38 extern void SPUabout(void);
39 extern long SPUfreeze(unsigned int, void *);
40 extern void SPUasync(unsigned int);
41 extern void SPUplayCDDAchannel(short *, int);
44 static long PADreadPort1(PadDataS *pad)
46 pad->controllerType = in_type;
47 pad->buttonStatus = ~in_keystate;
48 if (in_type == PSE_PAD_TYPE_ANALOGPAD) {
49 pad->leftJoyX = in_a1[0];
50 pad->leftJoyY = in_a1[1];
51 pad->rightJoyX = in_a2[0];
52 pad->rightJoyY = in_a2[1];
57 static long PADreadPort2(PadDataS *pad)
59 pad->controllerType = PSE_PAD_TYPE_STANDARD;
60 pad->buttonStatus = ~in_keystate >> 16;
65 extern long GPUopen(unsigned long *, char *, char *);
66 extern long GPUinit(void);
67 extern long GPUshutdown(void);
68 extern long GPUclose(void);
69 extern void GPUwriteStatus(uint32_t);
70 extern void GPUwriteData(uint32_t);
71 extern void GPUwriteDataMem(uint32_t *, int);
72 extern uint32_t GPUreadStatus(void);
73 extern uint32_t GPUreadData(void);
74 extern void GPUreadDataMem(uint32_t *, int);
75 extern long GPUdmaChain(uint32_t *,uint32_t);
76 extern void GPUupdateLace(void);
77 extern long GPUfreeze(uint32_t, void *);
80 #define DUMMY(id, name) \
81 { id, #name, dummy_func }
83 #define DIRECT(id, name) \
86 #define DUMMY_GPU(name) DUMMY(PLUGIN_GPU, name)
87 #define DUMMY_CDR(name) DUMMY(PLUGIN_CDR, name)
88 #define DUMMY_PAD(name) DUMMY(PLUGIN_PAD, name)
89 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
90 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
91 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
100 DUMMY_CDR(CDRshutdown),
106 DUMMY_CDR(CDRreadTrack),
107 DUMMY_CDR(CDRgetBuffer),
108 DUMMY_CDR(CDRgetBufferSub),
111 DUMMY_CDR(CDRgetStatus),
112 DUMMY_CDR(CDRgetDriveLetter),
113 DUMMY_CDR(CDRconfigure),
115 DUMMY_CDR(CDRsetfilename),
116 DUMMY_CDR(CDRreadCDDA),
119 DIRECT_SPU(SPUconfigure),
120 DIRECT_SPU(SPUabout),
122 DIRECT_SPU(SPUshutdown),
125 DIRECT_SPU(SPUclose),
126 // DIRECT_SPU(SPUplaySample), // unused?
127 DIRECT_SPU(SPUwriteRegister),
128 DIRECT_SPU(SPUreadRegister),
129 DIRECT_SPU(SPUwriteDMA),
130 DIRECT_SPU(SPUreadDMA),
131 DIRECT_SPU(SPUwriteDMAMem),
132 DIRECT_SPU(SPUreadDMAMem),
133 DIRECT_SPU(SPUplayADPCMchannel),
134 DIRECT_SPU(SPUfreeze),
135 DIRECT_SPU(SPUregisterCallback),
136 DIRECT_SPU(SPUasync),
137 DIRECT_SPU(SPUplayCDDAchannel),
140 DUMMY_PAD(PADshutdown),
143 DUMMY_PAD(PADsetSensitive),
144 DIRECT_PAD(PADreadPort1),
145 DIRECT_PAD(PADreadPort2),
148 DUMMY_PAD(PADconfigure),
151 DUMMY_PAD(PADkeypressed),
152 DUMMY_PAD(PADstartPoll),
156 DIRECT_GPU(GPUupdateLace),
158 DIRECT_GPU(GPUshutdown),
160 DIRECT_GPU(GPUclose),
161 DIRECT_GPU(GPUreadStatus),
162 DIRECT_GPU(GPUreadData),
163 DIRECT_GPU(GPUreadDataMem),
164 DIRECT_GPU(GPUwriteStatus),
165 DIRECT_GPU(GPUwriteData),
166 DIRECT_GPU(GPUwriteDataMem),
167 DIRECT_GPU(GPUdmaChain),
168 DIRECT_GPU(GPUfreeze),
170 DUMMY_GPU(GPUdisplayText),
172 DIRECT_GPU(GPUkeypressed),
173 DIRECT_GPU(GPUmakeSnapshot),
174 DIRECT_GPU(GPUconfigure),
176 DIRECT_GPU(GPUabout),
177 DIRECT_GPU(GPUgetScreenPic),
178 DIRECT_GPU(GPUshowScreenPic),
180 // DIRECT_GPU(GPUclearDynarec),
181 // DIRECT_GPU(GPUvBlank),
184 void *plugin_link(enum builtint_plugins_e id, const char *sym)
188 if (id == PLUGIN_CDRCIMG)
189 return cdrcimg_get_sym(sym);
191 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
192 if (id != plugin_funcs[i].id)
195 if (strcmp(sym, plugin_funcs[i].name) != 0)
198 return plugin_funcs[i].func;
201 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
205 void plugin_call_rearmed_cbs(void)
207 extern void *hGPUDriver;
208 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
210 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
211 if (rearmed_set_cbs != NULL)
212 rearmed_set_cbs(&pl_rearmed_cbs);
217 /* basic profile stuff */
220 unsigned int pcounters[PCNT_CNT];
221 unsigned int pcounter_starts[PCNT_CNT];
223 #define pc_hook_func(name, args, pargs, cnt) \
224 extern void (*name) args; \
225 static void (*o_##name) args; \
226 static void w_##name args \
228 unsigned int pc_start = pcnt_get(); \
230 pcounters[cnt] += pcnt_get() - pc_start; \
233 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
234 extern retn (*name) args; \
235 static retn (*o_##name) args; \
236 static retn w_##name args \
239 unsigned int pc_start = pcnt_get(); \
240 ret = o_##name pargs; \
241 pcounters[cnt] += pcnt_get() - pc_start; \
245 pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
246 pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
247 pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
248 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
249 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
250 pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
251 pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
252 pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
254 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1), (a0, a1), PCNT_SPU)
255 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
256 pc_hook_func (SPU_writeDMA, (unsigned short a0), (a0), PCNT_SPU)
257 pc_hook_func_ret(unsigned short,SPU_readDMA, (void), (), PCNT_SPU)
258 pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
259 pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
260 pc_hook_func (SPU_playADPCMchannel, (void *a0), (a0), PCNT_SPU)
261 pc_hook_func (SPU_async, (unsigned int a0), (a0), PCNT_SPU)
262 pc_hook_func (SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), PCNT_SPU)
264 #define hook_it(name) { \
269 void pcnt_hook_plugins(void)
274 hook_it(GPU_writeStatus);
275 hook_it(GPU_writeData);
276 hook_it(GPU_writeDataMem);
277 hook_it(GPU_readStatus);
278 hook_it(GPU_readData);
279 hook_it(GPU_readDataMem);
280 hook_it(GPU_dmaChain);
281 hook_it(GPU_updateLace);
282 hook_it(SPU_writeRegister);
283 hook_it(SPU_readRegister);
284 hook_it(SPU_writeDMA);
285 hook_it(SPU_readDMA);
286 hook_it(SPU_writeDMAMem);
287 hook_it(SPU_readDMAMem);
288 hook_it(SPU_playADPCMchannel);
290 hook_it(SPU_playCDDAchannel);