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 // this can't be __stdcall like it was in PSEmu API as too many functions are mixed up
22 static long CALLBACK dummy_func() {
27 extern long CALLBACK SPUopen(void);
28 extern long CALLBACK SPUinit(void);
29 extern long CALLBACK SPUshutdown(void);
30 extern long CALLBACK SPUclose(void);
31 extern void CALLBACK SPUwriteRegister(unsigned long, unsigned short, unsigned int);
32 extern unsigned short CALLBACK SPUreadRegister(unsigned long);
33 extern void CALLBACK SPUwriteDMAMem(unsigned short *, int, unsigned int);
34 extern void CALLBACK SPUreadDMAMem(unsigned short *, int, unsigned int);
35 extern void CALLBACK SPUplayADPCMchannel(void *, unsigned int, int);
36 extern void CALLBACK SPUregisterCallback(void (*cb)(void));
37 extern void CALLBACK SPUregisterScheduleCb(void (*cb)(unsigned int));
38 extern long CALLBACK SPUfreeze(unsigned int, void *, unsigned int);
39 extern void CALLBACK SPUasync(unsigned int, unsigned int);
40 extern int CALLBACK SPUplayCDDAchannel(short *, int, unsigned int, int);
43 static long CALLBACK PADreadPort1(PadDataS *pad)
45 pad->controllerType = in_type[0];
46 pad->buttonStatus = ~in_keystate[0];
47 if (in_type[0] == PSE_PAD_TYPE_ANALOGPAD) {
48 pad->leftJoyX = in_analog_left[0][0];
49 pad->leftJoyY = in_analog_left[0][1];
50 pad->rightJoyX = in_analog_right[0][0];
51 pad->rightJoyY = in_analog_right[0][1];
56 static long CALLBACK PADreadPort2(PadDataS *pad)
58 pad->controllerType = in_type[1];
59 pad->buttonStatus = ~in_keystate[0] >> 16;
64 extern long GPUopen(unsigned long *, char *, char *);
65 extern long GPUinit(void);
66 extern long GPUshutdown(void);
67 extern long GPUclose(void);
68 extern void GPUwriteStatus(uint32_t);
69 extern void GPUwriteData(uint32_t);
70 extern void GPUwriteDataMem(uint32_t *, int);
71 extern uint32_t GPUreadStatus(void);
72 extern uint32_t GPUreadData(void);
73 extern void GPUreadDataMem(uint32_t *, int);
74 extern long GPUdmaChain(uint32_t *,uint32_t);
75 extern void GPUupdateLace(void);
76 extern long GPUfreeze(uint32_t, void *);
77 extern void GPUvBlank(int, int);
78 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
81 #define DUMMY(id, name) \
82 { id, #name, dummy_func }
84 #define DIRECT(id, name) \
87 #define DUMMY_GPU(name) DUMMY(PLUGIN_GPU, name)
88 #define DUMMY_CDR(name) DUMMY(PLUGIN_CDR, name)
89 #define DUMMY_PAD(name) DUMMY(PLUGIN_PAD, name)
90 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
91 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
92 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
101 DUMMY_CDR(CDRshutdown),
107 DUMMY_CDR(CDRreadTrack),
108 DUMMY_CDR(CDRgetBuffer),
109 DUMMY_CDR(CDRgetBufferSub),
112 DUMMY_CDR(CDRgetStatus),
113 DUMMY_CDR(CDRgetDriveLetter),
114 DUMMY_CDR(CDRconfigure),
116 DUMMY_CDR(CDRsetfilename),
117 DUMMY_CDR(CDRreadCDDA),
121 DIRECT_SPU(SPUshutdown),
123 DIRECT_SPU(SPUclose),
124 DIRECT_SPU(SPUwriteRegister),
125 DIRECT_SPU(SPUreadRegister),
126 DIRECT_SPU(SPUwriteDMAMem),
127 DIRECT_SPU(SPUreadDMAMem),
128 DIRECT_SPU(SPUplayADPCMchannel),
129 DIRECT_SPU(SPUfreeze),
130 DIRECT_SPU(SPUregisterCallback),
131 DIRECT_SPU(SPUregisterScheduleCb),
132 DIRECT_SPU(SPUasync),
133 DIRECT_SPU(SPUplayCDDAchannel),
136 DUMMY_PAD(PADshutdown),
139 DUMMY_PAD(PADsetSensitive),
140 DIRECT_PAD(PADreadPort1),
141 DIRECT_PAD(PADreadPort2),
144 DUMMY_PAD(PADconfigure),
147 DUMMY_PAD(PADkeypressed),
148 DUMMY_PAD(PADstartPoll),
152 DIRECT_GPU(GPUupdateLace),
154 DIRECT_GPU(GPUshutdown),
156 DIRECT_GPU(GPUclose),
157 DIRECT_GPU(GPUreadStatus),
158 DIRECT_GPU(GPUreadData),
159 DIRECT_GPU(GPUreadDataMem),
160 DIRECT_GPU(GPUwriteStatus),
161 DIRECT_GPU(GPUwriteData),
162 DIRECT_GPU(GPUwriteDataMem),
163 DIRECT_GPU(GPUdmaChain),
164 DIRECT_GPU(GPUfreeze),
165 DIRECT_GPU(GPUvBlank),
166 DIRECT_GPU(GPUrearmedCallbacks),
168 DUMMY_GPU(GPUdisplayText),
170 DIRECT_GPU(GPUkeypressed),
171 DIRECT_GPU(GPUmakeSnapshot),
172 DIRECT_GPU(GPUconfigure),
174 DIRECT_GPU(GPUabout),
175 DIRECT_GPU(GPUgetScreenPic),
176 DIRECT_GPU(GPUshowScreenPic),
180 void *plugin_link(enum builtint_plugins_e id, const char *sym)
184 if (id == PLUGIN_CDRCIMG)
185 return cdrcimg_get_sym(sym);
187 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
188 if (id != plugin_funcs[i].id)
191 if (strcmp(sym, plugin_funcs[i].name) != 0)
194 return plugin_funcs[i].func;
197 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
201 void plugin_call_rearmed_cbs(void)
203 extern void *hGPUDriver;
204 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
206 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
207 if (rearmed_set_cbs != NULL)
208 rearmed_set_cbs(&pl_rearmed_cbs);
213 /* basic profile stuff */
216 unsigned int pcounters[PCNT_CNT];
217 unsigned int pcounter_starts[PCNT_CNT];
219 #define pc_hook_func(name, args, pargs, cnt) \
220 extern void (*name) args; \
221 static void (*o_##name) args; \
222 static void w_##name args \
224 unsigned int pc_start = pcnt_get(); \
226 pcounters[cnt] += pcnt_get() - pc_start; \
229 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
230 extern retn (*name) args; \
231 static retn (*o_##name) args; \
232 static retn w_##name args \
235 unsigned int pc_start = pcnt_get(); \
236 ret = o_##name pargs; \
237 pcounters[cnt] += pcnt_get() - pc_start; \
241 pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
242 pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
243 pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
244 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
245 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
246 pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
247 pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
248 pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
250 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
251 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
252 pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
253 pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
254 pc_hook_func (SPU_playADPCMchannel, (void *a0, unsigned int a1, int a2), (a0, a1, a2), PCNT_SPU)
255 pc_hook_func (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU)
256 pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1, unsigned int a2, int a3), (a0, a1, a2, a3), PCNT_SPU)
258 #define hook_it(name) { \
263 void pcnt_hook_plugins(void)
267 hook_it(GPU_writeStatus);
268 hook_it(GPU_writeData);
269 hook_it(GPU_writeDataMem);
270 hook_it(GPU_readStatus);
271 hook_it(GPU_readData);
272 hook_it(GPU_readDataMem);
273 hook_it(GPU_dmaChain);
274 hook_it(GPU_updateLace);
275 hook_it(SPU_writeRegister);
276 hook_it(SPU_readRegister);
277 hook_it(SPU_writeDMAMem);
278 hook_it(SPU_readDMAMem);
279 hook_it(SPU_playADPCMchannel);
281 hook_it(SPU_playCDDAchannel);
284 // hooked into recompiler
285 void pcnt_gte_start(int op)
287 pcnt_start(PCNT_GTE);
290 void pcnt_gte_end(int op)