home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / rt-config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  7.6 KB  |  276 lines

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