2016-09-25 21:46:11 +00:00
|
|
|
//
|
|
|
|
// AcornADF.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "AcornADF.hpp"
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "../Encodings/MFM.hpp"
|
|
|
|
|
2016-09-27 01:20:30 +00:00
|
|
|
namespace {
|
|
|
|
static const unsigned int sectors_per_track = 16;
|
|
|
|
static const unsigned int bytes_per_sector = 256;
|
|
|
|
}
|
|
|
|
|
2016-09-25 21:46:11 +00:00
|
|
|
using namespace Storage::Disk;
|
|
|
|
|
2016-11-21 12:14:09 +00:00
|
|
|
AcornADF::AcornADF(const char *file_name) :
|
|
|
|
Storage::FileHolder(file_name)
|
2016-09-25 21:46:11 +00:00
|
|
|
{
|
|
|
|
// very loose validation: the file needs to be a multiple of 256 bytes
|
|
|
|
// and not ungainly large
|
2016-11-21 12:14:09 +00:00
|
|
|
if(file_stats_.st_size % bytes_per_sector) throw ErrorNotAcornADF;
|
|
|
|
if(file_stats_.st_size < 7 * bytes_per_sector) throw ErrorNotAcornADF;
|
2016-09-25 21:46:11 +00:00
|
|
|
|
|
|
|
// check that the initial directory's 'Hugo's are present
|
2016-11-21 12:14:09 +00:00
|
|
|
fseek(file_, 513, SEEK_SET);
|
2016-09-25 21:46:11 +00:00
|
|
|
uint8_t bytes[4];
|
2016-11-21 12:14:09 +00:00
|
|
|
fread(bytes, 1, 4, file_);
|
2016-09-25 21:46:11 +00:00
|
|
|
if(bytes[0] != 'H' || bytes[1] != 'u' || bytes[2] != 'g' || bytes[3] != 'o') throw ErrorNotAcornADF;
|
|
|
|
|
2016-11-21 12:14:09 +00:00
|
|
|
fseek(file_, 0x6fb, SEEK_SET);
|
|
|
|
fread(bytes, 1, 4, file_);
|
2016-09-25 21:46:11 +00:00
|
|
|
if(bytes[0] != 'H' || bytes[1] != 'u' || bytes[2] != 'g' || bytes[3] != 'o') throw ErrorNotAcornADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AcornADF::get_head_position_count()
|
|
|
|
{
|
|
|
|
return 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AcornADF::get_head_count()
|
|
|
|
{
|
2016-09-27 01:20:30 +00:00
|
|
|
return 1;
|
2016-09-25 21:46:11 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 15:35:11 +00:00
|
|
|
std::shared_ptr<Track> AcornADF::get_uncached_track_at_position(unsigned int head, unsigned int position)
|
2016-09-25 21:46:11 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<Track> track;
|
|
|
|
|
|
|
|
if(head >= 2) return track;
|
2016-09-27 01:20:30 +00:00
|
|
|
long file_offset = (position * 1 + head) * bytes_per_sector * sectors_per_track;
|
2016-11-21 12:14:09 +00:00
|
|
|
fseek(file_, file_offset, SEEK_SET);
|
2016-09-25 21:46:11 +00:00
|
|
|
|
|
|
|
std::vector<Storage::Encodings::MFM::Sector> sectors;
|
2016-09-27 01:20:30 +00:00
|
|
|
for(int sector = 0; sector < sectors_per_track; sector++)
|
2016-09-25 21:46:11 +00:00
|
|
|
{
|
|
|
|
Storage::Encodings::MFM::Sector new_sector;
|
|
|
|
new_sector.track = (uint8_t)position;
|
2016-09-27 01:20:30 +00:00
|
|
|
new_sector.side = (uint8_t)head;
|
2016-09-25 21:46:11 +00:00
|
|
|
new_sector.sector = (uint8_t)sector;
|
|
|
|
|
2016-09-27 01:20:30 +00:00
|
|
|
new_sector.data.resize(bytes_per_sector);
|
2016-11-21 12:14:09 +00:00
|
|
|
fread(&new_sector.data[0], 1, bytes_per_sector, file_);
|
|
|
|
if(feof(file_))
|
2016-09-25 21:46:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
sectors.push_back(std::move(new_sector));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sectors.size()) return Storage::Encodings::MFM::GetMFMTrackWithSectors(sectors);
|
|
|
|
|
|
|
|
return track;
|
|
|
|
}
|