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.icache_emulation = Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
128 pl_rearmed_cbs.thread_rendering = 0;
130 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
131 pl_rearmed_cbs.gpu_neon.enhancement_enable =
132 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
133 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
134 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
135 pl_rearmed_cbs.gpu_unai.ilace_force = 0;
136 pl_rearmed_cbs.gpu_unai.pixel_skip = 1;
137 pl_rearmed_cbs.gpu_unai.lighting = 1;
138 pl_rearmed_cbs.gpu_unai.fast_lighting = 1;
139 pl_rearmed_cbs.gpu_unai.blending = 1;
140 pl_rearmed_cbs.gpu_unai.dithering = 0;
141 // old gpu_unai config
142 pl_rearmed_cbs.gpu_unai.abe_hack =
143 pl_rearmed_cbs.gpu_unai.no_light =
144 pl_rearmed_cbs.gpu_unai.no_blend = 0;
145 pl_rearmed_cbs.gpu_unai.scale_hires = 0;
146 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
147 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
148 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
150 spu_config.iUseReverb = 1;
151 spu_config.iUseInterpolation = 1;
152 spu_config.iXAPitch = 0;
153 spu_config.iVolume = 768;
154 spu_config.iTempo = 0;
155 spu_config.iUseThread = 1; // no effect if only 1 core is detected
156 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */
157 spu_config.iUseReverb = 0;
158 spu_config.iUseInterpolation = 0;
159 #ifndef HAVE_LIBRETRO
160 spu_config.iTempo = 1;
163 new_dynarec_hacks = 0;
164 cycle_multiplier = 200;
166 in_type[0] = PSE_PAD_TYPE_STANDARD;
167 in_type[1] = PSE_PAD_TYPE_STANDARD;
170 void do_emu_action(void)
174 emu_action_old = emu_action;
176 switch (emu_action) {
177 case SACTION_LOAD_STATE:
178 ret = emu_load_state(state_slot);
179 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
181 case SACTION_SAVE_STATE:
182 ret = emu_save_state(state_slot);
183 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
186 case SACTION_ENTER_MENU:
187 toggle_fast_forward(1);
190 case SACTION_NEXT_SSLOT:
195 case SACTION_PREV_SSLOT:
200 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
201 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
203 SysPrintf("* %s\n", hud_msg);
205 case SACTION_TOGGLE_FSKIP:
206 pl_rearmed_cbs.fskip_advice = 0;
207 pl_rearmed_cbs.frameskip++;
208 if (pl_rearmed_cbs.frameskip > 1)
209 pl_rearmed_cbs.frameskip = -1;
210 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
211 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
212 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
213 plugin_call_rearmed_cbs();
215 case SACTION_SWITCH_DISPMODE:
216 pl_switch_dispmode();
217 plugin_call_rearmed_cbs();
218 if (GPU_open != NULL && GPU_close != NULL) {
220 GPU_open(&gpuDisp, "PCSX", NULL);
223 case SACTION_FAST_FORWARD:
224 toggle_fast_forward(0);
225 plugin_call_rearmed_cbs();
227 case SACTION_TOGGLE_FPS:
228 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
229 == (OPT_SHOWFPS|OPT_SHOWCPU))
230 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
231 else if (g_opts & OPT_SHOWFPS)
232 g_opts |= OPT_SHOWCPU;
234 g_opts |= OPT_SHOWFPS;
236 case SACTION_TOGGLE_FULLSCREEN:
237 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
238 if (GPU_open != NULL && GPU_close != NULL) {
240 GPU_open(&gpuDisp, "PCSX", NULL);
243 case SACTION_SCREENSHOT:
245 char buf[MAXPATHLEN];
248 time_t t = time(NULL);
249 struct tm *tb = localtime(&t);
250 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
251 tb->tm_min * 100 + tb->tm_sec;
253 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
254 get_gameid_filename(buf, sizeof(buf),
255 "screenshots/%.32s-%.9s.%d.png", ti);
257 if (scrbuf != 0 && bpp == 16)
258 ret = writepng(buf, scrbuf, w, h);
260 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
263 case SACTION_VOLUME_UP:
264 case SACTION_VOLUME_DOWN:
267 plat_target_step_volume(&volume,
268 emu_action == SACTION_VOLUME_UP ? 1 : -1);
271 case SACTION_MINIMIZE:
272 if (GPU_close != NULL)
277 if (GPU_open != NULL) {
278 ret = GPU_open(&gpuDisp, "PCSX", NULL);
280 SysMessage("GPU_open returned %d", ret);
291 static char basic_lcase(char c)
293 if ('A' <= c && c <= 'Z')
294 return c - 'A' + 'a';
298 static int cdidcmp(const char *id1, const char *id2)
300 while (*id1 != 0 && *id2 != 0) {
301 if (*id1 == '_') { id1++; continue; }
302 if (*id2 == '_') { id2++; continue; }
303 if (basic_lcase(*id1) != basic_lcase(*id2))
312 static void parse_cwcheat(void)
314 char line[256], buf[256], name[256], *p;
319 f = fopen("cheatpops.db", "r");
324 while (fgets(line, sizeof(line), f)) {
325 if (sscanf(line, "_S %63s", buf) != 1)
327 if (cdidcmp(buf, CdromId) == 0)
334 SysPrintf("cwcheat section found for %s\n", CdromId);
335 while (fgets(line, sizeof(line), f))
337 p = line + strlen(line);
338 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
340 if (*p == 0 || *p == '#' || *p == ';')
343 if (strncmp(line, "_S", 2) == 0)
345 if (strncmp(line, "_G", 2) == 0) {
346 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
349 if (strncmp(line, "_C0", 3) == 0) {
350 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
351 SysPrintf("cheat '%s' failed to parse\n", name);
352 free(Cheats[NumCheats - 1].Descr);
355 snprintf(name, sizeof(name), "%s", line + 4);
359 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
360 SysPrintf("line failed to parse: '%s'\n", line);
365 if (NumCheats >= NumCheatsAllocated) {
366 NumCheatsAllocated += 16;
367 Cheats = realloc(Cheats, sizeof(Cheat) *
372 Cheats[NumCheats].Descr = strdup(name);
373 Cheats[NumCheats].Enabled = 0;
374 Cheats[NumCheats].WasEnabled = 0;
375 Cheats[NumCheats].First = NumCodes;
376 Cheats[NumCheats].n = 0;
381 if (NumCodes >= NumCodesAllocated) {
382 NumCodesAllocated += 16;
383 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
385 if (CheatCodes == NULL)
388 CheatCodes[NumCodes].Addr = a;
389 CheatCodes[NumCodes].Val = v;
391 Cheats[NumCheats - 1].n++;
398 void emu_on_new_cd(int show_hud_msg)
404 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
405 SysPrintf("----------------------------------------------------------\n");
409 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
414 int emu_core_preinit(void)
416 // what is the name of the config file?
417 // it may be redefined by -cfg on the command line
418 strcpy(cfgfile_basename, "pcsx.cfg");
421 emuLog = fopen("/User/Documents/pcsxr.log", "w");
423 emuLog = fopen("pcsxr.log", "w");
430 memset(&Config, 0, sizeof(Config));
433 emu_set_default_config();
434 strcpy(Config.Bios, "HLE");
439 int emu_core_init(void)
441 SysPrintf("Starting PCSX-ReARMed " REV "\n");
448 if (EmuInit() == -1) {
449 SysPrintf("PSX emulator couldn't be initialized.\n");
453 LoadMcds(Config.Mcd1, Config.Mcd2);
462 void emu_core_ask_exit(void)
470 #include <sys/stat.h>
471 #include <sys/types.h>
473 static void create_profile_dir(const char *directory) {
474 char path[MAXPATHLEN];
476 MAKE_PATH(path, directory, NULL);
477 mkdir(path, S_IRWXU | S_IRWXG);
480 static void check_profile(void) {
481 // make sure that ~/.pcsx exists
482 create_profile_dir(PCSX_DOT_DIR);
484 create_profile_dir(BIOS_DIR);
485 create_profile_dir(MEMCARD_DIR);
486 create_profile_dir(STATES_DIR);
487 create_profile_dir(PLUGINS_DIR);
488 create_profile_dir(PLUGINS_CFG_DIR);
489 create_profile_dir(CHEATS_DIR);
490 create_profile_dir(PATCHES_DIR);
491 create_profile_dir(PCSX_DOT_DIR "cfg");
492 create_profile_dir("/screenshots/");
495 static void check_memcards(void)
497 char buf[MAXPATHLEN];
501 for (i = 1; i <= 9; i++) {
502 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
504 f = fopen(buf, "rb");
506 SysPrintf("Creating memcard: %s\n", buf);
514 int main(int argc, char *argv[])
516 char file[MAXPATHLEN] = "";
517 char path[MAXPATHLEN];
518 const char *cdfile = NULL;
519 const char *loadst_f = NULL;
526 // read command line options
527 for (i = 1; i < argc; i++) {
528 if (!strcmp(argv[i], "-psxout")) psxout = 1;
529 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
530 else if (!strcmp(argv[i], "-cfg")) {
531 if (i+1 >= argc) break;
532 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
533 SysPrintf("Using config file %s.\n", cfgfile_basename);
535 else if (!strcmp(argv[i], "-cdfile")) {
536 char isofilename[MAXPATHLEN];
538 if (i+1 >= argc) break;
539 strncpy(isofilename, argv[++i], MAXPATHLEN);
540 if (isofilename[0] != '/') {
541 getcwd(path, MAXPATHLEN);
542 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
544 strcat(path, isofilename);
545 strcpy(isofilename, path);
550 cdfile = isofilename;
552 else if (!strcmp(argv[i], "-loadf")) {
553 if (i+1 >= argc) break;
554 loadst_f = argv[++i];
556 else if (!strcmp(argv[i], "-h") ||
557 !strcmp(argv[i], "-help") ||
558 !strcmp(argv[i], "--help")) {
559 printf("PCSX-ReARMed " REV "\n");
561 " pcsx [options] [file]\n"
563 "\t-cdfile FILE\tRuns a CD image file\n"
564 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
565 "\t-psxout\t\tEnable PSX output\n"
566 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
567 "\t-h -help\tDisplay this message\n"
568 "\tfile\t\tLoads a PSX EXE file\n"));
571 strncpy(file, argv[i], MAXPATHLEN);
572 if (file[0] != '/') {
573 getcwd(path, MAXPATHLEN);
574 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
585 set_cd_image(cdfile);
588 // init input but leave probing to platform code,
589 // they add input drivers and may need to modify them after probe
593 menu_init(); // loads config
595 if (emu_core_init() != 0)
601 if (LoadPlugins() == -1) {
602 // FIXME: this recovery doesn't work, just delete bad config and bail out
603 // SysMessage("could not load plugins, retrying with defaults\n");
605 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
607 SysMessage("Failed loading plugins!");
612 if (OpenPlugins() == -1) {
615 plugin_call_rearmed_cbs();
620 if (file[0] != '\0') {
621 if (Load(file) != -1)
625 if (LoadCdrom() == -1) {
627 SysPrintf(_("Could not load CD-ROM!\n"));
630 emu_on_new_cd(!loadst);
636 int ret = LoadState(loadst_f);
637 SysPrintf("%s state file: %s\n",
638 ret ? "failed to load" : "loaded", loadst_f);
639 ready_to_go |= ret == 0;
645 // If a state has been specified, then load that
647 int ret = emu_load_state(loadst - 1);
648 SysPrintf("%s state %d\n",
649 ret ? "failed to load" : "loaded", loadst);
657 while (!g_emu_want_quit)
660 emu_action = SACTION_NONE;
663 if (emu_action != SACTION_NONE)
676 static void toggle_fast_forward(int force_off)
678 static int fast_forward;
679 static int normal_g_opts;
680 static int normal_frameskip;
681 static int normal_enhancement_enable;
683 if (force_off && !fast_forward)
686 fast_forward = !fast_forward;
688 normal_g_opts = g_opts;
689 normal_frameskip = pl_rearmed_cbs.frameskip;
690 normal_enhancement_enable =
691 pl_rearmed_cbs.gpu_neon.enhancement_enable;
693 g_opts |= OPT_NO_FRAMELIM;
694 pl_rearmed_cbs.frameskip = 3;
695 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
697 g_opts = normal_g_opts;
698 pl_rearmed_cbs.frameskip = normal_frameskip;
699 pl_rearmed_cbs.gpu_neon.enhancement_enable =
700 normal_enhancement_enable;
702 pl_timing_prepare(Config.PsxType);
706 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
707 fast_forward ? "ON" : "OFF");
710 static void SignalExit(int sig) {
711 // only to restore framebuffer/resolution on some devices
718 printf("SysRunGui\n");
721 static void CALLBACK dummy_lace()
726 // rearmed hack: EmuReset() runs some code when real BIOS is used,
727 // but we usually do reset from menu while GPU is not open yet,
728 // so we need to prevent updateLace() call..
729 void *real_lace = GPU_updateLace;
730 GPU_updateLace = dummy_lace;
733 // reset can run code, timing must be set
734 pl_timing_prepare(Config.PsxType);
736 // hmh core forgets this
741 GPU_updateLace = real_lace;
751 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
760 int get_state_filename(char *buf, int size, int i) {
761 return get_gameid_filename(buf, size,
762 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
765 int emu_check_state(int slot)
767 char fname[MAXPATHLEN];
770 ret = get_state_filename(fname, sizeof(fname), slot);
774 return CheckState(fname);
777 int emu_save_state(int slot)
779 char fname[MAXPATHLEN];
782 ret = get_state_filename(fname, sizeof(fname), slot);
786 ret = SaveState(fname);
787 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */
790 SysPrintf("* %s \"%s\" [%d]\n",
791 ret == 0 ? "saved" : "failed to save", fname, slot);
795 int emu_load_state(int slot)
797 char fname[MAXPATHLEN];
802 ret = get_state_filename(fname, sizeof(fname), slot);
806 return LoadState(fname);
809 #ifndef HAVE_LIBRETRO
812 void SysPrintf(const char *fmt, ...) {
816 vfprintf(emuLog, fmt, list);
823 #include <android/log.h>
825 void SysPrintf(const char *fmt, ...) {
829 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
834 #endif /* HAVE_LIBRETRO */
836 void SysMessage(const char *fmt, ...) {
842 ret = vsnprintf(msg, sizeof(msg), fmt, list);
845 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
848 SysPrintf("%s\n", msg);
851 #define PARSEPATH(dst, src) \
852 ptr = src + strlen(src); \
853 while (*ptr != '\\' && ptr != src) ptr--; \
855 strcpy(dst, ptr+1); \
858 static int _OpenPlugins(void) {
862 signal(SIGINT, SignalExit);
863 signal(SIGPIPE, SignalExit);
866 GPU_clearDynarec(clearDynarec);
869 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
871 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
872 SPU_registerCallback(SPUirq);
873 SPU_registerScheduleCb(SPUschedule);
874 // pcsx-rearmed: we handle gpu elsewhere
875 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
876 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
877 ret = PAD1_open(&gpuDisp);
878 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
879 ret = PAD2_open(&gpuDisp);
880 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
882 if (Config.UseNet && !NetOpened) {
884 char path[MAXPATHLEN * 2];
885 char dotdir[MAXPATHLEN];
887 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
889 strcpy(info.EmuName, "PCSX");
890 memcpy(info.CdromID, CdromId, 9); /* no \0 trailing character? */
891 memcpy(info.CdromLabel, CdromLabel, 9);
892 info.CdromLabel[9] = '\0';
894 info.GPU_showScreenPic = GPU_showScreenPic;
895 info.GPU_displayText = GPU_displayText;
896 info.GPU_showScreenPic = GPU_showScreenPic;
897 info.PAD_setSensitive = PAD1_setSensitive;
898 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
899 strcpy(info.BIOSpath, path);
900 strcpy(info.MCD1path, Config.Mcd1);
901 strcpy(info.MCD2path, Config.Mcd2);
902 sprintf(path, "%s%s", dotdir, Config.Gpu);
903 strcpy(info.GPUpath, path);
904 sprintf(path, "%s%s", dotdir, Config.Spu);
905 strcpy(info.SPUpath, path);
906 sprintf(path, "%s%s", dotdir, Config.Cdr);
907 strcpy(info.CDRpath, path);
910 ret = NET_open(&gpuDisp);
913 // -2 is returned when something in the info
914 // changed and needs to be synced
917 PARSEPATH(Config.Bios, info.BIOSpath);
918 PARSEPATH(Config.Gpu, info.GPUpath);
919 PARSEPATH(Config.Spu, info.SPUpath);
920 PARSEPATH(Config.Cdr, info.CDRpath);
922 strcpy(Config.Mcd1, info.MCD1path);
923 strcpy(Config.Mcd2, info.MCD2path);
926 Config.UseNet = FALSE;
929 if (NET_queryPlayer() == 1) {
930 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
932 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
936 } else if (Config.UseNet) {
946 while ((ret = _OpenPlugins()) == -2) {
948 LoadMcds(Config.Mcd1, Config.Mcd2);
949 if (LoadPlugins() == -1) return -1;
954 void ClosePlugins() {
958 signal(SIGINT, SIG_DFL);
959 signal(SIGPIPE, SIG_DFL);
963 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
965 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
967 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
969 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
970 // pcsx-rearmed: we handle gpu elsewhere
972 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
979 /* we hook statically linked plugins here */
980 static const char *builtin_plugins[] = {
981 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
985 static const int builtin_plugin_ids[] = {
986 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
990 void *SysLoadLibrary(const char *lib) {
991 const char *tmp = strrchr(lib, '/');
995 SysPrintf("plugin: %s\n", lib);
999 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
1000 if (strcmp(tmp, builtin_plugins[i]) == 0)
1001 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
1004 #if !defined(_WIN32) && !defined(NO_DYLIB)
1005 ret = dlopen(lib, RTLD_NOW);
1007 SysMessage("dlopen: %s", dlerror());
1009 /* no external plugin support, abi is no longer
1010 * compatible with psemu/pcsx anyway */
1015 void *SysLoadSym(void *lib, const char *sym) {
1016 unsigned int plugid = (unsigned int)(long)lib;
1018 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1019 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1021 #if !defined(_WIN32) && !defined(NO_DYLIB)
1022 return dlsym(lib, sym);
1028 const char *SysLibError() {
1029 #if defined(NO_DYLIB)
1031 #elif !defined(_WIN32)
1034 return "not supported";
1038 void SysCloseLibrary(void *lib) {
1039 unsigned int plugid = (unsigned int)(long)lib;
1041 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1044 #if !defined(_WIN32) && !defined(NO_DYLIB)