- Enclosing interface:
- GBCartridge
public static interface GBCartridge.Header
The header of a Game Boy cartridge. Changes to the header are reflected in the cartridge, and
vice-versa.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intThe number of bytes reserved for the Nintendo logo.static intThe maximum RAM size, in bytes.static intThe maximum ROM size, in bytes.static intThe minimum ROM size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionbytechecksum()Returns the checksum of some header data.byteComputes the checksum of some header data (as returned bychecksum()) from the current header contents.booleanReturns the destination code.shortReturns the address to which the console's boot procedure jumps after initialization.bytegbc()Returns the value of the GBC flag.static byte[]Returns the Nintendo logo expected by the console.shortReturns the checksum of the entire ROM.booleanReturns whether the cartridge supports GBC functions.booleanReturns whether the cartridge supports SGB functions.booleanReturns whether the cartridge is supposed to be sold in Japan.shortlicensee()Returns the licensee code, which indicates the company or publisher of the cartridge.byte[]logo()Returns the Nintendo logo bitmap.voidlogo(byte[] dest)Copies the Nintendo logo bitmap into the given array.Returns the 4-character uppercase manufacturer code, only present in GBC cartridges.byteramSize()Returns the RAM size code.intReturns the RAM size, if any.booleanReturns whether the cartridge requires a GBC console to run.byteromSize()Returns the ROM size code.intReturns the ROM size.byteSets the header checksum to the value returned bycomputeChecksum().voidsetChecksum(byte checksum)Sets the header checksum.voidsetDestination(boolean destination)Sets the destination code.voidsetEntryPoint(short entryPoint)Sets the entry point address.voidsetGbc(byte value)Sets the GBC flag.voidsetGlobalChecksum(short checksum)Sets the global checksum.voidsetLogo(byte[] source)Sets the Nintendo logo bitmap.voidsetManufacturer(String manufacturer)Sets the cartridge manufacturer.voidsetNewLicensee(short licensee)Sets the licensee code, following the new format.voidsetOldLicensee(byte licensee)Sets the licensee code, following the old format.voidsetRamSize(byte code)Sets the RAM size code.voidsetRomSize(byte code)Sets the ROM size code.voidsetSgb(byte value)Sets the SGB flag.voidSets the cartridge title.voidsetType(GBCartridge.Type type)Sets the cartridge type.voidSets the valid Nintendo logo.voidsetVersion(byte version)Sets the cartridge version.bytesgb()Returns the value of the SGB flag.title()Returns the 16-character uppercase cartridge title.@Nullable GBCartridge.Typetype()Specifies the type of the cartridge.byteversion()Returns the cartridge version.
-
Field Details
-
LOGO_LENGTH
static final int LOGO_LENGTHThe number of bytes reserved for the Nintendo logo.- See Also:
- Constant Field Values
-
MIN_ROM_BYTES
static final int MIN_ROM_BYTESThe minimum ROM size, in bytes.- See Also:
- Constant Field Values
-
MAX_ROM_BYTES
static final int MAX_ROM_BYTESThe maximum ROM size, in bytes.- See Also:
- Constant Field Values
-
MAX_RAM_BYTES
static final int MAX_RAM_BYTESThe maximum RAM size, in bytes.- See Also:
- Constant Field Values
-
-
Method Details
-
entryPoint
short entryPoint()Returns the address to which the console's boot procedure jumps after initialization.The entry point area is a 4-byte region whose sole purpose is to jump to this address. It usually contains a
NOPinstruction followed by aJPorCALL.- Returns:
- the entry point address
- Throws:
IllegalStateException- if the entry point area contains noJPorCALLinstruction
-
setEntryPoint
void setEntryPoint(short entryPoint)Sets the entry point address. This writes aNOPinstruction followed by an unconditional jump to the given address.- Parameters:
entryPoint- the entry point address
-
getValidLogo
static byte[] getValidLogo()Returns the Nintendo logo expected by the console.- Returns:
- a copy of the valid logo
- See Also:
for details on verification
-
logo
byte[] logo()Returns the Nintendo logo bitmap.If incorrect, the console's boot procedure locks up in an infinite loop. Some console models partially verify the contents of the logo. For example, the GBC only verifies the first 18 bytes of the returned array.
- Returns:
- a copy of the logo
-
logo
void logo(byte[] dest)Copies the Nintendo logo bitmap into the given array.- Parameters:
dest- the destination array- Throws:
IllegalArgumentException- if the length ofdestis notLOGO_LENGTH- See Also:
for details on verification
-
setLogo
void setLogo(byte[] source)Sets the Nintendo logo bitmap.- Parameters:
source- the logo- Throws:
IllegalArgumentException- if the length ofsourceis notLOGO_LENGTH- See Also:
for details on verification
-
setValidLogo
void setValidLogo()Sets the valid Nintendo logo.- See Also:
to get a copy of the valid logo
-
title
String title()Returns the 16-character uppercase cartridge title.- Returns:
- the cartridge title
-
setTitle
Sets the cartridge title.- Parameters:
title- the cartridge title- Throws:
IllegalArgumentException- if the value has a length greater than 16, or contains non-ASCII or non-uppercase characters
-
manufacturer
String manufacturer()Returns the 4-character uppercase manufacturer code, only present in GBC cartridges.- Returns:
- the manufacturer code
-
setManufacturer
Sets the cartridge manufacturer.- Parameters:
manufacturer- the cartridge manufacturer- Throws:
IllegalArgumentException- if the value has a length greater than 4, or contains non-ASCII or non-uppercase characters
-
gbc
byte gbc()Returns the value of the GBC flag.- Returns:
- the GBC flag value
-
setGbc
void setGbc(byte value)Sets the GBC flag.- Parameters:
value- the GBC flag
-
hasColorFunctions
boolean hasColorFunctions()Returns whether the cartridge supports GBC functions.- Returns:
trueif the cartridge supports GBC functions- See Also:
to check if the cartridge requires a GBC to run
-
requiresColor
boolean requiresColor()Returns whether the cartridge requires a GBC console to run.- Returns:
trueif the cartridge requires a GBC to run
-
licensee
short licensee()Returns the licensee code, which indicates the company or publisher of the cartridge.- Returns:
- the licensee code
-
setOldLicensee
void setOldLicensee(byte licensee)Sets the licensee code, following the old format.- Parameters:
licensee- the licensee code
-
setNewLicensee
void setNewLicensee(short licensee)Sets the licensee code, following the new format.- Parameters:
licensee- the licensee code
-
sgb
byte sgb()Returns the value of the SGB flag.- Returns:
- the SGB flag value
-
setSgb
void setSgb(byte value)Sets the SGB flag.- Parameters:
value- the SGB flag
-
hasSuperFunctions
boolean hasSuperFunctions()Returns whether the cartridge supports SGB functions.- Returns:
trueif the cartridge supports SGB functions
-
type
@Nullable GBCartridge.Type type()Specifies the type of the cartridge.- Returns:
- the cartridge type, or
nullif unknown
-
setType
Sets the cartridge type.- Parameters:
type- the cartridge type
-
romSize
byte romSize()Returns the ROM size code.- Returns:
- the ROM size code
-
romSizeBytes
int romSizeBytes()Returns the ROM size.- Returns:
- the ROM size, in bytes
-
setRomSize
void setRomSize(byte code)Sets the ROM size code.Note that the cartridge may not support this configuration. In particular, sizes larger than
32 KBrequire a memory bank controller.- Parameters:
code- the ROM size code- Throws:
IllegalArgumentException- if the code is invalid
-
ramSize
byte ramSize()Returns the RAM size code.- Returns:
- the RAM size code
-
ramSizeBytes
int ramSizeBytes()Returns the RAM size, if any.- Returns:
- the RAM size, in bytes
- Throws:
IllegalStateException- if the current RAM size code is invalid
-
setRamSize
void setRamSize(byte code)Sets the RAM size code.Note that the cartridge may not support this configuration.
- Parameters:
code- the RAM size code- Throws:
IllegalArgumentException- if the code is invalid
-
destination
boolean destination()Returns the destination code.- Returns:
- the destination code
-
japaneseDistribution
boolean japaneseDistribution()Returns whether the cartridge is supposed to be sold in Japan.- Returns:
trueif the cartridge is solely distributed in Japan
-
setDestination
void setDestination(boolean destination)Sets the destination code.- Parameters:
destination- the destination code
-
version
byte version()Returns the cartridge version.- Returns:
- the version
-
setVersion
void setVersion(byte version)Sets the cartridge version.- Parameters:
version- the version
-
checksum
byte checksum()Returns the checksum of some header data. If incorrect, the console's boot procedure locks up in an infinite loop.- Returns:
- the header checksum
-
computeChecksum
byte computeChecksum()Computes the checksum of some header data (as returned bychecksum()) from the current header contents.- Returns:
- the computed header checksum
-
setChecksum
void setChecksum(byte checksum)Sets the header checksum.- Parameters:
checksum- the header checksum
-
setChecksum
byte setChecksum()Sets the header checksum to the value returned bycomputeChecksum().- Returns:
- the computed checksum
- See Also:
to compute, but not overwrite, the header checksum
-
globalChecksum
short globalChecksum()Returns the checksum of the entire ROM. Unlike the header checksum, the console boots even if incorrect.- Returns:
- the global checksum
-
setGlobalChecksum
void setGlobalChecksum(short checksum)Sets the global checksum.- Parameters:
checksum- the global checksum
-