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