basic6502c64

c64 Extended Color Mode: last character 63 = 191 to use background 2?? ($D022)


In extended colour mode:

For characters 32 to 63 on background 1 (53281/$D021 value), I can add 192 to get the same on background 2 (53282/$D022 value). For characters 64 to 95 on bg1, I can add 128 to get the same on bg2

...at least that's the theory. But I'm finding that character chr$(63) is falling in to the second set: so 63 + 128 = chr$(191) prints correctly, but chr$(255) doesn't? Not a biggy, I can workaround, but i'm reluctant to believe that the documentation is wrong especially as 64 seems to be a more sensible cutoff point than 63. This may be a Vice bug?


Solution

  • It looks like you're confusing the PETSCII values (CHR$()) for the screen codes that are used in display.

    Screen codes 0-63 use background 0, 64-127 use background 1, 128-191 use background 2, and 192-255 use background 3.

    There is not a 1:1 mapping between screen codes and PETSCII values. You can't take the ASC() value of a character and do something like CHR$(ASC("X")+64) to reliably get a screen code that happens to be 64 more, even though you may find some cases in which that might be true.