forked from Themaister/parallel-rdp-standalone
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfx_m64p.cpp
392 lines (325 loc) · 12 KB
/
gfx_m64p.cpp
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Mupen64plus-video-angrylionplus - plugin.c *
* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
* Copyright (C) 2014 Bobby Smiles *
* Copyright (C) 2009 Richard Goedeken *
* Copyright (C) 2002 Hacktarux *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define M64P_PLUGIN_PROTOTYPES 1
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include "gfx_m64p.h"
#include "screen.h"
#include "parallel_imp.h"
#include "util/logging.hpp"
#ifdef CONFIG_GUI
#include "UserInterface/MainDialog.hpp"
#endif // CONFIG_GUI
#include "m64p_types.h"
#include "m64p_config.h"
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
ptr_ConfigOpenSection ConfigOpenSection = NULL;
ptr_ConfigSaveSection ConfigSaveSection = NULL;
ptr_ConfigSetDefaultInt ConfigSetDefaultInt = NULL;
ptr_ConfigSetDefaultBool ConfigSetDefaultBool = NULL;
ptr_ConfigGetParamInt ConfigGetParamInt = NULL;
ptr_ConfigGetParamBool ConfigGetParamBool = NULL;
ptr_ConfigSetParameter ConfigSetParameter = NULL;
static bool vk_initialized;
static bool warn_hle;
static bool plugin_initialized;
void (*debug_callback)(void *, int, const char *);
void *debug_call_context;
m64p_dynlib_handle CoreLibHandle;
GFX_INFO gfx;
void (*render_callback)(int);
m64p_handle configVideoParallel = NULL;
#define PLUGIN_VERSION 0x000001
#define VIDEO_PLUGIN_API_VERSION 0x020200
#define DP_INTERRUPT 0x20
uint32_t rdram_size;
static ptr_PluginGetVersion CoreGetVersion = NULL;
void plugin_init(void)
{
CoreGetVersion = (ptr_PluginGetVersion)DLSYM(CoreLibHandle, "PluginGetVersion");
int core_version;
CoreGetVersion(NULL, &core_version, NULL, NULL, NULL);
if (core_version >= 0x020501)
{
rdram_size = *gfx.RDRAM_SIZE;
}
else
{
rdram_size = 0x800000;
}
}
void plugin_close(void)
{
}
void DebugMessage(int level, const char *message, ...)
{
char msgbuf[1024];
va_list args;
if (debug_callback == nullptr)
{
return;
}
va_start(args, message);
vsprintf(msgbuf, message, args);
(*debug_callback)(debug_call_context, level, msgbuf);
va_end(args);
}
class MupenLoggingInterface : public Util::LoggingInterface
{
public:
bool log(const char *tag, const char *fmt, va_list va)
{
char buf[1024];
int buf_len = 0;
int level = M64MSG_VERBOSE;
// copy string to buf
vsnprintf(buf, sizeof(buf), fmt, va);
// determine log level
if (strncmp(tag, "[INFO]", 6) == 0)
{
level = M64MSG_INFO;
}
else if (strncmp(tag, "[WARN]", 6) == 0)
{
level = M64MSG_WARNING;
}
else if (strncmp(tag, "[ERROR]", 7) == 0)
{
level = M64MSG_ERROR;
}
// strip newline
buf_len = strlen(buf);
if (buf[buf_len - 1] == '\n')
{
buf[buf_len - 1] = '\0';
}
DebugMessage(level, buf);
return true;
}
};
static MupenLoggingInterface l_LoggingInterface;
EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle _CoreLibHandle, void *Context,
void (*DebugCallback)(void *, int, const char *))
{
if (plugin_initialized)
{
return M64ERR_ALREADY_INIT;
}
/* first thing is to set the callback function for debug info */
debug_callback = DebugCallback;
debug_call_context = Context;
CoreLibHandle = _CoreLibHandle;
ConfigOpenSection = (ptr_ConfigOpenSection)DLSYM(CoreLibHandle, "ConfigOpenSection");
ConfigSaveSection = (ptr_ConfigSaveSection)DLSYM(CoreLibHandle, "ConfigSaveSection");
ConfigSetDefaultInt = (ptr_ConfigSetDefaultInt)DLSYM(CoreLibHandle, "ConfigSetDefaultInt");
ConfigSetDefaultBool = (ptr_ConfigSetDefaultBool)DLSYM(CoreLibHandle, "ConfigSetDefaultBool");
ConfigGetParamInt = (ptr_ConfigGetParamInt)DLSYM(CoreLibHandle, "ConfigGetParamInt");
ConfigGetParamBool = (ptr_ConfigGetParamBool)DLSYM(CoreLibHandle, "ConfigGetParamBool");
ConfigSetParameter = (ptr_ConfigSetParameter)DLSYM(CoreLibHandle, "ConfigSetParameter");
ConfigOpenSection("Video-Parallel", &configVideoParallel);
ConfigSetDefaultInt(configVideoParallel, KEY_UPSCALING, 1, "Amount of rescaling: 1=None, 2=2x, 4=4x, 8=8x");
ConfigSetDefaultBool(configVideoParallel, KEY_VSYNC, 0, "Enable VSync");
ConfigSetDefaultInt(configVideoParallel, KEY_SCREEN_WIDTH, 640, "Screen width");
ConfigSetDefaultInt(configVideoParallel, KEY_SCREEN_HEIGHT, 480, "Screen height");
ConfigSetDefaultBool(configVideoParallel, KEY_WIDESCREEN, 0, "Widescreen mode (stretched)");
ConfigSetDefaultBool(configVideoParallel, KEY_DEINTERLACE, 0, "Deinterlacing method. False=Bob, True=Weave");
ConfigSetDefaultBool(configVideoParallel, KEY_SSREADBACKS, 0, "Enable superscaling of readbacks when upsampling");
ConfigSetDefaultBool(configVideoParallel, KEY_SSDITHER, 1, "Enable superscaling of dithering when upsampling");
ConfigSetDefaultBool(configVideoParallel, KEY_SYNCHRONOUS, 1, "Enable synchronizing RDP and CPU");
ConfigSetDefaultInt(configVideoParallel, KEY_OVERSCANCROP, 0, "Amount of overscan pixels to crop on all sides");
ConfigSetDefaultInt(configVideoParallel, KEY_VERTICAL_STRETCH, 0, "Amount of pixels to stretch by vertically. Can fix PAL ports that didn't fill the PAL resolution of 288p (use value of 24 in that case).");
ConfigSetDefaultBool(configVideoParallel, KEY_AA, 1, "VI anti-aliasing, smooths polygon edges.");
ConfigSetDefaultBool(configVideoParallel, KEY_DIVOT, 1, "Allow VI divot filter, cleans up stray black pixels.");
ConfigSetDefaultBool(configVideoParallel, KEY_GAMMADITHER, 1, "Allow VI gamma dither");
ConfigSetDefaultBool(configVideoParallel, KEY_VIBILERP, 1, "Allow VI bilinear scaling");
ConfigSetDefaultBool(configVideoParallel, KEY_VIDITHER, 1, "Allow VI dedither filter");
ConfigSetDefaultInt(configVideoParallel, KEY_DOWNSCALE, 0, "Downsampling factor, downscales output after VI, equivalent to SSAA. 0=disabled, 1=1/2, 2=1/4, 3=1/8");
ConfigSetDefaultBool(configVideoParallel, KEY_NATIVETEXTLOD, 0, "Use native texture LOD computation when upscaling, effectively a LOD bias");
ConfigSetDefaultBool(configVideoParallel, KEY_NATIVETEXTRECT, 1, "Native resolution TEX_RECT. TEX_RECT primitives should generally be rendered at native resolution to avoid seams");
ConfigSaveSection("Video-Parallel");
// set logging interface
Util::set_thread_logging_interface(&l_LoggingInterface);
plugin_initialized = true;
vk_initialized = false;
return M64ERR_SUCCESS;
}
EXPORT m64p_error CALL PluginShutdown(void)
{
if (!plugin_initialized)
{
return M64ERR_NOT_INIT;
}
/* reset some local variable */
debug_callback = NULL;
debug_call_context = NULL;
plugin_initialized = false;
vk_initialized = false;
return M64ERR_SUCCESS;
}
EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *PluginType, int *PluginVersion, int *APIVersion, const char **PluginNamePtr, int *Capabilities)
{
/* set version info */
if (PluginType != NULL)
{
*PluginType = M64PLUGIN_GFX;
}
if (PluginVersion != NULL)
{
*PluginVersion = PLUGIN_VERSION;
}
if (APIVersion != NULL)
{
*APIVersion = VIDEO_PLUGIN_API_VERSION;
}
if (PluginNamePtr != NULL)
{
*PluginNamePtr = "parallel";
}
if (Capabilities != NULL)
{
*Capabilities = 0;
}
return M64ERR_SUCCESS;
}
#ifdef CONFIG_GUI
extern "C"
{
EXPORT m64p_error CALL PluginConfig(void)
{
if (!plugin_initialized)
{
return M64ERR_NOT_INIT;
}
UserInterface::MainDialog dialog(nullptr);
dialog.exec();
return M64ERR_SUCCESS;
}
}
#endif // CONFIG_GUI
EXPORT int CALL InitiateGFX(GFX_INFO Gfx_Info)
{
gfx = Gfx_Info;
return 1;
}
EXPORT void CALL MoveScreen(int xpos, int ypos)
{
}
EXPORT void CALL ProcessDList(void)
{
}
EXPORT void CALL ProcessRDPList(void)
{
vk_process_commands();
}
EXPORT int CALL RomOpen(void)
{
window_fullscreen = false;
window_width = ConfigGetParamInt(configVideoParallel, KEY_SCREEN_WIDTH);
window_height = ConfigGetParamInt(configVideoParallel, KEY_SCREEN_HEIGHT);
window_widescreen = ConfigGetParamBool(configVideoParallel, KEY_WIDESCREEN);
window_vsync = ConfigGetParamBool(configVideoParallel, KEY_VSYNC);
vk_rescaling = ConfigGetParamInt(configVideoParallel, KEY_UPSCALING);
vk_ssreadbacks = ConfigGetParamBool(configVideoParallel, KEY_SSREADBACKS);
vk_ssdither = ConfigGetParamBool(configVideoParallel, KEY_SSDITHER);
vk_divot_filter = ConfigGetParamBool(configVideoParallel, KEY_DIVOT);
vk_gamma_dither = ConfigGetParamBool(configVideoParallel, KEY_GAMMADITHER);
vk_vi_scale = ConfigGetParamBool(configVideoParallel, KEY_VIBILERP);
vk_vi_aa = ConfigGetParamBool(configVideoParallel, KEY_AA);
vk_dither_filter = ConfigGetParamBool(configVideoParallel, KEY_VIDITHER);
vk_native_texture_lod = ConfigGetParamBool(configVideoParallel, KEY_NATIVETEXTLOD);
vk_native_tex_rect = ConfigGetParamBool(configVideoParallel, KEY_NATIVETEXTRECT);
vk_interlacing = ConfigGetParamBool(configVideoParallel, KEY_DEINTERLACE);
vk_downscaling_steps = ConfigGetParamInt(configVideoParallel, KEY_DOWNSCALE);
vk_overscan = ConfigGetParamInt(configVideoParallel, KEY_OVERSCANCROP);
vk_vertical_stretch = ConfigGetParamInt(configVideoParallel, KEY_VERTICAL_STRETCH);
vk_synchronous = ConfigGetParamBool(configVideoParallel, KEY_SYNCHRONOUS);
plugin_init();
if (vk_init())
{
vk_initialized = true;
return 1;
}
else
{
vk_initialized = false;
DebugMessage(M64MSG_ERROR, "Could not start GFX plugin");
return 0;
}
}
EXPORT void CALL RomClosed(void)
{
if (vk_initialized)
{
vk_destroy();
}
}
EXPORT void CALL ShowCFB(void)
{
vk_rasterize();
}
EXPORT void CALL UpdateScreen(void)
{
vk_rasterize();
}
EXPORT void CALL ViStatusChanged(void)
{
}
EXPORT void CALL ViWidthChanged(void)
{
}
EXPORT void CALL ChangeWindow(void)
{
screen_toggle_fullscreen();
}
EXPORT void CALL ReadScreen2(void *dest, int *width, int *height, int front)
{
*width = window_width;
*height = window_height;
if (dest)
{
vk_read_screen((unsigned char*)dest);
}
}
EXPORT void CALL SetRenderingCallback(void (*callback)(int))
{
render_callback = callback;
}
EXPORT void CALL ResizeVideoOutput(int width, int height)
{
window_width = width;
window_height = height;
vk_resize();
}
EXPORT void CALL FBWrite(unsigned int addr, unsigned int size)
{
}
EXPORT void CALL FBRead(unsigned int addr)
{
}
EXPORT void CALL FBGetFrameBufferInfo(void *pinfo)
{
}