libdragon
|
Transfer Pak interface. More...
Go to the source code of this file.
Data Structures | |
struct | old_gbc_title |
"Old" Game Boy Color cartridge ROM header title structure. More... | |
struct | new_gbc_title |
"New" Game Boy Color cartridge ROM header title structure. More... | |
struct | gameboy_cartridge_header |
Game Boy cartridge ROM header structure. More... | |
union | gameboy_cartridge_header.__unnamed44__ |
Union of possible structures for the game title bytes. More... | |
Macros | |
Transfer Pak error values | |
#define | TPAK_ERROR_INVALID_ARGUMENT -1 |
Transfer Pak error: Invalid argument. | |
#define | TPAK_ERROR_NO_TPAK -2 |
Transfer Pak error: No Transfer Pak. | |
#define | TPAK_ERROR_NO_CONTROLLER -3 |
Transfer Pak error: No controller. | |
#define | TPAK_ERROR_UNKNOWN_BEHAVIOUR -4 |
Transfer Pak error: Unknown behavior. | |
#define | TPAK_ERROR_NO_CARTRIDGE -5 |
Transfer Pak error: No cartridge. | |
#define | TPAK_ERROR_ADDRESS_OVERFLOW -6 |
Transfer Pak error: Address overflow. | |
Transfer Pak status bits | |
#define | TPAK_STATUS_READY 0x01 |
Transfer Pak status bit 0: Ready. | |
#define | TPAK_STATUS_WAS_RESET 0x04 |
Transfer Pak status bit 2: Reset status. | |
#define | TPAK_STATUS_IS_RESETTING 0x08 |
Transfer Pak status bit 3: Reset detected. | |
#define | TPAK_STATUS_REMOVED 0x40 |
Transfer Pak status bit 6: Cartridge removed. | |
#define | TPAK_STATUS_POWERED 0x80 |
Transfer Pak status bit 7: Power status. | |
Functions | |
int | tpak_init (int controller) |
Prepare a Transfer Pak for read/write commands. | |
int | tpak_set_value (int controller, uint16_t address, uint8_t value) |
Set Transfer Pak or Game Boy cartridge status/control value. | |
int | tpak_set_bank (int controller, int bank) |
Set the cartridge data address memory bank for a Transfer Pak. | |
int | tpak_set_power (int controller, bool power_state) |
Set the power enabled flag for a Transfer Pak. | |
int | tpak_set_access (int controller, bool access_state) |
Set the access mode flag for a Transfer Pak. | |
uint8_t | tpak_get_status (int controller) |
Get the status flags for a Transfer Pak. | |
int | tpak_get_cartridge_header (int controller, struct gameboy_cartridge_header *header) |
Read the Game Boy cartridge ROM header from a Transfer Pak. | |
bool | tpak_check_header (struct gameboy_cartridge_header *header) |
Verify a Game Boy cartridge ROM header checksum. | |
int | tpak_write (int controller, uint16_t address, uint8_t *data, uint16_t size) |
Write data from a buffer to a Game Boy cartridge via Transfer Pak. | |
int | tpak_read (int controller, uint16_t address, uint8_t *buffer, uint16_t size) |
Read data from a Game Boy cartridge to a buffer via Transfer Pak. | |
Transfer Pak interface.
struct old_gbc_title |
"Old" Game Boy Color cartridge ROM header title structure.
When the Game Boy Color was first introduced, games could use up to 15 characters for the title, and 1 byte to signal CGB compatibility.
Data Fields | ||
---|---|---|
uint8_t | title[15] | Game title in ASCII. |
gbc_support_type | gbc_support | Game Boy Color support. |
struct new_gbc_title |
"New" Game Boy Color cartridge ROM header title structure.
Shortly after the Game Boy Color launched, games were limited to 11 characters for the title, 4 bytes for a manufacturer code, and 1 byte for CGB compatibility.
Data Fields | ||
---|---|---|
uint8_t | title[11] | Game title in ASCII. |
uint8_t | manufacturer_code[4] | Manufacturer identifier. |
gbc_support_type | gbc_support | Game Boy Color support. |
struct gameboy_cartridge_header |
Game Boy cartridge ROM header structure.
Data located at $0100-014F in each Game Boy cartridge ROM.
Data Fields | ||
---|---|---|
uint8_t | entry_point[4] | Z80 instructions to boot the main program. |
uint8_t | logo[48] | Bitmap image data for the boot logo. |
union gameboy_cartridge_header.__unnamed44__ | __unnamed__ | Union of possible structures for the game title bytes. |
uint16_t | new_licensee_code | "New" publisher identifier. |
sgb_support_type | is_sgb_supported | Super Game Boy support. |
gb_cart_type_t | cartridge_type | Cartridge type. |
gb_cart_rom_size_t | rom_size_code | ROM size identifier. |
gb_cart_ram_size_t | ram_size_code | RAM size identifier. |
uint8_t | destination_code | Japan-only identifier. |
uint8_t | old_licensee_code | "Old" publisher identifier. |
uint8_t | version_number | Version number of the game. |
uint8_t | header_checksum | Checksum of cartridge ROM header. |
uint16_t | global_checksum | Checksum of entire cartridge ROM. |
uint8_t | overflow[16] | Padding. |
union gameboy_cartridge_header.__unnamed44__ |
Union of possible structures for the game title bytes.
Data Fields | ||
---|---|---|
uint8_t | title[16] | Game title in ASCII. |
struct old_gbc_title | old_title | "Old" Game Boy Color title structure. |
struct new_gbc_title | new_title | "New" Game Boy Color title structure. |
#define TPAK_STATUS_READY 0x01 |
Transfer Pak status bit 0: Ready.
Also referred to as the "Access Mode" flag. If not set, Transfer Pak cartridge reads/writes will fail.
#define TPAK_STATUS_WAS_RESET 0x04 |
Transfer Pak status bit 2: Reset status.
If set, the Game Boy cartridge is in the process of booting or resetting.
#define TPAK_STATUS_IS_RESETTING 0x08 |
Transfer Pak status bit 3: Reset detected.
If set, the Game Boy cartridge has been reset since the last status read.
#define TPAK_STATUS_REMOVED 0x40 |
Transfer Pak status bit 6: Cartridge removed.
If set, there is no Game Boy cartridge in the Transfer Pak.
#define TPAK_STATUS_POWERED 0x80 |
Transfer Pak status bit 7: Power status.
If set, the Transfer Pak has enabled power to the Game Boy cartridge.
enum gb_cart_type_t |
Game Boy cartridge types.
Describes the Memory Bank Controller and other hardware on the cartridge.
enum gb_cart_rom_size_t |
Game Boy cartridge ROM size types.
Describes how many ROM banks are available on the cartridge.
enum gb_cart_ram_size_t |
Game Boy cartridge RAM size types.
Describes how much SRAM is available on the cartridge.
enum gbc_support_type |
Game Boy Color cartridge compatibility values.
Found in the cartridge ROM header; describes whether the game should boot into CGB mode or monochrome "Non CGB" compatibility mode.
enum sgb_support_type |
int tpak_init | ( | int | controller | ) |
Prepare a Transfer Pak for read/write commands.
Powers on the Transfer Pak and enables access to the Game Boy cartridge. Also performs status checks to confirm the Transfer Pak can be accessed reliably.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
int tpak_set_value | ( | int | controller, |
uint16_t | address, | ||
uint8_t | value | ||
) |
Set Transfer Pak or Game Boy cartridge status/control value.
This is an internal helper to set a Transfer Pak status or control setting. This function is not suitable for setting individual bytes in Save RAM!
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | address | Address of the setting. Should be between 0x8000 and 0xBFE0 |
[in] | value | A byte of data to fill the write buffer with. |
int tpak_set_bank | ( | int | controller, |
int | bank | ||
) |
Set the cartridge data address memory bank for a Transfer Pak.
Change the bank of address space that is available for tpak_read and tpak_write between Transfer Pak addresses 0xC000 and 0xFFFF.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | bank | The bank (0-3) to switch to. |
int tpak_set_power | ( | int | controller, |
bool | power_state | ||
) |
Set the power enabled flag for a Transfer Pak.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | power_state | True to power the Transfer Pak and cartridge on, false to turn it off. |
int tpak_set_access | ( | int | controller, |
bool | access_state | ||
) |
Set the access mode flag for a Transfer Pak.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | access_state | Whether to allow access to the Game Boy cartridge. |
uint8_t tpak_get_status | ( | int | controller | ) |
Get the status flags for a Transfer Pak.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
int tpak_get_cartridge_header | ( | int | controller, |
struct gameboy_cartridge_header * | header | ||
) |
Read the Game Boy cartridge ROM header from a Transfer Pak.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[out] | header | Pointer to destination Game Boy cartridge ROM header data structure. |
bool tpak_check_header | ( | struct gameboy_cartridge_header * | header | ) |
Verify a Game Boy cartridge ROM header checksum.
Confirms that the Transfer Pak is connected and working properly.
[in] | header | The Game Boy ROM header to check. |
int tpak_write | ( | int | controller, |
uint16_t | address, | ||
uint8_t * | data, | ||
uint16_t | size | ||
) |
Write data from a buffer to a Game Boy cartridge via Transfer Pak.
Save RAM is located between gameboy addresses 0xA000 and 0xBFFF, which is in the Transfer Pak's bank 2. This function does not account for cartridge bank switching, so to switch between MBC1 RAM banks, for example, you'll need to switch to Tpak bank 1, and write to address 0xE000, which translates to address 0x6000 on the gameboy.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | address | address in Game Boy cartridge space to write to. |
[in] | data | buffer containing the data to write. |
[in] | size | length of the buffer. |
int tpak_read | ( | int | controller, |
uint16_t | address, | ||
uint8_t * | buffer, | ||
uint16_t | size | ||
) |
Read data from a Game Boy cartridge to a buffer via Transfer Pak.
[in] | controller | The controller (0-3) with Transfer Pak connected. |
[in] | address | address in Game Boy cartridge space to read from. |
[in] | buffer | buffer to copy cartridge data into. |
[in] | size | length of the data to be read. |