home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / MainWndOptions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  37.8 KB  |  1,672 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20. #include "MainWnd.h"
  21.  
  22. #include "Associate.h"
  23. #include "Directories.h"
  24. #include "FileDlg.h"
  25. #include "GBColorDlg.h"
  26. #include "Joypad.h"
  27. #include "MaxScale.h"
  28. #include "ModeConfirm.h"
  29. #include "Reg.h"
  30. #include "RewindInterval.h"
  31. #include "skin.h"
  32. #include "Throttle.h"
  33. #include "WinResUtil.h"
  34.  
  35. #include "../System.h"
  36. #include "../agbprint.h"
  37. #include "../GBA.h"
  38. #include "../Globals.h"
  39. #include "../Sound.h"
  40. #include "../gb/GB.h"
  41. #include "../gb/gbGlobals.h"
  42. #include "../gb/gbPrinter.h"
  43.  
  44. extern int emulating;
  45.  
  46. #define VBA_CONFIRM_MODE WM_APP + 100
  47.  
  48. extern void CPUUpdateRenderBuffers(bool force);
  49.  
  50. void MainWnd::OnOptionsFrameskipThrottleNothrottle() 
  51. {
  52.   theApp.throttle = 0;  
  53. }
  54.  
  55. void MainWnd::OnUpdateOptionsFrameskipThrottleNothrottle(CCmdUI* pCmdUI) 
  56. {
  57.   pCmdUI->SetCheck(theApp.throttle == 0);  
  58. }
  59.  
  60. void MainWnd::OnOptionsFrameskipThrottle25() 
  61. {
  62.   theApp.throttle = 25;  
  63. }
  64.  
  65. void MainWnd::OnUpdateOptionsFrameskipThrottle25(CCmdUI* pCmdUI) 
  66. {
  67.   pCmdUI->SetCheck(theApp.throttle == 25);
  68. }
  69.  
  70. void MainWnd::OnOptionsFrameskipThrottle50() 
  71. {
  72.   theApp.throttle = 50;  
  73. }
  74.  
  75. void MainWnd::OnUpdateOptionsFrameskipThrottle50(CCmdUI* pCmdUI) 
  76. {
  77.   pCmdUI->SetCheck(theApp.throttle == 50);
  78. }
  79.  
  80. void MainWnd::OnOptionsFrameskipThrottle100() 
  81. {
  82.   theApp.throttle = 100;  
  83. }
  84.  
  85. void MainWnd::OnUpdateOptionsFrameskipThrottle100(CCmdUI* pCmdUI) 
  86. {
  87.   pCmdUI->SetCheck(theApp.throttle == 100);
  88. }
  89.  
  90. void MainWnd::OnOptionsFrameskipThrottle150() 
  91. {
  92.   theApp.throttle = 150;  
  93. }
  94.  
  95. void MainWnd::OnUpdateOptionsFrameskipThrottle150(CCmdUI* pCmdUI) 
  96. {
  97.   pCmdUI->SetCheck(theApp.throttle == 150);
  98. }
  99.  
  100. void MainWnd::OnOptionsFrameskipThrottle200() 
  101. {
  102.   theApp.throttle = 200;  
  103. }
  104.  
  105. void MainWnd::OnUpdateOptionsFrameskipThrottle200(CCmdUI* pCmdUI) 
  106. {
  107.   pCmdUI->SetCheck(theApp.throttle == 200);
  108. }
  109.  
  110. void MainWnd::OnOptionsFrameskipThrottleOther() 
  111. {
  112.   Throttle dlg;
  113.   int v = dlg.DoModal();
  114.   if(v)
  115.     theApp.throttle = v;
  116. }
  117.  
  118. void MainWnd::OnUpdateOptionsFrameskipThrottleOther(CCmdUI* pCmdUI) 
  119. {
  120.   int throttle = theApp.throttle;
  121.   pCmdUI->SetCheck(throttle != 0 && throttle != 25 &&
  122.                    throttle != 50 && throttle != 100 &&
  123.                    throttle != 150 && throttle != 200);
  124. }
  125.  
  126. void MainWnd::OnOptionsFrameskipAutomatic() 
  127. {
  128.   theApp.autoFrameSkip = !theApp.autoFrameSkip;
  129.   if(!theApp.autoFrameSkip && emulating)
  130.     theApp.updateFrameSkip();
  131. }
  132.  
  133. void MainWnd::OnUpdateOptionsFrameskipAutomatic(CCmdUI* pCmdUI) 
  134. {
  135.   pCmdUI->SetCheck(theApp.autoFrameSkip);  
  136. }
  137.  
  138. BOOL MainWnd::OnOptionsFrameskip(UINT nID)
  139. {
  140.   switch(nID) {
  141.   case ID_OPTIONS_VIDEO_FRAMESKIP_0:
  142.   case ID_OPTIONS_VIDEO_FRAMESKIP_1:
  143.   case ID_OPTIONS_VIDEO_FRAMESKIP_2:
  144.   case ID_OPTIONS_VIDEO_FRAMESKIP_3:
  145.   case ID_OPTIONS_VIDEO_FRAMESKIP_4:
  146.   case ID_OPTIONS_VIDEO_FRAMESKIP_5:
  147.     if(theApp.cartridgeType == 0) {
  148.       frameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0;
  149.     } else {
  150.       gbFrameSkip = nID - ID_OPTIONS_VIDEO_FRAMESKIP_0;
  151.     }
  152.     if(emulating)
  153.       theApp.updateFrameSkip();
  154.     return TRUE;
  155.     break;
  156.   case ID_OPTIONS_VIDEO_FRAMESKIP_6:
  157.   case ID_OPTIONS_VIDEO_FRAMESKIP_7:
  158.   case ID_OPTIONS_VIDEO_FRAMESKIP_8:
  159.   case ID_OPTIONS_VIDEO_FRAMESKIP_9:
  160.     if(theApp.cartridgeType == 0) {
  161.       frameSkip = 6 + nID - ID_OPTIONS_VIDEO_FRAMESKIP_6;
  162.     } else {
  163.       gbFrameSkip = 6 + nID - ID_OPTIONS_VIDEO_FRAMESKIP_6;
  164.     }
  165.     if(emulating)
  166.       theApp.updateFrameSkip();
  167.     return TRUE;
  168.     break;
  169.   }
  170.   return FALSE;
  171. }
  172.  
  173. void MainWnd::OnUpdateOptionsVideoFrameskip0(CCmdUI* pCmdUI) 
  174. {
  175.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 0 : gbFrameSkip == 0);  
  176. }
  177.  
  178. void MainWnd::OnUpdateOptionsVideoFrameskip1(CCmdUI* pCmdUI) 
  179. {
  180.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 1 : gbFrameSkip == 1);
  181. }
  182.  
  183. void MainWnd::OnUpdateOptionsVideoFrameskip2(CCmdUI* pCmdUI) 
  184. {
  185.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 2 : gbFrameSkip == 2);
  186. }
  187.  
  188. void MainWnd::OnUpdateOptionsVideoFrameskip3(CCmdUI* pCmdUI) 
  189. {
  190.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 3 : gbFrameSkip == 3);
  191. }
  192.  
  193. void MainWnd::OnUpdateOptionsVideoFrameskip4(CCmdUI* pCmdUI) 
  194. {
  195.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 4 : gbFrameSkip == 4);
  196. }
  197.  
  198. void MainWnd::OnUpdateOptionsVideoFrameskip5(CCmdUI* pCmdUI) 
  199. {
  200.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 5 : gbFrameSkip == 5);
  201. }
  202.  
  203. void MainWnd::OnUpdateOptionsVideoFrameskip6(CCmdUI* pCmdUI) 
  204. {
  205.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 6 : gbFrameSkip == 6);
  206. }
  207.  
  208. void MainWnd::OnUpdateOptionsVideoFrameskip7(CCmdUI* pCmdUI) 
  209. {
  210.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 7 : gbFrameSkip == 7);
  211. }
  212.  
  213. void MainWnd::OnUpdateOptionsVideoFrameskip8(CCmdUI* pCmdUI) 
  214. {
  215.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 8 : gbFrameSkip == 8);
  216. }
  217.  
  218. void MainWnd::OnUpdateOptionsVideoFrameskip9(CCmdUI* pCmdUI) 
  219. {
  220.   pCmdUI->SetCheck(theApp.cartridgeType == 0 ? frameSkip == 9 : gbFrameSkip == 9);
  221. }
  222.  
  223. void MainWnd::OnOptionsVideoVsync() 
  224. {
  225.   theApp.vsync = !theApp.vsync;
  226. }
  227.  
  228. void MainWnd::OnUpdateOptionsVideoVsync(CCmdUI* pCmdUI) 
  229. {
  230.   pCmdUI->SetCheck(theApp.vsync);
  231. }
  232.  
  233. void MainWnd::OnUpdateOptionsVideoX1(CCmdUI* pCmdUI) 
  234. {
  235.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_1X);
  236. }
  237.  
  238. void MainWnd::OnUpdateOptionsVideoX2(CCmdUI* pCmdUI) 
  239. {
  240.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_2X);
  241. }
  242.  
  243. void MainWnd::OnUpdateOptionsVideoX3(CCmdUI* pCmdUI) 
  244. {
  245.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_3X);
  246. }
  247.  
  248. void MainWnd::OnUpdateOptionsVideoX4(CCmdUI* pCmdUI) 
  249. {
  250.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_4X);
  251. }
  252.  
  253. void MainWnd::OnUpdateOptionsVideoFullscreen320x240(CCmdUI* pCmdUI) 
  254. {
  255.   pCmdUI->Enable(theApp.mode320Available);
  256.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_320x240);
  257. }
  258.  
  259. void MainWnd::OnUpdateOptionsVideoFullscreen640x480(CCmdUI* pCmdUI) 
  260. {
  261.   pCmdUI->Enable(theApp.mode640Available);
  262.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_640x480);
  263. }
  264.  
  265. void MainWnd::OnUpdateOptionsVideoFullscreen800x600(CCmdUI* pCmdUI) 
  266. {
  267.   pCmdUI->Enable(theApp.mode800Available);
  268.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_800x600);
  269. }
  270.  
  271. BOOL MainWnd::OnOptionVideoSize(UINT nID)
  272. {
  273.   theApp.updateVideoSize(nID);
  274.   theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE);
  275.   return TRUE;
  276. }
  277.  
  278. void MainWnd::OnOptionsVideoFullscreen320x240() 
  279. {
  280.   OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN320X240);
  281. }
  282.  
  283. void MainWnd::OnOptionsVideoFullscreen640x480() 
  284. {
  285.   OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN640X480);
  286. }
  287.  
  288. void MainWnd::OnOptionsVideoFullscreen800x600() 
  289. {
  290.   OnOptionVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN800X600);
  291. }
  292.  
  293. void MainWnd::OnOptionsVideoFullscreen() 
  294. {
  295.   theApp.winCheckFullscreen();        
  296.   GUID *pGUID = NULL;
  297.   int size = theApp.display->selectFullScreenMode(&pGUID);
  298.   if(size != -1) {
  299.     int width = (size >> 12) & 4095;
  300.     int height = (size & 4095);
  301.     int colorDepth = (size >> 24);
  302.     if(width != theApp.fsWidth ||
  303.        height != theApp.fsHeight ||
  304.        colorDepth != theApp.fsColorDepth ||
  305.        pGUID != theApp.pVideoDriverGUID ||
  306.        theApp.videoOption != VIDEO_OTHER) {
  307.       theApp.fsForceChange = true;
  308.       theApp.fsWidth = width;
  309.       theApp.fsHeight = height;
  310.       theApp.fsColorDepth = colorDepth;
  311.       theApp.pVideoDriverGUID = pGUID;
  312.       if(pGUID) {
  313.         theApp.videoDriverGUID = *pGUID;
  314.         regSetDwordValue("defaultVideoDriver", FALSE);
  315.         regSetBinaryValue("videoDriverGUID",
  316.                           (char *)pGUID, sizeof(GUID));
  317.       } else {
  318.         regSetDwordValue("defaultVideoDriver", TRUE);
  319.       }
  320.       theApp.updateVideoSize(ID_OPTIONS_VIDEO_FULLSCREEN);
  321.       theApp.m_pMainWnd->PostMessage(VBA_CONFIRM_MODE);
  322.     }
  323.   }
  324.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  325. }
  326.  
  327. void MainWnd::OnUpdateOptionsVideoFullscreen(CCmdUI* pCmdUI) 
  328. {
  329.   pCmdUI->SetCheck(theApp.videoOption == VIDEO_OTHER);
  330. }
  331.  
  332. void MainWnd::OnOptionsVideoDisablesfx() 
  333. {
  334.   cpuDisableSfx = !cpuDisableSfx;
  335.   if(emulating && theApp.cartridgeType == 0)
  336.     CPUUpdateRender();
  337. }
  338.  
  339. void MainWnd::OnUpdateOptionsVideoDisablesfx(CCmdUI* pCmdUI) 
  340. {
  341.   pCmdUI->SetCheck(cpuDisableSfx);
  342. }
  343.  
  344. void MainWnd::OnOptionsVideoFullscreenstretchtofit() 
  345. {
  346.   theApp.fullScreenStretch = !theApp.fullScreenStretch;
  347.   theApp.updateWindowSize(theApp.videoOption);
  348.   if(theApp.display)
  349.     theApp.display->clear();
  350. }
  351.  
  352. void MainWnd::OnUpdateOptionsVideoFullscreenstretchtofit(CCmdUI* pCmdUI) 
  353. {
  354.   pCmdUI->SetCheck(theApp.fullScreenStretch);
  355. }
  356.  
  357. BOOL MainWnd::OnVideoLayer(UINT nID)
  358. {
  359.   layerSettings ^= 0x0100 <<
  360.     ((nID & 0xFFFF) - ID_OPTIONS_VIDEO_LAYERS_BG0);
  361.   layerEnable = DISPCNT & layerSettings;
  362.   CPUUpdateRenderBuffers(false);
  363.   return TRUE;
  364. }
  365.  
  366. void MainWnd::OnUpdateVideoLayer(CCmdUI *pCmdUI)
  367. {
  368.   pCmdUI->SetCheck((layerSettings >> (8 + pCmdUI->m_nID - ID_OPTIONS_VIDEO_LAYERS_BG0)) & 1);
  369.   switch(pCmdUI->m_nID) {
  370.   case ID_OPTIONS_VIDEO_LAYERS_BG1:
  371.   case ID_OPTIONS_VIDEO_LAYERS_BG2:
  372.   case ID_OPTIONS_VIDEO_LAYERS_BG3:
  373.   case ID_OPTIONS_VIDEO_LAYERS_WIN1:
  374.   case ID_OPTIONS_VIDEO_LAYERS_OBJWIN:
  375.     pCmdUI->Enable(theApp.cartridgeType == 0);
  376.     break;
  377.   }
  378. }
  379.  
  380. void MainWnd::OnOptionsVideoRendermethodGdi() 
  381. {
  382.   theApp.renderMethod = GDI;
  383.   theApp.updateRenderMethod(false);
  384.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  385. }
  386.  
  387. void MainWnd::OnUpdateOptionsVideoRendermethodGdi(CCmdUI* pCmdUI) 
  388. {
  389.   pCmdUI->SetCheck(theApp.renderMethod == GDI);
  390. }
  391.  
  392. void MainWnd::OnOptionsVideoRendermethodDirectdraw() 
  393. {
  394.   theApp.renderMethod = DIRECT_DRAW;
  395.   theApp.updateRenderMethod(false);
  396.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  397. }
  398.  
  399. void MainWnd::OnUpdateOptionsVideoRendermethodDirectdraw(CCmdUI* pCmdUI) 
  400. {
  401.   pCmdUI->SetCheck(theApp.renderMethod == DIRECT_DRAW);
  402. }
  403.  
  404. void MainWnd::OnOptionsVideoRendermethodDirect3d() 
  405. {
  406.   theApp.renderMethod = DIRECT_3D;
  407.   theApp.updateRenderMethod(false);
  408.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  409. }
  410.  
  411. void MainWnd::OnUpdateOptionsVideoRendermethodDirect3d(CCmdUI* pCmdUI) 
  412. {
  413.   pCmdUI->SetCheck(theApp.renderMethod == DIRECT_3D);
  414. }
  415.  
  416. void MainWnd::OnOptionsVideoRendermethodOpengl() 
  417. {
  418.   theApp.renderMethod = OPENGL;
  419.   theApp.updateRenderMethod(false);
  420.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  421. }
  422.  
  423. void MainWnd::OnUpdateOptionsVideoRendermethodOpengl(CCmdUI* pCmdUI) 
  424. {
  425.   pCmdUI->SetCheck(theApp.renderMethod == OPENGL);
  426. }
  427.  
  428. void MainWnd::OnOptionsVideoTriplebuffering() 
  429. {
  430.   theApp.tripleBuffering = !theApp.tripleBuffering;
  431. }
  432.  
  433. void MainWnd::OnUpdateOptionsVideoTriplebuffering(CCmdUI* pCmdUI) 
  434. {
  435.   pCmdUI->SetCheck(theApp.tripleBuffering);
  436. }
  437.  
  438. void MainWnd::OnOptionsVideoDdrawemulationonly() 
  439. {
  440.   theApp.ddrawEmulationOnly = !theApp.ddrawEmulationOnly;
  441. }
  442.  
  443. void MainWnd::OnUpdateOptionsVideoDdrawemulationonly(CCmdUI* pCmdUI) 
  444. {
  445.   pCmdUI->SetCheck(theApp.ddrawEmulationOnly);
  446. }
  447.  
  448. void MainWnd::OnOptionsVideoDdrawusevideomemory() 
  449. {
  450.   theApp.ddrawUseVideoMemory = !theApp.ddrawUseVideoMemory;
  451. }
  452.  
  453. void MainWnd::OnUpdateOptionsVideoDdrawusevideomemory(CCmdUI* pCmdUI) 
  454. {
  455.   pCmdUI->SetCheck(theApp.ddrawUseVideoMemory);
  456. }
  457.  
  458. void MainWnd::OnOptionsVideoRenderoptionsD3dnofilter() 
  459. {
  460.   theApp.d3dFilter = 0;
  461.   if(theApp.display)
  462.     theApp.display->setOption("d3dFilter", 0);
  463. }
  464.  
  465. void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dnofilter(CCmdUI* pCmdUI) 
  466. {
  467.   pCmdUI->SetCheck(theApp.d3dFilter == 0);
  468. }
  469.  
  470. void MainWnd::OnOptionsVideoRenderoptionsD3dbilinear() 
  471. {
  472.   theApp.d3dFilter = 1;
  473.   if(theApp.display)
  474.     theApp.display->setOption("d3dFilter", 1);
  475. }
  476.  
  477. void MainWnd::OnUpdateOptionsVideoRenderoptionsD3dbilinear(CCmdUI* pCmdUI) 
  478. {
  479.   pCmdUI->SetCheck(theApp.d3dFilter == 1);
  480. }
  481.  
  482. void MainWnd::OnOptionsVideoRenderoptionsGlnearest() 
  483. {
  484.   theApp.glFilter = 0;
  485.   if(theApp.display)
  486.     theApp.display->setOption("glFilter", 0);
  487. }
  488.  
  489. void MainWnd::OnUpdateOptionsVideoRenderoptionsGlnearest(CCmdUI* pCmdUI) 
  490. {
  491.   pCmdUI->SetCheck(theApp.glFilter == 0);
  492. }
  493.  
  494. void MainWnd::OnOptionsVideoRenderoptionsGlbilinear() 
  495. {
  496.   theApp.glFilter = 1;
  497.   if(theApp.display)
  498.     theApp.display->setOption("glFilter", 1);
  499. }
  500.  
  501. void MainWnd::OnUpdateOptionsVideoRenderoptionsGlbilinear(CCmdUI* pCmdUI) 
  502. {
  503.   pCmdUI->SetCheck(theApp.glFilter == 1);
  504. }
  505.  
  506. void MainWnd::OnOptionsVideoRenderoptionsGltriangle() 
  507. {
  508.   theApp.glType = 0;
  509.   if(theApp.display)
  510.     theApp.display->setOption("glType", 0);
  511. }
  512.  
  513. void MainWnd::OnUpdateOptionsVideoRenderoptionsGltriangle(CCmdUI* pCmdUI) 
  514. {
  515.   pCmdUI->SetCheck(theApp.glType == 0);
  516. }
  517.  
  518. void MainWnd::OnOptionsVideoRenderoptionsGlquads() 
  519. {
  520.   theApp.glType = 1;
  521.   if(theApp.display)
  522.     theApp.display->setOption("glType", 1);
  523. }
  524.  
  525. void MainWnd::OnUpdateOptionsVideoRenderoptionsGlquads(CCmdUI* pCmdUI) 
  526. {
  527.   pCmdUI->SetCheck(theApp.glType == 1);
  528. }
  529.  
  530. void MainWnd::OnOptionsVideoRenderoptionsSelectskin() 
  531. {
  532.   LPCTSTR exts[] = {".ini" };
  533.   CString filter = winLoadFilter(IDS_FILTER_INI);
  534.   CString title = winResLoadString(IDS_SELECT_SKIN_FILE);
  535.  
  536.   FileDlg dlg(this,
  537.               theApp.skinName,
  538.               filter,
  539.               0,
  540.               "INI",
  541.               exts,
  542.               "", 
  543.               title,
  544.               false);
  545.  
  546.   if(dlg.DoModal() == IDCANCEL) {
  547.     return;
  548.   }
  549.  
  550.   bool result = false;
  551.   if(!theApp.skinEnabled) {
  552.     theApp.skinEnabled = !theApp.skinEnabled;    
  553.     regSetDwordValue("skinEnabled", theApp.skinEnabled);
  554.   }
  555.  
  556.   if(theApp.skin && theApp.skinEnabled) {
  557.     delete theApp.skin;
  558.     theApp.skin = NULL;
  559.   }
  560.  
  561.   theApp.skinName = dlg.GetPathName();
  562.  
  563.   theApp.winUpdateSkin();
  564.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  565. }
  566.  
  567. void MainWnd::OnUpdateOptionsVideoRenderoptionsSelectskin(CCmdUI* pCmdUI) 
  568. {
  569.   pCmdUI->Enable(theApp.display && theApp.display->isSkinSupported() &&
  570.                  theApp.videoOption <= VIDEO_4X);
  571. }
  572.  
  573. void MainWnd::OnOptionsVideoRenderoptionsSkin() 
  574. {
  575.   theApp.skinEnabled = !theApp.skinEnabled;
  576.   theApp.updateRenderMethod(true);
  577.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  578. }
  579.  
  580. void MainWnd::OnUpdateOptionsVideoRenderoptionsSkin(CCmdUI* pCmdUI) 
  581. {
  582.   pCmdUI->SetCheck(theApp.skinEnabled);
  583.   pCmdUI->Enable(theApp.display && theApp.display->isSkinSupported() && theApp.videoOption <= VIDEO_4X);
  584. }
  585.  
  586. void MainWnd::OnOptionsEmulatorAssociate() 
  587. {
  588.   theApp.winCheckFullscreen();
  589.   Associate dlg;
  590.   dlg.DoModal();
  591. }
  592.  
  593. void MainWnd::OnOptionsEmulatorDirectories() 
  594. {
  595.   theApp.winCheckFullscreen();
  596.   Directories dlg;
  597.   dlg.DoModal();
  598. }
  599.  
  600. void MainWnd::OnOptionsEmulatorDisablestatusmessages() 
  601. {
  602.   theApp.disableStatusMessage = !theApp.disableStatusMessage;
  603. }
  604.  
  605. void MainWnd::OnUpdateOptionsEmulatorDisablestatusmessages(CCmdUI* pCmdUI) 
  606. {
  607.   pCmdUI->SetCheck(theApp.disableStatusMessage);
  608. }
  609.  
  610. void MainWnd::OnOptionsEmulatorSynchronize() 
  611. {
  612.   synchronize = !synchronize;
  613. }
  614.  
  615. void MainWnd::OnUpdateOptionsEmulatorSynchronize(CCmdUI* pCmdUI) 
  616. {
  617.   pCmdUI->SetCheck(synchronize);
  618. }
  619.  
  620. void MainWnd::OnOptionsEmulatorPausewheninactive() 
  621. {
  622.   theApp.pauseWhenInactive = !theApp.pauseWhenInactive;
  623. }
  624.  
  625. void MainWnd::OnUpdateOptionsEmulatorPausewheninactive(CCmdUI* pCmdUI) 
  626. {
  627.   pCmdUI->SetCheck(theApp.pauseWhenInactive);
  628. }
  629.  
  630. void MainWnd::OnOptionsEmulatorSpeeduptoggle() 
  631. {
  632.   theApp.speedupToggle = !theApp.speedupToggle;
  633. }
  634.  
  635. void MainWnd::OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI* pCmdUI) 
  636. {
  637.   pCmdUI->SetCheck(theApp.speedupToggle);
  638. }
  639.  
  640. void MainWnd::OnOptionsEmulatorRemoveintrosgba() 
  641. {
  642.   //  theApp.removeIntros = !theApp.removeIntros;
  643. }
  644.  
  645. void MainWnd::OnUpdateOptionsEmulatorRemoveintrosgba(CCmdUI* pCmdUI) 
  646. {
  647.   pCmdUI->Enable(false);
  648.   //  pCmdUI->SetCheck(theApp.removeIntros);
  649. }
  650.  
  651. void MainWnd::OnOptionsEmulatorAutomaticallyipspatch() 
  652. {
  653.   theApp.autoIPS = !theApp.autoIPS;
  654. }
  655.  
  656. void MainWnd::OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI* pCmdUI) 
  657. {
  658.   pCmdUI->SetCheck(theApp.autoIPS);
  659. }
  660.  
  661. void MainWnd::OnOptionsEmulatorAgbprint() 
  662. {
  663.   agbPrintEnable(!agbPrintIsEnabled());
  664. }
  665.  
  666. void MainWnd::OnUpdateOptionsEmulatorAgbprint(CCmdUI* pCmdUI) 
  667. {
  668.   pCmdUI->SetCheck(agbPrintIsEnabled());
  669. }
  670.  
  671. void MainWnd::OnOptionsEmulatorRealtimeclock() 
  672. {
  673.   theApp.winRtcEnable = !theApp.winRtcEnable;
  674. }
  675.  
  676. void MainWnd::OnUpdateOptionsEmulatorRealtimeclock(CCmdUI* pCmdUI) 
  677. {
  678.   pCmdUI->SetCheck(theApp.winRtcEnable);
  679. }
  680.  
  681. void MainWnd::OnOptionsEmulatorAutohidemenu() 
  682. {
  683.   theApp.autoHideMenu = !theApp.autoHideMenu;
  684. }
  685.  
  686. void MainWnd::OnUpdateOptionsEmulatorAutohidemenu(CCmdUI* pCmdUI) 
  687. {
  688.   pCmdUI->SetCheck(theApp.autoHideMenu);
  689. }
  690.  
  691. void MainWnd::OnOptionsEmulatorRewindinterval() 
  692. {
  693.   RewindInterval dlg(theApp.rewindTimer/6);
  694.   int v = dlg.DoModal();
  695.  
  696.   if(v >= 0) {
  697.     theApp.rewindTimer = v*6; // convert to a multiple of 10 frames
  698.     regSetDwordValue("rewindTimer", v);
  699.     if(v == 0) {
  700.       if(theApp.rewindMemory)
  701.         free(theApp.rewindMemory);
  702.       theApp.rewindMemory = NULL;
  703.       theApp.rewindCount = 0;
  704.       theApp.rewindCounter = 0;
  705.       theApp.rewindSaveNeeded = false;
  706.     } else {
  707.       if(theApp.rewindMemory == NULL)
  708.         theApp.rewindMemory = (char *)malloc(8*REWIND_SIZE);
  709.     }
  710.   }
  711. }
  712.  
  713. BOOL MainWnd::OnOptionsEmulatorShowSpeed(UINT nID)
  714. {
  715.   switch(nID) {
  716.   case ID_OPTIONS_EMULATOR_SHOWSPEED_NONE:
  717.     theApp.showSpeed = 0;
  718.     systemSetTitle("VisualBoyAdvance");
  719.     break;
  720.   case ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE:
  721.     theApp.showSpeed = 1;
  722.     break;
  723.   case ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED:
  724.     theApp.showSpeed = 2;
  725.     break;
  726.   case ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT:
  727.     theApp.showSpeedTransparent = !theApp.showSpeedTransparent;
  728.     break;
  729.   default:
  730.     return FALSE;
  731.   }
  732.   return TRUE;
  733. }
  734.  
  735. void MainWnd::OnUpdateOptionsEmulatorShowSpeed(CCmdUI *pCmdUI)
  736. {
  737.   switch(pCmdUI->m_nID) {
  738.   case ID_OPTIONS_EMULATOR_SHOWSPEED_NONE:
  739.     pCmdUI->SetCheck(theApp.showSpeed == 0);
  740.     break;
  741.   case ID_OPTIONS_EMULATOR_SHOWSPEED_PERCENTAGE:
  742.     pCmdUI->SetCheck(theApp.showSpeed == 1);
  743.     break;
  744.   case ID_OPTIONS_EMULATOR_SHOWSPEED_DETAILED:
  745.     pCmdUI->SetCheck(theApp.showSpeed == 2);
  746.     break;
  747.   case ID_OPTIONS_EMULATOR_SHOWSPEED_TRANSPARENT:
  748.     pCmdUI->SetCheck(theApp.showSpeedTransparent);
  749.     break;
  750.   }
  751. }
  752.  
  753. void MainWnd::OnOptionsEmulatorSavetypeAutomatic() 
  754. {
  755.   theApp.winSaveType = 0;
  756. }
  757.  
  758. void MainWnd::OnUpdateOptionsEmulatorSavetypeAutomatic(CCmdUI* pCmdUI) 
  759. {
  760.   pCmdUI->SetCheck(theApp.winSaveType == 0);
  761. }
  762.  
  763. void MainWnd::OnOptionsEmulatorSavetypeEeprom() 
  764. {
  765.   theApp.winSaveType = 1;
  766. }
  767.  
  768. void MainWnd::OnUpdateOptionsEmulatorSavetypeEeprom(CCmdUI* pCmdUI) 
  769. {
  770.   pCmdUI->SetCheck(theApp.winSaveType == 1);
  771. }
  772.  
  773. void MainWnd::OnOptionsEmulatorSavetypeSram() 
  774. {
  775.   theApp.winSaveType = 2;
  776. }
  777.  
  778. void MainWnd::OnUpdateOptionsEmulatorSavetypeSram(CCmdUI* pCmdUI) 
  779. {
  780.   pCmdUI->SetCheck(theApp.winSaveType == 2);
  781. }
  782.  
  783. void MainWnd::OnOptionsEmulatorSavetypeFlash() 
  784. {
  785.   theApp.winSaveType = 3;
  786. }
  787.  
  788. void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash(CCmdUI* pCmdUI) 
  789. {
  790.   pCmdUI->SetCheck(theApp.winSaveType == 3);
  791. }
  792.  
  793. void MainWnd::OnOptionsEmulatorSavetypeEepromsensor() 
  794. {
  795.   theApp.winSaveType = 4;
  796. }
  797.  
  798. void MainWnd::OnUpdateOptionsEmulatorSavetypeEepromsensor(CCmdUI* pCmdUI) 
  799. {
  800.   pCmdUI->SetCheck(theApp.winSaveType == 4);
  801. }
  802.  
  803. void MainWnd::OnOptionsEmulatorSavetypeNone() 
  804. {
  805.   theApp.winSaveType = 5;
  806. }
  807.  
  808. void MainWnd::OnUpdateOptionsEmulatorSavetypeNone(CCmdUI* pCmdUI) 
  809. {
  810.   pCmdUI->SetCheck(theApp.winSaveType == 5);
  811. }
  812.  
  813. void MainWnd::OnOptionsEmulatorSavetypeFlash512k() 
  814. {
  815.   flashSetSize(0x10000);
  816.   theApp.winFlashSize = 0x10000;
  817. }
  818.  
  819. void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash512k(CCmdUI* pCmdUI) 
  820. {
  821.   pCmdUI->SetCheck(theApp.winFlashSize == 0x10000);
  822. }
  823.  
  824. void MainWnd::OnOptionsEmulatorSavetypeFlash1m() 
  825. {
  826.   flashSetSize(0x20000);
  827.   theApp.winFlashSize = 0x20000;
  828. }
  829.  
  830. void MainWnd::OnUpdateOptionsEmulatorSavetypeFlash1m(CCmdUI* pCmdUI) 
  831. {
  832.   pCmdUI->SetCheck(theApp.winFlashSize == 0x20000);
  833. }
  834.  
  835. void MainWnd::OnOptionsEmulatorUsebiosfile() 
  836. {
  837.   if(!theApp.biosFileName.IsEmpty())
  838.     theApp.useBiosFile = !theApp.useBiosFile;
  839. }
  840.  
  841. void MainWnd::OnUpdateOptionsEmulatorUsebiosfile(CCmdUI* pCmdUI) 
  842. {
  843.   pCmdUI->SetCheck(theApp.useBiosFile);
  844.   pCmdUI->Enable(!theApp.biosFileName.IsEmpty());
  845. }
  846.  
  847. void MainWnd::OnOptionsEmulatorSkipbios() 
  848. {
  849.   theApp.skipBiosFile = !theApp.skipBiosFile;
  850. }
  851.  
  852. void MainWnd::OnUpdateOptionsEmulatorSkipbios(CCmdUI* pCmdUI) 
  853. {
  854.   pCmdUI->SetCheck(theApp.skipBiosFile);
  855. }
  856.  
  857. void MainWnd::OnOptionsEmulatorSelectbiosfile() 
  858. {
  859.   theApp.winCheckFullscreen();
  860.   LPCTSTR exts[] = { "" };
  861.   CString filter = winLoadFilter(IDS_FILTER_BIOS);
  862.   CString title = winResLoadString(IDS_SELECT_BIOS_FILE);
  863.  
  864.   FileDlg dlg(this,
  865.               theApp.biosFileName,
  866.               filter,
  867.               0,
  868.               "BIOS",
  869.               exts,
  870.               "", 
  871.               title,
  872.               false);
  873.   
  874.   if(dlg.DoModal() == IDOK) {
  875.     theApp.biosFileName = dlg.GetPathName();
  876.   }
  877. }
  878.  
  879. void MainWnd::OnOptionsEmulatorPngformat() 
  880. {
  881.   theApp.captureFormat = 0;
  882. }
  883.  
  884. void MainWnd::OnUpdateOptionsEmulatorPngformat(CCmdUI* pCmdUI) 
  885. {
  886.   pCmdUI->SetCheck(theApp.captureFormat == 0);
  887. }
  888.  
  889. void MainWnd::OnOptionsEmulatorBmpformat() 
  890. {
  891.   theApp.captureFormat = 1;
  892. }
  893.  
  894. void MainWnd::OnUpdateOptionsEmulatorBmpformat(CCmdUI* pCmdUI) 
  895. {
  896.   pCmdUI->SetCheck(theApp.captureFormat == 1);
  897. }
  898.  
  899. void MainWnd::OnOptionsSoundOff() 
  900. {
  901.   soundOffFlag = true;
  902.   soundShutdown();
  903. }
  904.  
  905. void MainWnd::OnUpdateOptionsSoundOff(CCmdUI* pCmdUI) 
  906. {
  907.   pCmdUI->SetCheck(soundOffFlag);
  908. }
  909.  
  910. void MainWnd::OnOptionsSoundMute() 
  911. {
  912.   soundDisable(0x30f);
  913. }
  914.  
  915. void MainWnd::OnUpdateOptionsSoundMute(CCmdUI* pCmdUI) 
  916. {
  917.   int active = soundGetEnable() & 0x30f;
  918.   pCmdUI->SetCheck(active == 0);
  919. }
  920.  
  921. void MainWnd::OnOptionsSoundOn() 
  922. {
  923.   if(soundOffFlag) {
  924.     soundOffFlag = false;
  925.     soundInit();
  926.   }
  927.   soundEnable(0x30f);
  928. }
  929.  
  930. void MainWnd::OnUpdateOptionsSoundOn(CCmdUI* pCmdUI) 
  931. {
  932.   int active = soundGetEnable() & 0x30f;
  933.   pCmdUI->SetCheck(active != 0 && !soundOffFlag);
  934. }
  935.  
  936. void MainWnd::OnOptionsSoundUseoldsynchronization() 
  937. {
  938.   theApp.useOldSync = !theApp.useOldSync;
  939.   systemMessage(IDS_SETTING_WILL_BE_EFFECTIVE,
  940.                 "Setting will be effective the next time you start the emulator");      
  941. }
  942.  
  943. void MainWnd::OnUpdateOptionsSoundUseoldsynchronization(CCmdUI* pCmdUI) 
  944. {
  945.   pCmdUI->SetCheck(theApp.useOldSync);
  946. }
  947.  
  948. void MainWnd::OnOptionsSoundEcho() 
  949. {
  950.   soundEcho = !soundEcho;
  951. }
  952.  
  953. void MainWnd::OnUpdateOptionsSoundEcho(CCmdUI* pCmdUI) 
  954. {
  955.   pCmdUI->SetCheck(soundEcho);
  956. }
  957.  
  958. void MainWnd::OnOptionsSoundLowpassfilter() 
  959. {
  960.   soundLowPass = !soundLowPass;
  961. }
  962.  
  963. void MainWnd::OnUpdateOptionsSoundLowpassfilter(CCmdUI* pCmdUI) 
  964. {
  965.   pCmdUI->SetCheck(soundLowPass);
  966. }
  967.  
  968. void MainWnd::OnOptionsSoundReversestereo() 
  969. {
  970.   soundReverse = !soundReverse;
  971. }
  972.  
  973. void MainWnd::OnUpdateOptionsSoundReversestereo(CCmdUI* pCmdUI) 
  974. {
  975.   pCmdUI->SetCheck(soundReverse);
  976. }
  977.  
  978. void MainWnd::OnOptionsSound11khz() 
  979. {
  980.   if(theApp.cartridgeType == 0)
  981.     soundSetQuality(4);
  982.   else
  983.     gbSoundSetQuality(4);
  984. }
  985.  
  986. void MainWnd::OnUpdateOptionsSound11khz(CCmdUI* pCmdUI) 
  987. {
  988.   pCmdUI->SetCheck(soundQuality == 4);
  989. }
  990.  
  991. void MainWnd::OnOptionsSound22khz() 
  992. {
  993.   if(theApp.cartridgeType == 0)
  994.     soundSetQuality(2);
  995.   else
  996.     gbSoundSetQuality(2);
  997. }
  998.  
  999. void MainWnd::OnUpdateOptionsSound22khz(CCmdUI* pCmdUI) 
  1000. {
  1001.   pCmdUI->SetCheck(soundQuality == 2);
  1002. }
  1003.  
  1004. void MainWnd::OnOptionsSound44khz() 
  1005. {
  1006.   if(theApp.cartridgeType == 0)
  1007.     soundSetQuality(1);
  1008.   else
  1009.     gbSoundSetQuality(1);
  1010. }
  1011.  
  1012. void MainWnd::OnUpdateOptionsSound44khz(CCmdUI* pCmdUI) 
  1013. {
  1014.   pCmdUI->SetCheck(soundQuality == 1);
  1015. }
  1016.  
  1017. BOOL MainWnd::OnOptionsSoundVolume(UINT nID)
  1018. {
  1019.   soundVolume = nID - ID_OPTIONS_SOUND_VOLUME_1X;
  1020.   return TRUE;
  1021. }
  1022.  
  1023. void MainWnd::OnUpdateOptionsSoundVolume(CCmdUI *pCmdUI)
  1024. {
  1025.   pCmdUI->SetCheck(soundVolume == (int)(pCmdUI->m_nID - ID_OPTIONS_SOUND_VOLUME_1X));
  1026. }
  1027.  
  1028.  
  1029. void MainWnd::OnOptionsSoundVolume25x() 
  1030. {
  1031.   soundVolume = 4;
  1032. }
  1033.  
  1034. void MainWnd::OnUpdateOptionsSoundVolume25x(CCmdUI* pCmdUI) 
  1035. {
  1036.   pCmdUI->SetCheck(soundVolume == 4);
  1037. }
  1038.  
  1039. void MainWnd::OnOptionsSoundVolume5x() 
  1040. {
  1041.   soundVolume = 5;
  1042. }
  1043.  
  1044. void MainWnd::OnUpdateOptionsSoundVolume5x(CCmdUI* pCmdUI) 
  1045. {
  1046.   pCmdUI->SetCheck(soundVolume == 5);
  1047. }
  1048.  
  1049. void MainWnd::updateSoundChannels(UINT id)
  1050. {
  1051.   int flag = 0;
  1052.       
  1053.   if(id == ID_OPTIONS_SOUND_CHANNEL1)
  1054.     flag = 1;
  1055.  
  1056.   if(id == ID_OPTIONS_SOUND_CHANNEL2)
  1057.     flag = 2;
  1058.  
  1059.   if(id == ID_OPTIONS_SOUND_CHANNEL3)
  1060.     flag = 4;
  1061.  
  1062.   if(id == ID_OPTIONS_SOUND_CHANNEL4)
  1063.     flag = 8;
  1064.  
  1065.   if(id == ID_OPTIONS_SOUND_DIRECTSOUNDA)
  1066.     flag = 256;
  1067.  
  1068.   if(id == ID_OPTIONS_SOUND_DIRECTSOUNDB)
  1069.     flag = 512;
  1070.  
  1071.   int active = soundGetEnable() & 0x30f;
  1072.  
  1073.   if(active & flag)
  1074.     active &= (~flag);
  1075.   else
  1076.     active |= flag;
  1077.   
  1078.   soundEnable(active);
  1079.   soundDisable((~active)&0x30f);
  1080. }
  1081.  
  1082. void MainWnd::OnOptionsSoundChannel1() 
  1083. {
  1084.   updateSoundChannels(ID_OPTIONS_SOUND_CHANNEL1);
  1085. }
  1086.  
  1087. void MainWnd::OnUpdateOptionsSoundChannel1(CCmdUI* pCmdUI) 
  1088. {
  1089.   pCmdUI->SetCheck(soundGetEnable() & 1);
  1090. }
  1091.  
  1092. void MainWnd::OnOptionsSoundChannel2() 
  1093. {
  1094.   updateSoundChannels(ID_OPTIONS_SOUND_CHANNEL2);
  1095. }
  1096.  
  1097. void MainWnd::OnUpdateOptionsSoundChannel2(CCmdUI* pCmdUI) 
  1098. {
  1099.   pCmdUI->SetCheck(soundGetEnable() & 2);
  1100. }
  1101.  
  1102. void MainWnd::OnOptionsSoundChannel3() 
  1103. {
  1104.   updateSoundChannels(ID_OPTIONS_SOUND_CHANNEL3);
  1105. }
  1106.  
  1107. void MainWnd::OnUpdateOptionsSoundChannel3(CCmdUI* pCmdUI) 
  1108. {
  1109.   pCmdUI->SetCheck(soundGetEnable() & 4);
  1110. }
  1111.  
  1112. void MainWnd::OnOptionsSoundChannel4() 
  1113. {
  1114.   updateSoundChannels(ID_OPTIONS_SOUND_CHANNEL4);
  1115. }
  1116.  
  1117. void MainWnd::OnUpdateOptionsSoundChannel4(CCmdUI* pCmdUI) 
  1118. {
  1119.   pCmdUI->SetCheck(soundGetEnable() & 8);
  1120. }
  1121.  
  1122. void MainWnd::OnOptionsSoundDirectsounda() 
  1123. {
  1124.   updateSoundChannels(ID_OPTIONS_SOUND_DIRECTSOUNDA);
  1125. }
  1126.  
  1127. void MainWnd::OnUpdateOptionsSoundDirectsounda(CCmdUI* pCmdUI) 
  1128. {
  1129.   pCmdUI->SetCheck(soundGetEnable() & 256);
  1130.   pCmdUI->Enable(theApp.cartridgeType == 0);
  1131. }
  1132.  
  1133. void MainWnd::OnOptionsSoundDirectsoundb() 
  1134. {
  1135.   updateSoundChannels(ID_OPTIONS_SOUND_DIRECTSOUNDB);
  1136. }
  1137.  
  1138. void MainWnd::OnUpdateOptionsSoundDirectsoundb(CCmdUI* pCmdUI) 
  1139. {
  1140.   pCmdUI->SetCheck(soundGetEnable() & 512);
  1141.   pCmdUI->Enable(theApp.cartridgeType == 0);
  1142. }
  1143.  
  1144. void MainWnd::OnOptionsGameboyBorder() 
  1145. {
  1146.   theApp.winGbBorderOn = !theApp.winGbBorderOn;
  1147.   gbBorderOn = theApp.winGbBorderOn;
  1148.   if(emulating && theApp.cartridgeType == 1 && gbBorderOn) {
  1149.     gbSgbRenderBorder();
  1150.   }
  1151.   theApp.updateWindowSize(theApp.videoOption);
  1152. }
  1153.  
  1154. void MainWnd::OnUpdateOptionsGameboyBorder(CCmdUI* pCmdUI) 
  1155. {
  1156.   pCmdUI->SetCheck(theApp.winGbBorderOn);
  1157. }
  1158.  
  1159. void MainWnd::OnOptionsGameboyPrinter() 
  1160. {
  1161.   theApp.winGbPrinterEnabled = !theApp.winGbPrinterEnabled;
  1162.   if(theApp.winGbPrinterEnabled)
  1163.     gbSerialFunction = gbPrinterSend;
  1164.   else
  1165.     gbSerialFunction = NULL;
  1166. }
  1167.  
  1168. void MainWnd::OnUpdateOptionsGameboyPrinter(CCmdUI* pCmdUI) 
  1169. {
  1170.   pCmdUI->SetCheck(gbSerialFunction == gbPrinterSend);
  1171. }
  1172.  
  1173. void MainWnd::OnOptionsGameboyBorderAutomatic() 
  1174. {
  1175.   gbBorderAutomatic = !gbBorderAutomatic;
  1176.   if(emulating && theApp.cartridgeType == 1 && gbBorderOn) {
  1177.     gbSgbRenderBorder();
  1178.     theApp.updateWindowSize(theApp.videoOption);
  1179.   }
  1180. }
  1181.  
  1182. void MainWnd::OnUpdateOptionsGameboyBorderAutomatic(CCmdUI* pCmdUI) 
  1183. {
  1184.   pCmdUI->SetCheck(gbBorderAutomatic);  
  1185. }
  1186.  
  1187. void MainWnd::OnOptionsGameboyAutomatic() 
  1188. {
  1189.   gbEmulatorType = 0;
  1190. }
  1191.  
  1192. void MainWnd::OnUpdateOptionsGameboyAutomatic(CCmdUI* pCmdUI) 
  1193. {
  1194.   pCmdUI->SetCheck(gbEmulatorType == 0);
  1195. }
  1196.  
  1197. void MainWnd::OnOptionsGameboyGba() 
  1198. {
  1199.   gbEmulatorType = 4;
  1200. }
  1201.  
  1202. void MainWnd::OnUpdateOptionsGameboyGba(CCmdUI* pCmdUI) 
  1203. {
  1204.   pCmdUI->SetCheck(gbEmulatorType == 4);
  1205. }
  1206.  
  1207. void MainWnd::OnOptionsGameboyCgb() 
  1208. {
  1209.   gbEmulatorType = 1;
  1210. }
  1211.  
  1212. void MainWnd::OnUpdateOptionsGameboyCgb(CCmdUI* pCmdUI) 
  1213. {
  1214.   pCmdUI->SetCheck(gbEmulatorType == 1);
  1215. }
  1216.  
  1217. void MainWnd::OnOptionsGameboySgb() 
  1218. {
  1219.   gbEmulatorType = 2;  
  1220. }
  1221.  
  1222. void MainWnd::OnUpdateOptionsGameboySgb(CCmdUI* pCmdUI) 
  1223. {
  1224.   pCmdUI->SetCheck(gbEmulatorType == 2);
  1225. }
  1226.  
  1227. void MainWnd::OnOptionsGameboySgb2() 
  1228. {
  1229.   gbEmulatorType = 5;  
  1230. }
  1231.  
  1232. void MainWnd::OnUpdateOptionsGameboySgb2(CCmdUI* pCmdUI) 
  1233. {
  1234.   pCmdUI->SetCheck(gbEmulatorType == 5);
  1235. }
  1236.  
  1237. void MainWnd::OnOptionsGameboyGb() 
  1238. {
  1239.   gbEmulatorType = 3;  
  1240. }
  1241.  
  1242. void MainWnd::OnUpdateOptionsGameboyGb(CCmdUI* pCmdUI) 
  1243. {
  1244.   pCmdUI->SetCheck(gbEmulatorType == 3);
  1245. }
  1246.  
  1247. void MainWnd::OnOptionsGameboyRealcolors() 
  1248. {
  1249.   gbColorOption = 0;  
  1250. }
  1251.  
  1252. void MainWnd::OnUpdateOptionsGameboyRealcolors(CCmdUI* pCmdUI) 
  1253. {
  1254.   pCmdUI->SetCheck(gbColorOption == 0);  
  1255. }
  1256.  
  1257. void MainWnd::OnOptionsGameboyGameboycolors() 
  1258. {
  1259.   gbColorOption = 1;  
  1260. }
  1261.  
  1262. void MainWnd::OnUpdateOptionsGameboyGameboycolors(CCmdUI* pCmdUI) 
  1263. {
  1264.   pCmdUI->SetCheck(gbColorOption == 1);  
  1265. }
  1266.  
  1267.  
  1268. void MainWnd::OnOptionsGameboyColors() 
  1269. {
  1270.   theApp.winCheckFullscreen();
  1271.   GBColorDlg dlg;
  1272.   if(dlg.DoModal()) {
  1273.     gbPaletteOption = dlg.getWhich();
  1274.     memcpy(systemGbPalette, dlg.getColors(), 24*sizeof(u16));
  1275.     if(emulating && theApp.cartridgeType == 1) {
  1276.       memcpy(gbPalette, &systemGbPalette[dlg.getWhich()*8], 8*sizeof(u16));
  1277.     }
  1278.   }
  1279. }
  1280.  
  1281. BOOL MainWnd::OnOptionsPriority(UINT nID)
  1282. {
  1283.   switch(nID) {
  1284.   case ID_OPTIONS_PRIORITY_HIGHEST:
  1285.     theApp.threadPriority = 0;
  1286.     break;
  1287.   case ID_OPTIONS_PRIORITY_ABOVENORMAL:
  1288.     theApp.threadPriority = 1;
  1289.     break;
  1290.   case ID_OPTIONS_PRIORITY_NORMAL:
  1291.     theApp.threadPriority = 2;
  1292.     break;
  1293.   case ID_OPTIONS_PRIORITY_BELOWNORMAL:
  1294.     theApp.threadPriority = 3;
  1295.     break;
  1296.   default:
  1297.     return FALSE;
  1298.   }
  1299.   theApp.updatePriority();
  1300.  
  1301.   return TRUE;
  1302. }
  1303.  
  1304. void MainWnd::OnUpdateOptionsPriority(CCmdUI *pCmdUI)
  1305. {
  1306.   switch(pCmdUI->m_nID) {
  1307.   case ID_OPTIONS_PRIORITY_HIGHEST:
  1308.     pCmdUI->SetCheck(theApp.threadPriority == 0);
  1309.     break;
  1310.   case ID_OPTIONS_PRIORITY_ABOVENORMAL:
  1311.     pCmdUI->SetCheck(theApp.threadPriority == 1);
  1312.     break;
  1313.   case ID_OPTIONS_PRIORITY_NORMAL:
  1314.     pCmdUI->SetCheck(theApp.threadPriority == 2);
  1315.     break;
  1316.   case ID_OPTIONS_PRIORITY_BELOWNORMAL:
  1317.     pCmdUI->SetCheck(theApp.threadPriority == 3);
  1318.     break;
  1319.   }
  1320. }
  1321.  
  1322. BOOL MainWnd::OnOptionsFilter(UINT nID)
  1323. {
  1324.   switch(nID) {
  1325.   case ID_OPTIONS_FILTER_NORMAL:
  1326.     theApp.filterType = 0;
  1327.     break;
  1328.   case ID_OPTIONS_FILTER_TVMODE:
  1329.     theApp.filterType = 1;
  1330.     break;
  1331.   case ID_OPTIONS_FILTER_2XSAI:
  1332.     theApp.filterType = 2;
  1333.     break;
  1334.   case ID_OPTIONS_FILTER_SUPER2XSAI:
  1335.     theApp.filterType = 3;
  1336.     break;
  1337.   case ID_OPTIONS_FILTER_SUPEREAGLE:
  1338.     theApp.filterType = 4;
  1339.     break;
  1340.   case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL:
  1341.     theApp.filterType = 5;
  1342.     break;
  1343.   case ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL:
  1344.     theApp.filterType = 6;
  1345.     break;
  1346.   case ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X:
  1347.     theApp.filterType = 7;
  1348.     break;
  1349.   case ID_OPTIONS_FILTER16BIT_SIMPLE2X:
  1350.     theApp.filterType = 8;
  1351.     break;
  1352.   case ID_OPTIONS_FILTER_BILINEAR:
  1353.     theApp.filterType = 9;
  1354.     break;
  1355.   case ID_OPTIONS_FILTER_BILINEARPLUS:
  1356.     theApp.filterType = 10;
  1357.     break;
  1358.   case ID_OPTIONS_FILTER_SCANLINES:
  1359.     theApp.filterType = 11;
  1360.     break;
  1361.   case ID_OPTIONS_FILTER_HQ2X:
  1362.     theApp.filterType = 12;
  1363.     break;
  1364.   case ID_OPTIONS_FILTER_LQ2X:
  1365.     theApp.filterType = 13;
  1366.     break;
  1367.   default:
  1368.     return FALSE;
  1369.   }
  1370.   theApp.updateFilter();
  1371.   return TRUE;
  1372. }
  1373.  
  1374. void MainWnd::OnUpdateOptionsFilter(CCmdUI *pCmdUI)
  1375. {
  1376.   pCmdUI->Enable(systemColorDepth == 16 || systemColorDepth == 32);
  1377.   switch(pCmdUI->m_nID) {
  1378.   case ID_OPTIONS_FILTER_NORMAL:
  1379.     pCmdUI->SetCheck(theApp.filterType == 0);
  1380.     break;
  1381.   case ID_OPTIONS_FILTER_TVMODE:
  1382.     pCmdUI->SetCheck(theApp.filterType == 1);
  1383.     break;
  1384.   case ID_OPTIONS_FILTER_2XSAI:
  1385.     pCmdUI->SetCheck(theApp.filterType == 2);
  1386.     break;
  1387.   case ID_OPTIONS_FILTER_SUPER2XSAI:
  1388.     pCmdUI->SetCheck(theApp.filterType == 3);
  1389.     break;
  1390.   case ID_OPTIONS_FILTER_SUPEREAGLE:
  1391.     pCmdUI->SetCheck(theApp.filterType == 4);
  1392.     break;
  1393.   case ID_OPTIONS_FILTER16BIT_PIXELATEEXPERIMENTAL:
  1394.     pCmdUI->SetCheck(theApp.filterType == 5);
  1395.     break;
  1396.   case ID_OPTIONS_FILTER16BIT_MOTIONBLUREXPERIMENTAL:
  1397.     pCmdUI->SetCheck(theApp.filterType == 6);
  1398.     break;
  1399.   case ID_OPTIONS_FILTER16BIT_ADVANCEMAMESCALE2X:
  1400.     pCmdUI->SetCheck(theApp.filterType == 7);
  1401.     break;
  1402.   case ID_OPTIONS_FILTER16BIT_SIMPLE2X:
  1403.     pCmdUI->SetCheck(theApp.filterType == 8);
  1404.     break;
  1405.   case ID_OPTIONS_FILTER_BILINEAR:
  1406.     pCmdUI->SetCheck(theApp.filterType == 9);
  1407.     break;
  1408.   case ID_OPTIONS_FILTER_BILINEARPLUS:
  1409.     pCmdUI->SetCheck(theApp.filterType == 10);
  1410.     break;
  1411.   case ID_OPTIONS_FILTER_SCANLINES:
  1412.     pCmdUI->SetCheck(theApp.filterType == 11);
  1413.     break;
  1414.   case ID_OPTIONS_FILTER_HQ2X:
  1415.     pCmdUI->SetCheck(theApp.filterType == 12);
  1416.     break;
  1417.   case ID_OPTIONS_FILTER_LQ2X:
  1418.     pCmdUI->SetCheck(theApp.filterType == 13);
  1419.     break;
  1420.   }
  1421. }
  1422.  
  1423. BOOL MainWnd::OnOptionsFilterIFB(UINT nID)
  1424. {
  1425.   switch(nID) {
  1426.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE:
  1427.     theApp.ifbType = 0;
  1428.     break;
  1429.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR:
  1430.     theApp.ifbType = 1;
  1431.     break;
  1432.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART:
  1433.     theApp.ifbType = 2;
  1434.     break;
  1435.   default:
  1436.     return FALSE;
  1437.   }
  1438.   theApp.updateIFB();
  1439.   return TRUE;
  1440. }
  1441.  
  1442. void MainWnd::OnUpdateOptionsFilterIFB(CCmdUI *pCmdUI)
  1443. {
  1444.   switch(pCmdUI->m_nID) {
  1445.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_NONE:
  1446.     pCmdUI->SetCheck(theApp.ifbType == 0);
  1447.     break;
  1448.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_MOTIONBLUR:
  1449.     pCmdUI->SetCheck(theApp.ifbType == 1);
  1450.     break;
  1451.   case ID_OPTIONS_FILTER_INTERFRAMEBLENDING_SMART:
  1452.     pCmdUI->SetCheck(theApp.ifbType == 2);
  1453.     break;
  1454.   }
  1455. }
  1456.  
  1457. void MainWnd::OnOptionsFilterDisablemmx() 
  1458. {
  1459.   theApp.disableMMX = !theApp.disableMMX;
  1460.   if(!theApp.disableMMX)
  1461.     cpu_mmx = theApp.detectMMX();
  1462.   else
  1463.     cpu_mmx = 0;
  1464. }
  1465.  
  1466. void MainWnd::OnUpdateOptionsFilterDisablemmx(CCmdUI* pCmdUI) 
  1467. {
  1468.   pCmdUI->SetCheck(theApp.disableMMX);
  1469. }
  1470.  
  1471.  
  1472. void MainWnd::OnOptionsLanguageSystem() 
  1473. {
  1474.   theApp.winSetLanguageOption(0, false);
  1475.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  1476. }
  1477.  
  1478. void MainWnd::OnUpdateOptionsLanguageSystem(CCmdUI* pCmdUI) 
  1479. {
  1480.   pCmdUI->SetCheck(theApp.languageOption == 0);
  1481. }
  1482.  
  1483. void MainWnd::OnOptionsLanguageEnglish() 
  1484. {
  1485.   theApp.winSetLanguageOption(1, false);
  1486.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  1487. }
  1488.  
  1489. void MainWnd::OnUpdateOptionsLanguageEnglish(CCmdUI* pCmdUI) 
  1490. {
  1491.   pCmdUI->SetCheck(theApp.languageOption == 1);
  1492. }
  1493.  
  1494. void MainWnd::OnOptionsLanguageOther() 
  1495. {
  1496.   theApp.winCheckFullscreen();
  1497.   theApp.winSetLanguageOption(2, false);
  1498.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  1499. }
  1500.  
  1501. void MainWnd::OnUpdateOptionsLanguageOther(CCmdUI* pCmdUI) 
  1502. {
  1503.   pCmdUI->SetCheck(theApp.languageOption == 2);
  1504. }
  1505.  
  1506.  
  1507. void MainWnd::OnOptionsJoypadConfigure1() 
  1508. {
  1509.   theApp.winCheckFullscreen();
  1510.   JoypadConfig dlg(0);
  1511.   dlg.DoModal();
  1512. }
  1513.  
  1514. void MainWnd::OnUpdateOptionsJoypadConfigure1(CCmdUI* pCmdUI) 
  1515. {
  1516.   pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
  1517. }
  1518.  
  1519. void MainWnd::OnOptionsJoypadConfigure2() 
  1520. {
  1521.   theApp.winCheckFullscreen();
  1522.   JoypadConfig dlg(1);
  1523.   dlg.DoModal();
  1524. }
  1525.  
  1526. void MainWnd::OnUpdateOptionsJoypadConfigure2(CCmdUI* pCmdUI) 
  1527. {
  1528.   pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
  1529. }
  1530.  
  1531. void MainWnd::OnOptionsJoypadConfigure3() 
  1532. {
  1533.   theApp.winCheckFullscreen();
  1534.   JoypadConfig dlg(2);
  1535.   dlg.DoModal();
  1536. }
  1537.  
  1538. void MainWnd::OnUpdateOptionsJoypadConfigure3(CCmdUI* pCmdUI) 
  1539. {
  1540.   pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
  1541. }
  1542.  
  1543. void MainWnd::OnOptionsJoypadConfigure4() 
  1544. {
  1545.   theApp.winCheckFullscreen();
  1546.   JoypadConfig dlg(3);
  1547.   dlg.DoModal();
  1548. }
  1549.  
  1550. void MainWnd::OnUpdateOptionsJoypadConfigure4(CCmdUI* pCmdUI) 
  1551. {
  1552.   pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
  1553. }
  1554.  
  1555. BOOL MainWnd::OnOptionsJoypadDefault(UINT nID)
  1556. {
  1557.   theApp.joypadDefault = nID - ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1;
  1558.   return TRUE;
  1559. }
  1560.  
  1561. void MainWnd::OnUpdateOptionsJoypadDefault(CCmdUI *pCmdUI)
  1562. {
  1563.   pCmdUI->SetCheck(theApp.joypadDefault == (int)(pCmdUI->m_nID - ID_OPTIONS_JOYPAD_DEFAULTJOYPAD_1));
  1564. }
  1565.  
  1566. void MainWnd::OnOptionsJoypadMotionconfigure() 
  1567. {
  1568.   theApp.winCheckFullscreen();
  1569.   MotionConfig dlg;
  1570.   dlg.DoModal();
  1571. }
  1572.  
  1573. void MainWnd::OnUpdateOptionsJoypadMotionconfigure(CCmdUI* pCmdUI) 
  1574. {
  1575.   pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
  1576. }
  1577.  
  1578. BOOL MainWnd::OnOptionsJoypadAutofire(UINT nID)
  1579. {
  1580.   switch(nID) {
  1581.   case ID_OPTIONS_JOYPAD_AUTOFIRE_A:
  1582.     if(theApp.autoFire & 1) {
  1583.       theApp.autoFire &= ~1;
  1584.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_A_DISABLED));
  1585.     } else {
  1586.       theApp.autoFire |= 1;
  1587.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_A));
  1588.     }
  1589.     break;
  1590.   case ID_OPTIONS_JOYPAD_AUTOFIRE_B:
  1591.     if(theApp.autoFire & 2) {
  1592.       theApp.autoFire &= ~2;
  1593.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_B_DISABLED));
  1594.     } else {
  1595.       theApp.autoFire |= 2;
  1596.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_B));
  1597.     }
  1598.     break;
  1599.   case ID_OPTIONS_JOYPAD_AUTOFIRE_L:
  1600.     if(theApp.autoFire & 512) {
  1601.       theApp.autoFire &= ~512;
  1602.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_L_DISABLED));
  1603.     } else {
  1604.       theApp.autoFire |= 512;
  1605.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_L));
  1606.     }
  1607.     break;
  1608.   case ID_OPTIONS_JOYPAD_AUTOFIRE_R:
  1609.     if(theApp.autoFire & 256) {
  1610.       theApp.autoFire &= ~256;
  1611.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_R_DISABLED));
  1612.     } else {
  1613.       theApp.autoFire |= 256;
  1614.       systemScreenMessage(winResLoadString(IDS_AUTOFIRE_R));
  1615.     }
  1616.     break;
  1617.   default:
  1618.     return FALSE;
  1619.   }
  1620.   return TRUE;
  1621. }
  1622.  
  1623. void MainWnd::OnUpdateOptionsJoypadAutofire(CCmdUI *pCmdUI)
  1624. {
  1625.   bool check = true;
  1626.   switch(pCmdUI->m_nID) {
  1627.   case ID_OPTIONS_JOYPAD_AUTOFIRE_A:
  1628.     check = (theApp.autoFire & 1) != 0;
  1629.     break;
  1630.   case ID_OPTIONS_JOYPAD_AUTOFIRE_B:
  1631.     check = (theApp.autoFire & 2) != 0;
  1632.     break;
  1633.   case ID_OPTIONS_JOYPAD_AUTOFIRE_L:
  1634.     check = (theApp.autoFire & 512) != 0;
  1635.     break;
  1636.   case ID_OPTIONS_JOYPAD_AUTOFIRE_R:
  1637.     check = (theApp.autoFire & 256) != 0;
  1638.     break;
  1639.   }
  1640.   pCmdUI->SetCheck(check);
  1641. }
  1642.  
  1643. LRESULT MainWnd::OnConfirmMode(WPARAM, LPARAM)
  1644. {
  1645.   // we need to do this separately or the window will not have the right
  1646.   // parent. must be related to the way MFC does modal dialogs
  1647.   winConfirmMode();
  1648.   return 0;
  1649. }
  1650.  
  1651. void MainWnd::winConfirmMode()
  1652. {
  1653.   if(theApp.renderMethod == DIRECT_DRAW && theApp.videoOption > VIDEO_4X) {
  1654.     theApp.winCheckFullscreen();
  1655.     ModeConfirm dlg(theApp.m_pMainWnd);
  1656.  
  1657.     if(!dlg.DoModal()) {
  1658.       theApp.updateVideoSize(ID_OPTIONS_VIDEO_X2);
  1659.     }
  1660.   }
  1661.   theApp.winAccelMgr.UpdateMenu(theApp.menu);
  1662. }
  1663.  
  1664. void MainWnd::OnOptionsVideoFullscreenmaxscale() 
  1665. {
  1666.   MaxScale dlg;
  1667.  
  1668.   theApp.winCheckFullscreen();
  1669.  
  1670.   dlg.DoModal();
  1671. }
  1672.