|
|
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.7 ! root 12: char Configuration_rcsid[] = "Hatari $Id: configuration.c,v 1.30 2004/07/05 20:06:20 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 */
1.1.1.7 ! root 31: char sConfigFileName[FILENAME_MAX]; /* Stores the name of the configuration file */
1.1.1.6 root 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 },
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.bDoubleSizeWindow = FALSE;
225: ConfigureParams.Screen.bAllowOverscan = TRUE;
226: ConfigureParams.Screen.bInterlacedScreen = FALSE;
227: ConfigureParams.Screen.bSyncToRetrace = FALSE;
228: ConfigureParams.Screen.bFrameSkip = FALSE;
1.1.1.2 root 229: ConfigureParams.Screen.ChosenDisplayMode = DISPLAYMODE_HICOL_LOWRES;
1.1.1.4 root 230: ConfigureParams.Screen.bCaptureChange = FALSE;
1.1.1.7 ! root 231: ConfigureParams.Screen.nFramesPerSecond = 25;
1.1.1.4 root 232: ConfigureParams.Screen.bUseHighRes = FALSE;
233:
234: /* Set defaults for Sound */
235: ConfigureParams.Sound.bEnableSound = TRUE;
236: ConfigureParams.Sound.nPlaybackQuality = PLAYBACK_MEDIUM;
1.1.1.7 ! root 237: sprintf(ConfigureParams.Sound.szYMCaptureFileName, "%s/hatari.wav", szWorkingDir);
1.1.1.4 root 238:
239: /* Set defaults for TOSGEM */
240: sprintf(ConfigureParams.TOSGEM.szTOSImageFileName, "%s/tos.img", DATADIR);
241: ConfigureParams.TOSGEM.bUseExtGEMResolutions = FALSE;
242: ConfigureParams.TOSGEM.nGEMResolution = GEMRES_640x480;
243: ConfigureParams.TOSGEM.nGEMColours = GEMCOLOUR_16;
244:
1.1.1.5 root 245: /* Set defaults for System */
246: ConfigureParams.System.nCpuLevel = 0;
247: ConfigureParams.System.bCompatibleCpu = FALSE;
248: ConfigureParams.System.bAddressSpace24 = TRUE;
249: ConfigureParams.System.bBlitter = FALSE;
1.1.1.7 ! root 250: ConfigureParams.System.bPatchTimerD = TRUE;
1.1.1.6 root 251: ConfigureParams.System.nMinMaxSpeed = MINMAXSPEED_MIN;
252:
253: /* Initialize the configuration file name */
254: homeDir = getenv("HOME");
1.1.1.7 ! root 255: if(homeDir != NULL && homeDir[0] != 0 && strlen(homeDir) < sizeof(sConfigFileName)-13)
! 256: sprintf(sConfigFileName, "%s/.hatari.cfg", homeDir);
1.1.1.6 root 257: else
1.1.1.7 ! root 258: strcpy(sConfigFileName, "hatari.cfg");
1.1.1.2 root 259: }
260:
261:
262: /*-----------------------------------------------------------------------*/
263: /*
1.1.1.6 root 264: Load a settings section from the configuration file.
1.1 root 265: */
1.1.1.6 root 266: static int Configuration_LoadSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1 root 267: {
1.1.1.6 root 268: int ret;
1.1 root 269:
1.1.1.6 root 270: ret = input_config(pFilename, configs, pSection);
1.1 root 271:
1.1.1.6 root 272: if(ret < 0)
273: fprintf(stderr, "Can not load configuration file %s (section %s).\n",
1.1.1.7 ! root 274: sConfigFileName, pSection);
1.1 root 275:
1.1.1.6 root 276: return ret;
1.1 root 277: }
278:
279:
280: /*-----------------------------------------------------------------------*/
281: /*
1.1.1.6 root 282: Load program setting from configuration file
1.1 root 283: */
1.1.1.6 root 284: void Configuration_Load(void)
1.1 root 285: {
1.1.1.7 ! root 286: if (!File_Exists(sConfigFileName))
1.1.1.6 root 287: {
288: /* No configuration file, assume first-time install */
289: bFirstTimeInstall = TRUE;
1.1.1.7 ! root 290: fprintf(stderr, "Configuration file %s not found.\n", sConfigFileName);
1.1.1.6 root 291: return;
1.1 root 292: }
1.1.1.7 ! root 293:
! 294: bFirstTimeInstall = FALSE;
! 295:
! 296: Configuration_LoadSection(sConfigFileName, configs_Screen, "[Screen]");
! 297: Configuration_LoadSection(sConfigFileName, configs_Joystick0, "[Joystick0]");
! 298: Configuration_LoadSection(sConfigFileName, configs_Joystick1, "[Joystick1]");
! 299: Configuration_LoadSection(sConfigFileName, configs_Keyboard, "[Keyboard]");
! 300: Configuration_LoadSection(sConfigFileName, configs_Sound, "[Sound]");
! 301: Configuration_LoadSection(sConfigFileName, configs_Memory, "[Memory]");
! 302: Configuration_LoadSection(sConfigFileName, configs_Floppy, "[Floppy]");
! 303: Configuration_LoadSection(sConfigFileName, configs_HardDisc, "[HardDisc]");
! 304: Configuration_LoadSection(sConfigFileName, configs_TosGem, "[TOS-GEM]");
! 305: Configuration_LoadSection(sConfigFileName, configs_Rs232, "[RS232]");
! 306: Configuration_LoadSection(sConfigFileName, configs_Printer, "[Printer]");
! 307: Configuration_LoadSection(sConfigFileName, configs_Midi, "[Midi]");
! 308: Configuration_LoadSection(sConfigFileName, configs_System, "[System]");
1.1.1.6 root 309:
310: /* Copy details to global variables */
311: bEnableBlitter = ConfigureParams.System.bBlitter;
312: cpu_level = ConfigureParams.System.nCpuLevel;
313: cpu_compatible = ConfigureParams.System.bCompatibleCpu;
1.1 root 314:
1.1.1.6 root 315: bUseVDIRes = ConfigureParams.TOSGEM.bUseExtGEMResolutions;
316: bUseHighRes = ConfigureParams.Screen.bUseHighRes || (bUseVDIRes && (ConfigureParams.TOSGEM.nGEMColours==GEMCOLOUR_2));
1.1 root 317:
1.1.1.6 root 318: Dialog_CopyDetailsFromConfiguration(TRUE);
1.1 root 319: }
320:
321:
322: /*-----------------------------------------------------------------------*/
323: /*
1.1.1.6 root 324: Save a settings section to configuration file
1.1 root 325: */
1.1.1.6 root 326: static int Configuration_SaveSection(const char *pFilename, struct Config_Tag configs[], char *pSection)
1.1 root 327: {
1.1.1.6 root 328: int ret;
1.1 root 329:
1.1.1.6 root 330: ret = update_config(pFilename, configs, pSection);
1.1 root 331:
1.1.1.6 root 332: if(ret < 0)
333: fprintf(stderr, "Error while updating section %s\n", pSection);
1.1 root 334:
1.1.1.6 root 335: return ret;
1.1 root 336: }
337:
338:
339: /*-----------------------------------------------------------------------*/
340: /*
1.1.1.6 root 341: Save program setting to configuration file
1.1 root 342: */
1.1.1.6 root 343: void Configuration_Save(void)
1.1 root 344: {
1.1.1.7 ! root 345: if(Configuration_SaveSection(sConfigFileName, configs_Screen, "[Screen]") < 0)
1.1.1.6 root 346: {
347: fprintf(stderr, "Error saving config file.\n");
348: return;
349: }
1.1.1.7 ! root 350: Configuration_SaveSection(sConfigFileName, configs_Joystick0, "[Joystick0]");
! 351: Configuration_SaveSection(sConfigFileName, configs_Joystick1, "[Joystick1]");
! 352: Configuration_SaveSection(sConfigFileName, configs_Keyboard, "[Keyboard]");
! 353: Configuration_SaveSection(sConfigFileName, configs_Sound, "[Sound]");
! 354: Configuration_SaveSection(sConfigFileName, configs_Memory, "[Memory]");
! 355: Configuration_SaveSection(sConfigFileName, configs_Floppy, "[Floppy]");
! 356: Configuration_SaveSection(sConfigFileName, configs_HardDisc, "[HardDisc]");
! 357: Configuration_SaveSection(sConfigFileName, configs_TosGem, "[TOS-GEM]");
! 358: Configuration_SaveSection(sConfigFileName, configs_Rs232, "[RS232]");
! 359: Configuration_SaveSection(sConfigFileName, configs_Printer, "[Printer]");
! 360: Configuration_SaveSection(sConfigFileName, configs_Midi, "[Midi]");
! 361: Configuration_SaveSection(sConfigFileName, configs_System, "[System]");
1.1 root 362: }
1.1.1.6 root 363:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.