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.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.idiablofix = 0;
152 spu_config.iUseInterpolation = 1;
153 spu_config.iXAPitch = 0;
154 spu_config.iVolume = 768;
155 spu_config.iTempo = 0;
156 spu_config.iUseThread = 1; // no effect if only 1 core is detected
157 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) /* XXX GPH hack */
158 spu_config.iUseReverb = 0;
159 spu_config.iUseInterpolation = 0;
160 spu_config.iTempo = 1;
162 new_dynarec_hacks = 0;
163 cycle_multiplier = 200;
165 in_type[0] = PSE_PAD_TYPE_STANDARD;
166 in_type[1] = PSE_PAD_TYPE_STANDARD;
169 void do_emu_action(void)
173 emu_action_old = emu_action;
175 switch (emu_action) {
176 case SACTION_LOAD_STATE:
177 ret = emu_load_state(state_slot);
178 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
180 case SACTION_SAVE_STATE:
181 ret = emu_save_state(state_slot);
182 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
185 case SACTION_ENTER_MENU:
186 toggle_fast_forward(1);
189 case SACTION_NEXT_SSLOT:
194 case SACTION_PREV_SSLOT:
199 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
200 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
202 SysPrintf("* %s\n", hud_msg);
204 case SACTION_TOGGLE_FSKIP:
205 pl_rearmed_cbs.fskip_advice = 0;
206 pl_rearmed_cbs.frameskip++;
207 if (pl_rearmed_cbs.frameskip > 1)
208 pl_rearmed_cbs.frameskip = -1;
209 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
210 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
211 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
212 plugin_call_rearmed_cbs();
214 case SACTION_SWITCH_DISPMODE:
215 pl_switch_dispmode();
216 plugin_call_rearmed_cbs();
217 if (GPU_open != NULL && GPU_close != NULL) {
219 GPU_open(&gpuDisp, "PCSX", NULL);
222 case SACTION_FAST_FORWARD:
223 toggle_fast_forward(0);
224 plugin_call_rearmed_cbs();
226 case SACTION_TOGGLE_FPS:
227 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
228 == (OPT_SHOWFPS|OPT_SHOWCPU))
229 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
230 else if (g_opts & OPT_SHOWFPS)
231 g_opts |= OPT_SHOWCPU;
233 g_opts |= OPT_SHOWFPS;
235 case SACTION_TOGGLE_FULLSCREEN:
236 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
237 if (GPU_open != NULL && GPU_close != NULL) {
239 GPU_open(&gpuDisp, "PCSX", NULL);
242 case SACTION_SCREENSHOT:
244 char buf[MAXPATHLEN];
247 time_t t = time(NULL);
248 struct tm *tb = localtime(&t);
249 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
250 tb->tm_min * 100 + tb->tm_sec;
252 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
253 get_gameid_filename(buf, sizeof(buf),
254 "screenshots/%.32s-%.9s.%d.png", ti);
256 if (scrbuf != 0 && bpp == 16)
257 ret = writepng(buf, scrbuf, w, h);
259 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
262 case SACTION_VOLUME_UP:
263 case SACTION_VOLUME_DOWN:
266 plat_target_step_volume(&volume,
267 emu_action == SACTION_VOLUME_UP ? 1 : -1);
270 case SACTION_MINIMIZE:
271 if (GPU_close != NULL)
276 if (GPU_open != NULL) {
277 ret = GPU_open(&gpuDisp, "PCSX", NULL);
279 SysMessage("GPU_open returned %d", ret);
290 static char basic_lcase(char c)
292 if ('A' <= c && c <= 'Z')
293 return c - 'A' + 'a';
297 static int cdidcmp(const char *id1, const char *id2)
299 while (*id1 != 0 && *id2 != 0) {
300 if (*id1 == '_') { id1++; continue; }
301 if (*id2 == '_') { id2++; continue; }
302 if (basic_lcase(*id1) != basic_lcase(*id2))
311 static void parse_cwcheat(void)
313 char line[256], buf[256], name[256], *p;
318 f = fopen("cheatpops.db", "r");
323 while (fgets(line, sizeof(line), f)) {
324 if (sscanf(line, "_S %63s", buf) != 1)
326 if (cdidcmp(buf, CdromId) == 0)
333 SysPrintf("cwcheat section found for %s\n", CdromId);
334 while (fgets(line, sizeof(line), f))
336 p = line + strlen(line);
337 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
339 if (*p == 0 || *p == '#' || *p == ';')
342 if (strncmp(line, "_S", 2) == 0)
344 if (strncmp(line, "_G", 2) == 0) {
345 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
348 if (strncmp(line, "_C0", 3) == 0) {
349 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
350 SysPrintf("cheat '%s' failed to parse\n", name);
351 free(Cheats[NumCheats - 1].Descr);
354 snprintf(name, sizeof(name), "%s", line + 4);
358 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
359 SysPrintf("line failed to parse: '%s'\n", line);
364 if (NumCheats >= NumCheatsAllocated) {
365 NumCheatsAllocated += 16;
366 Cheats = realloc(Cheats, sizeof(Cheat) *
371 Cheats[NumCheats].Descr = strdup(name);
372 Cheats[NumCheats].Enabled = 0;
373 Cheats[NumCheats].WasEnabled = 0;
374 Cheats[NumCheats].First = NumCodes;
375 Cheats[NumCheats].n = 0;
380 if (NumCodes >= NumCodesAllocated) {
381 NumCodesAllocated += 16;
382 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
384 if (CheatCodes == NULL)
387 CheatCodes[NumCodes].Addr = a;
388 CheatCodes[NumCodes].Val = v;
390 Cheats[NumCheats - 1].n++;
397 void emu_on_new_cd(int show_hud_msg)
403 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
404 SysPrintf("----------------------------------------------------------\n");
408 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
413 int emu_core_preinit(void)
415 // what is the name of the config file?
416 // it may be redefined by -cfg on the command line
417 strcpy(cfgfile_basename, "pcsx.cfg");
420 emuLog = fopen("/User/Documents/pcsxr.log", "w");
422 emuLog = fopen("pcsxr.log", "w");
429 memset(&Config, 0, sizeof(Config));
432 emu_set_default_config();
433 strcpy(Config.Bios, "HLE");
438 int emu_core_init(void)
440 SysPrintf("Starting PCSX-ReARMed " REV "\n");
447 if (EmuInit() == -1) {
448 SysPrintf("PSX emulator couldn't be initialized.\n");
452 LoadMcds(Config.Mcd1, Config.Mcd2);
461 void emu_core_ask_exit(void)
469 #include <sys/stat.h>
470 #include <sys/types.h>
472 static void create_profile_dir(const char *directory) {
473 char path[MAXPATHLEN];
475 MAKE_PATH(path, directory, NULL);
476 mkdir(path, S_IRWXU | S_IRWXG);
479 static void check_profile(void) {
480 // make sure that ~/.pcsx exists
481 create_profile_dir(PCSX_DOT_DIR);
483 create_profile_dir(BIOS_DIR);
484 create_profile_dir(MEMCARD_DIR);
485 create_profile_dir(STATES_DIR);
486 create_profile_dir(PLUGINS_DIR);
487 create_profile_dir(PLUGINS_CFG_DIR);
488 create_profile_dir(CHEATS_DIR);
489 create_profile_dir(PATCHES_DIR);
490 create_profile_dir(PCSX_DOT_DIR "cfg");
491 create_profile_dir("/screenshots/");
494 static void check_memcards(void)
496 char buf[MAXPATHLEN];
500 for (i = 1; i <= 9; i++) {
501 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
503 f = fopen(buf, "rb");
505 SysPrintf("Creating memcard: %s\n", buf);
513 int main(int argc, char *argv[])
515 char file[MAXPATHLEN] = "";
516 char path[MAXPATHLEN];
517 const char *cdfile = NULL;
518 const char *loadst_f = NULL;
525 // read command line options
526 for (i = 1; i < argc; i++) {
527 if (!strcmp(argv[i], "-psxout")) psxout = 1;
528 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
529 else if (!strcmp(argv[i], "-cfg")) {
530 if (i+1 >= argc) break;
531 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
532 SysPrintf("Using config file %s.\n", cfgfile_basename);
534 else if (!strcmp(argv[i], "-cdfile")) {
535 char isofilename[MAXPATHLEN];
537 if (i+1 >= argc) break;
538 strncpy(isofilename, argv[++i], MAXPATHLEN);
539 if (isofilename[0] != '/') {
540 getcwd(path, MAXPATHLEN);
541 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
543 strcat(path, isofilename);
544 strcpy(isofilename, path);
549 cdfile = isofilename;
551 else if (!strcmp(argv[i], "-loadf")) {
552 if (i+1 >= argc) break;
553 loadst_f = argv[++i];
555 else if (!strcmp(argv[i], "-h") ||
556 !strcmp(argv[i], "-help") ||
557 !strcmp(argv[i], "--help")) {
558 printf("PCSX-ReARMed " REV "\n");
560 " pcsx [options] [file]\n"
562 "\t-cdfile FILE\tRuns a CD image file\n"
563 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
564 "\t-psxout\t\tEnable PSX output\n"
565 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
566 "\t-h -help\tDisplay this message\n"
567 "\tfile\t\tLoads a PSX EXE file\n"));
570 strncpy(file, argv[i], MAXPATHLEN);
571 if (file[0] != '/') {
572 getcwd(path, MAXPATHLEN);
573 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
584 set_cd_image(cdfile);
587 // init input but leave probing to platform code,
588 // they add input drivers and may need to modify them after probe
592 menu_init(); // loads config
594 if (emu_core_init() != 0)
600 if (LoadPlugins() == -1) {
601 // FIXME: this recovery doesn't work, just delete bad config and bail out
602 // SysMessage("could not load plugins, retrying with defaults\n");
604 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
606 SysMessage("Failed loading plugins!");
611 if (OpenPlugins() == -1) {
614 plugin_call_rearmed_cbs();
619 if (file[0] != '\0') {
620 if (Load(file) != -1)
624 if (LoadCdrom() == -1) {
626 SysPrintf(_("Could not load CD-ROM!\n"));
629 emu_on_new_cd(!loadst);
635 int ret = LoadState(loadst_f);
636 SysPrintf("%s state file: %s\n",
637 ret ? "failed to load" : "loaded", loadst_f);
638 ready_to_go |= ret == 0;
644 // If a state has been specified, then load that
646 int ret = emu_load_state(loadst - 1);
647 SysPrintf("%s state %d\n",
648 ret ? "failed to load" : "loaded", loadst);
656 while (!g_emu_want_quit)
659 emu_action = SACTION_NONE;
662 if (emu_action != SACTION_NONE)
675 static void toggle_fast_forward(int force_off)
677 static int fast_forward;
678 static int normal_g_opts;
679 static int normal_frameskip;
680 static int normal_enhancement_enable;
682 if (force_off && !fast_forward)
685 fast_forward = !fast_forward;
687 normal_g_opts = g_opts;
688 normal_frameskip = pl_rearmed_cbs.frameskip;
689 normal_enhancement_enable =
690 pl_rearmed_cbs.gpu_neon.enhancement_enable;
692 g_opts |= OPT_NO_FRAMELIM;
693 pl_rearmed_cbs.frameskip = 3;
694 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
696 g_opts = normal_g_opts;
697 pl_rearmed_cbs.frameskip = normal_frameskip;
698 pl_rearmed_cbs.gpu_neon.enhancement_enable =
699 normal_enhancement_enable;
701 pl_timing_prepare(Config.PsxType);
705 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
706 fast_forward ? "ON" : "OFF");
709 static void SignalExit(int sig) {
710 // only to restore framebuffer/resolution on some devices
717 printf("SysRunGui\n");
720 static void dummy_lace()
725 // rearmed hack: EmuReset() runs some code when real BIOS is used,
726 // but we usually do reset from menu while GPU is not open yet,
727 // so we need to prevent updateLace() call..
728 void *real_lace = GPU_updateLace;
729 GPU_updateLace = dummy_lace;
732 // reset can run code, timing must be set
733 pl_timing_prepare(Config.PsxType);
735 // hmh core forgets this
740 GPU_updateLace = real_lace;
750 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
759 int get_state_filename(char *buf, int size, int i) {
760 return get_gameid_filename(buf, size,
761 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
764 int emu_check_state(int slot)
766 char fname[MAXPATHLEN];
769 ret = get_state_filename(fname, sizeof(fname), slot);
773 return CheckState(fname);
776 int emu_save_state(int slot)
778 char fname[MAXPATHLEN];
781 ret = get_state_filename(fname, sizeof(fname), slot);
785 ret = SaveState(fname);
786 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */
789 SysPrintf("* %s \"%s\" [%d]\n",
790 ret == 0 ? "saved" : "failed to save", fname, slot);
794 int emu_load_state(int slot)
796 char fname[MAXPATHLEN];
801 ret = get_state_filename(fname, sizeof(fname), slot);
805 return LoadState(fname);
808 #ifndef HAVE_LIBRETRO
811 void SysPrintf(const char *fmt, ...) {
815 vfprintf(emuLog, fmt, list);
822 #include <android/log.h>
824 void SysPrintf(const char *fmt, ...) {
828 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
833 #endif /* HAVE_LIBRETRO */
835 void SysMessage(const char *fmt, ...) {
841 ret = vsnprintf(msg, sizeof(msg), fmt, list);
844 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
847 SysPrintf("%s\n", msg);
850 #define PARSEPATH(dst, src) \
851 ptr = src + strlen(src); \
852 while (*ptr != '\\' && ptr != src) ptr--; \
854 strcpy(dst, ptr+1); \
857 static int _OpenPlugins(void) {
861 signal(SIGINT, SignalExit);
862 signal(SIGPIPE, SignalExit);
865 GPU_clearDynarec(clearDynarec);
868 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
870 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
871 SPU_registerCallback(SPUirq);
872 SPU_registerScheduleCb(SPUschedule);
873 // pcsx-rearmed: we handle gpu elsewhere
874 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
875 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
876 ret = PAD1_open(&gpuDisp);
877 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
878 ret = PAD2_open(&gpuDisp);
879 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
881 if (Config.UseNet && !NetOpened) {
883 char path[MAXPATHLEN * 2];
884 char dotdir[MAXPATHLEN];
886 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
888 strcpy(info.EmuName, "PCSX");
889 memcpy(info.CdromID, CdromId, 9); /* no \0 trailing character? */
890 memcpy(info.CdromLabel, CdromLabel, 9);
891 info.CdromLabel[9] = '\0';
893 info.GPU_showScreenPic = GPU_showScreenPic;
894 info.GPU_displayText = GPU_displayText;
895 info.GPU_showScreenPic = GPU_showScreenPic;
896 info.PAD_setSensitive = PAD1_setSensitive;
897 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
898 strcpy(info.BIOSpath, path);
899 strcpy(info.MCD1path, Config.Mcd1);
900 strcpy(info.MCD2path, Config.Mcd2);
901 sprintf(path, "%s%s", dotdir, Config.Gpu);
902 strcpy(info.GPUpath, path);
903 sprintf(path, "%s%s", dotdir, Config.Spu);
904 strcpy(info.SPUpath, path);
905 sprintf(path, "%s%s", dotdir, Config.Cdr);
906 strcpy(info.CDRpath, path);
909 ret = NET_open(&gpuDisp);
912 // -2 is returned when something in the info
913 // changed and needs to be synced
916 PARSEPATH(Config.Bios, info.BIOSpath);
917 PARSEPATH(Config.Gpu, info.GPUpath);
918 PARSEPATH(Config.Spu, info.SPUpath);
919 PARSEPATH(Config.Cdr, info.CDRpath);
921 strcpy(Config.Mcd1, info.MCD1path);
922 strcpy(Config.Mcd2, info.MCD2path);
925 Config.UseNet = FALSE;
928 if (NET_queryPlayer() == 1) {
929 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
931 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
935 } else if (Config.UseNet) {
945 while ((ret = _OpenPlugins()) == -2) {
947 LoadMcds(Config.Mcd1, Config.Mcd2);
948 if (LoadPlugins() == -1) return -1;
953 void ClosePlugins() {
957 signal(SIGINT, SIG_DFL);
958 signal(SIGPIPE, SIG_DFL);
962 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
964 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
966 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
968 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
969 // pcsx-rearmed: we handle gpu elsewhere
971 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
978 /* we hook statically linked plugins here */
979 static const char *builtin_plugins[] = {
980 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
984 static const int builtin_plugin_ids[] = {
985 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
989 void *SysLoadLibrary(const char *lib) {
990 const char *tmp = strrchr(lib, '/');
994 SysPrintf("plugin: %s\n", lib);
998 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
999 if (strcmp(tmp, builtin_plugins[i]) == 0)
1000 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
1003 #if !defined(_WIN32) && !defined(NO_DYLIB)
1004 ret = dlopen(lib, RTLD_NOW);
1006 SysMessage("dlopen: %s", dlerror());
1008 /* no external plugin support, abi is no longer
1009 * compatible with psemu/pcsx anyway */
1014 void *SysLoadSym(void *lib, const char *sym) {
1015 unsigned int plugid = (unsigned int)(long)lib;
1017 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1018 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1020 #if !defined(_WIN32) && !defined(NO_DYLIB)
1021 return dlsym(lib, sym);
1027 const char *SysLibError() {
1028 #if defined(NO_DYLIB)
1030 #elif !defined(_WIN32)
1033 return "not supported";
1037 void SysCloseLibrary(void *lib) {
1038 unsigned int plugid = (unsigned int)(long)lib;
1040 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1043 #if !defined(_WIN32) && !defined(NO_DYLIB)