mirror of
https://github.com/SourMesen/Mesen-S.git
synced 2024-06-23 14:52:12 -04:00
Initialize all ram (vram, cgram, oam, work ram, save ram) based on ram power on state setting
This commit is contained in:
parent
f16970a2fd
commit
f282675003
|
@ -5,6 +5,7 @@
|
|||
#include "MemoryManager.h"
|
||||
#include "IMemoryHandler.h"
|
||||
#include "MessageManager.h"
|
||||
#include "EmuSettings.h"
|
||||
#include "../Utilities/HexUtilities.h"
|
||||
#include "../Utilities/VirtualFile.h"
|
||||
#include "../Utilities/FolderUtilities.h"
|
||||
|
@ -19,7 +20,7 @@ BaseCartridge::~BaseCartridge()
|
|||
delete[] _saveRam;
|
||||
}
|
||||
|
||||
shared_ptr<BaseCartridge> BaseCartridge::CreateCartridge(VirtualFile &romFile, VirtualFile &patchFile)
|
||||
shared_ptr<BaseCartridge> BaseCartridge::CreateCartridge(EmuSettings* settings, VirtualFile &romFile, VirtualFile &patchFile)
|
||||
{
|
||||
if(romFile.IsValid()) {
|
||||
shared_ptr<BaseCartridge> cart(new BaseCartridge());
|
||||
|
@ -37,6 +38,7 @@ shared_ptr<BaseCartridge> BaseCartridge::CreateCartridge(VirtualFile &romFile, V
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
cart->_settings = settings;
|
||||
cart->_romPath = romFile;
|
||||
cart->_prgRomSize = (uint32_t)romData.size();
|
||||
cart->_prgRom = new uint8_t[cart->_prgRomSize];
|
||||
|
@ -156,6 +158,7 @@ void BaseCartridge::Init()
|
|||
|
||||
_saveRamSize = _cartInfo.SramSize > 0 ? 1024 * (1 << _cartInfo.SramSize) : 0;
|
||||
_saveRam = new uint8_t[_saveRamSize];
|
||||
_settings->InitializeRam(_saveRam, _saveRamSize);
|
||||
|
||||
LoadBattery();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
class MemoryManager;
|
||||
class VirtualFile;
|
||||
class EmuSettings;
|
||||
|
||||
namespace CartFlags
|
||||
{
|
||||
|
@ -23,6 +24,8 @@ namespace CartFlags
|
|||
class BaseCartridge : public ISerializable
|
||||
{
|
||||
private:
|
||||
EmuSettings *_settings;
|
||||
|
||||
vector<unique_ptr<IMemoryHandler>> _prgRomHandlers;
|
||||
vector<unique_ptr<IMemoryHandler>> _saveRamHandlers;
|
||||
SnesCartInformation _cartInfo;
|
||||
|
@ -51,7 +54,7 @@ private:
|
|||
public:
|
||||
virtual ~BaseCartridge();
|
||||
|
||||
static shared_ptr<BaseCartridge> CreateCartridge(VirtualFile &romFile, VirtualFile &patchFile);
|
||||
static shared_ptr<BaseCartridge> CreateCartridge(EmuSettings* settings, VirtualFile &romFile, VirtualFile &patchFile);
|
||||
|
||||
void Init();
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom)
|
|||
_cart->SaveBattery();
|
||||
}
|
||||
|
||||
shared_ptr<BaseCartridge> cart = BaseCartridge::CreateCartridge(romFile, patchFile);
|
||||
shared_ptr<BaseCartridge> cart = BaseCartridge::CreateCartridge(_settings.get(), romFile, patchFile);
|
||||
if(cart) {
|
||||
if(stopRom) {
|
||||
Stop(false);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "stdafx.h"
|
||||
#include <random>
|
||||
#include "EmuSettings.h"
|
||||
#include "KeyManager.h"
|
||||
#include "MessageManager.h"
|
||||
|
@ -252,3 +253,20 @@ bool EmuSettings::CheckDebuggerFlag(DebuggerFlags flag)
|
|||
{
|
||||
return (_debuggerFlags & (int)flag) != 0;
|
||||
}
|
||||
|
||||
void EmuSettings::InitializeRam(void* data, uint32_t length)
|
||||
{
|
||||
switch(_emulation.RamPowerOnState) {
|
||||
default:
|
||||
case RamState::AllZeros: memset(data, 0, length); break;
|
||||
case RamState::AllOnes: memset(data, 0xFF, length); break;
|
||||
case RamState::Random:
|
||||
std::random_device rd;
|
||||
std::mt19937 mt(rd());
|
||||
std::uniform_int_distribution<> dist(0, 255);
|
||||
for(uint32_t i = 0; i < length; i++) {
|
||||
((uint8_t*)data)[i] = dist(mt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -67,4 +67,5 @@ public:
|
|||
|
||||
void SetDebuggerFlag(DebuggerFlags flag, bool enabled);
|
||||
bool CheckDebuggerFlag(DebuggerFlags flags);
|
||||
void InitializeRam(void* data, uint32_t length);
|
||||
};
|
|
@ -10,6 +10,7 @@
|
|||
#include "RamHandler.h"
|
||||
#include "MessageManager.h"
|
||||
#include "DebugTypes.h"
|
||||
#include "EmuSettings.h"
|
||||
#include "../Utilities/Serializer.h"
|
||||
#include "../Utilities/HexUtilities.h"
|
||||
|
||||
|
@ -24,6 +25,7 @@ void MemoryManager::Initialize(shared_ptr<Console> console)
|
|||
_ppu = console->GetPpu();
|
||||
|
||||
_workRam = new uint8_t[MemoryManager::WorkRamSize];
|
||||
_console->GetSettings()->InitializeRam(_workRam, MemoryManager::WorkRamSize);
|
||||
|
||||
_registerHandlerA.reset(new RegisterHandlerA(
|
||||
console->GetDmaController().get(),
|
||||
|
|
|
@ -33,6 +33,10 @@ Ppu::Ppu(shared_ptr<Console> console)
|
|||
_console = console;
|
||||
|
||||
_vram = new uint8_t[Ppu::VideoRamSize];
|
||||
_console->GetSettings()->InitializeRam(_vram, Ppu::VideoRamSize);
|
||||
_console->GetSettings()->InitializeRam(_cgram, Ppu::CgRamSize);
|
||||
_console->GetSettings()->InitializeRam(_oamRam, Ppu::SpriteRamSize);
|
||||
|
||||
_outputBuffers[0] = new uint16_t[512 * 478];
|
||||
_outputBuffers[1] = new uint16_t[512 * 478];
|
||||
memset(_outputBuffers[0], 0, 512 * 478 * sizeof(uint16_t));
|
||||
|
|
|
@ -38,6 +38,7 @@ static constexpr char* MesenRegion = "mesen-s_region";
|
|||
static constexpr char* MesenAspectRatio = "mesen-s_aspect_ratio";
|
||||
static constexpr char* MesenOverscanVertical = "mesen-s_overscan_vertical";
|
||||
static constexpr char* MesenOverscanHorizontal = "mesen-s_overscan_horizontal";
|
||||
static constexpr char* MesenRamState = "mesen-s_ramstate";
|
||||
|
||||
extern "C" {
|
||||
void logMessage(retro_log_level level, const char* message)
|
||||
|
@ -100,6 +101,7 @@ extern "C" {
|
|||
{ MesenOverscanVertical, "Vertical Overscan; None|8px|16px" },
|
||||
{ MesenOverscanHorizontal, "Horizontal Overscan; None|8px|16px" },
|
||||
{ MesenAspectRatio, "Aspect Ratio; Auto|No Stretching|NTSC|PAL|4:3|16:9" },
|
||||
{ MesenRamState, "Default power-on state for RAM; All 0s (Default)|All 1s|Random Values" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
@ -275,6 +277,17 @@ extern "C" {
|
|||
}
|
||||
}
|
||||
|
||||
if(readVariable(MesenRamState, var)) {
|
||||
string value = string(var.value);
|
||||
if(value == "All 0s (Default)") {
|
||||
emulation.RamPowerOnState = RamState::AllZeros;
|
||||
} else if(value == "All 1s") {
|
||||
emulation.RamPowerOnState = RamState::AllOnes;
|
||||
} else if(value == "Random Values") {
|
||||
emulation.RamPowerOnState = RamState::Random;
|
||||
}
|
||||
}
|
||||
|
||||
auto getKeyCode = [=](int port, int retroKey) {
|
||||
return (port << 8) | (retroKey + 1);
|
||||
};
|
||||
|
|
|
@ -1051,7 +1051,7 @@
|
|||
<Value ID="Catalan">Català</Value>
|
||||
<Value ID="Chinese">中文</Value>
|
||||
</Enum>
|
||||
<Enum ID="RamPowerOnState">
|
||||
<Enum ID="RamState">
|
||||
<Value ID="AllZeros">All 0s (Default)</Value>
|
||||
<Value ID="AllOnes">All 1s</Value>
|
||||
<Value ID="Random">Random Values</Value>
|
||||
|
|
83
UI/Forms/Config/frmEmulationConfig.Designer.cs
generated
83
UI/Forms/Config/frmEmulationConfig.Designer.cs
generated
|
@ -30,6 +30,7 @@
|
|||
this.tabMain = new System.Windows.Forms.TabControl();
|
||||
this.tpgGeneral = new System.Windows.Forms.TabPage();
|
||||
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.flowLayoutPanel9 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.nudTurboSpeed = new Mesen.GUI.Controls.MesenNumericUpDown();
|
||||
this.lblTurboSpeedHint = new System.Windows.Forms.Label();
|
||||
|
@ -42,29 +43,36 @@
|
|||
this.flowLayoutPanel10 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.nudRewindSpeed = new Mesen.GUI.Controls.MesenNumericUpDown();
|
||||
this.lblRewindSpeedHint = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.cboRegion = new System.Windows.Forms.ComboBox();
|
||||
this.tpgAdvanced = new System.Windows.Forms.TabPage();
|
||||
this.flowLayoutPanel8 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.lblRamPowerOnState = new System.Windows.Forms.Label();
|
||||
this.cboRamPowerOnState = new System.Windows.Forms.ComboBox();
|
||||
this.tabMain.SuspendLayout();
|
||||
this.tpgGeneral.SuspendLayout();
|
||||
this.tableLayoutPanel4.SuspendLayout();
|
||||
this.flowLayoutPanel9.SuspendLayout();
|
||||
this.flowLayoutPanel6.SuspendLayout();
|
||||
this.flowLayoutPanel10.SuspendLayout();
|
||||
this.tpgAdvanced.SuspendLayout();
|
||||
this.flowLayoutPanel8.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// baseConfigPanel
|
||||
//
|
||||
this.baseConfigPanel.Location = new System.Drawing.Point(0, 290);
|
||||
this.baseConfigPanel.Size = new System.Drawing.Size(414, 29);
|
||||
this.baseConfigPanel.TabIndex = 4;
|
||||
//
|
||||
// tabMain
|
||||
//
|
||||
this.tabMain.Controls.Add(this.tpgGeneral);
|
||||
this.tabMain.Controls.Add(this.tpgAdvanced);
|
||||
this.tabMain.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tabMain.Location = new System.Drawing.Point(0, 0);
|
||||
this.tabMain.Name = "tabMain";
|
||||
this.tabMain.SelectedIndex = 0;
|
||||
this.tabMain.Size = new System.Drawing.Size(414, 290);
|
||||
this.tabMain.Size = new System.Drawing.Size(414, 319);
|
||||
this.tabMain.TabIndex = 2;
|
||||
//
|
||||
// tpgGeneral
|
||||
|
@ -104,6 +112,16 @@
|
|||
this.tableLayoutPanel4.Size = new System.Drawing.Size(400, 258);
|
||||
this.tableLayoutPanel4.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(3, 88);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(44, 13);
|
||||
this.label1.TabIndex = 17;
|
||||
this.label1.Text = "Region:";
|
||||
//
|
||||
// flowLayoutPanel9
|
||||
//
|
||||
this.flowLayoutPanel9.AutoSize = true;
|
||||
|
@ -290,16 +308,6 @@
|
|||
this.lblRewindSpeedHint.TabIndex = 2;
|
||||
this.lblRewindSpeedHint.Text = "% (0 = Maximum speed)";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(3, 88);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(44, 13);
|
||||
this.label1.TabIndex = 17;
|
||||
this.label1.Text = "Region:";
|
||||
//
|
||||
// cboRegion
|
||||
//
|
||||
this.cboRegion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
|
@ -309,6 +317,47 @@
|
|||
this.cboRegion.Size = new System.Drawing.Size(121, 21);
|
||||
this.cboRegion.TabIndex = 18;
|
||||
//
|
||||
// tpgAdvanced
|
||||
//
|
||||
this.tpgAdvanced.Controls.Add(this.flowLayoutPanel8);
|
||||
this.tpgAdvanced.Location = new System.Drawing.Point(4, 22);
|
||||
this.tpgAdvanced.Name = "tpgAdvanced";
|
||||
this.tpgAdvanced.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tpgAdvanced.Size = new System.Drawing.Size(406, 293);
|
||||
this.tpgAdvanced.TabIndex = 3;
|
||||
this.tpgAdvanced.Text = "Advanced";
|
||||
this.tpgAdvanced.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// flowLayoutPanel8
|
||||
//
|
||||
this.flowLayoutPanel8.Controls.Add(this.lblRamPowerOnState);
|
||||
this.flowLayoutPanel8.Controls.Add(this.cboRamPowerOnState);
|
||||
this.flowLayoutPanel8.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flowLayoutPanel8.Location = new System.Drawing.Point(3, 3);
|
||||
this.flowLayoutPanel8.Margin = new System.Windows.Forms.Padding(7, 0, 0, 0);
|
||||
this.flowLayoutPanel8.Name = "flowLayoutPanel8";
|
||||
this.flowLayoutPanel8.Size = new System.Drawing.Size(400, 287);
|
||||
this.flowLayoutPanel8.TabIndex = 4;
|
||||
//
|
||||
// lblRamPowerOnState
|
||||
//
|
||||
this.lblRamPowerOnState.Anchor = System.Windows.Forms.AnchorStyles.Left;
|
||||
this.lblRamPowerOnState.AutoSize = true;
|
||||
this.lblRamPowerOnState.Location = new System.Drawing.Point(3, 7);
|
||||
this.lblRamPowerOnState.Name = "lblRamPowerOnState";
|
||||
this.lblRamPowerOnState.Size = new System.Drawing.Size(159, 13);
|
||||
this.lblRamPowerOnState.TabIndex = 0;
|
||||
this.lblRamPowerOnState.Text = "Default power on state for RAM:";
|
||||
//
|
||||
// cboRamPowerOnState
|
||||
//
|
||||
this.cboRamPowerOnState.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cboRamPowerOnState.FormattingEnabled = true;
|
||||
this.cboRamPowerOnState.Location = new System.Drawing.Point(168, 3);
|
||||
this.cboRamPowerOnState.Name = "cboRamPowerOnState";
|
||||
this.cboRamPowerOnState.Size = new System.Drawing.Size(176, 21);
|
||||
this.cboRamPowerOnState.TabIndex = 1;
|
||||
//
|
||||
// frmEmulationConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -321,8 +370,8 @@
|
|||
this.Name = "frmEmulationConfig";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "Emulation Config";
|
||||
this.Controls.SetChildIndex(this.baseConfigPanel, 0);
|
||||
this.Controls.SetChildIndex(this.tabMain, 0);
|
||||
this.Controls.SetChildIndex(this.baseConfigPanel, 0);
|
||||
this.tabMain.ResumeLayout(false);
|
||||
this.tpgGeneral.ResumeLayout(false);
|
||||
this.tpgGeneral.PerformLayout();
|
||||
|
@ -334,7 +383,11 @@
|
|||
this.flowLayoutPanel6.PerformLayout();
|
||||
this.flowLayoutPanel10.ResumeLayout(false);
|
||||
this.flowLayoutPanel10.PerformLayout();
|
||||
this.tpgAdvanced.ResumeLayout(false);
|
||||
this.flowLayoutPanel8.ResumeLayout(false);
|
||||
this.flowLayoutPanel8.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
|
@ -357,5 +410,9 @@
|
|||
private System.Windows.Forms.Label lblRewindSpeedHint;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.ComboBox cboRegion;
|
||||
private System.Windows.Forms.TabPage tpgAdvanced;
|
||||
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel8;
|
||||
private System.Windows.Forms.Label lblRamPowerOnState;
|
||||
private System.Windows.Forms.ComboBox cboRamPowerOnState;
|
||||
}
|
||||
}
|
|
@ -26,6 +26,8 @@ namespace Mesen.GUI.Forms.Config
|
|||
AddBinding(nameof(EmulationConfig.TurboSpeed), nudTurboSpeed);
|
||||
AddBinding(nameof(EmulationConfig.RewindSpeed), nudRewindSpeed);
|
||||
AddBinding(nameof(EmulationConfig.Region), cboRegion);
|
||||
|
||||
AddBinding(nameof(EmulationConfig.RamPowerOnState), cboRamPowerOnState);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
|
|
Loading…
Reference in a new issue