summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-08-06 05:02:14 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-08-06 05:03:24 (GMT)
commit280ff1cfa46da808d6b9f4c5994117e12b968cc6 (patch)
treef6d948b4c35d3e1e211d20a618a8e4182b4bc90f
parent500f67e5c3bdb9d0e8ebbe0b073a399da6d18a08 (diff)
downloadabcdisk-280ff1cfa46da808d6b9f4c5994117e12b968cc6.zip
abcdisk-280ff1cfa46da808d6b9f4c5994117e12b968cc6.tar.gz
abcdisk-280ff1cfa46da808d6b9f4c5994117e12b968cc6.tar.bz2
abcdisk-280ff1cfa46da808d6b9f4c5994117e12b968cc6.tar.xz
deinter: program to deinterleave raw floppy images
At least ABC830 disk images end up interleaved when read on a Linux system, so have a program to unscramble them.
-rw-r--r--Makefile9
-rw-r--r--deinter.c45
2 files changed, 52 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 3cfd225..807858e 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,9 @@ O = o
X =
endif
-all : abcwrite$(X) abcread$(X)
+PROGS = abcwrite$(X) abcread$(X) deinter$(X)
+
+all : $(PROGS)
.c.$(O):
$(CC) $(CFLAGS) -c -o $@ $<
@@ -20,5 +22,8 @@ abcwrite$(X): abcwrite.$(O) util.$(O) formats.$(O)
abcread$(X): abcread.$(O) util.$(O) formats.$(O)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+deinter$(X): deinter.$(O)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
clean:
- rm -f abcwrite$(X) abcread$(X) *.$(O) *~
+ rm -f $(PROGS) *.$(O) *~
diff --git a/deinter.c b/deinter.c
new file mode 100644
index 0000000..d3d62d6
--- /dev/null
+++ b/deinter.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/*
+ * deinter.c
+ *
+ * Undo software interleaving
+ */
+
+int main(int argc, char *argv[])
+{
+ int sectsize;
+ int ileave;
+ int ilsize;
+ FILE *f;
+ char *buf;
+ int i, j;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s file [ileave [ilsize [sector]]]\n", argv[0]);
+ exit(1);
+ }
+
+ f = fopen(argv[1], "rb");
+ if (!f) {
+ perror(argv[1]);
+ exit(1);
+ }
+
+ ileave = (argc > 2) ? atoi(argv[2]) : 7;
+ ilsize = (argc > 3) ? atoi(argv[3]) : 16;
+ sectsize = (argc > 4) ? atoi(argv[4]) : 256;
+
+ buf = malloc(sectsize * ilsize);
+
+ while (fread(buf, 1, sectsize * ilsize, f))
+ for (i = 0, j = 0; i < ilsize; i++, j = (j + ileave) % ilsize)
+ fwrite(buf + j*sectsize, 1, sectsize, stdout);
+
+ fclose(f);
+
+ return 0;
+}