Wiz 5 is now recognisable

This commit is contained in:
Denis Molony 2016-08-06 17:17:16 +10:00
parent f47ae78cfb
commit 8d562ddf12
9 changed files with 105 additions and 54 deletions

View File

@ -4,16 +4,16 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
import com.bytezone.diskbrowser.utilities.Utility;
public class PascalCode extends AbstractFile public class PascalCode extends AbstractFile
implements PascalConstants, Iterable<PascalSegment> implements PascalConstants, Iterable<PascalSegment>
{ {
private final List<PascalSegment> segments = new ArrayList<PascalSegment> (16); private final List<PascalSegment> segments = new ArrayList<PascalSegment> (16);
private final String comment; private final String comment;
private final int blockOffset; // private final int blockOffset;
private final Relocator relocator; // private final Relocator relocator;
public static void print () public static void print ()
{ {
@ -26,17 +26,15 @@ public class PascalCode extends AbstractFile
{ {
super (name, buffer); super (name, buffer);
this.blockOffset = blockOffset; SegmentDictionary segmentDictionary = new SegmentDictionary (name, buffer);
this.relocator = relocator; 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; 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) // Create segment list (up to 16 segments)
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
@ -47,6 +45,7 @@ public class PascalCode extends AbstractFile
codeName = "<NULL" + ++nonameCounter + ">"; codeName = "<NULL" + ++nonameCounter + ">";
if (size > 0) if (size > 0)
{ {
// this could throw an exception
PascalSegment pascalSegment = PascalSegment pascalSegment =
new PascalSegment (codeName, buffer, i, blockOffset, relocator); new PascalSegment (codeName, buffer, i, blockOffset, relocator);
segments.add (pascalSegment); segments.add (pascalSegment);
@ -63,8 +62,8 @@ public class PascalCode extends AbstractFile
text.append ("Segment Dictionary\n==================\n\n"); text.append ("Segment Dictionary\n==================\n\n");
text.append ("Slot Addr Blks Len Name Kind" text.append ("Slot Addr Blks Byte Name Kind"
+ " Txt Seg Mch Ver I/S I/S D:Blk\n"); + " Txt Seg Mch Ver I/S I/S Disk:Block\n");
text.append ("---- ---- ---- ---- -------- ---------------" text.append ("---- ---- ---- ---- -------- ---------------"
+ " --- --- --- --- --- --- ---------------------\n"); + " --- --- --- --- --- --- ---------------------\n");

View File

@ -70,8 +70,8 @@ public class PascalSegment extends AbstractFile implements PascalConstants
if (relocator != null) if (relocator != null)
{ {
if (segmentNoHeader > 1) // if (segmentNoHeader > 1)
{ // {
int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1;
int targetBlock = blockNo + blockOffset; int targetBlock = blockNo + blockOffset;
addresses = relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks); addresses = relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks);
@ -83,7 +83,7 @@ public class PascalSegment extends AbstractFile implements PascalConstants
else else
offset = -1; offset = -1;
} }
} // }
} }
if (offset < 0) if (offset < 0)
@ -144,14 +144,14 @@ public class PascalSegment extends AbstractFile implements PascalConstants
text.append (title + "\n" text.append (title + "\n"
+ "===============================".substring (0, title.length ()) + "\n\n"); + "===============================".substring (0, title.length ()) + "\n\n");
String warning = segmentNoBody == segmentNoHeader ? "" String warning = segmentNoBody == segmentNoHeader ? ""
: String.format (" (%02X in header)", segmentNoHeader); : String.format (" (%02X in routine)", segmentNoBody);
text.append (String.format ("Address........ %02X%n", blockNo)); text.append (String.format ("Address........ %02X%n", blockNo));
if (addresses != null) // if (addresses != null)
text.append (String.format ("Multi disk .... %s%n", getMultiDiskAddresses ())); text.append (String.format ("Multi disk .... %s%n", getMultiDiskAddresses ()));
text.append (String.format ("Length......... %04X%n", buffer.length)); text.append (String.format ("Length......... %04X%n", buffer.length));
text.append (String.format ("Machine type... %d%n", machineType)); text.append (String.format ("Machine type... %d%n", machineType));
text.append (String.format ("Version........ %d%n", version)); 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 (String.format ("Total procs.... %d%n", procedures.size ()));
text.append ("\nProcedure Dictionary\n====================\n\n"); text.append ("\nProcedure Dictionary\n====================\n\n");
@ -199,11 +199,12 @@ public class PascalSegment extends AbstractFile implements PascalConstants
String multiDiskAddressText = ""; String multiDiskAddressText = "";
int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1; int sizeInBlocks = (size - 1) / BLOCK_SIZE + 1;
if (segmentNoHeader == 1) // main segment // if (segmentNoHeader == 1) // main segment
{ // {
multiDiskAddressText = String.format ("1:%03X", (blockNo + blockOffset)); // multiDiskAddressText = String.format ("1:%03X", (blockNo + blockOffset));
} // }
else if (relocator != null) // else
if (relocator != null)
{ {
int targetBlock = blockNo + blockOffset; int targetBlock = blockNo + blockOffset;
List<MultiDiskAddress> addresses = List<MultiDiskAddress> addresses =

View File

@ -35,6 +35,9 @@ public class Relocator extends AbstractFile
addresses addresses
.add (new MultiDiskAddress (diskRecord.diskNumber, diskSegment.logicalBlock, .add (new MultiDiskAddress (diskRecord.diskNumber, diskSegment.logicalBlock,
diskSegment.physicalBlock, diskSegment.segmentLength)); diskSegment.physicalBlock, diskSegment.segmentLength));
getMultiDiskAddress ("BOOT", 0, 2);
getMultiDiskAddress ("CATALOG", 2, 4);
} }
public void list () public void list ()
@ -51,6 +54,7 @@ public class Relocator extends AbstractFile
List<MultiDiskAddress> foundAddresses = new ArrayList<MultiDiskAddress> (); List<MultiDiskAddress> foundAddresses = new ArrayList<MultiDiskAddress> ();
newAddresses.clear (); newAddresses.clear ();
oldAddresses.clear (); oldAddresses.clear ();
// System.out.printf ("%04X %04X %s%n", blockNumber, length, name);
for (MultiDiskAddress multiDiskAddress : addresses) for (MultiDiskAddress multiDiskAddress : addresses)
{ {
@ -103,6 +107,22 @@ public class Relocator extends AbstractFile
text.append ("\n"); 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 (); return text.toString ();
} }
@ -135,16 +155,13 @@ public class Relocator extends AbstractFile
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
int offset = 0xe2;
text.append (String.format ("Disk number.... %04X%n", diskNumber)); text.append (String.format ("Disk number.... %04X%n", diskNumber));
text.append (String.format ("Segments....... %04X%n%n", totDiskSegments)); text.append (String.format ("Segments....... %04X%n%n", totDiskSegments));
text.append (String.format ( text.append (String.format ("Segment Logical Physical Length%n"));
"Segment Logical Physical Length -%04X -%04X%n", offset, offset));
int count = 1; int count = 1;
for (DiskSegment segment : diskSegments) 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 (); return text.toString ();
} }

View File

@ -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;
}
}

View File

@ -34,16 +34,10 @@ abstract class CatalogEntry implements AppleFileSource
bytesUsedInLastBlock = HexFormatter.intValue (buffer[16], buffer[17]); bytesUsedInLastBlock = HexFormatter.intValue (buffer[16], buffer[17]);
Disk disk = parent.getDisk (); Disk disk = parent.getDisk ();
for (int i = firstBlock; i < lastBlock; i++) int max = Math.min (lastBlock, 0x118);
{ for (int i = firstBlock; i < max; i++)
if (i >= 0x118)
{
System.out.printf ("CatalogEntry: block 0x%04X >= 0x0118%n", i);
break;
}
blocks.add (disk.getDiskAddress (i)); blocks.add (disk.getDiskAddress (i));
} }
}
@Override @Override
public boolean contains (DiskAddress da) public boolean contains (DiskAddress da)

View File

@ -17,6 +17,13 @@ class FileEntry extends CatalogEntry
bytesUsedInLastBlock = HexFormatter.intValue (buffer[22], buffer[23]); bytesUsedInLastBlock = HexFormatter.intValue (buffer[22], buffer[23]);
date = HexFormatter.getPascalDate (buffer, 24); 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++) for (int i = firstBlock; i < lastBlock; i++)
{ {
if (i >= 280) if (i >= 280)
@ -114,7 +121,7 @@ class FileEntry extends CatalogEntry
byte[] buffer = parent.getDisk ().readSectors (blocks); byte[] buffer = parent.getDisk ().readSectors (blocks);
byte[] exactBuffer; byte[] exactBuffer;
if (bytesUsedInLastBlock < 512) if (buffer.length > 0 && bytesUsedInLastBlock < 512)
{ {
int exactLength = buffer.length - 512 + bytesUsedInLastBlock; int exactLength = buffer.length - 512 + bytesUsedInLastBlock;
exactBuffer = new byte[exactLength]; exactBuffer = new byte[exactLength];

View File

@ -105,13 +105,19 @@ public class PascalDisk extends AbstractFormattedDisk
fileEntries.add (fileEntry); fileEntries.add (fileEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry); DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry);
if (fileEntry.fileType == 5 && fileEntry.getDataSource () instanceof Relocator) DataSource dataSource = fileEntry.getDataSource ();
this.relocator = (Relocator) 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); node.setAllowsChildren (true);
PascalCode pascalCode = (PascalCode) fileEntry.getDataSource (); PascalCode pascalCode = (PascalCode) dataSource;
for (PascalSegment pascalSegment : pascalCode) for (PascalSegment pascalSegment : pascalCode)
{ {
DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode ( DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode (

View File

@ -28,6 +28,17 @@ class VolumeEntry extends CatalogEntry
firstBlock = HexFormatter.intValue (buffer[18], buffer[19]); // 0 firstBlock = HexFormatter.intValue (buffer[18], buffer[19]); // 0
date = HexFormatter.getPascalDate (buffer, 20); // 2 bytes date = HexFormatter.getPascalDate (buffer, 20); // 2 bytes
// bytes 0x16 - 0x19 are unused // 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 @Override