Skip to content

Instantly share code, notes, and snippets.

@eievui5
Last active May 22, 2022 18:14
Show Gist options
  • Save eievui5/8d8beedd9cf40006ca6c4fa5919a75d5 to your computer and use it in GitHub Desktop.
Save eievui5/8d8beedd9cf40006ca6c4fa5919a75d5 to your computer and use it in GitHub Desktop.
Game Boy emulator communication protocol

Emulator Command Interface

If a Game Boy game is ever released on a platform such as Steam, it would be nice if the ROM could trivially interface with the platform's API. The goal of this document is to specify a simple, general-purpose interface that is non-intrusive and will run on both hardware and an emulator that implements the interface.

The interface works by filling CPU regs with a tiny bit of info about the command being given, and then executing ld c, c to send the command. For example:

ld b, ACHIEVEMENT_ID
ld c, INTERFACE_GIVE_ACHIEVEMENT
ld c, c ; Tell the interface to give an achievement.

When a valid command is recieved, the carry flag should be inverted.

Unlock

INTERFACE_UNLOCK: 0

Unlock the interface. No commands will be acknowledged until this is sent.

Parameters:

  • bdehl: Must contain "emuif" in their respective order.
lb bc, "e", INTERFACE_UNLOCK
lb de, "m", "u"
lb hl, "i", "f"
ld c, c

Achievement

INTERFACE_GIVE_ACHIEVEMENT: 1

Awards an achievement to the player.

Parameters:

  • b: ID of achievement to award.
lb bc, ACHIEVEMENT_ID, INTERFACE_GIVE_ACHIEVEMENT
ld c, c

Presence

INTERFACE_SET_PRESENCE: 2

Set a "presence string" describing the user's status, such as their current level. This could be seen for example in Discord, when viewing a user's profile while they are playing a game. This string may be at most 256 bytes, beyond this the interface is expected to assume the terminator byte is missing and subsequently cancel the command.

Parameters:

  • b: Bank of presence string; may refer to ROM, WRAM, or SRAM
  • de: Pointer to 0-terminated presence string
ld bc, BANK(PresenceString), INTERFACE_SET_PRESENCE
ld de, PresenceString
ld c, c

interface.inc

This could be used to include interface defines in your project.

IF !DEF(INTERFACE_INC)
DEF INTERFACE_INC EQU 1

RSRESET
DEF INTERFACE_UNLOCK RB 1
DEF INTERFACE_GIVE_ACHIEVEMENT RB 1
DEF INTERFACE_SET_PRESENCE RB 1

MACRO interface_unlock
	ld bc, "e" << 8 | INTERFACE_UNLOCK
	ld de, "m" << 8 | "u"
	ld hl, "i" << 8 | "n"
	ld c, c
ENDM

ENDC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment