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