jfrace.device
Class CPMDisk

java.lang.Object
  |
  +--jfrace.device.CPMDisk

public class CPMDisk
extends java.lang.Object

Class which provides a file as a disk for the CP/M emulator.

Author:
Franz-Josef Elmer

Field Summary
static int READ
          Type of action event for reading data.
static int WRITE
          Type of action event for writing data.
 
Constructor Summary
CPMDisk(int size)
          Create an empty disk.
CPMDisk(java.lang.String diskName)
          Create a disk from the data of the file diskName.
CPMDisk(java.net.URL source)
          Create a disk from the data of an URL source.
 
Method Summary
 void add(java.lang.String fileName)
          Add a file of the real file system to this CP/M disk.
 void addActionListener(java.awt.event.ActionListener al)
          Add an interested listener for reading/writing events.
 boolean calculateDiskParameters()
          Calculate the disk parameters by analyzing the raw data of the disk.
 void finalize()
          Save changed data to the file given in the constructor.
 byte getByte(int address)
          Get a byte.
 int getNumberOfSectorsPerTrack()
          Return the number of sectors per track.
 int getNumberOfSystemTracks()
          Return the number of system tracks.
 int getNumberOfTracks()
          Return the number of tracks.
 boolean isUnchanged()
          Return true if nothing has been written to this disk.
 boolean loadCCPBDOS(AddressSpace as)
          Load CCP and BDOS from the system tracks.
 boolean readSector(int track, int sector, AddressSpace as, int destination)
          Read a logical sector from the disk.
 void removeActionListener(java.awt.event.ActionListener al)
          Remove a listener for reading/writing events.
 void setDiskParameters(AddressSpace as, int address)
          Set disk parameters.
 int translateSector(int sector)
          Translate a logical sector number into a corresponding logical sector number on the disk.
 boolean writeSector(int track, int sector, AddressSpace as, int source)
          Write a logical sector to the disk.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ

public static final int READ
Type of action event for reading data.

WRITE

public static final int WRITE
Type of action event for writing data.
Constructor Detail

CPMDisk

public CPMDisk(java.lang.String diskName)
        throws java.io.IOException
Create a disk from the data of the file diskName. The raw data of the disk will be read from the given file. Changed data will be written back to the file in the finalize method.
Throws:
java.io.IOException - in the case of a reading error.

CPMDisk

public CPMDisk(java.net.URL source)
        throws java.io.IOException
Create a disk from the data of an URL source. The raw data of the disk will be read from the source. Changed data will not be written back.
Parameters:
source - URL source of the raw data.
Throws:
java.io.IOException - in the case of a reading error.
See Also:
finalize

CPMDisk

public CPMDisk(int size)
Create an empty disk. Empty disks are used to make files of the real disk system (i.e. not the CP/M disk system) available for the CP/M emulator. Changes made by the emulator will not be made persistent.
Parameters:
size - Number of bytes of the disk.
Method Detail

getNumberOfSectorsPerTrack

public int getNumberOfSectorsPerTrack()
Return the number of sectors per track.

getNumberOfSystemTracks

public int getNumberOfSystemTracks()
Return the number of system tracks.

getNumberOfTracks

public int getNumberOfTracks()
Return the number of tracks.

calculateDiskParameters

public boolean calculateDiskParameters()
Calculate the disk parameters by analyzing the raw data of the disk.
Returns:
true if successful

setDiskParameters

public void setDiskParameters(AddressSpace as,
                              int address)
Set disk parameters.
Parameters:
as - Address space.
address - Start address in the address space.

translateSector

public int translateSector(int sector)
Translate a logical sector number into a corresponding logical sector number on the disk. This method is needed for implementing the BIOS method SECTRAN.
Parameters:
sector - Sector number from [0, numberOfSectorsPerTrack).
Returns:
translated sector number from [1, numberOfSectorsPerTrack].

finalize

public void finalize()
Save changed data to the file given in the constructor. Data of disks created with constructor for empty disk will not be saved.
Overrides:
finalize in class java.lang.Object

addActionListener

public void addActionListener(java.awt.event.ActionListener al)
Add an interested listener for reading/writing events.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener al)
Remove a listener for reading/writing events.

isUnchanged

public boolean isUnchanged()
Return true if nothing has been written to this disk.

add

public void add(java.lang.String fileName)
Add a file of the real file system to this CP/M disk. This method only works for instances created with the constructor for empty disk before the first invocation of the write method.
Parameters:
fileName - Name of the file to be added.

loadCCPBDOS

public boolean loadCCPBDOS(AddressSpace as)
Load CCP and BDOS from the system tracks. The method first searches for the COPYRIGHT text of the CCP. From the jump address of the CCP it determines the destination.
Parameters:
as - Address space of the destination.
Returns:
true if loading was successful.

getByte

public byte getByte(int address)
Get a byte.
Parameters:
address - Absolute address of a byte of the disk.
Returns:
the byte at address.

readSector

public boolean readSector(int track,
                          int sector,
                          AddressSpace as,
                          int destination)
Read a logical sector from the disk.
Parameters:
track - Track number.
sector - Sector number.
as - Address space.
destination - Address in the address space.
Returns:
true in the case of successful reading.

writeSector

public boolean writeSector(int track,
                           int sector,
                           AddressSpace as,
                           int source)
Write a logical sector to the disk.
Parameters:
track - Track number.
sector - Sector number.
source - Address in the address space.
destination - Address in the address space.
Returns:
true in the case of successful writing.