Repository: cc65/cc65 (2025-07-11T16:46:24Z)

Issue:
ca65: .charmap regression after evaluation changes
**Compiler and OS**
ca65 V2.19 - Git 5fc300b98
Gentoo Linux

**Describe the bug**
The `.charmap` directive emits evaluation errors when using `.include "ascii_charmap.inc"`, as well as when trying to use it directly at all.

**To Reproduce**
Should exit without output, and does so on builds earlier than those including  #2777 
`ca65 <(printf '.include "ascii_charmap.inc"\n') -o /dev/null` 

Instead, we get:
```
/usr/share/cc65/asminc/ascii_charmap.inc:30: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:31: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:32: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:33: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:34: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:35: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:36: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:37: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:38: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:39: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:40: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:41: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:42: Error: Index must be in byte range
/usr/share/cc65/asminc/ascii_charmap.inc:43: Error: Index must be in byte range
...
```


Discussion:
fix (and related regression test) coming up :)
Thanks for reporting!
Oops - my fault. Sorry and thanks for the fix!



Patch:
diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c
index 5ce4e8c6e9..88f609e25b 100644
--- a/src/ca65/pseudo.c
+++ b/src/ca65/pseudo.c
@@ -642,7 +642,7 @@ static void DoCharMap (void)
 
     /* Read the index as numerical value */
     Index = ConstExpression ();
-    if (IsByteRange (Index)) {
+    if (!IsByteRange (Index)) {
         /* Value out of range */
         ErrorSkip ("Index must be in byte range");
         return;


Test patch:
diff --git a/test/asm/val/charmap.s b/test/asm/val/charmap.s
new file mode 100644
index 0000000000..0a908ef139
--- /dev/null
+++ b/test/asm/val/charmap.s
@@ -0,0 +1,43 @@
+    .setcpu "6502"
+
+    .import _exit
+    .export _main
+
+    .charmap $41, 0
+    .charmap $42, 1
+    .charmap $43, 2
+mapped:
+    .byte "ABC"
+
+    .include "ascii_charmap.inc"
+ascii:
+    .byte "ABC"
+
+_main:
+    ldx #$01
+
+    lda mapped+0
+    cmp #0
+    bne error
+    lda mapped+1
+    cmp #1
+    bne error
+    lda mapped+2
+    cmp #2
+    bne error
+
+    lda ascii+0
+    cmp #$41
+    bne error
+    lda ascii+1
+    cmp #$42
+    bne error
+    lda ascii+2
+    cmp #$43
+    bne error
+
+    ldx #$00
+
+error:
+    txa
+    jmp _exit