mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Add a DiskCopy 4.2 image reader. We can now write files to floppy, and they
almost work.
This commit is contained in:
@@ -55,11 +55,25 @@ You should end up with a `mac.diskcopy` file which is compatible with DiskCopy
|
||||
different sizes and the odd sector size. If you use a normal `.img` file, then
|
||||
FluxEngine will store them in a simple 524 x 12 x 2 x 80 layout, with holes
|
||||
where missing sectors should be; this was easiest, but is unlikely to work with
|
||||
most Mac emulators and other software. In these files, the The 12 bytes of
|
||||
most Mac emulators and other software. In these files, the 12 bytes of
|
||||
metadata _follow_ the 512 bytes of user payload in the sector image. If you
|
||||
don't want it, specify a geometry in the output file with a 512-byte sectore
|
||||
size like `-o mac.img:c=80:h=1:s=12:b=512`.
|
||||
|
||||
Writing discs
|
||||
-------------
|
||||
|
||||
Just do:
|
||||
|
||||
```
|
||||
fluxengine write mac -i mac.diskcopy
|
||||
```
|
||||
|
||||
It'll read the DiskCopy 4.2 file and write it out.
|
||||
|
||||
The same warning as above applies --- you can use normal `.img` files but it's
|
||||
problematic. Use DiskCopy 4.2 files instead.
|
||||
|
||||
Useful references
|
||||
-----------------
|
||||
|
||||
|
||||
128
lib/imagereader/diskcopyimagereader.cc
Normal file
128
lib/imagereader/diskcopyimagereader.cc
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "globals.h"
|
||||
#include "flags.h"
|
||||
#include "dataspec.h"
|
||||
#include "sector.h"
|
||||
#include "sectorset.h"
|
||||
#include "imagereader/imagereader.h"
|
||||
#include "fmt/format.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
class DiskCopyImageReader : public ImageReader
|
||||
{
|
||||
public:
|
||||
DiskCopyImageReader(const ImageSpec& spec):
|
||||
ImageReader(spec)
|
||||
{}
|
||||
|
||||
SectorSet readImage()
|
||||
{
|
||||
std::ifstream inputFile(spec.filename, std::ios::in | std::ios::binary);
|
||||
if (!inputFile.is_open())
|
||||
Error() << "cannot open input file";
|
||||
|
||||
Bytes data;
|
||||
data.writer() += inputFile;
|
||||
ByteReader br(data);
|
||||
|
||||
br.seek(1);
|
||||
std::string label = br.read(data[0]);
|
||||
|
||||
br.seek(0x40);
|
||||
uint32_t dataSize = br.read_be32();
|
||||
|
||||
br.seek(0x50);
|
||||
uint8_t encoding = br.read_8();
|
||||
uint8_t formatByte = br.read_8();
|
||||
|
||||
unsigned numCylinders = 80;
|
||||
unsigned numHeads = 2;
|
||||
unsigned numSectors = 0;
|
||||
bool mfm = false;
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case 0: /* GCR CLV 400kB */
|
||||
numHeads = 1;
|
||||
break;
|
||||
|
||||
case 1: /* GCR CLV 800kB */
|
||||
break;
|
||||
|
||||
case 2: /* MFM CAV 720kB */
|
||||
numSectors = 9;
|
||||
mfm = true;
|
||||
break;
|
||||
|
||||
case 3: /* MFM CAV 1440kB */
|
||||
numSectors = 18;
|
||||
mfm = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
Error() << fmt::format("don't understant DiskCopy disks of type {}", encoding);
|
||||
}
|
||||
|
||||
std::cout << "reading DiskCopy 4.2 image\n"
|
||||
<< fmt::format("{} cylinders, {} heads; {}; {}\n",
|
||||
numCylinders, numHeads,
|
||||
mfm ? "MFM" : "GCR",
|
||||
label);
|
||||
|
||||
auto sectorsPerTrack = [&](int track) -> int
|
||||
{
|
||||
if (mfm)
|
||||
return numSectors;
|
||||
|
||||
if (track < 16)
|
||||
return 12;
|
||||
if (track < 32)
|
||||
return 11;
|
||||
if (track < 48)
|
||||
return 10;
|
||||
if (track < 64)
|
||||
return 9;
|
||||
return 8;
|
||||
};
|
||||
|
||||
uint32_t dataPtr = 0x54;
|
||||
uint32_t tagPtr = dataPtr + dataSize;
|
||||
|
||||
SectorSet sectors;
|
||||
for (int track = 0; track < numCylinders; track++)
|
||||
{
|
||||
int numSectors = sectorsPerTrack(track);
|
||||
for (int head = 0; head < numHeads; head++)
|
||||
{
|
||||
for (int sectorId = 0; sectorId < numSectors; sectorId++)
|
||||
{
|
||||
br.seek(dataPtr);
|
||||
Bytes payload = br.read(512);
|
||||
dataPtr += 512;
|
||||
|
||||
br.seek(tagPtr);
|
||||
Bytes tag = br.read(12);
|
||||
tagPtr += 12;
|
||||
|
||||
std::unique_ptr<Sector>& sector = sectors.get(track, head, sectorId);
|
||||
sector.reset(new Sector);
|
||||
sector->status = Sector::OK;
|
||||
sector->logicalTrack = sector->physicalTrack = track;
|
||||
sector->logicalSide = sector->physicalSide = head;
|
||||
sector->logicalSector = sectorId;
|
||||
sector->data.writer().append(payload).append(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sectors;
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<ImageReader> ImageReader::createDiskCopyImageReader(
|
||||
const ImageSpec& spec)
|
||||
{
|
||||
return std::unique_ptr<ImageReader>(new DiskCopyImageReader(spec));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ std::map<std::string, ImageReader::Constructor> ImageReader::formats =
|
||||
{
|
||||
{".adf", ImageReader::createImgImageReader},
|
||||
{".d81", ImageReader::createImgImageReader},
|
||||
{".diskcopy", ImageReader::createDiskCopyImageReader},
|
||||
{".img", ImageReader::createImgImageReader},
|
||||
{".ima", ImageReader::createImgImageReader},
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ private:
|
||||
|
||||
static std::map<std::string, Constructor> formats;
|
||||
|
||||
static std::unique_ptr<ImageReader> createDiskCopyImageReader(const ImageSpec& spec);
|
||||
static std::unique_ptr<ImageReader> createImgImageReader(const ImageSpec& spec);
|
||||
|
||||
static Constructor findConstructor(const ImageSpec& spec);
|
||||
|
||||
@@ -47,7 +47,6 @@ public:
|
||||
else
|
||||
Error() << "this image is not compatible with the DiskCopy 4.2 format";
|
||||
|
||||
|
||||
std::cout << "writing DiskCopy 4.2 image\n"
|
||||
<< fmt::format("{} tracks, {} heads, {} sectors, {} bytes per sector; {}\n",
|
||||
spec.cylinders, spec.heads, spec.sectors, spec.bytes,
|
||||
|
||||
@@ -151,6 +151,7 @@ buildlibrary libfmt.a \
|
||||
dep/fmt/posix.cc \
|
||||
|
||||
buildlibrary libbackend.a \
|
||||
lib/imagereader/diskcopyimagereader.cc \
|
||||
lib/imagereader/imagereader.cc \
|
||||
lib/imagereader/imgimagereader.cc \
|
||||
lib/imagewriter/d64imagewriter.cc \
|
||||
|
||||
Reference in New Issue
Block a user