libdragon
Loading...
Searching...
No Matches
tpak.h
Go to the documentation of this file.
1
10#ifndef __LIBDRAGON_TPAK_H
11#define __LIBDRAGON_TPAK_H
12
13#include <stdint.h>
14#include <stdbool.h>
15
44#ifdef __cplusplus
45extern "C" {
46#endif
47
54#define TPAK_ERROR_INVALID_ARGUMENT -1
56#define TPAK_ERROR_NO_TPAK -2
58#define TPAK_ERROR_NO_CONTROLLER -3
60#define TPAK_ERROR_UNKNOWN_BEHAVIOUR -4
62#define TPAK_ERROR_NO_CARTRIDGE -5
64#define TPAK_ERROR_ADDRESS_OVERFLOW -6
78#define TPAK_STATUS_READY 0x01
84#define TPAK_STATUS_WAS_RESET 0x04
90#define TPAK_STATUS_IS_RESETTING 0x08
96#define TPAK_STATUS_REMOVED 0x40
102#define TPAK_STATUS_POWERED 0x80
169
175typedef enum __attribute__ ((packed))
176{
202
208typedef enum __attribute__ ((packed))
209{
223
230typedef enum __attribute__ ((packed))
231{
256 GBC_ONLY_SUPPORTED = 0xC0
258
265typedef enum __attribute__ ((packed))
266{
270 SGB_ENHANCED = 0x03
272
286
303
347
358int tpak_init(int controller);
359
373int tpak_set_value(int controller, uint16_t address, uint8_t value);
374
387int tpak_set_bank(int controller, int bank);
388
398int tpak_set_power(int controller, bool power_state);
399
409int tpak_set_access(int controller, bool access_state);
410
418uint8_t tpak_get_status(int controller);
419
429int tpak_get_cartridge_header(int controller, struct gameboy_cartridge_header* header);
430
439
457int tpak_write(int controller, uint16_t address, uint8_t* data, uint16_t size);
458
472int tpak_read(int controller, uint16_t address, uint8_t* buffer, uint16_t size);
473
474#ifdef __cplusplus
475}
476#endif
477
478#endif
uint8_t destination_code
Japan-only identifier.
Definition tpak.h:335
int tpak_init(int controller)
Prepare a Transfer Pak for read/write commands.
Definition tpak.c:53
gb_cart_ram_size_t ram_size_code
RAM size identifier.
Definition tpak.h:333
int tpak_set_access(int controller, bool access_state)
Set the access mode flag for a Transfer Pak.
Definition tpak.c:73
gbc_support_type gbc_support
Game Boy Color support.
Definition tpak.h:301
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:145
uint8_t title[15]
Game title in ASCII.
Definition tpak.h:282
sgb_support_type is_sgb_supported
Super Game Boy support.
Definition tpak.h:327
int tpak_set_power(int controller, bool power_state)
Set the power enabled flag for a Transfer Pak.
Definition tpak.c:79
bool tpak_check_header(struct gameboy_cartridge_header *header)
Verify a Game Boy cartridge ROM header checksum.
Definition tpak.c:182
uint16_t global_checksum
Checksum of entire cartridge ROM.
Definition tpak.h:343
uint8_t logo[48]
Bitmap image data for the boot logo.
Definition tpak.h:314
sgb_support_type
Super Game Boy cartridge compatibility values.
Definition tpak.h:266
@ SGB_ENHANCED
Enhanced for Super Game Boy.
Definition tpak.h:270
@ SGB_NOT_ENHANCED
Not enhanced for Super Game Boy.
Definition tpak.h:268
gbc_support_type gbc_support
Game Boy Color support.
Definition tpak.h:284
gb_cart_rom_size_t rom_size_code
ROM size identifier.
Definition tpak.h:331
uint8_t header_checksum
Checksum of cartridge ROM header.
Definition tpak.h:341
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:46
uint8_t title[11]
Game title in ASCII.
Definition tpak.h:297
uint16_t new_licensee_code
"New" publisher identifier.
Definition tpak.h:325
uint8_t manufacturer_code[4]
Manufacturer identifier.
Definition tpak.h:299
gb_cart_type_t
Game Boy cartridge types.
Definition tpak.h:111
@ GB_MBC5_RUMBLE
MBC5 (max 8 MiB ROM) + Rumble.
Definition tpak.h:151
@ GB_MMM01_RAM_BATTERY
MMM01 ("Meta-mapper") + RAM + Battery.
Definition tpak.h:133
@ GB_HUC1_RAM_BATTERY
Hudson HuC1 + RAM + Battery.
Definition tpak.h:167
@ GB_HUC3
Hudson HuC3.
Definition tpak.h:165
@ GB_ROM_RAM
ROM (32 KiB) + RAM (max 8 KiB)
Definition tpak.h:125
@ GB_MBC5_RUMBLE_RAM_BATTERY
MBC5 (max 8 MiB ROM) + Rumble + RAM (128 KiB) + Battery.
Definition tpak.h:155
@ GB_MBC5_RAM_BATTERY
MBC5 (max 8 MiB ROM) + RAM (128 KiB) + Battery.
Definition tpak.h:149
@ GB_MBC2_BATTERY
MBC2 (max 256 KiB ROM; 512x4 bits RAM built-in) + Battery.
Definition tpak.h:123
@ GB_MBC3_TIMER_RAM_BATTERY
MBC3 (max 2 MiB ROM) + Real-Time Clock + RAM (64 KiB) + Battery.
Definition tpak.h:143
@ GB_MBC5_RUMBLE_RAM
MBC5 (max 8 MiB ROM) + Rumble + RAM (128 KiB)
Definition tpak.h:153
@ GB_MBC6
MBC6.
Definition tpak.h:157
@ GB_MBC5_RAM
MBC5 (max 8 MiB ROM) + RAM (128 KiB)
Definition tpak.h:147
@ GB_MBC3_RAM
MBC3 (max 2 MiB ROM) + RAM (64 KiB)
Definition tpak.h:137
@ GB_POCKET_CAMERA
Game Boy Camera.
Definition tpak.h:161
@ GB_MMM01
MMM01 ("Meta-mapper")
Definition tpak.h:129
@ GB_MBC3_RAM_BATTERY
MBC3 (max 2 MiB ROM) + RAM (64 KiB) + Battery.
Definition tpak.h:139
@ GB_BANDAI_TAMA5
Bandai TAMA5.
Definition tpak.h:163
@ GB_ROM_ONLY
ROM only (32 KiB ROM)
Definition tpak.h:113
@ GB_MBC2
MBC2 (max 256 KiB ROM; 512x4 bits RAM built-in)
Definition tpak.h:121
@ GB_MBC3_TIMER_BATTERY
MBC3 (max 2 MiB ROM) + Real-Time Clock + Battery.
Definition tpak.h:141
@ GB_MBC1_RAM_BATTERY
MBC1 (max 2 MiB ROM) + RAM (32 KiB) + Battery.
Definition tpak.h:119
@ GB_MBC1
MBC1 (max 2 MiB ROM)
Definition tpak.h:115
@ GB_MMM01_RAM
MMM01 ("Meta-mapper") + RAM.
Definition tpak.h:131
@ GB_MBC5
MBC5 (max 8 MiB ROM)
Definition tpak.h:145
@ GB_MBC1_RAM
MBC1 (max 2 MiB ROM) + RAM (32 KiB)
Definition tpak.h:117
@ GB_MBC7_SENSOR_RUMBLE_RAM_BATTERY
MBC7 + Tilt Sensor + Rumble + RAM + Battery.
Definition tpak.h:159
@ GB_MBC3
MBC3 (max 2 MiB ROM)
Definition tpak.h:135
@ GB_ROM_RAM_BATTERY
ROM (32 KiB) + RAM (max 8 KiB) + Battery.
Definition tpak.h:127
uint8_t version_number
Version number of the game.
Definition tpak.h:339
uint8_t old_licensee_code
"Old" publisher identifier.
Definition tpak.h:337
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:98
uint8_t entry_point[4]
Z80 instructions to boot the main program.
Definition tpak.h:312
gb_cart_type_t cartridge_type
Cartridge type.
Definition tpak.h:329
gb_cart_ram_size_t
Game Boy cartridge RAM size types.
Definition tpak.h:209
@ GB_RAM_2KB
RAM size: 2 KiB (no banks)
Definition tpak.h:213
@ GB_RAM_128KB
RAM size: 128 KiB (16 banks)
Definition tpak.h:221
@ GB_RAM_64KB
RAM size: 64 KiB (8 banks)
Definition tpak.h:219
@ GB_RAM_NONE
RAM not available.
Definition tpak.h:211
@ GB_RAM_32KB
RAM size: 32 KiB (4 banks)
Definition tpak.h:217
@ GB_RAM_8KB
RAM size: 8 KiB (no banks)
Definition tpak.h:215
int tpak_set_bank(int controller, int bank)
Set the cartridge data address memory bank for a Transfer Pak.
Definition tpak.c:85
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:108
uint8_t overflow[16]
Padding.
Definition tpak.h:345
gb_cart_rom_size_t
Game Boy cartridge ROM size types.
Definition tpak.h:176
@ GB_ROM_1536KB
ROM size: 1.5 MiB (96 banks)
Definition tpak.h:200
@ GB_ROM_64KB
ROM size: 64 KiB (4 banks)
Definition tpak.h:180
@ GB_ROM_1MB
ROM size: 1 MiB (64 banks)
Definition tpak.h:188
@ GB_ROM_1152KB
ROM size: 1.125 MiB (72 banks)
Definition tpak.h:196
@ GB_ROM_512KB
ROM size: 512 KiB (32 banks)
Definition tpak.h:186
@ GB_ROM_256KB
ROM size: 256 KiB (16 banks)
Definition tpak.h:184
@ GB_ROM_32KB
ROM size: 32 KiB (no banks)
Definition tpak.h:178
@ GB_ROM_8MB
ROM size: 8 MiB (512 banks)
Definition tpak.h:194
@ GB_ROM_1280KB
ROM size: 1.25 MiB (80 banks)
Definition tpak.h:198
@ GB_ROM_128KB
ROM size: 128 KiB (8 banks)
Definition tpak.h:182
@ GB_ROM_2MB
ROM size: 2 MiB (128 banks)
Definition tpak.h:190
@ GB_ROM_4MB
ROM size: 4 MiB (256 banks)
Definition tpak.h:192
gbc_support_type
Game Boy Color cartridge compatibility values.
Definition tpak.h:231
@ GBC_NOT_SUPPORTED
Game Boy Color not supported.
Definition tpak.h:239
@ GBC_ONLY_SUPPORTED
Game Boy Color required.
Definition tpak.h:256
@ GBC_DMG_SUPPORTED
Game Boy Color enhanced.
Definition tpak.h:247
uint8_t tpak_get_status(int controller)
Get the status flags for a Transfer Pak.
Definition tpak.c:90
Game Boy cartridge ROM header structure.
Definition tpak.h:310
"New" Game Boy Color cartridge ROM header title structure.
Definition tpak.h:295
"Old" Game Boy Color cartridge ROM header title structure.
Definition tpak.h:280