Chapter
6:
Graphics 181
SCREEN
MEMORY
LAYOUT
The characters you see on the screen are stored in memory as
an
array
of23 rows and
22
columns. This array
is
not a BASICvariable.1t
is
simply a
506-byte area in the VIC's memory
that
you can access with
PEEK
and
POKE,
but
you will find it helpful to visualize this area as an array. Each
element
of
this array holds one character from the screen: Element (0,0)
contains the character in the upper left corner
of
the display, and element
(22,21) holds the character in the lower right corner.
Once you have found where screen memory starts, using the formula
from the preceding section, you can readily calculate where to
POKE
for a
particular character. The formula
is
POKE location = start of screen + column +
22
* row
In order to use this formula, you must number screen columns from 0 to
21
and rows from 0
to
22.
To
see
an
example
of
this formula, type in the
following program:
100
SB-256*PEEK(648)
110
REM
FILL
SCREEN
MEMORY
WITH
"I)"
120
FOR
1-0
TO
512
130
POKE
SB+I,
0
140
NEXT
I
150
REM
WAIT
FOR
A
KEY
TO
BE
PRESSED
160
GET
)($
170
IF
X$a""
THEN
160
18e
REM
CHANGE
BACKGROUND
TO
BLACK
190
POKE
36979,11
Before running the program, clear the screen and list the program,
leaving the listing
on
the screen. Now
run
the program and observe the
results: All the characters on the screen, except spaces, were changed to @'s.
In fact, the program changed every character
to
an
@,
but
those
that
appear
on the screen as spaces are invisible. When VIC BASIC clears the screen, it
changes the character color
of
all characters on the screen to match the
background. Then, as each character
is
printed, the VIC sets its location in
color memory. Since some
ofthe
@'s are displayed as white characters on a
white background, they will be impossible
to
see. To make them visible,
press the space bar. The program will change the background color to black,
and the white @'s will appear.
You must be aware
of
this problem
of
disappearing characters when
using POKE in a display. Your program must ensure
that
the color
of
the