From 11abc99ef8f1636eab51b56957d1f1864a714b72 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 24 Jan 2018 22:35:54 -0500 Subject: [PATCH] Introduces the extra level of indirection necessary to make Analyser::Static::Target polymorphic. --- Analyser/Static/Acorn/StaticAnalyser.cpp | 34 +++++++------- Analyser/Static/Acorn/StaticAnalyser.hpp | 2 +- Analyser/Static/AmstradCPC/StaticAnalyser.cpp | 44 +++++++++---------- Analyser/Static/AmstradCPC/StaticAnalyser.hpp | 2 +- Analyser/Static/Atari/StaticAnalyser.cpp | 18 ++++---- Analyser/Static/Atari/StaticAnalyser.hpp | 2 +- Analyser/Static/Commodore/StaticAnalyser.cpp | 38 ++++++++-------- Analyser/Static/Commodore/StaticAnalyser.hpp | 2 +- Analyser/Static/MSX/StaticAnalyser.cpp | 24 +++++----- Analyser/Static/MSX/StaticAnalyser.hpp | 2 +- Analyser/Static/Oric/StaticAnalyser.cpp | 26 +++++------ Analyser/Static/Oric/StaticAnalyser.hpp | 2 +- Analyser/Static/StaticAnalyser.cpp | 12 ++--- Analyser/Static/StaticAnalyser.hpp | 8 ++-- Analyser/Static/ZX8081/StaticAnalyser.cpp | 28 ++++++------ Analyser/Static/ZX8081/StaticAnalyser.hpp | 2 +- Machines/Utility/MachineForTarget.cpp | 6 +-- Machines/Utility/MachineForTarget.hpp | 2 +- .../Clock Signal.xcodeproj/project.pbxproj | 40 ++++++++--------- .../Mac/Clock Signal/Machine/CSMachine.mm | 10 ++--- .../CSStaticAnalyser+TargetVector.h | 2 +- .../Machine/StaticAnalyser/CSStaticAnalyser.h | 2 - .../StaticAnalyser/CSStaticAnalyser.mm | 10 ++--- OSBindings/SDL/main.cpp | 6 +-- 24 files changed, 159 insertions(+), 165 deletions(-) diff --git a/Analyser/Static/Acorn/StaticAnalyser.cpp b/Analyser/Static/Acorn/StaticAnalyser.cpp index 10f653fd0..a251ef8c9 100644 --- a/Analyser/Static/Acorn/StaticAnalyser.cpp +++ b/Analyser/Static/Acorn/StaticAnalyser.cpp @@ -56,16 +56,16 @@ static std::vector> return acorn_cartridges; } -void Analyser::Static::Acorn::AddTargets(const Media &media, std::vector &destination) { - Target target; - target.machine = Machine::Electron; - target.probability = 1.0; // TODO: a proper estimation - target.acorn.has_dfs = false; - target.acorn.has_adfs = false; - target.acorn.should_shift_restart = false; +void Analyser::Static::Acorn::AddTargets(const Media &media, std::vector> &destination) { + std::unique_ptr target(new Target); + target->machine = Machine::Electron; + target->probability = 1.0; // TODO: a proper estimation + target->acorn.has_dfs = false; + target->acorn.has_adfs = false; + target->acorn.should_shift_restart = false; // strip out inappropriate cartridges - target.media.cartridges = AcornCartridgesFrom(media.cartridges); + target->media.cartridges = AcornCartridgesFrom(media.cartridges); // if there are any tapes, attempt to get data from the first if(media.tapes.size() > 0) { @@ -96,9 +96,9 @@ void Analyser::Static::Acorn::AddTargets(const Media &media, std::vector // Inspect first file. If it's protected or doesn't look like BASIC // then the loading command is *RUN. Otherwise it's CHAIN"". - target.loading_command = is_basic ? "CHAIN\"\"\n" : "*RUN\n"; + target->loading_command = is_basic ? "CHAIN\"\"\n" : "*RUN\n"; - target.media.tapes = media.tapes; + target->media.tapes = media.tapes; } } @@ -108,18 +108,18 @@ void Analyser::Static::Acorn::AddTargets(const Media &media, std::vector dfs_catalogue = GetDFSCatalogue(disk); if(dfs_catalogue == nullptr) adfs_catalogue = GetADFSCatalogue(disk); if(dfs_catalogue || adfs_catalogue) { - target.media.disks = media.disks; - target.acorn.has_dfs = !!dfs_catalogue; - target.acorn.has_adfs = !!adfs_catalogue; + target->media.disks = media.disks; + target->acorn.has_dfs = !!dfs_catalogue; + target->acorn.has_adfs = !!adfs_catalogue; Catalogue::BootOption bootOption = (dfs_catalogue ?: adfs_catalogue)->bootOption; if(bootOption != Catalogue::BootOption::None) - target.acorn.should_shift_restart = true; + target->acorn.should_shift_restart = true; else - target.loading_command = "*CAT\n"; + target->loading_command = "*CAT\n"; } } - if(target.media.tapes.size() || target.media.disks.size() || target.media.cartridges.size()) - destination.push_back(target); + if(target->media.tapes.size() || target->media.disks.size() || target->media.cartridges.size()) + destination.push_back(std::move(target)); } diff --git a/Analyser/Static/Acorn/StaticAnalyser.hpp b/Analyser/Static/Acorn/StaticAnalyser.hpp index a5f18efb3..695b5e183 100644 --- a/Analyser/Static/Acorn/StaticAnalyser.hpp +++ b/Analyser/Static/Acorn/StaticAnalyser.hpp @@ -15,7 +15,7 @@ namespace Analyser { namespace Static { namespace Acorn { -void AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp index 8299da24b..04bae8d70 100644 --- a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp +++ b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp @@ -58,7 +58,7 @@ static std::string RunCommandFor(const Storage::Disk::CPM::File &file) { static void InspectCatalogue( const Storage::Disk::CPM::Catalogue &catalogue, - Analyser::Static::Target &target) { + const std::unique_ptr &target) { std::vector candidate_files; candidate_files.reserve(catalogue.files.size()); @@ -95,7 +95,7 @@ static void InspectCatalogue( // If there's just one file, run that. if(candidate_files.size() == 1) { - target.loading_command = RunCommandFor(*candidate_files[0]); + target->loading_command = RunCommandFor(*candidate_files[0]); return; } @@ -126,7 +126,7 @@ static void InspectCatalogue( } if(basic_files == 1 || implicit_suffixed_files == 1) { std::size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file; - target.loading_command = RunCommandFor(*candidate_files[selected_file]); + target->loading_command = RunCommandFor(*candidate_files[selected_file]); return; } @@ -143,17 +143,17 @@ static void InspectCatalogue( if(name_counts.size() == 2) { for(auto &pair : name_counts) { if(pair.second == 1) { - target.loading_command = RunCommandFor(*candidate_files[indices_by_name[pair.first]]); + target->loading_command = RunCommandFor(*candidate_files[indices_by_name[pair.first]]); return; } } } // Desperation. - target.loading_command = "cat\n"; + target->loading_command = "cat\n"; } -static bool CheckBootSector(const std::shared_ptr &disk, Analyser::Static::Target &target) { +static bool CheckBootSector(const std::shared_ptr &disk, const std::unique_ptr &target) { Storage::Encodings::MFM::Parser parser(true, disk); Storage::Encodings::MFM::Sector *boot_sector = parser.get_sector(0, 0, 0x41); if(boot_sector != nullptr && !boot_sector->samples.empty()) { @@ -169,7 +169,7 @@ static bool CheckBootSector(const std::shared_ptr &disk, An // This is a system disk, then launch it as though it were CP/M. if(!matched) { - target.loading_command = "|cpm\n"; + target->loading_command = "|cpm\n"; return true; } } @@ -177,24 +177,24 @@ static bool CheckBootSector(const std::shared_ptr &disk, An return false; } -void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector &destination) { - Target target; - target.machine = Machine::AmstradCPC; - target.probability = 1.0; - target.media.disks = media.disks; - target.media.tapes = media.tapes; - target.media.cartridges = media.cartridges; +void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector> &destination) { + std::unique_ptr target(new Target); + target->machine = Machine::AmstradCPC; + target->probability = 1.0; + target->media.disks = media.disks; + target->media.tapes = media.tapes; + target->media.cartridges = media.cartridges; - target.amstradcpc.model = AmstradCPCModel::CPC6128; + target->amstradcpc.model = AmstradCPCModel::CPC6128; - if(!target.media.tapes.empty()) { + if(!target->media.tapes.empty()) { // Ugliness flows here: assume the CPC isn't smart enough to pause between pressing // enter and responding to the follow-on prompt to press a key, so just type for // a while. Yuck! - target.loading_command = "|tape\nrun\"\n1234567890"; + target->loading_command = "|tape\nrun\"\n1234567890"; } - if(!target.media.disks.empty()) { + if(!target->media.disks.empty()) { Storage::Disk::CPM::ParameterBlock data_format; data_format.sectors_per_track = 9; data_format.tracks = 40; @@ -203,11 +203,11 @@ void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector data_catalogue = Storage::Disk::CPM::GetCatalogue(target.media.disks.front(), data_format); + std::unique_ptr data_catalogue = Storage::Disk::CPM::GetCatalogue(target->media.disks.front(), data_format); if(data_catalogue) { InspectCatalogue(*data_catalogue, target); } else { - if(!CheckBootSector(target.media.disks.front(), target)) { + if(!CheckBootSector(target->media.disks.front(), target)) { Storage::Disk::CPM::ParameterBlock system_format; system_format.sectors_per_track = 9; system_format.tracks = 40; @@ -216,7 +216,7 @@ void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector system_catalogue = Storage::Disk::CPM::GetCatalogue(target.media.disks.front(), system_format); + std::unique_ptr system_catalogue = Storage::Disk::CPM::GetCatalogue(target->media.disks.front(), system_format); if(system_catalogue) { InspectCatalogue(*system_catalogue, target); } @@ -224,5 +224,5 @@ void Analyser::Static::AmstradCPC::AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/Atari/StaticAnalyser.cpp b/Analyser/Static/Atari/StaticAnalyser.cpp index 365aa6e8f..b687c0ada 100644 --- a/Analyser/Static/Atari/StaticAnalyser.cpp +++ b/Analyser/Static/Atari/StaticAnalyser.cpp @@ -178,14 +178,14 @@ static void DeterminePagingForCartridge(Analyser::Static::Target &target, const } } -void Analyser::Static::Atari::AddTargets(const Media &media, std::vector &destination) { +void Analyser::Static::Atari::AddTargets(const Media &media, std::vector> &destination) { // TODO: sanity checking; is this image really for an Atari 2600. - Target target; - target.machine = Machine::Atari2600; - target.probability = 1.0; - target.media.cartridges = media.cartridges; - target.atari.paging_model = Atari2600PagingModel::None; - target.atari.uses_superchip = false; + std::unique_ptr target(new Target); + target->machine = Machine::Atari2600; + target->probability = 1.0; + target->media.cartridges = media.cartridges; + target->atari.paging_model = Atari2600PagingModel::None; + target->atari.uses_superchip = false; // try to figure out the paging scheme if(!media.cartridges.empty()) { @@ -193,9 +193,9 @@ void Analyser::Static::Atari::AddTargets(const Media &media, std::vector if(segments.size() == 1) { const Storage::Cartridge::Cartridge::Segment &segment = segments.front(); - DeterminePagingForCartridge(target, segment); + DeterminePagingForCartridge(*target, segment); } } - destination.push_back(target); + destination.push_back(std::move(target)); } diff --git a/Analyser/Static/Atari/StaticAnalyser.hpp b/Analyser/Static/Atari/StaticAnalyser.hpp index 45957b675..8b3f03208 100644 --- a/Analyser/Static/Atari/StaticAnalyser.hpp +++ b/Analyser/Static/Atari/StaticAnalyser.hpp @@ -15,7 +15,7 @@ namespace Analyser { namespace Static { namespace Atari { -void AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/Commodore/StaticAnalyser.cpp b/Analyser/Static/Commodore/StaticAnalyser.cpp index 2bfa6971a..09aaf15fd 100644 --- a/Analyser/Static/Commodore/StaticAnalyser.cpp +++ b/Analyser/Static/Commodore/StaticAnalyser.cpp @@ -38,17 +38,17 @@ static std::vector> return vic20_cartridges; } -void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector &destination) { - Target target; - target.machine = Machine::Vic20; // TODO: machine estimation - target.probability = 1.0; // TODO: a proper estimation +void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector> &destination) { + std::unique_ptr target(new Target); + target->machine = Machine::Vic20; // TODO: machine estimation + target->probability = 1.0; // TODO: a proper estimation int device = 0; std::vector files; bool is_disk = false; // strip out inappropriate cartridges - target.media.cartridges = Vic20CartridgesFrom(media.cartridges); + target->media.cartridges = Vic20CartridgesFrom(media.cartridges); // check disks for(auto &disk : media.disks) { @@ -56,7 +56,7 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vectormedia.disks.push_back(disk); if(!device) device = 8; } } @@ -67,13 +67,13 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vectorreset(); if(!tape_files.empty()) { files.insert(files.end(), tape_files.begin(), tape_files.end()); - target.media.tapes.push_back(tape); + target->media.tapes.push_back(tape); if(!device) device = 1; } } if(!files.empty()) { - target.vic20.memory_model = Vic20MemoryModel::Unexpanded; + target->vic20.memory_model = Vic20MemoryModel::Unexpanded; std::ostringstream string_stream; string_stream << "LOAD\"" << (is_disk ? "*" : "") << "\"," << device << ","; if(files.front().is_basic()) { @@ -82,17 +82,17 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vectorloading_command = string_stream.str(); // make a first guess based on loading address switch(files.front().starting_address) { case 0x1001: default: break; case 0x1201: - target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; + target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; break; case 0x0401: - target.vic20.memory_model = Vic20MemoryModel::EightKB; + target->vic20.memory_model = Vic20MemoryModel::EightKB; break; } @@ -108,9 +108,9 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector 6655) - target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; - else if(target.vic20.memory_model == Vic20MemoryModel::Unexpanded && file_size > 3583) - target.vic20.memory_model = Vic20MemoryModel::EightKB; + target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; + else if(target->vic20.memory_model == Vic20MemoryModel::Unexpanded && file_size > 3583) + target->vic20.memory_model = Vic20MemoryModel::EightKB; } else {*/ @@ -129,13 +129,13 @@ void Analyser::Static::Commodore::AddTargets(const Media &media, std::vector 0x2000) - target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; - else if(target.vic20.memory_model == Vic20MemoryModel::Unexpanded && !(starting_address >= 0x1000 || starting_address+file_size < 0x0400)) - target.vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; + target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; + else if(target->vic20.memory_model == Vic20MemoryModel::Unexpanded && !(starting_address >= 0x1000 || starting_address+file_size < 0x0400)) + target->vic20.memory_model = Vic20MemoryModel::ThirtyTwoKB; // } } } - if(!target.media.tapes.empty() || !target.media.cartridges.empty() || !target.media.disks.empty()) - destination.push_back(target); + if(!target->media.empty()) + destination.push_back(std::move(target)); } diff --git a/Analyser/Static/Commodore/StaticAnalyser.hpp b/Analyser/Static/Commodore/StaticAnalyser.hpp index 4a5f3adde..a318cd16e 100644 --- a/Analyser/Static/Commodore/StaticAnalyser.hpp +++ b/Analyser/Static/Commodore/StaticAnalyser.hpp @@ -15,7 +15,7 @@ namespace Analyser { namespace Static { namespace Commodore { -void AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/MSX/StaticAnalyser.cpp b/Analyser/Static/MSX/StaticAnalyser.cpp index 9e7328cad..1a0ae98b1 100644 --- a/Analyser/Static/MSX/StaticAnalyser.cpp +++ b/Analyser/Static/MSX/StaticAnalyser.cpp @@ -200,32 +200,32 @@ static std::vector> return msx_cartridges; } -void Analyser::Static::MSX::AddTargets(const Media &media, std::vector &destination) { - Target target; +void Analyser::Static::MSX::AddTargets(const Media &media, std::vector> &destination) { + std::unique_ptr target(new Target); // Obtain only those cartridges which it looks like an MSX would understand. - target.media.cartridges = MSXCartridgesFrom(media.cartridges, target); + target->media.cartridges = MSXCartridgesFrom(media.cartridges, *target); // Check tapes for loadable files. for(const auto &tape : media.tapes) { std::vector files_on_tape = GetFiles(tape); if(!files_on_tape.empty()) { switch(files_on_tape.front().type) { - case File::Type::ASCII: target.loading_command = "RUN\"CAS:\r"; break; - case File::Type::TokenisedBASIC: target.loading_command = "CLOAD\rRUN\r"; break; - case File::Type::Binary: target.loading_command = "BLOAD\"CAS:\",R\r"; break; + case File::Type::ASCII: target->loading_command = "RUN\"CAS:\r"; break; + case File::Type::TokenisedBASIC: target->loading_command = "CLOAD\rRUN\r"; break; + case File::Type::Binary: target->loading_command = "BLOAD\"CAS:\",R\r"; break; default: break; } - target.media.tapes.push_back(tape); + target->media.tapes.push_back(tape); } } // Blindly accept disks for now. - target.media.disks = media.disks; + target->media.disks = media.disks; - if(!target.media.empty()) { - target.machine = Machine::MSX; - target.probability = 1.0; - destination.push_back(target); + if(!target->media.empty()) { + target->machine = Machine::MSX; + target->probability = 1.0; + destination.push_back(std::move(target)); } } diff --git a/Analyser/Static/MSX/StaticAnalyser.hpp b/Analyser/Static/MSX/StaticAnalyser.hpp index 9e03b783e..4f08ebb9d 100644 --- a/Analyser/Static/MSX/StaticAnalyser.hpp +++ b/Analyser/Static/MSX/StaticAnalyser.hpp @@ -15,7 +15,7 @@ namespace Analyser { namespace Static { namespace MSX { -void AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/Oric/StaticAnalyser.cpp b/Analyser/Static/Oric/StaticAnalyser.cpp index 53dfb2990..42101d52d 100644 --- a/Analyser/Static/Oric/StaticAnalyser.cpp +++ b/Analyser/Static/Oric/StaticAnalyser.cpp @@ -73,10 +73,10 @@ static int Basic11Score(const Analyser::Static::MOS6502::Disassembly &disassembl return Score(disassembly, rom_functions, variable_locations); } -void Analyser::Static::Oric::AddTargets(const Media &media, std::vector &destination) { - Target target; - target.machine = Machine::Oric; - target.probability = 1.0; +void Analyser::Static::Oric::AddTargets(const Media &media, std::vector> &destination) { + std::unique_ptr target(new Target); + target->machine = Machine::Oric; + target->probability = 1.0; int basic10_votes = 0; int basic11_votes = 0; @@ -97,23 +97,23 @@ void Analyser::Static::Oric::AddTargets(const Media &media, std::vector } } - target.media.tapes.push_back(tape); - target.loading_command = "CLOAD\"\"\n"; + target->media.tapes.push_back(tape); + target->loading_command = "CLOAD\"\"\n"; } } // trust that any disk supplied can be handled by the Microdisc. TODO: check. if(!media.disks.empty()) { - target.oric.has_microdisc = true; - target.media.disks = media.disks; + target->oric.has_microdisc = true; + target->media.disks = media.disks; } else { - target.oric.has_microdisc = false; + target->oric.has_microdisc = false; } // TODO: really this should add two targets if not all votes agree - target.oric.use_atmos_rom = basic11_votes >= basic10_votes; - if(target.oric.has_microdisc) target.oric.use_atmos_rom = true; + target->oric.use_atmos_rom = basic11_votes >= basic10_votes; + if(target->oric.has_microdisc) target->oric.use_atmos_rom = true; - if(target.media.tapes.size() || target.media.disks.size() || target.media.cartridges.size()) - destination.push_back(target); + if(target->media.tapes.size() || target->media.disks.size() || target->media.cartridges.size()) + destination.push_back(std::move(target)); } diff --git a/Analyser/Static/Oric/StaticAnalyser.hpp b/Analyser/Static/Oric/StaticAnalyser.hpp index decf9ebd1..1f2823be6 100644 --- a/Analyser/Static/Oric/StaticAnalyser.hpp +++ b/Analyser/Static/Oric/StaticAnalyser.hpp @@ -15,7 +15,7 @@ namespace Analyser { namespace Static { namespace Oric { -void AddTargets(const Media &media, std::vector &destination); +void AddTargets(const Media &media, std::vector> &destination); } } diff --git a/Analyser/Static/StaticAnalyser.cpp b/Analyser/Static/StaticAnalyser.cpp index 9851a6d09..6f59f8853 100644 --- a/Analyser/Static/StaticAnalyser.cpp +++ b/Analyser/Static/StaticAnalyser.cpp @@ -88,8 +88,8 @@ static Media GetMediaAndPlatforms(const char *file_name, TargetPlatform::IntType Format("adf", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // ADF Format("bin", result.cartridges, Cartridge::BinaryDump, TargetPlatform::Atari2600) // BIN Format("cas", result.tapes, Tape::CAS, TargetPlatform::MSX) // CAS - Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT - Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW + Format("cdt", result.tapes, Tape::TZX, TargetPlatform::AmstradCPC) // CDT + Format("csw", result.tapes, Tape::CSW, TargetPlatform::AllTape) // CSW Format("d64", result.disks, Disk::DiskImageHolder, TargetPlatform::Commodore) // D64 Format("dmk", result.disks, Disk::DiskImageHolder, TargetPlatform::MSX) // DMK Format("dsd", result.disks, Disk::DiskImageHolder, TargetPlatform::Acorn) // DSD @@ -139,8 +139,8 @@ Media Analyser::Static::GetMedia(const char *file_name) { return GetMediaAndPlatforms(file_name, throwaway); } -std::vector Analyser::Static::GetTargets(const char *file_name) { - std::vector targets; +std::vector> Analyser::Static::GetTargets(const char *file_name) { + std::vector> targets; // 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. @@ -158,8 +158,8 @@ std::vector Analyser::Static::GetTargets(const char *file_name) { if(potential_platforms & TargetPlatform::ZX8081) ZX8081::AddTargets(media, targets, potential_platforms); // Reset any tapes to their initial position - for(auto target : targets) { - for(auto tape : media.tapes) { + for(auto &target : targets) { + for(auto &tape : target->media.tapes) { tape->reset(); } } diff --git a/Analyser/Static/StaticAnalyser.hpp b/Analyser/Static/StaticAnalyser.hpp index b027245f0..86d49bd76 100644 --- a/Analyser/Static/StaticAnalyser.hpp +++ b/Analyser/Static/StaticAnalyser.hpp @@ -82,7 +82,10 @@ struct Media { */ struct Target { Machine machine; + Media media; + float probability; + std::string loading_command; // TODO: this is too C-like a solution; make Target a base class and // turn the following into information held by more specific subclasses. @@ -121,9 +124,6 @@ struct Target { MSXCartridgeType cartridge_type; } msx; }; - - std::string loading_command; - Media media; }; /*! @@ -131,7 +131,7 @@ struct Target { @returns The list of potential targets, sorted from most to least probable. */ -std::vector GetTargets(const char *file_name); +std::vector> GetTargets(const char *file_name); /*! Inspects the supplied file and determines the media included. diff --git a/Analyser/Static/ZX8081/StaticAnalyser.cpp b/Analyser/Static/ZX8081/StaticAnalyser.cpp index 8e1aefa4a..266b4c9df 100644 --- a/Analyser/Static/ZX8081/StaticAnalyser.cpp +++ b/Analyser/Static/ZX8081/StaticAnalyser.cpp @@ -27,41 +27,41 @@ static std::vector GetFiles(const std::shared_ptr &destination, TargetPlatform::IntType potential_platforms) { +void Analyser::Static::ZX8081::AddTargets(const Media &media, std::vector> &destination, TargetPlatform::IntType potential_platforms) { if(!media.tapes.empty()) { std::vector files = GetFiles(media.tapes.front()); media.tapes.front()->reset(); if(!files.empty()) { - Analyser::Static::Target target; - target.machine = Machine::ZX8081; + std::unique_ptr target(new Target); + target->machine = Machine::ZX8081; // Guess the machine type from the file only if it isn't already known. switch(potential_platforms & (TargetPlatform::ZX80 | TargetPlatform::ZX81)) { default: - target.zx8081.isZX81 = files.front().isZX81; + target->zx8081.isZX81 = files.front().isZX81; break; - case TargetPlatform::ZX80: target.zx8081.isZX81 = false; break; - case TargetPlatform::ZX81: target.zx8081.isZX81 = true; break; + case TargetPlatform::ZX80: target->zx8081.isZX81 = false; break; + case TargetPlatform::ZX81: target->zx8081.isZX81 = true; break; } /*if(files.front().data.size() > 16384) { - target.zx8081.memory_model = ZX8081MemoryModel::SixtyFourKB; + target->zx8081.memory_model = ZX8081MemoryModel::SixtyFourKB; } else*/ if(files.front().data.size() > 1024) { - target.zx8081.memory_model = ZX8081MemoryModel::SixteenKB; + target->zx8081.memory_model = ZX8081MemoryModel::SixteenKB; } else { - target.zx8081.memory_model = ZX8081MemoryModel::Unexpanded; + target->zx8081.memory_model = ZX8081MemoryModel::Unexpanded; } - target.media.tapes = media.tapes; + target->media.tapes = media.tapes; // TODO: how to run software once loaded? Might require a BASIC detokeniser. - if(target.zx8081.isZX81) { - target.loading_command = "J\"\"\n"; + if(target->zx8081.isZX81) { + target->loading_command = "J\"\"\n"; } else { - target.loading_command = "W\n"; + target->loading_command = "W\n"; } - destination.push_back(target); + destination.push_back(std::move(target)); } } } diff --git a/Analyser/Static/ZX8081/StaticAnalyser.hpp b/Analyser/Static/ZX8081/StaticAnalyser.hpp index bf1f071ec..420f21136 100644 --- a/Analyser/Static/ZX8081/StaticAnalyser.hpp +++ b/Analyser/Static/ZX8081/StaticAnalyser.hpp @@ -16,7 +16,7 @@ namespace Analyser { namespace Static { namespace ZX8081 { -void AddTargets(const Media &media, std::vector &destination, TargetPlatform::IntType potential_platforms); +void AddTargets(const Media &media, std::vector> &destination, TargetPlatform::IntType potential_platforms); } } diff --git a/Machines/Utility/MachineForTarget.cpp b/Machines/Utility/MachineForTarget.cpp index 78f962495..6769e8aa0 100644 --- a/Machines/Utility/MachineForTarget.cpp +++ b/Machines/Utility/MachineForTarget.cpp @@ -18,16 +18,16 @@ #include "TypedDynamicMachine.hpp" -::Machine::DynamicMachine *::Machine::MachineForTargets(const std::vector &targets) { +::Machine::DynamicMachine *::Machine::MachineForTargets(const std::vector> &targets) { // TODO: deal with target lists containing more than one machine. - switch(targets.front().machine) { + switch(targets.front()->machine) { case Analyser::Machine::AmstradCPC: return new TypedDynamicMachine(AmstradCPC::Machine::AmstradCPC()); case Analyser::Machine::Atari2600: return new TypedDynamicMachine(Atari2600::Machine::Atari2600()); case Analyser::Machine::Electron: return new TypedDynamicMachine(Electron::Machine::Electron()); case Analyser::Machine::MSX: return new TypedDynamicMachine(MSX::Machine::MSX()); case Analyser::Machine::Oric: return new TypedDynamicMachine(Oric::Machine::Oric()); case Analyser::Machine::Vic20: return new TypedDynamicMachine(Commodore::Vic20::Machine::Vic20()); - case Analyser::Machine::ZX8081: return new TypedDynamicMachine(ZX8081::Machine::ZX8081(targets.front())); + case Analyser::Machine::ZX8081: return new TypedDynamicMachine(ZX8081::Machine::ZX8081(*targets.front())); default: return nullptr; } diff --git a/Machines/Utility/MachineForTarget.hpp b/Machines/Utility/MachineForTarget.hpp index 0b04e3853..e78b215ad 100644 --- a/Machines/Utility/MachineForTarget.hpp +++ b/Machines/Utility/MachineForTarget.hpp @@ -42,7 +42,7 @@ struct DynamicMachine { receive the supplied static analyser result. The machine has been allocated on the heap. It is the caller's responsibility to delete the class when finished. */ -DynamicMachine *MachineForTargets(const std::vector &target); +DynamicMachine *MachineForTargets(const std::vector> &targets); /*! Returns a short string name for the machine identified by the target, diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 994095090..bceb8e7dc 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -2060,11 +2060,11 @@ 4B8944E3201967B4007DE474 /* Dynamic */ = { isa = PBXGroup; children = ( - 4B8944E4201967B4007DE474 /* ConfidenceSummary.hpp */, - 4B8944E5201967B4007DE474 /* ConfidenceSource.hpp */, 4B8944E6201967B4007DE474 /* ConfidenceCounter.cpp */, - 4B8944E7201967B4007DE474 /* ConfidenceCounter.hpp */, 4B8944E8201967B4007DE474 /* ConfidenceSummary.cpp */, + 4B8944E7201967B4007DE474 /* ConfidenceCounter.hpp */, + 4B8944E5201967B4007DE474 /* ConfidenceSource.hpp */, + 4B8944E4201967B4007DE474 /* ConfidenceSummary.hpp */, ); path = Dynamic; sourceTree = ""; @@ -2090,12 +2090,12 @@ isa = PBXGroup; children = ( 4B8944EC201967B4007DE474 /* Disk.cpp */, - 4B8944ED201967B4007DE474 /* StaticAnalyser.hpp */, - 4B8944EE201967B4007DE474 /* File.hpp */, - 4B8944EF201967B4007DE474 /* Tape.hpp */, + 4B8944F2201967B4007DE474 /* StaticAnalyser.cpp */, 4B8944F0201967B4007DE474 /* Tape.cpp */, 4B8944F1201967B4007DE474 /* Disk.hpp */, - 4B8944F2201967B4007DE474 /* StaticAnalyser.cpp */, + 4B8944EE201967B4007DE474 /* File.hpp */, + 4B8944ED201967B4007DE474 /* StaticAnalyser.hpp */, + 4B8944EF201967B4007DE474 /* Tape.hpp */, ); path = Acorn; sourceTree = ""; @@ -2103,8 +2103,8 @@ 4B8944F3201967B4007DE474 /* Atari */ = { isa = PBXGroup; children = ( - 4B8944F4201967B4007DE474 /* StaticAnalyser.hpp */, 4B8944F5201967B4007DE474 /* StaticAnalyser.cpp */, + 4B8944F4201967B4007DE474 /* StaticAnalyser.hpp */, ); path = Atari; sourceTree = ""; @@ -2112,10 +2112,10 @@ 4B8944F6201967B4007DE474 /* Oric */ = { isa = PBXGroup; children = ( + 4B8944FA201967B4007DE474 /* StaticAnalyser.cpp */, + 4B8944F9201967B4007DE474 /* Tape.cpp */, 4B8944F7201967B4007DE474 /* StaticAnalyser.hpp */, 4B8944F8201967B4007DE474 /* Tape.hpp */, - 4B8944F9201967B4007DE474 /* Tape.cpp */, - 4B8944FA201967B4007DE474 /* StaticAnalyser.cpp */, ); path = Oric; sourceTree = ""; @@ -2124,12 +2124,12 @@ isa = PBXGroup; children = ( 4B8944FC201967B4007DE474 /* Disk.cpp */, - 4B894502201967B4007DE474 /* Disk.hpp */, 4B894500201967B4007DE474 /* File.cpp */, - 4B8944FE201967B4007DE474 /* File.hpp */, 4B894503201967B4007DE474 /* StaticAnalyser.cpp */, - 4B8944FD201967B4007DE474 /* StaticAnalyser.hpp */, 4B894501201967B4007DE474 /* Tape.cpp */, + 4B894502201967B4007DE474 /* Disk.hpp */, + 4B8944FE201967B4007DE474 /* File.hpp */, + 4B8944FD201967B4007DE474 /* StaticAnalyser.hpp */, 4B8944FF201967B4007DE474 /* Tape.hpp */, ); path = Commodore; @@ -2138,8 +2138,8 @@ 4B894504201967B4007DE474 /* ZX8081 */ = { isa = PBXGroup; children = ( - 4B894505201967B4007DE474 /* StaticAnalyser.hpp */, 4B894506201967B4007DE474 /* StaticAnalyser.cpp */, + 4B894505201967B4007DE474 /* StaticAnalyser.hpp */, ); path = ZX8081; sourceTree = ""; @@ -2147,13 +2147,13 @@ 4B894507201967B4007DE474 /* Disassembler */ = { isa = PBXGroup; children = ( - 4B894508201967B4007DE474 /* 6502.hpp */, - 4B894509201967B4007DE474 /* AddressMapper.hpp */, - 4B89450A201967B4007DE474 /* Z80.hpp */, 4B89450B201967B4007DE474 /* 6502.cpp */, 4B89450C201967B4007DE474 /* AddressMapper.cpp */, 4B89450D201967B4007DE474 /* Z80.cpp */, + 4B894508201967B4007DE474 /* 6502.hpp */, + 4B894509201967B4007DE474 /* AddressMapper.hpp */, 4B89450E201967B4007DE474 /* Kernel.hpp */, + 4B89450A201967B4007DE474 /* Z80.hpp */, ); path = Disassembler; sourceTree = ""; @@ -2161,10 +2161,10 @@ 4B89450F201967B4007DE474 /* MSX */ = { isa = PBXGroup; children = ( + 4B894513201967B4007DE474 /* StaticAnalyser.cpp */, + 4B894512201967B4007DE474 /* Tape.cpp */, 4B894510201967B4007DE474 /* StaticAnalyser.hpp */, 4B894511201967B4007DE474 /* Tape.hpp */, - 4B894512201967B4007DE474 /* Tape.cpp */, - 4B894513201967B4007DE474 /* StaticAnalyser.cpp */, ); path = MSX; sourceTree = ""; @@ -2172,8 +2172,8 @@ 4B894514201967B4007DE474 /* AmstradCPC */ = { isa = PBXGroup; children = ( - 4B894515201967B4007DE474 /* StaticAnalyser.hpp */, 4B894516201967B4007DE474 /* StaticAnalyser.cpp */, + 4B894515201967B4007DE474 /* StaticAnalyser.hpp */, ); path = AmstradCPC; sourceTree = ""; diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index af37e18e4..4d0b5900c 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -63,15 +63,15 @@ struct MachineDelegate: CRTMachine::Machine::Delegate, public LockProtectedDeleg MachineDelegate _machineDelegate; NSLock *_delegateMachineAccessLock; - std::vector _targets; + CSStaticAnalyser *_analyser; std::unique_ptr _machine; } - (instancetype)initWithAnalyser:(CSStaticAnalyser *)result { self = [super init]; if(self) { - _targets = result.targets; - _machine.reset(Machine::MachineForTargets(_targets)); + _analyser = result; + _machine.reset(Machine::MachineForTargets(_analyser.targets)); _delegateMachineAccessLock = [[NSLock alloc] init]; _machineDelegate.machine = self; @@ -82,7 +82,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate, public LockProtectedDeleg _machine->crt_machine()->set_delegate(&_machineDelegate); CSApplyROMFetcher(*_machine->crt_machine()); - [self applyTarget:_targets.front()]; + [self applyTarget:*_analyser.targets.front()]; } return self; } @@ -344,7 +344,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate, public LockProtectedDeleg - (NSString *)userDefaultsPrefix { // Assumes that the first machine in the targets list is the source of user defaults. - std::string name = Machine::ShortNameForTargetMachine(_targets.front().machine); + std::string name = Machine::ShortNameForTargetMachine(_analyser.targets.front()->machine); return [[NSString stringWithUTF8String:name.c_str()] lowercaseString]; } diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser+TargetVector.h b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser+TargetVector.h index a7d0dc5a0..6d563c4b2 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser+TargetVector.h +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser+TargetVector.h @@ -10,6 +10,6 @@ @interface CSStaticAnalyser (ResultVector) -- (std::vector &)targets; +- (std::vector> &)targets; @end diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h index ea7dde231..47457adeb 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.h @@ -17,8 +17,6 @@ @property(nonatomic, readonly) NSString *optionsPanelNibName; @property(nonatomic, readonly) NSString *displayName; -- (void)applyToMachine:(CSMachine *)machine; - @end @interface CSMediaSet : NSObject diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm index fc29fbc25..da59b2b01 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm @@ -17,7 +17,7 @@ #import "Clock_Signal-Swift.h" @implementation CSStaticAnalyser { - std::vector _targets; + std::vector> _targets; } - (instancetype)initWithFileAtURL:(NSURL *)url { @@ -34,7 +34,7 @@ } - (NSString *)optionsPanelNibName { - switch(_targets.front().machine) { + switch(_targets.front()->machine) { case Analyser::Machine::AmstradCPC: return nil; case Analyser::Machine::Atari2600: return @"Atari2600Options"; case Analyser::Machine::Electron: return @"QuickLoadCompositeOptions"; @@ -46,11 +46,7 @@ } } -- (void)applyToMachine:(CSMachine *)machine { - [machine applyTarget:_targets.front()]; -} - -- (std::vector &)targets { +- (std::vector> &)targets { return _targets; } diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index ee2e45f50..da7098b1d 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -13,7 +13,7 @@ #include -#include "../../StaticAnalyser/StaticAnalyser.hpp" +#include "../../Analyser/Static/StaticAnalyser.hpp" #include "../../Machines/Utility/MachineForTarget.hpp" #include "../../Machines/ConfigurationTarget.hpp" @@ -250,7 +250,7 @@ int main(int argc, char *argv[]) { } // Determine the machine for the supplied file. - std::vector targets = Analyser::Static::GetTargets(arguments.file_name.c_str()); + std::vector> targets = Analyser::Static::GetTargets(arguments.file_name.c_str()); if(targets.empty()) { std::cerr << "Cannot open " << arguments.file_name << std::endl; return -1; @@ -353,7 +353,7 @@ int main(int argc, char *argv[]) { return -1; } - machine->configuration_target()->configure_as_target(targets.front()); + machine->configuration_target()->configure_as_target(*targets.front()); // Setup output, assuming a CRT machine for now, and prepare a best-effort updater. machine->crt_machine()->setup_output(4.0 / 3.0);