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"
21 #define WIN32_LEAN_AND_MEAN
25 static int dummy_func() {
30 extern long CALLBACK SPUopen(void);
31 extern long CALLBACK SPUinit(void);
32 extern long CALLBACK SPUshutdown(void);
33 extern long CALLBACK SPUclose(void);
34 extern void CALLBACK SPUplaySample(unsigned char);
35 extern void CALLBACK SPUwriteRegister(unsigned long, unsigned short, unsigned int);
36 extern unsigned short CALLBACK SPUreadRegister(unsigned long);
37 extern void CALLBACK SPUwriteDMA(unsigned short);
38 extern unsigned short CALLBACK SPUreadDMA(void);
39 extern void CALLBACK SPUwriteDMAMem(unsigned short *, int, unsigned int);
40 extern void CALLBACK SPUreadDMAMem(unsigned short *, int, unsigned int);
41 extern void CALLBACK SPUplayADPCMchannel(void *);
42 extern void CALLBACK SPUregisterCallback(void (*cb)(void));
43 extern void CALLBACK SPUregisterScheduleCb(void (*cb)(unsigned int));
44 extern long CALLBACK SPUconfigure(void);
45 extern long CALLBACK SPUtest(void);
46 extern void CALLBACK SPUabout(void);
47 extern long CALLBACK SPUfreeze(unsigned int, void *, unsigned int);
48 extern void CALLBACK SPUasync(unsigned int, unsigned int);
49 extern int CALLBACK SPUplayCDDAchannel(short *, int);
52 static long PADreadPort1(PadDataS *pad)
54 pad->controllerType = in_type1;
55 pad->buttonStatus = ~in_keystate;
56 if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) {
57 pad->leftJoyX = in_a1[0];
58 pad->leftJoyY = in_a1[1];
59 pad->rightJoyX = in_a2[0];
60 pad->rightJoyY = in_a2[1];
65 static long PADreadPort2(PadDataS *pad)
67 pad->controllerType = in_type2;
68 pad->buttonStatus = ~in_keystate >> 16;
73 extern long GPUopen(unsigned long *, char *, char *);
74 extern long GPUinit(void);
75 extern long GPUshutdown(void);
76 extern long GPUclose(void);
77 extern void GPUwriteStatus(uint32_t);
78 extern void GPUwriteData(uint32_t);
79 extern void GPUwriteDataMem(uint32_t *, int);
80 extern uint32_t GPUreadStatus(void);
81 extern uint32_t GPUreadData(void);
82 extern void GPUreadDataMem(uint32_t *, int);
83 extern long GPUdmaChain(uint32_t *,uint32_t);
84 extern void GPUupdateLace(void);
85 extern long GPUfreeze(uint32_t, void *);
86 extern void GPUvBlank(int, int);
87 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
90 #define DUMMY(id, name) \
91 { id, #name, dummy_func }
93 #define DIRECT(id, name) \
96 #define DUMMY_GPU(name) DUMMY(PLUGIN_GPU, name)
97 #define DUMMY_CDR(name) DUMMY(PLUGIN_CDR, name)
98 #define DUMMY_PAD(name) DUMMY(PLUGIN_PAD, name)
99 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
100 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
101 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
103 static const struct {
110 DUMMY_CDR(CDRshutdown),
116 DUMMY_CDR(CDRreadTrack),
117 DUMMY_CDR(CDRgetBuffer),
118 DUMMY_CDR(CDRgetBufferSub),
121 DUMMY_CDR(CDRgetStatus),
122 DUMMY_CDR(CDRgetDriveLetter),
123 DUMMY_CDR(CDRconfigure),
125 DUMMY_CDR(CDRsetfilename),
126 DUMMY_CDR(CDRreadCDDA),
129 DIRECT_SPU(SPUconfigure),
130 DIRECT_SPU(SPUabout),
132 DIRECT_SPU(SPUshutdown),
135 DIRECT_SPU(SPUclose),
136 // DIRECT_SPU(SPUplaySample), // unused?
137 DIRECT_SPU(SPUwriteRegister),
138 DIRECT_SPU(SPUreadRegister),
139 DIRECT_SPU(SPUwriteDMA),
140 DIRECT_SPU(SPUreadDMA),
141 DIRECT_SPU(SPUwriteDMAMem),
142 DIRECT_SPU(SPUreadDMAMem),
143 DIRECT_SPU(SPUplayADPCMchannel),
144 DIRECT_SPU(SPUfreeze),
145 DIRECT_SPU(SPUregisterCallback),
146 DIRECT_SPU(SPUregisterScheduleCb),
147 DIRECT_SPU(SPUasync),
148 DIRECT_SPU(SPUplayCDDAchannel),
151 DUMMY_PAD(PADshutdown),
154 DUMMY_PAD(PADsetSensitive),
155 DIRECT_PAD(PADreadPort1),
156 DIRECT_PAD(PADreadPort2),
159 DUMMY_PAD(PADconfigure),
162 DUMMY_PAD(PADkeypressed),
163 DUMMY_PAD(PADstartPoll),
167 DIRECT_GPU(GPUupdateLace),
169 DIRECT_GPU(GPUshutdown),
171 DIRECT_GPU(GPUclose),
172 DIRECT_GPU(GPUreadStatus),
173 DIRECT_GPU(GPUreadData),
174 DIRECT_GPU(GPUreadDataMem),
175 DIRECT_GPU(GPUwriteStatus),
176 DIRECT_GPU(GPUwriteData),
177 DIRECT_GPU(GPUwriteDataMem),
178 DIRECT_GPU(GPUdmaChain),
179 DIRECT_GPU(GPUfreeze),
180 DIRECT_GPU(GPUvBlank),
181 DIRECT_GPU(GPUrearmedCallbacks),
183 DUMMY_GPU(GPUdisplayText),
185 DIRECT_GPU(GPUkeypressed),
186 DIRECT_GPU(GPUmakeSnapshot),
187 DIRECT_GPU(GPUconfigure),
189 DIRECT_GPU(GPUabout),
190 DIRECT_GPU(GPUgetScreenPic),
191 DIRECT_GPU(GPUshowScreenPic),
193 // DIRECT_GPU(GPUclearDynarec),
196 void *plugin_link(enum builtint_plugins_e id, const char *sym)
200 if (id == PLUGIN_CDRCIMG)
201 return cdrcimg_get_sym(sym);
203 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
204 if (id != plugin_funcs[i].id)
207 if (strcmp(sym, plugin_funcs[i].name) != 0)
210 return plugin_funcs[i].func;
213 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
217 void plugin_call_rearmed_cbs(void)
219 extern void *hGPUDriver;
220 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
222 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
223 if (rearmed_set_cbs != NULL)
224 rearmed_set_cbs(&pl_rearmed_cbs);
229 /* basic profile stuff */
232 unsigned int pcounters[PCNT_CNT];
233 unsigned int pcounter_starts[PCNT_CNT];
235 #define pc_hook_func(name, args, pargs, cnt) \
236 extern void (*name) args; \
237 static void (*o_##name) args; \
238 static void w_##name args \
240 unsigned int pc_start = pcnt_get(); \
242 pcounters[cnt] += pcnt_get() - pc_start; \
245 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
246 extern retn (*name) args; \
247 static retn (*o_##name) args; \
248 static retn w_##name args \
251 unsigned int pc_start = pcnt_get(); \
252 ret = o_##name pargs; \
253 pcounters[cnt] += pcnt_get() - pc_start; \
257 pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
258 pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
259 pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
260 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
261 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
262 pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
263 pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
264 pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
266 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
267 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
268 pc_hook_func (SPU_writeDMA, (unsigned short a0), (a0), PCNT_SPU)
269 pc_hook_func_ret(unsigned short,SPU_readDMA, (void), (), PCNT_SPU)
270 pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
271 pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
272 pc_hook_func (SPU_playADPCMchannel, (void *a0), (a0), PCNT_SPU)
273 pc_hook_func (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU)
274 pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), PCNT_SPU)
276 #define hook_it(name) { \
281 void pcnt_hook_plugins(void)
285 hook_it(GPU_writeStatus);
286 hook_it(GPU_writeData);
287 hook_it(GPU_writeDataMem);
288 hook_it(GPU_readStatus);
289 hook_it(GPU_readData);
290 hook_it(GPU_readDataMem);
291 hook_it(GPU_dmaChain);
292 hook_it(GPU_updateLace);
293 hook_it(SPU_writeRegister);
294 hook_it(SPU_readRegister);
295 hook_it(SPU_writeDMA);
296 hook_it(SPU_readDMA);
297 hook_it(SPU_writeDMAMem);
298 hook_it(SPU_readDMAMem);
299 hook_it(SPU_playADPCMchannel);
301 hook_it(SPU_playCDDAchannel);
304 // hooked into recompiler
305 void pcnt_gte_start(int op)
307 pcnt_start(PCNT_GTE);
310 void pcnt_gte_end(int op)