|
|
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:
1.1.1.10! root 139: p->curses_reverse_video = 0;
! 140:
1.1.1.8 root 141: p->win32_middle_mouse = 0;
142: p->win32_sound_style = 0;
143: p->win32_sound_tweak = 0;
144: p->win32_logfile = 0;
145: p->win32_iconified_nospeed = 0;
146: p->win32_iconified_nosound = 0;
147:
1.1.1.6 root 148: p->immediate_blits = 0;
149: p->blits_32bit_enabled = 0;
150:
151: strcpy (p->df[0], "df0.adf");
152: strcpy (p->df[1], "df1.adf");
153: strcpy (p->df[2], "df2.adf");
154: strcpy (p->df[3], "df3.adf");
155:
156: strcpy (p->romfile, "kick.rom");
157: strcpy (p->keyfile, "");
158: strcpy (p->prtname, DEFPRTNAME);
159:
160: strcpy (p->path_rom, "./");
161: strcpy (p->path_floppy, "./");
162: strcpy (p->path_hardfile, "./");
163:
164: p->m68k_speed = 4;
165: p->cpu_level = 2;
166: p->cpu_compatible = 0;
167: p->address_space_24 = 0;
168:
169: p->fastmem_size = 0x00000000;
170: p->a3000mem_size = 0x00000000;
171: p->z3fastmem_size = 0x00000000;
172: p->chipmem_size = 0x00200000;
173: p->bogomem_size = 0x00000000;
174: p->gfxmem_size = 0x00000000;
1.1 root 175:
1.1.1.6 root 176: p->mountinfo = alloc_mountinfo ();
1.1.1.4 root 177: }
1.1 root 178:
1.1.1.4 root 179: void fixup_prefs_dimensions (struct uae_prefs *prefs)
180: {
181: if (prefs->gfx_width < 320)
182: prefs->gfx_width = 320;
183: if (prefs->gfx_height < 200)
184: prefs->gfx_height = 200;
185: if (prefs->gfx_height > 300 && ! prefs->gfx_linedbl)
186: prefs->gfx_height = 300;
187: if (prefs->gfx_height > 600)
188: prefs->gfx_height = 600;
1.1 root 189:
1.1.1.4 root 190: prefs->gfx_width += 7; /* X86.S wants multiples of 4 bytes, might be 8 in the future. */
191: prefs->gfx_width &= ~7;
192: }
1.1.1.3 root 193:
1.1.1.4 root 194: static void fix_options (void)
1.1.1.2 root 195: {
1.1.1.3 root 196: int err = 0;
197:
1.1.1.4 root 198: if ((currprefs.chipmem_size & (currprefs.chipmem_size - 1)) != 0
199: || currprefs.chipmem_size < 0x80000
200: || currprefs.chipmem_size > 0x800000)
1.1.1.3 root 201: {
1.1.1.4 root 202: currprefs.chipmem_size = 0x200000;
1.1.1.3 root 203: fprintf (stderr, "Unsupported chipmem size!\n");
204: err = 1;
205: }
1.1.1.4 root 206: if ((currprefs.fastmem_size & (currprefs.fastmem_size - 1)) != 0
207: || (currprefs.fastmem_size != 0 && (currprefs.fastmem_size < 0x100000 || currprefs.fastmem_size > 0x800000)))
1.1.1.3 root 208: {
1.1.1.4 root 209: currprefs.fastmem_size = 0;
1.1.1.3 root 210: fprintf (stderr, "Unsupported fastmem size!\n");
211: err = 1;
212: }
1.1.1.4 root 213: if ((currprefs.gfxmem_size & (currprefs.gfxmem_size - 1)) != 0
214: || (currprefs.gfxmem_size != 0 && (currprefs.gfxmem_size < 0x100000 || currprefs.gfxmem_size > 0x800000)))
1.1.1.3 root 215: {
1.1.1.4 root 216: currprefs.gfxmem_size = 0;
1.1.1.3 root 217: fprintf (stderr, "Unsupported graphics card memory size!\n");
218: err = 1;
219: }
1.1.1.4 root 220: if ((currprefs.z3fastmem_size & (currprefs.z3fastmem_size - 1)) != 0
221: || (currprefs.z3fastmem_size != 0 && (currprefs.z3fastmem_size < 0x100000 || currprefs.z3fastmem_size > 0x4000000)))
1.1.1.3 root 222: {
1.1.1.4 root 223: currprefs.z3fastmem_size = 0;
1.1.1.3 root 224: fprintf (stderr, "Unsupported Zorro III fastmem size!\n");
225: err = 1;
226: }
1.1.1.4 root 227: if (currprefs.address_space_24 && (currprefs.gfxmem_size != 0 || currprefs.z3fastmem_size != 0)) {
228: currprefs.z3fastmem_size = currprefs.gfxmem_size = 0;
1.1.1.3 root 229: fprintf (stderr, "Can't use a graphics card or Zorro III fastmem when using a 24 bit\n"
230: "address space - sorry.\n");
231: }
1.1.1.4 root 232: if ((currprefs.bogomem_size & (currprefs.bogomem_size - 1)) != 0
233: || (currprefs.bogomem_size != 0 && (currprefs.bogomem_size < 0x80000 || currprefs.bogomem_size > 0x100000)))
1.1.1.3 root 234: {
1.1.1.4 root 235: currprefs.bogomem_size = 0;
1.1.1.3 root 236: fprintf (stderr, "Unsupported bogomem size!\n");
237: err = 1;
238: }
239:
1.1.1.4 root 240: if (currprefs.chipmem_size > 0x200000 && currprefs.fastmem_size != 0) {
1.1.1.3 root 241: fprintf (stderr, "You can't use fastmem and more than 2MB chip at the same time!\n");
1.1.1.4 root 242: currprefs.fastmem_size = 0;
1.1.1.3 root 243: err = 1;
244: }
1.1.1.4 root 245: if (currprefs.m68k_speed < -1 || currprefs.m68k_speed > 20) {
246: fprintf (stderr, "Bad value for -w parameter: must be -1, 0, or within 1..20.\n");
1.1.1.3 root 247: currprefs.m68k_speed = 4;
248: err = 1;
249: }
250: if (currprefs.produce_sound < 0 || currprefs.produce_sound > 3) {
251: fprintf (stderr, "Bad value for -S parameter: enable value must be within 0..3\n");
252: currprefs.produce_sound = 0;
253: err = 1;
254: }
1.1.1.4 root 255: if (currprefs.cpu_level < 2 && currprefs.z3fastmem_size > 0) {
1.1.1.3 root 256: fprintf (stderr, "Z3 fast memory can't be used with a 68000/68010 emulation. It\n"
257: "requires a 68020 emulation. Turning off Z3 fast memory.\n");
1.1.1.4 root 258: currprefs.z3fastmem_size = 0;
1.1.1.3 root 259: err = 1;
260: }
1.1.1.8 root 261: if (currprefs.gfxmem_size > 0 && (currprefs.cpu_level < 2 || currprefs.address_space_24)) {
262: fprintf (stderr, "Picasso96 can't be used with a 68000/68010 or 68EC020 emulation. It\n"
1.1.1.3 root 263: "requires a 68020 emulation. Turning off Picasso96.\n");
1.1.1.4 root 264: currprefs.gfxmem_size = 0;
1.1.1.3 root 265: err = 1;
266: }
1.1.1.8 root 267: #ifndef BSDSOCKET_SUPPORTED
268: if (currprefs.socket_emu) {
269: fprintf (stderr, "Compile-time option of BSDSOCKET_SUPPORTED was not enabled. You can't use bsd-socket emulation.\n");
270: currprefs.socket_emu = 0;
271: err = 1;
272: }
273: #endif
1.1.1.3 root 274:
275: if (err)
276: fprintf (stderr, "Please use \"uae -h\" to get usage information.\n");
277: }
278:
279: int quit_program = 0;
280:
281: void uae_reset (void)
282: {
1.1.1.4 root 283: if (quit_program == 0)
1.1.1.3 root 284: quit_program = -2;
285: }
286:
287: void uae_quit (void)
288: {
289: if (quit_program != -1)
290: quit_program = -1;
1.1.1.2 root 291: }
1.1 root 292:
1.1.1.3 root 293: const char *gameport_state (int nr)
1.1 root 294: {
1.1.1.6 root 295: if (JSEM_ISJOY0 (nr, &currprefs) && nr_joysticks > 0)
1.1.1.3 root 296: return "using joystick #0";
1.1.1.6 root 297: else if (JSEM_ISJOY1 (nr, &currprefs) && nr_joysticks > 1)
1.1.1.3 root 298: return "using joystick #1";
1.1.1.6 root 299: else if (JSEM_ISMOUSE (nr, &currprefs))
1.1.1.3 root 300: return "using mouse";
1.1.1.6 root 301: else if (JSEM_ISNUMPAD (nr, &currprefs))
1.1.1.3 root 302: return "using numeric pad as joystick";
1.1.1.6 root 303: else if (JSEM_ISCURSOR (nr, &currprefs))
1.1.1.3 root 304: return "using cursor keys as joystick";
1.1.1.6 root 305: else if (JSEM_ISSOMEWHEREELSE (nr, &currprefs))
1.1.1.3 root 306: return "using T/F/H/B/Alt as joystick";
307:
308: return "not connected";
309: }
310:
1.1.1.6 root 311: #ifndef DONT_PARSE_CMDLINE
1.1.1.3 root 312:
1.1.1.6 root 313: void usage (void)
314: {
1.1.1.3 root 315: }
316:
1.1.1.6 root 317: void parse_cmdline (int argc, char **argv)
318: {
1.1.1.8 root 319: int i;
320: for (i = 1; i < argc; i++) {
321: if (strncmp (argv[i], "-config=", 8) == 0)
322: cfgfile_load (&currprefs, argv[i] + 8);
323: /* Check for new-style "-f xxx" argument, where xxx is config-file */
324: else if (strcmp (argv[i], "-f") == 0) {
325: if (i + 1 == argc)
326: fprintf (stderr, "Missing argument for '-f' option.\n");
327: else
328: cfgfile_load (&currprefs, argv[++i]);
329: } else if (strcmp (argv[i], "-s") == 0) {
330: if (i + 1 == argc)
331: fprintf (stderr, "Missing argument for '-s' option.\n");
332: else
333: cfgfile_parse_line (&currprefs, argv[++i]);
334: } else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "-help") == 0) {
1.1.1.6 root 335: usage ();
336: exit (0);
1.1.1.9 root 337: } else {
338: if (argv[i][0] == '-' && argv[i][1] != '\0') {
339: const char *arg = argv[i] + 2;
1.1.1.10! root 340: int extra_arg = *arg == '\0';
! 341: if (extra_arg)
1.1.1.9 root 342: arg = i + 1 < argc ? argv[i + 1] : 0;
1.1.1.10! root 343: if (parse_cmdline_option (argv[i][1], arg) && extra_arg)
! 344: i++;
1.1.1.9 root 345: }
1.1.1.3 root 346: }
1.1 root 347: }
348: }
349: #endif
350:
1.1.1.4 root 351: static void parse_cmdline_and_init_file (int argc, char **argv)
1.1 root 352: {
1.1.1.3 root 353: char *home;
1.1 root 354:
1.1.1.6 root 355: strcpy (optionsfile, "");
1.1 root 356:
1.1.1.3 root 357: #ifdef OPTIONS_IN_HOME
1.1.1.4 root 358: home = getenv ("HOME");
359: if (home != NULL && strlen (home) < 240)
1.1 root 360: {
1.1.1.4 root 361: strcpy (optionsfile, home);
362: strcat (optionsfile, "/");
1.1 root 363: }
364: #endif
365:
1.1.1.4 root 366: strcat (optionsfile, OPTIONSFILENAME);
1.1 root 367:
1.1.1.6 root 368: if (! cfgfile_load (&currprefs, optionsfile)) {
1.1.1.3 root 369: #ifdef OPTIONS_IN_HOME
1.1.1.6 root 370: /* sam: if not found in $HOME then look in current directory */
1.1.1.3 root 371: strcpy (optionsfile, OPTIONSFILENAME);
1.1.1.6 root 372: cfgfile_load (&currprefs, optionsfile);
1.1.1.2 root 373: }
374: #endif
375:
1.1.1.6 root 376: parse_cmdline (argc, argv);
1.1 root 377: }
378:
1.1.1.4 root 379: void write_log_standard (const char *fmt, ...)
380: {
381: va_list ap;
382: va_start (ap, fmt);
383: #ifdef HAVE_VFPRINTF
384: vfprintf (stderr, fmt, ap);
385: #else
386: /* Technique stolen from GCC. */
387: {
388: int x1, x2, x3, x4, x5, x6, x7, x8;
389: x1 = va_arg (ap, int);
390: x2 = va_arg (ap, int);
391: x3 = va_arg (ap, int);
392: x4 = va_arg (ap, int);
393: x5 = va_arg (ap, int);
394: x6 = va_arg (ap, int);
395: x7 = va_arg (ap, int);
396: x8 = va_arg (ap, int);
397: fprintf (stderr, fmt, x1, x2, x3, x4, x5, x6, x7, x8);
398: }
399: #endif
400: }
401:
402: void reset_all_systems (void)
403: {
1.1.1.6 root 404: bsdlib_reset ();
1.1.1.4 root 405: filesys_reset ();
406: filesys_start_threads ();
1.1.1.8 root 407: scsidev_reset ();
408: scsidev_start_threads ();
1.1.1.4 root 409: }
410:
1.1.1.2 root 411: /* Okay, this stuff looks strange, but it is here to encourage people who
412: * port UAE to re-use as much of this code as possible. Functions that you
413: * should be using are do_start_program() and do_leave_program(), as well
414: * as real_main(). Some OSes don't call main() (which is braindamaged IMHO,
415: * but unfortunately very common), so you need to call real_main() from
416: * whatever entry point you have. You may want to write your own versions
417: * of start_program() and leave_program() if you need to do anything special.
418: * Add #ifdefs around these as appropriate.
419: */
420:
1.1.1.4 root 421: void do_start_program (void)
1.1.1.2 root 422: {
1.1.1.3 root 423: /* Do a reset on startup. Whether this is elegant is debatable. */
424: quit_program = 2;
1.1.1.4 root 425: m68k_go (1);
1.1.1.2 root 426: }
427:
1.1.1.4 root 428: void do_leave_program (void)
1.1.1.2 root 429: {
1.1.1.4 root 430: graphics_leave ();
431: close_joystick ();
432: close_sound ();
433: dump_counts ();
434: serial_exit ();
435: zfile_exit ();
436: if (! no_gui)
437: gui_exit ();
1.1.1.2 root 438: }
439:
1.1.1.4 root 440: void start_program (void)
1.1.1.2 root 441: {
1.1.1.4 root 442: do_start_program ();
1.1.1.2 root 443: }
444:
1.1.1.4 root 445: void leave_program (void)
1.1.1.2 root 446: {
1.1.1.4 root 447: do_leave_program ();
1.1.1.2 root 448: }
449:
1.1.1.4 root 450: void real_main (int argc, char **argv)
1.1 root 451: {
452: FILE *hf;
453:
1.1.1.6 root 454: default_prefs (&currprefs);
1.1.1.3 root 455:
1.1.1.4 root 456: if (! graphics_setup ()) {
457: exit (1);
1.1 root 458: }
1.1.1.2 root 459:
1.1 root 460: rtarea_init ();
461: hardfile_install ();
1.1.1.8 root 462: scsidev_install ();
1.1 root 463:
1.1.1.4 root 464: parse_cmdline_and_init_file (argc, argv);
1.1.1.2 root 465:
1.1.1.4 root 466: machdep_init ();
1.1.1.3 root 467:
1.1.1.4 root 468: if (! setup_sound ()) {
1.1.1.3 root 469: fprintf (stderr, "Sound driver unavailable: Sound output disabled\n");
470: currprefs.produce_sound = 0;
1.1 root 471: }
1.1.1.4 root 472: init_joystick ();
1.1 root 473:
1.1.1.6 root 474: no_gui = ! currprefs.start_gui;
1.1.1.4 root 475: if (! no_gui) {
476: int err = gui_init ();
1.1.1.2 root 477: if (err == -1) {
1.1.1.3 root 478: fprintf (stderr, "Failed to initialize the GUI\n");
1.1.1.2 root 479: } else if (err == -2) {
1.1.1.4 root 480: exit (0);
1.1.1.2 root 481: }
1.1 root 482: }
1.1.1.5 root 483: if (sound_available && currprefs.produce_sound > 1 && ! init_sound ()) {
1.1.1.3 root 484: fprintf (stderr, "Sound driver unavailable: Sound output disabled\n");
485: currprefs.produce_sound = 0;
486: }
1.1.1.2 root 487:
1.1.1.4 root 488: fix_options ();
1.1.1.3 root 489: changed_prefs = currprefs;
490:
1.1.1.2 root 491: /* Install resident module to get 8MB chipmem, if requested */
1.1.1.4 root 492: rtarea_setup ();
1.1.1.3 root 493:
1.1.1.4 root 494: keybuf_init (); /* Must come after init_joystick */
1.1.1.3 root 495:
1.1 root 496: expansion_init ();
1.1.1.4 root 497: memory_init ();
498:
499: filesys_install ();
500: gfxlib_install ();
501: emulib_install ();
502: uaeexe_install ();
1.1.1.8 root 503: native2amiga_install ();
1.1.1.4 root 504:
505: custom_init (); /* Must come after memory_init */
506: serial_init ();
507: DISK_init ();
508:
509: reset_frame_rate_hack ();
510: init_m68k(); /* must come after reset_frame_rate_hack (); */
1.1 root 511:
1.1.1.4 root 512: compiler_init ();
513: gui_update ();
1.1.1.2 root 514:
1.1.1.3 root 515: if (graphics_init ()) {
516: setup_brkhandler ();
1.1.1.6 root 517: if (currprefs.start_debugger && debuggable ())
1.1.1.3 root 518: activate_debugger ();
519:
520: start_program ();
1.1 root 521: }
1.1.1.3 root 522: leave_program ();
1.1.1.2 root 523: }
524:
1.1.1.3 root 525: #ifndef NO_MAIN_IN_MAIN_C
1.1.1.4 root 526: int main (int argc, char **argv)
1.1.1.2 root 527: {
1.1.1.4 root 528: real_main (argc, argv);
1.1 root 529: return 0;
530: }
1.1.1.3 root 531: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.