|
|
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" ! 28: ! 29: ! 30: /*-----------------------------------------------------------------------*/ ! 31: /** ! 32: * Check if user needs to be warned that changes will take place after reset. ! 33: * Return true if wants to reset. ! 34: */ ! 35: bool Change_DoNeedReset(CNF_PARAMS *current, CNF_PARAMS *changed) ! 36: { ! 37: return true; ! 38: } ! 39: ! 40: ! 41: /*-----------------------------------------------------------------------*/ ! 42: /** ! 43: * Copy details back to configuration and perform reset. ! 44: */ ! 45: void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *changed, bool bForceReset) ! 46: { ! 47: bool NeedReset; ! 48: bool bReInitGemdosDrive = false; ! 49: bool bReInitAcsiEmu = false; ! 50: bool bReInitIDEEmu = false; ! 51: bool bReInitIoMem = false; ! 52: bool bScreenModeChange = false; ! 53: bool bReInitMidi = false; ! 54: bool bFloppyInsert[MAX_FLOPPYDRIVES]; ! 55: int i; ! 56: ! 57: /* Do we need to warn user that changes will only take effect after reset? */ ! 58: if (bForceReset) ! 59: NeedReset = bForceReset; ! 60: else ! 61: NeedReset = Change_DoNeedReset(current, changed); ! 62: ! 63: ! 64: /* Copy details to configuration, ! 65: * so it can be saved out or set on reset ! 66: */ ! 67: if (changed != &ConfigureParams) ! 68: { ! 69: ConfigureParams = *changed; ! 70: } ! 71: ! 72: /* Copy details to global, if we reset copy them all */ ! 73: Configuration_Apply(NeedReset); ! 74: ! 75: ! 76: /* Re-init IO memory map? */ ! 77: if (bReInitIoMem) ! 78: { ! 79: IoMem_Init(); ! 80: } ! 81: ! 82: ! 83: /* Force things associated with screen change */ ! 84: if (bScreenModeChange) ! 85: { ! 86: Screen_ModeChanged(); ! 87: } ! 88: ! 89: /* Do we need to perform reset? */ ! 90: if (NeedReset) ! 91: { ! 92: Reset_Cold(); ! 93: } ! 94: ! 95: /* Go into/return from full screen if flagged */ ! 96: if (!bInFullScreen && ConfigureParams.Screen.bFullScreen) ! 97: Screen_EnterFullScreen(); ! 98: else if (bInFullScreen && !ConfigureParams.Screen.bFullScreen) ! 99: Screen_ReturnFromFullScreen(); ! 100: ! 101: /* update statusbar info (CPU, MHz, mem etc) */ ! 102: Statusbar_UpdateInfo(); ! 103: } ! 104: ! 105: ! 106: /*-----------------------------------------------------------------------*/ ! 107: /** ! 108: * Change given Hatari options ! 109: * Return false if parsing failed, true otherwise ! 110: */ ! 111: static bool Change_Options(int argc, const char *argv[]) ! 112: { ! 113: bool bOK; ! 114: CNF_PARAMS current; ! 115: ! 116: Main_PauseEmulation(false); ! 117: ! 118: /* get configuration changes */ ! 119: current = ConfigureParams; ! 120: ConfigureParams.Screen.bFullScreen = bInFullScreen; ! 121: bOK = Opt_ParseParameters(argc, argv); ! 122: ! 123: /* Check if reset is required and ask user if he really wants to continue */ ! 124: if (bOK && Change_DoNeedReset(¤t, &ConfigureParams) ! 125: && current.Log.nAlertDlgLogLevel >= LOG_WARN) { ! 126: bOK = DlgAlert_Query("The emulated system must be " ! 127: "reset to apply these changes. " ! 128: "Apply changes now and reset " ! 129: "the emulator?"); ! 130: } ! 131: /* Copy details to configuration */ ! 132: if (bOK) { ! 133: Change_CopyChangedParamsToConfiguration(¤t, &ConfigureParams, false); ! 134: } else { ! 135: ConfigureParams = current; ! 136: } ! 137: ! 138: Main_UnPauseEmulation(); ! 139: return bOK; ! 140: } ! 141: ! 142: ! 143: /*-----------------------------------------------------------------------*/ ! 144: /** ! 145: * Parse given command line and change Hatari options accordingly ! 146: * Return false if parsing failed or there were no args, true otherwise ! 147: */ ! 148: bool Change_ApplyCommandline(char *cmdline) ! 149: { ! 150: int i, argc, inarg; ! 151: const char **argv; ! 152: bool ret; ! 153: ! 154: /* count args */ ! 155: inarg = argc = 0; ! 156: for (i = 0; cmdline[i]; i++) ! 157: { ! 158: if (isspace(cmdline[i])) ! 159: { ! 160: inarg = 0; ! 161: continue; ! 162: } ! 163: if (!inarg) ! 164: { ! 165: inarg++; ! 166: argc++; ! 167: } ! 168: } ! 169: if (!argc) ! 170: { ! 171: return false; ! 172: } ! 173: /* 2 = "hatari" + NULL */ ! 174: argv = malloc((argc+2) * sizeof(char*)); ! 175: if (!argv) ! 176: { ! 177: perror("command line alloc"); ! 178: return false; ! 179: } ! 180: ! 181: /* parse them to array */ ! 182: fprintf(stderr, "Command line with '%d' arguments:\n", argc); ! 183: inarg = argc = 0; ! 184: argv[argc++] = "hatari"; ! 185: for (i = 0; cmdline[i]; i++) ! 186: { ! 187: if (isspace(cmdline[i])) ! 188: { ! 189: cmdline[i] = '\0'; ! 190: if (inarg) ! 191: { ! 192: fprintf(stderr, "- '%s'\n", argv[argc-1]); ! 193: } ! 194: inarg = 0; ! 195: continue; ! 196: } ! 197: if (!inarg) ! 198: { ! 199: argv[argc++] = &(cmdline[i]); ! 200: inarg++; ! 201: } ! 202: } ! 203: if (inarg) ! 204: { ! 205: fprintf(stderr, "- '%s'\n", argv[argc-1]); ! 206: } ! 207: argv[argc] = NULL; ! 208: ! 209: /* do args */ ! 210: ret = Change_Options(argc, argv); ! 211: free((void *)argv); ! 212: return ret; ! 213: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.