empty-dmk.cc 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. typedef unsigned char byte;
  5. struct DmkHeader {
  6. byte writeProtected;
  7. byte numTracks;
  8. byte trackLen[2];
  9. byte flags;
  10. byte reserved[7];
  11. byte format[4];
  12. };
  13. static const int RAW_TRACK_SIZE = 6250; // 250kbps, 300rpm
  14. int main(int argc, char** argv)
  15. {
  16. if (argc != 2) {
  17. printf("empty-dmk\n"
  18. "\n"
  19. "Utility to create an empty DMK disk image.\n"
  20. "The disk image is double sided and contains\n"
  21. "80 unformatted tracks.\n"
  22. "\n"
  23. "usage: %s <filename>\n", argv[0]);
  24. exit(1);
  25. }
  26. FILE* f = fopen(argv[1], "wb");
  27. DmkHeader header;
  28. memset(&header, 0, sizeof(header));
  29. header.numTracks = 80;
  30. header.trackLen[0] = (128 + RAW_TRACK_SIZE) & 255;
  31. header.trackLen[1] = (128 + RAW_TRACK_SIZE) >> 8;
  32. fwrite(&header, sizeof(header), 1, f);
  33. byte buf[128 + RAW_TRACK_SIZE];
  34. memset(&buf[ 0], 0, 128);
  35. memset(&buf[128], 0x4e, RAW_TRACK_SIZE);
  36. for (int i = 0; i < 2 * 80; ++i) {
  37. fwrite(buf, sizeof(buf), 1, f);
  38. }
  39. fclose(f);
  40. }