4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
12 #include "plugin_lib.h"
14 #include "psemu_plugin_defs.h"
15 #include "../libpcsxcore/system.h"
16 #include "../libpcsxcore/psxcommon.h"
17 #include "../plugins/cdrcimg/cdrcimg.h"
19 // this can't be __stdcall like it was in PSEmu API as too many functions are mixed up
24 #include "../plugins/dfsound/spu.h"
27 long PAD1_readPort(PadDataS *pad) {
28 int pad_index = pad->requestPadIndex;
30 pad->controllerType = in_type[pad_index];
31 pad->buttonStatus = ~in_keystate[pad_index];
33 pad->portMultitap = multitap1;
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)
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];
42 pad->absoluteX = in_analog_left[pad_index][0];
43 pad->absoluteY = in_analog_left[pad_index][1];
46 if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
48 pad->moveX = in_mouse[pad_index][0];
49 pad->moveY = in_mouse[pad_index][1];
55 long PAD2_readPort(PadDataS *pad) {
56 int pad_index = pad->requestPadIndex;
58 pad->controllerType = in_type[pad_index];
59 pad->buttonStatus = ~in_keystate[pad_index];
61 pad->portMultitap = multitap2;
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)
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];
70 pad->absoluteX = in_analog_left[pad_index][0];
71 pad->absoluteY = in_analog_left[pad_index][1];
74 if (in_type[pad_index] == PSE_PAD_TYPE_MOUSE)
76 pad->moveX = in_mouse[pad_index][0];
77 pad->moveY = in_mouse[pad_index][1];
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);
94 extern long GPUdmaChain(uint32_t *, uint32_t, uint32_t *, int32_t *);
95 extern void GPUupdateLace(void);
96 extern long GPUfreeze(uint32_t, void *);
97 extern void GPUvBlank(int, int);
98 extern void GPUgetScreenInfo(int *y, int *base_hres);
99 extern void GPUrearmedCallbacks(const struct rearmed_cbs *cbs);
102 #define DIRECT(id, name) \
105 #define DIRECT_SPU(name) DIRECT(PLUGIN_SPU, name)
106 #define DIRECT_GPU(name) DIRECT(PLUGIN_GPU, name)
108 static const struct {
115 DIRECT_SPU(SPUshutdown),
117 DIRECT_SPU(SPUclose),
118 DIRECT_SPU(SPUwriteRegister),
119 DIRECT_SPU(SPUreadRegister),
120 DIRECT_SPU(SPUwriteDMAMem),
121 DIRECT_SPU(SPUreadDMAMem),
122 DIRECT_SPU(SPUplayADPCMchannel),
123 DIRECT_SPU(SPUfreeze),
124 DIRECT_SPU(SPUregisterCallback),
125 DIRECT_SPU(SPUregisterScheduleCb),
126 DIRECT_SPU(SPUasync),
127 DIRECT_SPU(SPUplayCDDAchannel),
128 DIRECT_SPU(SPUsetCDvol),
130 DIRECT_GPU(GPUupdateLace),
132 DIRECT_GPU(GPUshutdown),
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),
142 DIRECT_GPU(GPUfreeze),
143 DIRECT_GPU(GPUvBlank),
144 DIRECT_GPU(GPUgetScreenInfo),
145 DIRECT_GPU(GPUrearmedCallbacks),
148 void *plugin_link(enum builtint_plugins_e id, const char *sym)
152 for (i = 0; i < ARRAY_SIZE(plugin_funcs); i++) {
153 if (id != plugin_funcs[i].id)
156 if (strcmp(sym, plugin_funcs[i].name) != 0)
159 return plugin_funcs[i].func;
162 //fprintf(stderr, "plugin_link: missing symbol %d %s\n", id, sym);
166 void plugin_call_rearmed_cbs(void)
168 extern void *hGPUDriver;
169 void (*rearmed_set_cbs)(const struct rearmed_cbs *cbs);
171 pl_rearmed_cbs.screen_centering_type_default =
172 Config.hacks.gpu_centering ? C_INGAME : C_AUTO;
174 rearmed_set_cbs = SysLoadSym(hGPUDriver, "GPUrearmedCallbacks");
175 if (rearmed_set_cbs != NULL)
176 rearmed_set_cbs(&pl_rearmed_cbs);
181 /* basic profile stuff */
184 unsigned int pcounters[PCNT_CNT];
185 unsigned int pcounter_starts[PCNT_CNT];
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 \
192 unsigned int pc_start = pcnt_get(); \
194 pcounters[cnt] += pcnt_get() - pc_start; \
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 \
203 unsigned int pc_start = pcnt_get(); \
204 ret = o_##name pargs; \
205 pcounters[cnt] += pcnt_get() - pc_start; \
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)
218 pc_hook_func (SPU_writeRegister, (unsigned long a0, unsigned short a1, uint32_t a2), (a0, a1, a2), PCNT_SPU)
219 pc_hook_func_ret(unsigned short,SPU_readRegister, (unsigned long a0, , unsigned int a1), (a0, a1), PCNT_SPU)
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)
222 pc_hook_func (SPU_playADPCMchannel, (void *a0, unsigned int a1, int a2), (a0, a1, a2), PCNT_SPU)
223 pc_hook_func (SPU_async, (uint32_t a0, uint32_t a1), (a0, a1), PCNT_SPU)
224 pc_hook_func_ret(int, SPU_playCDDAchannel, (short *a0, int a1, unsigned int a2, int a3), (a0, a1, a2, a3), PCNT_SPU)
226 #define hook_it(name) { \
231 void pcnt_hook_plugins(void)
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);
245 hook_it(SPU_writeDMAMem);
246 hook_it(SPU_readDMAMem);
247 hook_it(SPU_playADPCMchannel);
249 hook_it(SPU_playCDDAchannel);
252 // hooked into recompiler
253 void pcnt_gte_start(int op)
255 pcnt_start(PCNT_GTE);
258 void pcnt_gte_end(int op)