Skip to content

Libraries: link CHGfx, CHGame and CHSd from archives - #20

Merged
bateske merged 1 commit into
mainfrom
claude/dot-a-linkage
Oct 9, 2026
Merged

bateske merged 1 commit into
mainfrom
claude/dot-a-linkage

Conversation

@bateske

@bateske bateske commented Oct 8, 2026

Copy link
Copy Markdown
Owner

What changed

dot_a_linkage=true in the library.properties of CHGfx, CHGame and CHSd, so each library links from an archive and an object of it is pulled in only when the sketch calls into it. Recorded in board/CHANGELOG.md (Unreleased), platform/README.md, the CHGame README's RAM note and CHGame.h's header comment.

Why

A developer using board package 0.3.0 for audio:: and chgame_readButtons() only, with their own display code, found every sketch that includes CHGame.h carrying CHGfx's 8 KB framebuffer, its chunk buffers and its SRAM converters. Confirmed: Arduino links a library's objects whole, and CHGfx.cpp's strong DMA1_Channel3_IRQHandler replaces the core's weak default, so the vector table keeps the handler and the handler keeps the framebuffer, drawing or not.

Audio-only sketch Flash Static RAM
0.3.0 as released 4,580 B 9,712 B
With the flag 4,132 B 352 B

For the reviewer

  • All 20 games and the 3 apps were built with and without the flag: sizes identical, release .bin byte-identical for all 23.
  • The two hooks the libraries override (that DMA handler, and osSystickHandler in Audio.cpp) sit in the same objects as gfx_begin() and audio::begin(), so a sketch that uses the feature always gets them. Verified in the archive build's disassembly that the SysTick handler still calls the audio code.
  • The -Os -flto builds produce slim LTO objects; plain riscv-none-embed-ar indexes them, so the link pulls the right members with no warning and no gcc-ar is needed.
  • The developer's other idea, a root CHGameAudio.h, does nothing on its own (arduino-cli compiles every .cpp of a discovered library, and Draw.cpp includes CHGfx.h); with the flag, #include <CHGame.h> already costs nothing. Not added.
  • A sketchbook copy of CHGfx would shadow the package's and lose the fix; arduino-cli says so with Multiple libraries were found for "CHGfx.h".
  • The simulator does not read the flag. No library version bumped; it ships with the next package release.

🤖 Generated with Claude Code

A developer using board package 0.3.0 for the sound engine and the
buttons only, with their own display code, found every sketch that
includes CHGame.h carrying CHGfx's 8 KB framebuffer, its chunk buffers
and its SRAM converters. Arduino links a library's objects whole, and
CHGfx.cpp's strong DMA1_Channel3_IRQHandler replaces the core's weak
default, so the vector table keeps the handler and the handler keeps
the framebuffer, drawing or not.

dot_a_linkage=true in the three library.properties links each library
from an archive, where an object is pulled in only when something calls
into it. The audio-only sketch takes 352 B of static RAM instead of
9,712 B. The two hooks the libraries override (that handler, and
osSystickHandler in Audio.cpp) sit in the same objects as gfx_begin()
and audio::begin(), so a sketch that uses a feature always gets them.
All 20 games' and 3 apps' release images are byte-identical with and
without the flag; plain riscv-none-embed-ar indexes GCC 8's slim LTO
objects, so the -Os -flto builds need no gcc-ar. The simulator does not
read the flag.

Recorded in board/CHANGELOG.md (Unreleased), platform/README.md, the
CHGame README's RAM note and CHGame.h's header comment.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@bateske
bateske merged commit 3be1570 into main Oct 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant