cc65 custom string conversion

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

cc65 custom string conversion

Post 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.
Avatar is pixel art of Noah Prime from Astral Chain
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: cc65 custom string conversion

Post 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?
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: cc65 custom string conversion

Post by tepples »

Read the description of the .charmap command.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: cc65 custom string conversion

Post by rainwarrior »

In ca65 you can redefine the mapping for string literals with .charmap.

In cc65 you can do the same with #pragma charmap.
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: cc65 custom string conversion

Post 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.
Avatar is pixel art of Noah Prime from Astral Chain
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: cc65 custom string conversion

Post 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
Post Reply