|
|
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" ! 15: #include "memory.h" ! 16: #include "custom.h" ! 17: #include "serial.h" ! 18: #include "newcpu.h" ! 19: #include "disk.h" ! 20: #include "debug.h" ! 21: #include "xwin.h" ! 22: #include "os.h" ! 23: #include "keybuf.h" ! 24: #include "gui.h" ! 25: #include "zfile.h" ! 26: #include "autoconf.h" ! 27: #include "compiler.h" ! 28: ! 29: int version = 100*UAEMAJOR + 10*UAEMINOR + UAEURSAMINOR; ! 30: int framerate = 1; ! 31: int use_debugger = 0; ! 32: int illegal_mem = 0; ! 33: int use_gfxlib = 0; ! 34: int no_xhair = 0; ! 35: int use_lores = 0; ! 36: int use_serial = 0; ! 37: int automount_uaedev = 1; ! 38: int produce_sound = 0; ! 39: int fake_joystick = 0; ! 40: KbdLang keyboard_lang = KBD_LANG_US; ! 41: int screen_res = 4; ! 42: int correct_aspect = 0; ! 43: int color_mode = 0; ! 44: int sound_desired_bits = 16; ! 45: int sound_desired_freq = 44100; ! 46: int sound_desired_bsiz = 8192; ! 47: int allow_save = 0; ! 48: int no_gui = 0; ! 49: ! 50: long hardfile_size = 0; ! 51: ! 52: ULONG fastmem_size = 0x000000; ! 53: ULONG chipmem_size = 0x200000; ! 54: ULONG bogomem_size = 0x000000; ! 55: char df0[256]="df0.adf", df1[256]="df1.adf", df2[256]="df2.adf", df3[256]="df3.adf"; ! 56: char romfile[256] = "kick.rom"; ! 57: #ifndef __DOS__ ! 58: char prtname[256] = "lpr "; ! 59: #else ! 60: char prtname[256] = "PRN"; ! 61: #endif ! 62: ! 63: char optionsfile[256]; ! 64: ! 65: /* If you want to pipe Printer output to a file, put something like ! 66: * "cat >>printerfile.tmp" above. ! 67: * The printer support was only tested with the driver "PostScript" on ! 68: * Amiga side, using apsfilter for linux to print ps-data. ! 69: * ! 70: * Note for the DOS-Port: Maybe it's only neccesary to use a ! 71: * -p LPT1: or -p PRN: to print in a DOSBOX. I don't know, ! 72: * I do not use DOS... (please try) -=SR=- ! 73: */ ! 74: ! 75: /* People must provide their own name for this */ ! 76: char sername[256] = ""; ! 77: ! 78: /* And again: Serial lines work under Linux. I don't know ! 79: * how this behaves in other OSes. This is work for the porting ! 80: * people -=SR=- ! 81: */ ! 82: ! 83: void usage(void) ! 84: { ! 85: printf("UAE - The Un*x Amiga emulator\n"); ! 86: printf("Summary of command-line options:\n"); ! 87: printf(" -h : Print help\n"); ! 88: printf(" -m VOLNAME:mount_point : mount file system at <mount point> as AmigaDOS\n" ! 89: " volume VOLNAME:\n"); ! 90: printf(" -M VOLNAME:mount_point : like -m, but mount read-only\n"); ! 91: printf(" -s n : Emulate n*256 KB slow memory at 0xC00000\n"); ! 92: printf(" -c n : Emulate n*512 KB chip memory at 0x000000\n"); ! 93: printf(" -F n : Emulate n MB fast memory at 0x200000\n"); ! 94: printf(" -a : Add no expansion devices (disables fastmem and\n" ! 95: " harddisk support.\n"); ! 96: printf(" -J : Fake joystick emulation with the numeric pad.\n"); ! 97: printf(" -f n : Set the frame rate to 1/n\n"); ! 98: printf(" -D : Start up the built-in debugger\n"); ! 99: printf(" -i : Print illegal memory accesses\n"); ! 100: printf(" -o : Allow options to be saved\n"); ! 101: printf(" -G : Disable user interface\n"); ! 102: printf(" -[0123] file : Use file instead of df[0123].adf as disk image.e\n"); ! 103: printf(" -r file : Use file as ROM image instead of kick.rom\n"); ! 104: target_specific_usage(); ! 105: /* printf(" -g : Turn on gfx-lib replacement (EXPERIMENTAL).\n");*/ ! 106: printf(" -d mode : Select resolution with the mode parameter.\n"); ! 107: printf(" -H mode : Set the number of colors with the mode parameter.\n"); ! 108: printf(" -C : Use correct aspect display mode.\n"); ! 109: printf("\n"); ! 110: printf("Valid resolutions: 0 (320x200); 1 (320x240); 2 (320x400); 3 (640x480);\n" ! 111: " 4 (800x600)\n" ! 112: "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n" ! 113: " 3 (256 colors, with dithering for better results)\n" ! 114: " 4 (16 colors, dithered); 5 (16 million colors)\n" ! 115: "UAE may choose to ignore the color mode/resolution setting.\n"); ! 116: } ! 117: ! 118: #ifdef __unix ! 119: ! 120: void parse_cmdline(int argc, char **argv) ! 121: { ! 122: int c; ! 123: extern char *optarg; ! 124: ! 125: while(((c = getopt(argc, argv, "l:Dif:gd:hxF:as:c:S:Jm:M:0:1:2:3:r:H:p:CI:b:R:B:oG")) != EOF)) ! 126: switch(c) { ! 127: case 'h': usage(); exit(0); ! 128: ! 129: case '0': strncpy(df0, optarg, 255); df0[255] = 0; break; ! 130: case '1': strncpy(df1, optarg, 255); df1[255] = 0; break; ! 131: case '2': strncpy(df2, optarg, 255); df2[255] = 0; break; ! 132: case '3': strncpy(df3, optarg, 255); df3[255] = 0; break; ! 133: case 'r': strncpy(romfile, optarg, 255); romfile[255] = 0; break; ! 134: case 'p': strncpy(prtname, optarg, 255); prtname[255] = 0; break; ! 135: case 'I': strncpy(sername, optarg, 255); sername[255] = 0; use_serial = 1; break; ! 136: case 'm': ! 137: case 'M': ! 138: { ! 139: char buf[256]; ! 140: char *s2; ! 141: int readonly = (c == 'M'); ! 142: ! 143: strncpy(buf, optarg, 255); buf[255] = 0; ! 144: s2 = strchr(buf, ':'); ! 145: if(s2) { ! 146: *s2++ = '\0'; ! 147: #ifdef __DOS__ ! 148: { ! 149: char *tmp; ! 150: ! 151: while ((tmp = strchr(s2, '\\'))) ! 152: *tmp = '/'; ! 153: } ! 154: #endif ! 155: add_filesys_unit(buf, s2, readonly); ! 156: } else { ! 157: fprintf(stderr, "Usage: [-m | -M] VOLNAME:/mount_point\n"); ! 158: } ! 159: } ! 160: break; ! 161: ! 162: case 'S': produce_sound = atoi(optarg); break; ! 163: case 'f': framerate = atoi(optarg); break; ! 164: case 'x': no_xhair = 1; break; ! 165: case 'D': use_debugger = 1; break; ! 166: case 'i': illegal_mem = 1; break; ! 167: case 'J': fake_joystick = 1; break; ! 168: case 'a': automount_uaedev = 0; break; ! 169: case 'g': use_gfxlib = 1; break; ! 170: case 'C': correct_aspect = 1; break; ! 171: case 'o': allow_save = 1; break; ! 172: case 'G': no_gui = 1; break; ! 173: ! 174: case 'F': ! 175: fastmem_size = atoi(optarg) * 0x100000; ! 176: if (fastmem_size != 0x100000 && fastmem_size != 0x200000 ! 177: && fastmem_size != 0x400000 && fastmem_size != 0x800000) ! 178: { ! 179: fastmem_size = 0; ! 180: fprintf(stderr, "Unsupported fastmem size!\n"); ! 181: } ! 182: break; ! 183: ! 184: case 's': ! 185: bogomem_size = atoi(optarg) * 0x40000; ! 186: if (bogomem_size != 0x80000 && bogomem_size != 0x100000 ! 187: /* Braino && bogomem_size != 0x180000 && bogomem_size != 0x1C0000*/) ! 188: { ! 189: bogomem_size = 0; ! 190: fprintf(stderr, "Unsupported bogomem size!\n"); ! 191: } ! 192: break; ! 193: ! 194: case 'c': ! 195: chipmem_size = atoi(optarg) * 0x80000; ! 196: if (chipmem_size != 0x80000 && chipmem_size != 0x100000 ! 197: && chipmem_size != 0x200000) ! 198: { ! 199: chipmem_size = 0x200000; ! 200: fprintf(stderr, "Unsupported chipmem size!\n"); ! 201: } ! 202: ! 203: break; ! 204: ! 205: case 'l': ! 206: if (0 == strcasecmp(optarg, "de")) ! 207: keyboard_lang = KBD_LANG_DE; ! 208: else if (0 == strcasecmp(optarg, "us")) ! 209: keyboard_lang = KBD_LANG_US; ! 210: else if (0 == strcasecmp(optarg, "se")) ! 211: keyboard_lang = KBD_LANG_SE; ! 212: else if (0 == strcasecmp(optarg, "fr")) ! 213: keyboard_lang = KBD_LANG_FR; ! 214: else if (0 == strcasecmp(optarg, "it")) ! 215: keyboard_lang = KBD_LANG_IT; ! 216: break; ! 217: ! 218: case 'd': ! 219: screen_res = atoi(optarg); ! 220: if (screen_res < 0 || screen_res > MAX_SCREEN_MODES) { ! 221: fprintf(stderr, "Bad video mode selected. Using default.\n"); ! 222: screen_res = 3; ! 223: } ! 224: break; ! 225: ! 226: case 'H': ! 227: color_mode = atoi(optarg); ! 228: if (color_mode < 0 || color_mode > MAX_COLOR_MODES) { ! 229: fprintf(stderr, "Bad color mode selected. Using default.\n"); ! 230: color_mode = 0; ! 231: } ! 232: break; ! 233: ! 234: case 'b': sound_desired_bits = atoi(optarg); break; ! 235: case 'B': sound_desired_bsiz = atoi(optarg); break; ! 236: case 'R': sound_desired_freq = atoi(optarg); break; ! 237: } ! 238: } ! 239: #endif ! 240: ! 241: #ifndef __bebox__ /* BeOS needs its own startup code */ ! 242: ! 243: static void parse_cmdline_and_init_file(int argc, char **argv) ! 244: { ! 245: FILE *f; ! 246: char *home; ! 247: char *buffer,*tmpbuf, *token; ! 248: char smallbuf[256]; ! 249: int bufsiz, result; ! 250: int n_args; ! 251: char **new_argv; ! 252: int new_argc; ! 253: ! 254: strcpy(optionsfile,""); ! 255: ! 256: #if !defined(__DOS__) && !defined(__mac__) ! 257: home = getenv("HOME"); ! 258: if (home != NULL && strlen(home) < 240) ! 259: { ! 260: strcpy(optionsfile, home); ! 261: strcat(optionsfile, "/"); ! 262: } ! 263: #endif ! 264: ! 265: #ifndef __DOS__ ! 266: strcat(optionsfile, ".uaerc"); ! 267: #else ! 268: strcat(optionsfile, "uae.rc"); ! 269: #endif ! 270: ! 271: f = fopen(optionsfile,"r"); ! 272: if (f == NULL) { ! 273: parse_cmdline(argc, argv); ! 274: return; ! 275: } ! 276: fseek(f, 0, SEEK_END); ! 277: bufsiz = ftell(f); ! 278: fseek(f, 0, SEEK_SET); ! 279: ! 280: buffer = (char *)malloc(bufsiz+1); ! 281: buffer[bufsiz] = 0; ! 282: if (fread(buffer, 1, bufsiz, f) < bufsiz) { ! 283: fprintf(stderr, "Error reading configuration file\n"); ! 284: fclose(f); ! 285: parse_cmdline(argc, argv); ! 286: return; ! 287: } ! 288: fclose(f); ! 289: ! 290: #ifdef __DOS__ ! 291: { ! 292: char *tmp; ! 293: ! 294: while ((tmp = strchr(buffer, 0x0d))) ! 295: *tmp = ' '; ! 296: while ((tmp = strchr(buffer, 0x0a))) ! 297: *tmp = ' '; ! 298: while (buffer[0] == ' ') ! 299: strcpy(buffer, buffer+1); ! 300: while ((strlen(buffer) > 0) && (buffer[strlen(buffer) - 1] == ' ')) ! 301: buffer[strlen(buffer) - 1] = '\0'; ! 302: while ((tmp = strstr(buffer, " "))) ! 303: strcpy(tmp, tmp+1); ! 304: } ! 305: #endif ! 306: ! 307: tmpbuf = my_strdup (buffer); ! 308: ! 309: n_args = 0; ! 310: if (strtok(tmpbuf, "\n ") != NULL) { ! 311: do { ! 312: n_args++; ! 313: } while (strtok(NULL, "\n ") != NULL); ! 314: } ! 315: free (tmpbuf); ! 316: ! 317: new_argv = (char **)malloc ((1 + n_args + argc) * sizeof (char **)); ! 318: new_argv[0] = argv[0]; ! 319: new_argc = 1; ! 320: ! 321: token = strtok(buffer, "\n "); ! 322: while (token != NULL) { ! 323: new_argv[new_argc] = my_strdup (token); ! 324: new_argc++; ! 325: token = strtok(NULL, "\n "); ! 326: } ! 327: for (n_args = 1; n_args < argc; n_args++) ! 328: new_argv[new_argc++] = argv[n_args]; ! 329: new_argv[new_argc] = NULL; ! 330: parse_cmdline(new_argc, new_argv); ! 331: } ! 332: ! 333: static int ARE_YOU_NUTS = 0; ! 334: ! 335: int main(int argc, char **argv) ! 336: { ! 337: FILE *hf; ! 338: ! 339: hf = fopen("hardfile", "rb"); ! 340: if (hf == NULL) ! 341: hardfile_size = 0; ! 342: else { ! 343: fseek(hf, 0, SEEK_END); ! 344: hardfile_size = ftell(hf); ! 345: fclose(hf); ! 346: } ! 347: rtarea_init (); ! 348: hardfile_install (); ! 349: ! 350: parse_cmdline_and_init_file(argc, argv); ! 351: if (!init_sound()) { ! 352: fprintf(stderr, "Sound driver unavailable: Sound output disabled\n"); ! 353: produce_sound = 0; ! 354: } ! 355: ! 356: if (!no_gui && gui_init() < 0) { ! 357: fprintf(stderr, "Failed to initialize the GUI\n"); ! 358: /* abort()? Maybe. */ ! 359: } ! 360: init_joystick(); ! 361: keybuf_init(); ! 362: ! 363: expansion_init (); ! 364: memory_init(); ! 365: ! 366: filesys_install(); ! 367: execlib_install(); ! 368: gfxlib_install(); ! 369: emulib_install(); ! 370: ! 371: custom_init(); ! 372: serial_init(); ! 373: DISK_init(); ! 374: init_m68k(); ! 375: compiler_init(); ! 376: ! 377: /* We ought to know this by now */ ! 378: use_lores = screen_res < 3; ! 379: ! 380: if (graphics_init()) { ! 381: m68k_reset(); ! 382: ! 383: setup_brkhandler(); ! 384: if (use_debugger && debuggable()) ! 385: activate_debugger(); ! 386: if (ARE_YOU_NUTS) ! 387: execlib_sysinit(); ! 388: else ! 389: m68k_go(1); ! 390: ! 391: graphics_leave(); ! 392: close_joystick(); ! 393: } ! 394: dump_counts(); ! 395: serial_exit(); ! 396: zfile_exit(); ! 397: if (!no_gui) ! 398: gui_exit(); ! 399: return 0; ! 400: } ! 401: #endif /* not __bebox__ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.