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 "../libpcsxcore/psxcommon.h"
17 #include "../plugins/cdrcimg/cdrcimg.h"
19 // this can't be __stdcall like it was in PSEmu API as too many functions are mixed up
25 static long CALLBACK CDRinit(void) { return 0; }
26 static long CALLBACK CDRshutdown(void) { return 0; }
27 static long CALLBACK CDRopen(void) { return 0; }
28 static long CALLBACK CDRclose(void) { return 0; }
29 static long CALLBACK CDRgetTN(unsigned char *_) { return 0; }
30 static long CALLBACK CDRgetTD(unsigned char _, unsigned char *__) { return 0; }
31 static boolean CALLBACK CDRreadTrack(unsigned char *_) { return FALSE; }
32 static unsigned char * CALLBACK CDRgetBuffer(void) { return NULL; }
33 static unsigned char * CALLBACK CDRgetBufferSub(int sector) { return NULL; }
34 static long CALLBACK CDRconfigure(void) { return 0; }
35 static long CALLBACK CDRtest(void) { return 0; }
36 static void CALLBACK CDRabout(void) { return; }
37 static long CALLBACK CDRplay(unsigned char *_) { return 0; }
38 static long CALLBACK CDRstop(void) { return 0; }
39 static long CALLBACK CDRsetfilename(char *_) { return 0; }
40 static long CALLBACK CDRgetStatus(struct CdrStat *_) { return 0; }
41 static char * CALLBACK CDRgetDriveLetter(void) { return NULL; }
42 static long CALLBACK CDRreadCDDA(unsigned char _, unsigned char __, unsigned char ___, unsigned char *____) { return 0; }
43 static long CALLBACK CDRgetTE(unsigned char _, unsigned char *__, unsigned char *___, unsigned char *____) { return 0; }
44 static long CALLBACK CDRprefetch(unsigned char m, unsigned char s, unsigned char f) { return 1; }
47 static void CALLBACK GPUdisplayText(char *_) { return; }
50 #include "../plugins/dfsound/spu.h"
53 static long CALLBACK PADinit(long _) { return 0; }
54 static long CALLBACK PADopen(unsigned long *_) { return 0; }
55 static long CALLBACK PADshutdown(void) { return 0; }
56 static long CALLBACK PADclose(void) { return 0; }
57 static void CALLBACK PADsetSensitive(int _) { return; }
59 static long CALLBACK PADreadPort1(PadDataS *pad) {
60 int pad_index = pad->requestPadIndex;
62 pad->controllerType = in_type[pad_index];
63 pad->buttonStatus = ~in_keystate[pad_index];
65 pad->portMultitap = multitap1;
67 if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON || in_type[pad_index] == PSE_PAD_TYPE_GUN)
69 pad->leftJoyX = in_analog_left[pad_index][0];
70 pad->leftJoyY = in_analog_left[pad_index][1];
71 pad->rightJoyX = in_analog_right[pad_index][0];
72 pad->rightJoyY = in_analog_right[pad_index][1];
74 pad->absoluteX = in_analog_left[pad_index][0];
75 pad->absoluteY = in_analog_left[pad_index][1];
78 if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
80 pad->moveX = in_mouse[pad_index][0];
81 pad->moveY = in_mouse[pad_index][1];
87 static long CALLBACK PADreadPort2(PadDataS *pad) {
88 int pad_index = pad->requestPadIndex;
90 pad->controllerType = in_type[pad_index];
91 pad->buttonStatus = ~in_keystate[pad_index];
93 pad->portMultitap = multitap2;
95 if (in_type[pad_index] == PSE_PAD_TYPE_ANALOGJOY || in_type[pad_index] == PSE_PAD_TYPE_ANALOGPAD || in_type[pad_index] == PSE_PAD_TYPE_NEGCON || in_type[pad_index] == PSE_PAD_TYPE_GUNCON || in_type[pad_index] == PSE_PAD_TYPE_GUN)
97 pad->leftJoyX = in_analog_left[pad_index][0];
98 pad->leftJoyY = in_analog_left[pad_index][1];
99 pad->rightJoyX = in_analog_right[pad_index][0];
100 pad->rightJoyY = in_analog_right[pad_index][1];
102 pad->absoluteX = in_analog_left[pad_index][0];
103 pad->absoluteY = in_analog_left[pad_index][1];
106 if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
108 pad->moveX = in_mouse[pad_index][0];
109 pad->moveY = in_mouse[pad_index][1];
116 extern long GPUopen(unsigned long *, char *, char *);
117 extern long GPUinit(void);
118 extern long GPUshutdown(void);
119 extern long GPUclose(void);
120 extern void GPUwriteStatus(uint32_t);
121 extern void GPUwriteData(uint32_t);
122 extern void GPUwriteDataMem(uint32_t *, int);
123 extern uint32_t GPUreadStatus(void);
124 extern uint32_t GPUreadData(void);
125 extern void GPUreadDataMem(uint32_t *, int);
126 extern long GPUdmaChain(uint32_t *, uint32_t, uint32_t *, int32_t *);
127 extern void GPUupdateLace(void);
128 extern long GPUfreeze(uint32_t, void *);
129 extern void GPUvBlank(int, int);
130 extern void GPUgetScreenInfo(int *y, int *base_hres);
131 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
134 #define DIRECT(id, name) \
137 #define DIRECT_CDR(name) DIRECT(PLUGIN_CDR, name)
138 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
139 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
140 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
142 static const struct {
149 DIRECT_CDR(CDRshutdown),
151 DIRECT_CDR(CDRclose),
153 DIRECT_CDR(CDRgetTN),
154 DIRECT_CDR(CDRgetTD),
155 DIRECT_CDR(CDRreadTrack),
156 DIRECT_CDR(CDRgetBuffer),
157 DIRECT_CDR(CDRgetBufferSub),
160 DIRECT_CDR(CDRgetStatus),
161 DIRECT_CDR(CDRgetDriveLetter),
162 DIRECT_CDR(CDRconfigure),
163 DIRECT_CDR(CDRabout),
164 DIRECT_CDR(CDRsetfilename),
165 DIRECT_CDR(CDRreadCDDA),
166 DIRECT_CDR(CDRgetTE),
167 DIRECT_CDR(CDRprefetch),
170 DIRECT_SPU(SPUshutdown),
172 DIRECT_SPU(SPUclose),
173 DIRECT_SPU(SPUwriteRegister),
174 DIRECT_SPU(SPUreadRegister),
175 DIRECT_SPU(SPUwriteDMAMem),
176 DIRECT_SPU(SPUreadDMAMem),
177 DIRECT_SPU(SPUplayADPCMchannel),
178 DIRECT_SPU(SPUfreeze),
179 DIRECT_SPU(SPUregisterCallback),
180 DIRECT_SPU(SPUregisterScheduleCb),
181 DIRECT_SPU(SPUasync),
182 DIRECT_SPU(SPUplayCDDAchannel),
183 DIRECT_SPU(SPUsetCDvol),
186 DIRECT_PAD(PADshutdown),
188 DIRECT_PAD(PADclose),
189 DIRECT_PAD(PADsetSensitive),
190 DIRECT_PAD(PADreadPort1),
191 DIRECT_PAD(PADreadPort2),
193 DIRECT_PAD(PADquery),
194 DIRECT_PAD(PADconfigure),
196 DIRECT_PAD(PADabout),
197 DIRECT_PAD(PADkeypressed),
198 DIRECT_PAD(PADstartPoll),
202 DIRECT_GPU(GPUupdateLace),
204 DIRECT_GPU(GPUshutdown),
206 DIRECT_GPU(GPUclose),
207 DIRECT_GPU(GPUreadStatus),
208 DIRECT_GPU(GPUreadData),
209 DIRECT_GPU(GPUreadDataMem),
210 DIRECT_GPU(GPUwriteStatus),
211 DIRECT_GPU(GPUwriteData),
212 DIRECT_GPU(GPUwriteDataMem),
213 DIRECT_GPU(GPUdmaChain),
214 DIRECT_GPU(GPUfreeze),
215 DIRECT_GPU(GPUvBlank),
216 DIRECT_GPU(GPUgetScreenInfo),
217 DIRECT_GPU(GPUrearmedCallbacks),
219 DIRECT_GPU(GPUdisplayText),
221 DIRECT_GPU(GPUkeypressed),
222 DIRECT_GPU(GPUmakeSnapshot),
223 DIRECT_GPU(GPUconfigure),
224 DIRECT_GPU(GPUgetScreenPic),
225 DIRECT_GPU(GPUshowScreenPic),
229 void *plugin_link(enum builtint_plugins_e id, const char *sym)
233 if (id == PLUGIN_CDRCIMG)
234 return cdrcimg_get_sym(sym);
236 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
237 if (id != plugin_funcs[i].id)
240 if (strcmp(sym, plugin_funcs[i].name) != 0)
243 return plugin_funcs[i].func;
246 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
250 void plugin_call_rearmed_cbs(void)
252 extern void *hGPUDriver;
253 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
255 pl_rearmed_cbs.screen_centering_type_default =
256 Config.hacks.gpu_centering ? C_INGAME : C_AUTO;
258 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
259 if (rearmed_set_cbs != NULL)
260 rearmed_set_cbs(&pl_rearmed_cbs);
265 /* basic profile stuff */
268 unsigned int pcounters[PCNT_CNT];
269 unsigned int pcounter_starts[PCNT_CNT];
271 #define pc_hook_func(name, args, pargs, cnt) \
272 extern void (*name) args; \
273 static void (*o_##name) args; \
274 static void w_##name args \
276 unsigned int pc_start = pcnt_get(); \
278 pcounters[cnt] += pcnt_get() - pc_start; \
281 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
282 extern retn (*name) args; \
283 static retn (*o_##name) args; \
284 static retn w_##name args \
287 unsigned int pc_start = pcnt_get(); \
288 ret = o_##name pargs; \
289 pcounters[cnt] += pcnt_get() - pc_start; \
293 pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
294 pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
295 pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
296 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
297 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
298 pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
299 pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
300 pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
302 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
303 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0, , unsigned int a1), (a0, a1), PCNT_SPU)
304 pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
305 pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
306 pc_hook_func (SPU_playADPCMchannel, (void *a0, unsigned int a1, int a2), (a0, a1, a2), PCNT_SPU)
307 pc_hook_func (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU)
308 pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1, unsigned int a2, int a3), (a0, a1, a2, a3), PCNT_SPU)
310 #define hook_it(name) { \
315 void pcnt_hook_plugins(void)
319 hook_it(GPU_writeStatus);
320 hook_it(GPU_writeData);
321 hook_it(GPU_writeDataMem);
322 hook_it(GPU_readStatus);
323 hook_it(GPU_readData);
324 hook_it(GPU_readDataMem);
325 hook_it(GPU_dmaChain);
326 hook_it(GPU_updateLace);
327 hook_it(SPU_writeRegister);
328 hook_it(SPU_readRegister);
329 hook_it(SPU_writeDMAMem);
330 hook_it(SPU_readDMAMem);
331 hook_it(SPU_playADPCMchannel);
333 hook_it(SPU_playCDDAchannel);
336 // hooked into recompiler
337 void pcnt_gte_start(int op)
339 pcnt_start(PCNT_GTE);
342 void pcnt_gte_end(int op)