This commit is contained in:
Denis Molony 2016-08-08 20:34:25 +10:00
parent 144c8e2e69
commit 6ad21060b3
7 changed files with 98 additions and 27 deletions

View File

@ -4,7 +4,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class Relocator extends AbstractFile public class Relocator extends AbstractFile
@ -18,9 +19,11 @@ public class Relocator extends AbstractFile
private final List<MultiDiskAddress> logicalAddresses = private final List<MultiDiskAddress> logicalAddresses =
new ArrayList<MultiDiskAddress> (); new ArrayList<MultiDiskAddress> ();
private final byte[] diskBlocks = new byte[0x800]; private final byte[] diskBlocks = new byte[0x800];
private final int[] diskOffsets = new int[0x800]; private final int[] diskOffsets = new int[0x800];
private final AppleDisk[] disks = new AppleDisk[5]; private final int[] diskOffsets2 = new int[0x800];
private final Disk[] dataDisks = new Disk[5];
public Relocator (String name, byte[] buffer) public Relocator (String name, byte[] buffer)
{ {
@ -64,14 +67,26 @@ public class Relocator extends AbstractFile
{ {
int lo = diskSegment.logicalBlock; int lo = diskSegment.logicalBlock;
int hi = diskSegment.logicalBlock + diskSegment.segmentLength; int hi = diskSegment.logicalBlock + diskSegment.segmentLength;
int count = 0;
for (int i = lo; i < hi; i++) for (int i = lo; i < hi; i++)
if (diskBlocks[i] == 0) if (diskBlocks[i] == 0)
{ {
diskBlocks[i] = disk; diskBlocks[i] = disk;
diskOffsets[i] = diskSegment.physicalBlock; diskOffsets[i] = diskSegment.physicalBlock;
diskOffsets2[i] = diskSegment.physicalBlock + count++;
} }
} }
public byte[] getLogicalBuffer (DiskAddress da)
{
int block = da.getBlock ();
System.out.println (diskBlocks[block]);
Disk disk = dataDisks[diskBlocks[block] - 1];
System.out.println (diskOffsets2[block]);
System.out.println (disk);
return disk.readSector (diskOffsets2[block]);
}
public List<MultiDiskAddress> getMultiDiskAddress (String name, int blockNumber, public List<MultiDiskAddress> getMultiDiskAddress (String name, int blockNumber,
int length) int length)
{ {
@ -117,17 +132,20 @@ public class Relocator extends AbstractFile
return foundAddresses; return foundAddresses;
} }
public void addDisk (AppleDisk disk) public void setDisks (Disk[] disks)
{ {
byte[] buffer = disk.readSector (1); for (Disk disk : disks)
int diskNo = buffer[510] & 0xFF; {
if (diskNo > 0 && diskNo <= 5) byte[] buffer = disk.readSector (1);
disks[diskNo - 1] = disk; int diskNo = buffer[510] & 0xFF;
if (diskNo > 0 && diskNo <= 5)
dataDisks[diskNo - 1] = disk;
}
} }
public boolean hasData () public boolean hasData ()
{ {
for (AppleDisk disk : disks) for (Disk disk : dataDisks)
if (disk == null) if (disk == null)
return false; return false;
return true; return true;

View File

@ -367,7 +367,7 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
System.out.printf ("Block %d not in range : 0-%d%n", block, freeBlocks.size () - 1); System.out.printf ("Block %d not in range : 0-%d%n", block, freeBlocks.size () - 1);
return; return;
} }
// assert block < freeBlocks.size () : String.format ("Set free block # %6d, size %6d", //assert block < freeBlocks.size () : String.format ("Set free block # %6d, size %6d",
// block, freeBlocks.size ()); // block, freeBlocks.size ());
freeBlocks.set (block, free); freeBlocks.set (block, free);
} }

View File

@ -361,7 +361,7 @@ public class AppleDisk implements Disk
int bufferOffset = 0; int bufferOffset = 0;
for (DiskAddress da : daList) for (DiskAddress da : daList)
{ {
if (da != null) // text files may have gaps if (da != null) // sparse text files may have gaps
readBuffer (da, buffer, bufferOffset); readBuffer (da, buffer, bufferOffset);
bufferOffset += sectorSize; bufferOffset += sectorSize;
} }
@ -485,12 +485,6 @@ public class AppleDisk implements Disk
*/ */
private void readBuffer (DiskAddress da, byte[] buffer, int bufferOffset) private void readBuffer (DiskAddress da, byte[] buffer, int bufferOffset)
{ {
if (da.getDisk () != this)
{
System.out.println (da.getDisk ());
System.out.println (this);
}
assert da.getDisk () == this : "Disk address not applicable to this disk"; assert da.getDisk () == this : "Disk address not applicable to this disk";
assert sectorSize == SECTOR_SIZE assert sectorSize == SECTOR_SIZE
|| sectorSize == BLOCK_SIZE : "Invalid sector size : " + sectorSize; || sectorSize == BLOCK_SIZE : "Invalid sector size : " + sectorSize;
@ -513,6 +507,30 @@ public class AppleDisk implements Disk
} }
} }
private void writeBuffer (DiskAddress da, byte[] buffer, int bufferOffset)
{
assert da.getDisk () == this : "Disk address not applicable to this disk";
assert sectorSize == SECTOR_SIZE
|| sectorSize == BLOCK_SIZE : "Invalid sector size : " + sectorSize;
assert interleave >= 0 && interleave <= MAX_INTERLEAVE : "Invalid interleave : "
+ interleave;
if (sectorSize == SECTOR_SIZE)
{
int diskOffset = getBufferOffset (da);
System.arraycopy (buffer, bufferOffset, diskBuffer, diskOffset, SECTOR_SIZE);
}
else
{
int diskOffset = getBufferOffset (da, 0);
System.arraycopy (buffer, bufferOffset, diskBuffer, diskOffset, SECTOR_SIZE);
diskOffset = getBufferOffset (da, 1);
System.arraycopy (buffer, bufferOffset + SECTOR_SIZE, diskBuffer, diskOffset,
SECTOR_SIZE);
}
}
private int getBufferOffset (DiskAddress da) private int getBufferOffset (DiskAddress da)
{ {
assert sectorSize == SECTOR_SIZE; assert sectorSize == SECTOR_SIZE;

View File

@ -34,8 +34,7 @@ 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 ();
int max = Math.min (lastBlock, 0x118); for (int i = firstBlock; i < lastBlock; i++)
for (int i = firstBlock; i < max; i++)
blocks.add (disk.getDiskAddress (i)); blocks.add (disk.getDiskAddress (i));
} }

View File

@ -1,6 +1,7 @@
package com.bytezone.diskbrowser.pascal; package com.bytezone.diskbrowser.pascal;
import com.bytezone.diskbrowser.applefile.*; import com.bytezone.diskbrowser.applefile.*;
import com.bytezone.diskbrowser.disk.DiskAddress;
import com.bytezone.diskbrowser.utilities.FileFormatException; import com.bytezone.diskbrowser.utilities.FileFormatException;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
@ -69,6 +70,8 @@ public class FileEntry extends CatalogEntry
if (file != null) if (file != null)
return file; return file;
// this needs to use the Relocator to obtain the currect blocks
assembleBuffer ();
byte[] buffer = getExactBuffer (); byte[] buffer = getExactBuffer ();
switch (fileType) switch (fileType)
@ -116,6 +119,23 @@ public class FileEntry extends CatalogEntry
return file; 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 () private byte[] getExactBuffer ()
{ {
byte[] buffer = parent.getDisk ().readSectors (blocks); byte[] buffer = parent.getDisk ().readSectors (blocks);

View File

@ -21,9 +21,11 @@ public class PascalDisk extends AbstractFormattedDisk
{ {
static final int CATALOG_ENTRY_SIZE = 26; static final int CATALOG_ENTRY_SIZE = 26;
private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT); private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT);
private final VolumeEntry volumeEntry; private VolumeEntry volumeEntry;
private final PascalCatalogSector diskCatalogSector; private PascalCatalogSector diskCatalogSector;
protected Relocator relocator; protected Relocator relocator;
protected Disk[] dataDisks;
final String[] fileTypes = final String[] fileTypes =
{ "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" }; { "Volume", "Xdsk", "Code", "Text", "Info", "Data", "Graf", "Foto", "SecureDir" };
@ -37,11 +39,26 @@ public class PascalDisk extends AbstractFormattedDisk
SectorType grafSector = new SectorType ("Graf", Color.cyan); SectorType grafSector = new SectorType ("Graf", Color.cyan);
SectorType fotoSector = new SectorType ("Foto", Color.gray); 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) public PascalDisk (Disk disk)
{ {
super (disk); super (disk);
init ();
}
System.out.println (disk.getTotalBlocks ()); private void init ()
{
sectorTypesList.add (diskBootSector); sectorTypesList.add (diskBootSector);
sectorTypesList.add (catalogSector); sectorTypesList.add (catalogSector);
sectorTypesList.add (dataSector); sectorTypesList.add (dataSector);
@ -104,11 +121,13 @@ public class PascalDisk extends AbstractFormattedDisk
fileEntries.add (fileEntry); fileEntries.add (fileEntry);
DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry); DefaultMutableTreeNode node = new DefaultMutableTreeNode (fileEntry);
DataSource dataSource = fileEntry.getDataSource (); // 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) if (fileEntry.fileType == 5 && dataSource instanceof Relocator)
{ {
this.relocator = (Relocator) dataSource; relocator = (Relocator) dataSource;
relocator.setDisks (dataDisks);
int size = fileEntry.lastBlock - fileEntry.firstBlock; int size = fileEntry.lastBlock - fileEntry.firstBlock;
relocator.getMultiDiskAddress (fileEntry.name, fileEntry.firstBlock, size); relocator.getMultiDiskAddress (fileEntry.name, fileEntry.firstBlock, size);
} }

View File

@ -14,10 +14,7 @@ public class Wizardry4BootDisk extends PascalDisk
public Wizardry4BootDisk (AppleDisk[] dataDisks) public Wizardry4BootDisk (AppleDisk[] dataDisks)
{ {
super (dataDisks[0]); super (dataDisks);
for (AppleDisk dataDisk : dataDisks)
relocator.addDisk (dataDisk);
} }
public static boolean isWizardryIV (Disk disk, boolean debug) public static boolean isWizardryIV (Disk disk, boolean debug)