rlm@1: #include "stdafx.h" rlm@1: #include rlm@1: #include "resource.h" rlm@1: #include "MainWnd.h" rlm@1: #include "AccelEditor.h" rlm@1: #include "AVIWrite.h" rlm@1: #include "Disassemble.h" rlm@1: #include "FileDlg.h" rlm@1: #include "GBDisassemble.h" rlm@1: #include "GBMapView.h" rlm@1: #include "GBMemoryViewerDlg.h" rlm@1: #include "GBOamView.h" rlm@1: #include "GBPaletteView.h" rlm@1: #include "GBTileView.h" rlm@1: #include "GDBConnection.h" rlm@1: #include "IOViewer.h" rlm@1: #include "MapView.h" rlm@1: #include "MemoryViewerDlg.h" rlm@1: #include "MovieOpen.h" rlm@1: #include "MovieCreate.h" rlm@1: #include "OamView.h" rlm@1: #include "PaletteView.h" rlm@1: #include "Reg.h" rlm@1: #include "TileView.h" rlm@1: #include "WavWriter.h" rlm@1: #include "WinResUtil.h" rlm@1: #include "WinMiscUtil.h" rlm@1: #include "VBA.h" rlm@1: rlm@1: #include "../gba/GBA.h" rlm@1: #include "../gba/GBAGlobals.h" rlm@1: #include "../gb/GB.h" rlm@1: rlm@1: extern int32 gbBorderOn; rlm@1: extern int32 soundQuality; rlm@1: rlm@1: extern bool debugger; rlm@1: extern int emulating; rlm@1: extern int remoteSocket; rlm@1: rlm@1: extern void remoteCleanUp(); rlm@1: extern void remoteSetSockets(SOCKET, SOCKET); rlm@1: extern void toolsLogging(); rlm@1: rlm@1: void MainWnd::OnToolsDisassemble() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: Disassemble *dlg = new Disassemble(); rlm@1: dlg->Create(IDD_DISASSEMBLE, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBDisassemble *dlg = new GBDisassemble(); rlm@1: dlg->Create(IDD_GB_DISASSEMBLE, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsDisassemble(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsLogging() rlm@1: { rlm@1: toolsLogging(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsLogging(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsIoviewer() rlm@1: { rlm@1: IOViewer *dlg = new IOViewer; rlm@1: dlg->Create(IDD_IO_VIEWER, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsIoviewer(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && systemCartridgeType == 0); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMapview() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: MapView *dlg = new MapView; rlm@1: dlg->Create(IDD_MAP_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBMapView *dlg = new GBMapView; rlm@1: dlg->Create(IDD_GB_MAP_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMapview(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMemoryviewer() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: MemoryViewerDlg *dlg = new MemoryViewerDlg; rlm@1: dlg->Create(IDD_MEM_VIEWER, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBMemoryViewerDlg *dlg = new GBMemoryViewerDlg; rlm@1: dlg->Create(IDD_MEM_VIEWER, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMemoryviewer(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOamviewer() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: OamView *dlg = new OamView; rlm@1: dlg->Create(IDD_OAM_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBOamView *dlg = new GBOamView; rlm@1: dlg->Create(IDD_GB_OAM_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOamviewer(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsPaletteview() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: PaletteView *dlg = new PaletteView; rlm@1: dlg->Create(IDD_PALETTE_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBPaletteView *dlg = new GBPaletteView; rlm@1: dlg->Create(IDD_GB_PALETTE_VIEW, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsPaletteview(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsTileviewer() rlm@1: { rlm@1: if (systemCartridgeType == 0) rlm@1: { rlm@1: TileView *dlg = new TileView; rlm@1: dlg->Create(IDD_TILE_VIEWER, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: else rlm@1: { rlm@1: GBTileView *dlg = new GBTileView; rlm@1: dlg->Create(IDD_GB_TILE_VIEWER, this); rlm@1: dlg->ShowWindow(SW_SHOW); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsTileviewer(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X); rlm@1: } rlm@1: rlm@1: void MainWnd::OnDebugNextframe() rlm@1: { rlm@1: systemSetPause(false); rlm@1: theApp.winPauseNextFrame = true; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateDebugNextframe(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: rlm@1: void MainWnd::OnDebugNextframeAccountForLag() rlm@1: { rlm@1: theApp.nextframeAccountForLag = !theApp.nextframeAccountForLag; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateDebugNextframeAccountForLag(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.nextframeAccountForLag); rlm@1: } rlm@1: rlm@1: void MainWnd::OnDebugFramesearch() rlm@1: { rlm@1: extern u16 currentButtons [4]; // from System.cpp rlm@1: extern SMovie Movie; rlm@1: if (!theApp.frameSearching) rlm@1: { rlm@1: // starting a new search rlm@1: theApp.frameSearching = true; rlm@1: theApp.frameSearchStart = (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame; rlm@1: theApp.frameSearchLength = 0; rlm@1: theApp.frameSearchLoadValid = false; rlm@1: theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); // 0 is start state, 1 is rlm@1: // intermediate state (for rlm@1: // speedup when going rlm@1: // forward), rlm@1: // 2 is end state rlm@1: theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE); rlm@1: rlm@1: // store old buttons from frame before the search rlm@1: for (int i = 0; i < 4; i++) rlm@1: theApp.frameSearchOldInput[i] = currentButtons[i]; rlm@1: } rlm@1: else rlm@1: { rlm@1: // advance forward 1 step in the search rlm@1: theApp.frameSearchLength++; rlm@1: rlm@1: // try it rlm@1: theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE); rlm@1: } rlm@1: rlm@1: char str [32]; rlm@1: sprintf(str, "%d frame search", theApp.frameSearchLength); rlm@1: systemScreenMessage(str, 0); rlm@1: rlm@1: theApp.frameSearchSkipping = true; rlm@1: rlm@1: // make sure the display updates at least 1 frame to show the new message rlm@1: theApp.frameSearchFirstStep = true; rlm@1: rlm@1: if (theApp.paused) rlm@1: theApp.paused = false; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateDebugFramesearch(CCmdUI *pCmdUI) rlm@1: { rlm@1: extern SMovie Movie; rlm@1: pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY); rlm@1: pCmdUI->SetCheck(theApp.frameSearching); rlm@1: } rlm@1: rlm@1: void MainWnd::OnDebugFramesearchPrev() rlm@1: { rlm@1: if (theApp.frameSearching) rlm@1: { rlm@1: if (theApp.frameSearchLength > 0) rlm@1: { rlm@1: // rewind 1 step in the search rlm@1: theApp.frameSearchLength--; rlm@1: } rlm@1: rlm@1: // try it rlm@1: theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); rlm@1: rlm@1: char str[32]; rlm@1: sprintf(str, "%d frame search", theApp.frameSearchLength); rlm@1: systemScreenMessage(str, 0); rlm@1: rlm@1: theApp.frameSearchSkipping = true; rlm@1: rlm@1: // make sure the display updates at least 1 frame to show the new message rlm@1: theApp.frameSearchFirstStep = true; rlm@1: rlm@1: if (theApp.paused) rlm@1: theApp.paused = false; rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateDebugFramesearchPrev(CCmdUI *pCmdUI) rlm@1: { rlm@1: extern SMovie Movie; rlm@1: pCmdUI->Enable(emulating && theApp.frameSearching && Movie.state != MOVIE_STATE_PLAY); rlm@1: } rlm@1: rlm@1: void MainWnd::OnDebugFramesearchLoad() rlm@1: { rlm@1: if (theApp.frameSearchLoadValid) rlm@1: { rlm@1: theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE); rlm@1: theApp.paused = true; rlm@1: rlm@1: if (theApp.frameSearching) rlm@1: systemScreenMessage("end frame search", 0); rlm@1: else rlm@1: systemScreenMessage("restore search end", 0); rlm@1: } rlm@1: theApp.frameSearching = false; rlm@1: theApp.frameSearchSkipping = false; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateDebugFramesearchLoad(CCmdUI *pCmdUI) rlm@1: { rlm@1: extern SMovie Movie; rlm@1: pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsFrameCounter() rlm@1: { rlm@1: theApp.frameCounter = !theApp.frameCounter; rlm@1: extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsFrameCounter(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.frameCounter); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsLagCounter() rlm@1: { rlm@1: theApp.lagCounter = !theApp.lagCounter; rlm@1: extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsLagCounter(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.lagCounter); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsExtraCounter() rlm@1: { rlm@1: theApp.extraCounter = !theApp.extraCounter; rlm@1: extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsExtraCounter(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.extraCounter); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsExtraCounterReset() rlm@1: { rlm@1: systemCounters.extraCount = systemCounters.frameCount; rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsInputDisplay() rlm@1: { rlm@1: theApp.inputDisplay = !theApp.inputDisplay; rlm@1: systemScreenMessage(theApp.inputDisplay ? "Input Display On" : "Input Display Off"); rlm@1: extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsInputDisplay(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.inputDisplay); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsDebugGdb() rlm@1: { rlm@1: theApp.winCheckFullscreen(); rlm@1: GDBPortDlg dlg; rlm@1: rlm@1: if (dlg.DoModal()) rlm@1: { rlm@1: GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); rlm@1: if (wait.DoModal()) rlm@1: { rlm@1: remoteSetSockets(wait.getListenSocket(), wait.getSocket()); rlm@1: debugger = true; rlm@1: emulating = 1; rlm@1: systemCartridgeType = 0; rlm@1: theApp.gameFilename = "\\gnu_stub"; rlm@1: rom = (u8 *)malloc(0x2000000 + 4); rlm@1: workRAM = (u8 *)calloc(1, 0x40000 + 4); rlm@1: bios = (u8 *)calloc(1, 0x4000 + 4); rlm@1: internalRAM = (u8 *)calloc(1, 0x8000 + 4); rlm@1: paletteRAM = (u8 *)calloc(1, 0x400 + 4); rlm@1: vram = (u8 *)calloc(1, 0x20000 + 4); rlm@1: oam = (u8 *)calloc(1, 0x400 + 4); rlm@1: pix = (u8 *)calloc(1, 4 * 240 * 160); rlm@1: ioMem = (u8 *)calloc(1, 0x400 + 4); rlm@1: rlm@1: theApp.emulator = GBASystem; rlm@1: rlm@1: CPUInit(); rlm@1: CPULoadBios(theApp.biosFileName, theApp.useBiosFile ? true : false); rlm@1: CPUReset(); rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsDebugGdb(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsDebugLoadandwait() rlm@1: { rlm@1: theApp.winCheckFullscreen(); rlm@1: if (winFileOpenSelect(0)) rlm@1: { rlm@1: if (winFileRun()) rlm@1: { rlm@1: if (systemCartridgeType != 0) rlm@1: { rlm@1: systemMessage(IDS_ERROR_NOT_GBA_IMAGE, "Error: not a GBA image"); rlm@1: OnFileClose(); rlm@1: return; rlm@1: } rlm@1: GDBPortDlg dlg; rlm@1: rlm@1: if (dlg.DoModal()) rlm@1: { rlm@1: GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort()); rlm@1: if (wait.DoModal()) rlm@1: { rlm@1: remoteSetSockets(wait.getListenSocket(), wait.getSocket()); rlm@1: debugger = true; rlm@1: emulating = 1; rlm@1: } rlm@1: } rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsDebugLoadandwait(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsDebugBreak() rlm@1: { rlm@1: if (armState) rlm@1: { rlm@1: armNextPC -= 4; rlm@1: reg[15].I -= 4; rlm@1: } rlm@1: else rlm@1: { rlm@1: armNextPC -= 2; rlm@1: reg[15].I -= 2; rlm@1: } rlm@1: debugger = true; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsDebugBreak(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsDebugDisconnect() rlm@1: { rlm@1: remoteCleanUp(); rlm@1: debugger = false; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsDebugDisconnect(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsSoundRecording() rlm@1: { rlm@1: if (!theApp.soundRecording) rlm@1: OnToolsSoundStartrecording(); rlm@1: else rlm@1: OnToolsSoundStoprecording(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsSoundStartrecording() rlm@1: { rlm@1: theApp.winCheckFullscreen(); rlm@1: rlm@1: CString wavName = theApp.gameFilename; rlm@1: rlm@1: if (VBAMovieActive()) rlm@1: { rlm@1: extern SMovie Movie; rlm@1: wavName = Movie.filename; rlm@1: int index = wavName.ReverseFind('.'); rlm@1: if (index != -1) rlm@1: wavName = wavName.Left(index); rlm@1: } rlm@1: rlm@1: LPCTSTR exts[] = { ".wav", NULL }; rlm@1: rlm@1: CString filter = winResLoadFilter(IDS_FILTER_WAV); rlm@1: CString title = winResLoadString(IDS_SELECT_WAV_NAME); rlm@1: rlm@1: wavName = winGetDestFilename(wavName, IDS_WAV_DIR, exts[0]); rlm@1: CString wavDir = winGetDestDir(IDS_WAV_DIR); rlm@1: rlm@1: FileDlg dlg(this, wavName, filter, 1, "WAV", exts, wavDir, title, true); rlm@1: rlm@1: if (dlg.DoModal() == IDCANCEL) rlm@1: { rlm@1: return; rlm@1: } rlm@1: rlm@1: theApp.soundRecordName = dlg.GetPathName(); rlm@1: theApp.soundRecording = true; rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsSoundStoprecording() rlm@1: { rlm@1: if (theApp.soundRecorder) rlm@1: { rlm@1: delete theApp.soundRecorder; rlm@1: theApp.soundRecorder = NULL; rlm@1: } rlm@1: theApp.soundRecording = false; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsSoundRecording(CCmdUI *pCmdUI) rlm@1: { rlm@1: if (pCmdUI->m_pMenu != NULL) rlm@1: { rlm@1: if (!theApp.soundRecording) rlm@1: pCmdUI->SetText(winResLoadString(IDS_STARTSOUNDRECORDING)); rlm@1: else rlm@1: pCmdUI->SetText(winResLoadString(IDS_STOPSOUNDRECORDING)); rlm@1: rlm@1: theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); rlm@1: } rlm@1: rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsAVIRecording() rlm@1: { rlm@1: if (!theApp.aviRecording) rlm@1: OnToolsStartAVIRecording(); rlm@1: else rlm@1: OnToolsStopAVIRecording(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsStartAVIRecording() rlm@1: { rlm@1: theApp.winCheckFullscreen(); rlm@1: rlm@1: CString aviName = theApp.gameFilename; rlm@1: rlm@1: if (VBAMovieActive()) rlm@1: { rlm@1: extern SMovie Movie; rlm@1: aviName = Movie.filename; rlm@1: int index = aviName.ReverseFind('.'); rlm@1: if (index != -1) rlm@1: aviName = aviName.Left(index); rlm@1: } rlm@1: rlm@1: LPCTSTR exts[] = { ".avi", NULL }; rlm@1: rlm@1: CString filter = winResLoadFilter(IDS_FILTER_AVI); rlm@1: CString title = winResLoadString(IDS_SELECT_AVI_NAME); rlm@1: rlm@1: aviName = winGetDestFilename(aviName, IDS_AVI_DIR, exts[0]); rlm@1: CString aviDir = winGetDestDir(IDS_AVI_DIR); rlm@1: rlm@1: FileDlg dlg(this, aviName, filter, 1, "AVI", exts, aviDir, title, true); rlm@1: rlm@1: if (dlg.DoModal() == IDCANCEL) rlm@1: { rlm@1: return; rlm@1: } rlm@1: rlm@1: theApp.aviRecordName = theApp.soundRecordName = dlg.GetPathName(); rlm@1: theApp.aviRecording = true; rlm@1: rlm@1: /// extern long linearFrameCount; linearFrameCount = 0; rlm@1: /// extern long linearSoundByteCount; linearSoundByteCount = 0; rlm@1: rlm@1: if (theApp.aviRecorder == NULL) rlm@1: { rlm@1: int width = 240; rlm@1: int height = 160; rlm@1: switch (systemCartridgeType) rlm@1: { rlm@1: case 0: rlm@1: width = 240; rlm@1: height = 160; rlm@1: break; rlm@1: case 1: rlm@1: if (gbBorderOn) rlm@1: { rlm@1: width = 256; rlm@1: height = 224; rlm@1: } rlm@1: else rlm@1: { rlm@1: width = 160; rlm@1: height = 144; rlm@1: } rlm@1: break; rlm@1: } rlm@1: rlm@1: theApp.aviRecorder = new AVIWrite(); rlm@1: rlm@1: theApp.aviRecorder->SetFPS(60); rlm@1: rlm@1: BITMAPINFOHEADER bi; rlm@1: memset(&bi, 0, sizeof(bi)); rlm@1: bi.biSize = 0x28; rlm@1: bi.biPlanes = 1; rlm@1: bi.biBitCount = 24; rlm@1: bi.biWidth = width; rlm@1: bi.biHeight = height; rlm@1: bi.biSizeImage = 3 * width * height; rlm@1: theApp.aviRecorder->SetVideoFormat(&bi); rlm@1: if (!theApp.aviRecorder->Open(theApp.aviRecordName)) rlm@1: { rlm@1: delete theApp.aviRecorder; rlm@1: theApp.aviRecorder = NULL; rlm@1: theApp.aviRecording = false; rlm@1: } rlm@1: rlm@1: if (theApp.aviRecorder) rlm@1: { rlm@1: WAVEFORMATEX wfx; rlm@1: memset(&wfx, 0, sizeof(wfx)); rlm@1: wfx.wFormatTag = WAVE_FORMAT_PCM; rlm@1: wfx.nChannels = 2; rlm@1: wfx.nSamplesPerSec = 44100 / soundQuality; rlm@1: wfx.wBitsPerSample = 16; rlm@1: wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels; rlm@1: wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; rlm@1: wfx.cbSize = 0; rlm@1: theApp.aviRecorder->SetSoundFormat(&wfx); rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsPauseAVIRecording() rlm@1: { rlm@1: theApp.aviRecorder->Pause(!theApp.aviRecorder->IsPaused()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsStopAVIRecording() rlm@1: { rlm@1: if (theApp.aviRecorder != NULL) rlm@1: { rlm@1: delete theApp.aviRecorder; rlm@1: theApp.aviRecorder = NULL; rlm@1: } rlm@1: theApp.aviRecording = false; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsAVIRecording(CCmdUI *pCmdUI) rlm@1: { rlm@1: if (pCmdUI->m_pMenu != NULL) rlm@1: { rlm@1: if (!theApp.aviRecording) rlm@1: pCmdUI->SetText(winResLoadString(IDS_STARTAVIRECORDING)); rlm@1: else rlm@1: pCmdUI->SetText(winResLoadString(IDS_STOPAVIRECORDING)); rlm@1: rlm@1: theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); rlm@1: } rlm@1: rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsPauseAVIRecording(CCmdUI *pCmdUI) rlm@1: { rlm@1: if (pCmdUI->m_pMenu != NULL) rlm@1: { rlm@1: if (!theApp.aviRecording) rlm@1: { rlm@1: pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING)); rlm@1: theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); rlm@1: pCmdUI->Enable(false); rlm@1: } rlm@1: else rlm@1: { rlm@1: if (!theApp.aviRecorder->IsPaused()) rlm@1: pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING)); rlm@1: else rlm@1: pCmdUI->SetText(winResLoadString(IDS_RESUMEAVIRECORDING)); rlm@1: rlm@1: theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu()); rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsRecordMovie() rlm@1: { rlm@1: MovieCreate dlg; rlm@1: dlg.DoModal(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsRecordMovie(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsStopMovie() rlm@1: { rlm@1: VBAMovieStop(false); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsStopMovie(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(emulating && VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsPlayMovie() rlm@1: { rlm@1: MovieOpen dlg; rlm@1: dlg.DoModal(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsPlayMovie(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(emulating); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsPlayReadOnly() rlm@1: { rlm@1: if (!VBAMovieActive()) rlm@1: { rlm@1: theApp.movieReadOnly = !theApp.movieReadOnly; rlm@1: systemScreenMessage(theApp.movieReadOnly ? "Movie now read-only" : "Movie now editable"); rlm@1: } rlm@1: else rlm@1: VBAMovieToggleReadOnly(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsPlayReadOnly(CCmdUI *pCmdUI) rlm@1: { rlm@1: /// pCmdUI->Enable(VBAMovieActive()); // FIXME: this is right, but disabling menu items screws up accelerators until you view rlm@1: // the menu! rlm@1: /// pCmdUI->SetCheck(VBAMovieReadOnly()); rlm@1: pCmdUI->Enable(TRUE); // TEMP rlm@1: pCmdUI->SetCheck(VBAMovieActive() ? VBAMovieReadOnly() : theApp.movieReadOnly); rlm@1: } rlm@1: rlm@1: void MainWnd::OnAsscWithSaveState() rlm@1: { rlm@1: theApp.AsscWithSaveState = !theApp.AsscWithSaveState; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateAsscWithSaveState(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(TRUE); // TEMP rlm@1: pCmdUI->SetCheck(theApp.AsscWithSaveState); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsResumeRecord() rlm@1: { rlm@1: // toggle playing/recording rlm@1: if (VBAMovieRecording()) rlm@1: { rlm@1: if (!VBAMovieSwitchToPlaying()) rlm@1: systemScreenMessage("Cannot continue playing"); rlm@1: } rlm@1: else rlm@1: { rlm@1: if (!VBAMovieSwitchToRecording()) rlm@1: systemScreenMessage("Cannot resume recording now"); rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsResumeRecord(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsPlayRestart() rlm@1: { rlm@1: VBAMovieRestart(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsPlayRestart(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOnMovieEndPause() rlm@1: { rlm@1: theApp.movieOnEndPause = !theApp.movieOnEndPause; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOnMovieEndPause(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetCheck(theApp.movieOnEndPause); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOnMovieEndStop() rlm@1: { rlm@1: theApp.movieOnEndBehavior = 0; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOnMovieEndStop(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetRadio(theApp.movieOnEndBehavior == 0); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOnMovieEndRestart() rlm@1: { rlm@1: theApp.movieOnEndBehavior = 1; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOnMovieEndRestart(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetRadio(theApp.movieOnEndBehavior == 1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOnMovieEndAppend() rlm@1: { rlm@1: theApp.movieOnEndBehavior = 2; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOnMovieEndAppend(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetRadio(theApp.movieOnEndBehavior == 2); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsOnMovieEndKeep() rlm@1: { rlm@1: theApp.movieOnEndBehavior = 3; rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsOnMovieEndKeep(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->SetRadio(theApp.movieOnEndBehavior == 3); rlm@1: } rlm@1: rlm@1: ///////////////////////////////// rlm@1: rlm@1: void MainWnd::OnToolsMovieSetPauseAt() rlm@1: { rlm@1: // TODO rlm@1: VBAMovieSetPauseAt(-1); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsSetMoviePauseAt(CCmdUI *pCmdUI) rlm@1: { rlm@1: // TODO rlm@1: pCmdUI->SetCheck(VBAMovieGetPauseAt() >= 0); rlm@1: pCmdUI->Enable(FALSE && VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMovieConvertCurrent() rlm@1: { rlm@1: // temporary rlm@1: int result = VBAMovieConvertCurrent(); rlm@1: switch (result) rlm@1: { rlm@1: case MOVIE_SUCCESS: rlm@1: systemScreenMessage("Movie converted"); rlm@1: break; rlm@1: case MOVIE_WRONG_VERSION: rlm@1: systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion()); rlm@1: break; rlm@1: default: rlm@1: systemScreenMessage("Nothing to convert"); rlm@1: break; rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMovieConvertCurrent(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMovieAutoConvert() rlm@1: { rlm@1: extern bool autoConvertMovieWhenPlaying; // from movie.cpp rlm@1: autoConvertMovieWhenPlaying = !autoConvertMovieWhenPlaying; rlm@1: if (autoConvertMovieWhenPlaying) rlm@1: { rlm@1: int result = VBAMovieConvertCurrent(); rlm@1: switch (result) rlm@1: { rlm@1: case MOVIE_SUCCESS: rlm@1: systemScreenMessage("Movie converted"); rlm@1: break; rlm@1: case MOVIE_WRONG_VERSION: rlm@1: systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion()); rlm@1: break; rlm@1: default: rlm@1: systemScreenMessage("Auto movie conversion enabled"); rlm@1: break; rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMovieAutoConvert(CCmdUI *pCmdUI) rlm@1: { rlm@1: extern bool autoConvertMovieWhenPlaying; // from movie.cpp rlm@1: pCmdUI->SetCheck(autoConvertMovieWhenPlaying); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMovieTruncateAtCurrent() rlm@1: { rlm@1: if (VBAMovieReadOnly()) rlm@1: systemScreenMessage("Cannot truncate movie in this mode"); rlm@1: else rlm@1: VBAMovieTuncateAtCurrentFrame(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMovieTruncateAtCurrent(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(VBAMovieActive()); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsMovieFixHeader() rlm@1: { rlm@1: VBAMovieFixHeader(); rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMovieFixHeader(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(VBAMovieActive()); rlm@1: } rlm@1: rlm@1: // TODO rlm@1: void MainWnd::OnToolsMovieExtractFromSavegame() rlm@1: { rlm@1: // Currently, snapshots taken from a movie don't contain the initial SRAM or savestate of the movie, rlm@1: // even if the movie was recorded from either of them. If a snapshot was taken at the first frame rlm@1: // i.e. Frame 0, it can be safely assumed that the snapshot reflects the initial state of such a movie. rlm@1: // However, if it was taken after the first frame, the SRAM contained might either be still the same rlm@1: // as the original (usually true if no write operations on the SRAM occured) or have been modified, rlm@1: // while the exact original state could hardly, if not impossibly, be safely worked out. rlm@1: rlm@1: // TODO rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsMovieExtractFromSavegame(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(FALSE); rlm@1: } rlm@1: rlm@1: /////////////////////////////////////////////////////////// rlm@1: rlm@1: void MainWnd::OnToolsRewind() rlm@1: { rlm@1: assert(theApp.rewindTimer > 0 && theApp.rewindSlots > 0); rlm@1: if (emulating && theApp.emulator.emuReadMemState && theApp.rewindMemory && theApp.rewindCount) rlm@1: { rlm@1: assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots); rlm@1: theApp.rewindPos = (--theApp.rewindPos + theApp.rewindSlots) % theApp.rewindSlots; rlm@1: assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots); rlm@1: theApp.emulator.emuReadMemState(&theApp.rewindMemory[REWIND_SIZE * theApp.rewindPos], REWIND_SIZE); rlm@1: theApp.rewindCount--; rlm@1: if (theApp.rewindCount > 0) rlm@1: theApp.rewindCounter = 0; rlm@1: else rlm@1: { rlm@1: theApp.rewindCounter = theApp.rewindTimer; rlm@1: theApp.rewindSaveNeeded = true; rlm@1: rlm@1: // immediately save state to avoid eroding away the earliest you can rewind to rlm@1: theApp.saveRewindStateIfNecessary(); rlm@1: rlm@1: theApp.rewindSaveNeeded = false; rlm@1: } rlm@1: } rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsRewind(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.rewindMemory != NULL && emulating && theApp.rewindCount); rlm@1: } rlm@1: rlm@1: void MainWnd::OnToolsCustomize() rlm@1: { rlm@1: theApp.recreateMenuBar(); rlm@1: rlm@1: AccelEditor dlg(this, &theApp.m_menu, &theApp.winAccelMgr); rlm@1: dlg.DoModal(); rlm@1: if (dlg.IsModified()) rlm@1: { rlm@1: theApp.winAccelMgr = dlg.GetResultMangager(); rlm@1: theApp.winAccelMgr.UpdateWndTable(); rlm@1: theApp.winAccelMgr.Write(); rlm@1: } rlm@1: rlm@1: theApp.winAccelMgr.UpdateMenu(theApp.menu); // we should always do this since the menu has been reloaded rlm@1: } rlm@1: rlm@1: void MainWnd::OnUpdateToolsCustomize(CCmdUI *pCmdUI) rlm@1: { rlm@1: pCmdUI->Enable(theApp.videoOption != VIDEO_320x240); rlm@1: } rlm@1: