2021-06-04 01:55:59 +00:00
|
|
|
//
|
|
|
|
// ROMCatalogue.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 01/06/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2021-06-04 01:55:59 +00:00
|
|
|
|
2021-06-07 02:36:26 +00:00
|
|
|
#include <algorithm>
|
2023-05-25 20:06:13 +00:00
|
|
|
#include <cstdint>
|
2021-06-05 02:03:08 +00:00
|
|
|
#include <functional>
|
2021-06-04 02:28:30 +00:00
|
|
|
#include <map>
|
2021-06-04 02:39:18 +00:00
|
|
|
#include <optional>
|
2021-06-06 18:24:38 +00:00
|
|
|
#include <set>
|
2021-06-04 02:39:18 +00:00
|
|
|
#include <string>
|
2021-06-04 01:55:59 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace ROM {
|
|
|
|
|
|
|
|
enum Name {
|
2021-06-06 01:09:35 +00:00
|
|
|
None,
|
2021-06-04 01:55:59 +00:00
|
|
|
|
|
|
|
// Acorn.
|
|
|
|
AcornBASICII,
|
|
|
|
AcornElectronMOS100,
|
|
|
|
PRESADFSSlot1,
|
|
|
|
PRESADFSSlot2,
|
|
|
|
AcornADFS,
|
|
|
|
PRESAdvancedPlus6,
|
|
|
|
Acorn1770DFS,
|
|
|
|
|
2021-07-16 01:09:20 +00:00
|
|
|
// Amiga.
|
|
|
|
AmigaKickstart10,
|
|
|
|
AmigaKickstart11,
|
|
|
|
AmigaKickstart12,
|
|
|
|
AmigaA500Kickstart13,
|
|
|
|
AmigaA3000Kickstart13,
|
|
|
|
AmigaKickstart20,
|
|
|
|
AmigaA500PlusKickstart204,
|
|
|
|
AmigaA600Kickstart205,
|
|
|
|
AmigaA500Kickstart31,
|
|
|
|
|
2021-08-07 20:56:18 +00:00
|
|
|
AmigaDiagROM121,
|
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
// Amstrad CPC.
|
|
|
|
AMSDOS,
|
|
|
|
CPC464Firmware, CPC464BASIC,
|
|
|
|
CPC664Firmware, CPC664BASIC,
|
|
|
|
CPC6128Firmware, CPC6128BASIC,
|
|
|
|
|
|
|
|
// Apple II.
|
|
|
|
AppleIIOriginal,
|
|
|
|
AppleIIPlus,
|
|
|
|
AppleIICharacter,
|
|
|
|
AppleIIe,
|
|
|
|
AppleIIeCharacter,
|
|
|
|
AppleIIEnhancedE,
|
|
|
|
AppleIIEnhancedECharacter,
|
2022-08-22 02:03:52 +00:00
|
|
|
AppleIISCSICard,
|
2021-06-04 01:55:59 +00:00
|
|
|
|
|
|
|
// Apple IIgs.
|
|
|
|
AppleIIgsROM00,
|
|
|
|
AppleIIgsROM01,
|
|
|
|
AppleIIgsROM03,
|
|
|
|
AppleIIgsMicrocontrollerROM03,
|
2021-06-04 23:19:55 +00:00
|
|
|
AppleIIgsCharacter,
|
2021-06-04 01:55:59 +00:00
|
|
|
|
|
|
|
// Atari ST.
|
|
|
|
AtariSTTOS100,
|
|
|
|
AtariSTTOS104,
|
|
|
|
|
|
|
|
// ColecoVision.
|
|
|
|
ColecoVisionBIOS,
|
|
|
|
|
|
|
|
// Commodore 1540/1541.
|
|
|
|
Commodore1540,
|
|
|
|
Commodore1541,
|
|
|
|
|
|
|
|
// Disk II.
|
|
|
|
DiskIIStateMachine16Sector,
|
|
|
|
DiskIIBoot16Sector,
|
|
|
|
DiskIIStateMachine13Sector,
|
|
|
|
DiskIIBoot13Sector,
|
|
|
|
|
2021-06-15 01:17:09 +00:00
|
|
|
// Enterprise.
|
2021-06-20 02:59:09 +00:00
|
|
|
EnterpriseEXOS10,
|
|
|
|
EnterpriseEXOS20,
|
|
|
|
EnterpriseEXOS21,
|
|
|
|
EnterpriseEXOS23,
|
|
|
|
|
|
|
|
EnterpriseBASIC10,
|
|
|
|
EnterpriseBASIC10Part1,
|
|
|
|
EnterpriseBASIC10Part2,
|
|
|
|
EnterpriseBASIC11,
|
|
|
|
EnterpriseBASIC11Suffixed,
|
|
|
|
EnterpriseBASIC21,
|
2021-06-15 01:17:09 +00:00
|
|
|
|
2021-06-21 00:30:54 +00:00
|
|
|
EnterpriseEPDOS,
|
|
|
|
EnterpriseEXDOS,
|
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
// Macintosh.
|
|
|
|
Macintosh128k,
|
|
|
|
Macintosh512k,
|
|
|
|
MacintoshPlus,
|
|
|
|
|
|
|
|
// Master System.
|
|
|
|
MasterSystemJapaneseBIOS,
|
|
|
|
MasterSystemWesternBIOS,
|
|
|
|
|
|
|
|
// MSX.
|
|
|
|
MSXGenericBIOS,
|
|
|
|
MSXJapaneseBIOS,
|
|
|
|
MSXAmericanBIOS,
|
|
|
|
MSXEuropeanBIOS,
|
|
|
|
MSXDOS,
|
2023-01-10 23:17:17 +00:00
|
|
|
|
|
|
|
MSX2GenericBIOS,
|
2023-01-11 17:56:09 +00:00
|
|
|
MSX2Extension,
|
2023-05-13 03:33:28 +00:00
|
|
|
MSXMusic,
|
2021-06-04 01:55:59 +00:00
|
|
|
|
|
|
|
// Oric.
|
|
|
|
OricColourROM,
|
|
|
|
OricBASIC10,
|
|
|
|
OricBASIC11,
|
|
|
|
OricPravetzBASIC,
|
|
|
|
OricByteDrive500,
|
|
|
|
OricJasmin,
|
|
|
|
OricMicrodisc,
|
|
|
|
Oric8DOSBoot,
|
|
|
|
|
2023-11-15 16:32:23 +00:00
|
|
|
// PCCompatible.
|
|
|
|
PCCompatibleGLaBIOS,
|
2023-12-07 03:56:09 +00:00
|
|
|
PCCompatibleGLaTICK,
|
2023-11-17 22:15:57 +00:00
|
|
|
PCCompatiblePhoenix80286BIOS,
|
2023-12-27 15:05:41 +00:00
|
|
|
|
2023-11-22 19:11:22 +00:00
|
|
|
PCCompatibleMDAFont,
|
2023-12-06 04:01:08 +00:00
|
|
|
PCCompatibleCGAFont,
|
2023-12-27 15:05:41 +00:00
|
|
|
PCCompatibleEGABIOS,
|
|
|
|
PCCompatibleVGABIOS,
|
2023-11-15 16:32:23 +00:00
|
|
|
|
2021-06-07 00:34:55 +00:00
|
|
|
// Sinclair QL.
|
|
|
|
SinclairQLJS,
|
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
// Vic-20.
|
|
|
|
Vic20BASIC,
|
|
|
|
Vic20EnglishCharacters,
|
|
|
|
Vic20EnglishPALKernel,
|
|
|
|
Vic20EnglishNTSCKernel,
|
|
|
|
Vic20DanishCharacters,
|
|
|
|
Vic20DanishKernel,
|
|
|
|
Vic20JapaneseCharacters,
|
|
|
|
Vic20JapaneseKernel,
|
|
|
|
Vic20SwedishCharacters,
|
|
|
|
Vic20SwedishKernel,
|
|
|
|
|
|
|
|
// ZX80/81.
|
|
|
|
ZX80,
|
|
|
|
ZX81,
|
|
|
|
|
|
|
|
// ZX Spectrum.
|
|
|
|
Spectrum48k,
|
|
|
|
Spectrum128k,
|
|
|
|
SpecrumPlus2,
|
|
|
|
SpectrumPlus3,
|
2021-06-07 00:34:55 +00:00
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using Map = std::map<ROM::Name, std::vector<uint8_t>>;
|
|
|
|
|
|
|
|
struct Description {
|
|
|
|
/// The ROM's enum name.
|
2021-06-06 01:09:35 +00:00
|
|
|
Name name = Name::None;
|
2021-06-04 01:55:59 +00:00
|
|
|
/// The machine with which this ROM is associated, in a form that is safe for using as
|
|
|
|
/// part of a file name.
|
|
|
|
std::string machine_name;
|
|
|
|
/// A descriptive name for this ROM, suitable for use in a bullet-point list, a bracket
|
|
|
|
/// clause, etc, e.g. "the Electron MOS 1.0".
|
|
|
|
std::string descriptive_name;
|
|
|
|
/// All idiomatic file name for this ROM, e.g. "os10.rom".
|
|
|
|
std::vector<std::string> file_names;
|
|
|
|
/// The expected size of this ROM in bytes, e.g. 32768.
|
|
|
|
size_t size = 0;
|
|
|
|
/// CRC32s for all known acceptable copies of this ROM; intended to allow a host platform
|
|
|
|
/// to test user-provided ROMs of unknown provenance. **Not** intended to be used
|
|
|
|
/// to exclude ROMs where the user's intent is otherwise clear.
|
2021-06-06 18:24:38 +00:00
|
|
|
std::set<uint32_t> crc32s;
|
2021-06-04 01:55:59 +00:00
|
|
|
|
|
|
|
/// Constructs the @c Description that correlates to @c name.
|
|
|
|
Description(Name name);
|
2021-06-04 02:39:18 +00:00
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
/// Constructs the @c Description that correlates to @c crc32, if any.
|
2021-06-04 02:39:18 +00:00
|
|
|
static std::optional<Description> from_crc(uint32_t crc32);
|
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
enum DescriptionFlag {
|
|
|
|
Size = 1 << 0,
|
|
|
|
CRC = 1 << 1,
|
|
|
|
Filename = 1 << 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Provides a single-line of text describing this ROM, including the usual base text
|
|
|
|
/// plus all the fields provided as @c flags .
|
|
|
|
std::string description(int flags) const;
|
|
|
|
|
2021-06-04 02:39:18 +00:00
|
|
|
private:
|
|
|
|
template <typename FileNameT, typename CRC32T> Description(
|
2021-06-06 18:24:38 +00:00
|
|
|
Name name, std::string machine_name, std::string descriptive_name, FileNameT file_names, size_t size, CRC32T crc32s = uint32_t(0)
|
2021-06-05 02:03:08 +00:00
|
|
|
) : name{name}, machine_name{machine_name}, descriptive_name{descriptive_name}, file_names{file_names}, size{size}, crc32s{crc32s} {
|
2021-06-06 18:24:38 +00:00
|
|
|
// Slightly lazy: deal with the case where the constructor wasn't provided with any
|
|
|
|
// CRCs by spotting that the set has exactly one member, which has value 0. The alternative
|
|
|
|
// would be to provide a partial specialisation that never put anything into the set.
|
|
|
|
if(this->crc32s.size() == 1 && !*this->crc32s.begin()) {
|
2021-06-05 02:03:08 +00:00
|
|
|
this->crc32s.clear();
|
|
|
|
}
|
|
|
|
}
|
2021-06-04 01:55:59 +00:00
|
|
|
};
|
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
/// @returns a vector of all possible instances of ROM::Description — i.e. descriptions of every ROM
|
|
|
|
/// currently known to the ROM catalogue.
|
2021-06-06 18:24:38 +00:00
|
|
|
std::vector<Description> all_descriptions();
|
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
struct Request {
|
|
|
|
Request(Name name, bool optional = false);
|
2021-06-04 02:39:18 +00:00
|
|
|
Request() {}
|
2021-06-04 01:55:59 +00:00
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
/// Forms the request that would be satisfied by @c this plus the right-hand side.
|
2021-06-04 01:55:59 +00:00
|
|
|
Request operator &&(const Request &);
|
2021-06-06 22:15:00 +00:00
|
|
|
|
|
|
|
/// Forms the request that would be satisfied by either @c this or the right-hand side.
|
2021-06-04 01:55:59 +00:00
|
|
|
Request operator ||(const Request &);
|
|
|
|
|
|
|
|
/// Inspects the ROMMap to ensure that it satisfies this @c Request.
|
|
|
|
/// @c returns @c true if the request is satisfied; @c false otherwise.
|
2021-06-04 22:54:50 +00:00
|
|
|
///
|
|
|
|
/// All ROMs in the map will be resized to their idiomatic sizes.
|
|
|
|
bool validate(Map &) const;
|
2021-06-04 01:55:59 +00:00
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
/// Returns a flattened array of all @c ROM::Descriptions that relate to anything
|
|
|
|
/// anywhere in this ROM request.
|
2021-06-04 01:55:59 +00:00
|
|
|
std::vector<Description> all_descriptions() const;
|
|
|
|
|
2021-06-06 22:15:00 +00:00
|
|
|
/// @returns @c true if this request is empty, i.e. would be satisfied with no ROMs; @c false otherwise.
|
|
|
|
bool empty();
|
|
|
|
|
|
|
|
/// @returns what remains of this ROM request given that everything in @c map has been found.
|
|
|
|
Request subtract(const ROM::Map &map) const;
|
|
|
|
|
2021-06-05 01:53:56 +00:00
|
|
|
enum class ListType {
|
|
|
|
Any, All, Single
|
|
|
|
};
|
|
|
|
void visit(
|
2021-06-07 00:25:26 +00:00
|
|
|
const std::function<void(ListType, size_t size)> &enter_list,
|
2021-06-05 01:53:56 +00:00
|
|
|
const std::function<void(void)> &exit_list,
|
|
|
|
const std::function<void(ROM::Request::ListType type, const ROM::Description &, bool is_optional, size_t remaining)> &add_item
|
|
|
|
) const;
|
|
|
|
|
2021-06-06 22:28:02 +00:00
|
|
|
enum class LineItem {
|
|
|
|
NewList, Description
|
|
|
|
};
|
|
|
|
void visit(
|
|
|
|
const std::function<void(LineItem, ListType, int level, const ROM::Description *, bool is_optional, size_t remaining)> &add_item
|
|
|
|
) const;
|
|
|
|
|
2021-06-07 00:02:13 +00:00
|
|
|
/// @returns a full bullet-pointed list of the requirements of this request, including
|
2021-06-07 00:25:26 +00:00
|
|
|
/// appropriate conjuntives. This text is intended to be glued to the end of an opening
|
|
|
|
/// portion of a sentence, e.g. "Please supply" + request.description(0, L'*').
|
2021-06-07 00:02:13 +00:00
|
|
|
std::wstring description(int description_flags, wchar_t bullet_point);
|
|
|
|
|
2021-06-04 01:55:59 +00:00
|
|
|
private:
|
|
|
|
struct Node {
|
|
|
|
enum class Type {
|
|
|
|
Any, All, One
|
|
|
|
};
|
|
|
|
Type type = Type::One;
|
2021-06-06 01:09:35 +00:00
|
|
|
Name name = Name::None;
|
2021-06-04 01:55:59 +00:00
|
|
|
/// @c true if this ROM is optional for machine startup. Generally indicates something
|
|
|
|
/// that would make emulation more accurate, but not sufficiently so to make it
|
|
|
|
/// a necessity.
|
|
|
|
bool is_optional = false;
|
|
|
|
std::vector<Node> children;
|
|
|
|
|
2021-06-20 02:13:17 +00:00
|
|
|
bool empty() const {
|
|
|
|
return type == Type::One && name == Name::None;
|
|
|
|
}
|
|
|
|
|
2021-06-04 02:39:18 +00:00
|
|
|
void add_descriptions(std::vector<Description> &) const;
|
2021-06-04 22:54:50 +00:00
|
|
|
bool validate(Map &) const;
|
2021-06-05 01:53:56 +00:00
|
|
|
void visit(
|
2021-06-07 00:25:26 +00:00
|
|
|
const std::function<void(ListType, size_t)> &enter_list,
|
2021-06-05 01:53:56 +00:00
|
|
|
const std::function<void(void)> &exit_list,
|
|
|
|
const std::function<void(ROM::Request::ListType type, const ROM::Description &, bool is_optional, size_t remaining)> &add_item
|
|
|
|
) const;
|
2021-06-06 01:09:35 +00:00
|
|
|
bool subtract(const ROM::Map &map);
|
2021-06-07 02:36:26 +00:00
|
|
|
void sort() {
|
|
|
|
// Don't do a full sort, but move anything optional to the back.
|
|
|
|
// This makes them print more nicely; it's a human-facing tweak only.
|
|
|
|
ssize_t index = ssize_t(children.size() - 1);
|
|
|
|
bool has_seen_non_optional = false;
|
|
|
|
while(index >= 0) {
|
|
|
|
has_seen_non_optional |= !children[size_t(index)].is_optional;
|
|
|
|
if(children[size_t(index)].is_optional && has_seen_non_optional) {
|
|
|
|
std::rotate(children.begin() + index, children.begin() + index + 1, children.end());
|
|
|
|
}
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
}
|
2021-06-04 01:55:59 +00:00
|
|
|
};
|
|
|
|
Node node;
|
2021-06-04 23:03:07 +00:00
|
|
|
|
|
|
|
Request append(Node::Type type, const Request &rhs);
|
2021-06-04 01:55:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|