mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-12-01 09:50:32 +00:00
wiz4
This commit is contained in:
parent
144c8e2e69
commit
6ad21060b3
@ -4,7 +4,8 @@ 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;
|
||||
|
||||
public class Relocator extends AbstractFile
|
||||
@ -18,9 +19,11 @@ public class Relocator extends AbstractFile
|
||||
|
||||
private final List<MultiDiskAddress> logicalAddresses =
|
||||
new ArrayList<MultiDiskAddress> ();
|
||||
|
||||
private final byte[] diskBlocks = new byte[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)
|
||||
{
|
||||
@ -64,14 +67,26 @@ public class Relocator extends AbstractFile
|
||||
{
|
||||
int lo = diskSegment.logicalBlock;
|
||||
int hi = diskSegment.logicalBlock + diskSegment.segmentLength;
|
||||
int count = 0;
|
||||
for (int i = lo; i < hi; i++)
|
||||
if (diskBlocks[i] == 0)
|
||||
{
|
||||
diskBlocks[i] = disk;
|
||||
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,
|
||||
int length)
|
||||
{
|
||||
@ -117,17 +132,20 @@ public class Relocator extends AbstractFile
|
||||
return foundAddresses;
|
||||
}
|
||||
|
||||
public void addDisk (AppleDisk disk)
|
||||
public void setDisks (Disk[] disks)
|
||||
{
|
||||
byte[] buffer = disk.readSector (1);
|
||||
int diskNo = buffer[510] & 0xFF;
|
||||
if (diskNo > 0 && diskNo <= 5)
|
||||
disks[diskNo - 1] = disk;
|
||||
for (Disk disk : disks)
|
||||
{
|
||||
byte[] buffer = disk.readSector (1);
|
||||
int diskNo = buffer[510] & 0xFF;
|
||||
if (diskNo > 0 && diskNo <= 5)
|
||||
dataDisks[diskNo - 1] = disk;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasData ()
|
||||
{
|
||||
for (AppleDisk disk : disks)
|
||||
for (Disk disk : dataDisks)
|
||||
if (disk == null)
|
||||
return false;
|
||||
return true;
|
||||
|
@ -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);
|
||||
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 ());
|
||||
freeBlocks.set (block, free);
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ public class AppleDisk implements Disk
|
||||
int bufferOffset = 0;
|
||||
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);
|
||||
bufferOffset += sectorSize;
|
||||
}
|
||||
@ -485,12 +485,6 @@ public class AppleDisk implements Disk
|
||||
*/
|
||||
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 sectorSize == SECTOR_SIZE
|
||||
|| 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)
|
||||
{
|
||||
assert sectorSize == SECTOR_SIZE;
|
||||
|
@ -34,8 +34,7 @@ abstract class CatalogEntry implements AppleFileSource
|
||||
bytesUsedInLastBlock = HexFormatter.intValue (buffer[16], buffer[17]);
|
||||
|
||||
Disk disk = parent.getDisk ();
|
||||
int max = Math.min (lastBlock, 0x118);
|
||||
for (int i = firstBlock; i < max; i++)
|
||||
for (int i = firstBlock; i < lastBlock; i++)
|
||||
blocks.add (disk.getDiskAddress (i));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.bytezone.diskbrowser.pascal;
|
||||
|
||||
import com.bytezone.diskbrowser.applefile.*;
|
||||
import com.bytezone.diskbrowser.disk.DiskAddress;
|
||||
import com.bytezone.diskbrowser.utilities.FileFormatException;
|
||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||
|
||||
@ -69,6 +70,8 @@ public class FileEntry extends CatalogEntry
|
||||
if (file != null)
|
||||
return file;
|
||||
|
||||
// this needs to use the Relocator to obtain the currect blocks
|
||||
assembleBuffer ();
|
||||
byte[] buffer = getExactBuffer ();
|
||||
|
||||
switch (fileType)
|
||||
@ -116,6 +119,23 @@ 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);
|
||||
|
@ -21,9 +21,11 @@ public class PascalDisk extends AbstractFormattedDisk
|
||||
{
|
||||
static final int CATALOG_ENTRY_SIZE = 26;
|
||||
private final DateFormat df = DateFormat.getDateInstance (DateFormat.SHORT);
|
||||
private final VolumeEntry volumeEntry;
|
||||
private final PascalCatalogSector diskCatalogSector;
|
||||
private VolumeEntry volumeEntry;
|
||||
private PascalCatalogSector diskCatalogSector;
|
||||
|
||||
protected Relocator relocator;
|
||||
protected Disk[] dataDisks;
|
||||
|
||||
final String[] fileTypes =
|
||||
{ "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 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 ();
|
||||
}
|
||||
|
||||
System.out.println (disk.getTotalBlocks ());
|
||||
private void init ()
|
||||
{
|
||||
sectorTypesList.add (diskBootSector);
|
||||
sectorTypesList.add (catalogSector);
|
||||
sectorTypesList.add (dataSector);
|
||||
@ -104,11 +121,13 @@ public class PascalDisk extends AbstractFormattedDisk
|
||||
fileEntries.add (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)
|
||||
{
|
||||
this.relocator = (Relocator) dataSource;
|
||||
relocator = (Relocator) dataSource;
|
||||
relocator.setDisks (dataDisks);
|
||||
int size = fileEntry.lastBlock - fileEntry.firstBlock;
|
||||
relocator.getMultiDiskAddress (fileEntry.name, fileEntry.firstBlock, size);
|
||||
}
|
||||
|
@ -14,10 +14,7 @@ public class Wizardry4BootDisk extends PascalDisk
|
||||
|
||||
public Wizardry4BootDisk (AppleDisk[] dataDisks)
|
||||
{
|
||||
super (dataDisks[0]);
|
||||
|
||||
for (AppleDisk dataDisk : dataDisks)
|
||||
relocator.addDisk (dataDisk);
|
||||
super (dataDisks);
|
||||
}
|
||||
|
||||
public static boolean isWizardryIV (Disk disk, boolean debug)
|
||||
|
Loading…
Reference in New Issue
Block a user