Why are characters offset by 0x40 on my Commodore 64 emulator?

I have 6502 code to print a line in the screen memory after clearing the screen. Unfortunately, if I print a line such as "HELLO WORLD", it will be displayed in garbled characters. I found this to happen because uppercase characters start with 0x01, not 0x41, as I thought from the PETSCII codes here .

I can fix this by subtracting 0x40 from my string, but then everything except the letters is wrong, for example, spaces. I just don’t know why the character generator rotates 0x01 to character "A" and not 0x41. It turns 0x41 into a sign of an inverted shovel (for example, on a deck of cards), and everything above it seems to be border symbols and strange symbols.

After looking around for a while, I found this quote on the wikipedia page for PETSCII, which seemed to state a problem that I'm trying to solve, but I'm not sure how to fix it and can't find any information anywhere ...

The ROM of a real character uses a different set of jobs. For example, to display the @ABC characters on the screen directly COVER the screen memory, you could BUY the decimal values ​​0, 1, 2, and 3, rather than 64, 65, 66, and 67.

I am running on a VICE x64 emulator on Mac OS X and I am building with an OS X port on 64tass.

This is the build 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 exit

Here is a screenshot of the output

Thanks to everyone in the comments!

Side note to help others

You can set which row and CHROUT columns to display by setting the cursor position with PLOT

http://sta.c64.org/cbm64krnfunc.html

+4
1

, ASCII- , 40 .

PETSCII, "-a" 64tass. . $c0 ( PETSCII). 40 ( PETSCII).

"" . , 64-, :

        .enc screen            ; switch to screen code encoding
hello   .text "hello world"
        .byte 0
        .enc none

, "@" 0 , . , , . $d018 $16, , , .

PETSCII:

    *=$c000

    lda #0
    sta $d020 ; border
    sta $d021 ; background

    ldx #0
lp  lda hello,x
    beq end
    jsr $ffd2 ;print character
    inx
    bne lp
end rts

hello .null "{clr}{swlc}HELLO WORLD"

64tass, "{clr}" "{swlc}" 147 14. , "-a" Unicode, ( ).

+8

All Articles