Mercurial > vba-linux
diff src/win32/MainWndTools.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/MainWndTools.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,1000 @@ 1.4 +#include "stdafx.h" 1.5 +#include <cassert> 1.6 +#include "resource.h" 1.7 +#include "MainWnd.h" 1.8 +#include "AccelEditor.h" 1.9 +#include "AVIWrite.h" 1.10 +#include "Disassemble.h" 1.11 +#include "FileDlg.h" 1.12 +#include "GBDisassemble.h" 1.13 +#include "GBMapView.h" 1.14 +#include "GBMemoryViewerDlg.h" 1.15 +#include "GBOamView.h" 1.16 +#include "GBPaletteView.h" 1.17 +#include "GBTileView.h" 1.18 +#include "GDBConnection.h" 1.19 +#include "IOViewer.h" 1.20 +#include "MapView.h" 1.21 +#include "MemoryViewerDlg.h" 1.22 +#include "MovieOpen.h" 1.23 +#include "MovieCreate.h" 1.24 +#include "OamView.h" 1.25 +#include "PaletteView.h" 1.26 +#include "Reg.h" 1.27 +#include "TileView.h" 1.28 +#include "WavWriter.h" 1.29 +#include "WinResUtil.h" 1.30 +#include "WinMiscUtil.h" 1.31 +#include "VBA.h" 1.32 + 1.33 +#include "../gba/GBA.h" 1.34 +#include "../gba/GBAGlobals.h" 1.35 +#include "../gb/GB.h" 1.36 + 1.37 +extern int32 gbBorderOn; 1.38 +extern int32 soundQuality; 1.39 + 1.40 +extern bool debugger; 1.41 +extern int emulating; 1.42 +extern int remoteSocket; 1.43 + 1.44 +extern void remoteCleanUp(); 1.45 +extern void remoteSetSockets(SOCKET, SOCKET); 1.46 +extern void toolsLogging(); 1.47 + 1.48 +void MainWnd::OnToolsDisassemble() 1.49 +{ 1.50 + if (systemCartridgeType == 0) 1.51 + { 1.52 + Disassemble *dlg = new Disassemble(); 1.53 + dlg->Create(IDD_DISASSEMBLE, this); 1.54 + dlg->ShowWindow(SW_SHOW); 1.55 + } 1.56 + else 1.57 + { 1.58 + GBDisassemble *dlg = new GBDisassemble(); 1.59 + dlg->Create(IDD_GB_DISASSEMBLE, this); 1.60 + dlg->ShowWindow(SW_SHOW); 1.61 + } 1.62 +} 1.63 + 1.64 +void MainWnd::OnUpdateToolsDisassemble(CCmdUI *pCmdUI) 1.65 +{ 1.66 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.67 +} 1.68 + 1.69 +void MainWnd::OnToolsLogging() 1.70 +{ 1.71 + toolsLogging(); 1.72 +} 1.73 + 1.74 +void MainWnd::OnUpdateToolsLogging(CCmdUI *pCmdUI) 1.75 +{ 1.76 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.77 +} 1.78 + 1.79 +void MainWnd::OnToolsIoviewer() 1.80 +{ 1.81 + IOViewer *dlg = new IOViewer; 1.82 + dlg->Create(IDD_IO_VIEWER, this); 1.83 + dlg->ShowWindow(SW_SHOW); 1.84 +} 1.85 + 1.86 +void MainWnd::OnUpdateToolsIoviewer(CCmdUI *pCmdUI) 1.87 +{ 1.88 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && systemCartridgeType == 0); 1.89 +} 1.90 + 1.91 +void MainWnd::OnToolsMapview() 1.92 +{ 1.93 + if (systemCartridgeType == 0) 1.94 + { 1.95 + MapView *dlg = new MapView; 1.96 + dlg->Create(IDD_MAP_VIEW, this); 1.97 + dlg->ShowWindow(SW_SHOW); 1.98 + } 1.99 + else 1.100 + { 1.101 + GBMapView *dlg = new GBMapView; 1.102 + dlg->Create(IDD_GB_MAP_VIEW, this); 1.103 + dlg->ShowWindow(SW_SHOW); 1.104 + } 1.105 +} 1.106 + 1.107 +void MainWnd::OnUpdateToolsMapview(CCmdUI *pCmdUI) 1.108 +{ 1.109 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.110 +} 1.111 + 1.112 +void MainWnd::OnToolsMemoryviewer() 1.113 +{ 1.114 + if (systemCartridgeType == 0) 1.115 + { 1.116 + MemoryViewerDlg *dlg = new MemoryViewerDlg; 1.117 + dlg->Create(IDD_MEM_VIEWER, this); 1.118 + dlg->ShowWindow(SW_SHOW); 1.119 + } 1.120 + else 1.121 + { 1.122 + GBMemoryViewerDlg *dlg = new GBMemoryViewerDlg; 1.123 + dlg->Create(IDD_MEM_VIEWER, this); 1.124 + dlg->ShowWindow(SW_SHOW); 1.125 + } 1.126 +} 1.127 + 1.128 +void MainWnd::OnUpdateToolsMemoryviewer(CCmdUI *pCmdUI) 1.129 +{ 1.130 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.131 +} 1.132 + 1.133 +void MainWnd::OnToolsOamviewer() 1.134 +{ 1.135 + if (systemCartridgeType == 0) 1.136 + { 1.137 + OamView *dlg = new OamView; 1.138 + dlg->Create(IDD_OAM_VIEW, this); 1.139 + dlg->ShowWindow(SW_SHOW); 1.140 + } 1.141 + else 1.142 + { 1.143 + GBOamView *dlg = new GBOamView; 1.144 + dlg->Create(IDD_GB_OAM_VIEW, this); 1.145 + dlg->ShowWindow(SW_SHOW); 1.146 + } 1.147 +} 1.148 + 1.149 +void MainWnd::OnUpdateToolsOamviewer(CCmdUI *pCmdUI) 1.150 +{ 1.151 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.152 +} 1.153 + 1.154 +void MainWnd::OnToolsPaletteview() 1.155 +{ 1.156 + if (systemCartridgeType == 0) 1.157 + { 1.158 + PaletteView *dlg = new PaletteView; 1.159 + dlg->Create(IDD_PALETTE_VIEW, this); 1.160 + dlg->ShowWindow(SW_SHOW); 1.161 + } 1.162 + else 1.163 + { 1.164 + GBPaletteView *dlg = new GBPaletteView; 1.165 + dlg->Create(IDD_GB_PALETTE_VIEW, this); 1.166 + dlg->ShowWindow(SW_SHOW); 1.167 + } 1.168 +} 1.169 + 1.170 +void MainWnd::OnUpdateToolsPaletteview(CCmdUI *pCmdUI) 1.171 +{ 1.172 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.173 +} 1.174 + 1.175 +void MainWnd::OnToolsTileviewer() 1.176 +{ 1.177 + if (systemCartridgeType == 0) 1.178 + { 1.179 + TileView *dlg = new TileView; 1.180 + dlg->Create(IDD_TILE_VIEWER, this); 1.181 + dlg->ShowWindow(SW_SHOW); 1.182 + } 1.183 + else 1.184 + { 1.185 + GBTileView *dlg = new GBTileView; 1.186 + dlg->Create(IDD_GB_TILE_VIEWER, this); 1.187 + dlg->ShowWindow(SW_SHOW); 1.188 + } 1.189 +} 1.190 + 1.191 +void MainWnd::OnUpdateToolsTileviewer(CCmdUI *pCmdUI) 1.192 +{ 1.193 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); 1.194 +} 1.195 + 1.196 +void MainWnd::OnDebugNextframe() 1.197 +{ 1.198 + systemSetPause(false); 1.199 + theApp.winPauseNextFrame = true; 1.200 +} 1.201 + 1.202 +void MainWnd::OnUpdateDebugNextframe(CCmdUI *pCmdUI) 1.203 +{ 1.204 + pCmdUI->Enable(emulating); 1.205 +} 1.206 + 1.207 +void MainWnd::OnDebugNextframeAccountForLag() 1.208 +{ 1.209 + theApp.nextframeAccountForLag = !theApp.nextframeAccountForLag; 1.210 +} 1.211 + 1.212 +void MainWnd::OnUpdateDebugNextframeAccountForLag(CCmdUI *pCmdUI) 1.213 +{ 1.214 + pCmdUI->SetCheck(theApp.nextframeAccountForLag); 1.215 +} 1.216 + 1.217 +void MainWnd::OnDebugFramesearch() 1.218 +{ 1.219 + extern u16 currentButtons [4]; // from System.cpp 1.220 + extern SMovie Movie; 1.221 + if (!theApp.frameSearching) 1.222 + { 1.223 + // starting a new search 1.224 + theApp.frameSearching = true; 1.225 + theApp.frameSearchStart = (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame; 1.226 + theApp.frameSearchLength = 0; 1.227 + theApp.frameSearchLoadValid = false; 1.228 + theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); // 0 is start state, 1 is 1.229 + // intermediate state (for 1.230 + // speedup when going 1.231 + // forward), 1.232 + // 2 is end state 1.233 + theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE); 1.234 + 1.235 + // store old buttons from frame before the search 1.236 + for (int i = 0; i < 4; i++) 1.237 + theApp.frameSearchOldInput[i] = currentButtons[i]; 1.238 + } 1.239 + else 1.240 + { 1.241 + // advance forward 1 step in the search 1.242 + theApp.frameSearchLength++; 1.243 + 1.244 + // try it 1.245 + theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE); 1.246 + } 1.247 + 1.248 + char str [32]; 1.249 + sprintf(str, "%d frame search", theApp.frameSearchLength); 1.250 + systemScreenMessage(str, 0); 1.251 + 1.252 + theApp.frameSearchSkipping = true; 1.253 + 1.254 + // make sure the display updates at least 1 frame to show the new message 1.255 + theApp.frameSearchFirstStep = true; 1.256 + 1.257 + if (theApp.paused) 1.258 + theApp.paused = false; 1.259 +} 1.260 + 1.261 +void MainWnd::OnUpdateDebugFramesearch(CCmdUI *pCmdUI) 1.262 +{ 1.263 + extern SMovie Movie; 1.264 + pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY); 1.265 + pCmdUI->SetCheck(theApp.frameSearching); 1.266 +} 1.267 + 1.268 +void MainWnd::OnDebugFramesearchPrev() 1.269 +{ 1.270 + if (theApp.frameSearching) 1.271 + { 1.272 + if (theApp.frameSearchLength > 0) 1.273 + { 1.274 + // rewind 1 step in the search 1.275 + theApp.frameSearchLength--; 1.276 + } 1.277 + 1.278 + // try it 1.279 + theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); 1.280 + 1.281 + char str[32]; 1.282 + sprintf(str, "%d frame search", theApp.frameSearchLength); 1.283 + systemScreenMessage(str, 0); 1.284 + 1.285 + theApp.frameSearchSkipping = true; 1.286 + 1.287 + // make sure the display updates at least 1 frame to show the new message 1.288 + theApp.frameSearchFirstStep = true; 1.289 + 1.290 + if (theApp.paused) 1.291 + theApp.paused = false; 1.292 + } 1.293 +} 1.294 + 1.295 +void MainWnd::OnUpdateDebugFramesearchPrev(CCmdUI *pCmdUI) 1.296 +{ 1.297 + extern SMovie Movie; 1.298 + pCmdUI->Enable(emulating && theApp.frameSearching && Movie.state != MOVIE_STATE_PLAY); 1.299 +} 1.300 + 1.301 +void MainWnd::OnDebugFramesearchLoad() 1.302 +{ 1.303 + if (theApp.frameSearchLoadValid) 1.304 + { 1.305 + theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE); 1.306 + theApp.paused = true; 1.307 + 1.308 + if (theApp.frameSearching) 1.309 + systemScreenMessage("end frame search", 0); 1.310 + else 1.311 + systemScreenMessage("restore search end", 0); 1.312 + } 1.313 + theApp.frameSearching = false; 1.314 + theApp.frameSearchSkipping = false; 1.315 +} 1.316 + 1.317 +void MainWnd::OnUpdateDebugFramesearchLoad(CCmdUI *pCmdUI) 1.318 +{ 1.319 + extern SMovie Movie; 1.320 + pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY); 1.321 +} 1.322 + 1.323 +void MainWnd::OnToolsFrameCounter() 1.324 +{ 1.325 + theApp.frameCounter = !theApp.frameCounter; 1.326 + extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); 1.327 +} 1.328 + 1.329 +void MainWnd::OnUpdateToolsFrameCounter(CCmdUI *pCmdUI) 1.330 +{ 1.331 + pCmdUI->SetCheck(theApp.frameCounter); 1.332 +} 1.333 + 1.334 +void MainWnd::OnToolsLagCounter() 1.335 +{ 1.336 + theApp.lagCounter = !theApp.lagCounter; 1.337 + extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); 1.338 +} 1.339 + 1.340 +void MainWnd::OnUpdateToolsLagCounter(CCmdUI *pCmdUI) 1.341 +{ 1.342 + pCmdUI->SetCheck(theApp.lagCounter); 1.343 +} 1.344 + 1.345 +void MainWnd::OnToolsExtraCounter() 1.346 +{ 1.347 + theApp.extraCounter = !theApp.extraCounter; 1.348 + extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); 1.349 +} 1.350 + 1.351 +void MainWnd::OnUpdateToolsExtraCounter(CCmdUI *pCmdUI) 1.352 +{ 1.353 + pCmdUI->SetCheck(theApp.extraCounter); 1.354 +} 1.355 + 1.356 +void MainWnd::OnToolsExtraCounterReset() 1.357 +{ 1.358 + systemCounters.extraCount = systemCounters.frameCount; 1.359 +} 1.360 + 1.361 +void MainWnd::OnToolsInputDisplay() 1.362 +{ 1.363 + theApp.inputDisplay = !theApp.inputDisplay; 1.364 + systemScreenMessage(theApp.inputDisplay ? "Input Display On" : "Input Display Off"); 1.365 + extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay(); 1.366 +} 1.367 + 1.368 +void MainWnd::OnUpdateToolsInputDisplay(CCmdUI *pCmdUI) 1.369 +{ 1.370 + pCmdUI->SetCheck(theApp.inputDisplay); 1.371 +} 1.372 + 1.373 +void MainWnd::OnToolsDebugGdb() 1.374 +{ 1.375 + theApp.winCheckFullscreen(); 1.376 + GDBPortDlg dlg; 1.377 + 1.378 + if (dlg.DoModal()) 1.379 + { 1.380 + GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); 1.381 + if (wait.DoModal()) 1.382 + { 1.383 + remoteSetSockets(wait.getListenSocket(), wait.getSocket()); 1.384 + debugger = true; 1.385 + emulating = 1; 1.386 + systemCartridgeType = 0; 1.387 + theApp.gameFilename = "\\gnu_stub"; 1.388 + rom = (u8 *)malloc(0x2000000 + 4); 1.389 + workRAM = (u8 *)calloc(1, 0x40000 + 4); 1.390 + bios = (u8 *)calloc(1, 0x4000 + 4); 1.391 + internalRAM = (u8 *)calloc(1, 0x8000 + 4); 1.392 + paletteRAM = (u8 *)calloc(1, 0x400 + 4); 1.393 + vram = (u8 *)calloc(1, 0x20000 + 4); 1.394 + oam = (u8 *)calloc(1, 0x400 + 4); 1.395 + pix = (u8 *)calloc(1, 4 * 240 * 160); 1.396 + ioMem = (u8 *)calloc(1, 0x400 + 4); 1.397 + 1.398 + theApp.emulator = GBASystem; 1.399 + 1.400 + CPUInit(); 1.401 + CPULoadBios(theApp.biosFileName, theApp.useBiosFile ? true : false); 1.402 + CPUReset(); 1.403 + } 1.404 + } 1.405 +} 1.406 + 1.407 +void MainWnd::OnUpdateToolsDebugGdb(CCmdUI *pCmdUI) 1.408 +{ 1.409 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1); 1.410 +} 1.411 + 1.412 +void MainWnd::OnToolsDebugLoadandwait() 1.413 +{ 1.414 + theApp.winCheckFullscreen(); 1.415 + if (winFileOpenSelect(0)) 1.416 + { 1.417 + if (winFileRun()) 1.418 + { 1.419 + if (systemCartridgeType != 0) 1.420 + { 1.421 + systemMessage(IDS_ERROR_NOT_GBA_IMAGE, "Error: not a GBA image"); 1.422 + OnFileClose(); 1.423 + return; 1.424 + } 1.425 + GDBPortDlg dlg; 1.426 + 1.427 + if (dlg.DoModal()) 1.428 + { 1.429 + GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); 1.430 + if (wait.DoModal()) 1.431 + { 1.432 + remoteSetSockets(wait.getListenSocket(), wait.getSocket()); 1.433 + debugger = true; 1.434 + emulating = 1; 1.435 + } 1.436 + } 1.437 + } 1.438 + } 1.439 +} 1.440 + 1.441 +void MainWnd::OnUpdateToolsDebugLoadandwait(CCmdUI *pCmdUI) 1.442 +{ 1.443 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1); 1.444 +} 1.445 + 1.446 +void MainWnd::OnToolsDebugBreak() 1.447 +{ 1.448 + if (armState) 1.449 + { 1.450 + armNextPC -= 4; 1.451 + reg[15].I -= 4; 1.452 + } 1.453 + else 1.454 + { 1.455 + armNextPC -= 2; 1.456 + reg[15].I -= 2; 1.457 + } 1.458 + debugger = true; 1.459 +} 1.460 + 1.461 +void MainWnd::OnUpdateToolsDebugBreak(CCmdUI *pCmdUI) 1.462 +{ 1.463 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1); 1.464 +} 1.465 + 1.466 +void MainWnd::OnToolsDebugDisconnect() 1.467 +{ 1.468 + remoteCleanUp(); 1.469 + debugger = false; 1.470 +} 1.471 + 1.472 +void MainWnd::OnUpdateToolsDebugDisconnect(CCmdUI *pCmdUI) 1.473 +{ 1.474 + pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1); 1.475 +} 1.476 + 1.477 +void MainWnd::OnToolsSoundRecording() 1.478 +{ 1.479 + if (!theApp.soundRecording) 1.480 + OnToolsSoundStartrecording(); 1.481 + else 1.482 + OnToolsSoundStoprecording(); 1.483 +} 1.484 + 1.485 +void MainWnd::OnToolsSoundStartrecording() 1.486 +{ 1.487 + theApp.winCheckFullscreen(); 1.488 + 1.489 + CString wavName = theApp.gameFilename; 1.490 + 1.491 + if (VBAMovieActive()) 1.492 + { 1.493 + extern SMovie Movie; 1.494 + wavName = Movie.filename; 1.495 + int index = wavName.ReverseFind('.'); 1.496 + if (index != -1) 1.497 + wavName = wavName.Left(index); 1.498 + } 1.499 + 1.500 + LPCTSTR exts[] = { ".wav", NULL }; 1.501 + 1.502 + CString filter = winResLoadFilter(IDS_FILTER_WAV); 1.503 + CString title = winResLoadString(IDS_SELECT_WAV_NAME); 1.504 + 1.505 + wavName = winGetDestFilename(wavName, IDS_WAV_DIR, exts[0]); 1.506 + CString wavDir = winGetDestDir(IDS_WAV_DIR); 1.507 + 1.508 + FileDlg dlg(this, wavName, filter, 1, "WAV", exts, wavDir, title, true); 1.509 + 1.510 + if (dlg.DoModal() == IDCANCEL) 1.511 + { 1.512 + return; 1.513 + } 1.514 + 1.515 + theApp.soundRecordName = dlg.GetPathName(); 1.516 + theApp.soundRecording = true; 1.517 +} 1.518 + 1.519 +void MainWnd::OnToolsSoundStoprecording() 1.520 +{ 1.521 + if (theApp.soundRecorder) 1.522 + { 1.523 + delete theApp.soundRecorder; 1.524 + theApp.soundRecorder = NULL; 1.525 + } 1.526 + theApp.soundRecording = false; 1.527 +} 1.528 + 1.529 +void MainWnd::OnUpdateToolsSoundRecording(CCmdUI *pCmdUI) 1.530 +{ 1.531 + if (pCmdUI->m_pMenu != NULL) 1.532 + { 1.533 + if (!theApp.soundRecording) 1.534 + pCmdUI->SetText(winResLoadString(IDS_STARTSOUNDRECORDING)); 1.535 + else 1.536 + pCmdUI->SetText(winResLoadString(IDS_STOPSOUNDRECORDING)); 1.537 + 1.538 + theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); 1.539 + } 1.540 + 1.541 + pCmdUI->Enable(emulating); 1.542 +} 1.543 + 1.544 +void MainWnd::OnToolsAVIRecording() 1.545 +{ 1.546 + if (!theApp.aviRecording) 1.547 + OnToolsStartAVIRecording(); 1.548 + else 1.549 + OnToolsStopAVIRecording(); 1.550 +} 1.551 + 1.552 +void MainWnd::OnToolsStartAVIRecording() 1.553 +{ 1.554 + theApp.winCheckFullscreen(); 1.555 + 1.556 + CString aviName = theApp.gameFilename; 1.557 + 1.558 + if (VBAMovieActive()) 1.559 + { 1.560 + extern SMovie Movie; 1.561 + aviName = Movie.filename; 1.562 + int index = aviName.ReverseFind('.'); 1.563 + if (index != -1) 1.564 + aviName = aviName.Left(index); 1.565 + } 1.566 + 1.567 + LPCTSTR exts[] = { ".avi", NULL }; 1.568 + 1.569 + CString filter = winResLoadFilter(IDS_FILTER_AVI); 1.570 + CString title = winResLoadString(IDS_SELECT_AVI_NAME); 1.571 + 1.572 + aviName = winGetDestFilename(aviName, IDS_AVI_DIR, exts[0]); 1.573 + CString aviDir = winGetDestDir(IDS_AVI_DIR); 1.574 + 1.575 + FileDlg dlg(this, aviName, filter, 1, "AVI", exts, aviDir, title, true); 1.576 + 1.577 + if (dlg.DoModal() == IDCANCEL) 1.578 + { 1.579 + return; 1.580 + } 1.581 + 1.582 + theApp.aviRecordName = theApp.soundRecordName = dlg.GetPathName(); 1.583 + theApp.aviRecording = true; 1.584 + 1.585 +/// extern long linearFrameCount; linearFrameCount = 0; 1.586 +/// extern long linearSoundByteCount; linearSoundByteCount = 0; 1.587 + 1.588 + if (theApp.aviRecorder == NULL) 1.589 + { 1.590 + int width = 240; 1.591 + int height = 160; 1.592 + switch (systemCartridgeType) 1.593 + { 1.594 + case 0: 1.595 + width = 240; 1.596 + height = 160; 1.597 + break; 1.598 + case 1: 1.599 + if (gbBorderOn) 1.600 + { 1.601 + width = 256; 1.602 + height = 224; 1.603 + } 1.604 + else 1.605 + { 1.606 + width = 160; 1.607 + height = 144; 1.608 + } 1.609 + break; 1.610 + } 1.611 + 1.612 + theApp.aviRecorder = new AVIWrite(); 1.613 + 1.614 + theApp.aviRecorder->SetFPS(60); 1.615 + 1.616 + BITMAPINFOHEADER bi; 1.617 + memset(&bi, 0, sizeof(bi)); 1.618 + bi.biSize = 0x28; 1.619 + bi.biPlanes = 1; 1.620 + bi.biBitCount = 24; 1.621 + bi.biWidth = width; 1.622 + bi.biHeight = height; 1.623 + bi.biSizeImage = 3 * width * height; 1.624 + theApp.aviRecorder->SetVideoFormat(&bi); 1.625 + if (!theApp.aviRecorder->Open(theApp.aviRecordName)) 1.626 + { 1.627 + delete theApp.aviRecorder; 1.628 + theApp.aviRecorder = NULL; 1.629 + theApp.aviRecording = false; 1.630 + } 1.631 + 1.632 + if (theApp.aviRecorder) 1.633 + { 1.634 + WAVEFORMATEX wfx; 1.635 + memset(&wfx, 0, sizeof(wfx)); 1.636 + wfx.wFormatTag = WAVE_FORMAT_PCM; 1.637 + wfx.nChannels = 2; 1.638 + wfx.nSamplesPerSec = 44100 / soundQuality; 1.639 + wfx.wBitsPerSample = 16; 1.640 + wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels; 1.641 + wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; 1.642 + wfx.cbSize = 0; 1.643 + theApp.aviRecorder->SetSoundFormat(&wfx); 1.644 + } 1.645 + } 1.646 +} 1.647 + 1.648 +void MainWnd::OnToolsPauseAVIRecording() 1.649 +{ 1.650 + theApp.aviRecorder->Pause(!theApp.aviRecorder->IsPaused()); 1.651 +} 1.652 + 1.653 +void MainWnd::OnToolsStopAVIRecording() 1.654 +{ 1.655 + if (theApp.aviRecorder != NULL) 1.656 + { 1.657 + delete theApp.aviRecorder; 1.658 + theApp.aviRecorder = NULL; 1.659 + } 1.660 + theApp.aviRecording = false; 1.661 +} 1.662 + 1.663 +void MainWnd::OnUpdateToolsAVIRecording(CCmdUI *pCmdUI) 1.664 +{ 1.665 + if (pCmdUI->m_pMenu != NULL) 1.666 + { 1.667 + if (!theApp.aviRecording) 1.668 + pCmdUI->SetText(winResLoadString(IDS_STARTAVIRECORDING)); 1.669 + else 1.670 + pCmdUI->SetText(winResLoadString(IDS_STOPAVIRECORDING)); 1.671 + 1.672 + theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); 1.673 + } 1.674 + 1.675 + pCmdUI->Enable(emulating); 1.676 +} 1.677 + 1.678 +void MainWnd::OnUpdateToolsPauseAVIRecording(CCmdUI *pCmdUI) 1.679 +{ 1.680 + if (pCmdUI->m_pMenu != NULL) 1.681 + { 1.682 + if (!theApp.aviRecording) 1.683 + { 1.684 + pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING)); 1.685 + theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); 1.686 + pCmdUI->Enable(false); 1.687 + } 1.688 + else 1.689 + { 1.690 + if (!theApp.aviRecorder->IsPaused()) 1.691 + pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING)); 1.692 + else 1.693 + pCmdUI->SetText(winResLoadString(IDS_RESUMEAVIRECORDING)); 1.694 + 1.695 + theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); 1.696 + pCmdUI->Enable(emulating); 1.697 + } 1.698 + } 1.699 +} 1.700 + 1.701 +void MainWnd::OnToolsRecordMovie() 1.702 +{ 1.703 + MovieCreate dlg; 1.704 + dlg.DoModal(); 1.705 +} 1.706 + 1.707 +void MainWnd::OnUpdateToolsRecordMovie(CCmdUI *pCmdUI) 1.708 +{ 1.709 + pCmdUI->Enable(emulating); 1.710 +} 1.711 + 1.712 +void MainWnd::OnToolsStopMovie() 1.713 +{ 1.714 + VBAMovieStop(false); 1.715 +} 1.716 + 1.717 +void MainWnd::OnUpdateToolsStopMovie(CCmdUI *pCmdUI) 1.718 +{ 1.719 + pCmdUI->Enable(emulating && VBAMovieActive()); 1.720 +} 1.721 + 1.722 +void MainWnd::OnToolsPlayMovie() 1.723 +{ 1.724 + MovieOpen dlg; 1.725 + dlg.DoModal(); 1.726 +} 1.727 + 1.728 +void MainWnd::OnUpdateToolsPlayMovie(CCmdUI *pCmdUI) 1.729 +{ 1.730 + pCmdUI->Enable(emulating); 1.731 +} 1.732 + 1.733 +void MainWnd::OnToolsPlayReadOnly() 1.734 +{ 1.735 + if (!VBAMovieActive()) 1.736 + { 1.737 + theApp.movieReadOnly = !theApp.movieReadOnly; 1.738 + systemScreenMessage(theApp.movieReadOnly ? "Movie now read-only" : "Movie now editable"); 1.739 + } 1.740 + else 1.741 + VBAMovieToggleReadOnly(); 1.742 +} 1.743 + 1.744 +void MainWnd::OnUpdateToolsPlayReadOnly(CCmdUI *pCmdUI) 1.745 +{ 1.746 +/// pCmdUI->Enable(VBAMovieActive()); // FIXME: this is right, but disabling menu items screws up accelerators until you view 1.747 +// the menu! 1.748 +/// pCmdUI->SetCheck(VBAMovieReadOnly()); 1.749 + pCmdUI->Enable(TRUE); // TEMP 1.750 + pCmdUI->SetCheck(VBAMovieActive() ? VBAMovieReadOnly() : theApp.movieReadOnly); 1.751 +} 1.752 + 1.753 +void MainWnd::OnAsscWithSaveState() 1.754 +{ 1.755 + theApp.AsscWithSaveState = !theApp.AsscWithSaveState; 1.756 +} 1.757 + 1.758 +void MainWnd::OnUpdateAsscWithSaveState(CCmdUI *pCmdUI) 1.759 +{ 1.760 + pCmdUI->Enable(TRUE); // TEMP 1.761 + pCmdUI->SetCheck(theApp.AsscWithSaveState); 1.762 +} 1.763 + 1.764 +void MainWnd::OnToolsResumeRecord() 1.765 +{ 1.766 + // toggle playing/recording 1.767 + if (VBAMovieRecording()) 1.768 + { 1.769 + if (!VBAMovieSwitchToPlaying()) 1.770 + systemScreenMessage("Cannot continue playing"); 1.771 + } 1.772 + else 1.773 + { 1.774 + if (!VBAMovieSwitchToRecording()) 1.775 + systemScreenMessage("Cannot resume recording now"); 1.776 + } 1.777 +} 1.778 + 1.779 +void MainWnd::OnUpdateToolsResumeRecord(CCmdUI *pCmdUI) 1.780 +{ 1.781 + pCmdUI->Enable(VBAMovieActive()); 1.782 +} 1.783 + 1.784 +void MainWnd::OnToolsPlayRestart() 1.785 +{ 1.786 + VBAMovieRestart(); 1.787 +} 1.788 + 1.789 +void MainWnd::OnUpdateToolsPlayRestart(CCmdUI *pCmdUI) 1.790 +{ 1.791 + pCmdUI->Enable(VBAMovieActive()); 1.792 +} 1.793 + 1.794 +void MainWnd::OnToolsOnMovieEndPause() 1.795 +{ 1.796 + theApp.movieOnEndPause = !theApp.movieOnEndPause; 1.797 +} 1.798 + 1.799 +void MainWnd::OnUpdateToolsOnMovieEndPause(CCmdUI *pCmdUI) 1.800 +{ 1.801 + pCmdUI->SetCheck(theApp.movieOnEndPause); 1.802 +} 1.803 + 1.804 +void MainWnd::OnToolsOnMovieEndStop() 1.805 +{ 1.806 + theApp.movieOnEndBehavior = 0; 1.807 +} 1.808 + 1.809 +void MainWnd::OnUpdateToolsOnMovieEndStop(CCmdUI *pCmdUI) 1.810 +{ 1.811 + pCmdUI->SetRadio(theApp.movieOnEndBehavior == 0); 1.812 +} 1.813 + 1.814 +void MainWnd::OnToolsOnMovieEndRestart() 1.815 +{ 1.816 + theApp.movieOnEndBehavior = 1; 1.817 +} 1.818 + 1.819 +void MainWnd::OnUpdateToolsOnMovieEndRestart(CCmdUI *pCmdUI) 1.820 +{ 1.821 + pCmdUI->SetRadio(theApp.movieOnEndBehavior == 1); 1.822 +} 1.823 + 1.824 +void MainWnd::OnToolsOnMovieEndAppend() 1.825 +{ 1.826 + theApp.movieOnEndBehavior = 2; 1.827 +} 1.828 + 1.829 +void MainWnd::OnUpdateToolsOnMovieEndAppend(CCmdUI *pCmdUI) 1.830 +{ 1.831 + pCmdUI->SetRadio(theApp.movieOnEndBehavior == 2); 1.832 +} 1.833 + 1.834 +void MainWnd::OnToolsOnMovieEndKeep() 1.835 +{ 1.836 + theApp.movieOnEndBehavior = 3; 1.837 +} 1.838 + 1.839 +void MainWnd::OnUpdateToolsOnMovieEndKeep(CCmdUI *pCmdUI) 1.840 +{ 1.841 + pCmdUI->SetRadio(theApp.movieOnEndBehavior == 3); 1.842 +} 1.843 + 1.844 +///////////////////////////////// 1.845 + 1.846 +void MainWnd::OnToolsMovieSetPauseAt() 1.847 +{ 1.848 + // TODO 1.849 + VBAMovieSetPauseAt(-1); 1.850 +} 1.851 + 1.852 +void MainWnd::OnUpdateToolsSetMoviePauseAt(CCmdUI *pCmdUI) 1.853 +{ 1.854 + // TODO 1.855 + pCmdUI->SetCheck(VBAMovieGetPauseAt() >= 0); 1.856 + pCmdUI->Enable(FALSE && VBAMovieActive()); 1.857 +} 1.858 + 1.859 +void MainWnd::OnToolsMovieConvertCurrent() 1.860 +{ 1.861 + // temporary 1.862 + int result = VBAMovieConvertCurrent(); 1.863 + switch (result) 1.864 + { 1.865 + case MOVIE_SUCCESS: 1.866 + systemScreenMessage("Movie converted"); 1.867 + break; 1.868 + case MOVIE_WRONG_VERSION: 1.869 + systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion()); 1.870 + break; 1.871 + default: 1.872 + systemScreenMessage("Nothing to convert"); 1.873 + break; 1.874 + } 1.875 +} 1.876 + 1.877 +void MainWnd::OnUpdateToolsMovieConvertCurrent(CCmdUI *pCmdUI) 1.878 +{ 1.879 + pCmdUI->Enable(VBAMovieActive()); 1.880 +} 1.881 + 1.882 +void MainWnd::OnToolsMovieAutoConvert() 1.883 +{ 1.884 + extern bool autoConvertMovieWhenPlaying; // from movie.cpp 1.885 + autoConvertMovieWhenPlaying = !autoConvertMovieWhenPlaying; 1.886 + if (autoConvertMovieWhenPlaying) 1.887 + { 1.888 + int result = VBAMovieConvertCurrent(); 1.889 + switch (result) 1.890 + { 1.891 + case MOVIE_SUCCESS: 1.892 + systemScreenMessage("Movie converted"); 1.893 + break; 1.894 + case MOVIE_WRONG_VERSION: 1.895 + systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion()); 1.896 + break; 1.897 + default: 1.898 + systemScreenMessage("Auto movie conversion enabled"); 1.899 + break; 1.900 + } 1.901 + } 1.902 +} 1.903 + 1.904 +void MainWnd::OnUpdateToolsMovieAutoConvert(CCmdUI *pCmdUI) 1.905 +{ 1.906 + extern bool autoConvertMovieWhenPlaying; // from movie.cpp 1.907 + pCmdUI->SetCheck(autoConvertMovieWhenPlaying); 1.908 +} 1.909 + 1.910 +void MainWnd::OnToolsMovieTruncateAtCurrent() 1.911 +{ 1.912 + if (VBAMovieReadOnly()) 1.913 + systemScreenMessage("Cannot truncate movie in this mode"); 1.914 + else 1.915 + VBAMovieTuncateAtCurrentFrame(); 1.916 +} 1.917 + 1.918 +void MainWnd::OnUpdateToolsMovieTruncateAtCurrent(CCmdUI *pCmdUI) 1.919 +{ 1.920 + pCmdUI->Enable(VBAMovieActive()); 1.921 +} 1.922 + 1.923 +void MainWnd::OnToolsMovieFixHeader() 1.924 +{ 1.925 + VBAMovieFixHeader(); 1.926 +} 1.927 + 1.928 +void MainWnd::OnUpdateToolsMovieFixHeader(CCmdUI *pCmdUI) 1.929 +{ 1.930 + pCmdUI->Enable(VBAMovieActive()); 1.931 +} 1.932 + 1.933 +// TODO 1.934 +void MainWnd::OnToolsMovieExtractFromSavegame() 1.935 +{ 1.936 + // Currently, snapshots taken from a movie don't contain the initial SRAM or savestate of the movie, 1.937 + // even if the movie was recorded from either of them. If a snapshot was taken at the first frame 1.938 + // i.e. Frame 0, it can be safely assumed that the snapshot reflects the initial state of such a movie. 1.939 + // However, if it was taken after the first frame, the SRAM contained might either be still the same 1.940 + // as the original (usually true if no write operations on the SRAM occured) or have been modified, 1.941 + // while the exact original state could hardly, if not impossibly, be safely worked out. 1.942 + 1.943 + // TODO 1.944 +} 1.945 + 1.946 +void MainWnd::OnUpdateToolsMovieExtractFromSavegame(CCmdUI *pCmdUI) 1.947 +{ 1.948 + pCmdUI->Enable(FALSE); 1.949 +} 1.950 + 1.951 +/////////////////////////////////////////////////////////// 1.952 + 1.953 +void MainWnd::OnToolsRewind() 1.954 +{ 1.955 + assert(theApp.rewindTimer > 0 && theApp.rewindSlots > 0); 1.956 + if (emulating && theApp.emulator.emuReadMemState && theApp.rewindMemory && theApp.rewindCount) 1.957 + { 1.958 + assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots); 1.959 + theApp.rewindPos = (--theApp.rewindPos + theApp.rewindSlots) % theApp.rewindSlots; 1.960 + assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots); 1.961 + theApp.emulator.emuReadMemState(&theApp.rewindMemory[REWIND_SIZE * theApp.rewindPos], REWIND_SIZE); 1.962 + theApp.rewindCount--; 1.963 + if (theApp.rewindCount > 0) 1.964 + theApp.rewindCounter = 0; 1.965 + else 1.966 + { 1.967 + theApp.rewindCounter = theApp.rewindTimer; 1.968 + theApp.rewindSaveNeeded = true; 1.969 + 1.970 + // immediately save state to avoid eroding away the earliest you can rewind to 1.971 + theApp.saveRewindStateIfNecessary(); 1.972 + 1.973 + theApp.rewindSaveNeeded = false; 1.974 + } 1.975 + } 1.976 +} 1.977 + 1.978 +void MainWnd::OnUpdateToolsRewind(CCmdUI *pCmdUI) 1.979 +{ 1.980 + pCmdUI->Enable(theApp.rewindMemory != NULL && emulating && theApp.rewindCount); 1.981 +} 1.982 + 1.983 +void MainWnd::OnToolsCustomize() 1.984 +{ 1.985 + theApp.recreateMenuBar(); 1.986 + 1.987 + AccelEditor dlg(this, &theApp.m_menu, &theApp.winAccelMgr); 1.988 + dlg.DoModal(); 1.989 + if (dlg.IsModified()) 1.990 + { 1.991 + theApp.winAccelMgr = dlg.GetResultMangager(); 1.992 + theApp.winAccelMgr.UpdateWndTable(); 1.993 + theApp.winAccelMgr.Write(); 1.994 + } 1.995 + 1.996 + theApp.winAccelMgr.UpdateMenu(theApp.menu); // we should always do this since the menu has been reloaded 1.997 +} 1.998 + 1.999 +void MainWnd::OnUpdateToolsCustomize(CCmdUI *pCmdUI) 1.1000 +{ 1.1001 + pCmdUI->Enable(theApp.videoOption != VIDEO_320x240); 1.1002 +} 1.1003 +