trs80: Add a tool to build the needed jv3 images
authorAlan Cox <alan@linux.intel.com>
Thu, 18 Dec 2014 00:49:53 +0000 (00:49 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 18 Dec 2014 00:49:53 +0000 (00:49 +0000)
Kernel/Makefile
Kernel/tools/makejv3.c [new file with mode: 0644]

index cd11993..a5fb69e 100644 (file)
@@ -1,6 +1,6 @@
 TARGET_LIST = platform-nc100 platform-micropack platform-pcw8256 platform-socz80 platform-zx128 platform-trs80 platform-z80pack platform-z80pack-lite platform-z80pack32 platform-dragon
 
-export TARGET= mtx
+export TARGET= trs80
 export CPU = z80
 #export TARGET = dragon
 #export CPU = 6809
@@ -154,6 +154,8 @@ tools/decbdragon: tools/decbdragon.c
 
 tools/bintomdv: tools/bintomdv.c
 
+tools/makejv3: tools/makejv3.c
+
 ifeq ($(CPU), z80)
 uzi.ihx: target $(OBJS) platform-$(TARGET)/uzi.lnk
        $(CROSS_LD) -n -k $(LIBZ80) -f platform-$(TARGET)/uzi.lnk
diff --git a/Kernel/tools/makejv3.c b/Kernel/tools/makejv3.c
new file mode 100644 (file)
index 0000000..7081c9d
--- /dev/null
@@ -0,0 +1,113 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+
+/* JV3 consists of a bunch of byte packed misaligned fields in an array,
+   followed by a writeprot byte and then the data, for 2901 sectors. If
+   it exceeds 2091 sectors then this repeats.
+   
+   One of the weirder disk formats emulation folk use */
+
+/* We should do skewing, but that makes writing the image fun, so for now
+   don't bother */
+
+#if 0
+static int skew[2][18] = {
+  {
+    0x06, 0x0C, 0x01, 0x07, 0x0D, 0x02, 0x08, 0x0E,
+    0x03, 0x09, 0x0F, 0x04, 0x0A, 0x10, 0x05, 0x0b,
+    0x11, 0x00
+  },
+  {
+    0x01, 0x05, 0x09, 0x02, 0x06, 0x0A, 0x03, 0x00, 0x07, 0x04
+  }
+};
+#endif
+
+static void jvc_writeheaders(int dd, int ntrack, int nside, int nsec, uint8_t *ptr)
+{
+  int i, j, k;
+  
+  /* Write the headers so the data is a straight copy in with dd to an
+     offset */
+  for (i = 0; i < ntrack; i++) {
+    for (j = 0; j < nside ; j ++) {
+      for (k = 1; k <= nsec ; k++) {
+        *ptr++=i;
+        *ptr++=k; /*skew[dd][k] + 1;*/
+        *ptr++= (0x80 * dd) | (0x10 * j);
+      }
+    }
+  }
+  /* Writeable */
+  *ptr = 1;
+}
+
+
+static void jvcwritesectors(int infd, int outfd,  int ntrack, int nside, int nsec)
+{
+  int i, j, k;
+  static char buf[256];
+  for (i = 0; i < ntrack; i++) {
+    for (j = 0; j < nside ; j ++) {
+      for (k = 1; k <= nsec ; k++) {
+        /* 0 itself is fine - we just blank the rest */
+        if (read(infd, buf, 256) < 0) {
+          perror("read sectors");
+          exit(1);
+        }
+        if (write(outfd, buf, 256) != 256) {
+          perror("write jvc3");
+          exit(1);
+        }
+      }
+    }
+  }
+}
+
+static char hdrbuf[8704];
+
+void main(int argc, char *argv[])
+{
+  int infd, outfd;
+  int nside = 2, dd = 1;
+  if (argc != 4) {
+    fprintf(stderr, "%s [type] [rawfs] [jv3file]\n", argv[0]);
+    exit(1);
+  }
+  if (strcmp(argv[1], "dd40") == 0)
+    ;
+  else if (strcmp(argv[1], "dd40s") == 0)
+    nside = 1;
+  else if (strcmp(argv[1], "sd40") == 0)
+    dd = 0;
+  else if (strcmp(argv[1], "sd80") == 0) {
+    dd = 0;
+    nside = 1;
+  } else {
+    fprintf(stderr, "%s: types dd40, dd80, dd40s, dd80s, sd40, sd80, sd40s, sd80s\n");
+    exit(1);
+  }
+  infd = open(argv[2], O_RDONLY);
+  if (infd == -1) {
+    perror(argv[2]);
+    exit(1);
+  }
+  outfd = open(argv[3], O_WRONLY|O_TRUNC|O_CREAT, 0666);
+  if (outfd == -1) {
+    perror(argv[3]);
+    exit(1);
+  }
+  jvc_writeheaders(dd, 40, nside, dd ? 18 : 10, hdrbuf);
+  if(write(outfd, hdrbuf, 8704) != 8704) {
+    perror(argv[3]);
+    exit(1);
+  }
+  jvcwritesectors(infd, outfd, 40, nside,  dd ? 20 : 10);
+  close(infd);
+  close(outfd);
+  exit(0);
+}