EasyManua.ls Logo

Commodore VIC-20 - Page 157

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 4 Advanced
BASIC
Programming
143
But why use a subroutine to get a character when a GET statement
would suffice?
A GET statement checks the keyboard for a keypress, but it gives no
clear sign to the operator that a character should be entered. The subroutine
at
line 5000 flashes the cursor while waiting for a keypress, thus making it
more obvious that the VIC
is
waiting for some kind
of
entry. Besides, the
get-character subroutine
is
used by another subroutine in this program.
It
makes sense to relegate this low-level function to another subroutine.
The subroutine starting
at
line 3500
and
ending
at
line 3600 asks for a
single-digit numeric entry. In the name-and-address program, the only
numeric entry
is
the number
of
the line to change, which ranges from I to
6.
3500
REM
ASK
FOR
A
NUMERIC
SELECTION
3510
REM
RETURN
SELECTION
IN
NM~
3520
REM
NM~
MUST
BE
LESS
THAN
HI~
AND
MORE
THAN
LO~
3530
REM
CALLINO
PROGRAM
MUST
SET
HI~,LO~
AND
QU$,
THE
QUESTION
ASKED
3540
OOSUB
9000:REM
POSITION
THE
CURSOR
3550
PRINT
QUS;
3560
GOSUB
5000
:
REM
GET
A
CHARACTER
3570
NM~·VAL(CS)
3580
IF
NM%<LO~
OR
NM~)HI~
THEN
3560
35!:l0
PRINT
C:S;
36180
RETURN
This subroutine must have several variables set by the main program
before it
is
called. First, the maximum
and
minimum allowable values of the
entry should be in integer variables HI% and LO%. Second, the subroutine
displays a question to the operator contained in QU$, which also has to be
set before calling the subroutine.
This subroutine positions the cursor to a given screen position, and
the coordinates
of
that
position need to be passed to the subroutine in the
variables R %
and
C%. Line 3540 calls the subroutine
at
line 9000, which
positions the cursor. Line 3550 displays the prompt,
and
line 3560 calls the
"get keyboard entry" subroutine.
The subroutine
at
line 5000
nee<is
no parameters.
It
simulates a flashing
cursor while waiting for a keyboard entry. A
FOR-NEXT
statement
on
line
5010 starts a timing loop that displays
an
inverse-video space for the first
30
times
through
the loop. Once the index variable I reaches 30, the statement
on
line 5030 erases the cursor. During this time, the subroutine
is
constantly
checking the keyboard for
an
entry.
If
a key
is
pressed, the statement on line

Other manuals for Commodore VIC-20

Related product manuals