cc65 custom string conversion
Moderator: Moderators
cc65 custom string conversion
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.
Avatar is pixel art of Noah Prime from Astral Chain
Re: cc65 custom string conversion
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?
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?
nesdoug.com -- blog/tutorial on programming for the NES
Re: cc65 custom string conversion
Read the description of the .charmap command.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: cc65 custom string conversion
In ca65 you can redefine the mapping for string literals with .charmap.
In cc65 you can do the same with #pragma charmap.
In cc65 you can do the same with #pragma charmap.
Re: cc65 custom string conversion
.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.
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.
Avatar is pixel art of Noah Prime from Astral Chain
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: cc65 custom string conversion
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