home *** CD-ROM | disk | FTP | other *** search
/ messroms.de / 2007-01-13_www.messroms.de.zip / PCCGA / TOOLS / MKHDIMG.ZIP / mkhdimg.c next >
C/C++ Source or Header  |  1998-12-21  |  2KB  |  78 lines

  1. #include <stdio.h>
  2.  
  3. #define CYLINDERS    615
  4. #define HEADS        4
  5. #define SECTORS     17
  6. #define MAGIC        0xaa55
  7. #define ECC         11
  8. #define CONTROL     5
  9. #define DIPSWITCH    0xff
  10.  
  11. #define SECLEN        512
  12.  
  13.  
  14. int main(int ac, char **av)
  15. {
  16. FILE *img;
  17. unsigned char buffer[SECLEN];
  18. int c, h, s;
  19.     if (ac < 2) {
  20.         fprintf(stderr, "usage: mkhdimage filename.img\n");
  21.         fprintf(stderr, "used to create an empty hard disk image for use with\n");
  22.         fprintf(stderr, "MESS' PC-XT emulation. The image size will be 21MB!\n");
  23.         fprintf(stderr, "%d cylinders, %d heads with %d * %d byte sectors.\n", CYLINDERS, HEADS, SECTORS, SECLEN);
  24.         return 1;
  25.     }
  26.     img = fopen(av[1], "wb");
  27.  
  28.     memset(buffer, 0, 512);
  29.  
  30.     /* fill in the drive geometry information */
  31. #if 0    /* this doesn't work to well, so just leave it empty for now */
  32.     buffer[0x1ad] = CYLINDERS & 0xff;           /* cylinders */
  33.     buffer[0x1ae] = (CYLINDERS >> 8) & 3;
  34.     buffer[0x1af] = HEADS;                        /* heads */
  35.     buffer[0x1b0] = (CYLINDERS+1) & 0xff;        /* write precompensation */
  36.     buffer[0x1b1] = ((CYLINDERS+1) >> 8) & 3;
  37.     buffer[0x1b2] = (CYLINDERS+1) & 0xff;        /* reduced write current */
  38.     buffer[0x1b3] = ((CYLINDERS+1) >> 8) & 3;
  39.     buffer[0x1b4] = ECC;                        /* ECC length */
  40.     buffer[0x1b5] = CONTROL;                    /* control (step rate) */
  41.     buffer[0x1b6] = CYLINDERS & 0xff;            /* parking cylinder */
  42.     buffer[0x1b7] = (CYLINDERS >> 8) & 3;
  43.     buffer[0x1b8] = 0x00;                        /* no idea */
  44.     buffer[0x1b9] = 0x00;
  45.     buffer[0x1ba] = 0x00;
  46.     buffer[0x1bb] = 0x00;
  47.     buffer[0x1bc] = 0x00;
  48.     buffer[0x1bd] = SECTORS;                    /* some non zero value */
  49.     buffer[0x1fe] = MAGIC & 0xff;
  50.     buffer[0x1ff] = (MAGIC >> 8) & 0xff;
  51. #endif
  52.  
  53.     if (fwrite(buffer, 1, SECLEN, img) != SECLEN) {
  54.         fprintf(stderr, "failed to write MBR of %s\n", av[1]);
  55.         return 1;
  56.     }
  57.  
  58.     /* write F6 patterns throughout the image */
  59.     memset(buffer, 0xf6, sizeof(buffer));
  60.  
  61.     for (c = 0; c < CYLINDERS; c++) {
  62.         for (h = 0; h < HEADS; h++) {
  63.             printf("\rwriting cylinder %4d, head %2d", c, h);
  64.             fflush(stdout);
  65.             for (s = 0; s < SECTORS; s++) {
  66.                 if (fwrite(buffer, 1, SECLEN, img) != SECLEN) {
  67.                     fprintf(stderr, "failed to write C%d, H%d, S%d of %s\n", c, h, s, av[1]);
  68.                     return 1;
  69.                 }
  70.             }
  71.         }
  72.     }
  73.  
  74.     fclose(img);
  75.  
  76.     return 0;
  77. }
  78.