2014-06-14 15:27:55 +00:00
|
|
|
#include "stdafx.h"
|
2019-06-22 20:33:59 +00:00
|
|
|
#include <random>
|
2014-06-14 15:27:55 +00:00
|
|
|
#include "Console.h"
|
2017-04-29 12:29:56 +00:00
|
|
|
#include "CPU.h"
|
|
|
|
#include "PPU.h"
|
|
|
|
#include "APU.h"
|
|
|
|
#include "MemoryManager.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-18 00:58:57 +00:00
|
|
|
#include "EmulationSettings.h"
|
2014-07-09 22:29:07 +00:00
|
|
|
#include "../Utilities/FolderUtilities.h"
|
2017-09-30 18:07:07 +00:00
|
|
|
#include "VirtualFile.h"
|
2017-06-28 23:00:08 +00:00
|
|
|
#include "HdBuilderPpu.h"
|
2015-08-15 01:50:14 +00:00
|
|
|
#include "HdPpu.h"
|
2016-01-15 00:33:16 +00:00
|
|
|
#include "SoundMixer.h"
|
2017-05-06 19:27:48 +00:00
|
|
|
#include "SaveStateManager.h"
|
2017-06-28 23:00:08 +00:00
|
|
|
#include "HdPackBuilder.h"
|
2017-08-19 20:46:57 +00:00
|
|
|
#include "HdAudioDevice.h"
|
2017-11-20 04:08:23 +00:00
|
|
|
#include "FDS.h"
|
|
|
|
#include "SystemActionManager.h"
|
|
|
|
#include "FdsSystemActionManager.h"
|
|
|
|
#include "VsSystemActionManager.h"
|
2017-11-25 02:38:12 +00:00
|
|
|
#include "FamilyBasicDataRecorder.h"
|
2017-11-20 04:08:23 +00:00
|
|
|
#include "IBarcodeReader.h"
|
|
|
|
#include "IBattery.h"
|
|
|
|
#include "KeyManager.h"
|
|
|
|
#include "BatteryManager.h"
|
2018-07-01 19:21:05 +00:00
|
|
|
#include "RomLoader.h"
|
|
|
|
#include "CheatManager.h"
|
|
|
|
#include "VideoDecoder.h"
|
|
|
|
#include "VideoRenderer.h"
|
2014-06-21 23:03:13 +00:00
|
|
|
|
2018-07-14 02:19:26 +00:00
|
|
|
Console::Console(shared_ptr<Console> master, EmulationSettings* initialSettings)
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2018-07-03 01:32:59 +00:00
|
|
|
_master = master;
|
2018-07-14 02:19:26 +00:00
|
|
|
|
|
|
|
if(_master) {
|
|
|
|
//Slave console should use the same settings as the master
|
|
|
|
_settings = _master->_settings;
|
|
|
|
} else {
|
|
|
|
if(initialSettings) {
|
|
|
|
_settings.reset(new EmulationSettings(*initialSettings));
|
|
|
|
} else {
|
|
|
|
_settings.reset(new EmulationSettings());
|
|
|
|
}
|
|
|
|
KeyManager::SetSettings(_settings.get());
|
|
|
|
}
|
|
|
|
|
2018-01-07 15:05:58 +00:00
|
|
|
_model = NesModel::NTSC;
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console()
|
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 18:29:56 +00:00
|
|
|
void Console::Init(retro_environment_t retroEnv)
|
2018-07-01 19:21:05 +00:00
|
|
|
{
|
2018-07-22 21:31:50 +00:00
|
|
|
_batteryManager.reset(new BatteryManager());
|
2018-07-03 01:32:59 +00:00
|
|
|
|
2022-04-06 18:29:56 +00:00
|
|
|
_videoRenderer.reset(new VideoRenderer(shared_from_this(), retroEnv));
|
2018-07-01 19:21:05 +00:00
|
|
|
_videoDecoder.reset(new VideoDecoder(shared_from_this()));
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
_saveStateManager.reset(new SaveStateManager(shared_from_this()));
|
2018-07-01 19:21:05 +00:00
|
|
|
_cheatManager.reset(new CheatManager(shared_from_this()));
|
2018-07-03 01:32:59 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_soundMixer.reset(new SoundMixer(shared_from_this()));
|
2018-07-03 01:32:59 +00:00
|
|
|
_soundMixer->SetNesModel(_model);
|
2018-07-01 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::Release(bool forShutdown)
|
|
|
|
{
|
2018-07-04 03:32:26 +00:00
|
|
|
if(_slave) {
|
|
|
|
_slave->Release(true);
|
|
|
|
_slave.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
if(forShutdown) {
|
|
|
|
_videoDecoder.reset();
|
2018-07-03 01:32:59 +00:00
|
|
|
_videoRenderer.reset();
|
|
|
|
|
|
|
|
_saveStateManager.reset();
|
2018-07-01 19:21:05 +00:00
|
|
|
_cheatManager.reset();
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
_soundMixer.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_hdPackBuilder.reset();
|
|
|
|
_hdData.reset();
|
|
|
|
_hdAudioDevice.reset();
|
|
|
|
|
|
|
|
_systemActionManager.reset();
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
_master.reset();
|
2018-07-01 19:21:05 +00:00
|
|
|
_cpu.reset();
|
|
|
|
_ppu.reset();
|
|
|
|
_apu.reset();
|
|
|
|
_mapper.reset();
|
|
|
|
_memoryManager.reset();
|
|
|
|
_controlManager.reset();
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 21:31:50 +00:00
|
|
|
shared_ptr<BatteryManager> Console::GetBatteryManager()
|
|
|
|
{
|
|
|
|
return _batteryManager;
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<SaveStateManager> Console::GetSaveStateManager()
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _saveStateManager;
|
2014-07-09 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<VideoDecoder> Console::GetVideoDecoder()
|
2015-07-21 03:20:41 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _videoDecoder;
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr<VideoRenderer> Console::GetVideoRenderer()
|
|
|
|
{
|
|
|
|
return _videoRenderer;
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
void Console::SaveBatteries()
|
|
|
|
{
|
2018-06-16 14:03:49 +00:00
|
|
|
shared_ptr<BaseMapper> mapper = _mapper;
|
|
|
|
shared_ptr<ControlManager> controlManager = _controlManager;
|
|
|
|
|
|
|
|
if(mapper) {
|
|
|
|
mapper->SaveBattery();
|
2018-01-05 00:03:47 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-06-16 14:03:49 +00:00
|
|
|
if(controlManager) {
|
|
|
|
shared_ptr<IBattery> device = std::dynamic_pointer_cast<IBattery>(controlManager->GetControlDevice(BaseControlDevice::ExpDevicePort));
|
2018-01-05 00:03:47 +00:00
|
|
|
if(device) {
|
|
|
|
device->SaveBattery();
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
2015-07-21 03:20:41 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
bool Console::LoadMatchingRom(string romName, HashInfo hashInfo)
|
|
|
|
{
|
|
|
|
if(_initialized) {
|
|
|
|
string currentRomFilepath = GetRomPath().GetFilePath();
|
|
|
|
if(!currentRomFilepath.empty()) {
|
2018-07-07 18:52:51 +00:00
|
|
|
HashInfo gameHashInfo = GetRomInfo().Hash;
|
|
|
|
if(gameHashInfo.Crc32 == hashInfo.Crc32 || gameHashInfo.Sha1.compare(hashInfo.Sha1) == 0 || gameHashInfo.PrgChrMd5.compare(hashInfo.PrgChrMd5) == 0) {
|
2018-07-01 19:21:05 +00:00
|
|
|
//Current game matches, power cycle game and return
|
|
|
|
PowerCycle();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string match = FindMatchingRom(romName, hashInfo);
|
|
|
|
if(!match.empty()) {
|
|
|
|
return Initialize(match);
|
|
|
|
}
|
2018-07-02 23:01:10 +00:00
|
|
|
return false;
|
2018-07-01 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string Console::FindMatchingRom(string romName, HashInfo hashInfo)
|
|
|
|
{
|
|
|
|
if(_initialized) {
|
|
|
|
VirtualFile currentRom = GetRomPath();
|
|
|
|
if(currentRom.IsValid() && !GetPatchFile().IsValid()) {
|
2018-07-07 18:52:51 +00:00
|
|
|
HashInfo gameHashInfo = GetRomInfo().Hash;
|
|
|
|
if(gameHashInfo.Crc32 == hashInfo.Crc32 || gameHashInfo.Sha1.compare(hashInfo.Sha1) == 0 || gameHashInfo.PrgChrMd5.compare(hashInfo.PrgChrMd5) == 0) {
|
2018-07-01 19:21:05 +00:00
|
|
|
//Current game matches
|
|
|
|
return currentRom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string lcRomname = romName;
|
|
|
|
std::transform(lcRomname.begin(), lcRomname.end(), lcRomname.begin(), ::tolower);
|
|
|
|
std::unordered_set<string> validExtensions = { { ".nes", ".fds", "*.unif", "*.unif", "*.nsf", "*.nsfe", "*.7z", "*.zip" } };
|
|
|
|
vector<string> romFiles;
|
|
|
|
for(string folder : FolderUtilities::GetKnownGameFolders()) {
|
|
|
|
vector<string> files = FolderUtilities::GetFilesInFolder(folder, validExtensions, true);
|
|
|
|
romFiles.insert(romFiles.end(), files.begin(), files.end());
|
|
|
|
}
|
|
|
|
|
2019-01-20 21:33:23 +00:00
|
|
|
if(!romName.empty()) {
|
|
|
|
//Perform quick search based on file name
|
|
|
|
string match = RomLoader::FindMatchingRom(romFiles, romName, hashInfo, true);
|
|
|
|
if(!match.empty()) {
|
|
|
|
return match;
|
|
|
|
}
|
2018-07-01 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Perform slow CRC32 search for ROM
|
2019-01-20 21:33:23 +00:00
|
|
|
string match = RomLoader::FindMatchingRom(romFiles, romName, hashInfo, false);
|
2018-07-01 19:21:05 +00:00
|
|
|
if(!match.empty()) {
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Initialize(string romFile, string patchFile)
|
|
|
|
{
|
|
|
|
VirtualFile rom = romFile;
|
|
|
|
VirtualFile patch = patchFile;
|
|
|
|
return Initialize(rom, patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Initialize(VirtualFile &romFile)
|
|
|
|
{
|
|
|
|
VirtualFile patchFile;
|
|
|
|
return Initialize(romFile, patchFile);
|
|
|
|
}
|
|
|
|
|
2019-11-17 23:44:36 +00:00
|
|
|
bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile, bool forPowerCycle)
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
2017-07-30 13:03:54 +00:00
|
|
|
if(romFile.IsValid()) {
|
2019-11-17 03:56:01 +00:00
|
|
|
if(!_romFilepath.empty() && _mapper) {
|
|
|
|
//Ensure we save any battery file before loading a new game
|
|
|
|
SaveBatteries();
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:58:15 +00:00
|
|
|
shared_ptr<HdPackData> originalHdPackData = _hdData;
|
2017-07-30 13:03:54 +00:00
|
|
|
LoadHdPack(romFile, patchFile);
|
2022-04-06 17:08:47 +00:00
|
|
|
if(patchFile.IsValid())
|
|
|
|
romFile.ApplyPatch(patchFile);
|
2016-07-26 23:19:28 +00:00
|
|
|
|
2018-07-22 21:31:50 +00:00
|
|
|
_batteryManager->Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false));
|
2019-06-22 20:33:59 +00:00
|
|
|
|
|
|
|
RomData romData;
|
2020-01-01 01:23:26 +00:00
|
|
|
shared_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(shared_from_this(), romFile, romData);
|
2017-06-28 23:00:08 +00:00
|
|
|
if(mapper) {
|
2018-06-17 03:42:22 +00:00
|
|
|
bool isDifferentGame = _romFilepath != (string)romFile || _patchFilename != (string)patchFile;
|
2015-12-26 22:11:00 +00:00
|
|
|
|
2018-06-17 03:42:22 +00:00
|
|
|
if(isDifferentGame) {
|
2017-11-20 04:08:23 +00:00
|
|
|
_romFilepath = romFile;
|
|
|
|
_patchFilename = patchFile;
|
|
|
|
|
|
|
|
//Changed game, stop all recordings
|
2018-07-03 01:32:59 +00:00
|
|
|
_soundMixer->StopRecording();
|
2017-11-20 04:08:23 +00:00
|
|
|
StopRecordingHdPack();
|
|
|
|
}
|
2017-05-26 00:04:49 +00:00
|
|
|
|
2019-11-17 23:44:36 +00:00
|
|
|
shared_ptr<BaseMapper> previousMapper = _mapper;
|
2017-06-28 23:00:08 +00:00
|
|
|
_mapper = mapper;
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager.reset(new MemoryManager(shared_from_this()));
|
|
|
|
_cpu.reset(new CPU(shared_from_this()));
|
|
|
|
_apu.reset(new APU(shared_from_this()));
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2019-06-23 21:15:05 +00:00
|
|
|
_mapper->SetConsole(shared_from_this());
|
|
|
|
_mapper->Initialize(romData);
|
2019-11-17 23:44:36 +00:00
|
|
|
if(!isDifferentGame && forPowerCycle) {
|
|
|
|
_mapper->CopyPrgChrRom(previousMapper);
|
|
|
|
}
|
2019-06-23 21:15:05 +00:00
|
|
|
|
2018-07-03 01:32:59 +00:00
|
|
|
if(_slave) {
|
|
|
|
_slave->Release(false);
|
|
|
|
_slave.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-07 18:52:51 +00:00
|
|
|
RomInfo romInfo = _mapper->GetRomInfo();
|
2018-07-07 21:30:13 +00:00
|
|
|
if(!_master && romInfo.VsType == VsSystemType::VsDualSystem) {
|
2022-04-06 18:29:56 +00:00
|
|
|
extern retro_environment_t env_cb;
|
2018-07-03 01:32:59 +00:00
|
|
|
_slave.reset(new Console(shared_from_this()));
|
2022-04-06 18:29:56 +00:00
|
|
|
_slave->Init(env_cb);
|
2018-07-03 01:32:59 +00:00
|
|
|
_slave->Initialize(romFile, patchFile);
|
|
|
|
}
|
|
|
|
|
2018-07-07 18:52:51 +00:00
|
|
|
switch(romInfo.System) {
|
2018-01-05 00:03:47 +00:00
|
|
|
case GameSystem::FDS:
|
2018-07-14 02:19:26 +00:00
|
|
|
_settings->SetPpuModel(PpuModel::Ppu2C02);
|
2018-07-01 19:21:05 +00:00
|
|
|
_systemActionManager.reset(new FdsSystemActionManager(shared_from_this(), _mapper));
|
2018-01-05 00:03:47 +00:00
|
|
|
break;
|
|
|
|
|
2018-07-07 18:52:51 +00:00
|
|
|
case GameSystem::VsSystem:
|
2018-07-14 02:19:26 +00:00
|
|
|
_settings->SetPpuModel(romInfo.VsPpuModel);
|
2018-07-01 19:21:05 +00:00
|
|
|
_systemActionManager.reset(new VsSystemActionManager(shared_from_this()));
|
2018-01-05 00:03:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-07-14 02:19:26 +00:00
|
|
|
_settings->SetPpuModel(PpuModel::Ppu2C02);
|
2018-07-01 19:21:05 +00:00
|
|
|
_systemActionManager.reset(new SystemActionManager(shared_from_this())); break;
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
2014-06-21 19:43:41 +00:00
|
|
|
|
2017-12-27 17:32:10 +00:00
|
|
|
//Temporarely disable battery saves to prevent battery files from being created for the wrong game (for Battle Box & Turbo File)
|
2018-07-22 21:31:50 +00:00
|
|
|
_batteryManager->SetSaveEnabled(false);
|
2018-07-02 22:46:02 +00:00
|
|
|
|
|
|
|
uint32_t pollCounter = 0;
|
|
|
|
if(_controlManager && !isDifferentGame) {
|
|
|
|
//When power cycling, poll counter must be preserved to allow movies to playback properly
|
|
|
|
pollCounter = _controlManager->GetPollCounter();
|
|
|
|
}
|
2018-07-03 01:32:59 +00:00
|
|
|
|
2018-07-07 18:52:51 +00:00
|
|
|
if(romInfo.System == GameSystem::VsSystem) {
|
2018-07-01 19:21:05 +00:00
|
|
|
_controlManager.reset(new VsControlManager(shared_from_this(), _systemActionManager, _mapper->GetMapperControlDevice()));
|
2017-11-20 04:08:23 +00:00
|
|
|
} else {
|
2018-07-01 19:21:05 +00:00
|
|
|
_controlManager.reset(new ControlManager(shared_from_this(), _systemActionManager, _mapper->GetMapperControlDevice()));
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
2018-07-02 22:46:02 +00:00
|
|
|
_controlManager->SetPollCounter(pollCounter);
|
2017-11-20 04:08:23 +00:00
|
|
|
_controlManager->UpdateControlDevices();
|
2018-07-02 22:46:02 +00:00
|
|
|
|
2017-12-27 17:32:10 +00:00
|
|
|
//Re-enable battery saves
|
2018-07-22 21:31:50 +00:00
|
|
|
_batteryManager->SetSaveEnabled(true);
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2017-08-19 21:51:36 +00:00
|
|
|
if(_hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty())) {
|
2018-07-01 19:21:05 +00:00
|
|
|
_ppu.reset(new HdPpu(shared_from_this(), _hdData.get()));
|
2017-06-28 23:00:08 +00:00
|
|
|
} else {
|
2018-07-01 19:21:05 +00:00
|
|
|
_ppu.reset(new PPU(shared_from_this()));
|
2017-06-28 23:00:08 +00:00
|
|
|
}
|
2016-01-23 05:52:06 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->SetMapper(_mapper);
|
2017-06-28 23:00:08 +00:00
|
|
|
_memoryManager->RegisterIODevice(_ppu.get());
|
|
|
|
_memoryManager->RegisterIODevice(_apu.get());
|
|
|
|
_memoryManager->RegisterIODevice(_controlManager.get());
|
|
|
|
_memoryManager->RegisterIODevice(_mapper.get());
|
2018-07-01 19:21:05 +00:00
|
|
|
|
2017-08-19 20:46:57 +00:00
|
|
|
if(_hdData && (!_hdData->BgmFilesById.empty() || !_hdData->SfxFilesById.empty())) {
|
2018-07-01 19:21:05 +00:00
|
|
|
_hdAudioDevice.reset(new HdAudioDevice(shared_from_this(), _hdData.get()));
|
2017-08-19 20:46:57 +00:00
|
|
|
_memoryManager->RegisterIODevice(_hdAudioDevice.get());
|
2018-08-06 21:58:15 +00:00
|
|
|
} else {
|
|
|
|
_hdAudioDevice.reset();
|
2017-08-19 20:46:57 +00:00
|
|
|
}
|
2016-01-29 03:34:23 +00:00
|
|
|
|
2017-06-28 23:00:08 +00:00
|
|
|
_model = NesModel::Auto;
|
|
|
|
UpdateNesModel(false);
|
2016-06-04 12:55:52 +00:00
|
|
|
|
2017-06-28 23:00:08 +00:00
|
|
|
_initialized = true;
|
2017-04-28 23:54:58 +00:00
|
|
|
|
2017-06-28 23:00:08 +00:00
|
|
|
ResetComponents(false);
|
2016-07-10 23:15:00 +00:00
|
|
|
|
2018-07-15 22:26:08 +00:00
|
|
|
//Poll controller input after creating rewind manager, to make sure it catches the first frame's input
|
|
|
|
_controlManager->UpdateInputState();
|
|
|
|
|
2017-07-30 13:03:54 +00:00
|
|
|
FolderUtilities::AddKnownGameFolder(romFile.GetFolderPath());
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-03 01:32:59 +00:00
|
|
|
if(IsMaster()) {
|
2018-07-14 02:19:26 +00:00
|
|
|
_settings->ClearFlags(EmulationFlags::ForceMaxSpeed);
|
2020-04-28 00:47:28 +00:00
|
|
|
}
|
2017-06-28 23:00:08 +00:00
|
|
|
return true;
|
2018-08-06 21:58:15 +00:00
|
|
|
} else {
|
|
|
|
_hdData = originalHdPackData;
|
2019-11-17 03:56:01 +00:00
|
|
|
|
|
|
|
//Reset battery source to current game if new game failed to load
|
|
|
|
_batteryManager->Initialize(FolderUtilities::GetFilename(GetRomInfo().RomName, false));
|
2016-06-12 22:11:31 +00:00
|
|
|
}
|
2014-07-10 23:25:35 +00:00
|
|
|
}
|
2017-06-28 23:00:08 +00:00
|
|
|
|
|
|
|
return false;
|
2015-07-06 02:23:44 +00:00
|
|
|
}
|
2014-07-01 16:44:01 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void Console::ProcessCpuClock()
|
2015-12-27 23:41:38 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
_mapper->ProcessCpuClock();
|
|
|
|
_apu->ProcessCpuClock();
|
2014-06-14 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
CPU* Console::GetCpu()
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _cpu.get();
|
|
|
|
}
|
2015-07-06 02:23:44 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
PPU* Console::GetPpu()
|
|
|
|
{
|
|
|
|
return _ppu.get();
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
APU* Console::GetApu()
|
2017-11-20 04:08:23 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _apu.get();
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<SoundMixer> Console::GetSoundMixer()
|
|
|
|
{
|
|
|
|
return _soundMixer;
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-07-14 02:19:26 +00:00
|
|
|
EmulationSettings* Console::GetSettings()
|
|
|
|
{
|
|
|
|
return _settings.get();
|
|
|
|
}
|
|
|
|
|
2018-07-03 01:32:59 +00:00
|
|
|
bool Console::IsDualSystem()
|
|
|
|
{
|
|
|
|
return _slave != nullptr || _master != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
shared_ptr<Console> Console::GetDualConsole()
|
|
|
|
{
|
|
|
|
//When called from the master, returns the slave.
|
|
|
|
//When called from the slave, returns the master.
|
|
|
|
//Returns a null pointer when not running a dualsystem game
|
|
|
|
return _slave ? _slave : _master;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::IsMaster()
|
|
|
|
{
|
|
|
|
return !_master;
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
BaseMapper* Console::GetMapper()
|
|
|
|
{
|
|
|
|
return _mapper.get();
|
|
|
|
}
|
2015-07-06 02:23:44 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
ControlManager* Console::GetControlManager()
|
|
|
|
{
|
|
|
|
return _controlManager.get();
|
|
|
|
}
|
2016-02-09 04:34:48 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
MemoryManager* Console::GetMemoryManager()
|
|
|
|
{
|
|
|
|
return _memoryManager.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
CheatManager* Console::GetCheatManager()
|
|
|
|
{
|
|
|
|
return _cheatManager.get();
|
|
|
|
}
|
|
|
|
|
2017-08-19 23:40:02 +00:00
|
|
|
VirtualFile Console::GetRomPath()
|
2014-07-09 22:29:07 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return static_cast<VirtualFile>(_romFilepath);
|
2014-06-14 15:27:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
VirtualFile Console::GetPatchFile()
|
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return (VirtualFile)_patchFilename;
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 18:52:51 +00:00
|
|
|
RomInfo Console::GetRomInfo()
|
2017-06-28 23:00:08 +00:00
|
|
|
{
|
2018-07-07 18:52:51 +00:00
|
|
|
return _mapper ? _mapper->GetRomInfo() : (RomInfo {});
|
2018-07-01 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Console::GetFrameCount()
|
|
|
|
{
|
|
|
|
return _ppu ? _ppu->GetFrameCount() : 0;
|
2017-06-28 23:00:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-02 03:54:31 +00:00
|
|
|
NesModel Console::GetModel()
|
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _model;
|
2016-07-02 03:54:31 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
shared_ptr<SystemActionManager> Console::GetSystemActionManager()
|
|
|
|
{
|
|
|
|
return _systemActionManager;
|
|
|
|
}
|
|
|
|
|
2017-05-03 03:31:06 +00:00
|
|
|
void Console::PowerCycle()
|
2019-11-17 23:44:36 +00:00
|
|
|
{
|
|
|
|
ReloadRom(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::ReloadRom(bool forPowerCycle)
|
2017-05-03 03:31:06 +00:00
|
|
|
{
|
2017-11-20 04:08:23 +00:00
|
|
|
if(_initialized && !_romFilepath.empty()) {
|
2018-07-01 19:21:05 +00:00
|
|
|
VirtualFile romFile = _romFilepath;
|
|
|
|
VirtualFile patchFile = _patchFilename;
|
2019-11-17 23:44:36 +00:00
|
|
|
Initialize(romFile, patchFile, forPowerCycle);
|
2017-05-03 03:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-05 23:35:38 +00:00
|
|
|
void Console::Reset(bool softReset)
|
2014-06-14 15:27:55 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
if(_initialized) {
|
2022-04-03 19:57:05 +00:00
|
|
|
if (softReset)
|
|
|
|
_systemActionManager->Reset();
|
|
|
|
else
|
|
|
|
_systemActionManager->PowerCycle();
|
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
|
|
|
{
|
2018-07-03 01:32:59 +00:00
|
|
|
if(_slave) {
|
|
|
|
//Always reset/power cycle the slave alongside the master CPU
|
|
|
|
_slave->ResetComponents(softReset);
|
|
|
|
}
|
|
|
|
|
2016-07-17 18:07:22 +00:00
|
|
|
_memoryManager->Reset(softReset);
|
2022-04-07 19:39:08 +00:00
|
|
|
if(!_settings->CheckFlag(EmulationFlags::DisablePpuReset) || !softReset)
|
2017-02-25 04:06:13 +00:00
|
|
|
_ppu->Reset();
|
2015-07-19 05:30:13 +00:00
|
|
|
_apu->Reset(softReset);
|
2017-04-21 01:58:35 +00:00
|
|
|
_cpu->Reset(softReset, _model);
|
2016-06-22 02:13:26 +00:00
|
|
|
_controlManager->Reset(softReset);
|
2014-06-24 06:47:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:03:47 +00:00
|
|
|
void Console::RunSingleFrame()
|
|
|
|
{
|
|
|
|
//Used by Libretro
|
2018-07-01 19:21:05 +00:00
|
|
|
uint32_t lastFrameNumber = _ppu->GetFrameCount();
|
2018-01-09 01:11:11 +00:00
|
|
|
UpdateNesModel(true);
|
2018-01-05 00:03:47 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
while(_ppu->GetFrameCount() == lastFrameNumber) {
|
2018-01-05 00:03:47 +00:00
|
|
|
_cpu->Exec();
|
2022-04-03 17:43:41 +00:00
|
|
|
if(_slave)
|
2018-07-04 03:32:26 +00:00
|
|
|
RunSlaveCpu();
|
2018-01-05 00:03:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-07 19:39:08 +00:00
|
|
|
_settings->DisableOverclocking(_disableOcNextFrame);
|
2018-01-05 00:03:47 +00:00
|
|
|
_disableOcNextFrame = false;
|
|
|
|
|
|
|
|
_systemActionManager->ProcessSystemActions();
|
|
|
|
_apu->EndFrame();
|
|
|
|
}
|
|
|
|
|
2018-07-04 03:32:26 +00:00
|
|
|
void Console::RunSlaveCpu()
|
|
|
|
{
|
2019-05-12 16:28:01 +00:00
|
|
|
int64_t cycleGap;
|
2018-07-04 03:32:26 +00:00
|
|
|
while(true) {
|
|
|
|
//Run the slave until it catches up to the master CPU (and take into account the CPU count overflow that occurs every ~20mins)
|
2019-05-12 16:28:01 +00:00
|
|
|
cycleGap = (int64_t)(_cpu->GetCycleCount() - _slave->_cpu->GetCycleCount());
|
|
|
|
if(cycleGap > 5 || _ppu->GetFrameCount() > _slave->_ppu->GetFrameCount()) {
|
2018-07-04 03:32:26 +00:00
|
|
|
_slave->_cpu->Exec();
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-10 23:15:00 +00:00
|
|
|
void Console::UpdateNesModel(bool sendNotification)
|
2015-07-22 03:05:27 +00:00
|
|
|
{
|
2022-04-04 05:37:14 +00:00
|
|
|
if(_settings->NeedControllerUpdate())
|
2016-02-06 04:14:27 +00:00
|
|
|
_controlManager->UpdateControlDevices();
|
|
|
|
|
2018-07-14 02:19:26 +00:00
|
|
|
NesModel model = _settings->GetNesModel();
|
2015-07-22 03:05:27 +00:00
|
|
|
if(model == NesModel::Auto) {
|
2018-07-07 18:52:51 +00:00
|
|
|
switch(_mapper->GetRomInfo().System) {
|
2016-06-16 01:59:34 +00:00
|
|
|
case GameSystem::NesPal: model = NesModel::PAL; break;
|
|
|
|
case GameSystem::Dendy: model = NesModel::Dendy; break;
|
|
|
|
default: model = NesModel::NTSC; break;
|
|
|
|
}
|
2015-07-22 03:05:27 +00:00
|
|
|
}
|
2022-04-04 05:37:14 +00:00
|
|
|
if(_model != model)
|
2016-02-06 04:14:27 +00:00
|
|
|
_model = model;
|
2016-07-10 23:15:00 +00:00
|
|
|
|
2019-11-10 22:35:29 +00:00
|
|
|
_cpu->SetMasterClockDivider(model);
|
2016-07-10 23:15:00 +00:00
|
|
|
_mapper->SetNesModel(model);
|
|
|
|
_ppu->SetNesModel(model);
|
|
|
|
_apu->SetNesModel(model);
|
|
|
|
}
|
|
|
|
|
2014-07-01 16:44:01 +00:00
|
|
|
void Console::SaveState(ostream &saveStream)
|
2014-06-26 01:52:37 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
if(_initialized) {
|
2019-12-24 18:46:10 +00:00
|
|
|
//Send any unprocessed sound to the SoundMixer - needed for rewind
|
|
|
|
_apu->EndFrame();
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_cpu->SaveSnapshot(&saveStream);
|
|
|
|
_ppu->SaveSnapshot(&saveStream);
|
|
|
|
_memoryManager->SaveSnapshot(&saveStream);
|
|
|
|
_apu->SaveSnapshot(&saveStream);
|
|
|
|
_controlManager->SaveSnapshot(&saveStream);
|
|
|
|
_mapper->SaveSnapshot(&saveStream);
|
|
|
|
if(_hdAudioDevice) {
|
|
|
|
_hdAudioDevice->SaveSnapshot(&saveStream);
|
2017-08-20 23:03:16 +00:00
|
|
|
} else {
|
|
|
|
Snapshotable::WriteEmptyBlock(&saveStream);
|
|
|
|
}
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
if(_slave) {
|
|
|
|
//For VS Dualsystem, append the 2nd console's savestate
|
|
|
|
_slave->SaveState(saveStream);
|
|
|
|
}
|
2014-07-06 23:54:47 +00:00
|
|
|
}
|
2014-07-01 16:44:01 +00:00
|
|
|
}
|
2014-06-26 01:52:37 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
void Console::LoadState(istream &loadStream)
|
|
|
|
{
|
|
|
|
LoadState(loadStream, SaveStateManager::FileFormatVersion);
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
void Console::LoadState(istream &loadStream, uint32_t stateVersion)
|
2014-07-01 16:44:01 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
if(_initialized) {
|
2019-12-24 18:46:10 +00:00
|
|
|
//Send any unprocessed sound to the SoundMixer - needed for rewind
|
|
|
|
_apu->EndFrame();
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_cpu->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
_ppu->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
_memoryManager->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
_apu->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
_controlManager->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
_mapper->LoadSnapshot(&loadStream, stateVersion);
|
|
|
|
if(_hdAudioDevice) {
|
|
|
|
_hdAudioDevice->LoadSnapshot(&loadStream, stateVersion);
|
2017-08-20 23:03:16 +00:00
|
|
|
} else {
|
|
|
|
Snapshotable::SkipBlock(&loadStream);
|
|
|
|
}
|
2018-07-03 01:32:59 +00:00
|
|
|
|
|
|
|
if(_slave) {
|
|
|
|
//For VS Dualsystem, the slave console's savestate is appended to the end of the file
|
|
|
|
_slave->LoadState(loadStream, stateVersion);
|
|
|
|
}
|
2014-07-10 01:11:02 +00:00
|
|
|
|
2018-08-26 22:53:15 +00:00
|
|
|
UpdateNesModel(false);
|
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
|
|
|
}
|
|
|
|
|
2017-04-29 20:11:22 +00:00
|
|
|
void Console::SetNextFrameOverclockStatus(bool disabled)
|
2016-12-23 18:56:45 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
_disableOcNextFrame = disabled;
|
2017-04-29 20:11:22 +00:00
|
|
|
}
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2019-06-22 20:33:59 +00:00
|
|
|
void Console::InitializeRam(void* data, uint32_t length)
|
|
|
|
{
|
|
|
|
InitializeRam(_settings->GetRamPowerOnState(), data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::InitializeRam(RamPowerOnState powerOnState, void* data, uint32_t length)
|
|
|
|
{
|
|
|
|
switch(powerOnState) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
shared_ptr<HdPackData> Console::GetHdData()
|
2017-06-28 23:00:08 +00:00
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _hdData;
|
2017-06-28 23:00:08 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 21:51:36 +00:00
|
|
|
bool Console::IsHdPpu()
|
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
return _hdData && std::dynamic_pointer_cast<HdPpu>(_ppu) != nullptr;
|
2017-08-19 21:51:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 13:03:54 +00:00
|
|
|
void Console::LoadHdPack(VirtualFile &romFile, VirtualFile &patchFile)
|
2017-06-28 23:00:08 +00:00
|
|
|
{
|
|
|
|
_hdData.reset();
|
2018-07-14 02:19:26 +00:00
|
|
|
if(_settings->CheckFlag(EmulationFlags::UseHdPacks)) {
|
2017-06-28 23:00:08 +00:00
|
|
|
_hdData.reset(new HdPackData());
|
2017-07-30 13:03:54 +00:00
|
|
|
if(!HdPackLoader::LoadHdNesPack(romFile, *_hdData.get())) {
|
2017-06-28 23:00:08 +00:00
|
|
|
_hdData.reset();
|
|
|
|
} else {
|
2017-07-30 13:03:54 +00:00
|
|
|
auto result = _hdData->PatchesByHash.find(romFile.GetSha1Hash());
|
2017-06-28 23:00:08 +00:00
|
|
|
if(result != _hdData->PatchesByHash.end()) {
|
2017-07-30 13:03:54 +00:00
|
|
|
patchFile = result->second;
|
2017-06-28 23:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::StartRecordingHdPack(string saveFolder, ScaleFilterType filterType, uint32_t scale, uint32_t flags, uint32_t chrRamBankSize)
|
|
|
|
{
|
|
|
|
std::stringstream saveState;
|
2018-07-01 19:21:05 +00:00
|
|
|
SaveState(saveState);
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_hdPackBuilder.reset();
|
|
|
|
_hdPackBuilder.reset(new HdPackBuilder(shared_from_this(), saveFolder, filterType, scale, flags, chrRamBankSize, !_mapper->HasChrRom()));
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->UnregisterIODevice(_ppu.get());
|
|
|
|
_ppu.reset();
|
2018-09-14 00:58:35 +00:00
|
|
|
_ppu.reset(new HdBuilderPpu(shared_from_this(), _hdPackBuilder.get(), chrRamBankSize, _hdData));
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->RegisterIODevice(_ppu.get());
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
LoadState(saveState);
|
2017-06-28 23:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Console::StopRecordingHdPack()
|
|
|
|
{
|
2018-07-01 19:21:05 +00:00
|
|
|
if(_hdPackBuilder) {
|
2017-08-09 21:44:52 +00:00
|
|
|
std::stringstream saveState;
|
2018-07-01 19:21:05 +00:00
|
|
|
SaveState(saveState);
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->UnregisterIODevice(_ppu.get());
|
|
|
|
_ppu.reset();
|
2018-09-14 00:58:35 +00:00
|
|
|
if(_hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty())) {
|
|
|
|
_ppu.reset(new HdPpu(shared_from_this(), _hdData.get()));
|
|
|
|
} else {
|
|
|
|
_ppu.reset(new PPU(shared_from_this()));
|
|
|
|
}
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->RegisterIODevice(_ppu.get());
|
|
|
|
_hdPackBuilder.reset();
|
2017-06-28 23:00:08 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
LoadState(saveState);
|
2017-08-09 21:44:52 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 00:03:47 +00:00
|
|
|
bool Console::UpdateHdPackMode()
|
|
|
|
{
|
|
|
|
//Switch back and forth between HD PPU and regular PPU as needed
|
|
|
|
|
|
|
|
VirtualFile romFile = _romFilepath;
|
|
|
|
VirtualFile patchFile = _patchFilename;
|
|
|
|
LoadHdPack(romFile, patchFile);
|
|
|
|
|
|
|
|
bool isHdPackLoaded = std::dynamic_pointer_cast<HdPpu>(_ppu) != nullptr;
|
|
|
|
bool hdPackFound = _hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty());
|
|
|
|
|
|
|
|
bool modeChanged = false;
|
|
|
|
if(isHdPackLoaded != hdPackFound) {
|
|
|
|
std::stringstream saveState;
|
2018-07-01 19:21:05 +00:00
|
|
|
SaveState(saveState);
|
2018-01-05 00:03:47 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->UnregisterIODevice(_ppu.get());
|
|
|
|
_ppu.reset();
|
2018-01-05 00:03:47 +00:00
|
|
|
if(_hdData && (!_hdData->Tiles.empty() || !_hdData->Backgrounds.empty())) {
|
2018-07-01 19:21:05 +00:00
|
|
|
_ppu.reset(new HdPpu(shared_from_this(), _hdData.get()));
|
2018-01-05 00:03:47 +00:00
|
|
|
} else {
|
2018-07-01 19:21:05 +00:00
|
|
|
_ppu.reset(new PPU(shared_from_this()));
|
2018-01-05 00:03:47 +00:00
|
|
|
}
|
2018-07-01 19:21:05 +00:00
|
|
|
_memoryManager->RegisterIODevice(_ppu.get());
|
2018-01-05 00:03:47 +00:00
|
|
|
|
2018-07-01 19:21:05 +00:00
|
|
|
LoadState(saveState);
|
2018-01-05 00:03:47 +00:00
|
|
|
modeChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return modeChanged;
|
|
|
|
}
|
|
|
|
|
2019-02-09 00:39:35 +00:00
|
|
|
uint32_t Console::GetDipSwitchCount()
|
|
|
|
{
|
|
|
|
shared_ptr<ControlManager> controlManager = _controlManager;
|
|
|
|
shared_ptr<BaseMapper> mapper = _mapper;
|
|
|
|
|
|
|
|
if(std::dynamic_pointer_cast<VsControlManager>(controlManager)) {
|
|
|
|
return IsDualSystem() ? 16 : 8;
|
|
|
|
} else if(mapper) {
|
|
|
|
return mapper->GetMapperDipSwitchCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
ConsoleFeatures Console::GetAvailableFeatures()
|
|
|
|
{
|
|
|
|
ConsoleFeatures features = ConsoleFeatures::None;
|
2018-06-16 14:03:49 +00:00
|
|
|
shared_ptr<BaseMapper> mapper = _mapper;
|
2018-06-16 19:47:06 +00:00
|
|
|
shared_ptr<ControlManager> controlManager = _controlManager;
|
2018-06-16 14:03:49 +00:00
|
|
|
if(mapper && controlManager) {
|
|
|
|
features = (ConsoleFeatures)((int)features | (int)mapper->GetAvailableFeatures());
|
2017-11-20 04:08:23 +00:00
|
|
|
|
2018-06-16 14:03:49 +00:00
|
|
|
if(dynamic_cast<VsControlManager*>(controlManager.get())) {
|
2017-11-20 04:08:23 +00:00
|
|
|
features = (ConsoleFeatures)((int)features | (int)ConsoleFeatures::VsSystem);
|
|
|
|
}
|
|
|
|
|
2018-06-16 14:03:49 +00:00
|
|
|
if(std::dynamic_pointer_cast<IBarcodeReader>(controlManager->GetControlDevice(BaseControlDevice::ExpDevicePort))) {
|
2017-11-20 04:08:23 +00:00
|
|
|
features = (ConsoleFeatures)((int)features | (int)ConsoleFeatures::BarcodeReader);
|
|
|
|
}
|
2017-11-25 02:38:12 +00:00
|
|
|
|
2018-06-16 14:03:49 +00:00
|
|
|
if(std::dynamic_pointer_cast<FamilyBasicDataRecorder>(controlManager->GetControlDevice(BaseControlDevice::ExpDevicePort2))) {
|
2017-11-25 02:38:12 +00:00
|
|
|
features = (ConsoleFeatures)((int)features | (int)ConsoleFeatures::TapeRecorder);
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::InputBarcode(uint64_t barcode, uint32_t digitCount)
|
|
|
|
{
|
2018-06-16 14:03:49 +00:00
|
|
|
shared_ptr<BaseMapper> mapper = _mapper;
|
2018-06-16 19:47:06 +00:00
|
|
|
shared_ptr<ControlManager> controlManager = _controlManager;
|
2018-06-16 14:03:49 +00:00
|
|
|
|
|
|
|
if(mapper) {
|
|
|
|
shared_ptr<IBarcodeReader> barcodeReader = std::dynamic_pointer_cast<IBarcodeReader>(mapper->GetMapperControlDevice());
|
|
|
|
if(barcodeReader) {
|
|
|
|
barcodeReader->InputBarcode(barcode, digitCount);
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
|
|
|
|
2018-06-16 14:03:49 +00:00
|
|
|
if(controlManager) {
|
|
|
|
shared_ptr<IBarcodeReader> barcodeReader = std::dynamic_pointer_cast<IBarcodeReader>(controlManager->GetControlDevice(BaseControlDevice::ExpDevicePort));
|
|
|
|
if(barcodeReader) {
|
|
|
|
barcodeReader->InputBarcode(barcode, digitCount);
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
}
|
2017-11-25 02:38:12 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 17:58:59 +00:00
|
|
|
uint8_t* Console::GetRamBuffer(uint16_t address)
|
2018-01-07 06:22:28 +00:00
|
|
|
{
|
|
|
|
//Only used by libretro port for achievements - should not be used by anything else.
|
2020-06-23 17:58:59 +00:00
|
|
|
AddressTypeInfo addrInfo;
|
|
|
|
_mapper->GetAbsoluteAddressAndType(address, &addrInfo);
|
|
|
|
|
2022-04-04 05:37:14 +00:00
|
|
|
if(addrInfo.Address >= 0)
|
|
|
|
{
|
|
|
|
if(addrInfo.Type == AddressType::InternalRam)
|
2020-06-23 17:58:59 +00:00
|
|
|
return _memoryManager->GetInternalRAM() + addrInfo.Address;
|
2022-04-04 05:37:14 +00:00
|
|
|
else if(addrInfo.Type == AddressType::WorkRam)
|
2020-06-23 17:58:59 +00:00
|
|
|
return _mapper->GetWorkRam() + addrInfo.Address;
|
2022-04-04 05:37:14 +00:00
|
|
|
else if(addrInfo.Type == AddressType::SaveRam)
|
2020-06-23 17:58:59 +00:00
|
|
|
return _mapper->GetSaveRam() + addrInfo.Address;
|
2018-01-07 06:22:28 +00:00
|
|
|
}
|
2020-06-23 17:58:59 +00:00
|
|
|
return nullptr;
|
2018-06-09 18:03:53 +00:00
|
|
|
}
|