Chapter
6:
Graphics 179
using the CTRL key. As
we
are
about
to
see, your program can also change it.
Once a character
is
gone from the screen, the color memory
is
reused to show
the color of the character
that
takes its place. Only the character itself
is
stored as part of the program.
As with reversed characters, this problem
is
solved by inserting control
characters into the program to set the color.
For
example, to make the
diamond red instead
of
blue, insert a CTRL-3 into line 200 following the
"reverse
on"
(reversed "R'') so
that
the line looks like the following:
10
PRINT"DJrII
29
PRINT"'"
Now
run
the program. Notice that the entire diamond
is
red, not just
the first line. Color controls, unlike the "reverse
on"
control, are not reset
when you start a new line. They remain in effect until a new color
is
set,
or
until you reset the VIC with the RUN/STOP and RESTORE keys.
CREATING
DISPLAYS
WITH
POKE
Sometimes it
is
not practical
to
use
PRINT
to build a graphic display.
For
example, if several players are moving about on the screen, you may
need
to
detect when they collide with each other
or
with
an
object on the
playfield.
Or
you might want to have a cursor on the screen when reading
characters with GET.
For
applications like these, you will want to access the
display directly. The VIC allows you to do this using PEEK and POKE.
Screen
Memory
The characters displayed on the screen are stored in the VIC's memory.
The VIC chip reads the image
of
a character from memory as it
is
being
displayed on the screen. The characters are stored in
an
area called screen
memory,
and the colors
of
the characters are stored in color memory.
Because these areas are part
of
the VIC's memory, you can use
PEEK
and
POKE to examine and change the contents
of
the display.
FINDING
SCREEN
MEMORY
In
most computers, the location
of
screen memory
is
part
of
the
hardware design and cannot be changed. In the VIC, although the number