Sample programs

A guide to every program in the examples/ directory of the Atari Lynx tree.

Each sample is a single, self-contained C file that builds to a .lnx cartridge image. They double as worked examples of this fork’s Lynx-specific features — the static Lynx graphics, joystick and serial libraries, and the Suzy hardware-math operators !* !/ !%. Build any one with the command shown, or run make in examples/ to build them all. Each entry carries a screenshot captured by booting its .lnx on the headless GearLynx emulator (tests/emu/gearlynx).

Getting started

lynxdemo.cstarter

lynxdemo on GearLynx: a scaled white ball above scaled HELLO, LYNX! text
Scaled sprite and text

The smallest complete Lynx program in the tree — the place to start.

  • Uses the static Lynx graphics library: no driver to install, just gfx_init().
  • A single hardware-scaled sprite bounces around a double-buffered screen.
  • Fractionally scaled text is drawn on top each frame.
Controls
A grows the ball, B shrinks it, pad left/right changes its colour.
Build
cl65 -Ors -o lynxdemo.lnx lynxdemo.c
Design notes
design/LYNX_GFX_DESIGN.md
Source
examples/lynxdemo.c · 90 lines

standaloneown Makefile

standalone on GearLynx: HELLO, WORLD! in white, centred on a black screen
One frame: default palette, HELLO, WORLD!

The barest self-contained project in the tree — the one to copy out and start from nothing.

  • Unlike every other sample, it is not built by the shared examples/ Makefile: it carries its own one-line cl65 build rule, so the directory works after you copy it out of the SDK tree and rename it.
  • Does only the minimum to put text on screen: gfx_init() brings up the static Lynx graphics library (no driver to load), gfx_setdefpalette() loads the built-in default palette, and one gfx_clear() / gfx_outtextxy() / gfx_updatedisplay() pass draws the message.
  • No game loop and no input: it renders a single frame and holds it, so the whole program fits in one screenful of C.
Build
make in examples/standalone/ (outputs land in build/)
Design notes
design/LYNX_GFX_DESIGN.md · design/LYNX_CL65_AUTOLIBS_DESIGN.md
Source
examples/standalone/src/main.c · examples/standalone/Makefile

Games

breakout.cSuzy math

breakout on GearLynx: a coloured brick grid above the paddle and ball with score and lives
Brick grid, paddle and ball

Single-file Breakout, built to exercise the fork's Suzy hardware math in real game code.

  • Paddle deflection, brick-grid hit testing and score formatting all run on Suzy's 16×16 multiply and 32/16 divide (!* !/ !%) instead of software loops.
  • The whole scene — 32 bricks, paddle and ball — is one SCB chain drawn with a single gfx_sprite() call; dead bricks are skipped with the SKIP bit.
  • All math sites stay in the main loop (never in IRQ), honouring the Suzy math contract.
Controls
Pad left/right moves the paddle, A serves / restarts.
Build
cl65 -Ors -o breakout.lnx breakout.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6
Source
examples/games/breakout.c · 338 lines

invaders.ccolour + sound

invaders on GearLynx: rows of colour-cycled invaders above bunkers and the cannon
Colour-cycled formation

Single-file Space Invaders — a companion to breakout that adds colour and audio.

  • Coloured enemies: every invader shares one sprite image; its row colour comes from the SCB penpal, and the RGB behind each pen is repainted from a 12-entry rainbow LUT so colour flows down the formation with zero extra sprite data.
  • Music + effects: channels C and D play the two-voice Space Invaders theme as compiled snd-engine streams (invtheme.s, extracted from the reference cartridge as interlocking pattern/loop sequences over a shared attack envelope); the streams self-loop while the interrupt walks them. Channels A and B stay hand-driven for laser and explosion noise (death/UFO share channel A) with per-frame volume envelopes.
  • Suzy math lays out the grid, does the hit-test lookup, paces the march and formats the score.
Controls
Pad left/right moves the cannon, A fires / restarts.
Build
cl65 -Ors -o invaders.lnx invaders.c invtheme.s
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6
Source
examples/games/invaders/invaders.c · 923 lines · examples/games/invaders/invtheme.s

lander.cphysics

lander on GearLynx: the lunar module firing its descent engine over jagged terrain with two landing pads, a fuel gauge and speed read-outs
Descent over randomised terrain with landing pads

A complete lunar-lander — MOON LANDER — with Newtonian flight, a fuel budget, randomised terrain and a full title menu, instructions screen and land / crash prompts.

  • Rotate the module and fire the descent engine against gravity; touch down slow, upright and on a flat pad to score, with narrower pads worth more. Position and velocity are 7.7 fixed point; a 24-entry sin/cos table turns the ship's heading into a thrust vector, so no trigonometry runs on the 6502.
  • The lander and its exhaust are pre-rendered rotation sprite sheets — 24 headings each, sliced from lander.pcx and flame.pcx by sp65 --sprite-sheet — so drawing a heading is one table index. Terrain columns, pads and stars are one solid sprite stretched and recoloured through each SCB pen palette, and the whole scene is one gfx_sprite() chain per frame. The HUD read-outs and landing score use the Suzy operators !* !/ !% in the main loop.
  • Four-channel audio through the snd engine: a calm menu loop and a driving melody-plus-bass game theme (compiled by abccc from the committed .abc tunes), a looping engine roar from the sfx pack while the thruster burns, and one-shot touchdown / crash blips.
Controls
Pad left/right rotate the lander, A fires the engine (burns fuel), Pause pauses. On the menu, Up/Down choose and A selects; on the instructions screen, B returns; after a landing or crash, A flies again and B returns to the menu.
Build
cl65 -Ors -o lander.lnx lander.c landermenu.s landergame.s landerbass.s
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6 · design/LYNX_SPRITE_SHEET_DESIGN.md · design/LYNX_SND_ENGINE_DESIGN.md · design/LYNX_SFX_LIBRARY_DESIGN.md
Source
examples/games/lander/lander.c · 744 lines · lander.pcx.py · landermenu.s landergame.s landerbass.s

raycaster.cscaled sprites

raycaster on GearLynx: a shaded first-person corridor view beneath a Wolfenstein-style status bar with an animated soldier face, wave, score, health and enemy count
Raycast 3D view with a Wolf3D-style status bar

A Wolfenstein-3D-style raycaster that leans on five things Lynx hardware makes cheap.

  • Hardware sprite scaling as a fill primitive: each vertical wall slice is one 2×1 solid sprite stretched by the SCB's vsize field — 80 scaled sprites paint the 3D view with no per-pixel plotting, and the same trick fills the ceiling band and the whole status-bar panel.
  • Suzy hardware math throughout the main loop: the first in-cell step is a hardware multiply (!*), and the billboard and hitscan projections are the fork's fused multiply-divide (lat !* projh !/ depth, one 32-bit operation). The per-column DDA delta-distances and slice height were hardware divides but are now reciprocal-table lookups built once at startup, so the wall cast issues no divide at all. None runs in an IRQ, so the math unit is never contended.
  • Cheap per-frame ray setup: the camera-plane sweep is stepped incrementally with a 32-bit add instead of a per-column divide-plus-multiply — and because those per-column values depend only on the view angle, the ramp runs only on frames the player turns; walking reuses the cached tables, a frame where nothing moved skips the wall cast entirely, and the DDA inner loop is add/index/load/test on a flat 256-byte map with its hot scalars in the zero page.
  • A Wolfenstein-style status bar across the bottom 22 rows — animated soldier face plus wave, score, health and enemies-left. Because it is opaque the 3D view is rendered only into the top 80 rows, a third fewer scaled-sprite fill pixels than a full-screen view.
  • One master sprite chain: sky, floor, all 80 wall columns, the billboard guards, the gun, the muzzle flash and the three status-bar pieces are linked back-to-front through their SCB .next pointers and painted by a single gfx_sprite() launch, so chain order is z-order, the CPU issues one sprite call per frame instead of ~90 — and because the chain members are opaque and cover every row between them there is no per-frame screen clear at all.
Controls
Pad up/down walks, left/right turns (hold B to strafe), A fires at the crosshair, Opt 1 toggles the HUD text for a clean view, Opt 2 toggles a half-resolution fast mode (40 double-width columns — half the raycast per frame).
Build
cl65 -Ors -o raycaster.lnx raycaster.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6, design/LYNX_RAYCASTER_DRAW_DESIGN.md
Source
examples/games/raycaster.c · 1213 lines

sybil.cplatformer

sybil on GearLynx: Sybil on stretched-block platforms with coins and enemies
Single-screen platformer

A single-screen Super-Mario-Bros.-style platformer starring Sybil.

  • Multi-colour 16×16 hardware sprite with true transparency: Sybil uses an identity SCB penpal (pixel value N → pen N), so her ten colours come straight from the 12-bit palette and pixel value 0 is the transparent pen of a TYPE_NORMAL sprite. Idle / run / jump animation just swaps the data pointer; left-facing frames are pre-mirrored arrays.
  • Sprite scaling as a fill primitive: every platform is one 8×8 solid block sprite stretched to size with the SCB hsize/vsize fields — a brown body plus a green cap, no tile map.
  • Direct Mikey audio (no driver): channel A = jump, B = coin / stomp, C = win & game-over jingles, D = ouch. Suzy math (!* !/ !%) formats the score and does coin scoring, all in the main loop.
Controls
Pad left/right runs, A jumps; A restarts after GAME OVER. Collect every coin to clear the level; stomp enemies from above, avoid them from the side.
Build
cl65 -Ors -o sybil.lnx sybil.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6 · design/LYNX_GFX_DESIGN.md
Source
examples/games/sybil.c · 781 lines

tetris.cpuzzle

tetris on GearLynx: a falling-block well with a settled stack, score/level/lines HUD and a next-piece preview
Falling-block well with HUD and next preview

A complete falling-block puzzle — TETROIDS — with a title menu, an instructions screen and the seven tetromino shapes.

  • A menu (Start / Instructions), a controls screen, gameplay and a game-over prompt, all driven by one state machine in the main loop.
  • The whole scene — grey well frame, every settled cell, the falling piece and the next-piece preview — is a single SCB chain drawn with one gfx_sprite() call. One 4×4 block image paints all seven piece colours plus the frame purely through per-SCB pen palettes (compare breakout.c).
  • Wall-kick rotation, hard drop and a level curve that shortens the drop interval as rows clear. Score formatting and the level-scaled line award use the Suzy hardware operators !* !/ !%, all in the main loop.
Controls
Pad left/right moves, Down soft-drops, Up hard-drops; A / B rotate; Pause pauses. On the menu, Up/Down choose and A selects; on the instructions screen, B returns.
Build
cl65 -Ors -o tetris.lnx tetris.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6 · design/LYNX_SPRITE_PADBYTE_DESIGN.md
Source
examples/games/tetris.c · 547 lines

Suzy hardware

muldivtest.ccorrectness

muldivtest on GearLynx: six pass/total sweeps all green with ALL PASS
All six sweeps passing

An on-hardware correctness test for the Suzy math operators !* !/ !%.

  • Six sweeps over a corner-value table compare each Suzy result against an independent software reference, in signed and unsigned variants.
  • Divisors 1, 127, 255 (narrow), 256 (boundary) and wide values exercise both sides of the small-divisor normalisation shift.
  • Shows pass/total per sweep and the first failing case; “ALL PASS” means every case matched.
Controls
A re-runs the sweeps.
Build
cl65 -O -o muldivtest.lnx muldivtest.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6
Source
examples/suzy/muldivtest.c · 189 lines

spritetest.cbuild-time packing

spritetest on GearLynx: a LITERAL and a PACKED heart drawn side by side, pixel-identical
Packed vs literal heart

The offline counterpart to packtest: sprite data packed at build time by sp65, not at runtime.

  • The Makefile runs the in-tree sp65 sprite converter (-c lynx-sprite,mode=packed and mode=literal) over heart.pcx to emit two C headers, which the sample #includes and drops straight into an SCB data pointer — no runtime packer in the ROM.
  • Both encodings of the same 16×16 image are drawn side by side at 3× scale with one identity-penpal SCB_REHV_PAL; only the PACKED bit of SPRCTL1 and the data pointer differ, so the columns must be pixel-identical while the packed block is the smaller asset.
  • heart.pcx keeps pen 0 along both side edges, so no scan line ends on an odd pen value and Suzy's last-pixel bug needs no pad byte; the PCX itself is reproduced by heart.pcx.py.
Build
make -C suzy/spritetest (regenerates the headers via sp65 first)
Design notes
doc/sp65.html §5, §6.4 · design/LYNX_SPRITE_PADBYTE_DESIGN.md §5
Source
examples/suzy/spritetest/spritetest.c · examples/suzy/spritetest/heart.pcx

spritesheet.csprite sheet

spritesheet on GearLynx: a single bouncing-ball frame drawn large under the SPRITE SHEET caption
One frame from the sheet table

Sprite sheets the easy way: sp65's --sprite-sheet driver turns one image into one indexable frame table.

  • One source image, sheet.pcx (a 4-frame, 16×16 bouncing-ball strip generated by sheet.pcx.py), is sliced in a single sp65 --sprite-sheet call that emits one header: a sheet_anim_data[] blob plus a generated sheet_anim[] pointer table and a sheet_anim_COUNT define.
  • Animating is just scb.data = (unsigned char *)sheet_anim[frame] — no per-frame files, no hand-written table.
  • The frame data is byte-for-byte identical to the manual --slice chain in spriteslice.c; only the packaging differs (verified on GearLynx, framebuffer read-back).
Build
make -C suzy/spritesheet (generates sheet_anim.h via sp65 first)
Design notes
design/LYNX_SPRITE_SHEET_DESIGN.md · doc/sp65.html §6.2
Source
examples/suzy/spritesheet/spritesheet.c · examples/suzy/spritesheet/sheet.pcx

spriteslice.cslice + pop

spriteslice on GearLynx: the same bouncing-ball frame drawn large under the SLICE + POP caption
Same frames, sliced by hand

Sprite sheets the manual way: sp65's --slice/--pop chain, no special tooling.

  • Reads the same sheet.pcx once and dices it into four standalone headers (frame0…frame3) in one sp65 run, popping back to the whole image between cells.
  • Because each header is an independent const unsigned char frameN[] sprite, the program gathers them into its own frames[] table and tracks the count itself — the hand-work the driver in spritesheet.c removes.
  • Draws the identical bouncing ball, proving the two routes produce the same frames; the right choice when you only want a few frames or want per-frame control.
Build
make -C suzy/spriteslice (generates frame0–3.h via sp65 first)
Design notes
design/LYNX_SPRITE_SHEET_DESIGN.md · doc/sp65.html §6.2
Source
examples/suzy/spriteslice/spriteslice.c · examples/suzy/spriteslice/sheet.pcx

sprpcktest.csprpck BMP + SPS

sprpcktest on GearLynx: a blue crystal labelled BMP beside a gold star labelled SPS, under the title sprpck
BMP crystal and SPS star

The sprpck counterpart to spritetest: sprites packed offline from the two input formats sp65 cannot read — a Windows BMP and a plain-ASCII SPS file.

  • The Makefile runs the vendored sprpck (tools/extern/sprpck) twice: -t6 -s4 logo.bmp logo.spr packs an indexed BMP, and -t2 -i016016 -s4 icon.sps icon.spr packs the ASCII star in icon.sps (one hex digit per pixel, space = pen 0).
  • sprpck writes the packed sprite as a raw binary .spr, not a C array, so sprpckdata.s pulls both in with ca65 .incbin and the C side reaches them as extern arrays — the idiomatic way to link sprpck output.
  • One SCB with a shared 16-pen palette draws both: the crystal in the BMP's compacted pens 1–3 (sprpck also emits a matching logo.pal), the star in its SPS pens 6 and 8. Default sprpck output is PACKED, so the SCB carries the packed SPRCTL1 bit.
Build
make -C suzy/sprpcktest (generates logo.spr/icon.spr via sprpck first)
Design notes
doc/sprpck.html · design/LYNX_EXTERN_TOOLS_DESIGN.md
Source
examples/suzy/sprpcktest/sprpcktest.c · examples/suzy/sprpcktest/sprpckdata.s · examples/suzy/sprpcktest/logo.bmp · examples/suzy/sprpcktest/icon.sps

spritefx.ctransforms + action point

spritefx on GearLynx: a large gold star scaled up and to the right of a fixed magenta cross, with FX:HSIZE SPR:STAR AP:BOT-LEFT read-outs
Star scaled about a bottom-left action point

An interactive tour of Suzy's four sprite transforms — hsize, vsize, stretch and tilt — and of where a sprite's action point sits.

  • One shape (cube / crystal / star / ball) is drawn around a fixed on-screen anchor and the selected transform is animated back and forth, so the picture visibly grows or shears outward from the anchor while the anchor pixel never moves. A bright magenta cross (a separate marker.pcx sprite whose own action point is its centre) is drawn at that anchor every frame to make the pivot unmistakable.
  • The action point is baked into the sprite data by sp65, not the SCB, so the Makefile compacts each shape five times — ax,ay at the four corners and the centre — and the program keeps a 4×5 table of the results. Cycling the action point swaps only the data pointer; every SCB scale field stays byte-for-byte identical, yet a scaled or sheared shape lands somewhere else because it now pivots about a different pixel. The centre variant is a true four-quadrant sprite, the case the hsizeoff/vsizeoff $007F correction (set once at start-up) exists to serve.
  • The four shapes use disjoint pen ranges baked in by spritefx_shapes.py, so one 16-entry palette and an identity SCB penpal colour all of them; sp65 picks each shape's bit depth from its highest pen index and the program reads the generated _COLORS define back to set the matching SPRCTL0 depth.
Controls
Pad selects the live transform (LEFT hsize, RIGHT vsize, UP stretch, DOWN tilt), A / B cycle the shape, OPTION 1 cycles the action point.
Build
make -C suzy/spritefx (regenerates the 20 shape headers + marker via sp65 first)
Design notes
doc/sprites.html §6, §6.1 · doc/sp65.html §6.1
Source
examples/suzy/spritefx/spritefx.c · examples/suzy/spritefx/spritefx_shapes.py · examples/suzy/spritefx/{cube,crystal,star,ball,marker}.pcx

suzyasync.casync math

suzyasync on GearLynx: a perspective starfield with the ASYNC SUZY MATH OK banner
Perspective starfield

A realistic use of the fork's asynchronous Suzy math (start / poll / harvest).

  • A perspective starfield: each star's screen position is a perspective divide, exactly the repeated divisor-varying divide the async API is built for.
  • The per-star projection is software-pipelined so the slow signed divide overlaps real, non-Suzy CPU work (depth update, screen-bounds culling).
  • A one-time self-check compares async results against the software operators; the HUD shows MATH OK or MATH FAIL.
Build
cl65 -O -o suzyasync.lnx suzyasync.c
Design notes
design/LYNX_SUZY_ASYNC_MATH_DESIGN.md
Source
examples/suzy/suzyasync.c · 212 lines

suzyasyncbench.casync speed

suzyasyncbench on GearLynx: a SOFT/SYNC/ASYNC timing table for three workload sizes
SOFT / SYNC / ASYNC timings

An honest speed benchmark for the asynchronous Suzy math API.

  • For three workload sizes (no / light / heavy work) it times SOFT (software divide), SYNC (blocking Suzy) and ASYNC (overlapped Suzy) per divide.
  • ASYNC runs unrelated CPU work in the shadow of the divide; the crossover where it overtakes SYNC is the whole point — with no overlap work it is honestly slower.
  • Every loop cross-checks SOFT, SYNC and ASYNC so a speed win is never a correctness loss.
Build
cl65 -Osri -o suzyasyncbench.lnx suzyasyncbench.c
Design notes
design/LYNX_SUZY_ASYNC_MATH_DESIGN.md
Source
examples/suzy/suzyasyncbench.c · 427 lines

suzybench.caccuracy + speed

suzybench on GearLynx: a SUZY MATH ACCURACY table with pass/fail counts per operator
Accuracy pass/fail table

The thorough accuracy-and-speed test for the synchronous Suzy math operators.

  • Correctness: each Suzy result is checked against the stock software operator over a corner cross-product plus a pseudo-random sweep, exercising all five runtime routines.
  • Speed: a free-running 24-bit, 1µs Mikey timer times software vs Suzy loops over identical operands, for both 8-bit and 16-bit widths.
  • A final screen pits cc65's compile-time strength reduction (shifts, AND masks, mulaxN helpers) against Suzy doing the same arithmetic.
Controls
A advances through the screens.
Build
cl65 -Osri -o suzybench.lnx suzybench.c
Design notes
design/LYNX_CODEGEN_DESIGN.md §2.6
Source
examples/suzy/suzybench.c · 964 lines

packtest.cpacked vs literal

packtest on GearLynx: LITERAL and PACKED columns of the same sprite at 1, 2, 3 and 4 bpp
Packed == literal, 1–4 bpp

On-hardware proof that Suzy's PACKED (RLE) sprite encoding is interchangeable with the LITERAL encoding, at every depth.

  • For each of the four Suzy depths (1/2/3/4 bpp) it draws the same 16×16 source image twice at 1× scale: a LITERAL copy as the control and a PACKED copy built at runtime by an in-program pack_line() encoder.
  • The source is deliberately adversarial — a vertical rainbow on top (every pen value, all adjacent pixels distinct: exercises literal packets and the value→pen map) over solid horizontal bands (exercises RLE runs).
  • Identity penpal and a TYPE_NORMAL sprite, so pixel value v draws pen v and value 0 is transparent; the literal copy carries the per-line pad byte and the packed copy's 00000 terminator supplies the same trailing slack for Suzy's last-pixel bug. If packing is correct the two columns are pixel-identical (verified on GearLynx, framebuffer read-back).
Build
cl65 -Ors -o packtest.lnx packtest.c
Design notes
design/LYNX_SPRITE_PADBYTE_DESIGN.md §1–2, §5–6
Source
examples/suzy/packtest.c

fonttest.cgraphics fonts

fonttest on GearLynx: the 5x5 compact font with a large scaled SCALE banner on blue
5×5 font, hardware-scaled

Shows the compact 5×5 Lynx graphics font and runtime font switching.

  • Selects GFX_FONT_COMPACT — 6-px pitch, transparent background, foreground drawn in the current pen.
  • Screen cleared to blue so the glyph transparency is obvious.
  • Suzy scales the text sprite natively in 8.8, so the banner is drawn at 1×/2×/3×.
Controls
A cycles the text scale (1× / 2× / 3×).
Build
cl65 -Ors -o fonttest.lnx fonttest.c
Design notes
design/LYNX_GFX_FONT5X5_DESIGN.md
Source
examples/suzy/fonttest.c · 81 lines

fontvar.cproportional font

fontvar on GearLynx: the proportional all-caps font showing tight I and wide M, W spacing
Proportional font

Shows the proportional (variable-width) Lynx graphics font and the advance-aware width query.

  • Selects GFX_FONT_VARIABLE — an all-caps pixel font whose glyphs are 1–5 px wide with a 1-px gap, transparent background, foreground in the current pen. The alphabet line makes the proportional spacing obvious: the I is tight, the M and W are wide.
  • Uses gfx_gettextwidth to centre the title and to drop a caret flush against a measured string — a visible proof that the proportional width query matches the glyphs gfx_outtext actually draws.
  • The B button cycles the sample block through all three fonts (proportional / 5×5 / 8×8), and Suzy scales the proportional text in 8.8 so glyphs and spacing grow together at 1×/2×/3×.
Controls
A cycles the scale (1× / 2× / 3×), B cycles the sample-block font.
Build
cl65 -Ors -o fontvar.lnx fontvar.c
Design notes
design/LYNX_GFX_FONTVAR_DESIGN.md
Source
examples/suzy/fontvar.c · 140 lines

textdir.cgraphics text

textdir on GearLynx: a HORIZONTAL panel with 010203 running left to right and a VERTICAL panel with the same tokens stacked top-down
Two text directions

Shows how gfx_settextdir changes the way the text cursor advances between successive gfx_outtext calls.

  • Each individual string is always drawn as a normal left-to-right strip; the direction only controls the post-draw cursor move — glyphs are never rotated.
  • GFX_TEXT_HORIZONTAL advances the cursor right by the string width, so chained tokens run on as 010203; GFX_TEXT_VERTICAL advances it down by one text line (the scaled font height), so the same calls stack top to bottom.
  • Both panels issue an identical gotoxy + three cursorless gfx_outtext sequence, isolating direction as the only difference.
Controls
A swaps which panel is highlighted.
Build
cl65 -Ors -o textdir.lnx textdir.c
Source
examples/suzy/textdir.c · 109 lines

collision.ccollision buffer

collision on GearLynx: a row of red, green, blue and yellow target blocks under the COLLISION BUFFER title; the white player block overlaps the third (blue) target, which has flashed magenta, and the read-out shows HIT TARGET 3
Depository read-back: HIT TARGET 3

Demonstrates Suzy's hardware collision buffer and the per-sprite collision depository — the only collision facility the Lynx has.

  • Four fixed target blocks carry distinct collision numbers 1–4; a white player block sweeps across them. Targets are drawn first so they lay their numbers into the collision buffer, then the player last — as it paints, Suzy reads those numbers back and drops the highest into the player's depository byte.
  • The depository lands one byte in front of the SCB (gfx_init sets COLLOFF = −1), so a wrapper struct with a leading coll byte reads which target was struck with no per-pixel testing in C; the hit target flashes and a HIT TARGET n read-out shows the value.
  • The one example in the tree that links with lynx-coll.cfg instead of the default config, because the collision buffer must be reserved in RAM; gfx_setcollisiondetection(1) turns detection on and makes gfx_clear() wipe both buffers each frame.
Controls
The player auto-sweeps; the d-pad steers it (up/down to change row, left/right to nudge).
Build
cl65 -Ors -C lynx-coll.cfg -o collision.lnx collision.c
Design notes
doc/collisions.html
Source
examples/suzy/collision.c

palette.cpalette

palette on GearLynx: sixteen full-width colour bands from red, green and blue through to greys under the LOADER: SETPALETTE title, with SNAPSHOTS: MATCH along the bottom
The same sixteen colours, loaded two ways — SNAPSHOTS: MATCH

Loads one palette by both of the arrays the palette generator emits, and proves they are equivalent.

  • The generator prints two C arrays for the same sixteen colours: a 32-byte unsigned char array for gfx_setpalette (16 green bytes, then 16 blue/red bytes) and a condensed 16-entry unsigned short array for gfx_setpalette16 (one packed 0x0GBR value per pen).
  • The example installs the 32-byte array, snapshots the hardware palette with gfx_getpalette, installs the 16-entry array, snapshots again, and compares the two: SNAPSHOTS: MATCH confirms gfx_setpalette16 splits each packed entry into the two GCOLMAP halves and lands exactly what gfx_setpalette does.
  • The sixteen pens are drawn as horizontal bands with gfx_clearrows; pressing A toggles which loader is live, and the bands do not change because both arrays describe the same colours.
Controls
A toggles the live loader between gfx_setpalette and gfx_setpalette16.
Build
cl65 -Ors -o palette.lnx palette.c
Design notes
doc/palgen.html, doc/graphics.html
Source
examples/suzy/palette.c

Mikey display

setbpp.c2bpp mode

setbpp on GearLynx: greyscale 2-bit bands and dither fields above the mode labels
2-bit greyscale display

Demonstrates gfx_setbpp() — the Lynx 2-bit / monochrome display mode.

  • Toggles Mikey's display DMA between 4bpp (Suzy-rendered) and a CPU-rendered 2bpp framebuffer (40 bytes/line × 102 lines, 4 pixels/byte).
  • Greyscale palette turns 2bpp into a monochrome mode: solid bands, three ordered-dither fields and a CPU-animated bouncing block.
  • Page-swap machinery is depth-independent, so the 2bpp screen is double buffered like any other.
Controls
A toggles 4bpp/2bpp, pad up rotates the display 180°.
Build
cl65 -Ors -o setbpp.lnx setbpp.c
Design notes
design/LYNX_GFX_DESIGN.md §2.7 — relies on a DISPCTL bit outside spec; unverified on hardware.
Source
examples/mikey/setbpp.c · 234 lines

Mikey audio

sndtune.csnd engine

sndtune on GearLynx: a pink screen titled lynxcc sound above abccc tune + sfx
Tune player title screen

Plays a compiled ABC tune through the snd sound engine alongside a direct-register beep.

  • The looping melody in theme_music[] is the event stream the abccc tune compiler emits offline from theme.abc; theme.s is committed beside the example so it links without the host tool present.
  • snd_init() then snd_play() starts the tune on channel 0, and the sound-timer interrupt advances the stream on its own while main() idles.
  • A one-shot rising blip on channel 3 uses only the mikey_snd_* direct helpers — taps, octave, pitch and volume — showing register-level SFX with no stream.
Build
cl65 -Ors -o sndtune.lnx sndtune.c theme.s
Design notes
design/LYNX_SND_ENGINE_DESIGN.md · doc/sound.html
Source
examples/mikey/sndtune/sndtune.c · 75 lines · examples/mikey/sndtune/theme.abc

sfxtest.csnd engine

sfxtest on GearLynx: a menu titled lynxcc sfx player listing six effects with Player shot highlighted and a stopped status line
Sound-test menu

A player-style sound test for the snd engine's compiled effect streams: pick an effect from a scrolling menu and audition it.

  • The effects in sfx.s are listed in a table-driven menu (sfx_list[]); adding a row to the table adds a menu entry automatically, so the same front-end scales to any number of effects.
  • The d-pad moves the highlight (the list scrolls when it overflows), A plays the selected effect on channel 0, and B stops every channel; the selected row is green and a still-sounding effect turns yellow, driven by snd_active().
  • Each effect is a self-contained event stream handed straight to snd_play(): the UFO drone loops until stopped, the rest are one-shots that free their channel on their own.
Build
cl65 -Ors -o sfxtest.lnx sfxtest.c sfx.s
Design notes
design/LYNX_SND_ENGINE_DESIGN.md · design/LYNX_SFX_LIBRARY_DESIGN.md · doc/sound.html
Source
examples/mikey/sfxtest/sfxtest.c · 153 lines · examples/mikey/sfxtest/sfx.s

sfxdemo.csfx pack

sfxdemo on GearLynx: a menu titled lynxcc sfx pack listing effects like Coin, Laser and Explosion with one row highlighted
Reusable sfx pack sound test

A sound test for the reusable sfx pack — the batteries-included effect library (<lynx/sfx.h>) that layers over the snd engine.

  • Fires every ready-made effect in the pack with the sfx_<name>(ch) macros — all 56 entries, from sfx_coin and sfx_laser to looping ambience like sfx_alarm — grouped into the same seven categories as <lynx/sfx.h>, each a pre-built compiled stream in lib/lynx-audio.lib.
  • Everything plays on channel 3, following the convention that reserves one channel for effects so they duck only themselves, never music on channels 0–2. The looping effects (alarm, ambient hum, engine, heartbeat) run until B calls snd_stop_channel.
  • Links with no extra source files: effects are still pulled out of the audio library at member granularity, but because this demo references the whole catalogue as a browser, it links in every effect object rather than a subset.
Controls
Up/Down move the selection (the list scrolls), A plays the effect on channel 3, B stops it.
Build
cl65 -Ors -o sfxdemo.lnx sfxdemo.c
Design notes
design/LYNX_SFX_LIBRARY_DESIGN.md · doc/sound.html §6
Source
examples/mikey/sfxdemo.c · 209 lines

System

poweroff.csoft power-off

poweroff on GearLynx: a SOFT POWER-OFF prompt explaining the SYSCTL1 power bit, with PRESS A TO POWER OFF
The prompt shown before power-off

Turns the Lynx off in software with poweroff().

  • Clears bit 1 of SYSCTL1 (0xFD87), the regulator's soft on/off line, which powers up as 1; clearing it disconnects the system from the battery — the same mechanism that auto-powers-off an idle unit.
  • The call masks interrupts and does not return on real hardware. A real game would save state to the EEPROM first; this demo keeps to the one call so the mechanism is clear.
  • A |/-\ spinner turns as a running-activity indicator: while it animates, power is on (SYSCTL1 bit 1 is still 1). It stops the instant poweroff() halts the CPU.
  • Emulators generally do not model the regulator soft-off, so under emulation the screen simply freezes on the “powering off” frame instead of switching off.
Controls
A powers the unit off.
Build
cl65 -Ors -o poweroff.lnx poweroff.c
Design notes
SYSCTL1 per tests/emu/gearlynx hardware notes; the soft-off is not modelled by emulators, so it is unverified in-sandbox.
Source
examples/mikey/poweroff.c · 110 lines

Memory

heaptest.cheap correctness

heaptest on GearLynx: a green OK grid of T1–T17 with PASS 17/17 and live heap variables
17/17 heap checks passing

On-target verification that the heap allocator's 2-byte block header behaves correctly.

  • Runs 17 checks across the public API — malloc, calloc, realloc, free, _heapblocksize, _heapmemavail, _heapadd — covering exact sizing, in-place vs moving realloc, coalescing and full reclamation.
  • Cross-checks the library against direct memory inspection: the raw size word stored just below each user pointer, the runtime heap variables (_heaporg / _heapptr / _heapend) and the free-list head, confirming the raw block is always (user − 2).
  • Draws a colour-coded grid — each test green (OK) or red (X) — with a PASS k/17 summary and the first failing test; the heap variables are shown live in hex.
Build
cl65 -Ors -o heaptest.lnx heaptest.c
Design notes
design/LYNX_HEAP_HEADER_DESIGN.md
Source
examples/memory/heaptest.c · 298 lines

zeropage.czero page

zeropage on GearLynx: live FRAME, PRESS and TICKH zero-page counters on blue
Live zero-page counters

Places C globals in the zero page with the __zeropage attribute.

  • Three counters are declared __zeropage (from <zeropage.h>), so the compiler emits them into the ZEROPAGE segment and addresses them with the fast 2-byte zero-page opcodes — inc _frame assembles to E6, not the 3-byte absolute EE.
  • No companion assembler file and no #pragma zpsym: a single C declaration both defines the storage and marks the symbol.
  • The Lynx graphics text harness shows the live counters; A and B bump the zero-page presses counter up and down.
Controls
A counts up, B counts down; the frame counter free-runs.
Build
cl65 -Ors -o zeropage.lnx zeropage.c
Design notes
design/LYNX_ZEROPAGE_VAR_DESIGN.md · doc/cc65.html §8.1
Source
examples/memory/zeropage.c · 105 lines

Network

comlynx.cserial + joypad

comlynx on GearLynx: OK 256, BAD 0, LOST 0, STATUS 00, CLOSED: QUIET OK loopback results
Serial loopback self-test

A ComLynx serial loopback self-test that needs no cable.

  • The ComLynx wire is open-collector with Tx and Rx tied together, so every transmitted byte is also received — a full send/receive/close test runs against itself.
  • Sends a known pattern at the Lynx-native 62500 baud, expects every byte back, then confirms reception stops once the port is closed.
  • Also demonstrates the static joy API: all nine inputs from one joy_read() call, with the one-line edge-detection idiom.
Build
cl65 -Ors -o comlynx.lnx comlynx.c
Design notes
design/LYNX_JOY_SER_DESIGN.md §8.2
Source
examples/network/comlynx.c · 131 lines

Storage

sdcardls.cSD/GD flash cart

sdcardls on GearLynx: the SD/GD CARD ROOT: title on a dark screen, the listing area empty because no SD card MCU is present
Root-listing front-end

Lists the root directory of a RetroHQ Lynx SD / GD flash cartridge using the sdcard_gd_* API.

  • Wakes the cart MCU with sdcard_gd_init(), opens the card root with sdcard_gd_opendir("/") and walks it with sdcard_gd_readdir(), printing each 8.3 name and marking sub-directories in green.
  • The opt-in lib/lynx-sdcard-gd.lib is auto-linked by cl65 (no -l flag) via the SDK manifest, exactly like the audio and compress libraries.
  • Only does anything on real hardware with an SD card inserted: in the emulator there is no cart-MCU to answer the FIFO handshake, so the capture shows just the title while the directory call waits. See SD / GD flash cart for the protocol and the on-card layout.
Build
cl65 -Ors -o sdcardls.lnx sdcardls.c
Design notes
design/LYNX_SDCARD_GD_API_DESIGN.md · doc/sdcard-gd.html
Source
examples/sdcard-gd/sdcardls.c · 72 lines

Multicart

multicartmenu loader

multicart on GearLynx: a MULTICART DEMO menu listing GAME 1, GAME 2 and GAME 3 with a cursor on GAME 1 and an UP/DOWN A=PLAY hint
Menu front-end; A launches a bundled game

A single .lnx that bundles a menu and three independent game ROMs; picking one loads it over the top of the menu and runs it.

  • The menu and each game are separate, self-contained programs built as BLL objects (cl65 -C lynx-bll.cfg); lnx multicart writes a lynxdir layout and lynxdir stitches them into one bootable cart.
  • multicart_run(n) hands off from the menu to game n: it stops the frame timers, blanks the palette, copies a small relocatable loader to $0040 and jumps to it; the loader pulls that game off the cartridge by its directory number and starts it.
  • Launching a game overwrites the menu, so there is no way back without a reboot — one game per power-on, as the LynxJam multicart worked on hardware.
Controls
Up/Down move the cursor, A (or B) launches the selected game.
Build
make in examples/multicart/ (drives cl65 + lnx multicart + lynxdir)
Design notes
design/LYNX_MULTICART_DESIGN.md · doc/multicart.html
Source
examples/multicart/menu.c · game1.c · game2.c · game3.c