2014-06-14 15:27:55 +00:00
|
|
|
#include "stdafx.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include <thread>
|
2014-06-14 15:27:55 +00:00
|
|
|
#include "Console.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include "BaseMapper.h"
|
2016-05-01 00:08:53 +00:00
|
|
|
#include "ControlManager.h"
|
|
|
|
#include "VsControlManager.h"
|
2014-06-24 06:47:32 +00:00
|
|
|
#include "MapperFactory.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include "Debugger.h"
|
2015-07-18 00:58:57 +00:00
|
|
|
#include "MessageManager.h"
|
2016-01-29 01:47:16 +00:00
|
|
|
#include "RomLoader.h"
|
2015-07-18 00:58:57 +00:00
|
|
|
#include "EmulationSettings.h"
|
2014-06-23 23:02:09 +00:00
|
|
|
#include "../Utilities/Timer.h"
|
2014-07-09 22:29:07 +00:00
|
|
|
#include "../Utilities/FolderUtilities.h"
|
2015-08-15 01:50:14 +00:00
|
|
|
#include "HdPpu.h"
|
2016-01-15 00:33:16 +00:00
|
|
|
#include "SoundMixer.h"
|
2014-06-14 15:27:55 +00:00
|
|
|
|
2015-07-06 02:23:44 +00:00
|
|
|
shared_ptr<Console> Console::Instance(new Console());
|
2014-06-21 23:03:13 +00:00
|
|
|
|
2015-07-06 02:23:44 +00:00
|
|
|
Console::Console()
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console()
|
|
|
|
{
|
|
|
|
Movie::Stop();
|
|
|
|
}
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
shared_ptr<Console> Console::GetInstance()
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
|
|
|
return Console::Instance;
|
|
|
|
}
|
|
|
|
|
2015-07-21 03:20:41 +00:00
|
|
|
void Console::Release()
|
|
|
|
{
|
|
|
|
Console::Instance.reset(new Console());
|
|
|
|
}
|
|
|
|
|
2015-12-27 23:41:38 +00:00
|
|
|
void Console::Initialize(string romFilename, stringstream *filestream, string ipsFilename)
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
2015-07-05 23:05:33 +00:00
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::GameStopped);
|
2015-12-27 23:41:38 +00:00
|
|
|
shared_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(romFilename, filestream, ipsFilename);
|
2015-12-26 22:11:00 +00:00
|
|
|
|
2014-07-10 23:25:35 +00:00
|
|
|
if(mapper) {
|
2015-12-27 23:41:38 +00:00
|
|
|
_romFilepath = romFilename;
|
2015-08-31 01:04:21 +00:00
|
|
|
|
|
|
|
VideoDecoder::GetInstance()->StopThread();
|
2014-06-22 12:38:42 +00:00
|
|
|
|
2014-07-10 23:25:35 +00:00
|
|
|
_mapper = mapper;
|
|
|
|
_memoryManager.reset(new MemoryManager(_mapper));
|
|
|
|
_cpu.reset(new CPU(_memoryManager.get()));
|
2015-08-15 01:50:14 +00:00
|
|
|
if(HdNesPack::HasHdPack(_romFilepath)) {
|
|
|
|
_ppu.reset(new HdPpu(_memoryManager.get()));
|
|
|
|
} else {
|
|
|
|
_ppu.reset(new PPU(_memoryManager.get()));
|
|
|
|
}
|
2014-07-10 23:25:35 +00:00
|
|
|
_apu.reset(new APU(_memoryManager.get()));
|
2014-06-23 02:15:35 +00:00
|
|
|
|
2016-05-01 00:08:53 +00:00
|
|
|
_controlManager.reset(_mapper->IsVsSystem() ? new VsControlManager() : new ControlManager());
|
2014-06-21 19:43:41 +00:00
|
|
|
|
2014-07-10 23:25:35 +00:00
|
|
|
_memoryManager->RegisterIODevice(_mapper.get());
|
|
|
|
_memoryManager->RegisterIODevice(_ppu.get());
|
|
|
|
_memoryManager->RegisterIODevice(_apu.get());
|
|
|
|
_memoryManager->RegisterIODevice(_controlManager.get());
|
2014-06-19 23:58:15 +00:00
|
|
|
|
2016-02-11 02:41:51 +00:00
|
|
|
UpdateNesModel(false);
|
2016-01-23 05:52:06 +00:00
|
|
|
|
2015-07-06 02:23:44 +00:00
|
|
|
_initialized = true;
|
2016-01-29 03:34:23 +00:00
|
|
|
|
2016-06-04 12:55:52 +00:00
|
|
|
if(_debugger) {
|
|
|
|
StopDebugger();
|
|
|
|
GetDebugger();
|
|
|
|
}
|
|
|
|
|
2016-01-29 03:34:23 +00:00
|
|
|
ResetComponents(false);
|
2016-01-23 05:52:06 +00:00
|
|
|
|
2015-08-31 01:04:21 +00:00
|
|
|
VideoDecoder::GetInstance()->StartThread();
|
2015-07-06 02:23:44 +00:00
|
|
|
|
2015-12-27 23:41:38 +00:00
|
|
|
FolderUtilities::AddKnowGameFolder(FolderUtilities::GetFolderName(romFilename));
|
2016-02-19 18:05:04 +00:00
|
|
|
MessageManager::DisplayMessage("GameLoaded", FolderUtilities::GetFilename(romFilename, false));
|
2014-07-10 23:25:35 +00:00
|
|
|
} else {
|
2016-02-19 18:05:04 +00:00
|
|
|
MessageManager::DisplayMessage("Error", "CouldNotLoadFile", FolderUtilities::GetFilename(romFilename, true));
|
2014-07-10 23:25:35 +00:00
|
|
|
}
|
2015-07-06 02:23:44 +00:00
|
|
|
}
|
2014-07-01 16:44:01 +00:00
|
|
|
|
2015-12-27 23:41:38 +00:00
|
|
|
void Console::ApplyIpsPatch(string ipsFilename)
|
|
|
|
{
|
|
|
|
Console::Pause();
|
|
|
|
Instance->Initialize(GetROMPath(), nullptr, ipsFilename);
|
|
|
|
Console::Resume();
|
|
|
|
}
|
|
|
|
|
2015-12-26 22:11:00 +00:00
|
|
|
void Console::LoadROM(string filepath, stringstream *filestream)
|
2015-07-06 02:23:44 +00:00
|
|
|
{
|
|
|
|
Console::Pause();
|
2015-12-26 22:11:00 +00:00
|
|
|
Instance->Initialize(filepath, filestream);
|
2015-07-06 02:23:44 +00:00
|
|
|
Console::Resume();
|
2014-06-14 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
bool Console::LoadROM(string filename, uint32_t crc32Hash)
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2015-07-11 12:27:22 +00:00
|
|
|
string currentRomFilepath = Console::GetROMPath();
|
|
|
|
string currentFolder = FolderUtilities::GetFolderName(currentRomFilepath);
|
2015-07-06 02:23:44 +00:00
|
|
|
if(!currentRomFilepath.empty()) {
|
2016-01-29 01:47:16 +00:00
|
|
|
if(RomLoader::GetCRC32(Console::GetROMPath()) == crc32Hash) {
|
2015-07-06 02:23:44 +00:00
|
|
|
//Current game matches, no need to do anything
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-09 04:34:48 +00:00
|
|
|
}
|
2015-07-06 02:23:44 +00:00
|
|
|
|
2016-02-09 04:34:48 +00:00
|
|
|
for(string folder : FolderUtilities::GetKnowGameFolders()) {
|
|
|
|
string match = RomLoader::FindMatchingRomInFolder(folder, filename, crc32Hash, true);
|
2015-07-06 02:23:44 +00:00
|
|
|
if(!match.empty()) {
|
|
|
|
Console::LoadROM(match);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-09 04:34:48 +00:00
|
|
|
//Perform slow CRC32 search for ROM
|
2015-07-11 12:27:22 +00:00
|
|
|
for(string folder : FolderUtilities::GetKnowGameFolders()) {
|
2016-02-09 04:34:48 +00:00
|
|
|
string match = RomLoader::FindMatchingRomInFolder(folder, filename, crc32Hash, false);
|
|
|
|
if(!match.empty()) {
|
|
|
|
Console::LoadROM(match);
|
|
|
|
return true;
|
2015-07-06 02:23:44 +00:00
|
|
|
}
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
2016-02-09 04:34:48 +00:00
|
|
|
|
2015-07-06 02:23:44 +00:00
|
|
|
return false;
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
string Console::GetROMPath()
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
2015-07-11 12:27:22 +00:00
|
|
|
return Instance->_romFilepath;
|
2014-06-14 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 01:47:16 +00:00
|
|
|
uint32_t Console::GetCrc32()
|
|
|
|
{
|
|
|
|
return Instance->_mapper->GetCrc32();
|
|
|
|
}
|
|
|
|
|
2015-07-05 23:35:38 +00:00
|
|
|
void Console::Reset(bool softReset)
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2014-07-01 22:05:54 +00:00
|
|
|
Movie::Stop();
|
2015-07-06 02:23:44 +00:00
|
|
|
if(Instance->_initialized) {
|
2015-07-02 03:17:14 +00:00
|
|
|
Console::Pause();
|
2015-12-26 22:11:00 +00:00
|
|
|
if(softReset) {
|
|
|
|
Instance->ResetComponents(softReset);
|
|
|
|
} else {
|
|
|
|
//Full reset of all objects to ensure the emulator always starts in the exact same state
|
|
|
|
Instance->Initialize(Instance->_romFilepath);
|
|
|
|
}
|
2015-07-02 03:17:14 +00:00
|
|
|
Console::Resume();
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
2014-06-14 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 17:30:02 +00:00
|
|
|
void Console::ResetComponents(bool softReset)
|
2014-06-24 06:47:32 +00:00
|
|
|
{
|
2015-07-06 02:23:44 +00:00
|
|
|
Movie::Stop();
|
|
|
|
|
2016-01-21 01:05:18 +00:00
|
|
|
_memoryManager->Reset(softReset);
|
2014-06-24 06:47:32 +00:00
|
|
|
_ppu->Reset();
|
2015-07-19 05:30:13 +00:00
|
|
|
_apu->Reset(softReset);
|
2015-07-02 03:17:14 +00:00
|
|
|
_cpu->Reset(softReset);
|
2015-07-06 00:30:39 +00:00
|
|
|
|
2016-01-15 00:33:16 +00:00
|
|
|
SoundMixer::StopAudio(true);
|
2015-08-25 00:27:07 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
if(softReset) {
|
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::GameReset);
|
|
|
|
} else {
|
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::GameLoaded);
|
|
|
|
}
|
2014-06-24 06:47:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-21 01:48:55 +00:00
|
|
|
void Console::Stop()
|
|
|
|
{
|
|
|
|
_stop = true;
|
2015-07-18 00:58:57 +00:00
|
|
|
EmulationSettings::ClearFlags(EmulationFlags::Paused);
|
2015-08-22 02:42:44 +00:00
|
|
|
if(_debugger) {
|
|
|
|
_debugger->Run();
|
|
|
|
}
|
2015-07-05 23:12:41 +00:00
|
|
|
_stopLock.Acquire();
|
|
|
|
_stopLock.Release();
|
2014-06-21 23:03:13 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 16:44:01 +00:00
|
|
|
void Console::Pause()
|
|
|
|
{
|
2015-08-22 02:42:44 +00:00
|
|
|
if(Console::Instance->_debugger) {
|
|
|
|
//Make sure debugger resumes if we try to pause the emu, otherwise we will get deadlocked.
|
2016-06-04 12:55:52 +00:00
|
|
|
Console::Instance->_debugger->Suspend();
|
2015-08-22 02:42:44 +00:00
|
|
|
}
|
2015-07-06 02:23:44 +00:00
|
|
|
Console::Instance->_pauseLock.Acquire();
|
|
|
|
//Spin wait until emu pauses
|
|
|
|
Console::Instance->_runLock.Acquire();
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::Resume()
|
|
|
|
{
|
2015-07-06 02:23:44 +00:00
|
|
|
Console::Instance->_runLock.Release();
|
|
|
|
Console::Instance->_pauseLock.Release();
|
2016-06-04 12:55:52 +00:00
|
|
|
|
|
|
|
if(Console::Instance->_debugger) {
|
|
|
|
//Make sure debugger resumes if we try to pause the emu, otherwise we will get deadlocked.
|
|
|
|
Console::Instance->_debugger->Resume();
|
|
|
|
}
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 15:27:55 +00:00
|
|
|
void Console::Run()
|
|
|
|
{
|
2014-06-21 19:43:41 +00:00
|
|
|
Timer clockTimer;
|
2015-07-22 03:05:27 +00:00
|
|
|
double targetTime;
|
|
|
|
uint32_t lastFrameNumber = -1;
|
2015-07-15 01:51:39 +00:00
|
|
|
|
2015-07-05 23:05:33 +00:00
|
|
|
_runLock.Acquire();
|
|
|
|
_stopLock.Acquire();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2016-02-11 02:41:51 +00:00
|
|
|
_model = NesModel::Auto;
|
|
|
|
|
|
|
|
targetTime = UpdateNesModel(false);
|
2015-07-22 03:05:27 +00:00
|
|
|
|
2015-08-31 01:04:21 +00:00
|
|
|
VideoDecoder::GetInstance()->StartThread();
|
|
|
|
|
2014-06-21 19:43:41 +00:00
|
|
|
while(true) {
|
2016-02-12 03:59:31 +00:00
|
|
|
try {
|
|
|
|
_cpu->Exec();
|
|
|
|
} catch(const std::runtime_error &ex) {
|
2016-02-19 18:05:04 +00:00
|
|
|
MessageManager::DisplayMessage("Error", "GameCrash", ex.what());
|
2016-02-12 03:59:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-16 20:55:16 +00:00
|
|
|
uint32_t currentFrameNumber = PPU::GetFrameCount();
|
|
|
|
if(currentFrameNumber != lastFrameNumber) {
|
|
|
|
lastFrameNumber = currentFrameNumber;
|
2014-06-30 18:44:30 +00:00
|
|
|
|
2015-08-31 01:04:21 +00:00
|
|
|
//Sleep until we're ready to start the next frame
|
|
|
|
clockTimer.WaitUntil(targetTime);
|
|
|
|
|
2015-07-05 23:05:33 +00:00
|
|
|
if(!_pauseLock.IsFree()) {
|
2014-07-06 23:54:47 +00:00
|
|
|
//Need to temporarely pause the emu (to save/load a state, etc.)
|
2015-07-05 23:05:33 +00:00
|
|
|
_runLock.Release();
|
2014-07-06 23:54:47 +00:00
|
|
|
|
|
|
|
//Spin wait until we are allowed to start again
|
2015-07-05 23:05:33 +00:00
|
|
|
_pauseLock.WaitForRelease();
|
2014-07-01 16:44:01 +00:00
|
|
|
|
2015-07-05 23:05:33 +00:00
|
|
|
_runLock.Acquire();
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
2014-07-06 23:54:47 +00:00
|
|
|
|
2016-02-06 04:14:27 +00:00
|
|
|
bool paused = EmulationSettings::IsPaused();
|
2016-01-31 18:53:17 +00:00
|
|
|
if(paused && !_stop) {
|
2015-07-02 03:17:14 +00:00
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::GamePaused);
|
2015-07-05 23:05:33 +00:00
|
|
|
_runLock.Release();
|
2015-07-02 03:17:14 +00:00
|
|
|
|
|
|
|
//Prevent audio from looping endlessly while game is paused
|
2016-01-15 00:33:16 +00:00
|
|
|
SoundMixer::StopAudio();
|
2015-07-02 03:17:14 +00:00
|
|
|
|
2016-01-31 18:53:17 +00:00
|
|
|
while(paused) {
|
2014-07-10 01:48:54 +00:00
|
|
|
//Sleep until emulation is resumed
|
|
|
|
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(100));
|
2016-02-06 04:14:27 +00:00
|
|
|
paused = EmulationSettings::IsPaused();
|
2014-07-10 01:48:54 +00:00
|
|
|
}
|
2015-07-05 23:05:33 +00:00
|
|
|
_runLock.Acquire();
|
2015-07-02 03:17:14 +00:00
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::GameResumed);
|
2014-07-10 01:48:54 +00:00
|
|
|
}
|
2015-07-22 03:05:27 +00:00
|
|
|
|
2015-08-31 01:04:21 +00:00
|
|
|
//Get next target time, and adjust based on whether we are ahead or behind
|
|
|
|
double timeLag = EmulationSettings::GetEmulationSpeed() == 0 ? 0 : clockTimer.GetElapsedMS() - targetTime;
|
2016-02-11 02:41:51 +00:00
|
|
|
targetTime = UpdateNesModel(true);
|
2014-07-06 23:54:47 +00:00
|
|
|
clockTimer.Reset();
|
2015-08-31 01:04:21 +00:00
|
|
|
targetTime -= timeLag;
|
|
|
|
if(targetTime < 0) {
|
|
|
|
targetTime = 0;
|
|
|
|
}
|
2014-07-06 23:54:47 +00:00
|
|
|
|
|
|
|
if(_stop) {
|
|
|
|
_stop = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 22:20:56 +00:00
|
|
|
}
|
2016-01-15 00:33:16 +00:00
|
|
|
SoundMixer::StopAudio();
|
2015-12-26 22:11:00 +00:00
|
|
|
Movie::Stop();
|
2015-08-31 01:04:21 +00:00
|
|
|
|
|
|
|
VideoDecoder::GetInstance()->StopThread();
|
|
|
|
|
2016-01-31 05:41:33 +00:00
|
|
|
_initialized = false;
|
2016-01-29 03:34:23 +00:00
|
|
|
_romFilepath = "";
|
|
|
|
|
2015-07-05 23:05:33 +00:00
|
|
|
_stopLock.Release();
|
|
|
|
_runLock.Release();
|
2014-06-26 01:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-02-14 17:58:35 +00:00
|
|
|
bool Console::IsRunning()
|
|
|
|
{
|
|
|
|
return !Instance->_stopLock.IsFree();
|
|
|
|
}
|
|
|
|
|
2016-02-11 02:41:51 +00:00
|
|
|
double Console::UpdateNesModel(bool sendNotification)
|
2015-07-22 03:05:27 +00:00
|
|
|
{
|
2016-02-06 04:14:27 +00:00
|
|
|
bool configChanged = false;
|
|
|
|
if(EmulationSettings::NeedControllerUpdate()) {
|
|
|
|
_controlManager->UpdateControlDevices();
|
|
|
|
configChanged = true;
|
|
|
|
}
|
|
|
|
|
2015-07-22 03:05:27 +00:00
|
|
|
NesModel model = EmulationSettings::GetNesModel();
|
2015-08-25 00:27:07 +00:00
|
|
|
uint32_t emulationSpeed = EmulationSettings::GetEmulationSpeed();
|
2015-07-22 03:05:27 +00:00
|
|
|
if(model == NesModel::Auto) {
|
|
|
|
model = _mapper->IsPalRom() ? NesModel::PAL : NesModel::NTSC;
|
|
|
|
}
|
2016-02-06 04:14:27 +00:00
|
|
|
if(_model != model) {
|
|
|
|
_model = model;
|
|
|
|
configChanged = true;
|
|
|
|
}
|
2015-08-24 00:24:24 +00:00
|
|
|
|
2016-01-23 05:52:06 +00:00
|
|
|
double frameDelay;
|
2015-08-25 00:27:07 +00:00
|
|
|
if(emulationSpeed == 0) {
|
2015-08-24 00:24:24 +00:00
|
|
|
frameDelay = 0;
|
|
|
|
} else {
|
2016-01-31 00:33:32 +00:00
|
|
|
//60.1fps (NTSC), 50.01fps (PAL/Dendy)
|
|
|
|
switch(model) {
|
2016-06-03 03:56:11 +00:00
|
|
|
default:
|
2016-01-31 00:33:32 +00:00
|
|
|
case NesModel::NTSC: frameDelay = 16.63926405550947; break;
|
|
|
|
case NesModel::PAL:
|
|
|
|
case NesModel::Dendy: frameDelay = 19.99720920217466; break;
|
|
|
|
}
|
2015-08-25 00:27:07 +00:00
|
|
|
frameDelay /= (double)emulationSpeed / 100.0;
|
2015-08-24 00:24:24 +00:00
|
|
|
}
|
2015-08-25 00:27:07 +00:00
|
|
|
|
2015-07-22 03:05:27 +00:00
|
|
|
_ppu->SetNesModel(model);
|
|
|
|
_apu->SetNesModel(model);
|
2016-01-23 05:52:06 +00:00
|
|
|
|
2016-02-11 02:41:51 +00:00
|
|
|
if(configChanged && sendNotification) {
|
2016-02-06 04:14:27 +00:00
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged);
|
|
|
|
}
|
|
|
|
|
2016-01-23 05:52:06 +00:00
|
|
|
return frameDelay;
|
2015-07-22 03:05:27 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 16:44:01 +00:00
|
|
|
void Console::SaveState(ostream &saveStream)
|
2014-06-26 01:52:37 +00:00
|
|
|
{
|
2015-07-06 02:23:44 +00:00
|
|
|
if(Instance->_initialized) {
|
2014-07-06 23:54:47 +00:00
|
|
|
Instance->_cpu->SaveSnapshot(&saveStream);
|
|
|
|
Instance->_ppu->SaveSnapshot(&saveStream);
|
|
|
|
Instance->_memoryManager->SaveSnapshot(&saveStream);
|
|
|
|
Instance->_mapper->SaveSnapshot(&saveStream);
|
|
|
|
Instance->_apu->SaveSnapshot(&saveStream);
|
|
|
|
Instance->_controlManager->SaveSnapshot(&saveStream);
|
|
|
|
}
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
2014-06-26 01:52:37 +00:00
|
|
|
|
2014-07-01 16:44:01 +00:00
|
|
|
void Console::LoadState(istream &loadStream)
|
|
|
|
{
|
2015-07-06 02:23:44 +00:00
|
|
|
if(Instance->_initialized) {
|
2014-07-06 23:54:47 +00:00
|
|
|
Instance->_cpu->LoadSnapshot(&loadStream);
|
|
|
|
Instance->_ppu->LoadSnapshot(&loadStream);
|
|
|
|
Instance->_memoryManager->LoadSnapshot(&loadStream);
|
|
|
|
Instance->_mapper->LoadSnapshot(&loadStream);
|
|
|
|
Instance->_apu->LoadSnapshot(&loadStream);
|
|
|
|
Instance->_controlManager->LoadSnapshot(&loadStream);
|
2014-07-10 01:11:02 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
MessageManager::SendNotification(ConsoleNotificationType::StateLoaded);
|
2014-07-06 23:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::LoadState(uint8_t *buffer, uint32_t bufferSize)
|
|
|
|
{
|
|
|
|
stringstream stream;
|
|
|
|
stream.write((char*)buffer, bufferSize);
|
|
|
|
stream.seekg(0, ios::beg);
|
|
|
|
LoadState(stream);
|
2014-06-26 01:52:37 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 12:55:52 +00:00
|
|
|
std::shared_ptr<Debugger> Console::GetDebugger()
|
2015-06-24 23:26:19 +00:00
|
|
|
{
|
2015-08-22 02:42:44 +00:00
|
|
|
if(!_debugger) {
|
|
|
|
_debugger.reset(new Debugger(Console::Instance, _cpu, _ppu, _memoryManager, _mapper));
|
|
|
|
}
|
|
|
|
return _debugger;
|
2015-06-24 23:26:19 +00:00
|
|
|
}
|
2015-08-22 02:42:44 +00:00
|
|
|
|
|
|
|
void Console::StopDebugger()
|
|
|
|
{
|
|
|
|
_debugger.reset();
|
2016-02-06 04:14:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NesModel Console::GetNesModel()
|
|
|
|
{
|
|
|
|
return Instance->_model;
|
2015-08-22 02:42:44 +00:00
|
|
|
}
|