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"
31 #include "libpicofe/input.h"
32 #include "libpicofe/plat.h"
33 #include "libpicofe/readpng.h"
35 static void toggle_fast_forward(int force_off);
36 static void check_profile(void);
37 static void check_memcards(void);
40 #define BOOT_MSG "Booting up..."
43 // don't include debug.h - it breaks ARM build (R1 redefined)
48 extern int iUseReverb;
49 extern int iUseInterpolation;
53 int ready_to_go, g_emu_want_quit, g_emu_resetting;
54 unsigned long gpuDisp;
55 char cfgfile_basename[MAXPATHLEN];
57 enum sched_action emu_action, emu_action_old;
61 static void make_path(char *buf, size_t size, const char *dir, const char *fname)
64 snprintf(buf, size, ".%s%s", dir, fname);
66 snprintf(buf, size, ".%s", dir);
68 #define MAKE_PATH(buf, dir, fname) \
69 make_path(buf, sizeof(buf), dir, fname)
71 static int get_gameid_filename(char *buf, int size, const char *fmt, int i) {
75 strncpy(trimlabel, CdromLabel, 32);
77 for (j = 31; j >= 0; j--)
78 if (trimlabel[j] == ' ')
83 snprintf(buf, size, fmt, trimlabel, CdromId, i);
88 void set_cd_image(const char *fname)
90 const char *ext = NULL;
93 ext = strrchr(fname, '.');
96 strcasecmp(ext, ".z") == 0 || strcasecmp(ext, ".bz") == 0 ||
97 strcasecmp(ext, ".znx") == 0 /*|| strcasecmp(ext, ".pbp") == 0*/)) {
99 cdrcimg_set_fname(fname);
100 strcpy(Config.Cdr, "builtin_cdrcimg");
103 strcpy(Config.Cdr, "builtin_cdr");
107 static void set_default_paths(void)
110 snprintf(Config.PatchesDir, sizeof(Config.PatchesDir), "." PATCHES_DIR);
111 MAKE_PATH(Config.Mcd1, MEMCARD_DIR, "card1.mcd");
112 MAKE_PATH(Config.Mcd2, MEMCARD_DIR, "card2.mcd");
113 strcpy(Config.BiosDir, "bios");
116 strcpy(Config.PluginsDir, "plugins");
117 strcpy(Config.Gpu, "builtin_gpu");
118 strcpy(Config.Spu, "builtin_spu");
119 strcpy(Config.Cdr, "builtin_cdr");
120 strcpy(Config.Pad1, "builtin_pad");
121 strcpy(Config.Pad2, "builtin_pad");
122 strcpy(Config.Net, "Disabled");
125 void emu_set_default_config(void)
127 // try to set sane config on which most games work
128 Config.Xa = Config.Cdda = Config.Sio =
129 Config.SpuIrq = Config.RCntFix = Config.VSyncWA = 0;
132 pl_rearmed_cbs.gpu_neon.allow_interlace = 2; // auto
133 pl_rearmed_cbs.gpu_neon.enhancement_enable =
134 pl_rearmed_cbs.gpu_neon.enhancement_no_main = 0;
135 pl_rearmed_cbs.gpu_peops.iUseDither = 0;
136 pl_rearmed_cbs.gpu_peops.dwActFixes = 1<<7;
137 pl_rearmed_cbs.gpu_unai.abe_hack =
138 pl_rearmed_cbs.gpu_unai.no_light =
139 pl_rearmed_cbs.gpu_unai.no_blend = 0;
140 memset(&pl_rearmed_cbs.gpu_peopsgl, 0, sizeof(pl_rearmed_cbs.gpu_peopsgl));
141 pl_rearmed_cbs.gpu_peopsgl.iVRamSize = 64;
142 pl_rearmed_cbs.gpu_peopsgl.iTexGarbageCollection = 1;
145 iUseInterpolation = 1;
148 #ifndef __ARM_ARCH_7A__ /* XXX */
150 iUseInterpolation = 0;
152 new_dynarec_hacks = 0;
153 cycle_multiplier = 200;
155 in_type1 = PSE_PAD_TYPE_STANDARD;
156 in_type2 = PSE_PAD_TYPE_STANDARD;
159 void do_emu_action(void)
163 emu_action_old = emu_action;
165 switch (emu_action) {
166 case SACTION_LOAD_STATE:
167 ret = emu_load_state(state_slot);
168 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
170 case SACTION_SAVE_STATE:
171 ret = emu_save_state(state_slot);
172 snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "SAVED" : "FAIL!");
175 case SACTION_ENTER_MENU:
176 toggle_fast_forward(1);
179 case SACTION_NEXT_SSLOT:
184 case SACTION_PREV_SSLOT:
189 snprintf(hud_msg, sizeof(hud_msg), "STATE SLOT %d [%s]", state_slot,
190 emu_check_state(state_slot) == 0 ? "USED" : "FREE");
192 SysPrintf("* %s\n", hud_msg);
194 case SACTION_TOGGLE_FSKIP:
195 pl_rearmed_cbs.fskip_advice = 0;
196 pl_rearmed_cbs.frameskip++;
197 if (pl_rearmed_cbs.frameskip > 1)
198 pl_rearmed_cbs.frameskip = -1;
199 snprintf(hud_msg, sizeof(hud_msg), "FRAMESKIP: %s",
200 pl_rearmed_cbs.frameskip == -1 ? "AUTO" :
201 pl_rearmed_cbs.frameskip == 0 ? "OFF" : "1" );
202 plugin_call_rearmed_cbs();
204 case SACTION_SWITCH_DISPMODE:
205 pl_switch_dispmode();
206 plugin_call_rearmed_cbs();
207 if (GPU_open != NULL && GPU_close != NULL) {
209 GPU_open(&gpuDisp, "PCSX", NULL);
212 case SACTION_FAST_FORWARD:
213 toggle_fast_forward(0);
214 plugin_call_rearmed_cbs();
216 case SACTION_TOGGLE_FPS:
217 if ((g_opts & (OPT_SHOWFPS|OPT_SHOWCPU))
218 == (OPT_SHOWFPS|OPT_SHOWCPU))
219 g_opts &= ~(OPT_SHOWFPS|OPT_SHOWCPU);
220 else if (g_opts & OPT_SHOWFPS)
221 g_opts |= OPT_SHOWCPU;
223 g_opts |= OPT_SHOWFPS;
225 case SACTION_TOGGLE_FULLSCREEN:
226 plat_target.vout_fullscreen = !plat_target.vout_fullscreen;
227 if (GPU_open != NULL && GPU_close != NULL) {
229 GPU_open(&gpuDisp, "PCSX", NULL);
232 case SACTION_SCREENSHOT:
234 char buf[MAXPATHLEN];
237 time_t t = time(NULL);
238 struct tm *tb = localtime(&t);
239 int ti = tb->tm_yday * 1000000 + tb->tm_hour * 10000 +
240 tb->tm_min * 100 + tb->tm_sec;
242 scrbuf = pl_prepare_screenshot(&w, &h, &bpp);
243 get_gameid_filename(buf, sizeof(buf),
244 "screenshots/%.32s-%.9s.%d.png", ti);
246 if (scrbuf != 0 && bpp == 16)
247 ret = writepng(buf, scrbuf, w, h);
249 snprintf(hud_msg, sizeof(hud_msg), "SCREENSHOT TAKEN");
252 case SACTION_VOLUME_UP:
253 case SACTION_VOLUME_DOWN:
256 plat_target_step_volume(&volume,
257 emu_action == SACTION_VOLUME_UP ? 1 : -1);
260 case SACTION_MINIMIZE:
261 if (GPU_close != NULL)
266 if (GPU_open != NULL) {
267 ret = GPU_open(&gpuDisp, "PCSX", NULL);
269 SysMessage("GPU_open returned %d", ret);
280 static char basic_lcase(char c)
282 if ('A' <= c && c <= 'Z')
283 return c - 'A' + 'a';
287 static int cdidcmp(const char *id1, const char *id2)
289 while (*id1 != 0 && *id2 != 0) {
290 if (*id1 == '_') { id1++; continue; }
291 if (*id2 == '_') { id2++; continue; }
292 if (basic_lcase(*id1) != basic_lcase(*id2))
301 static void parse_cwcheat(void)
303 char line[256], buf[64], name[64], *p;
308 f = fopen("cheatpops.db", "r");
313 while (fgets(line, sizeof(line), f)) {
314 if (sscanf(line, "_S %63s", buf) != 1)
316 if (cdidcmp(buf, CdromId) == 0)
323 SysPrintf("cwcheat section found for %s\n", CdromId);
324 while (fgets(line, sizeof(line), f))
326 p = line + strlen(line);
327 for (p--; p >= line && (*p == '\r' || *p == '\n' || *p == ' '); p--)
329 if (*p == 0 || *p == '#' || *p == ';')
332 if (strncmp(line, "_S", 2) == 0)
334 if (strncmp(line, "_G", 2) == 0) {
335 SysPrintf(" cwcheat game name: '%s'\n", line + 3);
338 if (strncmp(line, "_C0", 3) == 0) {
339 if (!newcheat && Cheats[NumCheats - 1].n == 0) {
340 SysPrintf("cheat '%s' failed to parse\n", name);
341 free(Cheats[NumCheats - 1].Descr);
344 snprintf(name, sizeof(name), "%s", line + 4);
348 if (sscanf(line, "_L %x %x", &a, &v) != 2) {
349 SysPrintf("line failed to parse: '%s'\n", line);
354 if (NumCheats >= NumCheatsAllocated) {
355 NumCheatsAllocated += 16;
356 Cheats = realloc(Cheats, sizeof(Cheat) *
361 Cheats[NumCheats].Descr = strdup(name);
362 Cheats[NumCheats].Enabled = 0;
363 Cheats[NumCheats].WasEnabled = 0;
364 Cheats[NumCheats].First = NumCodes;
365 Cheats[NumCheats].n = 0;
370 if (NumCodes >= NumCodesAllocated) {
371 NumCodesAllocated += 16;
372 CheatCodes = realloc(CheatCodes, sizeof(CheatCode) *
374 if (CheatCodes == NULL)
377 CheatCodes[NumCodes].Addr = a;
378 CheatCodes[NumCodes].Val = v;
380 Cheats[NumCheats - 1].n++;
387 void emu_on_new_cd(int show_hud_msg)
393 SysPrintf("note: running with HLE BIOS, expect compatibility problems\n");
394 SysPrintf("----------------------------------------------------------\n");
398 snprintf(hud_msg, sizeof(hud_msg), BOOT_MSG);
403 int emu_core_preinit(void)
405 // what is the name of the config file?
406 // it may be redefined by -cfg on the command line
407 strcpy(cfgfile_basename, "pcsx.cfg");
410 emuLog = fopen("/User/Documents/pcsxr.log", "w");
412 emuLog = fopen("pcsxr.log", "w");
419 memset(&Config, 0, sizeof(Config));
422 emu_set_default_config();
423 strcpy(Config.Bios, "HLE");
428 int emu_core_init(void)
430 SysPrintf("Starting PCSX-ReARMed " REV "\n");
437 if (EmuInit() == -1) {
438 SysPrintf("PSX emulator couldn't be initialized.\n");
442 LoadMcds(Config.Mcd1, Config.Mcd2);
451 void emu_core_ask_exit(void)
458 static void create_profile_dir(const char *directory) {
459 char path[MAXPATHLEN];
461 MAKE_PATH(path, directory, NULL);
462 mkdir(path, S_IRWXU | S_IRWXG);
465 static void check_profile(void) {
466 // make sure that ~/.pcsx exists
467 create_profile_dir(PCSX_DOT_DIR);
469 create_profile_dir(BIOS_DIR);
470 create_profile_dir(MEMCARD_DIR);
471 create_profile_dir(STATES_DIR);
472 create_profile_dir(PLUGINS_DIR);
473 create_profile_dir(PLUGINS_CFG_DIR);
474 create_profile_dir(CHEATS_DIR);
475 create_profile_dir(PATCHES_DIR);
476 create_profile_dir(PCSX_DOT_DIR "cfg");
477 create_profile_dir("/screenshots/");
480 static void check_memcards(void)
482 char buf[MAXPATHLEN];
486 for (i = 1; i <= 9; i++) {
487 snprintf(buf, sizeof(buf), ".%scard%d.mcd", MEMCARD_DIR, i);
489 f = fopen(buf, "rb");
491 SysPrintf("Creating memcard: %s\n", buf);
499 int main(int argc, char *argv[])
501 char file[MAXPATHLEN] = "";
502 char path[MAXPATHLEN];
503 const char *cdfile = NULL;
504 const char *loadst_f = NULL;
511 // read command line options
512 for (i = 1; i < argc; i++) {
513 if (!strcmp(argv[i], "-psxout")) psxout = 1;
514 else if (!strcmp(argv[i], "-load")) loadst = atol(argv[++i]);
515 else if (!strcmp(argv[i], "-cfg")) {
516 if (i+1 >= argc) break;
517 strncpy(cfgfile_basename, argv[++i], MAXPATHLEN-100); /* TODO buffer overruns */
518 SysPrintf("Using config file %s.\n", cfgfile_basename);
520 else if (!strcmp(argv[i], "-cdfile")) {
521 char isofilename[MAXPATHLEN];
523 if (i+1 >= argc) break;
524 strncpy(isofilename, argv[++i], MAXPATHLEN);
525 if (isofilename[0] != '/') {
526 getcwd(path, MAXPATHLEN);
527 if (strlen(path) + strlen(isofilename) + 1 < MAXPATHLEN) {
529 strcat(path, isofilename);
530 strcpy(isofilename, path);
535 cdfile = isofilename;
537 else if (!strcmp(argv[i], "-loadf")) {
538 if (i+1 >= argc) break;
539 loadst_f = argv[++i];
541 else if (!strcmp(argv[i], "-h") ||
542 !strcmp(argv[i], "-help") ||
543 !strcmp(argv[i], "--help")) {
544 printf("PCSX-ReARMed " REV "\n");
546 " pcsx [options] [file]\n"
548 "\t-cdfile FILE\tRuns a CD image file\n"
549 "\t-cfg FILE\tLoads desired configuration file (default: ~/.pcsx/pcsx.cfg)\n"
550 "\t-psxout\t\tEnable PSX output\n"
551 "\t-load STATENUM\tLoads savestate STATENUM (1-5)\n"
552 "\t-h -help\tDisplay this message\n"
553 "\tfile\t\tLoads a PSX EXE file\n"));
556 strncpy(file, argv[i], MAXPATHLEN);
557 if (file[0] != '/') {
558 getcwd(path, MAXPATHLEN);
559 if (strlen(path) + strlen(file) + 1 < MAXPATHLEN) {
570 set_cd_image(cdfile);
573 // init input but leave probing to platform code,
574 // they add input drivers and may need to modify them after probe
578 menu_init(); // loads config
580 if (emu_core_init() != 0)
586 if (LoadPlugins() == -1) {
587 // FIXME: this recovery doesn't work, just delete bad config and bail out
588 // SysMessage("could not load plugins, retrying with defaults\n");
590 snprintf(path, sizeof(path), "." PCSX_DOT_DIR "%s", cfgfile_basename);
592 SysMessage("Failed loading plugins!");
597 if (OpenPlugins() == -1) {
600 plugin_call_rearmed_cbs();
605 if (file[0] != '\0') {
606 if (Load(file) != -1)
610 if (LoadCdrom() == -1) {
612 SysPrintf(_("Could not load CD-ROM!\n"));
615 emu_on_new_cd(!loadst);
621 int ret = LoadState(loadst_f);
622 SysPrintf("%s state file: %s\n",
623 ret ? "failed to load" : "loaded", loadst_f);
624 ready_to_go |= ret == 0;
630 // If a state has been specified, then load that
632 int ret = emu_load_state(loadst - 1);
633 SysPrintf("%s state %d\n",
634 ret ? "failed to load" : "loaded", loadst);
642 while (!g_emu_want_quit)
645 emu_action = SACTION_NONE;
648 if (emu_action != SACTION_NONE)
661 static void toggle_fast_forward(int force_off)
663 static int fast_forward;
664 static int normal_g_opts;
665 static int normal_frameskip;
666 static int normal_enhancement_enable;
668 if (force_off && !fast_forward)
671 fast_forward = !fast_forward;
673 normal_g_opts = g_opts;
674 normal_frameskip = pl_rearmed_cbs.frameskip;
675 normal_enhancement_enable =
676 pl_rearmed_cbs.gpu_neon.enhancement_enable;
678 g_opts |= OPT_NO_FRAMELIM;
679 pl_rearmed_cbs.frameskip = 3;
680 pl_rearmed_cbs.gpu_neon.enhancement_enable = 0;
682 g_opts = normal_g_opts;
683 pl_rearmed_cbs.frameskip = normal_frameskip;
684 pl_rearmed_cbs.gpu_neon.enhancement_enable =
685 normal_enhancement_enable;
687 pl_timing_prepare(Config.PsxType);
691 snprintf(hud_msg, sizeof(hud_msg), "FAST FORWARD %s",
692 fast_forward ? "ON" : "OFF");
695 static void SignalExit(int sig) {
696 // only to restore framebuffer/resolution on some devices
703 printf("SysRunGui\n");
706 static void dummy_lace()
711 // rearmed hack: EmuReset() runs some code when real BIOS is used,
712 // but we usually do reset from menu while GPU is not open yet,
713 // so we need to prevent updateLace() call..
714 void *real_lace = GPU_updateLace;
715 GPU_updateLace = dummy_lace;
718 // reset can run code, timing must be set
719 pl_timing_prepare(Config.PsxType);
723 // hmh core forgets this
726 GPU_updateLace = real_lace;
736 if (emuLog != NULL && emuLog != stdout && emuLog != stderr) {
745 int get_state_filename(char *buf, int size, int i) {
746 return get_gameid_filename(buf, size,
747 "." STATES_DIR "%.32s-%.9s.%3.3d", i);
750 int emu_check_state(int slot)
752 char fname[MAXPATHLEN];
755 ret = get_state_filename(fname, sizeof(fname), slot);
759 return CheckState(fname);
762 int emu_save_state(int slot)
764 char fname[MAXPATHLEN];
767 ret = get_state_filename(fname, sizeof(fname), slot);
771 ret = SaveState(fname);
772 #ifndef __ARM_ARCH_7A__ /* XXX */
775 SysPrintf("* %s \"%s\" [%d]\n",
776 ret == 0 ? "saved" : "failed to save", fname, slot);
780 int emu_load_state(int slot)
782 char fname[MAXPATHLEN];
787 ret = get_state_filename(fname, sizeof(fname), slot);
791 return LoadState(fname);
796 void SysPrintf(const char *fmt, ...) {
800 vfprintf(emuLog, fmt, list);
807 #include <android/log.h>
809 void SysPrintf(const char *fmt, ...) {
813 __android_log_vprint(ANDROID_LOG_INFO, "PCSX", fmt, list);
819 void SysMessage(const char *fmt, ...) {
825 ret = vsnprintf(msg, sizeof(msg), fmt, list);
828 if (ret < sizeof(msg) && msg[ret - 1] == '\n')
831 SysPrintf("%s\n", msg);
834 #define PARSEPATH(dst, src) \
835 ptr = src + strlen(src); \
836 while (*ptr != '\\' && ptr != src) ptr--; \
838 strcpy(dst, ptr+1); \
841 static int _OpenPlugins(void) {
845 signal(SIGINT, SignalExit);
846 signal(SIGPIPE, SignalExit);
849 GPU_clearDynarec(clearDynarec);
852 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
854 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
855 SPU_registerCallback(SPUirq);
856 SPU_registerScheduleCb(SPUschedule);
857 // pcsx-rearmed: we handle gpu elsewhere
858 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
859 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
860 ret = PAD1_open(&gpuDisp);
861 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
862 ret = PAD2_open(&gpuDisp);
863 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
865 if (Config.UseNet && !NetOpened) {
867 char path[MAXPATHLEN];
868 char dotdir[MAXPATHLEN];
870 MAKE_PATH(dotdir, "/.pcsx/plugins/", NULL);
872 strcpy(info.EmuName, "PCSX");
873 strncpy(info.CdromID, CdromId, 9);
874 strncpy(info.CdromLabel, CdromLabel, 9);
876 info.GPU_showScreenPic = GPU_showScreenPic;
877 info.GPU_displayText = GPU_displayText;
878 info.GPU_showScreenPic = GPU_showScreenPic;
879 info.PAD_setSensitive = PAD1_setSensitive;
880 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
881 strcpy(info.BIOSpath, path);
882 strcpy(info.MCD1path, Config.Mcd1);
883 strcpy(info.MCD2path, Config.Mcd2);
884 sprintf(path, "%s%s", dotdir, Config.Gpu);
885 strcpy(info.GPUpath, path);
886 sprintf(path, "%s%s", dotdir, Config.Spu);
887 strcpy(info.SPUpath, path);
888 sprintf(path, "%s%s", dotdir, Config.Cdr);
889 strcpy(info.CDRpath, path);
892 ret = NET_open(&gpuDisp);
895 // -2 is returned when something in the info
896 // changed and needs to be synced
899 PARSEPATH(Config.Bios, info.BIOSpath);
900 PARSEPATH(Config.Gpu, info.GPUpath);
901 PARSEPATH(Config.Spu, info.SPUpath);
902 PARSEPATH(Config.Cdr, info.CDRpath);
904 strcpy(Config.Mcd1, info.MCD1path);
905 strcpy(Config.Mcd2, info.MCD2path);
908 Config.UseNet = FALSE;
911 if (NET_queryPlayer() == 1) {
912 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
914 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
918 } else if (Config.UseNet) {
928 while ((ret = _OpenPlugins()) == -2) {
930 LoadMcds(Config.Mcd1, Config.Mcd2);
931 if (LoadPlugins() == -1) return -1;
936 void ClosePlugins() {
940 signal(SIGINT, SIG_DFL);
941 signal(SIGPIPE, SIG_DFL);
945 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
947 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
949 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
951 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
952 // pcsx-rearmed: we handle gpu elsewhere
954 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }
961 /* we hook statically linked plugins here */
962 static const char *builtin_plugins[] = {
963 "builtin_gpu", "builtin_spu", "builtin_cdr", "builtin_pad",
967 static const int builtin_plugin_ids[] = {
968 PLUGIN_GPU, PLUGIN_SPU, PLUGIN_CDR, PLUGIN_PAD,
972 void *SysLoadLibrary(const char *lib) {
973 const char *tmp = strrchr(lib, '/');
977 SysPrintf("plugin: %s\n", lib);
981 for (i = 0; i < ARRAY_SIZE(builtin_plugins); i++)
982 if (strcmp(tmp, builtin_plugins[i]) == 0)
983 return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]);
986 ret = dlopen(lib, RTLD_NOW);
988 SysMessage("dlopen: %s", dlerror());
992 void *SysLoadSym(void *lib, const char *sym) {
993 unsigned int plugid = (unsigned int)(long)lib;
995 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))
996 return plugin_link(plugid - PLUGIN_DL_BASE, sym);
998 return dlsym(lib, sym);
1001 const char *SysLibError() {
1005 void SysCloseLibrary(void *lib) {
1006 unsigned int plugid = (unsigned int)(long)lib;
1008 if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins))