Skip to content

Instantly share code, notes, and snippets.

View eievui5's full-sized avatar
🐾
paws-ix

Evie eievui5

🐾
paws-ix
View GitHub Profile
@eievui5
eievui5 / emucom.md
Last active May 22, 2022 18:14
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.
@eievui5
eievui5 / bitfield.asm
Created September 8, 2021 17:41
Used to address large arrays of boolean values, packing 8 values into each byte.
; Bitfield Library, by Eievui
; Used to address large arrays of boolean values, packing 8 values into each
; byte.
; Set Nth bool:
; ld a, N
; call GetBitfieldMask
; or a, [hl]
; ld [hl], a

Interrupts

This guide assumes you have a short project to test code on. ISSOtm's "Hello World!" tutorial should work fine as a base.

Interrupts are used to call a given function when certain conditions are met. On the Game Boy, these conditions are:

  • The beginning of the VBlank period
  • A Joypad input
  • A serial data transfer from the link cable
  • The tick of a configurable timer
  • A configurable LCD Status interrupt
@eievui5
eievui5 / enum.inc
Created May 4, 2021 21:04
Enumeration macro pack, used to add enums to RGBDS
;
; Enumeration macro pack for RGBDS
;
; Copyright 2021, Eievui
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;

Functions, Macros, and Encapsulation; Promoting code re-use in assembly

The Game Boy has very simple function support through the call and ret opcodes. These allow you to create blocks of code that can be run from any location in rom, allowing you to re-use code from many different places.

Additionally, RGBDS has support for macros, blocks of code which are expanded at compile-time to real code or data rather then calling to another location in rom.

Understanding how and when to use these features is crucial in keeping your game