Micropolis raw 275 byte sectors

These are used by formats like VGI since the ECC varied per machine and
the 10 extra bytes of user data may contain useful information.
This commit is contained in:
Eric Anderson
2021-10-02 22:59:14 -07:00
parent a00137d742
commit ce5fcaf172
5 changed files with 82 additions and 3 deletions

View File

@@ -6,6 +6,7 @@
#include "micropolis.h"
#include "bytes.h"
#include "fmt/format.h"
#include "lib/decoders/decoders.pb.h"
/* The sector has a preamble of MFM 0x00s and uses 0xFF as a sync pattern. */
static const FluxPattern SECTOR_SYNC_PATTERN(32, 0xaaaa5555);
@@ -28,7 +29,8 @@ class MicropolisDecoder : public AbstractDecoder
{
public:
MicropolisDecoder(const DecoderProto& config):
AbstractDecoder(config)
AbstractDecoder(config),
_config(config.micropolis())
{}
RecordType advanceToNextRecord()
@@ -59,13 +61,21 @@ public:
return;
br.read(10); /* OS data or padding */
_sector->data = br.read(256);
auto data = br.read(256);
uint8_t wantChecksum = br.read_8();
uint8_t gotChecksum = micropolisChecksum(bytes.slice(1, 2+266));
br.read(5); /* 4 byte ECC and ECC-present flag */
if (_config.sector_output_size() == 256)
_sector->data = data;
else if (_config.sector_output_size() == MICROPOLIS_ENCODED_SECTOR_SIZE)
_sector->data = bytes;
else
Error() << "Sector output size may only be 256 or 275";
_sector->status = (wantChecksum == gotChecksum) ? Sector::OK : Sector::BAD_CHECKSUM;
}
private:
const MicropolisDecoderProto& _config;
};
std::unique_ptr<AbstractDecoder> createMicropolisDecoder(const DecoderProto& config)

View File

@@ -19,7 +19,15 @@ static void write_sector(std::vector<bool>& bits, unsigned& cursor, const std::s
fullSector->push_back(0);
Bytes sectorData;
if (sector->data.size() == MICROPOLIS_ENCODED_SECTOR_SIZE)
{
if (sector->data[0] != 0xFF)
Error() << "275 byte sector doesn't start with sync byte 0xFF. Corrupted sector";
uint8_t wantChecksum = sector->data[1+2+266];
uint8_t gotChecksum = micropolisChecksum(sector->data.slice(1, 2+266));
if (wantChecksum != gotChecksum)
std::cerr << "Warning: checksum incorrect. Sector: " << sector->logicalSector << std::endl;
sectorData = sector->data;
}
else
{
ByteWriter writer(sectorData);

View File

@@ -1,5 +1,11 @@
syntax = "proto2";
message MicropolisDecoderProto {}
import "lib/common.proto";
message MicropolisDecoderProto {
optional int32 sector_output_size = 1 [default = 256,
(help) = "How much of the raw sector should be saved. Must be 256 or 275"];
}
message MicropolisEncoderProto {}

View File

@@ -422,6 +422,7 @@ FORMATS="\
mac400 \
mac800 \
micropolis \
micropolis275 \
mx \
northstar175 \
northstar350 \

View File

@@ -0,0 +1,54 @@
comment: 'Micropolis MetaFloppy 630kB 5.25" DSDD hard-sectored'
flux_source {
drive {
hard_sector_count: 16
}
}
flux_sink {
drive {
hard_sector_count: 16
}
}
image_reader {
filename: "micropolis.img"
img {
tracks: 77
sides: 2
trackdata {
sector_size: 275
sector_range {
start_sector: 0
sector_count: 16
}
}
}
}
image_writer {
filename: "micropolis.img"
img {}
}
encoder {
micropolis {}
}
decoder {
micropolis {
sector_output_size: 275
}
}
cylinders {
start: 0
end: 76
}
heads {
start: 0
end: 1
}