From 71e94c61ba82f922a295ec5c9c38b0d9a90ecbd5 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Wed, 24 Feb 2016 20:48:09 +1100 Subject: [PATCH] some CPM --- src/com/bytezone/diskbrowser/cpm/CPMDisk.java | 10 ++-- .../diskbrowser/cpm/DirectoryEntry.java | 48 +++++++++++++++++++ .../diskbrowser/disk/DiskFactory.java | 7 ++- 3 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java diff --git a/src/com/bytezone/diskbrowser/cpm/CPMDisk.java b/src/com/bytezone/diskbrowser/cpm/CPMDisk.java index 192129a..6fe0d5f 100644 --- a/src/com/bytezone/diskbrowser/cpm/CPMDisk.java +++ b/src/com/bytezone/diskbrowser/cpm/CPMDisk.java @@ -3,7 +3,6 @@ package com.bytezone.diskbrowser.cpm; import java.awt.Color; import java.util.List; -import com.bytezone.diskbrowser.HexFormatter; import com.bytezone.diskbrowser.applefile.BootSector; import com.bytezone.diskbrowser.disk.AbstractFormattedDisk; import com.bytezone.diskbrowser.disk.AppleDisk; @@ -53,10 +52,11 @@ public class CPMDisk extends AbstractFormattedDisk return false; if (buffer[i] == 0) { - String filename = HexFormatter.getString (buffer, i + 1, 8); - String filetype = HexFormatter.getString (buffer, i + 9, 3); - String bytes = HexFormatter.getHexString (buffer, i + 12, 20); - System.out.println (filename + " " + filetype + " " + bytes); + // String filename = HexFormatter.getString (buffer, i + 1, 8); + // String filetype = HexFormatter.getString (buffer, i + 9, 3); + // String bytes = HexFormatter.getHexString (buffer, i + 12, 20); + // System.out.println (filename + " " + filetype + " " + bytes); + System.out.println (new DirectoryEntry (buffer, i)); } } } diff --git a/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java new file mode 100644 index 0000000..f1697bb --- /dev/null +++ b/src/com/bytezone/diskbrowser/cpm/DirectoryEntry.java @@ -0,0 +1,48 @@ +package com.bytezone.diskbrowser.cpm; + +import com.bytezone.diskbrowser.HexFormatter; + +public class DirectoryEntry +{ + private final int userNumber; + private final String name; + private final String type; + private final int ex; + private final int s1; + private final int s2; + private final int rc; + private final byte[] blockList = new byte[16]; + + public DirectoryEntry (byte[] buffer, int offset) + { + userNumber = buffer[offset] & 0xFF; + name = new String (buffer, offset + 1, 8).trim (); + type = new String (buffer, offset + 9, 3).trim (); + ex = buffer[offset + 12] & 0xFF; + s2 = buffer[offset + 13] & 0xFF; + s1 = buffer[offset + 14] & 0xFF; + rc = buffer[offset + 15] & 0xFF; + System.arraycopy (buffer, offset + 16, blockList, 0, 16); + } + + @Override + public String toString () + { + StringBuilder text = new StringBuilder (); + + text.append (String.format ("User number .... %d%n", userNumber)); + text.append (String.format ("File name ...... %s%n", name + "." + type)); + // text.append (String.format ("File type ...... %s%n", type)); + text.append (String.format ("Extents lo ..... %d%n", ex)); + text.append (String.format ("Extents hi ..... %d%n", s2)); + text.append (String.format ("Reserved ....... %d%n", s1)); + + int blocks = ((rc & 0xF0) >> 3) + (((rc & 0x0F) + 7) / 8); + text.append (String.format ("Records ........ %02X (%d)%n", rc, blocks)); + text.append (String + .format ("Allocation ..... %s%n", + HexFormatter.formatNoHeader (blockList, 0, 16).subSequence (8, 55))); + + return text.toString (); + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/disk/DiskFactory.java b/src/com/bytezone/diskbrowser/disk/DiskFactory.java index f1e0f47..f30d76c 100755 --- a/src/com/bytezone/diskbrowser/disk/DiskFactory.java +++ b/src/com/bytezone/diskbrowser/disk/DiskFactory.java @@ -20,7 +20,7 @@ import com.bytezone.diskbrowser.wizardry.WizardryScenarioDisk; public class DiskFactory { - private static boolean debug = false; + private static boolean debug = true; private DiskFactory () { @@ -178,9 +178,12 @@ public class DiskFactory else if (checksum == 3028642627L || checksum == 2070151659L) disk = checkInfocomDisk (file); - else if (checksum == 1212926910L || checksum == 1365043894L) + else if (checksum == 1212926910L || checksum == 1365043894L + || checksum == 2128073918L) disk = checkCPMDisk (file); + // System.out.println (checksum); + if (disk != null) { if (compressed)