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