|
|
1.1 root 1: /*
2: Hatari
3:
4: Configuration File
5:
1.1.1.3 root 6: The configuration file is stored in a binary format to prevent tampering.
7: We also store the version number in the file to prevent people from
8: copying old .cfg files between versions.
1.1 root 9: */
10:
11: #include "main.h"
12: #include "configuration.h"
13: #include "dialog.h"
14: #include "video.h"
15: #include "vdi.h"
1.1.1.2 root 16: #include "screen.h"
1.1.1.4 ! root 17: #include "shortcut.h"
1.1 root 18:
19: static FILE *ConfigFile;
1.1.1.4 ! root 20: BOOL bFirstTimeInstall=FALSE; /* Has been run before? Used to set default joysticks etc... */
1.1 root 21:
22:
23: /*-----------------------------------------------------------------------*/
24: /*
1.1.1.4 ! root 25: Set default configuration values.
1.1.1.2 root 26: */
27: void Configuration_SetDefault(void)
28: {
1.1.1.4 ! root 29: int i;
! 30:
! 31: /* Clear parameters */
! 32: Memory_Clear(&ConfigureParams, sizeof(DLG_PARAMS));
! 33:
! 34: /* Set defaults for CPU dialog */
! 35: ConfigureParams.Configure.nMinMaxSpeed = ConfigureParams.Configure.nPrevMinMaxSpeed = MINMAXSPEED_MIN;
! 36:
! 37: /* Set defaults for Disc Image */
! 38: ConfigureParams.DiscImage.bAutoInsertDiscB = TRUE;
! 39: strcpy(ConfigureParams.DiscImage.szDiscImageDirectory, szWorkingDir);
! 40: File_AddSlashToEndFileName(ConfigureParams.DiscImage.szDiscImageDirectory);
! 41:
! 42: /* Set defaults for Hard Disc */
! 43: ConfigureParams.HardDisc.nDriveList = DRIVELIST_NONE;
! 44: ConfigureParams.HardDisc.bBootFromHardDisc = FALSE;
! 45: ConfigureParams.HardDisc.nHardDiscDir = DRIVE_C;
! 46: for(i=0; i<MAX_HARDDRIVES; i++)
! 47: {
! 48: strcpy(ConfigureParams.HardDisc.szHardDiscDirectories[i], szWorkingDir);
! 49: File_CleanFileName(ConfigureParams.HardDisc.szHardDiscDirectories[i]);
! 50: }
! 51: strcpy(ConfigureParams.HardDisc.szHardDiscImage, szWorkingDir);
! 52:
! 53: /* Set defaults for Joysticks */
! 54: for(i=0; i<2; i++)
! 55: {
! 56: ConfigureParams.Joysticks.Joy[i].bCursorEmulation = FALSE;
! 57: ConfigureParams.Joysticks.Joy[i].bEnableAutoFire = FALSE;
! 58: }
! 59:
! 60: /* Set defaults for Keyboard */
! 61: ConfigureParams.Keyboard.bDisableKeyRepeat = TRUE;
! 62: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_KEY] = SHORTCUT_FULLSCREEN;
! 63: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_SHIFT] = SHORTCUT_NOTASSIGNED;
! 64: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_CTRL] = SHORTCUT_NOTASSIGNED;
! 65: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_KEY] = SHORTCUT_NOTASSIGNED;
! 66: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_SHIFT] = SHORTCUT_NOTASSIGNED;
! 67: ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_CTRL] = SHORTCUT_NOTASSIGNED;
! 68: strcpy(ConfigureParams.Keyboard.szMappingFileName, "");
! 69:
! 70: /* Set defaults for Memory */
! 71: ConfigureParams.Memory.nMemorySize = MEMORY_SIZE_1Mb;
! 72: strcpy(ConfigureParams.Memory.szMemoryCaptureFileName, "");
! 73:
! 74: /* Set defaults for Printer */
! 75: ConfigureParams.Printer.bEnablePrinting = FALSE;
! 76: ConfigureParams.Printer.bPrintToFile = FALSE;
! 77: strcpy(ConfigureParams.Printer.szPrintToFileName,"");
! 78:
! 79: /* Set defaults for RS232 */
! 80: ConfigureParams.RS232.bEnableRS232 = FALSE;
! 81: ConfigureParams.RS232.nCOMPort = COM_PORT_1;
! 82:
! 83: /* Set defaults for Screen */
! 84: ConfigureParams.Screen.bFullScreen = FALSE;
! 85: ConfigureParams.Screen.Advanced.bDoubleSizeWindow = FALSE;
1.1.1.2 root 86: ConfigureParams.Screen.Advanced.bAllowOverscan = TRUE;
1.1.1.4 ! root 87: ConfigureParams.Screen.Advanced.bInterlacedFullScreen = TRUE;
! 88: ConfigureParams.Screen.Advanced.bSyncToRetrace = FALSE;
! 89: ConfigureParams.Screen.Advanced.bFrameSkip = FALSE;
1.1.1.2 root 90: ConfigureParams.Screen.ChosenDisplayMode = DISPLAYMODE_HICOL_LOWRES;
1.1.1.4 ! root 91: ConfigureParams.Screen.bCaptureChange = FALSE;
! 92: ConfigureParams.Screen.nFramesPerSecond = 1;
! 93: ConfigureParams.Screen.bUseHighRes = FALSE;
! 94:
! 95: /* Set defaults for Sound */
! 96: ConfigureParams.Sound.bEnableSound = TRUE;
! 97: ConfigureParams.Sound.nPlaybackQuality = PLAYBACK_MEDIUM;
! 98: strcpy(ConfigureParams.Sound.szYMCaptureFileName, "");
! 99:
! 100: /* Set defaults for TOSGEM */
! 101: sprintf(ConfigureParams.TOSGEM.szTOSImageFileName, "%s/tos.img", DATADIR);
! 102: ConfigureParams.TOSGEM.bUseTimeDate = FALSE;
! 103: ConfigureParams.TOSGEM.bAccGEMGraphics = FALSE;
! 104: ConfigureParams.TOSGEM.bUseExtGEMResolutions = FALSE;
! 105: ConfigureParams.TOSGEM.nGEMResolution = GEMRES_640x480;
! 106: ConfigureParams.TOSGEM.nGEMColours = GEMCOLOUR_16;
! 107:
! 108: /* Set defaults for Cpu */
! 109: ConfigureParams.Cpu.level = 0;
! 110: ConfigureParams.Cpu.compatible = FALSE;
! 111: ConfigureParams.Cpu.address_space_24 = TRUE;
1.1.1.2 root 112: }
113:
114:
115: /*-----------------------------------------------------------------------*/
116: /*
1.1 root 117: Load program setting from configuration file
118: */
1.1.1.2 root 119: void Configuration_Init(void)
1.1 root 120: {
121: /*
122: char sVersionString[VERSION_STRING_SIZE];
123: int i,j;
124:
125: // Set default settings, incase registry does not exist or is invalid
126: Dialog_DefaultConfigurationDetails();
127: View_DefaultWindowPos();
128:
129: // Open configuration file
130: if (Configuration_OpenFileToRead()) {
131: // Version, check matches
132: Configuration_ReadFromFile(sVersionString,VERSION_STRING_SIZE);
133: if (memcmp(sVersionString,VERSION_STRING,VERSION_STRING_SIZE)==0) {
134: // Configure
135: Configuration_ReadFromFile(&ConfigureParams.Configure.nMinMaxSpeed,4);
136: Configuration_ReadFromFile(&WindowInitRect.left,4);
137: Configuration_ReadFromFile(&WindowInitRect.top,4);
138: for(i=0; i<2; i++) {
139: for(j=0; j<MAX_FLOPPY_MENU_IMAGES; j++) {
140: Configuration_ReadFromFile(szPreviousImageFilenames[i][j],MAX_FILENAME_LENGTH);
141: }
142: Configuration_ReadFromFile(&nPreviousImageFilenames[i],4);
143: }
144: for(i=0; i<MAX_TOSIMAGE_COMBO_IMAGES; i++)
145: Configuration_ReadFromFile(szComboTOSImages[i],MAX_FILENAME_LENGTH);
146: // Screen
147: Configuration_ReadFromFile(&ConfigureParams.Screen.bFullScreen,4);
148: Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bDoubleSizeWindow,4);
149: Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bAllowOverscan,4);
150: Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bInterlacedFullScreen,4);
151: Configuration_ReadFromFile(&ConfigureParams.Screen.Advanced.bSyncToRetrace,4);
152: Configuration_ReadFromFile(&ConfigureParams.Screen.ChosenDisplayMode,4);
153: Configuration_ReadFromFile(&ConfigureParams.Screen.bCaptureChange,4);
154: Configuration_ReadFromFile(&ConfigureParams.Screen.nFramesPerSecond,4);
155: Configuration_ReadFromFile(&ConfigureParams.Screen.bUseHighRes,4);
156: // Joysticks
157: Configuration_ReadFromFile(&ConfigureParams.Joysticks.bUseDirectInput,4);
158: Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[0].bCursorEmulation,4);
159: Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[0].bEnableAutoFire,4);
160: Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[1].bCursorEmulation,4);
161: Configuration_ReadFromFile(&ConfigureParams.Joysticks.Joy[1].bEnableAutoFire,4);
162: // Keyboard
163: Configuration_ReadFromFile(&ConfigureParams.Keyboard.bDisableKeyRepeat,4);
164: Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_SHIFT],4);
165: Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_CTRL],4);
166: Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_SHIFT],4);
167: Configuration_ReadFromFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_CTRL],4);
168: Configuration_ReadFromFile(ConfigureParams.Keyboard.szMappingFileName,sizeof(ConfigureParams.Keyboard.szMappingFileName));
169: // Sound
170: Configuration_ReadFromFile(&ConfigureParams.Sound.bEnableSound,4);
171: Configuration_ReadFromFile(&ConfigureParams.Sound.nPlaybackQuality,4);
172: Configuration_ReadFromFile(ConfigureParams.Sound.szYMCaptureFileName,sizeof(ConfigureParams.Sound.szYMCaptureFileName));
173: // Memory
174: Configuration_ReadFromFile(&ConfigureParams.Memory.nMemorySize,4);
175: Configuration_ReadFromFile(ConfigureParams.Memory.szMemoryCaptureFileName,sizeof(ConfigureParams.Memory.szMemoryCaptureFileName));
176: // DiscImage
177: Configuration_ReadFromFile(&ConfigureParams.DiscImage.bAutoInsertDiscB,4);
178: Configuration_ReadFromFile(ConfigureParams.DiscImage.szDiscImageDirectory,sizeof(ConfigureParams.DiscImage.szDiscImageDirectory));
179: // HardDisc
180: Configuration_ReadFromFile(&ConfigureParams.HardDisc.nDriveList,4);
181: Configuration_ReadFromFile(&ConfigureParams.HardDisc.bBootFromHardDisc,4);
182: Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C]));
183: Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D]));
184: Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E]));
185: Configuration_ReadFromFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F]));
186: // TOSGEM
187: Configuration_ReadFromFile(ConfigureParams.TOSGEM.szTOSImageFileName,sizeof(ConfigureParams.TOSGEM.szTOSImageFileName));
188: Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bUseTimeDate,4);
189: Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bAccGEMGraphics,4);
190: Configuration_ReadFromFile(&ConfigureParams.TOSGEM.bUseExtGEMResolutions,4);
191: Configuration_ReadFromFile(&ConfigureParams.TOSGEM.nGEMResolution,4);
192: Configuration_ReadFromFile(&ConfigureParams.TOSGEM.nGEMColours,4);
193: // RS232
194: Configuration_ReadFromFile(&ConfigureParams.RS232.bEnableRS232,4);
195: Configuration_ReadFromFile(&ConfigureParams.RS232.nCOMPort,4);
196: // Printer
197: Configuration_ReadFromFile(&ConfigureParams.Printer.bEnablePrinting,4);
198: Configuration_ReadFromFile(&ConfigureParams.Printer.bPrintToFile,4);
199: Configuration_ReadFromFile(ConfigureParams.Printer.szPrintToFileName,sizeof(ConfigureParams.Printer.szPrintToFileName));
200: // Favourites
201: Configuration_ReadFromFile(&ConfigureParams.Favourites.bCheckDiscs,4);
202: Configuration_ReadFromFile(&ConfigureParams.Favourites.bOnlyShowIfExist,4);
203:
204: bUseVDIRes = ConfigureParams.TOSGEM.bUseExtGEMResolutions;
205: bUseHighRes = ConfigureParams.Screen.bUseHighRes || (bUseVDIRes && (ConfigureParams.TOSGEM.nGEMColours==GEMCOLOUR_2));
206: }
207:
208: // And close up
209: Configuration_CloseFile();
210: }
211: else {
212: // No configuration file, assume first-time install
213: bFirstTimeInstall = TRUE;
214: }
215:
216: // Copy details to globals, TRUE
217: Dialog_CopyDetailsFromConfiguration(TRUE);
218: */
219: }
220:
221:
222: /*-----------------------------------------------------------------------*/
223: /*
224: Save program setting to configuration file
225: */
226: void Configuration_UnInit(void)
227: {
228: /* FIXME: Rewrite this, too! */
229: /*
230: int i,j;
231:
232: // Open configuration file
233: if (Configuration_OpenFileToWrite()) {
234: // Version
235: Configuration_WriteToFile(VERSION_STRING,VERSION_STRING_SIZE);
236: // Configure
237: Configuration_WriteToFile(&ConfigureParams.Configure.nMinMaxSpeed,4);
238: ConfigureParams.Configure.nPrevMinMaxSpeed = ConfigureParams.Configure.nMinMaxSpeed;
239: Configuration_WriteToFile(&WindowInitRect.left,4);
240: Configuration_WriteToFile(&WindowInitRect.top,4);
241: for(i=0; i<2; i++) {
242: for(j=0; j<MAX_FLOPPY_MENU_IMAGES; j++) {
243: Configuration_WriteToFile(szPreviousImageFilenames[i][j],MAX_FILENAME_LENGTH);
244: }
245: Configuration_WriteToFile(&nPreviousImageFilenames[i],4);
246: }
247: for(i=0; i<MAX_TOSIMAGE_COMBO_IMAGES; i++)
248: Configuration_WriteToFile(szComboTOSImages[i],MAX_FILENAME_LENGTH);
249: // Screen
250: Configuration_WriteToFile(&ConfigureParams.Screen.bFullScreen,4);
251: Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bDoubleSizeWindow,4);
252: Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bAllowOverscan,4);
253: Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bInterlacedFullScreen,4);
254: Configuration_WriteToFile(&ConfigureParams.Screen.Advanced.bSyncToRetrace,4);
255: Configuration_WriteToFile(&ConfigureParams.Screen.ChosenDisplayMode,4);
256: Configuration_WriteToFile(&ConfigureParams.Screen.bCaptureChange,4);
257: Configuration_WriteToFile(&ConfigureParams.Screen.nFramesPerSecond,4);
258: Configuration_WriteToFile(&ConfigureParams.Screen.bUseHighRes,4);
259: // Joysticks
260: Configuration_WriteToFile(&ConfigureParams.Joysticks.bUseDirectInput,4);
261: Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[0].bCursorEmulation,4);
262: Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[0].bEnableAutoFire,4);
263: Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[1].bCursorEmulation,4);
264: Configuration_WriteToFile(&ConfigureParams.Joysticks.Joy[1].bEnableAutoFire,4);
265: // Keyboard
266: Configuration_WriteToFile(&ConfigureParams.Keyboard.bDisableKeyRepeat,4);
267: Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_SHIFT],4);
268: Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F11][SHORT_CUT_CTRL],4);
269: Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_SHIFT],4);
270: Configuration_WriteToFile(&ConfigureParams.Keyboard.ShortCuts[SHORT_CUT_F12][SHORT_CUT_CTRL],4);
271: Configuration_WriteToFile(ConfigureParams.Keyboard.szMappingFileName,sizeof(ConfigureParams.Keyboard.szMappingFileName));
272: // Sound
273: Configuration_WriteToFile(&ConfigureParams.Sound.bEnableSound,4);
274: Configuration_WriteToFile(&ConfigureParams.Sound.nPlaybackQuality,4);
275: Configuration_WriteToFile(ConfigureParams.Sound.szYMCaptureFileName,sizeof(ConfigureParams.Sound.szYMCaptureFileName));
276: // Memory
277: Configuration_WriteToFile(&ConfigureParams.Memory.nMemorySize,4);
278: Configuration_WriteToFile(ConfigureParams.Memory.szMemoryCaptureFileName,sizeof(ConfigureParams.Memory.szMemoryCaptureFileName));
279: // DiscImage
280: Configuration_WriteToFile(&ConfigureParams.DiscImage.bAutoInsertDiscB,4);
281: Configuration_WriteToFile(ConfigureParams.DiscImage.szDiscImageDirectory,sizeof(ConfigureParams.DiscImage.szDiscImageDirectory));
282: // HardDisc
283: Configuration_WriteToFile(&ConfigureParams.HardDisc.nDriveList,4);
284: Configuration_WriteToFile(&ConfigureParams.HardDisc.bBootFromHardDisc,4);
285: Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_C]));
286: Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_D]));
287: Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_E]));
288: Configuration_WriteToFile(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F],sizeof(ConfigureParams.HardDisc.szHardDiscDirectories[DRIVE_F]));
289: // TOSGEM
290: Configuration_WriteToFile(ConfigureParams.TOSGEM.szTOSImageFileName,sizeof(ConfigureParams.TOSGEM.szTOSImageFileName));
291: Configuration_WriteToFile(&ConfigureParams.TOSGEM.bUseTimeDate,4);
292: Configuration_WriteToFile(&ConfigureParams.TOSGEM.bAccGEMGraphics,4);
293: Configuration_WriteToFile(&ConfigureParams.TOSGEM.bUseExtGEMResolutions,4);
294: Configuration_WriteToFile(&ConfigureParams.TOSGEM.nGEMResolution,4);
295: Configuration_WriteToFile(&ConfigureParams.TOSGEM.nGEMColours,4);
296: // RS232
297: Configuration_WriteToFile(&ConfigureParams.RS232.bEnableRS232,4);
298: Configuration_WriteToFile(&ConfigureParams.RS232.nCOMPort,4);
299: // Printer
300: Configuration_WriteToFile(&ConfigureParams.Printer.bEnablePrinting,4);
301: Configuration_WriteToFile(&ConfigureParams.Printer.bPrintToFile,4);
302: Configuration_WriteToFile(ConfigureParams.Printer.szPrintToFileName,sizeof(ConfigureParams.Printer.szPrintToFileName));
303: // Favourites
304: Configuration_WriteToFile(&ConfigureParams.Favourites.bCheckDiscs,4);
305: Configuration_WriteToFile(&ConfigureParams.Favourites.bOnlyShowIfExist,4);
306:
307: // And close up
308: Configuration_CloseFile();
309: }
310: */
311: }
312:
313:
314: /*-----------------------------------------------------------------------*/
315: /*
316: Open configuration file to write to
317: */
318: BOOL Configuration_OpenFileToWrite(void)
319: {
320: char szString[MAX_FILENAME_LENGTH];
321:
322: /* Create file */
323: sprintf(szString,"%s/hatari.cfg",szWorkingDir);
324: ConfigFile = fopen(szString, "wb");
325: if (ConfigFile!=NULL)
326: return(TRUE);
327:
328: /* Whoops, error */
329: return(FALSE);
330: }
331:
332:
333: /*-----------------------------------------------------------------------*/
334: /*
335: Open configuration file for reading
336: */
337: BOOL Configuration_OpenFileToRead(void)
338: {
339: char szString[MAX_FILENAME_LENGTH];
340:
341: /* Create file */
342: sprintf(szString,"%s/hatari.cfg",szWorkingDir);
343: ConfigFile = fopen(szString, "rb");
344: if (ConfigFile!=NULL)
345: return(TRUE);
346:
347: /* Whoops, error */
348: return(FALSE);
349: }
350:
351:
352: /*-----------------------------------------------------------------------*/
353: /*
354: Close configuration
355: */
356: void Configuration_CloseFile(void)
357: {
358: fclose(ConfigFile);
359: }
360:
361:
362: /*-----------------------------------------------------------------------*/
363: /*
364: Write entry to configuration file
365: */
366: void Configuration_WriteToFile(void *pData,int nBytes)
367: {
368: fwrite(pData, 1, nBytes, ConfigFile);
369: }
370:
371:
372: /*-----------------------------------------------------------------------*/
373: /*
374: Read entry from configuration file
375: */
376: void Configuration_ReadFromFile(void *pData,int nBytes)
377: {
378: fread(pData, 1, nBytes, ConfigFile);
379: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.