From d1fccd3ea133ca59be8c69df9a7dd2c8aba13423 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 24 May 2026 10:11:18 -0400 Subject: [PATCH] Slightly improve file selection. --- Analyser/Static/TandyCoCo/StaticAnalyser.cpp | 65 +++++++++++++++++--- Storage/Disk/Parsers/TandyCoCo.hpp | 2 +- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/Analyser/Static/TandyCoCo/StaticAnalyser.cpp b/Analyser/Static/TandyCoCo/StaticAnalyser.cpp index f9e4dca02..32980f64e 100644 --- a/Analyser/Static/TandyCoCo/StaticAnalyser.cpp +++ b/Analyser/Static/TandyCoCo/StaticAnalyser.cpp @@ -48,15 +48,64 @@ Analyser::Static::TargetList Analyser::Static::TandyCoCo::GetTargets( if(!media.disks.empty()) { target->has_disk_drive = true; - const auto directory = Storage::Disk::TandyCoCo::directory(*media.disks.front()); - if(directory.has_value() && directory->size() == 1) { - auto &entry = directory.value()[0]; - const bool is_basic = entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC; + auto loadable = [&]() -> std::optional { + const auto maybe_directory = Storage::Disk::TandyCoCo::directory(*media.disks.front()); + if(!maybe_directory.has_value()) { + return std::nullopt; + } + auto directory = *maybe_directory; - target->loading_command = is_basic ? L"LOAD\"" : L"LOADM\""; - target->loading_command += std::wstring(entry.name.begin(), entry.name.end()); - target->loading_command += L"\":"; - target->loading_command += is_basic ? L"RUN\n" : L"EXEC\n"; + // Remove anything the user can't actually type. + std::erase_if(directory, [](const auto &entry) { + if(entry.name == " ") return true; + for(const auto c: entry.name) { + if(c & 0x80) return true; + } + return false; + }); + + // Single item: return that. + if(directory.size() == 1) { + return directory[0]; + } + + // Failing that, is there a single thing that's BASIC or no BASIC and a single thing that's machine code? + int basics = 0; + int machine_languages = 0; + for(const auto &entry: directory) { + basics += entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC; + machine_languages += + entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::MachineLanguage; + } + + if(basics == 1) { + for(const auto &entry: directory) { + if(entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC) { + return entry; + } + } + } + + if(!basics && machine_languages == 1) { + for(const auto &entry: directory) { + if(entry.file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::MachineLanguage) { + return entry; + } + } + } + + return std::nullopt; + } (); + + if(loadable.has_value()) { + const bool is_basic = loadable->file_type == Storage::Disk::TandyCoCo::DirectoryEntry::FileType::BASIC; + + target->loading_command = is_basic ? L"RUN\"" : L"LOADM\""; + target->loading_command += std::wstring(loadable->name.begin(), loadable->name.end()); + if(!is_basic) { + target->loading_command += L"\":EXEC"; + } + target->loading_command += L"\n"; } else { target->loading_command = L"DIR\n"; } diff --git a/Storage/Disk/Parsers/TandyCoCo.hpp b/Storage/Disk/Parsers/TandyCoCo.hpp index 7d2115131..9f95afece 100644 --- a/Storage/Disk/Parsers/TandyCoCo.hpp +++ b/Storage/Disk/Parsers/TandyCoCo.hpp @@ -24,7 +24,7 @@ struct DirectoryEntry { BASIC = 0, BASICData = 1, MachineLanguage = 2, - TextEditorsource = 3, + TextEditorSource = 3, }; FileType file_type;