home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Emulatoren / UAE061.LZH / uae-0.6.1 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  9.6 KB  |  351 lines

  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 "newcpu.h"
  18. #include "disk.h"
  19. #include "debug.h"
  20. #include "xwin.h"
  21. #include "os.h"
  22. #include "filesys.h"
  23. #include "keybuf.h"
  24. #include "gui.h"
  25. #include "zfile.h"
  26.  
  27. int framerate = 1;
  28. int use_debugger = 0;
  29. int use_gfxlib = 0;
  30. int use_xhair = 0;
  31. int use_lores = 0;
  32. int automount_uaedev = 1;
  33. int produce_sound = 1;
  34. int fake_joystick = 0;
  35. KbdLang keyboard_lang = KBD_LANG_US;
  36. int screen_res = 4;
  37. int correct_aspect = 0;
  38. int color_mode = 0;
  39. ULONG fastmem_size = 0x000000;
  40. ULONG chipmem_size = 0x200000;
  41. ULONG bogomem_size = 0x000000;
  42. char df0[256]="df0.adf", df1[256]="df1.adf", df2[256]="df2.adf", df3[256]="df3.adf";
  43. char romfile[256] = "kick.rom";
  44. #ifndef __DOS__
  45. char prtname[256] = "lpr ";
  46. #else
  47. char prtname[256] = "LPT1:";
  48. #endif
  49.  
  50. /* If you want to pipe Printer output to a file, put something like
  51.  * "cat >>printerfile.tmp" above.
  52.  * The printer support was only tested with the driver "PostScript" on
  53.  * Amiga side, using apsfilter for linux to print ps-data.
  54.  *
  55.  * Note for the DOS-Port: Maybe it's only neccesary to use a
  56.  * -p LPT1: or -p PRN: to print in a DOSBOX. I don't know,
  57.  * I do not use DOS... (please try) -=SR=-
  58.  */
  59.  
  60. #ifndef __bebox__  /* BeOS needs its own startup code */
  61.  
  62. static void usage(void)
  63. {
  64.     printf("UAE - The Un*x Amiga emulator\n");
  65.     printf("Summary of command-line options:\n");
  66.     printf("  -h                       : Print help\n");
  67.     printf("  -m VOLNAME:mount_point   : mount file system at <mount point> as AmigaDOS\n"
  68.        "                             volume VOLNAME:\n");
  69.     printf("  -M VOLNAME:mount_point   : like -m, but mount read-only\n");
  70.     printf("  -a                       : Don't mount the harddisk file automatically.\n"
  71.        "                             Useful only for testing.\n");
  72.     printf("  -s n                     : Emulate n*256 KB slow memory at 0xC00000\n");
  73.     printf("  -c n                     : Emulate n*512 KB chip memory at 0x000000\n");
  74.     printf("  -F n                     : Emulate n MB fast memory at 0x200000\n");
  75.     printf("  -f n                     : Set the frame rate to 1/n\n");
  76.     printf("  -D                       : Start up the built-in debugger\n");
  77.     printf("  -[0123] file             : Use file instead of df[0123].adf as disk image.e\n");
  78.     printf("  -r file                  : Use file as ROM image instead of kick.rom\n");
  79.     printf("  -J                       : Fake joystick emulation with the numeric pad.\n");
  80.     target_specific_usage();
  81.     printf("  -g                       : Turn on gfx-lib replacement.\n");
  82.     /* We'll have to sort out the following a little better in the future... */
  83.     printf("  -d mode                  : Select resolution with the mode parameter.\n");
  84.     printf("  -H mode                  : Set the number of colors with the mode parameter.\n");
  85.     printf("  -C                       : Use correct aspect display mode.\n");
  86.     printf("\n");
  87.     printf("Valid resolutions: 0 (320x200); 1 (320x240); 2 (320x400); 3 (640x480);\n"
  88.        "                   4 (800x600)\n"
  89.        "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n"
  90.        "                   3 (256 colors, with dithering for better results)\n"
  91.        "                   4 (16 colors, dithered); 5 (16 million colors)\n"
  92.        "UAE may choose to ignore the color mode/resolution setting.\n");
  93. }
  94.  
  95. #if defined(__unix) || defined(AMIGA)
  96.  
  97. /*static*/ /* main.c:98: warning: static declaration for `parse_cmdline' follows non-static */
  98. void parse_cmdline(int argc, char **argv)
  99. {
  100.     int c;
  101.     extern char *optarg;
  102.  
  103.     while(((c = getopt(argc, argv, "l:Df:gd:hxF:as:c:SJm:M:0:1:2:3:r:H:p:C")) != EOF)) switch(c) {
  104.      case 'h': usage();    exit(0);
  105.  
  106.      case '0': strncpy(df0, optarg, 255); df0[255] = 0;    break;
  107.      case '1': strncpy(df1, optarg, 255); df1[255] = 0; break;
  108.      case '2': strncpy(df2, optarg, 255); df2[255] = 0; break;
  109.      case '3': strncpy(df3, optarg, 255); df3[255] = 0; break;
  110.      case 'r': strncpy(romfile, optarg, 255); romfile[255] = 0; break;
  111.      case 'p': strncpy(prtname, optarg, 255); prtname[255] = 0; break;            
  112.      case 'm':
  113.      case 'M':
  114.     {
  115.         static int mount_seen = 0;
  116.         char buf[256];
  117.         char *s2;
  118.         int readonly = (c == 'M');
  119.  
  120.         if (mount_seen)
  121.         fprintf(stderr, "warning: multiple mounts confuse Kickstart 1.3\n");
  122.         mount_seen = 1;
  123.         strncpy(buf, optarg, 255); buf[255] = 0;
  124.         s2 = strchr(buf, ':');
  125.         if(s2) {
  126.         *s2++ = '\0';
  127. #ifdef __DOS__
  128.         {
  129.             char *tmp;
  130.  
  131.             while ((tmp = strchr(s2, '\\')))
  132.             *tmp = '/';
  133.         }
  134. #endif
  135.         add_filesys_unit(buf, s2, readonly);
  136.         } else {
  137.         fprintf(stderr, "Usage: [-m | -M] VOLNAME:/mount_point\n");
  138.         }
  139.     }
  140.     break;
  141.     
  142.      case 'S': produce_sound = 0; break;
  143.      case 'f': framerate = atoi(optarg); break;
  144.      case 'x': use_xhair = 1; break;
  145.      case 'D': use_debugger = 1; break;
  146.      case 'J': fake_joystick = 1; break;
  147.      case 'a': automount_uaedev = 0; break;
  148.      case 'g': use_gfxlib = 1; break;
  149.      case 'C': correct_aspect = 1; break;
  150.  
  151.      case 'F':
  152.     fastmem_size = atoi(optarg) * 0x100000;
  153.     if (fastmem_size != 0x100000 && fastmem_size != 0x200000 
  154.         && fastmem_size != 0x400000 && fastmem_size != 0x800000) 
  155.     {
  156.         fastmem_size = 0;
  157.         fprintf(stderr, "Unsupported fastmem size!\n");
  158.     }    
  159.     break;
  160.  
  161.      case 's':
  162.     bogomem_size = atoi(optarg) * 0x40000;
  163.     if (bogomem_size != 0x80000 && bogomem_size != 0x100000
  164.         && bogomem_size != 0x180000 && bogomem_size != 0x1C0000)
  165.     {
  166.         bogomem_size = 0;
  167.         fprintf(stderr, "Unsupported bogomem size!\n");
  168.     }
  169.     break;
  170.  
  171.      case 'c':
  172.     chipmem_size = atoi(optarg) * 0x80000;
  173.     if (chipmem_size != 0x80000 && chipmem_size != 0x100000
  174.         && chipmem_size != 0x200000)
  175.     {
  176.         chipmem_size = 0x200000;
  177.         fprintf(stderr, "Unsupported chipmem size!\n");
  178.     }
  179.     
  180.     break;
  181.  
  182.      case 'l':
  183.     if (0 == strcasecmp(optarg, "de"))
  184.         keyboard_lang = KBD_LANG_DE;
  185.     else if (0 == strcasecmp(optarg, "us"))
  186.         keyboard_lang = KBD_LANG_US;
  187.     else if (0 == strcasecmp(optarg, "se"))
  188.         keyboard_lang = KBD_LANG_SE;
  189.     else if (0 == strcasecmp(optarg, "fr"))
  190.         keyboard_lang = KBD_LANG_FR;
  191.     else if (0 == strcasecmp(optarg, "it"))
  192.         keyboard_lang = KBD_LANG_IT;
  193.     break;
  194.  
  195.      case 'd':
  196.     screen_res = atoi(optarg);
  197.     if (screen_res < 0 || screen_res > MAX_SCREEN_MODES) {
  198.         fprintf(stderr, "Bad video mode selected. Using default.\n");
  199.         screen_res = 3;
  200.     }
  201.     use_lores = screen_res < 3;
  202.     break;
  203.  
  204.      case 'H':
  205.     color_mode = atoi(optarg);
  206.     if (color_mode < 0 || color_mode > MAX_COLOR_MODES) {
  207.         fprintf(stderr, "Bad color mode selected. Using default.\n");
  208.         color_mode = 0;
  209.     }
  210.     break;
  211.     }
  212. }
  213. #endif
  214.  
  215. static void parse_cmdline_and_init_file(int argc, char **argv)
  216. {
  217.     FILE *f;
  218.     char file[256], *home;
  219.     char *buffer,*tmpbuf, *token;
  220.     char smallbuf[256];
  221.     int bufsiz, result;
  222.     int n_args;
  223.     char **new_argv;
  224.     int new_argc;
  225.  
  226.     strcpy(file,"");
  227.  
  228. #if !defined(__DOS__) && !defined(__mac__)
  229.     home = getenv("HOME");
  230.     if (home != NULL && strlen(home) < 240)
  231.     {
  232.     strcpy(file, home);
  233.     strcat(file, "/");
  234.     }
  235. #endif
  236.  
  237. #if (defined(__unix) || defined(AMIGA)) && !defined(__DOS__)
  238.     strcat(file, ".uaerc");
  239. #else
  240.     strcat(file, "uae.rc");
  241. #endif
  242.  
  243.     f = fopen(file,"rb");
  244.     if (f == NULL) {
  245. /* sam: if not found in $HOME then look in current directory */
  246. #if (defined(__unix) || defined(AMIGA)) && !defined(__DOS__)
  247.         f = fopen(".uaerc","rb");
  248. #else
  249.         f = fopen("uae.rc","rb");
  250. #endif
  251.     }
  252.     if (f == NULL) {
  253.     parse_cmdline(argc, argv);
  254.     return;
  255.     }
  256.     fseek(f, 0, SEEK_END);
  257.     bufsiz = ftell(f);
  258.     fseek(f, 0, SEEK_SET);
  259.  
  260.     buffer = (char *)malloc(bufsiz+1);
  261.     buffer[bufsiz] = 0;
  262.     if (fread(buffer, 1, bufsiz, f) < bufsiz) {
  263.     fprintf(stderr, "Error reading configuration file\n");
  264.     fclose(f);
  265.     parse_cmdline(argc, argv);
  266.     return;
  267.     }
  268.     fclose(f);
  269.  
  270. #ifdef __DOS__
  271.     {
  272.     char *tmp;
  273.  
  274.     while ((tmp = strchr(buffer, 0x0d)))
  275.         *tmp = ' ';
  276.     while ((tmp = strchr(buffer, 0x0a)))
  277.         *tmp = ' ';
  278.     while (buffer[0] == ' ')
  279.         strcpy(buffer, buffer+1);
  280.     while ((strlen(buffer) > 0) && (buffer[strlen(buffer) - 1] == ' '))
  281.         buffer[strlen(buffer) - 1] = '\0';
  282.     while ((tmp = strstr(buffer, "  ")))
  283.         strcpy(tmp, tmp+1);
  284.     }
  285. #endif
  286.  
  287.     tmpbuf = my_strdup (buffer);
  288.  
  289.     n_args = 0;
  290.     if (strtok(tmpbuf, "\n ") != NULL) {
  291.     do {
  292.         n_args++;
  293.     } while (strtok(NULL, "\n ") != NULL);
  294.     }
  295.     free (tmpbuf);
  296.  
  297.     new_argv = (char **)malloc ((1 + n_args + argc) * sizeof (char **));
  298.     new_argv[0] = argv[0];
  299.     new_argc = 1;
  300.  
  301.     token = strtok(buffer, "\n ");
  302.     while (token != NULL) {
  303.     new_argv[new_argc] = my_strdup (token);
  304.     new_argc++;
  305.     token = strtok(NULL, "\n ");
  306.     }
  307.     for (n_args = 1; n_args < argc; n_args++)
  308.     new_argv[new_argc++] = argv[n_args];
  309.     new_argv[new_argc] = NULL;
  310.     parse_cmdline(new_argc, new_argv);
  311. }
  312.  
  313. int main(int argc, char **argv)
  314. {
  315.     parse_cmdline_and_init_file(argc, argv);
  316.     if (produce_sound && !init_sound()) {
  317.     fprintf(stderr, "Sound driver unavailable: Sound output disabled\n");
  318.     produce_sound = 0;
  319.     }
  320.  
  321.     if (gui_init() < 0) {
  322.     fprintf(stderr, "Failed to initialize the GUI\n");
  323.     /* abort()? Maybe. */
  324.     }
  325.     init_joystick();
  326.     keybuf_init();
  327.     memory_init();
  328.     custom_init();
  329.     DISK_init();
  330.     init_m68k();
  331.     
  332.     if (graphics_init()) {
  333.     MC68000_reset();
  334.  
  335.     debug();
  336.     
  337.     graphics_leave();
  338.     close_joystick();
  339.     }
  340. #ifdef COUNT_INSTRS
  341.     {
  342.     extern void dump_counts(void);
  343.     dump_counts();
  344.     }
  345. #endif
  346.     zfile_exit();
  347.     gui_exit();
  348.     return 0;
  349. }
  350. #endif /* not __bebox__ */
  351.