1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Abstracts the target platform type out from the static analyser's ownership.

This commit is contained in:
Thomas Harte 2017-08-27 15:02:13 -04:00
parent fab6908129
commit 9aa150c338
3 changed files with 45 additions and 22 deletions

View File

@ -1060,6 +1060,7 @@
4BEF6AAB1D35D1C400E73575 /* DPLLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPLLTests.swift; sourceTree = "<group>"; };
4BF1354A1D6D2C300054B2EA /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticAnalyser.cpp; path = ../../StaticAnalyser/StaticAnalyser.cpp; sourceTree = "<group>"; };
4BF1354B1D6D2C300054B2EA /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = StaticAnalyser.hpp; path = ../../StaticAnalyser/StaticAnalyser.hpp; sourceTree = "<group>"; };
4BF4A2D91F534DB300B171F4 /* TargetPlatforms.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = TargetPlatforms.hpp; sourceTree = "<group>"; };
4BF6606A1F281573002CB053 /* ClockReceiver.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ClockReceiver.hpp; sourceTree = "<group>"; };
4BF8295B1D8F048B001BAE39 /* MFM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MFM.cpp; path = Encodings/MFM.cpp; sourceTree = "<group>"; };
4BF8295C1D8F048B001BAE39 /* MFM.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MFM.hpp; path = Encodings/MFM.hpp; sourceTree = "<group>"; };
@ -1457,6 +1458,7 @@
4BB697C91D4B6D3E00248BDF /* TimedEventLoop.cpp */,
4B5FADB91DE3151600AEC565 /* FileHolder.hpp */,
4BAB62AE1D32730D00DF5BA0 /* Storage.hpp */,
4BF4A2D91F534DB300B171F4 /* TargetPlatforms.hpp */,
4BB697CA1D4B6D3E00248BDF /* TimedEventLoop.hpp */,
4BEE0A691D72496600532C7B /* Cartridge */,
4B8805F81DCFF6CD003085B1 /* Data */,

View File

@ -40,22 +40,12 @@
#include "../Storage/Tape/Formats/TZX.hpp"
#include "../Storage/Tape/Formats/ZX80O81P.hpp"
typedef int TargetPlatformType;
enum class TargetPlatform: TargetPlatformType {
Acorn = 1 << 0,
AmstradCPC = 1 << 1,
Atari2600 = 1 << 2,
Commodore = 1 << 3,
Oric = 1 << 4,
ZX8081 = 1 << 5,
AllTape = Acorn | AmstradCPC | Commodore | Oric | ZX8081,
AllDisk = Acorn | AmstradCPC | Commodore | Oric,
};
// Target Platform Types
#include "../Storage/TargetPlatforms.hpp"
using namespace StaticAnalyser;
static Media GetMediaAndPlatforms(const char *file_name, TargetPlatformType &potential_platforms) {
static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType &potential_platforms) {
// 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, '.');
@ -72,7 +62,7 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatformType &pot
Media result;
#define Insert(list, class, platforms) \
list.emplace_back(new Storage::class(file_name));\
potential_platforms |= (TargetPlatformType)(platforms);\
potential_platforms |= platforms;\
#define TryInsert(list, class, platforms) \
try {\
@ -132,7 +122,7 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatformType &pot
}
Media StaticAnalyser::GetMedia(const char *file_name) {
TargetPlatformType throwaway;
TargetPlatform::IntType throwaway;
return GetMediaAndPlatforms(file_name, throwaway);
}
@ -141,17 +131,17 @@ std::list<Target> StaticAnalyser::GetTargets(const char *file_name) {
// 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.
TargetPlatformType potential_platforms = 0;
TargetPlatform::IntType potential_platforms = 0;
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.
if(potential_platforms & (TargetPlatformType)TargetPlatform::Acorn) Acorn::AddTargets(media, targets);
if(potential_platforms & (TargetPlatformType)TargetPlatform::AmstradCPC) AmstradCPC::AddTargets(media, targets);
if(potential_platforms & (TargetPlatformType)TargetPlatform::Atari2600) Atari::AddTargets(media, targets);
if(potential_platforms & (TargetPlatformType)TargetPlatform::Commodore) Commodore::AddTargets(media, targets);
if(potential_platforms & (TargetPlatformType)TargetPlatform::Oric) Oric::AddTargets(media, targets);
if(potential_platforms & (TargetPlatformType)TargetPlatform::ZX8081) ZX8081::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Acorn) Acorn::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::AmstradCPC) AmstradCPC::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Atari2600) Atari::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Commodore) Commodore::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::Oric) Oric::AddTargets(media, targets);
if(potential_platforms & TargetPlatform::ZX8081) ZX8081::AddTargets(media, targets);
// Reset any tapes to their initial position
for(auto target : targets) {

View File

@ -0,0 +1,31 @@
//
// TargetPlatforms.h
// Clock Signal
//
// Created by Thomas Harte on 27/08/2017.
// Copyright © 2017 Thomas Harte. All rights reserved.
//
#ifndef TargetPlatforms_hpp
#define TargetPlatforms_hpp
namespace TargetPlatform {
typedef int IntType;
enum Type: IntType {
Acorn = 1 << 0,
AmstradCPC = 1 << 1,
Atari2600 = 1 << 2,
Commodore = 1 << 3,
Oric = 1 << 4,
ZX80 = 1 << 5,
ZX81 = 1 << 6,
ZX8081 = ZX80 | ZX81,
AllTape = Acorn | AmstradCPC | Commodore | Oric | ZX80 | ZX81,
AllDisk = Acorn | AmstradCPC | Commodore | Oric,
};
}
#endif /* TargetPlatforms_h */