4 * This work is licensed under the terms of the GNU GPLv2 or later.
5 * See the COPYING file in the top-level directory.
13 #include <sys/types.h>
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"
32 #include "libpicofe/input.h"
33 #include "libpicofe/plat.h"
34 #include "libpicofe/readpng.h"
36 static void toggle_fast_forward(int force_off);
37 static void check_profile(void);
38 static void check_memcards(void);
41 #define BOOT_MSG "Booting up..."
44 // don't include debug.h - it breaks ARM build (R1 redefined)
48 int ready_to_go, g_emu_want_quit, g_emu_resetting;
49 unsigned long gpuDisp;
50 char cfgfile_basename[MAXPATHLEN];
52 enum sched_action emu_action, emu_action_old;
56 static void make_path(char *buf, size_t size, const char *dir, const char *fname)
59 snprintf(buf, size, ".%s%s", dir, fname);
61 snprintf(buf, size, ".%s", dir);
63 #define MAKE_PATH(buf, dir, fname) \
64 make_path(buf, sizeof(buf), dir, fname)
66 static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
70 strncpy(trimlabel, CdromLabel, 32);
72 for (j = 31; j >= 0; j--)
73 if (trimlabel[j] == ' ')
78 snprintf(buf, size, fmt, trimlabel, CdromId, i);
83 void set_cd_image(const char *fname)
85 const char *ext = NULL;
88 ext = strrchr(fname, '.');
91 strcasecmp(ext, ".z") == 0 || strcasecmp(ext, ".bz") == 0 ||
92 strcasecmp(ext, ".znx") == 0 /*|| strcasecmp(ext, ".pbp") == 0*/)) {
94 cdrcimg_set_fname(fname);
95 strcpy(Config.Cdr, "builtin_cdrcimg");
98 strcpy(Config.Cdr, "builtin_cdr");
102 static void set_default_paths(void)
105 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR);
106 MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
107 MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
108 strcpy(Config.BiosDir, "bios");
111 strcpy(Config.PluginsDir, "plugins");
112 strcpy(Config.Gpu, "builtin_gpu");
113 strcpy(Config.Spu, "builtin_spu");
114 strcpy(Config.Cdr, "builtin_cdr");
115 strcpy(Config.Pad1, "builtin_pad");
116 strcpy(Config.Pad2, "builtin_pad");
117 strcpy(Config.Net, "Disabled");
120 void emu_set_default_config(void)
122 // try to set sane config on which most games work
123 Config.Xa = Config.Cdda = Config.Sio =
124 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
127 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
128 pl_rearmed_cbs.gpu_neon.enhancement_enable =
129 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
130 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
131 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
132 pl_rearmed_cbs.gpu_unai.abe_hack =
133 pl_rearmed_cbs.gpu_unai.no_light =
134 pl_rearmed_cbs.gpu_unai.no_blend = 0;
135 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
136 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
137 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
139 spu_config.iUseReverb = 1;
140 spu_config.iUseInterpolation = 1;
141 spu_config.iXAPitch = 0;
142 spu_config.iVolume = 768;
143 spu_config.iTempo = 0;
144 #if defined(__arm__) && !defined(__ARM_ARCH_7A__) /* XXX */
145 spu_config.iUseReverb = 0;
146 spu_config.iUseInterpolation = 0;
147 spu_config.iTempo = 1;
149 new_dynarec_hacks = 0;
150 cycle_multiplier = 200;
152 in_type1 = PSE_PAD_TYPE_STANDARD;
153 in_type2 = PSE_PAD_TYPE_STANDARD;
156 void do_emu_action(void)
160 emu_action_old = emu_action;
162 switch (emu_action) {
163 case SACTION_LOAD_STATE:
164 ret = emu_load_state(state_slot);
165 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
167 case SACTION_SAVE_STATE:
168 ret = emu_save_state(state_slot);
169 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
172 case SACTION_ENTER_MENU:
173 toggle_fast_forward(1);
176 case SACTION_NEXT_SSLOT:
181 case SACTION_PREV_SSLOT:
186 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
187 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
189 SysPrintf("* %s\n", hud_msg);
191 case SACTION_TOGGLE_FSKIP:
192 pl_rearmed_cbs.fskip_advice = 0;
193 pl_rearmed_cbs.frameskip++;
194 if (pl_rearmed_cbs.frameskip > 1)
195 pl_rearmed_cbs.frameskip = -1;
196 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
197 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
198 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
199 plugin_call_rearmed_cbs();
201 case SACTION_SWITCH_DISPMODE:
202 pl_switch_dispmode();
203 plugin_call_rearmed_cbs();
204 if (GPU_open != NULL && GPU_close != NULL) {
206 GPU_open(&gpuDisp, "PCSX", NULL);
209 case SACTION_FAST_FORWARD:
210 toggle_fast_forward(0);
211 plugin_call_rearmed_cbs();
213 case SACTION_TOGGLE_FPS:
214 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
215 == (OPT_SHOWFPS|OPT_SHOWCPU))
216 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
217 else if (g_opts & OPT_SHOWFPS)
218 g_opts |= OPT_SHOWCPU;
220 g_opts |= OPT_SHOWFPS;
222 case SACTION_TOGGLE_FULLSCREEN:
223 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
224 if (GPU_open != NULL && GPU_close != NULL) {
226 GPU_open(&gpuDisp, "PCSX", NULL);
229 case SACTION_SCREENSHOT:
231 char buf[MAXPATHLEN];
234 time_t t = time(NULL);
235 struct tm *tb = localtime(&t);
236 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
237 tb->tm_min * 100 + tb->tm_sec;
239 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
240 get_gameid_filename(buf, sizeof(buf),
241 "screenshots/%.32s-%.9s.%d.png", ti);
243 if (scrbuf != 0 && bpp == 16)
244 ret = writepng(buf, scrbuf, w, h);
246 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
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);
277 static char basic_lcase(char c)
279 if ('A' <= c && c <= 'Z')
280 return c - 'A' + 'a';
284 static int cdidcmp(const char *id1, const char *id2)
286 while (*id1 != 0 && *id2 != 0) {
287 if (*id1 == '_') { id1++; continue; }
288 if (*id2 == '_') { id2++; continue; }
289 if (basic_lcase(*id1) != basic_lcase(*id2))
298 static void parse_cwcheat(void)
300 char line[256], buf[64], name[64], *p;
305 f = fopen("cheatpops.db", "r");
310 while (fgets(line, sizeof(line), f)) {
311 if (sscanf(line, "_S %63s", buf) != 1)
313 if (cdidcmp(buf, CdromId) == 0)
320 SysPrintf("cwcheat section found for %s\n", CdromId);
321 while (fgets(line, sizeof(line), f))
323 p = line + strlen(line);
324 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
326 if (*p == 0 || *p == '#' || *p == ';')
329 if (strncmp(line, "_S", 2) == 0)
331 if (strncmp(line, "_G", 2) == 0) {
332 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
335 if (strncmp(line, "_C0", 3) == 0) {
336 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
337 SysPrintf("cheat '%s' failed to parse\n", name);
338 free(Cheats[NumCheats - 1].Descr);
341 snprintf(name, sizeof(name), "%s", line + 4);
345 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
346 SysPrintf("line failed to parse: '%s'\n", line);
351 if (NumCheats >= NumCheatsAllocated) {
352 NumCheatsAllocated += 16;
353 Cheats = realloc(Cheats, sizeof(Cheat) *
358 Cheats[NumCheats].Descr = strdup(name);
359 Cheats[NumCheats].Enabled = 0;
360 Cheats[NumCheats].WasEnabled = 0;
361 Cheats[NumCheats].First = NumCodes;
362 Cheats[NumCheats].n = 0;
367 if (NumCodes >= NumCodesAllocated) {
368 NumCodesAllocated += 16;
369 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
371 if (CheatCodes == NULL)
374 CheatCodes[NumCodes].Addr = a;
375 CheatCodes[NumCodes].Val = v;
377 Cheats[NumCheats - 1].n++;
384 void emu_on_new_cd(int show_hud_msg)
390 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
391 SysPrintf("----------------------------------------------------------\n");
395 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
400 int emu_core_preinit(void)
402 // what is the name of the config file?
403 // it may be redefined by -cfg on the command line
404 strcpy(cfgfile_basename, "pcsx.cfg");
407 emuLog = fopen("/User/Documents/pcsxr.log", "w");
409 emuLog = fopen("pcsxr.log", "w");
416 memset(&Config, 0, sizeof(Config));
419 emu_set_default_config();
420 strcpy(Config.Bios, "HLE");
425 int emu_core_init(void)
427 SysPrintf("Starting PCSX-ReARMed " REV "\n");
434 if (EmuInit() == -1) {
435 SysPrintf("PSX emulator couldn't be initialized.\n");
439 LoadMcds(Config.Mcd1, Config.Mcd2);
448 void emu_core_ask_exit(void)
455 static void create_profile_dir(const char *directory) {
456 char path[MAXPATHLEN];
458 MAKE_PATH(path, directory, NULL);
459 mkdir(path, S_IRWXU | S_IRWXG);
462 static void check_profile(void) {
463 // make sure that ~/.pcsx exists
464 create_profile_dir(PCSX_DOT_DIR);
466 create_profile_dir(BIOS_DIR);
467 create_profile_dir(MEMCARD_DIR);
468 create_profile_dir(STATES_DIR);
469 create_profile_dir(PLUGINS_DIR);
470 create_profile_dir(PLUGINS_CFG_DIR);
471 create_profile_dir(CHEATS_DIR);
472 create_profile_dir(PATCHES_DIR);
473 create_profile_dir(PCSX_DOT_DIR "cfg");
474 create_profile_dir("/screenshots/");
477 static void check_memcards(void)
479 char buf[MAXPATHLEN];
483 for (i = 1; i <= 9; i++) {
484 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
486 f = fopen(buf, "rb");
488 SysPrintf("Creating memcard: %s\n", buf);
496 int main(int argc, char *argv[])
498 char file[MAXPATHLEN] = "";
499 char path[MAXPATHLEN];
500 const char *cdfile = NULL;
501 const char *loadst_f = NULL;
508 // read command line options
509 for (i = 1; i < argc; i++) {
510 if (!strcmp(argv[i], "-psxout")) psxout = 1;
511 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
512 else if (!strcmp(argv[i], "-cfg")) {
513 if (i+1 >= argc) break;
514 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
515 SysPrintf("Using config file %s.\n", cfgfile_basename);
517 else if (!strcmp(argv[i], "-cdfile")) {
518 char isofilename[MAXPATHLEN];
520 if (i+1 >= argc) break;
521 strncpy(isofilename, argv[++i], MAXPATHLEN);
522 if (isofilename[0] != '/') {
523 getcwd(path, MAXPATHLEN);
524 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
526 strcat(path, isofilename);
527 strcpy(isofilename, path);
532 cdfile = isofilename;
534 else if (!strcmp(argv[i], "-loadf")) {
535 if (i+1 >= argc) break;
536 loadst_f = argv[++i];
538 else if (!strcmp(argv[i], "-h") ||
539 !strcmp(argv[i], "-help") ||
540 !strcmp(argv[i], "--help")) {
541 printf("PCSX-ReARMed " REV "\n");
543 " pcsx [options] [file]\n"
545 "\t-cdfile FILE\tRuns a CD image file\n"
546 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
547 "\t-psxout\t\tEnable PSX output\n"
548 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
549 "\t-h -help\tDisplay this message\n"
550 "\tfile\t\tLoads a PSX EXE file\n"));
553 strncpy(file, argv[i], MAXPATHLEN);
554 if (file[0] != '/') {
555 getcwd(path, MAXPATHLEN);
556 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
567 set_cd_image(cdfile);
570 // init input but leave probing to platform code,
571 // they add input drivers and may need to modify them after probe
575 menu_init(); // loads config
577 if (emu_core_init() != 0)
583 if (LoadPlugins() == -1) {
584 // FIXME: this recovery doesn't work, just delete bad config and bail out
585 // SysMessage("could not load plugins, retrying with defaults\n");
587 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
589 SysMessage("Failed loading plugins!");
594 if (OpenPlugins() == -1) {
597 plugin_call_rearmed_cbs();
602 if (file[0] != '\0') {
603 if (Load(file) != -1)
607 if (LoadCdrom() == -1) {
609 SysPrintf(_("Could not load CD-ROM!\n"));
612 emu_on_new_cd(!loadst);
618 int ret = LoadState(loadst_f);
619 SysPrintf("%s state file: %s\n",
620 ret ? "failed to load" : "loaded", loadst_f);
621 ready_to_go |= ret == 0;
627 // If a state has been specified, then load that
629 int ret = emu_load_state(loadst - 1);
630 SysPrintf("%s state %d\n",
631 ret ? "failed to load" : "loaded", loadst);
639 while (!g_emu_want_quit)
642 emu_action = SACTION_NONE;
645 if (emu_action != SACTION_NONE)
658 static void toggle_fast_forward(int force_off)
660 static int fast_forward;
661 static int normal_g_opts;
662 static int normal_frameskip;
663 static int normal_enhancement_enable;
665 if (force_off && !fast_forward)
668 fast_forward = !fast_forward;
670 normal_g_opts = g_opts;
671 normal_frameskip = pl_rearmed_cbs.frameskip;
672 normal_enhancement_enable =
673 pl_rearmed_cbs.gpu_neon.enhancement_enable;
675 g_opts |= OPT_NO_FRAMELIM;
676 pl_rearmed_cbs.frameskip = 3;
677 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
679 g_opts = normal_g_opts;
680 pl_rearmed_cbs.frameskip = normal_frameskip;
681 pl_rearmed_cbs.gpu_neon.enhancement_enable =
682 normal_enhancement_enable;
684 pl_timing_prepare(Config.PsxType);
688 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
689 fast_forward ? "ON" : "OFF");
692 static void SignalExit(int sig) {
693 // only to restore framebuffer/resolution on some devices
700 printf("SysRunGui\n");
703 static void dummy_lace()
708 // rearmed hack: EmuReset() runs some code when real BIOS is used,
709 // but we usually do reset from menu while GPU is not open yet,
710 // so we need to prevent updateLace() call..
711 void *real_lace = GPU_updateLace;
712 GPU_updateLace = dummy_lace;
715 // reset can run code, timing must be set
716 pl_timing_prepare(Config.PsxType);
720 // hmh core forgets this
723 GPU_updateLace = real_lace;
733 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
742 int get_state_filename(char *buf, int size, int i) {
743 return get_gameid_filename(buf, size,
744 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
747 int emu_check_state(int slot)
749 char fname[MAXPATHLEN];
752 ret = get_state_filename(fname, sizeof(fname), slot);
756 return CheckState(fname);
759 int emu_save_state(int slot)
761 char fname[MAXPATHLEN];
764 ret = get_state_filename(fname, sizeof(fname), slot);
768 ret = SaveState(fname);
769 #ifndef __ARM_ARCH_7A__ /* XXX */
772 SysPrintf("* %s \"%s\" [%d]\n",
773 ret == 0 ? "saved" : "failed to save", fname, slot);
777 int emu_load_state(int slot)
779 char fname[MAXPATHLEN];
784 ret = get_state_filename(fname, sizeof(fname), slot);
788 return LoadState(fname);
793 void SysPrintf(const char *fmt, ...) {
797 vfprintf(emuLog, fmt, list);
804 #include <android/log.h>
806 void SysPrintf(const char *fmt, ...) {
810 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
816 void SysMessage(const char *fmt, ...) {
822 ret = vsnprintf(msg, sizeof(msg), fmt, list);
825 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
828 SysPrintf("%s\n", msg);
831 #define PARSEPATH(dst, src) \
832 ptr = src + strlen(src); \
833 while (*ptr != '\\' && ptr != src) ptr--; \
835 strcpy(dst, ptr+1); \
838 static int _OpenPlugins(void) {
842 signal(SIGINT, SignalExit);
843 signal(SIGPIPE, SignalExit);
846 GPU_clearDynarec(clearDynarec);
849 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
851 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
852 SPU_registerCallback(SPUirq);
853 SPU_registerScheduleCb(SPUschedule);
854 // pcsx-rearmed: we handle gpu elsewhere
855 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
856 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
857 ret = PAD1_open(&gpuDisp);
858 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
859 ret = PAD2_open(&gpuDisp);
860 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
862 if (Config.UseNet && !NetOpened) {
864 char path[MAXPATHLEN];
865 char dotdir[MAXPATHLEN];
867 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
869 strcpy(info.EmuName, "PCSX");
870 strncpy(info.CdromID, CdromId, 9);
871 strncpy(info.CdromLabel, CdromLabel, 9);
873 info.GPU_showScreenPic = GPU_showScreenPic;
874 info.GPU_displayText = GPU_displayText;
875 info.GPU_showScreenPic = GPU_showScreenPic;
876 info.PAD_setSensitive = PAD1_setSensitive;
877 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
878 strcpy(info.BIOSpath, path);
879 strcpy(info.MCD1path, Config.Mcd1);
880 strcpy(info.MCD2path, Config.Mcd2);
881 sprintf(path, "%s%s", dotdir, Config.Gpu);
882 strcpy(info.GPUpath, path);
883 sprintf(path, "%s%s", dotdir, Config.Spu);
884 strcpy(info.SPUpath, path);
885 sprintf(path, "%s%s", dotdir, Config.Cdr);
886 strcpy(info.CDRpath, path);
889 ret = NET_open(&gpuDisp);
892 // -2 is returned when something in the info
893 // changed and needs to be synced
896 PARSEPATH(Config.Bios, info.BIOSpath);
897 PARSEPATH(Config.Gpu, info.GPUpath);
898 PARSEPATH(Config.Spu, info.SPUpath);
899 PARSEPATH(Config.Cdr, info.CDRpath);
901 strcpy(Config.Mcd1, info.MCD1path);
902 strcpy(Config.Mcd2, info.MCD2path);
905 Config.UseNet = FALSE;
908 if (NET_queryPlayer() == 1) {
909 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
911 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
915 } else if (Config.UseNet) {
925 while ((ret = _OpenPlugins()) == -2) {
927 LoadMcds(Config.Mcd1, Config.Mcd2);
928 if (LoadPlugins() == -1) return -1;
933 void ClosePlugins() {
937 signal(SIGINT, SIG_DFL);
938 signal(SIGPIPE, SIG_DFL);
942 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
944 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
946 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
948 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
949 // pcsx-rearmed: we handle gpu elsewhere
951 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
958 /* we hook statically linked plugins here */
959 static const char *builtin_plugins[] = {
960 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
964 static const int builtin_plugin_ids[] = {
965 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
969 void *SysLoadLibrary(const char *lib) {
970 const char *tmp = strrchr(lib, '/');
974 SysPrintf("plugin: %s\n", lib);
978 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
979 if (strcmp(tmp, builtin_plugins[i]) == 0)
980 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
983 ret = dlopen(lib, RTLD_NOW);
985 SysMessage("dlopen: %s", dlerror());
989 void *SysLoadSym(void *lib, const char *sym) {
990 unsigned int plugid = (unsigned int)(long)lib;
992 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
993 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
995 return dlsym(lib, sym);
998 const char *SysLibError() {
1002 void SysCloseLibrary(void *lib) {
1003 unsigned int plugid = (unsigned int)(long)lib;
1005 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))