From 40412223a4ce95a741f6450300da9f8144c8e358 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Sun, 1 Nov 2026 15:34:13 -0500 Subject: [PATCH] palm-client: shared tables must not be const (prc-tools puts const in code) The transcript wrapped after a few characters on the Visor: gSmallFontWidths was const, so prc-tools placed it in .text, but text.c reached it through an extern declaration A5-relative (lea %a5@(0)) as if it were data, and read garbage widths. The same applied to gPresets. Both generators now emit non-const tables, with a note why. Host tests can't see this. --- docs/progress.md | 1 + palm-client/src/presets.c | 7 +++++-- palm-client/src/presets.h | 5 +++-- palm-client/src/ui/fontmetrics.c | 4 +++- palm-client/src/ui/fontmetrics.h | 3 ++- palm-client/tools/gen_font.py | 4 +++- palm-client/tools/gen_presets.py | 7 +++++-- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/docs/progress.md b/docs/progress.md index 8e93b20..83cc779 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -70,3 +70,4 @@ - Node Settings verified from the Visor: radio now 919.500 MHz / BW 500 / SF10 / CR5, 2-byte path hash (confirmed independently over the XIAO's USB). Seen in the bridge log: the Visor's USB link dropped while the Settings form was open and re-attached on the next send; it worked, but commands only try once, so this needs a closer look. - Reception was dead until the XIAO rebooted: SET_RADIO_PARAMS saves and reports the new settings, but the receiver only retunes on a restart. Settings now offers to reboot the radio (CMD_REBOOT) after a radio change and reconnects. The radio then heard the user's contact. - MeshTerm-style UI built: generated 4x6 font (PilRC's FONT compiler writes a corrupt NFNT, so gen_font.py writes it), rowlist, text layout (host-tested), message store and sync, Home/Conversation/Contacts/Node screens. Font verified readable on the Neo. +- Transcript wrapped after ~4 characters on the Visor: prc-tools puts `const` data in the code section, but another file reaching an `extern const` table addresses it A5-relative as data, so it read garbage widths. Shared tables (font widths, presets) are now non-const, set in their generators. Host tests can't catch this. Rule: never share an `extern const` table across files in palm-client. diff --git a/palm-client/src/presets.c b/palm-client/src/presets.c index 3e34e8b..61e24a9 100644 --- a/palm-client/src/presets.c +++ b/palm-client/src/presets.c @@ -6,7 +6,10 @@ */ #include "presets.h" -const VmPreset gPresets[] = { +/* Not const: prc-tools puts const data in the code section, but other files reach an + * extern table A5-relative as if it were data, so a const table reads as garbage on the Visor. */ + +VmPreset gPresets[] = { { "PhillyMesh", 919500UL, 500000UL, 10, 5, 2 }, { "Australia", 915800UL, 250000UL, 10, 5, 0 }, { "Australia (Narrow)", 916575UL, 62500UL, 7, 7, 0 }, @@ -37,4 +40,4 @@ const VmPreset gPresets[] = { { "Vietnam (Deprecated)", 920250UL, 250000UL, 11, 5, 0 }, }; -const UInt16 gPresetCount = sizeof(gPresets) / sizeof(gPresets[0]); +UInt16 gPresetCount = sizeof(gPresets) / sizeof(gPresets[0]); diff --git a/palm-client/src/presets.h b/palm-client/src/presets.h index 803a34c..d7f8f04 100644 --- a/palm-client/src/presets.h +++ b/palm-client/src/presets.h @@ -12,7 +12,8 @@ typedef struct { UInt8 pathHashSize; /* bytes; 0 = preset doesn't specify one */ } VmPreset; -extern const VmPreset gPresets[]; -extern const UInt16 gPresetCount; +/* Not const: see the note in presets.c (prc-tools puts const data in code). */ +extern VmPreset gPresets[]; +extern UInt16 gPresetCount; #endif diff --git a/palm-client/src/ui/fontmetrics.c b/palm-client/src/ui/fontmetrics.c index 2cd6adb..37c16a9 100644 --- a/palm-client/src/ui/fontmetrics.c +++ b/palm-client/src/ui/fontmetrics.c @@ -1,7 +1,9 @@ /* GENERATED by tools/gen_font.py: small-font character widths in pixels. */ #include "fontmetrics.h" -const UInt8 gSmallFontWidths[256] = { +/* Not const: prc-tools puts const data in the code section, but other files reach an + * extern table A5-relative as if it were data, so a const table reads as garbage on the Visor. */ +UInt8 gSmallFontWidths[256] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, diff --git a/palm-client/src/ui/fontmetrics.h b/palm-client/src/ui/fontmetrics.h index 3b35618..0b6216a 100644 --- a/palm-client/src/ui/fontmetrics.h +++ b/palm-client/src/ui/fontmetrics.h @@ -4,6 +4,7 @@ #include "../protocol.h" /* integer types on both Palm and host */ /* Small-font character widths in pixels, indexed by (UInt8) character. */ -extern const UInt8 gSmallFontWidths[256]; +/* Not const: see the note in fontmetrics.c (prc-tools puts const data in code). */ +extern UInt8 gSmallFontWidths[256]; #endif diff --git a/palm-client/tools/gen_font.py b/palm-client/tools/gen_font.py index c159fbc..ac4526d 100644 --- a/palm-client/tools/gen_font.py +++ b/palm-client/tools/gen_font.py @@ -198,7 +198,9 @@ def main(): widths = [len(font[c][0]) if c in font else len(missing[0]) for c in range(256)] with open(OUT_METRICS, 'w') as f: f.write('/* GENERATED by tools/gen_font.py: small-font character widths in pixels. */\n') - f.write('#include "fontmetrics.h"\n\nconst UInt8 gSmallFontWidths[256] = {\n') + f.write('#include "fontmetrics.h"\n\n') + f.write('/* Not const: prc-tools puts const data in the code section, but other files reach an\n * extern table A5-relative as if it were data, so a const table reads as garbage on the Visor. */\n') + f.write('UInt8 gSmallFontWidths[256] = {\n') for r in range(0, 256, 16): f.write('\t' + ', '.join(str(w) for w in widths[r:r + 16]) + ',\n') f.write('};\n') diff --git a/palm-client/tools/gen_presets.py b/palm-client/tools/gen_presets.py index 4626dfe..a52b9c5 100755 --- a/palm-client/tools/gen_presets.py +++ b/palm-client/tools/gen_presets.py @@ -60,11 +60,14 @@ def main(): */ #include "presets.h" -const VmPreset gPresets[] = {{ +/* Not const: prc-tools puts const data in the code section, but other files reach an + * extern table A5-relative as if it were data, so a const table reads as garbage on the Visor. */ + +VmPreset gPresets[] = {{ ''' + '\n'.join(rows) + f''' }}; -const UInt16 gPresetCount = sizeof(gPresets) / sizeof(gPresets[0]); +UInt16 gPresetCount = sizeof(gPresets) / sizeof(gPresets[0]); ''') print(f'{len(rows)} presets -> {os.path.relpath(OUT)}')