Skip to content

Commit

Permalink
Factgor out and reuse is-ZX test.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHarte committed Aug 23, 2024
1 parent 69ba94e commit eece8c5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Analyser/Static/AmstradCPC/StaticAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Storage::Disk::CPM::Catalogue> 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;
Expand All @@ -248,7 +248,7 @@ Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Medi

// Failing that check for a system catalogue.
std::unique_ptr<Storage::Disk::CPM::Catalogue> 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;
Expand Down
7 changes: 1 addition & 6 deletions Analyser/Static/ZXSpectrum/StaticAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ bool IsSpectrumDisk(const std::shared_ptr<Storage::Disk::Disk> &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();
}

}
Expand Down
10 changes: 10 additions & 0 deletions Storage/Disk/Parsers/CPM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,13 @@ std::unique_ptr<Storage::Disk::CPM::Catalogue> 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;
}
2 changes: 2 additions & 0 deletions Storage/Disk/Parsers/CPM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct File {

struct Catalogue {
std::vector<File> files;

bool is_zx_spectrum_booter();
};

std::unique_ptr<Catalogue> GetCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk, const ParameterBlock &parameters);
Expand Down

0 comments on commit eece8c5

Please sign in to comment.