Page 1 of 1

cc65 custom string conversion

Posted: Sat Oct 17, 2020 12:58 pm
by SusiKette
When you define a string in cc65 it seems to convert it to bytes according to ASCII table, but I was wondering if there is a way to map the letters to different values. Many NES games have $00-$09 as numbers from 0-9, $0A-$23 as letters from A-Z and some bytes after that as special characters. It would be a bit more practical to map the letters this way. Especially if your game has a lot of text.

Re: cc65 custom string conversion

Posted: Sat Oct 17, 2020 1:14 pm
by dougeff
Perhaps an automated conversion tool would be a solution. So you would type the string into a custom tool that would output a byte/char array that you copy and paste into your c files.

I don't know of any such tool, but you could write one yourself. Perhaps in python.

one issue with your plan. Typically C strings are zero terminated, so using values 0-9 as numbers 0-9 would make string functions useless. How would you determine string length?

Re: cc65 custom string conversion

Posted: Sat Oct 17, 2020 1:51 pm
by tepples
Read the description of the .charmap command.

Re: cc65 custom string conversion

Posted: Sat Oct 17, 2020 1:53 pm
by rainwarrior
In ca65 you can redefine the mapping for string literals with .charmap.

In cc65 you can do the same with #pragma charmap.

Re: cc65 custom string conversion

Posted: Sat Oct 17, 2020 2:24 pm
by SusiKette
.charmap seems to be one option, although it's a shame that you can't map characters using .charmap "A",$0A

A custom program might work too. I'm not sure if compression algorithms work well on text, but one could be built in the program too. Although you probably need a lot of text to need compression.

Re: cc65 custom string conversion

Posted: Sat Oct 17, 2020 2:34 pm
by rainwarrior
SusiKette wrote:
Sat Oct 17, 2020 2:24 pm
.charmap seems to be one option, although it's a shame that you can't map characters using .charmap "A",$0A
You can, though it needs to be single quotes I think.

The doc suggests against it because any previously existing charmap applies to the 'A' but you don't have to take their advice. Without a specified target, the default mapping is ASCII so it should be fine as long as you don't have duplicates. ;P