The On Goto/Gosub Command; Using Memory Location; Using Peek And Poke For Ram Access - Commodore 128D User Manual

Hide thumbs Also See for 128D:
Table of Contents

Advertisement

n
n
n
n
Using Memory
Locations
1
I
The ON GOTO/GOSUB Command
There is another way to make the computer jump to another section
of your program (called branching). Using the ON statement, you can
have the computer decide what part of the program to branch to
based on a calculation or keyboard input. The ON statement is used
with either the GOTO or GOSUB-RETURN commands, depending on
what you need the program to do. A variable or calculation should be
after the ON command. After the GOTO or GOSUB command, there
should be a list of line numbers. Type the program below to see how
the ON command works.
10 ? "ENTER A NUMBER BETWEEN ONE AND FIVE"
20 INPUT X
30 ON X GOSUB 100,200,300,400,500
40 END
100 ? "YOUR NUMBER WAS ONE":RETURN
200 ? "YOUR NUMBER WAS TWO":RETURN
300 ? "YOUR NUMBER WAS THREE":RETURN
400 ? "YOUR NUMBER WAS FOUR":RETURN
500 ? "YOUR NUMBER WAS FIVE":RETURN
When the value of X is 1, the computer branches to the first line num
ber in the list (100). When X is 2, the computer branches to the sec
ond number in the list (200), and so on.
Using PEEK and POKE for RAM/ROM Access
Each area of the computer's memory has a special function. For
instance, there is a very large area to store your programs and the
variables associated with them. This part of memory, called RAM, is
cleared when you use the NEW command. Other areas are not as
large, but they have very specialized functions. For instance, there is
an area of memory locations that controls the music features of the
computer.
There are two BASIC commands—PEEK and POKE—that you can
use to access and manipulate the computer's memory. Use of PEEK
and POKE commands can be a powerful programming device
because the contents of the computer's memory locations deter
mine exactly what the computer should be doing at a specific time.
65
USING C128 MODE—Advanced BASIC Programming
n

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 128D and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents