annotate src/win32/MovieCreate.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
rev   line source
rlm@1 1 // MovieCreate.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "resource.h"
rlm@1 6 #include "MovieCreate.h"
rlm@1 7 #include "MainWnd.h"
rlm@1 8 #include "FileDlg.h"
rlm@1 9 #include "WinResUtil.h"
rlm@1 10 #include "WinMiscUtil.h"
rlm@1 11 #include "VBA.h"
rlm@1 12
rlm@1 13 #include "../NLS.h"
rlm@1 14 #include "../common/Util.h"
rlm@1 15 #include "../common/movie.h"
rlm@1 16 #include "../gba/GBAGlobals.h"
rlm@1 17 #include "../gb/gbGlobals.h"
rlm@1 18
rlm@1 19 extern u32 myROM[];
rlm@1 20
rlm@1 21 #define GBC_CAPABLE ((gbRom[0x143] & 0x80) != 0)
rlm@1 22 #define SGB_CAPABLE (gbRom[0x146] == 0x03)
rlm@1 23
rlm@1 24 // MovieCreate dialog
rlm@1 25
rlm@1 26 IMPLEMENT_DYNAMIC(MovieCreate, CDialog)
rlm@1 27 MovieCreate::MovieCreate(CWnd *pParent /*=NULL*/)
rlm@1 28 : CDialog(MovieCreate::IDD, pParent)
rlm@1 29 {
rlm@1 30 //{{AFX_DATA_INIT(MovieCreate)
rlm@1 31 m_startOption = 2; // "from start" as default
rlm@1 32 m_systemOption = systemCartridgeType == 0 ? 0 : (GBC_CAPABLE ? 1 : (SGB_CAPABLE ? 2 : 3)); // GBA, GBC, SGB, or GB
rlm@1 33 m_biosOption = systemCartridgeType == 0 ? (useBios ? 2 : 1) : 0; // none for non-GBA, or introless and based on settings
rlm@1 34 //}}AFX_DATA_INIT
rlm@1 35 }
rlm@1 36
rlm@1 37 MovieCreate::~MovieCreate()
rlm@1 38 {}
rlm@1 39
rlm@1 40 BOOL MovieCreate::OnInitDialog()
rlm@1 41 {
rlm@1 42 CDialog::OnInitDialog();
rlm@1 43
rlm@1 44 GetDlgItem(IDC_REC_GBA)->EnableWindow(systemCartridgeType == 0);
rlm@1 45 GetDlgItem(IDC_REC_GBC)->EnableWindow(systemCartridgeType != 0 && GBC_CAPABLE);
rlm@1 46 GetDlgItem(IDC_REC_SGB)->EnableWindow(systemCartridgeType != 0 && SGB_CAPABLE);
rlm@1 47 GetDlgItem(IDC_REC_GB)->EnableWindow(systemCartridgeType != 0);
rlm@1 48
rlm@1 49 GetDlgItem(IDC_REC_NOBIOS)->EnableWindow(systemCartridgeType != 0);
rlm@1 50 GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(systemCartridgeType == 0);
rlm@1 51 GetDlgItem(IDC_REC_GBABIOS)->EnableWindow(systemCartridgeType == 0);
rlm@1 52 GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(systemCartridgeType == 0);
rlm@1 53
rlm@1 54 CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
rlm@1 55
rlm@1 56 m_editFilename.LimitText(_MAX_PATH);
rlm@1 57 m_editAuthor.LimitText(MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 58 m_editDescription.LimitText(MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 59
rlm@1 60 // convert the ROM filename into a default movie name
rlm@1 61 CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, ".vbm");
rlm@1 62
rlm@1 63 GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
rlm@1 64
rlm@1 65 // scroll to show the rightmost side of the movie filename
rlm@1 66 ((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
rlm@1 67
rlm@1 68 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 69 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 70 }
rlm@1 71
rlm@1 72 void MovieCreate::DoDataExchange(CDataExchange *pDX)
rlm@1 73 {
rlm@1 74 CDialog::DoDataExchange(pDX);
rlm@1 75 //{{AFX_DATA_MAP(MovieCreate)
rlm@1 76 DDX_Radio(pDX, IDC_RECNOW, m_startOption);
rlm@1 77 DDX_Radio(pDX, IDC_REC_GBA, m_systemOption);
rlm@1 78 /// done manually DDX_Radio(pDX, IDC_REC_NOBIOS, m_biosOption);
rlm@1 79 DDX_Control(pDX, IDC_EDIT_AUTHOR, m_editAuthor);
rlm@1 80 DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
rlm@1 81 DDX_Control(pDX, IDC_MOVIE_FILENAME, m_editFilename);
rlm@1 82 //}}AFX_DATA_MAP
rlm@1 83 }
rlm@1 84
rlm@1 85 BEGIN_MESSAGE_MAP(MovieCreate, CDialog)
rlm@1 86 ON_BN_CLICKED(IDOK, OnBnClickedOk)
rlm@1 87 ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
rlm@1 88 ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
rlm@1 89 ON_BN_CLICKED(IDC_RECSTART, OnBnClickedRecstart)
rlm@1 90 ON_BN_CLICKED(IDC_RECRESET, OnBnClickedRecreset)
rlm@1 91 ON_BN_CLICKED(IDC_RECNOW, OnBnClickedRecnow)
rlm@1 92 ON_BN_CLICKED(IDC_REC_GBA, OnBnClickedRecGba)
rlm@1 93 ON_BN_CLICKED(IDC_REC_GBC, OnBnClickedRecGbc)
rlm@1 94 ON_BN_CLICKED(IDC_REC_SGB, OnBnClickedRecSgb)
rlm@1 95 ON_BN_CLICKED(IDC_REC_GB, OnBnClickedRecGb)
rlm@1 96 ON_BN_CLICKED(IDC_REC_NOBIOS, OnBnClickedRecNobios)
rlm@1 97 ON_BN_CLICKED(IDC_REC_EMUBIOS, OnBnClickedRecEmubios)
rlm@1 98 ON_BN_CLICKED(IDC_REC_GBABIOS, OnBnClickedRecGbabios)
rlm@1 99 ON_BN_CLICKED(IDC_REC_GBABIOSINTRO, OnBnClickedRecGbabiosintro)
rlm@1 100 END_MESSAGE_MAP()
rlm@1 101
rlm@1 102 // MovieCreate message handlers
rlm@1 103
rlm@1 104 void MovieCreate::OnBnClickedBrowse()
rlm@1 105 {
rlm@1 106 theApp.winCheckFullscreen();
rlm@1 107
rlm@1 108 LPCTSTR exts[] = { ".vbm", NULL };
rlm@1 109
rlm@1 110 CString filter = winResLoadFilter(IDS_FILTER_MOVIE);
rlm@1 111 CString title = winResLoadString(IDS_SELECT_MOVIE_NAME);
rlm@1 112
rlm@1 113 CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, exts[0]);
rlm@1 114 CString movieDir = winGetDestDir(IDS_MOVIE_DIR);
rlm@1 115
rlm@1 116 FileDlg dlg(this, movieName, filter, 1, "VBM", exts, movieDir, title, true);
rlm@1 117
rlm@1 118 if (dlg.DoModal() == IDCANCEL)
rlm@1 119 {
rlm@1 120 return;
rlm@1 121 }
rlm@1 122
rlm@1 123 movieName = dlg.GetPathName();
rlm@1 124
rlm@1 125 GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
rlm@1 126
rlm@1 127 // scroll to show the rightmost side of the movie filename
rlm@1 128 ((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
rlm@1 129 }
rlm@1 130
rlm@1 131 void MovieCreate::OnBnClickedOk()
rlm@1 132 {
rlm@1 133 // has to be done before creating the movie
rlm@1 134 bool useBiosFile = false;
rlm@1 135 bool skipBiosFile = false;
rlm@1 136
rlm@1 137 if (m_biosOption == 1)
rlm@1 138 {
rlm@1 139 useBiosFile = false;
rlm@1 140 }
rlm@1 141 else if (m_biosOption == 2)
rlm@1 142 {
rlm@1 143 useBiosFile = true;
rlm@1 144 skipBiosFile = true;
rlm@1 145 }
rlm@1 146 else if (m_biosOption == 3)
rlm@1 147 {
rlm@1 148 useBiosFile = true;
rlm@1 149 skipBiosFile = false;
rlm@1 150 }
rlm@1 151
rlm@1 152 extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
rlm@1 153 if (!systemLoadBIOS(theApp.biosFileName, useBiosFile))
rlm@1 154 {
rlm@1 155 if (m_biosOption > 1)
rlm@1 156 {
rlm@1 157 systemMessage(0, "Invalid GBA BIOS file!");
rlm@1 158 return;
rlm@1 159 }
rlm@1 160 }
rlm@1 161
rlm@1 162 theApp.useBiosFile = useBiosFile;
rlm@1 163 if (useBiosFile)
rlm@1 164 theApp.skipBiosFile = skipBiosFile;
rlm@1 165
rlm@1 166 int startFlags = 0, controllerFlags = 0, typeFlags = 0;
rlm@1 167
rlm@1 168 if (m_startOption == 0)
rlm@1 169 startFlags |= MOVIE_START_FROM_SNAPSHOT;
rlm@1 170 else if (m_startOption == 1)
rlm@1 171 startFlags |= MOVIE_START_FROM_SRAM;
rlm@1 172 //else
rlm@1 173 // startFlags = 0; // no SRAM or snapshot
rlm@1 174
rlm@1 175 if (m_systemOption == 0)
rlm@1 176 {
rlm@1 177 typeFlags |= MOVIE_TYPE_GBA;
rlm@1 178 gbEmulatorType = 4;
rlm@1 179 }
rlm@1 180 else if (m_systemOption == 1)
rlm@1 181 {
rlm@1 182 typeFlags |= MOVIE_TYPE_GBC;
rlm@1 183 gbEmulatorType = 1;
rlm@1 184 }
rlm@1 185 else if (m_systemOption == 2)
rlm@1 186 {
rlm@1 187 typeFlags |= MOVIE_TYPE_SGB;
rlm@1 188 gbEmulatorType = 2;
rlm@1 189 }
rlm@1 190 else
rlm@1 191 {
rlm@1 192 gbEmulatorType = 3; // plain old GB
rlm@1 193 }
rlm@1 194
rlm@1 195 controllerFlags |= MOVIE_CONTROLLER(0);
rlm@1 196 if (typeFlags & MOVIE_TYPE_SGB)
rlm@1 197 {
rlm@1 198 // XXX FIXME - the code for multiple controllers must be broken somehow
rlm@1 199 // (it crashes strangely during FreezeToStream in SGB games)
rlm@1 200
rlm@1 201 // SGB games are free to request controllers while running, so we have to assume it needs all 4
rlm@1 202 /// controllerFlags |= MOVIE_CONTROLLER(1) | MOVIE_CONTROLLER(2) | MOVIE_CONTROLLER(3);
rlm@1 203 }
rlm@1 204
rlm@1 205 // get author and movie info from the edit fields:
rlm@1 206 char info [MOVIE_METADATA_SIZE], buffer [MOVIE_METADATA_SIZE];
rlm@1 207
rlm@1 208 GetDlgItem(IDC_EDIT_AUTHOR)->GetWindowText(buffer, MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 209 strncpy(info, buffer, MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 210 info[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
rlm@1 211
rlm@1 212 GetDlgItem(IDC_EDIT_DESCRIPTION)->GetWindowText(buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 213 strncpy(info + MOVIE_METADATA_AUTHOR_SIZE, buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
rlm@1 214 info[MOVIE_METADATA_SIZE - 1] = '\0';
rlm@1 215
rlm@1 216 if (memLagTempEnabled && systemCartridgeType == 0)
rlm@1 217 {
rlm@1 218 // lag reduction is off -- if the user didn't turn it off, silently turn it back on, otherwise ask
rlm@1 219 int ans = !memLagEnabled ? IDYES : AfxGetApp()->m_pMainWnd->MessageBox(
rlm@1 220 "Lag reduction is currently OFF.\nIt is recommended that you turn this ON for recording.\nWould you like to turn it on now?",
rlm@1 221 "Warning",
rlm@1 222 MB_YESNOCANCEL | MB_ICONWARNING);
rlm@1 223 switch (ans)
rlm@1 224 {
rlm@1 225 case IDYES:
rlm@1 226 extern void SetPrefetchHack(bool);
rlm@1 227 SetPrefetchHack(true);
rlm@1 228 break;
rlm@1 229 case IDNO:
rlm@1 230 break;
rlm@1 231 case IDCANCEL:
rlm@1 232 return;
rlm@1 233 }
rlm@1 234 }
rlm@1 235
rlm@1 236 CString movieName;
rlm@1 237 GetDlgItem(IDC_MOVIE_FILENAME)->GetWindowText(movieName);
rlm@1 238
rlm@1 239 // actually make the movie file:
rlm@1 240 int code = VBAMovieCreate(movieName, info, startFlags, controllerFlags, typeFlags);
rlm@1 241
rlm@1 242 if (code != MOVIE_SUCCESS)
rlm@1 243 {
rlm@1 244 systemMessage(0, "Failed to create movie %s", (const char *)movieName);
rlm@1 245 return;
rlm@1 246 }
rlm@1 247
rlm@1 248 OnOK();
rlm@1 249 }
rlm@1 250
rlm@1 251 void MovieCreate::OnBnClickedCancel()
rlm@1 252 {
rlm@1 253 OnCancel();
rlm@1 254 }
rlm@1 255
rlm@1 256 void MovieCreate::OnBnClickedRecstart()
rlm@1 257 {
rlm@1 258 m_startOption = 2;
rlm@1 259 if (systemCartridgeType == 0)
rlm@1 260 {
rlm@1 261 GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
rlm@1 262 GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
rlm@1 263 }
rlm@1 264 else
rlm@1 265 {
rlm@1 266 GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
rlm@1 267 GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
rlm@1 268 GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
rlm@1 269 }
rlm@1 270 }
rlm@1 271
rlm@1 272 void MovieCreate::OnBnClickedRecreset()
rlm@1 273 {
rlm@1 274 m_startOption = 1;
rlm@1 275 if (systemCartridgeType == 0)
rlm@1 276 {
rlm@1 277 GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
rlm@1 278 GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
rlm@1 279 }
rlm@1 280 else
rlm@1 281 {
rlm@1 282 GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
rlm@1 283 GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
rlm@1 284 GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
rlm@1 285 }
rlm@1 286 }
rlm@1 287
rlm@1 288 void MovieCreate::OnBnClickedRecnow()
rlm@1 289 {
rlm@1 290 m_startOption = 0;
rlm@1 291
rlm@1 292 // starting from emulator bios file from a snapshot made while playing with GBA bios file won't work
rlm@1 293 if (systemCartridgeType == 0 && useBios)
rlm@1 294 {
rlm@1 295 if (m_biosOption == 1)
rlm@1 296 {
rlm@1 297 OnBnClickedRecGbabios();
rlm@1 298 CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
rlm@1 299 }
rlm@1 300 GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(FALSE);
rlm@1 301 }
rlm@1 302
rlm@1 303 // "with intro" distinction makes no sense when continuing from snapshot
rlm@1 304 if (systemCartridgeType == 0)
rlm@1 305 {
rlm@1 306 if (m_biosOption == 3)
rlm@1 307 {
rlm@1 308 OnBnClickedRecGbabios();
rlm@1 309 CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
rlm@1 310 }
rlm@1 311 GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(FALSE);
rlm@1 312 }
rlm@1 313
rlm@1 314 // can't switch systems while recording from snapshot!
rlm@1 315 if (systemCartridgeType != 0)
rlm@1 316 {
rlm@1 317 int curSystemOption = (gbCgbMode == 1 ? 1 : (gbSgbMode == 1 ? 2 : 3)); // GBC, SGB, or GB
rlm@1 318 GetDlgItem(IDC_REC_GBC)->EnableWindow(curSystemOption == 1);
rlm@1 319 GetDlgItem(IDC_REC_SGB)->EnableWindow(curSystemOption == 2);
rlm@1 320 GetDlgItem(IDC_REC_GB)->EnableWindow(curSystemOption == 3);
rlm@1 321 m_systemOption = curSystemOption;
rlm@1 322 CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, IDC_REC_GBA + m_systemOption);
rlm@1 323 }
rlm@1 324 }
rlm@1 325
rlm@1 326 void MovieCreate::OnBnClickedRecGba()
rlm@1 327 {
rlm@1 328 m_systemOption = 0;
rlm@1 329 }
rlm@1 330
rlm@1 331 void MovieCreate::OnBnClickedRecGbc()
rlm@1 332 {
rlm@1 333 m_systemOption = 1;
rlm@1 334 }
rlm@1 335
rlm@1 336 void MovieCreate::OnBnClickedRecSgb()
rlm@1 337 {
rlm@1 338 m_systemOption = 2;
rlm@1 339 }
rlm@1 340
rlm@1 341 void MovieCreate::OnBnClickedRecGb()
rlm@1 342 {
rlm@1 343 m_systemOption = 3;
rlm@1 344 }
rlm@1 345
rlm@1 346 void MovieCreate::OnBnClickedRecNobios()
rlm@1 347 {
rlm@1 348 m_biosOption = 0;
rlm@1 349 }
rlm@1 350
rlm@1 351 void MovieCreate::OnBnClickedRecEmubios()
rlm@1 352 {
rlm@1 353 m_biosOption = 1;
rlm@1 354 }
rlm@1 355
rlm@1 356 void MovieCreate::OnBnClickedRecGbabios()
rlm@1 357 {
rlm@1 358 if (utilCheckBIOS(theApp.biosFileName, 4))
rlm@1 359 m_biosOption = 2;
rlm@1 360 else
rlm@1 361 {
rlm@1 362 ((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
rlm@1 363 if (utilCheckBIOS(theApp.biosFileName, 4))
rlm@1 364 m_biosOption = 2;
rlm@1 365 else
rlm@1 366 {
rlm@1 367 systemMessage(0, "This option requires a valid GBA BIOS file.");
rlm@1 368 CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
rlm@1 369 }
rlm@1 370 }
rlm@1 371 }
rlm@1 372
rlm@1 373 void MovieCreate::OnBnClickedRecGbabiosintro()
rlm@1 374 {
rlm@1 375 if (utilCheckBIOS(theApp.biosFileName, 4))
rlm@1 376 m_biosOption = 3;
rlm@1 377 else
rlm@1 378 {
rlm@1 379 ((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
rlm@1 380 if (utilCheckBIOS(theApp.biosFileName, 4))
rlm@1 381 m_biosOption = 3;
rlm@1 382 else
rlm@1 383 {
rlm@1 384 systemMessage(0, "This option requires a valid GBA BIOS file.");
rlm@1 385 CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
rlm@1 386 }
rlm@1 387 }
rlm@1 388 }
rlm@1 389