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

cartlib

`require("stations.cartlib")` gives every console station one shared list of the cartridges in the room: each core's committed demo carts, the local player's own uploads, and what every other player in the session holds. Players upload ROMs from their computer and anyone in the r…

by◐Deata·posted 3d ago
What it does

cartlib — the session cartridge library

require("stations.cartlib") gives every console station one shared list of the cartridges in the room: each core's committed demo carts, the local player's own uploads, and what every other player in the session holds. Players upload ROMs from their computer and anyone in the room can play them; the bytes are copied peer to peer on demand.

Uploaded ROMs are never written to /zero/source: they live in the uploader's runtime-data library (chunked under the 256 KB value cap, the retro.host RomLibrary layout, so a console's own loader lists them too) and in memory. Carts copied from another player live in memory for the session only.

API

local Cartlib = require("stations.cartlib")

Cartlib.list(consoleId?)  -> { Entry }       -- sorted by console, BIOS first, then title
-- Entry = { id, console, title, size, holders = {peerId}, builtin, isBios }
-- id = console .. ":" .. filename .. ":" .. size (stable across peers)
Cartlib.has(id) -> boolean                   -- bytes available on this peer
Cartlib.bytes(id) -> string?                 -- committed file, runtime library, or session cache
Cartlib.upload(consoleId?) -> (Entry?, why?) -- yields; system file picker, validate, store, announce
Cartlib.fetch(id, function(ok, why) end)     -- copy from a holder peer (<= 8 MB)
Cartlib.onChanged(cb) -> unsubscribe
Cartlib.biosFor(consoleId) -> id?            -- a locally held BIOS (e.g. neogeo.zip)
Cartlib.openLoader({ title, consoles = {"gameboy", ...}, onPick = function(entry) end })
Cartlib.closeLoader()
Cartlib.handleCallback(id, data) -> boolean  -- forward a UI callback (see below)
Cartlib.tick()                               -- prune players who left (CartLoader calls it)

Extras: Cartlib.get(id), Cartlib.progress(id) (0..1 while copying), Cartlib.consoles(), Cartlib.formatSize(n), Cartlib.refresh() (rescan disk and the runtime library), Cartlib.isLoaderOpen(), Cartlib.isUploading().

Consoles come from every installed emulatorCore (retro.host.registry). Any .zip is a Neo Geo set (console neogeo); neogeo.zip is the Neo Geo BIOS (isBios = true, validation skipped). If no core claims neogeo, the library still files zips under it. builtin entries are the files in each core's romsDir, held by everyone.

Neo Geo system files

The Neo Geo core reads its BIOS from a zip (neogeo.package romset): a system ROM (sp-s2.sp1, sp-s3.sp1, sp-u2.sp1, sp-j2.sp1, uni-bios*.rom, … the romset's BIOS_NAMES), sfix.sfix, sm1.sm1, and optionally 000-lo.lo. Players don't have to build that zip themselves:

  • Loose files (.sp1 .sfix .sm1 .rom .bin .lo, renamed copies like sp-s2 (1).sp1 included; Cartlib._biosPart(name) names each one's role) are kept in the player's runtime-data library under neogeo_bios/. Once a system ROM, sfix and sm1 are all held, they are packed (stored, uncompressed, Cartlib._storeZip) into neogeo.zip, which becomes the BIOS entry.
  • A zip of system files under any name is the BIOS when it holds all three; otherwise its files join the loose parts.
  • Cartlib.neoSetup() answers what is here: { ready, system, sfix, sm1, lo, missing, games }.

The picker takes several files at once on the All and Neo Geo tabs.

Help on the shelf

Every tab opens with an Adding games strip: the file types it takes and that uploads stay in the player's library and are shared with the room while they are here. The Neo Geo tab adds a setup card: step 1 System files (each file ✓/○, an Upload system files button while any is missing) and step 2 Your game zip. PLAY on a Neo Geo game without the system files keeps the shelf open, switches to that tab, says what is missing and puts focus on the upload button.

The loader panel

openLoader shows a centred card over a dimmed backdrop: console tabs (All + the consoles you pass), one row per cart (console tag, BIOS tag, title, console, size, who has it, and an action: PLAY when the bytes are here, GET to copy them, COPYING n%, TOO BIG past 8 MB), a close button (Esc) and an Upload from your computer button that filters the picker to the current tab's extensions. Everything is a button, so arrows / d-pad / stick move focus, Enter / south press, and touch taps. Picking a cart that is elsewhere copies it first and then calls onPick; an upload calls onPick with the new entry.

UI callbacks run in play. openLoader registers its own callback env, so callbacks reach it when it is opened from a component's code. A component that wants to be sure can forward its own onCallback(id, data) to Cartlib.handleCallback(id, data) (repeats within the same frame are ignored), or carry the stations/CartLoader component, which does that and calls Cartlib.tick().

Session sync

  • cartlib.announce {v=1, carts={meta...}} — each peer broadcasts the metadata (never bytes) of what it holds beyond the built-in carts: on load, after any upload or copy, and in answer to a hello.
  • cartlib.hello — sent on load and when a loader opens; every peer answers with an announce, so a late joiner learns the room.
  • Players who leave are dropped from every list (multiplayer.getPeers() checked on each list() and each tick()).

Transfer protocol

All messages are broadcasts that name their target peer first; other peers ignore them.

  1. requester → cartlib.req (holder, reqId, cartId)
  2. holder → cartlib.head (requester, reqId, chunkCount, byteLen) or cartlib.deny (requester, reqId, why)
  3. holder → cartlib.chunk (requester, reqId, i, base64) — 12 000 characters each, paced by a 150 KB/s budget shared by all transfers it serves; the budget halves when multiplayer.getDiagnostics().refusals rises and recovers by 10 % every half second.
  4. holder → cartlib.done; requester → cartlib.nack (holder, reqId, {missing}) for any gaps (also after 4 s without a chunk), up to 6 times.
  5. requester reassembles, checks the decoded length, caches in memory, announces itself as a holder. A holder that does not answer in 6 s, stalls or denies is swapped for the next holder (lowest latency first).

Carts over 8 MB never move (requester and holder both refuse); players upload their own copy.

Testing hook

Cartlib._addLocal(name, bytes, consoleHint?, { persist = false, share = false }?) is the path the picker uses after it reads the file (persist = false: session only; share = false: kept off the room's list); Cartlib._addFiles(files, consoleHint?, opts?) is the same for a picker's whole selection. _split, _assembler, _encode, _decode, _classify and _fetchFrom(peer, id, meta, onDone) are exposed for tests.

Interface

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

conforms to

zero/source-extract/v2

strict

now( ) → number

myPeer( ) → number

connected( ) → boolean

send(channel: string, ...: any) → void

argtypedescription
channelstring
...any

extOf(name: string) → string

argtypedescription
namestring

sanitize(name: string) → string

argtypedescription
namestring

prettyTitle(name: string, isBios: boolean, console: string) → string

argtypedescription
namestring
isBiosboolean
consolestring

formatSize(n: number) → string

argtypedescription
nnumber

makeId(console: string, name: string, size: number) → string

argtypedescription
consolestring
namestring
sizenumber

_split(s: string, size: number) → void

split a string into pieces of at most `size` characters

argtypedescription
sstring
sizenumber

_assembler(total: number) → any

Reassembles a numbered chunk stream: add(idx, data) in any order, with duplicates ignored; missing() lists the gaps; result() concatenates.

argtypedescription
totalnumber

add(idx: number, data: string) → boolean

argtypedescription
idxnumber
datastring

complete( ) → boolean

missing(limit: number?) → void

argtypedescription
limitnumber?

result( ) → string

_encode(bytes: string) → void

encode bytes for the wire: base64 chunks

argtypedescription
bytesstring

_decode(joined: string, byteLen: number) → string

decode a completed stream; nil when malformed or the length is wrong

argtypedescription
joinedstring
byteLennumber

loadConsoles( ) → void

consoles( ) → void

claimedBy(bytes: string) → string

the console (other than the Neo Geo) whose core claims these bytes, e.g. a zip holding a Mega Drive cart; cores opt in with spec.claims(bytes)

argtypedescription
bytesstring

_classify(name: string, bytes: string?) → void

which console a filename belongs to, and whether it is a BIOS set; with the bytes, a zip that another console claims (a zipped Mega Drive cart) is that console's

argtypedescription
namestring
bytesstring?

_biosPart(name: string) → void

what a loose file is to the Neo Geo BIOS: role ("system", "sfix", "sm1", "lo") and the name it takes inside the packed zip. Forgiving about renamed copies ("sp-s2 (1).sp1", "sfix.sfx").

argtypedescription
namestring

coreBiosRole(n: string) → string

the role a file inside a BIOS zip plays for the core, by the exact names it looks up

argtypedescription
nstring

neoZip( ) → any

baseName(entryName: string) → string

argtypedescription
entryNamestring

inspectZip(bytes: string) → void

what a zip holds for the BIOS: role -> file name (exact core names), whether a game's program ROM is in it, and the forgiving part names of every file

argtypedescription
bytesstring

_storeZip(files: { { name: string, bytes: string } }) → string

a zip with every file stored (no compression), readable by the core's zip reader

argtypedescription
files{ { name: string, bytes: string } }

scanBuiltin( ) → void

scanStored( ) → void

localHeld(id: string) → Held

argtypedescription
idstring

fireChanged( ) → void

onChanged(cb: () → void

argtypedescription
cb(

peerSet( ) → void

prune( ) → boolean

forget the carts of peers that have left; true when anything was dropped

heldForAnnounce( ) → void

add(h: Held) → void

argtypedescription
hHeld

announceSoon( ) → void

validMeta(m: any) → Meta

argtypedescription
many

list(consoleId: string?) → void

argtypedescription
consoleIdstring?

entryFor(id: string, console: string, title: string, size: number, isBios: boolean, builtin: boolean) → Entry

argtypedescription
idstring
consolestring
titlestring
sizenumber
isBiosboolean
builtinboolean

addHolder(e: Entry, peer: number) → void

argtypedescription
eEntry
peernumber

get(id: string) → Entry

argtypedescription
idstring

has(id: string) → boolean

argtypedescription
idstring

bytes(id: string) → string

argtypedescription
idstring

biosFor(consoleId: string) → string

argtypedescription
consoleIdstring

refresh( ) → void

rescan disk and the runtime library (after something outside this module changed either)

heldParts( ) → void

canonical part name -> role, for every part held (stored and this session's)

partBytes(name: string) → string

argtypedescription
namestring

biosZipRoles( ) → void

role -> file name inside the BIOS zip the core will be handed

neoSetup( ) → NeoSetup

What the Neo Geo needs and what this player already has.

assembleBios(opts: CartAddOpts?) → Entry

pack every system file held (from the current BIOS zip and the loose parts) into neogeo.zip once a system ROM, sfix and sm1 are all here

argtypedescription
optsCartAddOpts?

addBiosPart(canonical: string, bytes: string, opts: CartAddOpts?) → Entry

keep one loose system file; returns the BIOS entry when it completed the set

argtypedescription
canonicalstring
bytesstring
optsCartAddOpts?

_addLocal(name: string, bytes: string, consoleHint: string?, opts: CartAddOpts?) → void

The one path every new cart takes (the picker, tests, other code): classify, validate, keep in memory for the session, persist to the player's runtime-data library (unless opts.persist == false), list and announce. Yields while persisting.

argtypedescription
namestring
bytesstring
consoleHintstring?
optsCartAddOpts?

addBiosZip(bytes: string, opts: CartAddOpts?) → void

argtypedescription
bytesstring
optsCartAddOpts?

isUploading( ) → boolean

upload(consoleId: string?) → void

argtypedescription
consoleIdstring?

addExt(x: string) → void

argtypedescription
xstring

_addFiles(files: { any }, consoleId: string?, opts: CartAddOpts?) → void

Add what a picker brought: { { name, bytes?, vfsPath? } }. Answers the entry to show (a game before a BIOS), what went wrong, and a note for files kept on the way to something (Neo Geo system files waiting for the rest).

argtypedescription
files{ any }
consoleIdstring?
optsCartAddOpts?

startServer( ) → void

progress(id: string) → number

argtypedescription
idstring

finish(rid: string, ok: boolean, why: string?) → void

argtypedescription
ridstring
okboolean
whystring?

holdersOf(id: string) → void

argtypedescription
idstring

nextHolder(rid: string, why: string) → void

argtypedescription
ridstring
whystring

watchdog(rid: string) → void

argtypedescription
ridstring

startRequest(rid: string) → void

argtypedescription
ridstring

complete(rid: string) → void

argtypedescription
ridstring

_fetchFrom(peer: number, id: string, meta: Meta, onDone: (boolean, string?) → void

internal: fetch from one named peer, even when the bytes are already here (the loopback test uses it with this peer as the holder)

argtypedescription
peernumber
idstring
metaMeta
onDone(boolean, string?

fetch(id: string, onDone: (boolean, string?) → void

argtypedescription
idstring
onDone(boolean, string?

focusRing(style: any, radius: number?) → any

the hangout's focus ring (stations.hui), or a plain one where the kit is absent

argtypedescription
styleany
radiusnumber?

peerName(peer: number) → string

argtypedescription
peernumber

whoHas(e: Entry) → string

argtypedescription
eEntry

consoleLabel(id: string) → string

argtypedescription
idstring

setStatus(s: string, tone: string?) → void

argtypedescription
sstring
tonestring?

chip(text: string, fg: string, bg: string) → any

argtypedescription
textstring
fgstring
bgstring

labelColour(title: string) → string

argtypedescription
titlestring

cartArt(e: Entry) → any

argtypedescription
eEntry

cartTile(e: Entry, i: number, rowId: string, action: string, actionFg: string, actionBg: string, compact: boolean?, nav: { [string]: string }?) → any

`compact` (a screen too short for the tall card: a phone turned sideways) lays the cartridge beside its title and PLAY instead of above them

argtypedescription
eEntry
inumber
rowIdstring
actionstring
actionFgstring
actionBgstring
compactboolean?
nav{ [string]: string }?

huiKit( ) → any

tok(name: string, fallback: string) → string

argtypedescription
namestring
fallbackstring

txt(text: string, style: any) → any

argtypedescription
textstring
styleany

fileChip(text: string) → any

argtypedescription
textstring

extsOf(consoleId: string) → void

argtypedescription
consoleIdstring

helpNode(tab: string, consoles: { string }, compact: boolean, neo: NeoSetup?) → any

which files a tab takes, and where uploads go

argtypedescription
tabstring
consoles{ string }
compactboolean
neoNeoSetup?

stepMark(done: boolean, n: string) → any

argtypedescription
doneboolean
nstring

stateChip(done: boolean, doneText: string, todoText: string) → any

argtypedescription
doneboolean
doneTextstring
todoTextstring

fileState(have: boolean, label: string, optional: boolean?) → any

argtypedescription
haveboolean
labelstring
optionalboolean?

neoCard(s: NeoSetup, compact: boolean, nav: { up: string, down: string }) → any

the Neo Geo's two steps: its system files, then a game zip

argtypedescription
sNeoSetup
compactboolean
nav{ up: string, down: string }

showcase( ) → any

consoleEntry(id: string) → any

argtypedescription
idstring

lastConsole( ) → string

rememberConsole(id: string) → void

argtypedescription
idstring

consoleFacts(id: string) → void

the console's name, its kind line, how many games the room has for it and the files it takes

argtypedescription
idstring

stageLayout( ) → any

the stage's size on this screen: the card, the 3D view and what sits by it

chevron(id: string, glyph: string, cb: string, side: string, h: number) → any

argtypedescription
idstring
glyphstring
cbstring
sidestring
hnumber

stageTree( ) → any

buildTree( ) → any

goId(i: number) → string

argtypedescription
inumber

render( ) → void

renderSoon( ) → void

pickEntry(e: Entry) → void

argtypedescription
eEntry

setShelfControls( ) → void

stageStep(d: number) → void

argtypedescription
dnumber

stageInput(on: boolean) → void

argtypedescription
onboolean

focusSoon(target: string) → void

argtypedescription
targetstring

enterStage( ) → void

the stage, back from a console's games (or as the shelf opens)

enterList(id: string) → void

a console's games, chosen on the stage

argtypedescription
idstring

stageDrag(data: any) → void

argtypedescription
dataany

openLoader(opts: LoaderOpts) → void

argtypedescription
optsLoaderOpts

onCallback(id: string, data: any) → void

argtypedescription
idstring
dataany

closeLoader( ) → void

isLoaderOpen( ) → boolean

handleCallback(id: string, data: any) → boolean

Route a UI callback id. Returns true when it was the loader's. Safe to call from a component's onCallback even though the module registers its own callback env: a repeat of the same id within a frame or two is ignored.

argtypedescription
idstring
dataany

tick( ) → void

⌬ Types
Entry = {CartAddOpts = { persist: boolean?, share: boolean? }NeoSetup = {

Problems

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

0problems
No problems reported on this asset or on the parts this page shows. Parts it leaves out are not counted here.
⌬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.