From 8d562ddf1234d2005d51ef71f7607a0d7c0d2c96 Mon Sep 17 00:00:00 2001 From: Denis Molony Date: Sat, 6 Aug 2016 17:17:16 +1000 Subject: [PATCH] Wiz 5 is now recognisable --- .../diskbrowser/applefile/PascalCode.java | 27 ++++++------ .../diskbrowser/applefile/PascalSegment.java | 43 ++++++++++--------- .../diskbrowser/applefile/Relocator.java | 27 +++++++++--- .../applefile/SegmentDictionary.java | 16 +++++++ .../diskbrowser/pascal/CatalogEntry.java | 10 +---- .../diskbrowser/pascal/FileEntry.java | 9 +++- .../pascal/PascalCatalogSector.java | 2 +- .../diskbrowser/pascal/PascalDisk.java | 14 ++++-- .../diskbrowser/pascal/VolumeEntry.java | 11 +++++ 9 files changed, 105 insertions(+), 54 deletions(-) create mode 100644 src/com/bytezone/diskbrowser/applefile/SegmentDictionary.java diff --git a/src/com/bytezone/diskbrowser/applefile/PascalCode.java b/src/com/bytezone/diskbrowser/applefile/PascalCode.java index 1ddfbad..3885840 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalCode.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalCode.java @@ -4,16 +4,16 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import com.bytezone.diskbrowser.utilities.FileFormatException; import com.bytezone.diskbrowser.utilities.HexFormatter; -import com.bytezone.diskbrowser.utilities.Utility; public class PascalCode extends AbstractFile implements PascalConstants, Iterable { private final List segments = new ArrayList (16); private final String comment; - private final int blockOffset; - private final Relocator relocator; + // private final int blockOffset; + // private final Relocator relocator; public static void print () { @@ -26,17 +26,15 @@ public class PascalCode extends AbstractFile { super (name, buffer); - this.blockOffset = blockOffset; - this.relocator = relocator; + SegmentDictionary segmentDictionary = new SegmentDictionary (name, buffer); + if (!segmentDictionary.isValid ()) + throw new FileFormatException ("Error in PascalSegment"); + // this.blockOffset = blockOffset; + // this.relocator = relocator; + if (relocator != null) + relocator.getMultiDiskAddress ("SEG-DIC", blockOffset, 1); int nonameCounter = 0; - if (false) - { - // System.out.println (name); - // byte[] key = new byte[] { 0x38, 0x00, 0x0C, 0x1C }; - byte[] key = new byte[] { 0x0F }; - Utility.find (buffer, key); - } // Create segment list (up to 16 segments) for (int i = 0; i < 16; i++) @@ -47,6 +45,7 @@ public class PascalCode extends AbstractFile codeName = ""; if (size > 0) { + // this could throw an exception PascalSegment pascalSegment = new PascalSegment (codeName, buffer, i, blockOffset, relocator); segments.add (pascalSegment); @@ -63,8 +62,8 @@ public class PascalCode extends AbstractFile text.append ("Segment Dictionary\n==================\n\n"); - text.append ("Slot Addr Blks Len Name Kind" - + " Txt Seg Mch Ver I/S I/S D:Blk\n"); + text.append ("Slot Addr Blks Byte Name Kind" + + " Txt Seg Mch Ver I/S I/S Disk:Block\n"); text.append ("---- ---- ---- ---- -------- ---------------" + " --- --- --- --- --- --- ---------------------\n"); diff --git a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java index 15d0afb..1948f67 100755 --- a/src/com/bytezone/diskbrowser/applefile/PascalSegment.java +++ b/src/com/bytezone/diskbrowser/applefile/PascalSegment.java @@ -70,20 +70,20 @@ public class PascalSegment extends AbstractFile implements PascalConstants if (relocator != null) { - if (segmentNoHeader > 1) + // if (segmentNoHeader > 1) + // { + int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; + int targetBlock = blockNo + blockOffset; + addresses = relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks); + if (addresses.size () > 0) { - int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; - int targetBlock = blockNo + blockOffset; - addresses = relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks); - if (addresses.size () > 0) - { - MultiDiskAddress multiDiskAddress = addresses.get (0); - if (multiDiskAddress.diskNumber == 1) - offset = (multiDiskAddress.physicalBlockNumber - blockOffset) * BLOCK_SIZE; - else - offset = -1; - } + MultiDiskAddress multiDiskAddress = addresses.get (0); + if (multiDiskAddress.diskNumber == 1) + offset = (multiDiskAddress.physicalBlockNumber - blockOffset) * BLOCK_SIZE; + else + offset = -1; } + // } } if (offset < 0) @@ -144,14 +144,14 @@ public class PascalSegment extends AbstractFile implements PascalConstants text.append (title + "\n" + "===============================".substring (0, title.length ()) + "\n\n"); String warning = segmentNoBody == segmentNoHeader ? "" - : String.format (" (%02X in header)", segmentNoHeader); + : String.format (" (%02X in routine)", segmentNoBody); text.append (String.format ("Address........ %02X%n", blockNo)); - if (addresses != null) - text.append (String.format ("Multi disk .... %s%n", getMultiDiskAddresses ())); + // if (addresses != null) + text.append (String.format ("Multi disk .... %s%n", getMultiDiskAddresses ())); text.append (String.format ("Length......... %04X%n", buffer.length)); text.append (String.format ("Machine type... %d%n", machineType)); text.append (String.format ("Version........ %d%n", version)); - text.append (String.format ("Segment........ %02X%s%n", segmentNoBody, warning)); + text.append (String.format ("Segment........ %02X%s%n", segmentNoHeader, warning)); text.append (String.format ("Total procs.... %d%n", procedures.size ())); text.append ("\nProcedure Dictionary\n====================\n\n"); @@ -199,11 +199,12 @@ public class PascalSegment extends AbstractFile implements PascalConstants String multiDiskAddressText = ""; int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; - if (segmentNoHeader == 1) // main segment - { - multiDiskAddressText = String.format ("1:%03X", (blockNo + blockOffset)); - } - else if (relocator != null) + // if (segmentNoHeader == 1) // main segment + // { + // multiDiskAddressText = String.format ("1:%03X", (blockNo + blockOffset)); + // } + // else + if (relocator != null) { int targetBlock = blockNo + blockOffset; List addresses = diff --git a/src/com/bytezone/diskbrowser/applefile/Relocator.java b/src/com/bytezone/diskbrowser/applefile/Relocator.java index d728810..9843592 100644 --- a/src/com/bytezone/diskbrowser/applefile/Relocator.java +++ b/src/com/bytezone/diskbrowser/applefile/Relocator.java @@ -35,6 +35,9 @@ public class Relocator extends AbstractFile addresses .add (new MultiDiskAddress (diskRecord.diskNumber, diskSegment.logicalBlock, diskSegment.physicalBlock, diskSegment.segmentLength)); + + getMultiDiskAddress ("BOOT", 0, 2); + getMultiDiskAddress ("CATALOG", 2, 4); } public void list () @@ -51,6 +54,7 @@ public class Relocator extends AbstractFile List foundAddresses = new ArrayList (); newAddresses.clear (); oldAddresses.clear (); + // System.out.printf ("%04X %04X %s%n", blockNumber, length, name); for (MultiDiskAddress multiDiskAddress : addresses) { @@ -103,6 +107,22 @@ public class Relocator extends AbstractFile text.append ("\n"); } + int previousDiskNumber = 0; + for (MultiDiskAddress multiDiskAddress : addresses) + { + if (multiDiskAddress.diskNumber != previousDiskNumber) + { + previousDiskNumber = multiDiskAddress.diskNumber; + text.append ("\n"); + text.append ("Disk Logical Physical Size Name\n"); + text.append ("---- ------- -------- ---- -----------\n"); + } + text.append (String.format (" %d %03X %03X %03X %s%n", + multiDiskAddress.diskNumber, multiDiskAddress.logicalBlockNumber, + multiDiskAddress.physicalBlockNumber, multiDiskAddress.totalBlocks, + multiDiskAddress.name)); + } + return text.toString (); } @@ -135,16 +155,13 @@ public class Relocator extends AbstractFile { StringBuilder text = new StringBuilder (); - int offset = 0xe2; - text.append (String.format ("Disk number.... %04X%n", diskNumber)); text.append (String.format ("Segments....... %04X%n%n", totDiskSegments)); - text.append (String.format ( - "Segment Logical Physical Length -%04X -%04X%n", offset, offset)); + text.append (String.format ("Segment Logical Physical Length%n")); int count = 1; for (DiskSegment segment : diskSegments) - text.append (String.format (" %02X %s %n", count++, segment.toString (offset))); + text.append (String.format (" %02X %s %n", count++, segment.toString ())); return text.toString (); } diff --git a/src/com/bytezone/diskbrowser/applefile/SegmentDictionary.java b/src/com/bytezone/diskbrowser/applefile/SegmentDictionary.java new file mode 100644 index 0000000..d33db77 --- /dev/null +++ b/src/com/bytezone/diskbrowser/applefile/SegmentDictionary.java @@ -0,0 +1,16 @@ +package com.bytezone.diskbrowser.applefile; + +public class SegmentDictionary +{ + private final boolean isValid; + + public SegmentDictionary (String name, byte[] buffer) + { + isValid = !name.equals ("SYSTEM.INTERP"); // temporary + } + + public boolean isValid () + { + return isValid; + } +} \ No newline at end of file diff --git a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java index 7eae848..ffeb23d 100644 --- a/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/CatalogEntry.java @@ -34,15 +34,9 @@ abstract class CatalogEntry implements AppleFileSource bytesUsedInLastBlock = HexFormatter.intValue (buffer[16], buffer[17]); Disk disk = parent.getDisk (); - for (int i = firstBlock; i < lastBlock; i++) - { - if (i >= 0x118) - { - System.out.printf ("CatalogEntry: block 0x%04X >= 0x0118%n", i); - break; - } + int max = Math.min (lastBlock, 0x118); + for (int i = firstBlock; i < max; i++) blocks.add (disk.getDiskAddress (i)); - } } @Override diff --git a/src/com/bytezone/diskbrowser/pascal/FileEntry.java b/src/com/bytezone/diskbrowser/pascal/FileEntry.java index a524257..598338e 100644 --- a/src/com/bytezone/diskbrowser/pascal/FileEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/FileEntry.java @@ -17,6 +17,13 @@ class FileEntry extends CatalogEntry bytesUsedInLastBlock = HexFormatter.intValue (buffer[22], buffer[23]); date = HexFormatter.getPascalDate (buffer, 24); + if (relocator != null) + { + int size = lastBlock - firstBlock; + // System.out.printf ("%04X %04X %s%n", firstBlock, size, name); + relocator.getMultiDiskAddress (name, firstBlock, size); + } + for (int i = firstBlock; i < lastBlock; i++) { if (i >= 280) @@ -114,7 +121,7 @@ class FileEntry extends CatalogEntry byte[] buffer = parent.getDisk ().readSectors (blocks); byte[] exactBuffer; - if (bytesUsedInLastBlock < 512) + if (buffer.length > 0 && bytesUsedInLastBlock < 512) { int exactLength = buffer.length - 512 + bytesUsedInLastBlock; exactBuffer = new byte[exactLength]; diff --git a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java index b0f1533..2b595fb 100644 --- a/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalCatalogSector.java @@ -69,7 +69,7 @@ class PascalCatalogSector extends AbstractSector addText (text, buffer, ptr + 24, 2, "Date : " + date); ptr += PascalDisk.CATALOG_ENTRY_SIZE; - --totalFiles; // what if there are deleted files? + --totalFiles; // what if there are deleted files? } return text.toString (); diff --git a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java index be5e60f..bd745eb 100755 --- a/src/com/bytezone/diskbrowser/pascal/PascalDisk.java +++ b/src/com/bytezone/diskbrowser/pascal/PascalDisk.java @@ -105,13 +105,19 @@ public class PascalDisk extends AbstractFormattedDisk fileEntries.add (fileEntry); DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry); - if (fileEntry.fileType == 5 && fileEntry.getDataSource () instanceof Relocator) - this.relocator = (Relocator) fileEntry.getDataSource (); + DataSource dataSource = fileEntry.getDataSource (); - if (fileEntry.fileType == 2 && fileEntry.getDataSource () instanceof PascalCode) + if (fileEntry.fileType == 5 && dataSource instanceof Relocator) + { + this.relocator = (Relocator) dataSource; + int size = fileEntry.lastBlock - fileEntry.firstBlock; + relocator.getMultiDiskAddress (fileEntry.name, fileEntry.firstBlock, size); + } + + if (fileEntry.fileType == 2 && dataSource instanceof PascalCode) { node.setAllowsChildren (true); - PascalCode pascalCode = (PascalCode) fileEntry.getDataSource (); + PascalCode pascalCode = (PascalCode) dataSource; for (PascalSegment pascalSegment : pascalCode) { DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode ( diff --git a/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java b/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java index 28853da..9799070 100644 --- a/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java +++ b/src/com/bytezone/diskbrowser/pascal/VolumeEntry.java @@ -28,6 +28,17 @@ class VolumeEntry extends CatalogEntry firstBlock = HexFormatter.intValue (buffer[18], buffer[19]); // 0 date = HexFormatter.getPascalDate (buffer, 20); // 2 bytes // bytes 0x16 - 0x19 are unused + + if (false) + { + System.out.printf ("Total files ..... %d%n", totalFiles); + System.out.printf ("Total blocks .... %d%n", totalBlocks); + System.out.printf ("Block1 .......... %d%n", block1); + System.out.printf ("Last block ...... %d%n", lastDirectoryBlock); + System.out.printf ("Record type ..... %d%n", recordType); + System.out.printf ("Name length ..... %d%n", nameLength); + System.out.printf ("Name ............ %s%n", name); + } } @Override