Fixed rom search causing logging, input changes and FDSbios prompt

This commit is contained in:
Sour 2018-02-25 11:27:32 -05:00
parent 7ccf093a7e
commit 02aaad65a8
12 changed files with 108 additions and 57 deletions

22
Core/BaseLoader.h Normal file
View file

@ -0,0 +1,22 @@
#pragma once
#include "stdafx.h"
#include "MessageManager.h"
class BaseLoader
{
protected:
bool _checkOnly;
void Log(string message)
{
if(!_checkOnly) {
MessageManager::Log(message);
}
}
public:
BaseLoader(bool checkOnly = false)
{
_checkOnly = checkOnly;
}
};

View file

@ -513,6 +513,7 @@
<ClInclude Include="BandaiHyperShot.h" />
<ClInclude Include="BandaiMicrophone.h" />
<ClInclude Include="BarcodeBattlerReader.h" />
<ClInclude Include="BaseLoader.h" />
<ClInclude Include="BaseRenderer.h" />
<ClInclude Include="BatteryManager.h" />
<ClInclude Include="BattleBox.h" />

View file

@ -1360,6 +1360,9 @@
<ClInclude Include="HdPackConditions.h">
<Filter>HdPacks</Filter>
</ClInclude>
<ClInclude Include="BaseLoader.h">
<Filter>Nes\RomLoader</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View file

@ -8,8 +8,9 @@
#include "MessageManager.h"
#include "MapperFactory.h"
#include "GameDatabase.h"
#include "BaseLoader.h"
class FdsLoader
class FdsLoader : public BaseLoader
{
private:
const size_t FdsDiskSideCapacity = 65500;
@ -62,13 +63,17 @@ private:
if(biosFile) {
return vector<uint8_t>(std::istreambuf_iterator<char>(biosFile), {});
} else {
MessageManager::SendNotification(ConsoleNotificationType::FdsBiosNotFound);
if(!_checkOnly) {
MessageManager::SendNotification(ConsoleNotificationType::FdsBiosNotFound);
}
}
}
return {};
}
public:
using BaseLoader::BaseLoader;
vector<uint8_t> RebuildFdsFile(vector<vector<uint8_t>> diskData, bool needHeader)
{
vector<uint8_t> output;
@ -159,7 +164,7 @@ public:
}
//Setup default controllers
if(EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput)) {
if(!_checkOnly && EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput)) {
GameDatabase::InitializeInputDevices("", GameSystem::FDS);
}

View file

@ -1,8 +1,9 @@
#pragma once
#include "stdafx.h"
#include "RomData.h"
#include "BaseLoader.h"
class NsfLoader
class NsfLoader : public BaseLoader
{
private:
void Read(uint8_t* &data, uint8_t& dest)
@ -51,27 +52,27 @@ protected:
}
//Log window output
MessageManager::Log("[NSF] Region: " + string(header.Flags == 0x00 ? "NTSC" : (header.Flags == 0x01 ? "PAL" : "NTSC & PAL")));
Log("[NSF] Region: " + string(header.Flags == 0x00 ? "NTSC" : (header.Flags == 0x01 ? "PAL" : "NTSC & PAL")));
if(header.PlaySpeedNtsc > 0) {
MessageManager::Log("[NSF] Play speed (NTSC): " + std::to_string(1000000.0 / (double)header.PlaySpeedNtsc) + " Hz");
Log("[NSF] Play speed (NTSC): " + std::to_string(1000000.0 / (double)header.PlaySpeedNtsc) + " Hz");
}
if(header.PlaySpeedPal > 0) {
MessageManager::Log("[NSF] Play speed (PAL): " + std::to_string(1000000.0 / (double)header.PlaySpeedPal) + " Hz");
Log("[NSF] Play speed (PAL): " + std::to_string(1000000.0 / (double)header.PlaySpeedPal) + " Hz");
}
MessageManager::Log("[NSF] Title: " + string(header.SongName));
MessageManager::Log("[NSF] Artist: " + string(header.ArtistName));
MessageManager::Log("[NSF] Copyright: " + string(header.CopyrightHolder));
MessageManager::Log("[NSF] Ripper: " + string(header.RipperName));
Log("[NSF] Title: " + string(header.SongName));
Log("[NSF] Artist: " + string(header.ArtistName));
Log("[NSF] Copyright: " + string(header.CopyrightHolder));
Log("[NSF] Ripper: " + string(header.RipperName));
stringstream ss;
ss << "[NSF] Load Address: 0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << header.LoadAddress;
MessageManager::Log(ss.str());
Log(ss.str());
ss = stringstream();
ss << "[NSF] Init Address: 0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << header.InitAddress;
MessageManager::Log(ss.str());
Log(ss.str());
ss = stringstream();
ss << "[NSF] Play Address: 0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << header.PlayAddress;
MessageManager::Log(ss.str());
Log(ss.str());
vector<string> chips;
if(header.SoundChips & 0x01) {
@ -104,8 +105,8 @@ protected:
ss << chips[i];
}
MessageManager::Log("[NSF] Sound Chips: " + ss.str());
MessageManager::Log("[NSF] ROM size: " + std::to_string(romData.PrgRom.size() / 1024) + " KB");
Log("[NSF] Sound Chips: " + ss.str());
Log("[NSF] ROM size: " + std::to_string(romData.PrgRom.size() / 1024) + " KB");
}
void InitHeader(NsfHeader& header)
@ -119,6 +120,8 @@ protected:
}
public:
using BaseLoader::BaseLoader;
RomData LoadRom(vector<uint8_t>& romFile)
{
RomData romData;

View file

@ -178,6 +178,8 @@ private:
}
public:
using NsfLoader::NsfLoader;
RomData LoadRom(vector<uint8_t>& romFile)
{
RomData romData;

View file

@ -35,35 +35,35 @@ bool RomLoader::LoadFile(string filename, vector<uint8_t> &fileData)
string romName = FolderUtilities::GetFilename(filename, true);
uint32_t crc = CRC32::GetCRC(fileData.data(), fileData.size());
MessageManager::Log("");
MessageManager::Log("Loading rom: " + romName);
Log("");
Log("Loading rom: " + romName);
stringstream crcHex;
crcHex << std::hex << std::uppercase << std::setfill('0') << std::setw(8) << crc;
MessageManager::Log("File CRC32: 0x" + crcHex.str());
Log("File CRC32: 0x" + crcHex.str());
if(memcmp(fileData.data(), "NES\x1a", 4) == 0) {
iNesLoader loader;
iNesLoader loader(_checkOnly);
_romData = loader.LoadRom(fileData, nullptr);
} else if(memcmp(fileData.data(), "FDS\x1a", 4) == 0 || memcmp(fileData.data(), "\x1*NINTENDO-HVC*", 15) == 0) {
FdsLoader loader;
FdsLoader loader(_checkOnly);
_romData = loader.LoadRom(fileData, _filename);
} else if(memcmp(fileData.data(), "NESM\x1a", 5) == 0) {
NsfLoader loader;
NsfLoader loader(_checkOnly);
_romData = loader.LoadRom(fileData);
} else if(memcmp(fileData.data(), "NSFE", 4) == 0) {
NsfeLoader loader;
NsfeLoader loader(_checkOnly);
_romData = loader.LoadRom(fileData);
} else if(memcmp(fileData.data(), "UNIF", 4) == 0) {
UnifLoader loader;
UnifLoader loader(_checkOnly);
_romData = loader.LoadRom(fileData);
} else {
NESHeader header = {};
if(GameDatabase::GetiNesHeader(crc, header)) {
MessageManager::Log("[DB] Headerless ROM file found - using game database data.");
Log("[DB] Headerless ROM file found - using game database data.");
iNesLoader loader;
_romData = loader.LoadRom(fileData, &header);
} else {
MessageManager::Log("Invalid rom file.");
Log("Invalid rom file.");
_romData.Error = true;
}
}
@ -100,7 +100,7 @@ string RomLoader::FindMatchingRomInFile(string filePath, HashInfo hashInfo)
shared_ptr<ArchiveReader> reader = ArchiveReader::GetReader(filePath);
if(reader) {
for(string file : reader->GetFileList(VirtualFile::RomExtensions)) {
RomLoader loader;
RomLoader loader(true);
vector<uint8_t> fileData;
if(loader.LoadFile(filePath)) {
if(hashInfo.Crc32Hash == loader._romData.Crc32 || hashInfo.Sha1Hash.compare(loader._romData.Sha1) == 0) {
@ -109,7 +109,7 @@ string RomLoader::FindMatchingRomInFile(string filePath, HashInfo hashInfo)
}
}
} else {
RomLoader loader;
RomLoader loader(true);
vector<uint8_t> fileData;
if(loader.LoadFile(filePath)) {
if(hashInfo.Crc32Hash == loader._romData.Crc32 || hashInfo.Sha1Hash.compare(loader._romData.Sha1) == 0) {

View file

@ -2,17 +2,20 @@
#include "stdafx.h"
#include "VirtualFile.h"
#include "RomData.h"
#include "BaseLoader.h"
class ArchiveReader;
class RomLoader
class RomLoader : public BaseLoader
{
private:
RomData _romData;
string _filename;
static string FindMatchingRomInFile(string filePath, HashInfo hashInfo);
public:
using BaseLoader::BaseLoader;
bool LoadFile(VirtualFile romFile);
bool LoadFile(string filename, vector<uint8_t> &fileData);

View file

@ -1,5 +1,6 @@
#pragma once
#include "stdafx.h"
#include <unordered_map>
#include "../Utilities/CRC32.h"
#include "../Utilities/md5.h"
#include "../Utilities/HexUtilities.h"
@ -8,9 +9,9 @@
#include "UnifBoards.h"
#include "MessageManager.h"
#include "EmulationSettings.h"
#include <unordered_map>
#include "BaseLoader.h"
class UnifLoader
class UnifLoader : public BaseLoader
{
private:
static std::unordered_map<string, int> _boardMappings;
@ -85,7 +86,7 @@ private:
if(_mapperName.size() > 0) {
romData.MapperID = GetMapperID(_mapperName);
if(romData.MapperID == UnifBoards::UnknownBoard) {
MessageManager::Log("[UNIF] Error: Unknown board");
Log("[UNIF] Error: Unknown board");
}
} else {
romData.Error = true;
@ -139,6 +140,8 @@ private:
}
public:
using BaseLoader::BaseLoader;
static int32_t GetMapperID(string mapperName)
{
string prefix = mapperName.substr(0, 4);
@ -183,12 +186,12 @@ public:
romData.PrgChrCrc32 = CRC32::GetCRC(fullRom.data(), fullRom.size());
romData.PrgChrMd5 = GetMd5Sum(fullRom.data(), fullRom.size());
MessageManager::Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.PrgChrCrc32));
MessageManager::Log("[UNIF] Board Name: " + _mapperName);
MessageManager::Log("[UNIF] PRG ROM: " + std::to_string(romData.PrgRom.size() / 1024) + " KB");
MessageManager::Log("[UNIF] CHR ROM: " + std::to_string(romData.ChrRom.size() / 1024) + " KB");
Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.PrgChrCrc32));
Log("[UNIF] Board Name: " + _mapperName);
Log("[UNIF] PRG ROM: " + std::to_string(romData.PrgRom.size() / 1024) + " KB");
Log("[UNIF] CHR ROM: " + std::to_string(romData.ChrRom.size() / 1024) + " KB");
if(romData.ChrRom.size() == 0) {
MessageManager::Log("[UNIF] CHR RAM: 8 KB");
Log("[UNIF] CHR RAM: 8 KB");
}
string mirroringType;
@ -200,13 +203,17 @@ public:
case MirroringType::FourScreens: mirroringType = "Four Screens"; break;
}
MessageManager::Log("[UNIF] Mirroring: " + mirroringType);
MessageManager::Log("[UNIF] Battery: " + string(romData.HasBattery ? "Yes" : "No"));
Log("[UNIF] Mirroring: " + mirroringType);
Log("[UNIF] Battery: " + string(romData.HasBattery ? "Yes" : "No"));
GameDatabase::SetGameInfo(romData.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase));
if(!_checkOnly) {
GameDatabase::SetGameInfo(romData.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase));
}
if(romData.MapperID == UnifBoards::UnknownBoard) {
MessageManager::DisplayMessage("Error", "UnsupportedMapper", "UNIF: " + _mapperName);
if(!_checkOnly) {
MessageManager::DisplayMessage("Error", "UnsupportedMapper", "UNIF: " + _mapperName);
}
romData.Error = true;
}
}

View file

@ -77,33 +77,35 @@ RomData iNesLoader::LoadRom(vector<uint8_t>& romFile, NESHeader *preloadedHeader
romData.PrgCrc32 = CRC32::GetCRC(romData.PrgRom.data(), romData.PrgRom.size());
MessageManager::Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.PrgChrCrc32));
Log("PRG+CHR CRC32: 0x" + HexUtilities::ToHex(romData.PrgChrCrc32));
if(romData.IsNes20Header) {
MessageManager::Log("[iNes] NES 2.0 file: Yes");
Log("[iNes] NES 2.0 file: Yes");
}
MessageManager::Log("[iNes] Mapper: " + std::to_string(romData.MapperID) + " Sub:" + std::to_string(romData.SubMapperID));
MessageManager::Log("[iNes] PRG ROM: " + std::to_string(romData.PrgRom.size()/1024) + " KB");
MessageManager::Log("[iNes] CHR ROM: " + std::to_string(romData.ChrRom.size()/1024) + " KB");
Log("[iNes] Mapper: " + std::to_string(romData.MapperID) + " Sub:" + std::to_string(romData.SubMapperID));
Log("[iNes] PRG ROM: " + std::to_string(romData.PrgRom.size()/1024) + " KB");
Log("[iNes] CHR ROM: " + std::to_string(romData.ChrRom.size()/1024) + " KB");
if(romData.ChrRamSize > 0 || romData.IsNes20Header) {
MessageManager::Log("[iNes] CHR RAM: " + std::to_string(romData.ChrRamSize / 1024) + " KB");
Log("[iNes] CHR RAM: " + std::to_string(romData.ChrRamSize / 1024) + " KB");
} else if(romData.ChrRom.size() == 0) {
MessageManager::Log("[iNes] CHR RAM: 8 KB");
Log("[iNes] CHR RAM: 8 KB");
}
if(romData.WorkRamSize > 0 || romData.IsNes20Header) {
MessageManager::Log("[iNes] Work RAM: " + std::to_string(romData.WorkRamSize / 1024) + " KB");
Log("[iNes] Work RAM: " + std::to_string(romData.WorkRamSize / 1024) + " KB");
}
if(romData.SaveRamSize > 0 || romData.IsNes20Header) {
MessageManager::Log("[iNes] Save RAM: " + std::to_string(romData.SaveRamSize / 1024) + " KB");
Log("[iNes] Save RAM: " + std::to_string(romData.SaveRamSize / 1024) + " KB");
}
MessageManager::Log("[iNes] Mirroring: " + string(romData.Mirroring == MirroringType::Horizontal ? "Horizontal" : romData.Mirroring == MirroringType::Vertical ? "Vertical" : "Four Screens"));
MessageManager::Log("[iNes] Battery: " + string(romData.HasBattery ? "Yes" : "No"));
Log("[iNes] Mirroring: " + string(romData.Mirroring == MirroringType::Horizontal ? "Horizontal" : romData.Mirroring == MirroringType::Vertical ? "Vertical" : "Four Screens"));
Log("[iNes] Battery: " + string(romData.HasBattery ? "Yes" : "No"));
if(romData.HasTrainer) {
MessageManager::Log("[iNes] Trainer: Yes");
Log("[iNes] Trainer: Yes");
}
GameDatabase::SetGameInfo(romData.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase) && header.GetRomHeaderVersion() != RomHeaderVersion::Nes2_0);
if(!_checkOnly) {
GameDatabase::SetGameInfo(romData.PrgChrCrc32, romData, !EmulationSettings::CheckFlag(EmulationFlags::DisableGameDatabase) && header.GetRomHeaderVersion() != RomHeaderVersion::Nes2_0);
}
return romData;
}

View file

@ -1,9 +1,12 @@
#pragma once
#include "stdafx.h"
#include "RomData.h"
#include "BaseLoader.h"
class iNesLoader
class iNesLoader : public BaseLoader
{
public:
using BaseLoader::BaseLoader;
RomData LoadRom(vector<uint8_t>& romFile, NESHeader *preloadedHeader);
};

View file

@ -231,7 +231,7 @@ namespace InteropEmu {
romInfo.Format = Console::GetRomFormat();
romInfo.IsChrRam = Console::IsChrRam();
} else {
RomLoader romLoader;
RomLoader romLoader(true);
if(romLoader.LoadFile(romPath)) {
RomData romData = romLoader.GetRomData();