Updated movie/savestate code to save new emulation flags (that can affect execution)

This commit is contained in:
Souryo 2017-02-25 15:15:44 -05:00
parent 3aaacb1bc3
commit db23821fe6
7 changed files with 121 additions and 69 deletions

View File

@ -279,18 +279,20 @@ void ControlManager::StreamState(bool saving)
ExpansionPortDevice expansionDevice;
ConsoleType consoleType;
bool hasFourScore;
bool useNes101Hvc101Behavior;
if(saving) {
nesModel = Console::GetNesModel();
expansionDevice = EmulationSettings::GetExpansionDevice();
consoleType = EmulationSettings::GetConsoleType();
hasFourScore = EmulationSettings::CheckFlag(EmulationFlags::HasFourScore);
useNes101Hvc101Behavior = EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior);
for(int i = 0; i < 4; i++) {
controllerTypes[i] = EmulationSettings::GetControllerType(i);
}
}
ArrayInfo<ControllerType> types = { controllerTypes, 4 };
Stream(_refreshState, _mousePosition.X, _mousePosition.Y, nesModel, expansionDevice, consoleType, types, hasFourScore);
Stream(_refreshState, _mousePosition.X, _mousePosition.Y, nesModel, expansionDevice, consoleType, types, hasFourScore, useNes101Hvc101Behavior);
if(!saving) {
EmulationSettings::SetNesModel(nesModel);
@ -300,11 +302,8 @@ void ControlManager::StreamState(bool saving)
EmulationSettings::SetControllerType(i, controllerTypes[i]);
}
if(hasFourScore) {
EmulationSettings::SetFlags(EmulationFlags::HasFourScore);
} else {
EmulationSettings::ClearFlags(EmulationFlags::HasFourScore);
}
EmulationSettings::SetFlagState(EmulationFlags::HasFourScore, hasFourScore);
EmulationSettings::SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, useNes101Hvc101Behavior);
UpdateControlDevices();
}

View File

@ -384,7 +384,7 @@ public:
return std::to_string(_versionMajor) + "." + std::to_string(_versionMinor) + "." + std::to_string(_versionRevision);
}
static void SetFlags(EmulationFlags flags)
static void SetFlags(uint64_t flags)
{
_flags |= flags;
@ -392,7 +392,19 @@ public:
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
}
static void ClearFlags(EmulationFlags flags)
static void SetFlagState(EmulationFlags flag, bool enabled)
{
if(enabled) {
_flags |= flag;
} else {
_flags &= ~flag;
}
_backgroundEnabled = !CheckFlag(EmulationFlags::DisableBackground);
_spritesEnabled = !CheckFlag(EmulationFlags::DisableSprites);
}
static void ClearFlags(uint64_t flags)
{
_flags &= ~flags;
}

View File

@ -215,10 +215,15 @@ struct MovieHeader
uint32_t ConsoleType;
uint8_t ControllerTypes[4];
uint32_t ExpansionDevice;
uint32_t OverclockRate;
bool OverclockAdjustApu;
uint32_t ExtraScanlinesBeforeNmi;
uint32_t ExtraScanlinesAfterNmi;
uint32_t OverclockRate = 100;
bool OverclockAdjustApu = true;
uint32_t ExtraScanlinesBeforeNmi = 0;
uint32_t ExtraScanlinesAfterNmi = 0;
bool DisablePpu2004Reads = false;
bool DisablePaletteRead = false;
bool DisableOamAddrBug = false;
bool UseNes101Hvc101Behavior = false;
uint32_t CheatCount;
uint32_t FilenameLength;
};
@ -237,6 +242,10 @@ bool Movie::Save()
header.ExpansionDevice = (uint32_t)EmulationSettings::GetExpansionDevice();
header.OverclockRate = (uint32_t)EmulationSettings::GetOverclockRate();
header.OverclockAdjustApu = EmulationSettings::GetOverclockAdjustApu();
header.DisablePpu2004Reads = EmulationSettings::CheckFlag(EmulationFlags::DisablePpu2004Reads);
header.DisablePaletteRead = EmulationSettings::CheckFlag(EmulationFlags::DisablePaletteRead);
header.DisableOamAddrBug = EmulationSettings::CheckFlag(EmulationFlags::DisableOamAddrBug);
header.UseNes101Hvc101Behavior = EmulationSettings::CheckFlag(EmulationFlags::UseNes101Hvc101Behavior);
for(int port = 0; port < 4; port++) {
header.ControllerTypes[port] = (uint32_t)EmulationSettings::GetControllerType(port);
}
@ -258,6 +267,10 @@ bool Movie::Save()
_file.write((char*)&header.OverclockAdjustApu, sizeof(header.OverclockAdjustApu));
_file.write((char*)&header.ExtraScanlinesBeforeNmi, sizeof(header.ExtraScanlinesBeforeNmi));
_file.write((char*)&header.ExtraScanlinesAfterNmi, sizeof(header.ExtraScanlinesAfterNmi));
_file.write((char*)&header.DisablePpu2004Reads, sizeof(header.DisablePpu2004Reads));
_file.write((char*)&header.DisablePaletteRead, sizeof(header.DisablePaletteRead));
_file.write((char*)&header.DisableOamAddrBug, sizeof(header.DisableOamAddrBug));
_file.write((char*)&header.UseNes101Hvc101Behavior, sizeof(header.UseNes101Hvc101Behavior));
_file.write((char*)&header.CheatCount, sizeof(header.CheatCount));
_file.write((char*)&header.FilenameLength, sizeof(header.FilenameLength));
@ -331,14 +344,25 @@ bool Movie::Load(std::stringstream &file, bool autoLoadRom)
//New fields in version 3
file.read((char*)&header.OverclockRate, sizeof(header.OverclockRate));
file.read((char*)&header.OverclockAdjustApu, sizeof(header.OverclockAdjustApu));
EmulationSettings::SetOverclockRate(header.OverclockRate, header.OverclockAdjustApu);
if(header.MovieFormatVersion >= 4) {
file.read((char*)&header.ExtraScanlinesBeforeNmi, sizeof(header.ExtraScanlinesBeforeNmi));
file.read((char*)&header.ExtraScanlinesAfterNmi, sizeof(header.ExtraScanlinesAfterNmi));
EmulationSettings::SetPpuNmiConfig(header.ExtraScanlinesBeforeNmi, header.ExtraScanlinesAfterNmi);
}
}
if(header.MovieFormatVersion >= 4) {
file.read((char*)&header.ExtraScanlinesBeforeNmi, sizeof(header.ExtraScanlinesBeforeNmi));
file.read((char*)&header.ExtraScanlinesAfterNmi, sizeof(header.ExtraScanlinesAfterNmi));
}
if(header.MovieFormatVersion >= 5) {
file.read((char*)&header.DisablePpu2004Reads, sizeof(header.DisablePpu2004Reads));
file.read((char*)&header.DisablePaletteRead, sizeof(header.DisablePaletteRead));
file.read((char*)&header.DisableOamAddrBug, sizeof(header.DisableOamAddrBug));
file.read((char*)&header.UseNes101Hvc101Behavior, sizeof(header.UseNes101Hvc101Behavior));
}
EmulationSettings::SetOverclockRate(header.OverclockRate, header.OverclockAdjustApu);
EmulationSettings::SetPpuNmiConfig(header.ExtraScanlinesBeforeNmi, header.ExtraScanlinesAfterNmi);
EmulationSettings::SetFlagState(EmulationFlags::UseNes101Hvc101Behavior, header.UseNes101Hvc101Behavior);
EmulationSettings::SetFlagState(EmulationFlags::DisablePpu2004Reads, header.DisablePpu2004Reads);
EmulationSettings::SetFlagState(EmulationFlags::DisablePaletteRead, header.DisablePaletteRead);
EmulationSettings::SetFlagState(EmulationFlags::DisableOamAddrBug, header.DisableOamAddrBug);
file.read((char*)&header.CheatCount, sizeof(header.CheatCount));
file.read((char*)&header.FilenameLength, sizeof(header.FilenameLength));
@ -351,7 +375,6 @@ bool Movie::Load(std::stringstream &file, bool autoLoadRom)
char* romFilename = new char[header.FilenameLength + 1];
memset(romFilename, 0, header.FilenameLength + 1);
file.read((char*)romFilename, header.FilenameLength);
delete[] romFilename;
_cheatList.clear();
CodeInfo cheatCode;
@ -402,5 +425,7 @@ bool Movie::Load(std::stringstream &file, bool autoLoadRom)
} else {
MessageManager::DisplayMessage("Movies", "MovieMissingRom", romFilename);
}
delete[] romFilename;
return loadedGame;
}

View File

@ -14,7 +14,7 @@ class Movie
{
private:
static shared_ptr<Movie> _instance;
const uint32_t MovieFormatVersion = 4;
const uint32_t MovieFormatVersion = 5;
bool _recording = false;
bool _playing = false;
uint8_t _counter[4];

View File

@ -1011,6 +1011,16 @@ void PPU::StreamState(bool saving)
ArrayInfo<uint8_t> secondarySpriteRam = { _secondarySpriteRAM, 0x20 };
ArrayInfo<int32_t> openBusDecayStamp = { _openBusDecayStamp, 8 };
bool disablePpu2004Reads;
bool disablePaletteRead;
bool disableOamAddrBug;
if(saving) {
disablePpu2004Reads = EmulationSettings::CheckFlag(EmulationFlags::DisablePpu2004Reads);
disablePaletteRead = EmulationSettings::CheckFlag(EmulationFlags::DisablePaletteRead);
disableOamAddrBug = EmulationSettings::CheckFlag(EmulationFlags::DisableOamAddrBug);
}
uint16_t unusedSpriteDmaAddr = 0;
uint16_t unusedSpriteDmaCounter = 0;
@ -1022,13 +1032,17 @@ void PPU::StreamState(bool saving)
_nextTile.PaletteOffset, _nextTile.TileAddr, _previousTile.LowByte, _previousTile.HighByte, _previousTile.PaletteOffset, _spriteIndex, _spriteCount,
_secondaryOAMAddr, _sprite0Visible, _oamCopybuffer, _spriteInRange, _sprite0Added, _spriteAddrH, _spriteAddrL, _oamCopyDone, _nesModel, unusedSpriteDmaAddr,
unusedSpriteDmaCounter, _prevRenderingEnabled, _renderingEnabled, _openBus, _ignoreVramRead, _skipScrollingIncrement, paletteRam, spriteRam, secondarySpriteRam,
openBusDecayStamp, _cyclesNeeded);
openBusDecayStamp, _cyclesNeeded, disablePpu2004Reads, disablePaletteRead, disableOamAddrBug);
for(int i = 0; i < 64; i++) {
Stream(_spriteTiles[i].SpriteX, _spriteTiles[i].LowByte, _spriteTiles[i].HighByte, _spriteTiles[i].PaletteOffset, _spriteTiles[i].HorizontalMirror, _spriteTiles[i].BackgroundPriority);
}
if(!saving) {
EmulationSettings::SetFlagState(EmulationFlags::DisablePpu2004Reads, disablePpu2004Reads);
EmulationSettings::SetFlagState(EmulationFlags::DisablePaletteRead, disablePaletteRead);
EmulationSettings::SetFlagState(EmulationFlags::DisableOamAddrBug, disableOamAddrBug);
SetNesModel(_nesModel);
UpdateMinimumDrawCycles();
}

View File

@ -29,7 +29,7 @@
{
this.tabMain = new System.Windows.Forms.TabControl();
this.tpgControllers = new System.Windows.Forms.TabPage();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.tlpControllers = new System.Windows.Forms.TableLayoutPanel();
this.btnSetupP4 = new System.Windows.Forms.Button();
this.btnSetupP3 = new System.Windows.Forms.Button();
this.lblPlayer1 = new System.Windows.Forms.Label();
@ -63,7 +63,7 @@
this.cboDisplayInputPosition = new System.Windows.Forms.ComboBox();
this.tabMain.SuspendLayout();
this.tpgControllers.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.tlpControllers.SuspendLayout();
this.tpgAdvanced.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.grpDisplayInput.SuspendLayout();
@ -90,7 +90,7 @@
//
// tpgControllers
//
this.tpgControllers.Controls.Add(this.tableLayoutPanel1);
this.tpgControllers.Controls.Add(this.tlpControllers);
this.tpgControllers.Location = new System.Drawing.Point(4, 22);
this.tpgControllers.Name = "tpgControllers";
this.tpgControllers.Size = new System.Drawing.Size(362, 225);
@ -98,46 +98,46 @@
this.tpgControllers.Text = "Controllers";
this.tpgControllers.UseVisualStyleBackColor = true;
//
// tableLayoutPanel1
// tlpControllers
//
this.tableLayoutPanel1.ColumnCount = 3;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel1.Controls.Add(this.btnSetupP4, 2, 7);
this.tableLayoutPanel1.Controls.Add(this.btnSetupP3, 2, 6);
this.tableLayoutPanel1.Controls.Add(this.lblPlayer1, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.lblPlayer2, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.cboPlayer4, 1, 7);
this.tableLayoutPanel1.Controls.Add(this.cboPlayer3, 1, 6);
this.tableLayoutPanel1.Controls.Add(this.cboPlayer1, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.lblPlayer4, 0, 7);
this.tableLayoutPanel1.Controls.Add(this.cboPlayer2, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.lblPlayer3, 0, 6);
this.tableLayoutPanel1.Controls.Add(this.btnSetupP1, 2, 2);
this.tableLayoutPanel1.Controls.Add(this.btnSetupP2, 2, 3);
this.tableLayoutPanel1.Controls.Add(this.lblNesType, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.cboConsoleType, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.lblExpansionPort, 0, 5);
this.tableLayoutPanel1.Controls.Add(this.cboExpansionPort, 1, 5);
this.tableLayoutPanel1.Controls.Add(this.chkFourScore, 0, 4);
this.tableLayoutPanel1.Controls.Add(this.chkAutoConfigureInput, 0, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 10;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(362, 225);
this.tableLayoutPanel1.TabIndex = 0;
this.tlpControllers.ColumnCount = 3;
this.tlpControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tlpControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpControllers.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tlpControllers.Controls.Add(this.btnSetupP4, 2, 7);
this.tlpControllers.Controls.Add(this.btnSetupP3, 2, 6);
this.tlpControllers.Controls.Add(this.lblPlayer1, 0, 2);
this.tlpControllers.Controls.Add(this.lblPlayer2, 0, 3);
this.tlpControllers.Controls.Add(this.cboPlayer4, 1, 7);
this.tlpControllers.Controls.Add(this.cboPlayer3, 1, 6);
this.tlpControllers.Controls.Add(this.cboPlayer1, 1, 2);
this.tlpControllers.Controls.Add(this.lblPlayer4, 0, 7);
this.tlpControllers.Controls.Add(this.cboPlayer2, 1, 3);
this.tlpControllers.Controls.Add(this.lblPlayer3, 0, 6);
this.tlpControllers.Controls.Add(this.btnSetupP1, 2, 2);
this.tlpControllers.Controls.Add(this.btnSetupP2, 2, 3);
this.tlpControllers.Controls.Add(this.lblNesType, 0, 0);
this.tlpControllers.Controls.Add(this.cboConsoleType, 1, 0);
this.tlpControllers.Controls.Add(this.lblExpansionPort, 0, 5);
this.tlpControllers.Controls.Add(this.cboExpansionPort, 1, 5);
this.tlpControllers.Controls.Add(this.chkFourScore, 0, 4);
this.tlpControllers.Controls.Add(this.chkAutoConfigureInput, 0, 1);
this.tlpControllers.Dock = System.Windows.Forms.DockStyle.Fill;
this.tlpControllers.Location = new System.Drawing.Point(0, 0);
this.tlpControllers.Name = "tlpControllers";
this.tlpControllers.RowCount = 10;
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tlpControllers.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tlpControllers.Size = new System.Drawing.Size(362, 225);
this.tlpControllers.TabIndex = 0;
//
// btnSetupP4
//
@ -315,7 +315,7 @@
//
this.chkFourScore.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.chkFourScore.AutoSize = true;
this.tableLayoutPanel1.SetColumnSpan(this.chkFourScore, 2);
this.tlpControllers.SetColumnSpan(this.chkFourScore, 2);
this.chkFourScore.Location = new System.Drawing.Point(3, 113);
this.chkFourScore.Name = "chkFourScore";
this.chkFourScore.Size = new System.Drawing.Size(151, 17);
@ -327,7 +327,7 @@
// chkAutoConfigureInput
//
this.chkAutoConfigureInput.AutoSize = true;
this.tableLayoutPanel1.SetColumnSpan(this.chkAutoConfigureInput, 3);
this.tlpControllers.SetColumnSpan(this.chkAutoConfigureInput, 3);
this.chkAutoConfigureInput.Location = new System.Drawing.Point(3, 30);
this.chkAutoConfigureInput.Name = "chkAutoConfigureInput";
this.chkAutoConfigureInput.Size = new System.Drawing.Size(290, 17);
@ -497,8 +497,8 @@
this.Controls.SetChildIndex(this.tabMain, 0);
this.tabMain.ResumeLayout(false);
this.tpgControllers.ResumeLayout(false);
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.tlpControllers.ResumeLayout(false);
this.tlpControllers.PerformLayout();
this.tpgAdvanced.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.grpDisplayInput.ResumeLayout(false);
@ -516,7 +516,7 @@
private System.Windows.Forms.TabControl tabMain;
private System.Windows.Forms.TabPage tpgControllers;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.TableLayoutPanel tlpControllers;
private System.Windows.Forms.Label lblPlayer1;
private System.Windows.Forms.Label lblPlayer2;
private System.Windows.Forms.Label lblPlayer3;

View File

@ -17,6 +17,8 @@ namespace Mesen.GUI.Forms.Config
{
InitializeComponent();
tlpControllers.Enabled = !InteropEmu.MoviePlaying() && !InteropEmu.MovieRecording();
InteropEmu.UpdateInputDevices();
Entity = ConfigManager.Config.InputInfo;