|
|
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.8 ! root 12: char Configuration_rcsid[] = "Hatari $Id: configuration.c,v 1.33 2004/12/05 23:30:17 thothy Exp $";
1.1 root 13:
14: #include "main.h"
15: #include "configuration.h"
1.1.1.8 ! root 16: #include "audio.h"
1.1 root 17: #include "dialog.h"
18: #include "video.h"
19: #include "vdi.h"
1.1.1.2 root 20: #include "screen.h"
1.1.1.4 root 21: #include "shortcut.h"
1.1.1.5 root 22: #include "memAlloc.h"
23: #include "file.h"
1.1.1.6 root 24: #include "uae-cpu/hatari-glue.h"
25: #include "intercept.h"
26: #include "gemdos.h"
27: #include "cfgopts.h"
28:
29:
30: BOOL bFirstTimeInstall = FALSE; /* Has been run before? Used to set default joysticks etc... */
31: CNF_PARAMS ConfigureParams; /* List of configuration for the emulator */
1.1.1.7 root 32: char sConfigFileName[FILENAME_MAX]; /* Stores the name of the configuration file */
1.1.1.6 root 33:
34:
35: /* Used to load/save screen options */
36: struct Config_Tag configs_Screen[] =
37: {
38: { "bFullScreen", Bool_Tag, &ConfigureParams.Screen.bFullScreen },
39: { "bFrameSkip", Bool_Tag, &ConfigureParams.Screen.bFrameSkip },
1.1.1.8 ! root 40: { "bAllowOverscan", Bool_Tag, &ConfigureParams.Screen.bAllowOverscan },
! 41: { "bInterleavedScreen", Bool_Tag, &ConfigureParams.Screen.bInterleavedScreen },
1.1.1.6 root 42: { "ChosenDisplayMode", Int_Tag, &ConfigureParams.Screen.ChosenDisplayMode },
1.1.1.8 ! root 43: { "bUseHighRes", Bool_Tag, &ConfigureParams.Screen.bUseHighRes },
! 44: { "bUseExtVdiResolutions", Bool_Tag, &ConfigureParams.Screen.bUseExtVdiResolutions },
! 45: { "nVdiResolution", Int_Tag, &ConfigureParams.Screen.nVdiResolution },
! 46: { "nVdiColors", Int_Tag, &ConfigureParams.Screen.nVdiColors },
1.1.1.6 root 47: { "bCaptureChange", Bool_Tag, &ConfigureParams.Screen.bCaptureChange },
48: { "nFramesPerSecond", Int_Tag, &ConfigureParams.Screen.nFramesPerSecond },
49: { NULL , Error_Tag, NULL }
50: };
51:
52: /* Used to load/save joystick options */
53: struct Config_Tag configs_Joystick0[] =
54: {
55: { "bCursorEmulation", Bool_Tag, &ConfigureParams.Joysticks.Joy[0].bCursorEmulation },
56: { "bEnableAutoFire", Bool_Tag, &ConfigureParams.Joysticks.Joy[0].bEnableAutoFire },
57: { NULL , Error_Tag, NULL }
58: };
59: struct Config_Tag configs_Joystick1[] =
60: {
61: { "bCursorEmulation", Bool_Tag, &ConfigureParams.Joysticks.Joy[1].bCursorEmulation },
62: { "bEnableAutoFire", Bool_Tag, &ConfigureParams.Joysticks.Joy[1].bEnableAutoFire },
63: { NULL , Error_Tag, NULL }
64: };
1.1.1.5 root 65:
1.1.1.6 root 66: /* Used to load/save keyboard options */
67: struct Config_Tag configs_Keyboard[] =
68: {
69: { "bDisableKeyRepeat", Bool_Tag, &ConfigureParams.Keyboard.bDisableKeyRepeat },
70: { "nKeymapType", Int_Tag, &ConfigureParams.Keyboard.nKeymapType },
71: { "szMappingFileName", String_Tag, ConfigureParams.Keyboard.szMappingFileName },
72: { NULL , Error_Tag, NULL }
73: };
1.1 root 74:
1.1.1.6 root 75: /* Used to load/save sound options */
76: struct Config_Tag configs_Sound[] =
77: {
78: { "bEnableSound", Bool_Tag, &ConfigureParams.Sound.bEnableSound },
79: { "nPlaybackQuality", Int_Tag, &ConfigureParams.Sound.nPlaybackQuality },
80: { "szYMCaptureFileName", String_Tag, ConfigureParams.Sound.szYMCaptureFileName },
81: { NULL , Error_Tag, NULL }
82: };
83:
84: /* Used to load/save memory options */
85: struct Config_Tag configs_Memory[] =
86: {
87: { "nMemorySize", Int_Tag, &ConfigureParams.Memory.nMemorySize },
88: { "szMemoryCaptureFileName", String_Tag, ConfigureParams.Memory.szMemoryCaptureFileName },
89: { NULL , Error_Tag, NULL }
90: };
91:
92:
93: /* Used to load/save floppy options */
94: struct Config_Tag configs_Floppy[] =
95: {
96: { "bAutoInsertDiscB", Bool_Tag, &ConfigureParams.DiscImage.bAutoInsertDiscB },
97: { "szDiscImageDirectory", String_Tag, ConfigureParams.DiscImage.szDiscImageDirectory },
98: { NULL , Error_Tag, NULL }
99: };
100:
101: /* Used to load/save HD options */
102: struct Config_Tag configs_HardDisc[] =
103: {
104: /*{ "nDriveList", Int_Tag, &ConfigureParams.HardDisc.nDriveList },*/
105: { "bBootFromHardDisc", Bool_Tag, &ConfigureParams.HardDisc.bBootFromHardDisc },
106: { "bUseHardDiscDirectory", Bool_Tag, &ConfigureParams.HardDisc.bUseHardDiscDirectories },
107: { "szHardDiscDirectory", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C] },
108: /*{ "szHardDiscDirD", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D] },*/
109: /*{ "szHardDiscDirE", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E] },*/
110: /*{ "szHardDiscDirF", String_Tag, ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F] },*/
111: { "bUseHardDiscImage", Bool_Tag, &ConfigureParams.HardDisc.bUseHardDiscImage },
112: { "szHardDiscImage", String_Tag, ConfigureParams.HardDisc.szHardDiscImage },
113: { NULL , Error_Tag, NULL }
114: };
115:
1.1.1.8 ! root 116: /* Used to load/save ROM options */
! 117: struct Config_Tag configs_Rom[] =
1.1.1.6 root 118: {
1.1.1.8 ! root 119: { "szTosImageFileName", String_Tag, ConfigureParams.Rom.szTosImageFileName },
! 120: { "szCartridgeImageFileName", String_Tag, ConfigureParams.Rom.szCartridgeImageFileName },
1.1.1.6 root 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 },
1.1.1.7 root 128: { "szOutFileName", String_Tag, ConfigureParams.RS232.szOutFileName },
129: { "szInFileName", String_Tag, ConfigureParams.RS232.szInFileName },
1.1.1.6 root 130: { NULL , Error_Tag, NULL }
131: };
132:
133: /* Used to load/save printer options */
134: struct Config_Tag configs_Printer[] =
135: {
136: { "bEnablePrinting", Bool_Tag, &ConfigureParams.Printer.bEnablePrinting },
137: { "bPrintToFile", Bool_Tag, &ConfigureParams.Printer.bPrintToFile },
138: { "szPrintToFileName", String_Tag, ConfigureParams.Printer.szPrintToFileName },
139: { NULL , Error_Tag, NULL }
140: };
141:
1.1.1.7 root 142: /* Used to load/save MIDI options */
143: struct Config_Tag configs_Midi[] =
144: {
145: { "bEnableMidi", Bool_Tag, &ConfigureParams.Midi.bEnableMidi },
146: { "szMidiOutFileName", String_Tag, ConfigureParams.Midi.szMidiOutFileName },
147: { NULL , Error_Tag, NULL }
148: };
149:
1.1.1.6 root 150: /* Used to load/save system options */
151: struct Config_Tag configs_System[] =
152: {
153: { "nMinMaxSpeed", Int_Tag, &ConfigureParams.System.nMinMaxSpeed },
154: { "nCpuLevel", Int_Tag, &ConfigureParams.System.nCpuLevel },
155: { "bCompatibleCpu", Bool_Tag, &ConfigureParams.System.bCompatibleCpu },
156: { "bBlitter", Bool_Tag, &ConfigureParams.System.bBlitter },
1.1.1.7 root 157: { "bPatchTimerD", Bool_Tag, &ConfigureParams.System.bPatchTimerD },
1.1.1.6 root 158: { NULL , Error_Tag, NULL }
159: };
1.1 root 160:
161:
162: /*-----------------------------------------------------------------------*/
163: /*
1.1.1.4 root 164: Set default configuration values.
1.1.1.2 root 165: */
166: void Configuration_SetDefault(void)
167: {
1.1.1.4 root 168: int i;
1.1.1.6 root 169: char *homeDir;
1.1.1.4 root 170:
171: /* Clear parameters */
1.1.1.6 root 172: Memory_Clear(&ConfigureParams, sizeof(CNF_PARAMS));
1.1.1.4 root 173:
174: /* Set defaults for Disc Image */
175: ConfigureParams.DiscImage.bAutoInsertDiscB = TRUE;
176: strcpy(ConfigureParams.DiscImage.szDiscImageDirectory, szWorkingDir);
177: File_AddSlashToEndFileName(ConfigureParams.DiscImage.szDiscImageDirectory);
178:
179: /* Set defaults for Hard Disc */
180: ConfigureParams.HardDisc.nDriveList = DRIVELIST_NONE;
181: ConfigureParams.HardDisc.bBootFromHardDisc = FALSE;
182: ConfigureParams.HardDisc.nHardDiscDir = DRIVE_C;
1.1.1.6 root 183: ConfigureParams.HardDisc.bUseHardDiscDirectories = FALSE;
1.1.1.4 root 184: for(i=0; i<MAX_HARDDRIVES; i++)
185: {
186: strcpy(ConfigureParams.HardDisc.szHardDiscDirectories[i], szWorkingDir);
187: File_CleanFileName(ConfigureParams.HardDisc.szHardDiscDirectories[i]);
188: }
1.1.1.6 root 189: ConfigureParams.HardDisc.bUseHardDiscImage = FALSE;
1.1.1.4 root 190: strcpy(ConfigureParams.HardDisc.szHardDiscImage, szWorkingDir);
191:
192: /* Set defaults for Joysticks */
193: for(i=0; i<2; i++)
194: {
195: ConfigureParams.Joysticks.Joy[i].bCursorEmulation = FALSE;
196: ConfigureParams.Joysticks.Joy[i].bEnableAutoFire = FALSE;
197: }
198:
199: /* Set defaults for Keyboard */
200: ConfigureParams.Keyboard.bDisableKeyRepeat = TRUE;
1.1.1.6 root 201: ConfigureParams.Keyboard.nKeymapType = KEYMAP_SYMBOLIC;
1.1.1.4 root 202: strcpy(ConfigureParams.Keyboard.szMappingFileName, "");
203:
204: /* Set defaults for Memory */
205: ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_1Mb;
1.1.1.7 root 206: sprintf(ConfigureParams.Memory.szMemoryCaptureFileName, "%s/hatari.sav", szWorkingDir);
1.1.1.4 root 207:
208: /* Set defaults for Printer */
209: ConfigureParams.Printer.bEnablePrinting = FALSE;
1.1.1.7 root 210: ConfigureParams.Printer.bPrintToFile = TRUE;
211: sprintf(ConfigureParams.Printer.szPrintToFileName, "%s/hatari.prn", szWorkingDir);
1.1.1.4 root 212:
213: /* Set defaults for RS232 */
214: ConfigureParams.RS232.bEnableRS232 = FALSE;
1.1.1.7 root 215: strcpy(ConfigureParams.RS232.szOutFileName, "/dev/modem");
216: strcpy(ConfigureParams.RS232.szInFileName, "/dev/modem");
217:
218: /* Set defaults for MIDI */
219: ConfigureParams.Midi.bEnableMidi = FALSE;
220: strcpy(ConfigureParams.Midi.szMidiOutFileName, "/dev/midi00");
1.1.1.4 root 221:
222: /* Set defaults for Screen */
223: ConfigureParams.Screen.bFullScreen = FALSE;
1.1.1.6 root 224: ConfigureParams.Screen.bFrameSkip = FALSE;
1.1.1.8 ! root 225: ConfigureParams.Screen.bAllowOverscan = TRUE;
! 226: ConfigureParams.Screen.bInterleavedScreen = FALSE;
1.1.1.2 root 227: ConfigureParams.Screen.ChosenDisplayMode = DISPLAYMODE_HICOL_LOWRES;
1.1.1.8 ! root 228: ConfigureParams.Screen.bUseHighRes = FALSE;
! 229: ConfigureParams.Screen.bUseExtVdiResolutions = FALSE;
! 230: ConfigureParams.Screen.nVdiResolution = GEMRES_640x480;
! 231: ConfigureParams.Screen.nVdiColors = GEMCOLOUR_16;
1.1.1.4 root 232: ConfigureParams.Screen.bCaptureChange = FALSE;
1.1.1.7 root 233: ConfigureParams.Screen.nFramesPerSecond = 25;
1.1.1.4 root 234:
235: /* Set defaults for Sound */
236: ConfigureParams.Sound.bEnableSound = TRUE;
237: ConfigureParams.Sound.nPlaybackQuality = PLAYBACK_MEDIUM;
1.1.1.7 root 238: sprintf(ConfigureParams.Sound.szYMCaptureFileName, "%s/hatari.wav", szWorkingDir);
1.1.1.4 root 239:
1.1.1.8 ! root 240: /* Set defaults for Rom */
! 241: sprintf(ConfigureParams.Rom.szTosImageFileName, "%s/tos.img", DATADIR);
! 242: strcpy(ConfigureParams.Rom.szCartridgeImageFileName, "");
1.1.1.4 root 243:
1.1.1.5 root 244: /* Set defaults for System */
245: ConfigureParams.System.nCpuLevel = 0;
246: ConfigureParams.System.bCompatibleCpu = FALSE;
247: ConfigureParams.System.bAddressSpace24 = TRUE;
248: ConfigureParams.System.bBlitter = FALSE;
1.1.1.7 root 249: ConfigureParams.System.bPatchTimerD = TRUE;
1.1.1.6 root 250: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MIN;
251:
252: /* Initialize the configuration file name */
253: homeDir = getenv("HOME");
1.1.1.7 root 254: if(homeDir != NULL && homeDir[0] != 0 && strlen(homeDir) < sizeof(sConfigFileName)-13)
255: sprintf(sConfigFileName, "%s/.hatari.cfg", homeDir);
1.1.1.6 root 256: else
1.1.1.7 root 257: strcpy(sConfigFileName, "hatari.cfg");
1.1.1.2 root 258: }
259:
260:
261: /*-----------------------------------------------------------------------*/
262: /*
1.1.1.8 ! root 263: Copy details from configuration structure into global variables for system,
! 264: clean file names, etc...
! 265: */
! 266: void Configuration_WorkOnDetails(BOOL bReset)
! 267: {
! 268: /* Set resolution change */
! 269: if (bReset)
! 270: {
! 271: bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions;
! 272: bUseHighRes = (!bUseVDIRes && ConfigureParams.Screen.bUseHighRes)
! 273: || (bUseVDIRes && ConfigureParams.Screen.nVdiColors==GEMCOLOUR_2);
! 274: VDI_SetResolution(ConfigureParams.Screen.nVdiResolution, ConfigureParams.Screen.nVdiColors);
! 275: }
! 276:
! 277: /* Set playback frequency */
! 278: if (ConfigureParams.Sound.bEnableSound)
! 279: Audio_SetOutputAudioFreq(ConfigureParams.Sound.nPlaybackQuality);
! 280:
! 281: /* Remove slashes, etc.. from names */
! 282: File_CleanFileName(ConfigureParams.Rom.szTosImageFileName);
! 283: }
! 284:
! 285:
! 286: /*-----------------------------------------------------------------------*/
! 287: /*
1.1.1.6 root 288: Load a settings section from the configuration file.
1.1 root 289: */
1.1.1.6 root 290: static int Configuration_LoadSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1 root 291: {
1.1.1.6 root 292: int ret;
1.1 root 293:
1.1.1.6 root 294: ret = input_config(pFilename, configs, pSection);
1.1 root 295:
1.1.1.6 root 296: if(ret < 0)
297: fprintf(stderr, "Can not load configuration file %s (section %s).\n",
1.1.1.7 root 298: sConfigFileName, pSection);
1.1 root 299:
1.1.1.6 root 300: return ret;
1.1 root 301: }
302:
303:
304: /*-----------------------------------------------------------------------*/
305: /*
1.1.1.6 root 306: Load program setting from configuration file
1.1 root 307: */
1.1.1.6 root 308: void Configuration_Load(void)
1.1 root 309: {
1.1.1.7 root 310: if (!File_Exists(sConfigFileName))
1.1.1.6 root 311: {
312: /* No configuration file, assume first-time install */
313: bFirstTimeInstall = TRUE;
1.1.1.7 root 314: fprintf(stderr, "Configuration file %s not found.\n", sConfigFileName);
1.1.1.6 root 315: return;
1.1 root 316: }
1.1.1.7 root 317:
318: bFirstTimeInstall = FALSE;
319:
320: Configuration_LoadSection(sConfigFileName, configs_Screen, "[Screen]");
321: Configuration_LoadSection(sConfigFileName, configs_Joystick0, "[Joystick0]");
322: Configuration_LoadSection(sConfigFileName, configs_Joystick1, "[Joystick1]");
323: Configuration_LoadSection(sConfigFileName, configs_Keyboard, "[Keyboard]");
324: Configuration_LoadSection(sConfigFileName, configs_Sound, "[Sound]");
325: Configuration_LoadSection(sConfigFileName, configs_Memory, "[Memory]");
326: Configuration_LoadSection(sConfigFileName, configs_Floppy, "[Floppy]");
327: Configuration_LoadSection(sConfigFileName, configs_HardDisc, "[HardDisc]");
1.1.1.8 ! root 328: Configuration_LoadSection(sConfigFileName, configs_Rom, "[ROM]");
1.1.1.7 root 329: Configuration_LoadSection(sConfigFileName, configs_Rs232, "[RS232]");
330: Configuration_LoadSection(sConfigFileName, configs_Printer, "[Printer]");
331: Configuration_LoadSection(sConfigFileName, configs_Midi, "[Midi]");
332: Configuration_LoadSection(sConfigFileName, configs_System, "[System]");
1.1.1.6 root 333:
334: /* Copy details to global variables */
335: bEnableBlitter = ConfigureParams.System.bBlitter;
336: cpu_level = ConfigureParams.System.nCpuLevel;
337: cpu_compatible = ConfigureParams.System.bCompatibleCpu;
1.1 root 338:
1.1.1.8 ! root 339: Configuration_WorkOnDetails(TRUE);
1.1 root 340: }
341:
342:
343: /*-----------------------------------------------------------------------*/
344: /*
1.1.1.6 root 345: Save a settings section to configuration file
1.1 root 346: */
1.1.1.6 root 347: static int Configuration_SaveSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1 root 348: {
1.1.1.6 root 349: int ret;
1.1 root 350:
1.1.1.6 root 351: ret = update_config(pFilename, configs, pSection);
1.1 root 352:
1.1.1.6 root 353: if(ret < 0)
354: fprintf(stderr, "Error while updating section %s\n", pSection);
1.1 root 355:
1.1.1.6 root 356: return ret;
1.1 root 357: }
358:
359:
360: /*-----------------------------------------------------------------------*/
361: /*
1.1.1.6 root 362: Save program setting to configuration file
1.1 root 363: */
1.1.1.6 root 364: void Configuration_Save(void)
1.1 root 365: {
1.1.1.7 root 366: if(Configuration_SaveSection(sConfigFileName, configs_Screen, "[Screen]") < 0)
1.1.1.6 root 367: {
368: fprintf(stderr, "Error saving config file.\n");
369: return;
370: }
1.1.1.7 root 371: Configuration_SaveSection(sConfigFileName, configs_Joystick0, "[Joystick0]");
372: Configuration_SaveSection(sConfigFileName, configs_Joystick1, "[Joystick1]");
373: Configuration_SaveSection(sConfigFileName, configs_Keyboard, "[Keyboard]");
374: Configuration_SaveSection(sConfigFileName, configs_Sound, "[Sound]");
375: Configuration_SaveSection(sConfigFileName, configs_Memory, "[Memory]");
376: Configuration_SaveSection(sConfigFileName, configs_Floppy, "[Floppy]");
377: Configuration_SaveSection(sConfigFileName, configs_HardDisc, "[HardDisc]");
1.1.1.8 ! root 378: Configuration_SaveSection(sConfigFileName, configs_Rom, "[ROM]");
1.1.1.7 root 379: Configuration_SaveSection(sConfigFileName, configs_Rs232, "[RS232]");
380: Configuration_SaveSection(sConfigFileName, configs_Printer, "[Printer]");
381: Configuration_SaveSection(sConfigFileName, configs_Midi, "[Midi]");
382: Configuration_SaveSection(sConfigFileName, configs_System, "[System]");
1.1 root 383: }
1.1.1.6 root 384:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.