greyhammer
New member
Hello all!
I was having trouble with the 0.5 command line version loading gfx plugins correctly, so I looked at the source and found the problem was with the command line parsing. Rather than simply fix the error, I felt it was worth my time to re-write the implementation.
This is still somewhat quick-fix-ish, but it works, at least for me.
*Warning*
After applying the patch, the --interactive option will have been removed. Interactive will be the default behavior. If you want to use your config file, use the -c or --config options. Interactive mode will not ask for any option specified on the command line.
For example:
mupen64_nogui rom
Will ask you to select an emulation mode, and ask you to select each plugin, one at a time.
mupen64_nogui -e 1 rom
Will only ask you to select plugins.
If you use -c or --config, the interactive mode will ask for any parameters missing from the config file.
All long options now have corresponding short options:
-f, --fullscreen : turn fullscreen mode on
-n, --noask : do not ask to force load hacks/bad dumps
-e, --emumode (number) : set emu mode to
1=interpreter 2=dynamic recompiler 3=pure interpeter
-g, --gfx (plugin) : set gfx plugin to (plugin)
-a, --audio (plugin) : set audio plugin to (plugin)
-i, --input (plugin) : set input plugin to (plugin)
-r, --rsp (plugin) : set rsp plugin to (plugin)
And there are new options:
-h, -?, --help : display usage summary
-v, --verbose : verbose output
-c, --config : use gui config file
*Big Fat Warning*
I have almost no formal training writing code, and absolutly no formal training writing C code. I make no guarantee it will compile, much less work for anyone else but me.
The patch should be applied to the 0.5 source.
Apply the path with the following:
patch /path/to/mupen64/source/main/main.c /path/to/patchfile.patch
Here is the patch:
I hope someone finds this useful.
If anyone wants changes to be made, or maybe something added, post a reply and let me know. I'll see what I can do.
I was having trouble with the 0.5 command line version loading gfx plugins correctly, so I looked at the source and found the problem was with the command line parsing. Rather than simply fix the error, I felt it was worth my time to re-write the implementation.
This is still somewhat quick-fix-ish, but it works, at least for me.
*Warning*
After applying the patch, the --interactive option will have been removed. Interactive will be the default behavior. If you want to use your config file, use the -c or --config options. Interactive mode will not ask for any option specified on the command line.
For example:
mupen64_nogui rom
Will ask you to select an emulation mode, and ask you to select each plugin, one at a time.
mupen64_nogui -e 1 rom
Will only ask you to select plugins.
If you use -c or --config, the interactive mode will ask for any parameters missing from the config file.
All long options now have corresponding short options:
-f, --fullscreen : turn fullscreen mode on
-n, --noask : do not ask to force load hacks/bad dumps
-e, --emumode (number) : set emu mode to
1=interpreter 2=dynamic recompiler 3=pure interpeter
-g, --gfx (plugin) : set gfx plugin to (plugin)
-a, --audio (plugin) : set audio plugin to (plugin)
-i, --input (plugin) : set input plugin to (plugin)
-r, --rsp (plugin) : set rsp plugin to (plugin)
And there are new options:
-h, -?, --help : display usage summary
-v, --verbose : verbose output
-c, --config : use gui config file
*Big Fat Warning*
I have almost no formal training writing code, and absolutly no formal training writing C code. I make no guarantee it will compile, much less work for anyone else but me.
The patch should be applied to the 0.5 source.
Apply the path with the following:
patch /path/to/mupen64/source/main/main.c /path/to/patchfile.patch
Here is the patch:
Code:
39a40,42
> #include <getopt.h>
> #include <dirent.h>
> #include <sys/stat.h>
65c68,69
< int p_noask;
---
> static int p_noask = 0;
> static int verbose = 0;
94c98,100
< {
---
> {
> if(p_noask && !verbose) return 1;
>
97a104,106
>
> if(p_noask) return 1;
>
100,107c109,112
< if(p_noask) return 1;
< else
< {
< c = getchar();
< getchar();
< if (c=='y' || c=='Y') return 1;
< else return 0;
< }
---
> c = getchar();
> getchar();
> if (c=='y' || c=='Y') return 1;
> else return 0;
111a117,118
> if(p_noask && !verbose) return 1;
>
115a123,125
>
> if(p_noask) return 1;
>
118,125c128,131
< if(p_noask) return 1;
< else
< {
< c = getchar();
< getchar();
< if (c=='y' || c=='Y') return 1;
< else return 0;
< }
---
> c = getchar();
> getchar();
> if (c=='y' || c=='Y') return 1;
> else return 0;
228a235,257
> static void usage (int h)
> {
> printf("\nUsage: mupen64_nogui [OPTIONS]... rom\n\nOPTIONS:\n"
> " -h, -?, --help : display this usage summary\n"
> " -v, --verbose : verbose output\n"
> " -c, --config : use gui config file\n"
> " -f, --fullscreen : turn fullscreen mode on\n"
> " -n, --noask : do not ask to force load hacks/bad dumps\n"
> " -e, --emumode (number) : set emu mode to: 1=interp./2=recomp./3=pure interp\n"
> " -g, --gfx (plugin) : set gfx plugin to (plugin)\n"
> " -a, --audio (plugin) : set audio plugin to (plugin)\n"
> " -i, --input (plugin) : set input plugin to (plugin)\n"
> " -r, --rsp (plugin) : set rsp plugin to (plugin)\n\n");
>
> if(h)
> printf("You can use the Config-File from the Gui-Version with -c or --config\n"
> "There are aditional Parameters for the NO-GUI Version:\n\n"
> " Fullscreen = (true/false) : set fullscreen mode\n"
> " Core = (number) : set emumode to (number)\n"
> " No Ask = (true/false) : do not ask to force load hacks/bad dumps\n\n");
>
> }
>
231,232d259
< char c;
< char plugins[100][100], s[20];
234,238c261,265
< 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;
---
> char plugins[100][100];
> int old_i, i, i1;
> int p_fullscreen = 0, p_emumode = 0, p_config = 0;
> char *buffer = NULL;
> const char *gplug = NULL, *aplug = NULL, *iplug = NULL, *rplug = NULL;
349,389c376,377
< //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");
---
> // read plugins
> plugin_scan_directory(cwd);
391,529c379
< 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;
< }
---
> /* parse command line options */
530a381,525
> static struct option longoptions[] =
> {
> { "verbose", no_argument, 0, 'v' },
> { "help", no_argument, 0, 'h' },
> { "fullscreen", no_argument, 0, 'f' },
> { "noask", no_argument, 0, 'n' },
> { "config", no_argument, 0, 'c' },
> { "emumode", required_argument, 0, 'e' },
> { "gfx", required_argument, 0, 'g' },
> { "audio", required_argument, 0, 'a' },
> { "input", required_argument, 0, 'i' },
> { "rsp", required_argument, 0, 'r' },
> { 0, 0, 0, 0 }
> };
>
> int o, *option_index = 0;
>
> while((o = getopt_long(argc, argv, "?vhfnce:g:a:i:r:",
> longoptions, option_index)) != -1)
> {
> switch (o)
> {
> case 'v':
> verbose = 1;
> break;
> case 'f':
> p_fullscreen = 1;
> break;
> case 'n':
> p_noask = 1;
> break;
> case 'c':
> p_config = 1;
> break;
> case 'e':
> sscanf(optarg, "%ld", &dynacore);
> dynacore--;
> p_emumode = 1;
> break;
> case 'g':
> gplug = plugin_name_by_filename(optarg);
> break;
> case 'a':
> aplug = plugin_name_by_filename(optarg);
> break;
> case 'i':
> iplug = plugin_name_by_filename(optarg);
> break;
> case 'r':
> rplug = plugin_name_by_filename(optarg);
> break;
> case 'h':
> case '?':
> usage(1);
> break;
> default:
> usage(0);
> return 0;
> }
> }
>
> if(p_config)
> {
> //read config file
> config_read();
>
> //get config file settings
>
> if(!gplug)
> {
> buffer = (char*)config_get_string("Gfx Plugin", "");
> gplug = plugin_name_by_filename(buffer);
> if(!gplug && buffer && verbose)
> printf("GFX Plugin: %s\nfrom config file could not be loaded!\n", buffer);
> }
>
> if(!aplug)
> {
> buffer = (char*)config_get_string("Audio Plugin", "");
> aplug = plugin_name_by_filename(buffer);
> if(!aplug && buffer && verbose)
> printf("Audio Plugin: %s\nfrom config file could not be loaded!\n", buffer);
> }
>
> if(!iplug)
> {
> buffer = (char*)config_get_string("Input Plugin", "");
> iplug = plugin_name_by_filename(buffer);
> if(!iplug && buffer && verbose)
> printf("Input Plugin: %s\nfrom config file could not be loaded!\n", buffer);
> }
>
> if(!rplug)
> {
> buffer = (char*)config_get_string("RSP Plugin", "");
> rplug = plugin_name_by_filename(buffer);
> if(!rplug && buffer && verbose)
> printf("RSP Plugin: %s\nfrom config file could not be loaded\n", buffer);
> }
>
> if(!p_emumode)
> {
> buffer = (char*)config_get_string("Core", "");
>
> if(strcmp(buffer,""))
> {
> sscanf(buffer, "%ld", &dynacore);
> dynacore--;
> p_emumode = 1;
> }
> }
>
> if(!p_fullscreen)
> {
> buffer = (char*)config_get_string("Fullscreen", "");
>
> if(strcmp(buffer,""))
> {
> if(!strcmp(buffer, "true"))
> p_fullscreen = 1;
> }
> }
>
> if(!p_noask)
> {
> buffer = (char*)config_get_string("No Ask", "");
>
> if(strcmp(buffer,""))
> {
> if(!strcmp(buffer, "true"))
> p_noask = 1;
> }
> }
>
> }
>
> if(!argv[optind])
> {
> usage(0);
> return 0;
> }
>
> /* loading ROM file */
> strncpy(romfile, argv[optind], PATH_MAX);
>
537,543c532,538
< 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(verbose)
> {
> printf("Goodname:%s\n", ROM_SETTINGS.goodname);
> printf("16kb eeprom=%d\n", ROM_SETTINGS.eeprom_16kb);
> }
>
545,576c540,554
< 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;
---
> {
> if(verbose)
> {
> printf ("Using emulation mode: ");
>
> if(dynacore == 0)
> printf ("Interpreter\n");
>
> if(dynacore == 1)
> printf ("Dynamic recompiler\n");
>
> if(dynacore == 2)
> printf ("Pure interpreter\n");
> }
> }
578,669c556,674
< {
< 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]);
---
> {
> printf ("Choose emulation mode:\n"
> " 1. interpreter\n"
> " 2. dynamic recompiler (default)\n"
> " 3. pure interpreter\n");
>
> scanf("%ld", &dynacore);
>
> dynacore--;
> }
>
> if(dynacore > 2 || dynacore < 0) dynacore=1;
>
>
> // --------------------- loading plugins ----------------------
> i=1;
> i1=1;
>
> if(!gplug)
> {
> printf("Choose your gfx plugin : \n");
>
> while(plugin_type() != -1)
> {
> if (plugin_type() == PLUGIN_TYPE_GFX)
> {
> strcpy(plugins[i], plugin_next());
> printf(" %s\n (%s)\n", plugins[i],
> plugin_filename_by_name(plugins[i]));
> i++;
> }
> else plugin_next();
> }
>
> scanf("%d", &i1);
> gplug = plugins[i1];
> plugin_rewind();
> }
>
> if(!aplug)
> {
> old_i = i;
> i1 = i;
>
> printf("Choose your audio plugin : \n");
>
> while(plugin_type() != -1)
> {
> if (plugin_type() == PLUGIN_TYPE_AUDIO)
> {
> strcpy(plugins[i], plugin_next());
> printf(" %s\n (%s)\n", plugins[i],
> plugin_filename_by_name(plugins[i]));
> i++;
> }
> else plugin_next();
> }
>
> scanf("%d", &i1);
> i1 = i1 + old_i - 1;
> aplug = plugins[i1];
>
> plugin_rewind();
> }
>
> if(!iplug)
> {
> old_i = i;
> i1 = i;
>
> printf("Choose your input plugin : \n");
>
> while(plugin_type() != -1)
> {
> if (plugin_type() == PLUGIN_TYPE_CONTROLLER)
> {
> strcpy(plugins[i], plugin_next());
> printf(" %s\n (%s)\n", plugins[i],
> plugin_filename_by_name(plugins[i]));
> i++;
> }
> else plugin_next();
> }
>
> scanf("%d", &i1);
> i1 = i1 + old_i - 1;
> iplug = plugins[i1];
>
> plugin_rewind();
> }
>
> if(!rplug)
> {
> old_i = i;
> i1 = i;
>
> printf("Choose your RSP plugin : \n");
> while(plugin_type() != -1)
> {
> if (plugin_type() == PLUGIN_TYPE_RSP)
> {
> strcpy(plugins[i], plugin_next());
> printf(" %s\n (%s)\n", plugins[i],
> plugin_filename_by_name(plugins[i]));
> i++;
> }
> else plugin_next();
> }
>
> scanf("%d", &i1);
> i1 = i1 + old_i - 1;
> rplug = plugins[i1];
> }
>
> if(verbose)
> printf("\nSelected Plugins: %s,\n"
> " %s,\n"
> " %s,\n"
> " %s,\n\n", gplug, aplug, iplug, rplug);
671,693c676,709
< 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;
---
> plugin_load_plugins(gplug, aplug, iplug, rplug);
>
> // ------------------------------------------------------------
>
> /* startup SDL */
> SDL_Init(SDL_INIT_VIDEO);
> SDL_SetVideoMode(10, 10, 16, 0);
> SDL_ShowCursor(0);
> SDL_EnableKeyRepeat(0, 0);
> SDL_EnableUNICODE(1);
> init_memory();
>
> 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;
I hope someone finds this useful.
If anyone wants changes to be made, or maybe something added, post a reply and let me know. I'll see what I can do.