1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-26 10:29:31 +00:00

Implements ROM::Request::validate.

It now also validates ROM sizes, so can no longer take a const Map.
This commit is contained in:
Thomas Harte 2021-06-04 18:54:50 -04:00
parent d923fe72c0
commit f4db4c3a73
12 changed files with 49 additions and 14 deletions

View File

@ -811,7 +811,7 @@ template <bool has_fdc> class ConcreteMachine:
}
// Fetch and verify the ROMs.
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -123,7 +123,7 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
// Grab a copy of the ROM and convert it into big-endian data.
ROM::Request request(rom_name);
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -76,7 +76,7 @@ class ConcreteMachine:
constexpr ROM::Name rom_name = ROM::Name::AtariSTTOS100;
ROM::Request request(rom_name);
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -129,7 +129,7 @@ class ConcreteMachine:
constexpr ROM::Name rom_name = ROM::Name::ColecoVisionBIOS;
const ROM::Request request(rom_name);
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -82,7 +82,7 @@ template <bool has_scsi_bus> class ConcreteMachine:
if(target.has_ap6_rom) {
request = request && ::ROM::Request(::ROM::Name::PRESAdvancedPlus6);
}
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -219,7 +219,7 @@ class ConcreteMachine:
request = bios_request;
}
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -143,7 +143,8 @@ class ConcreteMachine:
const bool is_japanese = target.region == Target::Region::Japan;
const ROM::Name bios_name = is_japanese ? ROM::Name::MasterSystemJapaneseBIOS : ROM::Name::MasterSystemWesternBIOS;
ROM::Request request(bios_name, true);
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
request.validate(roms);
const auto rom = roms.find(bios_name);
if(rom == roms.end()) {

View File

@ -330,7 +330,7 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface, CPU::MOS
break;
}
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -157,7 +157,7 @@ template<Model model> class ConcreteMachine:
// TODO: possibly accept the +3 ROM in multiple parts?
}
const auto request = ROM::Request(rom_name);
const auto roms = rom_fetcher(request);
auto roms = rom_fetcher(request);
if(!request.validate(roms)) {
throw ROMMachine::Error::MissingROMs;
}

View File

@ -28,9 +28,8 @@ Request Request::operator ||(const Request &rhs) {
return *this;
}
bool Request::validate(const Map &) const {
/* TODO. */
return true;
bool Request::validate(Map &map) const {
return node.validate(map);
}
std::vector<ROM::Description> Request::all_descriptions() const {
@ -50,6 +49,38 @@ void Request::Node::add_descriptions(std::vector<Description> &result) const {
}
}
bool Request::Node::validate(Map &map) const {
// Leaf nodes are easy: check that the named ROM is present,
// unless it's optional, in which case it is always valid.
//
// If it is present, make sure it's the proper size.
if(type == Type::One) {
auto rom = map.find(name);
if(rom == map.end()) {
return is_optional;
}
const Description description(name);
rom->second.resize(description.size);
return true;
}
// This is a collection node then. Check for both any or all
// simultaneously, since all nodes will need to be visited
// regardless of any/all in order to ensure proper sizing.
bool has_all = true;
bool has_any = false;
for(const auto &child: children) {
const bool is_valid = child.validate(map);
has_all &= is_valid;
has_any |= is_valid;
}
return (type == Type::Any && has_any) || (type == Type::All && has_all);
}
std::optional<Description> Description::from_crc(uint32_t crc32) {
for(int name = 1; name <= SpectrumPlus3; name++) {
const Description candidate = Description(ROM::Name(name));

View File

@ -156,7 +156,9 @@ struct Request {
/// Inspects the ROMMap to ensure that it satisfies this @c Request.
/// @c returns @c true if the request is satisfied; @c false otherwise.
bool validate(const Map &) const;
///
/// All ROMs in the map will be resized to their idiomatic sizes.
bool validate(Map &) const;
std::vector<Description> all_descriptions() const;
@ -174,6 +176,7 @@ struct Request {
std::vector<Node> children;
void add_descriptions(std::vector<Description> &) const;
bool validate(Map &) const;
};
Node node;
};

View File

@ -106,7 +106,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--rompath=/Users/thomasharte/Projects/CLK/ROMImages"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "--help"