EasyManua.ls Logo

Commodore VIC-20 - Page 225

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...
Chapter 6 Graphics 211
The bit within
that
byte
is
the remainder
of
the division by 8
we
did to
find the column. To calculate the right bit, use
460
PL=7168+Y+64*COL
470
BIT=7-(X-COL*8)
We subtracted the remainder from 7 because
our
high-resolution
columns are numbered from left to right, but the bits in a byte are numbered
from right to left.
Just
knowing the number
of
the bit
is
not enough. Because it will be
using POKE to change the display, your program must calculate the number
that
corresponds to
that
bit. Remember
that
each bit in the byte represents a
power
of
2.
Bit Number I
71
6 I 5 I 4 I 3 I 2
11
I 0 I
Value for POKE
128
64
32
16
8 4 2 1
Since this
is
the case, you can easily convert from the bit number to the
POKE value using the exponentiation operator.
480
PV=21'BIT
Your program cannot simply POKE blindly into the byte it has found
because there are seven other bits there
that
you don't want to disturb. To
change just one bit, you must PEEK the byte to be changed, modify only the
correct bit, and then POKE it back. To change only a single bit, you can use
the AND and
OR
operators.
For
example, to set a bit to 0 (making its
dot
the background color), you can use a variation
of
the masking technique
that was used to isolate the bits for joystick switches.
500
POKE
PL,PEEK(Pl)
AND
NOT
PI,'
Notice the use
of
the NOT operator. When
we
were isolating the
joystick switches
we
used the value of the bit directly. That produced a mask
in which the bit
we
wanted was a
1,
and all the others were
Os.
This time
we
are using a mask in which the bit
we
are interested in
is
a 0 and all the others
are Is. The AND will force that bit to 0 and leave the others undisturbed.
Suppose
we
want to
turn
off bit 3 in location 7432, which currently contains
a value
of
43.
We
could use a BASIC statement like this.

Other manuals for Commodore VIC-20

Related product manuals