mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
The image readers now log to the logger.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "image.h"
|
||||
#include "proto.h"
|
||||
#include "logger.h"
|
||||
#include "lib/config.pb.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
@@ -16,18 +17,17 @@
|
||||
class D88ImageReader : public ImageReader
|
||||
{
|
||||
public:
|
||||
D88ImageReader(const ImageReaderProto& config):
|
||||
ImageReader(config)
|
||||
{}
|
||||
D88ImageReader(const ImageReaderProto& config): ImageReader(config) {}
|
||||
|
||||
std::unique_ptr<Image> readImage()
|
||||
{
|
||||
std::ifstream inputFile(_config.filename(), std::ios::in | std::ios::binary);
|
||||
std::unique_ptr<Image> readImage()
|
||||
{
|
||||
std::ifstream inputFile(
|
||||
_config.filename(), std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
Error() << "cannot open input file";
|
||||
|
||||
Bytes header(0x24); // read first entry of track table as well
|
||||
inputFile.read((char*) header.begin(), header.size());
|
||||
inputFile.read((char*)header.begin(), header.size());
|
||||
|
||||
// the DIM header technically has a bit field for sectors present,
|
||||
// however it is currently ignored by this reader
|
||||
@@ -35,45 +35,55 @@ public:
|
||||
std::string diskName = header.slice(0, 0x16);
|
||||
|
||||
if (diskName[0])
|
||||
std::cout << "D88: disk name: " << diskName << "\n";
|
||||
Logger() << fmt::format("D88: disk name: {}", diskName);
|
||||
|
||||
ByteReader headerReader(header);
|
||||
|
||||
char mediaFlag = headerReader.seek(0x1b).read_8();
|
||||
|
||||
inputFile.seekg( 0, std::ios::end );
|
||||
inputFile.seekg(0, std::ios::end);
|
||||
int fileSize = inputFile.tellg();
|
||||
|
||||
int diskSize = headerReader.seek(0x1c).read_le32();
|
||||
|
||||
if (diskSize > fileSize)
|
||||
std::cout << "D88: found multiple disk images. Only using first\n";
|
||||
Logger() << "D88: found multiple disk images. Only using first";
|
||||
|
||||
int trackTableEnd = headerReader.seek(0x20).read_le32();
|
||||
int trackTableSize = trackTableEnd - 0x20;
|
||||
|
||||
Bytes trackTable(trackTableSize);
|
||||
inputFile.seekg(0x20);
|
||||
inputFile.read((char*) trackTable.begin(), trackTable.size());
|
||||
inputFile.read((char*)trackTable.begin(), trackTable.size());
|
||||
ByteReader trackTableReader(trackTable);
|
||||
|
||||
if (config.encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET)
|
||||
std::cout << "D88: overriding configured format\n";
|
||||
if (config.encoder().format_case() !=
|
||||
EncoderProto::FormatCase::FORMAT_NOT_SET)
|
||||
Logger() << "D88: overriding configured format";
|
||||
|
||||
auto ibm = config.mutable_encoder()->mutable_ibm();
|
||||
int physicalStep = 1;
|
||||
int clockRate = 500;
|
||||
if (mediaFlag == 0x20) {
|
||||
std::cout << "D88: high density mode\n";
|
||||
if (config.flux_sink().dest_case() == FluxSinkProto::DestCase::kDrive) {
|
||||
config.mutable_flux_sink()->mutable_drive()->set_high_density(true);
|
||||
if (mediaFlag == 0x20)
|
||||
{
|
||||
Logger() << "D88: high density mode";
|
||||
if (config.flux_sink().dest_case() ==
|
||||
FluxSinkProto::DestCase::kDrive)
|
||||
{
|
||||
config.mutable_flux_sink()->mutable_drive()->set_high_density(
|
||||
true);
|
||||
}
|
||||
} else {
|
||||
std::cout << "D88: single/double density mode\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger() << "D88: single/double density mode";
|
||||
physicalStep = 2;
|
||||
clockRate = 300;
|
||||
if (config.flux_sink().dest_case() == FluxSinkProto::DestCase::kDrive) {
|
||||
config.mutable_flux_sink()->mutable_drive()->set_high_density(false);
|
||||
if (config.flux_sink().dest_case() ==
|
||||
FluxSinkProto::DestCase::kDrive)
|
||||
{
|
||||
config.mutable_flux_sink()->mutable_drive()->set_high_density(
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +91,13 @@ public:
|
||||
for (int track = 0; track < trackTableSize / 4; track++)
|
||||
{
|
||||
int trackOffset = trackTableReader.seek(track * 4).read_le32();
|
||||
if (trackOffset == 0) continue;
|
||||
if (trackOffset == 0)
|
||||
continue;
|
||||
|
||||
int currentTrackOffset = trackOffset;
|
||||
int currentTrackCylinder = -1;
|
||||
int currentSectorsInTrack = 0xffff; // don't know # of sectors until we read the first one
|
||||
int currentSectorsInTrack =
|
||||
0xffff; // don't know # of sectors until we read the first one
|
||||
int trackSectorSize = -1;
|
||||
int trackMfm = -1;
|
||||
|
||||
@@ -94,9 +106,12 @@ public:
|
||||
trackdata->set_track_length_ms(167);
|
||||
auto sectors = trackdata->mutable_sectors();
|
||||
|
||||
for (int sectorInTrack = 0; sectorInTrack < currentSectorsInTrack; sectorInTrack++){
|
||||
for (int sectorInTrack = 0; sectorInTrack < currentSectorsInTrack;
|
||||
sectorInTrack++)
|
||||
{
|
||||
Bytes sectorHeader(0x10);
|
||||
inputFile.read((char*) sectorHeader.begin(), sectorHeader.size());
|
||||
inputFile.read(
|
||||
(char*)sectorHeader.begin(), sectorHeader.size());
|
||||
ByteReader sectorHeaderReader(sectorHeader);
|
||||
int cylinder = sectorHeaderReader.seek(0).read_8();
|
||||
int head = sectorHeaderReader.seek(1).read_8();
|
||||
@@ -107,50 +122,70 @@ public:
|
||||
int ddam = sectorHeaderReader.seek(7).read_8();
|
||||
int fddStatusCode = sectorHeaderReader.seek(8).read_8();
|
||||
int rpm = sectorHeaderReader.seek(13).read_8();
|
||||
// D88 provides much more sector information that is currently ignored
|
||||
// D88 provides much more sector information that is currently
|
||||
// ignored
|
||||
if (ddam != 0)
|
||||
Error() << "D88: nonzero ddam currently unsupported";
|
||||
if (rpm != 0)
|
||||
Error() << "D88: 1.44MB 300rpm formats currently unsupported";
|
||||
Error()
|
||||
<< "D88: 1.44MB 300rpm formats currently unsupported";
|
||||
if (fddStatusCode != 0)
|
||||
Error() << "D88: nonzero fdd status codes are currently unsupported";
|
||||
if (currentSectorsInTrack == 0xffff) {
|
||||
Error() << "D88: nonzero fdd status codes are currently "
|
||||
"unsupported";
|
||||
if (currentSectorsInTrack == 0xffff)
|
||||
{
|
||||
currentSectorsInTrack = sectorsInTrack;
|
||||
} else if (currentSectorsInTrack != sectorsInTrack) {
|
||||
}
|
||||
else if (currentSectorsInTrack != sectorsInTrack)
|
||||
{
|
||||
Error() << "D88: mismatched number of sectors in track";
|
||||
}
|
||||
if (currentTrackCylinder < 0) {
|
||||
if (currentTrackCylinder < 0)
|
||||
{
|
||||
currentTrackCylinder = cylinder;
|
||||
} else if (currentTrackCylinder != cylinder) {
|
||||
Error() << "D88: all sectors in a track must belong to the same cylinder";
|
||||
}
|
||||
if (trackSectorSize < 0) {
|
||||
else if (currentTrackCylinder != cylinder)
|
||||
{
|
||||
Error() << "D88: all sectors in a track must belong to the "
|
||||
"same cylinder";
|
||||
}
|
||||
if (trackSectorSize < 0)
|
||||
{
|
||||
trackSectorSize = sectorSize;
|
||||
// this is the first sector we've read, use it settings for per-track data
|
||||
// this is the first sector we've read, use it settings for
|
||||
// per-track data
|
||||
trackdata->set_cylinder(cylinder * physicalStep);
|
||||
trackdata->set_head(head);
|
||||
trackdata->set_sector_size(sectorSize);
|
||||
trackdata->set_use_fm(fm);
|
||||
if (fm) {
|
||||
if (fm)
|
||||
{
|
||||
trackdata->set_gap_fill_byte(0xffff);
|
||||
trackdata->set_idam_byte(0xf57e);
|
||||
trackdata->set_dam_byte(0xf56f);
|
||||
}
|
||||
// create timings to approximately match N88-BASIC
|
||||
if (sectorSize <= 128) {
|
||||
if (sectorSize <= 128)
|
||||
{
|
||||
trackdata->set_gap0(0x1b);
|
||||
trackdata->set_gap2(0x09);
|
||||
trackdata->set_gap3(0x1b);
|
||||
} else if (sectorSize <= 256) {
|
||||
}
|
||||
else if (sectorSize <= 256)
|
||||
{
|
||||
trackdata->set_gap0(0x36);
|
||||
trackdata->set_gap3(0x36);
|
||||
}
|
||||
} else if (trackSectorSize != sectorSize) {
|
||||
Error() << "D88: multiple sector sizes per track are currently unsupported";
|
||||
}
|
||||
else if (trackSectorSize != sectorSize)
|
||||
{
|
||||
Error() << "D88: multiple sector sizes per track are "
|
||||
"currently unsupported";
|
||||
}
|
||||
Bytes data(sectorSize);
|
||||
inputFile.read((char*) data.begin(), data.size());
|
||||
const auto& sector = image->put(cylinder * physicalStep, head, sectorId);
|
||||
inputFile.read((char*)data.begin(), data.size());
|
||||
const auto& sector =
|
||||
image->put(cylinder * physicalStep, head, sectorId);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = cylinder;
|
||||
sector->physicalCylinder = cylinder * physicalStep;
|
||||
@@ -161,7 +196,8 @@ public:
|
||||
sectors->add_sector(sectorId);
|
||||
}
|
||||
|
||||
if (physicalStep == 2) {
|
||||
if (physicalStep == 2)
|
||||
{
|
||||
auto trackdata = ibm->add_trackdata();
|
||||
trackdata->set_clock_rate_khz(clockRate);
|
||||
trackdata->set_track_length_ms(167);
|
||||
@@ -170,31 +206,30 @@ public:
|
||||
|
||||
image->calculateSize();
|
||||
const Geometry& geometry = image->getGeometry();
|
||||
std::cout << fmt::format("D88: read {} tracks, {} sides\n",
|
||||
geometry.numTracks, geometry.numSides);
|
||||
Logger() << fmt::format("D88: read {} tracks, {} sides",
|
||||
geometry.numTracks,
|
||||
geometry.numSides);
|
||||
|
||||
if (!config.has_heads())
|
||||
{
|
||||
auto* heads = config.mutable_heads();
|
||||
heads->set_start(0);
|
||||
heads->set_end(geometry.numSides - 1);
|
||||
}
|
||||
if (!config.has_heads())
|
||||
{
|
||||
auto* heads = config.mutable_heads();
|
||||
heads->set_start(0);
|
||||
heads->set_end(geometry.numSides - 1);
|
||||
}
|
||||
|
||||
if (!config.has_cylinders())
|
||||
{
|
||||
auto* cylinders = config.mutable_cylinders();
|
||||
cylinders->set_start(0);
|
||||
cylinders->set_end(geometry.numTracks - 1);
|
||||
}
|
||||
if (!config.has_cylinders())
|
||||
{
|
||||
auto* cylinders = config.mutable_cylinders();
|
||||
cylinders->set_start(0);
|
||||
cylinders->set_end(geometry.numTracks - 1);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
std::unique_ptr<ImageReader> ImageReader::createD88ImageReader(
|
||||
const ImageReaderProto& config)
|
||||
const ImageReaderProto& config)
|
||||
{
|
||||
return std::unique_ptr<ImageReader>(new D88ImageReader(config));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user