7

I have a code like below, and it works fine. It clears the screen, puts some color in color memory of first 12 characters on screen, and prints a text on the screen.

         jsr $e544
         ldx #$00
         lda #3
loopclr: sta $d800,x
         inx
         cpx #$0c
         bne loopclr
         ldx #$00
         lda #0
loop:    lda message,x
         sta $0400,x
         inx
         cpx #$0c
         bne loop
         rts
message: .byte "Hello "
         .byte "World!"

What I wonder is, if there's an easier way to change the text color in C64 Assembly, like POKE 646,color in BASIC?

Edit: I thought I need to be more clear, I can use

lda #color
sta 646

But it doesn't affect the text put on screen by assembly code in 1024+.

Is there an address that affects all characters put on screen?

Edit: I think I know the answer, no.

1 Answers1

10

Now there's a question I never thought I'd be asked! sta $0286 (646 decimal) sets the background color to be used when using the system print routine ($FFD2) which I recommend over direct access to the video ram since it takes into account the cursor position. So:

        lda #$00     ; Black letters
        sta $0286    ; Set color
        ldx #$00
msgloop:
        lda message,x
        beq msgdone  ; Zero byte sets z flag - end of string - shorter than checking x value
        jsr $ffd2    ; print a to current device at current position (default: screen)
        inx
        bne msgloop  ; pretty much always unless you have a string > 255
msgdone:
        rts

message: .byte "Hello "
         .byte "World!"
         .byte 0

Well, there goes my credibility as a modern assembler guy! ;-)

Mike
  • 2,721
  • 1
  • 15
  • 20
  • Why would your credibility go? I think your answer is great. I didn't know about `$ffd2` trick. Thanks. –  Feb 19 '15 at 03:18
  • 2
    That's one that's stuck in my head even 30 years after I last used it. You probably want to familiarize yourself with the operating system. There's a complete disassembly at http://www.ffd2.com/fridge/docs/c64-diss.html, the kernel vectors start at $FF81 with a brief description of what each one does. – Mike Feb 19 '15 at 03:38
  • Wow, 30 years! I was trying to program C64 30 years ago too, but back then it was impossible for me to reach any programming resources in my country. After 30 years, I decided to learn C64 assembly. With people like you, it seems possible. –  Feb 19 '15 at 03:41
  • You too! As one of my more esoteric projects, I'm trying to figure out what the future would have looked like if there had been a decent C compiler and unix-like OS on the old C64. – Mike Feb 19 '15 at 04:15
  • 1
    It'd be totally awesome. I think I would start using Linux right after c64, and wouldn't spend some of my youth on Windows. –  Feb 19 '15 at 04:20