From eece8c54a4b2de2b3ceceab1d52c91f9d4e1ec78 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 22 Aug 2024 21:17:35 -0400 Subject: [PATCH] Factgor out and reuse is-ZX test. --- Analyser/Static/AmstradCPC/StaticAnalyser.cpp | 6 +++--- Analyser/Static/ZXSpectrum/StaticAnalyser.cpp | 7 +------ Storage/Disk/Parsers/CPM.cpp | 10 ++++++++++ Storage/Disk/Parsers/CPM.hpp | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp index 419e855dc..49b002890 100644 --- a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp +++ b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp @@ -232,9 +232,9 @@ Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Medi const auto system_format = Storage::Disk::CPM::ParameterBlock::cpc_system_format(); for(auto &disk: media.disks) { - // Check for an ordinary catalogue. + // Check for an ordinary catalogue, making sure this isn't actually a ZX Spectrum disk. std::unique_ptr data_catalogue = Storage::Disk::CPM::GetCatalogue(disk, data_format); - if(data_catalogue) { + if(data_catalogue && !data_catalogue->is_zx_spectrum_booter()) { InspectCatalogue(*data_catalogue, target); target->media.disks.push_back(disk); continue; @@ -248,7 +248,7 @@ Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Medi // Failing that check for a system catalogue. std::unique_ptr system_catalogue = Storage::Disk::CPM::GetCatalogue(disk, system_format); - if(system_catalogue) { + if(system_catalogue && !system_catalogue->is_zx_spectrum_booter()) { InspectCatalogue(*system_catalogue, target); target->media.disks.push_back(disk); continue; diff --git a/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp b/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp index 1a60b5ae8..d47e8d4c0 100644 --- a/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp +++ b/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp @@ -98,12 +98,7 @@ bool IsSpectrumDisk(const std::shared_ptr &disk) { // ... otherwise read a CPM directory and look for a BASIC program called "DISK". const auto catalogue = Storage::Disk::CPM::GetCatalogue(disk, cpm_format); - if(!catalogue) return false; - const auto file = std::find_if(catalogue->files.begin(), catalogue->files.end(), [](const auto &file) { return file.name == "DISK "; }); - if(file == catalogue->files.end()) return false; - - // TODO: check out contents of "DISK" - return true; + return catalogue && catalogue->is_zx_spectrum_booter(); } } diff --git a/Storage/Disk/Parsers/CPM.cpp b/Storage/Disk/Parsers/CPM.cpp index b6a757091..93e3efa9a 100644 --- a/Storage/Disk/Parsers/CPM.cpp +++ b/Storage/Disk/Parsers/CPM.cpp @@ -158,3 +158,13 @@ std::unique_ptr Storage::Disk::CPM::GetCatalogue( return result; } + +bool Catalogue::is_zx_spectrum_booter() { + // Check for a file called 'DISK'. + const auto file = std::find_if(files.begin(), files.end(), [](const auto &file) { return file.name == "DISK "; }); + if(file == files.end()) return false; + + // TODO: check the file is valid ZX Spectrum BASIC. + + return true; +} diff --git a/Storage/Disk/Parsers/CPM.hpp b/Storage/Disk/Parsers/CPM.hpp index 847a5ab24..02958e822 100644 --- a/Storage/Disk/Parsers/CPM.hpp +++ b/Storage/Disk/Parsers/CPM.hpp @@ -60,6 +60,8 @@ struct File { struct Catalogue { std::vector files; + + bool is_zx_spectrum_booter(); }; std::unique_ptr GetCatalogue(const std::shared_ptr &disk, const ParameterBlock ¶meters);