PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jni/AcornGUI.cc

http://github.com/shagr4th/FrodoC64
C++ | 1804 lines | 1457 code | 200 blank | 147 comment | 517 complexity | e3f4574516e3f20e0e2ea869b5c22582 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file