2017-11-05 17:49:28 +00:00
|
|
|
//
|
|
|
|
// MachineForTarget.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/11/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-11-05 17:49:28 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "MachineForTarget.hpp"
|
|
|
|
|
|
|
|
#include "../AmstradCPC/AmstradCPC.hpp"
|
2018-04-14 23:46:15 +00:00
|
|
|
#include "../AppleII/AppleII.hpp"
|
2017-11-05 17:49:28 +00:00
|
|
|
#include "../Atari2600/Atari2600.hpp"
|
2018-02-24 03:47:15 +00:00
|
|
|
#include "../ColecoVision/ColecoVision.hpp"
|
2017-11-05 17:49:28 +00:00
|
|
|
#include "../Commodore/Vic-20/Vic20.hpp"
|
|
|
|
#include "../Electron/Electron.hpp"
|
2017-11-25 18:18:24 +00:00
|
|
|
#include "../MSX/MSX.hpp"
|
2017-11-05 17:49:28 +00:00
|
|
|
#include "../Oric/Oric.hpp"
|
|
|
|
#include "../ZX8081/ZX8081.hpp"
|
|
|
|
|
2018-01-29 03:22:21 +00:00
|
|
|
#include "../../Analyser/Dynamic/MultiMachine/MultiMachine.hpp"
|
2017-11-25 02:36:22 +00:00
|
|
|
#include "TypedDynamicMachine.hpp"
|
2017-11-05 17:49:28 +00:00
|
|
|
|
2018-01-29 03:22:21 +00:00
|
|
|
namespace {
|
2018-01-25 23:28:19 +00:00
|
|
|
|
2018-03-09 20:36:11 +00:00
|
|
|
::Machine::DynamicMachine *MachineForTarget(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher, Machine::Error &error) {
|
2018-01-29 03:22:21 +00:00
|
|
|
error = Machine::Error::None;
|
2018-01-25 23:28:19 +00:00
|
|
|
::Machine::DynamicMachine *machine = nullptr;
|
2018-03-09 20:36:11 +00:00
|
|
|
switch(target->machine) {
|
2018-02-24 03:47:15 +00:00
|
|
|
case Analyser::Machine::AmstradCPC: machine = new Machine::TypedDynamicMachine<AmstradCPC::Machine>(AmstradCPC::Machine::AmstradCPC()); break;
|
2018-04-14 23:46:15 +00:00
|
|
|
case Analyser::Machine::AppleII: machine = new Machine::TypedDynamicMachine<AppleII::Machine>(AppleII::Machine::AppleII()); break;
|
2018-02-24 03:47:15 +00:00
|
|
|
case Analyser::Machine::Atari2600: machine = new Machine::TypedDynamicMachine<Atari2600::Machine>(Atari2600::Machine::Atari2600()); break;
|
|
|
|
case Analyser::Machine::ColecoVision: machine = new Machine::TypedDynamicMachine<Coleco::Vision::Machine>(Coleco::Vision::Machine::ColecoVision()); break;
|
|
|
|
case Analyser::Machine::Electron: machine = new Machine::TypedDynamicMachine<Electron::Machine>(Electron::Machine::Electron()); break;
|
|
|
|
case Analyser::Machine::MSX: machine = new Machine::TypedDynamicMachine<MSX::Machine>(MSX::Machine::MSX()); break;
|
2018-05-09 02:05:43 +00:00
|
|
|
case Analyser::Machine::Oric: machine = new Machine::TypedDynamicMachine<Oric::Machine>(Oric::Machine::Oric(target)); break;
|
2018-02-24 03:47:15 +00:00
|
|
|
case Analyser::Machine::Vic20: machine = new Machine::TypedDynamicMachine<Commodore::Vic20::Machine>(Commodore::Vic20::Machine::Vic20()); break;
|
|
|
|
case Analyser::Machine::ZX8081: machine = new Machine::TypedDynamicMachine<ZX8081::Machine>(ZX8081::Machine::ZX8081(target)); break;
|
2018-01-25 23:28:19 +00:00
|
|
|
|
|
|
|
default:
|
2018-01-29 03:22:21 +00:00
|
|
|
error = Machine::Error::UnknownMachine;
|
2018-01-25 23:28:19 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this shouldn't depend on CRT machine's inclusion of ROM machine.
|
|
|
|
CRTMachine::Machine *crt_machine = machine->crt_machine();
|
|
|
|
if(crt_machine) {
|
|
|
|
if(!machine->crt_machine()->set_rom_fetcher(rom_fetcher)) {
|
|
|
|
delete machine;
|
2018-01-29 03:22:21 +00:00
|
|
|
error = Machine::Error::MissingROM;
|
2018-01-25 23:28:19 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-11-06 01:12:01 +00:00
|
|
|
}
|
2018-01-25 23:28:19 +00:00
|
|
|
|
|
|
|
ConfigurationTarget::Machine *configuration_target = machine->configuration_target();
|
|
|
|
if(configuration_target) {
|
2018-01-29 03:22:21 +00:00
|
|
|
machine->configuration_target()->configure_as_target(target);
|
2018-01-25 23:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return machine;
|
2017-11-06 01:12:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 23:46:15 +00:00
|
|
|
::Machine::DynamicMachine *::Machine::MachineForTargets(const Analyser::Static::TargetList &targets, const ROMMachine::ROMFetcher &rom_fetcher, Error &error) {
|
2018-01-29 03:22:21 +00:00
|
|
|
// Zero targets implies no machine.
|
|
|
|
if(targets.empty()) {
|
|
|
|
error = Error::NoTargets;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's more than one target, get all the machines and combine them into a multimachine.
|
|
|
|
if(targets.size() > 1) {
|
|
|
|
std::vector<std::unique_ptr<Machine::DynamicMachine>> machines;
|
|
|
|
for(const auto &target: targets) {
|
2018-03-09 20:36:11 +00:00
|
|
|
machines.emplace_back(MachineForTarget(target.get(), rom_fetcher, error));
|
2018-02-09 01:33:57 +00:00
|
|
|
|
|
|
|
// Exit early if any errors have occurred.
|
|
|
|
if(error != Error::None) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 00:08:02 +00:00
|
|
|
// If a multimachine would just instantly collapse the list to a single machine, do
|
|
|
|
// so without the ongoing baggage of a multimachine.
|
|
|
|
if(Analyser::Dynamic::MultiMachine::would_collapse(machines)) {
|
|
|
|
return machines.front().release();
|
|
|
|
} else {
|
|
|
|
return new Analyser::Dynamic::MultiMachine(std::move(machines));
|
|
|
|
}
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// There's definitely exactly one target.
|
2018-03-09 20:36:11 +00:00
|
|
|
return MachineForTarget(targets.front().get(), rom_fetcher, error);
|
2018-01-29 03:22:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
std::string Machine::ShortNameForTargetMachine(const Analyser::Machine machine) {
|
2017-11-21 02:55:32 +00:00
|
|
|
switch(machine) {
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::AmstradCPC: return "AmstradCPC";
|
2018-04-14 23:46:15 +00:00
|
|
|
case Analyser::Machine::AppleII: return "AppleII";
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::Atari2600: return "Atari2600";
|
2018-02-24 03:47:15 +00:00
|
|
|
case Analyser::Machine::ColecoVision: return "ColecoVision";
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::Electron: return "Electron";
|
|
|
|
case Analyser::Machine::MSX: return "MSX";
|
|
|
|
case Analyser::Machine::Oric: return "Oric";
|
|
|
|
case Analyser::Machine::Vic20: return "Vic20";
|
|
|
|
case Analyser::Machine::ZX8081: return "ZX8081";
|
2017-11-12 21:41:09 +00:00
|
|
|
|
|
|
|
default: return "";
|
2017-11-05 17:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-21 02:55:32 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
std::string Machine::LongNameForTargetMachine(Analyser::Machine machine) {
|
2017-11-21 02:55:32 +00:00
|
|
|
switch(machine) {
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::AmstradCPC: return "Amstrad CPC";
|
2018-04-14 23:46:15 +00:00
|
|
|
case Analyser::Machine::AppleII: return "Apple II";
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::Atari2600: return "Atari 2600";
|
2018-02-24 03:47:15 +00:00
|
|
|
case Analyser::Machine::ColecoVision: return "ColecoVision";
|
2018-01-25 02:48:44 +00:00
|
|
|
case Analyser::Machine::Electron: return "Acorn Electron";
|
|
|
|
case Analyser::Machine::MSX: return "MSX";
|
|
|
|
case Analyser::Machine::Oric: return "Oric";
|
|
|
|
case Analyser::Machine::Vic20: return "Vic 20";
|
|
|
|
case Analyser::Machine::ZX8081: return "ZX80/81";
|
2017-11-21 02:55:32 +00:00
|
|
|
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string, std::vector<std::unique_ptr<Configurable::Option>>> Machine::AllOptionsByMachineName() {
|
|
|
|
std::map<std::string, std::vector<std::unique_ptr<Configurable::Option>>> options;
|
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
options.emplace(std::make_pair(LongNameForTargetMachine(Analyser::Machine::Electron), Electron::get_options()));
|
|
|
|
options.emplace(std::make_pair(LongNameForTargetMachine(Analyser::Machine::MSX), MSX::get_options()));
|
|
|
|
options.emplace(std::make_pair(LongNameForTargetMachine(Analyser::Machine::Oric), Oric::get_options()));
|
|
|
|
options.emplace(std::make_pair(LongNameForTargetMachine(Analyser::Machine::Vic20), Commodore::Vic20::get_options()));
|
|
|
|
options.emplace(std::make_pair(LongNameForTargetMachine(Analyser::Machine::ZX8081), ZX8081::get_options()));
|
2017-11-21 02:55:32 +00:00
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|