libdragon
Macros | Functions

Transfer Pak interface. More...

Macros

#define TPAK_BLOCK_SIZE   0x20
 Transfer Pak command block size (32 bytes)
 
#define TPAK_BANK_SIZE   0x4000
 Transfer Pak cartridge bank size (16 KiB)
 
Transfer Pak power control values

See also
tpak_set_power
#define TPAK_POWER_ON   0x84
 Transfer Pak power on.
 
#define TPAK_POWER_OFF   0xFE
 Transfer Pak power off.
 
Transfer Pak address values

#define TPAK_ADDRESS_POWER   0x8000
 Transfer Pak address for power control.
 
#define TPAK_ADDRESS_BANK   0xA000
 Transfer Pak address for bank switching.
 
#define TPAK_ADDRESS_STATUS   0xB000
 Transfer Pak address for status flags.
 
#define TPAK_ADDRESS_DATA   0xC000
 Transfer Pak address for cartridge data.
 

Functions

int tpak_set_value (int controller, uint16_t address, uint8_t value)
 Set Transfer Pak or Game Boy cartridge status/control value. More...
 
int tpak_init (int controller)
 Prepare a Transfer Pak for read/write commands. More...
 
int tpak_set_access (int controller, bool access_state)
 Set the access mode flag for a Transfer Pak. More...
 
int tpak_set_power (int controller, bool power_state)
 Set the power enabled flag for a Transfer Pak. More...
 
int tpak_set_bank (int controller, int bank)
 Set the cartridge data address memory bank for a Transfer Pak. More...
 
uint8_t tpak_get_status (int controller)
 Get the status flags for a Transfer Pak. More...
 
int tpak_get_cartridge_header (int controller, struct gameboy_cartridge_header *header)
 Read the Game Boy cartridge ROM header from a Transfer Pak. More...
 
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. More...
 
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. More...
 
bool tpak_check_header (struct gameboy_cartridge_header *header)
 Verify a Game Boy cartridge ROM header checksum. More...
 

Detailed Description

Transfer Pak interface.

Function Documentation

◆ tpak_set_value()

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!

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]addressAddress of the setting. Should be between 0x8000 and 0xBFE0
[in]valueA byte of data to fill the write buffer with.

◆ tpak_init()

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.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_set_access()

int tpak_set_access ( int  controller,
bool  access_state 
)

Set the access mode flag for a Transfer Pak.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]access_stateWhether to allow access to the Game Boy cartridge.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_set_power()

int tpak_set_power ( int  controller,
bool  power_state 
)

Set the power enabled flag for a Transfer Pak.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]power_stateTrue to power the Transfer Pak and cartridge on, false to turn it off.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_set_bank()

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.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]bankThe bank (0-3) to switch to.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_get_status()

uint8_t tpak_get_status ( int  controller)

Get the status flags for a Transfer Pak.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
Returns
The status byte with TPAK_STATUS flags

◆ tpak_get_cartridge_header()

int tpak_get_cartridge_header ( int  controller,
struct gameboy_cartridge_header header 
)

Read the Game Boy cartridge ROM header from a Transfer Pak.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[out]headerPointer to destination Game Boy cartridge ROM header data structure.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_write()

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.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]addressaddress in Game Boy cartridge space to write to.
[in]databuffer containing the data to write.
[in]sizelength of the buffer.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_read()

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.

Parameters
[in]controllerThe controller (0-3) with Transfer Pak connected.
[in]addressaddress in Game Boy cartridge space to read from.
[in]bufferbuffer to copy cartridge data into.
[in]sizelength of the data to be read.
Returns
0 if successful or TPAK_ERROR otherwise.

◆ tpak_check_header()

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.

Parameters
[in]headerThe Game Boy ROM header to check.