|
|
1.1 root 1: /*
2: Hatari - change.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.
6:
7: This code handles run-time configuration changes. We keep all our
8: configuration details in a structure called 'ConfigureParams'. Before
9: doing he changes, a backup copy is done of this structure. When
10: the changes are done, these are compared to see whether emulator
11: needs to be rebooted
12: */
13: const char Change_fileid[] = "Hatari change.c : " __DATE__ " " __TIME__;
14:
15: #include <ctype.h>
16: #include "main.h"
17: #include "configuration.h"
18: #include "change.h"
19: #include "dialog.h"
20: #include "ioMem.h"
21: #include "m68000.h"
22: #include "options.h"
23: #include "reset.h"
24: #include "screen.h"
25: #include "statusbar.h"
26: #include "video.h"
27: #include "hatari-glue.h"
1.1.1.3 ! root 28: #include "scsi.h"
1.1 root 29:
1.1.1.3 ! root 30: #define DEBUG 1
1.1.1.2 root 31: #if DEBUG
32: #define Dprintf(a) printf(a)
33: #else
34: #define Dprintf(a)
35: #endif
1.1 root 36:
37: /*-----------------------------------------------------------------------*/
38: /**
39: * Check if user needs to be warned that changes will take place after reset.
40: * Return true if wants to reset.
41: */
42: bool Change_DoNeedReset(CNF_PARAMS *current, CNF_PARAMS *changed)
43: {
1.1.1.3 ! root 44: /* Did we change ROM file? */
! 45: if (current->System.nMachineType == NEXT_CUBE030 && strcmp(current->Rom.szRom030FileName, changed->Rom.szRom030FileName)) {
! 46: printf("rom030 reset\n");
! 47: return true;
! 48: }
! 49: if (current->System.nMachineType == NEXT_CUBE040 || current->System.nMachineType == NEXT_STATION) {
! 50: if (!current->System.bTurbo && strcmp(current->Rom.szRom040FileName, changed->Rom.szRom040FileName)) {
! 51: printf("rom040 reset\n");
! 52: return true;
! 53: }
! 54: if (current->System.bTurbo && strcmp(current->Rom.szRomTurboFileName, changed->Rom.szRomTurboFileName)) {
! 55: printf("romturbo reset\n");
! 56: return true;
! 57: }
! 58: }
! 59:
! 60: /* Did we change machine type? */
! 61: if (current->System.nMachineType != changed->System.nMachineType) {
! 62: printf("machine type reset\n");
! 63: return true;
! 64: }
! 65: if (current->System.bColor != changed->System.bColor) {
! 66: printf("machine type reset (color)\n");
! 67: return true;
! 68: }
! 69: if (current->System.bTurbo != changed->System.bTurbo) {
! 70: printf("machine type reset (turbo)\n");
! 71: return true;
! 72: }
! 73:
! 74: /* Did we change CPU type? */
! 75: if (current->System.nCpuLevel != changed->System.nCpuLevel) {
! 76: printf("cpu type reset\n");
! 77: return true;
! 78: }
! 79:
! 80: /* Did we change FPU type? */
! 81: if (current->System.n_FPUType != changed->System.n_FPUType) {
! 82: printf("fpu type reset\n");
! 83: return true;
! 84: }
! 85:
! 86: /* Did we change SCSI controller? */
! 87: if (current->System.nSCSI != changed->System.nSCSI) {
! 88: printf("scsi controller reset\n");
! 89: return true;
! 90: }
! 91:
! 92: /* Did we change RTC chip? */
! 93: if (current->System.nRTC != changed->System.nRTC) {
! 94: printf("rtc chip reset\n");
! 95: return true;
! 96: }
! 97:
! 98: /* Did we change ADB emulation? */
! 99: if (current->System.bADB != changed->System.bADB) {
! 100: printf("adb reset\n");
! 101: return true;
! 102: }
! 103:
! 104: /* Did we change memory size? */
! 105: int i;
! 106: for (i = 0; i < 4; i++) {
! 107: if (current->Memory.nMemoryBankSize[i] != changed->Memory.nMemoryBankSize[i]) {
! 108: printf("memory size reset\n");
! 109: return true;
! 110: }
! 111: }
! 112:
! 113: /* Did we change boot options? */
! 114: if (current->Boot.nBootDevice != changed->Boot.nBootDevice) {
! 115: printf("boot options reset\n");
! 116: return true;
! 117: }
! 118: if (current->Boot.bEnableDRAMTest != changed->Boot.bEnableDRAMTest) {
! 119: printf("boot options reset\n");
! 120: return true;
! 121: }
! 122: if (current->Boot.bEnablePot != changed->Boot.bEnablePot) {
! 123: printf("boot options reset\n");
! 124: return true;
! 125: }
! 126: if (current->Boot.bEnableSoundTest != changed->Boot.bEnableSoundTest) {
! 127: printf("boot options reset\n");
! 128: return true;
! 129: }
! 130: if (current->Boot.bEnableSCSITest != changed->Boot.bEnableSCSITest) {
! 131: printf("boot options reset\n");
! 132: return true;
! 133: }
! 134: if (current->Boot.bLoopPot != changed->Boot.bLoopPot) {
! 135: printf("boot options reset\n");
! 136: return true;
! 137: }
! 138: if (current->Boot.bVerbose != changed->Boot.bVerbose) {
! 139: printf("boot options reset\n");
! 140: return true;
! 141: }
! 142: if (current->Boot.bExtendedPot != changed->Boot.bExtendedPot) {
! 143: printf("boot options reset\n");
! 144: return true;
! 145: }
! 146:
! 147: /* Did we change SCSI disk? */
! 148: int target;
! 149: bool bSCSIdisk_change = false;
! 150: for (target = 0; target < ESP_MAX_DEVS; target++) {
! 151: if (!current->SCSI.target[target].bCDROM || !(current->SCSI.target[target].bCDROM == changed->SCSI.target[target].bCDROM)) {
! 152: if ((current->SCSI.target[target].bAttached || current->SCSI.target[target].bAttached != changed->SCSI.target[target].bAttached)) {
! 153: if (strcmp(current->SCSI.target[target].szImageName, changed->SCSI.target[target].szImageName)) {
! 154: bSCSIdisk_change = true;
! 155: break;
! 156: }
! 157: }
! 158: }
! 159: }
! 160: if (bSCSIdisk_change) {
! 161: printf("scsi disk reset\n");
! 162: return true;
! 163: }
! 164:
! 165: /* Else no reset is required */
! 166: printf("No Reset needed!\n");
! 167: return false;
1.1 root 168: }
169:
170:
171: /*-----------------------------------------------------------------------*/
172: /**
173: * Copy details back to configuration and perform reset.
174: */
1.1.1.3 ! root 175: bool Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *changed, bool bForceReset)
1.1 root 176: {
177: bool NeedReset;
178: bool bReInitGemdosDrive = false;
1.1.1.3 ! root 179: bool bReInitSCSIEmu = false;
1.1 root 180: bool bReInitIDEEmu = false;
181: bool bReInitIoMem = false;
182: bool bScreenModeChange = false;
183: bool bReInitMidi = false;
184: bool bFloppyInsert[MAX_FLOPPYDRIVES];
185: int i;
186:
1.1.1.2 root 187: Dprintf("Changes for:\n");
1.1 root 188: /* Do we need to warn user that changes will only take effect after reset? */
189: if (bForceReset)
190: NeedReset = bForceReset;
191: else
192: NeedReset = Change_DoNeedReset(current, changed);
1.1.1.3 ! root 193:
! 194: /* Do we need to change SCSI disks? */
! 195: int target;
! 196: for (target = 0; target < ESP_MAX_DEVS; target++) {
! 197: if (!NeedReset && (current->SCSI.target[target].bAttached != changed->SCSI.target[target].bAttached || strcmp(current->SCSI.target[target].szImageName, changed->SCSI.target[target].szImageName))) {
! 198: bReInitSCSIEmu = true;
! 199: break;
! 200: }
! 201: }
1.1 root 202:
203: /* Copy details to configuration,
204: * so it can be saved out or set on reset
205: */
206: if (changed != &ConfigureParams)
207: {
208: ConfigureParams = *changed;
209: }
210:
211: /* Copy details to global, if we reset copy them all */
212: Configuration_Apply(NeedReset);
1.1.1.3 ! root 213:
! 214: /* Check if all necessary files exist */
! 215: Dialog_CheckFiles();
! 216: if (bQuitProgram)
! 217: {
! 218: SDL_Quit();
! 219: exit(-2);
! 220: }
1.1 root 221:
222: /* Re-init IO memory map? */
223: if (bReInitIoMem)
224: {
1.1.1.2 root 225: Dprintf("- IO mem<\n");
1.1 root 226: IoMem_Init();
227: }
1.1.1.3 ! root 228:
! 229: /* Re-init SCSI disks? */
! 230: if (bReInitSCSIEmu) {
! 231: Dprintf("- SCSI disks<\n");
! 232: SCSI_Reset();
! 233: }
1.1 root 234:
235: /* Force things associated with screen change */
236: if (bScreenModeChange)
237: {
1.1.1.2 root 238: Dprintf("- screenmode<\n");
1.1 root 239: Screen_ModeChanged();
240: }
241:
242: /* Do we need to perform reset? */
243: if (NeedReset)
244: {
1.1.1.3 ! root 245: const char *err_msg;
1.1.1.2 root 246: Dprintf("- reset\n");
1.1.1.3 ! root 247: err_msg=Reset_Cold();
! 248: // if (err_msg!=NULL) {
! 249: // DlgAlert_Notice(err_msg);
! 250: // return false;
! 251: // }
1.1 root 252: }
253:
254: /* Go into/return from full screen if flagged */
255: if (!bInFullScreen && ConfigureParams.Screen.bFullScreen)
256: Screen_EnterFullScreen();
257: else if (bInFullScreen && !ConfigureParams.Screen.bFullScreen)
258: Screen_ReturnFromFullScreen();
259:
260: /* update statusbar info (CPU, MHz, mem etc) */
261: Statusbar_UpdateInfo();
1.1.1.2 root 262: Dprintf("done.\n");
1.1.1.3 ! root 263: return true;
1.1 root 264: }
265:
266:
267: /*-----------------------------------------------------------------------*/
268: /**
269: * Change given Hatari options
270: * Return false if parsing failed, true otherwise
271: */
272: static bool Change_Options(int argc, const char *argv[])
273: {
274: bool bOK;
275: CNF_PARAMS current;
276:
277: Main_PauseEmulation(false);
278:
279: /* get configuration changes */
280: current = ConfigureParams;
281: ConfigureParams.Screen.bFullScreen = bInFullScreen;
282: bOK = Opt_ParseParameters(argc, argv);
283:
284: /* Check if reset is required and ask user if he really wants to continue */
285: if (bOK && Change_DoNeedReset(¤t, &ConfigureParams)
1.1.1.2 root 286: && current.Log.nAlertDlgLogLevel > LOG_FATAL) {
1.1 root 287: bOK = DlgAlert_Query("The emulated system must be "
288: "reset to apply these changes. "
289: "Apply changes now and reset "
290: "the emulator?");
291: }
292: /* Copy details to configuration */
293: if (bOK) {
1.1.1.3 ! root 294: if (!Change_CopyChangedParamsToConfiguration(¤t, &ConfigureParams, false)) {
! 295: ConfigureParams = current;
! 296: DlgAlert_Notice("Return to old parameters...");
! 297: Reset_Cold();
! 298: }
1.1 root 299: } else {
300: ConfigureParams = current;
301: }
302:
303: Main_UnPauseEmulation();
304: return bOK;
305: }
306:
307:
308: /*-----------------------------------------------------------------------*/
309: /**
310: * Parse given command line and change Hatari options accordingly
311: * Return false if parsing failed or there were no args, true otherwise
312: */
313: bool Change_ApplyCommandline(char *cmdline)
314: {
315: int i, argc, inarg;
316: const char **argv;
317: bool ret;
318:
319: /* count args */
320: inarg = argc = 0;
321: for (i = 0; cmdline[i]; i++)
322: {
323: if (isspace(cmdline[i]))
324: {
325: inarg = 0;
326: continue;
327: }
328: if (!inarg)
329: {
330: inarg++;
331: argc++;
332: }
333: }
334: if (!argc)
335: {
336: return false;
337: }
338: /* 2 = "hatari" + NULL */
339: argv = malloc((argc+2) * sizeof(char*));
340: if (!argv)
341: {
342: perror("command line alloc");
343: return false;
344: }
345:
346: /* parse them to array */
347: fprintf(stderr, "Command line with '%d' arguments:\n", argc);
348: inarg = argc = 0;
349: argv[argc++] = "hatari";
350: for (i = 0; cmdline[i]; i++)
351: {
352: if (isspace(cmdline[i]))
353: {
354: cmdline[i] = '\0';
355: if (inarg)
356: {
357: fprintf(stderr, "- '%s'\n", argv[argc-1]);
358: }
359: inarg = 0;
360: continue;
361: }
362: if (!inarg)
363: {
364: argv[argc++] = &(cmdline[i]);
365: inarg++;
366: }
367: }
368: if (inarg)
369: {
370: fprintf(stderr, "- '%s'\n", argv[argc-1]);
371: }
372: argv[argc] = NULL;
373:
374: /* do args */
375: ret = Change_Options(argc, argv);
376: free((void *)argv);
377: return ret;
378: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.