Migrating from upstream cc65 to lynxcc
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
| Area | Upstream cc65 | lynxcc SDK | Porting 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. |
| Libraries | one lynx.lib | core lynx.lib + optional lynx-graphics, lynx-audio, lynx-math, lynx-compress | Usually none — cl65 auto-pulls them. Only ld65-direct users add -l entries. |
| Tree layout | src/ 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 design | A missing-header build error is the intended signal to run the include-rewrite. |
| CLI flags | --target --cpu --memory-model --standard | removed — hard-wired to Lynx + 65SC02, permanent cc65 dialect | Drop 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:
assert.h,device.h,pen.h,locale.h,sys/and the user-facingtarget.hare removed.time.his trimmed toclock()andsleep().- The stdio output family and the whole
FILEstream layer are gone; the in-RAMsprintf,snprintfandsscanfare kept. - Cart access is numbered-only (
openn) — there is nofopen.
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.
- Drop
--standardfromcc65invocations. The only dialect now iscc65—c89/c99are no longer selectable — so the flag is removed. - Include
<lynx/lynx.h>wherever you use the hardware defines. Constants such asBPP_1,REHVSTand the rest of the Suzy/Mikey symbols live in the platform headers thatlynx/lynx.hpulls in; a source file that references them must include it explicitly. - Remove the TGI driver-install calls. Delete every
tgi_install(…)call, including thetgi_static_stddrvreference it took as its argument. Lynx graphics has no driver to install — callgfx_initinstead. - Change
time_tvariables toclock_t. The Lynx has no wall-clock/calendar time;time.hprovides onlyclock()andsleep(), and the calendar types (time_t,struct tm, …) are gone. - Replace
open()withopenn(). Lynx cart files are numbered, not named, so there is noopen()/fopen(). Open a file by index withopenn(fileno), thenread()/lseek()on it. - Use the chip-specific EEPROM functions. Replace the generic
lynx_eeread/lynx_eewritewith the variant matching your cart's serial EEPROM:eeprom_93c46_read/eeprom_93c66_read/eeprom_93c86_readand the correspondingeeprom_93c46_write/eeprom_93c66_write/eeprom_93c86_write. The formerlynx_ee*names still work as deprecated aliases — see section 7. - Don't use
assert().assert.hhas been removed; deleteassert()calls and any code that relied on them. - Build with the separate tools, not
cl65. Move from the one-shotcl65driver to invokingcc65,ca65andld65as discrete steps; see Using make for a worked build. - Drop the
-t lynxoption from every tool. The target is hard-wired to the Lynx, so the-t/--targetselector no longer exists.
5. Compatibility deliberately preserved
The following are kept on purpose, so most projects move with minimal churn:
CC65_HOME/ WinBin discovery, and theinclude,asminc,libandcfgdirectory names and locations.- The basic
cl65workflow. .lnxoutput and cfg-driven memory layout.- All standard C library headers at their flat paths.
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_init | gfx_init |
tgi_clear | gfx_clear |
tgi_clearrows | gfx_clearrows |
tgi_sprite | gfx_sprite |
tgi_flip | gfx_flip |
tgi_setviewpage | gfx_setviewpage |
tgi_setdrawpage | gfx_setdrawpage |
tgi_busy | gfx_busy |
tgi_updatedisplay | gfx_updatedisplay |
tgi_setframerate | gfx_setframerate |
tgi_setcollisiondetection | gfx_setcollisiondetection |
tgi_setbpp | gfx_setbpp |
tgi_setcolor | gfx_setcolor |
tgi_getcolor | gfx_getcolor |
tgi_setbgcolor | gfx_setbgcolor |
tgi_setpalette | gfx_setpalette |
tgi_getpalette | gfx_getpalette |
tgi_getdefpalette | gfx_getdefpalette |
tgi_gotoxy | gfx_gotoxy |
tgi_outtext | gfx_outtext |
tgi_outtextxy | gfx_outtextxy |
tgi_settextscale | gfx_settextscale |
tgi_settextstyle | gfx_settextstyle |
tgi_setfont | gfx_setfont |
tgi_settextdir | gfx_settextdir |
tgi_gettextwidth | gfx_gettextwidth |
tgi_gettextheight | gfx_gettextheight |
6.2. Query macros
| Deprecated | Replacement |
|---|---|
tgi_getxres | gfx_getxres |
tgi_getmaxx | gfx_getmaxx |
tgi_getyres | gfx_getyres |
tgi_getmaxy | gfx_getmaxy |
tgi_getcolorcount | gfx_getcolorcount |
tgi_getmaxcolor | gfx_getmaxcolor |
tgi_getpagecount | gfx_getpagecount |
6.3. Constants
| Deprecated | Replacement |
|---|---|
TGI_XRES | GFX_XRES |
TGI_YRES | GFX_YRES |
TGI_COLORCOUNT | GFX_COLORCOUNT |
TGI_PAGECOUNT | GFX_PAGECOUNT |
TGI_FONT_BITMAP | GFX_FONT_BITMAP |
TGI_FONT_COMPACT | GFX_FONT_COMPACT |
TGI_FONT_VARIABLE | GFX_FONT_VARIABLE |
TGI_TEXT_HORIZONTAL | GFX_TEXT_HORIZONTAL |
TGI_TEXT_VERTICAL | GFX_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_93c46 | eeprom_93c46_read |
lynx_eeread_93c66 | eeprom_93c66_read |
lynx_eeread_93c86 | eeprom_93c86_read |
lynx_eewrite_93c46 | eeprom_93c46_write |
lynx_eewrite_93c66 | eeprom_93c66_write |
lynx_eewrite_93c86 | eeprom_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.