Wiz4 first stage complete

This commit is contained in:
Denis Molony 2016-08-09 14:15:44 +10:00
parent 6ad21060b3
commit 9104389d22
10 changed files with 163 additions and 153 deletions

View File

@ -22,7 +22,7 @@ public class PascalCode extends AbstractFile
PascalConstants.mnemonics[i], PascalConstants.descriptions[i]);
}
public PascalCode (String name, byte[] buffer, int blockOffset, Relocator relocator)
public PascalCode (String name, byte[] buffer, int blockOffset)
{
super (name, buffer);
@ -31,8 +31,8 @@ public class PascalCode extends AbstractFile
throw new FileFormatException ("Error in PascalSegment");
// this.blockOffset = blockOffset;
// this.relocator = relocator;
if (relocator != null)
relocator.getMultiDiskAddress ("SEG-DIC", blockOffset, 1);
// if (relocator != null)
// relocator.getMultiDiskAddress ("SEG-DIC", blockOffset, 1);
int nonameCounter = 0;
@ -47,7 +47,7 @@ public class PascalCode extends AbstractFile
{
// this could throw an exception
PascalSegment pascalSegment =
new PascalSegment (codeName, buffer, i, blockOffset, relocator);
new PascalSegment (codeName, buffer, i, blockOffset);
segments.add (pascalSegment);
}
}

View File

@ -70,7 +70,7 @@ public class PascalProcedure
// System.out.printf ("ptr:%d, max:%d, buf:%d %n", ptr, max, buffer.length);
if (ptr >= buffer.length || ptr < 0)
{
System.out.println ("Ptr outside buffer");
System.out.printf ("Ptr outside buffer: %d %d%n", ptr, buffer.length);
break;
}
PascalCodeStatement cs = new PascalCodeStatement (buffer, ptr, procOffset);

View File

@ -13,7 +13,7 @@ public class PascalSegment extends AbstractFile implements PascalConstants
final int segmentNoHeader;
private int segmentNoBody;
private final int blockOffset;
private final Relocator relocator;
// private final Relocator relocator;
public int blockNo;
// public int newBlockNo;
@ -30,14 +30,13 @@ public class PascalSegment extends AbstractFile implements PascalConstants
private List<PascalProcedure> procedures;
private List<MultiDiskAddress> addresses;
public PascalSegment (String name, byte[] fullBuffer, int seq, int blockOffset,
Relocator relocator)
public PascalSegment (String name, byte[] fullBuffer, int seq, int blockOffset)
{
super (name, fullBuffer); // sets this.buffer to the full buffer temporarily
this.slot = seq;
this.blockOffset = blockOffset;
this.relocator = relocator;
// this.relocator = relocator;
this.blockNo = HexFormatter.intValue (fullBuffer[seq * 4], fullBuffer[seq * 4 + 1]);
this.size = HexFormatter.intValue (fullBuffer[seq * 4 + 2], fullBuffer[seq * 4 + 3]);
@ -68,23 +67,23 @@ public class PascalSegment extends AbstractFile implements PascalConstants
int offset = blockNo * 512;
if (relocator != null)
{
// if (segmentNoHeader > 1)
// if (relocator != null)
// {
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;
}
// // if (segmentNoHeader > 1)
// // {
// 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;
// }
// // }
// }
}
if (offset < 0)
{
@ -204,26 +203,26 @@ public class PascalSegment extends AbstractFile implements PascalConstants
// multiDiskAddressText = String.format ("1:%03X", (blockNo + blockOffset));
// }
// else
if (relocator != null)
{
int targetBlock = blockNo + blockOffset;
List<MultiDiskAddress> addresses =
relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks);
if (addresses.isEmpty ())
multiDiskAddressText = ".";
else
{
StringBuilder locations = new StringBuilder ();
for (MultiDiskAddress multiDiskAddress : addresses)
locations.append (multiDiskAddress.toString () + ", ");
if (locations.length () > 2)
{
locations.deleteCharAt (locations.length () - 1);
locations.deleteCharAt (locations.length () - 1);
}
multiDiskAddressText = locations.toString ();
}
}
// if (relocator != null)
// {
// int targetBlock = blockNo + blockOffset;
// List<MultiDiskAddress> addresses =
// relocator.getMultiDiskAddress (name, targetBlock, sizeInBlocks);
// if (addresses.isEmpty ())
// multiDiskAddressText = ".";
// else
// {
// StringBuilder locations = new StringBuilder ();
// for (MultiDiskAddress multiDiskAddress : addresses)
// locations.append (multiDiskAddress.toString () + ", ");
// if (locations.length () > 2)
// {
// locations.deleteCharAt (locations.length () - 1);
// locations.deleteCharAt (locations.length () - 1);
// }
// multiDiskAddressText = locations.toString ();
// }
// }
return multiDiskAddressText;
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.bytezone.diskbrowser.disk.AppleDisk;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.utilities.HexFormatter;
@ -151,6 +152,24 @@ public class Relocator extends AbstractFile
return true;
}
public void createNewBuffer (Disk[] dataDisks)
{
AppleDisk master = (AppleDisk) dataDisks[0];
for (int logicalBlock = 0; logicalBlock < diskBlocks.length; logicalBlock++)
{
int physicalBlock = diskOffsets2[logicalBlock];
int diskNo = diskBlocks[logicalBlock];
if (diskNo > 0)
{
Disk disk = dataDisks[diskNo];
byte[] temp = disk.readSector (physicalBlock);
DiskAddress da = master.getDiskAddress (logicalBlock);
master.writeSector (da, temp);
}
}
}
@Override
public String getText ()
{
@ -165,6 +184,8 @@ public class Relocator extends AbstractFile
text.append ("\n");
}
if (false)
{
int previousDiskNumber = 0;
for (MultiDiskAddress multiDiskAddress : addresses)
{
@ -180,8 +201,9 @@ public class Relocator extends AbstractFile
multiDiskAddress.physicalBlockNumber, multiDiskAddress.totalBlocks,
multiDiskAddress.name));
}
}
text.append ("\n\n Logical Size Disk Physical");
text.append ("\n Logical Size Disk Physical");
text.append ("\n--------- ---- ---- ---------\n");
int first = 0;

View File

@ -381,10 +381,11 @@ public class AppleDisk implements Disk
}
@Override
public int writeSector (DiskAddress da, byte[] buffer)
public void writeSector (DiskAddress da, byte[] buffer)
{
System.out.println ("Not yet implemented");
return -1;
// System.out.println ("Not yet implemented");
// return -1;
writeBuffer (da, buffer);
}
@Override
@ -507,7 +508,7 @@ public class AppleDisk implements Disk
}
}
private void writeBuffer (DiskAddress da, byte[] buffer, int bufferOffset)
private void writeBuffer (DiskAddress da, byte[] buffer)
{
assert da.getDisk () == this : "Disk address not applicable to this disk";
assert sectorSize == SECTOR_SIZE
@ -518,16 +519,15 @@ public class AppleDisk implements Disk
if (sectorSize == SECTOR_SIZE)
{
int diskOffset = getBufferOffset (da);
System.arraycopy (buffer, bufferOffset, diskBuffer, diskOffset, SECTOR_SIZE);
System.arraycopy (buffer, 0, diskBuffer, diskOffset, SECTOR_SIZE);
}
else
{
int diskOffset = getBufferOffset (da, 0);
System.arraycopy (buffer, bufferOffset, diskBuffer, diskOffset, SECTOR_SIZE);
System.arraycopy (buffer, 0, diskBuffer, diskOffset, SECTOR_SIZE);
diskOffset = getBufferOffset (da, 1);
System.arraycopy (buffer, bufferOffset + SECTOR_SIZE, diskBuffer, diskOffset,
SECTOR_SIZE);
System.arraycopy (buffer, SECTOR_SIZE, diskBuffer, diskOffset, SECTOR_SIZE);
}
}

View File

@ -40,7 +40,7 @@ public interface Disk extends Iterable<DiskAddress>
public byte[] readSectors (List<DiskAddress> daList);
public int writeSector (DiskAddress da, byte[] buffer);
public void writeSector (DiskAddress da, byte[] buffer);
public boolean isSectorEmpty (DiskAddress da);

View File

@ -390,13 +390,15 @@ public class DiskFactory
if (Wizardry4BootDisk.isWizardryIV (disk, debug))
{
// collect 4 data disks
AppleDisk[] disks = new AppleDisk[5];
AppleDisk d = new AppleDisk (file, 256, 8);
d.setInterleave (1);
disks[0] = d;
// collect 4 extra data disks
AppleDisk[] disks = new AppleDisk[6];
for (int i = 2; i <= 5; i++)
disks[0] = new AppleDisk (file, 256, 8); // will become a PascalDisk
disks[1] = new AppleDisk (file, 256, 8); // will remain a DataDisk
disks[0].setInterleave (1);
disks[1].setInterleave (1);
for (int i = 2; i < disks.length; i++)
{
String filename = file.getAbsolutePath ().replace ("1.dsk", i + ".dsk");
File f = new File (filename);
@ -404,7 +406,7 @@ public class DiskFactory
{
AppleDisk dataDisk = new AppleDisk (f, 35, 8);
dataDisk.setInterleave (1);
disks[i - 1] = dataDisk;
disks[i] = dataDisk;
}
else
{

View File

@ -1,35 +1,26 @@
package com.bytezone.diskbrowser.pascal;
import javax.swing.tree.DefaultMutableTreeNode;
import com.bytezone.diskbrowser.applefile.*;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class FileEntry extends CatalogEntry
{
int bytesUsedInLastBlock;
private final Relocator relocator;
private DefaultMutableTreeNode node;
AbstractFile file;
public FileEntry (PascalDisk parent, byte[] buffer, Relocator relocator)
public FileEntry (PascalDisk parent, byte[] buffer)
{
super (parent, buffer);
this.relocator = relocator;
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)
break;
switch (fileType)
{
case 2:
@ -64,14 +55,22 @@ public class FileEntry extends CatalogEntry
}
}
void setNode (DefaultMutableTreeNode node)
{
this.node = node;
}
public void setFile (AbstractFile file)
{
this.file = file;
}
@Override
public AbstractFile getDataSource ()
{
if (file != null)
return file;
// this needs to use the Relocator to obtain the currect blocks
assembleBuffer ();
byte[] buffer = getExactBuffer ();
switch (fileType)
@ -79,7 +78,16 @@ public class FileEntry extends CatalogEntry
case 2: // code (6502 or Pascal)
try
{
file = new PascalCode (name, buffer, firstBlock, relocator);
file = new PascalCode (name, buffer, firstBlock);
node.removeAllChildren ();
for (PascalSegment pascalSegment : (PascalCode) file)
{
DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode (
new PascalCodeObject (parent, pascalSegment, firstBlock));
node.add (segmentNode);
segmentNode.setAllowsChildren (false);
}
}
catch (FileFormatException e)
{
@ -103,8 +111,8 @@ public class FileEntry extends CatalogEntry
file = new Charset (name, buffer);
// else if (name.equals ("WT")) // only testing
// file = new WizardryTitle (name, buffer);
else if (name.equals ("SYSTEM.RELOC"))
file = new Relocator (name, buffer);
// else if (name.equals ("SYSTEM.RELOC"))
// file = new Relocator (name, buffer);
else
file = new DefaultAppleFile (name, buffer);
break;
@ -119,27 +127,11 @@ public class FileEntry extends CatalogEntry
return file;
}
private byte[] assembleBuffer ()
{
if (relocator != null)
for (DiskAddress da : blocks)
{
System.out.println (da);
if (da.getBlock () < 20)
{
byte[] buffer = relocator.getLogicalBuffer (da);
System.out.println (HexFormatter.format (buffer));
}
}
return null;
}
// use Relocator to obtain correct blocks
private byte[] getExactBuffer ()
{
byte[] buffer = parent.getDisk ().readSectors (blocks);
byte[] exactBuffer;
// System.out.println (HexFormatter.format (buffer));
if (buffer.length > 0 && bytesUsedInLastBlock < 512)
{

View File

@ -10,8 +10,6 @@ import javax.swing.tree.DefaultMutableTreeNode;
import com.bytezone.diskbrowser.applefile.AppleFileSource;
import com.bytezone.diskbrowser.applefile.BootSector;
import com.bytezone.diskbrowser.applefile.PascalCode;
import com.bytezone.diskbrowser.applefile.PascalSegment;
import com.bytezone.diskbrowser.applefile.Relocator;
import com.bytezone.diskbrowser.disk.*;
import com.bytezone.diskbrowser.gui.DataSource;
@ -21,11 +19,10 @@ public class PascalDisk extends AbstractFormattedDisk
{
static final int CATALOG_ENTRY_SIZE = 26;
private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT);
private VolumeEntry volumeEntry;
private PascalCatalogSector diskCatalogSector;
private final VolumeEntry volumeEntry;
private final PascalCatalogSector diskCatalogSector;
protected Relocator relocator;
protected Disk[] dataDisks;
final String[] fileTypes =
{ "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" };
@ -39,26 +36,10 @@ public class PascalDisk extends AbstractFormattedDisk
SectorType grafSector = new SectorType ("Graf", Color.cyan);
SectorType fotoSector = new SectorType ("Foto", Color.gray);
public PascalDisk (Disk[] disks)
{
super (disks[0]);
init ();
dataDisks = disks; // these need to be in place before ...
// 1. create new disk buffer
// 2. copy sectors from 5 data disks to new buffer
// 3. replace old disk buffer with new disk buffer
}
public PascalDisk (Disk disk)
{
super (disk);
init ();
}
private void init ()
{
sectorTypesList.add (diskBootSector);
sectorTypesList.add (catalogSector);
sectorTypesList.add (dataSector);
@ -117,32 +98,24 @@ public class PascalDisk extends AbstractFormattedDisk
data = new byte[CATALOG_ENTRY_SIZE];
System.arraycopy (buffer, ptr, data, 0, CATALOG_ENTRY_SIZE);
FileEntry fileEntry = new FileEntry (this, data, relocator);
FileEntry fileEntry = new FileEntry (this, data);
fileEntries.add (fileEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry);
fileEntry.setNode (node);
// why is this being called? it creates every file on the disk
DataSource dataSource = fileEntry.getDataSource (); // reads all buffers
if (fileEntry.fileType == 5 && dataSource instanceof Relocator)
{
relocator = (Relocator) dataSource;
relocator.setDisks (dataDisks);
int size = fileEntry.lastBlock - fileEntry.firstBlock;
relocator.getMultiDiskAddress (fileEntry.name, fileEntry.firstBlock, size);
}
if (fileEntry.fileType == 2 && dataSource instanceof PascalCode)
if (fileEntry.fileType == 2)// && dataSource instanceof PascalCode)
{
node.setAllowsChildren (true);
PascalCode pascalCode = (PascalCode) dataSource;
for (PascalSegment pascalSegment : pascalCode)
{
DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode (
new PascalCodeObject (this, pascalSegment, fileEntry.firstBlock));
node.add (segmentNode);
segmentNode.setAllowsChildren (false);
}
// this does not trigger correctly when opening the arrow
// PascalCode pascalCode = (PascalCode) dataSource;
// for (PascalSegment pascalSegment : pascalCode)
// {
// DefaultMutableTreeNode segmentNode = new DefaultMutableTreeNode (
// new PascalCodeObject (this, pascalSegment, fileEntry.firstBlock));
// node.add (segmentNode);
// segmentNode.setAllowsChildren (false);
// }
}
else
node.setAllowsChildren (false);

View File

@ -3,18 +3,40 @@ package com.bytezone.diskbrowser.wizardry;
import java.util.ArrayList;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import com.bytezone.diskbrowser.applefile.Relocator;
import com.bytezone.diskbrowser.disk.AppleDisk;
import com.bytezone.diskbrowser.disk.Disk;
import com.bytezone.diskbrowser.pascal.FileEntry;
import com.bytezone.diskbrowser.pascal.PascalDisk;
import com.bytezone.diskbrowser.utilities.Utility;
public class Wizardry4BootDisk extends PascalDisk
{
List<AppleDisk> disks = new ArrayList<AppleDisk> ();
protected Disk[] dataDisks;
private Relocator relocator;
public Wizardry4BootDisk (AppleDisk[] dataDisks)
{
super (dataDisks);
super (dataDisks[0]);
this.dataDisks = dataDisks;
DefaultTreeModel model = (DefaultTreeModel) catalogTree.getModel ();
DefaultMutableTreeNode currentRoot = (DefaultMutableTreeNode) model.getRoot ();
DefaultMutableTreeNode relocNode = findNode (currentRoot, "SYSTEM.RELOC");
FileEntry fileEntry = (FileEntry) relocNode.getUserObject ();
if (fileEntry != null)
{
relocator =
new Relocator (fileEntry.getUniqueName (), fileEntry.getDataSource ().buffer);
relocator.createNewBuffer (dataDisks);
fileEntry.setFile (relocator);
}
}
public static boolean isWizardryIV (Disk disk, boolean debug)