4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
14 #if !defined(_WIN32) && !defined(NO_DYLIB)
20 #include "plugin_lib.h"
24 #include "../libpcsxcore/misc.h"
25 #include "../libpcsxcore/cheat.h"
26 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
27 #include "../plugins/cdrcimg/cdrcimg.h"
28 #include "../plugins/dfsound/spu_config.h"
32 #include "libpicofe/input.h"
33 #include "libpicofe/plat.h"
34 #include "libpicofe/readpng.h"
36 static void toggle_fast_forward(int force_off);
37 static void check_profile(void);
38 static void check_memcards(void);
41 #define BOOT_MSG "Booting up..."
44 // don't include debug.h - it breaks ARM build (R1 redefined)
48 int ready_to_go, g_emu_want_quit, g_emu_resetting;
49 unsigned long gpuDisp;
50 char cfgfile_basename[MAXPATHLEN];
52 enum sched_action emu_action, emu_action_old;
56 static void make_path(char *buf, size_t size, const char *dir, const char *fname)
59 snprintf(buf, size, ".%s%s", dir, fname);
61 snprintf(buf, size, ".%s", dir);
63 #define MAKE_PATH(buf, dir, fname) \
64 make_path(buf, sizeof(buf), dir, fname)
66 static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
70 strncpy(trimlabel, CdromLabel, 32);
72 for (j = 31; j >= 0; j--)
73 if (trimlabel[j] == ' ')
78 snprintf(buf, size, fmt, trimlabel, CdromId, i);
83 void set_cd_image(const char *fname)
85 const char *ext = NULL;
88 ext = strrchr(fname, '.');
91 strcasecmp(ext, ".z") == 0 || strcasecmp(ext, ".bz") == 0 ||
92 strcasecmp(ext, ".znx") == 0 /*|| strcasecmp(ext, ".pbp") == 0*/)) {
94 cdrcimg_set_fname(fname);
95 strcpy(Config.Cdr, "builtin_cdrcimg");
98 strcpy(Config.Cdr, "builtin_cdr");
102 static void set_default_paths(void)
105 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR);
106 MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
107 MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
108 strcpy(Config.BiosDir, "bios");
111 strcpy(Config.PluginsDir, "plugins");
112 strcpy(Config.Gpu, "builtin_gpu");
113 strcpy(Config.Spu, "builtin_spu");
114 strcpy(Config.Cdr, "builtin_cdr");
115 strcpy(Config.Pad1, "builtin_pad");
116 strcpy(Config.Pad2, "builtin_pad");
117 strcpy(Config.Net, "Disabled");
120 void emu_set_default_config(void)
122 // try to set sane config on which most games work
123 Config.Xa = Config.Cdda = Config.Sio =
124 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
127 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
128 pl_rearmed_cbs.gpu_neon.enhancement_enable =
129 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
130 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
131 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
132 pl_rearmed_cbs.gpu_unai.abe_hack =
133 pl_rearmed_cbs.gpu_unai.no_light =
134 pl_rearmed_cbs.gpu_unai.no_blend = 0;
135 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
136 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
137 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
139 spu_config.iUseReverb = 1;
140 spu_config.iUseInterpolation = 1;
141 spu_config.iXAPitch = 0;
142 spu_config.iVolume = 768;
143 spu_config.iTempo = 0;
144 spu_config.iUseThread = 1; // no effect if only 1 core is detected
145 #if defined(__arm__) && !defined(__ARM_ARCH_7A__) /* XXX GPH hack */
146 spu_config.iUseReverb = 0;
147 spu_config.iUseInterpolation = 0;
148 spu_config.iTempo = 1;
150 new_dynarec_hacks = 0;
151 cycle_multiplier = 200;
153 in_type1 = PSE_PAD_TYPE_STANDARD;
154 in_type2 = PSE_PAD_TYPE_STANDARD;
157 void do_emu_action(void)
161 emu_action_old = emu_action;
163 switch (emu_action) {
164 case SACTION_LOAD_STATE:
165 ret = emu_load_state(state_slot);
166 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
168 case SACTION_SAVE_STATE:
169 ret = emu_save_state(state_slot);
170 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
173 case SACTION_ENTER_MENU:
174 toggle_fast_forward(1);
177 case SACTION_NEXT_SSLOT:
182 case SACTION_PREV_SSLOT:
187 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
188 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
190 SysPrintf("* %s\n", hud_msg);
192 case SACTION_TOGGLE_FSKIP:
193 pl_rearmed_cbs.fskip_advice = 0;
194 pl_rearmed_cbs.frameskip++;
195 if (pl_rearmed_cbs.frameskip > 1)
196 pl_rearmed_cbs.frameskip = -1;
197 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
198 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
199 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
200 plugin_call_rearmed_cbs();
202 case SACTION_SWITCH_DISPMODE:
203 pl_switch_dispmode();
204 plugin_call_rearmed_cbs();
205 if (GPU_open != NULL && GPU_close != NULL) {
207 GPU_open(&gpuDisp, "PCSX", NULL);
210 case SACTION_FAST_FORWARD:
211 toggle_fast_forward(0);
212 plugin_call_rearmed_cbs();
214 case SACTION_TOGGLE_FPS:
215 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
216 == (OPT_SHOWFPS|OPT_SHOWCPU))
217 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
218 else if (g_opts & OPT_SHOWFPS)
219 g_opts |= OPT_SHOWCPU;
221 g_opts |= OPT_SHOWFPS;
223 case SACTION_TOGGLE_FULLSCREEN:
224 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
225 if (GPU_open != NULL && GPU_close != NULL) {
227 GPU_open(&gpuDisp, "PCSX", NULL);
230 case SACTION_SCREENSHOT:
232 char buf[MAXPATHLEN];
235 time_t t = time(NULL);
236 struct tm *tb = localtime(&t);
237 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
238 tb->tm_min * 100 + tb->tm_sec;
240 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
241 get_gameid_filename(buf, sizeof(buf),
242 "screenshots/%.32s-%.9s.%d.png", ti);
244 if (scrbuf != 0 && bpp == 16)
245 ret = writepng(buf, scrbuf, w, h);
247 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
250 case SACTION_VOLUME_UP:
251 case SACTION_VOLUME_DOWN:
254 plat_target_step_volume(&volume,
255 emu_action == SACTION_VOLUME_UP ? 1 : -1);
258 case SACTION_MINIMIZE:
259 if (GPU_close != NULL)
264 if (GPU_open != NULL) {
265 ret = GPU_open(&gpuDisp, "PCSX", NULL);
267 SysMessage("GPU_open returned %d", ret);
278 static char basic_lcase(char c)
280 if ('A' <= c && c <= 'Z')
281 return c - 'A' + 'a';
285 static int cdidcmp(const char *id1, const char *id2)
287 while (*id1 != 0 && *id2 != 0) {
288 if (*id1 == '_') { id1++; continue; }
289 if (*id2 == '_') { id2++; continue; }
290 if (basic_lcase(*id1) != basic_lcase(*id2))
299 static void parse_cwcheat(void)
301 char line[256], buf[64], name[64], *p;
306 f = fopen("cheatpops.db", "r");
311 while (fgets(line, sizeof(line), f)) {
312 if (sscanf(line, "_S %63s", buf) != 1)
314 if (cdidcmp(buf, CdromId) == 0)
321 SysPrintf("cwcheat section found for %s\n", CdromId);
322 while (fgets(line, sizeof(line), f))
324 p = line + strlen(line);
325 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
327 if (*p == 0 || *p == '#' || *p == ';')
330 if (strncmp(line, "_S", 2) == 0)
332 if (strncmp(line, "_G", 2) == 0) {
333 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
336 if (strncmp(line, "_C0", 3) == 0) {
337 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
338 SysPrintf("cheat '%s' failed to parse\n", name);
339 free(Cheats[NumCheats - 1].Descr);
342 snprintf(name, sizeof(name), "%s", line + 4);
346 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
347 SysPrintf("line failed to parse: '%s'\n", line);
352 if (NumCheats >= NumCheatsAllocated) {
353 NumCheatsAllocated += 16;
354 Cheats = realloc(Cheats, sizeof(Cheat) *
359 Cheats[NumCheats].Descr = strdup(name);
360 Cheats[NumCheats].Enabled = 0;
361 Cheats[NumCheats].WasEnabled = 0;
362 Cheats[NumCheats].First = NumCodes;
363 Cheats[NumCheats].n = 0;
368 if (NumCodes >= NumCodesAllocated) {
369 NumCodesAllocated += 16;
370 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
372 if (CheatCodes == NULL)
375 CheatCodes[NumCodes].Addr = a;
376 CheatCodes[NumCodes].Val = v;
378 Cheats[NumCheats - 1].n++;
385 void emu_on_new_cd(int show_hud_msg)
391 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
392 SysPrintf("----------------------------------------------------------\n");
396 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
401 int emu_core_preinit(void)
403 // what is the name of the config file?
404 // it may be redefined by -cfg on the command line
405 strcpy(cfgfile_basename, "pcsx.cfg");
408 emuLog = fopen("/User/Documents/pcsxr.log", "w");
410 emuLog = fopen("pcsxr.log", "w");
417 memset(&Config, 0, sizeof(Config));
420 emu_set_default_config();
421 strcpy(Config.Bios, "HLE");
426 int emu_core_init(void)
428 SysPrintf("Starting PCSX-ReARMed " REV "\n");
435 if (EmuInit() == -1) {
436 SysPrintf("PSX emulator couldn't be initialized.\n");
440 LoadMcds(Config.Mcd1, Config.Mcd2);
449 void emu_core_ask_exit(void)
457 #include <sys/stat.h>
458 #include <sys/types.h>
460 static void create_profile_dir(const char *directory) {
461 char path[MAXPATHLEN];
463 MAKE_PATH(path, directory, NULL);
464 mkdir(path, S_IRWXU | S_IRWXG);
467 static void check_profile(void) {
468 // make sure that ~/.pcsx exists
469 create_profile_dir(PCSX_DOT_DIR);
471 create_profile_dir(BIOS_DIR);
472 create_profile_dir(MEMCARD_DIR);
473 create_profile_dir(STATES_DIR);
474 create_profile_dir(PLUGINS_DIR);
475 create_profile_dir(PLUGINS_CFG_DIR);
476 create_profile_dir(CHEATS_DIR);
477 create_profile_dir(PATCHES_DIR);
478 create_profile_dir(PCSX_DOT_DIR "cfg");
479 create_profile_dir("/screenshots/");
482 static void check_memcards(void)
484 char buf[MAXPATHLEN];
488 for (i = 1; i <= 9; i++) {
489 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
491 f = fopen(buf, "rb");
493 SysPrintf("Creating memcard: %s\n", buf);
501 int main(int argc, char *argv[])
503 char file[MAXPATHLEN] = "";
504 char path[MAXPATHLEN];
505 const char *cdfile = NULL;
506 const char *loadst_f = NULL;
513 // read command line options
514 for (i = 1; i < argc; i++) {
515 if (!strcmp(argv[i], "-psxout")) psxout = 1;
516 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
517 else if (!strcmp(argv[i], "-cfg")) {
518 if (i+1 >= argc) break;
519 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
520 SysPrintf("Using config file %s.\n", cfgfile_basename);
522 else if (!strcmp(argv[i], "-cdfile")) {
523 char isofilename[MAXPATHLEN];
525 if (i+1 >= argc) break;
526 strncpy(isofilename, argv[++i], MAXPATHLEN);
527 if (isofilename[0] != '/') {
528 getcwd(path, MAXPATHLEN);
529 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
531 strcat(path, isofilename);
532 strcpy(isofilename, path);
537 cdfile = isofilename;
539 else if (!strcmp(argv[i], "-loadf")) {
540 if (i+1 >= argc) break;
541 loadst_f = argv[++i];
543 else if (!strcmp(argv[i], "-h") ||
544 !strcmp(argv[i], "-help") ||
545 !strcmp(argv[i], "--help")) {
546 printf("PCSX-ReARMed " REV "\n");
548 " pcsx [options] [file]\n"
550 "\t-cdfile FILE\tRuns a CD image file\n"
551 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
552 "\t-psxout\t\tEnable PSX output\n"
553 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
554 "\t-h -help\tDisplay this message\n"
555 "\tfile\t\tLoads a PSX EXE file\n"));
558 strncpy(file, argv[i], MAXPATHLEN);
559 if (file[0] != '/') {
560 getcwd(path, MAXPATHLEN);
561 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
572 set_cd_image(cdfile);
575 // init input but leave probing to platform code,
576 // they add input drivers and may need to modify them after probe
580 menu_init(); // loads config
582 if (emu_core_init() != 0)
588 if (LoadPlugins() == -1) {
589 // FIXME: this recovery doesn't work, just delete bad config and bail out
590 // SysMessage("could not load plugins, retrying with defaults\n");
592 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
594 SysMessage("Failed loading plugins!");
599 if (OpenPlugins() == -1) {
602 plugin_call_rearmed_cbs();
607 if (file[0] != '\0') {
608 if (Load(file) != -1)
612 if (LoadCdrom() == -1) {
614 SysPrintf(_("Could not load CD-ROM!\n"));
617 emu_on_new_cd(!loadst);
623 int ret = LoadState(loadst_f);
624 SysPrintf("%s state file: %s\n",
625 ret ? "failed to load" : "loaded", loadst_f);
626 ready_to_go |= ret == 0;
632 // If a state has been specified, then load that
634 int ret = emu_load_state(loadst - 1);
635 SysPrintf("%s state %d\n",
636 ret ? "failed to load" : "loaded", loadst);
644 while (!g_emu_want_quit)
647 emu_action = SACTION_NONE;
650 if (emu_action != SACTION_NONE)
663 static void toggle_fast_forward(int force_off)
665 static int fast_forward;
666 static int normal_g_opts;
667 static int normal_frameskip;
668 static int normal_enhancement_enable;
670 if (force_off && !fast_forward)
673 fast_forward = !fast_forward;
675 normal_g_opts = g_opts;
676 normal_frameskip = pl_rearmed_cbs.frameskip;
677 normal_enhancement_enable =
678 pl_rearmed_cbs.gpu_neon.enhancement_enable;
680 g_opts |= OPT_NO_FRAMELIM;
681 pl_rearmed_cbs.frameskip = 3;
682 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
684 g_opts = normal_g_opts;
685 pl_rearmed_cbs.frameskip = normal_frameskip;
686 pl_rearmed_cbs.gpu_neon.enhancement_enable =
687 normal_enhancement_enable;
689 pl_timing_prepare(Config.PsxType);
693 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
694 fast_forward ? "ON" : "OFF");
697 static void SignalExit(int sig) {
698 // only to restore framebuffer/resolution on some devices
705 printf("SysRunGui\n");
708 static void dummy_lace()
713 // rearmed hack: EmuReset() runs some code when real BIOS is used,
714 // but we usually do reset from menu while GPU is not open yet,
715 // so we need to prevent updateLace() call..
716 void *real_lace = GPU_updateLace;
717 GPU_updateLace = dummy_lace;
720 // reset can run code, timing must be set
721 pl_timing_prepare(Config.PsxType);
725 // hmh core forgets this
728 GPU_updateLace = real_lace;
738 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
747 int get_state_filename(char *buf, int size, int i) {
748 return get_gameid_filename(buf, size,
749 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
752 int emu_check_state(int slot)
754 char fname[MAXPATHLEN];
757 ret = get_state_filename(fname, sizeof(fname), slot);
761 return CheckState(fname);
764 int emu_save_state(int slot)
766 char fname[MAXPATHLEN];
769 ret = get_state_filename(fname, sizeof(fname), slot);
773 ret = SaveState(fname);
774 #if defined(__arm__) && !defined(__ARM_ARCH_7A__) && !defined(_3DS) /* XXX GPH hack */
777 SysPrintf("* %s \"%s\" [%d]\n",
778 ret == 0 ? "saved" : "failed to save", fname, slot);
782 int emu_load_state(int slot)
784 char fname[MAXPATHLEN];
789 ret = get_state_filename(fname, sizeof(fname), slot);
793 return LoadState(fname);
798 void SysPrintf(const char *fmt, ...) {
802 vfprintf(emuLog, fmt, list);
809 #include <android/log.h>
811 void SysPrintf(const char *fmt, ...) {
815 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
821 void SysMessage(const char *fmt, ...) {
827 ret = vsnprintf(msg, sizeof(msg), fmt, list);
830 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
833 SysPrintf("%s\n", msg);
836 #define PARSEPATH(dst, src) \
837 ptr = src + strlen(src); \
838 while (*ptr != '\\' && ptr != src) ptr--; \
840 strcpy(dst, ptr+1); \
843 static int _OpenPlugins(void) {
847 signal(SIGINT, SignalExit);
848 signal(SIGPIPE, SignalExit);
851 GPU_clearDynarec(clearDynarec);
854 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
856 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
857 SPU_registerCallback(SPUirq);
858 SPU_registerScheduleCb(SPUschedule);
859 // pcsx-rearmed: we handle gpu elsewhere
860 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
861 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
862 ret = PAD1_open(&gpuDisp);
863 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
864 ret = PAD2_open(&gpuDisp);
865 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
867 if (Config.UseNet && !NetOpened) {
869 char path[MAXPATHLEN];
870 char dotdir[MAXPATHLEN];
872 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
874 strcpy(info.EmuName, "PCSX");
875 strncpy(info.CdromID, CdromId, 9);
876 strncpy(info.CdromLabel, CdromLabel, 9);
878 info.GPU_showScreenPic = GPU_showScreenPic;
879 info.GPU_displayText = GPU_displayText;
880 info.GPU_showScreenPic = GPU_showScreenPic;
881 info.PAD_setSensitive = PAD1_setSensitive;
882 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
883 strcpy(info.BIOSpath, path);
884 strcpy(info.MCD1path, Config.Mcd1);
885 strcpy(info.MCD2path, Config.Mcd2);
886 sprintf(path, "%s%s", dotdir, Config.Gpu);
887 strcpy(info.GPUpath, path);
888 sprintf(path, "%s%s", dotdir, Config.Spu);
889 strcpy(info.SPUpath, path);
890 sprintf(path, "%s%s", dotdir, Config.Cdr);
891 strcpy(info.CDRpath, path);
894 ret = NET_open(&gpuDisp);
897 // -2 is returned when something in the info
898 // changed and needs to be synced
901 PARSEPATH(Config.Bios, info.BIOSpath);
902 PARSEPATH(Config.Gpu, info.GPUpath);
903 PARSEPATH(Config.Spu, info.SPUpath);
904 PARSEPATH(Config.Cdr, info.CDRpath);
906 strcpy(Config.Mcd1, info.MCD1path);
907 strcpy(Config.Mcd2, info.MCD2path);
910 Config.UseNet = FALSE;
913 if (NET_queryPlayer() == 1) {
914 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
916 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
920 } else if (Config.UseNet) {
930 while ((ret = _OpenPlugins()) == -2) {
932 LoadMcds(Config.Mcd1, Config.Mcd2);
933 if (LoadPlugins() == -1) return -1;
938 void ClosePlugins() {
942 signal(SIGINT, SIG_DFL);
943 signal(SIGPIPE, SIG_DFL);
947 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
949 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
951 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
953 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
954 // pcsx-rearmed: we handle gpu elsewhere
956 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
963 /* we hook statically linked plugins here */
964 static const char *builtin_plugins[] = {
965 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
969 static const int builtin_plugin_ids[] = {
970 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
974 void *SysLoadLibrary(const char *lib) {
975 const char *tmp = strrchr(lib, '/');
979 SysPrintf("plugin: %s\n", lib);
983 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
984 if (strcmp(tmp, builtin_plugins[i]) == 0)
985 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
988 #if !defined(_WIN32) && !defined(NO_DYLIB)
989 ret = dlopen(lib, RTLD_NOW);
991 SysMessage("dlopen: %s", dlerror());
993 /* no external plugin support, abi is no longer
994 * compatible with psemu/pcsx anyway */
999 void *SysLoadSym(void *lib, const char *sym) {
1000 unsigned int plugid = (unsigned int)(long)lib;
1002 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1003 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1005 #if !defined(_WIN32) && !defined(NO_DYLIB)
1006 return dlsym(lib, sym);
1012 const char *SysLibError() {
1013 #if defined(NO_DYLIB)
1015 #elif !defined(_WIN32)
1018 return "not supported";
1022 void SysCloseLibrary(void *lib) {
1023 unsigned int plugid = (unsigned int)(long)lib;
1025 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1028 #if !defined(_WIN32) && !defined(NO_DYLIB)