spu: rm bunch of unused functions
[pcsx_rearmed.git] / frontend / plugin.c
1 /*
2  * (C) notaz, 2010
3  *
4  * This work is licensed under the terms of the GNU GPLv2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
11
12 #include "plugin_lib.h"
13 #include "plugin.h"
14 #include "psemu_plugin_defs.h"
15 #include "../libpcsxcore/system.h"
16 #include "../plugins/cdrcimg/cdrcimg.h"
17
18 // this can't be __stdcall like it was in PSEmu API as too many functions are mixed up
19 #undef CALLBACK
20 #define CALLBACK
21
22 static long CALLBACK dummy_func() {
23         return 0;
24 }
25
26 /* SPU */
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);
41
42 /* PAD */
43 static long CALLBACK PADreadPort1(PadDataS *pad) {
44         int pad_index = pad->requestPadIndex;
45
46         pad->controllerType = in_type[pad_index];
47         pad->buttonStatus = ~in_keystate[pad_index];
48
49         if (multitap1 == 1)
50                 pad->portMultitap = 1;
51         else
52                 pad->portMultitap = 0;
53
54         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)
55         {
56                 pad->leftJoyX = in_analog_left[pad_index][0];
57                 pad->leftJoyY = in_analog_left[pad_index][1];
58                 pad->rightJoyX = in_analog_right[pad_index][0];
59                 pad->rightJoyY = in_analog_right[pad_index][1];
60
61                 pad->absoluteX = in_analog_left[pad_index][0];
62                 pad->absoluteY = in_analog_left[pad_index][1];
63         }
64
65         if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
66         {
67                 pad->moveX = in_mouse[pad_index][0];
68                 pad->moveY = in_mouse[pad_index][1];
69         }
70
71         return 0;
72 }
73
74 static long CALLBACK PADreadPort2(PadDataS *pad) {
75         int pad_index = pad->requestPadIndex;
76
77         pad->controllerType = in_type[pad_index];
78         pad->buttonStatus = ~in_keystate[pad_index];
79
80         if (multitap2 == 1)
81                 pad->portMultitap = 2;
82         else
83                 pad->portMultitap = 0;
84
85         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)
86         {
87                 pad->leftJoyX = in_analog_left[pad_index][0];
88                 pad->leftJoyY = in_analog_left[pad_index][1];
89                 pad->rightJoyX = in_analog_right[pad_index][0];
90                 pad->rightJoyY = in_analog_right[pad_index][1];
91
92                 pad->absoluteX = in_analog_left[pad_index][0];
93                 pad->absoluteY = in_analog_left[pad_index][1];
94         }
95
96         if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
97         {
98                 pad->moveX = in_mouse[pad_index][0];
99                 pad->moveY = in_mouse[pad_index][1];
100         }
101
102         return 0;
103 }
104
105 /* GPU */
106 extern long GPUopen(unsigned long *, char *, char *);
107 extern long GPUinit(void);
108 extern long GPUshutdown(void);
109 extern long GPUclose(void);
110 extern void GPUwriteStatus(uint32_t);
111 extern void GPUwriteData(uint32_t);
112 extern void GPUwriteDataMem(uint32_t *, int);
113 extern uint32_t GPUreadStatus(void);
114 extern uint32_t GPUreadData(void);
115 extern void GPUreadDataMem(uint32_t *, int);
116 extern long GPUdmaChain(uint32_t *,uint32_t);
117 extern void GPUupdateLace(void);
118 extern long GPUfreeze(uint32_t, void *);
119 extern void GPUvBlank(int, int);
120 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
121
122
123 #define DUMMY(id, name) \
124         { id, #name, dummy_func }
125
126 #define DIRECT(id, name) \
127         { id, #name, name }
128
129 #define DUMMY_GPU(name)  DUMMY(PLUGIN_GPU, name)
130 #define DUMMY_CDR(name)  DUMMY(PLUGIN_CDR, name)
131 #define DUMMY_PAD(name)  DUMMY(PLUGIN_PAD, name)
132 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
133 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
134 #define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
135
136 static const struct {
137         int id;
138         const char *name;
139         void *func;
140 } plugin_funcs[] = {
141         /* CDR */
142         DUMMY_CDR(CDRinit),
143         DUMMY_CDR(CDRshutdown),
144         DUMMY_CDR(CDRopen),
145         DUMMY_CDR(CDRclose),
146         DUMMY_CDR(CDRtest),
147         DUMMY_CDR(CDRgetTN),
148         DUMMY_CDR(CDRgetTD),
149         DUMMY_CDR(CDRreadTrack),
150         DUMMY_CDR(CDRgetBuffer),
151         DUMMY_CDR(CDRgetBufferSub),
152         DUMMY_CDR(CDRplay),
153         DUMMY_CDR(CDRstop),
154         DUMMY_CDR(CDRgetStatus),
155         DUMMY_CDR(CDRgetDriveLetter),
156         DUMMY_CDR(CDRconfigure),
157         DUMMY_CDR(CDRabout),
158         DUMMY_CDR(CDRsetfilename),
159         DUMMY_CDR(CDRreadCDDA),
160         DUMMY_CDR(CDRgetTE),
161         /* SPU */
162         DIRECT_SPU(SPUinit),
163         DIRECT_SPU(SPUshutdown),
164         DIRECT_SPU(SPUopen),
165         DIRECT_SPU(SPUclose),
166         DIRECT_SPU(SPUwriteRegister),
167         DIRECT_SPU(SPUreadRegister),
168         DIRECT_SPU(SPUwriteDMAMem),
169         DIRECT_SPU(SPUreadDMAMem),
170         DIRECT_SPU(SPUplayADPCMchannel),
171         DIRECT_SPU(SPUfreeze),
172         DIRECT_SPU(SPUregisterCallback),
173         DIRECT_SPU(SPUregisterScheduleCb),
174         DIRECT_SPU(SPUasync),
175         DIRECT_SPU(SPUplayCDDAchannel),
176         /* PAD */
177         DUMMY_PAD(PADinit),
178         DUMMY_PAD(PADshutdown),
179         DUMMY_PAD(PADopen),
180         DUMMY_PAD(PADclose),
181         DUMMY_PAD(PADsetSensitive),
182         DIRECT_PAD(PADreadPort1),
183         DIRECT_PAD(PADreadPort2),
184 /*
185         DUMMY_PAD(PADquery),
186         DUMMY_PAD(PADconfigure),
187         DUMMY_PAD(PADtest),
188         DUMMY_PAD(PADabout),
189         DUMMY_PAD(PADkeypressed),
190         DUMMY_PAD(PADstartPoll),
191         DUMMY_PAD(PADpoll),
192 */
193         /* GPU */
194         DIRECT_GPU(GPUupdateLace),
195         DIRECT_GPU(GPUinit),
196         DIRECT_GPU(GPUshutdown),
197         DIRECT_GPU(GPUopen),
198         DIRECT_GPU(GPUclose),
199         DIRECT_GPU(GPUreadStatus),
200         DIRECT_GPU(GPUreadData),
201         DIRECT_GPU(GPUreadDataMem),
202         DIRECT_GPU(GPUwriteStatus),
203         DIRECT_GPU(GPUwriteData),
204         DIRECT_GPU(GPUwriteDataMem),
205         DIRECT_GPU(GPUdmaChain),
206         DIRECT_GPU(GPUfreeze),
207         DIRECT_GPU(GPUvBlank),
208         DIRECT_GPU(GPUrearmedCallbacks),
209
210         DUMMY_GPU(GPUdisplayText),
211 /*
212         DIRECT_GPU(GPUkeypressed),
213         DIRECT_GPU(GPUmakeSnapshot),
214         DIRECT_GPU(GPUconfigure),
215         DIRECT_GPU(GPUtest),
216         DIRECT_GPU(GPUabout),
217         DIRECT_GPU(GPUgetScreenPic),
218         DIRECT_GPU(GPUshowScreenPic),
219 */
220 };
221
222 void *plugin_link(enum builtint_plugins_e id, const char *sym)
223 {
224         int i;
225
226         if (id == PLUGIN_CDRCIMG)
227                 return cdrcimg_get_sym(sym);
228
229         for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
230                 if (id != plugin_funcs[i].id)
231                         continue;
232
233                 if (strcmp(sym, plugin_funcs[i].name) != 0)
234                         continue;
235
236                 return plugin_funcs[i].func;
237         }
238
239         //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
240         return NULL;
241 }
242
243 void plugin_call_rearmed_cbs(void)
244 {
245         extern void *hGPUDriver;
246         void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
247
248         rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
249         if (rearmed_set_cbs != NULL)
250                 rearmed_set_cbs(&pl_rearmed_cbs);
251 }
252
253 #ifdef PCNT
254
255 /* basic profile stuff */
256 #include "pcnt.h"
257
258 unsigned int pcounters[PCNT_CNT];
259 unsigned int pcounter_starts[PCNT_CNT];
260
261 #define pc_hook_func(name, args, pargs, cnt) \
262 extern void (*name) args; \
263 static void (*o_##name) args; \
264 static void w_##name args \
265 { \
266         unsigned int pc_start = pcnt_get(); \
267         o_##name pargs; \
268         pcounters[cnt] += pcnt_get() - pc_start; \
269 }
270
271 #define pc_hook_func_ret(retn, name, args, pargs, cnt) \
272 extern retn (*name) args; \
273 static retn (*o_##name) args; \
274 static retn w_##name args \
275 { \
276         retn ret; \
277         unsigned int pc_start = pcnt_get(); \
278         ret = o_##name pargs; \
279         pcounters[cnt] += pcnt_get() - pc_start; \
280         return ret; \
281 }
282
283 pc_hook_func              (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
284 pc_hook_func              (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
285 pc_hook_func              (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
286 pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
287 pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
288 pc_hook_func              (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
289 pc_hook_func_ret(long,     GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
290 pc_hook_func              (GPU_updateLace, (void), (), PCNT_GPU)
291
292 pc_hook_func              (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
293 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
294 pc_hook_func              (SPU_writeDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
295 pc_hook_func              (SPU_readDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
296 pc_hook_func              (SPU_playADPCMchannel, (void *a0, unsigned int a1, int a2), (a0, a1, a2), PCNT_SPU)
297 pc_hook_func              (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU)
298 pc_hook_func_ret(int,      SPU_playCDDAchannel, (short *a0, int a1, unsigned int a2, int a3), (a0, a1, a2, a3), PCNT_SPU)
299
300 #define hook_it(name) { \
301         o_##name = name; \
302         name = w_##name; \
303 }
304
305 void pcnt_hook_plugins(void)
306 {
307         pcnt_init();
308
309         hook_it(GPU_writeStatus);
310         hook_it(GPU_writeData);
311         hook_it(GPU_writeDataMem);
312         hook_it(GPU_readStatus);
313         hook_it(GPU_readData);
314         hook_it(GPU_readDataMem);
315         hook_it(GPU_dmaChain);
316         hook_it(GPU_updateLace);
317         hook_it(SPU_writeRegister);
318         hook_it(SPU_readRegister);
319         hook_it(SPU_writeDMAMem);
320         hook_it(SPU_readDMAMem);
321         hook_it(SPU_playADPCMchannel);
322         hook_it(SPU_async);
323         hook_it(SPU_playCDDAchannel);
324 }
325
326 // hooked into recompiler
327 void pcnt_gte_start(int op)
328 {
329         pcnt_start(PCNT_GTE);
330 }
331
332 void pcnt_gte_end(int op)
333 {
334         pcnt_end(PCNT_GTE);
335 }
336
337 #endif