Commodore PET User Manual page 311

Table of Contents

Advertisement

The first version of the program above randomly fills the screen with the
keyed-in character. It does this by simply POKEing to random screen locations. It
may POKE many times to the same location when other locations are not yet
filled, and it continues to POKE even after the screen is filled until a new character
is keyed in.
When the program is run, about half the screen positions quickly fill with
the character. Then character placement slows down more and more until at the
end, when the screen is almost filled, and remaining positions are filled very
slowly. It takes about three minutes to completely fill the screen with this version
of the program.
The program is operating at the same speed throughout. but it doesn't get
much work done towards the end because many of the positions that it POKEs to
are already filled. The program appears to slow down because a POKE (or PRINT)
of a character over the same character has no visible effect.
The program can be speeded up a good deal by eliminating the superfluous
POKEs to screen positions that are already fi lied. A new version of program
BLANKET does this.
Rather than calculating a number in the same range ail the time and discard-
ing, or in this case re-POKEing, the duplicate numbers, the new program
decreases the range of numbers generated to correspond with the number of
items left to operate on. It does this by keeping track of the screen positions re-
maining to be filled in a table and generating a random number within the range
of table indexes yet to be POKEd to. The POKE address itself is gotten from the
contents at the table index.
5 REM RANDOM VERSION 2
10 REM
~*****~
B LAN K E T
*~*~~**
2(1 RE!'1 RANDOM DI SPLAY OF ONE
30 REM
CHARACTER ENTERED FROM THE
40 REM
KEYBOARD
50 REM
*****~~~***~**************~****
70 DIM
T(999)
80 GOSUB 200
:REM INITIALIZE TABLE
9(1 PRINT"HIT A KEY OR <:R:> TO END
Il ;
1(10 GET C$:IF C$="" GOTO 100
1(15 IF C$=CHR$(13) GOTO 170
110 PR 1tH ":']" .;
: REM CLEA!': SCREEt"
120 X=RND ( - TI)
: REM STA!':T NEW SEEII
125 C=(ASC(C$)At'Œ128)/2 OF: (ASC(C$)AND63)
126 FOR N=999 Ta 0 STEP -1
127
A~=(N+1)*RND(1)
:REM PICK AN ELEM
128
A=T(A~)+32768
:REM FORM POKE ADDR
129 TP=T(A;O: T(A;':)=T(tü: T(t-D=TP: REM
S~.JAP
ELEME~nS
130 POKE A.C
:REM DISPLAY CHAR
140
NE~~T
t"
160 GOTO 100
170 ENI'
199 REM **SUBR TO INITIALIZE
TABLE~*
200 FOR 1=(1 Ta 999:T(!)=I:NEXT
210 RETURN
298

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cbm

Table of Contents