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