2016-09-19 01:18:11 +00:00
|
|
|
//
|
|
|
|
// Disk.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-09-19 01:18:11 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Disk.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
|
|
|
|
#include "../../../Storage/Disk/Controller/DiskController.hpp"
|
|
|
|
#include "../../../Storage/Disk/Encodings/MFM/Parser.hpp"
|
2020-01-20 04:14:35 +00:00
|
|
|
#include "../../../Numeric/CRC.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
|
2016-09-19 11:35:02 +00:00
|
|
|
#include <algorithm>
|
2016-09-19 01:18:11 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
using namespace Analyser::Static::Acorn;
|
2016-09-19 01:18:11 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetDFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
|
2016-09-19 02:18:01 +00:00
|
|
|
// c.f. http://beebwiki.mdfs.net/Acorn_DFS_disc_format
|
2019-12-22 04:52:04 +00:00
|
|
|
auto catalogue = std::make_unique<Catalogue>();
|
2016-12-26 01:00:57 +00:00
|
|
|
Storage::Encodings::MFM::Parser parser(false, disk);
|
2016-09-19 02:03:06 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
Storage::Encodings::MFM::Sector *names = parser.get_sector(0, 0, 0);
|
|
|
|
Storage::Encodings::MFM::Sector *details = parser.get_sector(0, 0, 1);
|
2016-09-19 02:18:01 +00:00
|
|
|
|
2016-09-25 21:46:11 +00:00
|
|
|
if(!names || !details) return nullptr;
|
2017-11-01 01:32:28 +00:00
|
|
|
if(names->samples.empty() || details->samples.empty()) return nullptr;
|
|
|
|
if(names->samples[0].size() != 256 || details->samples[0].size() != 256) return nullptr;
|
2016-09-19 02:18:01 +00:00
|
|
|
|
2017-11-01 01:32:28 +00:00
|
|
|
uint8_t final_file_offset = details->samples[0][5];
|
2016-09-19 11:35:02 +00:00
|
|
|
if(final_file_offset&7) return nullptr;
|
2016-12-30 22:29:51 +00:00
|
|
|
if(final_file_offset < 8) return nullptr;
|
2016-09-19 02:18:01 +00:00
|
|
|
|
2016-09-19 11:35:02 +00:00
|
|
|
char disk_name[13];
|
2017-11-01 01:32:28 +00:00
|
|
|
snprintf(disk_name, 13, "%.8s%.4s", &names->samples[0][0], &details->samples[0][0]);
|
2016-09-19 11:35:02 +00:00
|
|
|
catalogue->name = disk_name;
|
|
|
|
|
2017-11-01 01:32:28 +00:00
|
|
|
switch((details->samples[0][6] >> 4)&3) {
|
2016-09-19 11:35:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-24 03:18:16 +00:00
|
|
|
for(std::size_t file_offset = 8; file_offset < final_file_offset; file_offset += 8) {
|
2016-09-19 11:35:02 +00:00
|
|
|
File new_file;
|
2016-09-19 02:18:01 +00:00
|
|
|
char name[10];
|
2017-11-01 01:32:28 +00:00
|
|
|
snprintf(name, 10, "%c.%.7s", names->samples[0][file_offset + 7] & 0x7f, &names->samples[0][file_offset]);
|
2016-09-19 11:35:02 +00:00
|
|
|
new_file.name = name;
|
2017-11-01 01:32:28 +00:00
|
|
|
new_file.load_address = (uint32_t)(details->samples[0][file_offset] | (details->samples[0][file_offset+1] << 8) | ((details->samples[0][file_offset+6]&0x0c) << 14));
|
|
|
|
new_file.execution_address = (uint32_t)(details->samples[0][file_offset+2] | (details->samples[0][file_offset+3] << 8) | ((details->samples[0][file_offset+6]&0xc0) << 10));
|
|
|
|
new_file.is_protected = !!(names->samples[0][file_offset + 7] & 0x80);
|
2016-09-19 11:35:02 +00:00
|
|
|
|
2017-11-01 01:32:28 +00:00
|
|
|
long data_length = static_cast<long>(details->samples[0][file_offset+4] | (details->samples[0][file_offset+5] << 8) | ((details->samples[0][file_offset+6]&0x30) << 12));
|
|
|
|
int start_sector = details->samples[0][file_offset+7] | ((details->samples[0][file_offset+6]&0x03) << 8);
|
2017-11-11 20:28:40 +00:00
|
|
|
new_file.data.reserve(static_cast<std::size_t>(data_length));
|
2016-09-19 11:35:02 +00:00
|
|
|
|
|
|
|
if(start_sector < 2) continue;
|
2017-03-26 18:34:47 +00:00
|
|
|
while(data_length > 0) {
|
2017-10-22 01:50:53 +00:00
|
|
|
uint8_t sector = static_cast<uint8_t>(start_sector % 10);
|
|
|
|
uint8_t track = static_cast<uint8_t>(start_sector / 10);
|
2016-09-19 11:35:02 +00:00
|
|
|
start_sector++;
|
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
Storage::Encodings::MFM::Sector *next_sector = parser.get_sector(0, track, sector);
|
2016-09-19 11:35:02 +00:00
|
|
|
if(!next_sector) break;
|
|
|
|
|
|
|
|
long length_from_sector = std::min(data_length, 256l);
|
2017-11-01 01:32:28 +00:00
|
|
|
new_file.data.insert(new_file.data.end(), next_sector->samples[0].begin(), next_sector->samples[0].begin() + length_from_sector);
|
2016-09-19 11:35:02 +00:00
|
|
|
data_length -= length_from_sector;
|
|
|
|
}
|
2018-01-24 03:18:16 +00:00
|
|
|
if(!data_length) catalogue->files.push_back(new_file);
|
2016-09-19 02:18:01 +00:00
|
|
|
}
|
2016-09-19 02:03:06 +00:00
|
|
|
|
2016-09-19 11:35:02 +00:00
|
|
|
return catalogue;
|
2016-09-19 01:18:11 +00:00
|
|
|
}
|
2018-01-25 02:48:44 +00:00
|
|
|
std::unique_ptr<Catalogue> Analyser::Static::Acorn::GetADFSCatalogue(const std::shared_ptr<Storage::Disk::Disk> &disk) {
|
2019-12-22 04:52:04 +00:00
|
|
|
auto catalogue = std::make_unique<Catalogue>();
|
2016-12-26 01:00:57 +00:00
|
|
|
Storage::Encodings::MFM::Parser parser(true, disk);
|
2016-09-25 18:11:22 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
Storage::Encodings::MFM::Sector *free_space_map_second_half = parser.get_sector(0, 0, 1);
|
2016-09-25 22:32:26 +00:00
|
|
|
if(!free_space_map_second_half) return nullptr;
|
|
|
|
|
|
|
|
std::vector<uint8_t> root_directory;
|
|
|
|
root_directory.reserve(5 * 256);
|
2017-03-26 18:34:47 +00:00
|
|
|
for(uint8_t c = 2; c < 7; c++) {
|
2017-09-30 00:08:36 +00:00
|
|
|
Storage::Encodings::MFM::Sector *sector = parser.get_sector(0, 0, c);
|
2016-09-25 22:32:26 +00:00
|
|
|
if(!sector) return nullptr;
|
2017-11-01 01:32:28 +00:00
|
|
|
root_directory.insert(root_directory.end(), sector->samples[0].begin(), sector->samples[0].end());
|
2016-09-25 22:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Quick sanity checks.
|
|
|
|
if(root_directory[0x4cb]) return nullptr;
|
|
|
|
if(root_directory[1] != 'H' || root_directory[2] != 'u' || root_directory[3] != 'g' || root_directory[4] != 'o') return nullptr;
|
|
|
|
if(root_directory[0x4FB] != 'H' || root_directory[0x4FC] != 'u' || root_directory[0x4FD] != 'g' || root_directory[0x4FE] != 'o') return nullptr;
|
|
|
|
|
2017-11-01 01:32:28 +00:00
|
|
|
switch(free_space_map_second_half->samples[0][0xfd]) {
|
2016-09-25 22:32:26 +00:00
|
|
|
default: 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;
|
|
|
|
}
|
2016-09-25 18:11:22 +00:00
|
|
|
|
|
|
|
return catalogue;
|
|
|
|
}
|