summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-19 21:05:35 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-19 21:09:11 (GMT)
commit957e625e0fa39a6bc1bec30d22aeffacd33a0f22 (patch)
tree07ac372c8351be822c8d458220589488b0606c74
parent9e46fe5e6d90cad53889e2c92a6ee8811508f670 (diff)
downloadabcdisk-957e625e0fa39a6bc1bec30d22aeffacd33a0f22.zip
abcdisk-957e625e0fa39a6bc1bec30d22aeffacd33a0f22.tar.gz
abcdisk-957e625e0fa39a6bc1bec30d22aeffacd33a0f22.tar.bz2
abcdisk-957e625e0fa39a6bc1bec30d22aeffacd33a0f22.tar.xz
Try to better match observed disk formats...
- Only the first MFD sector has a zero entry, at least under UFD-DOS - ABC830 apparently had its system sectors at 6 even on UFD-DOS, but the MFD could be at 8 or 16 - If the MFD is at 8 then 16 contains a backup - Last byte in the lockout sector (and maybe the bitmap sector?) contains log2(sector size)
-rw-r--r--abcwrite.c7
-rw-r--r--formats.c38
-rw-r--r--util.c21
-rw-r--r--util.h1
4 files changed, 40 insertions, 27 deletions
diff --git a/abcwrite.c b/abcwrite.c
index 98e5b60..3108799 100644
--- a/abcwrite.c
+++ b/abcwrite.c
@@ -409,6 +409,13 @@ int main(int argc, char *argv[])
/* Install files */
get_files(&disk->mfd, argv[2]);
+ /* Create backup MFD if it exists */
+ if (fmt->dirsec[1]) {
+ memcpy(disk->image + (fmt->dirsec[1] << 8),
+ disk->image + (fmt->dirsec[0] << 8),
+ fmt->dirsecs << 8);
+ }
+
/* Finally, write out image */
f = !strcmp(argv[3], "-") ? stdout : fopen(argv[3], "wb");
if (!f) {
diff --git a/formats.c b/formats.c
index d5aa241..af1e9eb 100644
--- a/formats.c
+++ b/formats.c
@@ -7,25 +7,28 @@
static const struct diskfmt formats[] =
{
- { "fd2", F( 40,1, 8), 0, 6, 8 },
- { "dd80", F( 40,1, 8), 0, 6, 8 },
- { "fd2d", F( 40,1,16), 0, 6, 8 },
- { "dd82", F( 40,1,16), 0, 6, 8 },
- { "abc830", F( 40,1,16), 0, 6, 8 },
- { "abc830-ufd", F( 40,1,16), 0, 14, 16 },
- { "abc832", F( 80,2,16), 2, 14, 16 },
- { "abc832", F( 80,2,16), 2, 14, 16 },
- { "abc834", F( 80,2,16), 2, 14, 16 },
- { "abc838", F( 77,2,26), 2, 14, 16 },
- { "hd", F(238,8,32), 5, 14, 16 },
- { NULL, F(0,0,0), 0, 0, 0 }
+ { "fd2", F( 40,1, 8), 0, 6, { 8, 16 }, 8 },
+ { "dd80", F( 40,1, 8), 0, 6, { 8, 16 }, 8 },
+ { "fd2d", F( 40,1,16), 0, 6, { 8, 16 }, 8 },
+ { "dd82", F( 40,1,16), 0, 6, { 8, 16 }, 8 },
+ { "abc830", F( 40,1,16), 0, 6, { 8, 16 }, 8 },
+ { "abc830-ufd", F( 40,1,16), 0, 6, { 16, 0 }, 16 },
+ { "abc832", F( 80,2,16), 2, 14, { 16, 0 }, 16 },
+ { "abc832", F( 80,2,16), 2, 14, { 16, 0 }, 16 },
+ { "abc834", F( 80,2,16), 2, 14, { 16, 0 }, 16 },
+ /* XXX: right? I have seen a claim one track "disappears"... */
+ { "abc838", F( 77,2,26), 2, 14, { 16, 0 }, 16 },
+ { "hd", F(238,8,32), 5, 14, { 16, 0 }, 16 },
};
+static const int nformats = (sizeof(formats)/sizeof(formats[0]));
+
const struct diskfmt *get_format(const char *name)
{
const struct diskfmt *fmt;
+ int i;
- for (fmt = formats; fmt->name; fmt++) {
+ for (i = 0, fmt = formats; i < nformats; i++, fmt++) {
if (!strcmp(fmt->name, name))
return fmt;
}
@@ -36,15 +39,14 @@ const struct diskfmt *get_format(const char *name)
void show_formats(FILE *f)
{
const struct diskfmt *fmt;
+ int i;
fprintf(f, "Format Tracks Sides Sec/trk Cluster Sectors Total System\n");
- for (fmt = formats; fmt->name; fmt++) {
- fprintf(f, "%-13s %4d %6d %7d %9d %9d %6dK %5d\n",
+ for (i = 0, fmt = formats; i < nformats; i++, fmt++) {
+ fprintf(f, "%-13s %4d %6d %7d %9d %9d %6dK %2d/%2d\n",
fmt->name, fmt->c, fmt->h, fmt->s,
1 << fmt->cluster_shift,
- fmt->sectors, fmt->sectors >> 2, fmt->syssec);
+ fmt->sectors, fmt->sectors >> 2, fmt->syssec, fmt->dirsec[0]);
}
}
-
-
diff --git a/util.c b/util.c
index cc265b1..81fa181 100644
--- a/util.c
+++ b/util.c
@@ -23,6 +23,7 @@ struct disk *allocate_disk(const struct diskfmt *fmt)
size_t size = fmt->sectors << 8;
int i, starter;
int secperclust = 1 << fmt->cluster_shift;
+ unsigned char *p;
memset(disk, 0, sizeof *disk);
@@ -31,18 +32,22 @@ struct disk *allocate_disk(const struct diskfmt *fmt)
disk->bitmap = disk->image + (fmt->syssec << 8);
disk->mfd.disk = disk;
disk->mfd.bitmap = disk->bitmap;
- disk->mfd.dirsec = disk->bitmap + 2*256;
+ disk->mfd.dirsec = disk->image + (fmt->dirsec[0] << 8);
disk->mfd.block = 0; /* This is the MFD */
/* Post-formatting content? */
memset(disk->image, 0x40, size);
/* Create empty bitmap */
- memset(disk->bitmap, 0, 239);
+ memset(disk->bitmap, 0, 256);
for (i = fmt->sectors >> fmt->cluster_shift; i < 239*8; i++)
mark_used(disk, i); /* Mark nonexistent clusters busy */
- memset(disk->bitmap+239, 0x01, fmt->dirsecs); /* MFD bitmap */
- disk->bitmap[0xff] = 0x00;
+
+ /* 239..254 is the MFD bitmap */
+ disk->bitmap[239] = 0x01; /* Reserved entry */
+
+ /* This is claimed in a message found on ABC-klubben MSG */
+ disk->bitmap[0xff] = fmt->cluster_shift;
/* Mark the first 16/32 sectors used */
starter = (fmt->syssec + 2 + fmt->dirsecs + secperclust - 1)
@@ -54,11 +59,9 @@ struct disk *allocate_disk(const struct diskfmt *fmt)
memcpy(disk->bitmap + 256, disk->bitmap, 256);
/* Create MFD directory sectors */
- for (i = 0; i < fmt->dirsecs; i++) {
- unsigned char *p = disk->mfd.dirsec + ((i + fmt->syssec) << 8);
- memset(p, 0x00, 16);
- memset(p+16, 0xFF, 240);
- }
+ p = disk->mfd.dirsec + (fmt->dirsec[0] << 8);
+ memset(p, 0x00, 16); /* Reserved entry */
+ memset(p+16, 0xff, (fmt->dirsecs << 8) - 16);
return disk;
}
diff --git a/util.h b/util.h
index a8d2d95..65166f4 100644
--- a/util.h
+++ b/util.h
@@ -10,6 +10,7 @@ struct diskfmt {
int sectors; /* Total sectors (max 1911 clusters) */
unsigned int cluster_shift; /* Size of a cluster, log2 */
int syssec; /* First system sector (bitmap) */
+ int dirsec[2]; /* First directory sector (main, backup) */
int dirsecs; /* Number of directory sectors */
};