home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / Atari800 / rt-config.c < prev    next >
C/C++ Source or Header  |  1997-10-30  |  9KB  |  301 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. static char *rcsid = "$Id: rt-config.c,v 1.2 1997/04/12 12:45:31 david Exp $";
  6.  
  7. #define FALSE   0
  8. #define TRUE    1
  9.  
  10. #include "atari.h"
  11. #include "prompts.h"
  12. #include "rt-config.h"
  13.  
  14. char atari_osa_filename[MAX_FILENAME_LEN];
  15. char atari_osb_filename[MAX_FILENAME_LEN];
  16. char atari_xlxe_filename[MAX_FILENAME_LEN];
  17. char atari_basic_filename[MAX_FILENAME_LEN];
  18. char atari_5200_filename[MAX_FILENAME_LEN];
  19. char atari_disk_dir[MAX_FILENAME_LEN];
  20. char atari_rom_dir[MAX_FILENAME_LEN];
  21. char atari_h1_dir[MAX_FILENAME_LEN];
  22. char atari_h2_dir[MAX_FILENAME_LEN];
  23. char atari_h3_dir[MAX_FILENAME_LEN];
  24. char atari_h4_dir[MAX_FILENAME_LEN];
  25. char print_command[256];
  26. int refresh_rate;
  27. int maxmiss;
  28. int default_system;
  29. int default_tv_mode;
  30. int hold_option;
  31. int enable_c000_ram;
  32. int enable_sio_patch;
  33. int enable_xcolpf1;
  34.  
  35. static char *rtconfig_filename1 = "atari800.cfg";
  36. static char *rtconfig_filename2 = "/etc/atari800.cfg";
  37.  
  38. int RtConfigLoad (char *rtconfig_filename)
  39. {
  40.   FILE *fp;
  41.   int status = TRUE;
  42.  
  43.   /*
  44.    * Set Configuration Parameters to sensible values
  45.    * in case the configuration file is missing.
  46.    */
  47.  
  48.   atari_osa_filename[0] = '\0';
  49.   atari_osb_filename[0] = '\0';
  50.   atari_xlxe_filename[0] = '\0';
  51.   atari_basic_filename[0] = '\0';
  52.   atari_5200_filename[0] = '\0';
  53.   atari_disk_dir[0] = '\0';
  54.   atari_rom_dir[0] = '\0';
  55.   atari_h1_dir[0] = '\0';
  56.   atari_h2_dir[0] = '\0';
  57.   atari_h3_dir[0] = '\0';
  58.   atari_h4_dir[0] = '\0';
  59.   strcpy (print_command, "lpr %s");
  60.   refresh_rate = 1;
  61.   maxmiss = 0;
  62.   default_system = 3;
  63.   default_tv_mode = 1;
  64.   hold_option = 0;
  65.   enable_c000_ram = 0;
  66.   enable_sio_patch = 1;
  67.   enable_xcolpf1 = 0;
  68.  
  69.   if (rtconfig_filename)
  70.     {
  71.       fp = fopen (rtconfig_filename, "r");
  72.       if (!fp)
  73.         {
  74.           perror (rtconfig_filename);
  75.           exit (1);
  76.         }
  77.     }
  78.   else
  79.     {
  80.       fp = fopen (rtconfig_filename1, "r");
  81.       if (!fp)
  82.         fp = fopen (rtconfig_filename2, "r");
  83.     }
  84.  
  85.   if (fp)
  86.     {
  87.       char string[256];
  88.       char *ptr;
  89.  
  90.       fgets (string, 256, fp);
  91.  
  92.       printf ("Configuration Created by %s", string);
  93.  
  94.       while (fgets (string, 256, fp))
  95.         {
  96.           RemoveLF (string);
  97.           ptr = strchr(string,'=');
  98.           if (ptr)
  99.             {
  100.               *ptr++ = '\0';
  101.  
  102.               if (strcmp(string,"OS/A_ROM") == 0)
  103.                 strcpy (atari_osa_filename, ptr);
  104.               else if (strcmp(string,"OS/B_ROM") == 0)
  105.                 strcpy (atari_osb_filename, ptr);
  106.               else if (strcmp(string,"XL/XE_ROM") == 0)
  107.                 strcpy (atari_xlxe_filename, ptr);
  108.               else if (strcmp(string,"BASIC_ROM") == 0)
  109.                 strcpy (atari_basic_filename, ptr);
  110.               else if (strcmp(string,"5200_ROM") == 0)
  111.                 strcpy (atari_5200_filename, ptr);
  112.               else if (strcmp(string,"DISK_DIR") == 0)
  113.                 strcpy (atari_disk_dir, ptr);
  114.               else if (strcmp(string,"ROM_DIR") == 0)
  115.                 strcpy (atari_rom_dir, ptr);
  116.               else if (strcmp(string,"H1_DIR") == 0)
  117.                 strcpy (atari_h1_dir, ptr);
  118.               else if (strcmp(string,"H2_DIR") == 0)
  119.                 strcpy (atari_h2_dir, ptr);
  120.               else if (strcmp(string,"H3_DIR") == 0)
  121.                 strcpy (atari_h3_dir, ptr);
  122.               else if (strcmp(string,"H4_DIR") == 0)
  123.                 strcpy (atari_h4_dir, ptr);
  124.               else if (strcmp(string,"PRINT_COMMAND") == 0)
  125.                 strcpy (print_command, ptr);
  126.               else if (strcmp(string,"SCREEN_REFRESH_RATIO") == 0)
  127.                 sscanf (ptr,"%d", &refresh_rate);
  128.               else if (strcmp(string,"MAXIMAL_MISSING_FRAMES") == 0)
  129.                 sscanf (ptr,"%d", &maxmiss);
  130.               else if (strcmp(string,"HOLD_OPTION") == 0)
  131.                 sscanf (ptr,"%d", &hold_option);
  132.               else if (strcmp(string,"ENABLE_C000_RAM") == 0)
  133.                 sscanf (ptr,"%d", &enable_c000_ram);
  134.               else if (strcmp(string,"ENABLE_SIO_PATCH") == 0)
  135.                 sscanf (ptr,"%d", &enable_sio_patch);
  136.               else if (strcmp(string,"ENABLE_XCOLPF1") == 0)
  137.                 sscanf (ptr,"%d", &enable_xcolpf1);
  138.               else if (strcmp(string,"DEFAULT_SYSTEM") == 0)
  139.                 {
  140.                   if (strcmp(ptr,"Atari OS/A") == 0)
  141.                     default_system = 1;
  142.                   else if (strcmp(ptr,"Atari OS/B") == 0)
  143.                     default_system = 2;
  144.                   else if (strcmp(ptr,"Atari XL") == 0)
  145.                     default_system = 3;
  146.                   else if (strcmp(ptr,"Atari XE") == 0)
  147.                     default_system = 4;
  148.                   else if (strcmp(ptr,"Atari 5200") == 0)
  149.                     default_system = 5;
  150.                   else
  151.                     printf ("Invalid System: %s\n", ptr);
  152.                 }
  153.               else if (strcmp(string,"DEFAULT_TV_MODE") == 0)
  154.                 {
  155.                   if (strcmp(ptr,"PAL") == 0)
  156.                     default_tv_mode = 1;
  157.                   else if (strcmp(ptr,"NTSC") == 0)
  158.                     default_tv_mode = 2;
  159.                   else
  160.                     printf ("Invalid TV Mode: %s\n", ptr);
  161.                 }
  162.               else
  163.                 printf ("Unrecognized Variable: %s\n", string);
  164.             }
  165.           else
  166.             {
  167.               printf ("Ignored Config Line: %s\n", string);
  168.             }
  169.         }
  170.  
  171.  
  172.       fclose (fp);
  173.     }
  174.   else
  175.     {
  176.       status = FALSE;
  177.     }
  178.  
  179.   return status;
  180. }
  181.  
  182. void RtConfigSave (void)
  183. {
  184.   FILE *fp;
  185.  
  186.   fp = fopen (rtconfig_filename1, "w");
  187.   if (!fp)
  188.     {
  189.       perror (rtconfig_filename1);
  190.       exit (1);
  191.     }
  192.  
  193.   printf ("\nWriting: %s\n\n", rtconfig_filename1);
  194.  
  195.   fprintf (fp, "%s\n", ATARI_TITLE);
  196.   fprintf (fp, "OS/A_ROM=%s\n", atari_osa_filename);
  197.   fprintf (fp, "OS/B_ROM=%s\n", atari_osb_filename);
  198.   fprintf (fp, "XL/XE_ROM=%s\n", atari_xlxe_filename);
  199.   fprintf (fp, "BASIC_ROM=%s\n", atari_basic_filename);
  200.   fprintf (fp, "5200_ROM=%s\n", atari_5200_filename);
  201.   fprintf (fp, "DISK_DIR=%s\n", atari_disk_dir);
  202.   fprintf (fp, "ROM_DIR=%s\n", atari_rom_dir);
  203.   fprintf (fp, "H1_DIR=%s\n", atari_h1_dir);
  204.   fprintf (fp, "H2_DIR=%s\n", atari_h2_dir);
  205.   fprintf (fp, "H3_DIR=%s\n", atari_h3_dir);
  206.   fprintf (fp, "H4_DIR=%s\n", atari_h4_dir);
  207.   fprintf (fp, "PRINT_COMMAND=%s\n", print_command);
  208.   fprintf (fp, "SCREEN_REFRESH_RATIO=%d\n", refresh_rate);
  209.   fprintf (fp, "MAXIMAL_MISSING_FRAMES=%d\n", maxmiss);
  210.  
  211.  
  212.   fprintf (fp, "DEFAULT_SYSTEM=Atari ");
  213.   switch (default_system)
  214.     {
  215.       case 1 :
  216.         fprintf (fp, "OS/A\n");
  217.         break;
  218.       case 2 :
  219.         fprintf (fp, "OS/B\n");
  220.         break;
  221.       case 3 :
  222.         fprintf (fp, "XL\n");
  223.         break;
  224.       case 4 :
  225.         fprintf (fp, "XE\n");
  226.         break;
  227.       case 5 :
  228.         fprintf (fp, "5200\n");
  229.         break;
  230.     } 
  231.  
  232.   if (default_tv_mode == 1)
  233.     fprintf (fp,"DEFAULT_TV_MODE=PAL\n");
  234.   else
  235.     fprintf (fp,"DEFAULT_TV_MODE=NTSC\n");
  236.  
  237.   fprintf (fp,"HOLD_OPTION=%d\n", hold_option);
  238.   fprintf (fp,"ENABLE_C000_RAM=%d\n", enable_c000_ram);
  239.   fprintf (fp,"ENABLE_SIO_PATCH=%d\n", enable_sio_patch);
  240.   fprintf (fp,"ENABLE_XCOLPF1=%d\n", enable_xcolpf1);
  241.  
  242.   fclose (fp);
  243. }
  244.  
  245. void RtConfigUpdate (void)
  246. {
  247.   GetString ("Enter path to Atari OS/A ROM [%s] ", atari_osa_filename);
  248.   GetString ("Enter path to Atari OS/B ROM [%s] ", atari_osb_filename);
  249.   GetString ("Enter path to Atari XL/XE ROM [%s] ", atari_xlxe_filename);
  250.   GetString ("Enter path to Atari BASIC ROM [%s] ", atari_basic_filename);
  251.   GetString ("Enter path to Atari 5200 ROM [%s] ", atari_5200_filename);
  252.   GetString ("Enter path for disk images [%s] ", atari_disk_dir);
  253.   GetString ("Enter path for ROM images [%s] ", atari_rom_dir);
  254.   GetString ("Enter path for H1: device [%s] ", atari_h1_dir);
  255.   GetString ("Enter path for H2: device [%s] ", atari_h2_dir);
  256.   GetString ("Enter path for H3: device [%s] ", atari_h3_dir);
  257.   GetString ("Enter path for H4: device [%s] ", atari_h4_dir);
  258.   GetString ("Enter print command [%s] ", print_command);
  259.   GetNumber ("Enter default screen refresh ratio 1:[%d] ", &refresh_rate);
  260.   if (refresh_rate < 1)
  261.     refresh_rate = 1;
  262.   else if (refresh_rate > 60)
  263.     refresh_rate = 60;
  264.  
  265.   do
  266.     {
  267.       GetNumber ("Default System 1) OS/A, 2) OS/B, 3) XL, 4) XE, 5) 5200 [%d] ",
  268.                  &default_system);
  269.     } while ((default_system < 1) || (default_system > 5));
  270.  
  271.   do
  272.     {
  273.       GetNumber ("Default TV mode 1) PAL, 2) NTSC [%d] ",
  274.                  &default_tv_mode);
  275.     } while ((default_tv_mode < 1) || (default_tv_mode > 2));
  276.  
  277.   do
  278.     {
  279.       GetNumber ("Hold OPTION during Coldstart [%d] ",
  280.                  &hold_option);
  281.     } while ((hold_option < 0) || (hold_option > 1));
  282.  
  283.   do
  284.     {
  285.       GetNumber ("Enable C000-CFFF RAM in Atari800 mode [%d] ",
  286.                  &enable_c000_ram);
  287.     } while ((enable_c000_ram < 0) || (enable_c000_ram > 1));
  288.  
  289.   do
  290.     {
  291.       GetNumber ("Enable SIO PATCH (Recommended) [%d] ",
  292.                  &enable_sio_patch);
  293.     } while ((enable_sio_patch < 0) || (enable_sio_patch > 1));
  294.  
  295.   do
  296.     {
  297.       GetNumber ("Enable Extended COLPF1 [%d] ",
  298.                  &enable_xcolpf1);
  299.     } while ((enable_xcolpf1 < 0) || (enable_xcolpf1 > 1));
  300. }
  301.