|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
1.1.1.3 root 3: *
4: * Main program
5: *
6: * Copyright 1995 Ed Hanway
7: * Copyright 1995, 1996, 1997 Bernd Schmidt
1.1 root 8: */
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12: #include <assert.h>
13:
14: #include "config.h"
15: #include "options.h"
1.1.1.3 root 16: #include "threaddep/penguin.h"
1.1.1.2 root 17: #include "uae.h"
1.1.1.3 root 18: #include "gensound.h"
19: #include "sounddep/sound.h"
1.1.1.2 root 20: #include "events.h"
1.1 root 21: #include "memory.h"
22: #include "custom.h"
23: #include "serial.h"
1.1.1.2 root 24: #include "readcpu.h"
1.1 root 25: #include "newcpu.h"
26: #include "disk.h"
27: #include "debug.h"
28: #include "xwin.h"
1.1.1.3 root 29: #include "joystick.h"
1.1 root 30: #include "keybuf.h"
31: #include "gui.h"
32: #include "zfile.h"
33: #include "autoconf.h"
1.1.1.2 root 34: #include "osemu.h"
1.1.1.3 root 35: #include "osdep/exectasks.h"
1.1 root 36: #include "compiler.h"
1.1.1.3 root 37: #include "picasso96.h"
1.1.1.6 root 38: #include "bsdsocket.h"
1.1.1.3 root 39: #include "uaeexe.h"
1.1.1.8 root 40: #include "native2amiga.h"
41: #include "scsidev.h"
1.1 root 42:
1.1.1.4 root 43: long int version = 256*65536L*UAEMAJOR + 65536L*UAEMINOR + UAESUBREV;
1.1.1.3 root 44:
1.1.1.6 root 45: struct uae_prefs currprefs, changed_prefs;
1.1.1.4 root 46:
1.1.1.6 root 47: int no_gui = 0;
1.1.1.4 root 48: int joystickpresent = 0;
49: int cloanto_rom = 0;
50:
51: char warning_buffer[256];
52:
53: char optionsfile[256];
54:
55: /* If you want to pipe printer output to a file, put something like
56: * "cat >>printerfile.tmp" above.
57: * The printer support was only tested with the driver "PostScript" on
58: * Amiga side, using apsfilter for linux to print ps-data.
59: *
60: * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a
61: * PostScript printer or ghostscript -=SR=-
62: */
63:
64: /* People must provide their own name for this */
65: char sername[256] = "";
66:
67: /* Slightly stupid place for this... */
68: /* ncurses.c might use quite a few of those. */
69: char *colormodes[] = { "256 colors", "32768 colors", "65536 colors",
70: "256 colors dithered", "16 colors dithered", "16 million colors",
71: "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
72: "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
73: "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
74: "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
75: "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
76: };
77:
1.1.1.6 root 78: void discard_prefs (struct uae_prefs *p)
1.1.1.3 root 79: {
1.1.1.6 root 80: struct strlist **ps = &p->unknown_lines;
81: while (*ps) {
82: struct strlist *s = *ps;
83: *ps = s->next;
84: free (s->str);
85: free (s);
86: }
87: free_mountinfo (p->mountinfo);
88: }
89:
90: void default_prefs (struct uae_prefs *p)
91: {
92: strcpy (p->description, "UAE default configuration");
93:
94: p->start_gui = 1;
95: p->start_debugger = 0;
96:
97: p->unknown_lines = 0;
1.1.1.4 root 98: /* Note to porters: please don't change any of these options! UAE is supposed
99: * to behave identically on all platforms if possible. */
1.1.1.6 root 100: p->illegal_mem = 0;
101: p->no_xhair = 0;
102: p->use_serial = 0;
103: p->serial_demand = 0;
104: p->parallel_demand = 0;
105: p->automount_uaedev = 1;
106:
107: p->jport0 = 2;
108: p->jport1 = 0;
109: p->keyboard_lang = KBD_LANG_US;
110: p->emul_accuracy = 2;
111: p->test_drawing_speed = 0;
112:
113: p->produce_sound = 0;
114: p->stereo = 0;
115: p->sound_bits = DEFAULT_SOUND_BITS;
116: p->sound_freq = DEFAULT_SOUND_FREQ;
117: p->sound_minbsiz = DEFAULT_SOUND_MINB;
118: p->sound_maxbsiz = DEFAULT_SOUND_MAXB;
1.1.1.9 ! root 119: p->sound_interpol = 0;
1.1.1.6 root 120:
1.1.1.8 root 121: p->gfx_framerate = 1;
1.1.1.6 root 122: p->gfx_width = 800;
123: p->gfx_height = 600;
124: p->gfx_lores = 0;
125: p->gfx_linedbl = 0;
126: p->gfx_afullscreen = 0;
127: p->gfx_pfullscreen = 0;
128: p->gfx_correct_aspect = 0;
129: p->gfx_xcenter = 0;
130: p->gfx_ycenter = 0;
131: p->color_mode = 0;
132:
133: p->x11_use_low_bandwidth = 0;
134: p->x11_use_mitshm = 0;
135: p->x11_hide_cursor = 1;
136:
1.1.1.8 root 137: p->svga_no_linear = 0;
138:
139: p->win32_middle_mouse = 0;
140: p->win32_sound_style = 0;
141: p->win32_sound_tweak = 0;
142: p->win32_logfile = 0;
143: p->win32_iconified_nospeed = 0;
144: p->win32_iconified_nosound = 0;
145:
1.1.1.6 root 146: p->immediate_blits = 0;
147: p->blits_32bit_enabled = 0;
148:
149: strcpy (p->df[0], "df0.adf");
150: strcpy (p->df[1], "df1.adf");
151: strcpy (p->df[2], "df2.adf");
152: strcpy (p->df[3], "df3.adf");
153:
154: strcpy (p->romfile, "kick.rom");
155: strcpy (p->keyfile, "");
156: strcpy (p->prtname, DEFPRTNAME);
157:
158: strcpy (p->path_rom, "./");
159: strcpy (p->path_floppy, "./");
160: strcpy (p->path_hardfile, "./");
161:
162: p->m68k_speed = 4;
163: p->cpu_level = 2;
164: p->cpu_compatible = 0;
165: p->address_space_24 = 0;
166:
167: p->fastmem_size = 0x00000000;
168: p->a3000mem_size = 0x00000000;
169: p->z3fastmem_size = 0x00000000;
170: p->chipmem_size = 0x00200000;
171: p->bogomem_size = 0x00000000;
172: p->gfxmem_size = 0x00000000;
1.1 root 173:
1.1.1.6 root 174: p->mountinfo = alloc_mountinfo ();
1.1.1.4 root 175: }
1.1 root 176:
1.1.1.4 root 177: void fixup_prefs_dimensions (struct uae_prefs *prefs)
178: {
179: if (prefs->gfx_width < 320)
180: prefs->gfx_width = 320;
181: if (prefs->gfx_height < 200)
182: prefs->gfx_height = 200;
183: if (prefs->gfx_height > 300 && ! prefs->gfx_linedbl)
184: prefs->gfx_height = 300;
185: if (prefs->gfx_height > 600)
186: prefs->gfx_height = 600;
1.1 root 187:
1.1.1.4 root 188: prefs->gfx_width += 7; /* X86.S wants multiples of 4 bytes, might be 8 in the future. */
189: prefs->gfx_width &= ~7;
190: }
1.1.1.3 root 191:
1.1.1.4 root 192: static void fix_options (void)
1.1.1.2 root 193: {
1.1.1.3 root 194: int err = 0;
195:
1.1.1.4 root 196: if ((currprefs.chipmem_size & (currprefs.chipmem_size - 1)) != 0
197: || currprefs.chipmem_size < 0x80000
198: || currprefs.chipmem_size > 0x800000)
1.1.1.3 root 199: {
1.1.1.4 root 200: currprefs.chipmem_size = 0x200000;
1.1.1.3 root 201: fprintf (stderr, "Unsupported chipmem size!\n");
202: err = 1;
203: }
1.1.1.4 root 204: if ((currprefs.fastmem_size & (currprefs.fastmem_size - 1)) != 0
205: || (currprefs.fastmem_size != 0 && (currprefs.fastmem_size < 0x100000 || currprefs.fastmem_size > 0x800000)))
1.1.1.3 root 206: {
1.1.1.4 root 207: currprefs.fastmem_size = 0;
1.1.1.3 root 208: fprintf (stderr, "Unsupported fastmem size!\n");
209: err = 1;
210: }
1.1.1.4 root 211: if ((currprefs.gfxmem_size & (currprefs.gfxmem_size - 1)) != 0
212: || (currprefs.gfxmem_size != 0 && (currprefs.gfxmem_size < 0x100000 || currprefs.gfxmem_size > 0x800000)))
1.1.1.3 root 213: {
1.1.1.4 root 214: currprefs.gfxmem_size = 0;
1.1.1.3 root 215: fprintf (stderr, "Unsupported graphics card memory size!\n");
216: err = 1;
217: }
1.1.1.4 root 218: if ((currprefs.z3fastmem_size & (currprefs.z3fastmem_size - 1)) != 0
219: || (currprefs.z3fastmem_size != 0 && (currprefs.z3fastmem_size < 0x100000 || currprefs.z3fastmem_size > 0x4000000)))
1.1.1.3 root 220: {
1.1.1.4 root 221: currprefs.z3fastmem_size = 0;
1.1.1.3 root 222: fprintf (stderr, "Unsupported Zorro III fastmem size!\n");
223: err = 1;
224: }
1.1.1.4 root 225: if (currprefs.address_space_24 && (currprefs.gfxmem_size != 0 || currprefs.z3fastmem_size != 0)) {
226: currprefs.z3fastmem_size = currprefs.gfxmem_size = 0;
1.1.1.3 root 227: fprintf (stderr, "Can't use a graphics card or Zorro III fastmem when using a 24 bit\n"
228: "address space - sorry.\n");
229: }
1.1.1.4 root 230: if ((currprefs.bogomem_size & (currprefs.bogomem_size - 1)) != 0
231: || (currprefs.bogomem_size != 0 && (currprefs.bogomem_size < 0x80000 || currprefs.bogomem_size > 0x100000)))
1.1.1.3 root 232: {
1.1.1.4 root 233: currprefs.bogomem_size = 0;
1.1.1.3 root 234: fprintf (stderr, "Unsupported bogomem size!\n");
235: err = 1;
236: }
237:
1.1.1.4 root 238: if (currprefs.chipmem_size > 0x200000 && currprefs.fastmem_size != 0) {
1.1.1.3 root 239: fprintf (stderr, "You can't use fastmem and more than 2MB chip at the same time!\n");
1.1.1.4 root 240: currprefs.fastmem_size = 0;
1.1.1.3 root 241: err = 1;
242: }
1.1.1.4 root 243: if (currprefs.m68k_speed < -1 || currprefs.m68k_speed > 20) {
244: fprintf (stderr, "Bad value for -w parameter: must be -1, 0, or within 1..20.\n");
1.1.1.3 root 245: currprefs.m68k_speed = 4;
246: err = 1;
247: }
248: if (currprefs.produce_sound < 0 || currprefs.produce_sound > 3) {
249: fprintf (stderr, "Bad value for -S parameter: enable value must be within 0..3\n");
250: currprefs.produce_sound = 0;
251: err = 1;
252: }
1.1.1.4 root 253: if (currprefs.cpu_level < 2 && currprefs.z3fastmem_size > 0) {
1.1.1.3 root 254: fprintf (stderr, "Z3 fast memory can't be used with a 68000/68010 emulation. It\n"
255: "requires a 68020 emulation. Turning off Z3 fast memory.\n");
1.1.1.4 root 256: currprefs.z3fastmem_size = 0;
1.1.1.3 root 257: err = 1;
258: }
1.1.1.8 root 259: if (currprefs.gfxmem_size > 0 && (currprefs.cpu_level < 2 || currprefs.address_space_24)) {
260: fprintf (stderr, "Picasso96 can't be used with a 68000/68010 or 68EC020 emulation. It\n"
1.1.1.3 root 261: "requires a 68020 emulation. Turning off Picasso96.\n");
1.1.1.4 root 262: currprefs.gfxmem_size = 0;
1.1.1.3 root 263: err = 1;
264: }
1.1.1.8 root 265: #ifndef BSDSOCKET_SUPPORTED
266: if (currprefs.socket_emu) {
267: fprintf (stderr, "Compile-time option of BSDSOCKET_SUPPORTED was not enabled. You can't use bsd-socket emulation.\n");
268: currprefs.socket_emu = 0;
269: err = 1;
270: }
271: #endif
1.1.1.3 root 272:
273: if (err)
274: fprintf (stderr, "Please use \"uae -h\" to get usage information.\n");
275: }
276:
277: int quit_program = 0;
278:
279: void uae_reset (void)
280: {
1.1.1.4 root 281: if (quit_program == 0)
1.1.1.3 root 282: quit_program = -2;
283: }
284:
285: void uae_quit (void)
286: {
287: if (quit_program != -1)
288: quit_program = -1;
1.1.1.2 root 289: }
1.1 root 290:
1.1.1.3 root 291: const char *gameport_state (int nr)
1.1 root 292: {
1.1.1.6 root 293: if (JSEM_ISJOY0 (nr, &currprefs) && nr_joysticks > 0)
1.1.1.3 root 294: return "using joystick #0";
1.1.1.6 root 295: else if (JSEM_ISJOY1 (nr, &currprefs) && nr_joysticks > 1)
1.1.1.3 root 296: return "using joystick #1";
1.1.1.6 root 297: else if (JSEM_ISMOUSE (nr, &currprefs))
1.1.1.3 root 298: return "using mouse";
1.1.1.6 root 299: else if (JSEM_ISNUMPAD (nr, &currprefs))
1.1.1.3 root 300: return "using numeric pad as joystick";
1.1.1.6 root 301: else if (JSEM_ISCURSOR (nr, &currprefs))
1.1.1.3 root 302: return "using cursor keys as joystick";
1.1.1.6 root 303: else if (JSEM_ISSOMEWHEREELSE (nr, &currprefs))
1.1.1.3 root 304: return "using T/F/H/B/Alt as joystick";
305:
306: return "not connected";
307: }
308:
1.1.1.6 root 309: #ifndef DONT_PARSE_CMDLINE
1.1.1.3 root 310:
1.1.1.6 root 311: void usage (void)
312: {
1.1.1.3 root 313: }
314:
1.1.1.6 root 315: void parse_cmdline (int argc, char **argv)
316: {
1.1.1.8 root 317: int i;
318: for (i = 1; i < argc; i++) {
319: if (strncmp (argv[i], "-config=", 8) == 0)
320: cfgfile_load (&currprefs, argv[i] + 8);
321: /* Check for new-style "-f xxx" argument, where xxx is config-file */
322: else if (strcmp (argv[i], "-f") == 0) {
323: if (i + 1 == argc)
324: fprintf (stderr, "Missing argument for '-f' option.\n");
325: else
326: cfgfile_load (&currprefs, argv[++i]);
327: } else if (strcmp (argv[i], "-s") == 0) {
328: if (i + 1 == argc)
329: fprintf (stderr, "Missing argument for '-s' option.\n");
330: else
331: cfgfile_parse_line (&currprefs, argv[++i]);
332: } else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "-help") == 0) {
1.1.1.6 root 333: usage ();
334: exit (0);
1.1.1.9 ! root 335: } else {
! 336: if (argv[i][0] == '-' && argv[i][1] != '\0') {
! 337: const char *arg = argv[i] + 2;
! 338: if (*arg == '\0')
! 339: arg = i + 1 < argc ? argv[i + 1] : 0;
! 340: i += parse_cmdline_option (argv[i][1], arg);
! 341: }
1.1.1.3 root 342: }
1.1 root 343: }
344: }
345: #endif
346:
1.1.1.4 root 347: static void parse_cmdline_and_init_file (int argc, char **argv)
1.1 root 348: {
1.1.1.3 root 349: char *home;
1.1 root 350:
1.1.1.6 root 351: strcpy (optionsfile, "");
1.1 root 352:
1.1.1.3 root 353: #ifdef OPTIONS_IN_HOME
1.1.1.4 root 354: home = getenv ("HOME");
355: if (home != NULL && strlen (home) < 240)
1.1 root 356: {
1.1.1.4 root 357: strcpy (optionsfile, home);
358: strcat (optionsfile, "/");
1.1 root 359: }
360: #endif
361:
1.1.1.4 root 362: strcat (optionsfile, OPTIONSFILENAME);
1.1 root 363:
1.1.1.6 root 364: if (! cfgfile_load (&currprefs, optionsfile)) {
1.1.1.3 root 365: #ifdef OPTIONS_IN_HOME
1.1.1.6 root 366: /* sam: if not found in $HOME then look in current directory */
1.1.1.3 root 367: strcpy (optionsfile, OPTIONSFILENAME);
1.1.1.6 root 368: cfgfile_load (&currprefs, optionsfile);
1.1.1.2 root 369: }
370: #endif
371:
1.1.1.6 root 372: parse_cmdline (argc, argv);
1.1 root 373: }
374:
1.1.1.4 root 375: void write_log_standard (const char *fmt, ...)
376: {
377: va_list ap;
378: va_start (ap, fmt);
379: #ifdef HAVE_VFPRINTF
380: vfprintf (stderr, fmt, ap);
381: #else
382: /* Technique stolen from GCC. */
383: {
384: int x1, x2, x3, x4, x5, x6, x7, x8;
385: x1 = va_arg (ap, int);
386: x2 = va_arg (ap, int);
387: x3 = va_arg (ap, int);
388: x4 = va_arg (ap, int);
389: x5 = va_arg (ap, int);
390: x6 = va_arg (ap, int);
391: x7 = va_arg (ap, int);
392: x8 = va_arg (ap, int);
393: fprintf (stderr, fmt, x1, x2, x3, x4, x5, x6, x7, x8);
394: }
395: #endif
396: }
397:
398: void reset_all_systems (void)
399: {
1.1.1.6 root 400: bsdlib_reset ();
1.1.1.4 root 401: filesys_reset ();
402: filesys_start_threads ();
1.1.1.8 root 403: scsidev_reset ();
404: scsidev_start_threads ();
1.1.1.4 root 405: }
406:
1.1.1.2 root 407: /* Okay, this stuff looks strange, but it is here to encourage people who
408: * port UAE to re-use as much of this code as possible. Functions that you
409: * should be using are do_start_program() and do_leave_program(), as well
410: * as real_main(). Some OSes don't call main() (which is braindamaged IMHO,
411: * but unfortunately very common), so you need to call real_main() from
412: * whatever entry point you have. You may want to write your own versions
413: * of start_program() and leave_program() if you need to do anything special.
414: * Add #ifdefs around these as appropriate.
415: */
416:
1.1.1.4 root 417: void do_start_program (void)
1.1.1.2 root 418: {
1.1.1.3 root 419: /* Do a reset on startup. Whether this is elegant is debatable. */
420: quit_program = 2;
1.1.1.4 root 421: m68k_go (1);
1.1.1.2 root 422: }
423:
1.1.1.4 root 424: void do_leave_program (void)
1.1.1.2 root 425: {
1.1.1.4 root 426: graphics_leave ();
427: close_joystick ();
428: close_sound ();
429: dump_counts ();
430: serial_exit ();
431: zfile_exit ();
432: if (! no_gui)
433: gui_exit ();
1.1.1.2 root 434: }
435:
1.1.1.4 root 436: void start_program (void)
1.1.1.2 root 437: {
1.1.1.4 root 438: do_start_program ();
1.1.1.2 root 439: }
440:
1.1.1.4 root 441: void leave_program (void)
1.1.1.2 root 442: {
1.1.1.4 root 443: do_leave_program ();
1.1.1.2 root 444: }
445:
1.1.1.4 root 446: void real_main (int argc, char **argv)
1.1 root 447: {
448: FILE *hf;
449:
1.1.1.6 root 450: default_prefs (&currprefs);
1.1.1.3 root 451:
1.1.1.4 root 452: if (! graphics_setup ()) {
453: exit (1);
1.1 root 454: }
1.1.1.2 root 455:
1.1 root 456: rtarea_init ();
457: hardfile_install ();
1.1.1.8 root 458: scsidev_install ();
1.1 root 459:
1.1.1.4 root 460: parse_cmdline_and_init_file (argc, argv);
1.1.1.2 root 461:
1.1.1.4 root 462: machdep_init ();
1.1.1.3 root 463:
1.1.1.4 root 464: if (! setup_sound ()) {
1.1.1.3 root 465: fprintf (stderr, "Sound driver unavailable: Sound output disabled\n");
466: currprefs.produce_sound = 0;
1.1 root 467: }
1.1.1.4 root 468: init_joystick ();
1.1 root 469:
1.1.1.6 root 470: no_gui = ! currprefs.start_gui;
1.1.1.4 root 471: if (! no_gui) {
472: int err = gui_init ();
1.1.1.2 root 473: if (err == -1) {
1.1.1.3 root 474: fprintf (stderr, "Failed to initialize the GUI\n");
1.1.1.2 root 475: } else if (err == -2) {
1.1.1.4 root 476: exit (0);
1.1.1.2 root 477: }
1.1 root 478: }
1.1.1.5 root 479: if (sound_available && currprefs.produce_sound > 1 && ! init_sound ()) {
1.1.1.3 root 480: fprintf (stderr, "Sound driver unavailable: Sound output disabled\n");
481: currprefs.produce_sound = 0;
482: }
1.1.1.2 root 483:
1.1.1.4 root 484: fix_options ();
1.1.1.3 root 485: changed_prefs = currprefs;
486:
1.1.1.2 root 487: /* Install resident module to get 8MB chipmem, if requested */
1.1.1.4 root 488: rtarea_setup ();
1.1.1.3 root 489:
1.1.1.4 root 490: keybuf_init (); /* Must come after init_joystick */
1.1.1.3 root 491:
1.1 root 492: expansion_init ();
1.1.1.4 root 493: memory_init ();
494:
495: filesys_install ();
496: gfxlib_install ();
497: emulib_install ();
498: uaeexe_install ();
1.1.1.8 root 499: native2amiga_install ();
1.1.1.4 root 500:
501: custom_init (); /* Must come after memory_init */
502: serial_init ();
503: DISK_init ();
504:
505: reset_frame_rate_hack ();
506: init_m68k(); /* must come after reset_frame_rate_hack (); */
1.1 root 507:
1.1.1.4 root 508: compiler_init ();
509: gui_update ();
1.1.1.2 root 510:
1.1.1.3 root 511: if (graphics_init ()) {
512: setup_brkhandler ();
1.1.1.6 root 513: if (currprefs.start_debugger && debuggable ())
1.1.1.3 root 514: activate_debugger ();
515:
516: start_program ();
1.1 root 517: }
1.1.1.3 root 518: leave_program ();
1.1.1.2 root 519: }
520:
1.1.1.3 root 521: #ifndef NO_MAIN_IN_MAIN_C
1.1.1.4 root 522: int main (int argc, char **argv)
1.1.1.2 root 523: {
1.1.1.4 root 524: real_main (argc, argv);
1.1 root 525: return 0;
526: }
1.1.1.3 root 527: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.