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" |
b23cf6d9 |
16 | #include "../libpcsxcore/psxcommon.h" |
47bf65ab |
17 | #include "../plugins/cdrcimg/cdrcimg.h" |
e906c010 |
18 | |
029e681c |
19 | // this can't be __stdcall like it was in PSEmu API as too many functions are mixed up |
20 | #undef CALLBACK |
003cfc63 |
21 | #define CALLBACK |
003cfc63 |
22 | |
e906c010 |
23 | /* SPU */ |
38b8a211 |
24 | #include "../plugins/dfsound/spu.h" |
e906c010 |
25 | |
26 | /* PAD */ |
aa4cdd73 |
27 | long PAD1_readPort(PadDataS *pad) { |
2db412ad |
28 | int pad_index = pad->requestPadIndex; |
29 | |
30 | pad->controllerType = in_type[pad_index]; |
31 | pad->buttonStatus = ~in_keystate[pad_index]; |
32 | |
f6eb0b1c |
33 | pad->portMultitap = multitap1; |
2db412ad |
34 | |
d6a231b7 |
35 | 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 || in_type[pad_index] == PSE_PAD_TYPE_GUN) |
2db412ad |
36 | { |
37 | pad->leftJoyX = in_analog_left[pad_index][0]; |
38 | pad->leftJoyY = in_analog_left[pad_index][1]; |
39 | pad->rightJoyX = in_analog_right[pad_index][0]; |
40 | pad->rightJoyY = in_analog_right[pad_index][1]; |
41 | |
42 | pad->absoluteX = in_analog_left[pad_index][0]; |
43 | pad->absoluteY = in_analog_left[pad_index][1]; |
799b0b87 |
44 | } |
2db412ad |
45 | |
46 | if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE) |
47 | { |
48 | pad->moveX = in_mouse[pad_index][0]; |
49 | pad->moveY = in_mouse[pad_index][1]; |
50 | } |
51 | |
e1d2234d |
52 | return 0; |
e906c010 |
53 | } |
54 | |
aa4cdd73 |
55 | long PAD2_readPort(PadDataS *pad) { |
2db412ad |
56 | int pad_index = pad->requestPadIndex; |
57 | |
58 | pad->controllerType = in_type[pad_index]; |
59 | pad->buttonStatus = ~in_keystate[pad_index]; |
60 | |
f6eb0b1c |
61 | pad->portMultitap = multitap2; |
2db412ad |
62 | |
d6a231b7 |
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 || in_type[pad_index] == PSE_PAD_TYPE_GUN) |
2db412ad |
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 | |
e1d2234d |
80 | return 0; |
e906c010 |
81 | } |
82 | |
83 | /* GPU */ |
84 | extern long GPUopen(unsigned long *, char *, char *); |
85 | extern long GPUinit(void); |
86 | extern long GPUshutdown(void); |
87 | extern long GPUclose(void); |
88 | extern void GPUwriteStatus(uint32_t); |
89 | extern void GPUwriteData(uint32_t); |
90 | extern void GPUwriteDataMem(uint32_t *, int); |
91 | extern uint32_t GPUreadStatus(void); |
92 | extern uint32_t GPUreadData(void); |
93 | extern void GPUreadDataMem(uint32_t *, int); |
8412166f |
94 | extern long GPUdmaChain(uint32_t *, uint32_t, uint32_t *, int32_t *); |
e906c010 |
95 | extern void GPUupdateLace(void); |
e906c010 |
96 | extern long GPUfreeze(uint32_t, void *); |
72e5023f |
97 | extern void GPUvBlank(int, int); |
ab88daca |
98 | extern void GPUgetScreenInfo(int *y, int *base_hres); |
e64dc4c5 |
99 | extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs); |
e906c010 |
100 | |
101 | |
e906c010 |
102 | #define DIRECT(id, name) \ |
103 | { id, #name, name } |
104 | |
e906c010 |
105 | #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name) |
106 | #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name) |
e906c010 |
107 | |
108 | static const struct { |
109 | int id; |
110 | const char *name; |
111 | void *func; |
112 | } plugin_funcs[] = { |
e906c010 |
113 | /* SPU */ |
e906c010 |
114 | DIRECT_SPU(SPUinit), |
115 | DIRECT_SPU(SPUshutdown), |
e906c010 |
116 | DIRECT_SPU(SPUopen), |
117 | DIRECT_SPU(SPUclose), |
e906c010 |
118 | DIRECT_SPU(SPUwriteRegister), |
119 | DIRECT_SPU(SPUreadRegister), |
e906c010 |
120 | DIRECT_SPU(SPUwriteDMAMem), |
121 | DIRECT_SPU(SPUreadDMAMem), |
122 | DIRECT_SPU(SPUplayADPCMchannel), |
123 | DIRECT_SPU(SPUfreeze), |
124 | DIRECT_SPU(SPUregisterCallback), |
2b30c129 |
125 | DIRECT_SPU(SPUregisterScheduleCb), |
e906c010 |
126 | DIRECT_SPU(SPUasync), |
127 | DIRECT_SPU(SPUplayCDDAchannel), |
38b8a211 |
128 | DIRECT_SPU(SPUsetCDvol), |
e906c010 |
129 | /* GPU */ |
130 | DIRECT_GPU(GPUupdateLace), |
131 | DIRECT_GPU(GPUinit), |
132 | DIRECT_GPU(GPUshutdown), |
e906c010 |
133 | DIRECT_GPU(GPUopen), |
134 | DIRECT_GPU(GPUclose), |
135 | DIRECT_GPU(GPUreadStatus), |
136 | DIRECT_GPU(GPUreadData), |
137 | DIRECT_GPU(GPUreadDataMem), |
138 | DIRECT_GPU(GPUwriteStatus), |
139 | DIRECT_GPU(GPUwriteData), |
140 | DIRECT_GPU(GPUwriteDataMem), |
141 | DIRECT_GPU(GPUdmaChain), |
c5061935 |
142 | DIRECT_GPU(GPUfreeze), |
72e5023f |
143 | DIRECT_GPU(GPUvBlank), |
ab88daca |
144 | DIRECT_GPU(GPUgetScreenInfo), |
e64dc4c5 |
145 | DIRECT_GPU(GPUrearmedCallbacks), |
e906c010 |
146 | }; |
147 | |
148 | void *plugin_link(enum builtint_plugins_e id, const char *sym) |
149 | { |
150 | int i; |
151 | |
152 | for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) { |
153 | if (id != plugin_funcs[i].id) |
154 | continue; |
155 | |
156 | if (strcmp(sym, plugin_funcs[i].name) != 0) |
157 | continue; |
158 | |
159 | return plugin_funcs[i].func; |
160 | } |
161 | |
e1d2234d |
162 | //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym); |
e906c010 |
163 | return NULL; |
164 | } |
165 | |
201c21e2 |
166 | void plugin_call_rearmed_cbs(void) |
167 | { |
168 | extern void *hGPUDriver; |
169 | void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs); |
170 | |
9ed80467 |
171 | pl_rearmed_cbs.screen_centering_type_default = |
172 | Config.hacks.gpu_centering ? C_INGAME : C_AUTO; |
173 | |
201c21e2 |
174 | rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks"); |
175 | if (rearmed_set_cbs != NULL) |
176 | rearmed_set_cbs(&pl_rearmed_cbs); |
177 | } |
178 | |
fa9cfe0a |
179 | #ifdef PCNT |
180 | |
14dffdb7 |
181 | /* basic profile stuff */ |
182 | #include "pcnt.h" |
183 | |
184 | unsigned int pcounters[PCNT_CNT]; |
185 | unsigned int pcounter_starts[PCNT_CNT]; |
186 | |
187 | #define pc_hook_func(name, args, pargs, cnt) \ |
188 | extern void (*name) args; \ |
189 | static void (*o_##name) args; \ |
190 | static void w_##name args \ |
191 | { \ |
192 | unsigned int pc_start = pcnt_get(); \ |
193 | o_##name pargs; \ |
194 | pcounters[cnt] += pcnt_get() - pc_start; \ |
195 | } |
196 | |
197 | #define pc_hook_func_ret(retn, name, args, pargs, cnt) \ |
198 | extern retn (*name) args; \ |
199 | static retn (*o_##name) args; \ |
200 | static retn w_##name args \ |
201 | { \ |
202 | retn ret; \ |
203 | unsigned int pc_start = pcnt_get(); \ |
204 | ret = o_##name pargs; \ |
205 | pcounters[cnt] += pcnt_get() - pc_start; \ |
206 | return ret; \ |
207 | } |
208 | |
209 | pc_hook_func (GPU_writeStatus, (uint32_t a0), (a0), PCNT_GPU) |
210 | pc_hook_func (GPU_writeData, (uint32_t a0), (a0), PCNT_GPU) |
211 | pc_hook_func (GPU_writeDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU) |
212 | pc_hook_func_ret(uint32_t, GPU_readStatus, (void), (), PCNT_GPU) |
213 | pc_hook_func_ret(uint32_t, GPU_readData, (void), (), PCNT_GPU) |
214 | pc_hook_func (GPU_readDataMem, (uint32_t *a0, int a1), (a0, a1), PCNT_GPU) |
215 | pc_hook_func_ret(long, GPU_dmaChain, (uint32_t *a0, int32_t a1), (a0, a1), PCNT_GPU) |
216 | pc_hook_func (GPU_updateLace, (void), (), PCNT_GPU) |
217 | |
650adfd2 |
218 | pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU) |
d358733b |
219 | pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0, , unsigned int a1), (a0, a1), PCNT_SPU) |
650adfd2 |
220 | pc_hook_func (SPU_writeDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU) |
221 | pc_hook_func (SPU_readDMAMem, (unsigned short *a0, int a1, uint32_t a2), (a0, a1, a2), PCNT_SPU) |
9cf79034 |
222 | pc_hook_func (SPU_playADPCMchannel, (void *a0, unsigned int a1, int a2), (a0, a1, a2), PCNT_SPU) |
650adfd2 |
223 | pc_hook_func (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU) |
9cf79034 |
224 | pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1, unsigned int a2, int a3), (a0, a1, a2, a3), PCNT_SPU) |
14dffdb7 |
225 | |
226 | #define hook_it(name) { \ |
227 | o_##name = name; \ |
228 | name = w_##name; \ |
229 | } |
230 | |
231 | void pcnt_hook_plugins(void) |
232 | { |
19e57cbf |
233 | pcnt_init(); |
f95a77f7 |
234 | |
14dffdb7 |
235 | hook_it(GPU_writeStatus); |
236 | hook_it(GPU_writeData); |
237 | hook_it(GPU_writeDataMem); |
238 | hook_it(GPU_readStatus); |
239 | hook_it(GPU_readData); |
240 | hook_it(GPU_readDataMem); |
241 | hook_it(GPU_dmaChain); |
242 | hook_it(GPU_updateLace); |
243 | hook_it(SPU_writeRegister); |
244 | hook_it(SPU_readRegister); |
14dffdb7 |
245 | hook_it(SPU_writeDMAMem); |
246 | hook_it(SPU_readDMAMem); |
247 | hook_it(SPU_playADPCMchannel); |
248 | hook_it(SPU_async); |
249 | hook_it(SPU_playCDDAchannel); |
250 | } |
251 | |
82ed88eb |
252 | // hooked into recompiler |
253 | void pcnt_gte_start(int op) |
254 | { |
255 | pcnt_start(PCNT_GTE); |
256 | } |
257 | |
258 | void pcnt_gte_end(int op) |
259 | { |
260 | pcnt_end(PCNT_GTE); |
261 | } |
262 | |
fa9cfe0a |
263 | #endif |