| 1 |
#include "dmk-common.hh" |
| 2 |
|
| 3 |
#include <array> |
| 4 |
#include <cstdint> |
| 5 |
#include <cstdio> |
| 6 |
#include <cstring> |
| 7 |
#include <cstdlib> |
| 8 |
#include <span> |
| 9 |
|
| 10 |
static const int RAW_TRACK_SIZE = 6250; |
| 11 |
|
| 12 |
int main(int argc, const char** argv) |
| 13 |
{ |
| 14 |
std::span arg(argv, argc); |
| 15 |
if (arg.size() != 2) { |
| 16 |
printf("empty-dmk\n" |
| 17 |
"\n" |
| 18 |
"Utility to create an empty DMK disk image.\n" |
| 19 |
"The disk image is double sided and contains\n" |
| 20 |
"80 unformatted tracks.\n" |
| 21 |
"\n" |
| 22 |
"usage: %s <filename>\n", arg[0]); |
| 23 |
exit(1); |
| 24 |
} |
| 25 |
|
| 26 |
FILE_t f(fopen(arg[1], "wb")); |
| 27 |
if (!f) { |
| 28 |
printf("Error opening file '%s' for writing.\n", arg[1]); |
| 29 |
exit(1); |
| 30 |
} |
| 31 |
|
| 32 |
DmkHeader header; |
| 33 |
memset(&header, 0, sizeof(header)); |
| 34 |
header.numTracks = 80; |
| 35 |
header.trackLen[0] = (128 + RAW_TRACK_SIZE) & 255; |
| 36 |
header.trackLen[1] = (128 + RAW_TRACK_SIZE) >> 8; |
| 37 |
fwrite(&header, sizeof(header), 1, f.get()); |
| 38 |
|
| 39 |
std::array<uint8_t, 128 + RAW_TRACK_SIZE> buf; |
| 40 |
memset(&buf[ 0], 0, 128); |
| 41 |
memset(&buf[128], 0x4e, RAW_TRACK_SIZE); |
| 42 |
for (int i = 0; i < 2 * 80; ++i) { |
| 43 |
fwrite(buf.data(), buf.size(), 1, f.get()); |
| 44 |
} |
| 45 |
} |