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