annotate src/win32/MainWndTools.cpp @ 2:3549bbe597ed

adding makefile.am
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:47 -0600
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include "stdafx.h"
rlm@1 2 #include <cassert>
rlm@1 3 #include "resource.h"
rlm@1 4 #include "MainWnd.h"
rlm@1 5 #include "AccelEditor.h"
rlm@1 6 #include "AVIWrite.h"
rlm@1 7 #include "Disassemble.h"
rlm@1 8 #include "FileDlg.h"
rlm@1 9 #include "GBDisassemble.h"
rlm@1 10 #include "GBMapView.h"
rlm@1 11 #include "GBMemoryViewerDlg.h"
rlm@1 12 #include "GBOamView.h"
rlm@1 13 #include "GBPaletteView.h"
rlm@1 14 #include "GBTileView.h"
rlm@1 15 #include "GDBConnection.h"
rlm@1 16 #include "IOViewer.h"
rlm@1 17 #include "MapView.h"
rlm@1 18 #include "MemoryViewerDlg.h"
rlm@1 19 #include "MovieOpen.h"
rlm@1 20 #include "MovieCreate.h"
rlm@1 21 #include "OamView.h"
rlm@1 22 #include "PaletteView.h"
rlm@1 23 #include "Reg.h"
rlm@1 24 #include "TileView.h"
rlm@1 25 #include "WavWriter.h"
rlm@1 26 #include "WinResUtil.h"
rlm@1 27 #include "WinMiscUtil.h"
rlm@1 28 #include "VBA.h"
rlm@1 29
rlm@1 30 #include "../gba/GBA.h"
rlm@1 31 #include "../gba/GBAGlobals.h"
rlm@1 32 #include "../gb/GB.h"
rlm@1 33
rlm@1 34 extern int32 gbBorderOn;
rlm@1 35 extern int32 soundQuality;
rlm@1 36
rlm@1 37 extern bool debugger;
rlm@1 38 extern int emulating;
rlm@1 39 extern int remoteSocket;
rlm@1 40
rlm@1 41 extern void remoteCleanUp();
rlm@1 42 extern void remoteSetSockets(SOCKET, SOCKET);
rlm@1 43 extern void toolsLogging();
rlm@1 44
rlm@1 45 void MainWnd::OnToolsDisassemble()
rlm@1 46 {
rlm@1 47 if (systemCartridgeType == 0)
rlm@1 48 {
rlm@1 49 Disassemble *dlg = new Disassemble();
rlm@1 50 dlg->Create(IDD_DISASSEMBLE, this);
rlm@1 51 dlg->ShowWindow(SW_SHOW);
rlm@1 52 }
rlm@1 53 else
rlm@1 54 {
rlm@1 55 GBDisassemble *dlg = new GBDisassemble();
rlm@1 56 dlg->Create(IDD_GB_DISASSEMBLE, this);
rlm@1 57 dlg->ShowWindow(SW_SHOW);
rlm@1 58 }
rlm@1 59 }
rlm@1 60
rlm@1 61 void MainWnd::OnUpdateToolsDisassemble(CCmdUI *pCmdUI)
rlm@1 62 {
rlm@1 63 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 64 }
rlm@1 65
rlm@1 66 void MainWnd::OnToolsLogging()
rlm@1 67 {
rlm@1 68 toolsLogging();
rlm@1 69 }
rlm@1 70
rlm@1 71 void MainWnd::OnUpdateToolsLogging(CCmdUI *pCmdUI)
rlm@1 72 {
rlm@1 73 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 74 }
rlm@1 75
rlm@1 76 void MainWnd::OnToolsIoviewer()
rlm@1 77 {
rlm@1 78 IOViewer *dlg = new IOViewer;
rlm@1 79 dlg->Create(IDD_IO_VIEWER, this);
rlm@1 80 dlg->ShowWindow(SW_SHOW);
rlm@1 81 }
rlm@1 82
rlm@1 83 void MainWnd::OnUpdateToolsIoviewer(CCmdUI *pCmdUI)
rlm@1 84 {
rlm@1 85 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && systemCartridgeType == 0);
rlm@1 86 }
rlm@1 87
rlm@1 88 void MainWnd::OnToolsMapview()
rlm@1 89 {
rlm@1 90 if (systemCartridgeType == 0)
rlm@1 91 {
rlm@1 92 MapView *dlg = new MapView;
rlm@1 93 dlg->Create(IDD_MAP_VIEW, this);
rlm@1 94 dlg->ShowWindow(SW_SHOW);
rlm@1 95 }
rlm@1 96 else
rlm@1 97 {
rlm@1 98 GBMapView *dlg = new GBMapView;
rlm@1 99 dlg->Create(IDD_GB_MAP_VIEW, this);
rlm@1 100 dlg->ShowWindow(SW_SHOW);
rlm@1 101 }
rlm@1 102 }
rlm@1 103
rlm@1 104 void MainWnd::OnUpdateToolsMapview(CCmdUI *pCmdUI)
rlm@1 105 {
rlm@1 106 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 107 }
rlm@1 108
rlm@1 109 void MainWnd::OnToolsMemoryviewer()
rlm@1 110 {
rlm@1 111 if (systemCartridgeType == 0)
rlm@1 112 {
rlm@1 113 MemoryViewerDlg *dlg = new MemoryViewerDlg;
rlm@1 114 dlg->Create(IDD_MEM_VIEWER, this);
rlm@1 115 dlg->ShowWindow(SW_SHOW);
rlm@1 116 }
rlm@1 117 else
rlm@1 118 {
rlm@1 119 GBMemoryViewerDlg *dlg = new GBMemoryViewerDlg;
rlm@1 120 dlg->Create(IDD_MEM_VIEWER, this);
rlm@1 121 dlg->ShowWindow(SW_SHOW);
rlm@1 122 }
rlm@1 123 }
rlm@1 124
rlm@1 125 void MainWnd::OnUpdateToolsMemoryviewer(CCmdUI *pCmdUI)
rlm@1 126 {
rlm@1 127 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 128 }
rlm@1 129
rlm@1 130 void MainWnd::OnToolsOamviewer()
rlm@1 131 {
rlm@1 132 if (systemCartridgeType == 0)
rlm@1 133 {
rlm@1 134 OamView *dlg = new OamView;
rlm@1 135 dlg->Create(IDD_OAM_VIEW, this);
rlm@1 136 dlg->ShowWindow(SW_SHOW);
rlm@1 137 }
rlm@1 138 else
rlm@1 139 {
rlm@1 140 GBOamView *dlg = new GBOamView;
rlm@1 141 dlg->Create(IDD_GB_OAM_VIEW, this);
rlm@1 142 dlg->ShowWindow(SW_SHOW);
rlm@1 143 }
rlm@1 144 }
rlm@1 145
rlm@1 146 void MainWnd::OnUpdateToolsOamviewer(CCmdUI *pCmdUI)
rlm@1 147 {
rlm@1 148 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 149 }
rlm@1 150
rlm@1 151 void MainWnd::OnToolsPaletteview()
rlm@1 152 {
rlm@1 153 if (systemCartridgeType == 0)
rlm@1 154 {
rlm@1 155 PaletteView *dlg = new PaletteView;
rlm@1 156 dlg->Create(IDD_PALETTE_VIEW, this);
rlm@1 157 dlg->ShowWindow(SW_SHOW);
rlm@1 158 }
rlm@1 159 else
rlm@1 160 {
rlm@1 161 GBPaletteView *dlg = new GBPaletteView;
rlm@1 162 dlg->Create(IDD_GB_PALETTE_VIEW, this);
rlm@1 163 dlg->ShowWindow(SW_SHOW);
rlm@1 164 }
rlm@1 165 }
rlm@1 166
rlm@1 167 void MainWnd::OnUpdateToolsPaletteview(CCmdUI *pCmdUI)
rlm@1 168 {
rlm@1 169 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 170 }
rlm@1 171
rlm@1 172 void MainWnd::OnToolsTileviewer()
rlm@1 173 {
rlm@1 174 if (systemCartridgeType == 0)
rlm@1 175 {
rlm@1 176 TileView *dlg = new TileView;
rlm@1 177 dlg->Create(IDD_TILE_VIEWER, this);
rlm@1 178 dlg->ShowWindow(SW_SHOW);
rlm@1 179 }
rlm@1 180 else
rlm@1 181 {
rlm@1 182 GBTileView *dlg = new GBTileView;
rlm@1 183 dlg->Create(IDD_GB_TILE_VIEWER, this);
rlm@1 184 dlg->ShowWindow(SW_SHOW);
rlm@1 185 }
rlm@1 186 }
rlm@1 187
rlm@1 188 void MainWnd::OnUpdateToolsTileviewer(CCmdUI *pCmdUI)
rlm@1 189 {
rlm@1 190 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X);
rlm@1 191 }
rlm@1 192
rlm@1 193 void MainWnd::OnDebugNextframe()
rlm@1 194 {
rlm@1 195 systemSetPause(false);
rlm@1 196 theApp.winPauseNextFrame = true;
rlm@1 197 }
rlm@1 198
rlm@1 199 void MainWnd::OnUpdateDebugNextframe(CCmdUI *pCmdUI)
rlm@1 200 {
rlm@1 201 pCmdUI->Enable(emulating);
rlm@1 202 }
rlm@1 203
rlm@1 204 void MainWnd::OnDebugNextframeAccountForLag()
rlm@1 205 {
rlm@1 206 theApp.nextframeAccountForLag = !theApp.nextframeAccountForLag;
rlm@1 207 }
rlm@1 208
rlm@1 209 void MainWnd::OnUpdateDebugNextframeAccountForLag(CCmdUI *pCmdUI)
rlm@1 210 {
rlm@1 211 pCmdUI->SetCheck(theApp.nextframeAccountForLag);
rlm@1 212 }
rlm@1 213
rlm@1 214 void MainWnd::OnDebugFramesearch()
rlm@1 215 {
rlm@1 216 extern u16 currentButtons [4]; // from System.cpp
rlm@1 217 extern SMovie Movie;
rlm@1 218 if (!theApp.frameSearching)
rlm@1 219 {
rlm@1 220 // starting a new search
rlm@1 221 theApp.frameSearching = true;
rlm@1 222 theApp.frameSearchStart = (Movie.state == MOVIE_STATE_NONE) ? systemCounters.frameCount : Movie.currentFrame;
rlm@1 223 theApp.frameSearchLength = 0;
rlm@1 224 theApp.frameSearchLoadValid = false;
rlm@1 225 theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE); // 0 is start state, 1 is
rlm@1 226 // intermediate state (for
rlm@1 227 // speedup when going
rlm@1 228 // forward),
rlm@1 229 // 2 is end state
rlm@1 230 theApp.emulator.emuWriteMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
rlm@1 231
rlm@1 232 // store old buttons from frame before the search
rlm@1 233 for (int i = 0; i < 4; i++)
rlm@1 234 theApp.frameSearchOldInput[i] = currentButtons[i];
rlm@1 235 }
rlm@1 236 else
rlm@1 237 {
rlm@1 238 // advance forward 1 step in the search
rlm@1 239 theApp.frameSearchLength++;
rlm@1 240
rlm@1 241 // try it
rlm@1 242 theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 1], REWIND_SIZE);
rlm@1 243 }
rlm@1 244
rlm@1 245 char str [32];
rlm@1 246 sprintf(str, "%d frame search", theApp.frameSearchLength);
rlm@1 247 systemScreenMessage(str, 0);
rlm@1 248
rlm@1 249 theApp.frameSearchSkipping = true;
rlm@1 250
rlm@1 251 // make sure the display updates at least 1 frame to show the new message
rlm@1 252 theApp.frameSearchFirstStep = true;
rlm@1 253
rlm@1 254 if (theApp.paused)
rlm@1 255 theApp.paused = false;
rlm@1 256 }
rlm@1 257
rlm@1 258 void MainWnd::OnUpdateDebugFramesearch(CCmdUI *pCmdUI)
rlm@1 259 {
rlm@1 260 extern SMovie Movie;
rlm@1 261 pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY);
rlm@1 262 pCmdUI->SetCheck(theApp.frameSearching);
rlm@1 263 }
rlm@1 264
rlm@1 265 void MainWnd::OnDebugFramesearchPrev()
rlm@1 266 {
rlm@1 267 if (theApp.frameSearching)
rlm@1 268 {
rlm@1 269 if (theApp.frameSearchLength > 0)
rlm@1 270 {
rlm@1 271 // rewind 1 step in the search
rlm@1 272 theApp.frameSearchLength--;
rlm@1 273 }
rlm@1 274
rlm@1 275 // try it
rlm@1 276 theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 0], REWIND_SIZE);
rlm@1 277
rlm@1 278 char str[32];
rlm@1 279 sprintf(str, "%d frame search", theApp.frameSearchLength);
rlm@1 280 systemScreenMessage(str, 0);
rlm@1 281
rlm@1 282 theApp.frameSearchSkipping = true;
rlm@1 283
rlm@1 284 // make sure the display updates at least 1 frame to show the new message
rlm@1 285 theApp.frameSearchFirstStep = true;
rlm@1 286
rlm@1 287 if (theApp.paused)
rlm@1 288 theApp.paused = false;
rlm@1 289 }
rlm@1 290 }
rlm@1 291
rlm@1 292 void MainWnd::OnUpdateDebugFramesearchPrev(CCmdUI *pCmdUI)
rlm@1 293 {
rlm@1 294 extern SMovie Movie;
rlm@1 295 pCmdUI->Enable(emulating && theApp.frameSearching && Movie.state != MOVIE_STATE_PLAY);
rlm@1 296 }
rlm@1 297
rlm@1 298 void MainWnd::OnDebugFramesearchLoad()
rlm@1 299 {
rlm@1 300 if (theApp.frameSearchLoadValid)
rlm@1 301 {
rlm@1 302 theApp.emulator.emuReadMemState(&theApp.frameSearchMemory[REWIND_SIZE * 2], REWIND_SIZE);
rlm@1 303 theApp.paused = true;
rlm@1 304
rlm@1 305 if (theApp.frameSearching)
rlm@1 306 systemScreenMessage("end frame search", 0);
rlm@1 307 else
rlm@1 308 systemScreenMessage("restore search end", 0);
rlm@1 309 }
rlm@1 310 theApp.frameSearching = false;
rlm@1 311 theApp.frameSearchSkipping = false;
rlm@1 312 }
rlm@1 313
rlm@1 314 void MainWnd::OnUpdateDebugFramesearchLoad(CCmdUI *pCmdUI)
rlm@1 315 {
rlm@1 316 extern SMovie Movie;
rlm@1 317 pCmdUI->Enable(emulating && Movie.state != MOVIE_STATE_PLAY);
rlm@1 318 }
rlm@1 319
rlm@1 320 void MainWnd::OnToolsFrameCounter()
rlm@1 321 {
rlm@1 322 theApp.frameCounter = !theApp.frameCounter;
rlm@1 323 extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
rlm@1 324 }
rlm@1 325
rlm@1 326 void MainWnd::OnUpdateToolsFrameCounter(CCmdUI *pCmdUI)
rlm@1 327 {
rlm@1 328 pCmdUI->SetCheck(theApp.frameCounter);
rlm@1 329 }
rlm@1 330
rlm@1 331 void MainWnd::OnToolsLagCounter()
rlm@1 332 {
rlm@1 333 theApp.lagCounter = !theApp.lagCounter;
rlm@1 334 extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
rlm@1 335 }
rlm@1 336
rlm@1 337 void MainWnd::OnUpdateToolsLagCounter(CCmdUI *pCmdUI)
rlm@1 338 {
rlm@1 339 pCmdUI->SetCheck(theApp.lagCounter);
rlm@1 340 }
rlm@1 341
rlm@1 342 void MainWnd::OnToolsExtraCounter()
rlm@1 343 {
rlm@1 344 theApp.extraCounter = !theApp.extraCounter;
rlm@1 345 extern void VBAUpdateFrameCountDisplay(); VBAUpdateFrameCountDisplay();
rlm@1 346 }
rlm@1 347
rlm@1 348 void MainWnd::OnUpdateToolsExtraCounter(CCmdUI *pCmdUI)
rlm@1 349 {
rlm@1 350 pCmdUI->SetCheck(theApp.extraCounter);
rlm@1 351 }
rlm@1 352
rlm@1 353 void MainWnd::OnToolsExtraCounterReset()
rlm@1 354 {
rlm@1 355 systemCounters.extraCount = systemCounters.frameCount;
rlm@1 356 }
rlm@1 357
rlm@1 358 void MainWnd::OnToolsInputDisplay()
rlm@1 359 {
rlm@1 360 theApp.inputDisplay = !theApp.inputDisplay;
rlm@1 361 systemScreenMessage(theApp.inputDisplay ? "Input Display On" : "Input Display Off");
rlm@1 362 extern void VBAUpdateButtonPressDisplay(); VBAUpdateButtonPressDisplay();
rlm@1 363 }
rlm@1 364
rlm@1 365 void MainWnd::OnUpdateToolsInputDisplay(CCmdUI *pCmdUI)
rlm@1 366 {
rlm@1 367 pCmdUI->SetCheck(theApp.inputDisplay);
rlm@1 368 }
rlm@1 369
rlm@1 370 void MainWnd::OnToolsDebugGdb()
rlm@1 371 {
rlm@1 372 theApp.winCheckFullscreen();
rlm@1 373 GDBPortDlg dlg;
rlm@1 374
rlm@1 375 if (dlg.DoModal())
rlm@1 376 {
rlm@1 377 GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort());
rlm@1 378 if (wait.DoModal())
rlm@1 379 {
rlm@1 380 remoteSetSockets(wait.getListenSocket(), wait.getSocket());
rlm@1 381 debugger = true;
rlm@1 382 emulating = 1;
rlm@1 383 systemCartridgeType = 0;
rlm@1 384 theApp.gameFilename = "\\gnu_stub";
rlm@1 385 rom = (u8 *)malloc(0x2000000 + 4);
rlm@1 386 workRAM = (u8 *)calloc(1, 0x40000 + 4);
rlm@1 387 bios = (u8 *)calloc(1, 0x4000 + 4);
rlm@1 388 internalRAM = (u8 *)calloc(1, 0x8000 + 4);
rlm@1 389 paletteRAM = (u8 *)calloc(1, 0x400 + 4);
rlm@1 390 vram = (u8 *)calloc(1, 0x20000 + 4);
rlm@1 391 oam = (u8 *)calloc(1, 0x400 + 4);
rlm@1 392 pix = (u8 *)calloc(1, 4 * 240 * 160);
rlm@1 393 ioMem = (u8 *)calloc(1, 0x400 + 4);
rlm@1 394
rlm@1 395 theApp.emulator = GBASystem;
rlm@1 396
rlm@1 397 CPUInit();
rlm@1 398 CPULoadBios(theApp.biosFileName, theApp.useBiosFile ? true : false);
rlm@1 399 CPUReset();
rlm@1 400 }
rlm@1 401 }
rlm@1 402 }
rlm@1 403
rlm@1 404 void MainWnd::OnUpdateToolsDebugGdb(CCmdUI *pCmdUI)
rlm@1 405 {
rlm@1 406 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1);
rlm@1 407 }
rlm@1 408
rlm@1 409 void MainWnd::OnToolsDebugLoadandwait()
rlm@1 410 {
rlm@1 411 theApp.winCheckFullscreen();
rlm@1 412 if (winFileOpenSelect(0))
rlm@1 413 {
rlm@1 414 if (winFileRun())
rlm@1 415 {
rlm@1 416 if (systemCartridgeType != 0)
rlm@1 417 {
rlm@1 418 systemMessage(IDS_ERROR_NOT_GBA_IMAGE, "Error: not a GBA image");
rlm@1 419 OnFileClose();
rlm@1 420 return;
rlm@1 421 }
rlm@1 422 GDBPortDlg dlg;
rlm@1 423
rlm@1 424 if (dlg.DoModal())
rlm@1 425 {
rlm@1 426 GDBWaitingDlg wait(dlg.getSocket(), dlg.getPort());
rlm@1 427 if (wait.DoModal())
rlm@1 428 {
rlm@1 429 remoteSetSockets(wait.getListenSocket(), wait.getSocket());
rlm@1 430 debugger = true;
rlm@1 431 emulating = 1;
rlm@1 432 }
rlm@1 433 }
rlm@1 434 }
rlm@1 435 }
rlm@1 436 }
rlm@1 437
rlm@1 438 void MainWnd::OnUpdateToolsDebugLoadandwait(CCmdUI *pCmdUI)
rlm@1 439 {
rlm@1 440 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket == -1);
rlm@1 441 }
rlm@1 442
rlm@1 443 void MainWnd::OnToolsDebugBreak()
rlm@1 444 {
rlm@1 445 if (armState)
rlm@1 446 {
rlm@1 447 armNextPC -= 4;
rlm@1 448 reg[15].I -= 4;
rlm@1 449 }
rlm@1 450 else
rlm@1 451 {
rlm@1 452 armNextPC -= 2;
rlm@1 453 reg[15].I -= 2;
rlm@1 454 }
rlm@1 455 debugger = true;
rlm@1 456 }
rlm@1 457
rlm@1 458 void MainWnd::OnUpdateToolsDebugBreak(CCmdUI *pCmdUI)
rlm@1 459 {
rlm@1 460 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1);
rlm@1 461 }
rlm@1 462
rlm@1 463 void MainWnd::OnToolsDebugDisconnect()
rlm@1 464 {
rlm@1 465 remoteCleanUp();
rlm@1 466 debugger = false;
rlm@1 467 }
rlm@1 468
rlm@1 469 void MainWnd::OnUpdateToolsDebugDisconnect(CCmdUI *pCmdUI)
rlm@1 470 {
rlm@1 471 pCmdUI->Enable(theApp.videoOption <= VIDEO_4X && remoteSocket != -1);
rlm@1 472 }
rlm@1 473
rlm@1 474 void MainWnd::OnToolsSoundRecording()
rlm@1 475 {
rlm@1 476 if (!theApp.soundRecording)
rlm@1 477 OnToolsSoundStartrecording();
rlm@1 478 else
rlm@1 479 OnToolsSoundStoprecording();
rlm@1 480 }
rlm@1 481
rlm@1 482 void MainWnd::OnToolsSoundStartrecording()
rlm@1 483 {
rlm@1 484 theApp.winCheckFullscreen();
rlm@1 485
rlm@1 486 CString wavName = theApp.gameFilename;
rlm@1 487
rlm@1 488 if (VBAMovieActive())
rlm@1 489 {
rlm@1 490 extern SMovie Movie;
rlm@1 491 wavName = Movie.filename;
rlm@1 492 int index = wavName.ReverseFind('.');
rlm@1 493 if (index != -1)
rlm@1 494 wavName = wavName.Left(index);
rlm@1 495 }
rlm@1 496
rlm@1 497 LPCTSTR exts[] = { ".wav", NULL };
rlm@1 498
rlm@1 499 CString filter = winResLoadFilter(IDS_FILTER_WAV);
rlm@1 500 CString title = winResLoadString(IDS_SELECT_WAV_NAME);
rlm@1 501
rlm@1 502 wavName = winGetDestFilename(wavName, IDS_WAV_DIR, exts[0]);
rlm@1 503 CString wavDir = winGetDestDir(IDS_WAV_DIR);
rlm@1 504
rlm@1 505 FileDlg dlg(this, wavName, filter, 1, "WAV", exts, wavDir, title, true);
rlm@1 506
rlm@1 507 if (dlg.DoModal() == IDCANCEL)
rlm@1 508 {
rlm@1 509 return;
rlm@1 510 }
rlm@1 511
rlm@1 512 theApp.soundRecordName = dlg.GetPathName();
rlm@1 513 theApp.soundRecording = true;
rlm@1 514 }
rlm@1 515
rlm@1 516 void MainWnd::OnToolsSoundStoprecording()
rlm@1 517 {
rlm@1 518 if (theApp.soundRecorder)
rlm@1 519 {
rlm@1 520 delete theApp.soundRecorder;
rlm@1 521 theApp.soundRecorder = NULL;
rlm@1 522 }
rlm@1 523 theApp.soundRecording = false;
rlm@1 524 }
rlm@1 525
rlm@1 526 void MainWnd::OnUpdateToolsSoundRecording(CCmdUI *pCmdUI)
rlm@1 527 {
rlm@1 528 if (pCmdUI->m_pMenu != NULL)
rlm@1 529 {
rlm@1 530 if (!theApp.soundRecording)
rlm@1 531 pCmdUI->SetText(winResLoadString(IDS_STARTSOUNDRECORDING));
rlm@1 532 else
rlm@1 533 pCmdUI->SetText(winResLoadString(IDS_STOPSOUNDRECORDING));
rlm@1 534
rlm@1 535 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
rlm@1 536 }
rlm@1 537
rlm@1 538 pCmdUI->Enable(emulating);
rlm@1 539 }
rlm@1 540
rlm@1 541 void MainWnd::OnToolsAVIRecording()
rlm@1 542 {
rlm@1 543 if (!theApp.aviRecording)
rlm@1 544 OnToolsStartAVIRecording();
rlm@1 545 else
rlm@1 546 OnToolsStopAVIRecording();
rlm@1 547 }
rlm@1 548
rlm@1 549 void MainWnd::OnToolsStartAVIRecording()
rlm@1 550 {
rlm@1 551 theApp.winCheckFullscreen();
rlm@1 552
rlm@1 553 CString aviName = theApp.gameFilename;
rlm@1 554
rlm@1 555 if (VBAMovieActive())
rlm@1 556 {
rlm@1 557 extern SMovie Movie;
rlm@1 558 aviName = Movie.filename;
rlm@1 559 int index = aviName.ReverseFind('.');
rlm@1 560 if (index != -1)
rlm@1 561 aviName = aviName.Left(index);
rlm@1 562 }
rlm@1 563
rlm@1 564 LPCTSTR exts[] = { ".avi", NULL };
rlm@1 565
rlm@1 566 CString filter = winResLoadFilter(IDS_FILTER_AVI);
rlm@1 567 CString title = winResLoadString(IDS_SELECT_AVI_NAME);
rlm@1 568
rlm@1 569 aviName = winGetDestFilename(aviName, IDS_AVI_DIR, exts[0]);
rlm@1 570 CString aviDir = winGetDestDir(IDS_AVI_DIR);
rlm@1 571
rlm@1 572 FileDlg dlg(this, aviName, filter, 1, "AVI", exts, aviDir, title, true);
rlm@1 573
rlm@1 574 if (dlg.DoModal() == IDCANCEL)
rlm@1 575 {
rlm@1 576 return;
rlm@1 577 }
rlm@1 578
rlm@1 579 theApp.aviRecordName = theApp.soundRecordName = dlg.GetPathName();
rlm@1 580 theApp.aviRecording = true;
rlm@1 581
rlm@1 582 /// extern long linearFrameCount; linearFrameCount = 0;
rlm@1 583 /// extern long linearSoundByteCount; linearSoundByteCount = 0;
rlm@1 584
rlm@1 585 if (theApp.aviRecorder == NULL)
rlm@1 586 {
rlm@1 587 int width = 240;
rlm@1 588 int height = 160;
rlm@1 589 switch (systemCartridgeType)
rlm@1 590 {
rlm@1 591 case 0:
rlm@1 592 width = 240;
rlm@1 593 height = 160;
rlm@1 594 break;
rlm@1 595 case 1:
rlm@1 596 if (gbBorderOn)
rlm@1 597 {
rlm@1 598 width = 256;
rlm@1 599 height = 224;
rlm@1 600 }
rlm@1 601 else
rlm@1 602 {
rlm@1 603 width = 160;
rlm@1 604 height = 144;
rlm@1 605 }
rlm@1 606 break;
rlm@1 607 }
rlm@1 608
rlm@1 609 theApp.aviRecorder = new AVIWrite();
rlm@1 610
rlm@1 611 theApp.aviRecorder->SetFPS(60);
rlm@1 612
rlm@1 613 BITMAPINFOHEADER bi;
rlm@1 614 memset(&bi, 0, sizeof(bi));
rlm@1 615 bi.biSize = 0x28;
rlm@1 616 bi.biPlanes = 1;
rlm@1 617 bi.biBitCount = 24;
rlm@1 618 bi.biWidth = width;
rlm@1 619 bi.biHeight = height;
rlm@1 620 bi.biSizeImage = 3 * width * height;
rlm@1 621 theApp.aviRecorder->SetVideoFormat(&bi);
rlm@1 622 if (!theApp.aviRecorder->Open(theApp.aviRecordName))
rlm@1 623 {
rlm@1 624 delete theApp.aviRecorder;
rlm@1 625 theApp.aviRecorder = NULL;
rlm@1 626 theApp.aviRecording = false;
rlm@1 627 }
rlm@1 628
rlm@1 629 if (theApp.aviRecorder)
rlm@1 630 {
rlm@1 631 WAVEFORMATEX wfx;
rlm@1 632 memset(&wfx, 0, sizeof(wfx));
rlm@1 633 wfx.wFormatTag = WAVE_FORMAT_PCM;
rlm@1 634 wfx.nChannels = 2;
rlm@1 635 wfx.nSamplesPerSec = 44100 / soundQuality;
rlm@1 636 wfx.wBitsPerSample = 16;
rlm@1 637 wfx.nBlockAlign = (wfx.wBitsPerSample / 8) * wfx.nChannels;
rlm@1 638 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
rlm@1 639 wfx.cbSize = 0;
rlm@1 640 theApp.aviRecorder->SetSoundFormat(&wfx);
rlm@1 641 }
rlm@1 642 }
rlm@1 643 }
rlm@1 644
rlm@1 645 void MainWnd::OnToolsPauseAVIRecording()
rlm@1 646 {
rlm@1 647 theApp.aviRecorder->Pause(!theApp.aviRecorder->IsPaused());
rlm@1 648 }
rlm@1 649
rlm@1 650 void MainWnd::OnToolsStopAVIRecording()
rlm@1 651 {
rlm@1 652 if (theApp.aviRecorder != NULL)
rlm@1 653 {
rlm@1 654 delete theApp.aviRecorder;
rlm@1 655 theApp.aviRecorder = NULL;
rlm@1 656 }
rlm@1 657 theApp.aviRecording = false;
rlm@1 658 }
rlm@1 659
rlm@1 660 void MainWnd::OnUpdateToolsAVIRecording(CCmdUI *pCmdUI)
rlm@1 661 {
rlm@1 662 if (pCmdUI->m_pMenu != NULL)
rlm@1 663 {
rlm@1 664 if (!theApp.aviRecording)
rlm@1 665 pCmdUI->SetText(winResLoadString(IDS_STARTAVIRECORDING));
rlm@1 666 else
rlm@1 667 pCmdUI->SetText(winResLoadString(IDS_STOPAVIRECORDING));
rlm@1 668
rlm@1 669 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
rlm@1 670 }
rlm@1 671
rlm@1 672 pCmdUI->Enable(emulating);
rlm@1 673 }
rlm@1 674
rlm@1 675 void MainWnd::OnUpdateToolsPauseAVIRecording(CCmdUI *pCmdUI)
rlm@1 676 {
rlm@1 677 if (pCmdUI->m_pMenu != NULL)
rlm@1 678 {
rlm@1 679 if (!theApp.aviRecording)
rlm@1 680 {
rlm@1 681 pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING));
rlm@1 682 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
rlm@1 683 pCmdUI->Enable(false);
rlm@1 684 }
rlm@1 685 else
rlm@1 686 {
rlm@1 687 if (!theApp.aviRecorder->IsPaused())
rlm@1 688 pCmdUI->SetText(winResLoadString(IDS_PAUSEAVIRECORDING));
rlm@1 689 else
rlm@1 690 pCmdUI->SetText(winResLoadString(IDS_RESUMEAVIRECORDING));
rlm@1 691
rlm@1 692 theApp.winAccelMgr.UpdateMenu(pCmdUI->m_pMenu->GetSafeHmenu());
rlm@1 693 pCmdUI->Enable(emulating);
rlm@1 694 }
rlm@1 695 }
rlm@1 696 }
rlm@1 697
rlm@1 698 void MainWnd::OnToolsRecordMovie()
rlm@1 699 {
rlm@1 700 MovieCreate dlg;
rlm@1 701 dlg.DoModal();
rlm@1 702 }
rlm@1 703
rlm@1 704 void MainWnd::OnUpdateToolsRecordMovie(CCmdUI *pCmdUI)
rlm@1 705 {
rlm@1 706 pCmdUI->Enable(emulating);
rlm@1 707 }
rlm@1 708
rlm@1 709 void MainWnd::OnToolsStopMovie()
rlm@1 710 {
rlm@1 711 VBAMovieStop(false);
rlm@1 712 }
rlm@1 713
rlm@1 714 void MainWnd::OnUpdateToolsStopMovie(CCmdUI *pCmdUI)
rlm@1 715 {
rlm@1 716 pCmdUI->Enable(emulating && VBAMovieActive());
rlm@1 717 }
rlm@1 718
rlm@1 719 void MainWnd::OnToolsPlayMovie()
rlm@1 720 {
rlm@1 721 MovieOpen dlg;
rlm@1 722 dlg.DoModal();
rlm@1 723 }
rlm@1 724
rlm@1 725 void MainWnd::OnUpdateToolsPlayMovie(CCmdUI *pCmdUI)
rlm@1 726 {
rlm@1 727 pCmdUI->Enable(emulating);
rlm@1 728 }
rlm@1 729
rlm@1 730 void MainWnd::OnToolsPlayReadOnly()
rlm@1 731 {
rlm@1 732 if (!VBAMovieActive())
rlm@1 733 {
rlm@1 734 theApp.movieReadOnly = !theApp.movieReadOnly;
rlm@1 735 systemScreenMessage(theApp.movieReadOnly ? "Movie now read-only" : "Movie now editable");
rlm@1 736 }
rlm@1 737 else
rlm@1 738 VBAMovieToggleReadOnly();
rlm@1 739 }
rlm@1 740
rlm@1 741 void MainWnd::OnUpdateToolsPlayReadOnly(CCmdUI *pCmdUI)
rlm@1 742 {
rlm@1 743 /// pCmdUI->Enable(VBAMovieActive()); // FIXME: this is right, but disabling menu items screws up accelerators until you view
rlm@1 744 // the menu!
rlm@1 745 /// pCmdUI->SetCheck(VBAMovieReadOnly());
rlm@1 746 pCmdUI->Enable(TRUE); // TEMP
rlm@1 747 pCmdUI->SetCheck(VBAMovieActive() ? VBAMovieReadOnly() : theApp.movieReadOnly);
rlm@1 748 }
rlm@1 749
rlm@1 750 void MainWnd::OnAsscWithSaveState()
rlm@1 751 {
rlm@1 752 theApp.AsscWithSaveState = !theApp.AsscWithSaveState;
rlm@1 753 }
rlm@1 754
rlm@1 755 void MainWnd::OnUpdateAsscWithSaveState(CCmdUI *pCmdUI)
rlm@1 756 {
rlm@1 757 pCmdUI->Enable(TRUE); // TEMP
rlm@1 758 pCmdUI->SetCheck(theApp.AsscWithSaveState);
rlm@1 759 }
rlm@1 760
rlm@1 761 void MainWnd::OnToolsResumeRecord()
rlm@1 762 {
rlm@1 763 // toggle playing/recording
rlm@1 764 if (VBAMovieRecording())
rlm@1 765 {
rlm@1 766 if (!VBAMovieSwitchToPlaying())
rlm@1 767 systemScreenMessage("Cannot continue playing");
rlm@1 768 }
rlm@1 769 else
rlm@1 770 {
rlm@1 771 if (!VBAMovieSwitchToRecording())
rlm@1 772 systemScreenMessage("Cannot resume recording now");
rlm@1 773 }
rlm@1 774 }
rlm@1 775
rlm@1 776 void MainWnd::OnUpdateToolsResumeRecord(CCmdUI *pCmdUI)
rlm@1 777 {
rlm@1 778 pCmdUI->Enable(VBAMovieActive());
rlm@1 779 }
rlm@1 780
rlm@1 781 void MainWnd::OnToolsPlayRestart()
rlm@1 782 {
rlm@1 783 VBAMovieRestart();
rlm@1 784 }
rlm@1 785
rlm@1 786 void MainWnd::OnUpdateToolsPlayRestart(CCmdUI *pCmdUI)
rlm@1 787 {
rlm@1 788 pCmdUI->Enable(VBAMovieActive());
rlm@1 789 }
rlm@1 790
rlm@1 791 void MainWnd::OnToolsOnMovieEndPause()
rlm@1 792 {
rlm@1 793 theApp.movieOnEndPause = !theApp.movieOnEndPause;
rlm@1 794 }
rlm@1 795
rlm@1 796 void MainWnd::OnUpdateToolsOnMovieEndPause(CCmdUI *pCmdUI)
rlm@1 797 {
rlm@1 798 pCmdUI->SetCheck(theApp.movieOnEndPause);
rlm@1 799 }
rlm@1 800
rlm@1 801 void MainWnd::OnToolsOnMovieEndStop()
rlm@1 802 {
rlm@1 803 theApp.movieOnEndBehavior = 0;
rlm@1 804 }
rlm@1 805
rlm@1 806 void MainWnd::OnUpdateToolsOnMovieEndStop(CCmdUI *pCmdUI)
rlm@1 807 {
rlm@1 808 pCmdUI->SetRadio(theApp.movieOnEndBehavior == 0);
rlm@1 809 }
rlm@1 810
rlm@1 811 void MainWnd::OnToolsOnMovieEndRestart()
rlm@1 812 {
rlm@1 813 theApp.movieOnEndBehavior = 1;
rlm@1 814 }
rlm@1 815
rlm@1 816 void MainWnd::OnUpdateToolsOnMovieEndRestart(CCmdUI *pCmdUI)
rlm@1 817 {
rlm@1 818 pCmdUI->SetRadio(theApp.movieOnEndBehavior == 1);
rlm@1 819 }
rlm@1 820
rlm@1 821 void MainWnd::OnToolsOnMovieEndAppend()
rlm@1 822 {
rlm@1 823 theApp.movieOnEndBehavior = 2;
rlm@1 824 }
rlm@1 825
rlm@1 826 void MainWnd::OnUpdateToolsOnMovieEndAppend(CCmdUI *pCmdUI)
rlm@1 827 {
rlm@1 828 pCmdUI->SetRadio(theApp.movieOnEndBehavior == 2);
rlm@1 829 }
rlm@1 830
rlm@1 831 void MainWnd::OnToolsOnMovieEndKeep()
rlm@1 832 {
rlm@1 833 theApp.movieOnEndBehavior = 3;
rlm@1 834 }
rlm@1 835
rlm@1 836 void MainWnd::OnUpdateToolsOnMovieEndKeep(CCmdUI *pCmdUI)
rlm@1 837 {
rlm@1 838 pCmdUI->SetRadio(theApp.movieOnEndBehavior == 3);
rlm@1 839 }
rlm@1 840
rlm@1 841 /////////////////////////////////
rlm@1 842
rlm@1 843 void MainWnd::OnToolsMovieSetPauseAt()
rlm@1 844 {
rlm@1 845 // TODO
rlm@1 846 VBAMovieSetPauseAt(-1);
rlm@1 847 }
rlm@1 848
rlm@1 849 void MainWnd::OnUpdateToolsSetMoviePauseAt(CCmdUI *pCmdUI)
rlm@1 850 {
rlm@1 851 // TODO
rlm@1 852 pCmdUI->SetCheck(VBAMovieGetPauseAt() >= 0);
rlm@1 853 pCmdUI->Enable(FALSE && VBAMovieActive());
rlm@1 854 }
rlm@1 855
rlm@1 856 void MainWnd::OnToolsMovieConvertCurrent()
rlm@1 857 {
rlm@1 858 // temporary
rlm@1 859 int result = VBAMovieConvertCurrent();
rlm@1 860 switch (result)
rlm@1 861 {
rlm@1 862 case MOVIE_SUCCESS:
rlm@1 863 systemScreenMessage("Movie converted");
rlm@1 864 break;
rlm@1 865 case MOVIE_WRONG_VERSION:
rlm@1 866 systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion());
rlm@1 867 break;
rlm@1 868 default:
rlm@1 869 systemScreenMessage("Nothing to convert");
rlm@1 870 break;
rlm@1 871 }
rlm@1 872 }
rlm@1 873
rlm@1 874 void MainWnd::OnUpdateToolsMovieConvertCurrent(CCmdUI *pCmdUI)
rlm@1 875 {
rlm@1 876 pCmdUI->Enable(VBAMovieActive());
rlm@1 877 }
rlm@1 878
rlm@1 879 void MainWnd::OnToolsMovieAutoConvert()
rlm@1 880 {
rlm@1 881 extern bool autoConvertMovieWhenPlaying; // from movie.cpp
rlm@1 882 autoConvertMovieWhenPlaying = !autoConvertMovieWhenPlaying;
rlm@1 883 if (autoConvertMovieWhenPlaying)
rlm@1 884 {
rlm@1 885 int result = VBAMovieConvertCurrent();
rlm@1 886 switch (result)
rlm@1 887 {
rlm@1 888 case MOVIE_SUCCESS:
rlm@1 889 systemScreenMessage("Movie converted");
rlm@1 890 break;
rlm@1 891 case MOVIE_WRONG_VERSION:
rlm@1 892 systemMessage(0, "Cannot convert from VBM revision %u", VBAMovieGetMinorVersion());
rlm@1 893 break;
rlm@1 894 default:
rlm@1 895 systemScreenMessage("Auto movie conversion enabled");
rlm@1 896 break;
rlm@1 897 }
rlm@1 898 }
rlm@1 899 }
rlm@1 900
rlm@1 901 void MainWnd::OnUpdateToolsMovieAutoConvert(CCmdUI *pCmdUI)
rlm@1 902 {
rlm@1 903 extern bool autoConvertMovieWhenPlaying; // from movie.cpp
rlm@1 904 pCmdUI->SetCheck(autoConvertMovieWhenPlaying);
rlm@1 905 }
rlm@1 906
rlm@1 907 void MainWnd::OnToolsMovieTruncateAtCurrent()
rlm@1 908 {
rlm@1 909 if (VBAMovieReadOnly())
rlm@1 910 systemScreenMessage("Cannot truncate movie in this mode");
rlm@1 911 else
rlm@1 912 VBAMovieTuncateAtCurrentFrame();
rlm@1 913 }
rlm@1 914
rlm@1 915 void MainWnd::OnUpdateToolsMovieTruncateAtCurrent(CCmdUI *pCmdUI)
rlm@1 916 {
rlm@1 917 pCmdUI->Enable(VBAMovieActive());
rlm@1 918 }
rlm@1 919
rlm@1 920 void MainWnd::OnToolsMovieFixHeader()
rlm@1 921 {
rlm@1 922 VBAMovieFixHeader();
rlm@1 923 }
rlm@1 924
rlm@1 925 void MainWnd::OnUpdateToolsMovieFixHeader(CCmdUI *pCmdUI)
rlm@1 926 {
rlm@1 927 pCmdUI->Enable(VBAMovieActive());
rlm@1 928 }
rlm@1 929
rlm@1 930 // TODO
rlm@1 931 void MainWnd::OnToolsMovieExtractFromSavegame()
rlm@1 932 {
rlm@1 933 // Currently, snapshots taken from a movie don't contain the initial SRAM or savestate of the movie,
rlm@1 934 // even if the movie was recorded from either of them. If a snapshot was taken at the first frame
rlm@1 935 // i.e. Frame 0, it can be safely assumed that the snapshot reflects the initial state of such a movie.
rlm@1 936 // However, if it was taken after the first frame, the SRAM contained might either be still the same
rlm@1 937 // as the original (usually true if no write operations on the SRAM occured) or have been modified,
rlm@1 938 // while the exact original state could hardly, if not impossibly, be safely worked out.
rlm@1 939
rlm@1 940 // TODO
rlm@1 941 }
rlm@1 942
rlm@1 943 void MainWnd::OnUpdateToolsMovieExtractFromSavegame(CCmdUI *pCmdUI)
rlm@1 944 {
rlm@1 945 pCmdUI->Enable(FALSE);
rlm@1 946 }
rlm@1 947
rlm@1 948 ///////////////////////////////////////////////////////////
rlm@1 949
rlm@1 950 void MainWnd::OnToolsRewind()
rlm@1 951 {
rlm@1 952 assert(theApp.rewindTimer > 0 && theApp.rewindSlots > 0);
rlm@1 953 if (emulating && theApp.emulator.emuReadMemState && theApp.rewindMemory && theApp.rewindCount)
rlm@1 954 {
rlm@1 955 assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots);
rlm@1 956 theApp.rewindPos = (--theApp.rewindPos + theApp.rewindSlots) % theApp.rewindSlots;
rlm@1 957 assert(theApp.rewindPos >= 0 && theApp.rewindPos < theApp.rewindSlots);
rlm@1 958 theApp.emulator.emuReadMemState(&theApp.rewindMemory[REWIND_SIZE * theApp.rewindPos], REWIND_SIZE);
rlm@1 959 theApp.rewindCount--;
rlm@1 960 if (theApp.rewindCount > 0)
rlm@1 961 theApp.rewindCounter = 0;
rlm@1 962 else
rlm@1 963 {
rlm@1 964 theApp.rewindCounter = theApp.rewindTimer;
rlm@1 965 theApp.rewindSaveNeeded = true;
rlm@1 966
rlm@1 967 // immediately save state to avoid eroding away the earliest you can rewind to
rlm@1 968 theApp.saveRewindStateIfNecessary();
rlm@1 969
rlm@1 970 theApp.rewindSaveNeeded = false;
rlm@1 971 }
rlm@1 972 }
rlm@1 973 }
rlm@1 974
rlm@1 975 void MainWnd::OnUpdateToolsRewind(CCmdUI *pCmdUI)
rlm@1 976 {
rlm@1 977 pCmdUI->Enable(theApp.rewindMemory != NULL && emulating && theApp.rewindCount);
rlm@1 978 }
rlm@1 979
rlm@1 980 void MainWnd::OnToolsCustomize()
rlm@1 981 {
rlm@1 982 theApp.recreateMenuBar();
rlm@1 983
rlm@1 984 AccelEditor dlg(this, &theApp.m_menu, &theApp.winAccelMgr);
rlm@1 985 dlg.DoModal();
rlm@1 986 if (dlg.IsModified())
rlm@1 987 {
rlm@1 988 theApp.winAccelMgr = dlg.GetResultMangager();
rlm@1 989 theApp.winAccelMgr.UpdateWndTable();
rlm@1 990 theApp.winAccelMgr.Write();
rlm@1 991 }
rlm@1 992
rlm@1 993 theApp.winAccelMgr.UpdateMenu(theApp.menu); // we should always do this since the menu has been reloaded
rlm@1 994 }
rlm@1 995
rlm@1 996 void MainWnd::OnUpdateToolsCustomize(CCmdUI *pCmdUI)
rlm@1 997 {
rlm@1 998 pCmdUI->Enable(theApp.videoOption != VIDEO_320x240);
rlm@1 999 }
rlm@1 1000