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)
18 #include "../frontend/libretro-rthreads.h"
23 #include "plugin_lib.h"
27 #include "../libpcsxcore/misc.h"
28 #include "../libpcsxcore/cheat.h"
29 #include "../libpcsxcore/sio.h"
30 #include "../libpcsxcore/database.h"
31 #include "../libpcsxcore/cdrom-async.h"
32 #include "../libpcsxcore/new_dynarec/new_dynarec.h"
33 #include "../plugins/cdrcimg/cdrcimg.h"
34 #include "../plugins/dfsound/spu_config.h"
35 #include "arm_features.h"
38 #if defined(__EMSCRIPTEN__)
39 #define DO_CPU_CHECKS 0
40 #elif defined(__has_builtin)
41 #define DO_CPU_CHECKS __has_builtin(__builtin_cpu_init)
42 #elif defined(__x86_64__) || defined(__i386__)
43 #define DO_CPU_CHECKS 1
45 #define DO_CPU_CHECKS 0
50 #include "libpicofe/input.h"
51 #include "libpicofe/plat.h"
52 #include "libpicofe/readpng.h"
54 static void toggle_fast_forward(int force_off);
55 static void check_profile(void);
56 static void check_memcards(void);
57 static int get_gameid_filename(char *buf, int size, const char *fmt, int i);
58 static const char *get_home_dir(void);
59 #define MAKE_PATH(buf, dir, fname) \
60 emu_make_path(buf, sizeof(buf), dir, fname)
64 #define BOOT_MSG "Booting up..."
67 // don't include debug.h - it breaks ARM build (R1 redefined)
68 static void StartDebugger() {}
69 static void StopDebugger() {}
71 int ready_to_go, g_emu_want_quit, g_emu_resetting;
72 unsigned long gpuDisp;
73 char cfgfile_basename[MAXPATHLEN];
75 enum sched_action emu_action, emu_action_old;
79 void set_cd_image(const char *fname)
84 static void set_default_paths(void)
87 const char *home = get_home_dir();
89 MAKE_PATH(Config.PatchesDir, PATCHES_DIR, NULL);
90 MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
91 MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
92 MAKE_PATH(Config.BiosDir, BIOS_DIR, NULL);
94 emu_make_data_path(Config.PluginsDir, "plugins", sizeof(Config.PluginsDir));
96 // prefer bios in working dir for compatibility
97 if (!strcmp(home, ".") && !stat("bios", &st))
98 strcpy(Config.BiosDir, "bios");
100 SysPrintf("dirs: profile=%s" PCSX_DOT_DIR ", bios=%s, plugins=%s\n",
101 home, Config.BiosDir, Config.PluginsDir);
104 strcpy(Config.Gpu, "builtin_gpu");
105 strcpy(Config.Spu, "builtin_spu");
108 void emu_set_default_config(void)
110 // try to set sane config on which most games work
111 Config.Xa = Config.Cdda = 0;
112 Config.icache_emulation = 0;
114 Config.cycle_multiplier = CYCLE_MULT_DEFAULT;
115 Config.GpuListWalking = -1;
116 Config.FractionalFramerate = -1;
118 pl_rearmed_cbs.dithering = 1;
119 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
120 pl_rearmed_cbs.gpu_neon.enhancement_enable =
121 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
122 pl_rearmed_cbs.gpu_neon.enhancement_tex_adj = 1;
123 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
124 pl_rearmed_cbs.gpu_unai.old_renderer = 0;
125 pl_rearmed_cbs.gpu_unai.ilace_force = 0;
126 pl_rearmed_cbs.gpu_unai.lighting = 1;
127 pl_rearmed_cbs.gpu_unai.fast_lighting = 0;
128 pl_rearmed_cbs.gpu_unai.blending = 1;
129 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
130 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
131 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
133 spu_config.iUseReverb = 1;
134 spu_config.iUseInterpolation = 1;
135 spu_config.iXAPitch = 0;
136 spu_config.iVolume = 768;
137 spu_config.iTempo = 0;
138 // may cause issues, no effect if only 1 core is detected
139 spu_config.iUseThread = 0;
140 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */
141 spu_config.iUseReverb = 0;
142 spu_config.iUseInterpolation = 0;
143 #ifndef HAVE_LIBRETRO
144 spu_config.iTempo = 1;
149 in_type[0] = PSE_PAD_TYPE_STANDARD;
150 in_type[1] = PSE_PAD_TYPE_STANDARD;
155 void do_emu_action(void)
159 emu_action_old = emu_action;
161 switch (emu_action) {
162 case SACTION_LOAD_STATE:
163 ret = emu_load_state(state_slot);
164 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
166 case SACTION_SAVE_STATE:
167 ret = emu_save_state(state_slot);
168 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
170 case SACTION_ENTER_MENU:
171 toggle_fast_forward(1);
174 case SACTION_NEXT_SSLOT:
179 case SACTION_PREV_SSLOT:
184 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
185 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
187 SysPrintf("* %s\n", hud_msg);
189 case SACTION_TOGGLE_FSKIP:
190 pl_rearmed_cbs.fskip_advice = 0;
191 pl_rearmed_cbs.frameskip++;
192 if (pl_rearmed_cbs.frameskip > 1)
193 pl_rearmed_cbs.frameskip = -1;
194 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
195 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
196 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
197 plugin_call_rearmed_cbs();
199 case SACTION_SWITCH_DISPMODE:
200 pl_switch_dispmode();
201 plugin_call_rearmed_cbs();
202 if (GPU_open != NULL && GPU_close != NULL) {
204 GPU_open(&gpuDisp, "PCSX", NULL);
207 case SACTION_FAST_FORWARD:
208 toggle_fast_forward(0);
209 plugin_call_rearmed_cbs();
211 case SACTION_TOGGLE_FPS:
212 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
213 == (OPT_SHOWFPS|OPT_SHOWCPU))
214 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
215 else if (g_opts & OPT_SHOWFPS)
216 g_opts |= OPT_SHOWCPU;
218 g_opts |= OPT_SHOWFPS;
220 case SACTION_TOGGLE_FULLSCREEN:
221 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
222 if (GPU_open != NULL && GPU_close != NULL) {
224 GPU_open(&gpuDisp, "PCSX", NULL);
227 case SACTION_SCREENSHOT:
229 char buf[MAXPATHLEN];
232 time_t t = time(NULL);
233 struct tm *tb = localtime(&t);
234 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
235 tb->tm_min * 100 + tb->tm_sec;
237 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
238 get_gameid_filename(buf, sizeof(buf),
239 "%s" SCREENSHOTS_DIR "%.32s-%.9s.%d.png", ti);
241 if (scrbuf != 0 && bpp == 16)
242 ret = writepng(buf, scrbuf, w, h);
244 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
246 SysPrintf("writepng %s: %d\n", buf, ret);
249 case SACTION_VOLUME_UP:
250 case SACTION_VOLUME_DOWN:
253 plat_target_step_volume(&volume,
254 emu_action == SACTION_VOLUME_UP ? 1 : -1);
257 case SACTION_MINIMIZE:
258 if (GPU_close != NULL)
263 if (GPU_open != NULL) {
264 ret = GPU_open(&gpuDisp, "PCSX", NULL);
266 SysMessage("GPU_open returned %d", ret);
269 case SACTION_ANALOG_TOGGLE:
270 ret = padToggleAnalog(0);
271 snprintf(hud_msg, sizeof(hud_msg), "ANALOG %s", ret ? "ON" : "OFF");
282 static char basic_lcase(char c)
284 if ('A' <= c && c <= 'Z')
285 return c - 'A' + 'a';
289 static int cdidcmp(const char *id1, const char *id2)
291 while (*id1 != 0 && *id2 != 0) {
292 if (*id1 == '_') { id1++; continue; }
293 if (*id2 == '_') { id2++; continue; }
294 if (basic_lcase(*id1) != basic_lcase(*id2))
303 static void parse_cwcheat(void)
305 char line[256], buf[256], name[256], *p;
310 f = fopen("cheatpops.db", "r");
315 while (fgets(line, sizeof(line), f)) {
316 if (sscanf(line, "_S %63s", buf) != 1)
318 if (cdidcmp(buf, CdromId) == 0)
325 SysPrintf("cwcheat section found for %s\n", CdromId);
326 while (fgets(line, sizeof(line), f))
328 p = line + strlen(line);
329 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
331 if (*p == 0 || *p == '#' || *p == ';')
334 if (strncmp(line, "_S", 2) == 0)
336 if (strncmp(line, "_G", 2) == 0) {
337 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
340 if (strncmp(line, "_C0", 3) == 0) {
341 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
342 SysPrintf("cheat '%s' failed to parse\n", name);
343 free(Cheats[NumCheats - 1].Descr);
346 snprintf(name, sizeof(name), "%s", line + 4);
350 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
351 SysPrintf("line failed to parse: '%s'\n", line);
356 if (NumCheats >= NumCheatsAllocated) {
357 NumCheatsAllocated += 16;
358 Cheats = realloc(Cheats, sizeof(Cheat) *
363 Cheats[NumCheats].Descr = strdup(name);
364 Cheats[NumCheats].Enabled = 0;
365 Cheats[NumCheats].WasEnabled = 0;
366 Cheats[NumCheats].First = NumCodes;
367 Cheats[NumCheats].n = 0;
372 if (NumCodes >= NumCodesAllocated) {
373 NumCodesAllocated += 16;
374 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
376 if (CheatCodes == NULL)
379 CheatCodes[NumCodes].Addr = a;
380 CheatCodes[NumCodes].Val = v;
382 Cheats[NumCheats - 1].n++;
389 void emu_on_new_cd(int show_hud_msg)
395 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
396 SysPrintf("----------------------------------------------------------\n");
399 SysPrintf("note: TurboCD is enabled, this breaks games\n");
402 if (check_unsatisfied_libcrypt())
403 snprintf(hud_msg, sizeof(hud_msg),
404 "LibCrypt protected game with missing SBI detected");
406 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
411 static void log_wrong_cpu(void)
414 __builtin_cpu_init();
415 #define CHECK_CPU(name) if (!__builtin_cpu_supports(name)) \
416 SysPrintf("ERROR: compiled for " name ", which is unsupported by the CPU\n")
426 #endif // DO_CPU_CHECKS
429 int emu_core_preinit(void)
431 // what is the name of the config file?
432 // it may be redefined by -cfg on the command line
433 strcpy(cfgfile_basename, "pcsx.cfg");
436 emuLog = fopen("/User/Documents/pcsxr.log", "w");
438 emuLog = fopen("pcsxr.log", "w");
447 memset(&Config, 0, sizeof(Config));
450 emu_set_default_config();
451 strcpy(Config.Bios, "HLE");
456 int emu_core_init(void)
458 SysPrintf("Starting PCSX-ReARMed " REV " (%s)\n", get_build_info());
459 SysPrintf("build time: " __DATE__ " " __TIME__ "\n");
461 #if defined(__arm__) && defined(__ARM_FP)
464 __asm__ volatile("vmrs %0, fpscr" : "=r"(fpscr));
465 SysPrintf("old fpscr = %08x\n", fpscr);
466 fpscr &= ~0x00009f9f;
467 fpscr |= 0x03000000; // DN | FZ
468 __asm__ volatile("vmsr fpscr, %0" :: "r"(fpscr));
472 pcsxr_sthread_init();
479 if (EmuInit() == -1) {
480 SysPrintf("PSX emulator couldn't be initialized.\n");
484 LoadMcds(Config.Mcd1, Config.Mcd2);
493 void emu_core_ask_exit(void)
501 #include <sys/stat.h>
502 #include <sys/types.h>
504 static const char *get_home_dir(void)
506 #if defined(PANDORA) || !defined(__unix__)
509 static const char *home = NULL;
513 // for compatibility with older versions, look for .pcsx in the working dir
514 if (stat(PCSX_DOT_DIR + 1, &st) != 0)
515 home = getenv("HOME");
522 void emu_make_path(char *buf, size_t size, const char *dir, const char *fname)
524 const char *home = get_home_dir();
526 snprintf(buf, size, "%s%s%s", home, dir, fname);
528 snprintf(buf, size, "%s%s", home, dir);
531 void emu_make_data_path(char *buff, const char *end, int size)
535 end_len = strlen(end);
536 pos = plat_get_root_dir(buff, size);
537 strncpy(buff + pos, end, size - pos);
539 if (pos + end_len > size - 1)
540 printf("Warning: path truncated: %s\n", buff);
543 static void create_profile_dir(const char *directory) {
544 char path[MAXPATHLEN];
546 MAKE_PATH(path, directory, NULL);
547 mkdir(path, S_IRWXU | S_IRWXG);
550 static void check_profile(void) {
551 // make sure that ~/.pcsx exists
552 create_profile_dir(PCSX_DOT_DIR);
554 create_profile_dir(BIOS_DIR);
555 create_profile_dir(MEMCARD_DIR);
556 create_profile_dir(STATES_DIR);
557 create_profile_dir(CHEATS_DIR);
558 create_profile_dir(PATCHES_DIR);
559 create_profile_dir(CFG_DIR);
560 create_profile_dir(SCREENSHOTS_DIR);
563 static void check_memcards(void)
565 char buf[MAXPATHLEN];
569 for (i = 1; i <= 9; i++) {
570 snprintf(buf, sizeof(buf), "%s%scard%d.mcd",
571 get_home_dir(), MEMCARD_DIR, i);
573 f = fopen(buf, "rb");
575 SysPrintf("Creating memcard: %s\n", buf);
583 int main(int argc, char *argv[])
585 char file[MAXPATHLEN] = "";
586 char path[MAXPATHLEN];
587 char isofilename[MAXPATHLEN];
588 const char *cdfile = NULL;
589 const char *loadst_f = NULL;
596 // read command line options
597 for (i = 1; i < argc; i++) {
598 if (!strcmp(argv[i], "-psxout")) psxout = 1;
599 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
600 else if (!strcmp(argv[i], "-cfg")) {
601 if (i+1 >= argc) break;
602 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
603 SysPrintf("Using config file %s.\n", cfgfile_basename);
605 else if (!strcmp(argv[i], "-cdfile")) {
606 if (i+1 >= argc) break;
607 strncpy(isofilename, argv[++i], MAXPATHLEN);
608 if (isofilename[0] != '/') {
609 getcwd(path, MAXPATHLEN);
610 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
612 strcat(path, isofilename);
613 strcpy(isofilename, path);
618 cdfile = isofilename;
620 else if (!strcmp(argv[i], "-loadf")) {
621 if (i+1 >= argc) break;
622 loadst_f = argv[++i];
624 else if (!strcmp(argv[i], "-h") ||
625 !strcmp(argv[i], "-help") ||
626 !strcmp(argv[i], "--help")) {
627 printf("PCSX-ReARMed " REV "\n");
629 " pcsx [options] [file]\n"
631 "\t-cdfile FILE\tRuns a CD image file\n"
632 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
633 "\t-psxout\t\tEnable PSX output\n"
634 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
635 "\t-h -help\tDisplay this message\n"
636 "\tfile\t\tLoads a PSX EXE file\n"));
639 strncpy(file, argv[i], MAXPATHLEN);
640 if (file[0] != '/') {
641 getcwd(path, MAXPATHLEN);
642 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
653 set_cd_image(cdfile);
656 // init input but leave probing to platform code,
657 // they add input drivers and may need to modify them after probe
661 menu_init(); // loads config
663 if (emu_core_init() != 0)
669 if (LoadPlugins() == -1) {
670 // FIXME: this recovery doesn't work, just delete bad config and bail out
671 // SysMessage("could not load plugins, retrying with defaults\n");
673 snprintf(path, sizeof(path), "%s" PCSX_DOT_DIR "%s",
674 get_home_dir(), cfgfile_basename);
676 SysMessage("Failed loading plugins!");
681 if (OpenPlugins() == -1) {
686 plugin_call_rearmed_cbs();
689 if (file[0] != '\0') {
690 if (Load(file) != -1)
694 if (LoadCdrom() == -1) {
696 SysPrintf(_("Could not load CD-ROM!\n"));
699 emu_on_new_cd(!loadst);
705 int ret = LoadState(loadst_f);
706 SysPrintf("%s state file: %s\n",
707 ret ? "failed to load" : "loaded", loadst_f);
708 ready_to_go |= ret == 0;
712 if (menu_load_config(1) != 0)
716 // If a state has been specified, then load that
718 int ret = emu_load_state(loadst - 1);
719 SysPrintf("%s state %d\n",
720 ret ? "failed to load" : "loaded", loadst);
726 #ifndef LIGHTREC_DEBUG
730 while (!g_emu_want_quit)
733 emu_action = SACTION_NONE;
735 psxCpu->Execute(&psxRegs);
736 if (emu_action != SACTION_NONE)
749 static void toggle_fast_forward(int force_off)
751 static int fast_forward;
752 static int normal_g_opts;
753 static int normal_enhancement_enable;
754 //static int normal_frameskip;
756 if (force_off && !fast_forward)
759 fast_forward = !fast_forward;
761 normal_g_opts = g_opts;
762 //normal_frameskip = pl_rearmed_cbs.frameskip;
763 normal_enhancement_enable =
764 pl_rearmed_cbs.gpu_neon.enhancement_enable;
766 g_opts |= OPT_NO_FRAMELIM;
767 // pl_rearmed_cbs.frameskip = 3; // too broken
768 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
770 g_opts = normal_g_opts;
771 //pl_rearmed_cbs.frameskip = normal_frameskip;
772 pl_rearmed_cbs.gpu_neon.enhancement_enable =
773 normal_enhancement_enable;
775 pl_timing_prepare(Config.PsxType);
779 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
780 fast_forward ? "ON" : "OFF");
783 static void SignalExit(int sig) {
784 SysPrintf("got signal %d\n", sig);
785 // only to restore framebuffer/resolution on some devices
790 static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
794 strncpy(trimlabel, CdromLabel, 32);
796 for (j = 31; j >= 0; j--)
797 if (trimlabel[j] == ' ')
802 snprintf(buf, size, fmt, get_home_dir(), trimlabel, CdromId, i);
807 int get_state_filename(char *buf, int size, int i) {
808 return get_gameid_filename(buf, size,
809 "%s" STATES_DIR "%.32s-%.9s.%3.3d", i);
812 int emu_check_state(int slot)
814 char fname[MAXPATHLEN];
817 ret = get_state_filename(fname, sizeof(fname), slot);
821 return CheckState(fname);
824 int emu_save_state(int slot)
826 char fname[MAXPATHLEN];
829 ret = get_state_filename(fname, sizeof(fname), slot);
833 ret = SaveState(fname);
834 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */
837 SysPrintf("* %s \"%s\" [%d]\n",
838 ret == 0 ? "saved" : "failed to save", fname, slot);
842 int emu_load_state(int slot)
844 char fname[MAXPATHLEN];
849 ret = get_state_filename(fname, sizeof(fname), slot);
853 return LoadState(fname);
856 #endif // NO_FRONTEND
858 static void CALLBACK dummy_lace(void)
863 // rearmed hack: EmuReset() runs some code when real BIOS is used,
864 // but we usually do reset from menu while GPU is not open yet,
865 // so we need to prevent updateLace() call..
866 void *real_lace = GPU_updateLace;
867 GPU_updateLace = dummy_lace;
870 // reset can run code, timing must be set
871 pl_timing_prepare(Config.PsxType);
875 GPU_updateLace = real_lace;
885 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
891 #ifndef HAVE_LIBRETRO
894 void SysPrintf(const char *fmt, ...) {
898 vfprintf(emuLog, fmt, list);
905 #include <android/log.h>
907 void SysPrintf(const char *fmt, ...) {
911 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
916 #endif /* HAVE_LIBRETRO */
918 void SysMessage(const char *fmt, ...) {
924 ret = vsnprintf(msg, sizeof(msg), fmt, list);
927 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
930 SysPrintf("%s\n", msg);
933 #define PARSEPATH(dst, src) \
934 ptr = src + strlen(src); \
935 while (*ptr != '\\' && ptr != src) ptr--; \
937 strcpy(dst, ptr+1); \
940 static int _OpenPlugins(void) {
944 signal(SIGINT, SignalExit);
945 signal(SIGPIPE, SignalExit);
949 if (UsingIso() && ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
951 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
952 SPU_registerCallback(SPUirq);
953 SPU_registerScheduleCb(SPUschedule);
954 // pcsx-rearmed: we handle gpu elsewhere
955 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
956 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
964 while ((ret = _OpenPlugins()) == -2) {
966 LoadMcds(Config.Mcd1, Config.Mcd2);
967 if (LoadPlugins() == -1) return -1;
972 void ClosePlugins() {
976 signal(SIGINT, SIG_DFL);
977 signal(SIGPIPE, SIG_DFL);
982 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); }
983 // pcsx-rearmed: we handle gpu elsewhere
985 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
988 /* we hook statically linked plugins here */
989 static const char *builtin_plugins[] = {
990 "builtin_gpu", "builtin_spu"
993 static const int builtin_plugin_ids[] = {
994 PLUGIN_GPU, PLUGIN_SPU
997 void *SysLoadLibrary(const char *lib) {
998 const char *tmp = strrchr(lib, '/');
1002 SysPrintf("plugin: %s\n", lib);
1006 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
1007 if (strcmp(tmp, builtin_plugins[i]) == 0)
1008 return (void *)(uintptr_t)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
1011 #if !defined(_WIN32) && !defined(NO_DYLIB)
1012 ret = dlopen(lib, RTLD_NOW);
1014 SysMessage("dlopen: %s", dlerror());
1016 /* no external plugin support, abi is no longer
1017 * compatible with psemu/pcsx anyway */
1022 void *SysLoadSym(void *lib, const char *sym) {
1023 unsigned int plugid = (unsigned int)(uintptr_t)lib;
1025 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1026 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1028 #if !defined(_WIN32) && !defined(NO_DYLIB)
1029 return dlsym(lib, sym);
1035 const char *SysLibError() {
1036 #if defined(NO_DYLIB)
1038 #elif !defined(_WIN32)
1041 return "not supported";
1045 void SysCloseLibrary(void *lib) {
1046 unsigned int plugid = (unsigned int)(uintptr_t)lib;
1048 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1051 #if !defined(_WIN32) && !defined(NO_DYLIB)