Annotation of hatari/src/configuration.c, revision 1.1.1.6

1.1       root        1: /*
1.1.1.6 ! root        2:   Hatari - configuration.c
        !             3: 
        !             4:   This file is distributed under the GNU Public License, version 2 or at
        !             5:   your option any later version. Read the file gpl.txt for details.
1.1       root        6: 
                      7:   Configuration File
                      8: 
1.1.1.6 ! root        9:   The configuration file is now stored in an ASCII format to allow the user
        !            10:   to edit the file manually.
1.1       root       11: */
1.1.1.6 ! root       12: static char rcsid[] = "Hatari $Id: configuration.c,v 1.22 2003/07/04 12:38:37 thothy Exp $";
1.1       root       13: 
                     14: #include "main.h"
                     15: #include "configuration.h"
                     16: #include "dialog.h"
                     17: #include "video.h"
                     18: #include "vdi.h"
1.1.1.2   root       19: #include "screen.h"
1.1.1.4   root       20: #include "shortcut.h"
1.1.1.5   root       21: #include "memAlloc.h"
                     22: #include "file.h"
1.1.1.6 ! root       23: #include "uae-cpu/hatari-glue.h"
        !            24: #include "intercept.h"
        !            25: #include "gemdos.h"
        !            26: #include "cfgopts.h"
        !            27: 
        !            28: 
        !            29: BOOL bFirstTimeInstall = FALSE;             /* Has been run before? Used to set default joysticks etc... */
        !            30: CNF_PARAMS ConfigureParams;                 /* List of configuration for the emulator */
        !            31: static char cfgName[MAX_FILENAME_LENGTH];   /* Stores the name of the configuration file */
        !            32: 
        !            33: 
        !            34: /* Used to load/save screen options */
        !            35: struct Config_Tag configs_Screen[] =
        !            36: {
        !            37:   { "bFullScreen", Bool_Tag, &ConfigureParams.Screen.bFullScreen },
        !            38:   { "bDoubleSizeWindow", Bool_Tag, &ConfigureParams.Screen.bDoubleSizeWindow },
        !            39:   { "bAllowOverscan", Bool_Tag, &ConfigureParams.Screen.bAllowOverscan },
        !            40:   { "bInterlacedScreen", Bool_Tag, &ConfigureParams.Screen.bInterlacedScreen },
        !            41:   /*{ "bSyncToRetrace", Bool_Tag, &ConfigureParams.Screen.bSyncToRetrace },*/
        !            42:   { "bFrameSkip", Bool_Tag, &ConfigureParams.Screen.bFrameSkip },
        !            43:   { "ChosenDisplayMode", Int_Tag, &ConfigureParams.Screen.ChosenDisplayMode },
        !            44:   { "bCaptureChange", Bool_Tag, &ConfigureParams.Screen.bCaptureChange },
        !            45:   { "nFramesPerSecond", Int_Tag, &ConfigureParams.Screen.nFramesPerSecond },
        !            46:   { "bUseHighRes", Bool_Tag, &ConfigureParams.Screen.bUseHighRes },
        !            47:   { NULL , Error_Tag, NULL }
        !            48: };
        !            49: 
        !            50: /* Used to load/save joystick options */
        !            51: struct Config_Tag configs_Joystick0[] =
        !            52: {
        !            53:   { "bCursorEmulation", Bool_Tag, &ConfigureParams.Joysticks.Joy[0].bCursorEmulation },
        !            54:   { "bEnableAutoFire", Bool_Tag, &ConfigureParams.Joysticks.Joy[0].bEnableAutoFire },
        !            55:   { NULL , Error_Tag, NULL }
        !            56: };
        !            57: struct Config_Tag configs_Joystick1[] =
        !            58: {
        !            59:   { "bCursorEmulation", Bool_Tag, &ConfigureParams.Joysticks.Joy[1].bCursorEmulation },
        !            60:   { "bEnableAutoFire", Bool_Tag, &ConfigureParams.Joysticks.Joy[1].bEnableAutoFire },
        !            61:   { NULL , Error_Tag, NULL }
        !            62: };
1.1.1.5   root       63: 
1.1.1.6 ! root       64: /* Used to load/save keyboard options */
        !            65: struct Config_Tag configs_Keyboard[] =
        !            66: {
        !            67:   { "bDisableKeyRepeat", Bool_Tag, &ConfigureParams.Keyboard.bDisableKeyRepeat },
        !            68:   { "nKeymapType", Int_Tag, &ConfigureParams.Keyboard.nKeymapType },
        !            69:   { "szMappingFileName", String_Tag, ConfigureParams.Keyboard.szMappingFileName },
        !            70:   { NULL , Error_Tag, NULL }
        !            71: };
1.1       root       72: 
1.1.1.6 ! root       73: /* Used to load/save sound options */
        !            74: struct Config_Tag configs_Sound[] =
        !            75: {
        !            76:   { "bEnableSound", Bool_Tag, &ConfigureParams.Sound.bEnableSound },
        !            77:   { "nPlaybackQuality", Int_Tag, &ConfigureParams.Sound.nPlaybackQuality },
        !            78:   { "szYMCaptureFileName", String_Tag, ConfigureParams.Sound.szYMCaptureFileName },
        !            79:   { NULL , Error_Tag, NULL }
        !            80: };
        !            81: 
        !            82: /* Used to load/save memory options */
        !            83: struct Config_Tag configs_Memory[] =
        !            84: {
        !            85:   { "nMemorySize", Int_Tag, &ConfigureParams.Memory.nMemorySize },
        !            86:   { "szMemoryCaptureFileName", String_Tag, ConfigureParams.Memory.szMemoryCaptureFileName },
        !            87:   { NULL , Error_Tag, NULL }
        !            88: };
        !            89: 
        !            90: 
        !            91: /* Used to load/save floppy options */
        !            92: struct Config_Tag configs_Floppy[] =
        !            93: {
        !            94:   { "bAutoInsertDiscB", Bool_Tag, &ConfigureParams.DiscImage.bAutoInsertDiscB },
        !            95:   { "szDiscImageDirectory", String_Tag, ConfigureParams.DiscImage.szDiscImageDirectory },
        !            96:   { NULL , Error_Tag, NULL }
        !            97: };
        !            98: 
        !            99: /* Used to load/save HD options */
        !           100: struct Config_Tag configs_HardDisc[] =
        !           101: {
        !           102:   /*{ "nDriveList", Int_Tag, &ConfigureParams.HardDisc.nDriveList },*/
        !           103:   { "bBootFromHardDisc", Bool_Tag, &ConfigureParams.HardDisc.bBootFromHardDisc },
        !           104:   { "bUseHardDiscDirectory", Bool_Tag, &ConfigureParams.HardDisc.bUseHardDiscDirectories },
        !           105:   { "szHardDiscDirectory", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C] },
        !           106:   /*{ "szHardDiscDirD", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D] },*/
        !           107:   /*{ "szHardDiscDirE", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E] },*/
        !           108:   /*{ "szHardDiscDirF", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F] },*/
        !           109:   { "bUseHardDiscImage", Bool_Tag, &ConfigureParams.HardDisc.bUseHardDiscImage },
        !           110:   { "szHardDiscImage", String_Tag, ConfigureParams.HardDisc.szHardDiscImage },
        !           111:   { NULL , Error_Tag, NULL }
        !           112: };
        !           113: 
        !           114: /* Used to load/save TOS/GEM options */
        !           115: struct Config_Tag configs_TosGem[] =
        !           116: {
        !           117:   { "szTOSImageFileName", String_Tag, ConfigureParams.TOSGEM.szTOSImageFileName },
        !           118:   { "bUseExtGEMResolutions", Bool_Tag, &ConfigureParams.TOSGEM.bUseExtGEMResolutions },
        !           119:   { "nGEMResolution", Int_Tag, &ConfigureParams.TOSGEM.nGEMResolution },
        !           120:   { "nGEMColours", Int_Tag, &ConfigureParams.TOSGEM.nGEMColours },
        !           121:   { NULL , Error_Tag, NULL }
        !           122: };
        !           123: 
        !           124: /* Used to load/save RS232 options */
        !           125: struct Config_Tag configs_Rs232[] =
        !           126: {
        !           127:   { "bEnableRS232", Bool_Tag, &ConfigureParams.RS232.bEnableRS232 },
        !           128:   { "nCOMPort", Int_Tag, &ConfigureParams.RS232.nCOMPort },
        !           129:   { NULL , Error_Tag, NULL }
        !           130: };
        !           131: 
        !           132: /* Used to load/save printer options */
        !           133: struct Config_Tag configs_Printer[] =
        !           134: {
        !           135:   { "bEnablePrinting", Bool_Tag, &ConfigureParams.Printer.bEnablePrinting },
        !           136:   { "bPrintToFile", Bool_Tag, &ConfigureParams.Printer.bPrintToFile },
        !           137:   { "szPrintToFileName", String_Tag, ConfigureParams.Printer.szPrintToFileName },
        !           138:   { NULL , Error_Tag, NULL }
        !           139: };
        !           140: 
        !           141: /* Used to load/save system options */
        !           142: struct Config_Tag configs_System[] =
        !           143: {
        !           144:   { "nMinMaxSpeed", Int_Tag, &ConfigureParams.System.nMinMaxSpeed },
        !           145:   { "nCpuLevel", Int_Tag, &ConfigureParams.System.nCpuLevel },
        !           146:   { "bCompatibleCpu", Bool_Tag, &ConfigureParams.System.bCompatibleCpu },
        !           147:   { "bBlitter", Bool_Tag, &ConfigureParams.System.bBlitter },
        !           148:   { NULL , Error_Tag, NULL }
        !           149: };
1.1       root      150: 
                    151: 
                    152: /*-----------------------------------------------------------------------*/
                    153: /*
1.1.1.4   root      154:   Set default configuration values.
1.1.1.2   root      155: */
                    156: void Configuration_SetDefault(void)
                    157: {
1.1.1.4   root      158:   int i;
1.1.1.6 ! root      159:   char *homeDir;
1.1.1.4   root      160: 
                    161:   /* Clear parameters */
1.1.1.6 ! root      162:   Memory_Clear(&ConfigureParams, sizeof(CNF_PARAMS));
1.1.1.4   root      163: 
                    164:   /* Set defaults for Disc Image */
                    165:   ConfigureParams.DiscImage.bAutoInsertDiscB = TRUE;
                    166:   strcpy(ConfigureParams.DiscImage.szDiscImageDirectory, szWorkingDir);
                    167:   File_AddSlashToEndFileName(ConfigureParams.DiscImage.szDiscImageDirectory);
                    168: 
                    169:   /* Set defaults for Hard Disc */
                    170:   ConfigureParams.HardDisc.nDriveList = DRIVELIST_NONE;
                    171:   ConfigureParams.HardDisc.bBootFromHardDisc = FALSE;
                    172:   ConfigureParams.HardDisc.nHardDiscDir = DRIVE_C;
1.1.1.6 ! root      173:   ConfigureParams.HardDisc.bUseHardDiscDirectories = FALSE;
1.1.1.4   root      174:   for(i=0; i<MAX_HARDDRIVES; i++)
                    175:   {
                    176:     strcpy(ConfigureParams.HardDisc.szHardDiscDirectories[i], szWorkingDir);
                    177:     File_CleanFileName(ConfigureParams.HardDisc.szHardDiscDirectories[i]);
                    178:   }
1.1.1.6 ! root      179:   ConfigureParams.HardDisc.bUseHardDiscImage = FALSE;
1.1.1.4   root      180:   strcpy(ConfigureParams.HardDisc.szHardDiscImage, szWorkingDir);
                    181: 
                    182:   /* Set defaults for Joysticks */
                    183:   for(i=0; i<2; i++)
                    184:   {
                    185:     ConfigureParams.Joysticks.Joy[i].bCursorEmulation = FALSE;
                    186:     ConfigureParams.Joysticks.Joy[i].bEnableAutoFire = FALSE;
                    187:   }
                    188: 
                    189:   /* Set defaults for Keyboard */
                    190:   ConfigureParams.Keyboard.bDisableKeyRepeat = TRUE;
1.1.1.6 ! root      191:   ConfigureParams.Keyboard.nKeymapType = KEYMAP_SYMBOLIC;
1.1.1.4   root      192:   strcpy(ConfigureParams.Keyboard.szMappingFileName, "");
                    193: 
                    194:   /* Set defaults for Memory */
                    195:   ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_1Mb;
                    196:   strcpy(ConfigureParams.Memory.szMemoryCaptureFileName, "");
                    197: 
                    198:   /* Set defaults for Printer */
                    199:   ConfigureParams.Printer.bEnablePrinting = FALSE;
                    200:   ConfigureParams.Printer.bPrintToFile = FALSE;
                    201:   strcpy(ConfigureParams.Printer.szPrintToFileName,"");
                    202: 
                    203:   /* Set defaults for RS232 */
                    204:   ConfigureParams.RS232.bEnableRS232 = FALSE;
1.1.1.6 ! root      205:   /*ConfigureParams.RS232.nCOMPort = COM_PORT_1;*/
1.1.1.4   root      206: 
                    207:   /* Set defaults for Screen */
                    208:   ConfigureParams.Screen.bFullScreen = FALSE;
1.1.1.6 ! root      209:   ConfigureParams.Screen.bDoubleSizeWindow = FALSE;
        !           210:   ConfigureParams.Screen.bAllowOverscan = TRUE;
        !           211:   ConfigureParams.Screen.bInterlacedScreen = FALSE;
        !           212:   ConfigureParams.Screen.bSyncToRetrace = FALSE;
        !           213:   ConfigureParams.Screen.bFrameSkip = FALSE;
1.1.1.2   root      214:   ConfigureParams.Screen.ChosenDisplayMode = DISPLAYMODE_HICOL_LOWRES;
1.1.1.4   root      215:   ConfigureParams.Screen.bCaptureChange = FALSE;
                    216:   ConfigureParams.Screen.nFramesPerSecond = 1;
                    217:   ConfigureParams.Screen.bUseHighRes = FALSE;
                    218: 
                    219:   /* Set defaults for Sound */
                    220:   ConfigureParams.Sound.bEnableSound = TRUE;
                    221:   ConfigureParams.Sound.nPlaybackQuality = PLAYBACK_MEDIUM;
                    222:   strcpy(ConfigureParams.Sound.szYMCaptureFileName, "");
                    223: 
                    224:   /* Set defaults for TOSGEM */
                    225:   sprintf(ConfigureParams.TOSGEM.szTOSImageFileName, "%s/tos.img", DATADIR);
                    226:   ConfigureParams.TOSGEM.bUseExtGEMResolutions = FALSE;
                    227:   ConfigureParams.TOSGEM.nGEMResolution = GEMRES_640x480;
                    228:   ConfigureParams.TOSGEM.nGEMColours = GEMCOLOUR_16;
                    229: 
1.1.1.5   root      230:   /* Set defaults for System */
                    231:   ConfigureParams.System.nCpuLevel = 0;
                    232:   ConfigureParams.System.bCompatibleCpu = FALSE;
                    233:   ConfigureParams.System.bAddressSpace24 = TRUE;
                    234:   ConfigureParams.System.bBlitter = FALSE;
1.1.1.6 ! root      235:   ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MIN;
        !           236: 
        !           237:   /* Initialize the configuration file name */
        !           238:   homeDir = getenv("HOME");
        !           239:   if(homeDir != NULL && homeDir[0] != 0 && strlen(homeDir) < sizeof(cfgName)-13)
        !           240:     sprintf(cfgName, "%s/.hatari.cfg", homeDir);
        !           241:   else
        !           242:     strcpy(cfgName, "hatari.cfg");
1.1.1.2   root      243: }
                    244: 
                    245: 
                    246: /*-----------------------------------------------------------------------*/
                    247: /*
1.1.1.6 ! root      248:   Load a settings section from the configuration file.
1.1       root      249: */
1.1.1.6 ! root      250: static int Configuration_LoadSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1       root      251: {
1.1.1.6 ! root      252:   int ret;
1.1       root      253: 
1.1.1.6 ! root      254:   ret = input_config(pFilename, configs, pSection);
1.1       root      255: 
1.1.1.6 ! root      256:    if(ret < 0)
        !           257:      fprintf(stderr, "Can not load configuration file %s (section %s).\n",
        !           258:              cfgName, pSection);
1.1       root      259: 
1.1.1.6 ! root      260:   return ret;
1.1       root      261: }
                    262: 
                    263: 
                    264: /*-----------------------------------------------------------------------*/
                    265: /*
1.1.1.6 ! root      266:   Load program setting from configuration file
1.1       root      267: */
1.1.1.6 ! root      268: void Configuration_Load(void)
1.1       root      269: {
1.1.1.6 ! root      270:   char sVersionString[VERSION_STRING_SIZE];
1.1       root      271:   int i,j;
                    272: 
1.1.1.6 ! root      273:   if(Configuration_LoadSection(cfgName, configs_Screen, "[Screen]") < 0)
        !           274:   {
        !           275:     /* No configuration file, assume first-time install */
        !           276:     bFirstTimeInstall = TRUE;
        !           277:     return;
1.1       root      278:   }
1.1.1.6 ! root      279:   Configuration_LoadSection(cfgName, configs_Joystick0, "[Joystick0]");
        !           280:   Configuration_LoadSection(cfgName, configs_Joystick1, "[Joystick1]");
        !           281:   Configuration_LoadSection(cfgName, configs_Keyboard, "[Keyboard]");
        !           282:   Configuration_LoadSection(cfgName, configs_Sound, "[Sound]");
        !           283:   Configuration_LoadSection(cfgName, configs_Memory, "[Memory]");
        !           284:   Configuration_LoadSection(cfgName, configs_Floppy, "[Floppy]");
        !           285:   Configuration_LoadSection(cfgName, configs_HardDisc, "[HardDisc]");
        !           286:   Configuration_LoadSection(cfgName, configs_TosGem, "[TOS-GEM]");
        !           287:   /*Configuration_LoadSection(cfgName, configs_Rs232, "[RS232]");*/
        !           288:   /*Configuration_LoadSection(cfgName, configs_Printer, "[Printer]");*/
        !           289:   Configuration_LoadSection(cfgName, configs_System, "[System]");
        !           290: 
        !           291:   /* Copy details to global variables */
        !           292:   bEnableBlitter = ConfigureParams.System.bBlitter;
        !           293:   cpu_level = ConfigureParams.System.nCpuLevel;
        !           294:   cpu_compatible = ConfigureParams.System.bCompatibleCpu;
1.1       root      295: 
1.1.1.6 ! root      296:   bUseVDIRes = ConfigureParams.TOSGEM.bUseExtGEMResolutions;
        !           297:   bUseHighRes = ConfigureParams.Screen.bUseHighRes || (bUseVDIRes && (ConfigureParams.TOSGEM.nGEMColours==GEMCOLOUR_2));
1.1       root      298: 
1.1.1.6 ! root      299:   Dialog_CopyDetailsFromConfiguration(TRUE);
1.1       root      300: }
                    301: 
                    302: 
                    303: /*-----------------------------------------------------------------------*/
                    304: /*
1.1.1.6 ! root      305:   Save a settings section to configuration file
1.1       root      306: */
1.1.1.6 ! root      307: static int Configuration_SaveSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1       root      308: {
1.1.1.6 ! root      309:   int ret;
1.1       root      310: 
1.1.1.6 ! root      311:   ret = update_config(pFilename, configs, pSection);
1.1       root      312: 
1.1.1.6 ! root      313:    if(ret < 0)
        !           314:      fprintf(stderr, "Error while updating section %s\n", pSection);
1.1       root      315: 
1.1.1.6 ! root      316:   return ret;
1.1       root      317: }
                    318: 
                    319: 
                    320: /*-----------------------------------------------------------------------*/
                    321: /*
1.1.1.6 ! root      322:   Save program setting to configuration file
1.1       root      323: */
1.1.1.6 ! root      324: void Configuration_Save(void)
1.1       root      325: {
1.1.1.6 ! root      326:   int i,j;
1.1       root      327: 
1.1.1.6 ! root      328:   if(Configuration_SaveSection(cfgName, configs_Screen, "[Screen]") < 0)
        !           329:   {
        !           330:     fprintf(stderr, "Error saving config file.\n");
        !           331:     return;
        !           332:   }
        !           333:   Configuration_SaveSection(cfgName, configs_Joystick0, "[Joystick0]");
        !           334:   Configuration_SaveSection(cfgName, configs_Joystick1, "[Joystick1]");
        !           335:   Configuration_SaveSection(cfgName, configs_Keyboard, "[Keyboard]");
        !           336:   Configuration_SaveSection(cfgName, configs_Sound, "[Sound]");
        !           337:   Configuration_SaveSection(cfgName, configs_Memory, "[Memory]");
        !           338:   Configuration_SaveSection(cfgName, configs_Floppy, "[Floppy]");
        !           339:   Configuration_SaveSection(cfgName, configs_HardDisc, "[HardDisc]");
        !           340:   Configuration_SaveSection(cfgName, configs_TosGem, "[TOS-GEM]");
        !           341:   /*Configuration_SaveSection(cfgName, configs_Rs232, "[RS232]");*/
        !           342:   /*Configuration_SaveSection(cfgName, configs_Printer, "[Printer]");*/
        !           343:   Configuration_SaveSection(cfgName, configs_System, "[System]");
1.1       root      344: }
1.1.1.6 ! root      345: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.