com.webcodepro.applecommander.storage
Class Disk

java.lang.Object
  extended by com.webcodepro.applecommander.storage.Disk
Direct Known Subclasses:
FormattedDisk

public class Disk
extends java.lang.Object

Abstract representation of an Apple2 disk (floppy, 800k, hard disk).

Date created: Oct 3, 2002 10:59:47 PM

Author:
Rob Greene

Nested Class Summary
 class Disk.FilenameFilter
          Specifies a filter to be used in determining filetypes which are supported.
 
Field Summary
static int APPLE_10MB_HARDDISK
           
static int APPLE_140KB_DISK
           
static int APPLE_140KB_NIBBLE_DISK
           
static int APPLE_20MB_HARDDISK
           
static int APPLE_32MB_HARDDISK
           
static int APPLE_5MB_HARDDISK
           
static int APPLE_800KB_2IMG_DISK
           
static int APPLE_800KB_DISK
           
static int BLOCK_SIZE
           
static int DOS33_SECTORS_ON_140KB_DISK
           
static int PRODOS_BLOCKS_ON_140KB_DISK
           
static int SECTOR_SIZE
           
 
Constructor Summary
  Disk(java.lang.String filename)
          Construct a Disk and load the specified file.
protected Disk(java.lang.String filename, ImageOrder imageOrder)
          Construct a Disk with the given byte array.
 
Method Summary
 ByteArrayImageLayout getDiskImageManager()
          Returns the diskImage.
 java.lang.String getFilename()
          Returns the filename.
static Disk.FilenameFilter[] getFilenameFilters()
          Get the supported file filters supported by the Disk interface.
 FormattedDisk[] getFormattedDisks()
          Determine type of disk, and return the appropriate FormattedDisk object.
 ImageOrder getImageOrder()
          Answer with the phyiscal ordering of the disk.
 int getPhysicalSize()
          Identify the size of this disk.
 boolean hasChanged()
          Indicates if the disk has changed.
protected  boolean is140KbDisk()
          Answers true if this disk image is within the expected 140K disk size.
 boolean is2ImgOrder()
          Indicate if this disk is a 2IMG disk.
protected  boolean is800KbDisk()
          Answers true if this disk image is within the expected 800K disk size.
 boolean isCompressed()
          Indicate if this disk is GZIP compressed.
 boolean isCpmFormat()
          Test the disk format to see if this is a CP/M formatted disk.
 boolean isDosFormat()
          Test the disk format to see if this is a DOS 3.3 formatted disk.
 boolean isDosOrder()
          Indicate if this disk is DOS ordered (T0,S0 - T35,S15).
 boolean isNewImage()
          Indicates if the disk image is new.
 boolean isNibbleOrder()
          Indicate if this disk is a nibbilized disk..
 boolean isOzDosFormat()
          Test the disk format to see if this is a OzDOS formatted disk.
 boolean isPascalFormat()
          Test the disk format to see if this is a Pascal formatted disk.
 boolean isProdosFormat()
          Test the disk format to see if this is a ProDOS formatted disk.
 boolean isProdosOrder()
          Indicate if this disk is ProDOS ordered (beginning with block 0).
 boolean isRdosFormat()
          Test the disk format to see if this is a RDOS formatted disk.
 boolean isUniDosFormat()
          Test the disk format to see if this is a UniDOS formatted disk.
 byte[] readBlock(int block)
          Read the block from the disk image.
 byte[] readSector(int track, int sector)
          Retrieve the specified sector.
protected  void resizeDiskImage(int newSize)
          Resize a disk image up to a larger size.
 void save()
          Save a Disk image to its file.
 void saveAs(java.lang.String filename)
          Save a Disk image as a new/different file.
 void setFilename(java.lang.String filename)
          Sets the filename.
protected  void setImageOrder(ImageOrder imageOrder)
          Set the physical ordering of the disk.
 void writeBlock(int block, byte[] data)
          Write the block to the disk image.
 void writeSector(int track, int sector, byte[] bytes)
          Write the specified sector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCK_SIZE

public static final int BLOCK_SIZE
See Also:
Constant Field Values

SECTOR_SIZE

public static final int SECTOR_SIZE
See Also:
Constant Field Values

PRODOS_BLOCKS_ON_140KB_DISK

public static final int PRODOS_BLOCKS_ON_140KB_DISK
See Also:
Constant Field Values

DOS33_SECTORS_ON_140KB_DISK

public static final int DOS33_SECTORS_ON_140KB_DISK
See Also:
Constant Field Values

APPLE_140KB_DISK

public static final int APPLE_140KB_DISK
See Also:
Constant Field Values

APPLE_140KB_NIBBLE_DISK

public static final int APPLE_140KB_NIBBLE_DISK
See Also:
Constant Field Values

APPLE_800KB_DISK

public static final int APPLE_800KB_DISK
See Also:
Constant Field Values

APPLE_800KB_2IMG_DISK

public static final int APPLE_800KB_2IMG_DISK
See Also:
Constant Field Values

APPLE_5MB_HARDDISK

public static final int APPLE_5MB_HARDDISK
See Also:
Constant Field Values

APPLE_10MB_HARDDISK

public static final int APPLE_10MB_HARDDISK
See Also:
Constant Field Values

APPLE_20MB_HARDDISK

public static final int APPLE_20MB_HARDDISK
See Also:
Constant Field Values

APPLE_32MB_HARDDISK

public static final int APPLE_32MB_HARDDISK
See Also:
Constant Field Values
Constructor Detail

Disk

protected Disk(java.lang.String filename,
               ImageOrder imageOrder)
Construct a Disk with the given byte array.


Disk

public Disk(java.lang.String filename)
     throws java.io.IOException
Construct a Disk and load the specified file. Read in the entire contents of the file.

Throws:
java.io.IOException
Method Detail

getFilenameFilters

public static Disk.FilenameFilter[] getFilenameFilters()
Get the supported file filters supported by the Disk interface. This is due to the fact that FilenameFilter is an innerclass of Disk - without an instance of the class, the filters cannot be created.


save

public void save()
          throws java.io.IOException
Save a Disk image to its file.

Throws:
java.io.IOException

saveAs

public void saveAs(java.lang.String filename)
            throws java.io.IOException
Save a Disk image as a new/different file.

Throws:
java.io.IOException

getFormattedDisks

public FormattedDisk[] getFormattedDisks()
Determine type of disk, and return the appropriate FormattedDisk object. Returns null if none are recognized.


getDiskImageManager

public ByteArrayImageLayout getDiskImageManager()
Returns the diskImage.

Returns:
byte[]

getFilename

public java.lang.String getFilename()
Returns the filename.

Returns:
String

setFilename

public void setFilename(java.lang.String filename)
Sets the filename.


isCompressed

public boolean isCompressed()
Indicate if this disk is GZIP compressed.


isProdosOrder

public boolean isProdosOrder()
Indicate if this disk is ProDOS ordered (beginning with block 0).


isDosOrder

public boolean isDosOrder()
Indicate if this disk is DOS ordered (T0,S0 - T35,S15).


is2ImgOrder

public boolean is2ImgOrder()
Indicate if this disk is a 2IMG disk. This is ProDOS ordered, but with a header on the disk.


isNibbleOrder

public boolean isNibbleOrder()
Indicate if this disk is a nibbilized disk..


getPhysicalSize

public int getPhysicalSize()
Identify the size of this disk.


resizeDiskImage

protected void resizeDiskImage(int newSize)
Resize a disk image up to a larger size. The primary intention is to "fix" disk images that have been created too small. The primary culprit is ApplePC HDV images which dynamically grow. Since AppleCommander works with a byte array, the image must grow to its full size.

Parameters:
newSize -

readBlock

public byte[] readBlock(int block)
Read the block from the disk image.


writeBlock

public void writeBlock(int block,
                       byte[] data)
Write the block to the disk image.


readSector

public byte[] readSector(int track,
                         int sector)
                  throws java.lang.IllegalArgumentException
Retrieve the specified sector.

Throws:
java.lang.IllegalArgumentException

writeSector

public void writeSector(int track,
                        int sector,
                        byte[] bytes)
                 throws java.lang.IllegalArgumentException
Write the specified sector.

Throws:
java.lang.IllegalArgumentException

isProdosFormat

public boolean isProdosFormat()
Test the disk format to see if this is a ProDOS formatted disk.


isDosFormat

public boolean isDosFormat()
Test the disk format to see if this is a DOS 3.3 formatted disk. This is a little nasty - since 800KB and 140KB images have different characteristics. This just tests 140KB images.


isUniDosFormat

public boolean isUniDosFormat()
Test the disk format to see if this is a UniDOS formatted disk. UniDOS creates two logical disks on an 800KB physical disk. The first logical disk takes up the first 400KB and the second logical disk takes up the second 400KB.


isOzDosFormat

public boolean isOzDosFormat()
Test the disk format to see if this is a OzDOS formatted disk. OzDOS creates two logical disks on an 800KB physical disk. The first logical disk takes the first half of each block and the second logical disk takes the second half of each block.


isPascalFormat

public boolean isPascalFormat()
Test the disk format to see if this is a Pascal formatted disk. Pascal disks may be either 140K or 800K.


isCpmFormat

public boolean isCpmFormat()
Test the disk format to see if this is a CP/M formatted disk. Check the first 256 bytes of the CP/M directory for validity.


is140KbDisk

protected boolean is140KbDisk()
Answers true if this disk image is within the expected 140K disk size. Can vary if a header has been applied or if this is a nibblized disk image.


is800KbDisk

protected boolean is800KbDisk()
Answers true if this disk image is within the expected 800K disk size. Can vary if a 2IMG header has been applied.


isRdosFormat

public boolean isRdosFormat()
Test the disk format to see if this is a RDOS formatted disk.


hasChanged

public boolean hasChanged()
Indicates if the disk has changed. Triggered when data is written and cleared when data is saved.


isNewImage

public boolean isNewImage()
Indicates if the disk image is new. This can be used for Save As processing.


getImageOrder

public ImageOrder getImageOrder()
Answer with the phyiscal ordering of the disk.


setImageOrder

protected void setImageOrder(ImageOrder imageOrder)
Set the physical ordering of the disk.