diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/MovieCreate.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,389 @@
     1.4 +// MovieCreate.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "MovieCreate.h"
    1.10 +#include "MainWnd.h"
    1.11 +#include "FileDlg.h"
    1.12 +#include "WinResUtil.h"
    1.13 +#include "WinMiscUtil.h"
    1.14 +#include "VBA.h"
    1.15 +
    1.16 +#include "../NLS.h"
    1.17 +#include "../common/Util.h"
    1.18 +#include "../common/movie.h"
    1.19 +#include "../gba/GBAGlobals.h"
    1.20 +#include "../gb/gbGlobals.h"
    1.21 +
    1.22 +extern u32 myROM[];
    1.23 +
    1.24 +#define GBC_CAPABLE ((gbRom[0x143] & 0x80) != 0)
    1.25 +#define SGB_CAPABLE (gbRom[0x146] == 0x03)
    1.26 +
    1.27 +// MovieCreate dialog
    1.28 +
    1.29 +IMPLEMENT_DYNAMIC(MovieCreate, CDialog)
    1.30 +MovieCreate::MovieCreate(CWnd *pParent /*=NULL*/)
    1.31 +	: CDialog(MovieCreate::IDD, pParent)
    1.32 +{
    1.33 +	//{{AFX_DATA_INIT(MovieCreate)
    1.34 +	m_startOption  = 2; // "from start" as default
    1.35 +	m_systemOption = systemCartridgeType == 0 ? 0 : (GBC_CAPABLE ? 1 : (SGB_CAPABLE ? 2 : 3)); // GBA, GBC, SGB, or GB
    1.36 +	m_biosOption   = systemCartridgeType == 0 ? (useBios ? 2 : 1) : 0; // none for non-GBA, or introless and based on settings
    1.37 +	//}}AFX_DATA_INIT
    1.38 +}
    1.39 +
    1.40 +MovieCreate::~MovieCreate()
    1.41 +{}
    1.42 +
    1.43 +BOOL MovieCreate::OnInitDialog()
    1.44 +{
    1.45 +	CDialog::OnInitDialog();
    1.46 +
    1.47 +	GetDlgItem(IDC_REC_GBA)->EnableWindow(systemCartridgeType == 0);
    1.48 +	GetDlgItem(IDC_REC_GBC)->EnableWindow(systemCartridgeType != 0 && GBC_CAPABLE);
    1.49 +	GetDlgItem(IDC_REC_SGB)->EnableWindow(systemCartridgeType != 0 && SGB_CAPABLE);
    1.50 +	GetDlgItem(IDC_REC_GB)->EnableWindow(systemCartridgeType != 0);
    1.51 +
    1.52 +	GetDlgItem(IDC_REC_NOBIOS)->EnableWindow(systemCartridgeType != 0);
    1.53 +	GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(systemCartridgeType == 0);
    1.54 +	GetDlgItem(IDC_REC_GBABIOS)->EnableWindow(systemCartridgeType == 0);
    1.55 +	GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(systemCartridgeType == 0);
    1.56 +
    1.57 +	CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
    1.58 +
    1.59 +	m_editFilename.LimitText(_MAX_PATH);
    1.60 +	m_editAuthor.LimitText(MOVIE_METADATA_AUTHOR_SIZE);
    1.61 +	m_editDescription.LimitText(MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
    1.62 +
    1.63 +	// convert the ROM filename into a default movie name
    1.64 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, ".vbm");
    1.65 +
    1.66 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
    1.67 +
    1.68 +	// scroll to show the rightmost side of the movie filename
    1.69 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
    1.70 +
    1.71 +	return TRUE; // return TRUE unless you set the focus to a control
    1.72 +	// EXCEPTION: OCX Property Pages should return FALSE
    1.73 +}
    1.74 +
    1.75 +void MovieCreate::DoDataExchange(CDataExchange *pDX)
    1.76 +{
    1.77 +	CDialog::DoDataExchange(pDX);
    1.78 +	//{{AFX_DATA_MAP(MovieCreate)
    1.79 +	DDX_Radio(pDX, IDC_RECNOW, m_startOption);
    1.80 +	DDX_Radio(pDX, IDC_REC_GBA, m_systemOption);
    1.81 +///	done manually DDX_Radio(pDX, IDC_REC_NOBIOS, m_biosOption);
    1.82 +	DDX_Control(pDX, IDC_EDIT_AUTHOR, m_editAuthor);
    1.83 +	DDX_Control(pDX, IDC_EDIT_DESCRIPTION, m_editDescription);
    1.84 +	DDX_Control(pDX, IDC_MOVIE_FILENAME, m_editFilename);
    1.85 +	//}}AFX_DATA_MAP
    1.86 +}
    1.87 +
    1.88 +BEGIN_MESSAGE_MAP(MovieCreate, CDialog)
    1.89 +ON_BN_CLICKED(IDOK, OnBnClickedOk)
    1.90 +ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
    1.91 +ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
    1.92 +ON_BN_CLICKED(IDC_RECSTART, OnBnClickedRecstart)
    1.93 +ON_BN_CLICKED(IDC_RECRESET, OnBnClickedRecreset)
    1.94 +ON_BN_CLICKED(IDC_RECNOW, OnBnClickedRecnow)
    1.95 +ON_BN_CLICKED(IDC_REC_GBA, OnBnClickedRecGba)
    1.96 +ON_BN_CLICKED(IDC_REC_GBC, OnBnClickedRecGbc)
    1.97 +ON_BN_CLICKED(IDC_REC_SGB, OnBnClickedRecSgb)
    1.98 +ON_BN_CLICKED(IDC_REC_GB, OnBnClickedRecGb)
    1.99 +ON_BN_CLICKED(IDC_REC_NOBIOS, OnBnClickedRecNobios)
   1.100 +ON_BN_CLICKED(IDC_REC_EMUBIOS, OnBnClickedRecEmubios)
   1.101 +ON_BN_CLICKED(IDC_REC_GBABIOS, OnBnClickedRecGbabios)
   1.102 +ON_BN_CLICKED(IDC_REC_GBABIOSINTRO, OnBnClickedRecGbabiosintro)
   1.103 +END_MESSAGE_MAP()
   1.104 +
   1.105 +// MovieCreate message handlers
   1.106 +
   1.107 +void MovieCreate::OnBnClickedBrowse()
   1.108 +{
   1.109 +	theApp.winCheckFullscreen();
   1.110 +
   1.111 +	LPCTSTR exts[] = { ".vbm", NULL };
   1.112 +
   1.113 +	CString filter = winResLoadFilter(IDS_FILTER_MOVIE);
   1.114 +	CString title  = winResLoadString(IDS_SELECT_MOVIE_NAME);
   1.115 +
   1.116 +	CString movieName = winGetDestFilename(theApp.gameFilename, IDS_MOVIE_DIR, exts[0]);
   1.117 +	CString movieDir  = winGetDestDir(IDS_MOVIE_DIR);
   1.118 +
   1.119 +	FileDlg dlg(this, movieName, filter, 1, "VBM", exts, movieDir, title, true);
   1.120 +
   1.121 +	if (dlg.DoModal() == IDCANCEL)
   1.122 +	{
   1.123 +		return;
   1.124 +	}
   1.125 +
   1.126 +	movieName = dlg.GetPathName();
   1.127 +
   1.128 +	GetDlgItem(IDC_MOVIE_FILENAME)->SetWindowText(movieName);
   1.129 +
   1.130 +	// scroll to show the rightmost side of the movie filename
   1.131 +	((CEdit *)GetDlgItem(IDC_MOVIE_FILENAME))->SetSel((DWORD)(movieName.GetLength() - 1), FALSE);
   1.132 +}
   1.133 +
   1.134 +void MovieCreate::OnBnClickedOk()
   1.135 +{
   1.136 +	// has to be done before creating the movie
   1.137 +	bool useBiosFile  = false;
   1.138 +	bool skipBiosFile = false;
   1.139 +
   1.140 +	if (m_biosOption == 1)
   1.141 +	{
   1.142 +		useBiosFile = false;
   1.143 +	}
   1.144 +	else if (m_biosOption == 2)
   1.145 +	{
   1.146 +		useBiosFile	 = true;
   1.147 +		skipBiosFile = true;
   1.148 +	}
   1.149 +	else if (m_biosOption == 3)
   1.150 +	{
   1.151 +		useBiosFile	 = true;
   1.152 +		skipBiosFile = false;
   1.153 +	}
   1.154 +
   1.155 +	extern bool systemLoadBIOS(const char *biosFileName, bool useBiosFile);
   1.156 +	if (!systemLoadBIOS(theApp.biosFileName, useBiosFile))
   1.157 +	{
   1.158 +		if (m_biosOption > 1)
   1.159 +		{
   1.160 +			systemMessage(0, "Invalid GBA BIOS file!");
   1.161 +			return;
   1.162 +		}
   1.163 +	}
   1.164 +
   1.165 +	theApp.useBiosFile = useBiosFile;
   1.166 +	if (useBiosFile)
   1.167 +		theApp.skipBiosFile = skipBiosFile;
   1.168 +
   1.169 +	int startFlags = 0, controllerFlags = 0, typeFlags = 0;
   1.170 +
   1.171 +	if (m_startOption == 0)
   1.172 +		startFlags |= MOVIE_START_FROM_SNAPSHOT;
   1.173 +	else if (m_startOption == 1)
   1.174 +		startFlags |= MOVIE_START_FROM_SRAM;
   1.175 +	//else
   1.176 +	//	startFlags = 0; // no SRAM or snapshot
   1.177 +
   1.178 +	if (m_systemOption == 0)
   1.179 +	{
   1.180 +		typeFlags	  |= MOVIE_TYPE_GBA;
   1.181 +		gbEmulatorType = 4;
   1.182 +	}
   1.183 +	else if (m_systemOption == 1)
   1.184 +	{
   1.185 +		typeFlags	  |= MOVIE_TYPE_GBC;
   1.186 +		gbEmulatorType = 1;
   1.187 +	}
   1.188 +	else if (m_systemOption == 2)
   1.189 +	{
   1.190 +		typeFlags	  |= MOVIE_TYPE_SGB;
   1.191 +		gbEmulatorType = 2;
   1.192 +	}
   1.193 +	else
   1.194 +	{
   1.195 +		gbEmulatorType = 3;  // plain old GB
   1.196 +	}
   1.197 +
   1.198 +	controllerFlags |= MOVIE_CONTROLLER(0);
   1.199 +	if (typeFlags & MOVIE_TYPE_SGB)
   1.200 +	{
   1.201 +		// XXX FIXME - the code for multiple controllers must be broken somehow
   1.202 +		// (it crashes strangely during FreezeToStream in SGB games)
   1.203 +
   1.204 +		// SGB games are free to request controllers while running, so we have to assume it needs all 4
   1.205 +///		controllerFlags |= MOVIE_CONTROLLER(1) | MOVIE_CONTROLLER(2) | MOVIE_CONTROLLER(3);
   1.206 +	}
   1.207 +
   1.208 +	// get author and movie info from the edit fields:
   1.209 +	char info [MOVIE_METADATA_SIZE], buffer [MOVIE_METADATA_SIZE];
   1.210 +
   1.211 +	GetDlgItem(IDC_EDIT_AUTHOR)->GetWindowText(buffer, MOVIE_METADATA_AUTHOR_SIZE);
   1.212 +	strncpy(info, buffer, MOVIE_METADATA_AUTHOR_SIZE);
   1.213 +	info[MOVIE_METADATA_AUTHOR_SIZE - 1] = '\0';
   1.214 +
   1.215 +	GetDlgItem(IDC_EDIT_DESCRIPTION)->GetWindowText(buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
   1.216 +	strncpy(info + MOVIE_METADATA_AUTHOR_SIZE, buffer, MOVIE_METADATA_SIZE - MOVIE_METADATA_AUTHOR_SIZE);
   1.217 +	info[MOVIE_METADATA_SIZE - 1] = '\0';
   1.218 +
   1.219 +	if (memLagTempEnabled && systemCartridgeType == 0)
   1.220 +	{
   1.221 +		// lag reduction is off -- if the user didn't turn it off, silently turn it back on, otherwise ask
   1.222 +		int ans = !memLagEnabled ? IDYES : AfxGetApp()->m_pMainWnd->MessageBox(
   1.223 +		    "Lag reduction is currently OFF.\nIt is recommended that you turn this ON for recording.\nWould you like to turn it on now?",
   1.224 +		    "Warning",
   1.225 +		    MB_YESNOCANCEL | MB_ICONWARNING);
   1.226 +		switch (ans)
   1.227 +		{
   1.228 +		case IDYES:
   1.229 +			extern void SetPrefetchHack(bool);
   1.230 +			SetPrefetchHack(true);
   1.231 +			break;
   1.232 +		case IDNO:
   1.233 +			break;
   1.234 +		case IDCANCEL:
   1.235 +			return;
   1.236 +		}
   1.237 +	}
   1.238 +
   1.239 +	CString movieName;
   1.240 +	GetDlgItem(IDC_MOVIE_FILENAME)->GetWindowText(movieName);
   1.241 +
   1.242 +	// actually make the movie file:
   1.243 +	int code = VBAMovieCreate(movieName, info, startFlags, controllerFlags, typeFlags);
   1.244 +
   1.245 +	if (code != MOVIE_SUCCESS)
   1.246 +	{
   1.247 +		systemMessage(0, "Failed to create movie %s", (const char *)movieName);
   1.248 +		return;
   1.249 +	}
   1.250 +
   1.251 +	OnOK();
   1.252 +}
   1.253 +
   1.254 +void MovieCreate::OnBnClickedCancel()
   1.255 +{
   1.256 +	OnCancel();
   1.257 +}
   1.258 +
   1.259 +void MovieCreate::OnBnClickedRecstart()
   1.260 +{
   1.261 +	m_startOption = 2;
   1.262 +	if (systemCartridgeType == 0)
   1.263 +	{
   1.264 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
   1.265 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
   1.266 +	}
   1.267 +	else
   1.268 +	{
   1.269 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
   1.270 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
   1.271 +		GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
   1.272 +	}
   1.273 +}
   1.274 +
   1.275 +void MovieCreate::OnBnClickedRecreset()
   1.276 +{
   1.277 +	m_startOption = 1;
   1.278 +	if (systemCartridgeType == 0)
   1.279 +	{
   1.280 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(TRUE);
   1.281 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(TRUE);
   1.282 +	}
   1.283 +	else
   1.284 +	{
   1.285 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(GBC_CAPABLE);
   1.286 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(SGB_CAPABLE);
   1.287 +		GetDlgItem(IDC_REC_GB)->EnableWindow(TRUE);
   1.288 +	}
   1.289 +}
   1.290 +
   1.291 +void MovieCreate::OnBnClickedRecnow()
   1.292 +{
   1.293 +	m_startOption = 0;
   1.294 +
   1.295 +	// starting from emulator bios file from a snapshot made while playing with GBA bios file won't work
   1.296 +	if (systemCartridgeType == 0 && useBios)
   1.297 +	{
   1.298 +		if (m_biosOption == 1)
   1.299 +		{
   1.300 +			OnBnClickedRecGbabios();
   1.301 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
   1.302 +		}
   1.303 +		GetDlgItem(IDC_REC_EMUBIOS)->EnableWindow(FALSE);
   1.304 +	}
   1.305 +
   1.306 +	// "with intro" distinction makes no sense when continuing from snapshot
   1.307 +	if (systemCartridgeType == 0)
   1.308 +	{
   1.309 +		if (m_biosOption == 3)
   1.310 +		{
   1.311 +			OnBnClickedRecGbabios();
   1.312 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_NOBIOS + m_biosOption);
   1.313 +		}
   1.314 +		GetDlgItem(IDC_REC_GBABIOSINTRO)->EnableWindow(FALSE);
   1.315 +	}
   1.316 +
   1.317 +	// can't switch systems while recording from snapshot!
   1.318 +	if (systemCartridgeType != 0)
   1.319 +	{
   1.320 +		int curSystemOption = (gbCgbMode == 1 ? 1 : (gbSgbMode == 1 ? 2 : 3)); // GBC, SGB, or GB
   1.321 +		GetDlgItem(IDC_REC_GBC)->EnableWindow(curSystemOption == 1);
   1.322 +		GetDlgItem(IDC_REC_SGB)->EnableWindow(curSystemOption == 2);
   1.323 +		GetDlgItem(IDC_REC_GB)->EnableWindow(curSystemOption == 3);
   1.324 +		m_systemOption = curSystemOption;
   1.325 +		CheckRadioButton(IDC_REC_GBA, IDC_REC_GB, IDC_REC_GBA + m_systemOption);
   1.326 +	}
   1.327 +}
   1.328 +
   1.329 +void MovieCreate::OnBnClickedRecGba()
   1.330 +{
   1.331 +	m_systemOption = 0;
   1.332 +}
   1.333 +
   1.334 +void MovieCreate::OnBnClickedRecGbc()
   1.335 +{
   1.336 +	m_systemOption = 1;
   1.337 +}
   1.338 +
   1.339 +void MovieCreate::OnBnClickedRecSgb()
   1.340 +{
   1.341 +	m_systemOption = 2;
   1.342 +}
   1.343 +
   1.344 +void MovieCreate::OnBnClickedRecGb()
   1.345 +{
   1.346 +	m_systemOption = 3;
   1.347 +}
   1.348 +
   1.349 +void MovieCreate::OnBnClickedRecNobios()
   1.350 +{
   1.351 +	m_biosOption = 0;
   1.352 +}
   1.353 +
   1.354 +void MovieCreate::OnBnClickedRecEmubios()
   1.355 +{
   1.356 +	m_biosOption = 1;
   1.357 +}
   1.358 +
   1.359 +void MovieCreate::OnBnClickedRecGbabios()
   1.360 +{
   1.361 +	if (utilCheckBIOS(theApp.biosFileName, 4))
   1.362 +		m_biosOption = 2;
   1.363 +	else
   1.364 +	{
   1.365 +		((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
   1.366 +		if (utilCheckBIOS(theApp.biosFileName, 4))
   1.367 +			m_biosOption = 2;
   1.368 +		else
   1.369 +		{
   1.370 +			systemMessage(0, "This option requires a valid GBA BIOS file.");
   1.371 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
   1.372 +		}
   1.373 +	}
   1.374 +}
   1.375 +
   1.376 +void MovieCreate::OnBnClickedRecGbabiosintro()
   1.377 +{
   1.378 +	if (utilCheckBIOS(theApp.biosFileName, 4))
   1.379 +		m_biosOption = 3;
   1.380 +	else
   1.381 +	{
   1.382 +		((MainWnd *)theApp.m_pMainWnd)->OnOptionsEmulatorSelectbiosfile();
   1.383 +		if (utilCheckBIOS(theApp.biosFileName, 4))
   1.384 +			m_biosOption = 3;
   1.385 +		else
   1.386 +		{
   1.387 +			systemMessage(0, "This option requires a valid GBA BIOS file.");
   1.388 +			CheckRadioButton(IDC_REC_NOBIOS, IDC_REC_GBABIOSINTRO, IDC_REC_EMUBIOS);
   1.389 +		}
   1.390 +	}
   1.391 +}
   1.392 +