2017-04-22 17:19:21 +00:00
|
|
|
#include "stdafx.h"
|
2017-12-23 17:32:44 +00:00
|
|
|
#include "ControlManager.h"
|
2017-11-20 04:08:23 +00:00
|
|
|
#include "SystemActionManager.h"
|
|
|
|
#include "FdsSystemActionManager.h"
|
|
|
|
#include "VsSystemActionManager.h"
|
2017-04-22 17:19:21 +00:00
|
|
|
#include "BizhawkMovie.h"
|
|
|
|
#include "VsControlManager.h"
|
|
|
|
#include "FDS.h"
|
|
|
|
|
|
|
|
BizhawkMovie::BizhawkMovie()
|
|
|
|
{
|
|
|
|
_originalPowerOnState = EmulationSettings::GetRamPowerOnState();
|
|
|
|
}
|
|
|
|
|
|
|
|
BizhawkMovie::~BizhawkMovie()
|
|
|
|
{
|
2017-11-20 04:08:23 +00:00
|
|
|
Stop();
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
void BizhawkMovie::Stop()
|
2017-04-22 17:19:21 +00:00
|
|
|
{
|
2017-11-20 04:08:23 +00:00
|
|
|
if(_isPlaying) {
|
|
|
|
EndMovie();
|
|
|
|
EmulationSettings::SetRamPowerOnState(_originalPowerOnState);
|
|
|
|
_isPlaying = false;
|
|
|
|
}
|
|
|
|
ControlManager::UnregisterInputProvider(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BizhawkMovie::SetInput(BaseControlDevice *device)
|
|
|
|
{
|
|
|
|
SystemActionManager* actionManager = dynamic_cast<SystemActionManager*>(device);
|
2017-12-23 17:32:44 +00:00
|
|
|
int32_t pollCounter = ControlManager::GetPollCounter();
|
2017-11-20 04:08:23 +00:00
|
|
|
if(actionManager) {
|
2017-12-23 17:32:44 +00:00
|
|
|
if(pollCounter < (int32_t)_systemActionByFrame.size()) {
|
|
|
|
uint32_t systemAction = _systemActionByFrame[pollCounter];
|
2017-04-22 17:19:21 +00:00
|
|
|
if(systemAction & 0x01) {
|
2017-11-20 04:08:23 +00:00
|
|
|
actionManager->SetBit(SystemActionManager::Buttons::PowerButton);
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
if(systemAction & 0x02) {
|
2017-11-20 04:08:23 +00:00
|
|
|
actionManager->SetBit(SystemActionManager::Buttons::ResetButton);
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
|
|
|
VsSystemActionManager* vsActionManager = dynamic_cast<VsSystemActionManager*>(device);
|
|
|
|
if(vsActionManager) {
|
|
|
|
if(systemAction & 0x04) {
|
|
|
|
actionManager->SetBit(VsSystemActionManager::VsButtons::InsertCoin1);
|
|
|
|
}
|
|
|
|
if(systemAction & 0x08) {
|
|
|
|
actionManager->SetBit(VsSystemActionManager::VsButtons::InsertCoin2);
|
|
|
|
}
|
|
|
|
if(systemAction & 0x10) {
|
|
|
|
actionManager->SetBit(VsSystemActionManager::VsButtons::ServiceButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FdsSystemActionManager* fdsActionManager = dynamic_cast<FdsSystemActionManager*>(device);
|
|
|
|
if(fdsActionManager) {
|
2017-04-22 17:19:21 +00:00
|
|
|
//FDS timings between NesHawk & Mesen are currently significantly different
|
|
|
|
//So FDS games will always go out of sync
|
|
|
|
if(systemAction & 0x04) {
|
2017-11-20 04:08:23 +00:00
|
|
|
fdsActionManager->SetBit(FdsSystemActionManager::FdsButtons::EjectDiskButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(systemAction >= 8) {
|
2017-04-22 17:19:21 +00:00
|
|
|
systemAction >>= 3;
|
|
|
|
uint32_t diskNumber = 0;
|
|
|
|
while(!(systemAction & 0x01)) {
|
|
|
|
systemAction >>= 1;
|
|
|
|
diskNumber++;
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
|
|
|
fdsActionManager->SetBit(FdsSystemActionManager::FdsButtons::InsertDisk1 + diskNumber);
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-11-20 04:08:23 +00:00
|
|
|
int port = device->GetPort();
|
|
|
|
StandardController* controller = dynamic_cast<StandardController*>(device);
|
|
|
|
if(controller) {
|
2017-12-23 17:32:44 +00:00
|
|
|
if(pollCounter < (int32_t)_dataByFrame[port].size()) {
|
|
|
|
controller->SetTextState(_dataByFrame[port][pollCounter]);
|
2017-11-20 04:08:23 +00:00
|
|
|
} else {
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
}
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
|
|
|
return true;
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
bool BizhawkMovie::InitializeGameData(ZipReader &reader)
|
2017-04-22 17:19:21 +00:00
|
|
|
{
|
2017-11-20 04:08:23 +00:00
|
|
|
stringstream fileData;
|
|
|
|
if(!reader.GetStream("Header.txt", fileData)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-22 17:19:21 +00:00
|
|
|
|
2017-12-23 17:32:44 +00:00
|
|
|
ControlManager::ResetPollCounter();
|
2017-11-26 23:16:32 +00:00
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
while(!fileData.eof()) {
|
2017-04-22 17:19:21 +00:00
|
|
|
string line;
|
2017-11-20 04:08:23 +00:00
|
|
|
std::getline(fileData, line);
|
2017-04-22 17:19:21 +00:00
|
|
|
if(line.compare(0, 4, "SHA1", 4) == 0) {
|
|
|
|
if(line.size() >= 45) {
|
2017-07-30 13:03:54 +00:00
|
|
|
HashInfo hashInfo;
|
|
|
|
hashInfo.Sha1Hash = line.substr(5, 40);
|
|
|
|
if(Console::LoadROM("", hashInfo)) {
|
2017-11-20 04:08:23 +00:00
|
|
|
return true;
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-29 16:58:30 +00:00
|
|
|
} else if(line.compare(0, 3, "MD5", 3) == 0) {
|
|
|
|
if(line.size() >= 36) {
|
|
|
|
HashInfo hashInfo;
|
|
|
|
hashInfo.PrgChrMd5Hash = line.substr(4, 32);
|
|
|
|
std::transform(hashInfo.PrgChrMd5Hash.begin(), hashInfo.PrgChrMd5Hash.end(), hashInfo.PrgChrMd5Hash.begin(), ::toupper);
|
|
|
|
if(Console::LoadROM("", hashInfo)) {
|
2017-11-20 04:08:23 +00:00
|
|
|
return true;
|
2017-04-29 16:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
return false;
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
bool BizhawkMovie::InitializeInputData(ZipReader &reader)
|
2017-04-22 17:19:21 +00:00
|
|
|
{
|
2017-11-20 04:08:23 +00:00
|
|
|
stringstream inputData;
|
|
|
|
if(!reader.GetStream("Input Log.txt", inputData)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-22 17:19:21 +00:00
|
|
|
|
|
|
|
int systemActionCount = 2;
|
2017-11-20 04:08:23 +00:00
|
|
|
shared_ptr<FdsSystemActionManager> fdsActionManager = Console::GetInstance()->GetSystemActionManager<FdsSystemActionManager>();
|
|
|
|
if(fdsActionManager) {
|
2017-04-22 17:19:21 +00:00
|
|
|
//Eject disk + Insert Disk #XX
|
2017-11-20 04:08:23 +00:00
|
|
|
systemActionCount += fdsActionManager->GetSideCount() + 1;
|
|
|
|
} else {
|
|
|
|
shared_ptr<VsSystemActionManager> vsActionManager = Console::GetInstance()->GetSystemActionManager<VsSystemActionManager>();
|
|
|
|
if(vsActionManager) {
|
|
|
|
//Insert coin 1, 2 + service button
|
|
|
|
systemActionCount += 3;
|
|
|
|
}
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
2017-11-20 04:08:23 +00:00
|
|
|
|
|
|
|
while(!inputData.eof()) {
|
2017-04-22 17:19:21 +00:00
|
|
|
string line;
|
2017-11-20 04:08:23 +00:00
|
|
|
std::getline(inputData, line);
|
2017-04-22 17:19:21 +00:00
|
|
|
|
|
|
|
if(line.size() > 0 && line[0] == '|') {
|
|
|
|
line.erase(std::remove(line.begin(), line.end(), '|'), line.end());
|
|
|
|
line = line.substr(0, line.size() - 1);
|
|
|
|
|
|
|
|
//Read power/reset/FDS/VS/etc. commands
|
|
|
|
uint32_t systemAction = 0;
|
|
|
|
for(int i = 0; i < systemActionCount; i++) {
|
|
|
|
if(line[i] != '.') {
|
|
|
|
systemAction |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_systemActionByFrame.push_back(systemAction);
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
line = line.substr(systemActionCount);
|
|
|
|
int port = 0;
|
|
|
|
while(line.size() >= 8) {
|
|
|
|
_dataByFrame[port].push_back(line.substr(0, 8));
|
|
|
|
line = line.substr(8);
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
while(port < 4) {
|
|
|
|
_dataByFrame[port].push_back("........");
|
|
|
|
port++;
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _dataByFrame[0].size() > 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
bool BizhawkMovie::Play(VirtualFile &file)
|
2017-04-22 17:19:21 +00:00
|
|
|
{
|
|
|
|
Console::Pause();
|
|
|
|
ZipReader reader;
|
2017-11-20 04:08:23 +00:00
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
file.ReadFile(ss);
|
|
|
|
|
|
|
|
reader.LoadArchive(ss);
|
|
|
|
ControlManager::RegisterInputProvider(this);
|
|
|
|
if(InitializeInputData(reader) && InitializeGameData(reader)) {
|
|
|
|
//NesHawk initializes memory to 1s
|
|
|
|
EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes);
|
|
|
|
_isPlaying = true;
|
|
|
|
} else {
|
|
|
|
ControlManager::UnregisterInputProvider(this);
|
2017-04-22 17:19:21 +00:00
|
|
|
}
|
|
|
|
Console::Resume();
|
|
|
|
return _isPlaying;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BizhawkMovie::IsPlaying()
|
|
|
|
{
|
|
|
|
return _isPlaying;
|
|
|
|
}
|