Removed experimental code, repaired 13 sector and unidos handling.

This commit is contained in:
Denis Molony 2020-04-20 17:46:56 +10:00
parent 65bcec4e90
commit 0b032b13f5
10 changed files with 40 additions and 282 deletions

View File

@ -557,4 +557,15 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
actionListenerList
.actionPerformed (new ActionEvent (this, ActionEvent.ACTION_PERFORMED, text));
}
// ---------------------------------------------------------------------------------//
@Override
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("Block size..... %d%n", disk.getBlockSize ()));
text.append (String.format ("Interleave..... %d", disk.getInterleave ()));
return text.toString ();
}
}

View File

@ -1,137 +0,0 @@
package com.bytezone.diskbrowser.disk;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.bytezone.diskbrowser.utilities.FileFormatException;
// -----------------------------------------------------------------------------------//
public class AppleDisk2 implements Disk2
// -----------------------------------------------------------------------------------//
{
File file;
int totalBlocks;
int fileOffset;
int blockSize;
BlockReader blockReader;
List<AppleDisk2Address> addressList = new ArrayList<> ();
private final byte[] diskBuffer; // contains the disk contents in memory
// ---------------------------------------------------------------------------------//
public AppleDisk2 (File file, int blocks, int blockSize) throws FileFormatException
// ---------------------------------------------------------------------------------//
{
this (file, blocks, blockSize, 0);
}
// ---------------------------------------------------------------------------------//
public AppleDisk2 (File file, int totalBlocks, int blockSize, int fileOffset)
throws FileFormatException
// ---------------------------------------------------------------------------------//
{
this.file = file;
this.totalBlocks = totalBlocks;
this.fileOffset = fileOffset;
diskBuffer = new byte[totalBlocks * blockSize];
try (BufferedInputStream in = new BufferedInputStream (new FileInputStream (file)))
{
if (fileOffset > 0)
in.skip (fileOffset);
int bytesRead = in.read (diskBuffer);
}
catch (IOException e)
{
e.printStackTrace ();
throw new FileFormatException (e.getMessage ());
}
}
// ---------------------------------------------------------------------------------//
@Override
public Iterator<AppleDisk2Address> iterator ()
// ---------------------------------------------------------------------------------//
{
return addressList.iterator ();
}
// ---------------------------------------------------------------------------------//
@Override
public File getFile ()
// ---------------------------------------------------------------------------------//
{
return file;
}
// ---------------------------------------------------------------------------------//
@Override
public int getBlockSize ()
// ---------------------------------------------------------------------------------//
{
return blockSize;
}
// ---------------------------------------------------------------------------------//
@Override
public boolean isValidAddress (int blockNo)
// ---------------------------------------------------------------------------------//
{
return blockNo >= 0 && blockNo < totalBlocks;
}
// ---------------------------------------------------------------------------------//
@Override
public int getTotalBlocks ()
// ---------------------------------------------------------------------------------//
{
return totalBlocks;
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] getBlock (int blockNo)
// ---------------------------------------------------------------------------------//
{
return blockReader.readBlock (blockNo);
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] getDiskBuffer ()
// ---------------------------------------------------------------------------------//
{
return diskBuffer;
}
// ---------------------------------------------------------------------------------//
@Override
public void setBlockReader (BlockReader blockReader)
// ---------------------------------------------------------------------------------//
{
this.blockReader = blockReader;
}
// ---------------------------------------------------------------------------------//
@Override
public void read (byte[] buffer, int diskOffset, int length)
// ---------------------------------------------------------------------------------//
{
System.arraycopy (diskBuffer, diskOffset, buffer, 0, length);
}
// ---------------------------------------------------------------------------------//
@Override
public void read (byte[] buffer, int diskOffset, int bufferOffset, int length)
// ---------------------------------------------------------------------------------//
{
System.arraycopy (diskBuffer, diskOffset, buffer, bufferOffset, length);
}
}

View File

@ -1,37 +0,0 @@
package com.bytezone.diskbrowser.disk;
// -----------------------------------------------------------------------------------//
public class AppleDisk2Address implements Disk2Address
//-----------------------------------------------------------------------------------//
{
private Disk2 disk;
private int blockNo;
private byte[] buffer;
// ---------------------------------------------------------------------------------//
public AppleDisk2Address (Disk2 disk, int blockNo) throws Exception
// ---------------------------------------------------------------------------------//
{
this.disk = disk;
this.blockNo = blockNo;
}
// ---------------------------------------------------------------------------------//
@Override
public int getBlockNo ()
// ---------------------------------------------------------------------------------//
{
return blockNo;
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] getBlock ()
// ---------------------------------------------------------------------------------//
{
if (buffer == null)
buffer = disk.getBlock (blockNo);
return buffer;
}
}

View File

@ -1,53 +0,0 @@
package com.bytezone.diskbrowser.disk;
import java.util.List;
// -----------------------------------------------------------------------------------//
public class BasicBlockReader implements BlockReader
// -----------------------------------------------------------------------------------//
{
Disk2 disk;
// ---------------------------------------------------------------------------------//
public BasicBlockReader (Disk2 disk)
// ---------------------------------------------------------------------------------//
{
this.disk = disk;
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] readBlock (int blockNo)
// ---------------------------------------------------------------------------------//
{
byte[] buffer = new byte[disk.getBlockSize ()];
int offset = disk.getBlockSize () * blockNo;
System.arraycopy (disk.getDiskBuffer (), offset, buffer, offset, buffer.length);
return buffer;
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] readBlock (Disk2Address diskAddress)
// ---------------------------------------------------------------------------------//
{
return readBlock (diskAddress.getBlockNo ());
}
// ---------------------------------------------------------------------------------//
@Override
public byte[] readBlocks (List<Disk2Address> diskAddresses)
// ---------------------------------------------------------------------------------//
{
int blockSize = disk.getBlockSize ();
byte[] buffer = new byte[diskAddresses.size () * blockSize];
int ptr = 0;
for (Disk2Address diskAddress : diskAddresses)
{
disk.read (buffer, diskAddress.getBlockNo () * disk.getBlockSize (), ptr,
blockSize);
ptr += blockSize;
}
return buffer;
}
}

View File

@ -1,12 +0,0 @@
package com.bytezone.diskbrowser.disk;
import java.util.List;
public interface BlockReader
{
public byte[] readBlock (int blockNo);
public byte[] readBlock (Disk2Address diskAddress);
public byte[] readBlocks (List<Disk2Address> diskAddresses);
}

View File

@ -1,26 +0,0 @@
package com.bytezone.diskbrowser.disk;
import java.io.File;
// -----------------------------------------------------------------------------------//
public interface Disk2 extends Iterable<AppleDisk2Address>
//-----------------------------------------------------------------------------------//
{
public File getFile ();
public int getBlockSize (); // bytes per block - 256 or 512
public int getTotalBlocks (); // blocks per disk - usually 560 or 280
public boolean isValidAddress (int blockNo);
public byte[] getDiskBuffer ();
public byte[] getBlock (int blockNo);
public void setBlockReader (BlockReader blockReader);
public void read (byte[] buffer, int diskOffset, int length);
public void read (byte[] buffer, int diskOffset, int bufferOffset, int length);
}

View File

@ -1,10 +0,0 @@
package com.bytezone.diskbrowser.disk;
// -----------------------------------------------------------------------------------//
public interface Disk2Address
//-----------------------------------------------------------------------------------//
{
public int getBlockNo ();
public byte[] getBlock ();
}

View File

@ -48,6 +48,19 @@ public class DiskFactory
// ---------------------------------------------------------------------------------//
public static FormattedDisk createDisk (String path)
// ---------------------------------------------------------------------------------//
{
FormattedDisk disk = create (path);
if (disk.getDisk ().getInterleave () > 0)
{
System.out.println (disk);
System.out.println ();
}
return disk;
}
// ---------------------------------------------------------------------------------//
private static FormattedDisk create (String path)
// ---------------------------------------------------------------------------------//
{
if (debug)
System.out.println ("\nFactory : " + path);

View File

@ -277,14 +277,20 @@ public class DosDisk extends AbstractFormattedDisk
return true;
}
if (disk.getBlocksPerTrack () > 16)
int blocksPerTrack = disk.getBlocksPerTrack ();
if (blocksPerTrack > 16 && blocksPerTrack != 32) // 32 = unidos
{
if (debug)
System.out.printf ("Blocks per track: %d", blocksPerTrack);
return false;
}
int[] cb = new int[3];
int best = 0;
int il = -1;
int max = disk.getBlocksPerTrack () == 16 ? 3 : 1; // no interleave for 13 sector?
for (int interleave = 0; interleave < 3; interleave++)
for (int interleave = 0; interleave < max; interleave++)
{
if (debug)
System.out.printf ("Checking interleave %d%n", interleave);
@ -442,15 +448,15 @@ public class DosDisk extends AbstractFormattedDisk
public String toString ()
// ---------------------------------------------------------------------------------//
{
// StringBuffer text = new StringBuffer (dosVTOCSector.toString ());
// return text.toString ();
StringBuffer text = new StringBuffer ();
StringBuilder text = new StringBuilder ();
text.append (String.format ("Disk name ............. %s%n", getDisplayPath ()));
text.append (
String.format ("DOS version ........... %s%n", dosVTOCSector.dosVersion));
text.append (
String.format ("Sectors per track ..... %d%n", dosVTOCSector.maxSectors));
text.append (String.format ("Volume no ............. %d", volumeNo));
text.append (String.format ("Volume no ............. %d%n", volumeNo));
text.append (String.format ("Interleave ............ %d", disk.getInterleave ()));
return text.toString ();
}

View File

@ -335,12 +335,14 @@ public class ProdosDisk extends AbstractFormattedDisk
public String toString ()
// ---------------------------------------------------------------------------------//
{
StringBuffer text = new StringBuffer ();
StringBuilder text = new StringBuilder ();
String newLine = String.format ("%n");
VolumeDirectoryHeader volumeDirectory = (VolumeDirectoryHeader) headerEntries.get (0);
String timeC = volumeDirectory.created == null ? ""
: df.format (volumeDirectory.created.getTime ());
text.append (String.format ("Disk name : %s%n", getDisplayPath ()));
text.append ("Volume name : " + volumeDirectory.name + newLine);
text.append ("Creation date : " + timeC + newLine);
text.append ("ProDOS version : " + volumeDirectory.version + newLine);
@ -351,6 +353,7 @@ public class ProdosDisk extends AbstractFormattedDisk
text.append ("File count : " + volumeDirectory.fileCount + newLine);
text.append ("Bitmap block : " + volumeDirectory.bitMapBlock + newLine);
text.append ("Total blocks : " + volumeDirectory.totalBlocks + newLine);
text.append (String.format ("Interleave : %d", disk.getInterleave ()));
return text.toString ();
}