From C64-Wiki
Jump to navigationJump to search

Address 646 (Hexadecimal: $0286) holds the color code for the current cursor color: Kernal applies the color code stored here to the text color RAM for each visible character printed on the screen.

This example places 16 different values in address 646 to display the palette of 16 colors available on the C-64:

for n=0 to 15:poke 646,n:print chr$(18);
"Color";n;:next n
Color 0 Color 1 Color 2 Color 3 Color 4
Color 5 Color 6 Color 7 Color 8 Color 9
Color 10 Color 11 Color 12 Color 13 Colo
r 14 Color 15

Note that chr$(18) is the control character for "reverse on" mode.

ROM details[edit]

During the system initialization after a cold start (i.e. power-up or reset), address 646 is set to 14 for light blue; this takes place at 58678–58682/$E536–E53A.

Kernal has a short subroutine at 58586–58591/$E4DA–E4DF that assigns the color to a character on the screen: It places the color code held in the accumulator in the color RAM address designated by the zeropage pointer in 243–244/$F3–$F4, and the Y index register.

Using INST and DEL "opens" up a blank character space either at the cursor position or at the end of the line: These "new blanks" are assigned the current color code as per address 646. This is handled at 59255–59259/$E777–E77B (for DEL), and 59423–59427/$E81F–E823 (for INST).

Printing one of the sixteen control characters which change the text color, is handled by a subroutine at 59595–59609/$E8CB–E8D9: This routine assumes the accumulator holds a PETSCII character code, and compares it against a table of the 16 color control characters (59610–59625/$E8DA–E8E9): If a match is found, the index of the character in the table gives the color code, which is then stored in address 646.

This provides another, quite quirky way of displaying the above palette example:

for n=0 to 15:print chr$(peek(59610+n));
"rColor";n;:next n