release r4
[pcsx_rearmed.git] / frontend / plugin.c
... / ...
CommitLineData
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 "../libpcsxcore/psemu_plugin_defs.h"
15#include "../libpcsxcore/system.h"
16#include "../plugins/cdrcimg/cdrcimg.h"
17
18static int dummy_func() {
19 return 0;
20}
21
22/* SPU */
23extern long SPUopen(void);
24extern long SPUinit(void);
25extern long SPUshutdown(void);
26extern long SPUclose(void);
27extern void SPUplaySample(unsigned char);
28extern void SPUwriteRegister(unsigned long, unsigned short);
29extern unsigned short SPUreadRegister(unsigned long);
30extern void SPUwriteDMA(unsigned short);
31extern unsigned short SPUreadDMA(void);
32extern void SPUwriteDMAMem(unsigned short *, int);
33extern void SPUreadDMAMem(unsigned short *, int);
34extern void SPUplayADPCMchannel(void *);
35extern void SPUregisterCallback(void (*callback)(void));
36extern long SPUconfigure(void);
37extern long SPUtest(void);
38extern void SPUabout(void);
39extern long SPUfreeze(unsigned int, void *);
40extern void SPUasync(unsigned int);
41extern void SPUplayCDDAchannel(short *, int);
42
43/* PAD */
44static long PADreadPort1(PadDataS *pad)
45{
46 pad->controllerType = PSE_PAD_TYPE_STANDARD;
47 pad->buttonStatus = ~keystate;
48 return 0;
49}
50
51static long PADreadPort2(PadDataS *pad)
52{
53 pad->controllerType = PSE_PAD_TYPE_STANDARD;
54 pad->buttonStatus = ~keystate >> 16;
55 return 0;
56}
57
58/* GPU */
59extern long GPUopen(unsigned long *, char *, char *);
60extern long GPUinit(void);
61extern long GPUshutdown(void);
62extern long GPUclose(void);
63extern void GPUwriteStatus(uint32_t);
64extern void GPUwriteData(uint32_t);
65extern void GPUwriteDataMem(uint32_t *, int);
66extern uint32_t GPUreadStatus(void);
67extern uint32_t GPUreadData(void);
68extern void GPUreadDataMem(uint32_t *, int);
69extern long GPUdmaChain(uint32_t *,uint32_t);
70extern void GPUupdateLace(void);
71extern long GPUfreeze(uint32_t, void *);
72
73
74#define DUMMY(id, name) \
75 { id, #name, dummy_func }
76
77#define DIRECT(id, name) \
78 { id, #name, name }
79
80#define DUMMY_GPU(name) DUMMY(PLUGIN_GPU, name)
81#define DUMMY_CDR(name) DUMMY(PLUGIN_CDR, name)
82#define DUMMY_PAD(name) DUMMY(PLUGIN_PAD, name)
83#define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
84#define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
85#define DIRECT_PAD(name) DIRECT(PLUGIN_PAD, name)
86
87static const struct {
88 int id;
89 const char *name;
90 void *func;
91} plugin_funcs[] = {
92 /* CDR */
93 DUMMY_CDR(CDRinit),
94 DUMMY_CDR(CDRshutdown),
95 DUMMY_CDR(CDRopen),
96 DUMMY_CDR(CDRclose),
97 DUMMY_CDR(CDRtest),
98 DUMMY_CDR(CDRgetTN),
99 DUMMY_CDR(CDRgetTD),
100 DUMMY_CDR(CDRreadTrack),
101 DUMMY_CDR(CDRgetBuffer),
102 DUMMY_CDR(CDRgetBufferSub),
103 DUMMY_CDR(CDRplay),
104 DUMMY_CDR(CDRstop),
105 DUMMY_CDR(CDRgetStatus),
106 DUMMY_CDR(CDRgetDriveLetter),
107 DUMMY_CDR(CDRconfigure),
108 DUMMY_CDR(CDRabout),
109 DUMMY_CDR(CDRsetfilename),
110 DUMMY_CDR(CDRreadCDDA),
111 DUMMY_CDR(CDRgetTE),
112 /* SPU */
113 DIRECT_SPU(SPUconfigure),
114 DIRECT_SPU(SPUabout),
115 DIRECT_SPU(SPUinit),
116 DIRECT_SPU(SPUshutdown),
117 DIRECT_SPU(SPUtest),
118 DIRECT_SPU(SPUopen),
119 DIRECT_SPU(SPUclose),
120// DIRECT_SPU(SPUplaySample), // unused?
121 DIRECT_SPU(SPUwriteRegister),
122 DIRECT_SPU(SPUreadRegister),
123 DIRECT_SPU(SPUwriteDMA),
124 DIRECT_SPU(SPUreadDMA),
125 DIRECT_SPU(SPUwriteDMAMem),
126 DIRECT_SPU(SPUreadDMAMem),
127 DIRECT_SPU(SPUplayADPCMchannel),
128 DIRECT_SPU(SPUfreeze),
129 DIRECT_SPU(SPUregisterCallback),
130 DIRECT_SPU(SPUasync),
131 DIRECT_SPU(SPUplayCDDAchannel),
132 /* PAD */
133 DUMMY_PAD(PADinit),
134 DUMMY_PAD(PADshutdown),
135 DUMMY_PAD(PADopen),
136 DUMMY_PAD(PADclose),
137 DUMMY_PAD(PADsetSensitive),
138 DIRECT_PAD(PADreadPort1),
139 DIRECT_PAD(PADreadPort2),
140/*
141 DUMMY_PAD(PADquery),
142 DUMMY_PAD(PADconfigure),
143 DUMMY_PAD(PADtest),
144 DUMMY_PAD(PADabout),
145 DUMMY_PAD(PADkeypressed),
146 DUMMY_PAD(PADstartPoll),
147 DUMMY_PAD(PADpoll),
148*/
149 /* GPU */
150 DIRECT_GPU(GPUupdateLace),
151 DIRECT_GPU(GPUinit),
152 DIRECT_GPU(GPUshutdown),
153 DIRECT_GPU(GPUopen),
154 DIRECT_GPU(GPUclose),
155 DIRECT_GPU(GPUreadStatus),
156 DIRECT_GPU(GPUreadData),
157 DIRECT_GPU(GPUreadDataMem),
158 DIRECT_GPU(GPUwriteStatus),
159 DIRECT_GPU(GPUwriteData),
160 DIRECT_GPU(GPUwriteDataMem),
161 DIRECT_GPU(GPUdmaChain),
162 DIRECT_GPU(GPUfreeze),
163
164 DUMMY_GPU(GPUdisplayText),
165/*
166 DIRECT_GPU(GPUkeypressed),
167 DIRECT_GPU(GPUmakeSnapshot),
168 DIRECT_GPU(GPUconfigure),
169 DIRECT_GPU(GPUtest),
170 DIRECT_GPU(GPUabout),
171 DIRECT_GPU(GPUgetScreenPic),
172 DIRECT_GPU(GPUshowScreenPic),
173*/
174// DIRECT_GPU(GPUclearDynarec),
175// DIRECT_GPU(GPUvBlank),
176};
177
178void *plugin_link(enum builtint_plugins_e id, const char *sym)
179{
180 int i;
181
182 if (id == PLUGIN_CDRCIMG)
183 return cdrcimg_get_sym(sym);
184
185 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
186 if (id != plugin_funcs[i].id)
187 continue;
188
189 if (strcmp(sym, plugin_funcs[i].name) != 0)
190 continue;
191
192 return plugin_funcs[i].func;
193 }
194
195 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
196 return NULL;
197}
198
199void plugin_call_rearmed_cbs(void)
200{
201 extern void *hGPUDriver;
202 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
203
204 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
205 if (rearmed_set_cbs != NULL)
206 rearmed_set_cbs(&pl_rearmed_cbs);
207}
208
209#ifdef PCNT
210
211/* basic profile stuff */
212#include "pcnt.h"
213
214unsigned int pcounters[PCNT_CNT];
215unsigned int pcounter_starts[PCNT_CNT];
216
217#define pc_hook_func(name, args, pargs, cnt) \
218extern void (*name) args; \
219static void (*o_##name) args; \
220static void w_##name args \
221{ \
222 unsigned int pc_start = pcnt_get(); \
223 o_##name pargs; \
224 pcounters[cnt] += pcnt_get() - pc_start; \
225}
226
227#define pc_hook_func_ret(retn, name, args, pargs, cnt) \
228extern retn (*name) args; \
229static retn (*o_##name) args; \
230static retn w_##name args \
231{ \
232 retn ret; \
233 unsigned int pc_start = pcnt_get(); \
234 ret = o_##name pargs; \
235 pcounters[cnt] += pcnt_get() - pc_start; \
236 return ret; \
237}
238
239pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU)
240pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU)
241pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
242pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU)
243pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU)
244pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU)
245pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU)
246pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU)
247
248pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1), (a0, a1), PCNT_SPU)
249pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0), (a0), PCNT_SPU)
250pc_hook_func (SPU_writeDMA, (unsigned short a0), (a0), PCNT_SPU)
251pc_hook_func_ret(unsigned short,SPU_readDMA, (void), (), PCNT_SPU)
252pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
253pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1), (a0, a1), PCNT_SPU)
254pc_hook_func (SPU_playADPCMchannel, (void *a0), (a0), PCNT_SPU)
255pc_hook_func (SPU_async, (unsigned int a0), (a0), PCNT_SPU)
256pc_hook_func (SPU_playCDDAchannel, (short *a0, int a1), (a0, a1), PCNT_SPU)
257
258#define hook_it(name) { \
259 o_##name = name; \
260 name = w_##name; \
261}
262
263void pcnt_hook_plugins(void)
264{
265 /* test it first */
266 pcnt_get();
267
268 hook_it(GPU_writeStatus);
269 hook_it(GPU_writeData);
270 hook_it(GPU_writeDataMem);
271 hook_it(GPU_readStatus);
272 hook_it(GPU_readData);
273 hook_it(GPU_readDataMem);
274 hook_it(GPU_dmaChain);
275 hook_it(GPU_updateLace);
276 hook_it(SPU_writeRegister);
277 hook_it(SPU_readRegister);
278 hook_it(SPU_writeDMA);
279 hook_it(SPU_readDMA);
280 hook_it(SPU_writeDMAMem);
281 hook_it(SPU_readDMAMem);
282 hook_it(SPU_playADPCMchannel);
283 hook_it(SPU_async);
284 hook_it(SPU_playCDDAchannel);
285}
286
287#endif