Radio Shack TRS-80 Model 100 Basic Manual page 125

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Experiment #8 Keyboard Control of the Display
This experiment
will
teach you how to input keyboard characters without pressing
(EBll8). This is ljseful when you want the Computer to respond immediately when a
key is depressed.
Clear memory with the NEW command and then enter the following program:
100 CLS: A
=
100 : AT
=
A : PRINT
@
At
"*"
200 A$
=
INKEY$ : IF A$
= ""
THEN 200
210 IF A$
=
"0" THEN AT
=
AT
+
1
220 IF A$
=
"5" THEN AT
=
AT - 1
300 PRINT
@
At " "; : PRINT
@
AT,
"*";
310 A
=
AT : GoTo 200
Execute this program.
You will see an asterisk
(*)
appear in the center of the display (approximately). Press
(]J. The asterisk should move to the right. Press (]J and the asterisk should move to
the left. You should be able to move the asterisk back and forth on the display by
pressing (]) to move it to the right and (]J to move it to the left. Press (BREAK) to
terminate execution of the program.
Note that this program has multiple statements on some lines to conserve display
space.
Line 198 The display is cleared and the variables A and AT are initialized to 100. The
PRINT@ statement displays an asterisk in position 100, which is approximately in the
center of the display.
Line 288 The statement
A$
=
INKEY$
causes the Computer to look at the keyboard to see if any key is being depressed.
If
a
key is being depressed when the statement is executed, the INKEY$ function will
return a one character string for that key. For example, if (]) is being depressed when
Line 200 is executed, INKEY$ will return the one character string "0" and store it in
the string variable A$. If no key is being depressed when Line 200 is executed,
INKEY$ will return a null string (""), and A$ will be null ("").
The second statement in Line 200:
IF A$
= ""
THEN 200
causes a loop which continuously looks at the keyboard to see if a key has been
depressed. If no key is depressed, A$ is null and execution of Line 200 is repeated.
When a key is depressed, A$
will
no longer be null and the condition in the IF
statement will be False, causing execution to resume with the next Line, 210.
Line 218
If
OD
is depressed, the PRINT@ position (AT) is increased by one which
will move the asterisk to the right.
Line 228
If ([) is depressed, the PRINT@ position (AT) is decreased by one, which
will move the asterisk to the left.
119

Advertisement

Table of Contents
loading

Table of Contents