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"
29 #include "arm_features.h"
33 #include "libpicofe/input.h"
34 #include "libpicofe/plat.h"
35 #include "libpicofe/readpng.h"
37 static void toggle_fast_forward(int force_off);
38 static void check_profile(void);
39 static void check_memcards(void);
42 #define BOOT_MSG "Booting up..."
45 // don't include debug.h - it breaks ARM build (R1 redefined)
49 int ready_to_go, g_emu_want_quit, g_emu_resetting;
50 unsigned long gpuDisp;
51 char cfgfile_basename[MAXPATHLEN];
53 enum sched_action emu_action, emu_action_old;
57 static void make_path(char *buf, size_t size, const char *dir, const char *fname)
60 snprintf(buf, size, ".%s%s", dir, fname);
62 snprintf(buf, size, ".%s", dir);
64 #define MAKE_PATH(buf, dir, fname) \
65 make_path(buf, sizeof(buf), dir, fname)
67 static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
71 strncpy(trimlabel, CdromLabel, 32);
73 for (j = 31; j >= 0; j--)
74 if (trimlabel[j] == ' ')
79 snprintf(buf, size, fmt, trimlabel, CdromId, i);
84 void set_cd_image(const char *fname)
86 const char *ext = NULL;
89 ext = strrchr(fname, '.');
92 strcasecmp(ext, ".z") == 0 || strcasecmp(ext, ".bz") == 0 ||
93 strcasecmp(ext, ".znx") == 0 /*|| strcasecmp(ext, ".pbp") == 0*/)) {
95 cdrcimg_set_fname(fname);
96 strcpy(Config.Cdr, "builtin_cdrcimg");
99 strcpy(Config.Cdr, "builtin_cdr");
103 static void set_default_paths(void)
106 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR);
107 MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
108 MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
109 strcpy(Config.BiosDir, "bios");
112 strcpy(Config.PluginsDir, "plugins");
113 strcpy(Config.Gpu, "builtin_gpu");
114 strcpy(Config.Spu, "builtin_spu");
115 strcpy(Config.Cdr, "builtin_cdr");
116 strcpy(Config.Pad1, "builtin_pad");
117 strcpy(Config.Pad2, "builtin_pad");
118 strcpy(Config.Net, "Disabled");
121 void emu_set_default_config(void)
123 // try to set sane config on which most games work
124 Config.Xa = Config.Cdda = Config.Sio =
125 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
128 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
129 pl_rearmed_cbs.gpu_neon.enhancement_enable =
130 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
131 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
132 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
133 pl_rearmed_cbs.gpu_unai.ilace_force = 0;
134 pl_rearmed_cbs.gpu_unai.pixel_skip = 1;
135 pl_rearmed_cbs.gpu_unai.lighting = 1;
136 pl_rearmed_cbs.gpu_unai.fast_lighting = 1;
137 pl_rearmed_cbs.gpu_unai.blending = 1;
138 pl_rearmed_cbs.gpu_unai.dithering = 0;
139 // old gpu_unai config
140 pl_rearmed_cbs.gpu_unai.abe_hack =
141 pl_rearmed_cbs.gpu_unai.no_light =
142 pl_rearmed_cbs.gpu_unai.no_blend = 0;
143 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
144 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
145 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
147 spu_config.iUseReverb = 1;
148 spu_config.idiablofix = 0;
149 spu_config.iUseInterpolation = 1;
150 spu_config.iXAPitch = 0;
151 spu_config.iVolume = 768;
152 spu_config.iTempo = 0;
153 spu_config.iUseThread = 1; // no effect if only 1 core is detected
154 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */
155 spu_config.iUseReverb = 0;
156 spu_config.iUseInterpolation = 0;
157 spu_config.iTempo = 1;
159 new_dynarec_hacks = 0;
160 cycle_multiplier = 200;
162 in_type[0] = PSE_PAD_TYPE_STANDARD;
163 in_type[1] = PSE_PAD_TYPE_STANDARD;
166 void do_emu_action(void)
170 emu_action_old = emu_action;
172 switch (emu_action) {
173 case SACTION_LOAD_STATE:
174 ret = emu_load_state(state_slot);
175 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
177 case SACTION_SAVE_STATE:
178 ret = emu_save_state(state_slot);
179 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
182 case SACTION_ENTER_MENU:
183 toggle_fast_forward(1);
186 case SACTION_NEXT_SSLOT:
191 case SACTION_PREV_SSLOT:
196 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
197 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
199 SysPrintf("* %s\n", hud_msg);
201 case SACTION_TOGGLE_FSKIP:
202 pl_rearmed_cbs.fskip_advice = 0;
203 pl_rearmed_cbs.frameskip++;
204 if (pl_rearmed_cbs.frameskip > 1)
205 pl_rearmed_cbs.frameskip = -1;
206 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
207 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
208 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
209 plugin_call_rearmed_cbs();
211 case SACTION_SWITCH_DISPMODE:
212 pl_switch_dispmode();
213 plugin_call_rearmed_cbs();
214 if (GPU_open != NULL && GPU_close != NULL) {
216 GPU_open(&gpuDisp, "PCSX", NULL);
219 case SACTION_FAST_FORWARD:
220 toggle_fast_forward(0);
221 plugin_call_rearmed_cbs();
223 case SACTION_TOGGLE_FPS:
224 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
225 == (OPT_SHOWFPS|OPT_SHOWCPU))
226 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
227 else if (g_opts & OPT_SHOWFPS)
228 g_opts |= OPT_SHOWCPU;
230 g_opts |= OPT_SHOWFPS;
232 case SACTION_TOGGLE_FULLSCREEN:
233 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
234 if (GPU_open != NULL && GPU_close != NULL) {
236 GPU_open(&gpuDisp, "PCSX", NULL);
239 case SACTION_SCREENSHOT:
241 char buf[MAXPATHLEN];
244 time_t t = time(NULL);
245 struct tm *tb = localtime(&t);
246 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
247 tb->tm_min * 100 + tb->tm_sec;
249 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
250 get_gameid_filename(buf, sizeof(buf),
251 "screenshots/%.32s-%.9s.%d.png", ti);
253 if (scrbuf != 0 && bpp == 16)
254 ret = writepng(buf, scrbuf, w, h);
256 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
259 case SACTION_VOLUME_UP:
260 case SACTION_VOLUME_DOWN:
263 plat_target_step_volume(&volume,
264 emu_action == SACTION_VOLUME_UP ? 1 : -1);
267 case SACTION_MINIMIZE:
268 if (GPU_close != NULL)
273 if (GPU_open != NULL) {
274 ret = GPU_open(&gpuDisp, "PCSX", NULL);
276 SysMessage("GPU_open returned %d", ret);
287 static char basic_lcase(char c)
289 if ('A' <= c && c <= 'Z')
290 return c - 'A' + 'a';
294 static int cdidcmp(const char *id1, const char *id2)
296 while (*id1 != 0 && *id2 != 0) {
297 if (*id1 == '_') { id1++; continue; }
298 if (*id2 == '_') { id2++; continue; }
299 if (basic_lcase(*id1) != basic_lcase(*id2))
308 static void parse_cwcheat(void)
310 char line[256], buf[64], name[64], *p;
315 f = fopen("cheatpops.db", "r");
320 while (fgets(line, sizeof(line), f)) {
321 if (sscanf(line, "_S %63s", buf) != 1)
323 if (cdidcmp(buf, CdromId) == 0)
330 SysPrintf("cwcheat section found for %s\n", CdromId);
331 while (fgets(line, sizeof(line), f))
333 p = line + strlen(line);
334 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
336 if (*p == 0 || *p == '#' || *p == ';')
339 if (strncmp(line, "_S", 2) == 0)
341 if (strncmp(line, "_G", 2) == 0) {
342 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
345 if (strncmp(line, "_C0", 3) == 0) {
346 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
347 SysPrintf("cheat '%s' failed to parse\n", name);
348 free(Cheats[NumCheats - 1].Descr);
351 snprintf(name, sizeof(name), "%s", line + 4);
355 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
356 SysPrintf("line failed to parse: '%s'\n", line);
361 if (NumCheats >= NumCheatsAllocated) {
362 NumCheatsAllocated += 16;
363 Cheats = realloc(Cheats, sizeof(Cheat) *
368 Cheats[NumCheats].Descr = strdup(name);
369 Cheats[NumCheats].Enabled = 0;
370 Cheats[NumCheats].WasEnabled = 0;
371 Cheats[NumCheats].First = NumCodes;
372 Cheats[NumCheats].n = 0;
377 if (NumCodes >= NumCodesAllocated) {
378 NumCodesAllocated += 16;
379 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
381 if (CheatCodes == NULL)
384 CheatCodes[NumCodes].Addr = a;
385 CheatCodes[NumCodes].Val = v;
387 Cheats[NumCheats - 1].n++;
394 void emu_on_new_cd(int show_hud_msg)
400 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
401 SysPrintf("----------------------------------------------------------\n");
405 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
410 int emu_core_preinit(void)
412 // what is the name of the config file?
413 // it may be redefined by -cfg on the command line
414 strcpy(cfgfile_basename, "pcsx.cfg");
417 emuLog = fopen("/User/Documents/pcsxr.log", "w");
419 emuLog = fopen("pcsxr.log", "w");
426 memset(&Config, 0, sizeof(Config));
429 emu_set_default_config();
430 strcpy(Config.Bios, "HLE");
435 int emu_core_init(void)
437 SysPrintf("Starting PCSX-ReARMed " REV "\n");
444 if (EmuInit() == -1) {
445 SysPrintf("PSX emulator couldn't be initialized.\n");
449 LoadMcds(Config.Mcd1, Config.Mcd2);
458 void emu_core_ask_exit(void)
466 #include <sys/stat.h>
467 #include <sys/types.h>
469 static void create_profile_dir(const char *directory) {
470 char path[MAXPATHLEN];
472 MAKE_PATH(path, directory, NULL);
473 mkdir(path, S_IRWXU | S_IRWXG);
476 static void check_profile(void) {
477 // make sure that ~/.pcsx exists
478 create_profile_dir(PCSX_DOT_DIR);
480 create_profile_dir(BIOS_DIR);
481 create_profile_dir(MEMCARD_DIR);
482 create_profile_dir(STATES_DIR);
483 create_profile_dir(PLUGINS_DIR);
484 create_profile_dir(PLUGINS_CFG_DIR);
485 create_profile_dir(CHEATS_DIR);
486 create_profile_dir(PATCHES_DIR);
487 create_profile_dir(PCSX_DOT_DIR "cfg");
488 create_profile_dir("/screenshots/");
491 static void check_memcards(void)
493 char buf[MAXPATHLEN];
497 for (i = 1; i <= 9; i++) {
498 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
500 f = fopen(buf, "rb");
502 SysPrintf("Creating memcard: %s\n", buf);
510 int main(int argc, char *argv[])
512 char file[MAXPATHLEN] = "";
513 char path[MAXPATHLEN];
514 const char *cdfile = NULL;
515 const char *loadst_f = NULL;
522 // read command line options
523 for (i = 1; i < argc; i++) {
524 if (!strcmp(argv[i], "-psxout")) psxout = 1;
525 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
526 else if (!strcmp(argv[i], "-cfg")) {
527 if (i+1 >= argc) break;
528 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
529 SysPrintf("Using config file %s.\n", cfgfile_basename);
531 else if (!strcmp(argv[i], "-cdfile")) {
532 char isofilename[MAXPATHLEN];
534 if (i+1 >= argc) break;
535 strncpy(isofilename, argv[++i], MAXPATHLEN);
536 if (isofilename[0] != '/') {
537 getcwd(path, MAXPATHLEN);
538 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
540 strcat(path, isofilename);
541 strcpy(isofilename, path);
546 cdfile = isofilename;
548 else if (!strcmp(argv[i], "-loadf")) {
549 if (i+1 >= argc) break;
550 loadst_f = argv[++i];
552 else if (!strcmp(argv[i], "-h") ||
553 !strcmp(argv[i], "-help") ||
554 !strcmp(argv[i], "--help")) {
555 printf("PCSX-ReARMed " REV "\n");
557 " pcsx [options] [file]\n"
559 "\t-cdfile FILE\tRuns a CD image file\n"
560 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
561 "\t-psxout\t\tEnable PSX output\n"
562 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
563 "\t-h -help\tDisplay this message\n"
564 "\tfile\t\tLoads a PSX EXE file\n"));
567 strncpy(file, argv[i], MAXPATHLEN);
568 if (file[0] != '/') {
569 getcwd(path, MAXPATHLEN);
570 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
581 set_cd_image(cdfile);
584 // init input but leave probing to platform code,
585 // they add input drivers and may need to modify them after probe
589 menu_init(); // loads config
591 if (emu_core_init() != 0)
597 if (LoadPlugins() == -1) {
598 // FIXME: this recovery doesn't work, just delete bad config and bail out
599 // SysMessage("could not load plugins, retrying with defaults\n");
601 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
603 SysMessage("Failed loading plugins!");
608 if (OpenPlugins() == -1) {
611 plugin_call_rearmed_cbs();
616 if (file[0] != '\0') {
617 if (Load(file) != -1)
621 if (LoadCdrom() == -1) {
623 SysPrintf(_("Could not load CD-ROM!\n"));
626 emu_on_new_cd(!loadst);
632 int ret = LoadState(loadst_f);
633 SysPrintf("%s state file: %s\n",
634 ret ? "failed to load" : "loaded", loadst_f);
635 ready_to_go |= ret == 0;
641 // If a state has been specified, then load that
643 int ret = emu_load_state(loadst - 1);
644 SysPrintf("%s state %d\n",
645 ret ? "failed to load" : "loaded", loadst);
653 while (!g_emu_want_quit)
656 emu_action = SACTION_NONE;
659 if (emu_action != SACTION_NONE)
672 static void toggle_fast_forward(int force_off)
674 static int fast_forward;
675 static int normal_g_opts;
676 static int normal_frameskip;
677 static int normal_enhancement_enable;
679 if (force_off && !fast_forward)
682 fast_forward = !fast_forward;
684 normal_g_opts = g_opts;
685 normal_frameskip = pl_rearmed_cbs.frameskip;
686 normal_enhancement_enable =
687 pl_rearmed_cbs.gpu_neon.enhancement_enable;
689 g_opts |= OPT_NO_FRAMELIM;
690 pl_rearmed_cbs.frameskip = 3;
691 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
693 g_opts = normal_g_opts;
694 pl_rearmed_cbs.frameskip = normal_frameskip;
695 pl_rearmed_cbs.gpu_neon.enhancement_enable =
696 normal_enhancement_enable;
698 pl_timing_prepare(Config.PsxType);
702 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
703 fast_forward ? "ON" : "OFF");
706 static void SignalExit(int sig) {
707 // only to restore framebuffer/resolution on some devices
714 printf("SysRunGui\n");
717 static void dummy_lace()
722 // rearmed hack: EmuReset() runs some code when real BIOS is used,
723 // but we usually do reset from menu while GPU is not open yet,
724 // so we need to prevent updateLace() call..
725 void *real_lace = GPU_updateLace;
726 GPU_updateLace = dummy_lace;
729 // reset can run code, timing must be set
730 pl_timing_prepare(Config.PsxType);
732 // hmh core forgets this
737 GPU_updateLace = real_lace;
747 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
756 int get_state_filename(char *buf, int size, int i) {
757 return get_gameid_filename(buf, size,
758 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
761 int emu_check_state(int slot)
763 char fname[MAXPATHLEN];
766 ret = get_state_filename(fname, sizeof(fname), slot);
770 return CheckState(fname);
773 int emu_save_state(int slot)
775 char fname[MAXPATHLEN];
778 ret = get_state_filename(fname, sizeof(fname), slot);
782 ret = SaveState(fname);
783 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */
786 SysPrintf("* %s \"%s\" [%d]\n",
787 ret == 0 ? "saved" : "failed to save", fname, slot);
791 int emu_load_state(int slot)
793 char fname[MAXPATHLEN];
798 ret = get_state_filename(fname, sizeof(fname), slot);
802 return LoadState(fname);
805 #ifndef HAVE_LIBRETRO
808 void SysPrintf(const char *fmt, ...) {
812 vfprintf(emuLog, fmt, list);
819 #include <android/log.h>
821 void SysPrintf(const char *fmt, ...) {
825 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
830 #endif /* HAVE_LIBRETRO */
832 void SysMessage(const char *fmt, ...) {
838 ret = vsnprintf(msg, sizeof(msg), fmt, list);
841 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
844 SysPrintf("%s\n", msg);
847 #define PARSEPATH(dst, src) \
848 ptr = src + strlen(src); \
849 while (*ptr != '\\' && ptr != src) ptr--; \
851 strcpy(dst, ptr+1); \
854 static int _OpenPlugins(void) {
858 signal(SIGINT, SignalExit);
859 signal(SIGPIPE, SignalExit);
862 GPU_clearDynarec(clearDynarec);
865 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
867 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
868 SPU_registerCallback(SPUirq);
869 SPU_registerScheduleCb(SPUschedule);
870 // pcsx-rearmed: we handle gpu elsewhere
871 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
872 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
873 ret = PAD1_open(&gpuDisp);
874 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
875 ret = PAD2_open(&gpuDisp);
876 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
878 if (Config.UseNet && !NetOpened) {
880 char path[MAXPATHLEN * 2];
881 char dotdir[MAXPATHLEN];
883 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
885 strcpy(info.EmuName, "PCSX");
886 strncpy(info.CdromID, CdromId, 9);
887 strncpy(info.CdromLabel, CdromLabel, 9);
889 info.GPU_showScreenPic = GPU_showScreenPic;
890 info.GPU_displayText = GPU_displayText;
891 info.GPU_showScreenPic = GPU_showScreenPic;
892 info.PAD_setSensitive = PAD1_setSensitive;
893 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
894 strcpy(info.BIOSpath, path);
895 strcpy(info.MCD1path, Config.Mcd1);
896 strcpy(info.MCD2path, Config.Mcd2);
897 sprintf(path, "%s%s", dotdir, Config.Gpu);
898 strcpy(info.GPUpath, path);
899 sprintf(path, "%s%s", dotdir, Config.Spu);
900 strcpy(info.SPUpath, path);
901 sprintf(path, "%s%s", dotdir, Config.Cdr);
902 strcpy(info.CDRpath, path);
905 ret = NET_open(&gpuDisp);
908 // -2 is returned when something in the info
909 // changed and needs to be synced
912 PARSEPATH(Config.Bios, info.BIOSpath);
913 PARSEPATH(Config.Gpu, info.GPUpath);
914 PARSEPATH(Config.Spu, info.SPUpath);
915 PARSEPATH(Config.Cdr, info.CDRpath);
917 strcpy(Config.Mcd1, info.MCD1path);
918 strcpy(Config.Mcd2, info.MCD2path);
921 Config.UseNet = FALSE;
924 if (NET_queryPlayer() == 1) {
925 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
927 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
931 } else if (Config.UseNet) {
941 while ((ret = _OpenPlugins()) == -2) {
943 LoadMcds(Config.Mcd1, Config.Mcd2);
944 if (LoadPlugins() == -1) return -1;
949 void ClosePlugins() {
953 signal(SIGINT, SIG_DFL);
954 signal(SIGPIPE, SIG_DFL);
958 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
960 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
962 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
964 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
965 // pcsx-rearmed: we handle gpu elsewhere
967 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
974 /* we hook statically linked plugins here */
975 static const char *builtin_plugins[] = {
976 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
980 static const int builtin_plugin_ids[] = {
981 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
985 void *SysLoadLibrary(const char *lib) {
986 const char *tmp = strrchr(lib, '/');
990 SysPrintf("plugin: %s\n", lib);
994 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
995 if (strcmp(tmp, builtin_plugins[i]) == 0)
996 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
999 #if !defined(_WIN32) && !defined(NO_DYLIB)
1000 ret = dlopen(lib, RTLD_NOW);
1002 SysMessage("dlopen: %s", dlerror());
1004 /* no external plugin support, abi is no longer
1005 * compatible with psemu/pcsx anyway */
1010 void *SysLoadSym(void *lib, const char *sym) {
1011 unsigned int plugid = (unsigned int)(long)lib;
1013 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1014 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1016 #if !defined(_WIN32) && !defined(NO_DYLIB)
1017 return dlsym(lib, sym);
1023 const char *SysLibError() {
1024 #if defined(NO_DYLIB)
1026 #elif !defined(_WIN32)
1029 return "not supported";
1033 void SysCloseLibrary(void *lib) {
1034 unsigned int plugid = (unsigned int)(long)lib;
1036 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1039 #if !defined(_WIN32) && !defined(NO_DYLIB)