The Commodore 128 has a nice API for setting graphics mode and plotting graphics, that can be used in 40 column mode. The GRAPHIC command takes a mode (0 to 5) and a “clear screen flag”, and changes the current graphics mode. 0 is the 40 column text mode and 1 is the high resolution monochrome graphics mode. This program sets a few random pixels on the screen using the DRAW command:

10 GRAPHIC 1, 1
20 FOR A = 1 TO 100
30 DRAW 1, RND(1) * 320, RND(1) * 200
40 NEXT A

When the program is run, the text is hidden, so to retain the text cursor, just type GRAPHIC 0 and hit Enter. If you like, you can add this to your program.

The Commodore 64 does not provide any API for graphics, so on the C64 this task is accomplished by manipulating bits in a memory area. You can jump to graphics mode by setting the bit 6 on byte 53265 to 1 and return to text mode by setting it to 0. While plotting, you must make sure you know how to handle bit patterns. The screen area can be located at 8192 if we set a flag for this (bit 4 at byte 53272), like so:

10 POKE 53272, PEEK(53272) OR 8

The screen consist of 8000 bytes, so in this case from 8192 to 9191. Then, enter graphics mode:

20 POKE 53265, PEEK(53265) OR 32

Now we don’t have the service to get a clean color map (that is Commodore 128 luxury), so random boxes (8×8 pixels) will have strange colors. No worries, this is expected.

Finally, these lines of code will draw a few horizontal lines in the upper left 8×8 pixel area:

Set graphics mode

30 POKE 8192, 255
40 POKE 8193, 0
50 POKE 8194, 255
60 POKE 8195, 0
70 POKE 8196, 255
80 POKE 8197, 0
90 POKE 8198, 255
100 POKE 8199, 0

Click to view

When the program has run, you will not see the text cursor, but to restore everything, type:

POKE 53272, 21
POKE 53265, 27

…and our horizontal lines will be gone and the text cursor is back.

Restoring.

Leave a Reply

Your email address will not be published. Required fields are marked *