Quick color tool

May 22, 2019
This BASIC program lets you quickly view the standard 16-color palette on the Commander X16. You can paste this code directly into the emulator with Control-V (or maybe Command-V if you're on a Mac.)

10 TI$="000000"
20 PRINT CHR$(147);"    ";
30 FOR X=0 TO 15
40 PRINT RIGHT$("   "+STR$(X),3);" ";
70 FOR Y=0 TO 15
90 C=Y*16
100 PRINT RIGHT$("   "+STR$(C),3);" ";
110 FOR X=0 TO 15
120 C=Y*16+X
130 PRINT RIGHT$("   "+STR$(C),3);" ";
140 NEXT
160 NEXT
170 FOR Y=0 TO 15
180 FOR X=0 TO 15
190 N=Y*768+X*8+521
200 C=Y*16+X
210 FOR I=0 TO 3
220 VPOKE 0,N+I*2,C
230 VPOKE 0,N+I*2+256,C
240 VPOKE 0,N+I*2+512,C
250 NEXT I
260 NEXT X
270 NEXT Y
The output looks like this:
Last edited:
  • Like
Reactions: x7c and Fullauto556


New Member
Sep 13, 2019
The first line, contents of the string don't copy well. Maybe better to convert to chr$(xx).
May 22, 2019
Theory of operation:

The program prints all of the color cell numbers in white text, then goes back and VPOKEs the colors into the screen to match the displayed numbers.

This program has two main loops. The first is the loop to print the color numbers in lines 100-150. This computes the color number by taking the row number, multiplying that by 16, then adding the column number.

110 C=Y*16+X

The second loop is lines 160-260. This is basically a reprise of the X/Y loop above, but adds in code to poke the colors into display memory. To do that, the program actually has to compute both the color (using the same formula as above) and the index into the display buffer.

180 N=Y*768+X*8+521

A screen row on VERA is 256 bytes, with text and color interleaved. So we index rows and columns a bit like this:

0 2 4 6 8 10 ...
256 258 260 262 264 266 ...
512 514 516 518 520 522 ...

So to poke a character into the screen, we get the start of the row by multiplying the row by 256

And we then offset the column by adding X*2

P=Y*256 + X*2

Finally, we need to add 1 to get to the color cell

P=Y*256 + X*2 + 1

However, I'm setting four character cells at a time, so I am multiplying X by 8 (4*2), and the loop in 200-240 is responsible for setting those colors on 3 rows. Technically, lines 210-230 violate the "don't repeat yourself" rule, but a FOR loop for 3 iterations doesn't really save space or resources.

I'm actually computing the upper-left corner of each numeric block, and the first block is on row 2, column 4. I came up with 521 as a starting offset. Let's do the math, anyway:

Row: 2 * 256 = 512
Col: 4 * 2 = 8
512+8 = 520

Don't forget to add the 1, and we get 521.

So the final formula is:

Y is the row index
768 is the number of cells between the start of each color row (3 lines of 256 bytes)
X is the column index
8 is 4 columns per color, with 2 bytes per cell
512 is the start index.
May 22, 2019
The first line, contents of the string don't copy well. Maybe better to convert to chr$(xx).
Sorry about that - that's a BasText code. You're supposed to press shift+home when entering the program.

If you're trying to copy+paste it in, change that to
PRINT CHR$(147);" ";

I'm working on writing my own tokenizer/IDE that will have some quality of life features like auto line numbering and BasText support; look for that in the next few weeks.