~ubuntu-branches/ubuntu/trusty/mupen64plus/trusty

« back to all changes in this revision

Viewing changes to .pc/xdg-basedir.patch/main/plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2010-03-15 16:22:03 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20100315162203-dtxgbbr8q7ycnojc
Tags: 1.5+dfsg1-8
* debian/patches:
  - Add rice_fog.patch, Reduce flickering when enabling fog in rice
  - Update fix_readpng.patch, Fix FTBFS with libpng14 and remove coding style
    only changes
* Convert to 3.0 (quilt) source format
* Remove outdated README.source
* debian/control:
  - Remove shlibs:Depends for binary packages without shared libs dependencies
  - Remove unneeded build dependency to quilt
  - Upgraded to policy 3.8.4, no changes required
* Correct spelling errors found by lintian
* debian/copyright: Update copyright years
* Check all files ever published on the download page in debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 *   Mupen64plus - plugin.c                                                *
 
3
 *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
 
4
 *   Copyright (C) 2002 Hacktarux                                          *
 
5
 *                                                                         *
 
6
 *   This program is free software; you can redistribute it and/or modify  *
 
7
 *   it under the terms of the GNU General Public License as published by  *
 
8
 *   the Free Software Foundation; either version 2 of the License, or     *
 
9
 *   (at your option) any later version.                                   *
 
10
 *                                                                         *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 
20
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
21
 
 
22
#include <dlfcn.h>
 
23
#include <stdio.h>
 
24
#include <dirent.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
#include <unistd.h>
 
28
#include <limits.h>
 
29
 
 
30
#include "plugin.h"
 
31
#include "main.h"
 
32
#include "util.h"
 
33
#include "rom.h"
 
34
#include "../memory/memory.h"
 
35
#include "../r4300/interupt.h"
 
36
#include "../r4300/r4300.h"
 
37
 
 
38
CONTROL Controls[4];
 
39
 
 
40
static char l_PluginDir[PATH_MAX] = {0};
 
41
 
 
42
static GFX_INFO gfx_info;
 
43
static AUDIO_INFO audio_info;
 
44
static CONTROL_INFO control_info;
 
45
static RSP_INFO rsp_info;
 
46
 
 
47
void (*getDllInfo)(PLUGIN_INFO *PluginInfo);
 
48
void (*dllConfig)(HWND hParent);
 
49
void (*dllTest)(HWND hParent);
 
50
void (*dllAbout)(HWND hParent);
 
51
 
 
52
/* dummy functions to prevent mupen from crashing if a plugin is missing */
 
53
static void dummy_void() {}
 
54
static BOOL dummy_initiateGFX(GFX_INFO Gfx_Info) { return TRUE; }
 
55
static BOOL dummy_initiateAudio(AUDIO_INFO Audio_Info) { return TRUE; }
 
56
static void dummy_initiateControllers(CONTROL_INFO Control_Info) {}
 
57
static void dummy_old_initiateControllers(HWND hMainWindow, CONTROL Controls[4]) {}
 
58
static void dummy_aiDacrateChanged(int SystemType) {}
 
59
static DWORD dummy_aiReadLength() { return 0; }
 
60
static void dummy_setSpeedFactor(int percent) {}
 
61
static const char * dummy_volumeGetString() { return NULL; }
 
62
//static void dummy_aiUpdate(BOOL Wait) {}
 
63
static void dummy_controllerCommand(int Control, BYTE * Command) {}
 
64
static void dummy_getKeys(int Control, BUTTONS *Keys) {}
 
65
static void dummy_readController(int Control, BYTE *Command) {}
 
66
static void dummy_keyDown(WPARAM wParam, LPARAM lParam) {}
 
67
static void dummy_keyUp(WPARAM wParam, LPARAM lParam) {}
 
68
static void dummy_setConfigDir(char *configDir) {}
 
69
static void dummy_setInstallDir(char *installDir) {}
 
70
static unsigned int dummy;
 
71
static DWORD dummy_doRspCycles(DWORD Cycles) { return Cycles; };
 
72
static void dummy_initiateRSP(RSP_INFO Rsp_Info, DWORD * CycleCount) {};
 
73
static void dummy_fBRead(DWORD addr) {};
 
74
static void dummy_fBWrite(DWORD addr, DWORD size) {};
 
75
static void dummy_fBGetFrameBufferInfo(void *p) {};
 
76
 
 
77
void (*changeWindow)() = dummy_void;
 
78
void (*closeDLL_gfx)() = dummy_void;
 
79
BOOL (*initiateGFX)(GFX_INFO Gfx_Info) = dummy_initiateGFX;
 
80
void (*processDList)() = dummy_void;
 
81
void (*processRDPList)() = dummy_void;
 
82
void (*romClosed_gfx)() = dummy_void;
 
83
void (*romOpen_gfx)() = dummy_void;
 
84
void (*showCFB)() = dummy_void;
 
85
void (*updateScreen)() = dummy_void;
 
86
void (*viStatusChanged)() = dummy_void;
 
87
void (*viWidthChanged)() = dummy_void;
 
88
void (*readScreen)(void **dest, int *width, int *height) = 0;
 
89
void (*captureScreen)(char *dirpath) = 0;
 
90
void (*setRenderingCallback)(void (*callback)()) = dummy_void;
 
91
 
 
92
void (*aiDacrateChanged)(int SystemType) = dummy_aiDacrateChanged;
 
93
void (*aiLenChanged)() = dummy_void;
 
94
DWORD (*aiReadLength)() = dummy_aiReadLength;
 
95
//void (*aiUpdate)(BOOL Wait) = dummy_aiUpdate;
 
96
void (*closeDLL_audio)() = dummy_void;
 
97
BOOL (*initiateAudio)(AUDIO_INFO Audio_Info) = dummy_initiateAudio;
 
98
void (*processAList)() = dummy_void;
 
99
void (*romClosed_audio)() = dummy_void;
 
100
void (*romOpen_audio)() = dummy_void;
 
101
void (*setSpeedFactor)(int percent) = dummy_setSpeedFactor;
 
102
void (*volumeUp)() = dummy_void;
 
103
void (*volumeDown)() = dummy_void;
 
104
void (*volumeMute)() = dummy_void;
 
105
const char * (*volumeGetString)() = dummy_volumeGetString;
 
106
 
 
107
void (*closeDLL_input)() = dummy_void;
 
108
void (*controllerCommand)(int Control, BYTE * Command) = dummy_controllerCommand;
 
109
void (*getKeys)(int Control, BUTTONS *Keys) = dummy_getKeys;
 
110
void (*old_initiateControllers)(HWND hMainWindow, CONTROL Controls[4]) = dummy_old_initiateControllers;
 
111
void (*initiateControllers)(CONTROL_INFO ControlInfo) = dummy_initiateControllers;
 
112
void (*readController)(int Control, BYTE *Command) = dummy_readController;
 
113
void (*romClosed_input)() = dummy_void;
 
114
void (*romOpen_input)() = dummy_void;
 
115
void (*keyDown)(WPARAM wParam, LPARAM lParam) = dummy_keyDown;
 
116
void (*keyUp)(WPARAM wParam, LPARAM lParam) = dummy_keyUp;
 
117
void (*setConfigDir)(char *configDir) = dummy_setConfigDir;
 
118
void (*setInstallDir)(char *installDir) = dummy_setInstallDir;
 
119
 
 
120
void (*closeDLL_RSP)() = dummy_void;
 
121
DWORD (*doRspCycles)(DWORD Cycles) = dummy_doRspCycles;
 
122
void (*initiateRSP)(RSP_INFO Rsp_Info, DWORD * CycleCount) = dummy_initiateRSP;
 
123
void (*romClosed_RSP)() = dummy_void;
 
124
 
 
125
void (*fBRead)(DWORD addr) = dummy_fBRead;
 
126
void (*fBWrite)(DWORD addr, DWORD size) = dummy_fBWrite;
 
127
void (*fBGetFrameBufferInfo)(void *p) = dummy_fBGetFrameBufferInfo;
 
128
 
 
129
list_t g_PluginList = NULL;
 
130
 
 
131
HINSTANCE g_ProgramInstance = 0;
 
132
HWND g_RenderWindow = 0;
 
133
HWND g_StatusBar = 0;
 
134
 
 
135
void plugin_delete_list(void)
 
136
{
 
137
    list_node_t *node;
 
138
    plugin *p;
 
139
 
 
140
    list_foreach(g_PluginList, node)
 
141
    {
 
142
        p = (plugin *)node->data;
 
143
        free(p->file_name);
 
144
        free(p->plugin_name);
 
145
        if (p->handle != NULL)
 
146
            dlclose(p->handle);
 
147
    }
 
148
 
 
149
    list_delete(&g_PluginList);
 
150
}
 
151
 
 
152
/* plugin_scan_file
 
153
 *  If given filename is a valid plugin, inserts it into the plugin list and returns TRUE.
 
154
 *   file_name - string containing either full path to plugin file or, if just the filename is given, it is assumed that the
 
155
 *               plugin is in the plugins/ subfolder of the installdir.
 
156
 *   plugin_type - if nonzero, plugin_scan_file will check that the given plugin's type matches plugin_type. If it doesn't, the
 
157
 *                 plugin will not be added to the list.
 
158
 */
 
159
int plugin_scan_file(const char *file_name, WORD plugin_type)
 
160
{
 
161
    PLUGIN_INFO pluginInfo;
 
162
    void *handle;
 
163
    plugin *p;
 
164
    char *bname = NULL;
 
165
    char filepath[PATH_MAX];
 
166
 
 
167
#ifdef __WIN32__
 
168
    snprintf(filepath, PATH_MAX, "%s%s", l_PluginDir, file_name);
 
169
#else
 
170
    if(strstr(file_name, "/"))
 
171
        realpath(file_name, filepath);
 
172
    else
 
173
        strncpy(filepath, file_name, PATH_MAX);
 
174
 
 
175
    // if this is not an absolute path, assume plugin file is in plugin dir
 
176
    if (filepath[0] != '/')
 
177
    {
 
178
        bname = strdup(filepath);
 
179
        basename(bname);
 
180
        snprintf(filepath, PATH_MAX, "%s%s", l_PluginDir, bname);
 
181
        filepath[PATH_MAX-1] = '\0';
 
182
    }
 
183
#endif
 
184
 
 
185
    handle = dlopen(filepath, RTLD_NOW);
 
186
    if(handle)
 
187
    {
 
188
        getDllInfo = dlsym(handle, "GetDllInfo");
 
189
        if(getDllInfo)
 
190
        {
 
191
            getDllInfo(&pluginInfo);
 
192
 
 
193
            if(plugin_type != 0 &&
 
194
               pluginInfo.Type != plugin_type)
 
195
            {
 
196
                printf("Plugin '%s' is the wrong type!\n", file_name);
 
197
                dlclose(handle);
 
198
                return FALSE;
 
199
 
 
200
            }
 
201
            else
 
202
                plugin_type = pluginInfo.Type;
 
203
        }
 
204
        else
 
205
        {
 
206
            puts(dlerror());
 
207
            printf("Plugin '%s' is an invalid plugin\n", file_name);
 
208
            dlclose(handle);
 
209
            return FALSE;
 
210
        }
 
211
    }
 
212
    else
 
213
    {
 
214
        printf("Couldn't load plugin '%s': %s\n", file_name, dlerror());
 
215
        return FALSE;
 
216
    }
 
217
 
 
218
    p = malloc(sizeof(plugin));
 
219
    p->type = plugin_type;
 
220
    p->handle = handle;
 
221
    if(bname)
 
222
        p->file_name = bname;
 
223
    else
 
224
        p->file_name = strdup(file_name);
 
225
    p->plugin_name = strdup(pluginInfo.Name);
 
226
    list_append(&g_PluginList, p);
 
227
 
 
228
    return TRUE;
 
229
}
 
230
 
 
231
/* plugin_scan_directory
 
232
 *
 
233
 *  Populates plugin list with any valid plugins found in the "plugins" folder
 
234
 */
 
235
void plugin_scan_directory(const char *plugindir)
 
236
{
 
237
    DIR *dir;
 
238
    struct dirent *entry;
 
239
#ifdef __WIN32__
 
240
    const char* suffix = ".dll";
 
241
#else
 
242
    const char* suffix = ".so";
 
243
#endif
 
244
 
 
245
    // open the plugins directory and if it's valid, copy it to the static l_PluginDir char array
 
246
    dir = opendir(plugindir);
 
247
    if(dir == NULL)
 
248
    {
 
249
        perror(plugindir);
 
250
        return;
 
251
    }
 
252
    strncpy(l_PluginDir, plugindir, PATH_MAX-2);
 
253
    l_PluginDir[PATH_MAX-2] = 0;
 
254
 
 
255
    // make sure plugin dir has a '/' on the end.
 
256
    if (l_PluginDir[strlen(l_PluginDir)-1] != '/')
 
257
        strcat(l_PluginDir, "/");
 
258
 
 
259
    // look for any shared libraries in this folder, and scan them
 
260
    while((entry = readdir(dir)) != NULL)
 
261
    {
 
262
        if (strcmp(entry->d_name + strlen(entry->d_name) - strlen(suffix), suffix) != 0)
 
263
            continue;
 
264
        
 
265
        plugin_scan_file(entry->d_name, 0);
 
266
    }
 
267
 
 
268
    closedir(dir);
 
269
}
 
270
 
 
271
/* plugin_set_configdir
 
272
 *  Sets config dir of all plugins that support the SetConfigDir API call to the given dir.
 
273
 */
 
274
void plugin_set_dirs(char* configdir, char* installdir)
 
275
{
 
276
    plugin* p = NULL;
 
277
    list_node_t* node;
 
278
 
 
279
    list_foreach(g_PluginList, node)
 
280
        {
 
281
        p = (plugin*)node->data;
 
282
 
 
283
        if(p->handle)
 
284
            {
 
285
            /* If plugin provides ability to set config or install directories, set them. */
 
286
            setConfigDir = dlsym(p->handle, "SetConfigDir");
 
287
            if(setConfigDir)
 
288
                setConfigDir(configdir);
 
289
            setInstallDir = dlsym(p->handle, "SetInstallDir");
 
290
            if(setInstallDir)
 
291
                setInstallDir(installdir);
 
292
        }
 
293
    }
 
294
}
 
295
 
 
296
plugin *plugin_get_by_name(const char *name)
 
297
{
 
298
    plugin *p = NULL;
 
299
    list_node_t *node;
 
300
 
 
301
    list_foreach(g_PluginList, node)
 
302
    {
 
303
        p = (plugin *)node->data;
 
304
        if (!strcmp(p->plugin_name, name))
 
305
            return p;
 
306
    }
 
307
 
 
308
    return NULL;
 
309
}
 
310
 
 
311
char *plugin_filename_by_name(const char *name)
 
312
{
 
313
    plugin *p = plugin_get_by_name(name);
 
314
 
 
315
    if(p) return p->file_name;
 
316
    return NULL;
 
317
}
 
318
 
 
319
char *plugin_name_by_filename(const char *filename)
 
320
{
 
321
    plugin *p;
 
322
    list_node_t *node;
 
323
    char real_filename1[PATH_MAX], real_filename2[PATH_MAX];
 
324
 
 
325
#ifdef __WIN32__
 
326
    strncpy(real_filename1, filename, PATH_MAX);
 
327
#else
 
328
    if (!realpath(filename, real_filename1))
 
329
        strcpy(real_filename1, filename);
 
330
#endif
 
331
 
 
332
    list_foreach(g_PluginList, node)
 
333
    {
 
334
        p = (plugin *)node->data;
 
335
 
 
336
#ifdef __WIN32__
 
337
        strncpy(real_filename2, p->file_name, PATH_MAX);
 
338
#else    
 
339
        if (!realpath(p->file_name, real_filename2))
 
340
            strcpy(real_filename2, p->file_name);
 
341
#endif
 
342
 
 
343
        if (!strcmp(real_filename1, real_filename2))
 
344
            return p->plugin_name;
 
345
    }
 
346
 
 
347
    return NULL;
 
348
}
 
349
 
 
350
static void sucre()
 
351
{
 
352
}
 
353
 
 
354
void plugin_exec_config(const char *name)
 
355
{
 
356
    plugin_exec_config_with_wid(name, 0);
 
357
}
 
358
 
 
359
void plugin_exec_config_with_wid(const char *name, HWND wid)
 
360
{
 
361
    plugin *p = plugin_get_by_name(name);
 
362
 
 
363
    if(p && p->handle)
 
364
    {
 
365
         /* Commenting out since this interferes with Rice's initialization on Linux.
 
366
        Added originally for better win32 compatibility? Not sure why.
 
367
        switch (p->type)
 
368
        {
 
369
            case PLUGIN_TYPE_CONTROLLER:
 
370
                plugin_load_input_plugin(name);
 
371
                break;
 
372
            case PLUGIN_TYPE_RSP:
 
373
                plugin_load_rsp_plugin(name);
 
374
                break;
 
375
            case PLUGIN_TYPE_GFX:
 
376
                plugin_load_gfx_plugin(name);
 
377
                break;
 
378
            case PLUGIN_TYPE_AUDIO:
 
379
                plugin_load_audio_plugin(name);
 
380
                break;
 
381
        }
 
382
       */
 
383
 
 
384
        dllConfig = dlsym(p->handle, "DllConfig");
 
385
        if(dllConfig)
 
386
            dllConfig(wid);
 
387
    }
 
388
}
 
389
 
 
390
void plugin_exec_test(const char *name)
 
391
{
 
392
    plugin_exec_test_with_wid(name, 0);
 
393
}
 
394
 
 
395
void plugin_exec_test_with_wid(const char *name, HWND wid)
 
396
{
 
397
    plugin *p = plugin_get_by_name(name);
 
398
 
 
399
    if(p && p->handle)
 
400
    {
 
401
        dllTest = dlsym(p->handle, "DllTest");
 
402
        if(dllTest)
 
403
            dllTest(wid);
 
404
    }
 
405
}
 
406
 
 
407
void plugin_exec_about(const char *name)
 
408
{
 
409
    plugin_exec_about_with_wid(name, 0);
 
410
}
 
411
 
 
412
void plugin_exec_about_with_wid(const char *name, HWND wid)
 
413
{
 
414
    plugin *p = plugin_get_by_name(name);
 
415
 
 
416
    if(p && p->handle)
 
417
    {
 
418
        dllAbout = dlsym(p->handle, "DllAbout");
 
419
        if(dllAbout)
 
420
            dllAbout(wid);
 
421
    }
 
422
}
 
423
 
 
424
void plugin_load_plugins(const char *gfx_name,
 
425
                         const char *audio_name,
 
426
                         const char *input_name,
 
427
                         const char *RSP_name)
 
428
{
 
429
   plugin_load_gfx_plugin(gfx_name);
 
430
   plugin_load_audio_plugin(audio_name);
 
431
   plugin_load_input_plugin(input_name);
 
432
   plugin_load_rsp_plugin(RSP_name);
 
433
}
 
434
 
 
435
void plugin_load_rsp_plugin(const char* RSP_name)
 
436
{
 
437
       plugin *p;
 
438
   void *handle_RSP = NULL;        
 
439
   
 
440
   p = plugin_get_by_name(RSP_name);
 
441
   if(p) handle_RSP = p->handle;     
 
442
 
 
443
   if (handle_RSP)
 
444
     {
 
445
    closeDLL_RSP = dlsym(handle_RSP, "CloseDLL");
 
446
    doRspCycles = dlsym(handle_RSP, "DoRspCycles");
 
447
    initiateRSP = dlsym(handle_RSP, "InitiateRSP");
 
448
    romClosed_RSP = dlsym(handle_RSP, "RomClosed");
 
449
    
 
450
    if (closeDLL_RSP == NULL) closeDLL_RSP = dummy_void;
 
451
    if (doRspCycles == NULL) doRspCycles = dummy_doRspCycles;
 
452
    if (initiateRSP == NULL) initiateRSP = dummy_initiateRSP;
 
453
    if (romClosed_RSP == NULL) romClosed_RSP = dummy_void;
 
454
    
 
455
    rsp_info.MemoryBswaped = TRUE;
 
456
    rsp_info.RDRAM = (BYTE*)rdram;
 
457
    rsp_info.DMEM = (BYTE*)SP_DMEM;
 
458
    rsp_info.IMEM = (BYTE*)SP_IMEM;
 
459
    rsp_info.MI_INTR_REG = &MI_register.mi_intr_reg;
 
460
    rsp_info.SP_MEM_ADDR_REG = &sp_register.sp_mem_addr_reg;
 
461
    rsp_info.SP_DRAM_ADDR_REG = &sp_register.sp_dram_addr_reg;
 
462
    rsp_info.SP_RD_LEN_REG = &sp_register.sp_rd_len_reg;
 
463
    rsp_info.SP_WR_LEN_REG = &sp_register.sp_wr_len_reg;
 
464
    rsp_info.SP_STATUS_REG = &sp_register.sp_status_reg;
 
465
    rsp_info.SP_DMA_FULL_REG = &sp_register.sp_dma_full_reg;
 
466
    rsp_info.SP_DMA_BUSY_REG = &sp_register.sp_dma_busy_reg;
 
467
    rsp_info.SP_PC_REG = &rsp_register.rsp_pc;
 
468
    rsp_info.SP_SEMAPHORE_REG = &sp_register.sp_semaphore_reg;
 
469
    rsp_info.DPC_START_REG = &dpc_register.dpc_start;
 
470
    rsp_info.DPC_END_REG = &dpc_register.dpc_end;
 
471
    rsp_info.DPC_CURRENT_REG = &dpc_register.dpc_current;
 
472
    rsp_info.DPC_STATUS_REG = &dpc_register.dpc_status;
 
473
    rsp_info.DPC_CLOCK_REG = &dpc_register.dpc_clock;
 
474
    rsp_info.DPC_BUFBUSY_REG = &dpc_register.dpc_bufbusy;
 
475
    rsp_info.DPC_PIPEBUSY_REG = &dpc_register.dpc_pipebusy;
 
476
    rsp_info.DPC_TMEM_REG = &dpc_register.dpc_tmem;
 
477
    rsp_info.CheckInterrupts = sucre;
 
478
    rsp_info.ProcessDlistList = processDList;
 
479
    rsp_info.ProcessAlistList = processAList;
 
480
    rsp_info.ProcessRdpList = processRDPList;
 
481
    rsp_info.ShowCFB = showCFB;
 
482
    rsp_info.hInst = g_ProgramInstance;
 
483
    initiateRSP(rsp_info,(DWORD*) NULL);
 
484
     }
 
485
   else
 
486
     {
 
487
    closeDLL_RSP = dummy_void;
 
488
    doRspCycles = dummy_doRspCycles;
 
489
    initiateRSP = dummy_initiateRSP;
 
490
    romClosed_RSP = dummy_void;
 
491
     }
 
492
}
 
493
 
 
494
void plugin_load_input_plugin(const char* input_name)
 
495
{
 
496
    int i;
 
497
    plugin *p;
 
498
    void *handle_input = NULL;
 
499
    PLUGIN_INFO input_pluginInfo;
 
500
    
 
501
   p = plugin_get_by_name(input_name);
 
502
   if(p) handle_input = p->handle;
 
503
 
 
504
   if (handle_input)
 
505
     {               
 
506
    getDllInfo = dlsym(handle_input, "GetDllInfo");
 
507
    getDllInfo(&input_pluginInfo);
 
508
    closeDLL_input = dlsym(handle_input, "CloseDLL");
 
509
    controllerCommand = dlsym(handle_input, "ControllerCommand");
 
510
    getKeys = dlsym(handle_input, "GetKeys");
 
511
    initiateControllers = dlsym(handle_input, "InitiateControllers");
 
512
    old_initiateControllers = dlsym(handle_input, "InitiateControllers");
 
513
    readController = dlsym(handle_input, "ReadController");
 
514
    romClosed_input = dlsym(handle_input, "RomClosed");
 
515
    romOpen_input = dlsym(handle_input, "RomOpen");
 
516
    keyDown = dlsym(handle_input, "WM_KeyDown");
 
517
    keyUp = dlsym(handle_input, "WM_KeyUp");
 
518
    
 
519
    if (closeDLL_input == NULL) closeDLL_input = dummy_void;
 
520
    if (controllerCommand == NULL) controllerCommand = dummy_controllerCommand;
 
521
    if (getKeys == NULL) getKeys = dummy_getKeys;
 
522
    if (initiateControllers == NULL) initiateControllers = dummy_initiateControllers;
 
523
    if (readController == NULL) readController = dummy_readController;
 
524
    if (romClosed_input == NULL) romClosed_input = dummy_void;
 
525
    if (romOpen_input == NULL) romOpen_input = dummy_void;
 
526
    if (keyDown == NULL) keyDown = dummy_keyDown;
 
527
    if (keyUp == NULL) keyUp = dummy_keyUp;
 
528
    
 
529
    control_info.MemoryBswaped = TRUE;
 
530
    control_info.HEADER = rom;
 
531
    control_info.Controls = Controls;
 
532
    control_info.hMainWindow = g_RenderWindow;
 
533
    control_info.hinst = g_ProgramInstance;
 
534
    for (i=0; i<4; i++)
 
535
      {
 
536
         Controls[i].Present = FALSE;
 
537
         Controls[i].RawData = FALSE;
 
538
         Controls[i].Plugin = PLUGIN_NONE;
 
539
      }
 
540
    if (input_pluginInfo.Version == 0x0101)
 
541
    {
 
542
        initiateControllers(control_info);
 
543
    }
 
544
    else
 
545
    {
 
546
        old_initiateControllers(g_RenderWindow, Controls);
 
547
    }
 
548
     }
 
549
   else
 
550
     {
 
551
    closeDLL_input = dummy_void;
 
552
    controllerCommand = dummy_controllerCommand;
 
553
    getKeys = dummy_getKeys;
 
554
    initiateControllers = dummy_initiateControllers;
 
555
    readController = dummy_readController;
 
556
    romClosed_input = dummy_void;
 
557
    romOpen_input = dummy_void;
 
558
    keyDown = dummy_keyDown;
 
559
    keyUp = dummy_keyUp;
 
560
     }
 
561
}
 
562
 
 
563
void plugin_load_audio_plugin(const char* audio_name)
 
564
{
 
565
   plugin *p;
 
566
   void *handle_audio = NULL;
 
567
 
 
568
   p = plugin_get_by_name(audio_name);
 
569
   if(p) handle_audio = p->handle;
 
570
   
 
571
   if (handle_audio)
 
572
     {
 
573
    closeDLL_audio = dlsym(handle_audio, "CloseDLL");
 
574
    aiDacrateChanged = dlsym(handle_audio, "AiDacrateChanged");
 
575
    aiLenChanged = dlsym(handle_audio, "AiLenChanged");
 
576
    aiReadLength = dlsym(handle_audio, "AiReadLength");
 
577
    //aiUpdate = dlsym(handle_audio, "AiUpdate");
 
578
    initiateAudio = dlsym(handle_audio, "InitiateAudio");
 
579
    processAList = dlsym(handle_audio, "ProcessAList");
 
580
    romClosed_audio = dlsym(handle_audio, "RomClosed");
 
581
    romOpen_audio = dlsym(handle_audio, "RomOpen");
 
582
    setSpeedFactor = dlsym(handle_audio, "SetSpeedFactor");
 
583
    volumeUp = dlsym(handle_audio, "VolumeUp");
 
584
    volumeDown = dlsym(handle_audio, "VolumeDown");
 
585
    volumeMute = dlsym(handle_audio, "VolumeMute");
 
586
    volumeGetString = dlsym(handle_audio, "VolumeGetString");
 
587
    
 
588
    if (aiDacrateChanged == NULL) aiDacrateChanged = dummy_aiDacrateChanged;
 
589
    if (aiLenChanged == NULL) aiLenChanged = dummy_void;
 
590
    if (aiReadLength == NULL) aiReadLength = dummy_aiReadLength;
 
591
    //if (aiUpdate == NULL) aiUpdate = dummy_aiUpdate;
 
592
    if (closeDLL_audio == NULL) closeDLL_audio = dummy_void;
 
593
    if (initiateAudio == NULL) initiateAudio = dummy_initiateAudio;
 
594
    if (processAList == NULL) processAList = dummy_void;
 
595
    if (romClosed_audio == NULL) romClosed_audio = dummy_void;
 
596
    if (romOpen_audio == NULL) romOpen_audio = dummy_void;
 
597
    if (setSpeedFactor == NULL) setSpeedFactor = dummy_setSpeedFactor;
 
598
    if (volumeUp == NULL) volumeUp = dummy_void;
 
599
    if (volumeDown == NULL) volumeDown = dummy_void;
 
600
    if (volumeMute == NULL) volumeMute = dummy_void;
 
601
    if (volumeGetString == NULL) volumeGetString = dummy_volumeGetString;
 
602
    
 
603
    audio_info.MemoryBswaped = TRUE;
 
604
    audio_info.HEADER = rom;
 
605
    audio_info.RDRAM = (BYTE*)rdram;
 
606
    audio_info.DMEM = (BYTE*)SP_DMEM;
 
607
    audio_info.IMEM = (BYTE*)SP_IMEM;
 
608
    audio_info.MI_INTR_REG = &(MI_register.mi_intr_reg);
 
609
    audio_info.AI_DRAM_ADDR_REG = &(ai_register.ai_dram_addr);
 
610
    audio_info.AI_LEN_REG = &(ai_register.ai_len);
 
611
    audio_info.AI_CONTROL_REG = &(ai_register.ai_control);
 
612
    audio_info.AI_STATUS_REG = &dummy;
 
613
    audio_info.AI_DACRATE_REG = &(ai_register.ai_dacrate);
 
614
    audio_info.AI_BITRATE_REG = &(ai_register.ai_bitrate);
 
615
    audio_info.CheckInterrupts = sucre;
 
616
    audio_info.hwnd = g_RenderWindow;
 
617
    audio_info.hinst = g_ProgramInstance;
 
618
    initiateAudio(audio_info);
 
619
     }
 
620
   else
 
621
     {
 
622
    aiDacrateChanged = dummy_aiDacrateChanged;
 
623
    aiLenChanged = dummy_void;
 
624
    aiReadLength = dummy_aiReadLength;
 
625
    //aiUpdate = dummy_aiUpdate;
 
626
    closeDLL_audio = dummy_void;
 
627
    initiateAudio = dummy_initiateAudio;
 
628
    processAList = dummy_void;
 
629
    romClosed_audio = dummy_void;
 
630
    romOpen_audio = dummy_void;
 
631
    setSpeedFactor = dummy_setSpeedFactor;
 
632
     }
 
633
}
 
634
 
 
635
void plugin_load_gfx_plugin(const char* gfx_name)
 
636
{
 
637
   plugin *p;
 
638
   void *handle_gfx = NULL;
 
639
    
 
640
   p = plugin_get_by_name(gfx_name);
 
641
   if(p) handle_gfx = p->handle;
 
642
   
 
643
      if (handle_gfx)
 
644
     {
 
645
    changeWindow = dlsym(handle_gfx, "ChangeWindow");
 
646
    closeDLL_gfx = dlsym(handle_gfx, "CloseDLL");
 
647
    dllAbout = dlsym(handle_gfx, "DllAbout");
 
648
    dllConfig = dlsym(handle_gfx, "DllConfig");
 
649
    dllTest = dlsym(handle_gfx, "DllTest");
 
650
    initiateGFX = dlsym(handle_gfx, "InitiateGFX");
 
651
    processDList = dlsym(handle_gfx, "ProcessDList");
 
652
    processRDPList = dlsym(handle_gfx, "ProcessRDPList");
 
653
    romClosed_gfx = dlsym(handle_gfx, "RomClosed");
 
654
    romOpen_gfx = dlsym(handle_gfx, "RomOpen");
 
655
    showCFB = dlsym(handle_gfx, "ShowCFB");
 
656
    updateScreen = dlsym(handle_gfx, "UpdateScreen");
 
657
    viStatusChanged = dlsym(handle_gfx, "ViStatusChanged");
 
658
    viWidthChanged = dlsym(handle_gfx, "ViWidthChanged");
 
659
    readScreen = dlsym(handle_gfx, "ReadScreen");
 
660
    captureScreen = dlsym(handle_gfx, "CaptureScreen");
 
661
    setRenderingCallback = dlsym(handle_gfx, "SetRenderingCallback");
 
662
    
 
663
    fBRead = dlsym(handle_gfx, "FBRead");
 
664
    fBWrite = dlsym(handle_gfx, "FBWrite");
 
665
    fBGetFrameBufferInfo = dlsym(handle_gfx, "FBGetFrameBufferInfo");
 
666
 
 
667
    if (changeWindow == NULL) changeWindow = dummy_void;
 
668
    if (closeDLL_gfx == NULL) closeDLL_gfx = dummy_void;
 
669
    if (initiateGFX == NULL) initiateGFX = dummy_initiateGFX;
 
670
    if (processDList == NULL) processDList = dummy_void;
 
671
    if (processRDPList == NULL) processRDPList = dummy_void;
 
672
    if (romClosed_gfx == NULL) romClosed_gfx = dummy_void;
 
673
    if (romOpen_gfx == NULL) romOpen_gfx = dummy_void;
 
674
    if (showCFB == NULL) showCFB = dummy_void;
 
675
    if (updateScreen == NULL) updateScreen = dummy_void;
 
676
    if (viStatusChanged == NULL) viStatusChanged = dummy_void;
 
677
    if (viWidthChanged == NULL) viWidthChanged = dummy_void;
 
678
    if (captureScreen == NULL) captureScreen = dummy_void;
 
679
    if (setRenderingCallback == NULL) setRenderingCallback = dummy_void;
 
680
 
 
681
    gfx_info.MemoryBswaped = TRUE;
 
682
    gfx_info.HEADER = rom;
 
683
    gfx_info.RDRAM = (BYTE*)rdram;
 
684
    gfx_info.DMEM = (BYTE*)SP_DMEM;
 
685
    gfx_info.IMEM = (BYTE*)SP_IMEM;
 
686
    gfx_info.MI_INTR_REG = &(MI_register.mi_intr_reg);
 
687
    gfx_info.DPC_START_REG = &(dpc_register.dpc_start);
 
688
    gfx_info.DPC_END_REG = &(dpc_register.dpc_end);
 
689
    gfx_info.DPC_CURRENT_REG = &(dpc_register.dpc_current);
 
690
    gfx_info.DPC_STATUS_REG = &(dpc_register.dpc_status);
 
691
    gfx_info.DPC_CLOCK_REG = &(dpc_register.dpc_clock);
 
692
    gfx_info.DPC_BUFBUSY_REG = &(dpc_register.dpc_bufbusy);
 
693
    gfx_info.DPC_PIPEBUSY_REG = &(dpc_register.dpc_pipebusy);
 
694
    gfx_info.DPC_TMEM_REG = &(dpc_register.dpc_tmem);
 
695
    gfx_info.VI_STATUS_REG = &(vi_register.vi_status);
 
696
    gfx_info.VI_ORIGIN_REG = &(vi_register.vi_origin);
 
697
    gfx_info.VI_WIDTH_REG = &(vi_register.vi_width);
 
698
    gfx_info.VI_INTR_REG = &(vi_register.vi_v_intr);
 
699
    gfx_info.VI_V_CURRENT_LINE_REG = &(vi_register.vi_current);
 
700
    gfx_info.VI_TIMING_REG = &(vi_register.vi_burst);
 
701
    gfx_info.VI_V_SYNC_REG = &(vi_register.vi_v_sync);
 
702
    gfx_info.VI_H_SYNC_REG = &(vi_register.vi_h_sync);
 
703
    gfx_info.VI_LEAP_REG = &(vi_register.vi_leap);
 
704
    gfx_info.VI_H_START_REG = &(vi_register.vi_h_start);
 
705
    gfx_info.VI_V_START_REG = &(vi_register.vi_v_start);
 
706
    gfx_info.VI_V_BURST_REG = &(vi_register.vi_v_burst);
 
707
    gfx_info.VI_X_SCALE_REG = &(vi_register.vi_x_scale);
 
708
    gfx_info.VI_Y_SCALE_REG = &(vi_register.vi_y_scale);
 
709
    gfx_info.CheckInterrupts = sucre;
 
710
    gfx_info.hWnd = g_RenderWindow;
 
711
    gfx_info.hStatusBar = g_StatusBar;
 
712
    initiateGFX(gfx_info);
 
713
     }
 
714
   else
 
715
     {
 
716
    changeWindow = dummy_void;
 
717
    closeDLL_gfx = dummy_void;
 
718
    initiateGFX = dummy_initiateGFX;
 
719
    processDList = dummy_void;
 
720
    processRDPList = dummy_void;
 
721
    romClosed_gfx = dummy_void;
 
722
    romOpen_gfx = dummy_void;
 
723
    showCFB = dummy_void;
 
724
    updateScreen = dummy_void;
 
725
    viStatusChanged = dummy_void;
 
726
    viWidthChanged = dummy_void;
 
727
    readScreen = 0;
 
728
    captureScreen = dummy_void;
 
729
    setRenderingCallback = dummy_void;
 
730
     }
 
731
}
 
732
 
 
733
void plugin_close_plugins()
 
734
{
 
735
    closeDLL_gfx();
 
736
    closeDLL_audio();
 
737
    closeDLL_input();
 
738
    closeDLL_RSP();
 
739
}
 
740