forked from p1pkin/demul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugins.c
233 lines (197 loc) · 5.02 KB
/
Plugins.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Demul
* Copyright (C) 2006 Demul Team
*
* Demul is not free software: you can't redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Demul isn't distributed in the hope that it will be useful,
* and WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <windows.h>
#include "plugins.h"
#include "memory.h"
#include "gpu.h"
#include "configure.h"
#define LoadFunc(lib, name) { \
## name ## = (_ ## name ## )GetProcAddress(h ## lib ## Plugin, # name); \
if ( ## name ## == NULL) return false; \
}
HMODULE hGPUPlugin = NULL;
HMODULE hGDRPlugin = NULL;
HMODULE hPADPlugin = NULL;
HMODULE hSPUPlugin = NULL;
_gpuOpen gpuOpen;
_gpuClose gpuClose;
_gpuReset gpuReset;
_gpuConfigure gpuConfigure;
_gpuAbout gpuAbout;
_gpuSync gpuSync;
_gpuRead32 gpuRead32;
_gpuWrite32 gpuWrite32;
_gpuSetIrqHandler gpuSetIrqHandler;
_gpuTaTransfer gpuTaTransfer;
_gpuYuvTransfer gpuYuvTransfer;
_gdrOpen gdrOpen;
_gdrClose gdrClose;
_gdrReset gdrReset;
_gdrConfigure gdrConfigure;
_gdrAbout gdrAbout;
_gdrReadTOC gdrReadTOC;
_gdrReadInfoSession gdrReadInfoSession;
_gdrGetStatus gdrGetStatus;
_gdrReadSectors gdrReadSectors;
_padOpen padOpen;
_padClose padClose;
_padReset padReset;
_padConfigure padConfigure;
_padAbout padAbout;
_padJoyCaps padJoyCaps;
_padReadJoy padReadJoy;
_spuOpen spuOpen;
_spuClose spuClose;
_spuReset spuReset;
_spuConfigure spuConfigure;
_spuAbout spuAbout;
_spuSync spuSync;
_spuRead8 spuRead8;
_spuRead16 spuRead16;
_spuRead32 spuRead32;
_spuWrite8 spuWrite8;
_spuWrite16 spuWrite16;
_spuWrite32 spuWrite32;
bool loadGPUPlugin(char *name) {
hGPUPlugin = LoadLibrary(name);
if (hGPUPlugin == NULL) {
return false;
}
LoadFunc(GPU, gpuOpen);
LoadFunc(GPU, gpuClose);
LoadFunc(GPU, gpuReset);
LoadFunc(GPU, gpuConfigure);
LoadFunc(GPU, gpuAbout);
LoadFunc(GPU, gpuSync);
LoadFunc(GPU, gpuRead32);
LoadFunc(GPU, gpuWrite32);
LoadFunc(GPU, gpuSetIrqHandler);
LoadFunc(GPU, gpuTaTransfer);
LoadFunc(GPU, gpuYuvTransfer);
return true;
}
int loadGDRPlugin(char *name) {
hGDRPlugin = LoadLibrary(name);
if (hGDRPlugin == NULL) {
return false;
}
LoadFunc(GDR, gdrOpen);
LoadFunc(GDR, gdrClose);
LoadFunc(GDR, gdrReset);
LoadFunc(GDR, gdrConfigure);
LoadFunc(GDR, gdrAbout);
LoadFunc(GDR, gdrReadTOC);
LoadFunc(GDR, gdrReadInfoSession);
LoadFunc(GDR, gdrGetStatus);
LoadFunc(GDR, gdrReadSectors);
return true;
}
int loadPADPlugin(char *name) {
hPADPlugin = LoadLibrary(name);
if (hPADPlugin == NULL) {
return false;
}
LoadFunc(PAD, padOpen);
LoadFunc(PAD, padClose);
LoadFunc(PAD, padReset);
LoadFunc(PAD, padConfigure);
LoadFunc(PAD, padAbout);
LoadFunc(PAD, padJoyCaps);
LoadFunc(PAD, padReadJoy);
return true;
}
bool loadSPUPlugin(char *name) {
hSPUPlugin = LoadLibrary(name);
if (hSPUPlugin == NULL) {
return false;
}
LoadFunc(SPU, spuOpen);
LoadFunc(SPU, spuClose);
LoadFunc(SPU, spuReset);
LoadFunc(SPU, spuConfigure);
LoadFunc(SPU, spuAbout);
LoadFunc(SPU, spuSync);
LoadFunc(SPU, spuRead8);
LoadFunc(SPU, spuRead16);
LoadFunc(SPU, spuRead32);
LoadFunc(SPU, spuWrite8);
LoadFunc(SPU, spuWrite16);
LoadFunc(SPU, spuWrite32);
return true;
}
bool openPlugins() {
int st;
st = gpuOpen(&demulInfo, pgpu);
if (st == 0) {
closePlugins();
return false;
}
gpuSetIrqHandler((void*)gpuIrq);
st = gdrOpen(&demulInfo);
if (st == 0) {
closePlugins();
return false;
}
st = padOpen(&demulInfo);
if (st == 0) {
closePlugins();
return false;
}
st = spuOpen(&demulInfo, pspu);
if (st == 0) {
closePlugins();
return false;
}
return true;
}
void closePlugins() {
gpuClose();
gdrClose();
padClose();
spuClose();
}
bool loadPlugins() {
if (!loadGPUPlugin(cfg.gpuPluginName)) {
MessageBox(GetActiveWindow(), "Unable to load", "GPUPlugin", MB_ICONERROR);
unloadPlugins();
return false;
}
if (!loadGDRPlugin(cfg.gdrPluginName)) {
MessageBox(GetActiveWindow(), "Unable to load", "GDRPlugin", MB_ICONERROR);
unloadPlugins();
return false;
}
if (!loadPADPlugin(cfg.padPluginName)) {
MessageBox(GetActiveWindow(), "Unable to load", "PADPlugin", MB_ICONERROR);
unloadPlugins();
return false;
}
if (!loadSPUPlugin(cfg.spuPluginName)) {
MessageBox(GetActiveWindow(), "Unable to load", "SPUPlugin", MB_ICONERROR);
unloadPlugins();
return false;
}
return true;
}
void unloadPlugins() {
if (hGPUPlugin != NULL) FreeLibrary((HMODULE)hGPUPlugin);
if (hGDRPlugin != NULL) FreeLibrary((HMODULE)hGDRPlugin);
if (hPADPlugin != NULL) FreeLibrary((HMODULE)hPADPlugin);
if (hSPUPlugin != NULL) FreeLibrary((HMODULE)hSPUPlugin);
hGPUPlugin = NULL;
hGDRPlugin = NULL;
hPADPlugin = NULL;
hSPUPlugin = NULL;
}