2016-08-24 01:35:59 +00:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 23/08/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-08-24 01:35:59 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2018-02-19 13:13:41 +00:00
|
|
|
#include <algorithm>
|
2016-08-27 18:25:16 +00:00
|
|
|
#include <cstdlib>
|
2017-11-10 03:04:49 +00:00
|
|
|
#include <cstring>
|
2018-04-14 16:12:12 +00:00
|
|
|
#include <iterator>
|
2016-08-27 17:42:51 +00:00
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
// Analysers
|
2016-09-15 23:24:59 +00:00
|
|
|
#include "Acorn/StaticAnalyser.hpp"
|
2017-07-31 01:15:20 +00:00
|
|
|
#include "AmstradCPC/StaticAnalyser.hpp"
|
2018-04-14 16:12:12 +00:00
|
|
|
#include "AppleII/StaticAnalyser.hpp"
|
2016-09-15 23:34:45 +00:00
|
|
|
#include "Atari/StaticAnalyser.hpp"
|
2018-02-24 03:47:15 +00:00
|
|
|
#include "Coleco/StaticAnalyser.hpp"
|
2016-09-15 23:24:59 +00:00
|
|
|
#include "Commodore/StaticAnalyser.hpp"
|
2018-05-04 22:02:36 +00:00
|
|
|
#include "DiskII/StaticAnalyser.hpp"
|
2019-06-02 17:39:25 +00:00
|
|
|
#include "Macintosh/StaticAnalyser.hpp"
|
2017-11-25 18:18:24 +00:00
|
|
|
#include "MSX/StaticAnalyser.hpp"
|
2016-10-12 02:20:13 +00:00
|
|
|
#include "Oric/StaticAnalyser.hpp"
|
2018-09-21 02:04:28 +00:00
|
|
|
#include "Sega/StaticAnalyser.hpp"
|
2017-06-04 21:04:06 +00:00
|
|
|
#include "ZX8081/StaticAnalyser.hpp"
|
2016-08-29 12:48:49 +00:00
|
|
|
|
|
|
|
// Cartridges
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Cartridge/Formats/BinaryDump.hpp"
|
|
|
|
#include "../../Storage/Cartridge/Formats/PRG.hpp"
|
2016-08-27 22:26:51 +00:00
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
// Disks
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/AcornADF.hpp"
|
2018-04-28 03:18:45 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/AppleDSK.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/CPCDSK.hpp"
|
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/D64.hpp"
|
2019-06-18 18:32:58 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/MacintoshIMG.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/G64.hpp"
|
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/DMK.hpp"
|
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/HFE.hpp"
|
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/MSXDSK.hpp"
|
2018-04-22 04:21:57 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/NIB.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/OricMFMDSK.hpp"
|
2019-06-05 01:41:09 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/PlusTooBIN.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/SSD.hpp"
|
2018-04-24 02:57:45 +00:00
|
|
|
#include "../../Storage/Disk/DiskImage/Formats/WOZ.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
// Tapes
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/Tape/Formats/CAS.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/CommodoreTAP.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/CSW.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/OricTAP.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/TapePRG.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/TapeUEF.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/TZX.hpp"
|
|
|
|
#include "../../Storage/Tape/Formats/ZX80O81P.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2017-08-27 19:02:13 +00:00
|
|
|
// Target Platform Types
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../Storage/TargetPlatforms.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
using namespace Analyser::Static;
|
2016-08-27 17:42:51 +00:00
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
static Media GetMediaAndPlatforms(const std::string &file_name, TargetPlatform::IntType &potential_platforms) {
|
|
|
|
Media result;
|
|
|
|
|
2016-08-27 18:25:16 +00:00
|
|
|
// Get the extension, if any; it will be assumed that extensions are reliable, so an extension is a broad-phase
|
|
|
|
// test as to file format.
|
2018-04-06 21:42:24 +00:00
|
|
|
std::string::size_type final_dot = file_name.find_last_of(".");
|
|
|
|
if(final_dot == std::string::npos) return result;
|
|
|
|
std::string extension = file_name.substr(final_dot + 1);
|
|
|
|
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
2016-08-27 17:42:51 +00:00
|
|
|
|
2016-08-27 22:26:51 +00:00
|
|
|
#define Insert(list, class, platforms) \
|
|
|
|
list.emplace_back(new Storage::class(file_name));\
|
2017-08-27 19:02:13 +00:00
|
|
|
potential_platforms |= platforms;\
|
2017-08-27 19:20:58 +00:00
|
|
|
TargetPlatform::TypeDistinguisher *distinguisher = dynamic_cast<TargetPlatform::TypeDistinguisher *>(list.back().get());\
|
|
|
|
if(distinguisher) potential_platforms &= distinguisher->target_platform_type();
|
2016-08-27 22:26:51 +00:00
|
|
|
|
2016-08-28 16:20:40 +00:00
|
|
|
#define TryInsert(list, class, platforms) \
|
|
|
|
try {\
|
|
|
|
Insert(list, class, platforms) \
|
|
|
|
} catch(...) {}
|
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
#define Format(ext, list, class, platforms) \
|
|
|
|
if(extension == ext) { \
|
2016-08-28 16:20:40 +00:00
|
|
|
TryInsert(list, class, platforms) \
|
2016-08-27 20:40:21 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 17:39:25 +00:00
|
|
|
Format("80", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 80
|
|
|
|
Format("81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // 81
|
|
|
|
Format("a26", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // A26
|
|
|
|
Format("adf", result.disks, Disk::DiskImageHolder<Storage::Disk::AcornADF>, TargetPlatform::Acorn) // ADF
|
2019-06-06 22:32:11 +00:00
|
|
|
// Format("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::AllCartridge) // BIN (cartridge dump)
|
2019-06-05 01:41:09 +00:00
|
|
|
Format("bin", result.disks, Disk::DiskImageHolder<Storage::Disk::PlusTooBIN>, TargetPlatform::Macintosh) // BIN (PlusToo disk image)
|
2019-06-02 17:39:25 +00:00
|
|
|
Format("cas", result.tapes, Tape::CAS, TargetPlatform::MSX) // CAS
|
|
|
|
Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT
|
|
|
|
Format("col", result.cartridges, Cartridge::BinaryDump, TargetPlatform::ColecoVision) // COL
|
|
|
|
Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW
|
|
|
|
Format("d64", result.disks, Disk::DiskImageHolder<Storage::Disk::D64>, TargetPlatform::Commodore) // D64
|
|
|
|
Format("dmk", result.disks, Disk::DiskImageHolder<Storage::Disk::DMK>, TargetPlatform::MSX) // DMK
|
|
|
|
Format("do", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // DO
|
|
|
|
Format("dsd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // DSD
|
|
|
|
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::CPCDSK>, TargetPlatform::AmstradCPC) // DSK (Amstrad CPC)
|
2019-07-12 02:56:29 +00:00
|
|
|
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // DSK (Apple II)
|
|
|
|
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::Macintosh) // DSK (Macintosh)
|
2019-06-02 17:39:25 +00:00
|
|
|
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::MSXDSK>, TargetPlatform::MSX) // DSK (MSX)
|
|
|
|
Format("dsk", result.disks, Disk::DiskImageHolder<Storage::Disk::OricMFMDSK>, TargetPlatform::Oric) // DSK (Oric)
|
|
|
|
Format("g64", result.disks, Disk::DiskImageHolder<Storage::Disk::G64>, TargetPlatform::Commodore) // G64
|
2018-04-06 21:42:24 +00:00
|
|
|
Format( "hfe",
|
|
|
|
result.disks,
|
|
|
|
Disk::DiskImageHolder<Storage::Disk::HFE>,
|
|
|
|
TargetPlatform::Acorn | TargetPlatform::AmstradCPC | TargetPlatform::Commodore | TargetPlatform::Oric)
|
|
|
|
// HFE (TODO: switch to AllDisk once the MSX stops being so greedy)
|
2019-06-18 18:32:58 +00:00
|
|
|
Format("img", result.disks, Disk::DiskImageHolder<Storage::Disk::MacintoshIMG>, TargetPlatform::Macintosh) // IMG (DiskCopy 4.2)
|
2019-06-02 17:39:25 +00:00
|
|
|
Format("nib", result.disks, Disk::DiskImageHolder<Storage::Disk::NIB>, TargetPlatform::DiskII) // NIB
|
|
|
|
Format("o", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // O
|
|
|
|
Format("p", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P
|
|
|
|
Format("po", result.disks, Disk::DiskImageHolder<Storage::Disk::AppleDSK>, TargetPlatform::DiskII) // PO
|
|
|
|
Format("p81", result.tapes, Tape::ZX80O81P, TargetPlatform::ZX8081) // P81
|
2018-04-06 21:42:24 +00:00
|
|
|
|
|
|
|
// PRG
|
|
|
|
if(extension == "prg") {
|
|
|
|
// try instantiating as a ROM; failing that accept as a tape
|
|
|
|
try {
|
|
|
|
Insert(result.cartridges, Cartridge::PRG, TargetPlatform::Commodore)
|
|
|
|
} catch(...) {
|
2016-08-27 22:17:40 +00:00
|
|
|
try {
|
2018-04-06 21:42:24 +00:00
|
|
|
Insert(result.tapes, Tape::PRG, TargetPlatform::Commodore)
|
|
|
|
} catch(...) {}
|
2016-08-27 22:17:40 +00:00
|
|
|
}
|
2018-04-06 21:42:24 +00:00
|
|
|
}
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
Format( "rom",
|
|
|
|
result.cartridges,
|
|
|
|
Cartridge::BinaryDump,
|
2019-06-02 17:39:25 +00:00
|
|
|
TargetPlatform::AcornElectron | TargetPlatform::ColecoVision | TargetPlatform::MSX) // ROM
|
|
|
|
Format("sg", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Sega) // SG
|
|
|
|
Format("sms", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Sega) // SMS
|
|
|
|
Format("ssd", result.disks, Disk::DiskImageHolder<Storage::Disk::SSD>, TargetPlatform::Acorn) // SSD
|
|
|
|
Format("tap", result.tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore)
|
|
|
|
Format("tap", result.tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric)
|
|
|
|
Format("tsx", result.tapes, Tape::TZX, TargetPlatform::MSX) // TSX
|
|
|
|
Format("tzx", result.tapes, Tape::TZX, TargetPlatform::ZX8081) // TZX
|
|
|
|
Format("uef", result.tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape)
|
|
|
|
Format("woz", result.disks, Disk::DiskImageHolder<Storage::Disk::WOZ>, TargetPlatform::DiskII) // WOZ
|
2016-08-27 20:40:21 +00:00
|
|
|
|
|
|
|
#undef Format
|
2016-08-27 22:26:51 +00:00
|
|
|
#undef Insert
|
2017-02-11 18:36:36 +00:00
|
|
|
#undef TryInsert
|
2016-08-27 17:42:51 +00:00
|
|
|
|
2017-08-17 14:48:29 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-06 21:42:24 +00:00
|
|
|
Media Analyser::Static::GetMedia(const std::string &file_name) {
|
2017-08-27 19:02:13 +00:00
|
|
|
TargetPlatform::IntType throwaway;
|
2017-08-17 14:48:29 +00:00
|
|
|
return GetMediaAndPlatforms(file_name, throwaway);
|
|
|
|
}
|
|
|
|
|
2018-04-14 16:12:12 +00:00
|
|
|
TargetList Analyser::Static::GetTargets(const std::string &file_name) {
|
|
|
|
TargetList targets;
|
2017-08-17 14:48:29 +00:00
|
|
|
|
|
|
|
// Collect all disks, tapes and ROMs as can be extrapolated from this file, forming the
|
|
|
|
// union of all platforms this file might be a target for.
|
2017-08-27 19:02:13 +00:00
|
|
|
TargetPlatform::IntType potential_platforms = 0;
|
2017-08-17 14:48:29 +00:00
|
|
|
Media media = GetMediaAndPlatforms(file_name, potential_platforms);
|
|
|
|
|
|
|
|
// Hand off to platform-specific determination of whether these things are actually compatible and,
|
|
|
|
// if so, how to load them.
|
2018-04-14 16:12:12 +00:00
|
|
|
#define Append(x) {\
|
|
|
|
auto new_targets = x::GetTargets(media, file_name, potential_platforms);\
|
|
|
|
std::move(new_targets.begin(), new_targets.end(), std::back_inserter(targets));\
|
|
|
|
}
|
|
|
|
if(potential_platforms & TargetPlatform::Acorn) Append(Acorn);
|
|
|
|
if(potential_platforms & TargetPlatform::AmstradCPC) Append(AmstradCPC);
|
|
|
|
if(potential_platforms & TargetPlatform::AppleII) Append(AppleII);
|
|
|
|
if(potential_platforms & TargetPlatform::Atari2600) Append(Atari);
|
|
|
|
if(potential_platforms & TargetPlatform::ColecoVision) Append(Coleco);
|
|
|
|
if(potential_platforms & TargetPlatform::Commodore) Append(Commodore);
|
2018-05-04 22:02:36 +00:00
|
|
|
if(potential_platforms & TargetPlatform::DiskII) Append(DiskII);
|
2019-06-02 17:39:25 +00:00
|
|
|
if(potential_platforms & TargetPlatform::Macintosh) Append(Macintosh);
|
2018-04-14 16:12:12 +00:00
|
|
|
if(potential_platforms & TargetPlatform::MSX) Append(MSX);
|
|
|
|
if(potential_platforms & TargetPlatform::Oric) Append(Oric);
|
2019-06-02 17:39:25 +00:00
|
|
|
if(potential_platforms & TargetPlatform::Sega) Append(Sega);
|
2018-04-14 16:12:12 +00:00
|
|
|
if(potential_platforms & TargetPlatform::ZX8081) Append(ZX8081);
|
|
|
|
#undef Append
|
2017-08-17 14:48:29 +00:00
|
|
|
|
2017-05-07 02:19:08 +00:00
|
|
|
// Reset any tapes to their initial position
|
2018-05-01 02:23:57 +00:00
|
|
|
for(const auto &target : targets) {
|
2018-01-25 03:35:54 +00:00
|
|
|
for(auto &tape : target->media.tapes) {
|
2017-05-07 02:19:08 +00:00
|
|
|
tape->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 03:16:46 +00:00
|
|
|
// Sort by initial confidence. Use a stable sort in case any of the machine-specific analysers
|
|
|
|
// picked their insertion order carefully.
|
2018-02-19 13:13:41 +00:00
|
|
|
std::stable_sort(targets.begin(), targets.end(),
|
2018-05-05 23:32:20 +00:00
|
|
|
[] (const std::unique_ptr<Target> &a, const std::unique_ptr<Target> &b) {
|
|
|
|
return a->confidence > b->confidence;
|
|
|
|
});
|
2018-01-26 03:16:46 +00:00
|
|
|
|
2016-08-27 17:42:51 +00:00
|
|
|
return targets;
|
|
|
|
}
|