preparing for new disk stuff

This commit is contained in:
Denis Molony 2020-04-12 22:09:14 +10:00
parent fbd55d4ae9
commit 65bcec4e90
8 changed files with 277 additions and 2 deletions

View File

@ -40,7 +40,7 @@ public class AppleDisk implements Disk
private int interleave = 0;
private static int[][] interleaveSector = //
{ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }, // None
22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }, // None
{ 0, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 15 }, // Prodos/Pascal
{ 0, 13, 11, 9, 7, 5, 3, 1, 14, 12, 10, 8, 6, 4, 2, 15 }, // Infocom
{ 0, 6, 12, 3, 9, 15, 14, 5, 11, 2, 8, 7, 13, 4, 10, 1 } }; // CPM

View File

@ -0,0 +1,137 @@
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

@ -0,0 +1,37 @@
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

@ -0,0 +1,53 @@
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

@ -0,0 +1,12 @@
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

@ -0,0 +1,26 @@
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

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

View File

@ -42,7 +42,7 @@ public class DosDisk extends AbstractFormattedDisk
protected List<AppleFileSource> deletedFileEntries = new ArrayList<> ();
private static boolean debug = true;
private static boolean debug = false;
enum FileType
{