static void *main_thread(void *p) { if (GTK_TOGGLE_BUTTON(dynam)->active == 1) dynacore = 1; else if (GTK_TOGGLE_BUTTON(pure_interp)->active == 1) dynacore = 2; else dynacore = 0; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(10, 10, 16, 0); SDL_SetEventFilter(filter); SDL_ShowCursor(0); SDL_EnableKeyRepeat(0, 0); init_memory(); plugin_load_plugins(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_gfx)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_audio)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_input)->entry)), gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_RSP)->entry))); romOpen_gfx(); romOpen_audio(); romOpen_input(); go(); romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); free(rom); rom = NULL; free(ROM_HEADER); ROM_HEADER = NULL; free_memory(); file_selection_launched = 0; return 0; }
int main (int argc, char **argv) { char *emulation; long start_time = get_run_time (); #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, ""); #endif #if defined (HAVE_SETLOCALE) setlocale (LC_CTYPE, ""); #endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; xmalloc_set_program_name (program_name); START_PROGRESS (program_name, 0); expandargv (&argc, &argv); bfd_init (); bfd_set_error_program_name (program_name); /* We want to notice and fail on those nasty BFD assertions which are likely to signal incorrect output being generated but otherwise may leave no trace. */ default_bfd_assert_handler = bfd_set_assert_handler (ld_bfd_assert_handler); xatexit (ld_cleanup); /* Set up the sysroot directory. */ ld_sysroot = get_sysroot (argc, argv); if (*ld_sysroot) { if (*TARGET_SYSTEM_ROOT == 0) { einfo ("%P%F: this linker was not configured to use sysroots\n"); ld_sysroot = ""; } else ld_canon_sysroot = lrealpath (ld_sysroot); } if (ld_canon_sysroot) ld_canon_sysroot_len = strlen (ld_canon_sysroot); else ld_canon_sysroot_len = -1; /* Set the default BFD target based on the configured target. Doing this permits the linker to be configured for a particular target, and linked against a shared BFD library which was configured for a different target. The macro TARGET is defined by Makefile. */ if (! bfd_set_default_target (TARGET)) { einfo (_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); xexit (1); } #if YYDEBUG { extern int yydebug; yydebug = 1; } #endif config.build_constructors = TRUE; config.rpath_separator = ':'; config.split_by_reloc = (unsigned) -1; config.split_by_file = (bfd_size_type) -1; config.make_executable = TRUE; config.magic_demand_paged = TRUE; config.text_read_only = TRUE; command_line.warn_mismatch = TRUE; command_line.warn_search_mismatch = TRUE; command_line.check_section_addresses = -1; command_line.disable_target_specific_optimizations = -1; /* We initialize DEMANGLING based on the environment variable COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the output of the linker, unless COLLECT_NO_DEMANGLE is set in the environment. Acting the same way here lets us provide the same interface by default. */ demangling = getenv ("COLLECT_NO_DEMANGLE") == NULL; link_info.allow_undefined_version = TRUE; link_info.keep_memory = TRUE; link_info.combreloc = TRUE; link_info.strip_discarded = TRUE; link_info.emit_hash = TRUE; link_info.callbacks = &link_callbacks; link_info.input_bfds_tail = &link_info.input_bfds; /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init and _fini symbols. We are compatible. */ link_info.init_function = "_init"; link_info.fini_function = "_fini"; link_info.relax_pass = 1; link_info.pei386_auto_import = -1; link_info.spare_dynamic_tags = 5; link_info.path_separator = ':'; ldfile_add_arch (""); emulation = get_emulation (argc, argv); ldemul_choose_mode (emulation); default_target = ldemul_choose_target (argc, argv); config.maxpagesize = bfd_emul_get_maxpagesize (default_target); config.commonpagesize = bfd_emul_get_commonpagesize (default_target); lang_init (); ldemul_before_parse (); lang_has_input_file = FALSE; parse_args (argc, argv); if (config.hash_table_size != 0) bfd_hash_set_default_size (config.hash_table_size); #ifdef ENABLE_PLUGINS /* Now all the plugin arguments have been gathered, we can load them. */ if (plugin_load_plugins ()) einfo (_("%P%F: %s: error loading plugin\n"), plugin_error_plugin ()); #endif /* ENABLE_PLUGINS */ ldemul_set_symbols (); /* If we have not already opened and parsed a linker script, try the default script from command line first. */ if (saved_script_handle == NULL && command_line.default_script != NULL) { ldfile_open_command_file (command_line.default_script); parser_input = input_script; yyparse (); } /* If we have not already opened and parsed a linker script read the emulation's appropriate default script. */ if (saved_script_handle == NULL) { int isfile; char *s = ldemul_get_script (&isfile); if (isfile) ldfile_open_default_command_file (s); else { lex_string = s; lex_redirect (s, _("built in linker script"), 1); } parser_input = input_script; yyparse (); lex_string = NULL; } if (verbose) { if (saved_script_handle) info_msg (_("using external linker script:")); else info_msg (_("using internal linker script:")); info_msg ("\n==================================================\n"); if (saved_script_handle) { static const int ld_bufsz = 8193; size_t n; char *buf = (char *) xmalloc (ld_bufsz); rewind (saved_script_handle); while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0) { buf[n] = 0; info_msg (buf); } rewind (saved_script_handle); free (buf); } else { int isfile; info_msg (ldemul_get_script (&isfile)); } info_msg ("\n==================================================\n"); } if (command_line.print_output_format) info_msg ("%s\n", lang_get_output_target ()); lang_final (); if (!lang_has_input_file) { if (version_printed || command_line.print_output_format) xexit (0); einfo (_("%P%F: no input files\n")); } if (trace_files) info_msg (_("%P: mode %s\n"), emulation); ldemul_after_parse (); if (config.map_filename) { if (strcmp (config.map_filename, "-") == 0) { config.map_file = stdout; } else { config.map_file = fopen (config.map_filename, FOPEN_WT); if (config.map_file == (FILE *) NULL) { bfd_set_error (bfd_error_system_call); einfo (_("%P%F: cannot open map file %s: %E\n"), config.map_filename); } } } lang_process (); /* Print error messages for any missing symbols, for any warning symbols, and possibly multiple definitions. */ if (link_info.relocatable) link_info.output_bfd->flags &= ~EXEC_P; else link_info.output_bfd->flags |= EXEC_P; ldwrite (); if (config.map_file != NULL) lang_map (); if (command_line.cref) output_cref (config.map_file != NULL ? config.map_file : stdout); if (nocrossref_list != NULL) check_nocrossrefs (); lang_finish (); /* Even if we're producing relocatable output, some non-fatal errors should be reported in the exit status. (What non-fatal errors, if any, do we want to ignore for relocatable output?) */ if (!config.make_executable && !force_make_executable) { if (trace_files) einfo (_("%P: link errors found, deleting executable `%s'\n"), output_filename); /* The file will be removed by ld_cleanup. */ xexit (1); } else { if (! bfd_close (link_info.output_bfd)) einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd); /* If the --force-exe-suffix is enabled, and we're making an executable file and it doesn't end in .exe, copy it to one which does. */ if (! link_info.relocatable && command_line.force_exe_suffix) { int len = strlen (output_filename); if (len < 4 || (strcasecmp (output_filename + len - 4, ".exe") != 0 && strcasecmp (output_filename + len - 4, ".dll") != 0)) { FILE *src; FILE *dst; const int bsize = 4096; char *buf = (char *) xmalloc (bsize); int l; char *dst_name = (char *) xmalloc (len + 5); strcpy (dst_name, output_filename); strcat (dst_name, ".exe"); src = fopen (output_filename, FOPEN_RB); dst = fopen (dst_name, FOPEN_WB); if (!src) einfo (_("%X%P: unable to open for source of copy `%s'\n"), output_filename); if (!dst) einfo (_("%X%P: unable to open for destination of copy `%s'\n"), dst_name); while ((l = fread (buf, 1, bsize, src)) > 0) { int done = fwrite (buf, 1, l, dst); if (done != l) einfo (_("%P: Error writing file `%s'\n"), dst_name); } fclose (src); if (fclose (dst) == EOF) einfo (_("%P: Error closing file `%s'\n"), dst_name); free (dst_name); free (buf); } } } END_PROGRESS (program_name); if (config.stats) { #ifdef HAVE_SBRK char *lim = (char *) sbrk (0); #endif long run_time = get_run_time () - start_time; fflush (stdout); fprintf (stderr, _("%s: total time in link: %ld.%06ld\n"), program_name, run_time / 1000000, run_time % 1000000); #ifdef HAVE_SBRK fprintf (stderr, _("%s: data size %ld\n"), program_name, (long) (lim - (char *) &environ)); #endif fflush (stderr); } /* Prevent ld_cleanup from doing anything, after a successful link. */ output_filename = NULL; xexit (0); return 0; }
int main (int argc, char *argv[]) { char c; char plugins[100][100], s[20]; char romfile[PATH_MAX]; int old_i, i, i1, i2, i3, i4; int p, p_fullscreen = 0, p_emumode = 0, p_gfx = 0, p_audio = 0, p_input = 0, p_rsp = 0, p_help = 0, p_error = 0; int p_emumode_value=1, fileloaded = 0, p_interactive = 0; int true = 1; char *buffer, *buffer2; #if defined (__linux__) if (signal(SIGTERM, sigterm_handler) == SIG_ERR) printf("Warning: Couldn't register SIGTERM signal handler!\n"); #endif //Set working dir #ifdef WITH_HOME { char temp[PATH_MAX], orig[PATH_MAX]; FILE *src, *dest; struct dirent *entry; DIR *dir; strcpy(g_WorkingDir, getenv("HOME")); strcat(g_WorkingDir, "/.mupen64/"); strcpy(cwd, g_WorkingDir); mkdir(g_WorkingDir, 0700); strcpy(temp, g_WorkingDir); strcat(temp, "mupen64.ini"); dest = fopen(temp, "rb"); if (dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/mupen64.ini"); src = fopen(orig, "rb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); strcpy(temp, g_WorkingDir); strcat(temp, "lang"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/lang"); symlink(orig, temp); /*strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); symlink(orig, temp);*/ strcpy(temp, g_WorkingDir); strcat(temp, "plugins"); mkdir(temp, 0700); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins"); dir = opendir(orig); while((entry = readdir(dir)) != NULL) { if(strcmp(entry->d_name + strlen(entry->d_name) - 3, ".so")) { strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); src = fopen(orig, "rb"); if(src == NULL) continue; strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); dest = fopen(temp, "rb"); if(dest == NULL) { unsigned char byte; dest = fopen(temp, "wb"); while(fread(&byte, 1, 1, src)) fwrite(&byte, 1, 1, dest); fclose(src); fclose(dest); } else fclose(dest); } else { strcpy(temp, g_WorkingDir); strcat(temp, "plugins/"); strcat(temp, entry->d_name); strcpy(orig, WITH_HOME); strcat(orig, "share/mupen64/plugins/"); strcat(orig, entry->d_name); symlink(orig, temp); } } strcpy(temp, g_WorkingDir); strcat(temp, "save/"); mkdir(temp, 0700); chdir(g_WorkingDir); } #else if (argv[0][0] != '/') { getcwd(cwd, 1024); strcat(cwd, "/"); strcat(cwd, argv[0]); } else strcpy(cwd, argv[0]); while(cwd[strlen(cwd)-1] != '/') cwd[strlen(cwd)-1] = '\0'; strcpy(g_WorkingDir, cwd); #endif //read config file, read plugins config_read(); plugin_scan_directory(cwd); //get config file settings buffer = (char*)config_get_string("Gfx Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[100], buffer2); p_gfx = true; } else if(buffer) printf("GFX Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Audio Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[99], buffer2); p_audio = true; } else if(buffer) printf("Audio Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Input Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[98], buffer2); p_input = true; } else if(buffer) printf("Input Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("RSP Plugin", ""); buffer2= plugin_name_by_filename(buffer); if(buffer2) { strcpy(plugins[97], buffer2); p_rsp = true; } else if(buffer) printf("RSP Plugin from ini-file could not be loaded\n"); buffer = (char*)config_get_string("Core", ""); if(strcmp(buffer,"")) { p_emumode = true; p_emumode_value = buffer[0]-'0'+1; } buffer = (char*)config_get_string("Fullscreen", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_fullscreen = true; } buffer = (char*)config_get_string("No Ask", ""); if(strcmp(buffer,"")) { if(!strcmp(buffer, "true")) p_noask = true; } // Command Line Parameter - Parsing for(p=1; p<argc; p++) { if(argv[p][0] == '-') { if(!strcmp(argv[p], "--fullscreen")) p_fullscreen = true; else if(!strcmp(argv[p], "--help")) p_help = true; else if(!strcmp(argv[p], "--noask")) p_noask = true; else if(!strcmp(argv[p], "--interactive")) p_interactive = true; else if(!strcmp(argv[p], "--emumode")) { p++; if(p < argc) { p_emumode_value = argv[p][0]; p_emumode = true; } } else if(!strcmp(argv[p], "--gfx")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[100], buffer); p_gfx = true; } else printf("specified GFX Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--audio")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[99], buffer); p_audio = true; } else printf("specified Audio Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--input")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[98], buffer); p_input = true; } else printf("specified Input Plugin couldn't be loaded!\n"); } } else if(!strcmp(argv[p], "--rsp")) { p++; if(p < argc) { buffer = plugin_name_by_filename(argv[p]); if(buffer) { strcpy(plugins[97], buffer); p_rsp = true; } else printf("specified RSP Plugin couldn't be loaded!\n"); } } } else { strcpy(romfile, argv[p]); fileloaded = true; } } if(p_interactive) { p_emumode = 0; p_gfx = 0; p_audio = 0; p_input = 0; p_rsp = 0; } printf("\nMupen64 version : %s\n", VERSION); if (argc < 2 || p_help || p_error || fileloaded != true) { printf("\n\n" "syntax: mupen64_nogui [parameter(s)] rom\n" "\n" "Parameters:\n" " --fullscreen : turn fullscreen mode on\n" " --gfx (plugin) : set gfx plugin to (plugin)\n" " --audio (plugin) : set audio plugin to (plugin)\n" " --input (plugin) : set input plugin to (plugin)\n" " --rsp (plugin) : set rsp plugin to (plugin)\n" " --emumode (number) : set emu mode to: 1=interp./2=recomp./3=pure interp\n" " --noask : don't ask to force load on bad dumps\n" " --interactive : ask interactively for all plugins\n" "\n" "You can also use the Config-File from the Gui-Version\n" "but there are aditional Parameters for the NO-GUI Version\n" "\n"); return 0; } if (rom_read(romfile)) { if(rom) free(rom); if(ROM_HEADER) free(ROM_HEADER); return 1; } printf("Goodname:%s\n", ROM_SETTINGS.goodname); printf("16kb eeprom=%d\n", ROM_SETTINGS.eeprom_16kb); printf ("emulation mode:\n" " 1. interpreter\n" " 2. dynamic recompiler (default)\n" " 3. pure interpreter\n"); if(p_emumode) c = p_emumode_value; else c = getchar(); if (c == '1') dynacore=0; else if (c == '3') dynacore=2; else dynacore=1; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(10, 10, 16, 0); SDL_ShowCursor(0); SDL_EnableKeyRepeat(0, 0); SDL_EnableUNICODE(1); init_memory(); // --------------------- loading plugins ---------------------- i=1; i1=1; printf(" Choose your gfx plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_GFX) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } if(p_gfx) i1 = 100; else { if(p_emumode) getchar(); /*c = getchar(); s[0] = c; s[1] = 0;*/ scanf("%10s", s); i1 = atoi(s); } plugin_rewind(); old_i = i; printf(" Choose your audio plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_AUDIO) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_audio) i2 = 99; else { scanf("%10s", s); i2 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your input plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_CONTROLLER) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); //getchar(); s[0] = c; s[1] = 0;*/ if(p_input) i3 = 98; else { scanf("%10s", s); i3 = old_i + atoi(s) - 1; } plugin_rewind(); old_i = i; printf(" Choose your RSP plugin : \n"); while(plugin_type() != -1) { if (plugin_type() == PLUGIN_TYPE_RSP) { strcpy(plugins[i], plugin_next()); printf("%s (%s)\n", plugins[i], plugin_filename_by_name(plugins[i])); i++; } else plugin_next(); } /*getchar(); c = getchar(); getchar(); s[0] = c; s[1] = 0;*/ if(p_rsp) i4 = 97; else { scanf("%10s", s); i4 = old_i + atoi(s) - 1; } printf("\n\nSelected Plugins: %s, %s, %s, %s\n", plugins[i1], plugins[i2], plugins[3], plugins[i4]); plugin_load_plugins(plugins[i1], plugins[i2], plugins[i3], plugins[i4]); romOpen_gfx(); romOpen_audio(); romOpen_input(); // ------------------------------------------------------------ SDL_SetEventFilter(filter); if(p_fullscreen) changeWindow(); go(); romClosed_RSP(); romClosed_input(); romClosed_audio(); romClosed_gfx(); closeDLL_RSP(); closeDLL_input(); closeDLL_audio(); closeDLL_gfx(); free(rom); free(ROM_HEADER); free_memory(); return 0; }