EasyManua.ls Logo

Commodore CBM - Page 312

Commodore CBM
447 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...
ln this program, lines 5 through 50 are the standard header. The Table
T,
used to hold the 1000 screen position indicators,
is
dimensioned in line
70.
At
line 80
an
initialization subroutine
is
called that places the numbers a
through 999 into corresponding elements of Table 1.
T(O)
will
contain
0,
T(l)
will
contain
1,
...
T(999)
will
contain 999. The elements
would
not have to
be
filled
with
consecutive numbers since they are to
be
picked randomly,
but
this
is
the
easiest
way
to program the
fililoop.
In
fact. the table
will
be
in order only the first
time the program
is
run after loading. Lnes 90 through 125 are exactly the same
as
in the earlier version.
Lines 126 through 140 form a
FOR
...
NEXT
loop for filling the 1000 screen
locations
with
the keyed-in character. Line 127 picks a random table index
A%from
theremaining unfilled range of ato
N.
The formula
(N+l)*RND(l)
is
taken
from the boxed formulas given earlier. Line 128 forms the
POKE
address A
as
the
sum of the T table element whose index was picked by line
12/,
plus the begin-
ning screen memory address of 32768. Line 129 exchanges the picked table ele-
ment T(A
%)
with
the highest active table element
T(N)
via a temporary location
TP.
Line 130 displays the character at the random screen location. The NEXT N at
line 140 decrements the pointer N
50
that the used screen address just swapped
into
T(N)
is
not picked again during the current program
run.
5
REM
RANDOM
VERSION 2A
10
REM
*******
B
LAN
K E T
*******
20
REM
RANDOM
DISPLAY
OF
ONE
30
REM
CHARACTER
ENTERED
FROM
THE
40
REM
KEYBOARD
50
REM
*******************************
70
DIM
T1(249).T2C249).T3C249).T4(249)
75
T=4
:REM
NUMBER
OF
TABLES
76
N=250
:
F~EM
NO
OF
ELEr1ENTS
80
GOSUB
200
:REM
INITIALIZE
TABLES
90
PRINT"HIT
A
KE'T'
OF~
<F~>
TO
Et·m".:
95
Nl=N:N2=N:N3=N:N4=N
1(1(1
GET
C$:
IF
C$=""
GOTO
100
105
IF
C$=CHR$(13)
GOTO
170
11
(1
PF:
1
tH"
:T'
.;
:
REr1
CLEAF:
SCREEN
120
X=RNDC-TI)
:REM
START
NEW
SEED
125
C=(ASCCC$)AND128)/2
OR
(ASCCC$)AND63)
126
FOR
L=lT01000
:REM
1
FOR
EACH
SPOT
127
n~=T*RND
( 1 ) +1 :
REr1
PI
CK
A
TABLE
128
ON
T%
GOSUB
300.400,500.600
:REM
GO
PICK
AN
ELEMENT
130
POKE
A.C
:REM
DISPLAY
CHAR
140
~IE>'::T
L
160
GOTO
95
170
END
199
RErl
**SU:E:F~
TO
ItH
TI
ALI
ZE
TABLES**
200
FOR
1=0
TO
N-l:T1CI)=I:NEXT
210
FOR
I~0
TO
N-l:T2CI)=I+250:NEXT
220
FOR
I~0
TO
N-l:T3CI)=I+500:NEXT
230
FOR
1=0
TO
N-l
·T4(I)=I+750:NEXT
24(1
RETURt~
299
REM
**SUBROUTINE
FOR
TABLE
Tl**
299

Table of Contents

Other manuals for Commodore CBM

Related product manuals