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 "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 int SPUplayCDDAchannel(short *, int);
44 static long PADreadPort1(PadDataS *pad)
46 pad->controllerType = in_type1;
47 pad->buttonStatus = ~in_keystate;
48 if (in_type1 == 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 = in_type2;
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 *);
78 extern void GPUvBlank(int, int);
79 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
82 #define DUMMY(id, name) \
83 { id, #name, dummy_func }
85 #define DIRECT(id, name) \
88 #define DUMMY_GPU(name) DUMMY(PLUGIN_GPU, name)
89 #define DUMMY_CDR(name) DUMMY(PLUGIN_CDR, name)
90 #define DUMMY_PAD(name) DUMMY(PLUGIN_PAD, name)
91 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
92 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
93 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
102 DUMMY_CDR(CDRshutdown),
108 DUMMY_CDR(CDRreadTrack),
109 DUMMY_CDR(CDRgetBuffer),
110 DUMMY_CDR(CDRgetBufferSub),
113 DUMMY_CDR(CDRgetStatus),
114 DUMMY_CDR(CDRgetDriveLetter),
115 DUMMY_CDR(CDRconfigure),
117 DUMMY_CDR(CDRsetfilename),
118 DUMMY_CDR(CDRreadCDDA),
121 DIRECT_SPU(SPUconfigure),
122 DIRECT_SPU(SPUabout),
124 DIRECT_SPU(SPUshutdown),
127 DIRECT_SPU(SPUclose),
128 // DIRECT_SPU(SPUplaySample), // unused?
129 DIRECT_SPU(SPUwriteRegister),
130 DIRECT_SPU(SPUreadRegister),
131 DIRECT_SPU(SPUwriteDMA),
132 DIRECT_SPU(SPUreadDMA),
133 DIRECT_SPU(SPUwriteDMAMem),
134 DIRECT_SPU(SPUreadDMAMem),
135 DIRECT_SPU(SPUplayADPCMchannel),
136 DIRECT_SPU(SPUfreeze),
137 DIRECT_SPU(SPUregisterCallback),
138 DIRECT_SPU(SPUasync),
139 DIRECT_SPU(SPUplayCDDAchannel),
142 DUMMY_PAD(PADshutdown),
145 DUMMY_PAD(PADsetSensitive),
146 DIRECT_PAD(PADreadPort1),
147 DIRECT_PAD(PADreadPort2),
150 DUMMY_PAD(PADconfigure),
153 DUMMY_PAD(PADkeypressed),
154 DUMMY_PAD(PADstartPoll),
158 DIRECT_GPU(GPUupdateLace),
160 DIRECT_GPU(GPUshutdown),
162 DIRECT_GPU(GPUclose),
163 DIRECT_GPU(GPUreadStatus),
164 DIRECT_GPU(GPUreadData),
165 DIRECT_GPU(GPUreadDataMem),
166 DIRECT_GPU(GPUwriteStatus),
167 DIRECT_GPU(GPUwriteData),
168 DIRECT_GPU(GPUwriteDataMem),
169 DIRECT_GPU(GPUdmaChain),
170 DIRECT_GPU(GPUfreeze),
171 DIRECT_GPU(GPUvBlank),
172 DIRECT_GPU(GPUrearmedCallbacks),
174 DUMMY_GPU(GPUdisplayText),
176 DIRECT_GPU(GPUkeypressed),
177 DIRECT_GPU(GPUmakeSnapshot),
178 DIRECT_GPU(GPUconfigure),
180 DIRECT_GPU(GPUabout),
181 DIRECT_GPU(GPUgetScreenPic),
182 DIRECT_GPU(GPUshowScreenPic),
184 // DIRECT_GPU(GPUclearDynarec),
187 void *plugin_link(enum builtint_plugins_e id, const char *sym)
191 if (id == PLUGIN_CDRCIMG)
192 return cdrcimg_get_sym(sym);
194 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
195 if (id != plugin_funcs[i].id)
198 if (strcmp(sym, plugin_funcs[i].name) != 0)
201 return plugin_funcs[i].func;
204 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
208 void plugin_call_rearmed_cbs(void)
210 extern void *hGPUDriver;
211 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
213 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
214 if (rearmed_set_cbs != NULL)
215 rearmed_set_cbs(&pl_rearmed_cbs);
220 /* basic profile stuff */
223 unsigned int pcounters[PCNT_CNT];
224 unsigned int pcounter_starts[PCNT_CNT];
226 #define pc_hook_func(name, args, pargs, cnt) \
227 extern void (*name) args; \
228 static void (*o_##name) args; \
229 static void w_##name args \
231 unsigned int pc_start = pcnt_get(); \
233 pcounters[cnt] += pcnt_get() - pc_start; \
236 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
237 extern retn (*name) args; \
238 static retn (*o_##name) args; \
239 static retn w_##name args \
242 unsigned int pc_start = pcnt_get(); \
243 ret = o_##name pargs; \
244 pcounters[cnt] += pcnt_get() - pc_start; \
248 pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
249 pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
250 pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
251 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
252 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
253 pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
254 pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
255 pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
257 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1), (a0, a1), PCNT_SPU)
258 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
259 pc_hook_func (SPU_writeDMA, (unsigned short a0), (a0), PCNT_SPU)
260 pc_hook_func_ret(unsigned short,SPU_readDMA, (void), (), PCNT_SPU)
261 pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
262 pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
263 pc_hook_func (SPU_playADPCMchannel, (void *a0), (a0), PCNT_SPU)
264 pc_hook_func (SPU_async, (unsigned int a0), (a0), PCNT_SPU)
265 pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), PCNT_SPU)
267 #define hook_it(name) { \
272 void pcnt_hook_plugins(void)
276 hook_it(GPU_writeStatus);
277 hook_it(GPU_writeData);
278 hook_it(GPU_writeDataMem);
279 hook_it(GPU_readStatus);
280 hook_it(GPU_readData);
281 hook_it(GPU_readDataMem);
282 hook_it(GPU_dmaChain);
283 hook_it(GPU_updateLace);
284 hook_it(SPU_writeRegister);
285 hook_it(SPU_readRegister);
286 hook_it(SPU_writeDMA);
287 hook_it(SPU_readDMA);
288 hook_it(SPU_writeDMAMem);
289 hook_it(SPU_readDMAMem);
290 hook_it(SPU_playADPCMchannel);
292 hook_it(SPU_playCDDAchannel);
295 // hooked into recompiler
296 void pcnt_gte_start(int op)
298 pcnt_start(PCNT_GTE);
301 void pcnt_gte_end(int op)