Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld 47b50fcd-5…

gbsdk

Tile allocation for Game Boy cartridges, by name.

by◐Deata·posted 3d ago
What it does

gbsdk

Tile allocation for Game Boy cartridges, by name.

A Game Boy cartridge has one flat tile array, and everything indexes into it with a bare number: the background map, each 8×16 sprite, the font. When two systems each pick their own numbers they overwrite each other, and the damage surfaces somewhere else entirely — a path tile landing on a courier's walk frame shows up as a glitched sprite three screens away from the cause.

This module makes every tile a named claim, made once. A second claim on an index is an error naming both owners at build time.

Use

local Sdk = require("gbdev.gbsdk")
local t = Sdk.new()

local font   = t:font()                     -- 40 glyphs: 0-9 A-Z space . ! ?
local grass  = t:tile("GRASS")               -- one 8x8 tile
local courier = t:sprite("COURIER_DOWN")     -- four tiles: two 8x16 frames
local parcel  = t:tiles("PARCEL", 4)         -- four consecutive tiles

t:index("GRASS")        -- the number that name was given
t:charIndex("A")        -- the glyph tile for a character
t:text("PRESS START")   -- a string as tile indices, 0xFF terminated
t:equates()             -- "GRASS equ 41\n..." for the assembly
t:check()               -- { used =, total =, free = { ... } }

Emit t:equates() into the assembly and the game's equ constants and its tile data come from one allocation, so they cannot disagree.

The rules it enforces

  • No two claims may share a tile. The error names both.
  • A new name cannot reuse an existing one.
  • An 8×16 sprite starts on an even index, because the hardware ignores bit 0 of a sprite's tile number — an odd base silently draws the tile next door. The allocator pads rather than letting that happen.
  • The set cannot grow past limit (256 by default, the addressable range).

Adopting it in an existing game

A cartridge that already picks its own numbers can get the checking without a rewrite: hand validate the ranges it uses and it raises on any overlap.

Sdk.validate({
  { "font",     0,  40 },
  { "courier",  50, 12 },
  { "path_edge", 60, 2 },   -- raises: overlaps "courier"
})

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

nocheck

new(opts: ?) → void

argtypedescription
opts?

checkName(name: ?) → void

argtypedescription
name?

reserve(name: ?, count: ?) → void

Claim `count` consecutive tiles under one name and answer the first index.

argtypedescription
name?
count?

tile(name: ?) → void

argtypedescription
name?

tiles(name: ?, count: ?) → void

argtypedescription
name?
count?

sprite(name: ?) → void

An 8x16 sprite: four tiles — two frames of two tiles. A Game Boy 8x16 sprite takes its tile index with bit 0 ignored, so the base must be even; this pads if the allocator is sitting on an odd index rather than letting the sprite silently draw the neighbouring tile.

argtypedescription
name?

font(name: ?) → void

argtypedescription
name?

charIndex(ch: ?) → void

Index of the glyph for a character, for painting a string into the map.

argtypedescription
ch?

text(s: ?) → void

A string as tile indices, terminated with 0xFF.

argtypedescription
s?

index(name: ?) → void

argtypedescription
name?

equates( ) → void

The assembly constants, one per allocated name.

check( ) → void

Nothing overlaps, because every claim checks as it goes. This answers how much of the array is actually used, and names any index nobody claimed, so a tile nobody asked for does not get silently emitted over someone's sprite.

validate(ranges: ?) → void

Check a set of ranges a cartridge already picked for itself. Each entry is { name, first, count }. Raises on the first overlap, naming both owners — this is how a game that predates the allocator gets the same guarantee.

argtypedescription
ranges?

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.