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 spu_config.iTempo = 1;
161 new_dynarec_hacks = 0;
162 cycle_multiplier = 200;
164 in_type[0] = PSE_PAD_TYPE_STANDARD;
165 in_type[1] = PSE_PAD_TYPE_STANDARD;
168 void do_emu_action(void)
172 emu_action_old = emu_action;
174 switch (emu_action) {
175 case SACTION_LOAD_STATE:
176 ret = emu_load_state(state_slot);
177 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
179 case SACTION_SAVE_STATE:
180 ret = emu_save_state(state_slot);
181 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
184 case SACTION_ENTER_MENU:
185 toggle_fast_forward(1);
188 case SACTION_NEXT_SSLOT:
193 case SACTION_PREV_SSLOT:
198 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
199 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
201 SysPrintf("* %s\n", hud_msg);
203 case SACTION_TOGGLE_FSKIP:
204 pl_rearmed_cbs.fskip_advice = 0;
205 pl_rearmed_cbs.frameskip++;
206 if (pl_rearmed_cbs.frameskip > 1)
207 pl_rearmed_cbs.frameskip = -1;
208 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
209 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
210 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
211 plugin_call_rearmed_cbs();
213 case SACTION_SWITCH_DISPMODE:
214 pl_switch_dispmode();
215 plugin_call_rearmed_cbs();
216 if (GPU_open != NULL && GPU_close != NULL) {
218 GPU_open(&gpuDisp, "PCSX", NULL);
221 case SACTION_FAST_FORWARD:
222 toggle_fast_forward(0);
223 plugin_call_rearmed_cbs();
225 case SACTION_TOGGLE_FPS:
226 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
227 == (OPT_SHOWFPS|OPT_SHOWCPU))
228 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
229 else if (g_opts & OPT_SHOWFPS)
230 g_opts |= OPT_SHOWCPU;
232 g_opts |= OPT_SHOWFPS;
234 case SACTION_TOGGLE_FULLSCREEN:
235 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
236 if (GPU_open != NULL && GPU_close != NULL) {
238 GPU_open(&gpuDisp, "PCSX", NULL);
241 case SACTION_SCREENSHOT:
243 char buf[MAXPATHLEN];
246 time_t t = time(NULL);
247 struct tm *tb = localtime(&t);
248 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
249 tb->tm_min * 100 + tb->tm_sec;
251 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
252 get_gameid_filename(buf, sizeof(buf),
253 "screenshots/%.32s-%.9s.%d.png", ti);
255 if (scrbuf != 0 && bpp == 16)
256 ret = writepng(buf, scrbuf, w, h);
258 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
261 case SACTION_VOLUME_UP:
262 case SACTION_VOLUME_DOWN:
265 plat_target_step_volume(&volume,
266 emu_action == SACTION_VOLUME_UP ? 1 : -1);
269 case SACTION_MINIMIZE:
270 if (GPU_close != NULL)
275 if (GPU_open != NULL) {
276 ret = GPU_open(&gpuDisp, "PCSX", NULL);
278 SysMessage("GPU_open returned %d", ret);
289 static char basic_lcase(char c)
291 if ('A' <= c && c <= 'Z')
292 return c - 'A' + 'a';
296 static int cdidcmp(const char *id1, const char *id2)
298 while (*id1 != 0 && *id2 != 0) {
299 if (*id1 == '_') { id1++; continue; }
300 if (*id2 == '_') { id2++; continue; }
301 if (basic_lcase(*id1) != basic_lcase(*id2))
310 static void parse_cwcheat(void)
312 char line[256], buf[256], name[256], *p;
317 f = fopen("cheatpops.db", "r");
322 while (fgets(line, sizeof(line), f)) {
323 if (sscanf(line, "_S %63s", buf) != 1)
325 if (cdidcmp(buf, CdromId) == 0)
332 SysPrintf("cwcheat section found for %s\n", CdromId);
333 while (fgets(line, sizeof(line), f))
335 p = line + strlen(line);
336 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
338 if (*p == 0 || *p == '#' || *p == ';')
341 if (strncmp(line, "_S", 2) == 0)
343 if (strncmp(line, "_G", 2) == 0) {
344 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
347 if (strncmp(line, "_C0", 3) == 0) {
348 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
349 SysPrintf("cheat '%s' failed to parse\n", name);
350 free(Cheats[NumCheats - 1].Descr);
353 snprintf(name, sizeof(name), "%s", line + 4);
357 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
358 SysPrintf("line failed to parse: '%s'\n", line);
363 if (NumCheats >= NumCheatsAllocated) {
364 NumCheatsAllocated += 16;
365 Cheats = realloc(Cheats, sizeof(Cheat) *
370 Cheats[NumCheats].Descr = strdup(name);
371 Cheats[NumCheats].Enabled = 0;
372 Cheats[NumCheats].WasEnabled = 0;
373 Cheats[NumCheats].First = NumCodes;
374 Cheats[NumCheats].n = 0;
379 if (NumCodes >= NumCodesAllocated) {
380 NumCodesAllocated += 16;
381 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
383 if (CheatCodes == NULL)
386 CheatCodes[NumCodes].Addr = a;
387 CheatCodes[NumCodes].Val = v;
389 Cheats[NumCheats - 1].n++;
396 void emu_on_new_cd(int show_hud_msg)
402 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
403 SysPrintf("----------------------------------------------------------\n");
407 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
412 int emu_core_preinit(void)
414 // what is the name of the config file?
415 // it may be redefined by -cfg on the command line
416 strcpy(cfgfile_basename, "pcsx.cfg");
419 emuLog = fopen("/User/Documents/pcsxr.log", "w");
421 emuLog = fopen("pcsxr.log", "w");
428 memset(&Config, 0, sizeof(Config));
431 emu_set_default_config();
432 strcpy(Config.Bios, "HLE");
437 int emu_core_init(void)
439 SysPrintf("Starting PCSX-ReARMed " REV "\n");
446 if (EmuInit() == -1) {
447 SysPrintf("PSX emulator couldn't be initialized.\n");
451 LoadMcds(Config.Mcd1, Config.Mcd2);
460 void emu_core_ask_exit(void)
468 #include <sys/stat.h>
469 #include <sys/types.h>
471 static void create_profile_dir(const char *directory) {
472 char path[MAXPATHLEN];
474 MAKE_PATH(path, directory, NULL);
475 mkdir(path, S_IRWXU | S_IRWXG);
478 static void check_profile(void) {
479 // make sure that ~/.pcsx exists
480 create_profile_dir(PCSX_DOT_DIR);
482 create_profile_dir(BIOS_DIR);
483 create_profile_dir(MEMCARD_DIR);
484 create_profile_dir(STATES_DIR);
485 create_profile_dir(PLUGINS_DIR);
486 create_profile_dir(PLUGINS_CFG_DIR);
487 create_profile_dir(CHEATS_DIR);
488 create_profile_dir(PATCHES_DIR);
489 create_profile_dir(PCSX_DOT_DIR "cfg");
490 create_profile_dir("/screenshots/");
493 static void check_memcards(void)
495 char buf[MAXPATHLEN];
499 for (i = 1; i <= 9; i++) {
500 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
502 f = fopen(buf, "rb");
504 SysPrintf("Creating memcard: %s\n", buf);
512 int main(int argc, char *argv[])
514 char file[MAXPATHLEN] = "";
515 char path[MAXPATHLEN];
516 const char *cdfile = NULL;
517 const char *loadst_f = NULL;
524 // read command line options
525 for (i = 1; i < argc; i++) {
526 if (!strcmp(argv[i], "-psxout")) psxout = 1;
527 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
528 else if (!strcmp(argv[i], "-cfg")) {
529 if (i+1 >= argc) break;
530 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
531 SysPrintf("Using config file %s.\n", cfgfile_basename);
533 else if (!strcmp(argv[i], "-cdfile")) {
534 char isofilename[MAXPATHLEN];
536 if (i+1 >= argc) break;
537 strncpy(isofilename, argv[++i], MAXPATHLEN);
538 if (isofilename[0] != '/') {
539 getcwd(path, MAXPATHLEN);
540 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
542 strcat(path, isofilename);
543 strcpy(isofilename, path);
548 cdfile = isofilename;
550 else if (!strcmp(argv[i], "-loadf")) {
551 if (i+1 >= argc) break;
552 loadst_f = argv[++i];
554 else if (!strcmp(argv[i], "-h") ||
555 !strcmp(argv[i], "-help") ||
556 !strcmp(argv[i], "--help")) {
557 printf("PCSX-ReARMed " REV "\n");
559 " pcsx [options] [file]\n"
561 "\t-cdfile FILE\tRuns a CD image file\n"
562 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
563 "\t-psxout\t\tEnable PSX output\n"
564 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
565 "\t-h -help\tDisplay this message\n"
566 "\tfile\t\tLoads a PSX EXE file\n"));
569 strncpy(file, argv[i], MAXPATHLEN);
570 if (file[0] != '/') {
571 getcwd(path, MAXPATHLEN);
572 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
583 set_cd_image(cdfile);
586 // init input but leave probing to platform code,
587 // they add input drivers and may need to modify them after probe
591 menu_init(); // loads config
593 if (emu_core_init() != 0)
599 if (LoadPlugins() == -1) {
600 // FIXME: this recovery doesn't work, just delete bad config and bail out
601 // SysMessage("could not load plugins, retrying with defaults\n");
603 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
605 SysMessage("Failed loading plugins!");
610 if (OpenPlugins() == -1) {
613 plugin_call_rearmed_cbs();
618 if (file[0] != '\0') {
619 if (Load(file) != -1)
623 if (LoadCdrom() == -1) {
625 SysPrintf(_("Could not load CD-ROM!\n"));
628 emu_on_new_cd(!loadst);
634 int ret = LoadState(loadst_f);
635 SysPrintf("%s state file: %s\n",
636 ret ? "failed to load" : "loaded", loadst_f);
637 ready_to_go |= ret == 0;
643 // If a state has been specified, then load that
645 int ret = emu_load_state(loadst - 1);
646 SysPrintf("%s state %d\n",
647 ret ? "failed to load" : "loaded", loadst);
655 while (!g_emu_want_quit)
658 emu_action = SACTION_NONE;
661 if (emu_action != SACTION_NONE)
674 static void toggle_fast_forward(int force_off)
676 static int fast_forward;
677 static int normal_g_opts;
678 static int normal_frameskip;
679 static int normal_enhancement_enable;
681 if (force_off && !fast_forward)
684 fast_forward = !fast_forward;
686 normal_g_opts = g_opts;
687 normal_frameskip = pl_rearmed_cbs.frameskip;
688 normal_enhancement_enable =
689 pl_rearmed_cbs.gpu_neon.enhancement_enable;
691 g_opts |= OPT_NO_FRAMELIM;
692 pl_rearmed_cbs.frameskip = 3;
693 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
695 g_opts = normal_g_opts;
696 pl_rearmed_cbs.frameskip = normal_frameskip;
697 pl_rearmed_cbs.gpu_neon.enhancement_enable =
698 normal_enhancement_enable;
700 pl_timing_prepare(Config.PsxType);
704 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
705 fast_forward ? "ON" : "OFF");
708 static void SignalExit(int sig) {
709 // only to restore framebuffer/resolution on some devices
716 printf("SysRunGui\n");
719 static void dummy_lace()
724 // rearmed hack: EmuReset() runs some code when real BIOS is used,
725 // but we usually do reset from menu while GPU is not open yet,
726 // so we need to prevent updateLace() call..
727 void *real_lace = GPU_updateLace;
728 GPU_updateLace = dummy_lace;
731 // reset can run code, timing must be set
732 pl_timing_prepare(Config.PsxType);
734 // hmh core forgets this
739 GPU_updateLace = real_lace;
749 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
758 int get_state_filename(char *buf, int size, int i) {
759 return get_gameid_filename(buf, size,
760 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
763 int emu_check_state(int slot)
765 char fname[MAXPATHLEN];
768 ret = get_state_filename(fname, sizeof(fname), slot);
772 return CheckState(fname);
775 int emu_save_state(int slot)
777 char fname[MAXPATHLEN];
780 ret = get_state_filename(fname, sizeof(fname), slot);
784 ret = SaveState(fname);
785 #if defined(HAVE_PRE_ARMV7) && !defined(_3DS) && !defined(__SWITCH__) /* XXX GPH hack */
788 SysPrintf("* %s \"%s\" [%d]\n",
789 ret == 0 ? "saved" : "failed to save", fname, slot);
793 int emu_load_state(int slot)
795 char fname[MAXPATHLEN];
800 ret = get_state_filename(fname, sizeof(fname), slot);
804 return LoadState(fname);
807 #ifndef HAVE_LIBRETRO
810 void SysPrintf(const char *fmt, ...) {
814 vfprintf(emuLog, fmt, list);
821 #include <android/log.h>
823 void SysPrintf(const char *fmt, ...) {
827 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
832 #endif /* HAVE_LIBRETRO */
834 void SysMessage(const char *fmt, ...) {
840 ret = vsnprintf(msg, sizeof(msg), fmt, list);
843 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
846 SysPrintf("%s\n", msg);
849 #define PARSEPATH(dst, src) \
850 ptr = src + strlen(src); \
851 while (*ptr != '\\' && ptr != src) ptr--; \
853 strcpy(dst, ptr+1); \
856 static int _OpenPlugins(void) {
860 signal(SIGINT, SignalExit);
861 signal(SIGPIPE, SignalExit);
864 GPU_clearDynarec(clearDynarec);
867 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
869 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
870 SPU_registerCallback(SPUirq);
871 SPU_registerScheduleCb(SPUschedule);
872 // pcsx-rearmed: we handle gpu elsewhere
873 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
874 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
875 ret = PAD1_open(&gpuDisp);
876 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
877 ret = PAD2_open(&gpuDisp);
878 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
880 if (Config.UseNet && !NetOpened) {
882 char path[MAXPATHLEN * 2];
883 char dotdir[MAXPATHLEN];
885 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
887 strcpy(info.EmuName, "PCSX");
888 memcpy(info.CdromID, CdromId, 9); /* no \0 trailing character? */
889 memcpy(info.CdromLabel, CdromLabel, 9);
890 info.CdromLabel[9] = '\0';
892 info.GPU_showScreenPic = GPU_showScreenPic;
893 info.GPU_displayText = GPU_displayText;
894 info.GPU_showScreenPic = GPU_showScreenPic;
895 info.PAD_setSensitive = PAD1_setSensitive;
896 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
897 strcpy(info.BIOSpath, path);
898 strcpy(info.MCD1path, Config.Mcd1);
899 strcpy(info.MCD2path, Config.Mcd2);
900 sprintf(path, "%s%s", dotdir, Config.Gpu);
901 strcpy(info.GPUpath, path);
902 sprintf(path, "%s%s", dotdir, Config.Spu);
903 strcpy(info.SPUpath, path);
904 sprintf(path, "%s%s", dotdir, Config.Cdr);
905 strcpy(info.CDRpath, path);
908 ret = NET_open(&gpuDisp);
911 // -2 is returned when something in the info
912 // changed and needs to be synced
915 PARSEPATH(Config.Bios, info.BIOSpath);
916 PARSEPATH(Config.Gpu, info.GPUpath);
917 PARSEPATH(Config.Spu, info.SPUpath);
918 PARSEPATH(Config.Cdr, info.CDRpath);
920 strcpy(Config.Mcd1, info.MCD1path);
921 strcpy(Config.Mcd2, info.MCD2path);
924 Config.UseNet = FALSE;
927 if (NET_queryPlayer() == 1) {
928 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
930 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
934 } else if (Config.UseNet) {
944 while ((ret = _OpenPlugins()) == -2) {
946 LoadMcds(Config.Mcd1, Config.Mcd2);
947 if (LoadPlugins() == -1) return -1;
952 void ClosePlugins() {
956 signal(SIGINT, SIG_DFL);
957 signal(SIGPIPE, SIG_DFL);
961 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
963 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
965 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
967 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
968 // pcsx-rearmed: we handle gpu elsewhere
970 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
977 /* we hook statically linked plugins here */
978 static const char *builtin_plugins[] = {
979 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
983 static const int builtin_plugin_ids[] = {
984 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
988 void *SysLoadLibrary(const char *lib) {
989 const char *tmp = strrchr(lib, '/');
993 SysPrintf("plugin: %s\n", lib);
997 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
998 if (strcmp(tmp, builtin_plugins[i]) == 0)
999 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
1002 #if !defined(_WIN32) && !defined(NO_DYLIB)
1003 ret = dlopen(lib, RTLD_NOW);
1005 SysMessage("dlopen: %s", dlerror());
1007 /* no external plugin support, abi is no longer
1008 * compatible with psemu/pcsx anyway */
1013 void *SysLoadSym(void *lib, const char *sym) {
1014 unsigned int plugid = (unsigned int)(long)lib;
1016 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1017 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
1019 #if !defined(_WIN32) && !defined(NO_DYLIB)
1020 return dlsym(lib, sym);
1026 const char *SysLibError() {
1027 #if defined(NO_DYLIB)
1029 #elif !defined(_WIN32)
1032 return "not supported";
1036 void SysCloseLibrary(void *lib) {
1037 unsigned int plugid = (unsigned int)(long)lib;
1039 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
1042 #if !defined(_WIN32) && !defined(NO_DYLIB)