2021-06-25 01:04:21 +00:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/06/2021.
|
|
|
|
// Copyright 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
|
|
|
#include "Target.hpp"
|
|
|
|
|
2021-07-02 22:56:43 +00:00
|
|
|
#include "../../../Storage/Disk/Parsers/FAT.hpp"
|
|
|
|
|
2021-07-02 23:42:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool insensitive_equal(const std::string &lhs, const std::string &rhs) {
|
|
|
|
return std::equal(
|
|
|
|
lhs.begin(), lhs.end(),
|
|
|
|
rhs.begin(), rhs.end(),
|
|
|
|
[] (char l, char r) {
|
|
|
|
return tolower(l) == tolower(r);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-25 01:04:21 +00:00
|
|
|
Analyser::Static::TargetList Analyser::Static::Enterprise::GetTargets(const Media &media, const std::string &, TargetPlatform::IntType) {
|
|
|
|
// This analyser can comprehend disks only.
|
|
|
|
if(media.disks.empty()) return {};
|
|
|
|
|
2021-07-02 22:56:43 +00:00
|
|
|
// Otherwise, assume a return will happen.
|
2021-06-25 01:04:21 +00:00
|
|
|
Analyser::Static::TargetList targets;
|
|
|
|
using Target = Analyser::Static::Enterprise::Target;
|
|
|
|
auto *const target = new Target;
|
|
|
|
target->media = media;
|
|
|
|
|
|
|
|
// Always require a BASIC.
|
|
|
|
target->basic_version = Target::BASICVersion::Any;
|
|
|
|
|
2021-07-02 22:56:43 +00:00
|
|
|
// Inspect any supplied disks.
|
2023-11-29 19:54:33 +00:00
|
|
|
//
|
|
|
|
// TODO: how best can these be discerned from MS-DOS and MSX disks?
|
2021-06-25 01:04:21 +00:00
|
|
|
if(!media.disks.empty()) {
|
2021-07-02 23:42:43 +00:00
|
|
|
// DOS will be needed.
|
2021-06-25 01:04:21 +00:00
|
|
|
target->dos = Target::DOS::EXDOS;
|
2021-07-02 23:42:43 +00:00
|
|
|
|
|
|
|
// Grab the volume information, which includes the root directory.
|
|
|
|
auto volume = Storage::Disk::FAT::GetVolume(media.disks.front());
|
|
|
|
if(volume) {
|
|
|
|
// If there's an EXDOS.INI then this disk should be able to boot itself.
|
2021-07-16 01:57:25 +00:00
|
|
|
// If not but if there's only one visible .COM or .BAS, automatically load
|
|
|
|
// that. Otherwise, issue a :DIR.
|
|
|
|
using File = Storage::Disk::FAT::File;
|
|
|
|
const File *selected_file = nullptr;
|
2021-07-02 23:42:43 +00:00
|
|
|
bool has_exdos_ini = false;
|
|
|
|
bool did_pick_file = false;
|
|
|
|
for(const auto &file: (*volume).root_directory) {
|
2021-07-02 23:50:27 +00:00
|
|
|
if(insensitive_equal(file.name, "exdos") && insensitive_equal(file.extension, "ini")) {
|
2021-07-02 23:42:43 +00:00
|
|
|
has_exdos_ini = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-16 01:57:25 +00:00
|
|
|
if(!(file.attributes & File::Attribute::Hidden) &&
|
|
|
|
(insensitive_equal(file.extension, "com") || insensitive_equal(file.extension, "bas"))
|
|
|
|
) {
|
2021-07-02 23:42:43 +00:00
|
|
|
did_pick_file = !selected_file;
|
|
|
|
selected_file = &file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!has_exdos_ini) {
|
|
|
|
if(did_pick_file) {
|
2021-07-07 03:16:16 +00:00
|
|
|
target->loading_command = std::string("run \"") + selected_file->name + "." + selected_file->extension + "\"\n";
|
2021-07-02 23:42:43 +00:00
|
|
|
} else {
|
2021-07-03 01:15:48 +00:00
|
|
|
target->loading_command = ":dir\n";
|
2021-07-02 23:42:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 01:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(target));
|
|
|
|
|
|
|
|
return targets;
|
|
|
|
}
|