Skip to content

Instantly share code, notes, and snippets.

@loopj
Created May 30, 2026 06:36
Show Gist options
  • Select an option

  • Save loopj/a94c19f6562db21c807872d88570d582 to your computer and use it in GitHub Desktop.

Select an option

Save loopj/a94c19f6562db21c807872d88570d582 to your computer and use it in GitHub Desktop.
Example "in memory" controller pak
static uint8_t pak_storage[CONTROLLER_PAK_SIZE];
static void controller_pak_read_block(struct joybus_n64_accessory *accessory, uint16_t addr,
uint8_t buf[JOYBUS_ACCESSORY_BLOCK_SIZE])
{
// Return zeroes for out-of-bounds addresses
if (addr >= CONTROLLER_PAK_SIZE) {
memset(buf, 0, JOYBUS_ACCESSORY_BLOCK_SIZE);
return;
}
// Read the block from RAM into the response buffer
memcpy(buf, &pak_storage[addr], JOYBUS_ACCESSORY_BLOCK_SIZE);
}
static void controller_pak_write_block(struct joybus_n64_accessory *accessory, uint16_t addr,
const uint8_t buf[JOYBUS_ACCESSORY_BLOCK_SIZE])
{
// Ignore writes to out-of-bounds addresses
if (addr >= CONTROLLER_PAK_SIZE)
return;
// Write the block to RAM
memcpy(&pak_storage[addr], buf, JOYBUS_ACCESSORY_BLOCK_SIZE);
}
static const struct joybus_n64_accessory_api controller_pak_api = {
.read_block = controller_pak_read_block,
.write_block = controller_pak_write_block,
};
static struct joybus_n64_accessory controller_pak = {
.api = &controller_pak_api,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment