Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## tapeutils.zx81
Class PFile

    java.lang.Object
      tapeutils.zx81.PFile

public class PFile
extends java.lang.Object

This class provides utilities that act on the contents of a .P file.

It is possible to list the contents, play as a tape signal, or save the tape signal to a sampled sound file.

Author:
  hldswrth

Constructor Summary
`PFile(byte[] fileBytes, java.lang.String programName)` Construct the .P file from a byte array of the file's contents.
`PFile(java.io.File file, java.lang.String programName)` Construct from a file.

Method Summary
`byte` | `getByte(int index)` Returns a byte from the file content.
`byte[]` | `getBytes()` Returns all the bytes in the file content.
`int` | `getDisplayEndOffset()` Get the offset in the file of the end of the display.
`int` | `getProgramEndOffset()` Get the offset in the file of the end of the program.
`int` | `getTotalFileLength()` Get the total length of the file, according to the system variable values.
`void` | `list(boolean outputSystem, boolean outputVariables, boolean outputDisplay, boolean dumpNumberValues)` List the requested parts of the file.
`java.lang.String` | `listDisplay(boolean print)` List the display.
`java.lang.String` | `listProgram(boolean print, boolean dumpNumberValues)` List the program.
`java.lang.String` | `listSystemVariables(boolean print)` Get the system variables.
`java.lang.String` | `listVariables(boolean print)` List the program variables.
`void` | `play(float frequency, boolean squareWave)` Play the contents of the .P file as a sound sample.
`void` | `write(java.io.OutputStream output)` Write the contents of the .P file to the output stream.
`void` | `writeSampleToFile(float frequency, java.io.File sampleFile, boolean squareWave)` Write the contents of the .P file as a sound sample.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PFile

    public PFile(java.io.File file,
                 java.lang.String programName)
          throws java.io.IOException

  Construct from a file.

  The program name is required as it is not in the .P file itself.

Parameters:
  `file` - The file.
  `programName` - The name of the program.
Throws:
  `java.io.IOException` - An error occurred reading from the file.

### PFile

    public PFile(byte[] fileBytes,
                 java.lang.String programName)

  Construct the .P file from a byte array of the file's contents.

  The program name is required as it is not in the .P file itself.

Parameters:
  `fileBytes` - The file bytes.
  `programName` - The name of the program.

Method Detail

### list

    public void list(boolean outputSystem,
                     boolean outputVariables,
                     boolean outputDisplay,
                     boolean dumpNumberValues)

  List the requested parts of the file.

  Parameters:
    `outputSystem` - Indicates whether to output system variables.
    `outputVariables` - Indicates whether to output program variables.
    `outputDisplay` - Indicates whether to output the display.
    `dumpNumberValues` - Indicates whether to dump number values in BASIC listing.

### listSystemVariables

    public java.lang.String listSystemVariables(boolean print)

  Get the system variables.

  Parameters:
    `print` -
  Returns:
    A string containing the system variable output.

### listProgram

    public java.lang.String listProgram(boolean print,
                                        boolean dumpNumberValues)

  List the program.

  Parameters:
    `print` -
    `dumpNumberValues` - Indicates whether to dump number values.
  Returns:
    A string containing the program output.

### listDisplay

    public java.lang.String listDisplay(boolean print)

  List the display.

  Parameters:
    `print` -
  Returns:
    A string containing the display output.

### listVariables

    public java.lang.String listVariables(boolean print)

  List the program variables.

  Parameters:
    `print` -
  Returns:
    A string containing the variables output.

### getTotalFileLength

    public int getTotalFileLength()

  Get the total length of the file, according to the system variable values.

  Returns:
    The total length of the file.

### getProgramEndOffset

    public int getProgramEndOffset()

  Get the offset in the file of the end of the program.

  Returns:
    The end of program offset.

### getDisplayEndOffset

    public int getDisplayEndOffset()

  Get the offset in the file of the end of the display.

  Returns:
    The end of display offset.

### write

    public void write(java.io.OutputStream output)
               throws java.io.IOException

  Write the contents of the .P file to the output stream.

  Parameters:
    `output` - The output stream.
  Throws:
    `java.io.IOException` - An error occurred writing to the stream.

### getByte

    public byte getByte(int index)

  Returns a byte from the file content.

  Parameters:
    `index` - The index of the byte.
  Returns:
    The byte.

### getBytes

    public byte[] getBytes()

  Returns all the bytes in the file content.

  Returns:
    The bytes.

### writeSampleToFile

    public void writeSampleToFile(float frequency,
                                  java.io.File sampleFile,
                                  boolean squareWave)
                           throws java.io.IOException

  Write the contents of the .P file as a sound sample.

  The format of the sample is determined by the file extension.

  Parameters:
    `frequency` - The sample frequency.
    `sampleFile` - The sample file.
    `squareWave` - Indicates whether to use a square wave.
  Throws:
    `java.io.IOException` - An error occurred writing the sample file.

### play

    public void play(float frequency,
                     boolean squareWave)
              throws javax.sound.sampled.LineUnavailableException

  Play the contents of the .P file as a sound sample.

  Parameters:
    `frequency` - The sample frequency.
    `squareWave` - Indicates whether to use a square wave.
  Throws:
    `javax.sound.sampled.LineUnavailableException` - The resources are not available to play the sound.

Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD