1 |
/* |
2 |
* Prefs_Amiga.h - Global preferences, Amiga specific stuff |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002-2005 Christian Bauer |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include <intuition/intuition.h> |
22 |
#include <intuition/gadgetclass.h> |
23 |
#include <libraries/asl.h> |
24 |
#include <proto/exec.h> |
25 |
#include <proto/gadtools.h> |
26 |
#include <proto/asl.h> |
27 |
#include <proto/dos.h> |
28 |
|
29 |
extern "C" { |
30 |
#include "AmigaGUI.h" |
31 |
} |
32 |
|
33 |
|
34 |
// Flag: All done, close prefs window |
35 |
static bool done, result; |
36 |
|
37 |
// Pointer to preferences being edited |
38 |
static Prefs *prefs; |
39 |
|
40 |
// Pointer to prefs file name |
41 |
static char *path; |
42 |
|
43 |
// File requesters |
44 |
struct FileRequester *open_req, *save_req, *drive_req; |
45 |
|
46 |
// Prototypes |
47 |
static void set_values(void); |
48 |
static void get_values(void); |
49 |
static void ghost_gadgets(void); |
50 |
static void get_drive(int i); |
51 |
|
52 |
|
53 |
/* |
54 |
* Show preferences editor (synchronously) |
55 |
* prefs_name points to the file name of the preferences (which may be changed) |
56 |
*/ |
57 |
|
58 |
bool Prefs::ShowEditor(bool startup, char *prefs_name) |
59 |
{ |
60 |
done = result = FALSE; |
61 |
prefs = this; |
62 |
path = prefs_name; |
63 |
open_req = save_req = NULL; |
64 |
|
65 |
// Open prefs window |
66 |
if (!SetupScreen()) { |
67 |
if (!OpenPrefsWindow()) { |
68 |
|
69 |
// Allocate file requesters |
70 |
open_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, |
71 |
ASLFR_Window, (ULONG)PrefsWnd, |
72 |
ASLFR_SleepWindow, TRUE, |
73 |
ASLFR_TitleText, (ULONG)"Frodo: Open preferences...", |
74 |
ASLFR_RejectIcons, TRUE, |
75 |
TAG_DONE); |
76 |
save_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, |
77 |
ASLFR_Window, (ULONG)PrefsWnd, |
78 |
ASLFR_SleepWindow, TRUE, |
79 |
ASLFR_TitleText, (ULONG)"Frodo: Save preferences as...", |
80 |
ASLFR_DoSaveMode, TRUE, |
81 |
ASLFR_RejectIcons, TRUE, |
82 |
TAG_DONE); |
83 |
drive_req = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest, |
84 |
ASLFR_Window, (ULONG)PrefsWnd, |
85 |
ASLFR_SleepWindow, TRUE, |
86 |
ASLFR_RejectIcons, TRUE, |
87 |
TAG_DONE); |
88 |
|
89 |
// Handle prefs window |
90 |
set_values(); |
91 |
while (!done) { |
92 |
WaitPort(PrefsWnd->UserPort); |
93 |
HandlePrefsIDCMP(); |
94 |
} |
95 |
|
96 |
// Free file requesters |
97 |
FreeAslRequest(open_req); |
98 |
FreeAslRequest(save_req); |
99 |
FreeAslRequest(drive_req); |
100 |
} |
101 |
ClosePrefsWindow(); |
102 |
} |
103 |
CloseDownScreen(); |
104 |
|
105 |
return result; |
106 |
} |
107 |
|
108 |
|
109 |
/* |
110 |
* Set the values of the gadgets |
111 |
*/ |
112 |
|
113 |
static void set_values(void) |
114 |
{ |
115 |
prefs->Check(); |
116 |
|
117 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_NormalCycles], PrefsWnd, NULL, GTIN_Number, prefs->NormalCycles, TAG_DONE); |
118 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_BadLineCycles], PrefsWnd, NULL, GTIN_Number, prefs->BadLineCycles, TAG_DONE); |
119 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_CIACycles], PrefsWnd, NULL, GTIN_Number, prefs->CIACycles, TAG_DONE); |
120 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_FloppyCycles], PrefsWnd, NULL, GTIN_Number, prefs->FloppyCycles, TAG_DONE); |
121 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_SkipFrames], PrefsWnd, NULL, GTIN_Number, prefs->SkipFrames, TAG_DONE); |
122 |
|
123 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_SIDType], PrefsWnd, NULL, GTCY_Active, prefs->SIDType, TAG_DONE); |
124 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_REUSize], PrefsWnd, NULL, GTCY_Active, prefs->REUSize, TAG_DONE); |
125 |
|
126 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_SpritesOn], PrefsWnd, NULL, GTCB_Checked, prefs->SpritesOn, TAG_DONE); |
127 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_SpriteCollisions], PrefsWnd, NULL, GTCB_Checked, prefs->SpriteCollisions, TAG_DONE); |
128 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_Joystick2On], PrefsWnd, NULL, GTCB_Checked, prefs->Joystick2On, TAG_DONE); |
129 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_JoystickSwap], PrefsWnd, NULL, GTCB_Checked, prefs->JoystickSwap, TAG_DONE); |
130 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_LimitSpeed], PrefsWnd, NULL, GTCB_Checked, prefs->LimitSpeed, TAG_DONE); |
131 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_FastReset], PrefsWnd, NULL, GTCB_Checked, prefs->FastReset, TAG_DONE); |
132 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_CIAIRQHack], PrefsWnd, NULL, GTCB_Checked, prefs->CIAIRQHack, TAG_DONE); |
133 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_SIDFilters], PrefsWnd, NULL, GTCB_Checked, prefs->SIDFilters, TAG_DONE); |
134 |
|
135 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath8], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[0], TAG_DONE); |
136 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath9], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[1], TAG_DONE); |
137 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath10], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[2], TAG_DONE); |
138 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_DrivePath11], PrefsWnd, NULL, GTST_String, (ULONG)prefs->DrivePath[3], TAG_DONE); |
139 |
|
140 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_MapSlash], PrefsWnd, NULL, GTCB_Checked, prefs->MapSlash, TAG_DONE); |
141 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_Emul1541Proc], PrefsWnd, NULL, GTCB_Checked, prefs->Emul1541Proc, TAG_DONE); |
142 |
|
143 |
ghost_gadgets(); |
144 |
} |
145 |
|
146 |
|
147 |
/* |
148 |
* Get the values of the gadgets |
149 |
*/ |
150 |
|
151 |
static void get_values(void) |
152 |
{ |
153 |
prefs->NormalCycles = GetNumber(PrefsGadgets[GDX_NormalCycles]); |
154 |
prefs->BadLineCycles = GetNumber(PrefsGadgets[GDX_BadLineCycles]); |
155 |
prefs->CIACycles = GetNumber(PrefsGadgets[GDX_CIACycles]); |
156 |
prefs->FloppyCycles = GetNumber(PrefsGadgets[GDX_FloppyCycles]); |
157 |
prefs->SkipFrames = GetNumber(PrefsGadgets[GDX_SkipFrames]); |
158 |
|
159 |
strcpy(prefs->DrivePath[0], GetString(PrefsGadgets[GDX_DrivePath8])); |
160 |
strcpy(prefs->DrivePath[1], GetString(PrefsGadgets[GDX_DrivePath9])); |
161 |
strcpy(prefs->DrivePath[2], GetString(PrefsGadgets[GDX_DrivePath10])); |
162 |
strcpy(prefs->DrivePath[3], GetString(PrefsGadgets[GDX_DrivePath11])); |
163 |
|
164 |
prefs->Check(); |
165 |
} |
166 |
|
167 |
|
168 |
/* |
169 |
* Enable/disable certain gadgets |
170 |
*/ |
171 |
|
172 |
static void ghost_gadgets(void) |
173 |
{ |
174 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_NormalCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE); |
175 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_BadLineCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE); |
176 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_CIACycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE); |
177 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_FloppyCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE); |
178 |
GT_SetGadgetAttrs(PrefsGadgets[GDX_CIAIRQHack], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE); |
179 |
} |
180 |
|
181 |
|
182 |
/* |
183 |
* Handle gadgets |
184 |
*/ |
185 |
|
186 |
int SpritesOnClicked(void) |
187 |
{ |
188 |
prefs->SpritesOn = !prefs->SpritesOn; |
189 |
} |
190 |
|
191 |
int SpriteCollisionsClicked(void) |
192 |
{ |
193 |
prefs->SpriteCollisions = !prefs->SpriteCollisions; |
194 |
} |
195 |
|
196 |
int Joystick2OnClicked(void) |
197 |
{ |
198 |
prefs->Joystick2On = !prefs->Joystick2On; |
199 |
} |
200 |
|
201 |
int JoystickSwapClicked(void) |
202 |
{ |
203 |
prefs->JoystickSwap = !prefs->JoystickSwap; |
204 |
} |
205 |
|
206 |
int LimitSpeedClicked(void) |
207 |
{ |
208 |
prefs->LimitSpeed = !prefs->LimitSpeed; |
209 |
} |
210 |
|
211 |
int FastResetClicked(void) |
212 |
{ |
213 |
prefs->FastReset = !prefs->FastReset; |
214 |
} |
215 |
|
216 |
int CIAIRQHackClicked(void) |
217 |
{ |
218 |
prefs->CIAIRQHack = !prefs->CIAIRQHack; |
219 |
} |
220 |
|
221 |
int SIDFiltersClicked(void) |
222 |
{ |
223 |
prefs->SIDFilters = !prefs->SIDFilters; |
224 |
} |
225 |
|
226 |
int NormalCyclesClicked(void) {} |
227 |
int BadLineCyclesClicked(void) {} |
228 |
int CIACyclesClicked(void) {} |
229 |
int FloppyCyclesClicked(void) {} |
230 |
int SkipFramesClicked(void) {} |
231 |
int DrivePath8Clicked(void) {} |
232 |
int DrivePath9Clicked(void) {} |
233 |
int DrivePath10Clicked(void) {} |
234 |
int DrivePath11Clicked(void) {} |
235 |
|
236 |
int SIDTypeClicked(void) |
237 |
{ |
238 |
prefs->SIDType = PrefsMsg.Code; |
239 |
} |
240 |
|
241 |
int REUSizeClicked(void) |
242 |
{ |
243 |
prefs->REUSize = PrefsMsg.Code; |
244 |
} |
245 |
|
246 |
void get_drive(int i) |
247 |
{ |
248 |
bool result = FALSE; |
249 |
|
250 |
if (drive_req == NULL) |
251 |
return; |
252 |
|
253 |
get_values(); |
254 |
|
255 |
if (prefs->DriveType[i] == DRVTYPE_DIR) |
256 |
result = AslRequestTags(drive_req, |
257 |
ASLFR_TitleText, (ULONG)"Frodo: Select directory", |
258 |
ASLFR_DrawersOnly, TRUE, |
259 |
ASLFR_DoPatterns, FALSE, |
260 |
ASLFR_InitialPattern, (ULONG)"#?", |
261 |
ASLFR_InitialDrawer, (ULONG)prefs->DrivePath[i], |
262 |
ASLFR_InitialFile, (ULONG)"", |
263 |
TAG_DONE); |
264 |
else { |
265 |
|
266 |
// Separate path and file |
267 |
char dir[256], file[256]; |
268 |
strncpy(dir, prefs->DrivePath[i], 255); |
269 |
char *s = FilePart(dir); |
270 |
strncpy(file, s, 255); |
271 |
*s = 0; |
272 |
|
273 |
result = AslRequestTags(drive_req, |
274 |
ASLFR_TitleText, (ULONG)"Frodo: Select disk image or archive file", |
275 |
ASLFR_DrawersOnly, FALSE, |
276 |
ASLFR_DoPatterns, TRUE, |
277 |
ASLFR_InitialPattern, (ULONG)"#?.(d64|x64|t64|LNX|P00)", |
278 |
ASLFR_InitialDrawer, (ULONG)dir, |
279 |
ASLFR_InitialFile, (ULONG)file, |
280 |
TAG_DONE); |
281 |
} |
282 |
|
283 |
if (result) { |
284 |
strncpy(prefs->DrivePath[i], drive_req->fr_Drawer, 255); |
285 |
if (prefs->DriveType[i] != DRVTYPE_DIR) |
286 |
AddPart(prefs->DrivePath[i], drive_req->fr_File, 255); |
287 |
set_values(); |
288 |
} |
289 |
} |
290 |
|
291 |
int GetDrive8Clicked(void) |
292 |
{ |
293 |
get_drive(0); |
294 |
} |
295 |
|
296 |
int GetDrive9Clicked(void) |
297 |
{ |
298 |
get_drive(1); |
299 |
} |
300 |
|
301 |
int GetDrive10Clicked(void) |
302 |
{ |
303 |
get_drive(2); |
304 |
} |
305 |
|
306 |
int GetDrive11Clicked(void) |
307 |
{ |
308 |
get_drive(3); |
309 |
} |
310 |
|
311 |
int MapSlashClicked(void) |
312 |
{ |
313 |
prefs->MapSlash = !prefs->MapSlash; |
314 |
} |
315 |
|
316 |
int Emul1541ProcClicked(void) |
317 |
{ |
318 |
prefs->Emul1541Proc = !prefs->Emul1541Proc; |
319 |
} |
320 |
|
321 |
int OKClicked(void) |
322 |
{ |
323 |
get_values(); |
324 |
done = result = TRUE; |
325 |
} |
326 |
|
327 |
int CancelClicked(void) |
328 |
{ |
329 |
done = TRUE; |
330 |
result = FALSE; |
331 |
} |
332 |
|
333 |
|
334 |
/* |
335 |
* Handle menus |
336 |
*/ |
337 |
|
338 |
int PrefsOpen(void) |
339 |
{ |
340 |
if (open_req != NULL && AslRequest(open_req, NULL)) { |
341 |
strncpy(path, open_req->fr_Drawer, 255); |
342 |
AddPart(path, open_req->fr_File, 255); |
343 |
|
344 |
get_values(); // Useful if Load() is unsuccessful |
345 |
prefs->Load(path); |
346 |
set_values(); |
347 |
} |
348 |
} |
349 |
|
350 |
int PrefsRevert(void) |
351 |
{ |
352 |
get_values(); // Useful if Load() is unsuccessful |
353 |
prefs->Load(path); |
354 |
set_values(); |
355 |
} |
356 |
|
357 |
int PrefsSaveAs(void) |
358 |
{ |
359 |
if (save_req != NULL && AslRequest(save_req, NULL)) { |
360 |
strncpy(path, save_req->fr_Drawer, 255); |
361 |
AddPart(path, save_req->fr_File, 255); |
362 |
|
363 |
get_values(); |
364 |
prefs->Save(path); |
365 |
} |
366 |
} |
367 |
|
368 |
int PrefsSave(void) |
369 |
{ |
370 |
get_values(); |
371 |
prefs->Save(path); |
372 |
} |
373 |
|
374 |
int PrefsOK(void) |
375 |
{ |
376 |
return OKClicked(); |
377 |
} |
378 |
|
379 |
int PrefsCancel(void) |
380 |
{ |
381 |
return CancelClicked(); |
382 |
} |
383 |
|
384 |
|
385 |
/* |
386 |
* Handle keys |
387 |
*/ |
388 |
|
389 |
int PrefsVanillaKey(void) |
390 |
{ |
391 |
switch (PrefsMsg.Code) { |
392 |
case 'o': case 'O': |
393 |
return OKClicked(); |
394 |
case 'c': case 'C': |
395 |
return CancelClicked(); |
396 |
} |
397 |
} |