mtx512: Add tools for converting fuzix fs images into mfloppy disk format
authorAlan Cox <alan@linux.intel.com>
Sun, 14 Dec 2014 23:04:43 +0000 (23:04 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 14 Dec 2014 23:04:43 +0000 (23:04 +0000)
Standalone/Makefile
Standalone/raw2mfloppy.c [new file with mode: 0644]

index c94072f..51b375e 100644 (file)
@@ -1,6 +1,6 @@
 CC=gcc
 CCOPTS=-O2 -g -Wall -Wno-char-subscripts -Wno-deprecated-declarations
-TARGETS=mkfs fsck ucp
+TARGETS=mkfs fsck ucp raw2mfloppy
 UTILS=util.o devio.o xfs1.o xfs1a.o xfs1b.o xfs2.o
 
 all:   $(TARGETS)
@@ -17,5 +17,8 @@ fsck: fsck.o util.o
 ucp:   ucp.o $(UTILS)
        $(CC) $(CCOPTS) -o $@ $< $(UTILS)
 
+raw2mfloppy: raw2mfloppy.o
+       $(CC) $(CCOPTS) -o $@ $<
+
 %.o:   %.c
        $(CC) $(CCOPTS) -c -o $@ $<
diff --git a/Standalone/raw2mfloppy.c b/Standalone/raw2mfloppy.c
new file mode 100644 (file)
index 0000000..d0c31ad
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ *     Shuffle a disk into the right order
+ *
+ *     Converts the output of tools like ufs into an MTX512 mfloppy virtual
+ *     disk (or vice versa)
+ */
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+int main(int argc, char *argv[])
+{
+  char buf[8192];      /* 16 sectors */
+  int track;
+  int side;
+  int in, out;
+  
+  if (argc != 3) {
+    fprintf(stderr, "%s: in out\n", argv[0]);
+    exit(1);
+  }
+  
+  in = open(argv[1], O_RDONLY);
+  if (in == -1) {
+    perror(argv[1]);
+    exit(1);
+  }
+  out = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666);
+  if (out == -1) {
+    perror(argv[2]);
+    exit(1);
+  }
+
+  for (side = 0; side < 2; side++) {
+    for (track = 0; track < 40; track++) {
+      if (lseek(in, 16384 * track + 8192 * side, 0) == -1) {
+        perror(argv[1]);
+        exit(1);
+      }
+      if (read(in, buf, 8192) != 8192) {
+        perror(argv[1]);
+        exit(1);
+      }
+      if (write(out, buf, 8192) != 8192) {
+        perror(argv[2]);
+        exit(1);
+      }
+    }
+  }
+  close(in);
+  close(out);
+  exit(0);
+}