home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
messroms.de
/
2007-01-13_www.messroms.de.zip
/
PCMDA
/
TOOLS
/
MKHDIMG.ZIP
/
mkhdimg.c
next >
Wrap
C/C++ Source or Header
|
1998-12-21
|
2KB
|
78 lines
#include <stdio.h>
#define CYLINDERS 615
#define HEADS 4
#define SECTORS 17
#define MAGIC 0xaa55
#define ECC 11
#define CONTROL 5
#define DIPSWITCH 0xff
#define SECLEN 512
int main(int ac, char **av)
{
FILE *img;
unsigned char buffer[SECLEN];
int c, h, s;
if (ac < 2) {
fprintf(stderr, "usage: mkhdimage filename.img\n");
fprintf(stderr, "used to create an empty hard disk image for use with\n");
fprintf(stderr, "MESS' PC-XT emulation. The image size will be 21MB!\n");
fprintf(stderr, "%d cylinders, %d heads with %d * %d byte sectors.\n", CYLINDERS, HEADS, SECTORS, SECLEN);
return 1;
}
img = fopen(av[1], "wb");
memset(buffer, 0, 512);
/* fill in the drive geometry information */
#if 0 /* this doesn't work to well, so just leave it empty for now */
buffer[0x1ad] = CYLINDERS & 0xff; /* cylinders */
buffer[0x1ae] = (CYLINDERS >> 8) & 3;
buffer[0x1af] = HEADS; /* heads */
buffer[0x1b0] = (CYLINDERS+1) & 0xff; /* write precompensation */
buffer[0x1b1] = ((CYLINDERS+1) >> 8) & 3;
buffer[0x1b2] = (CYLINDERS+1) & 0xff; /* reduced write current */
buffer[0x1b3] = ((CYLINDERS+1) >> 8) & 3;
buffer[0x1b4] = ECC; /* ECC length */
buffer[0x1b5] = CONTROL; /* control (step rate) */
buffer[0x1b6] = CYLINDERS & 0xff; /* parking cylinder */
buffer[0x1b7] = (CYLINDERS >> 8) & 3;
buffer[0x1b8] = 0x00; /* no idea */
buffer[0x1b9] = 0x00;
buffer[0x1ba] = 0x00;
buffer[0x1bb] = 0x00;
buffer[0x1bc] = 0x00;
buffer[0x1bd] = SECTORS; /* some non zero value */
buffer[0x1fe] = MAGIC & 0xff;
buffer[0x1ff] = (MAGIC >> 8) & 0xff;
#endif
if (fwrite(buffer, 1, SECLEN, img) != SECLEN) {
fprintf(stderr, "failed to write MBR of %s\n", av[1]);
return 1;
}
/* write F6 patterns throughout the image */
memset(buffer, 0xf6, sizeof(buffer));
for (c = 0; c < CYLINDERS; c++) {
for (h = 0; h < HEADS; h++) {
printf("\rwriting cylinder %4d, head %2d", c, h);
fflush(stdout);
for (s = 0; s < SECTORS; s++) {
if (fwrite(buffer, 1, SECLEN, img) != SECLEN) {
fprintf(stderr, "failed to write C%d, H%d, S%d of %s\n", c, h, s, av[1]);
return 1;
}
}
}
}
fclose(img);
return 0;
}