Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.nio.charset.Charset;
- /**
- * Represents a single Gameboy or Gameboy Color ROM.
- *
- * @author Ryan Greene
- *
- */
- public final class ROM {
- /**
- * The file where the ROM is located.
- */
- private final File file;
- /**
- * The input stream used to read the ROM.
- */
- private final InputStream input;
- /**
- * The bytes which make up the ROM.
- */
- private final byte[] data;
- /**
- * Title of the game in UPPER CASE ASCII. If it is less than 16 characters
- * then the remaining bytes are filled with 00's. When inventing the CGB,
- * Nintendo has reduced the length of this area to 15 characters, and some
- * months later they had the fantastic idea to reduce it to 11 characters
- * only.
- */
- private final String title;
- /**
- * In older cartridges this area has been part of the Title, in newer
- * cartridges this area contains an 4 character uppercase manufacturer code.
- * Purpose and Deeper Meaning unknown.
- */
- private final String manufacturerCode;
- /**
- * In older cartridges this byte has been part of the Title. In CGB
- * cartridges the upper bit is used to enable CGB functions. This is
- * required, otherwise the CGB switches itself into Non-CGB-Mode.
- */
- private final boolean cgb;
- /**
- * Specifies a two character ASCII licensee code, indicating the company or
- * publisher of the game. These two bytes are used in newer games only
- * (games that have been released after the SGB has been invented). Older
- * games are using the header entry at 014B instead.
- */
- private final String newLicenseeCode;
- /**
- * Specifies whether the game supports SGB functions.
- */
- private final boolean sgb;
- /**
- * Constructs a new ROM from the specified directory.
- *
- * @param directory
- * The directory the ROM is located.
- * @throws IOException
- * If an exception occurs while constructing the ROM.
- */
- public ROM(final String directory) throws IOException {
- file = new File(directory);
- input = new FileInputStream(file);
- data = new byte[(int) file.length()];
- input.read(data);
- title = new String(data, 0x134, 11, Charset.forName("US-ASCII"));
- manufacturerCode = new String(data, 0x13F, 4);
- cgb = data[0x143] == 0xC0 ? true : false;
- newLicenseeCode = new String(data, 0x144, 2, Charset.forName("US-ASCII"));
- sgb = data[0x164] == 0x3 ? true : false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement