2016-08-24 01:35:59 +00:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 23/08/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2016-08-27 18:25:16 +00:00
|
|
|
#include <cstdlib>
|
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"
|
2016-09-15 23:34:45 +00:00
|
|
|
#include "Atari/StaticAnalyser.hpp"
|
2016-09-15 23:24:59 +00:00
|
|
|
#include "Commodore/StaticAnalyser.hpp"
|
2016-10-12 02:20:13 +00:00
|
|
|
#include "Oric/StaticAnalyser.hpp"
|
2016-08-29 12:48:49 +00:00
|
|
|
|
|
|
|
// Cartridges
|
|
|
|
#include "../Storage/Cartridge/Formats/BinaryDump.hpp"
|
2016-08-27 22:26:51 +00:00
|
|
|
#include "../Storage/Cartridge/Formats/PRG.hpp"
|
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
// Disks
|
2016-09-25 21:46:11 +00:00
|
|
|
#include "../Storage/Disk/Formats/AcornADF.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
#include "../Storage/Disk/Formats/D64.hpp"
|
|
|
|
#include "../Storage/Disk/Formats/G64.hpp"
|
2016-09-18 23:21:02 +00:00
|
|
|
#include "../Storage/Disk/Formats/SSD.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
// Tapes
|
2016-08-27 20:40:21 +00:00
|
|
|
#include "../Storage/Tape/Formats/CommodoreTAP.hpp"
|
2016-10-11 11:39:48 +00:00
|
|
|
#include "../Storage/Tape/Formats/OricTAP.hpp"
|
2016-08-27 20:40:21 +00:00
|
|
|
#include "../Storage/Tape/Formats/TapePRG.hpp"
|
|
|
|
#include "../Storage/Tape/Formats/TapeUEF.hpp"
|
|
|
|
|
|
|
|
typedef int TargetPlatformType;
|
|
|
|
enum class TargetPlatform: TargetPlatformType {
|
|
|
|
Acorn = 1 << 0,
|
|
|
|
Atari2600 = 1 << 1,
|
2016-10-11 11:39:48 +00:00
|
|
|
Commodore = 1 << 2,
|
|
|
|
Oric = 1 << 3
|
2016-08-27 20:40:21 +00:00
|
|
|
};
|
|
|
|
|
2016-08-27 17:42:51 +00:00
|
|
|
using namespace StaticAnalyser;
|
|
|
|
|
2016-08-27 18:25:16 +00:00
|
|
|
std::list<Target> StaticAnalyser::GetTargets(const char *file_name)
|
2016-08-27 17:42:51 +00:00
|
|
|
{
|
|
|
|
std::list<Target> targets;
|
|
|
|
|
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.
|
|
|
|
const char *mixed_case_extension = strrchr(file_name, '.');
|
|
|
|
char *lowercase_extension = nullptr;
|
|
|
|
if(mixed_case_extension)
|
2016-08-27 17:42:51 +00:00
|
|
|
{
|
2016-08-27 20:40:21 +00:00
|
|
|
lowercase_extension = strdup(mixed_case_extension+1);
|
2016-08-27 18:25:16 +00:00
|
|
|
char *parser = lowercase_extension;
|
|
|
|
while(*parser)
|
|
|
|
{
|
|
|
|
*parser = (char)tolower(*parser);
|
|
|
|
parser++;
|
|
|
|
}
|
2016-08-27 17:42:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 18:25:16 +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.
|
2016-08-27 21:15:09 +00:00
|
|
|
std::list<std::shared_ptr<Storage::Disk::Disk>> disks;
|
2016-08-27 21:09:45 +00:00
|
|
|
std::list<std::shared_ptr<Storage::Tape::Tape>> tapes;
|
2016-08-27 22:26:51 +00:00
|
|
|
std::list<std::shared_ptr<Storage::Cartridge::Cartridge>> cartridges;
|
2016-08-27 20:40:21 +00:00
|
|
|
TargetPlatformType potential_platforms = 0;
|
|
|
|
|
2016-08-27 22:26:51 +00:00
|
|
|
#define Insert(list, class, platforms) \
|
|
|
|
list.emplace_back(new Storage::class(file_name));\
|
|
|
|
potential_platforms |= (TargetPlatformType)(platforms);\
|
|
|
|
|
2016-08-28 16:20:40 +00:00
|
|
|
#define TryInsert(list, class, platforms) \
|
|
|
|
try {\
|
|
|
|
Insert(list, class, platforms) \
|
|
|
|
} catch(...) {}
|
|
|
|
|
2016-08-27 20:40:21 +00:00
|
|
|
#define Format(extension, list, class, platforms) \
|
|
|
|
if(!strcmp(lowercase_extension, extension)) \
|
|
|
|
{ \
|
2016-08-28 16:20:40 +00:00
|
|
|
TryInsert(list, class, platforms) \
|
2016-08-27 20:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
Format("a26", cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // A26
|
2016-09-25 21:46:11 +00:00
|
|
|
Format("adf", disks, Disk::AcornADF, TargetPlatform::Acorn) // ADF
|
2016-08-29 12:48:49 +00:00
|
|
|
Format("bin", cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // BIN
|
|
|
|
Format("d64", disks, Disk::D64, TargetPlatform::Commodore) // D64
|
2016-09-18 23:21:02 +00:00
|
|
|
Format("dsd", disks, Disk::SSD, TargetPlatform::Acorn) // DSD
|
2016-08-29 12:48:49 +00:00
|
|
|
Format("g64", disks, Disk::G64, TargetPlatform::Commodore) // G64
|
2016-08-27 20:40:21 +00:00
|
|
|
|
|
|
|
// PRG
|
|
|
|
if(!strcmp(lowercase_extension, "prg"))
|
|
|
|
{
|
|
|
|
// try instantiating as a ROM; failing that accept as a tape
|
|
|
|
try {
|
2016-08-27 22:26:51 +00:00
|
|
|
Insert(cartridges, Cartridge::PRG, TargetPlatform::Commodore)
|
2016-08-27 22:17:40 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
try {
|
2016-08-27 22:26:51 +00:00
|
|
|
Insert(tapes, Tape::PRG, TargetPlatform::Commodore)
|
2016-08-27 22:17:40 +00:00
|
|
|
} catch(...) {}
|
|
|
|
}
|
2016-08-27 20:40:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 12:48:49 +00:00
|
|
|
Format("rom", cartridges, Cartridge::BinaryDump, TargetPlatform::Acorn) // ROM
|
2016-09-18 23:21:02 +00:00
|
|
|
Format("ssd", disks, Disk::SSD, TargetPlatform::Acorn) // SSD
|
2016-10-11 11:39:48 +00:00
|
|
|
Format("tap", tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP (Commodore)
|
|
|
|
Format("tap", tapes, Tape::OricTAP, TargetPlatform::Oric) // TAP (Oric)
|
2016-08-28 16:20:40 +00:00
|
|
|
Format("uef", tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape)
|
2016-08-27 20:40:21 +00:00
|
|
|
|
|
|
|
#undef Format
|
2016-08-27 22:26:51 +00:00
|
|
|
#undef Insert
|
2016-08-27 17:42:51 +00:00
|
|
|
|
2016-08-27 20:40:21 +00:00
|
|
|
// Hand off to platform-specific determination of whether these things are actually compatible and,
|
|
|
|
// if so, how to load them. (TODO)
|
2016-09-06 10:39:40 +00:00
|
|
|
if(potential_platforms & (TargetPlatformType)TargetPlatform::Acorn) Acorn::AddTargets(disks, tapes, cartridges, targets);
|
2016-09-15 23:34:45 +00:00
|
|
|
if(potential_platforms & (TargetPlatformType)TargetPlatform::Atari2600) Atari::AddTargets(disks, tapes, cartridges, targets);
|
2016-10-12 02:20:13 +00:00
|
|
|
if(potential_platforms & (TargetPlatformType)TargetPlatform::Commodore) Commodore::AddTargets(disks, tapes, cartridges, targets);
|
|
|
|
if(potential_platforms & (TargetPlatformType)TargetPlatform::Oric) Oric::AddTargets(disks, tapes, cartridges, targets);
|
2016-08-27 18:25:16 +00:00
|
|
|
|
|
|
|
free(lowercase_extension);
|
2016-08-27 17:42:51 +00:00
|
|
|
return targets;
|
|
|
|
}
|