ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_Amiga.h
Revision: 1.4
Committed: 2004-01-13T17:09:17Z (19 years ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.3: +0 -1 lines
Log Message:
microscopic cleanup

File Contents

# Content
1 /*
2 * Prefs_Amiga.h - Global preferences, Amiga specific stuff
3 *
4 * Frodo (C) 1994-1997,2002-2004 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_DriveType8], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[0], TAG_DONE);
141 GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType9], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[1], TAG_DONE);
142 GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType10], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[2], TAG_DONE);
143 GT_SetGadgetAttrs(PrefsGadgets[GDX_DriveType11], PrefsWnd, NULL, GTCY_Active, prefs->DriveType[3], TAG_DONE);
144
145 GT_SetGadgetAttrs(PrefsGadgets[GDX_MapSlash], PrefsWnd, NULL, GTCB_Checked, prefs->MapSlash, TAG_DONE);
146 GT_SetGadgetAttrs(PrefsGadgets[GDX_Emul1541Proc], PrefsWnd, NULL, GTCB_Checked, prefs->Emul1541Proc, TAG_DONE);
147
148 ghost_gadgets();
149 }
150
151
152 /*
153 * Get the values of the gadgets
154 */
155
156 static void get_values(void)
157 {
158 prefs->NormalCycles = GetNumber(PrefsGadgets[GDX_NormalCycles]);
159 prefs->BadLineCycles = GetNumber(PrefsGadgets[GDX_BadLineCycles]);
160 prefs->CIACycles = GetNumber(PrefsGadgets[GDX_CIACycles]);
161 prefs->FloppyCycles = GetNumber(PrefsGadgets[GDX_FloppyCycles]);
162 prefs->SkipFrames = GetNumber(PrefsGadgets[GDX_SkipFrames]);
163
164 strcpy(prefs->DrivePath[0], GetString(PrefsGadgets[GDX_DrivePath8]));
165 strcpy(prefs->DrivePath[1], GetString(PrefsGadgets[GDX_DrivePath9]));
166 strcpy(prefs->DrivePath[2], GetString(PrefsGadgets[GDX_DrivePath10]));
167 strcpy(prefs->DrivePath[3], GetString(PrefsGadgets[GDX_DrivePath11]));
168
169 prefs->Check();
170 }
171
172
173 /*
174 * Enable/disable certain gadgets
175 */
176
177 static void ghost_gadgets(void)
178 {
179 GT_SetGadgetAttrs(PrefsGadgets[GDX_NormalCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
180 GT_SetGadgetAttrs(PrefsGadgets[GDX_BadLineCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
181 GT_SetGadgetAttrs(PrefsGadgets[GDX_CIACycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
182 GT_SetGadgetAttrs(PrefsGadgets[GDX_FloppyCycles], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
183 GT_SetGadgetAttrs(PrefsGadgets[GDX_CIAIRQHack], PrefsWnd, NULL, GA_Disabled, IsFrodoSC, TAG_DONE);
184 }
185
186
187 /*
188 * Handle gadgets
189 */
190
191 int SpritesOnClicked(void)
192 {
193 prefs->SpritesOn = !prefs->SpritesOn;
194 }
195
196 int SpriteCollisionsClicked(void)
197 {
198 prefs->SpriteCollisions = !prefs->SpriteCollisions;
199 }
200
201 int Joystick2OnClicked(void)
202 {
203 prefs->Joystick2On = !prefs->Joystick2On;
204 }
205
206 int JoystickSwapClicked(void)
207 {
208 prefs->JoystickSwap = !prefs->JoystickSwap;
209 }
210
211 int LimitSpeedClicked(void)
212 {
213 prefs->LimitSpeed = !prefs->LimitSpeed;
214 }
215
216 int FastResetClicked(void)
217 {
218 prefs->FastReset = !prefs->FastReset;
219 }
220
221 int CIAIRQHackClicked(void)
222 {
223 prefs->CIAIRQHack = !prefs->CIAIRQHack;
224 }
225
226 int SIDFiltersClicked(void)
227 {
228 prefs->SIDFilters = !prefs->SIDFilters;
229 }
230
231 int NormalCyclesClicked(void) {}
232 int BadLineCyclesClicked(void) {}
233 int CIACyclesClicked(void) {}
234 int FloppyCyclesClicked(void) {}
235 int SkipFramesClicked(void) {}
236 int DrivePath8Clicked(void) {}
237 int DrivePath9Clicked(void) {}
238 int DrivePath10Clicked(void) {}
239 int DrivePath11Clicked(void) {}
240
241 int SIDTypeClicked(void)
242 {
243 prefs->SIDType = PrefsMsg.Code;
244 }
245
246 int REUSizeClicked(void)
247 {
248 prefs->REUSize = PrefsMsg.Code;
249 }
250
251 int DriveType8Clicked(void)
252 {
253 prefs->DriveType[0] = PrefsMsg.Code;
254 }
255
256 int DriveType9Clicked(void)
257 {
258 prefs->DriveType[1] = PrefsMsg.Code;
259 }
260
261 int DriveType10Clicked(void)
262 {
263 prefs->DriveType[2] = PrefsMsg.Code;
264 }
265
266 int DriveType11Clicked(void)
267 {
268 prefs->DriveType[3] = PrefsMsg.Code;
269 }
270
271 void get_drive(int i)
272 {
273 bool result = FALSE;
274
275 if (drive_req == NULL)
276 return;
277
278 get_values();
279
280 if (prefs->DriveType[i] == DRVTYPE_DIR)
281 result = AslRequestTags(drive_req,
282 ASLFR_TitleText, (ULONG)"Frodo: Select directory",
283 ASLFR_DrawersOnly, TRUE,
284 ASLFR_DoPatterns, FALSE,
285 ASLFR_InitialPattern, (ULONG)"#?",
286 ASLFR_InitialDrawer, (ULONG)prefs->DrivePath[i],
287 ASLFR_InitialFile, (ULONG)"",
288 TAG_DONE);
289 else {
290
291 // Separate path and file
292 char dir[256], file[256];
293 strncpy(dir, prefs->DrivePath[i], 255);
294 char *s = FilePart(dir);
295 strncpy(file, s, 255);
296 *s = 0;
297
298 if (prefs->DriveType[i] == DRVTYPE_D64)
299 result = AslRequestTags(drive_req,
300 ASLFR_TitleText, (ULONG)"Frodo: Select disk image file",
301 ASLFR_DrawersOnly, FALSE,
302 ASLFR_DoPatterns, TRUE,
303 ASLFR_InitialPattern, (ULONG)"#?.(d64|x64)",
304 ASLFR_InitialDrawer, (ULONG)dir,
305 ASLFR_InitialFile, (ULONG)file,
306 TAG_DONE);
307 else
308 result = AslRequestTags(drive_req,
309 ASLFR_TitleText, (ULONG)"Frodo: Select archive file",
310 ASLFR_DrawersOnly, FALSE,
311 ASLFR_DoPatterns, TRUE,
312 ASLFR_InitialPattern, (ULONG)"#?.(t64|LNX)",
313 ASLFR_InitialDrawer, (ULONG)dir,
314 ASLFR_InitialFile, (ULONG)file,
315 TAG_DONE);
316 }
317
318 if (result) {
319 strncpy(prefs->DrivePath[i], drive_req->fr_Drawer, 255);
320 if (prefs->DriveType[i] != DRVTYPE_DIR)
321 AddPart(prefs->DrivePath[i], drive_req->fr_File, 255);
322 set_values();
323 }
324 }
325
326 int GetDrive8Clicked(void)
327 {
328 get_drive(0);
329 }
330
331 int GetDrive9Clicked(void)
332 {
333 get_drive(1);
334 }
335
336 int GetDrive10Clicked(void)
337 {
338 get_drive(2);
339 }
340
341 int GetDrive11Clicked(void)
342 {
343 get_drive(3);
344 }
345
346 int MapSlashClicked(void)
347 {
348 prefs->MapSlash = !prefs->MapSlash;
349 }
350
351 int Emul1541ProcClicked(void)
352 {
353 prefs->Emul1541Proc = !prefs->Emul1541Proc;
354 }
355
356 int OKClicked(void)
357 {
358 get_values();
359 done = result = TRUE;
360 }
361
362 int CancelClicked(void)
363 {
364 done = TRUE;
365 result = FALSE;
366 }
367
368
369 /*
370 * Handle menus
371 */
372
373 int PrefsOpen(void)
374 {
375 if (open_req != NULL && AslRequest(open_req, NULL)) {
376 strncpy(path, open_req->fr_Drawer, 255);
377 AddPart(path, open_req->fr_File, 255);
378
379 get_values(); // Useful if Load() is unsuccessful
380 prefs->Load(path);
381 set_values();
382 }
383 }
384
385 int PrefsRevert(void)
386 {
387 get_values(); // Useful if Load() is unsuccessful
388 prefs->Load(path);
389 set_values();
390 }
391
392 int PrefsSaveAs(void)
393 {
394 if (save_req != NULL && AslRequest(save_req, NULL)) {
395 strncpy(path, save_req->fr_Drawer, 255);
396 AddPart(path, save_req->fr_File, 255);
397
398 get_values();
399 prefs->Save(path);
400 }
401 }
402
403 int PrefsSave(void)
404 {
405 get_values();
406 prefs->Save(path);
407 }
408
409 int PrefsOK(void)
410 {
411 return OKClicked();
412 }
413
414 int PrefsCancel(void)
415 {
416 return CancelClicked();
417 }
418
419
420 /*
421 * Handle keys
422 */
423
424 int PrefsVanillaKey(void)
425 {
426 switch (PrefsMsg.Code) {
427 case 'o': case 'O':
428 return OKClicked();
429 case 'c': case 'C':
430 return CancelClicked();
431 }
432 }