Multicart
.lnx cartridge that
bundles a menu program together with several independent game
ROMs. At power-on the cart's mini-loader runs the menu; when the player picks
a game, the menu calls multicart_run(),
which pulls that game off the cartridge — over the top of the menu — and
runs it. Launching a game overwrites the menu, so it is one game per power-on:
returning to the menu means a reboot. This page explains the cart layout, the
relocatable runtime loader, the multicart_run() hand-off, and the
lnx multicart + lynxdir build
flow.1. What a multicart is
The menu and every game are ordinary Lynx programs. Each is compiled and linked
on its own as a BLL object (cl65 -C lynx-bll.cfg) —
the same object format the single-program cart tools
understand. The menu knows nothing about the games beyond their slot number, and
each game is complete and self-contained: it boots through its own
crt0 exactly as it would if it were the only program on the cart.
What ties them together is a small runtime loader baked into the SDK and a directory the ROM builder lays down. When the player selects game n, the menu copies the loader into low memory and hands it the number n; the loader reads that game off the cartridge and starts it. Because the game is loaded on top of the menu, there is no way back without a power-cycle.
2. Building one
Three steps turn a menu and some games into a bootable cart. cl65
builds each program as a BLL object; lnx multicart
writes a lynxdir .mak describing the
layout; and lynxdir assembles the final image (naming its output
after the .mak):
cl65 -C lynx-bll.cfg -o menu.o menu.c
cl65 -C lynx-bll.cfg -o game1.o game1.c # game2.o, game3.o, ...
lnx multicart --menu menu.o -o multicart.mak game1.o game2.o game3.o
lynxdir multicart.mak # -> multicart.lnx (+ .lyx)
The order of the game files on the lnx multicart command line sets
the game numbers multicart_run() takes: the first game is 0, the
second is 1, and so on. The multicart example wires all
of this into a Makefile.
lnx multicart options: --menu <file> (required),
--blocksize 512|1024|2048 (default 2048),
--dirstart N, --diroffset N (default 896), and
-o <file>. The defaults match the layout the runtime loader
is built for; change them only if you also rebuild the loader.
3. The cart layout
lnx multicart emits a layout with three fixed regions in cart
block 0. The NewMini mini-loader at $FB68 runs the
first directory entry at power-on — the EPYX-encoded menu.
Behind the menu sits the game directory at byte offset
$0380 (896), followed by the BLL-encoded game images.
3.1. The game directory
Each directory entry is 8 bytes, in Bastian Schick's new_bll
NEWHEAD format. Entry n lives at
MULTICART_DIROFFSET + n×8:
| Offset | Field | Meaning |
|---|---|---|
0 | StartBlock | first cart block of the file |
1–2 | BlockOffset | byte offset within that block (little-endian) |
3 | ExecFlag | new_bll exec flag (unused by this loader) |
4–5 | DestAddr | RAM load address (little-endian); 0 = append to previous |
6–7 | FileLen | image length in bytes (little-endian) |
Every bundled program is a full BLL image whose DestAddr is
$0400 (__MAIN_START__), so each game loads to the same
place the menu ran — over the top of it.
4. Launching a game: multicart_run()
From inside the menu, multicart_run(n)
performs the hand-off. It never returns.
Step by step, multicart_run():
- masks interrupts (
sei) — the loader runs with IRQs off; - clears the timer-interrupt enables on TIM0 (HBL) and TIM2 (VBL) so a pending frame IRQ cannot run menu code that is about to be overwritten;
- blanks the palette for a clean hand-off (no garbage flash while the game loads and before it installs its own palette);
- copies the
_multicart_loaderblob down to$0040; jmp $0040withA = romNum.
The loaded game re-initialises the timers, palette and everything else from
scratch in its own crt0, so the blanked/stopped state the menu leaves
behind is only ever transient.
5. The relocatable runtime loader
The loader (runtime/lynx/multicartldr.s) is a small, self-contained
routine — a trimmed reimplementation of new_bll's file loader.
Where the SDK's power-on bootloader only ever loads directory entry 0, this
loader takes a file number in A and indexes the game
directory at MULTICART_DIROFFSET. It reads bank 0 through
RCART0, strobing the cart block-address shift register to select each
block, and uses zero page $00–$0D as scratch (free, because the
menu is being torn down).
It is not linked into a program. It is assembled and linked on its own with
cfg/lynx-multicartldr.cfg, which locates it at $0040 and
emits a headerless raw image; tools/lnx/gen-multicartldr.sh
(make multicart-loader-gen) captures those bytes as the committed
blob libraries/core/multicartldr_gen.s. Because the captured bytes
carry the absolute addresses the linker resolved at $0040, the blob
is position-dependent: it only runs correctly at
$0040. Regenerate the blob after any change to the loader source.
The blob is copied to $0040 with an ascending count-up loop, not a
descending one. This matters: the blob is larger than 128 bytes, and a
dey / bpl loop would treat a starting index of
128 or more as already negative and copy nothing at all, leaving the CPU to
execute stale bytes at $0040 and hang. An
.assert multicart_loader_size ≤ $100 guards the
one-page bound. See design/LYNX_MULTICART_DESIGN.md.
6. Writing a menu
A menu is a normal Lynx program. It draws the game list, reads the joypad, and
calls multicart_run() when the player commits. Include
<lynx/multicart.h>:
#include <lynx/multicart.h>
void __fastcall__ multicart_run (unsigned char romNum);
multicart_run(romNum) launches bundled game number
romNum (0 = the first game in the directory the ROM builder laid
down). It masks interrupts, stops the display timers, blanks the palette, copies
the runtime loader to $0040 and jumps to it; the loader reads the
selected game off the cartridge and runs it. It overwrites the menu and
never returns, so call it only from a program that was itself built and
bundled as a multicart menu. The header also exposes the two layout constants for
reference and tooling:
| Macro | Value | Meaning |
|---|---|---|
MULTICART_DIROFFSET | 0x0380 (896) | game-directory offset within cart block 0 |
MULTICART_LOADER_ADDR | 0x0040 | where the runtime loader is copied to and runs |
A minimal launch, once the player has chosen a slot sel:
if (pressed & JOY_BTN_A_MASK) {
multicart_run (sel); /* load + run game "sel"; never returns */
}
7. Limitations and gotchas
- One game per power-on. A launched game overwrites the menu; there is no return path without a reboot. Design the menu accordingly.
- Games must be BLL objects. Build the menu and every game with
cl65 -C lynx-bll.cfg. A game linked with a different config will not carry the BLL header the directory and loader expect. - The loader is built for the default layout. The 2048-byte
block size and the
$0380directory offset are baked into the runtime loader. If you pass a non-default--blocksizeor--diroffsettolnx multicart, rebuild the loader to match and regenerate its blob. - No ONCE padding is needed. A bundled game's own startup ONCE reclaim relocation stays within its BSS region and does not touch neighbouring files, so no dead-space filler between games is required.
8. License
The Lynx runtime, like the rest of the package, is distributed under the cc65 zlib-style license. The full text, together with every other copyright notice in the distribution, is reproduced verbatim on the consolidated Licenses and copyright notices page.