1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-07 23:29:06 +00:00
CLK/StaticAnalyser/StaticAnalyser.cpp

105 lines
2.6 KiB
C++
Raw Normal View History

//
// StaticAnalyser.cpp
// Clock Signal
//
// Created by Thomas Harte on 23/08/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#include "StaticAnalyser.hpp"
#include <cstdlib>
2016-08-27 17:42:51 +00:00
#include "../Storage/Disk/Formats/D64.hpp"
#include "../Storage/Disk/Formats/G64.hpp"
#include "../Storage/Tape/Formats/CommodoreTAP.hpp"
#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,
Commodore = 1 << 2
};
2016-08-27 17:42:51 +00:00
using namespace StaticAnalyser;
std::list<Target> StaticAnalyser::GetTargets(const char *file_name)
2016-08-27 17:42:51 +00:00
{
std::list<Target> targets;
// 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
{
lowercase_extension = strdup(mixed_case_extension+1);
char *parser = lowercase_extension;
while(*parser)
{
*parser = (char)tolower(*parser);
parser++;
}
2016-08-27 17:42:51 +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;
TargetPlatformType potential_platforms = 0;
#define Format(extension, list, class, platforms) \
if(!strcmp(lowercase_extension, extension)) \
{ \
try { \
list.emplace_back(new Storage::class(file_name));\
potential_platforms |= (TargetPlatformType)(platforms);\
} catch(...) {}\
}
// A26
if(!strcmp(lowercase_extension, "a26"))
{
}
// BIN
if(!strcmp(lowercase_extension, "bin"))
{
}
2016-08-27 21:15:09 +00:00
Format("d64", disks, Disk::D64, TargetPlatform::Commodore) // D64
Format("g64", disks, Disk::G64, TargetPlatform::Commodore) // G64
// PRG
if(!strcmp(lowercase_extension, "prg"))
{
// try instantiating as a ROM; failing that accept as a tape
try {
2016-08-27 21:09:45 +00:00
tapes.emplace_back(new Storage::Tape::PRG(file_name));
potential_platforms |= (TargetPlatformType)TargetPlatform::Commodore;
} catch(...) {}
}
// ROM
if(!strcmp(lowercase_extension, "rom"))
{
}
2016-08-27 21:09:45 +00:00
Format("tap", tapes, Tape::CommodoreTAP, TargetPlatform::Commodore) // TAP
Format("uef", tapes, Tape::UEF, TargetPlatform::Acorn) // UEF (tape)
#undef Format
2016-08-27 17:42:51 +00:00
// Hand off to platform-specific determination of whether these things are actually compatible and,
// if so, how to load them. (TODO)
printf("Lowercase extension: %s", lowercase_extension);
2016-08-27 17:42:51 +00:00
free(lowercase_extension);
2016-08-27 17:42:51 +00:00
return targets;
}