assembly - Why are characters being offset by 0x40 on my Commodore 64 emulator? -
i have 6502 code print string screen memory after clearing screen. unfortunately if print string, example "hello world", come out in garbled characters. i've found because upper case characters start @ 0x01, not 0x41 thought petscii codes here.
i can fix subtracting 0x40 string, other letters incorrect, example, spaces. i'm not sure why character generator turning 0x01 character 'a' , not 0x41. turns 0x41 inverted spade sign (like on deck of cards) , above seems border characters , weird symbols.
after looking around while found quote on wikipedia page petscii seemed state problem i'm trying solve, i'm not sure how fix , can't find information anywhere...
the actual character generator rom used different set of assignments. example, display characters "@abc" on screen directly pokeing screen memory, 1 poke decimal values 0, 1, 2, , 3 rather 64, 65, 66, , 67.
i running on vice x64 emulator on mac os x, , i'm assembling os x port of 64tass.
this 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 reached null byte, break beq strexit sta $0400, x inx jmp strloop strexit rts hello .text "hello world" .byte 0
here screenshot of output
thanks in comments!
side note others
you can set row , column chrout output setting cursor position plot
you're possibly writing ascii codes screen memory directly, that's why it's offset $40.
to have them in petscii, need add "-a" option 64tass. alone not enough. example offset $c0 (uppercase petscii letters) now. changing text lowercase still gives $40 offset (lowercase petscii).
you need write "screen" codes screen. fortunately there's built in conversion in 64tass if this:
.enc screen ; switch screen code encoding hello .text "hello world" .byte 0 .enc none
but remember "@" 0 in screen code, it'll termitate loop. text in lower case, default font uppercase it'll end uppercase. set $d018 $16 switch lower case font, it'll match write.
a proper petscii example be:
*=$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"
compile not old 64tass translates "{clr}" , "{swlc}" control codes 147 , 14. , don't forget "-a" switch enable unicode support, otherwise assembler won't translation of string , copy verbatim (as raw bytes).
Comments
Post a Comment