2017-09-30 02:07:23 +00:00
|
|
|
//
|
|
|
|
// ImplicitSectors.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 29/09/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-09-30 02:07:23 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "ImplicitSectors.hpp"
|
|
|
|
|
2017-11-11 02:56:53 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-09-30 02:07:23 +00:00
|
|
|
#include "../../../Encodings/MFM/Sector.hpp"
|
|
|
|
#include "../../../Encodings/MFM/Encoder.hpp"
|
|
|
|
#include "../../../Encodings/MFM/Constants.hpp"
|
|
|
|
#include "../../../Track/TrackSerialiser.hpp"
|
|
|
|
#include "../../../Encodings/MFM/SegmentParser.hpp"
|
|
|
|
|
|
|
|
using namespace Storage::Disk;
|
|
|
|
|
2019-10-04 02:41:20 +00:00
|
|
|
std::shared_ptr<Track> Storage::Disk::track_for_sectors(const uint8_t *const source, int number_of_sectors, uint8_t track, uint8_t side, uint8_t first_sector, uint8_t size, bool is_double_density) {
|
2017-09-30 02:07:23 +00:00
|
|
|
std::vector<Storage::Encodings::MFM::Sector> sectors;
|
|
|
|
|
2020-05-10 03:00:39 +00:00
|
|
|
off_t byte_size = off_t(128 << size);
|
2017-09-30 02:07:23 +00:00
|
|
|
off_t source_pointer = 0;
|
2018-05-07 03:17:36 +00:00
|
|
|
for(int sector = 0; sector < number_of_sectors; sector++) {
|
2017-09-30 02:07:23 +00:00
|
|
|
sectors.emplace_back();
|
|
|
|
|
|
|
|
Storage::Encodings::MFM::Sector &new_sector = sectors.back();
|
|
|
|
new_sector.address.track = track;
|
2018-01-08 01:02:40 +00:00
|
|
|
new_sector.address.side = side;
|
2017-09-30 02:07:23 +00:00
|
|
|
new_sector.address.sector = first_sector;
|
|
|
|
first_sector++;
|
|
|
|
new_sector.size = size;
|
|
|
|
|
2017-11-01 01:32:28 +00:00
|
|
|
new_sector.samples.emplace_back();
|
|
|
|
new_sector.samples[0].insert(new_sector.samples[0].begin(), source + source_pointer, source + source_pointer + byte_size);
|
2017-09-30 02:07:23 +00:00
|
|
|
source_pointer += byte_size;
|
|
|
|
}
|
|
|
|
|
2018-07-11 00:01:11 +00:00
|
|
|
if(!sectors.empty()) {
|
2017-09-30 02:07:23 +00:00
|
|
|
return is_double_density ? Storage::Encodings::MFM::GetMFMTrackWithSectors(sectors) : Storage::Encodings::MFM::GetFMTrackWithSectors(sectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Storage::Disk::decode_sectors(Track &track, uint8_t *const destination, uint8_t first_sector, uint8_t last_sector, uint8_t sector_size, bool is_double_density) {
|
2017-11-11 20:28:40 +00:00
|
|
|
std::map<std::size_t, Storage::Encodings::MFM::Sector> sectors =
|
2017-09-30 02:07:23 +00:00
|
|
|
Storage::Encodings::MFM::sectors_from_segment(
|
|
|
|
Storage::Disk::track_serialisation(track, is_double_density ? Storage::Encodings::MFM::MFMBitLength : Storage::Encodings::MFM::FMBitLength),
|
2017-09-30 02:48:00 +00:00
|
|
|
is_double_density);
|
2017-09-30 02:07:23 +00:00
|
|
|
|
2020-05-10 03:00:39 +00:00
|
|
|
std::size_t byte_size = size_t(128 << sector_size);
|
2018-05-01 02:23:57 +00:00
|
|
|
for(const auto &pair : sectors) {
|
2017-09-30 02:07:23 +00:00
|
|
|
if(pair.second.address.sector > last_sector) continue;
|
|
|
|
if(pair.second.address.sector < first_sector) continue;
|
|
|
|
if(pair.second.size != sector_size) continue;
|
2017-11-01 01:32:28 +00:00
|
|
|
if(pair.second.samples.empty()) continue;
|
2017-11-11 20:28:40 +00:00
|
|
|
std::memcpy(&destination[pair.second.address.sector * byte_size], pair.second.samples[0].data(), std::min(pair.second.samples[0].size(), byte_size));
|
2017-09-30 02:07:23 +00:00
|
|
|
}
|
|
|
|
}
|