3

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?

Example:

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 Oct 20 at 14:32
4

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 arbitary 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)

.FEATURE STRING_ESCAPES

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, stings 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 seams to be a backport by Oliver Schmidt from 2.5 into the free version.

*3 - When using the commantline option features need to be specified all lower case as --feature string_escapes.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.