Mercurial > vba-clojure
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 #include "stdafx.h" | |
2 #include "resource.h" | |
3 #include "MainWnd.h" | |
4 #include "ExportGSASnapshot.h" | |
5 #include "FileDlg.h" | |
6 #include "GSACodeSelect.h" | |
7 #include "RomInfo.h" | |
8 #include "Reg.h" | |
9 #include "WinResUtil.h" | |
10 #include "WinMiscUtil.h" | |
11 #include "LuaOpenDialog.h" | |
12 #include "ram_search.h" | |
13 #include "ramwatch.h" | |
14 #include "Sound.h" | |
15 #include "VBA.h" | |
16 | |
17 #include "../NLS.h" | |
18 #include "../version.h" | |
19 #include "../gba/GBA.h" | |
20 #include "../gba/GBAGlobals.h" | |
21 #include "../gba/EEprom.h" | |
22 #include "../gba/GBASound.h" | |
23 #include "../gb/GB.h" | |
24 #include "../gb/gbGlobals.h" | |
25 #include "../common/movie.h" | |
26 #include "../common/vbalua.h" | |
27 | |
28 void MainWnd::OnFileOpen() | |
29 { | |
30 theApp.winCheckFullscreen(); | |
31 if (winFileOpenSelect(0)) | |
32 { | |
33 winFileRun(); | |
34 } | |
35 } | |
36 | |
37 void MainWnd::OnFileOpenGBx() | |
38 { | |
39 theApp.winCheckFullscreen(); | |
40 if (winFileOpenSelect(1)) | |
41 { | |
42 winFileRun(); | |
43 } | |
44 } | |
45 | |
46 void MainWnd::OnFilePause() | |
47 { | |
48 systemSetPause(!theApp.paused); | |
49 } | |
50 | |
51 void MainWnd::OnUpdateFilePause(CCmdUI *pCmdUI) | |
52 { | |
53 pCmdUI->SetCheck(theApp.paused); | |
54 } | |
55 | |
56 void MainWnd::OnFileReset() | |
57 { | |
58 if (emulating) | |
59 { | |
60 if (VBAMovieGetState() == MOVIE_STATE_PLAY) | |
61 { | |
62 OnToolsPlayRestart(); // HACK: shortcut | |
63 } | |
64 else | |
65 { | |
66 theApp.emulator.emuReset(true); | |
67 systemScreenMessage(winResLoadString(IDS_RESET)); | |
68 } | |
69 } | |
70 } | |
71 | |
72 void MainWnd::OnUpdateFileReset(CCmdUI *pCmdUI) | |
73 { | |
74 pCmdUI->Enable(emulating); | |
75 } | |
76 | |
77 void MainWnd::OnFileRecentFreeze() | |
78 { | |
79 theApp.recentFreeze = !theApp.recentFreeze; | |
80 } | |
81 | |
82 void MainWnd::OnUpdateFileRecentFreeze(CCmdUI *pCmdUI) | |
83 { | |
84 pCmdUI->SetCheck(theApp.recentFreeze); | |
85 } | |
86 | |
87 void MainWnd::OnFileRecentReset() | |
88 { | |
89 theApp.winCheckFullscreen(); | |
90 systemSoundClearBuffer(); | |
91 if (MessageBox("Really clear your recent ROMs list?", //winResLoadString(IDS_REALLY_CLEAR), | |
92 winResLoadString(IDS_CONFIRM_ACTION), | |
93 MB_YESNO | MB_DEFBUTTON2) == IDNO) | |
94 return; | |
95 | |
96 for (int i = 0; i < 10; ++i) | |
97 theApp.recentFiles[i] = ""; | |
98 } | |
99 | |
100 BOOL MainWnd::OnFileRecentFile(UINT nID) | |
101 { | |
102 if (theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1].GetLength()) | |
103 { | |
104 theApp.romFilename = theApp.recentFiles[(nID & 0xFFFF) - ID_FILE_MRU_FILE1]; | |
105 winFileRun(); | |
106 } | |
107 return TRUE; | |
108 } | |
109 | |
110 void MainWnd::OnUpdateFileRecentFile(CCmdUI *pCmdUI) | |
111 { | |
112 int fileID = pCmdUI->m_nID - ID_FILE_MRU_FILE1; | |
113 | |
114 bool bExist = !theApp.recentFiles[fileID].IsEmpty(); | |
115 | |
116 if (pCmdUI->m_pMenu != NULL) | |
117 { | |
118 CString p = theApp.recentFiles[fileID]; | |
119 | |
120 int index = max(p.ReverseFind('/'), max(p.ReverseFind('\\'), p.ReverseFind('|'))); | |
121 | |
122 if (index != -1) | |
123 { | |
124 p.Delete(0, index + 1); | |
125 } | |
126 | |
127 p.Replace("&", "&&"); | |
128 | |
129 CString number("1&0 - "); | |
130 if (fileID < 9) | |
131 number.Format("&%d - ", fileID + 1); | |
132 | |
133 if (p.IsEmpty()) | |
134 { | |
135 p = "No Recent ROM"; | |
136 bExist = false; | |
137 } | |
138 | |
139 pCmdUI->SetText(number + p); | |
140 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
141 } | |
142 | |
143 pCmdUI->Enable(bExist); | |
144 } | |
145 | |
146 void MainWnd::OnFileExit() | |
147 { | |
148 if (AskSave()) | |
149 SendMessage(WM_CLOSE); | |
150 } | |
151 | |
152 void MainWnd::OnFileClose() | |
153 { | |
154 // save battery file before we change the filename... | |
155 CloseRamWindows(); | |
156 winFileClose(); | |
157 } | |
158 | |
159 void MainWnd::OnUpdateFileClose(CCmdUI *pCmdUI) | |
160 { | |
161 pCmdUI->Enable(emulating); | |
162 } | |
163 | |
164 void MainWnd::OnFileLoad() | |
165 { | |
166 theApp.winCheckFullscreen(); | |
167 | |
168 LPCTSTR exts[] = { ".sgm", NULL }; | |
169 CString filter = winResLoadFilter(IDS_FILTER_SGM); | |
170 CString title = winResLoadString(IDS_SELECT_SAVE_GAME_NAME); | |
171 | |
172 CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]); | |
173 CString saveDir = winGetDestDir(IDS_SAVE_DIR); | |
174 | |
175 FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, false, true); | |
176 | |
177 if (dlg.DoModal() == IDOK) | |
178 { | |
179 bool res = winReadSaveGame(dlg.GetPathName()); | |
180 | |
181 theApp.rewindCount = 0; | |
182 theApp.rewindCounter = 0; | |
183 theApp.rewindSaveNeeded = false; | |
184 | |
185 if (res) | |
186 { | |
187 if (VBAMovieActive() && !VBAMovieReadOnly()) | |
188 { | |
189 VBAMovieSwitchToRecording(); | |
190 } | |
191 systemScreenMessage(winResLoadString(IDS_LOADED_STATE)); | |
192 } | |
193 } | |
194 } | |
195 | |
196 void MainWnd::OnUpdateFileLoad(CCmdUI *pCmdUI) | |
197 { | |
198 pCmdUI->Enable(emulating); | |
199 } | |
200 | |
201 BOOL MainWnd::OnFileLoadSlot(UINT nID) | |
202 { | |
203 nID = nID + 1 - ID_FILE_LOADGAME_SLOT1; | |
204 | |
205 CString filename = winGetSavestateFilename(theApp.gameFilename, nID); | |
206 | |
207 bool res = winReadSaveGame(filename); | |
208 | |
209 // deleting rewinds because you loaded a save state is stupid | |
210 /// theApp.rewindCount = 0; | |
211 /// theApp.rewindCounter = 0; | |
212 /// theApp.rewindSaveNeeded = false; | |
213 | |
214 if (res) | |
215 { | |
216 CString format; | |
217 if (VBAMovieActive()) | |
218 { | |
219 if (VBAMovieReadOnly()) | |
220 { | |
221 format = winResLoadString(IDS_REPLAYED_STATE_N); | |
222 } | |
223 else | |
224 { | |
225 VBAMovieSwitchToRecording(); | |
226 format = winResLoadString(IDS_RERECORDED_STATE_N); | |
227 } | |
228 } | |
229 else | |
230 { | |
231 format = winResLoadString(IDS_LOADED_STATE_N); | |
232 } | |
233 | |
234 CString buffer; | |
235 buffer.Format(format, nID); | |
236 systemScreenMessage(buffer); | |
237 | |
238 int lastSlot = theApp.currentSlot; | |
239 | |
240 if (theApp.loadMakesRecent) | |
241 { | |
242 // to update the file's modification date | |
243 SYSTEMTIME st; | |
244 FILETIME ft; | |
245 GetSystemTime(&st); | |
246 SystemTimeToFileTime(&st, &ft); | |
247 HANDLE fh = CreateFile(filename, | |
248 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, | |
249 NULL, | |
250 OPEN_EXISTING, | |
251 0, | |
252 NULL); | |
253 if (fh != INVALID_HANDLE_VALUE) | |
254 SetFileTime(fh, NULL, NULL, &ft); | |
255 CloseHandle(fh); | |
256 } | |
257 | |
258 if (theApp.loadMakesCurrent) | |
259 theApp.currentSlot = nID - 1; | |
260 else | |
261 theApp.currentSlot = lastSlot; // restore value in case the call to OnFileSaveSlot changed it | |
262 | |
263 theApp.frameSearching = false; | |
264 theApp.frameSearchSkipping = false; | |
265 } | |
266 | |
267 return res; | |
268 } | |
269 | |
270 void MainWnd::OnFileSave() | |
271 { | |
272 theApp.winCheckFullscreen(); | |
273 | |
274 LPCTSTR exts[] = { ".sgm", NULL }; | |
275 CString filter = winResLoadFilter(IDS_FILTER_SGM); | |
276 CString title = winResLoadString(IDS_SELECT_SAVE_GAME_NAME); | |
277 | |
278 CString saveName = winGetDestFilename(theApp.gameFilename, IDS_SAVE_DIR, exts[0]); | |
279 CString saveDir = winGetDestDir(IDS_SAVE_DIR); | |
280 | |
281 FileDlg dlg(this, saveName, filter, 0, "SGM", exts, saveDir, title, true); | |
282 | |
283 if (dlg.DoModal() == IDOK) | |
284 { | |
285 bool res = winWriteSaveGame(dlg.GetPathName()); | |
286 if (res) | |
287 systemScreenMessage(winResLoadString(IDS_WROTE_STATE)); | |
288 } | |
289 } | |
290 | |
291 void MainWnd::OnUpdateFileSave(CCmdUI *pCmdUI) | |
292 { | |
293 pCmdUI->Enable(emulating); | |
294 } | |
295 | |
296 BOOL MainWnd::OnFileSaveSlot(UINT nID) | |
297 { | |
298 nID = nID + 1 - ID_FILE_SAVEGAME_SLOT1; | |
299 | |
300 if (theApp.saveMakesCurrent) | |
301 theApp.currentSlot = nID - 1; | |
302 | |
303 CString filename = winGetSavestateFilename(theApp.gameFilename, nID); | |
304 | |
305 bool res = winWriteSaveGame(filename); | |
306 | |
307 CString format = winResLoadString(IDS_WROTE_STATE_N); | |
308 CString buffer; | |
309 buffer.Format(format, nID); | |
310 | |
311 systemScreenMessage(buffer); | |
312 | |
313 return res; | |
314 } | |
315 | |
316 BOOL MainWnd::OnSelectSlot(UINT nID) | |
317 { | |
318 nID -= ID_SELECT_SLOT1; | |
319 theApp.currentSlot = nID; | |
320 | |
321 CString buffer; | |
322 buffer.Format("Slot %d selected", nID + 1); | |
323 systemScreenMessage(buffer, 0); | |
324 | |
325 return true; | |
326 } | |
327 | |
328 void MainWnd::OnFileImportBatteryfile() | |
329 { | |
330 theApp.winCheckFullscreen(); | |
331 | |
332 LPCTSTR exts[] = { ".sav", NULL }; | |
333 CString filter = winResLoadFilter(IDS_FILTER_SAV); | |
334 CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); | |
335 | |
336 CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]); | |
337 CString batteryDir = winGetDestDir(IDS_BATTERY_DIR); | |
338 | |
339 FileDlg dlg(this, batteryName, filter, 0, "SAV", exts, batteryDir, title, false, true); | |
340 | |
341 if (dlg.DoModal() == IDCANCEL) | |
342 return; | |
343 | |
344 CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST); | |
345 CString str2 = winResLoadString(IDS_CONFIRM_ACTION); | |
346 | |
347 systemSoundClearBuffer(); | |
348 if (MessageBox(str1, | |
349 str2, | |
350 MB_OKCANCEL) == IDCANCEL) | |
351 return; | |
352 | |
353 bool res = false; | |
354 | |
355 res = theApp.emulator.emuReadBattery(dlg.GetPathName()); | |
356 | |
357 if (!res) | |
358 systemMessage(MSG_CANNOT_OPEN_FILE, "Cannot open file %s", dlg.GetPathName()); | |
359 else | |
360 { | |
361 theApp.emulator.emuReset(true); | |
362 } | |
363 } | |
364 | |
365 void MainWnd::OnUpdateFileImportBatteryfile(CCmdUI *pCmdUI) | |
366 { | |
367 // we allow this as we allow using cheats during recording | |
368 pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/); | |
369 } | |
370 | |
371 void MainWnd::OnFileImportGamesharkcodefile() | |
372 { | |
373 theApp.winCheckFullscreen(); | |
374 | |
375 LPCTSTR exts[] = { NULL }; | |
376 CString filter = systemCartridgeType == 0 ? winResLoadFilter(IDS_FILTER_SPC) : winResLoadFilter(IDS_FILTER_GCF); | |
377 CString title = winResLoadString(IDS_SELECT_CODE_FILE); | |
378 | |
379 FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true); | |
380 | |
381 if (dlg.DoModal() == IDCANCEL) | |
382 return; | |
383 | |
384 CString str1 = winResLoadString(IDS_CODES_WILL_BE_LOST); | |
385 CString str2 = winResLoadString(IDS_CONFIRM_ACTION); | |
386 | |
387 systemSoundClearBuffer(); | |
388 if (MessageBox(str1, | |
389 str2, | |
390 MB_OKCANCEL) == IDCANCEL) | |
391 return; | |
392 | |
393 CString file = dlg.GetPathName(); | |
394 bool res = winImportGSACodeFile(file); | |
395 } | |
396 | |
397 void MainWnd::OnUpdateFileImportGamesharkcodefile(CCmdUI *pCmdUI) | |
398 { | |
399 pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/); | |
400 } | |
401 | |
402 void MainWnd::OnFileImportGamesharksnapshot() | |
403 { | |
404 theApp.winCheckFullscreen(); | |
405 | |
406 LPCTSTR exts[] = { NULL }; | |
407 CString filter = systemCartridgeType == 1 ? winResLoadFilter(IDS_FILTER_GBS) : winResLoadFilter(IDS_FILTER_SPS); | |
408 CString title = winResLoadString(IDS_SELECT_SNAPSHOT_FILE); | |
409 | |
410 FileDlg dlg(this, "", filter, 0, "", exts, "", title, false, true); | |
411 | |
412 if (dlg.DoModal() == IDCANCEL) | |
413 return; | |
414 | |
415 CString str1 = winResLoadString(IDS_SAVE_WILL_BE_LOST); | |
416 CString str2 = winResLoadString(IDS_CONFIRM_ACTION); | |
417 | |
418 systemSoundClearBuffer(); | |
419 if (MessageBox(str1, | |
420 str2, | |
421 MB_OKCANCEL) == IDCANCEL) | |
422 return; | |
423 | |
424 if (systemCartridgeType == 1) | |
425 gbReadGSASnapshot(dlg.GetPathName()); | |
426 else | |
427 CPUReadGSASnapshot(dlg.GetPathName()); | |
428 } | |
429 | |
430 void MainWnd::OnUpdateFileImportGamesharksnapshot(CCmdUI *pCmdUI) | |
431 { | |
432 pCmdUI->Enable(emulating /*&& !VBAMovieActive()*/); | |
433 } | |
434 | |
435 void MainWnd::OnFileExportBatteryfile() | |
436 { | |
437 theApp.winCheckFullscreen(); | |
438 | |
439 LPCTSTR exts[] = { ".sav", ".dat", NULL }; | |
440 CString filter = winResLoadFilter(IDS_FILTER_SAV); | |
441 CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); | |
442 | |
443 CString batteryName = winGetDestFilename(theApp.gameFilename, IDS_BATTERY_DIR, exts[0]); | |
444 CString batteryDir = winGetDestDir(IDS_BATTERY_DIR); | |
445 | |
446 FileDlg dlg(this, batteryName, filter, 1, "SAV", exts, batteryDir, title, true); | |
447 | |
448 if (dlg.DoModal() == IDCANCEL) | |
449 { | |
450 return; | |
451 } | |
452 | |
453 bool result = false; | |
454 | |
455 if (systemCartridgeType == 1) | |
456 { | |
457 result = gbWriteBatteryFile(dlg.GetPathName(), false); | |
458 } | |
459 else | |
460 result = theApp.emulator.emuWriteBattery(dlg.GetPathName()); | |
461 | |
462 if (!result) | |
463 systemMessage(MSG_ERROR_CREATING_FILE, "Error creating file %s", | |
464 dlg.GetPathName()); | |
465 } | |
466 | |
467 void MainWnd::OnUpdateFileExportBatteryfile(CCmdUI *pCmdUI) | |
468 { | |
469 pCmdUI->Enable(emulating); | |
470 } | |
471 | |
472 void MainWnd::OnFileExportGamesharksnapshot() | |
473 { | |
474 theApp.winCheckFullscreen(); | |
475 if (eepromInUse) | |
476 { | |
477 systemMessage(IDS_EEPROM_NOT_SUPPORTED, "EEPROM saves cannot be exported"); | |
478 return; | |
479 } | |
480 | |
481 LPCTSTR exts[] = { ".sps", NULL }; | |
482 | |
483 CString filter = winResLoadFilter(IDS_FILTER_SPS); | |
484 CString title = winResLoadString(IDS_SELECT_SNAPSHOT_FILE); | |
485 | |
486 CString name = winGetDestFilename(theApp.gameFilename, CString(), exts[0]); | |
487 | |
488 FileDlg dlg(this, name, filter, 1, "SPS", exts, "", title, true); | |
489 | |
490 if (dlg.DoModal() == IDCANCEL) | |
491 return; | |
492 | |
493 char buffer[16]; | |
494 strncpy(buffer, (const char *)&rom[0xa0], 12); | |
495 buffer[12] = 0; | |
496 | |
497 ExportGSASnapshot dlg2(dlg.GetPathName(), buffer, this); | |
498 dlg2.DoModal(); | |
499 } | |
500 | |
501 void MainWnd::OnUpdateFileExportGamesharksnapshot(CCmdUI *pCmdUI) | |
502 { | |
503 pCmdUI->Enable(emulating && systemCartridgeType == 0); | |
504 } | |
505 | |
506 void MainWnd::OnFileQuickScreencapture() | |
507 { | |
508 extern int32 captureNumber; // GBAGlobals.cpp | |
509 captureNumber = winScreenCapture(captureNumber); | |
510 } | |
511 | |
512 void MainWnd::OnFileScreencapture() | |
513 { | |
514 theApp.winCheckFullscreen(); | |
515 | |
516 LPCTSTR exts[] = { ".png", ".bmp", NULL }; | |
517 | |
518 CString filter = winResLoadFilter(IDS_FILTER_PNG); | |
519 CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME); | |
520 | |
521 CString ext; | |
522 | |
523 if (theApp.captureFormat != 0) | |
524 ext.Format(".bmp"); | |
525 else | |
526 ext.Format(".png"); | |
527 | |
528 CString captureName = winGetDestFilename(theApp.gameFilename, IDS_CAPTURE_DIR, ext); | |
529 CString captureDir = winGetDestDir(IDS_CAPTURE_DIR); | |
530 | |
531 FileDlg dlg(this, | |
532 captureName, | |
533 filter, | |
534 theApp.captureFormat ? 2 : 1, | |
535 theApp.captureFormat ? "BMP" : "PNG", | |
536 exts, | |
537 captureDir, | |
538 title, | |
539 true); | |
540 | |
541 if (dlg.DoModal() == IDCANCEL) | |
542 return; | |
543 | |
544 if (dlg.getFilterIndex() == 2) | |
545 theApp.emulator.emuWriteBMP(dlg.GetPathName()); | |
546 else | |
547 theApp.emulator.emuWritePNG(dlg.GetPathName()); | |
548 | |
549 systemScreenMessage(winResLoadString(IDS_SCREEN_CAPTURE)); | |
550 } | |
551 | |
552 void MainWnd::OnUpdateFileScreencapture(CCmdUI *pCmdUI) | |
553 { | |
554 pCmdUI->Enable(emulating); | |
555 } | |
556 | |
557 void MainWnd::OnFileRominformation() | |
558 { | |
559 theApp.winCheckFullscreen(); | |
560 if (systemCartridgeType == 0) | |
561 { | |
562 RomInfoGBA dlg(rom); | |
563 dlg.DoModal(); | |
564 } | |
565 else | |
566 { | |
567 RomInfoGB dlg(gbRom); | |
568 dlg.DoModal(); | |
569 } | |
570 } | |
571 | |
572 void MainWnd::OnUpdateFileRominformation(CCmdUI *pCmdUI) | |
573 { | |
574 pCmdUI->Enable(emulating); | |
575 } | |
576 | |
577 void MainWnd::OnFileTogglemenu() | |
578 { | |
579 theApp.menuToggle = !theApp.menuToggle; | |
580 | |
581 if (theApp.menuToggle) | |
582 { | |
583 SetMenu(&theApp.m_menu); | |
584 if (theApp.tripleBuffering) | |
585 { | |
586 if (theApp.display) | |
587 theApp.display->renderMenu(); | |
588 } | |
589 } | |
590 else | |
591 { | |
592 SetMenu(NULL); | |
593 } | |
594 | |
595 theApp.adjustDestRect(); | |
596 } | |
597 | |
598 void MainWnd::OnUpdateFileTogglemenu(CCmdUI *pCmdUI) | |
599 { | |
600 pCmdUI->Enable(theApp.videoOption > VIDEO_4X); | |
601 } | |
602 | |
603 void MainWnd::OnFileSavegameOldestslot() | |
604 { | |
605 if (!emulating) | |
606 return; | |
607 | |
608 CFileStatus status; | |
609 CString str; | |
610 time_t time = -1; | |
611 int found = -1; | |
612 | |
613 for (int i = 0; i < 10; i++) | |
614 { | |
615 if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status)) | |
616 { | |
617 if (time - status.m_mtime.GetTime() > 0 || time == -1) | |
618 { | |
619 time = (time_t)status.m_mtime.GetTime(); | |
620 found = i; | |
621 } | |
622 } | |
623 else | |
624 { | |
625 found = i; | |
626 break; | |
627 } | |
628 } | |
629 | |
630 OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + found); | |
631 } | |
632 | |
633 void MainWnd::OnUpdateFileSavegameOldestslot(CCmdUI *pCmdUI) | |
634 { | |
635 bool enabled = emulating; | |
636 if (pCmdUI->m_pMenu != NULL) | |
637 { | |
638 CFileStatus status; | |
639 time_t time = -1; | |
640 int found = -1; | |
641 | |
642 if (emulating) | |
643 { | |
644 for (int i = 0; i < 10; i++) | |
645 { | |
646 if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status)) | |
647 { | |
648 if (time - status.m_mtime.GetTime() > 0 || time == -1) | |
649 { | |
650 time = (time_t)status.m_mtime.GetTime(); | |
651 found = i; | |
652 } | |
653 } | |
654 else | |
655 { | |
656 found = i; | |
657 break; | |
658 } | |
659 } | |
660 } | |
661 | |
662 CString str; | |
663 enabled = (found != -1); | |
664 if (enabled) | |
665 str.Format("&Oldest Slot (#%d)", found + 1); | |
666 else | |
667 str.Format("&Oldest Slot", found + 1); | |
668 | |
669 pCmdUI->SetText(str); | |
670 | |
671 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
672 } | |
673 | |
674 pCmdUI->Enable(enabled); | |
675 } | |
676 | |
677 void MainWnd::OnFileLoadgameMostrecent() | |
678 { | |
679 if (!emulating) | |
680 return; | |
681 | |
682 CFileStatus status; | |
683 CString str; | |
684 time_t time = 0; | |
685 int found = -1; | |
686 | |
687 for (int i = 0; i < 10; i++) | |
688 { | |
689 if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status)) | |
690 { | |
691 if (status.m_mtime.GetTime() > time) | |
692 { | |
693 time = (time_t)status.m_mtime.GetTime(); | |
694 found = i; | |
695 } | |
696 } | |
697 } | |
698 | |
699 if (found != -1) | |
700 { | |
701 OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + found); | |
702 } | |
703 } | |
704 | |
705 void MainWnd::OnUpdateFileLoadgameMostrecent(CCmdUI *pCmdUI) | |
706 { | |
707 bool enabled = emulating; | |
708 if (pCmdUI->m_pMenu != NULL) | |
709 { | |
710 CFileStatus status; | |
711 int found = -1; | |
712 | |
713 time_t time = 0; | |
714 if (emulating) | |
715 { | |
716 for (int i = 0; i < 10; i++) | |
717 { | |
718 if (CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, i + 1), status)) | |
719 { | |
720 if (status.m_mtime.GetTime() > time) | |
721 { | |
722 time = (time_t)status.m_mtime.GetTime(); | |
723 found = i; | |
724 } | |
725 } | |
726 } | |
727 } | |
728 | |
729 CString str; | |
730 enabled = (found != -1); | |
731 if (enabled) | |
732 str.Format("Most &Recent Slot (#%d)", found + 1); | |
733 else | |
734 str.Format("Most &Recent Slot", found + 1); | |
735 | |
736 pCmdUI->SetText(str); | |
737 | |
738 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
739 } | |
740 | |
741 pCmdUI->Enable(enabled); | |
742 } | |
743 | |
744 void MainWnd::OnUpdateFileLoadSlot(CCmdUI *pCmdUI) | |
745 { | |
746 int slotID = pCmdUI->m_nID - ID_FILE_LOADGAME_SLOT1 + 1; | |
747 | |
748 if (pCmdUI->m_pMenu != NULL) | |
749 { | |
750 pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID)); | |
751 | |
752 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
753 } | |
754 | |
755 pCmdUI->Enable(emulating && winFileExists(winGetSavestateFilename(theApp.gameFilename, slotID))); | |
756 } | |
757 | |
758 void MainWnd::OnUpdateFileSaveSlot(CCmdUI *pCmdUI) | |
759 { | |
760 if (pCmdUI->m_pMenu != NULL) | |
761 { | |
762 int slotID = pCmdUI->m_nID - ID_FILE_SAVEGAME_SLOT1 + 1; | |
763 | |
764 pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slotID)); | |
765 | |
766 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
767 } | |
768 | |
769 pCmdUI->Enable(emulating); | |
770 } | |
771 | |
772 void MainWnd::OnUpdateSelectSlot(CCmdUI *pCmdUI) | |
773 { | |
774 if (pCmdUI->m_pMenu != NULL) | |
775 { | |
776 int slot = pCmdUI->m_nID - ID_SELECT_SLOT1; | |
777 | |
778 pCmdUI->SetText(winGetSavestateMenuString(theApp.gameFilename, slot + 1)); | |
779 | |
780 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
781 | |
782 pCmdUI->SetCheck(slot == theApp.currentSlot); | |
783 } | |
784 } | |
785 | |
786 void MainWnd::OnFileLoadgameAutoloadmostrecent() | |
787 { | |
788 theApp.autoLoadMostRecent = !theApp.autoLoadMostRecent; | |
789 } | |
790 | |
791 void MainWnd::OnUpdateFileLoadgameAutoloadmostrecent(CCmdUI *pCmdUI) | |
792 { | |
793 pCmdUI->SetCheck(theApp.autoLoadMostRecent); | |
794 } | |
795 | |
796 void MainWnd::OnFileLoadgameMakeRecent() | |
797 { | |
798 theApp.loadMakesRecent = !theApp.loadMakesRecent; | |
799 } | |
800 | |
801 void MainWnd::OnUpdateFileLoadgameMakeRecent(CCmdUI *pCmdUI) | |
802 { | |
803 pCmdUI->SetCheck(theApp.loadMakesRecent); | |
804 } | |
805 | |
806 void MainWnd::OnFileSavegameCurrent() | |
807 { | |
808 OnFileSaveSlot(ID_FILE_SAVEGAME_SLOT1 + theApp.currentSlot); | |
809 } | |
810 | |
811 void MainWnd::OnUpdateFileSavegameCurrent(CCmdUI *pCmdUI) | |
812 { | |
813 if (pCmdUI->m_pMenu != NULL) | |
814 { | |
815 int slotID = theApp.currentSlot + 1; | |
816 | |
817 CString str; | |
818 str.Format("&Current Slot (#%d)", slotID); | |
819 | |
820 pCmdUI->SetText(str); | |
821 | |
822 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
823 } | |
824 | |
825 pCmdUI->Enable(emulating); | |
826 } | |
827 | |
828 void MainWnd::OnFileLoadgameCurrent() | |
829 { | |
830 OnFileLoadSlot(ID_FILE_LOADGAME_SLOT1 + theApp.currentSlot); | |
831 } | |
832 | |
833 void MainWnd::OnUpdateFileLoadgameCurrent(CCmdUI *pCmdUI) | |
834 { | |
835 int slotID = theApp.currentSlot + 1; | |
836 | |
837 if (pCmdUI->m_pMenu != NULL) | |
838 { | |
839 CString str; | |
840 str.Format("&Current Slot (#%d)", slotID); | |
841 | |
842 pCmdUI->SetText(str); | |
843 | |
844 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
845 } | |
846 | |
847 CFileStatus status; | |
848 pCmdUI->Enable(emulating && CFile::GetStatus(winGetSavestateFilename(theApp.gameFilename, slotID), status)); | |
849 } | |
850 | |
851 void MainWnd::OnFileLoadgameMakeCurrent() | |
852 { | |
853 theApp.loadMakesCurrent = !theApp.loadMakesCurrent; | |
854 } | |
855 | |
856 void MainWnd::OnUpdateFileLoadgameMakeCurrent(CCmdUI *pCmdUI) | |
857 { | |
858 pCmdUI->SetCheck(theApp.loadMakesCurrent); | |
859 } | |
860 | |
861 void MainWnd::OnFileSavegameMakeCurrent() | |
862 { | |
863 theApp.saveMakesCurrent = !theApp.saveMakesCurrent; | |
864 } | |
865 | |
866 void MainWnd::OnUpdateFileSavegameMakeCurrent(CCmdUI *pCmdUI) | |
867 { | |
868 pCmdUI->SetCheck(theApp.saveMakesCurrent); | |
869 } | |
870 | |
871 void MainWnd::OnFileSavegameIncrementSlot() | |
872 { | |
873 theApp.currentSlot = (theApp.currentSlot + 1) % 10; | |
874 | |
875 char str [32]; | |
876 sprintf(str, "Current Slot: %d", theApp.currentSlot + 1); | |
877 systemScreenMessage(str, 0); | |
878 } | |
879 | |
880 void MainWnd::OnUpdateFileSavegameIncrementSlot(CCmdUI *pCmdUI) | |
881 { | |
882 if (pCmdUI->m_pMenu != NULL) | |
883 { | |
884 int slotID = theApp.currentSlot + 1; | |
885 | |
886 CString str; | |
887 str.Format("&Increase Current Slot (#%d -> #%d)", slotID, slotID % 10 + 1); | |
888 | |
889 pCmdUI->SetText(str); | |
890 | |
891 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
892 } | |
893 } | |
894 | |
895 void MainWnd::OnFileSavegameDecrementSlot() | |
896 { | |
897 theApp.currentSlot = (theApp.currentSlot + 9) % 10; | |
898 | |
899 char str [32]; | |
900 sprintf(str, "Current Slot: %d", theApp.currentSlot + 1); | |
901 systemScreenMessage(str, 0); | |
902 } | |
903 | |
904 void MainWnd::OnUpdateFileSavegameDecrementSlot(CCmdUI *pCmdUI) | |
905 { | |
906 if (pCmdUI->m_pMenu != NULL) | |
907 { | |
908 int slotID = theApp.currentSlot + 1; | |
909 | |
910 CString str; | |
911 str.Format("&Decrease Current Slot (#%d -> #%d)", slotID, (slotID + 8) % 10 + 1); | |
912 | |
913 pCmdUI->SetText(str); | |
914 | |
915 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); | |
916 } | |
917 } | |
918 | |
919 void MainWnd::OnFileSlotDisplayModificationTime() | |
920 { | |
921 theApp.showSlotTime = !theApp.showSlotTime; | |
922 } | |
923 | |
924 void MainWnd::OnUpdateFileSlotDisplayModificationTime(CCmdUI *pCmdUI) | |
925 { | |
926 pCmdUI->SetCheck(theApp.showSlotTime); | |
927 } | |
928 | |
929 void MainWnd::OnFileLuaOpen() | |
930 { | |
931 theApp.winCheckFullscreen(); | |
932 | |
933 if (!LuaConsoleHWnd) | |
934 { | |
935 LuaConsoleHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_LUA), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) DlgLuaScriptDialog); | |
936 } | |
937 else | |
938 ::SetForegroundWindow(LuaConsoleHWnd); | |
939 } | |
940 | |
941 void MainWnd::OnUpdateFileLuaOpen(CCmdUI *pCmdUI) | |
942 { | |
943 pCmdUI->SetCheck(LuaConsoleHWnd != NULL); | |
944 pCmdUI->Enable(true); | |
945 } | |
946 | |
947 void MainWnd::OnFileLuaCloseAll() | |
948 { | |
949 if (LuaConsoleHWnd) | |
950 ::PostMessage(LuaConsoleHWnd, WM_CLOSE, 0, 0); | |
951 } | |
952 | |
953 void MainWnd::OnFileLuaReload() | |
954 { | |
955 VBAReloadLuaCode(); | |
956 } | |
957 | |
958 void MainWnd::OnFileLuaStop() | |
959 { | |
960 VBALuaStop(); | |
961 } | |
962 | |
963 void MainWnd::OnFileRamSearch() | |
964 { | |
965 theApp.winCheckFullscreen(); | |
966 | |
967 if (!RamSearchHWnd) | |
968 { | |
969 reset_address_info(); | |
970 LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); | |
971 ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMSEARCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamSearchProc); | |
972 } | |
973 else | |
974 ::SetForegroundWindow(RamSearchHWnd); | |
975 } | |
976 | |
977 void MainWnd::OnUpdateFileRamSearch(CCmdUI *pCmdUI) | |
978 { | |
979 pCmdUI->Enable(TRUE); | |
980 } | |
981 | |
982 void MainWnd::OnFileRamWatch() | |
983 { | |
984 theApp.winCheckFullscreen(); | |
985 | |
986 if (!RamWatchHWnd) | |
987 { | |
988 LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); | |
989 RamWatchHWnd = ::CreateDialog(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD_RAMWATCH), AfxGetMainWnd()->GetSafeHwnd(), (DLGPROC) RamWatchProc); | |
990 } | |
991 else | |
992 ::SetForegroundWindow(RamWatchHWnd); | |
993 } | |
994 | |
995 void MainWnd::OnUpdateFileRamWatch(CCmdUI *pCmdUI) | |
996 { | |
997 pCmdUI->Enable(TRUE); | |
998 } | |
999 | |
1000 void MainWnd::OnUpdateFileLuaCloseAll(CCmdUI *pCmdUI) | |
1001 { | |
1002 pCmdUI->Enable(LuaConsoleHWnd != NULL); | |
1003 } | |
1004 |