I have some 6502 code to print a string to the screen memory after clearing the screen. Unfortunately if I print a string, for example "HELLO WORLD", it will come out in garbled characters. I've found that this is because the upper case characters start at 0x01, not 0x41 as I thought from the PETSCII codes here.
I can fix this by subtracting 0x40 from my string, but then everything other than letters are incorrect, for example, spaces. I'm just not sure why the character generator is turning 0x01 into the character 'A' and not 0x41. It turns 0x41 into an inverted spade sign (like on a deck of cards) and everything above it seems to be border characters and weird symbols.
After looking around for a while I found this quote on the wikipedia page for PETSCII which seemed to state the problem I'm trying to solve, but I'm not sure how to fix it and can't find any information anywhere...
The actual character generator ROM used a different set of assignments. For example, to display the characters "@ABC" on screen by directly POKEing the screen memory, one would POKE the decimal values 0, 1, 2, and 3 rather than 64, 65, 66, and 67.
I am running on the VICE x64 emulator on Mac OS X, and I'm assembling with an OS X port of 64tass.
This is the assembly code without subtracting 0x40:
*=$c000
BORDER = $d020
INNER = $d021
start lda #0
sta BORDER
lda #0
sta INNER
jsr clear
jsr string
loop
jmp loop
clear ; clear screen
lda #$00
tax
lda #$20
clrloop
sta $0400, x ; clear each memory "row"
sta $0500, x
sta $0600, x
sta $0700, x
dex
bne clrloop ; clear if x != 0
rts
string ; load string
ldx #$0
strloop lda hello, x ; load each byte in turn
cmp #0 ; if we reached a null byte, break
beq strexit
sta $0400, x
inx
jmp strloop
strexit rts
hello .text "HELLO WORLD"
.byte 0
Here is a screenshot of the output
Thanks to everyone in the comments!
Side note to help others
You can set which row and column CHROUT will output to by setting the cursor position with PLOT