From ca4df5dd617f3f34d3b8a6611baabfa61aa5663f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 19 Sep 2016 07:35:02 -0400 Subject: [PATCH] Introduced a full container for disk catalogues, so as also to capture non-file information, and 'completed' (i.e. albeit that CRC checking is still absent) DFS catalogue decoding. --- StaticAnalyser/Acorn/Disk.cpp | 63 ++++++++++++++++++++----- StaticAnalyser/Acorn/Disk.hpp | 15 +++++- StaticAnalyser/Acorn/StaticAnalyser.cpp | 2 +- 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/StaticAnalyser/Acorn/Disk.cpp b/StaticAnalyser/Acorn/Disk.cpp index 1d03067ae..d3f08e467 100644 --- a/StaticAnalyser/Acorn/Disk.cpp +++ b/StaticAnalyser/Acorn/Disk.cpp @@ -9,6 +9,7 @@ #include "Disk.hpp" #include "../../Storage/Disk/DiskDrive.hpp" #include "../../Storage/Disk/Encodings/MFM.hpp" +#include using namespace StaticAnalyser::Acorn; @@ -38,7 +39,7 @@ class FMParser: public Storage::Disk::Drive { if(difference) { int direction = difference < 0 ? -1 : 1; - difference *= 2 * direction; + difference *= direction; for(int c = 0; c < difference; c++) step(direction); } @@ -139,29 +140,67 @@ class FMParser: public Storage::Disk::Drive { } }; -std::list StaticAnalyser::Acorn::GetDFSFiles(const std::shared_ptr &disk) +std::unique_ptr StaticAnalyser::Acorn::GetDFSCatalogue(const std::shared_ptr &disk) { // c.f. http://beebwiki.mdfs.net/Acorn_DFS_disc_format - std::list files; + std::unique_ptr catalogue(new Catalogue); FMParser parser; parser.set_disk(disk); std::shared_ptr names = parser.get_sector(0, 0); std::shared_ptr details = parser.get_sector(0, 1); - if(!names || !details) return files; - if(names->data.size() != 256 || details->data.size() != 256) return files; + if(!names || !details) return catalogue; + if(names->data.size() != 256 || details->data.size() != 256) return nullptr; uint8_t final_file_offset = details->data[5]; - if(final_file_offset&7) return files; + if(final_file_offset&7) return nullptr; - size_t number_of_files = (final_file_offset >> 3)-1; - for(size_t file = 0; file < number_of_files; file++) + char disk_name[13]; + snprintf(disk_name, 13, "%.8s%.4s", &names->data[0], &details->data[0]); + catalogue->name = disk_name; + + switch((details->data[6] >> 4)&3) { - char name[10]; - snprintf(name, 10, "%c.%7s", names->data[file * 8 + 7], &names->data[file * 8]); - printf("%s\n", name); + case 0: catalogue->bootOption = Catalogue::BootOption::None; break; + case 1: catalogue->bootOption = Catalogue::BootOption::LoadBOOT; break; + case 2: catalogue->bootOption = Catalogue::BootOption::RunBOOT; break; + case 3: catalogue->bootOption = Catalogue::BootOption::ExecBOOT; break; } - return files; + // DFS files are stored contiguously, and listed in descending order of distance from track 0. + // So iterating backwards implies the least amount of seeking. + for(size_t file_offset = final_file_offset - 8; file_offset > 0; file_offset -= 8) + { + File new_file; + char name[10]; + snprintf(name, 10, "%c.%.7s", names->data[file_offset + 7] & 0x7f, &names->data[file_offset]); + new_file.name = name; + new_file.load_address = (uint32_t)(details->data[file_offset] | (details->data[file_offset+1] << 8) | ((details->data[file_offset+6]&0x0c) << 14)); + new_file.execution_address = (uint32_t)(details->data[file_offset+2] | (details->data[file_offset+3] << 8) | ((details->data[file_offset+6]&0xc0) << 10)); + new_file.is_protected = !!(names->data[file_offset + 7] & 0x80); + + long data_length = (long)(details->data[file_offset+4] | (details->data[file_offset+5] << 8) | ((details->data[file_offset+6]&0x30) << 12)); + int start_sector = details->data[file_offset+7] | ((details->data[file_offset+6]&0x03) << 8); + new_file.data.reserve((size_t)data_length); + + if(start_sector < 2) continue; + + while(data_length > 0) + { + uint8_t sector = (uint8_t)(start_sector % 10); + uint8_t track = (uint8_t)(start_sector / 10); + start_sector++; + + std::shared_ptr next_sector = parser.get_sector(track, sector); + if(!next_sector) break; + + long length_from_sector = std::min(data_length, 256l); + new_file.data.insert(new_file.data.end(), next_sector->data.begin(), next_sector->data.begin() + length_from_sector); + data_length -= length_from_sector; + if(!data_length) catalogue->files.push_front(new_file); + } + } + + return catalogue; } diff --git a/StaticAnalyser/Acorn/Disk.hpp b/StaticAnalyser/Acorn/Disk.hpp index 92ea3ba1e..5b7bc3ed7 100644 --- a/StaticAnalyser/Acorn/Disk.hpp +++ b/StaticAnalyser/Acorn/Disk.hpp @@ -15,8 +15,19 @@ namespace StaticAnalyser { namespace Acorn { -std::list GetDFSFiles(const std::shared_ptr &disk); -std::list GetADFSFiles(const std::shared_ptr &disk); +struct Catalogue { + std::string name; + std::list files; + enum class BootOption { + None, + LoadBOOT, + RunBOOT, + ExecBOOT + } bootOption; +}; + +std::unique_ptr GetDFSCatalogue(const std::shared_ptr &disk); +std::unique_ptr GetADFSCatalogue(const std::shared_ptr &disk); } } diff --git a/StaticAnalyser/Acorn/StaticAnalyser.cpp b/StaticAnalyser/Acorn/StaticAnalyser.cpp index 93d92022f..35f8d3491 100644 --- a/StaticAnalyser/Acorn/StaticAnalyser.cpp +++ b/StaticAnalyser/Acorn/StaticAnalyser.cpp @@ -115,7 +115,7 @@ void StaticAnalyser::Acorn::AddTargets( if(disks.size() > 0) { std::shared_ptr disk = disks.front(); - std::list dfs_files = GetDFSFiles(disk); + std::unique_ptr dfs_catalogue = GetDFSCatalogue(disk); } if(target.tapes.size() || target.cartridges.size())