lnx Users Guide
.lnx file). It can
print or hex-dump the header, rewrite its fields from command-line flags or a
per-game JSON config, and wrap a raw image with a fresh header. It is a
post-build editor, not a linker: cartridge images are still produced by ld65 and
the cfg/*.cfg memory layout.1. Overview
Every linked .lnx file begins with a fixed 64-byte header that emulators
(Handy, Mednafen) and flash carts read to learn the cartridge's bank sizes,
name, manufacturer and screen rotation. In the lynxcc runtime this header is
emitted by runtime/lynx/exehdr.s with placeholder values baked in at
assembly time, so changing a game's cartridge name or rotation would otherwise
mean editing the shared runtime and relinking.
lnx makes the header a post-link, per-game configuration. A project keeps a small JSON file describing its cartridge metadata and stamps it onto the built image with a single command. The image body is never touched — only the 64 header bytes are rewritten — so patching is fast and safe to repeat.
lnx deliberately does not link programs, list or extract directory segments, or
convert sprites. Symbol resolution and relocation stay with ld65 and the
cfg/*.cfg files; sprite conversion is sp65's job. lnx reads and rewrites the
header, wraps a raw image with one, and — with the bll command
(section 6) — wraps an already-linked BLL/BS93 object
with the boot loader that turns it into a runnable cartridge ROM. That last step
is a post-build format conversion of a finished object, not a second linker.
2. The .lnx header
The header is 64 bytes; multi-byte numbers are little-endian. String fields are stored fixed-width and NUL-padded.
| Offset | Size | Field | Notes |
|---|---|---|---|
| 0 | 4 | magic | ASCII "LYNX" |
| 4 | 2 | bank-0 page size | bank-0 cart block size (e.g. 1024) |
| 6 | 2 | bank-1 page size | bank-1 block size (0 if single bank) |
| 8 | 2 | version | format version (1) |
| 10 | 32 | cart name | NUL-padded ASCII |
| 42 | 16 | manufacturer | NUL-padded ASCII |
| 58 | 1 | rotation | 0 none, 1 left, 2 right |
| 59 | 1 | audin | AUDIN used for addressing: 0 no, 1 yes |
| 60 | 1 | eeprom | EEPROM flag bit field (below) |
| 61 | 3 | spare | reserved, written as zero |
The EEPROM flag byte (offset 60) is a bit field: bits 0–2 select the chip
(0 none, 1 93c46, 2 93c56, 3 93c66, 4 93c76, 5 93c86; size in bits is
2chip+9), bits 3–5 are reserved, bit 6 is 0 for a real EEPROM
chip or 1 for a LynxSD save file, and bit 7 is the word size (0 = 16-bit,
1 = 8-bit). lnx info decodes these bits for you.
A file is treated as having a header when its first four bytes are
LYNX; otherwise it is a raw (headerless) image, as produced by a no-header
linker config or any binary you want to wrap with lnx create. Over-long name
values are truncated to the field width (31 characters for the cart name, 15 for
the manufacturer) with a warning; the 64-byte header size never changes.
3. Usage
3.1. Command line overview
lnx is invoked with a command, options, and an input file:
---------------------------------------------------------------------------
usage: lnx <command> [options] <file>
commands:
info <file.lnx> print the header fields
dump <file.lnx> hex+ASCII dump of the 64-byte header
patch [field-opts] <file> rewrite header fields of a .lnx
create [field-opts] <raw> wrap a raw image with a fresh header
bll [bll-opts] <obj.o> BLL/BS93 object -> bootable cart ROM
bll options:
--size 128|256|512 target cart size in KiB (default: smallest fit)
--lnx also prepend a 64-byte LYNX header
(plus the field options below, which apply to the --lnx header)
field options (patch/create/bll):
--config <file.json> read fields from a JSON config
--allow-unknown accept (and ignore) unrecognised config keys
--cartname <str> set the 32-byte cart name
--manufacturer <str> set the 16-byte manufacturer name
--rotation none|left|right set the rotation flag (or 0|1|2)
--audin 0|1 set the AUDIN-addressing flag
--eeprom <n> set the whole EEPROM flag byte (bit field)
--eeprom-chip <name|0-5> set EEPROM chip (none|93c46|93c56|93c66|93c76|93c86)
--eeprom-lynxsd 0|1 set the LynxSD-save bit (bit 6)
--eeprom-word 8|16 set the EEPROM word size (bit 7)
--bank0 <n> set bank-0 page size
--bank1 <n> set bank-1 page size
--version <n> set the header version word
-o, --output <file> write result here (create requires -o;
patch defaults to in place)
-h, --help this help
-V, --tool-version print tool version
---------------------------------------------------------------------------
3.2. Commands in detail
info <file.lnx>-
Print the decoded header fields (cart name, manufacturer, rotation, bank page sizes, version) in human-readable form. Read-only. Errors if the input has no
LYNXheader. dump <file.lnx>-
Print a hex-and-ASCII dump of the raw 64 header bytes, for verifying exact on-disk layout. Read-only.
patch [field-opts] <file>-
Rewrite the header of an existing
.lnxfrom the supplied field options and/or--configfile. With no-o, the header is rewritten in place; with-o, the file is copied and the copy's header is rewritten. The body after byte 64 is left byte-for-byte unchanged, so re-running the same patch leaves the file identical. Errors if the input has noLYNXheader (usecreateto add one). create [field-opts] <raw>-
Wrap a raw (headerless) image with a fresh 64-byte header, writing
<header><raw body>to the-otarget (which is required). The fresh header starts from documented defaults (bank0 = 1024, bank1 = 0, version = 1, rotation = none, blank names) and is then overlaid with the config/flags. A warning is printed if the input already starts withLYNX, since that would double-head the image. bll [bll-opts] <obj.o>-
Convert a BLL/BS93 object — as produced by
cl65 -C cfg/lynx-bll.cfg— into a bootable raw cartridge ROM, writing it to the-otarget (required). See section 6 for the object format, the ROM layout and the--size/--lnxoptions.
3.3. Field options
The field options are shared by patch and create. They are applied in a
fixed order regardless of their order on the command line: the starting header
(an existing one for patch, the defaults for create) is overlaid first by
any --config file, then by each explicit --flag. So a flag always wins over
the same field in the config, which lets a build pass a one-off override on top
of the checked-in per-game JSON:
--config <file.json>Read header fields from a JSON config (see section 4).
--allow-unknownAccept and ignore config keys the tool does not recognise, instead of rejecting them as errors. Lets a shared config carry extra attributes the tool has no field for (see section 4).
--cartname <str>Set the 32-byte cart name (truncated to 31 characters if longer).
--manufacturer <str>Set the 16-byte manufacturer name (truncated to 15 characters if longer).
--rotation none|left|rightSet the rotation flag. The numeric forms
0,1,2are also accepted.--audin 0|1Set the AUDIN-used-for-addressing flag.
--eeprom <n>Set the whole EEPROM flag byte (0–255) as the raw bit field described in section 2.
--eeprom-chip none|93c46|93c56|93c66|93c76|93c86Set just the EEPROM chip (bits 0–2). A bare number
0–5is also accepted.--eeprom-lynxsd 0|1Set just the LynxSD-save bit (bit 6):
1= LynxSD save file,0= real EEPROM chip.--eeprom-word 8|16Set just the EEPROM word size (bit 7):
16-bit (common) or8-bit.--bank0 <n>/--bank1 <n>Set the bank-0 / bank-1 page size word (0–65535).
--version <n>Set the header version word (0–65535; normally 1).
-o, --output <file>Write the result to this file.
createrequires it;patchdefaults to rewriting the input in place.
4. Per-game JSON configuration
The per-game config is a flat JSON object. Every key is optional — only keys
that are present change the header, so the config layers cleanly on top of the
existing header (for patch) or the defaults (for create). Unknown keys are
rejected as errors by default, which catches typos rather than silently doing
nothing; pass --allow-unknown to accept and ignore keys the tool has no field
for (their values must still be a supported scalar — a string, an integer, or
true/false/null; nested objects and arrays remain unsupported).
{
"cartname": "Sybil's Quest",
"manufacturer": "lynxcc SDK",
"rotation": "left",
"audin": 0,
"eeprom_flag": 1,
"bank0_page_size": 1024,
"bank1_page_size": 0,
"version": 1
}
The keys map to header fields as follows:
| JSON key | Header field | JSON type |
|---|---|---|
cartname | cart name | string |
manufacturer | manufacturer | string |
rotation | rotation | string none/left/right or number 0/1/2 |
audin | AUDIN flag | number 0/1 or boolean |
eeprom_flag (alias eeprom) | EEPROM byte (whole) | number 0–255 (bit field) |
eeprom_chip | EEPROM bits 0–2 | chip name or number 0–5 |
eeprom_lynxsd | EEPROM bit 6 | number 0/1 or boolean |
eeprom_word_size | EEPROM bit 7 | number 8 or 16 |
bank0_page_size | bank-0 page size | number |
bank1_page_size | bank-1 page size | number |
version | version | number |
The EEPROM byte can be set as a whole (eeprom_flag) or field by field
(eeprom_chip, eeprom_lynxsd, eeprom_word_size), and the same applies to
the matching command-line flags. The pieces are combined in a fixed order
regardless of how they are supplied: the starting byte is the raw value if one
was given, otherwise the existing header byte, then the chip overlays bits
0–2, the LynxSD flag bit 6, and the word size bit 7. Fields you do not set
keep their existing bits, so you can flip one bit without touching the rest, and
a command-line flag overrides the same field from the config (for example
--eeprom-lynxsd 0 clears a LynxSD bit the config set).
lnx reads this config with a small built-in parser that accepts a single flat
object of string and integer values (plus the true/false/null literals).
Nested objects, arrays and fractional numbers are not supported and are
reported as errors — the header has no use for them, and the restriction keeps
lnx free of any third-party JSON dependency.
5. Examples
Inspect the header a build produced:
lnx info game.lnx
Stamp a checked-in per-game config onto the built image, in place:
lnx patch --config game.json game.lnx
Use the config but override the cartridge name for a special build, writing to a separate file rather than in place:
lnx patch --config game.json --cartname "Game (Beta)" -o beta.lnx game.lnx
Wrap a raw, headerless image with a fresh header described by a config:
lnx create --config game.json -o game.lnx game.raw
A Makefile can apply the per-game header as a post-link step after cl65:
game.lnx: src/main.c game.json
cl65 -o $@ src/main.c
lnx patch --config game.json $@
Turn a BLL/BS93 object into a bootable cartridge ROM (see section 6):
cl65 -t lynx -C cfg/lynx-bll.cfg -o game.o src/main.c
lnx bll game.o -o game.lyx
6. BLL objects → cartridge ROM
The SDK can link a program into a compact BLL/BS93 object with
cfg/lynx-bll.cfg: a 10-byte header followed by the program body, with no boot
loader and no cartridge padding. On its own such an object will not boot — it
still needs the Lynx secondary loader in front of it and a directory entry telling
that loader where the body lives. lnx bll performs exactly that wrap, producing
a raw cartridge ROM that boots on real hardware, emulators and flash carts.
6.1. The BLL/BS93 object
The object begins with a 10-byte header. Multi-byte numbers here are
big-endian. Bytes 6–9 hold the ASCII magic "BS93" — this is what
lnx bll checks to recognise the file (note the magic sits after the address and
length fields, not at offset 0).
| Offset | Size | Field | Notes |
|---|---|---|---|
| 0 | 2 | loader hint | not used by the conversion |
| 2 | 2 | load address | big-endian; where the body loads in RAM |
| 4 | 2 | block length | big-endian; length of header + body (body + 10) |
| 6 | 4 | magic | ASCII "BS93" |
| 10 | … | body | the program image (block length − 10 bytes) |
6.2. The cartridge ROM it builds
The output is a raw cartridge image: the 203-byte secondary loader, an 8-byte
directory entry at offset 0xCB, the object body at offset 211 (0xD3), and
zero padding out to the chosen cart size.
lnx bll from a BLL/BS93 object.The loader itself is the SDK's own boot loader (runtime/lynx/bootldr.s): the
three loader variants embedded in lnx are generated from it at build time, one per
block size, so a converted cartridge boots with exactly the loader the SDK ships
in its full ROMs.
6.3. Cart size and the LYNX header
By default lnx bll picks the smallest of 128, 256 or 512 KiB that holds the
body (the body must fit cart size − 211 bytes); --size forces a
particular size. The output is a raw image with no 64-byte LYNX header, which
is what flash carts and most emulators expect. Pass --lnx to additionally
prepend a header (built from the same field options and --config as
create); its bank-0 page size defaults to the cart's block size. Emulators strip
that header and boot the raw cartridge underneath, so both forms run identically.
7. Copyright
lnx is part of the lynxcc Lynx Game Development SDK. The full license text is reproduced verbatim, together with every other copyright notice in the distribution, on the consolidated Licenses and copyright notices page.