Migrating from upstream cc65 to lynxcc

What changes when you move a project from stock cc65 (its Lynx target) to the lynxcc SDK, and how to handle each difference.

1. Overview

lynxcc is not a drop-in upstream cc65: it is the Lynx Game Development SDK. Code and build scripts carried over from stock cc65 — including its own Lynx target — generally need some adjustment. This guide catalogs every difference a porter meets and how to handle it.

The good news first: the CC65_HOME discovery contract is unchanged. The include/, asminc/, lib/ and cfg/ directories keep their names and root locations, so existing project Makefiles that set CC65_HOME keep working without edits. A project that uses only the C standard library and the core platform, built through cl65, may need no changes at all (see section 5).

2. Differences from upstream cc65

2.1. Source- and build-level changes

AreaUpstream cc65lynxcc SDKPorting action
Platform includes<lynx.h> <tgi.h> <suzymath.h> <serial.h> <joystick.h> <zlib.h> <lz4.h>same headers, now under <lynx/…>Rewrite those #include lines (see 3.1); C-stdlib headers are unchanged.
Librariesone lynx.libcore lynx.lib + optional lynx-graphics, lynx-audio, lynx-math, lynx-compressUsually none — cl65 auto-pulls them. Only ld65-direct users add -l entries.
Tree layoutsrc/ libsrc/ samples/compiler/ runtime/ libraries/ examples/Affects only those who build the toolchain or reference tree paths, not end-user game projects.
Header shims—none by designA missing-header build error is the intended signal to run the include-rewrite.
CLI flags--target --cpu --memory-model --standardremoved — hard-wired to Lynx + 65SC02, permanent cc65 dialectDrop these flags from build scripts.

2.2. API and runtime changes

Fork-only operators. The Suzy hardware operators !*, !/ and !% are lynxcc extensions. Source using them is rejected by stock cc65, so the move is one-way — nothing to do when porting into lynxcc; relevant only if you ever port back out.

Removed and trimmed APIs. Several headers and library areas are gone or reduced. Replace or remove these uses:

Static drivers. There is no dynamic driver loading (modload, mouse, em and dbg are removed). Lynx graphics, joystick and serial are direct-call static APIs. Drop any driver-load or driver-install calls and use the static entry points directly.

3. Migration aids

3.1. The include-rewrite

Because the header move is mechanical and total (no shims), the supported path is a scripted rewrite that applies the fixed mapping below. The seven platform headers lynx.h tgi.h suzymath.h serial.h joystick.h zlib.h lz4.h each gain a lynx/ prefix; every other header (the C standard library) is left alone.

# Rewrite lynxcc platform includes in-place across a source tree.
for h in lynx tgi suzymath serial joystick zlib lz4; do
  find . -name '*.c' -o -name '*.h' -o -name '*.s' | xargs -r sed -i \
    -E "s@(#include[[:space:]]*[<\"])$h\.h([>\"])@\1lynx/$h.h\2@g"
done

Run it once over your project; a clean rebuild afterwards should resolve all missing-header errors that flagged the move.

3.2. Resolving the optional libraries

Whichever build path you use, the optional libraries must be resolved. The cl65 driver auto-resolves them for you, so a quick cl65 build needs no link-line change. When you build with the separate tools — the SDK's recommended path (see section 4, item 7, and Using make) — you list the optional libraries you use on the ld65 link line with -l, dependents-first and the core lynx.lib last.

3.3. Reference builds

Port against the updated examples/ and templates/, which demonstrate the new include paths and zero-config linking. Where an emulator is available, verify on tests/emu/gearlynx.

4. Checklist of concrete edits

The points below are the specific source and command-line changes most projects need. They expand on the differences in section 2 into an actionable list.

  1. Drop --standard from cc65 invocations. The only dialect now is cc65 — c89/c99 are no longer selectable — so the flag is removed.
  2. Include <lynx/lynx.h> wherever you use the hardware defines. Constants such as BPP_1, REHVST and the rest of the Suzy/Mikey symbols live in the platform headers that lynx/lynx.h pulls in; a source file that references them must include it explicitly.
  3. Remove the TGI driver-install calls. Delete every tgi_install(…) call, including the tgi_static_stddrv reference it took as its argument. Lynx graphics has no driver to install — call gfx_init instead.
  4. Change time_t variables to clock_t. The Lynx has no wall-clock/calendar time; time.h provides only clock() and sleep(), and the calendar types (time_t, struct tm, …) are gone.
  5. Replace open() with openn(). Lynx cart files are numbered, not named, so there is no open()/fopen(). Open a file by index with openn(fileno), then read()/lseek() on it.
  6. Use the chip-specific EEPROM functions. Replace the generic lynx_eeread/lynx_eewrite with the variant matching your cart's serial EEPROM: eeprom_93c46_read/eeprom_93c66_read/eeprom_93c86_read and the corresponding eeprom_93c46_write/eeprom_93c66_write/eeprom_93c86_write. The former lynx_ee* names still work as deprecated aliases — see section 7.
  7. Don't use assert(). assert.h has been removed; delete assert() calls and any code that relied on them.
  8. Build with the separate tools, not cl65. Move from the one-shot cl65 driver to invoking cc65, ca65 and ld65 as discrete steps; see Using make for a worked build.
  9. Drop the -t lynx option from every tool. The target is hard-wired to the Lynx, so the -t/--target selector no longer exists.

5. Compatibility deliberately preserved

The following are kept on purpose, so most projects move with minimal churn:

A project that uses only the C standard library and the core platform, built via cl65, may need no changes at all.

6. TGI Deprecation

The Lynx graphics API was historically named with the tgi_ / TGI_ prefix, after the cc65 "Tiny Graphics Interface" loadable-driver framework it was extracted from. That framework no longer exists in this tree — the graphics library is a direct-call static library for the one fixed Lynx display mode — so the public surface has moved to a plain gfx_ / GFX_ ("Lynx graphics") prefix.

The old names are deprecated but still work. Including <lynx/gfx.h> (or <lynx.h>, which pulls it in) gives you the canonical gfx_ names. Including <lynx/tgi.h> additionally defines one tgi_ alias per symbol; these are pure preprocessor macros that expand to the gfx_ names, so they add no code or data and do not defeat ld65 smart linking. The aliases will be removed in a future release.

To prove a project is already clean, define LYNX_NO_TGI_COMPAT before including the headers: the compatibility aliases are then suppressed and any lingering tgi_ / TGI_ use becomes a compile error. Once your sources build with that switch, you are ready for the eventual removal of <lynx/tgi.h>.

The full old→new equivalence is below; every old name maps to exactly one new name with unchanged semantics, arguments and return values.

6.1. Functions

Deprecated (tgi_*)Replacement (gfx_*)
tgi_initgfx_init
tgi_cleargfx_clear
tgi_clearrowsgfx_clearrows
tgi_spritegfx_sprite
tgi_flipgfx_flip
tgi_setviewpagegfx_setviewpage
tgi_setdrawpagegfx_setdrawpage
tgi_busygfx_busy
tgi_updatedisplaygfx_updatedisplay
tgi_setframerategfx_setframerate
tgi_setcollisiondetectiongfx_setcollisiondetection
tgi_setbppgfx_setbpp
tgi_setcolorgfx_setcolor
tgi_getcolorgfx_getcolor
tgi_setbgcolorgfx_setbgcolor
tgi_setpalettegfx_setpalette
tgi_getpalettegfx_getpalette
tgi_getdefpalettegfx_getdefpalette
tgi_gotoxygfx_gotoxy
tgi_outtextgfx_outtext
tgi_outtextxygfx_outtextxy
tgi_settextscalegfx_settextscale
tgi_settextstylegfx_settextstyle
tgi_setfontgfx_setfont
tgi_settextdirgfx_settextdir
tgi_gettextwidthgfx_gettextwidth
tgi_gettextheightgfx_gettextheight

6.2. Query macros

DeprecatedReplacement
tgi_getxresgfx_getxres
tgi_getmaxxgfx_getmaxx
tgi_getyresgfx_getyres
tgi_getmaxygfx_getmaxy
tgi_getcolorcountgfx_getcolorcount
tgi_getmaxcolorgfx_getmaxcolor
tgi_getpagecountgfx_getpagecount

6.3. Constants

DeprecatedReplacement
TGI_XRESGFX_XRES
TGI_YRESGFX_YRES
TGI_COLORCOUNTGFX_COLORCOUNT
TGI_PAGECOUNTGFX_PAGECOUNT
TGI_FONT_BITMAPGFX_FONT_BITMAP
TGI_FONT_COMPACTGFX_FONT_COMPACT
TGI_FONT_VARIABLEGFX_FONT_VARIABLE
TGI_TEXT_HORIZONTALGFX_TEXT_HORIZONTAL
TGI_TEXT_VERTICALGFX_TEXT_VERTICAL
TGI_COLOR_* (e.g. TGI_COLOR_WHITE)GFX_COLOR_* (e.g. GFX_COLOR_WHITE), declared in <lynx/lynx.h>

Header: include <lynx/gfx.h> instead of <lynx/tgi.h> (or just <lynx.h>, which now pulls in gfx.h).

7. EEPROM API rename

The serial-EEPROM read/write calls were historically named with a lynx_ee prefix that fused the platform tag and an abbreviated subsystem tag, and put the operation before the chip model (lynx_eeread_93c46). They now use a plain eeprom_ prefix with the chip model before the operation (eeprom_93c46_read), so the family reads and sorts by chip: all eeprom_93c46_* calls together, then eeprom_93c66_*, then eeprom_93c86_*. This matches the spelled-out, platform-prefix-free naming used by every other subsystem (gfx_, joy_, ser_, snd_).

The old names are deprecated but still work. Including <lynx/lynx.h> (or <lynx.h>) gives you the canonical eeprom_ names and additionally defines one lynx_ee* alias per function; these are pure preprocessor macros that expand to the eeprom_ names, so they add no code or data and do not defeat ld65 smart linking. The aliases will be removed in a future release.

To prove a project is already clean, define LYNX_NO_EEPROM_COMPAT before including the header: the compatibility aliases are then suppressed and any lingering lynx_ee* use becomes a compile error. Once your sources build with that switch, you are ready for the eventual removal of the aliases.

The full old→new equivalence is below; every old name maps to exactly one new name with unchanged semantics, arguments and return values.

Deprecated (lynx_ee*)Replacement (eeprom_<chip>_<op>)
lynx_eeread_93c46eeprom_93c46_read
lynx_eeread_93c66eeprom_93c66_read
lynx_eeread_93c86eeprom_93c86_read
lynx_eewrite_93c46eeprom_93c46_write
lynx_eewrite_93c66eeprom_93c66_write
lynx_eewrite_93c86eeprom_93c86_write

8. Default palette no longer auto-loaded

Historically gfx_init copied the built-in 16-colour default palette into the hardware palette. It no longer does: gfx_init now clears the palette to black, and the default palette table — together with the two calls that use it, gfx_setdefpalette and gfx_getdefpalette — now lives in its own object module. The 32-byte table is therefore linked into a program only when it is actually referenced: a program that installs its own palette with gfx_setpalette no longer pays for the default table it never uses.

This is a runtime-silent behaviour change, not a compile error. A program that drew text or sprites after gfx_init while relying on the implicit default palette now renders against an all-black palette (everything invisible). Every program must therefore install a palette after gfx_init, either by loading the built-in default with gfx_setdefpalette or by installing a custom palette with one of the two palette setters, gfx_setpalette (the 32-byte form) or gfx_setpalette16 (the condensed 16-entry form). To restore the historical default the fix is one line:

gfx_init ();
gfx_setdefpalette ();       /* restore the historical 16-colour default */

Programs already unaffected are those that call gfx_setpalette() with their own palette right after gfx_init(); they need no change. If you previously wrote gfx_setpalette (gfx_getdefpalette ()) to force the default, replace it with the shorter gfx_setdefpalette (), which loads the same table without exposing the pointer. All bundled examples were retrofitted this way.