Emulation: Init sram/wram/chrram/ntram the same way as the internal ram

This commit is contained in:
Souryo 2016-08-24 20:48:14 -04:00
parent f4081bc1ee
commit 9d239daf3c
5 changed files with 32 additions and 18 deletions

View File

@ -1,5 +1,6 @@
#include "stdafx.h"
#include "BaseMapper.h"
#include <random>
#include <assert.h>
#include "../Utilities/FolderUtilities.h"
#include "CheatManager.h"
@ -257,6 +258,23 @@ void BaseMapper::SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memor
SetPpuMemoryMapping(startAddr, endAddr, page, memoryType);
}
}
void BaseMapper::InitializeRam(void* data, uint32_t length)
{
switch(EmulationSettings::GetRamPowerOnState()) {
default:
case RamPowerOnState::AllZeros: memset(data, 0, length); break;
case RamPowerOnState::AllOnes: memset(data, 0xFF, length); break;
case RamPowerOnState::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;
}
}
bool BaseMapper::HasBattery()
{
@ -329,7 +347,7 @@ void BaseMapper::InitializeChrRam(int32_t chrRamSize)
_chrRamSize = chrRamSize >= 0 ? chrRamSize : defaultRamSize;
if(_chrRamSize > 0) {
_chrRam = new uint8_t[_chrRamSize];
memset(_chrRam, 0, _chrRamSize);
InitializeRam(_chrRam, _chrRamSize);
}
}
@ -446,8 +464,8 @@ void BaseMapper::Initialize(RomData &romData)
_saveRam = new uint8_t[_saveRamSize];
_workRam = new uint8_t[_workRamSize];
memset(_saveRam, 0, _saveRamSize);
memset(_workRam, 0, _workRamSize);
InitializeRam(_saveRam, _saveRamSize);
InitializeRam(_workRam, _workRamSize);
if(romData.HasTrainer && _workRamSize >= 0x2000) {
memcpy(_workRam + 0x1000, romData.TrainerData.data(), 512);
}
@ -575,9 +593,11 @@ void BaseMapper::SetNametable(uint8_t index, uint8_t nametableIndex)
{
if(nametableIndex == 2 && _cartNametableRam[0] == nullptr) {
_cartNametableRam[0] = new uint8_t[0x400];
InitializeRam(_cartNametableRam[0], 0x400);
}
if(nametableIndex == 3 && _cartNametableRam[1] == nullptr) {
_cartNametableRam[1] = new uint8_t[0x400];
InitializeRam(_cartNametableRam[1], 0x400);
}
_nametableIndexes[index] = nametableIndex;

View File

@ -199,6 +199,8 @@ public:
virtual uint8_t ReadVRAM(uint16_t addr, MemoryOperationType type = MemoryOperationType::Read);
void WriteVRAM(uint16_t addr, uint8_t value);
void InitializeRam(void* data, uint32_t length);
//Debugger Helper Functions
uint8_t* GetPrgRom();
uint8_t* GetWorkRam();

View File

@ -3,7 +3,6 @@
#include "BaseMapper.h"
#include "Debugger.h"
#include "CheatManager.h"
#include <random>
//Used for open bus
uint8_t MemoryManager::_lastReadValue = 0;
@ -16,7 +15,7 @@ MemoryManager::MemoryManager(shared_ptr<BaseMapper> mapper)
_internalRAM = new uint8_t[InternalRAMSize];
for(int i = 0; i < 2; i++) {
_nametableRAM[i] = new uint8_t[NameTableScreenSize];
memset(_nametableRAM[i], 0, NameTableScreenSize);
_mapper->InitializeRam(_nametableRAM[i], NameTableScreenSize);
}
_mapper->SetDefaultNametables(_nametableRAM[0], _nametableRAM[1]);
@ -42,19 +41,7 @@ MemoryManager::~MemoryManager()
void MemoryManager::Reset(bool softReset)
{
if(!softReset) {
switch(EmulationSettings::GetRamPowerOnState()) {
default:
case RamPowerOnState::AllZeros: memset(_internalRAM, 0, InternalRAMSize); break;
case RamPowerOnState::AllOnes: memset(_internalRAM, 0xFF, InternalRAMSize); break;
case RamPowerOnState::Random:
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<> dist(0, 255);
for(int i = 0; i < InternalRAMSize; i++) {
_internalRAM[i] = dist(mt);
}
break;
}
_mapper->InitializeRam(_internalRAM, InternalRAMSize);
}
_mapper->Reset(softReset);

View File

@ -55,5 +55,6 @@ class MemoryManager: public Snapshotable
uint32_t ToAbsoluteChrAddress(uint16_t vramAddr);
static uint8_t GetOpenBus(uint8_t mask = 0xFF);
static void InitializeRam(uint8_t* data, uint32_t length);
};

View File

@ -25,6 +25,8 @@ namespace Mesen.GUI.Config
public UInt32 PpuExtraScanlinesBeforeNmi = 0;
public UInt32 PpuExtraScanlinesAfterNmi = 0;
public RamPowerOnState RamPowerOnState;
public bool ShowLagCounter = false;
public UInt32 EmulationSpeed = 100;
@ -46,6 +48,8 @@ namespace Mesen.GUI.Config
InteropEmu.SetOverclockRate(emulationInfo.OverclockRate, emulationInfo.OverclockAdjustApu);
InteropEmu.SetPpuNmiConfig(emulationInfo.PpuExtraScanlinesBeforeNmi, emulationInfo.PpuExtraScanlinesAfterNmi);
InteropEmu.SetRamPowerOnState(emulationInfo.RamPowerOnState);
}
}
}