From dd27ec8696224a782154f2cd3a77a3b0428c2fcd Mon Sep 17 00:00:00 2001 From: Kugel Fuhr <98353208+kugelfuhr@users.noreply.github.com> Date: Thu, 3 Jul 2025 08:54:10 +0200 Subject: [PATCH] When creating a VICE label file, replace characters in labels that VICE doesn't understand with '_'. Fixes #836. --- src/ld65/dbgsyms.c | 2 +- src/ld65/exports.c | 34 +++++++++++++++++++++++++++++++++- src/ld65/exports.h | 3 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ld65/dbgsyms.c b/src/ld65/dbgsyms.c index 955f0f76d..082954b07 100644 --- a/src/ld65/dbgsyms.c +++ b/src/ld65/dbgsyms.c @@ -532,7 +532,7 @@ void PrintDbgSymLabels (FILE* F) if (GetDbgSym (D, Val) == 0) { /* Emit the VICE label line */ - fprintf (F, "al %06lX .%s\n", Val, GetString (D->Name)); + PrintLabelLine (F, D->Name, Val); /* Insert the symbol into the table */ InsertDbgSym (D, Val); diff --git a/src/ld65/exports.c b/src/ld65/exports.c index 9fa0e4019..f457b5490 100644 --- a/src/ld65/exports.c +++ b/src/ld65/exports.c @@ -39,6 +39,7 @@ /* common */ #include "addrsize.h" +#include "chartype.h" #include "check.h" #include "hashfunc.h" #include "lidefs.h" @@ -1006,6 +1007,36 @@ void PrintImportMap (FILE* F) +void PrintLabelLine (FILE* F, unsigned NameId, long Val) +/* Output one label into a vice label file doing some cleanup on the name. */ +{ + /* Get the name */ + const char* N = GetString (NameId); + + /* Cleanup the name. It might be generated by the assembler when creating + ** internally used labels. Such names contain invalid characters to avoid + ** clashes with user input and cannot be read by VICE. + */ + fprintf (F, "al %06lX .", Val); + if (IsAlpha (*N) || *N == '@' || *N == '?' || *N == '_') { + putc (*N, F); + } else { + putc ('_', F); + } + ++N; + while (*N) { + if (IsAlpha (*N) || IsDigit (*N) || *N == '_') { + putc (*N, F); + } else { + putc ('_', F); + } + ++N; + } + putc ('\n', F); +} + + + void PrintExportLabels (FILE* F) /* Print the exports in a VICE label file */ { @@ -1014,7 +1045,8 @@ void PrintExportLabels (FILE* F) /* Print all exports */ for (I = 0; I < ExpCount; ++I) { const Export* E = ExpPool [I]; - fprintf (F, "al %06lX .%s\n", GetExportVal (E), GetString (E->Name)); + PrintLabelLine (F, E->Name, GetExportVal (E)); + } } diff --git a/src/ld65/exports.h b/src/ld65/exports.h index d69e6d7ad..cc7870bc5 100644 --- a/src/ld65/exports.h +++ b/src/ld65/exports.h @@ -195,6 +195,9 @@ void PrintExportMapByValue (FILE* F); void PrintImportMap (FILE* F); /* Print an import map to the given file */ +void PrintLabelLine (FILE* F, unsigned NameId, long Val); +/* Output one label into a vice label file doing some cleanup on the name. */ + void PrintExportLabels (FILE* F); /* Print the exports in a VICE label file */