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 {
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];
52         }
53         return 0;
54 }
55
56 static long CALLBACK PADreadPort2(PadDataS *pad)
57 {
58         pad->controllerType = in_type[1];
59         pad->buttonStatus = ~in_keystate[0] >> 16;
60         return 0;
61 }
62
63 /* GPU */
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);
79
80
81 #define DUMMY(id, name) \
82         { id, #name, dummy_func }
83
84 #define DIRECT(id, name) \
85         { id, #name, name }
86
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)
93
94 static const struct {
95         int id;
96         const char *name;
97         void *func;
98 } plugin_funcs[] = {
99         /* CDR */
100         DUMMY_CDR(CDRinit),
101         DUMMY_CDR(CDRshutdown),
102         DUMMY_CDR(CDRopen),
103         DUMMY_CDR(CDRclose),
104         DUMMY_CDR(CDRtest),
105         DUMMY_CDR(CDRgetTN),
106         DUMMY_CDR(CDRgetTD),
107         DUMMY_CDR(CDRreadTrack),
108         DUMMY_CDR(CDRgetBuffer),
109         DUMMY_CDR(CDRgetBufferSub),
110         DUMMY_CDR(CDRplay),
111         DUMMY_CDR(CDRstop),
112         DUMMY_CDR(CDRgetStatus),
113         DUMMY_CDR(CDRgetDriveLetter),
114         DUMMY_CDR(CDRconfigure),
115         DUMMY_CDR(CDRabout),
116         DUMMY_CDR(CDRsetfilename),
117         DUMMY_CDR(CDRreadCDDA),
118         DUMMY_CDR(CDRgetTE),
119         /* SPU */
120         DIRECT_SPU(SPUinit),
121         DIRECT_SPU(SPUshutdown),
122         DIRECT_SPU(SPUopen),
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),
134         /* PAD */
135         DUMMY_PAD(PADinit),
136         DUMMY_PAD(PADshutdown),
137         DUMMY_PAD(PADopen),
138         DUMMY_PAD(PADclose),
139         DUMMY_PAD(PADsetSensitive),
140         DIRECT_PAD(PADreadPort1),
141         DIRECT_PAD(PADreadPort2),
142 /*
143         DUMMY_PAD(PADquery),
144         DUMMY_PAD(PADconfigure),
145         DUMMY_PAD(PADtest),
146         DUMMY_PAD(PADabout),
147         DUMMY_PAD(PADkeypressed),
148         DUMMY_PAD(PADstartPoll),
149         DUMMY_PAD(PADpoll),
150 */
151         /* GPU */
152         DIRECT_GPU(GPUupdateLace),
153         DIRECT_GPU(GPUinit),
154         DIRECT_GPU(GPUshutdown),
155         DIRECT_GPU(GPUopen),
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),
167
168         DUMMY_GPU(GPUdisplayText),
169 /*
170         DIRECT_GPU(GPUkeypressed),
171         DIRECT_GPU(GPUmakeSnapshot),
172         DIRECT_GPU(GPUconfigure),
173         DIRECT_GPU(GPUtest),
174         DIRECT_GPU(GPUabout),
175         DIRECT_GPU(GPUgetScreenPic),
176         DIRECT_GPU(GPUshowScreenPic),
177 */
178 };
179
180 void *plugin_link(enum builtint_plugins_e id, const char *sym)
181 {
182         int i;
183
184         if (id == PLUGIN_CDRCIMG)
185                 return cdrcimg_get_sym(sym);
186
187         for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
188                 if (id != plugin_funcs[i].id)
189                         continue;
190
191                 if (strcmp(sym, plugin_funcs[i].name) != 0)
192                         continue;
193
194                 return plugin_funcs[i].func;
195         }
196
197         //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
198         return NULL;
199 }
200
201 void plugin_call_rearmed_cbs(void)
202 {
203         extern void *hGPUDriver;
204         void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
205
206         rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
207         if (rearmed_set_cbs != NULL)
208                 rearmed_set_cbs(&pl_rearmed_cbs);
209 }
210
211 #ifdef PCNT
212
213 /* basic profile stuff */
214 #include "pcnt.h"
215
216 unsigned int pcounters[PCNT_CNT];
217 unsigned int pcounter_starts[PCNT_CNT];
218
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 \
223 { \
224         unsigned int pc_start = pcnt_get(); \
225         o_##name pargs; \
226         pcounters[cnt] += pcnt_get() - pc_start; \
227 }
228
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 \
233 { \
234         retn ret; \
235         unsigned int pc_start = pcnt_get(); \
236         ret = o_##name pargs; \
237         pcounters[cnt] += pcnt_get() - pc_start; \
238         return ret; \
239 }
240
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)
249
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)
257
258 #define hook_it(name) { \
259         o_##name = name; \
260         name = w_##name; \
261 }
262
263 void pcnt_hook_plugins(void)
264 {
265         pcnt_init();
266
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);
280         hook_it(SPU_async);
281         hook_it(SPU_playCDDAchannel);
282 }
283
284 // hooked into recompiler
285 void pcnt_gte_start(int op)
286 {
287         pcnt_start(PCNT_GTE);
288 }
289
290 void pcnt_gte_end(int op)
291 {
292         pcnt_end(PCNT_GTE);
293 }
294
295 #endif