--- uae/src/main.c 2018/04/24 16:39:57 1.1.1.3 +++ uae/src/main.c 2018/04/24 16:43:25 1.1.1.5 @@ -36,15 +36,55 @@ #include "compiler.h" #include "picasso96.h" #include "uaeexe.h" +#include "getopt.h" -int version = 100*UAEMAJOR + 10*UAEMINOR + UAEURSAMINOR; +long int version = 256*65536L*UAEMAJOR + 65536L*UAEMINOR + UAESUBREV; -/* Note to porters: please don't change any of these options! UAE is supposed - * to behave identically on all platforms if possible. */ struct uae_prefs currprefs; +struct uae_prefs changed_prefs; + +int no_gui = 0, use_debugger = 0, use_gfxlib = 0; + +int joystickpresent = 0; + +int cloanto_rom = 0; + +char warning_buffer[256]; + +char romfile[256] = "kick.rom"; +char keyfile[256] = ""; +char prtname[256] = DEFPRTNAME; + +char optionsfile[256]; + +/* If you want to pipe printer output to a file, put something like + * "cat >>printerfile.tmp" above. + * The printer support was only tested with the driver "PostScript" on + * Amiga side, using apsfilter for linux to print ps-data. + * + * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a + * PostScript printer or ghostscript -=SR=- + */ + +/* People must provide their own name for this */ +char sername[256] = ""; + +/* Slightly stupid place for this... */ +/* ncurses.c might use quite a few of those. */ +char *colormodes[] = { "256 colors", "32768 colors", "65536 colors", + "256 colors dithered", "16 colors dithered", "16 million colors", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" +}; + static void default_currprefs (void) { + /* Note to porters: please don't change any of these options! UAE is supposed + * to behave identically on all platforms if possible. */ currprefs.framerate = 1; currprefs.illegal_mem = 0; currprefs.no_xhair = 0; @@ -69,6 +109,8 @@ static void default_currprefs (void) currprefs.gfx_height = 600; currprefs.gfx_lores = 0; currprefs.gfx_linedbl = 0; + currprefs.gfx_afullscreen = 0; + currprefs.gfx_pfullscreen = 0; currprefs.gfx_correct_aspect = 0; currprefs.gfx_xcenter = 0; currprefs.gfx_ycenter = 0; @@ -89,106 +131,85 @@ static void default_currprefs (void) currprefs.cpu_level = 0; currprefs.cpu_compatible = 0; currprefs.address_space_24 = 1; -}; -struct uae_prefs changed_prefs; - -int no_gui = 0, use_debugger = 0, use_gfxlib = 0; - -int joystickpresent = 0; - -int cloanto_rom = 0; -char warning_buffer[256]; - -uae_u32 fastmem_size = 0x00000000; -uae_u32 a3000mem_size = 0x00000000; -uae_u32 z3fastmem_size = 0x00000000; -uae_u32 chipmem_size = 0x00200000; -uae_u32 bogomem_size = 0x00000000; -uae_u32 gfxmem_size = 0x00000000; - -char romfile[256] = "kick.rom"; -char keyfile[256] = ""; -char prtname[256] = DEFPRTNAME; + currprefs.fastmem_size = 0x00000000; + currprefs.a3000mem_size = 0x00000000; + currprefs.z3fastmem_size = 0x00000000; + currprefs.chipmem_size = 0x00200000; + currprefs.bogomem_size = 0x00000000; + currprefs.gfxmem_size = 0x00000000; -char optionsfile[256]; - -/* If you want to pipe printer output to a file, put something like - * "cat >>printerfile.tmp" above. - * The printer support was only tested with the driver "PostScript" on - * Amiga side, using apsfilter for linux to print ps-data. - * - * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a - * PostScript printer or ghostscript -=SR=- - */ + currprefs.mountinfo = alloc_mountinfo (); +} -/* People must provide their own name for this */ -char sername[256] = ""; +void fixup_prefs_dimensions (struct uae_prefs *prefs) +{ + if (prefs->gfx_width < 320) + prefs->gfx_width = 320; + if (prefs->gfx_height < 200) + prefs->gfx_height = 200; + if (prefs->gfx_height > 300 && ! prefs->gfx_linedbl) + prefs->gfx_height = 300; + if (prefs->gfx_height > 600) + prefs->gfx_height = 600; -/* Slightly stupid place for this... */ -/* ncurses.c might use quite a few of those. */ -char *colormodes[] = { "256 colors", "32768 colors", "65536 colors", - "256 colors dithered", "16 colors dithered", "16 million colors", - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" -}; + prefs->gfx_width += 7; /* X86.S wants multiples of 4 bytes, might be 8 in the future. */ + prefs->gfx_width &= ~7; +} -static void fix_options(void) +static void fix_options (void) { int err = 0; - if ((chipmem_size & (chipmem_size - 1)) != 0 - || chipmem_size < 0x80000 - || chipmem_size > 0x800000) + if ((currprefs.chipmem_size & (currprefs.chipmem_size - 1)) != 0 + || currprefs.chipmem_size < 0x80000 + || currprefs.chipmem_size > 0x800000) { - chipmem_size = 0x200000; + currprefs.chipmem_size = 0x200000; fprintf (stderr, "Unsupported chipmem size!\n"); err = 1; } - if ((fastmem_size & (fastmem_size - 1)) != 0 - || (fastmem_size != 0 && (fastmem_size < 0x100000 || fastmem_size > 0x800000))) + if ((currprefs.fastmem_size & (currprefs.fastmem_size - 1)) != 0 + || (currprefs.fastmem_size != 0 && (currprefs.fastmem_size < 0x100000 || currprefs.fastmem_size > 0x800000))) { - fastmem_size = 0; + currprefs.fastmem_size = 0; fprintf (stderr, "Unsupported fastmem size!\n"); err = 1; } - if ((gfxmem_size & (gfxmem_size - 1)) != 0 - || (gfxmem_size != 0 && (gfxmem_size < 0x100000 || gfxmem_size > 0x800000))) + if ((currprefs.gfxmem_size & (currprefs.gfxmem_size - 1)) != 0 + || (currprefs.gfxmem_size != 0 && (currprefs.gfxmem_size < 0x100000 || currprefs.gfxmem_size > 0x800000))) { - gfxmem_size = 0; + currprefs.gfxmem_size = 0; fprintf (stderr, "Unsupported graphics card memory size!\n"); err = 1; } - if ((z3fastmem_size & (z3fastmem_size - 1)) != 0 - || (z3fastmem_size != 0 && (z3fastmem_size < 0x100000 || z3fastmem_size > 0x4000000))) + if ((currprefs.z3fastmem_size & (currprefs.z3fastmem_size - 1)) != 0 + || (currprefs.z3fastmem_size != 0 && (currprefs.z3fastmem_size < 0x100000 || currprefs.z3fastmem_size > 0x4000000))) { - z3fastmem_size = 0; + currprefs.z3fastmem_size = 0; fprintf (stderr, "Unsupported Zorro III fastmem size!\n"); err = 1; } - if (currprefs.address_space_24 && (gfxmem_size != 0 || z3fastmem_size != 0)) { - z3fastmem_size = gfxmem_size = 0; + if (currprefs.address_space_24 && (currprefs.gfxmem_size != 0 || currprefs.z3fastmem_size != 0)) { + currprefs.z3fastmem_size = currprefs.gfxmem_size = 0; fprintf (stderr, "Can't use a graphics card or Zorro III fastmem when using a 24 bit\n" "address space - sorry.\n"); } - if ((bogomem_size & (bogomem_size - 1)) != 0 - || (bogomem_size != 0 && (bogomem_size < 0x80000 || bogomem_size > 0x100000))) + if ((currprefs.bogomem_size & (currprefs.bogomem_size - 1)) != 0 + || (currprefs.bogomem_size != 0 && (currprefs.bogomem_size < 0x80000 || currprefs.bogomem_size > 0x100000))) { - bogomem_size = 0; + currprefs.bogomem_size = 0; fprintf (stderr, "Unsupported bogomem size!\n"); err = 1; } - if (chipmem_size > 0x200000 && fastmem_size != 0) { + if (currprefs.chipmem_size > 0x200000 && currprefs.fastmem_size != 0) { fprintf (stderr, "You can't use fastmem and more than 2MB chip at the same time!\n"); - fastmem_size = 0; + currprefs.fastmem_size = 0; err = 1; } - if (currprefs.m68k_speed < 1 || currprefs.m68k_speed > 20) { - fprintf (stderr, "Bad value for -w parameter: must be within 1..20.\n"); + if (currprefs.m68k_speed < -1 || currprefs.m68k_speed > 20) { + fprintf (stderr, "Bad value for -w parameter: must be -1, 0, or within 1..20.\n"); currprefs.m68k_speed = 4; err = 1; } @@ -197,16 +218,16 @@ static void fix_options(void) currprefs.produce_sound = 0; err = 1; } - if (currprefs.cpu_level < 2 && z3fastmem_size > 0) { + if (currprefs.cpu_level < 2 && currprefs.z3fastmem_size > 0) { fprintf (stderr, "Z3 fast memory can't be used with a 68000/68010 emulation. It\n" "requires a 68020 emulation. Turning off Z3 fast memory.\n"); - z3fastmem_size = 0; + currprefs.z3fastmem_size = 0; err = 1; } - if (currprefs.cpu_level < 2 && gfxmem_size > 0) { + if (currprefs.cpu_level < 2 && currprefs.gfxmem_size > 0) { fprintf (stderr, "Picasso96 can't be used with a 68000/68010 emulation. It\n" "requires a 68020 emulation. Turning off Picasso96.\n"); - gfxmem_size = 0; + currprefs.gfxmem_size = 0; err = 1; } @@ -218,7 +239,7 @@ int quit_program = 0; void uae_reset (void) { - if (quit_program != 1 && quit_program != -1) + if (quit_program == 0) quit_program = -2; } @@ -233,7 +254,7 @@ void uae_quit (void) * from time to time (as I do). For example, running the SVGAlib version with * "-o" will discard the keyboard language information... */ -void save_options(FILE *f) +void save_options (FILE *f) { int i; if (use_debugger) @@ -278,15 +299,15 @@ void save_options(FILE *f) if (currprefs.gfx_correct_aspect) fprintf (f, "c"); fprintf (f, "\n-H %d\n", currprefs.color_mode); - if (fastmem_size > 0) - fprintf (f, "-F %d\n", fastmem_size / 0x100000); - if (z3fastmem_size > 0) - fprintf (f, "-Z %d\n", z3fastmem_size / 0x100000); - if (bogomem_size > 0) - fprintf (f, "-s %d\n", bogomem_size / 0x40000); - if (gfxmem_size > 0) - fprintf (f, "-U %d\n", gfxmem_size / 0x100000); - fprintf (f, "-c %d\n", chipmem_size / 0x80000); + if (currprefs.fastmem_size > 0) + fprintf (f, "-F %d\n", currprefs.fastmem_size / 0x100000); + if (currprefs.z3fastmem_size > 0) + fprintf (f, "-Z %d\n", currprefs.z3fastmem_size / 0x100000); + if (currprefs.bogomem_size > 0) + fprintf (f, "-s %d\n", currprefs.bogomem_size / 0x40000); + if (currprefs.gfxmem_size > 0) + fprintf (f, "-U %d\n", currprefs.gfxmem_size / 0x100000); + fprintf (f, "-c %d\n", currprefs.chipmem_size / 0x80000); fprintf (f, "-C %d%s\n", currprefs.cpu_level, (currprefs.cpu_compatible ? "c" @@ -303,7 +324,7 @@ void save_options(FILE *f) fprintf (f, "-A %d\n", currprefs.emul_accuracy); /* We don't write "-t" - I can hardly imagine a user who wants that in his * config file. */ - write_filesys_config(f); + write_filesys_config (currprefs.mountinfo, f); #ifndef UNSUPPORTED_OPTION_l fprintf (f, "-l %s\n", (currprefs.keyboard_lang == KBD_LANG_DE ? "de" : currprefs.keyboard_lang == KBD_LANG_ES ? "es" @@ -383,7 +404,7 @@ static struct optiondef uaeopts[] = { { "H:", " -H mode : Set the color mode (see below)\n" } }; -void usage(void) +void usage (void) { int i; @@ -448,8 +469,15 @@ static void parse_gfx_specs (char *spec) currprefs.gfx_xcenter = strchr (x2, 'x') != 0 ? 1 : strchr (x2, 'X') != 0 ? 2 : 0; currprefs.gfx_ycenter = strchr (x2, 'y') != 0 ? 1 : strchr (x2, 'Y') != 0 ? 2 : 0; currprefs.gfx_linedbl = strchr (x2, 'd') != 0; + currprefs.gfx_linedbl += 2 * (strchr (x2, 'D') != 0); + currprefs.gfx_afullscreen = strchr (x2, 'a') != 0; + currprefs.gfx_pfullscreen = strchr (x2, 'p') != 0; currprefs.gfx_correct_aspect = strchr (x2, 'c') != 0; + if (currprefs.gfx_linedbl == 3) { + fprintf (stderr, "You can't use both 'd' and 'D' modifiers in the display mode specification.\n"); + } + free (x0); return; @@ -519,7 +547,7 @@ const char *gameport_state (int nr) return "not connected"; } -static int parse_joy_spec (char *spec) +int parse_joy_spec (char *spec) { int v0 = 2, v1 = 0; if (strlen(spec) != 2) @@ -561,19 +589,19 @@ static void parse_filesys_spec (int read char buf[256]; char *s2; - strncpy(buf, spec, 255); buf[255] = 0; - s2 = strchr(buf, ':'); - if(s2) { + strncpy (buf, spec, 255); buf[255] = 0; + s2 = strchr (buf, ':'); + if (s2) { *s2++ = '\0'; #ifdef __DOS__ { char *tmp; - while ((tmp = strchr(s2, '\\'))) + while ((tmp = strchr (s2, '\\'))) *tmp = '/'; } #endif - s2 = add_filesys_unit(buf, s2, readonly, 0, 0, 0); + s2 = add_filesys_unit (currprefs.mountinfo, buf, s2, readonly, 0, 0, 0); if (s2) fprintf (stderr, "%s\n", s2); } else { @@ -598,7 +626,7 @@ static void parse_hardfile_spec (char *s if (x3 == NULL) goto argh; *x3++ = '\0'; - x3 = add_filesys_unit (0, x3, 0, atoi (x0), atoi (x1), atoi (x2)); + x3 = add_filesys_unit (currprefs.mountinfo, 0, x3, 0, atoi (x0), atoi (x1), atoi (x2)); if (x3) fprintf (stderr, "%s\n", x3); @@ -646,7 +674,7 @@ static void parse_cpu_specs (char *spec) #ifndef DONT_PARSE_CMDLINE -void parse_cmdline(int argc, char **argv) +void parse_cmdline (int argc, char **argv) { int c, i; char getopt_str[256]; @@ -656,9 +684,9 @@ void parse_cmdline(int argc, char **argv strcat (getopt_str, uaeopts[i].getopt_str); /* Help! We're running out of letters! */ - while(((c = getopt(argc, argv, getopt_str)) != EOF)) - switch(c) { - case 'h': usage(); exit(0); + while (((c = getopt (argc, argv, getopt_str)) != EOF)) + switch (c) { + case 'h': usage (); exit (0); case '0': strncpy (currprefs.df[0], optarg, 255); currprefs.df[0][255] = 0; break; case '1': strncpy (currprefs.df[1], optarg, 255); currprefs.df[1][255] = 0; break; @@ -699,23 +727,23 @@ void parse_cmdline(int argc, char **argv break; case 'Z': - z3fastmem_size = atoi (optarg) * 0x100000; + currprefs.z3fastmem_size = atoi (optarg) * 0x100000; break; case 'U': - gfxmem_size = atoi (optarg) * 0x100000; + currprefs.gfxmem_size = atoi (optarg) * 0x100000; break; case 'F': - fastmem_size = atoi (optarg) * 0x100000; + currprefs.fastmem_size = atoi (optarg) * 0x100000; break; case 's': - bogomem_size = atoi (optarg) * 0x40000; + currprefs.bogomem_size = atoi (optarg) * 0x40000; break; case 'c': - chipmem_size = atoi (optarg) * 0x80000; + currprefs.chipmem_size = atoi (optarg) * 0x80000; break; case 'l': @@ -757,50 +785,49 @@ void parse_cmdline(int argc, char **argv } #endif -static void parse_cmdline_and_init_file(int argc, char **argv) +static void parse_cmdline_and_init_file (int argc, char **argv) { FILE *f; char *tmp; int t; char *buffer,*tmpbuf, *token; - char smallbuf[256]; - int bufsiz, result; + int bufsiz; int n_args; char **new_argv; int new_argc; char *home; - strcpy(optionsfile,""); + strcpy (optionsfile,""); #ifdef OPTIONS_IN_HOME - home = getenv("HOME"); - if (home != NULL && strlen(home) < 240) + home = getenv ("HOME"); + if (home != NULL && strlen (home) < 240) { - strcpy(optionsfile, home); - strcat(optionsfile, "/"); + strcpy (optionsfile, home); + strcat (optionsfile, "/"); } #endif - strcat(optionsfile, OPTIONSFILENAME); + strcat (optionsfile, OPTIONSFILENAME); - f = fopen(optionsfile, "rb"); + f = fopen (optionsfile, "rb"); #ifdef OPTIONS_IN_HOME /* sam: if not found in $HOME then look in current directory */ if (f == NULL) { strcpy (optionsfile, OPTIONSFILENAME); - f = fopen(optionsfile, "rb"); + f = fopen (optionsfile, "rb"); } #endif if (f == NULL) { - parse_cmdline(argc, argv); + parse_cmdline (argc, argv); return; } - fseek(f, 0, SEEK_END); - bufsiz = ftell(f); - fseek(f, 0, SEEK_SET); + fseek (f, 0, SEEK_END); + bufsiz = ftell (f); + fseek (f, 0, SEEK_SET); - buffer = (char *)malloc(bufsiz+1); + buffer = (char *)malloc (bufsiz+1); buffer[bufsiz] = 0; if (fread (buffer, 1, bufsiz, f) < bufsiz) { fprintf (stderr, "Error reading configuration file\n"); @@ -827,7 +854,7 @@ static void parse_cmdline_and_init_file( *tmp = ' '; } } - while ((tmp = strchr(buffer, '\t'))) + while ((tmp = strchr (buffer, '\t'))) *tmp = ' '; tmp = buffer; @@ -863,7 +890,7 @@ static void parse_cmdline_and_init_file( while (token != NULL) { new_argv[new_argc] = my_strdup (token); new_argc++; - token = strtok(NULL, "\n "); + token = strtok (NULL, "\n "); } for (n_args = 1; n_args < argc; n_args++) new_argv[new_argc++] = argv[n_args]; @@ -871,6 +898,35 @@ static void parse_cmdline_and_init_file( parse_cmdline(new_argc, new_argv); } +void write_log_standard (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); +#ifdef HAVE_VFPRINTF + vfprintf (stderr, fmt, ap); +#else + /* Technique stolen from GCC. */ + { + int x1, x2, x3, x4, x5, x6, x7, x8; + x1 = va_arg (ap, int); + x2 = va_arg (ap, int); + x3 = va_arg (ap, int); + x4 = va_arg (ap, int); + x5 = va_arg (ap, int); + x6 = va_arg (ap, int); + x7 = va_arg (ap, int); + x8 = va_arg (ap, int); + fprintf (stderr, fmt, x1, x2, x3, x4, x5, x6, x7, x8); + } +#endif +} + +void reset_all_systems (void) +{ + filesys_reset (); + filesys_start_threads (); +} + /* Okay, this stuff looks strange, but it is here to encourage people who * port UAE to re-use as much of this code as possible. Functions that you * should be using are do_start_program() and do_leave_program(), as well @@ -881,99 +937,99 @@ static void parse_cmdline_and_init_file( * Add #ifdefs around these as appropriate. */ -void do_start_program(void) +void do_start_program (void) { /* Do a reset on startup. Whether this is elegant is debatable. */ quit_program = 2; - m68k_go(1); + m68k_go (1); } -void do_leave_program(void) +void do_leave_program (void) { - graphics_leave(); - close_joystick(); - close_sound(); - dump_counts(); - serial_exit(); - zfile_exit(); - if (!no_gui) - gui_exit(); + graphics_leave (); + close_joystick (); + close_sound (); + dump_counts (); + serial_exit (); + zfile_exit (); + if (! no_gui) + gui_exit (); } -#ifndef _WIN32 -void start_program(void) +void start_program (void) { - do_start_program(); + do_start_program (); } -#endif -void leave_program(void) +void leave_program (void) { - do_leave_program(); + do_leave_program (); } -void real_main(int argc, char **argv) +void real_main (int argc, char **argv) { FILE *hf; default_currprefs (); - if (!graphics_setup()) { - exit(1); + if (! graphics_setup ()) { + exit (1); } rtarea_init (); hardfile_install (); - parse_cmdline_and_init_file(argc, argv); + parse_cmdline_and_init_file (argc, argv); - machdep_init(); + machdep_init (); - if (!setup_sound()) { + if (! setup_sound ()) { fprintf (stderr, "Sound driver unavailable: Sound output disabled\n"); currprefs.produce_sound = 0; } - init_joystick(); + init_joystick (); - if (!no_gui) { - int err = gui_init(); + if (! no_gui) { + int err = gui_init (); if (err == -1) { fprintf (stderr, "Failed to initialize the GUI\n"); } else if (err == -2) { - exit(0); + exit (0); } } - if (sound_available && !init_sound()) { + if (sound_available && currprefs.produce_sound > 1 && ! init_sound ()) { fprintf (stderr, "Sound driver unavailable: Sound output disabled\n"); currprefs.produce_sound = 0; } - fix_options(); + fix_options (); changed_prefs = currprefs; /* Install resident module to get 8MB chipmem, if requested */ - rtarea_setup(); + rtarea_setup (); - keybuf_init(); /* Must come after init_joystick */ + keybuf_init (); /* Must come after init_joystick */ expansion_init (); - memory_init(); + memory_init (); + + filesys_install (); + gfxlib_install (); + emulib_install (); + uaeexe_install (); + + custom_init (); /* Must come after memory_init */ + serial_init (); + DISK_init (); + + reset_frame_rate_hack (); + init_m68k(); /* must come after reset_frame_rate_hack (); */ - filesys_install(); - gfxlib_install(); - emulib_install(); - uaeexe_install(); - - custom_init(); /* Must come after memory_init */ - serial_init(); - DISK_init(); - init_m68k(); - compiler_init(); - gui_update(); + compiler_init (); + gui_update (); if (graphics_init ()) { setup_brkhandler (); - filesys_start_threads (); if (use_debugger && debuggable ()) activate_debugger (); @@ -983,9 +1039,9 @@ void real_main(int argc, char **argv) } #ifndef NO_MAIN_IN_MAIN_C -int main(int argc, char **argv) +int main (int argc, char **argv) { - real_main(argc, argv); + real_main (argc, argv); return 0; } #endif