Interface GBACartridge

All Superinterfaces:
AutoCloseable, Cartridge

public interface GBACartridge extends Cartridge
A Game Boy Advance cartridge.
See Also:
GBATEK, GBA by R. Ziegler
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Indicates the entry point and size of the Debugging and Communication System (DACS) memory, used by the Nintendo hardware debugger when the debugging handler is enabled.
    static class 
    The world region where a cartridge is distributed.
    static interface 
    The header of a Game Boy Advance cartridge.
    static class 
    Specifies additional hardware present in the cartridge.
  • Method Summary

    Modifier and Type
    Method
    Description
    getAscii​(long offset, int length)
    Decodes length bytes to characters using the StandardCharsets.US_ASCII charset, beginning at the given offset in the cartridge.
    byte
    getByte​(long offset)
    Reads the byte at the given offset.
    void
    getBytes​(long offset, byte[] dest)
    Transfers bytes from the cartridge into the given array, beginning at the given offset in the cartridge.
    void
    getBytes​(long offset, byte[] dest, int destOffset, int length)
    Transfers length bytes from the cartridge into the given array, beginning at the given offset in the cartridge and at the given offset in the array.
    int
    getInt​(long offset)
    Reads the int at the given offset.
    long
    getLong​(long offset)
    Reads the long at the given offset.
    short
    getShort​(long offset)
    Reads the short at the given offset.
    getString​(long offset, int length, Charset charset)
    Decodes length bytes to characters using the given charset, beginning at the given offset in the cartridge.
    int
    getUnsignedByte​(long offset)
    Reads the unsigned byte at the given offset.
    long
    getUnsignedInt​(long offset)
    Reads the unsigned int at the given offset.
    int
    getUnsignedShort​(long offset)
    Reads the unsigned short at the given offset.
    getUtf8​(long offset, int length)
    Decodes length bytes to characters using the StandardCharsets.UTF_8 charset, beginning at the given offset in the cartridge.
    Returns the cartridge header.
    read​(InputStream stream)
    Reads a cartridge from the given stream.
    read​(Path path)
    Reads a cartridge from the given path.
    readAscii​(int length)
    Decodes length bytes to characters using the StandardCharsets.US_ASCII charset, beginning at the cartridge's current offset, which is then incremented by length.
    byte
    Reads the byte at the cartridge's current offset, and then increments the offset.
    void
    readBytes​(byte[] dest)
    Transfers bytes from the cartridge into the given array, beginning at the cartridge's current offset, which is then incremented by dest.length.
    void
    readBytes​(byte[] dest, int destOffset, int length)
    Transfers length bytes from the cartridge into the given array, beginning at the cartridge's current offset and at the given offset in the array.
    int
    Reads the int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
    long
    Reads the long at the cartridge's current offset, and then increments the offset by Long.BYTES.
    short
    Reads the short at the cartridge's current offset, and then increments the offset by Short.BYTES.
    readString​(int length, Charset charset)
    Decodes length bytes to characters using the given charset, beginning at the cartridge's current offset, which is then incremented by length.
    int
    Reads the unsigned byte at the cartridge's current offset, and then increments the offset.
    long
    Reads the unsigned int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
    int
    Reads the unsigned short at the cartridge's current offset, and then increments the offset by Short.BYTES.
    readUtf8​(int length)
    Decodes length bytes to characters using the StandardCharsets.UTF_8 charset, beginning at the cartridge's current offset, which is then incremented by length.
    int
    setAscii​(long offset, CharSequence sequence)
    Writes the encoded characters using the StandardCharsets.US_ASCII charset, beginning at the given offset in the cartridge.
    void
    setByte​(long offset, byte value)
    Writes the given byte at the given offset.
    void
    setBytes​(long offset, byte[] source)
    Transfers bytes from the given array into the cartridge, beginning at the given offset in the cartridge.
    void
    setBytes​(long offset, byte[] source, int sourceOffset, int length)
    Transfers length bytes from the given array into the cartridge, beginning at the given offset in the cartridge and at the given offset in the array.
    void
    setInt​(long offset, int value)
    Writes the given int at the given offset.
    void
    setLong​(long offset, long value)
    Writes the given long at the given offset.
    void
    setShort​(long offset, short value)
    Writes the given short at the given offset.
    int
    setString​(long offset, CharSequence sequence, Charset charset)
    Writes the encoded characters using the given charset, beginning at the given offset in the cartridge.
    void
    setUnsignedByte​(long offset, int value)
    Writes the given unsigned byte at the given offset.
    void
    setUnsignedInt​(long offset, long value)
    Writes the given unsigned int at the given offset.
    void
    setUnsignedShort​(long offset, int value)
    Writes the given unsigned short at the given offset.
    int
    setUtf8​(long offset, CharSequence sequence)
    Writes the encoded characters using the StandardCharsets.UTF_8 charset, beginning at the given offset in the cartridge.
    int
    writeAscii​(CharSequence sequence)
    Writes the encoded characters using the StandardCharsets.US_ASCII charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
    void
    writeByte​(byte value)
    Writes the given byte at the cartridge's current offset, and then increments the offset.
    void
    writeBytes​(byte[] source)
    Transfers the entire content of the given array into the cartridge, beginning at the cartridge's current offset, which is then incremented by source.length.
    void
    writeBytes​(byte[] source, int sourceOffset, int length)
    Transfers length bytes from the given array into the cartridge, beginning at the cartridge's current offset and at the given offset in the array.
    void
    writeInt​(int value)
    Writes the given int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
    void
    writeLong​(long value)
    Writes the given long at the cartridge's current offset, and then increments the offset by Long.BYTES.
    void
    writeShort​(short value)
    Writes the given short at the cartridge's current offset, and then increments the offset by Short.BYTES.
    int
    writeString​(CharSequence sequence, Charset charset)
    Writes the encoded characters using the given charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
    void
    writeUnsignedByte​(int value)
    Writes the given unsigned byte at the cartridge's current offset, and then increments the offset.
    void
    writeUnsignedInt​(long value)
    Writes the given unsigned int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
    void
    writeUnsignedShort​(int value)
    Writes the given unsigned short at the cartridge's current offset, and then increments the offset by Short.BYTES.
    int
    writeUtf8​(CharSequence sequence)
    Writes the encoded characters using the StandardCharsets.UTF_8 charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.

    Methods inherited from interface me.hugmanrique.cartage.Cartridge

    close, copyFrom, copyTo, copyTo, copyTo, hasRemaining, offset, order, order, remaining, setOffset, size, skip
  • Method Details

    • read

      static GBACartridge read(Path path) throws IOException
      Reads a cartridge from the given path.
      Parameters:
      path - the path
      Returns:
      the read cartridge
      Throws:
      IOException - if an I/O error occurs
    • read

      static GBACartridge read(InputStream stream) throws IOException
      Reads a cartridge from the given stream. The stream is not closed.
      Parameters:
      stream - the input stream
      Returns:
      the read cartridge
      Throws:
      IOException - if an I/O error occurs
    • header

      Returns the cartridge header.
      Returns:
      the header
    • readByte

      byte readByte()
      Reads the byte at the cartridge's current offset, and then increments the offset.
      Returns:
      the byte value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is 0
    • getByte

      byte getByte(long offset)
      Reads the byte at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the byte value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than or equal to Cartridge.size()
    • readUnsignedByte

      int readUnsignedByte()
      Reads the unsigned byte at the cartridge's current offset, and then increments the offset.
      Returns:
      the unsigned byte value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is 0
    • getUnsignedByte

      int getUnsignedByte(long offset)
      Reads the unsigned byte at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the unsigned byte value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than or equal to Cartridge.size()
    • writeByte

      void writeByte(byte value)
      Writes the given byte at the cartridge's current offset, and then increments the offset.
      Parameters:
      value - the byte value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is 0
    • setByte

      void setByte(long offset, byte value)
      Writes the given byte at the given offset.
      Parameters:
      offset - the offset to write to
      value - the byte value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than or equal to Cartridge.size()
    • writeUnsignedByte

      void writeUnsignedByte(int value)
      Writes the given unsigned byte at the cartridge's current offset, and then increments the offset.
      Parameters:
      value - the unsigned byte value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is 0
    • setUnsignedByte

      void setUnsignedByte(long offset, int value)
      Writes the given unsigned byte at the given offset.
      Parameters:
      offset - the offset to write to
      value - the byte value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than or equal to Cartridge.size()
    • readShort

      short readShort()
      Reads the short at the cartridge's current offset, and then increments the offset by Short.BYTES.
      Returns:
      the short value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Short.BYTES.
    • getShort

      short getShort(long offset)
      Reads the short at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the short value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Short#BYTES})
    • readUnsignedShort

      int readUnsignedShort()
      Reads the unsigned short at the cartridge's current offset, and then increments the offset by Short.BYTES.
      Returns:
      the unsigned short value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Short.BYTES.
    • getUnsignedShort

      int getUnsignedShort(long offset)
      Reads the unsigned short at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the unsigned short value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than {@link Cartridge#size()} - {@link Short#BYTES}
    • writeShort

      void writeShort(short value)
      Writes the given short at the cartridge's current offset, and then increments the offset by Short.BYTES.
      Parameters:
      value - the short value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Short.BYTES
    • setShort

      void setShort(long offset, short value)
      Writes the given short at the given offset.
      Parameters:
      offset - the offset to write to
      value - the short value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Short#BYTES})
    • writeUnsignedShort

      void writeUnsignedShort(int value)
      Writes the given unsigned short at the cartridge's current offset, and then increments the offset by Short.BYTES.
      Parameters:
      value - the unsigned short value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Short.BYTES
    • setUnsignedShort

      void setUnsignedShort(long offset, int value)
      Writes the given unsigned short at the given offset.
      Parameters:
      offset - the offset to write to
      value - the unsigned short value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Short#BYTES})
    • readInt

      int readInt()
      Reads the int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
      Returns:
      the int value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Integer.BYTES.
    • getInt

      int getInt(long offset)
      Reads the int at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the int value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Integer#BYTES})
    • readUnsignedInt

      long readUnsignedInt()
      Reads the unsigned int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
      Returns:
      the unsigned int value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Integer.BYTES.
    • getUnsignedInt

      long getUnsignedInt(long offset)
      Reads the unsigned int at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the unsigned int value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Integer#BYTES})
    • writeInt

      void writeInt(int value)
      Writes the given int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
      Parameters:
      value - the int value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Integer.BYTES
    • setInt

      void setInt(long offset, int value)
      Writes the given int at the given offset.
      Parameters:
      offset - the offset to write to
      value - the int value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Integer#BYTES})
    • writeUnsignedInt

      void writeUnsignedInt(long value)
      Writes the given unsigned int at the cartridge's current offset, and then increments the offset by Integer.BYTES.
      Parameters:
      value - the unsigned int value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Integer.BYTES
    • setUnsignedInt

      void setUnsignedInt(long offset, long value)
      Writes the given unsigned int at the given offset.
      Parameters:
      offset - the offset to write to
      value - the unsigned int value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Integer#BYTES})
    • readLong

      long readLong()
      Reads the long at the cartridge's current offset, and then increments the offset by Long.BYTES.
      Returns:
      the long value at the current offset
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Long.BYTES.
    • getLong

      long getLong(long offset)
      Reads the long at the given offset.
      Parameters:
      offset - the offset to read from
      Returns:
      the long value at the given offset
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Long#BYTES})
    • writeLong

      void writeLong(long value)
      Writes the given long at the cartridge's current offset, and then increments the offset by Long.BYTES.
      Parameters:
      value - the long value to write
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than Long.BYTES
    • setLong

      void setLong(long offset, long value)
      Writes the given long at the given offset.
      Parameters:
      offset - the offset to write to
      value - the long value to write
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - {@link Long#BYTES})
    • readBytes

      void readBytes(byte[] dest)
      Transfers bytes from the cartridge into the given array, beginning at the cartridge's current offset, which is then incremented by dest.length.
      Parameters:
      dest - the destination array
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than dest.length
    • readBytes

      void readBytes(byte[] dest, int destOffset, int length)
      Transfers length bytes from the cartridge into the given array, beginning at the cartridge's current offset and at the given offset in the array. The cartridge's offset is then incremented by length.
      Parameters:
      dest - the destination array
      destOffset - the offset within the array of the first byte to be written
      length - the number of bytes to be written
      Throws:
      IndexOutOfBoundsException - if destOffset is out of bounds, i.e. less than 0 or greater than dest.length - destOffset; or Cartridge.remaining() is less than length
    • getBytes

      void getBytes(long offset, byte[] dest)
      Transfers bytes from the cartridge into the given array, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge from which the first byte will be read
      dest - the destination array
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - dest.length)
    • getBytes

      void getBytes(long offset, byte[] dest, int destOffset, int length)
      Transfers length bytes from the cartridge into the given array, beginning at the given offset in the cartridge and at the given offset in the array.
      Parameters:
      offset - the offset in the cartridge from which the first byte will be read
      dest - the destination array
      destOffset - the offset within the array of the first byte to be written
      length - the number of bytes to be written
      Throws:
      IndexOutOfBoundsException - if offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - length); or destOffset is out of bounds, i.e. less than 0 or greater than dest.length - length; or Cartridge.remaining() is less than length
    • writeBytes

      void writeBytes(byte[] source)
      Transfers the entire content of the given array into the cartridge, beginning at the cartridge's current offset, which is then incremented by source.length.
      Parameters:
      source - the source array
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than source.length
    • writeBytes

      void writeBytes(byte[] source, int sourceOffset, int length)
      Transfers length bytes from the given array into the cartridge, beginning at the cartridge's current offset and at the given offset in the array. The cartridge's offset is then incremented by length.
      Parameters:
      source - the source array
      sourceOffset - the offset within the array of the first byte to be read
      length - the number of bytes to be written
      Throws:
      IndexOutOfBoundsException - if sourceOffset is out of bounds, i.e. less than 0 or greater than (source.length - sourceOffset); or Cartridge.remaining() is less than length
    • setBytes

      void setBytes(long offset, byte[] source)
      Transfers bytes from the given array into the cartridge, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge at which the first byte will be written
      source - the source array
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than {@link Cartridge#remaining()} - source.length
    • setBytes

      void setBytes(long offset, byte[] source, int sourceOffset, int length)
      Transfers length bytes from the given array into the cartridge, beginning at the given offset in the cartridge and at the given offset in the array.
      Parameters:
      offset - the offset in the cartridge at which the first byte will be written
      source - the source array
      sourceOffset - the offset within the array of the first byte to be read
      length - the number of bytes to be written
      Throws:
      IndexOutOfBoundsException - if offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - length); or sourceOffset is out of bounds, i.e. less than 0 or greater than (source.length - length); or Cartridge.remaining() is less than length
    • readString

      String readString(int length, Charset charset)
      Decodes length bytes to characters using the given charset, beginning at the cartridge's current offset, which is then incremented by length.
      Parameters:
      length - the number of bytes to be read
      charset - the charset to be used
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than length
    • getString

      String getString(long offset, int length, Charset charset)
      Decodes length bytes to characters using the given charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge from which the first byte will be read
      length - the number of bytes to be read
      charset - the charset to be used
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - length)
    • readAscii

      String readAscii(int length)
      Decodes length bytes to characters using the StandardCharsets.US_ASCII charset, beginning at the cartridge's current offset, which is then incremented by length.
      Parameters:
      length - the number of bytes to be read
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than length
    • getAscii

      String getAscii(long offset, int length)
      Decodes length bytes to characters using the StandardCharsets.US_ASCII charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge from which the first byte will be read
      length - the number of bytes to be read
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - length)
    • readUtf8

      String readUtf8(int length)
      Decodes length bytes to characters using the StandardCharsets.UTF_8 charset, beginning at the cartridge's current offset, which is then incremented by length.
      Parameters:
      length - the number of bytes to be read
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than length
    • getUtf8

      String getUtf8(long offset, int length)
      Decodes length bytes to characters using the StandardCharsets.UTF_8 charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge from which the first byte will be read
      length - the number of bytes to be read
      Returns:
      a string containing the decoded characters
      Throws:
      IndexOutOfBoundsException - if offset is out of bounds, i.e. less than 0 or greater than ({@link Cartridge#size()} - length)
    • writeString

      int writeString(CharSequence sequence, Charset charset)
      Writes the encoded characters using the given charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
      Parameters:
      sequence - the sequence of characters to be encoded
      charset - the charset to be used
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining()} is less than the number of bytes to be written
    • setString

      int setString(long offset, CharSequence sequence, Charset charset)
      Writes the encoded characters using the given charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge at which the first byte will be written
      sequence - the sequence of characters to be encoded
      charset - the charset to be used
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than Cartridge.size() minus the number of bytes to be written
    • writeAscii

      int writeAscii(CharSequence sequence)
      Writes the encoded characters using the StandardCharsets.US_ASCII charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
      Parameters:
      sequence - the sequence of characters to be encoded
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than the number of bytes to be written
    • setAscii

      int setAscii(long offset, CharSequence sequence)
      Writes the encoded characters using the StandardCharsets.US_ASCII charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge at which the first byte will be written
      sequence - the sequence of characters to be encoded
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than Cartridge.size() minus the number of bytes to be written
    • writeUtf8

      int writeUtf8(CharSequence sequence)
      Writes the encoded characters using the StandardCharsets.UTF_8 charset, beginning at the cartridge's current offset, which is then incremented by the number of written bytes.
      Parameters:
      sequence - the sequence of characters to be encoded
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if Cartridge.remaining() is less than the number of bytes to be written
    • setUtf8

      int setUtf8(long offset, CharSequence sequence)
      Writes the encoded characters using the StandardCharsets.UTF_8 charset, beginning at the given offset in the cartridge.
      Parameters:
      offset - the offset in the cartridge at which the first byte will be written
      sequence - the sequence of characters to be encoded
      Returns:
      the number of bytes written to the cartridge
      Throws:
      IndexOutOfBoundsException - if the given offset is out of bounds, i.e. less than 0 or greater than Cartridge.size() minus the number of bytes to be written