ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/AcornGUI.cc
Revision: 1.2
Committed: 2003-07-01T17:51:17Z (20 years, 10 months ago) by cebix
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
updated copyright date

File Contents

# Content
1 /*
2 * AcornGUI.cc - Frodo's Graphical User Interface for Acorn RISC OS machines
3 *
4 * (C) 1997 Andreas Dehmel
5 *
6 * Frodo (C) 1994-1997,2002-2003 Christian Bauer
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include "sysdeps.h"
24
25 #include "C64.h"
26 #include "VIC.h"
27 #include "Display.h"
28 #include "Prefs.h"
29 #include "main.h"
30 #include "ROlib.h"
31 #include "AcornGUI.h"
32 #include "Version.h"
33
34
35
36 #define CUSTOM_SPRITES "FrodoRsrc:Sprites"
37 #define TEMPLATES_FILE "FrodoRsrc:Templates"
38 #define WIMP_SCRAP_FILE "<Wimp$Scrap>"
39
40
41 #define FileType_Data 0xffd
42 #define FileType_Text 0xfff
43 #define FileType_C64File 0x064
44 #define FileType_D64File 0x164
45
46 #define IconSpriteSize 68 // OS units of an icon sprite (for dragging)
47 #define EstimatedPrefsSize 1024 // can't say how big it'll be before saving...
48 #define EstimatedConfSize 256
49 #define EstimatedRAMSize 0x10400
50 #define EstimatedSnapSize 0x11000
51
52
53
54
55 // For the scanning of the joystick keys in the SysConfig window
56 #define IntKey_ScanFrom 3
57 // This key gets translated to 0xff, i.e. none (joystick inactive)
58 #define IntKey_Void 44
59
60
61 #define Key_Return 13
62
63
64
65
66 // LED number to Icon number translation:
67 char LEDtoIcon[4] = {Icon_Pane_LED0, Icon_Pane_LED1, Icon_Pane_LED2, Icon_Pane_LED3};
68 // Drive number to Icon number (Pane) translation:
69 char PDrvToIcon[4] = {Icon_Pane_Drive0, Icon_Pane_Drive1, Icon_Pane_Drive2, Icon_Pane_Drive3};
70 // Drive number to Icon number (Prefs) translation:
71 #define IconsPerDrive 4
72 char DriveToIcon[16] = {
73 Icon_Prefs_Dr8DIR, Icon_Prefs_Dr8D64, Icon_Prefs_Dr8T64, Icon_Prefs_Dr8Path,
74 Icon_Prefs_Dr9DIR, Icon_Prefs_Dr9D64, Icon_Prefs_Dr9T64, Icon_Prefs_Dr9Path,
75 Icon_Prefs_Dr10DIR, Icon_Prefs_Dr10D64, Icon_Prefs_Dr10T64, Icon_Prefs_Dr10Path,
76 Icon_Prefs_Dr11DIR, Icon_Prefs_Dr11D64, Icon_Prefs_Dr11T64, Icon_Prefs_Dr11Path
77 };
78 // SID type to Icon number translation:
79 char SIDtoIcon[3] = {
80 Icon_Prefs_SIDNone, Icon_Prefs_SIDDigi, Icon_Prefs_SIDCard
81 };
82 // REU type to Icon number translation:
83 char REUtoIcon[4] = {
84 Icon_Prefs_REUNone, Icon_Prefs_REU128, Icon_Prefs_REU256, Icon_Prefs_REU512
85 };
86 char KJoyToIcon[2][5] = {
87 {Icon_Conf_Joy1Up, Icon_Conf_Joy1Down, Icon_Conf_Joy1Left, Icon_Conf_Joy1Right, Icon_Conf_Joy1Fire},
88 {Icon_Conf_Joy2Up, Icon_Conf_Joy2Down, Icon_Conf_Joy2Left, Icon_Conf_Joy2Right, Icon_Conf_Joy2Fire}
89 };
90
91
92
93
94
95 // Internal keynumbers lookup table
96 // Single characters are represented by single chars, others by pointers to strings
97 int IntKeyTable[128] = {
98 (int)"Shft", (int)"Ctrl", (int)"Alt", (int)"ShftL",
99 (int)"CtrlL", (int)"AltL", (int)"ShftR", (int)"CtrlR",
100 (int)"AltR", (int)"Slct", (int)"Menu", (int)"Adjst",
101 0, 0, 0, 0,
102 'q', '3', '4', '5',
103 (int)"F4", '8', (int)"F7", '-',
104 '6', (int)"Left", (int)"num6", (int)"num7",
105 (int)"F11", (int)"F12", (int)"F10", (int)"ScLck",
106 (int)"Prnt", 'w', 'e', 't',
107 '7', 'i', '9', '0',
108 '-', (int)"Down", (int)"num8", (int)"num9",
109 (int)"Brk", '`', '£', (int)"Del",
110 '1', '2', 'd', 'r',
111 '6', 'u', 'o', 'p',
112 '[', (int)"Up", (int)"num+", (int)"num-",
113 (int)"nmEnt", (int)"Isrt", (int)"Home", (int)"PgUp",
114 (int)"CpLck", 'a', 'x', 'f',
115 'y', 'j', 'k', '2',
116 ';', (int)"Ret", (int)"num/", 0,
117 (int)"num.", (int)"nmLck", (int)"PgDwn", '\'',
118 0, 's', 'c', 'g',
119 'h', 'n', 'l', ';',
120 ']', (int)"Del", (int)"num#", (int)"num*",
121 0, '=', (int)"Extra", 0,
122 (int)"Tab", 'z', (int)"Space", 'v',
123 'b', 'm', ',', '.',
124 '/', (int)"Copy", (int)"num0", (int)"num1",
125 (int)"num3", 0, 0, 0,
126 (int)"Esc", (int)"F1", (int)"F2", (int)"F3",
127 (int)"F5", (int)"F6", (int)"F8", (int)"F9",
128 '\\', (int)"Right", (int)"num4", (int)"num5",
129 (int)"num2", 0, 0, 0
130 };
131
132
133
134
135
136 // The icon bar icon
137 RO_IconDesc IBarIcon = {
138 -1, 0, 0, 68, 68, 0x301a,
139 #ifdef FRODO_SC
140 "!frodosc"
141 #else
142 # ifdef FRODO_PC
143 "!frodopc"
144 # else
145 "!frodo"
146 # endif
147 #endif
148 };
149
150
151
152
153
154 // The menus
155
156 char *MIBTextPrefs = "Preferences...";
157 char *MIBTextConf = "Configuration...";
158
159
160 struct MenuIconBar {
161 RO_MenuHead head;
162 RO_MenuItem item[Menu_IBar_Items];
163 } MenuIconBar = {
164 {
165 #ifdef FRODO_SC
166 "FrodoSC",
167 #else
168 # ifdef FRODO_PC
169 "FrodoPC",
170 # else
171 "Frodo",
172 # endif
173 #endif
174 7, 2, 7, 0, Menu_IBar_Width, Menu_Height, 0},
175 {
176 {0, (RO_MenuHead*)-1, Menu_Flags, "Info"},
177 {0, (RO_MenuHead*)-1, Menu_Flags + IFlg_Indir, ""},
178 {0, (RO_MenuHead*)-1, Menu_Flags + IFlg_Indir, ""},
179 {0, (RO_MenuHead*)-1, Menu_Flags, "Sound"},
180 {MFlg_LastItem, (RO_MenuHead*)-1, Menu_Flags, "Quit"}
181 }
182 };
183
184 struct MenuEmuWindow {
185 RO_MenuHead head;
186 RO_MenuItem item[Menu_EWind_Items];
187 } MenuEmuWindow = {
188 {
189 #ifdef FRODO_SC
190 "FrodoSC Job",
191 #else
192 # ifdef FRODO_PC
193 "FrodoPC Job",
194 # else
195 "Frodo Job",
196 # endif
197 #endif
198 7, 2, 7, 0, Menu_EWind_Width, Menu_Height, 0},
199 {
200 {0, (RO_MenuHead*)-1, Menu_Flags, "Info"},
201 {0, (RO_MenuHead*)-1, Menu_Flags, "Sound"},
202 {MFlg_Warning, (RO_MenuHead*)-1, Menu_Flags, "Save RAM"},
203 {MFlg_LastItem | MFlg_Warning, (RO_MenuHead*)-1, Menu_Flags, "Snapshot"}
204 }
205 };
206
207
208
209
210 // For less writing in LoadATemplate...
211 #define wic(base,no,off) base[RO_WINDOW_WORDS + no*RO_ICON_WORDS + off]
212
213 // For less writing in WindowToThePrefs...
214 #define pread_opt(var,icn) PrefsWindow->GetIconState(Icon_Prefs_##icn,AuxBlock);\
215 prefs->##var = ((AuxBlock[IconB_Flags] & IFlg_Slct) == 0) ? false : true;
216
217
218
219 //
220 // WIMP member-functions
221 //
222
223 WIMP::WIMP(C64 *my_c64)
224 {
225 int x,y,i;
226 WIdata *wid;
227
228 CMOS_DragType = ReadDragType();
229
230 // Determine the dimensions of the icon bar sprite first.
231 if (Wimp_SpriteInfo((char*)(&IBarIcon.dat),&x,&y,&i) == NULL)
232 {
233 IBarIcon.maxx = x << OS_ReadModeVariable(i,4);
234 IBarIcon.maxy = y << OS_ReadModeVariable(i,5);
235 }
236
237 IBicon = new Icon(0,&IBarIcon); Mask = 0x00000830;
238 LastMenu = LastClick = LastDrag = MenuType = DragType = 0;
239 UseScrap = false; EmuPaused = false; UseNULL = 0; // one NULL client - the emulator
240 the_c64 = my_c64;
241 EmuZoom = 1;
242
243 // Read the customized sprite area (LEDs etc)
244 if ((ReadCatalogueInfo(CUSTOM_SPRITES,AuxBlock) & 1) != 0) // (image) file
245 {
246 int i;
247 FILE *fp;
248
249 i = AuxBlock[2]; SpriteArea = (int*)(new char[i+16]); // allocate space for sprite
250 fp = fopen(CUSTOM_SPRITES,"rb");
251 i = fread(SpriteArea+1,1,i,fp); SpriteArea[0] = i+4;
252 fclose(fp);
253 }
254 else
255 {
256 WimpError.errnum = 0; sprintf(WimpError.errmess,"Can't read sprites!!!");
257 Wimp_ReportError(&WimpError,1,TASKNAME);
258 }
259
260 // Read Template and create windows
261 if (Wimp_OpenTemplate(TEMPLATES_FILE) == NULL)
262 {
263 // Load Pane first
264 LoadATemplate("EmuPane",&EmuPane);
265 LoadATemplate("EmuWindow",&EmuWindow);
266 LoadATemplate("ThePrefs",&PrefsWindow);
267 LoadATemplate("ConfigWind",&ConfigWindow);
268 LoadATemplate("InfoWindow",&InfoWindow);
269 LoadATemplate("SoundWindow",&SoundWindow);
270 LoadATemplate("SaveBox",&SaveBox);
271 }
272 else
273 {
274 Wimp_ReportError(&WimpError,1,TASKNAME);
275 WimpError.errnum = 0; sprintf(WimpError.errmess,"Error in Templates!!!");
276 }
277 Wimp_CloseTemplate();
278
279 // Add info window to icon bar menu
280 MenuIconBar.item[Menu_IBar_Info].submenu =
281 MenuEmuWindow.item[Menu_EWind_Info].submenu = (RO_MenuHead*)InfoWindow->MyHandle();
282 MenuIconBar.item[Menu_IBar_Sound].submenu =
283 MenuEmuWindow.item[Menu_EWind_Sound].submenu = (RO_MenuHead*)SoundWindow->MyHandle();
284 MenuEmuWindow.item[Menu_EWind_SaveRAM].submenu =
285 MenuEmuWindow.item[Menu_EWind_Snapshot].submenu = (RO_MenuHead*)SaveBox->MyHandle();
286 // I couldn't find ONE FUCKING WAY to do this in the initialisation directly and I'm
287 // REALLY PISSED OFF!
288 wid = &(MenuIconBar.item[Menu_IBar_Prefs].dat);
289 wid->ind.tit = (int*)MIBTextPrefs; wid->ind.val = NULL; wid->ind.len = sizeof(MIBTextPrefs);
290 wid = &(MenuIconBar.item[Menu_IBar_Config].dat);
291 wid->ind.tit = (int*)MIBTextConf; wid->ind.val = NULL; wid->ind.len = sizeof(MIBTextConf);
292
293 // Write default path into config window
294 ConfigWindow->WriteIconText(Icon_Conf_ConfPath,DEFAULT_SYSCONF);
295
296 // Set up the contents of the prefs window and init with the default prefs path
297 ThePrefsToWindow();
298 PrefsWindow->WriteIconText(Icon_Prefs_PrefPath,DEFAULT_PREFS);
299 // Grey out SID card icon -- not supported!
300 PrefsWindow->SetIconState(Icon_Prefs_SIDCard,IFlg_Grey,IFlg_Grey);
301
302 // Open Emulator window + pane in the center of the screen and give it the input focus
303 Wimp_GetCaretPosition(&LastCaret);
304 OpenEmuWindow();
305 Wimp_SetCaretPosition(EmuWindow->MyHandle(),-1,-100,100,-1,-1); // emu window gets input focus
306
307 // Init export files
308 sprintf(RAMFile+44,"C64_RAM"); sprintf(SnapFile+44,"FrodoSnap");
309 }
310
311
312 WIMP::~WIMP(void)
313 {
314 delete IBicon;
315 delete EmuWindow; delete EmuPane; delete PrefsWindow; delete ConfigWindow;
316 delete InfoWindow; delete SoundWindow; delete SaveBox;
317 }
318
319
320 bool WIMP::LoadATemplate(char *Name, Window **Which)
321 {
322 char *Buffer, *Indirect, *Desc;
323 int IndSize, Pos;
324 char TempName[12];
325
326 strncpy((char*)TempName,Name,12);
327 Buffer = NULL; Pos = 0;
328 if (Wimp_LoadTemplate(&Buffer,&Indirect,0,(char*)-1,TempName,&Pos) != NULL) {return(false);}
329 Buffer = new char[(int)Buffer + 4];
330 IndSize = (int)Indirect; Indirect = new char[IndSize];
331 Pos = 0; Desc = Buffer+4;
332 Wimp_LoadTemplate(&Desc,&Indirect,Indirect+IndSize,(char*)-1,TempName,&Pos);
333 if (Which == &EmuWindow)
334 {
335 int eigen, dx, dy;
336 RO_Window *row = (RO_Window*)Buffer;
337 RORes res;
338
339 // Center emulator window on screen
340 eigen = (res.eigx < res.eigy) ? res.eigx : res.eigy;
341 dx = (DISPLAY_X << eigen); dy = (DISPLAY_Y << eigen);
342 row->vminx = res.resx/2 - dx/2; row->vmaxx = row->vminx + dx;
343 row->vminy = res.resy/2 - dy/2; row->vmaxy = row->vminy + dy;
344 row->wminy = -dy; row->wmaxx = dx;
345 Indirect = (char*)VERSION_STRING;
346 }
347 else
348 {
349 if (Which == &EmuPane) // EmuPane needs customized sprites
350 {
351 register RO_Window *row = (RO_Window*)Buffer;
352 register int *b = (int*)Buffer;
353
354 // Insert sprite pointer in window and icon definitions
355 row->SpriteAreaPtr = (int)SpriteArea;
356 wic(b,Icon_Pane_LED0,RawIB_Data1) = wic(b,Icon_Pane_LED1,RawIB_Data1) =
357 wic(b,Icon_Pane_LED2,RawIB_Data1) = wic(b,Icon_Pane_LED3,RawIB_Data1) = (int)SpriteArea;
358 sprintf((char*)wic(b,Icon_Pane_Pause,RawIB_Data0),PANE_TEXT_PAUSE);
359 sprintf((char*)wic(b,Icon_Pane_Toggle,RawIB_Data0),PANE_TEXT_ZOOM2);
360 }
361 else if (Which == &SoundWindow) // ditto
362 {
363 register RO_Window *row = (RO_Window*)Buffer;
364 register int *b = (int*)Buffer;
365 register int orr;
366
367 row->SpriteAreaPtr = (int)SpriteArea;
368 // if sound emulation off grey out notes
369 if (ThePrefs.SIDType == SIDTYPE_NONE) {orr = IFlg_Grey;} else {orr = 0;}
370 wic(b,Icon_Sound_Notes,RawIB_Flags)=(wic(b,Icon_Sound_Notes,RawIB_Flags)&~IFlg_Grey)|orr;
371 }
372 else if (Which == &InfoWindow) // ditto
373 {
374 register RO_Window *row = (RO_Window*)Buffer;
375
376 row->SpriteAreaPtr = (int)SpriteArea;
377 }
378 Indirect = NULL;
379 }
380 *Which = new Window((int*)Buffer,Indirect);
381 return(true);
382 }
383
384
385 // All changes in position of the Emulator window have to be treated seperately
386 // to keep the pane attached to it at all times!
387 void WIMP::OpenEmuWindow(void)
388 {
389 RO_Window *wind;
390 int work[WindowB_WFlags], i;
391
392 wind = EmuWindow->Descriptor();
393 EmuPane->GetWorkArea(&work[WindowB_VMinX]); i = work[WindowB_VMaxX] - work[WindowB_VMinX];
394 if ((work[WindowB_VMinX] = wind->vminx - EmuPaneSpace - i) < 0)
395 {
396 // if main window still on screen then keep pane on screen as well
397 if (wind->vminx >= 0) {work[WindowB_VMinX] = 0;}
398 // otherwise align pane and main window on the left
399 else {work[WindowB_VMinX] = wind->vminx;}
400 }
401 work[WindowB_VMaxX] = work[WindowB_VMinX] + i;
402 work[WindowB_VMinY] = wind->vmaxy - (work[WindowB_VMaxY]-work[WindowB_VMinY]);
403 work[WindowB_VMaxY] = wind->vmaxy;
404 work[WindowB_Handle] = EmuPane->MyHandle();
405 work[WindowB_ScrollX] = work[WindowB_ScrollY] = 0;
406 work[WindowB_Stackpos] = -1; // open on top of stack
407 // open the pane first
408 EmuPane->open(work);
409 wind->stackpos = EmuPane->MyHandle(); // open window behind pane.
410 EmuWindow->open();
411 }
412
413
414 void WIMP::OpenEmuWindow(int *Where)
415 {
416 int work[WindowB_WFlags], i;
417
418 EmuPane->GetWorkArea(&work[WindowB_VMinX]); i = work[WindowB_VMaxX] - work[WindowB_VMinX];
419 if ((work[WindowB_VMinX] = Where[WindowB_VMinX] - EmuPaneSpace - i) < 0)
420 {
421 if (Where[WindowB_VMinX] >= 0) {work[WindowB_VMinX] = 0;}
422 else {work[WindowB_VMinX] = Where[WindowB_VMinX];}
423 }
424 work[WindowB_VMaxX] = work[WindowB_VMinX] + i;
425 work[WindowB_VMinY] = Where[WindowB_VMaxY] - (work[WindowB_VMaxY]-work[WindowB_VMinY]);
426 work[WindowB_VMaxY] = Where[WindowB_VMaxY];
427 work[WindowB_Handle] = EmuPane->MyHandle();
428 work[WindowB_ScrollX] = work[WindowB_ScrollY] = 0;
429 work[WindowB_Stackpos] = Where[WindowB_Stackpos];
430 // open the pane first
431 EmuPane->open(work);
432 Where[WindowB_Stackpos] = EmuPane->MyHandle(); // open window behind pane
433 EmuWindow->open(Where);
434 }
435
436
437 void WIMP::CloseEmuWindow(void)
438 {
439 EmuWindow->close(); EmuPane->close();
440 }
441
442
443 void WIMP::UpdateEmuWindow(void)
444 {
445 C64Display *disp = the_c64->TheDisplay;
446
447 EmuWindow->update(disp->BitmapBase(),disp);
448 }
449
450
451 // Write the values given in ThePrefs into the Prefs Window
452 void WIMP::ThePrefsToWindow(void)
453 {
454 int i, j, k;
455
456 // Update the data for each of the drives
457 for (i=0; i<4; i++)
458 {
459 switch(ThePrefs.DriveType[i])
460 {
461 case DRVTYPE_D64: j=1; break;
462 case DRVTYPE_T64: j=2; break;
463 default: j=0; break; // otherwise type 0 = DIR
464 }
465 // unselect all but other icons
466 for (k=0; k<3; k++)
467 {
468 if (k != j) {PrefsWindow->SetIconState(DriveToIcon[i*IconsPerDrive + k],0,IFlg_Slct);}
469 }
470 // and select the correct one.
471 PrefsWindow->SetIconState(DriveToIcon[i*IconsPerDrive + j],IFlg_Slct,IFlg_Slct);
472 // Now update the path name (buffer won't change, i.e. use original data)
473 PrefsWindow->WriteIconText(DriveToIcon[i*IconsPerDrive + 3],ThePrefs.DrivePath[i]);
474 }
475 if (ThePrefs.Emul1541Proc) {i = IFlg_Slct;} else {i = 0;}
476 PrefsWindow->SetIconState(Icon_Prefs_Emul1541,i,IFlg_Slct);
477 SetLEDIcons(ThePrefs.Emul1541Proc);
478 if (ThePrefs.MapSlash) {i = IFlg_Slct;} else {i = 0;}
479 PrefsWindow->SetIconState(Icon_Prefs_MapSlash,i,IFlg_Slct);
480
481 // SID prefs
482 switch (ThePrefs.SIDType)
483 {
484 case SIDTYPE_DIGITAL: i = 1; break;
485 case SIDTYPE_SIDCARD: i = 2; break;
486 default: i = 0; break; // includes NONE
487 }
488 for (j=0; j<3; j++)
489 {
490 if (j != i) {PrefsWindow->SetIconState(SIDtoIcon[j],0,IFlg_Slct);}
491 }
492 PrefsWindow->SetIconState(SIDtoIcon[i],IFlg_Slct,IFlg_Slct);
493 PrefsWindow->SetIconState(Icon_Prefs_SIDFilter,(ThePrefs.SIDFilters)?IFlg_Slct:0,IFlg_Slct);
494
495 // REU prefs
496 switch (ThePrefs.REUSize)
497 {
498 case REU_128K: i=1; break;
499 case REU_256K: i=2; break;
500 case REU_512K: i=3; break;
501 default: i=0; break;
502 }
503 for (j=0; j<4; j++)
504 {
505 if (j != i) {PrefsWindow->SetIconState(REUtoIcon[j],0,IFlg_Slct);}
506 }
507 PrefsWindow->SetIconState(REUtoIcon[i],IFlg_Slct,IFlg_Slct);
508
509 // Skip Frames
510 PrefsWindow->WriteIconNumber(Icon_Prefs_SkipFText,ThePrefs.SkipFrames);
511
512 // Sprites
513 PrefsWindow->SetIconState(Icon_Prefs_SprOn,(ThePrefs.SpritesOn)?IFlg_Slct:0,IFlg_Slct);
514 PrefsWindow->SetIconState(Icon_Prefs_SprColl,(ThePrefs.SpriteCollisions)?IFlg_Slct:0,IFlg_Slct);
515 // Joystick
516 PrefsWindow->SetIconState(Icon_Prefs_Joy1On,(ThePrefs.Joystick1On)?IFlg_Slct:0,IFlg_Slct);
517 PrefsWindow->SetIconState(Icon_Prefs_Joy2On,(ThePrefs.Joystick2On)?IFlg_Slct:0,IFlg_Slct);
518 PrefsWindow->SetIconState(Icon_Prefs_JoySwap,(ThePrefs.JoystickSwap)?IFlg_Slct:0,IFlg_Slct);
519
520 // Misc
521 SetSpeedLimiter(ThePrefs.LimitSpeed);
522 PrefsWindow->SetIconState(Icon_Prefs_FastReset,(ThePrefs.FastReset)?IFlg_Slct:0,IFlg_Slct);
523 PrefsWindow->SetIconState(Icon_Prefs_CIAHack,(ThePrefs.CIAIRQHack)?IFlg_Slct:0,IFlg_Slct);
524
525 // Cycles
526 PrefsWindow->WriteIconNumber(Icon_Prefs_CycleNorm,ThePrefs.NormalCycles);
527 PrefsWindow->WriteIconNumber(Icon_Prefs_CycleBad,ThePrefs.BadLineCycles);
528 PrefsWindow->WriteIconNumber(Icon_Prefs_CycleCIA,ThePrefs.CIACycles);
529 PrefsWindow->WriteIconNumber(Icon_Prefs_CycleFloppy,ThePrefs.FloppyCycles);
530 }
531
532
533 // Update ThePrefs according to the values given in the Prefs Window
534 void WIMP::WindowToThePrefs(void)
535 {
536 int i, j, k;
537 Prefs *prefs = new Prefs(ThePrefs);
538
539 for (i=0; i<4; i++)
540 {
541 // find out which of the drive type icons is selected
542 j = -1;
543 do
544 {
545 ++j; PrefsWindow->GetIconState(DriveToIcon[i*IconsPerDrive + j],AuxBlock);
546 }
547 while ((j < 3) && ((AuxBlock[IconB_Flags] & IFlg_Slct) == 0));
548 switch (j)
549 {
550 case 1: prefs->DriveType[i] = DRVTYPE_D64; break;
551 case 2: prefs->DriveType[i] = DRVTYPE_T64; break;
552 default: prefs->DriveType[i] = DRVTYPE_DIR; break;
553 }
554 strcpy(prefs->DrivePath[i],PrefsWindow->ReadIconText(DriveToIcon[i*IconsPerDrive + 3]));
555 }
556 // Emulation of the 1541 processor is a special case as it also affects LED1-3
557 pread_opt(Emul1541Proc,Emul1541);
558 SetLEDIcons(prefs->Emul1541Proc);
559 pread_opt(MapSlash,MapSlash);
560
561 // SID
562 j = -1;
563 do
564 {
565 ++j; PrefsWindow->GetIconState(SIDtoIcon[j],AuxBlock);
566 }
567 while ((j < 3) && ((AuxBlock[IconB_Flags] & IFlg_Slct) == 0));
568 switch (j)
569 {
570 case 1: prefs->SIDType = SIDTYPE_DIGITAL; break;
571 case 2: prefs->SIDType = SIDTYPE_SIDCARD; break;
572 default: prefs->SIDType = SIDTYPE_NONE; break;
573 }
574 pread_opt(SIDFilters,SIDFilter);
575 SoundWindow->SetIconState(Icon_Sound_Notes,(prefs->SIDType==SIDTYPE_NONE)?IFlg_Grey:0,IFlg_Grey);
576
577 // REU
578 j = -1;
579 do
580 {
581 ++j; PrefsWindow->GetIconState(REUtoIcon[j],AuxBlock);
582 }
583 while ((j < 4) && ((AuxBlock[IconB_Flags] & IFlg_Slct) == 0));
584 switch (j)
585 {
586 case 1: prefs->REUSize = REU_128K; break;
587 case 2: prefs->REUSize = REU_256K; break;
588 case 3: prefs->REUSize = REU_512K; break;
589 default: prefs->REUSize = REU_NONE; break;
590 }
591
592 // Skip Frames
593 prefs->SkipFrames = PrefsWindow->ReadIconNumber(Icon_Prefs_SkipFText);
594
595 // Sprites
596 pread_opt(SpritesOn,SprOn); pread_opt(SpriteCollisions,SprColl);
597
598 // Joystick
599 pread_opt(Joystick1On,Joy1On); pread_opt(Joystick2On,Joy2On); pread_opt(JoystickSwap,JoySwap);
600
601 // Misc
602 pread_opt(LimitSpeed,LimSpeed); pread_opt(FastReset,FastReset); pread_opt(CIAIRQHack,CIAHack);
603
604 // Cycles
605 prefs->NormalCycles = PrefsWindow->ReadIconNumber(Icon_Prefs_CycleNorm);
606 prefs->BadLineCycles = PrefsWindow->ReadIconNumber(Icon_Prefs_CycleBad);
607 prefs->CIACycles = PrefsWindow->ReadIconNumber(Icon_Prefs_CycleCIA);
608 prefs->FloppyCycles = PrefsWindow->ReadIconNumber(Icon_Prefs_CycleFloppy);
609
610 // Finally make the changes known to the system:
611 the_c64->NewPrefs(prefs);
612 ThePrefs = *prefs;
613 delete prefs;
614 }
615
616
617 // Update the SysConfig window according to the values used
618 void WIMP::SysConfToWindow(void)
619 {
620 int i, j, k;
621 Joy_Keys *jk;
622 char OneChar[2], *b;
623
624 OneChar[1] = 0;
625
626 // Write timings
627 the_c64->ReadTimings(&i,&j,&k);
628 ConfigWindow->WriteIconNumber(Icon_Conf_PollAfter, i);
629 ConfigWindow->WriteIconNumber(Icon_Conf_SpeedAfter, j);
630 ConfigWindow->WriteIconNumber(Icon_Conf_SoundAfter, k);
631
632 // Write joystick keys
633 for (i=0; i<2; i++)
634 {
635 jk = &(the_c64->TheDisplay->JoystickKeys[i]); NewJoyKeys[i] = *jk;
636 if ((j = jk->up) >= 128) {j = 127;}
637 j = IntKeyTable[j]; if (j < 256) {OneChar[0] = j; b = OneChar;} else {b = (char*)j;}
638 ConfigWindow->WriteIconText(KJoyToIcon[i][0], b);
639 if ((j = jk->down) >= 128) {j = 127;}
640 j = IntKeyTable[j]; if (j < 256) {OneChar[0] = j; b = OneChar;} else {b = (char*)j;}
641 ConfigWindow->WriteIconText(KJoyToIcon[i][1], b);
642 if ((j = jk->left) >= 128) {j = 127;}
643 j = IntKeyTable[j]; if (j < 256) {OneChar[0] = j; b = OneChar;} else {b = (char*)j;}
644 ConfigWindow->WriteIconText(KJoyToIcon[i][2], b);
645 if ((j = jk->right) >= 128) {j = 127;}
646 j = IntKeyTable[j]; if (j < 256) {OneChar[0] = j; b = OneChar;} else {b = (char*)j;}
647 ConfigWindow->WriteIconText(KJoyToIcon[i][3], b);
648 if ((j = jk->fire) >= 128) {j = 127;}
649 j = IntKeyTable[j]; if (j < 256) {OneChar[0] = j; b = OneChar;} else {b = (char*)j;}
650 ConfigWindow->WriteIconText(KJoyToIcon[i][4], b);
651 }
652 }
653
654
655 // Update SysConfig according to the values in the window
656 void WIMP::WindowToSysConf(void)
657 {
658 int i, j, k;
659 Joy_Keys *jk;
660
661 // Read timings
662 i = ConfigWindow->ReadIconNumber(Icon_Conf_PollAfter);
663 j = ConfigWindow->ReadIconNumber(Icon_Conf_SpeedAfter);
664 k = ConfigWindow->ReadIconNumber(Icon_Conf_SoundAfter);
665 the_c64->WriteTimings(i,j,k);
666
667 // Read joystick keys
668 for (i=0; i<2; i++)
669 {
670 jk = &(the_c64->TheDisplay->JoystickKeys[i]); *jk = NewJoyKeys[i];
671 }
672 }
673
674
675 // Low-level keyboard scan in SysConfig Window
676 void WIMP::PollSysConfWindow(void)
677 {
678 Wimp_GetPointerInfo(Block);
679 if (Block[MouseB_Window] == ConfigWindow->MyHandle())
680 {
681 int i, j;
682
683 for (i=0; i<2; i++)
684 {
685 for (j=0; j<5; j++)
686 {
687 if (Block[MouseB_Icon] == KJoyToIcon[i][j])
688 {
689 int key;
690
691 // Gain caret (to window, but none of its icons!)
692 Wimp_GetCaretPosition(&LastCaret);
693 Wimp_SetCaretPosition(ConfigWindow->MyHandle(),-1,0,0,-1,-1);
694 if ((key = ScanKeys(IntKey_ScanFrom)) != 0xff)
695 {
696 char OneChar[2], *b;
697
698 if (key == IntKey_Void) {key = 0xff;}
699 switch (j)
700 {
701 case 0: NewJoyKeys[i].up = key; break;
702 case 1: NewJoyKeys[i].down = key; break;
703 case 2: NewJoyKeys[i].left = key; break;
704 case 3: NewJoyKeys[i].right = key; break;
705 case 4: NewJoyKeys[i].fire = key; break;
706 }
707 if (key >= 128) {key = 127;}
708 key = IntKeyTable[key];
709 if (key < 256) {OneChar[0]=key; OneChar[1]=0; b=OneChar;} else {b=(char*)key;}
710 ConfigWindow->WriteIconText(KJoyToIcon[i][j], b);
711 }
712 }
713 }
714 }
715 }
716 }
717
718
719 // Start a drag operation on the icon <number> in the window <host>
720 void WIMP::DragIconSprite(Window *host, unsigned int number)
721 {
722 host->GetIconState(number,AuxBlock);
723 if ((AuxBlock[IconB_Flags] & IFlg_Sprite) != 0) // it needs to have a sprite, of course
724 {
725 char spritename[16] = "\0";
726
727 if ((AuxBlock[IconB_Flags] & IFlg_Indir) == 0) // not indirected
728 {
729 strncpy(spritename,((char*)AuxBlock+IconB_Data0),15);
730 }
731 else
732 {
733 if ((AuxBlock[IconB_Flags] & IFlg_Text) == 0)
734 {
735 strncpy(spritename,(char*)AuxBlock[IconB_Data0],15);
736 }
737 else // this necessitates parsing the validation string
738 {
739 register char *b, *d, *s, c;
740
741 s = spritename;
742 if ((b = (char*)AuxBlock[IconB_Data1]) != NULL) // pointer to val str
743 {
744 do
745 {
746 c = *b++;
747 if ((c == 's') || (c == 'S')) // sprite command
748 {
749 c = *b++; while ((c != ';') && (c >= 32)) {*s++ = c; c = *b++;}
750 c = 0; *s++ = c; // we can stop now
751 }
752 else if (c >= 32) // some other command ==> skip to next.
753 {
754 c = *b++;
755 while ((c != ';') && (c >= 32)) {if (c == '\\') {b++;} c = *b++;}
756 }
757 }
758 while (c >= 32);
759 }
760 }
761 }
762 // we should now have the spritename
763 if (spritename[0] != '\0')
764 {
765 LastDrag = host->MyHandle(); LastIcon = number;
766 if (CMOS_DragType == 0) // Drag outline
767 {
768 ROScreen *screen = the_c64->TheDisplay->screen;
769
770 AuxBlock[DragB_Handle] = LastDrag; AuxBlock[DragB_Type] = 5;
771 Wimp_GetPointerInfo(AuxBlock + DragB_IMinX);
772 // Drag fixed sized box of this size:
773 AuxBlock[DragB_IMinX] -= IconSpriteSize/2;
774 AuxBlock[DragB_IMaxX] = AuxBlock[DragB_IMinX] + IconSpriteSize;
775 AuxBlock[DragB_IMinY] -= IconSpriteSize/2;
776 AuxBlock[DragB_IMaxY] = AuxBlock[DragB_IMinY] + IconSpriteSize;
777 // Parent box is whole screen
778 AuxBlock[DragB_BBMinX] = AuxBlock[DragB_BBMinY] = 0;
779 AuxBlock[DragB_BBMaxX] = screen->resx; AuxBlock[DragB_BBMaxY] = screen->resy;
780 Wimp_DragBox(AuxBlock);
781 }
782 else // DragASprite
783 {
784 Wimp_GetPointerInfo(AuxBlock);
785 AuxBlock[DASB_MinX] -= IconSpriteSize/2;
786 AuxBlock[DASB_MaxX] = AuxBlock[DASB_MinX] + IconSpriteSize;
787 AuxBlock[DASB_MinY] -= IconSpriteSize/2;
788 AuxBlock[DASB_MaxY] = AuxBlock[DASB_MinY] + IconSpriteSize;
789 DragASprite_Start(0xc5,1,spritename,AuxBlock,NULL);
790 }
791 }
792 }
793 }
794
795
796 // Blk is a block as in MouseClick or PointerInfo
797 int WIMP::CalculateVolume(int *Blk)
798 {
799 int orgx, vol;
800
801 SoundWindow->getstate(AuxBlock);
802 orgx = AuxBlock[WindowB_VMinX] - AuxBlock[WindowB_ScrollX];
803 SoundWindow->GetIconState(Icon_Sound_Volume, AuxBlock);
804 vol = (MaximumVolume*((Blk[MouseB_PosX] - orgx) - AuxBlock[IconB_MinX] - WellBorder)) / (AuxBlock[IconB_MaxX] - AuxBlock[IconB_MinX] - 2*WellBorder);
805 if (vol < 0) {vol = 0;} if (vol > MaximumVolume) {vol = MaximumVolume;}
806 return(vol);
807 }
808
809
810 // Check whether a filename contains a full pathname and reports an error if not.
811 int WIMP::CheckFilename(char *name)
812 {
813 bool OK = false;
814 register char *b, *d, c;
815
816 b = d = name; c = *b++;
817 while (c > 32)
818 {
819 // valid path must contain '$' or ':'
820 if ((c == '$') || (c == ':')) {OK = true; d = b;}
821 if (c == '.') {d = b;}
822 c = *b++;
823 }
824 if ((b - d) == 1) {OK = false;} // filename mustn't end with '$', ':' or '.'
825 if (OK) {return(0);}
826
827 WimpError.errnum = 0; sprintf(WimpError.errmess,"Bad filename %s",name);
828 Wimp_ReportError(&WimpError,1,TASKNAME);
829 return(-1);
830 }
831
832
833 void WIMP::SnapshotSaved(bool OK)
834 {
835 if (OK)
836 {
837 int *b = (int*)SnapFile;
838
839 if (b[MsgB_Sender] != 0)
840 {
841 b[MsgB_YourRef] = b[MsgB_MyRef]; b[MsgB_Action] = Message_DataLoad;
842 Wimp_SendMessage(18,b,b[MsgB_Sender],b[6]);
843 }
844 else {Wimp_CreateMenu((int*)-1,0,0);}
845 SaveType = 0;
846 }
847 }
848
849
850 void WIMP::IssueSnapshotRequest(void)
851 {
852 if (EmuPaused)
853 {
854 EmuPane->WriteIconTextU(Icon_Pane_Pause, PANE_TEXT_PAUSE);
855 EmuPaused = false;
856 }
857 the_c64->RequestSnapshot();
858 }
859
860
861 // Sets the Emu pane's LEDs according to the floppy emulation state
862 void WIMP::SetLEDIcons(bool FloppyEmulation)
863 {
864 int i, eor;
865
866 if (FloppyEmulation) {eor = IFlg_Grey;} else {eor = 0;}
867 for (i=1; i<4; i++)
868 {
869 EmuPane->SetIconState(LEDtoIcon[i],eor,IFlg_Grey);
870 }
871 }
872
873
874
875 // Doesn't open window, just resizes...
876 void WIMP::SetEmuWindowSize(void)
877 {
878 register int i;
879 register C64Display *disp = the_c64->TheDisplay;
880
881 i = (disp->screen->eigx < disp->screen->eigy) ? disp->screen->eigx : disp->screen->eigy;
882 if (EmuZoom == 2) {i++;}
883 EmuWindow->extent(0,-(DISPLAY_Y << i),(DISPLAY_X << i),0);
884 }
885
886
887
888 // switch between zoom 1 and zoom 2
889 void WIMP::ToggleEmuWindowSize(void)
890 {
891 int x,y;
892
893 // Icon in pane shows _alternative_ zoom mode
894 if (EmuZoom == 1)
895 {
896 EmuZoom = 2;
897 EmuPane->WriteIconText(Icon_Pane_Toggle,"1 x");
898 }
899 else
900 {
901 EmuZoom = 1;
902 EmuPane->WriteIconText(Icon_Pane_Toggle,"2 x");
903 }
904 SetEmuWindowSize();
905 EmuWindow->GetWorkArea(AuxBlock);
906 x = AuxBlock[2] - AuxBlock[0]; y = AuxBlock[3] - AuxBlock[1];
907 EmuWindow->getstate(AuxBlock);
908 AuxBlock[WindowB_VMaxX] = AuxBlock[WindowB_VMinX] + x;
909 AuxBlock[WindowB_VMinY] = AuxBlock[WindowB_VMaxY] - y;
910 // Open emu window alone to get the dimensions set by the WIMP
911 Wimp_OpenWindow(AuxBlock);
912 // Then open with the pane at the correct position
913 EmuWindow->getstate(AuxBlock); OpenEmuWindow(AuxBlock); UpdateEmuWindow();
914 }
915
916
917
918 int WIMP::ReadEmuWindowSize(void)
919 {
920 return EmuZoom;
921 }
922
923
924
925 // Set a new drive path for drive DrNum. MsgBlock is the DataLoad MessageBlock.
926 void WIMP::NewDriveImage(int DrNum, int *MsgBlock, bool SetNow)
927 {
928 int type, j = -1, map = -1;
929
930 // determine currently selected type
931 do
932 {
933 ++j; PrefsWindow->GetIconState(DriveToIcon[DrNum*IconsPerDrive + j], AuxBlock);
934 }
935 while ((j < 3) && ((AuxBlock[6] & IFlg_Slct) == 0));
936 if (j >= 3) {j = 0;}
937 // Check the type and set the drive type accordingly
938 type = ReadCatalogueInfo(((char*)Block)+44,AuxBlock);
939 // New path is directory but DRVTYPE != DIR ==> set DIR
940 if ((type == 2) && (j != 0)) {map = 0;}
941 // New path is not directory/image but DRVTYPE == DIR ==> remap to D64
942 if (((type & 2) == 0) && (j == 0)) {map = 1;}
943 // Filetype indicated D64 image?
944 if (((type = AuxBlock[0]) & 0xfff00000) == 0xfff00000) // typed file
945 {
946 type = (type >> 8) & 0xfff;
947 // D64 image can also be used in DIR mode (-> D64ImageFS). Only remap from T64!
948 if ((type == FileType_D64File) && (j == 2)) {map = 1;}
949 }
950 // Do we need to remap?
951 if (map >= 0)
952 {
953 PrefsWindow->SetIconState(DriveToIcon[DrNum*IconsPerDrive+j],0,IFlg_Slct);
954 PrefsWindow->SetIconState(DriveToIcon[DrNum*IconsPerDrive+map],IFlg_Slct,IFlg_Slct);
955 j = map;
956 }
957 // j is the number of the emulation mode (DIR (0), D64 (1), T64 (2))
958 PrefsWindow->WriteIconText(DriveToIcon[DrNum*IconsPerDrive+3],((char*)Block)+44);
959 // Send acknowledge message
960 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoadAck;
961 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
962
963 // Set this drive path immediately?
964 if (SetNow)
965 {
966 Prefs *prefs = new Prefs(ThePrefs);
967
968 prefs->DriveType[DrNum] = j; strcpy(prefs->DrivePath[DrNum],((char*)Block)+44);
969 the_c64->NewPrefs(prefs);
970 ThePrefs = *prefs;
971 delete prefs;
972 }
973 }
974
975
976
977 void WIMP::SetSpeedLimiter(bool LimitSpeed)
978 {
979 RO_Icon *roi;
980 char *b, c;
981
982 PrefsWindow->SetIconState(Icon_Prefs_LimSpeed,(LimitSpeed) ? IFlg_Slct : 0, IFlg_Slct);
983 roi = EmuPane->GetIcon(Icon_Pane_Speed);
984 if ((b = (char*)roi->dat.ind.val) != NULL)
985 {
986 do
987 {
988 c = *b++;
989 if ((c == 'r') || (c == 'R')) // boRder command?
990 {
991 if (LimitSpeed) {*b++ = '1';} else {*b++ = '2';}
992 c = 0; // stop now
993 }
994 else if (c >= 32) // skip to next command
995 {
996 c = *b++;
997 while ((c >= 32) && (c != ';')) {if (c == '\\') {b++;} c = *b++;}
998 }
999 }
1000 while (c >= 32);
1001 EmuPane->UpdateIcon(Icon_Pane_Speed);
1002 }
1003 }
1004
1005
1006
1007
1008
1009 void WIMP::Poll(bool Paused)
1010 {
1011 int event;
1012 bool LastPause;
1013
1014 LastPause = EmuPaused; EmuPaused = Paused;
1015
1016 // If emulator is paused disable null events
1017 if ((!EmuPaused) || (UseNULL > 0)) {Mask &= 0xfffffffe;} else {Mask |= 1;}
1018
1019 do
1020 {
1021 // Loop until a null event is received, then continue the emulation.
1022 // (this looks best)
1023 do
1024 {
1025 event = Wimp_Poll(Mask,Block,NULL);
1026 switch (event)
1027 {
1028 case 1: Redraw(); break;
1029 case 2: OpenWindow(); break;
1030 case 3: CloseWindow(); break;
1031 case 6: MouseClick(); break;
1032 case 7: UserDrag(); break;
1033 case 8: if ((EmuPaused) && (Block[KeyPB_Window] == EmuWindow->MyHandle()))
1034 {
1035 if (the_c64->TheDisplay->CheckForUnpause(!LastPause)) {EmuPaused = false;}
1036 }
1037 KeyPressed(); break;
1038 case 9: MenuSelection(); break;
1039 case 17:
1040 case 18: UserMessage(); break;
1041 case 19: UserMessageAck(); break;
1042 default: break;
1043 }
1044 // This is important
1045 if ((!EmuPaused) || (UseNULL > 0)) {Mask &= 0xfffffffe;} else {Mask |= 1;}
1046 LastPause = EmuPaused;
1047 }
1048 while (event != 0);
1049 if (UseNULL > 0) {PollSysConfWindow();}
1050 // This should probably become a new member-function one day...
1051 if (DragType == DRAG_VolumeWell)
1052 {
1053 Wimp_GetPointerInfo(Block);
1054 if (Block[MouseB_Icon] == Icon_Sound_Volume) // should always be the case (BBox)!
1055 {
1056 the_c64->HostVolume = CalculateVolume(Block);
1057 SoundWindow->ForceIconRedraw(Icon_Sound_Volume);
1058 }
1059 }
1060 }
1061 while (EmuPaused);
1062 }
1063
1064
1065 void WIMP::Redraw(void)
1066 {
1067 if (Block[RedrawB_Handle] == EmuWindow->MyHandle()) // emulator main window
1068 {
1069 C64Display *disp = the_c64->TheDisplay;
1070
1071 EmuWindow->redraw(Block,disp->BitmapBase(),disp);
1072 }
1073 else if (Block[RedrawB_Handle] == SoundWindow->MyHandle()) // sound window
1074 {
1075 int more;
1076 int minx, miny, maxx, maxy, thresh;
1077
1078 more = Wimp_RedrawWindow(Block);
1079 // compute screen coordinates of work (0,0)
1080 minx = Block[RedrawB_VMinX] - Block[RedrawB_ScrollX];
1081 maxy = Block[RedrawB_VMaxY] - Block[RedrawB_ScrollY];
1082 // get volume well bounding box
1083 SoundWindow->GetIconState(Icon_Sound_Volume, AuxBlock);
1084 maxx = minx + AuxBlock[IconB_MaxX] - WellBorder; minx += AuxBlock[IconB_MinX] + WellBorder;
1085 miny = maxy + AuxBlock[IconB_MinY] + WellBorder; maxy += AuxBlock[IconB_MaxY] - WellBorder;
1086 thresh = minx + (the_c64->HostVolume * (maxx - minx))/ MaximumVolume;
1087 while (more != 0)
1088 {
1089 // clip
1090 if ((minx <= Block[RedrawB_CMaxX]) && (maxx >= Block[RedrawB_CMinX]) &&
1091 (miny <= Block[RedrawB_CMaxY]) && (maxy >= Block[RedrawB_CMinY]))
1092 {
1093 if (Block[RedrawB_CMinX] < thresh)
1094 {
1095 ColourTrans_SetGCOL(0x00ff0000,0,0); // green
1096 OS_Plot(0x04,minx,miny); OS_Plot(0x65,thresh,maxy);
1097 }
1098 if (Block[RedrawB_CMaxX] > thresh)
1099 {
1100 ColourTrans_SetGCOL(0xffffff00,0,0); // white
1101 OS_Plot(0x04,thresh,miny); OS_Plot(0x65,maxx,maxy);
1102 }
1103 }
1104 more = Wimp_GetRectangle(Block);
1105 }
1106 }
1107 else // Dummy redraw loop
1108 {
1109 int more;
1110
1111 more = Wimp_RedrawWindow(Block);
1112 while (more != 0)
1113 {
1114 more = Wimp_GetRectangle(Block);
1115 }
1116 }
1117 }
1118
1119
1120 void WIMP::OpenWindow(void)
1121 {
1122 if (Block[WindowB_Handle] == EmuWindow->MyHandle()) {OpenEmuWindow(Block);}
1123 else if (Block[WindowB_Handle] != EmuPane->MyHandle())
1124 {
1125 Wimp_OpenWindow(Block);
1126 }
1127 }
1128
1129
1130 void WIMP::CloseWindow(void)
1131 {
1132 if (Block[WindowB_Handle] == EmuWindow->MyHandle()) {CloseEmuWindow();}
1133 else if (Block[WindowB_Handle] != EmuPane->MyHandle())
1134 {
1135 if (Block[WindowB_Handle] == ConfigWindow->MyHandle()) {UseNULL--;}
1136 Wimp_CloseWindow(Block);
1137 }
1138 }
1139
1140
1141 void WIMP::MouseClick(void)
1142 {
1143 if ((Block[MouseB_Window] == -2) && (Block[MouseB_Icon] == IBicon->IHandle)) // Icon Bar icon
1144 {
1145 if (Block[MouseB_Buttons] == 2) // Menu
1146 {
1147 Wimp_CreateMenu((int*)&MenuIconBar,Block[MouseB_PosX]-MenuIconBar.head.width/2,96+Menu_Height*Menu_IBar_Items);
1148 LastMenu = Menu_IBar;
1149 }
1150 else // Some other click
1151 {
1152 if (!EmuWindow->OpenStatus(Block)) {Block[WindowB_Stackpos] = -1; OpenEmuWindow(Block);}
1153 }
1154 }
1155 else if (Block[MouseB_Window] == EmuWindow->MyHandle()) // Emulator window
1156 {
1157 if (Block[MouseB_Buttons] >= 256) // click
1158 {
1159 Wimp_GetCaretPosition(&LastCaret);
1160 Wimp_SetCaretPosition(Block[MouseB_Window],-1,-100,100,-1,-1); // gain input focus
1161 }
1162 if (Block[MouseB_Buttons] == 2) // menu
1163 {
1164 Wimp_CreateMenu((int*)&MenuEmuWindow,Block[MouseB_PosX]-MenuEmuWindow.head.width/2,Block[MouseB_PosY]);
1165 LastMenu = Menu_Emulator;
1166 }
1167 }
1168 else if (Block[MouseB_Window] == EmuPane->MyHandle()) // Emulator pane
1169 {
1170 if ((Block[MouseB_Buttons] == 1) || (Block[MouseB_Buttons] == 4))
1171 {
1172 switch (Block[MouseB_Icon])
1173 {
1174 case Icon_Pane_Pause: // Pause icon
1175 if (EmuPaused)
1176 {
1177 EmuPane->WriteIconText(Icon_Pane_Pause,PANE_TEXT_PAUSE);
1178 the_c64->Resume(); EmuPaused = false;
1179 }
1180 else
1181 {
1182 EmuPane->WriteIconText(Icon_Pane_Pause,PANE_TEXT_RESUME);
1183 the_c64->Pause(); EmuPaused = true;
1184 // Update the window now!
1185 UpdateEmuWindow();
1186 }
1187 break;
1188 case Icon_Pane_Reset: the_c64->Reset(); break;
1189 case Icon_Pane_Toggle: ToggleEmuWindowSize(); break;
1190 case Icon_Pane_Speed:
1191 ThePrefs.LimitSpeed = !ThePrefs.LimitSpeed; SetSpeedLimiter(ThePrefs.LimitSpeed);
1192 break;
1193 default: break;
1194 }
1195 }
1196 }
1197 else if (Block[MouseB_Window] == PrefsWindow->MyHandle()) // Prefs window
1198 {
1199 if ((Block[MouseB_Buttons] == 1) || (Block[MouseB_Buttons] == 4)) // normal click
1200 {
1201 register int i;
1202
1203 switch(Block[MouseB_Icon])
1204 {
1205 case Icon_Prefs_SkipFLeft:
1206 i = PrefsWindow->ReadIconNumber(Icon_Prefs_SkipFText);
1207 if (i > 0)
1208 {
1209 PrefsWindow->WriteIconNumber(Icon_Prefs_SkipFText,--i);
1210 ThePrefs.SkipFrames = i; // instant update
1211 }
1212 break;
1213 case Icon_Prefs_SkipFRight:
1214 i = PrefsWindow->ReadIconNumber(Icon_Prefs_SkipFText);
1215 PrefsWindow->WriteIconNumber(Icon_Prefs_SkipFText,++i);
1216 ThePrefs.SkipFrames = i; // instant update
1217 break;
1218 case Icon_Prefs_Cancel: ThePrefsToWindow(); break; // restore current settings
1219 case Icon_Prefs_OK: WindowToThePrefs();
1220 if (Block[MouseB_Buttons] == 4) {PrefsWindow->close();}
1221 break; // use new prefs
1222 case Icon_Prefs_Save:
1223 WindowToThePrefs();
1224 if (CheckFilename(PrefsWindow->ReadIconText(Icon_Prefs_PrefPath)) == 0)
1225 {
1226 ThePrefs.Save(PrefsWindow->ReadIconText(Icon_Prefs_PrefPath));
1227 }
1228 break;
1229 default: break;
1230 }
1231 }
1232 else if ((Block[MouseB_Buttons] == 16) || (Block[MouseB_Buttons] == 64))
1233 // drag (only the sprite)
1234 {
1235 if (Block[MouseB_Icon] == Icon_Prefs_PrefSprite)
1236 {
1237 DragIconSprite(PrefsWindow, Icon_Prefs_PrefSprite);
1238 DragType = DRAG_PrefsSprite;
1239 }
1240 }
1241 }
1242 else if (Block[MouseB_Window] == ConfigWindow->MyHandle()) // sys config window
1243 {
1244 if ((Block[MouseB_Buttons] == 1) || (Block[MouseB_Buttons] == 4))
1245 {
1246 if (Block[MouseB_Icon] == Icon_Conf_OK)
1247 {
1248 WindowToSysConf(); UseNULL--;
1249 if (Block[MouseB_Buttons] == 4) {ConfigWindow->close();}
1250 }
1251 else if (Block[MouseB_Icon] == Icon_Conf_Save)
1252 {
1253 if (CheckFilename(ConfigWindow->ReadIconText(Icon_Conf_ConfPath)) == 0)
1254 {
1255 WindowToSysConf(); UseNULL--; ConfigWindow->close();
1256 the_c64->SaveSystemConfig(ConfigWindow->ReadIconText(Icon_Conf_ConfPath));
1257 }
1258 }
1259 }
1260 else if ((Block[MouseB_Buttons] == 16) || (Block[MouseB_Buttons] == 64))
1261 {
1262 if (Block[MouseB_Icon] == Icon_Conf_ConfSprite)
1263 {
1264 DragIconSprite(ConfigWindow, Icon_Conf_ConfSprite);
1265 DragType = DRAG_ConfSprite;
1266 }
1267 }
1268 }
1269 else if (Block[MouseB_Window] == SoundWindow->MyHandle()) // sound window
1270 {
1271 if (Block[MouseB_Icon] == Icon_Sound_Volume)
1272 {
1273 if ((Block[MouseB_Buttons] == 1) || (Block[MouseB_Buttons] == 4)) // click
1274 {
1275 the_c64->HostVolume = CalculateVolume(Block); Sound_Volume(the_c64->HostVolume);
1276 SoundWindow->ForceIconRedraw(Icon_Sound_Volume);
1277 }
1278 else if ((Block[MouseB_Buttons] == 16) || (Block[MouseB_Buttons] == 64)) // drag
1279 {
1280 int orgx, orgy;
1281
1282 SoundWindow->getstate(AuxBlock);
1283 orgx = AuxBlock[WindowB_VMinX] - AuxBlock[WindowB_ScrollX];
1284 orgy = AuxBlock[WindowB_VMaxY] - AuxBlock[WindowB_ScrollY];
1285 SoundWindow->GetIconState(Icon_Sound_Volume, &AuxBlock[DragB_BBMinX - IconB_MinX]);
1286 AuxBlock[DragB_BBMinX] += orgx; AuxBlock[DragB_BBMinY] += orgy;
1287 AuxBlock[DragB_BBMaxX] += orgx; AuxBlock[DragB_BBMaxY] += orgy;
1288 AuxBlock[DragB_Type] = 7;
1289 Wimp_DragBox(AuxBlock);
1290 DragType = DRAG_VolumeWell; UseNULL++;
1291 }
1292 }
1293 }
1294 else if (Block[MouseB_Window] == SaveBox->MyHandle())
1295 {
1296 if ((Block[MouseB_Buttons] == 1) || (Block[MouseB_Buttons] == 4))
1297 {
1298 if (Block[MouseB_Icon] == Icon_Save_OK)
1299 {
1300 if (CheckFilename(SaveBox->ReadIconText(Icon_Save_Path)) == 0)
1301 {
1302 if (SaveType == SAVE_RAM)
1303 {
1304 strcpy(RAMFile+44,SaveBox->ReadIconText(Icon_Save_Path));
1305 the_c64->SaveRAM(RAMFile+44);
1306 Wimp_CreateMenu((int*)-1,0,0);
1307 SaveType = 0;
1308 }
1309 else if (SaveType == SAVE_Snapshot)
1310 {
1311 *(((int*)SnapFile) + MsgB_Sender) = 0;
1312 strcpy(SnapFile+44,SaveBox->ReadIconText(Icon_Save_Path));
1313 IssueSnapshotRequest();
1314 }
1315 }
1316 }
1317 }
1318 else if ((Block[MouseB_Buttons] == 16) || (Block[MouseB_Buttons] == 64))
1319 {
1320 if (Block[MouseB_Icon] == Icon_Save_Sprite)
1321 {
1322 DragIconSprite(SaveBox, Icon_Save_Sprite);
1323 DragType = DRAG_SaveSprite;
1324 }
1325 }
1326 }
1327 }
1328
1329
1330 // A drag operation has terminated
1331 void WIMP::UserDrag(void)
1332 {
1333 char *b = NULL;
1334 int filetype, size;
1335
1336 if ((CMOS_DragType == 0) || (DragType == DRAG_VolumeWell))
1337 {
1338 Wimp_DragBox(NULL);
1339 }
1340 else
1341 {
1342 DragASprite_Stop();
1343 }
1344
1345 if (DragType == DRAG_VolumeWell)
1346 {
1347 UseNULL--; DragType = 0; Sound_Volume(the_c64->HostVolume); // just set the new volume.
1348 }
1349
1350 // Drag of the path sprite
1351 if (DragType == DRAG_PrefsSprite)
1352 {
1353 b = PrefsWindow->ReadIconText(Icon_Prefs_PrefPath); filetype = FileType_Text;
1354 size = EstimatedPrefsSize; // can't say how large it's gonna be
1355 }
1356 else if (DragType == DRAG_ConfSprite)
1357 {
1358 b = ConfigWindow->ReadIconText(Icon_Conf_ConfPath); filetype = FileType_Text;
1359 size = EstimatedConfSize;
1360 }
1361 else if (DragType == DRAG_SaveSprite)
1362 {
1363 b = SaveBox->ReadIconText(Icon_Save_Path); filetype = FileType_Data;
1364 if (SaveType == SAVE_RAM) {size = EstimatedRAMSize;}
1365 else if (SaveType == SAVE_Snapshot) {size = EstimatedSnapSize;}
1366 else {size = 0;}
1367 }
1368
1369 // now b should point to the path and filetype should contain the type
1370 if (b != NULL)
1371 {
1372 Wimp_GetPointerInfo(Block);
1373 // Not on background and not on my own icon bar icon
1374 if ((Block[MouseB_Window] != -1) && ((Block[MouseB_Window] != -2) || (Block[MouseB_Icon] != IBicon->IHandle)))
1375 {
1376 int handle = Block[MouseB_Window];
1377
1378 // None of my windows
1379 if ((handle != EmuWindow->MyHandle()) && (handle != EmuPane->MyHandle()) &&
1380 (handle != PrefsWindow->MyHandle()) && (handle != ConfigWindow->MyHandle()) &&
1381 (handle != InfoWindow->MyHandle()) && (handle != SaveBox->MyHandle()))
1382 {
1383 char *d, c;
1384
1385 d = b; c = *b++;
1386 // get pointer to leafname in d
1387 while (c > 32) {if ((c == '.') || (c == ':')) {d = b;} c = *b++;}
1388 // Build message block
1389 Block[5] = Block[MouseB_Window]; Block[6] = Block[MouseB_Icon];
1390 Block[7] = Block[MouseB_PosX]; Block[8] = Block[MouseB_PosY];
1391 Block[9] = size; Block[10] = filetype;
1392 Block[MsgB_YourRef] = 0; Block[MsgB_Action] = Message_DataSave;
1393 b = ((char*)Block) + 44; c = *d++;
1394 while (c > 32) {*b++ = c; c = *d++;}
1395 *b++ = 0; Block[MsgB_Size] = (((int)(b - (char*)Block)) + 3) & 0xfffffffc;
1396 Wimp_SendMessage(18,Block,Block[5],Block[6]);
1397 }
1398 }
1399 }
1400 else {DragType = 0;}
1401 LastDrag = 0;
1402 }
1403
1404
1405 void WIMP::KeyPressed(void)
1406 {
1407 register int key = Block[KeyPB_Key];
1408
1409 if (Block[KeyPB_Window] == EmuWindow->MyHandle())
1410 {
1411 if ((key >= 0x180) && (key <= 0x1fd)) // special keys (incl. FKeys)
1412 {
1413 key -= 0x180;
1414 if ((((key & 0x4f) >= 0x05) && ((key & 0x4f) <= 0x09)) || // F5 -F9 [shift|ctrl]
1415 (((key & 0x4f) >= 0x4a) && ((key & 0x4f) <= 0x4c))) // F10-F12 [shift|ctrl]
1416 {
1417 if ((key != 0x06) && (key != 0x07) && (key != 0x08))
1418 {
1419 Wimp_ProcessKey(Block[KeyPB_Key]);
1420 }
1421 }
1422 }
1423 return;
1424 }
1425 else if (Block[KeyPB_Window] == PrefsWindow->MyHandle())
1426 {
1427 if (key == Key_Return)
1428 {
1429 WindowToThePrefs();
1430 if (Block[KeyPB_Icon] == Icon_Prefs_PrefPath) // return pressed in path string icon?
1431 {
1432 if (CheckFilename(PrefsWindow->ReadIconText(Icon_Prefs_PrefPath)) == 0)
1433 {
1434 ThePrefs.Save(PrefsWindow->ReadIconText(Icon_Prefs_PrefPath));
1435 }
1436 }
1437 return;
1438 }
1439 }
1440 else if (Block[KeyPB_Window] == ConfigWindow->MyHandle())
1441 {
1442 if ((key == Key_Return) && (Block[KeyPB_Icon] != -1))
1443 {
1444 WindowToSysConf(); UseNULL--; ConfigWindow->close();
1445 if (Block[KeyPB_Icon] == Icon_Conf_ConfPath) // return pressed in path string icon?
1446 {
1447 if (CheckFilename(ConfigWindow->ReadIconText(Icon_Conf_ConfPath)) == 0)
1448 {
1449 the_c64->SaveSystemConfig(ConfigWindow->ReadIconText(Icon_Conf_ConfPath));
1450 }
1451 }
1452 return;
1453 }
1454 }
1455 else if (Block[KeyPB_Window] == SaveBox->MyHandle())
1456 {
1457 if (key == Key_Return)
1458 {
1459 if (Block[KeyPB_Icon] == Icon_Save_Path)
1460 {
1461 if (CheckFilename(SaveBox->ReadIconText(Icon_Save_Path)) == 0)
1462 {
1463 if (SaveType == SAVE_RAM)
1464 {
1465 strcpy(RAMFile+44,SaveBox->ReadIconText(Icon_Save_Path));
1466 the_c64->SaveRAM(RAMFile+44);
1467 Wimp_CreateMenu((int*)-1,0,0);
1468 SaveType = 0;
1469 }
1470 else if (SaveType == SAVE_Snapshot)
1471 {
1472 *(((int*)SnapFile) + MsgB_Sender) = 0;
1473 strcpy(SnapFile+44,SaveBox->ReadIconText(Icon_Save_Path));
1474 IssueSnapshotRequest();
1475 }
1476 }
1477 }
1478 return;
1479 }
1480 }
1481 Wimp_ProcessKey(Block[KeyPB_Key]);
1482 }
1483
1484
1485 void WIMP::MenuSelection(void)
1486 {
1487 int Buttons;
1488
1489 Wimp_GetPointerInfo(AuxBlock); Buttons = AuxBlock[MouseB_Buttons];
1490
1491 switch (LastMenu)
1492 {
1493 case Menu_IBar:
1494 if (Block[0] == Menu_IBar_Quit) {EmuPaused = false; the_c64->Quit();}
1495 else if (Block[0] == Menu_IBar_Prefs)
1496 {
1497 // Is it already open? Then don't do anything
1498 if (!PrefsWindow->OpenStatus())
1499 {
1500 int y;
1501
1502 // Open Prefs window with top left corner in top left corner of screen
1503 PrefsWindow->getstate(AuxBlock);
1504 y = the_c64->TheDisplay->screen->resy;
1505 AuxBlock[WindowB_VMaxX] -= AuxBlock[WindowB_VMinX]; AuxBlock[WindowB_VMinX] = 0;
1506 AuxBlock[WindowB_VMinY] = y - (AuxBlock[WindowB_VMaxY] - AuxBlock[WindowB_VMinY]);
1507 AuxBlock[WindowB_VMaxY] = y;
1508 // Open Prefs window on top
1509 AuxBlock[WindowB_Stackpos] = -1;
1510 PrefsWindow->open(AuxBlock);
1511 }
1512 else
1513 {
1514 PrefsWindow->getstate(AuxBlock);
1515 AuxBlock[WindowB_Stackpos] = -1; PrefsWindow->open(AuxBlock);
1516 }
1517 }
1518 else if (Block[0] == Menu_IBar_Config)
1519 {
1520 if (!ConfigWindow->OpenStatus())
1521 {
1522 int x, y;
1523
1524 // Update window contents
1525 SysConfToWindow();
1526 // Open config window in top right corner of screen
1527 ConfigWindow->getstate(AuxBlock);
1528 x = the_c64->TheDisplay->screen->resx; y = the_c64->TheDisplay->screen->resy;
1529 AuxBlock[WindowB_VMinX] = x - (AuxBlock[WindowB_VMaxX] - AuxBlock[WindowB_VMinX]);
1530 AuxBlock[WindowB_VMaxX] = x;
1531 AuxBlock[WindowB_VMinY] = y - (AuxBlock[WindowB_VMaxY] - AuxBlock[WindowB_VMinY]);
1532 AuxBlock[WindowB_VMaxY] = y;
1533 AuxBlock[WindowB_Stackpos] = -1;
1534 ConfigWindow->open(AuxBlock);
1535 // We need NULL-events for the low-level keyboard scan.
1536 UseNULL++;
1537 }
1538 else
1539 {
1540 ConfigWindow->getstate(AuxBlock);
1541 AuxBlock[WindowB_Stackpos] = -1; ConfigWindow->open(AuxBlock);
1542 }
1543 }
1544 if (Buttons == 1) {Wimp_CreateMenu((int*)&MenuIconBar,0,0);}
1545 break;
1546 case Menu_Emulator:
1547 if (Buttons == 1) {Wimp_CreateMenu((int*)&MenuEmuWindow,0,0);}
1548 break;
1549 default: break;
1550 }
1551 }
1552
1553
1554 // Handle regular messages
1555 void WIMP::UserMessage(void)
1556 {
1557 C64Display *disp = the_c64->TheDisplay;
1558 int i;
1559
1560 switch (Block[MsgB_Action]) // Message Action
1561 {
1562 case Message_Quit:
1563 EmuPaused = false; the_c64->Quit(); break;
1564 case Message_ModeChange:
1565 disp->ModeChange(); the_c64->TheVIC->ReInitColors(); SetEmuWindowSize();
1566 // The window could have changed position ==> reposition pane as well!
1567 // we have to force the window to the screen manually
1568 EmuWindow->getstate(AuxBlock);
1569 if ((AuxBlock[WindowB_WFlags] & (1<<16)) != 0) // is it open anyway?
1570 {
1571 i = AuxBlock[WindowB_VMaxY] - AuxBlock[WindowB_VMinY];
1572 if (AuxBlock[WindowB_VMaxY] > disp->screen->resy - TitleBarHeight)
1573 {
1574 AuxBlock[WindowB_VMaxY] = disp->screen->resy - TitleBarHeight;
1575 if ((AuxBlock[WindowB_VMinY] = AuxBlock[WindowB_VMaxY] - i) < TitleBarHeight)
1576 {
1577 AuxBlock[WindowB_VMinY] = TitleBarHeight;
1578 }
1579 }
1580 i = AuxBlock[WindowB_VMaxX] - AuxBlock[WindowB_VMinX];
1581 if (AuxBlock[WindowB_VMaxX] > disp->screen->resx - TitleBarHeight)
1582 {
1583 AuxBlock[WindowB_VMaxX] = disp->screen->resx - TitleBarHeight;
1584 if ((AuxBlock[WindowB_VMinX] = AuxBlock[WindowB_VMaxX] - i) < 0)
1585 {
1586 AuxBlock[WindowB_VMinX] = 0;
1587 }
1588 }
1589 // Don't you just love it -- you can't open the window directly, you need
1590 // a delay... like for instance by sending yourself an OpenWindow message...
1591 Wimp_SendMessage(2,AuxBlock,TaskHandle,0);
1592 }
1593 break;
1594 case Message_PaletteChange:
1595 // Updating EmuWindow is pointless since the bitmap still contains data for another mode
1596 disp->ModeChange(); the_c64->TheVIC->ReInitColors();
1597 break;
1598 case Message_DataSave:
1599 i = -1; // indicator whether file is accepted
1600 if ((Block[5] == EmuWindow->MyHandle()) && (Block[10] == FileType_C64File)) {i=0;}
1601 else if ((Block[5] == EmuWindow->MyHandle()) && (Block[10] == FileType_Data)) {i=0;}
1602 else if ((Block[5] == PrefsWindow->MyHandle()) && (Block[10] == FileType_Text)) {i=0;}
1603 else if ((Block[5] == ConfigWindow->MyHandle()) && (Block[10] == FileType_Text)) {i=0;}
1604 if (i >= 0)
1605 {
1606 Block[9] = -1; // file unsafe
1607 strcpy(((char*)Block)+44,WIMP_SCRAP_FILE);
1608 Block[MsgB_Size] = (48 + strlen(WIMP_SCRAP_FILE)) & 0xfffffffc;
1609 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataSaveAck;
1610 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
1611 UseScrap = true;
1612 }
1613 break;
1614 case Message_DataLoad:
1615 if (Block[5] == EmuWindow->MyHandle()) // Emulator window: load file?
1616 {
1617 if (Block[10] == FileType_C64File) // Load only files with type &64 this way
1618 {
1619 FILE *fp;
1620
1621 if ((fp = fopen(((char*)Block)+44,"rb")) != NULL)
1622 {
1623 uint8 lo, hi, *mem = the_c64->RAM;
1624 int length;
1625
1626 lo = fgetc(fp); hi = fgetc(fp); length = lo + (hi<<8);
1627 length += fread(mem+length,1,0x10000-length,fp);
1628 // length is now end-address
1629 fclose(fp);
1630 mem[0xc3] = lo; mem[0xc4] = hi; // Load-address
1631 lo = length & 0xff; hi = (length >> 8) & 0xff;
1632 mem[0xae] = mem[0x2d] = mem[0x2f] = mem[0x31] = mem[0x33] = lo;
1633 mem[0xaf] = mem[0x2e] = mem[0x30] = mem[0x32] = mem[0x34] = hi;
1634 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoadAck;
1635 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
1636 }
1637 }
1638 else if (Block[10] == FileType_Data)
1639 {
1640 if (the_c64->LoadSnapshot(((char*)Block)+44))
1641 {
1642 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoadAck;
1643 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
1644 }
1645 }
1646 }
1647 else if (Block[5] == PrefsWindow->MyHandle()) // Prefs window?
1648 {
1649 if (Block[10] == FileType_Text) // load a prefs file?
1650 {
1651 Prefs *prefs = new Prefs(ThePrefs);
1652
1653 prefs->Load(((char*)Block)+44);
1654 the_c64->NewPrefs(prefs);
1655 ThePrefs = *prefs;
1656 delete prefs;
1657 PrefsWindow->WriteIconText(Icon_Prefs_PrefPath,((char*)Block)+44);
1658 ThePrefsToWindow();
1659 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoadAck;
1660 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
1661 }
1662 else // interpret as drive path (if dragged on one of the drive path icons)
1663 {
1664 switch (Block[6])
1665 {
1666 case Icon_Prefs_Dr8Path: i = 0; break;
1667 case Icon_Prefs_Dr9Path: i = 1; break;
1668 case Icon_Prefs_Dr10Path: i = 2; break;
1669 case Icon_Prefs_Dr11Path: i = 3; break;
1670 default: -1; break;
1671 }
1672 if (i >= 0) {NewDriveImage(i,Block,false);}
1673 }
1674 }
1675 else if (Block[5] == ConfigWindow->MyHandle()) // load sys config file
1676 {
1677 if (Block[10] == FileType_Text)
1678 {
1679 the_c64->LoadSystemConfig(((char*)Block)+44);
1680 SysConfToWindow();
1681 ConfigWindow->WriteIconText(Icon_Conf_ConfPath,((char*)Block)+44);
1682 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoadAck;
1683 Wimp_SendMessage(17,Block,Block[MsgB_Sender],Block[6]);
1684 }
1685 }
1686 else if (Block[5] == EmuPane->MyHandle()) // emulator pane
1687 {
1688 switch (Block[6])
1689 {
1690 case Icon_Pane_Drive0:
1691 case Icon_Pane_LED0: i = 0; break;
1692 case Icon_Pane_Drive1:
1693 case Icon_Pane_LED1: i = 1; break;
1694 case Icon_Pane_Drive2:
1695 case Icon_Pane_LED2: i = 2; break;
1696 case Icon_Pane_Drive3:
1697 case Icon_Pane_LED3: i = 3; break;
1698 default: i = -1; break;
1699 }
1700 if (i >= 0) {NewDriveImage(i,Block,true);}
1701 }
1702 // Clean up if necessary
1703 if (UseScrap) {DeleteFile(WIMP_SCRAP_FILE); UseScrap = false;}
1704 break;
1705 case Message_DataSaveAck:
1706 if (DragType == DRAG_PrefsSprite)
1707 {
1708 WindowToThePrefs(); // read window entries
1709 ThePrefs.Save(((char*)Block)+44);
1710 if (Block[9] != -1) // we're talking to the filer ==> set new pathname
1711 {
1712 PrefsWindow->WriteIconText(Icon_Prefs_PrefPath,((char*)Block)+44);
1713 }
1714 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoad;
1715 Wimp_SendMessage(18,Block,Block[MsgB_Sender],Block[6]);
1716 }
1717 else if (DragType == DRAG_ConfSprite)
1718 {
1719 WindowToSysConf(); // read window entries
1720 the_c64->SaveSystemConfig(((char*)Block)+44);
1721 if (Block[9] != -1)
1722 {
1723 ConfigWindow->WriteIconText(Icon_Conf_ConfPath,((char*)Block)+44);
1724 }
1725 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoad;
1726 Wimp_SendMessage(18,Block,Block[MsgB_Sender],Block[6]);
1727 }
1728 else if (DragType == DRAG_SaveSprite)
1729 {
1730 if (SaveType == SAVE_RAM)
1731 {
1732 memcpy(RAMFile,(char*)Block,256); the_c64->SaveRAM(RAMFile+44);
1733 Block[MsgB_YourRef] = Block[MsgB_MyRef]; Block[MsgB_Action] = Message_DataLoad;
1734 Wimp_SendMessage(18,Block,Block[MsgB_Sender],Block[6]);
1735 }
1736 else if (SaveType == SAVE_Snapshot)
1737 {
1738 memcpy(SnapFile,(char*)Block,256);
1739 IssueSnapshotRequest();
1740 }
1741 }
1742 break;
1743 case Message_DataLoadAck:
1744 if (DragType == DRAG_ConfSprite)
1745 {
1746 UseNULL--; ConfigWindow->close();
1747 }
1748 if (DragType == DRAG_SaveSprite)
1749 {
1750 Wimp_CreateMenu((int*)-1,0,0);
1751 }
1752 DragType = SaveType = 0; break;
1753 case Message_MenuWarning:
1754 if (LastMenu == Menu_Emulator)
1755 {
1756 if (Block[8] == Menu_EWind_SaveRAM)
1757 {
1758 SaveType = SAVE_RAM; SaveBox->WriteIconText(Icon_Save_Path,RAMFile+44);
1759 }
1760 else if (Block[8] == Menu_EWind_Snapshot)
1761 {
1762 SaveType = SAVE_Snapshot; SaveBox->WriteIconText(Icon_Save_Path,SnapFile+44);
1763 }
1764 else {SaveType = 0;}
1765 Wimp_CreateSubMenu((int*)Block[5],Block[6],Block[7]);
1766 }
1767 break;
1768 default: break;
1769 }
1770 }
1771
1772
1773 // If a recorded message was not answered, i.e. something went wrong.
1774 void WIMP::UserMessageAck(void)
1775 {
1776 switch(Block[MsgB_Action])
1777 {
1778 case Message_DataSave:
1779 sprintf(WimpError.errmess,"Can't save data."); break;
1780 case Message_DataLoad:
1781 sprintf(WimpError.errmess,"Receiver couldn't load data."); break;
1782 default:
1783 sprintf(WimpError.errmess,"Some error occurred..."); break;
1784 }
1785 WimpError.errnum = 0; Wimp_ReportError(&WimpError,1,TASKNAME);
1786 }