jmce - 1_02

jmce.sim.disk
Class AbstractDisk

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.sim.disk.AbstractDisk
All Implemented Interfaces:
Disk, Hardware, Peripheral
Direct Known Subclasses:
ImageDisk, MemoryDisk, NullDisk

public abstract class AbstractDisk
extends AbstractPeripheral
implements Disk

Abstract implementation of Disk.

Subclass must implements only the write and read method to access the phisical disk and if necessary can override the mount and dismount method.

Version:
1.01
Author:
Mario Viara

Field Summary
protected  byte[] buffer
          Buffer for one sector
protected  int head
          Disk current position
protected  boolean mounted
           
protected  int numHead
           
protected  int numSector
           
protected  int numTrack
           
protected  boolean readOnly
           
protected  int sector
          Disk current position
protected  int sectorSize
           
protected  int track
          Disk current position
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Fields inherited from interface jmce.sim.Disk
ERROR, ERROR_SEEK, ERROR_WRITE_PROTECT
 
Constructor Summary
AbstractDisk()
          Default contructor.
AbstractDisk(int track, int head, int sector, int ssize)
          Constructor with the specified geometry.
 
Method Summary
 void dismount()
          Dismount the disk
 void format()
          Format one track.
 byte[] getBuffer()
          Return one array used for data transfer.
 int getDiskSize()
           
 java.lang.String getDiskSizeString()
           
 int getHead()
          Get the current head
 int getNumHead()
          Return the number of head
 int getNumSector()
          Return the number of sector
 int getNumTrack()
          Return the numebr of track
 boolean getReadOnly()
          Return true if the disk is read only.
 int getSector()
          Get the current sector
 int getSectorSize()
          Return the sector size in bytes
 int getTrack()
          Get the current track
 boolean isMounted()
          Retrun true if the disk is mounted.
 boolean mount()
          Mount the disk.
 int read()
          Read one sector.
protected abstract  int read(int pos)
          Read one sector.
 int read(int track, int head, int sector)
           
 void setHead(int head)
          Set the head number
protected  boolean setMounted(boolean b)
           
 void setNumHead(int h)
          Set the number of head.
 void setNumSector(int s)
          Set the number of sector.
 void setNumTrack(int t)
          Set the number of track.
 void setReadOnly(boolean mode)
          Set the read only status for the disk.
 void setSector(int sector)
          Set the sector number
 void setSectorSize(int size)
          Set the sector size in byte.
 void setTrack(int track)
          Set the track number
 int write()
          Write one sector.
protected abstract  int write(int pos)
          Write one sector.
 int write(int track, int head, int sector)
           
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Peripheral
idle, registerCPU
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 

Field Detail

numTrack

protected int numTrack

numHead

protected int numHead

numSector

protected int numSector

sectorSize

protected int sectorSize

mounted

protected boolean mounted

readOnly

protected boolean readOnly

buffer

protected byte[] buffer
Buffer for one sector


track

protected int track
Disk current position


head

protected int head
Disk current position


sector

protected int sector
Disk current position

Constructor Detail

AbstractDisk

public AbstractDisk()
Default contructor. Create a disk wit IBM 3740 geometry.


AbstractDisk

public AbstractDisk(int track,
                    int head,
                    int sector,
                    int ssize)
Constructor with the specified geometry.

Parameters:
track - - Number of track.
head - - Number of head.
sector - - Number of sector.
ssize - - Sector size in bytes.
Method Detail

setNumTrack

public void setNumTrack(int t)
Description copied from interface: Disk
Set the number of track. Set the total number of track. vlaid track number are 0 to track -1.

Specified by:
setNumTrack in interface Disk
Parameters:
t - - Number of track.

getNumTrack

public int getNumTrack()
Description copied from interface: Disk
Return the numebr of track

Specified by:
getNumTrack in interface Disk

setNumSector

public void setNumSector(int s)
Description copied from interface: Disk
Set the number of sector. Set the toral number of sector. Valid sector number are 1 to sector.

Specified by:
setNumSector in interface Disk
Parameters:
s - - Total number of sector.

getNumSector

public int getNumSector()
Description copied from interface: Disk
Return the number of sector

Specified by:
getNumSector in interface Disk

setNumHead

public void setNumHead(int h)
Description copied from interface: Disk
Set the number of head. Set the total number of head. Valid head number are 0 to head - 1.

Specified by:
setNumHead in interface Disk
Parameters:
h - - Number of head.

getNumHead

public int getNumHead()
Description copied from interface: Disk
Return the number of head

Specified by:
getNumHead in interface Disk

setSectorSize

public void setSectorSize(int size)
Description copied from interface: Disk
Set the sector size in byte.

Specified by:
setSectorSize in interface Disk

getBuffer

public byte[] getBuffer()
Description copied from interface: Disk
Return one array used for data transfer. Is responsabity of the disk alloc one array of byte and use it for data transfer.

Specified by:
getBuffer in interface Disk
Returns:
The array for one sector.

dismount

public void dismount()
              throws SIMException
Description copied from interface: Disk
Dismount the disk

Specified by:
dismount in interface Disk
Throws:
SIMException

isMounted

public boolean isMounted()
Description copied from interface: Disk
Retrun true if the disk is mounted.

Specified by:
isMounted in interface Disk

setMounted

protected boolean setMounted(boolean b)

mount

public boolean mount()
              throws SIMException
Description copied from interface: Disk
Mount the disk.

Specified by:
mount in interface Disk
Returns:
true if the disk is correctly mounted.
Throws:
SIMException

read

public int read(int track,
                int head,
                int sector)
         throws SIMException
Throws:
SIMException

read

public int read()
         throws SIMException
Description copied from interface: Disk
Read one sector. The specified sector is readed form the disk and the data are moved in the allocated buffer.

Specified by:
read in interface Disk
Returns:
number of bytes readed.
Throws:
SIMException
See Also:
Disk.getBuffer()

write

public int write(int track,
                 int head,
                 int sector)
          throws SIMException
Throws:
SIMException

write

public int write()
          throws SIMException
Description copied from interface: Disk
Write one sector. Before to call this function data must be moved in the allocated buffer.

Specified by:
write in interface Disk
Returns:
number of bytes written.
Throws:
SIMException

getSectorSize

public int getSectorSize()
Description copied from interface: Disk
Return the sector size in bytes

Specified by:
getSectorSize in interface Disk

getSector

public int getSector()
Description copied from interface: Disk
Get the current sector

Specified by:
getSector in interface Disk

getHead

public int getHead()
Description copied from interface: Disk
Get the current head

Specified by:
getHead in interface Disk

getTrack

public int getTrack()
Description copied from interface: Disk
Get the current track

Specified by:
getTrack in interface Disk

setHead

public void setHead(int head)
Description copied from interface: Disk
Set the head number

Specified by:
setHead in interface Disk

setSector

public void setSector(int sector)
Description copied from interface: Disk
Set the sector number

Specified by:
setSector in interface Disk

setTrack

public void setTrack(int track)
Description copied from interface: Disk
Set the track number

Specified by:
setTrack in interface Disk

format

public void format()
            throws SIMException
Format one track. For one simulator format means write a default pattern in all sector of the disk

Specified by:
format in interface Disk
Throws:
SIMException

write

protected abstract int write(int pos)
                      throws SIMException
Write one sector. Write one sector at specified position. Must be implemented by subclass.

Returns:
the number of bytes written.
Throws:
SIMException

read

protected abstract int read(int pos)
                     throws SIMException
Read one sector. Read one sector at specified position. Must be implemented by subclass.

Returns:
the number of bytes readed.
Throws:
SIMException

getDiskSize

public int getDiskSize()

getDiskSizeString

public java.lang.String getDiskSizeString()

getReadOnly

public boolean getReadOnly()
Return true if the disk is read only.

Specified by:
getReadOnly in interface Disk
Since:
1.01

setReadOnly

public void setReadOnly(boolean mode)
Set the read only status for the disk.

Specified by:
setReadOnly in interface Disk
Since:
1.01

jmce - 1_02