diff src/win32/MainWndFile.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/MainWndFile.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,1004 @@
     1.4 +#include "stdafx.h"
     1.5 +#include "resource.h"
     1.6 +#include "MainWnd.h"
     1.7 +#include "ExportGSASnapshot.h"
     1.8 +#include "FileDlg.h"
     1.9 +#include "GSACodeSelect.h"
    1.10 +#include "RomInfo.h"
    1.11 +#include "Reg.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "WinMiscUtil.h"
    1.14 +#include "LuaOpenDialog.h"
    1.15 +#include "ram_search.h"
    1.16 +#include "ramwatch.h"
    1.17 +#include "Sound.h"
    1.18 +#include "VBA.h"
    1.19 +
    1.20 +#include "../NLS.h"
    1.21 +#include "../version.h"
    1.22 +#include "../gba/GBA.h"
    1.23 +#include "../gba/GBAGlobals.h"
    1.24 +#include "../gba/EEprom.h"
    1.25 +#include "../gba/GBASound.h"
    1.26 +#include "../gb/GB.h"
    1.27 +#include "../gb/gbGlobals.h"
    1.28 +#include "../common/movie.h"
    1.29 +#include "../common/vbalua.h"
    1.30 +
    1.31 +void MainWnd::OnFileOpen()
    1.32 +{
    1.33 +	theApp.winCheckFullscreen();
    1.34 +	if (winFileOpenSelect(0))
    1.35 +	{
    1.36 +		winFileRun();
    1.37 +	}
    1.38 +}
    1.39 +
    1.40 +void MainWnd::OnFileOpenGBx()
    1.41 +{
    1.42 +	theApp.winCheckFullscreen();
    1.43 +	if (winFileOpenSelect(1))
    1.44 +	{
    1.45 +		winFileRun();
    1.46 +	}
    1.47 +}
    1.48 +
    1.49 +void MainWnd::OnFilePause()
    1.50 +{
    1.51 +	systemSetPause(!theApp.paused);
    1.52 +}
    1.53 +
    1.54 +void MainWnd::OnUpdateFilePause(CCmdUI *pCmdUI)
    1.55 +{
    1.56 +	pCmdUI->SetCheck(theApp.paused);
    1.57 +}
    1.58 +
    1.59 +void MainWnd::OnFileReset()
    1.60 +{
    1.61 +	if (emulating)
    1.62 +	{
    1.63 +		if (VBAMovieGetState() == MOVIE_STATE_PLAY)
    1.64 +		{
    1.65 +			OnToolsPlayRestart();   // HACK: shortcut
    1.66 +		}
    1.67 +		else
    1.68 +		{
    1.69 +			theApp.emulator.emuReset(true);
    1.70 +			systemScreenMessage(winResLoadString(IDS_RESET));
    1.71 +		}
    1.72 +	}
    1.73 +}
    1.74 +
    1.75 +void MainWnd::OnUpdateFileReset(CCmdUI *pCmdUI)
    1.76 +{
    1.77 +	pCmdUI->Enable(emulating);
    1.78 +}
    1.79 +
    1.80 +void MainWnd::OnFileRecentFreeze()
    1.81 +{
    1.82 +	theApp.recentFreeze = !theApp.recentFreeze;
    1.83 +}
    1.84 +
    1.85 +void MainWnd::OnUpdateFileRecentFreeze(CCmdUI *pCmdUI)
    1.86 +{
    1.87 +	pCmdUI->SetCheck(theApp.recentFreeze);
    1.88 +}
    1.89 +
    1.90 +void MainWnd::OnFileRecentReset()
    1.91 +{
    1.92 +	theApp.winCheckFullscreen();
    1.93 +	systemSoundClearBuffer();
    1.94 +	if (MessageBox("Really clear your recent ROMs list?", //winResLoadString(IDS_REALLY_CLEAR),
    1.95 +	               winResLoadString(IDS_CONFIRM_ACTION),
    1.96 +	               MB_YESNO | MB_DEFBUTTON2) == IDNO)
    1.97 +		return;
    1.98 +
    1.99 +	for (int i = 0; i < 10; ++i)
   1.100 +		theApp.recentFiles[i] = "";
   1.101 +}
   1.102 +
   1.103 +BOOL MainWnd::OnFileRecentFile(UINT nID)
   1.104 +{
   1.105 +	if (theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1].GetLength())
   1.106 +	{
   1.107 +		theApp.romFilename = theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1];
   1.108 +		winFileRun();
   1.109 +	}
   1.110 +	return TRUE;
   1.111 +}
   1.112 +
   1.113 +void MainWnd::OnUpdateFileRecentFile(CCmdUI *pCmdUI)
   1.114 +{
   1.115 +	int fileID = pCmdUI->m_nID - ID_FILE_MRU_FILE1;
   1.116 +
   1.117 +	bool bExist = !theApp.recentFiles[fileID].IsEmpty();
   1.118 +
   1.119 +	if (pCmdUI->m_pMenu != NULL)
   1.120 +	{
   1.121 +		CString p = theApp.recentFiles[fileID];
   1.122 +
   1.123 +		int index = max(p.ReverseFind('/'), max(p.ReverseFind('\\'), p.ReverseFind('|')));
   1.124 +
   1.125 +		if (index != -1)
   1.126 +		{
   1.127 +			p.Delete(0, index + 1);
   1.128 +		}
   1.129 +
   1.130 +		p.Replace("&", "&&");
   1.131 +
   1.132 +		CString number("1&0 - ");
   1.133 +		if (fileID < 9)
   1.134 +			number.Format("&%d - ", fileID + 1);
   1.135 +
   1.136 +		if (p.IsEmpty())
   1.137 +		{
   1.138 +			p	   = "No Recent ROM";
   1.139 +			bExist = false;
   1.140 +		}
   1.141 +
   1.142 +		pCmdUI->SetText(number + p);
   1.143 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.144 +	}
   1.145 +
   1.146 +	pCmdUI->Enable(bExist);
   1.147 +}
   1.148 +
   1.149 +void MainWnd::OnFileExit()
   1.150 +{
   1.151 +	if (AskSave())
   1.152 +		SendMessage(WM_CLOSE);
   1.153 +}
   1.154 +
   1.155 +void MainWnd::OnFileClose()
   1.156 +{
   1.157 +	// save battery file before we change the filename...
   1.158 +	CloseRamWindows();
   1.159 +	winFileClose();
   1.160 +}
   1.161 +
   1.162 +void MainWnd::OnUpdateFileClose(CCmdUI *pCmdUI)
   1.163 +{
   1.164 +	pCmdUI->Enable(emulating);
   1.165 +}
   1.166 +
   1.167 +void MainWnd::OnFileLoad()
   1.168 +{
   1.169 +	theApp.winCheckFullscreen();
   1.170 +
   1.171 +	LPCTSTR exts[] = { ".sgm", NULL };
   1.172 +	CString filter = winResLoadFilter(IDS_FILTER_SGM);
   1.173 +	CString title  = winResLoadString(IDS_SELECT_SAVE_GAME_NAME);
   1.174 +
   1.175 +	CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]);
   1.176 +	CString saveDir	 = winGetDestDir(IDS_SAVE_DIR);
   1.177 +
   1.178 +	FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, false, true);
   1.179 +
   1.180 +	if (dlg.DoModal() == IDOK)
   1.181 +	{
   1.182 +		bool res = winReadSaveGame(dlg.GetPathName());
   1.183 +
   1.184 +		theApp.rewindCount		= 0;
   1.185 +		theApp.rewindCounter	= 0;
   1.186 +		theApp.rewindSaveNeeded = false;
   1.187 +
   1.188 +		if (res)
   1.189 +		{
   1.190 +			if (VBAMovieActive() && !VBAMovieReadOnly())
   1.191 +			{
   1.192 +				VBAMovieSwitchToRecording();
   1.193 +			}
   1.194 +			systemScreenMessage(winResLoadString(IDS_LOADED_STATE));
   1.195 +		}
   1.196 +	}
   1.197 +}
   1.198 +
   1.199 +void MainWnd::OnUpdateFileLoad(CCmdUI *pCmdUI)
   1.200 +{
   1.201 +	pCmdUI->Enable(emulating);
   1.202 +}
   1.203 +
   1.204 +BOOL MainWnd::OnFileLoadSlot(UINT nID)
   1.205 +{
   1.206 +	nID = nID + 1 - ID_FILE_LOADGAME_SLOT1;
   1.207 +
   1.208 +	CString filename = winGetSavestateFilename(theApp.gameFilename, nID);
   1.209 +
   1.210 +	bool res = winReadSaveGame(filename);
   1.211 +
   1.212 +	// deleting rewinds because you loaded a save state is stupid
   1.213 +///  theApp.rewindCount = 0;
   1.214 +///  theApp.rewindCounter = 0;
   1.215 +///  theApp.rewindSaveNeeded = false;
   1.216 +
   1.217 +	if (res)
   1.218 +	{
   1.219 +		CString format;
   1.220 +		if (VBAMovieActive())
   1.221 +		{
   1.222 +			if (VBAMovieReadOnly())
   1.223 +			{
   1.224 +				format = winResLoadString(IDS_REPLAYED_STATE_N);
   1.225 +			}
   1.226 +			else
   1.227 +			{
   1.228 +				VBAMovieSwitchToRecording();
   1.229 +				format = winResLoadString(IDS_RERECORDED_STATE_N);
   1.230 +			}
   1.231 +		}
   1.232 +		else
   1.233 +		{
   1.234 +			format = winResLoadString(IDS_LOADED_STATE_N);
   1.235 +		}
   1.236 +
   1.237 +		CString buffer;
   1.238 +		buffer.Format(format, nID);
   1.239 +		systemScreenMessage(buffer);
   1.240 +
   1.241 +		int lastSlot = theApp.currentSlot;
   1.242 +
   1.243 +		if (theApp.loadMakesRecent)
   1.244 +		{
   1.245 +			// to update the file's modification date
   1.246 +			SYSTEMTIME st;
   1.247 +			FILETIME   ft;
   1.248 +			GetSystemTime(&st);
   1.249 +			SystemTimeToFileTime(&st, &ft);
   1.250 +			HANDLE fh = CreateFile(filename, 
   1.251 +									GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 
   1.252 +									NULL, 
   1.253 +									OPEN_EXISTING, 
   1.254 +									0, 
   1.255 +									NULL);
   1.256 +			if (fh != INVALID_HANDLE_VALUE)
   1.257 +				SetFileTime(fh, NULL, NULL, &ft);
   1.258 +			CloseHandle(fh);
   1.259 +		}
   1.260 +
   1.261 +		if (theApp.loadMakesCurrent)
   1.262 +			theApp.currentSlot = nID - 1;
   1.263 +		else
   1.264 +			theApp.currentSlot = lastSlot;  // restore value in case the call to OnFileSaveSlot changed it
   1.265 +
   1.266 +		theApp.frameSearching	   = false;
   1.267 +		theApp.frameSearchSkipping = false;
   1.268 +	}
   1.269 +
   1.270 +	return res;
   1.271 +}
   1.272 +
   1.273 +void MainWnd::OnFileSave()
   1.274 +{
   1.275 +	theApp.winCheckFullscreen();
   1.276 +
   1.277 +	LPCTSTR exts[] = { ".sgm", NULL };
   1.278 +	CString filter = winResLoadFilter(IDS_FILTER_SGM);
   1.279 +	CString title  = winResLoadString(IDS_SELECT_SAVE_GAME_NAME);
   1.280 +
   1.281 +	CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]);
   1.282 +	CString saveDir	 = winGetDestDir(IDS_SAVE_DIR);
   1.283 +
   1.284 +	FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, true);
   1.285 +
   1.286 +	if (dlg.DoModal() == IDOK)
   1.287 +	{
   1.288 +		bool res = winWriteSaveGame(dlg.GetPathName());
   1.289 +		if (res)
   1.290 +			systemScreenMessage(winResLoadString(IDS_WROTE_STATE));
   1.291 +	}
   1.292 +}
   1.293 +
   1.294 +void MainWnd::OnUpdateFileSave(CCmdUI *pCmdUI)
   1.295 +{
   1.296 +	pCmdUI->Enable(emulating);
   1.297 +}
   1.298 +
   1.299 +BOOL MainWnd::OnFileSaveSlot(UINT nID)
   1.300 +{
   1.301 +	nID = nID + 1 - ID_FILE_SAVEGAME_SLOT1;
   1.302 +
   1.303 +	if (theApp.saveMakesCurrent)
   1.304 +		theApp.currentSlot = nID - 1;
   1.305 +
   1.306 +	CString filename = winGetSavestateFilename(theApp.gameFilename, nID);
   1.307 +
   1.308 +	bool res = winWriteSaveGame(filename);
   1.309 +
   1.310 +	CString format = winResLoadString(IDS_WROTE_STATE_N);
   1.311 +	CString buffer;
   1.312 +	buffer.Format(format, nID);
   1.313 +
   1.314 +	systemScreenMessage(buffer);
   1.315 +
   1.316 +	return res;
   1.317 +}
   1.318 +
   1.319 +BOOL MainWnd::OnSelectSlot(UINT nID)
   1.320 +{
   1.321 +	nID -= ID_SELECT_SLOT1;
   1.322 +	theApp.currentSlot = nID;
   1.323 +
   1.324 +	CString buffer;
   1.325 +	buffer.Format("Slot %d selected", nID + 1);
   1.326 +	systemScreenMessage(buffer, 0);
   1.327 +
   1.328 +	return true;
   1.329 +}
   1.330 +
   1.331 +void MainWnd::OnFileImportBatteryfile()
   1.332 +{
   1.333 +	theApp.winCheckFullscreen();
   1.334 +
   1.335 +	LPCTSTR exts[] = { ".sav", NULL };
   1.336 +	CString filter = winResLoadFilter(IDS_FILTER_SAV);
   1.337 +	CString title  = winResLoadString(IDS_SELECT_BATTERY_FILE);
   1.338 +
   1.339 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]);
   1.340 +	CString batteryDir	= winGetDestDir(IDS_BATTERY_DIR);
   1.341 +
   1.342 +	FileDlg dlg(this, batteryName, filter, 0, "SAV", exts, batteryDir, title, false, true);
   1.343 +
   1.344 +	if (dlg.DoModal() == IDCANCEL)
   1.345 +		return;
   1.346 +
   1.347 +	CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST);
   1.348 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
   1.349 +
   1.350 +	systemSoundClearBuffer();
   1.351 +	if (MessageBox(str1,
   1.352 +	               str2,
   1.353 +	               MB_OKCANCEL) == IDCANCEL)
   1.354 +		return;
   1.355 +
   1.356 +	bool res = false;
   1.357 +
   1.358 +	res = theApp.emulator.emuReadBattery(dlg.GetPathName());
   1.359 +
   1.360 +	if (!res)
   1.361 +		systemMessage(MSG_CANNOT_OPEN_FILE, "Cannot open file %s", dlg.GetPathName());
   1.362 +	else
   1.363 +	{
   1.364 +		theApp.emulator.emuReset(true);
   1.365 +	}
   1.366 +}
   1.367 +
   1.368 +void MainWnd::OnUpdateFileImportBatteryfile(CCmdUI *pCmdUI)
   1.369 +{
   1.370 +	// we allow this as we allow using cheats during recording
   1.371 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
   1.372 +}
   1.373 +
   1.374 +void MainWnd::OnFileImportGamesharkcodefile()
   1.375 +{
   1.376 +	theApp.winCheckFullscreen();
   1.377 +
   1.378 +	LPCTSTR exts[] = { NULL };
   1.379 +	CString filter = systemCartridgeType == 0 ? winResLoadFilter(IDS_FILTER_SPC) : winResLoadFilter(IDS_FILTER_GCF);
   1.380 +	CString title  = winResLoadString(IDS_SELECT_CODE_FILE);
   1.381 +
   1.382 +	FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true);
   1.383 +
   1.384 +	if (dlg.DoModal() == IDCANCEL)
   1.385 +		return;
   1.386 +
   1.387 +	CString str1 = winResLoadString(IDS_CODES_WILL_BE_LOST);
   1.388 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
   1.389 +
   1.390 +	systemSoundClearBuffer();
   1.391 +	if (MessageBox(str1,
   1.392 +	               str2,
   1.393 +	               MB_OKCANCEL) == IDCANCEL)
   1.394 +		return;
   1.395 +
   1.396 +	CString file = dlg.GetPathName();
   1.397 +	bool	res	 = winImportGSACodeFile(file);
   1.398 +}
   1.399 +
   1.400 +void MainWnd::OnUpdateFileImportGamesharkcodefile(CCmdUI *pCmdUI)
   1.401 +{
   1.402 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
   1.403 +}
   1.404 +
   1.405 +void MainWnd::OnFileImportGamesharksnapshot()
   1.406 +{
   1.407 +	theApp.winCheckFullscreen();
   1.408 +
   1.409 +	LPCTSTR exts[] = { NULL };
   1.410 +	CString filter = systemCartridgeType == 1 ? winResLoadFilter(IDS_FILTER_GBS) : winResLoadFilter(IDS_FILTER_SPS);
   1.411 +	CString title  = winResLoadString(IDS_SELECT_SNAPSHOT_FILE);
   1.412 +
   1.413 +	FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true);
   1.414 +
   1.415 +	if (dlg.DoModal() == IDCANCEL)
   1.416 +		return;
   1.417 +
   1.418 +	CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST);
   1.419 +	CString str2 = winResLoadString(IDS_CONFIRM_ACTION);
   1.420 +
   1.421 +	systemSoundClearBuffer();
   1.422 +	if (MessageBox(str1,
   1.423 +	               str2,
   1.424 +	               MB_OKCANCEL) == IDCANCEL)
   1.425 +		return;
   1.426 +
   1.427 +	if (systemCartridgeType == 1)
   1.428 +		gbReadGSASnapshot(dlg.GetPathName());
   1.429 +	else
   1.430 +		CPUReadGSASnapshot(dlg.GetPathName());
   1.431 +}
   1.432 +
   1.433 +void MainWnd::OnUpdateFileImportGamesharksnapshot(CCmdUI *pCmdUI)
   1.434 +{
   1.435 +	pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/);
   1.436 +}
   1.437 +
   1.438 +void MainWnd::OnFileExportBatteryfile()
   1.439 +{
   1.440 +	theApp.winCheckFullscreen();
   1.441 +
   1.442 +	LPCTSTR exts[] = { ".sav", ".dat", NULL };
   1.443 +	CString filter = winResLoadFilter(IDS_FILTER_SAV);
   1.444 +	CString title  = winResLoadString(IDS_SELECT_BATTERY_FILE);
   1.445 +
   1.446 +	CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]);
   1.447 +	CString batteryDir	= winGetDestDir(IDS_BATTERY_DIR);
   1.448 +
   1.449 +	FileDlg dlg(this, batteryName, filter, 1, "SAV", exts, batteryDir, title, true);
   1.450 +
   1.451 +	if (dlg.DoModal() == IDCANCEL)
   1.452 +	{
   1.453 +		return;
   1.454 +	}
   1.455 +
   1.456 +	bool result = false;
   1.457 +
   1.458 +	if (systemCartridgeType == 1)
   1.459 +	{
   1.460 +		result = gbWriteBatteryFile(dlg.GetPathName(), false);
   1.461 +	}
   1.462 +	else
   1.463 +		result = theApp.emulator.emuWriteBattery(dlg.GetPathName());
   1.464 +
   1.465 +	if (!result)
   1.466 +		systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s",
   1.467 +		              dlg.GetPathName());
   1.468 +}
   1.469 +
   1.470 +void MainWnd::OnUpdateFileExportBatteryfile(CCmdUI *pCmdUI)
   1.471 +{
   1.472 +	pCmdUI->Enable(emulating);
   1.473 +}
   1.474 +
   1.475 +void MainWnd::OnFileExportGamesharksnapshot()
   1.476 +{
   1.477 +	theApp.winCheckFullscreen();
   1.478 +	if (eepromInUse)
   1.479 +	{
   1.480 +		systemMessage(IDS_EEPROM_NOT_SUPPORTED, "EEPROM saves cannot be exported");
   1.481 +		return;
   1.482 +	}
   1.483 +
   1.484 +	LPCTSTR exts[] = { ".sps", NULL };
   1.485 +
   1.486 +	CString filter = winResLoadFilter(IDS_FILTER_SPS);
   1.487 +	CString title  = winResLoadString(IDS_SELECT_SNAPSHOT_FILE);
   1.488 +
   1.489 +	CString name = winGetDestFilename(theApp.gameFilename, CString(), exts[0]);
   1.490 +
   1.491 +	FileDlg dlg(this, name, filter, 1, "SPS", exts, "", title, true);
   1.492 +
   1.493 +	if (dlg.DoModal() == IDCANCEL)
   1.494 +		return;
   1.495 +
   1.496 +	char buffer[16];
   1.497 +	strncpy(buffer, (const char *)&rom[0xa0], 12);
   1.498 +	buffer[12] = 0;
   1.499 +
   1.500 +	ExportGSASnapshot dlg2(dlg.GetPathName(), buffer, this);
   1.501 +	dlg2.DoModal();
   1.502 +}
   1.503 +
   1.504 +void MainWnd::OnUpdateFileExportGamesharksnapshot(CCmdUI *pCmdUI)
   1.505 +{
   1.506 +	pCmdUI->Enable(emulating && systemCartridgeType == 0);
   1.507 +}
   1.508 +
   1.509 +void MainWnd::OnFileQuickScreencapture()
   1.510 +{
   1.511 +	extern int32 captureNumber;   // GBAGlobals.cpp
   1.512 +	captureNumber = winScreenCapture(captureNumber);
   1.513 +}
   1.514 +
   1.515 +void MainWnd::OnFileScreencapture()
   1.516 +{
   1.517 +	theApp.winCheckFullscreen();
   1.518 +
   1.519 +	LPCTSTR exts[] = { ".png", ".bmp", NULL };
   1.520 +
   1.521 +	CString filter = winResLoadFilter(IDS_FILTER_PNG);
   1.522 +	CString title  = winResLoadString(IDS_SELECT_CAPTURE_NAME);
   1.523 +
   1.524 +	CString ext;
   1.525 +
   1.526 +	if (theApp.captureFormat != 0)
   1.527 +		ext.Format(".bmp");
   1.528 +	else
   1.529 +		ext.Format(".png");
   1.530 +
   1.531 +	CString captureName = winGetDestFilename(theApp.gameFilename, IDS_CAPTURE_DIR, ext);
   1.532 +	CString captureDir	= winGetDestDir(IDS_CAPTURE_DIR);
   1.533 +
   1.534 +	FileDlg dlg(this,
   1.535 +	            captureName,
   1.536 +	            filter,
   1.537 +	            theApp.captureFormat ? 2 : 1,
   1.538 +	            theApp.captureFormat ? "BMP" : "PNG",
   1.539 +	            exts,
   1.540 +	            captureDir,
   1.541 +	            title,
   1.542 +	            true);
   1.543 +
   1.544 +	if (dlg.DoModal() == IDCANCEL)
   1.545 +		return;
   1.546 +
   1.547 +	if (dlg.getFilterIndex() == 2)
   1.548 +		theApp.emulator.emuWriteBMP(dlg.GetPathName());
   1.549 +	else
   1.550 +		theApp.emulator.emuWritePNG(dlg.GetPathName());
   1.551 +
   1.552 +	systemScreenMessage(winResLoadString(IDS_SCREEN_CAPTURE));
   1.553 +}
   1.554 +
   1.555 +void MainWnd::OnUpdateFileScreencapture(CCmdUI *pCmdUI)
   1.556 +{
   1.557 +	pCmdUI->Enable(emulating);
   1.558 +}
   1.559 +
   1.560 +void MainWnd::OnFileRominformation()
   1.561 +{
   1.562 +	theApp.winCheckFullscreen();
   1.563 +	if (systemCartridgeType == 0)
   1.564 +	{
   1.565 +		RomInfoGBA dlg(rom);
   1.566 +		dlg.DoModal();
   1.567 +	}
   1.568 +	else
   1.569 +	{
   1.570 +		RomInfoGB dlg(gbRom);
   1.571 +		dlg.DoModal();
   1.572 +	}
   1.573 +}
   1.574 +
   1.575 +void MainWnd::OnUpdateFileRominformation(CCmdUI *pCmdUI)
   1.576 +{
   1.577 +	pCmdUI->Enable(emulating);
   1.578 +}
   1.579 +
   1.580 +void MainWnd::OnFileTogglemenu()
   1.581 +{
   1.582 +	theApp.menuToggle = !theApp.menuToggle;
   1.583 +
   1.584 +	if (theApp.menuToggle)
   1.585 +	{
   1.586 +		SetMenu(&theApp.m_menu);
   1.587 +		if (theApp.tripleBuffering)
   1.588 +		{
   1.589 +			if (theApp.display)
   1.590 +				theApp.display->renderMenu();
   1.591 +		}
   1.592 +	}
   1.593 +	else
   1.594 +	{
   1.595 +		SetMenu(NULL);
   1.596 +	}
   1.597 +
   1.598 +	theApp.adjustDestRect();
   1.599 +}
   1.600 +
   1.601 +void MainWnd::OnUpdateFileTogglemenu(CCmdUI *pCmdUI)
   1.602 +{
   1.603 +	pCmdUI->Enable(theApp.videoOption > VIDEO_4X);
   1.604 +}
   1.605 +
   1.606 +void MainWnd::OnFileSavegameOldestslot()
   1.607 +{
   1.608 +	if (!emulating)
   1.609 +		return;
   1.610 +
   1.611 +	CFileStatus status;
   1.612 +	CString		str;
   1.613 +	time_t		time  = -1;
   1.614 +	int			found = -1;
   1.615 +
   1.616 +	for (int i = 0; i < 10; i++)
   1.617 +	{
   1.618 +		if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
   1.619 +		{
   1.620 +			if (time - status.m_mtime.GetTime() > 0 || time == -1)
   1.621 +			{
   1.622 +				time  = (time_t)status.m_mtime.GetTime();
   1.623 +				found = i;
   1.624 +			}
   1.625 +		}
   1.626 +		else
   1.627 +		{
   1.628 +			found = i;
   1.629 +			break;
   1.630 +		}
   1.631 +	}
   1.632 +
   1.633 +	OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + found);
   1.634 +}
   1.635 +
   1.636 +void MainWnd::OnUpdateFileSavegameOldestslot(CCmdUI *pCmdUI)
   1.637 +{
   1.638 +	bool enabled = emulating;
   1.639 +	if (pCmdUI->m_pMenu != NULL)
   1.640 +	{
   1.641 +		CFileStatus status;
   1.642 +		time_t		time  = -1;
   1.643 +		int			found = -1;
   1.644 +
   1.645 +		if (emulating)
   1.646 +		{
   1.647 +			for (int i = 0; i < 10; i++)
   1.648 +			{
   1.649 +				if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
   1.650 +				{
   1.651 +					if (time - status.m_mtime.GetTime() > 0 || time == -1)
   1.652 +					{
   1.653 +						time  = (time_t)status.m_mtime.GetTime();
   1.654 +						found = i;
   1.655 +					}
   1.656 +				}
   1.657 +				else
   1.658 +				{
   1.659 +					found = i;
   1.660 +					break;
   1.661 +				}
   1.662 +			}
   1.663 +		}
   1.664 +
   1.665 +		CString str;
   1.666 +		enabled = (found != -1);
   1.667 +		if (enabled)
   1.668 +			str.Format("&Oldest Slot (#%d)", found + 1);
   1.669 +		else
   1.670 +			str.Format("&Oldest Slot", found + 1);
   1.671 +
   1.672 +		pCmdUI->SetText(str);
   1.673 +
   1.674 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.675 +	}
   1.676 +
   1.677 +	pCmdUI->Enable(enabled);
   1.678 +}
   1.679 +
   1.680 +void MainWnd::OnFileLoadgameMostrecent()
   1.681 +{
   1.682 +	if (!emulating)
   1.683 +		return;
   1.684 +
   1.685 +	CFileStatus status;
   1.686 +	CString		str;
   1.687 +	time_t		time  = 0;
   1.688 +	int			found = -1;
   1.689 +
   1.690 +	for (int i = 0; i < 10; i++)
   1.691 +	{
   1.692 +		if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
   1.693 +		{
   1.694 +			if (status.m_mtime.GetTime() > time)
   1.695 +			{
   1.696 +				time  = (time_t)status.m_mtime.GetTime();
   1.697 +				found = i;
   1.698 +			}
   1.699 +		}
   1.700 +	}
   1.701 +
   1.702 +	if (found != -1)
   1.703 +	{
   1.704 +		OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + found);
   1.705 +	}
   1.706 +}
   1.707 +
   1.708 +void MainWnd::OnUpdateFileLoadgameMostrecent(CCmdUI *pCmdUI)
   1.709 +{
   1.710 +	bool enabled = emulating;
   1.711 +	if (pCmdUI->m_pMenu != NULL)
   1.712 +	{
   1.713 +		CFileStatus status;
   1.714 +		int			found = -1;
   1.715 +
   1.716 +		time_t time = 0;
   1.717 +		if (emulating)
   1.718 +		{
   1.719 +			for (int i = 0; i < 10; i++)
   1.720 +			{
   1.721 +				if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status))
   1.722 +				{
   1.723 +					if (status.m_mtime.GetTime() > time)
   1.724 +					{
   1.725 +						time  = (time_t)status.m_mtime.GetTime();
   1.726 +						found = i;
   1.727 +					}
   1.728 +				}
   1.729 +			}
   1.730 +		}
   1.731 +
   1.732 +		CString str;
   1.733 +		enabled = (found != -1);
   1.734 +		if (enabled)
   1.735 +			str.Format("Most &Recent Slot (#%d)", found + 1);
   1.736 +		else
   1.737 +			str.Format("Most &Recent Slot", found + 1);
   1.738 +
   1.739 +		pCmdUI->SetText(str);
   1.740 +
   1.741 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.742 +	}
   1.743 +
   1.744 +	pCmdUI->Enable(enabled);
   1.745 +}
   1.746 +
   1.747 +void MainWnd::OnUpdateFileLoadSlot(CCmdUI *pCmdUI)
   1.748 +{
   1.749 +	int slotID = pCmdUI->m_nID - ID_FILE_LOADGAME_SLOT1 + 1;
   1.750 +
   1.751 +	if (pCmdUI->m_pMenu != NULL)
   1.752 +	{
   1.753 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID));
   1.754 +
   1.755 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.756 +	}
   1.757 +
   1.758 +	pCmdUI->Enable(emulating && winFileExists(winGetSavestateFilename(theApp.gameFilename, slotID)));
   1.759 +}
   1.760 +
   1.761 +void MainWnd::OnUpdateFileSaveSlot(CCmdUI *pCmdUI)
   1.762 +{
   1.763 +	if (pCmdUI->m_pMenu != NULL)
   1.764 +	{
   1.765 +		int slotID = pCmdUI->m_nID - ID_FILE_SAVEGAME_SLOT1 + 1;
   1.766 +
   1.767 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID));
   1.768 +
   1.769 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.770 +	}
   1.771 +
   1.772 +	pCmdUI->Enable(emulating);
   1.773 +}
   1.774 +
   1.775 +void MainWnd::OnUpdateSelectSlot(CCmdUI *pCmdUI)
   1.776 +{
   1.777 +	if (pCmdUI->m_pMenu != NULL)
   1.778 +	{
   1.779 +		int slot = pCmdUI->m_nID - ID_SELECT_SLOT1;
   1.780 +
   1.781 +		pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slot + 1));
   1.782 +
   1.783 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.784 +
   1.785 +		pCmdUI->SetCheck(slot == theApp.currentSlot);
   1.786 +	}
   1.787 +}
   1.788 +
   1.789 +void MainWnd::OnFileLoadgameAutoloadmostrecent()
   1.790 +{
   1.791 +	theApp.autoLoadMostRecent = !theApp.autoLoadMostRecent;
   1.792 +}
   1.793 +
   1.794 +void MainWnd::OnUpdateFileLoadgameAutoloadmostrecent(CCmdUI *pCmdUI)
   1.795 +{
   1.796 +	pCmdUI->SetCheck(theApp.autoLoadMostRecent);
   1.797 +}
   1.798 +
   1.799 +void MainWnd::OnFileLoadgameMakeRecent()
   1.800 +{
   1.801 +	theApp.loadMakesRecent = !theApp.loadMakesRecent;
   1.802 +}
   1.803 +
   1.804 +void MainWnd::OnUpdateFileLoadgameMakeRecent(CCmdUI *pCmdUI)
   1.805 +{
   1.806 +	pCmdUI->SetCheck(theApp.loadMakesRecent);
   1.807 +}
   1.808 +
   1.809 +void MainWnd::OnFileSavegameCurrent()
   1.810 +{
   1.811 +	OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + theApp.currentSlot);
   1.812 +}
   1.813 +
   1.814 +void MainWnd::OnUpdateFileSavegameCurrent(CCmdUI *pCmdUI)
   1.815 +{
   1.816 +	if (pCmdUI->m_pMenu != NULL)
   1.817 +	{
   1.818 +		int slotID = theApp.currentSlot + 1;
   1.819 +
   1.820 +		CString str;
   1.821 +		str.Format("&Current Slot (#%d)", slotID);
   1.822 +
   1.823 +		pCmdUI->SetText(str);
   1.824 +
   1.825 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.826 +	}
   1.827 +
   1.828 +	pCmdUI->Enable(emulating);
   1.829 +}
   1.830 +
   1.831 +void MainWnd::OnFileLoadgameCurrent()
   1.832 +{
   1.833 +	OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + theApp.currentSlot);
   1.834 +}
   1.835 +
   1.836 +void MainWnd::OnUpdateFileLoadgameCurrent(CCmdUI *pCmdUI)
   1.837 +{
   1.838 +	int slotID = theApp.currentSlot + 1;
   1.839 +
   1.840 +	if (pCmdUI->m_pMenu != NULL)
   1.841 +	{
   1.842 +		CString str;
   1.843 +		str.Format("&Current Slot (#%d)", slotID);
   1.844 +
   1.845 +		pCmdUI->SetText(str);
   1.846 +
   1.847 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.848 +	}
   1.849 +
   1.850 +	CFileStatus status;
   1.851 +	pCmdUI->Enable(emulating && CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, slotID), status));
   1.852 +}
   1.853 +
   1.854 +void MainWnd::OnFileLoadgameMakeCurrent()
   1.855 +{
   1.856 +	theApp.loadMakesCurrent = !theApp.loadMakesCurrent;
   1.857 +}
   1.858 +
   1.859 +void MainWnd::OnUpdateFileLoadgameMakeCurrent(CCmdUI *pCmdUI)
   1.860 +{
   1.861 +	pCmdUI->SetCheck(theApp.loadMakesCurrent);
   1.862 +}
   1.863 +
   1.864 +void MainWnd::OnFileSavegameMakeCurrent()
   1.865 +{
   1.866 +	theApp.saveMakesCurrent = !theApp.saveMakesCurrent;
   1.867 +}
   1.868 +
   1.869 +void MainWnd::OnUpdateFileSavegameMakeCurrent(CCmdUI *pCmdUI)
   1.870 +{
   1.871 +	pCmdUI->SetCheck(theApp.saveMakesCurrent);
   1.872 +}
   1.873 +
   1.874 +void MainWnd::OnFileSavegameIncrementSlot()
   1.875 +{
   1.876 +	theApp.currentSlot = (theApp.currentSlot + 1) % 10;
   1.877 +
   1.878 +	char str [32];
   1.879 +	sprintf(str, "Current Slot: %d", theApp.currentSlot + 1);
   1.880 +	systemScreenMessage(str, 0);
   1.881 +}
   1.882 +
   1.883 +void MainWnd::OnUpdateFileSavegameIncrementSlot(CCmdUI *pCmdUI)
   1.884 +{
   1.885 +	if (pCmdUI->m_pMenu != NULL)
   1.886 +	{
   1.887 +		int slotID = theApp.currentSlot + 1;
   1.888 +
   1.889 +		CString str;
   1.890 +		str.Format("&Increase Current Slot (#%d -> #%d)", slotID, slotID % 10 + 1);
   1.891 +
   1.892 +		pCmdUI->SetText(str);
   1.893 +
   1.894 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.895 +	}
   1.896 +}
   1.897 +
   1.898 +void MainWnd::OnFileSavegameDecrementSlot()
   1.899 +{
   1.900 +	theApp.currentSlot = (theApp.currentSlot + 9) % 10;
   1.901 +
   1.902 +	char str [32];
   1.903 +	sprintf(str, "Current Slot: %d", theApp.currentSlot + 1);
   1.904 +	systemScreenMessage(str, 0);
   1.905 +}
   1.906 +
   1.907 +void MainWnd::OnUpdateFileSavegameDecrementSlot(CCmdUI *pCmdUI)
   1.908 +{
   1.909 +	if (pCmdUI->m_pMenu != NULL)
   1.910 +	{
   1.911 +		int slotID = theApp.currentSlot + 1;
   1.912 +
   1.913 +		CString str;
   1.914 +		str.Format("&Decrease Current Slot (#%d -> #%d)", slotID, (slotID + 8) % 10 + 1);
   1.915 +
   1.916 +		pCmdUI->SetText(str);
   1.917 +
   1.918 +		theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
   1.919 +	}
   1.920 +}
   1.921 +
   1.922 +void MainWnd::OnFileSlotDisplayModificationTime()
   1.923 +{
   1.924 +	theApp.showSlotTime = !theApp.showSlotTime;
   1.925 +}
   1.926 +
   1.927 +void MainWnd::OnUpdateFileSlotDisplayModificationTime(CCmdUI *pCmdUI)
   1.928 +{
   1.929 +	pCmdUI->SetCheck(theApp.showSlotTime);
   1.930 +}
   1.931 +
   1.932 +void MainWnd::OnFileLuaOpen()
   1.933 +{
   1.934 +	theApp.winCheckFullscreen();
   1.935 +
   1.936 +	if (!LuaConsoleHWnd)
   1.937 +	{
   1.938 +		LuaConsoleHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_LUA), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) DlgLuaScriptDialog);
   1.939 +	}
   1.940 +	else
   1.941 +		::SetForegroundWindow(LuaConsoleHWnd);
   1.942 +}
   1.943 +
   1.944 +void MainWnd::OnUpdateFileLuaOpen(CCmdUI *pCmdUI)
   1.945 +{
   1.946 +	pCmdUI->SetCheck(LuaConsoleHWnd != NULL);
   1.947 +	pCmdUI->Enable(true);
   1.948 +}
   1.949 +
   1.950 +void MainWnd::OnFileLuaCloseAll()
   1.951 +{
   1.952 +	if (LuaConsoleHWnd)
   1.953 +		::PostMessage(LuaConsoleHWnd, WM_CLOSE, 0, 0);
   1.954 +}
   1.955 +
   1.956 +void MainWnd::OnFileLuaReload()
   1.957 +{
   1.958 +	VBAReloadLuaCode();
   1.959 +}
   1.960 +
   1.961 +void MainWnd::OnFileLuaStop()
   1.962 +{
   1.963 +	VBALuaStop();
   1.964 +}
   1.965 +
   1.966 +void MainWnd::OnFileRamSearch()
   1.967 +{
   1.968 +	theApp.winCheckFullscreen();
   1.969 +
   1.970 +	if (!RamSearchHWnd)
   1.971 +	{
   1.972 +		reset_address_info();
   1.973 +		LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
   1.974 +		::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMSEARCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamSearchProc);
   1.975 +	}
   1.976 +	else
   1.977 +		::SetForegroundWindow(RamSearchHWnd);
   1.978 +}
   1.979 +
   1.980 +void MainWnd::OnUpdateFileRamSearch(CCmdUI *pCmdUI)
   1.981 +{
   1.982 +	pCmdUI->Enable(TRUE);
   1.983 +}
   1.984 +
   1.985 +void MainWnd::OnFileRamWatch()
   1.986 +{
   1.987 +	theApp.winCheckFullscreen();
   1.988 +
   1.989 +	if (!RamWatchHWnd)
   1.990 +	{
   1.991 +		LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
   1.992 +		RamWatchHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMWATCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamWatchProc);
   1.993 +	}
   1.994 +	else
   1.995 +		::SetForegroundWindow(RamWatchHWnd);
   1.996 +}
   1.997 +
   1.998 +void MainWnd::OnUpdateFileRamWatch(CCmdUI *pCmdUI)
   1.999 +{
  1.1000 +	pCmdUI->Enable(TRUE);
  1.1001 +}
  1.1002 +
  1.1003 +void MainWnd::OnUpdateFileLuaCloseAll(CCmdUI *pCmdUI)
  1.1004 +{
  1.1005 +	pCmdUI->Enable(LuaConsoleHWnd != NULL);
  1.1006 +}
  1.1007 +