-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from davidgiven/d64
Add write-only support for D64 disk images.
- Loading branch information
Showing
7 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "globals.h" | ||
#include "image.h" | ||
#include "flags.h" | ||
#include "dataspec.h" | ||
#include "sector.h" | ||
#include "sectorset.h" | ||
#include "imagewriter/imagewriter.h" | ||
#include "fmt/format.h" | ||
#include "ldbs.h" | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
static int sectors_per_track(int track) | ||
{ | ||
if (track < 17) | ||
return 21; | ||
if (track < 24) | ||
return 19; | ||
if (track < 30) | ||
return 18; | ||
return 17; | ||
} | ||
|
||
class D64ImageWriter : public ImageWriter | ||
{ | ||
public: | ||
D64ImageWriter(const SectorSet& sectors, const ImageSpec& spec): | ||
ImageWriter(sectors, spec) | ||
{} | ||
|
||
void writeImage() | ||
{ | ||
std::cout << "writing D64 triangular image\n"; | ||
|
||
std::ofstream outputFile(spec.filename, std::ios::out | std::ios::binary); | ||
if (!outputFile.is_open()) | ||
Error() << "cannot open output file"; | ||
|
||
uint32_t offset = 0; | ||
for (int track = 0; track < 40; track++) | ||
{ | ||
int sectorCount = sectors_per_track(track); | ||
for (int sectorId = 0; sectorId < sectorCount; sectorId++) | ||
{ | ||
const auto& sector = sectors.get(track, 0, sectorId); | ||
if (sector) | ||
{ | ||
outputFile.seekp(offset); | ||
outputFile.write((const char*) sector->data.cbegin(), 256); | ||
} | ||
|
||
offset += 256; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
std::unique_ptr<ImageWriter> ImageWriter::createD64ImageWriter( | ||
const SectorSet& sectors, const ImageSpec& spec) | ||
{ | ||
return std::unique_ptr<ImageWriter>(new D64ImageWriter(sectors, spec)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters