Skip to content

Instantly share code, notes, and snippets.

@ISSOtm
Last active April 11, 2021 17:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ISSOtm/a9057e7c66080f36afcd82ed2863fd62 to your computer and use it in GitHub Desktop.
Save ISSOtm/a9057e7c66080f36afcd82ed2863fd62 to your computer and use it in GitHub Desktop.
My conventions when writing Game Boy ASM (naming / casing, best practices)

Casing

  • Labels use PascalCase. DrawNPCs, GetOffsetFromCamera.
  • Labels in RAM (VRAM, SRAM, WRAM, HRAM; you shouldn't be using Echo RAM or OAM) use the same convention but are prefixed with the initial of the RAM they're in, in lowercase. wCameraOffsetBuffer, hVBlankFlag, vTilesetTiles, sSaveFileChecksum. Rationale: to know in which memory type the label is; this is important because VRAM and SRAM have special access precautions and HRAM can (should (must)) be accessed using the ldh instruction.
  • Local labels use camelCase, regardless of memory type. (.waitVRAM, wPlayer.xCoord)
  • Macro names use snake_case. wait_vram, rst wait_vblank, end_struct.
  • Constants use CAPS_SNAKE. NB_NPCS, OVERWORLD_STAT_LOAD_MAP.
  • Constants posing as labels use the appropriate label convention.

Best practices

Split everything, nobody likes big files. But keep the splitting reasonable and coherent.

Put everything you can in ROMX. But if it then has to do something like calling functions in other banks, then it should've been in ROM0.

Compress data. See PB16 below for good tile data compression.

Never let the hardware draw a corrupted frame even if it's just one frame. If it's noticeable by squinting hard enough, it has to go.

Makefiles are bae

Stuff I use

Resources

Shoutouts

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