EasyManua.ls Logo

Commodore VIC-20 - Page 226

Commodore VIC-20
404 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
212 The VIC 20
User
Guide
10
POKE
7432,PEEK(7432)
AND
HOT
2f3
[
I
t
tL---00001000
L...
-----1111O111
AND
00101011
L...-
___________
00100011
When
we
POKE
the result back into location 7432, only bit 3 has changed.
The other bits kept their old values.
To
change the
dot
back to the background color, use the
OR
operator.
113
POKE
7432,PEEK(7432)
OR
2f3
l
it
L
----
~0~01000
.
00100011
=
L...-
__________
00101011
As
before, only the value
of
bit 3
is
changed.
This
is
a lot oLwork just to change one bit. However, since there are
only eight bits in a byte, there are only eight possible values for the AND
mask, and eight for the
OR
mask. Since there are only eight
of
each type
of
mask, it
is
practical (and much faster) to calculate them in advance and store
them in tables. The program fragment
that
follows can be used as a subrou-
tine in programs
that
produce high-resolution displays.
It
creates two arrays
of
masks, called
MI%
(Make I) and
MO%
(Make 0).
1139
FOR
1=0
TO
7
110
M1;1,(
1)=21'1
1213
M0;1,(I)=HOT
Ml;1,(I)
1313
NEXT
I
Notice that our array indexes, like
our
bit numbers, start with 0 because
we
calculate the bit number using the remainder
of
a division, which can be
O.
The arrays are specified as integer variables because BASIC does Boolean
operations with integers.
Using these precalculated masks not only makes programs faster, but
also makes them easier to read. Compare
our
earlier examples for setting
and resetting bits with statements that perform the same operations using
the table.

Other manuals for Commodore VIC-20

Related product manuals