Class FileLoader.Block

java.lang.Object
net.emustudio.emulib.io.FileLoader.Block
Enclosing class:
FileLoader

public static final class FileLoader.Block extends Object
Immutable block of a file.

BIN/HEX blocks carry plain bytes. Tape blocks carry an ID and the original block body: TAP blocks have ID 0x10 and body = flag, data and checksum; TZX bodies contain all fields after the block ID.

  • Method Details

    • getFormat

      public FileLoader.Format getFormat()
      Returns:
      format of the file this block comes from
    • getAddress

      public OptionalInt getAddress()
      Returns:
      HEX block address; empty for BIN and tape blocks
    • getId

      public int getId()
      Returns:
      tape block ID (TAP blocks have 0x10), or -1 for BIN/HEX blocks
    • getData

      public byte[] getData() throws IOException
      Returns BIN/HEX bytes, or a Spectrum data packet (flag, data, checksum) of TAP, TZX 0x10 and TZX 0x11 blocks.
      Returns:
      copy of the data
      Throws:
      IOException - if this tape block has no data packet
    • getSpectrumHeader

      public Optional<FileLoader.SpectrumHeader> getSpectrumHeader() throws IOException
      Returns:
      Spectrum header, if this is a 19-byte data packet with flag 0
      Throws:
      IOException - if this tape block has no data packet
    • getUsedBitsInLastByte

      public int getUsedBitsInLastByte() throws IOException
      Returns:
      number of used bits in the last byte of the data packet (8 except for TZX turbo blocks)
      Throws:
      IOException - if this tape block has no data packet
    • hasValidChecksum

      public boolean hasValidChecksum() throws IOException
      Returns:
      true if XOR of the data packet bytes (including flag and checksum) is zero
      Throws:
      IOException - if this is not a tape block with a data packet