According to the cc65 documentation, a string constant in assembler programs can be defined with the .ASCIIZ command. However, I could not manage to sneak control commands in, for example, the backslash character is transcribed literally into character 0xBF. Given that commodore systems provide a powerful set of control characters including color setting this would be useful. Is there an escape character in ca65 to add such commands to a text string?


msg .ASCIIZ "hello world"

How could I add, for example, a control character for changing to white color before the second word? The CBM code for white is 05.

  • For code that specifically targets C64, you may want to look at 64tass (tass64.sourceforge.net). You can write things like .text "{clr}Text in PETSCII\n".
    – fadden
    Commented Oct 20, 2019 at 14:32
  • Is there some reason you want to avoid writing the screen directly? Performance is much better than using the Kernel routine.
    – supercat
    Commented Jun 19, 2020 at 17:30
  • @supercat: Using a routine that writes to the screen directly is fast, but at the cost of having exactly these control commands I'm interested in using.
    – Peter B.
    Commented Jun 19, 2020 at 19:33
  • @PeterB.: What are you seeking to do with the control characters that could not be done just as well by writing display memory yourself?
    – supercat
    Commented Jun 19, 2020 at 19:34
  • There are multiple applications. For example, I have made a driver that maps every character printing either to screen memory or to graphics memory. So the same program if just using printf-commands will run in the normal mode as well as in hires graphics mode. I never understood btw why they did not introduce this feature on the C128 BASIC. There is a seperate command for printing to screen, although it could have been mapped to the standard output.
    – Peter B.
    Commented Jun 19, 2020 at 19:52

1 Answer 1


Is there an escape character in ca65 to add such commands to a text string?

In general: No.

The whole ASCII(Z) mechanic is meant to write device independent code, so adding device specific sequences is rather outside of the scope. To get arbitrary inserts, you may want to use the good old .BYTE:

msg  .BYTE "Hello ",$05,"World",0

Then again, there is a way to do it, it just comes with a big caveat.

Starting with version 2.18 (*1,2) escape code processing can be enabled via a feature (*3)


This will enable C-style escape codes for special characters. Now it's possible to write

msg   .ASCIIZ "Hello \x05World"

So far a great thing, except, this is only painless on the source/module side, as character mapping according to the target will kick in when linking (*4). When linking, strings get translated into target codes, which can be vastly different depending on each machine.

Now, since we already left the path of compatibility, there is a way to add (somewhat) machine independent support by using defined character codes and have their mapping fixed using the .CHARMAP directive. And with a bit of Macro-Fu logical names could be used as well ... but all of that is a complete different story :)

*1 - More correct, it wasn't there in 2.15, but is available in 2.18.

*2 - It also seems to be a backport by Oliver Schmidt from 2.5 into the free version.

*3 - When using the command line option, feature needs to be specified all lower case as

--feature string_escapes

*4 -Unless no target is specified (-t none).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .