EasyManua.ls Logo

Commodore VIC-20 - Page 176

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...
162
The
VIC
20
User
Guide
Testing
the
Right
SWItch
The VIA pins for the Up, Left, Down, and Fire switches are normally
set up as inputs, but the Right switch pin has two functions. In addition to
acting as
an
input to test the switch, the Right switch pin serves as
an
output
pin to scan the keyboard. A VIA pin can be either
an
input
or
an
output.
If
the VIA
is
instructed to send a signal
out
through a pin, it can't sense
an
incoming signal
at
the same time.
When the VIA
is
told to use the Right switch pin as an input, the VIC
subroutine that scans the keyboard can't use it as an output.
If
the VIC can't
send a signal out through the pin, certain keys "disappear" and the VIC can
no longer tell if they are pressed. To resolve this conflict, programs that use
the joystick must instruct the VIA to use the pin as
an
input while checking
the joystick switch, then set it back to
an
output so the VIC can check the
keyboard. The program can do this by POKEing into a memory location
that controls the direction (in or out)
of
the pins. Each group
of
eight
1/0
pins corresponds to one of these locations. There
is
one bit in this location
for each of the eight pins. This bit
is
a 0 for
an
input pin
or
a 1 for
an
output
pm.
To minimize conflict with the keyboard scanner, your programs should
set the direction control, read the switch, and restore the direction control
on a single program line, as follows:
10
POKE37154,0
:
RS
=
PEEK(37152)
POKE37154,255
A Complete
Joystick
Scanner
We
will now look
at
the programming necessary to convert the joy-
stick's bit locations
to
physical movement.
If
you write one program that
uses a joystick, you will probably write others,
so
we'l
provide a standard
subroutine that can be typed into any program. This subroutine sets three
variables for the main program.
XI The X Increment. Controls movement to the right
or
left.
YI
The Y Increment. Controls movement up or down.
FB
Tells whether the Fire Button
was
pressed.
XI
is
set to
-1
for left, + 1 for right, and 0 for neither.
YI
is
set to
-1
for

Other manuals for Commodore VIC-20

Related product manuals