libdragon
tpak.h
Go to the documentation of this file.
1
7#ifndef __LIBDRAGON_TPAK_H
8#define __LIBDRAGON_TPAK_H
9
10#include <stdint.h>
11#include <stdbool.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
23#define TPAK_ERROR_INVALID_ARGUMENT -1
25#define TPAK_ERROR_NO_TPAK -2
27#define TPAK_ERROR_NO_CONTROLLER -3
29#define TPAK_ERROR_UNKNOWN_BEHAVIOUR -4
31#define TPAK_ERROR_NO_CARTRIDGE -5
33#define TPAK_ERROR_ADDRESS_OVERFLOW -6
47#define TPAK_STATUS_READY 0x01
53#define TPAK_STATUS_WAS_RESET 0x04
59#define TPAK_STATUS_IS_RESETTING 0x08
65#define TPAK_STATUS_REMOVED 0x40
71#define TPAK_STATUS_POWERED 0x80
79typedef enum __attribute__ ((packed))
80{
84 GB_MBC1 = 0x01,
90 GB_MBC2 = 0x05,
94 GB_ROM_RAM = 0x08,
98 GB_MMM01 = 0x0B,
104 GB_MBC3 = 0x11,
114 GB_MBC5 = 0x19,
126 GB_MBC6 = 0x20,
134 GB_HUC3 = 0xFE,
138
144typedef enum __attribute__ ((packed))
145{
171
177typedef enum __attribute__ ((packed))
178{
192
199typedef enum __attribute__ ((packed))
200{
225 GBC_ONLY_SUPPORTED = 0xC0
227
234typedef enum __attribute__ ((packed))
235{
239 SGB_ENHANCED = 0x03
241
249{
251 uint8_t title[15];
254};
255
264{
266 uint8_t title[11];
271};
272
279{
281 uint8_t entry_point[4];
283 uint8_t logo[48];
285 union {
287 uint8_t title[16];
289 struct old_gbc_title old_title;
291 struct new_gbc_title new_title;
292 };
314 uint8_t overflow[16];
315};
316
317int tpak_init(int controller);
318int tpak_set_value(int controller, uint16_t address, uint8_t value);
319int tpak_set_bank(int controller, int bank);
320int tpak_set_power(int controller, bool power_state);
321int tpak_set_access(int controller, bool access_state);
322uint8_t tpak_get_status(int controller);
323int tpak_get_cartridge_header(int controller, struct gameboy_cartridge_header* header);
325int tpak_write(int controller, uint16_t address, uint8_t* data, uint16_t size);
326int tpak_read(int controller, uint16_t address, uint8_t* buffer, uint16_t size);
327
328#ifdef __cplusplus
329}
330#endif
331
332#endif
uint8_t destination_code
Japan-only identifier.
Definition: tpak.h:304
int tpak_init(int controller)
Prepare a Transfer Pak for read/write commands.
Definition: tpak.c:102
gb_cart_ram_size_t ram_size_code
RAM size identifier.
Definition: tpak.h:302
int tpak_set_access(int controller, bool access_state)
Set the access mode flag for a Transfer Pak.
Definition: tpak.c:131
gbc_support_type gbc_support
Game Boy Color support.
Definition: tpak.h:270
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.
Definition: tpak.c:270
uint8_t title[15]
Game title in ASCII.
Definition: tpak.h:251
sgb_support_type is_sgb_supported
Super Game Boy support.
Definition: tpak.h:296
int tpak_set_power(int controller, bool power_state)
Set the power enabled flag for a Transfer Pak.
Definition: tpak.c:146
bool tpak_check_header(struct gameboy_cartridge_header *header)
Verify a Game Boy cartridge ROM header checksum.
Definition: tpak.c:314
uint16_t global_checksum
Checksum of entire cartridge ROM.
Definition: tpak.h:312
uint8_t logo[48]
Bitmap image data for the boot logo.
Definition: tpak.h:283
sgb_support_type
Super Game Boy cartridge compatibility values.
Definition: tpak.h:235
@ SGB_ENHANCED
Enhanced for Super Game Boy.
Definition: tpak.h:239
@ SGB_NOT_ENHANCED
Not enhanced for Super Game Boy.
Definition: tpak.h:237
gbc_support_type gbc_support
Game Boy Color support.
Definition: tpak.h:253
gb_cart_rom_size_t rom_size_code
ROM size identifier.
Definition: tpak.h:300
uint8_t header_checksum
Checksum of cartridge ROM header.
Definition: tpak.h:310
int tpak_set_value(int controller, uint16_t address, uint8_t value)
Set Transfer Pak or Game Boy cartridge status/control value.
Definition: tpak.c:85
uint8_t title[11]
Game title in ASCII.
Definition: tpak.h:266
uint16_t new_licensee_code
"New" publisher identifier.
Definition: tpak.h:294
uint8_t manufacturer_code[4]
Manufacturer identifier.
Definition: tpak.h:268
gb_cart_type_t
Game Boy cartridge types.
Definition: tpak.h:80
@ GB_MBC5_RUMBLE
MBC5 (max 8 MiB ROM) + Rumble.
Definition: tpak.h:120
@ GB_MMM01_RAM_BATTERY
MMM01 ("Meta-mapper") + RAM + Battery.
Definition: tpak.h:102
@ GB_HUC1_RAM_BATTERY
Hudson HuC1 + RAM + Battery.
Definition: tpak.h:136
@ GB_HUC3
Hudson HuC3.
Definition: tpak.h:134
@ GB_ROM_RAM
ROM (32 KiB) + RAM (max 8 KiB)
Definition: tpak.h:94
@ GB_MBC5_RUMBLE_RAM_BATTERY
MBC5 (max 8 MiB ROM) + Rumble + RAM (128 KiB) + Battery.
Definition: tpak.h:124
@ GB_MBC5_RAM_BATTERY
MBC5 (max 8 MiB ROM) + RAM (128 KiB) + Battery.
Definition: tpak.h:118
@ GB_MBC2_BATTERY
MBC2 (max 256 KiB ROM; 512x4 bits RAM built-in) + Battery.
Definition: tpak.h:92
@ GB_MBC3_TIMER_RAM_BATTERY
MBC3 (max 2 MiB ROM) + Real-Time Clock + RAM (64 KiB) + Battery.
Definition: tpak.h:112
@ GB_MBC5_RUMBLE_RAM
MBC5 (max 8 MiB ROM) + Rumble + RAM (128 KiB)
Definition: tpak.h:122
@ GB_MBC6
MBC6.
Definition: tpak.h:126
@ GB_MBC5_RAM
MBC5 (max 8 MiB ROM) + RAM (128 KiB)
Definition: tpak.h:116
@ GB_MBC3_RAM
MBC3 (max 2 MiB ROM) + RAM (64 KiB)
Definition: tpak.h:106
@ GB_POCKET_CAMERA
Game Boy Camera.
Definition: tpak.h:130
@ GB_MMM01
MMM01 ("Meta-mapper")
Definition: tpak.h:98
@ GB_MBC3_RAM_BATTERY
MBC3 (max 2 MiB ROM) + RAM (64 KiB) + Battery.
Definition: tpak.h:108
@ GB_BANDAI_TAMA5
Bandai TAMA5.
Definition: tpak.h:132
@ GB_ROM_ONLY
ROM only (32 KiB ROM)
Definition: tpak.h:82
@ GB_MBC2
MBC2 (max 256 KiB ROM; 512x4 bits RAM built-in)
Definition: tpak.h:90
@ GB_MBC3_TIMER_BATTERY
MBC3 (max 2 MiB ROM) + Real-Time Clock + Battery.
Definition: tpak.h:110
@ GB_MBC1_RAM_BATTERY
MBC1 (max 2 MiB ROM) + RAM (32 KiB) + Battery.
Definition: tpak.h:88
@ GB_MBC1
MBC1 (max 2 MiB ROM)
Definition: tpak.h:84
@ GB_MMM01_RAM
MMM01 ("Meta-mapper") + RAM.
Definition: tpak.h:100
@ GB_MBC5
MBC5 (max 8 MiB ROM)
Definition: tpak.h:114
@ GB_MBC1_RAM
MBC1 (max 2 MiB ROM) + RAM (32 KiB)
Definition: tpak.h:86
@ GB_MBC7_SENSOR_RUMBLE_RAM_BATTERY
MBC7 + Tilt Sensor + Rumble + RAM + Battery.
Definition: tpak.h:128
@ GB_MBC3
MBC3 (max 2 MiB ROM)
Definition: tpak.h:104
@ GB_ROM_RAM_BATTERY
ROM (32 KiB) + RAM (max 8 KiB) + Battery.
Definition: tpak.h:96
uint8_t version_number
Version number of the game.
Definition: tpak.h:308
uint8_t old_licensee_code
"Old" publisher identifier.
Definition: tpak.h:306
int tpak_get_cartridge_header(int controller, struct gameboy_cartridge_header *header)
Read the Game Boy cartridge ROM header from a Transfer Pak.
Definition: tpak.c:193
uint8_t entry_point[4]
Z80 instructions to boot the main program.
Definition: tpak.h:281
gb_cart_type_t cartridge_type
Cartridge type.
Definition: tpak.h:298
gb_cart_ram_size_t
Game Boy cartridge RAM size types.
Definition: tpak.h:178
@ GB_RAM_2KB
RAM size: 2 KiB (no banks)
Definition: tpak.h:182
@ GB_RAM_128KB
RAM size: 128 KiB (16 banks)
Definition: tpak.h:190
@ GB_RAM_64KB
RAM size: 64 KiB (8 banks)
Definition: tpak.h:188
@ GB_RAM_NONE
RAM not available.
Definition: tpak.h:180
@ GB_RAM_32KB
RAM size: 32 KiB (4 banks)
Definition: tpak.h:186
@ GB_RAM_8KB
RAM size: 8 KiB (no banks)
Definition: tpak.h:184
int tpak_set_bank(int controller, int bank)
Set the cartridge data address memory bank for a Transfer Pak.
Definition: tpak.c:164
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.
Definition: tpak.c:220
uint8_t overflow[16]
Padding.
Definition: tpak.h:314
gb_cart_rom_size_t
Game Boy cartridge ROM size types.
Definition: tpak.h:145
@ GB_ROM_1536KB
ROM size: 1.5 MiB (96 banks)
Definition: tpak.h:169
@ GB_ROM_64KB
ROM size: 64 KiB (4 banks)
Definition: tpak.h:149
@ GB_ROM_1MB
ROM size: 1 MiB (64 banks)
Definition: tpak.h:157
@ GB_ROM_1152KB
ROM size: 1.125 MiB (72 banks)
Definition: tpak.h:165
@ GB_ROM_512KB
ROM size: 512 KiB (32 banks)
Definition: tpak.h:155
@ GB_ROM_256KB
ROM size: 256 KiB (16 banks)
Definition: tpak.h:153
@ GB_ROM_32KB
ROM size: 32 KiB (no banks)
Definition: tpak.h:147
@ GB_ROM_8MB
ROM size: 8 MiB (512 banks)
Definition: tpak.h:163
@ GB_ROM_1280KB
ROM size: 1.25 MiB (80 banks)
Definition: tpak.h:167
@ GB_ROM_128KB
ROM size: 128 KiB (8 banks)
Definition: tpak.h:151
@ GB_ROM_2MB
ROM size: 2 MiB (128 banks)
Definition: tpak.h:159
@ GB_ROM_4MB
ROM size: 4 MiB (256 banks)
Definition: tpak.h:161
gbc_support_type
Game Boy Color cartridge compatibility values.
Definition: tpak.h:200
@ GBC_NOT_SUPPORTED
Game Boy Color not supported.
Definition: tpak.h:208
@ GBC_ONLY_SUPPORTED
Game Boy Color required.
Definition: tpak.h:225
@ GBC_DMG_SUPPORTED
Game Boy Color enhanced.
Definition: tpak.h:216
uint8_t tpak_get_status(int controller)
Get the status flags for a Transfer Pak.
Definition: tpak.c:176
Game Boy cartridge ROM header structure.
Definition: tpak.h:279
"New" Game Boy Color cartridge ROM header title structure.
Definition: tpak.h:264
"Old" Game Boy Color cartridge ROM header title structure.
Definition: tpak.h:249