|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Main program
5: *
6: * (c) 1995 Bernd Schmidt, Ed Hanway
7: */
8:
9: #include "sysconfig.h"
10: #include "sysdeps.h"
11: #include <assert.h>
12:
13: #include "config.h"
14: #include "options.h"
1.1.1.2 ! root 15: #include "uae.h"
! 16: #include "events.h"
1.1 root 17: #include "memory.h"
18: #include "custom.h"
19: #include "serial.h"
1.1.1.2 ! root 20: #include "readcpu.h"
1.1 root 21: #include "newcpu.h"
22: #include "disk.h"
23: #include "debug.h"
24: #include "xwin.h"
25: #include "os.h"
26: #include "keybuf.h"
27: #include "gui.h"
28: #include "zfile.h"
29: #include "autoconf.h"
1.1.1.2 ! root 30: #include "osemu.h"
1.1 root 31: #include "compiler.h"
32:
33: int version = 100*UAEMAJOR + 10*UAEMINOR + UAEURSAMINOR;
34: int framerate = 1;
35: int use_debugger = 0;
36: int illegal_mem = 0;
37: int use_gfxlib = 0;
38: int no_xhair = 0;
39: int use_serial = 0;
40: int automount_uaedev = 1;
41: int produce_sound = 0;
42: int fake_joystick = 0;
43: KbdLang keyboard_lang = KBD_LANG_US;
44: int correct_aspect = 0;
45: int color_mode = 0;
46: int sound_desired_bits = 16;
1.1.1.2 ! root 47: #ifdef AMIGA
! 48: int sound_desired_freq = 11025;
! 49: #else
1.1 root 50: int sound_desired_freq = 44100;
1.1.1.2 ! root 51: #endif
1.1 root 52: int sound_desired_bsiz = 8192;
53: int allow_save = 0;
54: int no_gui = 0;
1.1.1.2 ! root 55: int emul_accuracy = 2;
! 56: int test_drawing_speed = 0;
! 57: int gfx_requested_width = 800, gfx_requested_height = 600, gfx_requested_lores = 0;
! 58: int gfx_requested_linedbl = 0, gfx_requested_correct_aspect = 0;
! 59: int gfx_requested_xcenter = 0, gfx_requested_ycenter = 0;
! 60: int immediate_blits = 0, blits_32bit_enabled = 0;
1.1 root 61: long hardfile_size = 0;
62:
63: ULONG fastmem_size = 0x000000;
64: ULONG chipmem_size = 0x200000;
65: ULONG bogomem_size = 0x000000;
66: char df0[256]="df0.adf", df1[256]="df1.adf", df2[256]="df2.adf", df3[256]="df3.adf";
67: char romfile[256] = "kick.rom";
68: #ifndef __DOS__
69: char prtname[256] = "lpr ";
70: #else
71: char prtname[256] = "PRN";
72: #endif
73:
74: char optionsfile[256];
75:
76: /* If you want to pipe Printer output to a file, put something like
77: * "cat >>printerfile.tmp" above.
78: * The printer support was only tested with the driver "PostScript" on
79: * Amiga side, using apsfilter for linux to print ps-data.
80: *
1.1.1.2 ! root 81: * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a
! 82: * PostScript printer or ghostscript -=SR=-
1.1 root 83: */
84:
85: /* People must provide their own name for this */
86: char sername[256] = "";
87:
1.1.1.2 ! root 88: static void fix_options(void)
! 89: {
! 90: }
1.1 root 91:
92: void usage(void)
93: {
94: printf("UAE - The Un*x Amiga emulator\n");
95: printf("Summary of command-line options:\n");
1.1.1.2 ! root 96: printf(" -h : Print help\n");
! 97: printf(" -m VOL:dir : mount directory called <dir> as AmigaDOS volume VOL:\n");
! 98: printf(" -M VOL:dir : like -m, but mount read-only\n");
! 99: printf(" -s n : Emulate n*256 KB slow memory at 0xC00000\n");
! 100: printf(" -c n : Emulate n*512 KB chip memory at 0x000000\n");
! 101: printf(" -F n : Emulate n MB fast memory at 0x200000\n");
! 102: printf(" -a : Add no expansion devices (disables fastmem and\n"
! 103: " harddisk support\n");
! 104: printf(" -J : Fake joystick emulation with the numeric pad\n");
! 105: printf(" -f n : Set the frame rate to 1/n\n");
! 106: printf(" -D : Start up the built-in debugger\n");
! 107: printf(" -i : Print illegal memory accesses\n");
! 108: printf(" -o : Allow options to be saved\n");
! 109: printf(" -G : Disable user interface\n");
! 110: printf(" -A n : Set emulator accuracy to n (0, 1 or 2)\n");
! 111: printf(" -[0123] file : Use file instead of df[0123].adf as disk image\n");
! 112: printf(" -r file : Use file as ROM image instead of kick.rom\n");
1.1 root 113: target_specific_usage();
1.1.1.2 ! root 114: /* printf(" -g : Turn on gfx-lib replacement (EXPERIMENTAL).\n");*/
! 115: /* printf(" -d mode : OBSOLETE: Use \"-O\".\n");
! 116: printf(" -C : OBSOLETE: use \"-O\"\n"); */
! 117: printf(" -n parms : Set blitter parameters: 'i' enables immediate blits,\n"
! 118: " '3' enables 32 bit blits (may crash RISC machines)\n");
! 119: printf(" -O modespec : Define graphics mode (see below).\n");
! 120: printf(" -H mode : Set the color mode (see below).\n");
! 121: printf("\n"
1.1 root 122: "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n"
123: " 3 (256 colors, with dithering for better results)\n"
124: " 4 (16 colors, dithered); 5 (16 million colors)\n"
1.1.1.2 ! root 125: "The format for the modespec parameter of \"-O\" is as follows:\n"
! 126: " -O width:height:modifiers\n"
! 127: " \"width\" and \"height\" specify the dimensions of the picture.\n"
! 128: " \"modifiers\" is a string that contains zero or more of the following\n"
! 129: " characters:\n"
! 130: " l: Treat the display as lores, drawing only every second pixel\n"
! 131: " x, y: Center the screen horizontally or vertically.\n"
! 132: " d: Draw every line twice unless in interlace: this doubles the height\n"
! 133: " of the display (this is the old -C parameter).\n"
! 134: " c: Correct aspect ratio (this is _not_ the old -C parameter).\n"
! 135: "UAE may choose to ignore the color mode setting and/or adjust the\n"
! 136: "video mode setting to reasonable values.\n");
1.1 root 137: }
138:
1.1.1.2 ! root 139: static void parse_gfx_specs (char *spec)
! 140: {
! 141: char *x0 = my_strdup (spec);
! 142: char *x1, *x2;
! 143:
! 144: x1 = strchr (x0, ':');
! 145: if (x1 == 0)
! 146: goto argh;
! 147: x2 = strchr (x1+1, ':');
! 148: if (x2 == 0)
! 149: goto argh;
! 150: *x1++ = 0; *x2++ = 0;
! 151:
! 152: gfx_requested_width = atoi (x0);
! 153: gfx_requested_height = atoi (x1);
! 154: gfx_requested_lores = strchr (x2, 'l') != 0;
! 155: gfx_requested_xcenter = strchr (x2, 'x') != 0 ? 1 : strchr (x2, 'X') != 0 ? 2 : 0;
! 156: gfx_requested_ycenter = strchr (x2, 'y') != 0 ? 1 : strchr (x2, 'Y') != 0 ? 2 : 0;
! 157: gfx_requested_linedbl = strchr (x2, 'd') != 0;
! 158: gfx_requested_correct_aspect = strchr (x2, 'c') != 0;
! 159:
! 160: free (x0);
! 161: return;
! 162:
! 163: argh:
! 164: fprintf (stderr, "Bad display mode specification.\n");
! 165: fprintf (stderr, "The format to use is: \"width:height:modifiers\"\n");
! 166: free (x0);
! 167: }
! 168:
! 169: #if defined(__unix)||defined(AMIGA)
1.1 root 170:
171: void parse_cmdline(int argc, char **argv)
172: {
173: int c;
174: extern char *optarg;
1.1.1.2 ! root 175: #ifdef __BEOS__
! 176: if (argc < 2)
! 177: return;
! 178: #endif
! 179: /* Help! We're running out of letters! */
! 180: while(((c = getopt(argc, argv, "l:Dif:gd:hxF:as:c:S:Jm:M:0:1:2:3:r:H:p:C:I:b:R:B:oGA:tO:n:")) != EOF))
1.1 root 181: switch(c) {
182: case 'h': usage(); exit(0);
183:
184: case '0': strncpy(df0, optarg, 255); df0[255] = 0; break;
185: case '1': strncpy(df1, optarg, 255); df1[255] = 0; break;
186: case '2': strncpy(df2, optarg, 255); df2[255] = 0; break;
187: case '3': strncpy(df3, optarg, 255); df3[255] = 0; break;
188: case 'r': strncpy(romfile, optarg, 255); romfile[255] = 0; break;
189: case 'p': strncpy(prtname, optarg, 255); prtname[255] = 0; break;
190: case 'I': strncpy(sername, optarg, 255); sername[255] = 0; use_serial = 1; break;
191: case 'm':
192: case 'M':
193: {
194: char buf[256];
195: char *s2;
196: int readonly = (c == 'M');
197:
198: strncpy(buf, optarg, 255); buf[255] = 0;
199: s2 = strchr(buf, ':');
200: if(s2) {
201: *s2++ = '\0';
202: #ifdef __DOS__
203: {
204: char *tmp;
205:
206: while ((tmp = strchr(s2, '\\')))
207: *tmp = '/';
208: }
209: #endif
210: add_filesys_unit(buf, s2, readonly);
211: } else {
212: fprintf(stderr, "Usage: [-m | -M] VOLNAME:/mount_point\n");
213: }
214: }
215: break;
216:
217: case 'S': produce_sound = atoi(optarg); break;
218: case 'f': framerate = atoi(optarg); break;
1.1.1.2 ! root 219: case 'A': emul_accuracy = atoi(optarg); break;
1.1 root 220: case 'x': no_xhair = 1; break;
221: case 'D': use_debugger = 1; break;
222: case 'i': illegal_mem = 1; break;
223: case 'J': fake_joystick = 1; break;
224: case 'a': automount_uaedev = 0; break;
225: case 'g': use_gfxlib = 1; break;
226: case 'o': allow_save = 1; break;
227: case 'G': no_gui = 1; break;
1.1.1.2 ! root 228: case 't': test_drawing_speed = 1; break;
! 229:
! 230: case 'n':
! 231: if (strchr (optarg, '3') != 0)
! 232: blits_32bit_enabled = 1;
! 233: if (strchr (optarg, 'i') != 0)
! 234: immediate_blits = 0;
! 235: break;
! 236:
! 237: case 'C':
! 238: fprintf (stderr, "The -C option is obsolete, please use -O.\n");
! 239: correct_aspect = atoi(optarg);
! 240: if (correct_aspect < 0 || correct_aspect > 2) {
! 241: fprintf(stderr, "Bad parameter for -C !\n");
! 242: correct_aspect = 0;
! 243: }
! 244: break;
1.1 root 245:
246: case 'F':
247: fastmem_size = atoi(optarg) * 0x100000;
248: if (fastmem_size != 0x100000 && fastmem_size != 0x200000
249: && fastmem_size != 0x400000 && fastmem_size != 0x800000)
250: {
251: fastmem_size = 0;
252: fprintf(stderr, "Unsupported fastmem size!\n");
253: }
254: break;
255:
256: case 's':
257: bogomem_size = atoi(optarg) * 0x40000;
258: if (bogomem_size != 0x80000 && bogomem_size != 0x100000
259: /* Braino && bogomem_size != 0x180000 && bogomem_size != 0x1C0000*/)
260: {
261: bogomem_size = 0;
262: fprintf(stderr, "Unsupported bogomem size!\n");
263: }
264: break;
265:
266: case 'c':
267: chipmem_size = atoi(optarg) * 0x80000;
268: if (chipmem_size != 0x80000 && chipmem_size != 0x100000
1.1.1.2 ! root 269: && chipmem_size != 0x200000 && chipmem_size != 0x400000
! 270: && chipmem_size != 0x800000)
1.1 root 271: {
272: chipmem_size = 0x200000;
273: fprintf(stderr, "Unsupported chipmem size!\n");
274: }
275:
276: break;
277:
278: case 'l':
279: if (0 == strcasecmp(optarg, "de"))
280: keyboard_lang = KBD_LANG_DE;
281: else if (0 == strcasecmp(optarg, "us"))
282: keyboard_lang = KBD_LANG_US;
283: else if (0 == strcasecmp(optarg, "se"))
284: keyboard_lang = KBD_LANG_SE;
285: else if (0 == strcasecmp(optarg, "fr"))
286: keyboard_lang = KBD_LANG_FR;
287: else if (0 == strcasecmp(optarg, "it"))
288: keyboard_lang = KBD_LANG_IT;
1.1.1.2 ! root 289: else if (0 == strcasecmp(optarg, "es"))
! 290: keyboard_lang = KBD_LANG_ES;
1.1 root 291: break;
292:
1.1.1.2 ! root 293: case 'O': parse_gfx_specs (optarg); break;
1.1 root 294: case 'd':
1.1.1.2 ! root 295: fprintf (stderr, "Note: The -d option is obsolete, please use the new -O format.\n");
! 296: c = atoi(optarg);
! 297: switch (c) {
! 298: case 0:
! 299: parse_gfx_specs("320:200:lx");
! 300: break;
! 301: case 1:
! 302: parse_gfx_specs("320:240:lx");
! 303: break;
! 304: case 2:
! 305: parse_gfx_specs("320:400:lx");
! 306: break;
! 307: case 3:
! 308: parse_gfx_specs("640:300:x");
! 309: break;
! 310: default:
1.1 root 311: fprintf(stderr, "Bad video mode selected. Using default.\n");
1.1.1.2 ! root 312: /* fall through */
! 313: case 4:
! 314: parse_gfx_specs("800:600:");
! 315: break;
1.1 root 316: }
317: break;
318:
319: case 'H':
320: color_mode = atoi(optarg);
321: if (color_mode < 0 || color_mode > MAX_COLOR_MODES) {
322: fprintf(stderr, "Bad color mode selected. Using default.\n");
323: color_mode = 0;
324: }
325: break;
326:
327: case 'b': sound_desired_bits = atoi(optarg); break;
328: case 'B': sound_desired_bsiz = atoi(optarg); break;
329: case 'R': sound_desired_freq = atoi(optarg); break;
330: }
331: }
332: #endif
333:
334: static void parse_cmdline_and_init_file(int argc, char **argv)
335: {
336: FILE *f;
337: char *home;
338: char *buffer,*tmpbuf, *token;
339: char smallbuf[256];
340: int bufsiz, result;
341: int n_args;
342: char **new_argv;
343: int new_argc;
344:
345: strcpy(optionsfile,"");
346:
347: #if !defined(__DOS__) && !defined(__mac__)
348: home = getenv("HOME");
349: if (home != NULL && strlen(home) < 240)
350: {
351: strcpy(optionsfile, home);
352: strcat(optionsfile, "/");
353: }
354: #endif
355:
356: #ifndef __DOS__
357: strcat(optionsfile, ".uaerc");
358: #else
359: strcat(optionsfile, "uae.rc");
360: #endif
361:
1.1.1.2 ! root 362: f = fopen(optionsfile,"rb");
! 363: #ifndef __DOS__
! 364: /* sam: if not found in $HOME then look in current directory */
! 365: if (f == NULL) {
! 366: f = fopen(".uaerc","rb");
! 367: }
! 368: #endif
! 369:
1.1 root 370: if (f == NULL) {
371: parse_cmdline(argc, argv);
372: return;
373: }
374: fseek(f, 0, SEEK_END);
375: bufsiz = ftell(f);
376: fseek(f, 0, SEEK_SET);
377:
378: buffer = (char *)malloc(bufsiz+1);
379: buffer[bufsiz] = 0;
380: if (fread(buffer, 1, bufsiz, f) < bufsiz) {
381: fprintf(stderr, "Error reading configuration file\n");
382: fclose(f);
383: parse_cmdline(argc, argv);
384: return;
385: }
386: fclose(f);
387:
388: #ifdef __DOS__
389: {
390: char *tmp;
391:
392: while ((tmp = strchr(buffer, 0x0d)))
393: *tmp = ' ';
394: while ((tmp = strchr(buffer, 0x0a)))
395: *tmp = ' ';
396: while (buffer[0] == ' ')
397: strcpy(buffer, buffer+1);
398: while ((strlen(buffer) > 0) && (buffer[strlen(buffer) - 1] == ' '))
399: buffer[strlen(buffer) - 1] = '\0';
400: while ((tmp = strstr(buffer, " ")))
401: strcpy(tmp, tmp+1);
402: }
403: #endif
404:
405: tmpbuf = my_strdup (buffer);
406:
407: n_args = 0;
408: if (strtok(tmpbuf, "\n ") != NULL) {
409: do {
410: n_args++;
411: } while (strtok(NULL, "\n ") != NULL);
412: }
413: free (tmpbuf);
414:
415: new_argv = (char **)malloc ((1 + n_args + argc) * sizeof (char **));
416: new_argv[0] = argv[0];
417: new_argc = 1;
418:
419: token = strtok(buffer, "\n ");
420: while (token != NULL) {
421: new_argv[new_argc] = my_strdup (token);
422: new_argc++;
423: token = strtok(NULL, "\n ");
424: }
425: for (n_args = 1; n_args < argc; n_args++)
426: new_argv[new_argc++] = argv[n_args];
427: new_argv[new_argc] = NULL;
428: parse_cmdline(new_argc, new_argv);
429: }
430:
1.1.1.2 ! root 431: #define ARE_YOU_NUTS 0
1.1 root 432:
1.1.1.2 ! root 433: /* Okay, this stuff looks strange, but it is here to encourage people who
! 434: * port UAE to re-use as much of this code as possible. Functions that you
! 435: * should be using are do_start_program() and do_leave_program(), as well
! 436: * as real_main(). Some OSes don't call main() (which is braindamaged IMHO,
! 437: * but unfortunately very common), so you need to call real_main() from
! 438: * whatever entry point you have. You may want to write your own versions
! 439: * of start_program() and leave_program() if you need to do anything special.
! 440: * Add #ifdefs around these as appropriate.
! 441: */
! 442:
! 443: void do_start_program(void)
! 444: {
! 445: #ifdef USE_EXECLIB
! 446: if (ARE_YOU_NUTS && use_gfxlib)
! 447: execlib_sysinit();
! 448: else
! 449: #endif
! 450: m68k_go(1);
! 451: }
! 452:
! 453: void do_leave_program(void)
! 454: {
! 455: graphics_leave();
! 456: close_joystick();
! 457: dump_counts();
! 458: serial_exit();
! 459: zfile_exit();
! 460: if (!no_gui)
! 461: gui_exit();
! 462: }
! 463:
! 464: void start_program(void)
! 465: {
! 466: do_start_program();
! 467: }
! 468:
! 469: void leave_program(void)
! 470: {
! 471: do_leave_program();
! 472: }
! 473:
! 474: void real_main(int argc, char **argv)
1.1 root 475: {
476: FILE *hf;
477:
478: hf = fopen("hardfile", "rb");
479: if (hf == NULL)
1.1.1.2 ! root 480: hardfile_size = 0;
1.1 root 481: else {
1.1.1.2 ! root 482: fseek(hf, 0, SEEK_END);
! 483: hardfile_size = ftell(hf);
! 484: fclose(hf);
1.1 root 485: }
1.1.1.2 ! root 486:
1.1 root 487: rtarea_init ();
488: hardfile_install ();
489:
490: parse_cmdline_and_init_file(argc, argv);
1.1.1.2 ! root 491:
1.1 root 492: if (!init_sound()) {
493: fprintf(stderr, "Sound driver unavailable: Sound output disabled\n");
494: produce_sound = 0;
495: }
1.1.1.2 ! root 496: init_joystick();
1.1 root 497:
1.1.1.2 ! root 498: if (!no_gui) {
! 499: int err = gui_init();
! 500: if (err == -1) {
! 501: fprintf(stderr, "Failed to initialize the GUI\n");
! 502: } else if (err == -2) {
! 503: exit(0);
! 504: }
1.1 root 505: }
1.1.1.2 ! root 506:
! 507: fix_options();
! 508:
! 509: /* Install resident module to get 8MB chipmem, if requested */
! 510: rtarea_setup();
! 511:
1.1 root 512: keybuf_init();
513:
514: expansion_init ();
515: memory_init();
516:
517: filesys_install();
1.1.1.2 ! root 518: #ifdef USE_EXECLIB
1.1 root 519: execlib_install();
1.1.1.2 ! root 520: #endif
1.1 root 521: gfxlib_install();
522: emulib_install();
1.1.1.2 ! root 523: trackdisk_install();
1.1 root 524:
525: custom_init();
526: serial_init();
527: DISK_init();
528: init_m68k();
529: compiler_init();
1.1.1.2 ! root 530: gui_update();
1.1 root 531:
532: if (graphics_init()) {
1.1.1.2 ! root 533: customreset();
1.1 root 534: m68k_reset();
535:
536: setup_brkhandler();
537: if (use_debugger && debuggable())
538: activate_debugger();
1.1.1.2 ! root 539:
! 540: start_program();
1.1 root 541: }
1.1.1.2 ! root 542: leave_program();
! 543: }
! 544:
! 545: #ifndef __BEOS__ /* BeOS needs its own startup code */
! 546: int main(int argc, char **argv)
! 547: {
! 548: real_main(argc, argv);
1.1 root 549: return 0;
550: }
1.1.1.2 ! root 551: #endif /* not __BEOS__ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.