2016-09-18 23:21:02 +00:00
|
|
|
//
|
|
|
|
// SSD.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 18/09/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "SSD.hpp"
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
2016-09-18 23:32:08 +00:00
|
|
|
#include "../Encodings/MFM.hpp"
|
2016-09-18 23:21:02 +00:00
|
|
|
|
|
|
|
using namespace Storage::Disk;
|
|
|
|
|
2016-11-21 12:14:09 +00:00
|
|
|
SSD::SSD(const char *file_name) :
|
|
|
|
Storage::FileHolder(file_name)
|
2016-09-18 23:21:02 +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 & 255) throw ErrorNotSSD;
|
|
|
|
if(file_stats_.st_size < 512) throw ErrorNotSSD;
|
|
|
|
if(file_stats_.st_size > 800*256) throw ErrorNotSSD;
|
2016-09-18 23:32:08 +00:00
|
|
|
|
|
|
|
// this has two heads if the suffix is .dsd, one if it's .ssd
|
2016-11-21 12:14:09 +00:00
|
|
|
head_count_ = (tolower(file_name[strlen(file_name) - 3]) == 'd') ? 2 : 1;
|
|
|
|
track_count_ = (unsigned int)(file_stats_.st_size / (256 * 10));
|
|
|
|
if(track_count_ < 40) track_count_ = 40;
|
|
|
|
else if(track_count_ < 80) track_count_ = 80;
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SSD::get_head_position_count()
|
|
|
|
{
|
2016-11-21 12:14:09 +00:00
|
|
|
return track_count_;
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SSD::get_head_count()
|
|
|
|
{
|
2016-11-21 12:14:09 +00:00
|
|
|
return head_count_;
|
2016-09-18 23:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Track> SSD::get_track_at_position(unsigned int head, unsigned int position)
|
|
|
|
{
|
|
|
|
std::shared_ptr<Track> track;
|
2016-09-18 23:32:08 +00:00
|
|
|
|
2016-11-21 12:14:09 +00:00
|
|
|
if(head >= head_count_) return track;
|
|
|
|
long file_offset = (position * head_count_ + head) * 256 * 10;
|
|
|
|
fseek(file_, file_offset, SEEK_SET);
|
2016-09-18 23:32:08 +00:00
|
|
|
|
2016-09-19 01:09:32 +00:00
|
|
|
std::vector<Storage::Encodings::MFM::Sector> sectors;
|
2016-09-18 23:32:08 +00:00
|
|
|
for(int sector = 0; sector < 10; sector++)
|
|
|
|
{
|
2016-09-19 01:09:32 +00:00
|
|
|
Storage::Encodings::MFM::Sector new_sector;
|
|
|
|
new_sector.track = (uint8_t)position;
|
|
|
|
new_sector.side = 0;
|
|
|
|
new_sector.sector = (uint8_t)sector;
|
|
|
|
|
|
|
|
new_sector.data.resize(256);
|
2016-11-21 12:14:09 +00:00
|
|
|
fread(&new_sector.data[0], 1, 256, file_);
|
|
|
|
if(feof(file_))
|
2016-09-25 21:46:11 +00:00
|
|
|
break;
|
2016-09-19 01:09:32 +00:00
|
|
|
|
|
|
|
sectors.push_back(std::move(new_sector));
|
2016-09-18 23:32:08 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 01:09:32 +00:00
|
|
|
if(sectors.size()) return Storage::Encodings::MFM::GetFMTrackWithSectors(sectors);
|
|
|
|
|
2016-09-18 23:21:02 +00:00
|
|
|
return track;
|
|
|
|
}
|