100% found this document useful (1 vote)
1K views322 pages

COMPUTE!'s TI Collection Volume One

COMPUTE!'s TI Collection Volume One, COMPUTE! Publications

Uploaded by

remow
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views322 pages

COMPUTE!'s TI Collection Volume One

COMPUTE!'s TI Collection Volume One, COMPUTE! Publications

Uploaded by

remow
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 322

·' -

'- COMPUTE!'s

'-

COLLECTION
VOLUME ONE


'-

,
'-

,
'-

Greensboro. North Corolino


The following article was originally published in COMPUTE! magazine, copyright
1982, Small Systems Services, Inc.: "All Sorts of BASIC Sorts" (December).
The following articles were originally published in COMPUTE! magazine, copyright
1983, Small Systems Services, Inc.: " Programming the TI" (January); "Writing Your
Own Games" (February); "Easy Editing" (March); "TI Graphics Made Easy" (March);
"TI BASIC One-Uners" (May); " Using a Printer with the TI-99/4A" Uune).
The following articles were originally published in COMPUTE! magazine, copyright
1983, COMPUTE! Publications, Inc.: "TJ Mailing Ust" Uuly); "Sprite Editor for the
TI" (September); " Runway 180: Using Sprites in TI Extended BASIC" (October); "All
About the TI Character Set" (November); "TI Word Processor" (December).
The following articles were originally published in COMPUTE! magazine, copyright
1984, COMPUTE! Publications, Inc.: "The Mozart Machine" Uanuary); "Sound
Shaper" (March); "Wonn of Berner" (April); "Statistics for Nonstatisticians" Uul y).
The following articles were originally published in COMPUTE!'s GIlZtIt~ magazine,
copyright 1983, COMPUTE! Publications, Inc.: "Thinking" (December); "Bowling
Champ" (December).

Copyright 1984, COMPUTE! Publications, Inc. All rights reserved

Reproduction or translation of any part of this work beyond that permitted by


Sections 107 and 108 of the United States Copyright Act without the pennission of
the copyright owner is un lawful.

Printed in the United States of America

ISBN 0-942386-71-X

1098765432

COMPUTE! Publications, Inc., Post Office Box 5406, Greensboro, NC 27403, (9 19)
275-9809, is one of the ABC Publishing Companies, and is not associated with any
manufacturer of personal computers. TI-99/4 and TI-99/4A are tradema rks of Texas
Instruments, Inc.
Contents
Foreword .............. . ... .. ..... . . , .. . .. . ............ v

Chapter 1. Getting Started ....... .... .... . ......... . .... 1


'-- TI Features
C. Regena .. . . . . . . ... . . .. . • . .. . • . . . . . . . .. . 3
Wri te Your Own Games
C. Regell a . . .................. .. .. • ..........•....... 9
Easy Editing
C. Regena ...................• .. ..•... . . • • . . . • . . . . .. 14
All About the Character Set
Michael A. Covington ...... .. ....... .. ... .. ... . ...... 18

Chapter 2. The Basics ....... .. ... . .. . . . ..... ... .. . 27


TI BASIC One-Liners
Michael A. Covington 29
CALL KEY Hints
Roger Lathrop ........... .. • .. . .•.. .. • •.• •. •.• .. .... 34
All Sorts of BASIC Sorts
C. Regena ............. .. . .. .... . ... . .. .. . ...... 36
Searching Algorithms
Doug Hapeman ..............................•...... 41
Transferring Variables in TI Extended BASIC
Patrick Parrish ........................... .. •. . .. . .. . 49
Computer Visuals
Richard D. Jones and Howard A/vir ... . . ....•.... • ...... 55
Using a Printer
C. Regena ................. . 60
Chapter 3. Applications .... 63
Mailing List
Doug Hapeman ........ .. ............. . ..... . 65
Statistics for Nonstatisticians
A. Burke Luitich ([1 Translation by Patrick Parrish) ... . ..... 75
Tlcalc
Raymond J. Herold . .................................. 84
Financial Interests
Doug Hapeman .... . ....................•........... 99
A Mini Data Base Management System
Raymond J. Herold . . . . . .. ......... . • . • .. •....... 109
TI Word Processor
James D. Baker .......... • ....• . ...•..... • •... •.. ... 127

L.. Chapter 4. Recreation ...... .. . ..... . ... . . .. .. ... ..... 145


Trap
Larry Michalewicz .......•.....•...•................ 147
'-
Duck Leader
Douglas E. Smith and Douglas W. Smith ..... . .......... . 150
Freeway 2000
John B. Dorff .............. . 158
The Chase
Dennis M. Reddington .............................. . 165
Thinking
Andy VanDuyne (fI Version by Patrick Parrish) .......... . 172
Bowling Champ
Joseph Ganci (fl Translation by Patrick Parrish) .......... . 179
Worm of Berner
Stephe,! D. Fultz (fl Translation by Patrick Parrish) ....... . 186

Chapter 5. Sound and Graphics ......... . ............ . 195


TI Graphics Made Easy
Lyle O. Haga ......................... .. .... . 197
Animating TI Displays Without Sprites
Jim Schlegel ...............................•....... 201
SuperFont
Patrick Parrish .... .. . .. .. .. .. . . .. . .. . . ... ..... . ... . 211
Sound Maker
Frank Elsesser .................... . 226
Sound Shaper
Steven Kaye ([I Translation by Patrick Parrish) ....... . 238
The Mozart Machine
Donald J. Eddington ([1 Translation by Gregg Peele) .. 240

Chapter 6. Sprites ................................... . 245


A Beginner's Guide to Sprites
Gary K. Hamlin ......................... . 247
Sprite Editor
Larry Long ....................................... . 264
Runway 180: Using Sprites in Extended BASIC
James Dunn .... . ................... . ............. . 270

Chapter 7. Utilities ........ . ....... .. .. . ... . . . ...... . 281


TI Disk Deleter
Patrick Parrish . . .................... . .•.... . ....... 283
Master Disk Directory
Raymond J. Herold ................... ... ........... . 291

Appendix ........ . ....................... . ......... . 305


A Beginner's Guide to Typing In Programs .... . . ... ..... . 306

Index .. , .... " ............ , .................... . ... . , 308


Foreword
Why did you buy a computer? Was it to play games? Or were
you more interested in home applications? Maybe you hoped
that your children would learn BASIC programming. Whatever
your reason, you'll be pleased with what you find between the
covers of COMPUTEt's TI Collection, Volume 1.
COMPUTE! Publications has been supporting the TI-
99J 4A since columnist C. Regena first appeared in COMPUTE!
magazine in January 1983. Since then, through continuous
coverage in COMPUTE! magazine and the publication of seven
books, Tl owners have recognized the high-quality programs
and tutorials published by COMPUTE!. COMPUTE!'s TI Collec-
tion, Volume 1 continues that tradition, presenting over 30 pro-
grams and articles in clear and easy-te-understand language.
This anthology of games, applications, utilities, and
tutorials for the TI-99/ 4A contains many never before pub-
lished. "SuperFont" is an exceptionally powerful and simple-
to ~ use character editor. " Sprite Editor" and "Sound Shaper"
make graphics and sound programming easy. Games like
"Worm of Berner" and " Bowling Champ" will provide hours
of fun . "Thinking:' a game that tests your memory and
reasoning skills, can be played by the youngest leamer, yet
challenges even the most experienced game player. Need to
organize your Christmas card files? "Mailing List" fits the bill.
And if all this weren 't enough, we've included articles
that show you how to use sprites in your own programs, util ~
ities that help you organize your diskettes, an electronic
spreadsheet, a word processor, and much more.

v
'--

'--
L
I
TI Features
_____ c. Regen.

The T1 has some very powerful features. This overview of


hardware, software, Qnd miscellaneous resources will give
you an idea of just what the TI can do.
Welcome to the world of the TI-99/4A computer. For home,
personal, and educational applications, the TI -99/4A computer
is a very powerful machine. This article will discuss some of
the features unique to this microcomputer.
Extraordinary Graphics and Sound
Graphics. You may easily defme yow own high-resolution
(detailed) graphics characters. There are 16 colors, and you
may use all 16 on the screen at the same time in high-resolution
graphics (unlike other computers). You may also use text any-
where on the screen at the same time you use high-resolution
graph ics. Most other microcomputers are limited when com-
bining text with graphics.
Music. You may play up to three notes and one noise for
a specified time using one statement. The music is specified by
a number which represents a frequency of 110 Hz to 44733
Hz, tones from low A on the bass clef to beyond human hear-
ing range. The tone may be between regular musical notes. An
example which plays a three-note, C-major chord for three
seconds is:
CAL L 50 UND (3e~e.262.6.330.4.440.2}

The first number is the duration in milliseconds, in this case


3000. The next numbers are frequency and loudness for each
note. You may also add a "frequency" of - 1 through - 8 and
a loudness for the noise generator. You may combine tones
and noises for all kinds of sounds-everything from classical
music to sound effects from outer space.
Combining music and graphics. "Computer choreog-
raphy" is possible because other statements (including graph-
ics) may be executed while music is played. You may illustrate
a song, for example. Or if you have a game program, you may
make calculations while you are making a noise. The com-
puter will play music and execute statements until the dura-
tion runs out or until the program comes to another CALL
3
Getting Started _ _ _ _ __

SOUND statement with a positive duration. A negative num-


ber for the duration will start that CALL SOUND statement
even if the first duration has not finished. Try using a
FOR-NEXT loop to vary any of the parameters for special

,,
1 ••
.
effects. Here is a sample using just one tone:
FOR N=S00 TO 88. STEP 2.

..
CALL SOUND( - 99.N,2)
12. NEXT N

,13. FOR N=880 TO 5 •• STEP - 2.


CA LL SOUNO( - 99.N.2)
Noises. Using negative durations and combinations of
music and noise numbers for frequency, you can make all
sorts of synthesized noises. Quite often with noises you will
want to use a FOR-NEXT loop and vary the loudness
parameter.
Built-in BASIC. The programming language of TI BASIC
is built into the main console-nothing extra to buy. The TI
BASIC language is an excellent language for learning how to
program, yet it is powerful enough for an experienced math-
ematician because of the built-in functions.
String manipulations. String (non-number) manipula-
tions are also very powerful. Here is a sample program to print
a phrase A$ on the screen starting at row R and column C:
100 FOR 1=1 TO LEN(A$)
110 CALL HCHAR(R.C+I - l,ASC(SEG$(A$,I, 1»)
120 NEXT I
The loop will go from 1 to the LENgth of the phrase A$.
String variable names must always end with a dollar sign.
SEG$ takes a SEGment of the phrase. In this case we are start-
ing at the left side and taking one letter at a time. ASC gets
the ASCLI character code value of the character in the phrase.
CALL HCHAR uses a graphic method to place the character
on the screen at a certain row and column.
No Variable Name Worries
Variable naming. In your own programming on the TI-
99/4A you may use meaningful variable names, although in
many microcomputers the BASIC language recognizes only
two characters for a variable name. For example, if you have a
program with the variable name BLUE and another variable
name BLACK, other computers may recognize only one vari-

4
_ _ _ _ _ _ Getting Started

able, BL, but the TI-99/4A knows you are using two variables.
You also do tlot have to worry about embedded reserved
words in variable names.
Documentation. Two excellent manuals aTe included with
the computer. One teaches you programming in TI BASIC.
The manual is very easy to understand, and a person with no
previous computer experience can Jearn to program with this
book. Also included is the User's Reference Manual, which may
cost over $15 for other computers. The reference manual.
which is in loose-leaf form, includes aU the commands along
with explanations and sample programs.
Plug-in modules. The easiest way to use the Tl-99/4A is
to insert a command module which contains a program. The
modules actually add memory to the computer while they are
being used. Unfortunately many of the very best modules are
difficult to find or even completely unavailable.
Speech. Even though this feature is not built in, I'm going
to include speech in this list of unique features of the TI~
99/4A because it is very easy to use . The speech synthesizer
is a small box that attaches to the side of your console.
16-bit microprocessor. The TI ~99/4A uses a TMS9900,
16 ~bit microprocessor, which offers more computing power
and greater expansion and configuration flexibility than an
8~bit microprocessor. You can get higher numeric precision
and simplified memory addressing.
Programmer's aids. Programmers will enjoy the easy line
editing features. Various function keys allow you to insert or
delete characters or to erase or clear a line. There is also a
TRACE command to help in debugging.
Another feature programmers like is the built~in automatic
numbering. Just type in NUM, press ENTER, and you can start
programming. The line numbers start with 100 and automati~
cally increment by 10. Or you may specify any starting num-
ber and increment. NUM 5,2 will start with line 5 then
increment by 2.
After you have programmed and added or deleted state-
ments here and there, you'll enjoy the automatic resequencing
command, RES. This command will automatically renumber
your statements, including all statement numbers referenced
by other statements.

5
Getting Started _ _ _ _ __ "-

Using the Cassette Recorder


Cassette. Probably one of the first items you'll need is a
cassette cable to connect a cassette recorder to the computer.
Nearly any cassette recorder is acceptable; however, the vol-
ume setting for the TI-99J4A is quite critical. In general, a
battery-operated recorder does not work well enough for ac-
curate data retrieval. Also, your recorder should have a tone
control and a volume control. I have had the greatest success
using the Panasonic RQ2309A cassette recorder.
Page 1-9 in the User's Reference Guide tells how to connect
the cassette cable, and the pages following describe how to
save and load data from modules. Page II-42 shows an example
of how to load a program that you have saved or purchased.
Some other hints for using the cassette recorder are:
Tum the tone control to the highest setting.
Start with the volume about mid-range.
Follow the instructions after you type in OLD CS1.
If you get the message NO DATA FOUND, increase the
volume.
If you get the message ERROR IN DATA, decrease the
volume.
Sometimes a fraction of a change in volume can make all
the difference in your success in reading a program. Once in a
while, if I alternate between the two error messages at a vol-
ume setting near 2 or 3, I tum the volume to about 8 or 9 and
the program will load.
The smallest jack of the cassette cable goes into th e re-
mote switch of the cassette recorder so the computer can tum
the recorder on and off automatically. If th e recorder does not
turn on and off properly, simply remove the remote jack from
the plug. You can operate the cassette recorder manually to
save and load programs. For programs using the cassette re-
corder for data entry, you will need the remote capability. An
adapter is available for the remote switch.
Disk drives. You can save and retrieve data or programs
on a diskette much more quickly than by using a cassette sys-
tem. The TI-99J4A uses 51f4-inch, Single-sided, soft-sectored
diskettes. To connect a disk drive, you also need a disk
controller. One disk controller can handle up to three disk
drives. Many business applications require two disk drives.

6
_ _ _ _ _ _ Getting Started

Memory expansion. The TI Memory Expansion is for 32K


RAM, and you need a module that will access it. You cannot
use it with console BASIC. Extended BASIC does not require
the memory expansion but can use it. Pascal, TI Logo, and
Editor/Assembler require the memory expansion.
Periph eral box. The "old" method had each peripheral in
a separate " box" connected to the computer or the previous
peripheral; each had its own power cord. The " new" system is
the peripheral box, which has its own power supply and slots
fo r cards for the RS-232 interface, memory expansion, disk
controller, P-code, one disk drive, and possible future cards.
Monitor. Although most TI users connect their computers
to a regular television set, it is possible to connect to a mon-
itor. A monitor will give a very clear, sharp picture.
Making the Computer Speak
Speech. The TI Speech Synthesizer allows you to hear the
computer speak to you. You will need a command module
with built-in speech to hear the computer speak.
To program your own speech or to use any cassette or
disk programs that use speech, you will need a module.
Speech Editor and Extended BASIC have speech capabilities
with a given list of words. Terminal Emulator II allows un-
limited speech; the accompanying documentation gives you
ideas for programming speech using this module. You may
vary the pitch, slope, and inflections. You may use allophones
to create words, or you may have the computer speak words
which you spell phonetically.

Telecommunications and Languages


Termin al. The Terminal Emulator II command module
(or Terminal Emulator I, which does not have speech) allows
you to use your TI-99/4A to act as a terminal either to an-
other computer or to a large telecommunications service. You
will also need the TI RS-232 Interface and a telephone
modem.
Printer. You may use a number of different brands of
printers with your microcomputer. To connect your TI-99/4A
to a printer, you'll need the TI RS-232 Interface and a cable to
go from the interface to the printer (the cable is usually sold
with the printer).

7
Getting Started _ _ _ _ __

RS-232. The RS-232 Interface has two ports so you may


be connected to a modem and a printer at the same time. An
instruction book comes with the RS-232 so you'll know how
to operate the computer under different conditions.
Extended BASIC. Tl Extended BASIC (XBASIC) is a
programming language contained on a module. A manual
(over 200 pages) and a programmer's reference card come
with the module. No other peripherals are necessary to use
XBASIC. If a program has been written in XBASIC, the
XBASIC module must be inserted for the program to run.
Some of the advantages of XBASIC are multistatement lines,
complex IF-THEN-ELSE logic, subroutine and MERGE
capabilties, DISPLAY AT and PRINT USING, program se-
curity (SAVE protection), speech (with speech synthesizer),
and moving sprites with greater graphics capabilities.
Editor/Assembler. For machine language programmers,
it requires the memory expansion, disk controller, and one
disk drive.

Software
I've mentioned software (programs) last, although it's probably
the first extra purchase you will make for your computer. Soft-
ware is what you need to use your computer. Software is
available on command modules, cassettes, diskettes, and by
typing in programs you find in books and magazines. This
book is an example of a source of inexpensive software.

8
Write Your Own
Games
- - - - - C. Regen.

Some tips on getting the most out of your TI when writing


games.
You have probably discovered that one of the fun things to do
with your TI-99/ 4A is to play games. In fact, many people
who wanted one of the popular game machines have discov-
ered that for about the same amount of money they could
have a computer and still be able to play games. Many of the
games written for the T1-99/ 4A are arcade quality-that is,
they have good graphics and fast action.
To program your own games with fast, smoothly moving
objects, you will want to use TI Extended BASIC. It allows
you to use up to 28 sprites. You may define the shapes of the
sprites and designate a certain magnification. You may also
specify the sprites' speed. The row velOcity and the column
velocity may vary from - 127 to + 127, and by specifying
numbers for both velocities you will get a diagonal movement.
Sprites " wrap" at the edges of the screen, so you don 't need
to worry about " crashing" your program on edge conditions.
With one CALL SPRITE statement you can define the sprite
number, shape, color, position, and speed. (For more infor-
mation about sprites see chapter 6.)
TI Console BASIC (the BASIC built in with no accessories
or peripherals) is a language powerful enough that you can
design a variety of fun games with it. If you have moving ob-
jects, however, they have to move a square at a time and thus
will have jerky movement. Depending on the number of ob-
jects, BASIC games tend to be slow; however, I have seen sev-
eral fast action games that really require nimble fingers.
Whether you are writing a game in TI BASIC or in TI Ex-
tended BASIC, I can offer a few programming tips. Keep in
mind that the best way to learn is to actually start program-
ming-and playing.

9
Getting Started ______

Randomness
Probably a central tool in computer games is the machine's
ability to choose things randomly. Most computers have the
command RND, but each computer has a slightly different
syntax (way of writing the command). On the TI-99j4A, RND
represents a random number between zero and one. Tum on
your computer, press any key to begin, and press 1 for II
BASIC. Now type in PRINT RND and press ENTER. The com-
puter will print a decimal fraction (to ten places), Usually in
game situations you won't want a fraction, so multiply that
fraction by a number. For example, multipl y RND by 10 like
this: PRINT 10'RND or PRINT RND'IO. Now you will get
ten times that decimal fraction.
You probably want just the whole number part of that
mixed decimal number. Use the fNTeger function to get the
whole number. PRINT INT(IO'RND). If you keep trying this
command, you will get numbers from zero to nine. Remember,
INT truncates the decimal portion; it does not round the num-
ber. Suppose you really wanted a random number from one
through ten. The command would be: PRINT INT(IO'RND)+I
or PRINT INT(IO'RND + I).
One more step. Assume you want a number N to be a
random number between 10 and 20, inclusive. 20 - 10 = 10.
There are 10 numbers plus 1 ("inclusive"). The command
could be N ~ INT(l1'RND)+IO. The portion INT(ll'RND)
will give you numbers from 0 to 10; then you add 10 to get
numbers from 10 to 20.
Now try this short program:
190 FOR I - I TO 10
110 PRINT INT(10*RNO)+1
120 NEXT I

Run the program. Run it again. And again. The program is


printing ten random numbers from 1 to 10. However, you'll
notice that each time you run it, you get the same numbers in
the same order. You need to add the line: 105 RANDOMfZE.
The RANDOMIZE command mixes up the numbers so
that each time the program is run you will get different num-
bers-and that's what you want in a game. The User's Ref-
erence Guide indicates that the RANDOMIZE statement only
needs to be somewhere in the program to generate different
numbers; however, I have found that one RANDOMIZE state-

10
_ _ _ _ _ _ Getting Started

ment at the beginning of a program does not always work. It's


better to use the RANDOMIZE statement just before you use
the statement containing RND. Note: If you are debugging a
program, you may want to leave RANDOMIZE out so that
you'll know exactly what numbers your program is choosing.
Debug your program, then add the statement and test it.
Moving Objects
In general, the fewer moving objects you have in your game,
the faster the action can be, and the logic will be a lot less
complex. Also, each moving object should be specified by only
one character number so you don 't have to use up valuable
time by building an object out of several characters. To move
an object in TI BASIC you need to erase the object in the first
position (replace it with a space) and draw it again in the sec-
ond position-each move takes two statements.
Player Input
There are two main ways the computer can understand what
you want: by using the joysticks or pressing keys on the key-
board. Your game may be designated for joysticks only, key-
board only, or both. Because of the logic involved, a game
using both methods of input will be slightly slower in re-
sponse; and depending on the branch sequence, one of the
methods will be slower than the other.
Joysticks may be easier to use to learn a game, especially
if the player is used to a videogame using joysticks. My
own children, and many other players I know, prefer using
the keyboard for TI Invaders and MU1Ichma'l because the
joystick response is conSiderably slower than the keyboard
response.
The keyboard action is easy to learn because there are
standard arrow keys for all games designed for the TI-99 / 4A.
Programmers writing games for other computers often choose
their own favorite keys to use, and the directions are different
for each game. On the TI-99j4A, the arrow keys are E (up), X
(down), 5 (left), and 0 (right), with the shooting key either the
ENTER key or the period key. If there are two players, the
standard arrow keys on the right half of the keyboard are I, j,
K, and M.
The II joysticks (wired remote controllers) come with a
little instruction book with some sample programs. The main

11
Getting Started _ _ _ _ __

command is CALL JOYST(K,X,Y), which returns an X and Y


value for the position of the joystick, where X and Y may be
4, - 4, or O.
To detect keys pressed on the keyboard, use the CALL KEY
command. This command is like the GET command in other
BASIC languages. The fonn is CALL KEY(O,KEY,STATUS)
where a means to scan the whole keyboard. STATUS is a
variable name (it could be ST or S, or whatever you wish)
which will return whether a key has been pressed or not. KEY
is a variable name (again, use whatever you wish) that will re~
tum the ASCII code of the key pressed, such as 13 for the
ENTER key, 65 for the letter A, 69 for the letter E, etc.
By using IF statements, you can check which key was
pressed and branch accordingly. You can also GOTO the
CALL KEY statement for other keys to make the computer act
as if it is ignoring all responses except the keys allowed. Here
is a sample using arrow keys:
100 CALL KEV(0,K,S)
110 IF K:b9 THEN 1000 (up a ...... o w)
120 IF K:b8 THEN 2000 (ri ght a ...... ow)
130 IF K:B8 THEN 3000 (down a ...... o w)
140 IF K:183 THEN 4000 (} eft a ...... ow)
ELSE 100 (any othe ... key will
be igno ... ed)

Remember, there are several ways to program the same proce~


dure; this is just one way. You may prefer to use "not equal"
signs or a split keyboard and an ON~GOTO statement.
A split keyboard approach scans half the keyboard using
CALL KEY(I,KI,5I) or CALL KEY(2,K2,S2). The key codes re-
turned for up, right, down, and left are 5, 3, 0, and 2. A
sample program using the split keyboard is:
100 CALL KEV( I ,K,S)
110 IF (K < 0)+(K >S) THEN 100
120 ON K+ l GO TO 3000,100,4000,2000,100.1000

Line 110 makes sure the K value is in the right range; the key
value must be from a to 5. All other keys are ignored. Line
120 branches according to which key was pressed. The keys
corresponding to 1 and 4 were not acceptable, so they return
to the CALL KEY statement. If you want to tryout either of
these programs, add the following lines, then run and try
pressing various keys.

12
_ _ _ _ _ _ Getting Started

1000 PRINT "UP"


1010 GOTO 100
200121 PRINT "RIGHT"
2 010 GOTO 100
3 000 PRINT "DOWN"
3010 GOTO 1013
4000 PRINT "LEFT"
4010 GOTO 100

There is a slight problem in testing for zero on the TI-


99/ 4A console. Use logic such as IF K+l <> l rather than IF
K<> O. Also, some of the split keyboard codes are different for
the TI -99/ 4A than for the TI -99/ 4. It's better not to use the
comma, period, semicolon, slash, space bar, ENTER, SHIFT, B,
and G so that programs may be used on either console.

13
Easy Editing
- - - - - C. Regen.

If you use these editing keys and built-hI programmers'


commands, you'll soon discover how fun and easy-ta-use the
Tl-99/4A can be.

You are writing a program or keying one in from this book or


COMPUTE! magaZine when-cops!-you make an error. Hold
it! Don't type the whole line over! Take advantage of the easy-
to-use editing capabilities built into the TI-99/4A.
Take a look first at the arrow keys (found on letters
E,S,D,X). You thought they were just for games? They will
probably be the most frequently used editing keys once you
get used to them. Suppose you have typed lines 100-150 and
look up at the screen and notice you want to change the num-
ber in line 130;
1 30 CALL SCREEN( 14 )

Type in 130 then hold the function key (FCTN) down while
you press the down arrow (!). (It might be best to follow
through this article as you sit at your TI-99 / 4A.) You'll notice
line 130 comes up at the bottom of the screen with the cursor
at the first position. Now press FCTN and the right arrow. The
cursor will go toward the right. You may go one space at a
time, or hold the key and it will repeat. Go over to the 4 in
14. Stop right over the 4 and type 6. Press ENTER, and the
line will now be:
1 39 CALL SCREEN(16)

Any characters you don't want to change you can just


pass over with the arrow key. Change the character you want,
then press ENTER-you don't need to go to the end of the
line either.
Now suppose you don 't like color 16 (white) and decide
you want color 6. Type 130 then FCTN ~ . Use FCTN.... to get
over to the 1 in 16. Stop right on top of the 1. Now press
FCTN and 1, which is DEL, for DELete. Now press ENTER
and you should have:
13 0 CALL SCREEN(b)

14 --
_ _ _ _ _ _ Getting Started

Try another (unction key. Type 130 then FeTN!. Use


FeTN.... to go on top of the 6 and type 2. Just a second,
though. You don 't want screen 2; you want 12. Use FeTN'" to
back up one spot (cursor on 2). Press FeTN 2 for INSert. You
won 't notice anything right awaYI but now type I-you have
color 12. Press ENTER and your line has been changed.
Automatic Repeats
The left arrow, right arrow, and DELete keys repeat automati-
cally when you hold the key down. The INSert key needs to
be pressed just once and characters will keep being inserted as
you type until you press ENTER, DELete, or one of the arrow
keys. To delete or get rid of a whole line, type the line num-
ber and then press ENTER.
Two more handy editing keys are the up arrow and down
arrow. Let's assume you have the following lines:
200 CALL HCHAR( 3 , 5 ,4 2 >
210 CALL HCHAR(3,B,4 2 )
220 CALL HCHAR( 3 ,20,3 3 >
You run your program and discover the graphics need to be
a line lower- the row value needs to be changed from 3 to 4.
Type 200, press FCTN !, and use the right arrow to
change the 3. Instead of pressing the ENTER key, press
FCTN ! . After line 200 has been edited, the very next line, line
210 in this case, will appear for editing. Likewise, the up ar·
row will give you the line just before the one on which you
were working.
Two other editing keys you should be aware of are
ERASE (FCTN 3) and CLEAR (FCTN 4). You may already be
familiar with CLEAR. If you are running a program and want
to stop, FCTN 4 will interrupt the program. (QUIT, FCTN ~,
will stop the program, erase it from memory, and return to the
TI title screen; CLEAR stops the program but retains it in
memory and you may either CONtinue or RUN.)
CLEAR has another function while you are programming.
If you start typing a line and decide you don 't want that line
after all, press CLEAR. The cursor will go to the next line and
the line you were working on is ignored. ERASE will erase the
line that you are working on.
The other function keys you see along th e top row of
your keyboard are used in some of the command modules and
are described in the manuals accompanying the modules.

- 15
Getting Started _ _ _ _ __

Some helpful commands for programmers are LIST,


NUM, and RES. As you are writing a program, each command
needs a line number. When the program is run, the computer
executes each line in numerical order. The command LIST will
list your complete program in order. As your program lists, the
lines scroll off the top if the program is too long for one
screen. If you want to stop the listing, press CLEAR. If you
want to list only part of your program, just list the lines you
wish:
Command Lists:
LIST Whole program
L1ST-200 All lines up to and including line 200
LIST 100-300 Lines 100 to 300 inclusive
LIST 300- Lines 300 to the end
When you're typing in a program, it will save time and
reduce the chance for error if you let the computer type the
line numbers. Type in the command NUM (for NUMBER).
The computer will automatically start with line 100. Now type
in CALL CLEAR and press ENTER. The computer enters line
100 and starts you on line 110. The NUM command automati-
cally increments the line numbers by 10.
You may start anywhere-for example, type NUM 3220
and press ENTER. Your program starts with line 3220 and in-
crements by 10.
Yes, you can change the increments also. Type NUM
200,5 and you'll start with line 200 and increment by 5 (line
200,205,210, etc.). The general form is: NUM initial line,
increment .
If you want the program to start with line 100 but the in-
crements to be 7 instead of 10, you may use NUM ,7.
To get out of the automatic numbering, just press ENTER
after the line number or CLEAR. You'll also notice that if you
have a program in the computer and type NUM the computer
will show you what is on that line. If you want to keep the
line as is, just press ENTER.

Complete Renumbe r
RES is a command that stands for RESEQUENCE. You've
been programming and adding lines here and there and want
it to look nice again, all numbered by tens. Type RES and
press ENTER. As soon as the cursor reappears, your program

16
_ _ _ _ _ _ Getting Started

is resequenced or renumbered, induding all line numbers ref-


erenced in other lines. Try this sample:
1 2 CALL SC REE N(t 4)
2111 FO R 1= 1 TO B
3 0 CA LL S OU NO( 500 . - I. 2l
3 5 NEX T I
Now type RES and press ENTER, then LIST. The lines are
resequenced, starting with 100 and incrementing by 10. Like
the NUM command, you may specify the starting line number
and the increment: RES initial line, increment.
Tcy RES 10 then LIST.
Try RES 1,1 or RES ,5 and experiment with YOUT own
numbers.
Quite often 1 like to start writing programs with line num-
bers incrementing by 10. Type in NUM and start program-
ming. If the program has several branches, I may start one
branch at 1000 (NUM 1000), another at 2000, etc. Leaving
gaps in the line numbers makes it easier to add lines later.
For example, if I have a line 200 and the next line is line
210, I may easily add lines in between by numbering them
202, 204, etc. But what if I had to add 15 lines between lines
that are only ten apart? RES ,SO will spread the lines apart and
allow more numbers in between. Of course, when I'm through
with the program, I RES so the program starts at 100 and in-
crements by 10, and you can't tell where I planned poorly and
had to add lines.

17
All About the
Character Set
- - - - - Michael A. Covington

This brief outlille of the TI character set explains how the


computer reco8"izes each character. The author discusses
some uses of the characters' numeric codes and indicates
which characters' graphic representations can be assigned or
changed.

Chances are you've never given your computer's character set


much thought. You press keys on the keyboard and the
characters appear on the screen; that's all there is to it, or so it
seems. But there's a lot more going on than meets the eye.
Inside the computer, each character is represented by a
numeric code-a number between 0 and 255 inclusive. For in-
stance, the code for capital E is 69; the code for an exclama-
tion mark is 33; the code for a blank (a blank is a character
just like all the others) is 32. To associate these codes with the
characters you see on the screen, the computer has to know
two more things about each of them: a graphic representation
that describes how the character is supposed to look on the
screen, and a key assignment that indicates what key or
combination of keys you can hit on the keyboard to type the
character. For instance, the character string " HELW THERE!"
(not counting the quotation marks) is represented as shown in
Table I.
Table I . Representation of the Strine
" HELLO THEREI"

Graphic H E L L 0
representation:

Numeric code: 72 69 76 76 79 32
Key H E L L 0 space
assignment: key key key key key bar

18
_ _ _ _ _ _ Getting Started

Graphic T H E R E I
representation:

Numeric code: 84 72 69 82 69 33
Key T H E R E shift Be
assignment: key key key key key 1 keys

Statements Using Numeric Codes


Normally (when you type characters in response to a string
INPUT statement or when you type them as part of a pro-
gra m) you enter characters by hitting the keys that correspond
to th em. That is, you access them by means of their key
assignments, and within the program you treat them as
character-string data. But there are ways of referring to charac-
ters by their numeric codes and treating them as numbers. For
instance, the CALL HCHAR and CALL VCHAR statements,
which you meet at an early stage as you work through the
manuals that come with the computer, refer to characters by
their numbers. The statement:
CALL HCHAR( 3 .3,69,29)
will place a row of 20 capital E's (character number 69) on the
screen beginning at row 3, column 3.
Also, you can input characters as numeric codes. The
CALL KEY statement senses whether a particular key on the
keyboard is up or down; when a key is pressed, CALL KEY
gives you the numeric code corresponding to it. For instance,
here is a program which will tell you the numeric code of any
key on the keyboard:
1~ PRI NT ~ PRESS ANY KEY .•• "
29 CALL KEV(5,CODE,S T AT US)
39 IF STATUS <> 1 THEN 20
49 PRINT CODE
5t2! GO TO 19

The heart of the program is lines 20 and 30. Line 20 tells


the CALL KEY subroutine to look at the keyboard and report
what's going on. The variable STATUS wil1 equal 1 only if the
condition of the keyboard has changed since the last time the
routine looked at it. If STATUS does not equal 1, we simply
go back to line 20, since we don't want to do anything more if

19
Getting Started _ _ _ _ __

the user hasn 't pressed a key or hasn't yet let go of the one al·
ready looked at. The variable CODE contains the numeric
code associated with the key being pressed, if any. (The first
parameter of CALL KEY, the number 5, simply indicates that
we want the usual BASIC set of codes; specifying other num·
bers there instructs the computer to use other sets of key
assignments for various special purposes.)
The ASC and CHR$ functions allow you to convert back
and forth between numeric codes and character strings. If A$
is a character string, ASqA$) is the numeric code of its first
character; thus ASC("E") is 69. Conversely, if N is a number,
CHR$(N) is a one·character string of which N is the numeric
code; thus CHR$(69) is E. If we want the program above to
print the characters themselves rather than their codes, we can
convert the codes into characters by changing line 40 to:
40 PRINT CHR$(CODE)
The CALL CHAR subroutine allows you to alter graphic
representations using a hexadecimal code that the manual de·
scribes in detail. For instance, if you want to change the dollar
sign ($) into a British pound sign (£), just execute this
statement:
CALL CHAR(36."001C22207C20207E")
That will do it, at least as long as the program is running: The
key assignment and numeric code will be the same, but the
dollar sign will look like a pound sign. (It will revert to its
original appearance when your program stops executing.)
What's Not in the Manual
Those are the preliminaries; now we get to the really interest·
ing part (the part that isn't in the manual. at least not en·
tirely). Internally, the computer can use any number from 0 to
255 as a character code; any such code can be an element in a
character string and can be referred to by CALL YCHAR,
CALL HCHAR, and CHR$. (In fact, CALL YCHAR, CALL
HCHAR, and CHR$ will actually take numbers up to 32767;
multiples of 256 are subtracted as necessary to get a number
in the 0 to 255 range.) But not all the codes have key assign·
ments or graphic representations. The breakdown (by numeric
codes is as follows:

20
-- _ _ _ _ _ _ Getting Started

O-Undefined (no key assignment, no graphic


representation).
I-IS-Function keys (Table 2). Most of these characters
can be input by means of the CALL KEY statement, but they
cannot be typed in normal contexts (for example, in response
to an INPUT) because there they are interpreted as requests to
perform cursor movements or the like. They have no graphic
representations (if you print them, you get blanks or garbled
patches).
16-29-Undefined (like 0, these codes have no key
aSSignments and no graphic representations, and there is no
straightforward way of giving them either).
30-The graphiC representation of this character is the
black square that marks the cursor; thus, CHR$(30) is handy if
you want a black square. No key is assigned to it.
31-This is the screen border character-a blank that is
the color of the border rather than the typing area. No key is
aSSigned to it.
32-126-Standard ASCII character (Table 3). These are
the characters you use every day, including the alphabet, the
numbers, and all the punctuation marks and mathematical
symbols. Their graphic representations can be changed with
CALL CHAR but will revert to their original form when the
program ends.
127-1S9-User-defined characters (Table 4). These start
out with no graphic representations, but you can define them
with CALL CHAR, and, contrary to what the TI manual says,
such definitions remain in effect after the program stops run-
ning (though most are disrupted when another program is
loaded).
What most people don't realize is that these characters
can be typed-they have key assignments and are acceptable
in the same context as any other character (that is, in response
to an INPUT or CALL KEY, or within quotes in a program).
All but one of them reqUire you to hold down the CTRL key
(at the lower-left corner of the keyboard) when typing them;
character number 127 uses the FCTN key instead.
160-175-Undefined
176-198-These characters have key assignments (Table
S), but no graphic representations and no direct way of giving
them any. They can be used as special function keys of some

21
Getting Started _ _ _ _ __

sort (in response to either CALL KEY or IN PUT), but not as


displayable characters.
199-25S-Undefined.
Even the undefined character codes (those that cannot be
typed on the keyboard or displayed on the screen) are not
completely useless. You can refer to them by means of CHR$
and ASC and use them as special markers of various kinds
when manipulating character strings. They also may come into
play when you are transmitting data to other devices (for
example, printers or other computers) that have definitions for
characters that are undefined on the Tl -99.
Finally, consider this possibility. Each character in a
character string has a code between 0 and 255 inclu sive, acces-
sible through CHR$ and ASC. Also, the SEG$ function allows
you to address individual characters in a string, and the &
(concatenation) operator allows you to construct strings out of
individual characters. This means that a character string gives
you a compact way of storing a set of integers between 0 and
255-each element occupies only one byte in memory, as
compared to the eight bytes normally needed to store a num-
ber. So if you have a program that needs to keep track of
thousands of small integers-more than will fit in available
memory in numeric form-then character strings may be the
answer.
Table 2. Function Key Codes
(None of these characters have graphic representations, nor
can they be given them. They can be typed only through the
CALL KEY statement, not in response to a string INPUT state-
ment, or within a program.)
Code Key
J FCTN 7(" AID")
2 None usable. The key definition associated with this code is
FCTN4, but in BASIC, hitting that key interrupts the program.
3 FCTN J("DELETE")
4 FCTN 2("INSERT")
5 None usable. The key definition associated with this code is
FCTN =, but hitting that key forces a machine reset and the
program in memory is lost.
6 FCTN 8("REDO")
7 FCTN 3("ERASE")
8 FCTN S(left arrow)
9 FCTN D(right arrow)
22
_ _ _ _ _ _ Getting Started

10 FCTN X(down arrow)


11 FCTN E(up arrow)
12 FCTN 6("PROC'D" )
13 ENTER
14 FCTN 5("BEGIN")
15 FCTN 9(" BACK")

Table J. ASCII Graphic Characters on the


TI.99/ 4A
(This table gives the numeric codes and gra ph ic representa-
tions; the key assignments are marked on the keyboard. The
graphic representations ca n be changed by the CA LL CHAR
sta tements but revert to their o rig inal form w hen th e program
stops runn ing.)
Code Graph ic Code Graphic
Representation Representation
32 (space) 53 5
33 ! 54 6
34 55 7
35 # 56 8
36 $ 57 9
37 % 58
38 & 59
39 60 <
40 61 ~
41 62 >
42 • 63 ?
43 + 64 @
44 , 65 A
45 - (minus) 66 B
46 67 C
47 / 68 D
48 o 69 E
49 1 70 F
50 2 71 G
51 3 72 H
52 4 73

23
Getting Started _ _ _ __

74 J 97 a
75 K 98 b
76 L 99 c
77 M 100 d
78 N 101 e
79 0 102 r
80 p 103 g
81 Q 104 h
82 R 105
83 5 106 j
84 T 107 k
85 U 108 1
86 V 109 m
87 W 110 n
88 X 111 0
89 Y 112 P
90 Z 113 q
91 [ 114
92 \ (back slash) 115 ,e
93 [ 116 t
94 117 u
95 _ (underline) 118 v
96 119 w

120 x
121 y
122 z
123 ,{
12. ,
125 )
126

Table 4. User-Definable Graphics Characters


These characters can be typed using the key combinations
listed and are acceptable in any context (that is, they can be
input using the CALL KEY or INPUT statements and can ap-
pear between quotes within a BASIC program).
Graphic representations can be given to these characters
with the CALL CHAR statement. Contrary to TI documenta-
tion, such representations, once assigned, will persist after the
program stops running.

2'
- - -_ _ Getting Started

Code Key Code Key


127 FCTN V 144 CTRL P
128 CTRL ,(comma) 145 CTRL Q
129 CTRL A 146 CTRL R
130 CTRL B 147 CTRL 5
131 CTRL C 148 CTRL T
132 CTRL 0 149 CTRL U
133 CTRL E 150 CTRL V
134 CTRL F 151 CTRL W
135 CTRL G 152 CTRL X
136 CTRL H 153 CTRL Y
137 CTRL 1 154 CTRL Z
138 CTRL J 155 CTRL .(period)
139 CTRL K 156 CTRL ;
140 CTRL L 157 CTRL ~
141 CTRL M 158 CTRL 8
142 CTRL N 159 CTRL 9
143 CTRL 0

Table 5. Characters with Key Assicnments But


No Graphic Representations
These characters are not mentioned in TI documentation. They
can be typed in any context (that is, in response to an INPUT
or CALL KEY statement or between quotes in a program), but
they have no graphic representations and cannot be given any.
Code Key Code Key
176 CTRL 0 188 FCTN 0 (wo)
177 CTRL 1 189 FCTN ;
178 CTRL 2 190 FCTN B
179 CTRL 3 191 FCTN H
180 CTRL 4 192 FCTN J
181 CTRL 5 193 FCTN K
182 CTRL 6 194 FCTN L
183 CTRL 7 195 FCTN M
184 FCTN , (comma) 196 FCrN N
185 FCTN . (period) 197 FCTN Q
186 FCTN / 198 FCTN Y
187 CTRL /

25
i
~
2
TI BASIC One..
Liners
- - - - - - Michael A. Covington

The BASIC DEF statement can become a powerful tool in


your programmer's bag of tricks. Here 's how to use it.
If you've been programming in BASIC for any time at all,
you've surely come across, and used, some of the built-in
functions that the language provides, such as INT, SIN, COS,
TAN, ATN, and LOG. But did you know that you can use the
DEF statement to create functions of your own? Defining your
own functions lets you type a complicated formula only once,
and it allows you to build complex functions out of simple
ones in a most efficient way.
Suppose, for instance, that your LOG function gives you
natural (base e) logarithms, and you want base 10 logarithms.
(If you're not sure which you've got, type PRINT LOG(IO)-if
the answer is I , you're in base 10, and if it's about 2.3026,
you're in base e.) You can convert base e logarithms to base
10 by dividing them by 2.302585093, so one of the options
open to you is obviously to write LOG(X)/2.302585093 (or
whatever) every time you need a base 10 log. But there's an
easier way.
Creatine Funct ions
To create your own function-let's call it LOGI0, though
some computers may insist that you name it something like
FNL- just include, early in your program, a statement like
this:
1~ DEF LOG1~(X)=LOG(X)/2.392S85~93

From then on, you'll be able to use the new function


WGlD to get base 10 logarithms. Try it out with a program
like this:
1~ DEF LOGII2I(X)=LOG(X)/2.39258512193
20 FOR 1=1 TO 1121 STEP 0.1
30 PRINT I.LOGI0(I)
40 NEXT I

29
The Basic8 _ _ _ _ __

and compare the results against a table of logarithms.


The DEF statement is different from most BASIC state-
ments in that it can't refer to variables. (The X in it-it could
be any variable name-is used only as a placeholder for the
number within the parentheses; it is completely separate from
any variable named X that you may use elsewhere in the pro-
gram.) You can refer only to numbers or other functions.
Some computers require that the name of the function be
three letters and that the first two be FN-FNA, FNB, FNL,
and so forth-although the TJ-99, and many other micro-
computers, allow you to name functions with the same type of
names you use for variables.
Sample One -Line rs
So that's how it's done. Now let's look at some practical
examples.
1. Base 10 logarithms. That's what we've just discussed.
For reference, here is the statement:
DEF LOGl~(X)=LOG(X)/2.3~2585093

(assuming your machine's WG function gives you base e


Jogs),
2. Base 2 logarithms. For a machine on which the WG
function gives base e logarithms, you can get base 2 loga-
rithms by using:
DEF L062(X)zLOG(X)/0.b931471806

If your machine's WG function gives base 10 logarithms,


you'll need to use DEF WG2(X) ~ WG(X)!O,3010299957
instead.
3. Degrees to radians. If X is the measure of an angle in de-
grees, then RAO(X) will be the same angle measured in radio
ans, if you define the following function:
DEF RAD(X)=X/57.29577951

4. Radians to degrees. The opposite function, converting X


in radians to OEG(X) in degrees, is:
DEF DEG(X) =X t57_29577951

5. Arcsine (in radians). The following definition will give


you the arcsine function (which is not usually provided in im·
plementations of BASIC, although the arctangent is).

30
_ _ _ _ _ _ The Basics

DEF ASN(X);2*ATN(X/Cl+SQR(1 - XA 2»)

If you look through a table of trigonometric identities, you


may find an apparently equivalent, but simpler, fonnula that
would lead to the statement DEF ASN(X) ~ ATN(X/SQR
(1 - X~ 2». But note that this version won 't do ASN(l) correctly
(it will try to divide by zero). Hence the first version is
preferable.
6. Arccosine (in radians). If you have the arcsine function,
you can get the arccosine, as follows:
DEF ACS(X) = 1.570796 3 27 - ASN(X)

Remember that the OEF statement for ASN must precede the
DEF statement for ACS (you can 't refer to a function until
you've defined it).
7. Rounding to a particular number of decimal places. Where
n stands for the number of decimal places you want, use the
definition:
DEF ROU(X)=INT«(10 A N)'X)+0.5)/(10 A N)

Note that you must substitute a number for n; in most im ~


plementations, n cannot be a variable. Hence, if you want to
round to three decimal places, your statement will read DEF
ROU(X) ~ INT«(10'3)·X)+O . 5)/(10'3). The number of decimal
places can be negative, of course; if you want to round to the
nearest 20, ask for - 1 decimal place, and if you want to
round to the nearest 1000, ask for -3 decimal places.
8. Rounding to a particular number of significant digits.
Often, you' ll find that the most convenient type of rounding
involves coming up with a particular number of significant
digits rather than a particular number of decimal places. You
can accomplish this with the definition:
DEF RSF1(X) = (N - l) - INT(LOG10(X»
DEF RSF(X) = INT( «10 A RSFl(X»tX)+0.S)/(10 A RSF
1 (X»

Here the definition is so complex that it is best done in two


stages: first we define RSF1 , which is a function used in-
ternally in RSF, and then we define RSF, which is the function
we actually use. The character n stands for the number of
significant digits you want; as before, you must substitute a
number for it when typing the definition into the computer.

31
The Basics _ _ _ _ __

A word of warning: RSF (with its subsidiary calls to RSFI ,


which in tum calls LOGIO) can take quite a bit of time to exe~
cute (about half a second of realtime on the TI~99).
9. Sexagesimal output: minutes. Our practice of expressing
time in hours, minutes, and seconds, and angles in degrees,
minutes, and seconds, is a remnant of an ancient Babylonian
base~60 (sexagesimal) number system. Often, in a computer
program dealing with time or with angles, it's necessary to ex~
press the output in terms of units, minutes, and seconds. The
units are derived by taking INT(X); thus the units part of 2.5
hours = INT(2.S) = 2 hours. Here is a function that gives the
minutes part:
DEF MNT(X):INT(bet(X - INT(X»)

the INT of that.


10. Sexagesimal output: seconds. The seconds part of the
value, in tum, is given by:
DEF SCD(X):b~t(bet(X-INT(X»- MNT (X»

That is, we subtract the integer part and the minutes; what's
left gets multiplied by 60 twice.
The sexagesimal output functions can be tested by means
of a program such as the following:
1~ DEF MNT(X ):I NT(60t(X - INT<X»)
20 DEF SCO(X):b0t(b0t(X-INT(X) )-MNT(X»
3~ FOR H =0 TO 2 STEP 0.01
40 PRINT
50 PRINT H.~HOUR S"
b~ PRINT INT(H),MNT(H) ,SCO( H)
70 NEXT H
From this we learn, for example, that 0.01 of an hour is 36
seconds, and that 0.5 of an hour is 30 minutes. (If your com-
puter uses binary, rather than BCD or Radix-IOO, internal
representations of numbers, you may get odd errors due to
rounding or lack of it. The solution would be to round the
number of hours to some reasonably small number of decimal
places before invoking the conversions, and perhaps to insert
some rounding in the definitions of MNT and SCD
themselves.)
InCidentally, for sexagesimal input, you don't need any
special functions, only a bit of multiplication. For instance, the
statements:
32
- _ _ _ _ _ The Basics

10 PRINT -TYPE HOURS, MINUTES, SECONDS·


20 INPUT H.M,S
30 H=H+M/60+S/3600
will give you (as H) the number of hours expressed as a
decimal.
11. Modulo 12 arithmetic. In dealing with hours, you'll
often want to reduce numbers to modulo 12. For instance, if
it's 11 a.m., then you can calculate the time four hours later
by adding 11 + 4 (which gives you 15) and then taking the
resulting modulo 12. The function definition is:
DEF MOD1 2 (X)=12*(X / 12 - INTIX / 1 2 »
(unless, of course, your computer has a built-in MOD function,
which is even simpler to use). This particular function is likely
to be bothered by rounding and truncation errors. On the Tl-
99, I get accurate results for numbers under 1000 or so, hut
larger numbers give slightly erroneous answers.
12. Modul o 60 arithmetic. The same fun ction, giving mod·
ulo 60 answers (for dealing with minutes and seconds), is:
DEF HODb0(X):60*(X / b0 - INT(X / b0»
(as if you couldn't have guessed). The following program
starts with a time expressed as H hours M minutes, and adds
Ml minutes:
10 DE F HOD1 2( X)= 1 2 * (X/ 1 2 - INT (X/ 1 211
20 DE F HOD 60( X)=60 t ( X/60 - INT (X!60»
30 INPUT H , H
40 INPUT Hi
50 M = MOD 6 0(M~Hl )
60 H = H~INT(Mi /6 0 )
70 PRINT H.M
Line 50 adds the right number to the minutes part, and line 60
adds to the hours part if necessary.

33
CALL KEY Hints
- - - - - Roger Lathrop

CALL KEY is often used in programs, but there are a num-


ber of ways to use CALL KEY which are rarely seen and easy
to use.
If you use a TI-99J 4A and do your own programming you al-
ready know how to use the CALL KEY routine. In fact you
probably use it in just about all your programs. However there
is something they don't tell you in the user's manual that you
may find very useful. First let's look at a typical use of CALL
KEY, then let's see how it can be improved:
1~ PRINT N KEY R TO REPEAT KEY E TO END "
20 CALL KEY(S,A,B)
30 IF A=b9 THEN 50
4121 IF A=82 THEN 10 ELSE 20
5121 END

This kind of program is often used to get information


from the user: "Do you want to play another game Y or N?" It
works fine as long as uppercase letters are entered. You know
why it won't work with lowercase letters so you can quickly
correct your mistake and go on. It's just a minor nuisance.
Now change line 20 to read:
CALL KEY(3,A,B)
With this simple change you have eliminated the problem
altogether. Using a three as the first argument returns upper-
case characters only, so there is no chance of error. You may
remember reading this in the users manual, maybe you even
use it sometimes. But now let's go a step further, into some-
thing they don't tell you in the manual. Try this simple
program:
10 INPUT A$
20 PRINT A$
30 CALL KEY(3.A,B}
40
50
60
PRINT .$
INPUT .$
GOTO .\0

34
_ _ _ _ _ _ The Basics

Run this program using lowercase letters (it doesn't matter


what you enter). You will see that your first input will be
lowercase, just as you typed it, but all the following entries
will be returned as uppercase characters. Line 30 puts the
computer in key unit three, and it will stay in that mode even
when it performs an INPUT statement. Now add this line, and
run it again:
55 CALL KEY(S,A,B)

You are now switching back and forth between key units three
and five. Key unit five is the mode the computer is in nor-
mally. You can use this to ask a question, such as YES or NO,
and have it come back as uppercase to simplify verification, no
matter how it is entered. You may then switch back to key
unit five to enter information such as names, where both upper-
and lowercase letters may be desired. Note that control keys
are inactive in key unit three, and that numeric and punctua -
tion keys work normally with the SHIFT key.
If you need to switch back and forth often in a program
you may wish to make the CALL KEY statements a separate
subroutine. You can use dummy CALL KEYs, as we did in
lines 30 and 55, or you can use an active CALL KEY using the
key unit you wish. Any following INPUT statements will react
accordingly. Once you have the keyboard mapped the way
you wish, any following CALL KEYs may use a key unit of
zero. Key unit zero will not change the keyboard mapping.
Take the time to learn this simple programming trick. It's
easy to learn, will help make your programs easier to run, and
in many cases can make them simpler to write and debug.

35
All Sorts of BASIC
Sorts
- - - - - C. Regena

One of the functions of a computer is to organize data. You


may want to alphabetize lists, arrange events by date, or list
a class in order by test scores. There are a variety of sort
routines or algorithms to arrange data.
Computer programmers and analysts often enjoy looking at
sort routines and comparing speed and efficiency. Usually the
amount of time it takes a computer to sort depends on how
many items are in the list and how out-of-order the items are.
Different computers vary in speed also. (Although the Tl-
99/4A computer is slower than other microcomputers in
PRINTing or LiSting, it's just as fast or faster in calculations
and comparisons.)
Here are four different sort routines written in BASIC for
you to try, and to implement in your own programs. They will
work on a TI with regular or Extended BASIC.
In the listings, line 100 tells the type of sort being used.
Lines 110-170 randomly choose 50 integers from 1 to 100. Or·
dinarily, you would INPUT, READ, or calculate the numbers
used. The actual sorting starts at line 200. Lines 500 to the end
print the final sorted list of numbers in the example.
Bubble Sort
The Bubble Sort (or simple interchange sort) is probably the
most common and easy to understand sort. It's fine for small
numbers of items or for a list of items that is not much out of
order. The program compares each number to the next num·
ber and exchanges numbers where necessary.
If one switch has been made during a pass through all the
numbers, the loop of comparisons starts over. In this example,
if the 50 numbers happened to be in exact opposite order, the
maximum number of passes would be necessary, and the pro·
cess would take longer than if only a few numbers were out of
place. For larger numbers of items, this sort can seem to take
forever.
36
- - -_ _ _ The Basics

Shell Sort
The Shell Sort is considerably faster than the Bubble Sort. In
general, for a random order of 50 numbers, the shell sort is
about two or three times as fast as the Bubble Sort. The Shell
Sort speeds up execution because the number of comparisons
that need to be made is reduced.
In an array of N numbers, it first determines B so that
2B< N<2B +l and then the variable B is initialized to 28+1, The
loop varies the counter I from 1 to N - B. First, it checks if
A(I)<A(J + B). If so, it increments I and continues with the
comparisons. If not, it exchanges A(I) and A(I + B) and changes
the subscript.
When I reaches the value of N, it reduces B by a factor of
two and starts the loop again. When B = 0 the sort is com-
plete. I've used a couple of extra variables in the example for
darity.
Sort C
The third kind of sort routine offered here is also faster than
the Bubble Sort if the numbers are quite mixed up. The pro-
gram goes through all the numbers and places the minimum
value in the first spot of the array. The loop keeps finding the
minimum of the numbers remaining and replaces it in order.
Sort D
This sort is similar to the previous one, except that with each
pass through the numbers, both the minimum and the maxi-
mum numbers are found and placed at the appropriate end
spots.
The way these sorts are listed, the given numbers will be
arranged in ascending order. To change to descending order,
simply exchange the less than or greater than signs in the sort
comparisons.
If you are alphabetizing, the variable terms will be string
variables, such as A$(l).
You may have several items which need to be associated
as they are sorted. For example, suppose you have names and
scores to be arranged by score. The names and scores are first
arranged as N$(I), 5(1); N$(2), 5(2); etc. In the interchange
you would need to sort the 5 values, and then switch both
terms, like this:

37
The Basics ______

55=5(1)
NNS=NS(I)
S(IJ::S(J+1)
NS (J)=NS C1+1)
S(I+1>=SS
Nt: CI +1 ) =NNS

Program I . BASIC Bubble Sort


1101113 REM TI BASIC BUBBLE SORT
l I e DIM A(50)
121011 FOR 1=1 TO 51011
1313 RANDOMIZE
141011 ACI)=INTCRND'1101I0+1)
151011 PRINT A(I),
161011 NEXT I
171011 PRINT:
210110 L IM = 49
210 sw=e
220 FOR 1 = 1 TO LIM
231011 IF ACI) < =AC!+l)THEN 291011
241011 AA=A(I)
2 51011 ACI)=ACl+l)
261011 ACI+i)::AA
2713 S W::1
281011 LI M=I
291011 NEXT I
3 101113 IF SW=1 THEN 2113
510111011 FOR 1 = 1 TO 513
511011 PRINT ACI);
5213 NEXT I
530 END

P r ogram 2. BASIC Shell Sort


1130 REM TJ BASIC SHELL SORT
110 DIM A(50)
121011 FOR 1=1 TO 50
130 RANDOMIZE
141011 ACI)=INTCRND*11iJ0+1)
1513 PRINT A(ll;
160 NEXT I
170 PRINT
210111011 B=1
211011 8=2*8
220 IF B <~ S0 THEN 210
230 8=INT(8/2)
241011 IF 8=13 THEN see
251011 FOR 1=1 TO 51011-8

38
______• The Basics

2 •• e"'I
27. D:C +e
28. IF A(C) {= ACDITHEN 3 ••
2 •• AA:A(C)
3 •• A(C)=A(O)
31. A(D):::AA
32. CzC - B
33. IF C>. THEN 27.
3 •• NEXT I
35. GOTO 23.
5 •• FOR t '" 1 TO 5.
5 ' . PRINT A (1) ;
52. NEXT I
53. END

Procram 3. BASIC Sort C


11219 REH{ 3 SPACES}TI BASIC S ORT C
119 DtM A (50)
1 29 N:S0
13 9 FOR 1 =1 TO N
1 35 RANDOMIZE
149 A(I) = INT( RND *100.1)
1 59 PRINT A(I);
169 NEX T 1
179 PRINT:
21219 M- A(I)
2 19 IM = l
22 9 FOR 1=2 TO N
239 IF A(I) { H THEN 269
2 40 M=A(I)
25 9 IM:::I
26 9 NEXT I
279 AA = A(N)
28 9 A(N) = A(lM)
299 A (1 M ) ::AA
3 121121 N'"" N - l
319 IF N ) l THEN 2 99
5 1219 FOR 1 = 1 TO 59
SUI PRINT A(I):
529 NE X T I
5 39 END

Procram 4 . BASIC Sort D


11219 REM{4 SPACES } TI BASIC SORT 0
110 DIM A(50)
129 N ::: 50
1 3 9 FOR 1 = 1 TO N

39
The Basics ______•

13 5 RANDOHIZE
140 A ( I) = INT(RND*100+1)
15121 PR INT ACI ) :
16 0 NEXT I
17 0 PRINT :
2QlB 5:z 1
2 1B HN ::: A( S)
220 IMIN:::S
230 H X= HN
24B IMAX=5
250 FOR 1 =5 TO N
260 I F ACI) (= MX THEN 299
27B MX:::A( I)
28 0 IMA X=I
29 0 IF ACI»MN THEN 320
30 0 MN - ACI )
3 1B IMIN = I
320 NEXT I
330 IF IMIN () N THEN 350
3 4121 JMIN:::IMAX
35 0 AA =AC N )
360 ACN)=ACIMAX)
37 0 A( IMAX )=AA
380 N"" N- I
390 AA = AC S)
40121 A(S)=ACIHIN)
410 A(IMIN)=AA
420 5 - 5 +1
4 30 IF N ) S THEN 2 10
500 FOR 1 = 1 TO 50
5 10 PR INT A<I);
520 NEXT I
530 END

40
Searching
Algorithms
- - - - - Doug Hapeman

Searching through data using BASIC call be very slow. Some


searching algorithms can be much faster than others.

The word algorithm is derived from AI Khu warizmi, a ninth·


century Arabic mathematician. He was interested in solving
certain problems in arithmetic, and devised a number of meth-
ods for doing so. These methods were presented as a list of
specified instructions, and eventually his name became at-
tached to such methods.
An algorithm is simply a formula to use for getting done
what you want to accomplish. It's a sequence of operations that,
when applied to given information, will produce a desired result.
Algorithms are used unknowingly everyday. For instance, the
instruction sheet for assembling your child's new bicycle,
directions for opening a combination lock, kitchen recipes for
cooking, the rules for playing a game, and road maps are all
examples of algorithms. An algorithm, then, is a precisely de-
scribed set of directions to follow in order to accomplish a
stated task. The algOrithms we have in mind are the set of
procedures that can be used in searching through data lists.
In many program applications you will be storing a wide
variety of information, from inventory management, member-
ship and address files, genealogical records, meteorological
data-the list is endless! Most lists are stored in a data struc-
ture called a one-dimensional array, or subscripted variable.
Storing Information
An array is a block of storage locations in computer memory
which is reserved for a collection of variables. Each variable in
the list is called an element of the array. TI BASIC permits
you to use one-, two-, or three-dimensional arrays, in addition
to simple variables.
If you assign a numeric value or string expression to a
simple variable, then a specific memory location with an ad-
dress that is unique is set aside. For example, LET A=12; the
41
The Basics _ _ _ _ __

value of 12 is placed in a memory location and its address is


the variable A. If you ask the computer to PRINT A, it will
print 12, the value assigned to it. If you assign a second value
to A, LET A = 100, the first value is then forgotten. A simple
-
variable can hold only one value or expression at a time.
An array brings new dimensions to the variable. In an ar-
ray the variable is subscripted, A(J)= 12, and you may assign
many values or expressions to it. TI BASIC permits 11 ele-
ments without any special dimensioning. If the number of ele-
ments exceeds 11 , then extra room must be allocated with the
use of the DIMension statement. The array then sets aside a
big enough block of memory locations for the number of ele-
ments you set in the DIM statement.
What is in the space set aside for these elements? Try
these two short programs:
111'10 FOR 1=11'1 TO Ie
1111'1 PRINT "A(";I; " )= H;A (I)
1 20 NEXT I

100 FOR 1=11'1 TO 10


110 PRINT "A$(";I;H)_";A$(I)
120 NEXT 1

Notice that each element in the string array is a null string


and each element in a numeric array is a zero until you re-
place them with values during the program. When the array is
accessed, each element within the block must be given an ad-
dress that is unique. For example, A(1)= 12; A(2)=100. The A
is the name of the array, and the specific address is the
subscripted number given to the array A. As an illustration of
a one-dimensional string array, let's set up an array called
NAME$ that will hold the names of people. To INPUT a
number of names and fill in the array, you can key in the
following code:
100 CALL CLEAR
110 1= 0
120 INPUT MENTER THE NAHES; M;NA HE$(I)
130 1=1+1
140 GOTO 1 20
This program will fill array NAME$ until 11 names are
entered and then end with an ERROR MESSAGE"BAD SUB-
SCRIPT, because we did not DIMension a larger array.

42
_ _ _ _ _ _ The Basics

The one-dimensional array is often called a list, and has


only one integer value following its name A(6). The two-
dimensional array is referred to as a table, or matrix, because it
can represent any two-dimensional condition, such as charts,
graphs, or any tabular display that uses rows and columns. It
is described with two integer values which define the number
of rows and columns A(12,3). The three-dimensional array has
three integer values defining its characteristics A(S,2,1l).

Comparing Using ASCII Codes


A very common problem in working with lists stored in one-
d imensional arrays is the need to search the array to access a
particular item or to determine whether it is in the array.
Some of the slowest procedures in BASIC (and other computer
languages) are searching and sorting, because the process in-
volves time-consuming comparisons, whether string or
numeric.
In order to understand how strings are processed, some
background abou t ASCII character codes is necessary. ASCII
stands for American Standard Code for Information Inter-
change, and it is an established standard for computers. There
are 128 different codes defined in the ASCII standard to repre-
sent alphabetic, numeric, special characters, and control codes
(see " All About the Character Set" elsewhere in this book).
The way the ASClI codes are ordered-the space (32),
punctuation, numbers and other special characters (33-64),
uppercase alphabet (65-90), more special characters (91-96),
and then the lowercase alphabet (97-122)-makes it possible
to compare strings by using the same relational operators that
are used to compare numbers. The computer compares two
strings by comparing one character at a time, moving in a left-
to-right direction until a difference is found. Here are some
examples:
Is JORDEN greater than JORDAN?
jORDEN >jOR DAN?
74 79 82 68 69 78 74 79 82 58 65 78
69 is greater than 65, therefore JORDEN is greater than JORDAN.
Is GREENE equal to GREEN?
GREENE~GREEN ?
71 82 69 69 78 69 71 82 69 69 78 32
69 is greater than 32, so GREENE is not equal to GREEN.
(Note that 32 is ASCII for a space.

43
The Basics _ _ _ _ __

In data processing most of the time you will be working


with alphabetically ordered lists of information. There are
times though when you will have to work with unordered
lists. The program listing at the end of the article will dem-
onstrate how much faster a list can be searched when the
information is ordered (alphabetized).
The Linear Search
When processing unordered data the most common algorithm
is the linear search. The linear search takes the item you are
searching for and compares it with each succeeding item in
the list until it finds a match (this process can be very time
consuming). If the item is not in the list, the search cannot de-
tect it without passing through the entire array. Only then can
it verify that the item is not present. Line 340, IF C$ = B$(1)
THEN 660, where C$ is the item you are searching, is com-
pared to each element in the array until it finds the item being
searched .
The time required to search unordered data varies
depending on the length of the list and where exactly in the
list the item being searched for is located.
If you want to reduce the searching time, the first step
would be to order the list. How do you get an ordered list?
You could INPUT all the information alphabetically when
using the given application program, but that would not be
feasible or practical. Much easier would be to include a sorting
routine in the program. A sorting routine will alphabetize or
arrange numerics in ascending or descending order (see" All
Sorts of BASIC Sorts" elsewhere in this book).
The Alphabetical/ Linear Search
How can an ordered list be searched efficiently? Once the list
is alphabetized it immediately becomes easier to process,
particularly when searching for items that are not in the list.
In the case of the unordered list, the entire list had to be
searched to determine that an item was not there. For a list of
one hundred items that meant one hundred comparisons. But
when the list is ordered, the search only needs to move for-
ward until an item is found whose value is greater than the
item being searched. This is done in line 400, IF C$=B$(I)
THEN 660, and line 410, IF C$<B$(I) THEN 640. These two
lines make comparisons with each item in the array until the
item is located or an item of greater value is detected.
44
_ _ _ _ _ _ The Basics

The Binary Search


The third search routine in the program listing is called a bi-
nary search and is a very efficient search for long lists of
ordered data. It is called binary not because it uses machine
code, hut because the maximum number of comparisons that it
needs to make is represented by the power of 2 that results in
a number greater than the number of items in the list. For ex-
ample, in the program listing, there are 100 names taken from
the phone book. 2f7 is the next power of 2 larger than 100;
therefore, the binary search will take a maximum of seven
comparisons to locate the item in the list.
. The first comparison is made with the middle item in the
list. If the item being searched is greater than that item, then
the upper half of the list becomes the new list. The second
comparison is then made with the middle item of the upper
section . This procedure of dividing the list in half is repeated
until the item is located.
Here is an example of how it works. Suppose you want to
locate the name " Usher" from the data in the program listing.
There are 100 items in the list.
1. Comparison at item 50.
Usher>Jones, so the new range is 50 to 100.
2. Comparison at item INT«100 - 50)/2 + .5) + 50 ~ 75.
Usher> Peverill, so the new range is 75 to 100.
3. Comparison at item INT«IOO - 75)/ 2 + .5)+75 ~ 88.
Usher> Stewart, so the new range is 88 to 100.
4. Comparison at item INT«100 - 88)/2 + .5) + 88 ~ 94.
Usher < Ward, so the new range is 88 to 94.
5. Comparison at item INT«94 - 88)/ 2+ .5) + 88 ~ 9l.
Usher> Thomas, so the new range is 91 to 94.
6. Comparison at item INT«94 - 91)/2 + .5 + 91 ~ 93.
Usher< Vickruck, so the new range is 91 to 93.
7. Comparison at item INT«93 - 91)/2+.5)+91 ~ 92.
Usher = Usher, so GOTO 660.
Either of the linear searches would have required 92
comparisons to locate Usher. You can see, therefore, that the
binary search is quite powerful. You will discover that as lists
become longer and longer, the binary search algorithm be~
comes much more powerful and efficient than the linear
methods.

45
The Basics _ _ _ _ __

Explanation of the Program


100-220 Read and Display Data
230- 300 Print Main Menu
310-360 Linear Search Routine
370-430 Alphabetical/Linear Search Routine
440-620 Binary Search Routine
630-760 Common Print Routines
770-840 Data Statements

Searching Algorithms
100 RE M tt SEARCHING ALGORITH MStt
120 DIM B$( 1 00)
130 N= 1 00
14 0 RE M t t READ AND DISPLAY DATA t t
150 CALL CLEAR
160 FOR 1 =1 TO N
170 READ A$
180 B$(I)=A$
190 PRINT B$(]),
2{11{11 NEXT I
210 FOR T=1 TO 4 00
220 NEXT T
230 RE M ttPRI NT MAIN ME NU"
240 CALL CLEAR
250 PRIN T " " SEARCHING ALGORITHMS t ' " :
: "PRESS{3 SPACES}FOR" : : " 1 LI N
EAR SEARCH ":
260 PRINT" 2 = ALPHA/LINEAR SEARCH": :"
3 BINARY SEARCH": :" 4 FINISH
SESSION":
270 CALL KEY(0,KEY,S)
280 IF KEY ( 49 THE N 270
290 IF KEY ) 52 THEN 270
300 IF KEY=S2 THEN 750 ELSE 700
310 RE M t tLINEAR SEARCH"
320 FOR 1=1 TO N
330 PR IN T I;
340 IF C$=B$(I)THEN 660
350 NEXT I
360 GOTO 640
370 REM t ' ALPHABETICAL LINEAR SEARCH"
380 FOR 1=1 TO N
390 PR IN T I;
4 00 IF C$=B$(I)THEN 660
41 0 IF C$ ( B$(I) T HEN 640
420 NEXT I
430 GOTO 640

46
_ _ _ _ _ _ The Basics

440 REM _'BINARY SEARCH ••


4513 LOW =0
4613 HIGH = N
471i1 K=t
4813 X=INT(N/2+.5)
490 X=INT(X/2+.5)
5"'0 K=K+l
'510 IF X> t THEN 490
520 1=0
530 FOR J=l TO K
'54121 1 = 1+1
5'50 X=INT«HIGH-LDW)/2+.'5)+LOW
'569 PRINT X;
570 IF C$=B$(X)THEN 6613
S8e IF C$ ( B$(X)THEN 610
59@ LOW=X
60121 GOTO 620
610 HIGH =X
620 NEXT J
630 REM _'GENERAL PRINT ROUTINES ••
640 PRINT: :"SORRY.";C$:"IS NOT IN THE
LIST."
650 GOTO 67121
660 PRINT : : C$; ", ": "FOUND IN"; I; "CO MPAR
ISONS."
670 PRINT: : "'PRESS ANY KEY TO CONTINue."
680 CALL KEY(0.KEY.S)
6913 IF 5=13 THEN 6813 ELSE 240
7013 CALL CLEAR
7113 PRINT "THE NAME YOU ARE SEARCHING:":
720' INPUT C$
730 PRINT: :"COMPARING WITH NAME #";
740 ON KEY-48 GOTO 320,3 813,4513.750
750 CALL CLEAR
760 PRINT "(6 SPACES}HAVE A NICE OAY!~:

76'5 STOP
770 DATA ACKER,AINSLIE,ALLEN,ANDERSON,ARHSTR
DNG,BANCROFT,BAULD,BEATON,BEATTIE,BLACK,
BOWER,BROOKS,BROWN
780 DATA BURKE,CHANG,CHRISTIAN~CHU,COCHRANE,
CODNER,COLLIN5,COHEAU,COOK,COOPER,COX,DA
RROW,DAVIS,DAY
790 DATA OELONG.DICKIE,DOGGETT~DOUGLAS,EBBET
T ,E LLIS,EMBREE,EULOTH,FIELD,FIFIELD,FDY,
GAMMON,GREENE,HAPEMAN
B00 DATA HARPELL,HARTLIN,HILL,HUBLEY,HUSKINS
,JAMES,JAMIESON,JDHNSON,JONES,KENDALL,KE
TCHAM,KILLAWEE,KILLDRAN

47
The Basics ______

810 DATA LAHFORTH,LANGILLE,LERUE,LLOY.LYSEN.


MACDONALD,MACFADYEN,HACFAWN,MACLACHLAN,M
AILLET,MARSHALL,MASKELL
820 DATA MATTHEWS.MCCONNELL,MCDOWELL,MERCER.
MOULTON,NAGLE.NAPER,NICKERSON,PEVERILL,P
RESTON,PRICE,PROCTOR,RODDAM
830 DATA RONALDS,RUSSELL,SCHOEMAKER,SCHOFIEL
D,SHERIDAN,SMITH,STARRATT,STEVENS,STEWAR
T,SYKES,TAYLOR,THOHAS
840 DATA USHER,VICKRUCK,WARD,WEBB,WHITE,WHIT
ING,WJLBUR,WINTER,ZACHARY

48
Transferring
Variables in TI
Extended BASIC
- - - - - - Patrick Parrish

Variables can be passed from one program to another in most


microcomputers by POKEing them into memory. But on the
Tl-99 j 4A, standard PEEKs and POKEs can't be used. Here's
a way to transfer variables in TI Extended BASIC that uses
redefined characters.
The TI-99/4A has outstanding graphic capabilities. With its
subprogram CHAR, you can readily redefine characters within
the standard ASCII character set (character codes 32-1 26). Or,
you can create additional characters using codes 127-159
(codes 127- 143 in Extended BASIC).
But there's a potentially more powerful application for the
CHAR subprogram. Variable data can be passed from one pro-
gram to another using CHAR and CHARPAT, an Extended
BAS IC subprogram. So, if you use up the Tl's memory, it's
now possible to write a program in two parts and send vari-
ables to a second program. Even the user's name could be
among the variables transferred. But first let's take a brief look
at the traditional use of the CHAR subprogram.
Deflnlne Characters
On the TI-99/4A, characters are defined by a 16-character
hexadecimal string expression known as a pattern-identifier.
Pattern-identifiers are dot codes for depicting each cha racter in
an eigh t by eight grid (see the TI-99/4A User's Reference Guide
pp. 11-76 through 1I-79 for more).
Changing the pattern-identifier in memory for a character
enables you to define that character to suit yourself. For ex-
ample, suppose you wanted to represent the ASC II character
65 (normally, an A) as a box in a program. You could do this
with the CHAR subprogram as:
CALL CHAR(bS,NFFFFC3C3C3C3FFFF " )

49
The Basics _ _ _ _ __

Within the parentheses following CALL CHAR is the ASCII


character number (65) and the new pattern-identifier for the
character ("FFFFC3C3C3C3FFFF"). By redefining characters in
this manner, you can produce figures which greatly enhance
and enliven screen displays in your programs.
Protected M emory
CHAR, within a program, can also be used to store variable
data in the form of a pattern-identifier. Once stored, a second
program can fetch this variable data with the CHARPAT
subprogram.
CHARPAT is the converse of CHAR. Rather than specify-
ing the pattern-identifier for an ASCII character, it returns
from memory the pattern-identifier assigned to a particular
character. For instance, CALL CHARPAT (65,A$) returns the
pattern -identifier for ASCII character 65 as A$.
When you interrupt a TI program using redefined char-
acters, certain character codes retain their redefined con-
figuration while others return to their standard definitions. If
you haven't seen this before, enter and run the following
program:
11210 CALL CLEAR
11121 CALL CHARCI26."FFFFFFFFFFFFFFFF")
120 CALL CHAR(127."FFFFC3C3C3C3FFFF")
1 3 121 PRINT CHRS(126).CHRS<127)
14121 FOR 1=1 TO 11211210
15~ NEXT 1

Here, we redefined character 126 (it's normally a tilde) in


line 110 as a solid block and defined character 127 in line 120
as a hollow box. Next, we PRINTed both characters in line 130.
When you run this program, the two characters we've de-
fined will appear on the screen momentarily. Once the pro-
gram ends, the block character will change to a tilde while the
box character remains.
Why does this happen? When a program is interrupted,
only the standard character set on the TI (ASCII characters
32-126) is restored. Pattern -identifier data stored in ROM for
characters 32-126 is copied to RAM (this process also occurs
when the TI is first powered up or reset). As a result, ASCII
character 126, seen as a block during program execution, be-
comes a tilde when our program ends. But character 127 (the
box) retains its redefined shape.
50
_ _ _ _ _ _ The Basics

Indeed, all characters above 127 will keep their defined


form even if another program is run (provided these characters
are not defined differently by this subsequent program).
Normally, the RUN command clears all variables in mem -
ory-both numeric and string. That is, all numeric variables
become zero while string variables are set to nulL So, if you
chain to another program with RUN "device. program-name",
the variables will be cleared. The fa ct that certain character
codes remain intact even after a RUN will enable us to pass
variables between programs by stori ng them as pattern -
identifiers.
Storing Variable Data
The variable data that we wish to pass must be in hexadecimal
form so that it can be stored as a pattern-identifier. Once it
has been converted to hexadecimal form, it can be placed in
the character codes beginning at 127 for retrieval by a second
program.
Program 1 is a sample program which demonstrates the
necessary routines for storing variable data in character codes.
In this program, variables to be passed are generated in the
main portion of the program (lines 100-798). In this case,
we've simply assigned values to the three variables we want
to transfer (line 500).
Two of these variables are numeric (X and Y) while the
third is a string variable (NAME$). In line 800, the numeric
variables are converted to string variables, and then all three
variables are stored in the array D$. (Note in line 100 that
we've DIMensioned D$ for the number of variables we intend
to pass.) In line 900, we concatenate all values of D$O and
store them in E$.
Seventeen character codes (codes 127-143) are available
for variable storage. Each pattern-identifier is 16 hexadecimal
characters in length, so we have room to store 272 (17 X 16)
hexadecimal characters. Since 2 hexadecimal digits will be re-
quired to encode each character of E$, the length of E$ is lim-
ited to 136 characters (actually, 135 characters because the end
of E$ is marked with an additional CHR$(255) in line 930).
After each D$O is concatenated to E$ and CHR$(255) is
added as a separator between variables, a check of E$'s length
is made in line 910. If the last variable added to E$ causes it
to exceed 135 characters in length, the program will terminate,

51
The Basics ______

and the computer will display the number of variables you are
allowed to transfer.
As mentioned, pattern-identifiers must be stored as hexa -
decimal code. Our best approach here is to represent each
character of E$ by its ASCII value before converting it to
hexadecimal.
Lines 1000 to 1020 contain routines for doing this. In line
1010, each character of E$ is converted to its ASCII equiva-
lent. These ASCII values are, in turn, converted to a hexa-
decimal string expression, M1$, in line 1020.
Once M1$ reaches a length of 16 characters (or the end of
E$ is reached), it is assigned as a pattern-identifier (line 1025).
At this point, if MI$ is less than 16 characters long, TI Ex-
tended BASIC automatically fills the remaining characters in
the pattern-identifier with zeros.
Recovering Variable Data
Variable data stored with Program 1 can be recovered with
Program 2. Both programs serve as examples.
Again, you would place the main portion of your program
in lines 100-798. Be sure to DIMension 0$0 and DO in line
100 for the number of variables you stored with Program 1.
Lines 800 to 980 contain routines for recalling each vari-
able. In line 800, each pattern-identifier used to store data is
assigned as A$ using CHARPAT. In line 910, if the end of
variable data is detected as signified by "FFFF" (sequential
CHR$(255)'s), a flag variable FL is set to I.
Line 920 looks for the delimiter "FF" (CHR$(255» follow-
ing each variable 0$. If a delimiter is seen, the length of the
prior 0$0 is calculated as DO.
Two characters of A$ are set equal to M$ in line 930. The
two-digit hexadecimal number contained in M$ is sub-
sequently converted to a decimal value in line 940. These
decimal values are then converted to CHR$s in line 960 and
stored as F$.
In line 1000, F$ is divided into D$()'s using lengths DO.
As before, D$() represents the string form of each variable.
Finally, as a demonstration, our original variables are
PRINTed in line 1030. Of course, this may not be necessary in
your program.

52
______• The Basics

Program I. Passing Variables


10 REM PROGRAM 1 (VAR I ABLE OR I GIN PROGRAM)
99 REM IE . , LINES 100 -798 :: MAIN PORTION OF
VOUR PROGRAM
100 OPTION BASE J ._ DIM 0$(3):: REM DIMENSI
ON 0$ FOR NUMBER OF VARIABLES TO TRANSFE
R
499 REM VARIABLES IN LINE 500 ARE ASSIGNED W
ITHJN THE MAIN PROGRAM
50fc:l X=100 :: '1'=-'5.05 : : NAHE'5="JEFF TUDOR"
799 REM DEFINE S TRING AND NUMERIC VARIABLES
AS 0'5 ()
800 O$(l)=STR$(X):: D$(2'=STR'5(Y): : D'5( 3 )::HA
MEO
810 HEX$ = "012 3 45b789ABCDEF"
899 REM CONCATENATE D~()'S TO E$ AND DELIMIT
WITH CHRS(2'55)
900 E$="" :: FOR 1 - 1 TO 3 :: ES-E$~D$(I)~CHR
$ (25 5)
909 REM CHECK TO MAKE SURE LENGTH OF E$ DOES
NOT EXCEED 136(272/2)
910 I F LEN(E$» 1 3'5 THEN E$=SEG$(E$,l,LEN(E$)
- LENCDS(I»-I):: PRINT "ONLY ";1-1 :: PR
tNT "VARIABLES CAN BE TRANSFERRED . " :: 5
TOP
92@ NEXT 1
929 REM PLACE AOOITIONAL CHR$(255) AT END OF

93121 E$=E$~CHR$(255)
999 REM CONVERT E$ TO ASC'S AND THEN TO HEX
- CO NCATENATE EVERY 16 AS MI$ OR END OF
E.
1 f2If2If2I J = 127
:: M1 $="" :: FOR K= 1 TO LEN (E<f;)
l1Z110 D=ASCCSEG<f;CE'$.K,I»
11212121 MH = lNTCD / 1 6) :: ML=D-M H*t6 :: M'$=SEG<f;CHE
X$.MH+l,l)~<SEG$(HEX"',ML+l,I):: Ml'$=M
1$ &M$
112124 REM STORE HEX STR ING MIS AS CHAR PATTER
N-IDE NTIFIER

- 1@25 IF ( LEN(MlS) = 1 6) +( (LE NCE'f;)*2) =CJ- 127)*1


6+LENCMl$)THEN CAL L CHAR(J,Ml'$) : : J=J+
1 •• Ml'$ =""
110310 NEXT K
11214121 CALL CLEAR : : PRINT "NOW RUN PROGRAM 2.

53
The Basics ______•

Program 2. Receiving Variables


10 REM PROGRAM 2 ( VARIABLE RECEPTOR PROGRAM)
99 REM IE .. LINES J00-798 = MAIN PORT ION OF
THE PROGRA M
1121121 OPTION BASE 1 . . DIM D(3).D"S(3) : : REM 01
MEN SIO N 0 AND D"S FOR NUMBER OF VARIABLES
T O RE CE IVE
110 GO SU B 80121 : : STOP
799 REM RECALL PATTERN IDENTIFIERS USED FOR
VARIABLE S TORAGE
8vH3 ~=1 : : P=1 : : FOR L=t27 TO 143 :: CALL C
HARPAT(L.A"S )
899 RE M SE PARATE A"S'S INTO MS ' S AND CONVERT
BACK TO DS()'S
9121121 FOR 1 =1 TO LEN (A S ' STEP 2
999 REM CHECK FOR E ND OF S TRING AND SET FLAG
91121 IF S EGS(AS, 1,4 '="FFFF " THEN FL=1
919 RE M CHECK FOR DELIMITER. FROM THIS, DET
ERM I NE LENGTH OF EACH OS () - STORE AS 0 (
)
92121 IF SEGS(AS , I.2J="FF" THEN D(K'=(L - 127J.l
6+l - P :: K=K+ l : : P=(L - 127'*16"'1+2 : : IF
FL=1 THEN I =LE N (AS ) :: GOTO 97121
929 REM TAKE TW O CHARACTERS OF AS ANO CALL T
HEM M$
93121 MS =SE Gs(AS. 1.2)
939 REM CONVERT HEX STRING TO DECIMAL. THEN
TO CHR$'S
94121 M=0 :: FOR J=l TO 2 :: Ml=ASC<MS):: Ml =M
1 - 48+(Ml ) 64)*7 . . MS=SEGS(MS,2,1):: M=16
*M+Ml
95121 NEXT J
959 REM CONCATENATE ALL CHRS'S TO FS
96121 FS=FS&CHRS(M)
97121 NEXT I
975 IF FL=1 THEN L=143
980 NEXT L
999 REM DEFINE OS ()'S USING D(I'S AND FS. TH
EN PRINT EACH OS().
100121 P=0 :: FOR 1 = 1 TO 3 : : DS(IJ=SEGS(FS,P+
1,0(1)/2):: P=P+D(IJ/2+1
11211121 NEXT I
Ji2I 2vl X=VAL(O$(l»:: Y= VAL(OS(21):: NAMEs=OS(
3)
1121 30 PRINT X,Y,NAMES
112140 RETURN

54
computer VisualsRichard D. Jones and Howard Alvir

Use your microcomputer to create effective visuals.

We give many presentations to groups of all sizes and have


found that good graphics increase understanding of theoretical
concepts and capture the interest of the audience. Recently the
TI-99/4A joined the overhead projector and flipchart in our
arsena l of visual aids.
Because of its small size, the TI-99/4A is very portable. A
briefcase holds the computer, power cord, RF modulator, por-
table cassette recorder an d cable. Rigging a snap connection
for the RF cable and an extension cord will make setup a little
easier. The television monitor is not as easily transported, so
it's best to arrange to have it at the meeting site before you
arrive.
Usually it takes 5-10 minutes prior to the meeting to set
up (it usually takes that long to set up an easel tripod!). Make
a few connections, load your program and begin. Since a 25-
inch monitor can be easily seen from 30 feet, we have used
the microcomputer with audiences of up to 75 people. Mul-
tiple monitors work well for larger audiences.
There are several advantages to using the computer
visuals. First, visuals can be changed freq uently and easily.
(We are always changing presentations). Second, information
is presented one point at a time. Third, since our presentations
usually focus on technology, we practice what we preach.
Fourth, the system is inexpensive and of high quality.
The following is a simple program illustration for present-
ing visuals. The routine organizes ten screens of information
with words stored in DATA statements. Each screen can be
called up a line at a time or the entire screen at once. The titl e
screen is displayed initially and is set for full screen display.
Each of the following screens is displayed in this sequence,
unless called by the 'IF" key.
During display there are several function keys. These are
as follows:
C-c1ear screen
F-display entire screen
55
The Basics _ _ _ _ __

space-scroll up
T- input additional words during display
1-9-calls appropriate screen
O-calls title screen
All other keys advance the screen a line at a time.
Color is added by the CALL COLOR command. As a re-
sult any character in character set 2 is displayed as color.
Thirty-two characters will display a colored :ine.
Experiment with numerous screen variations (e.g., color
combinations, larger letters, and speech to introduce major
pOints). We have even experimented with using the speech
synthesizer to open the presentation. Adding commands in
Extended BASIC can improve graphics but it adds complexity
to the equipment.
Generating visuals by computer opens exciting possibil-
ities for the future. Certainly improvements in video display
and microcomputers will expand the application of computer
visuals. In the meantime, you can enter a new arena of pro-
fessional computer use and discard your image as a hobbyist.
Computer Visuals
100 REM ***t*t****t****t****
110 REM * CO MPUTER VISUALS *
1 20 REM ********************
130 REM
140 REM
150 REM
160 REM
170 CA LL CLEAR
180 PRINT TAB<41 ;"PRE SS ANY KEY TO BEGIN"
190 CALL KEY(0,K,S)
200 IF S:0 THEN 190
210 CALL CLEAR
220 CALL COLOR(2,5,S)
230 CALL SCREE N(1 2)
240 RESTORE 1050
250 REM FULL SCREE N ROUTINE
260 CALL CLEAR
270 READ LINES
280 IF LINE$="END" THEN 500
290 IF LINES="." THEN 970
300 IF LINE$:"~" THEN 510
310 L=LEN<LINE$)
320 M=L/2
330 I=15 - M

56
- -_ _ _ _ The Basics

34. PRINT TAB(I) ;LINES


35 . PRINT
3 •• GOTO 270
37 . REM
38 . REM LINE ROUTINE
~ 3 9. tALL CLEAR
4 •• READ LINES
41. IF lINEt. = "END" THEN 500
42. IF LINE .. = "." THEN 970
4 3. IF LINE$ = ":i)" THEN 370
44. L=LEN<LINE'S)
450 M= L /2
4 6. I = lS - M
4 7. PRINT TAB<I);LINES
4 8. PRINT
4 90 GO TO 5 10
5 •• END
5 1. CALL KEY(0,K.S)
52. IF K=32 THEN 530 ELSE 550
53. PR I NT
5 40 GOTO 5 1 0
55. IF K=67 THEN 56. ELSE 580
56 . CA LL CLEAR
57 0 GOTD 51 .
580 IF K=84 THEN 5911' ELSE 6 40
59. PRINT
6 •• INPUT LI N E $
6 1. GaTO 41 .
620 PRINT
630 GOTO SUI
64. I F K=70 THEN 27 •
• 5. I F K:48 THEN 2 411'
66. IF K = 49 THEN 92.
67. I F K =5 0 THEN 9 • •
68. IF K = 51 THEN 88.
69. I F K=52 THEN 86.
7 •• IF K=53 THEN 84.
7 1. IF K ::;5 4 THEN 82.
72. I F K =55 THEN 8 ••
73. IF Kc56 THEN 78.
7 4. IF K=57 THEN 7 ••
75. IF So . THEN 510 ELSE 95.
7 •• RESTORE 1591'£1
77. GO TO •••
7 8. RESTORE 1 5310
79 . GOTO 4 ••
8 •• RE S TORE 1470
al. GOTO •••
82 (3 RESTORE 1410

57
The Basics ______

830 GOTO 400


840 RESTORE 1350
850 GOTO 4!!l0
860 RESTORE 129@
8713 GOTO 4130
880 RESTORE 1230
89!!l GOTO 400
90!!l RESTORE 1170
9113 GOTO 400
920 RESTORE 1110
9313 GOTO 400
940 GOT a 95121
950 IF 5 = 0 THEN 510
9613 GOTO 400
970 CALL SOUND(100.294,S)
9813 GOT a 5113
9913 REM DAT A FOR SC REENS
1000 REM
101121 REM
1132121 REM
113 3 13 REM
1040 REM TtTLE SCREEN
1050 DATA ----------------------------------
- -- ------------------- . ,COMPU TER VISUAL
S.USI NG THE
1136 0 DATA TI 99 4A COMPUTER ,
1070 DATA ----------------------------------

1080 DATA
10 9111
DATA **.;i)
11013 REM SCREE N 1
1110 DATA ADVANTAGE S
11 20 DATA ----------------------------
11 313DATA EASY TO EDIT,INEXPE NSIVE.ORGA NIZED
,EFFICIENT,COLORFUL.PORTABLE , ATTENTION
GATHERING
11413 DATA
1150DATA**,;i)
11 60 REM SCREEN 2
11713 DATA EQUIPMENT NEEDED, -----------------
----------- .TI 99 4A,CASSETTE RECORDER,
TELEVI S ION OR MONITOR. -------------- - --

1180 DATA REA L LY TH AT 1 5 ALL ~,


1190 DATA
1200 DATA
1210 DATA **, ;i)
122!!l REM SCREEN 3
1230 DATA HOW TO USE
1240 DATA ----------------------------
56
_ _ _ _ _ _• The Basics

1250 DATA OUTLINE PRESENTATION . ENTER KEY POI


NT S IN DATA. SAVE THE PROGRAM,SET UP YOU
R CO MPUTER AND TV
1 2b~ DATA LOAD AND RUN PROGRAM, IMPRESS YOUR
AUOIENCE . ----------------------------
1 2711' DATA " . il
1 2811' REM SCREEN 4
1290 DATA SCREEN 4
1 311'0 DATA
1 310 DATA
1 320 DATA
1 33121 DATA # . :>1
1 34121 REM SCREEN '5
1350 DATA SCREEN '5
13610 DATA
137121 DATA
1 380 DATA
1390 DATA #. :il
14011' REM SCREEN 6
14 1 0 DATA SCREEN 6
1420 DATA
1430 DATA
1440 DATA
1450 DATA t.. ;'j)
1460 REM SCREEN 7
1470 DATA SCREEN 7
1 480 DATA
1490 DATA
150121 DATA
151 0 DATA •• ~
1520 REM SCREEN S
1 530 OATA SCREEN a
1540 DATA
155121 DATA
156121 DATA
1 570 DATA "fl.:;)
1 58121 REM SCREEN 9
1 590 DATA SCREEN 9
1 6j1l0 DATA
1610 DATA
162121 DATA
1 63121 DATA * ,41
1640 DATA END

59
Using a Printer
- - - - - C. Regeno

These tips will give you a good start on adding a printer to


tile TI-99/4A. Here are the fundamentals, from the RS-232
Interface to PRINT # statements.
Texas Instruments has a thermal printer which attaches to the
side of the TI. It's a small unit which uses a special thermal
printer paper and can print a 3D-column line. A number of
other printers may also be used with your TI. The price de-
pends on whether the printing is dot-matrix or letter quality,
on various options available, and on how the printer is built.
To connect your printer to your TI-99j 4A, you will need
the RS -232 Interface. You may use either the "old-style" in -
dividual RS-232 Interface peripheral or the RS-232 Interface
Card which fits in the TI Peripheral Expansion Box. You will
also need a cable to go from the interface to the printer, and
the cable should be sold with the printer. If you want to wire
your own cable, the plug is a sta ndard DB-25, and the pin
connections are given in the manual that comes with the RS-
232 Interface.
Co nfigur ation s
Manuals are important. The manual that comes with the RS-
232 Interface describes how you list parameters for your
"printer configuration" so you can give instructions to your
computer to access the printer through the RS-232. The man-
ual that comes with the printer should describe how to
achieve various type styles (fonts) and how to set margins,
line lengths, and the top of the form. Be prepared to spend
some time experimenting with the different switches and fea -
tures of your printer.
When you use the printer con figuration in a command, it
is set off in quotes. Parameters may be chosen for baud rate,
stop bits, and number of nulls. Some examples are:
" RS232 .TW.BA ~ 11 0" (teletype)
" RS232.BA ~600" (T1 825 0< TI 840 pc;ntec)
"RS 232.BA ~9600.DA~8" (Epson MX 80)

60
_ _ _ _ _ _ The Basics

One of the primary uses o f a p rin ter is to obtain a


hardcopy listing of a program. Using your own printer
configu ration in the quotes, the fo llowing comma nds may be
used:
LIST "RS232.BA ~ 600"
Lists whole program
LIST "RS232.BA - 600",·250
Lists program lines up to line 250
LIST " RS232.BA = 600" :300-330
Lists program Jines 300 to 330
LIST " RS232.BA = 600":700-
Lists program from line 700 to end
Another valuable use for a p rin ter is to prin t a report from
your program. Before you pri nt, an O PEN statement is nec-
essary. The OPEN statement designates a device number and
your printer configuration. You may have several devices, and
you may number your devices in any order. An example state-
men t is:
120 OPEN #1 ,"RS232.BA ~ 600"
After th e OPEN statement, you may p rint to the prin ter
by a statement such as:
130 PRINT #l ,"MY N AME IS REGENA."
Wh en you 've finis h ed prin ting or you're at the end of the
program, you s hould close all devices. Th is can be done with
the foHowing statem ent:
550 CWS E #1
Here is a short sam ple program th at ill ustrates pri nting to
a prin ter:
100 OPEN #1, "RS232. BA ~ 600"
Opens device 1 for printer.
110 OPEN #2,"SPEECH",DUTPUT
Opens device 2 for speech (Terminal Emulator II required).
120 PRINT " HERE IS A SAMPLE."
Prints message on screen.
130 PRINT #l ,"TEST REPORT
Prints on printer.
140 PRINT #2,"HELW"
Speaks the word using synthesizer.
150 CWSE #1
Closes device 1.

61
The Basics _ _ _ _ __

160 CWSE #2
Closes device 2.
170 END
The print list fo ll owing th e colon in a PRI NT # statement
follows the same rules as regular printing to the screen. Since
the length of lines may be longer on the printer (the screen
has 28 columns in a print line), you may use the TAB function
to arrange your printing:
100 OPEN #1 ,"RS232.BA ~ 600"
110 PRINT #HAB(2W'MONTHlY PAYMENTS"
You may use a variable in the TAB fun ction:
200 PRINT #l,TAB(T + A);MONTH$;X
You may also use colons to print blank lin es:
220 PRINT #1 ,,,
If you have adjusted your printer properly for vertical
tabs, you may go to the top of the next page by using:
300 PRINT #l ,CHRSm)

'-

62
3
Mail~!!~te~nist
This program call be used for developing small mailing lists,
for famifies or for orgallizations. There are tell options,
including printing a single label or all entire alphabetized
mailing list.

Have you ever kept a file of addresses on index cards, hoping


to o rganize them someday in an orderly fashion? It sounds
simple, but in practice you know how difficult it is to organize
and update a paper-based filing system. "Mailing List" offers
you an easy method of creating, maintaining, and utilizing a
mailing list file.
Without any programming experience you can keep an
up-to-date, well-organized file. The program will prompt you
step-by-step through the entry of names, addresses, and
phone numbers. Then, with a few simple keystrokes, you can
update your file, print lists in two different modes, or save
your file on a storage device . It's that easy.
Mailing List is designed specifically as a family mailing
list, but is flexible enough to accommodate a number of
applications. The program will store last names, first names,
children's names, addresses, and phone numbers.
The program is written in a Canadian format-that is,
province and postal code. However, the format can be easily
adjusted to the American system as you type in the program.
Procram Environment
The program is set up for 45 entries. After 45 entries you will
be given the message ·DATA FILE IS FULL·. This feature will
prevent your program from crashing with a MEMORY FULL
error message. If you have more than 45 addresses to enter,
you may easily divide your list into two or more files-for ex-
ample: (A-L) and (M-Z).
When you run the program, the initial title screen ap-
pears. The next display permits you to initialize the printer. Be
sure to enter the proper name and spelling of the device
you're USing, because an improper name will cause the pro-
gram to break when you attempt to address the device later in
the program.
65
Applications ______

Ten Options
Once the computer "environment" is established, you are
taken to the Main Index. Here you will discover ten options:
1 View Names List
2 Search for a Name
3 Add Names
4 Change Names
5 Delete Names
6 Alphabetize List
7 Save Data File
8 Load Data File
9 Print Labels/ List
10 Finish Session
Of course, to create a mailing list you would first choose
option 3 (Add Names). The other options will enable you to
update, maintain, and utilize an existing file. The program will
guide you step-by-step through the procedure for each option.
There are many helpful features, such as the Search, Change,
and Delete. You can also enter names and addresses in any
order, and then, by choosing the Alphabetize option, have the
computer sort them for you.
The Data File
The program is written to both save and load data files for
either cassette or disk storage. When you choose either the
Save or Load option, you will be given any further step-by-
step instructions.
Print Options
The program offers you two print options-one for mailing
labels, and the other for the mailing list.
The Print Labels option will print the first name, followed
by the last name, and then the address on lines two and three.
For example:
John Doe
1234 Street Address
City Province Postal Code
The Print Mailing List option will prin t the last name first,
fo llowed by the first name and children's names, with the ad -
dress on line two, and the phone number on line three. For
example:

66
- - - -_ _ Applications

Doe, John Mary Joe Sally


1234 Address City Province Postal Code
(p)-444/4456

Line spacing between addresses is flexible via a minor pro-


gram change. If you wish to alter the line spacing, program
lines 497 (labels) and 517 (list) may be adjusted by either
increasing or decreasing the number of colons (:) at the end of
each line. Each colon represents one line space. For example:
497 PRINT #HAB(S);NA$(i);" ";LN$(i),TAB(S);A05(I),TAB(S);
CP$(I);" ";PC${I):::; (Add or delete colons here.)
In the Print Labels option, you may wish to print two la-
bels per line instead of one. If so, you should adjust the line
listing as follows:
Change line 487 to:
87 FOR 1= 1 to N STEP 2
Change line 497 to:
497 PRINT #HAB(S);NA5(I);" ";LN$(i);TAB(4S);NA$(i + 1);
" ";LN$(i + 1),TAB(S);AD$(i);TAB(45);AD$(1 + I)
Add line 498:
498 PRINT #HAB(5);CP$(I);" ";PC5(I);TAB(4S);CP$O +1);
" ";PC$(i +1)""
The Search option permits the printing of a single mailing
label. After finding the name you are seeking, the display asks
if you would like a mailing label printed. If yes, the program
branches to the print routine and then returns to the search
option.
Mailing List Program Structure
1-21 REMs and computer environment.
23-47 Main loop, main index.
49-73 Subroutine to view names.
75-109 Subroutine to search for a name.
111-181 Subroutine to add names.
183-285 Subroutine to change data.
287-331 Subroutine to delete names.
333-423 Subroutine to alphabetize list.
425-441 Subroutine to save data.
443-471 Subroutine to load data.
473-521 Subroutine to print.
523-533 Subroutine to finish session .

67
Applications _ _ _ _ __

Mailing List
5 REH t.COMPUTER ENVIRONMENTtt
7 DIM LN$(45),NA$(45).CH$(45),AD$(45),CP$(45
) , PCS(45),TPS(45)
9 CALL CLEAR
11 PRINT" .(3 SPACES } 99/4A MAILING LIST
( 3 SPACES}.":
13 INPUT "(4 SPACES}PRES5 ENTER TO BEGIN":XS
15 CALL CLEAR
1 7 PRINT "(5 SPACES}WHAT ]5 THE NAME OF":"
(4 5PACES}VOUR PRINTING DEVICE ? "::M (EX
AMPLE: RS2 32 . BA=4800)":

19 INPUT PS
21 Gs = "(7 SPACES}PLEASE WAIT._. ( 7 SPACES}WHI
LE THE PRINTER IS WORKING"
2 3 REM •• MAIL LIST MENU**
25 CALL CLEAR
2 7 PRINT "(8 SPACES}MAIN INDEX u :
2 9 PRINT "PRE S S( 3 SPACES}TO": :
3 1 PRINT" VIEW NAMES LIST":" 2 =
SEARCH FOR A NAME":" 3 = ADD NAMES":M
4 CHANGE NAME S "
33 PRINT" 5 DELETE NAMES":" 6 = ALP
HABETIZE LIST":-' 7 "" SAVE DATA FILE":"
8 ~ LOAD DATA FILE"
35 PRINT" 9 = PRINT LABELS/LIST":" 10 ""
FINISH SESSION":
37 INPUT P
3 9 IF P } 10 THEN 3 7
4 1 I F P < 1 THEN 37
4 3 CALL CLEAR
4 5 ON P GOSUB 51, 77 ,11 3 ,185, 2 89,335,42 7 ,445,
47 5 ,525
4 7 GOTO 2 5
49 REM {3 SPACES } t*VIEW NAMES LIST*t
5 1 T= 0
53 FOR 1 = 1 TO N
55 T= T+l
5 7 PRINT NASCI) . LNSCI):CHSCI):ADSCI):CPSII):
PCS(I):"(P) - ";TPSCI);
59 IF T < 2 THEN 6 9
61 PRINT" tPRESS ENTER TO CONTINUEt";" *""R
"",ENTER FOR HAIN INDEX*"
6 3 INPUT X$
65 IF Xs="R" THEN 7 3
6 7 T= 0

68
- -_ _ _ _ Applications

69 NEXT I
7 1 INPUT "(7 SPACES}*END OF FILEa{9 SPACES)'
PRESS ENTER TO CONTINUE'·:X~
73 RETURN
75 REM( l SPACES} •• SEARCH NAMES ••
77 INPUT "LAST NAME? "!Y$
79 FOR 1= 1 TO N
al IF LN$ ( I) (> Y$ THEN 11213
83 PR INT :" IS THE PERSON:": :" "; NAs (
I ) : " ";LN$(I):
85 INPUT (YI N )? ": XS
87 IF X$"'''N'' THEN 10 3
89 PR J NT: : NAS (I) ,LN$ (I ) : eHS (I) : ADS (I) : CP
S(I):PC$(I):"CP l - ";TP$(I):
91 INPUT " {3 SPACES}OO YOU WI S H TO PRINT
{b SPACES}A MAILING LABEL ? (Y / N)":Zs
93 IF ZS <> "V" THEN 97
95 GO SUB 495
97 IN P UT "SEARCH MORE NAME S? (Y/ N ) ":X'I
99 IF XS="Y" THEN 77
101 GOTO 11219
1£13 N EX T I
1121 5 PRINT : ;" THE ";YS:" YOU ARE SEARCH
I NG FOR ":" IS NOT IN THIS FILE.":
Ifl17 GOTO 97
109 RETURN
111 REH {3 SPACES}"ADD NAMES._ (S S PACES )
11 3 A=N+l
115 FOR I : A TO 45
117 CALL CLEAR
119 PRINT; ; "ENTER DATA; ";".";1;" (HA
X:4S)"; ;
121 PRINT n .LAST NAHE: n
123 INPUT LN~(I)
125 PRINT;" .FIRST NAMECS):"
127 INPUT NA~(I)
129 PRINT:" .CHILDREN:":"(3 SPACES}NOTE--D
o NOT USE COMMAS~"
1 3 1 INPUT CHS(I)
1 33 PRINT:" .STREET ADDRESS:"
1 3 5 INPUT AD~(I)
1 37 PRINT :" .CITY/PROVINCE:":"{3 SPACES}NO
TE -- DO NOT USE COMMAS~ ~
1 3 9 INPUT CPS(I)
141 PRINT:" apOSTAL CODE:"
143 INPUT PCS(I )
145 PRINT;" aPHONE:"
14 7 INPUT TP~(I)
149 V=I

69
Applications _ _ _ _ __

151 REM ,.VERI FY ENTRIES'.


1 53 CALL CLEAR
155 PRINT ~ENTRY";".";V:
157 PRINT "YOU ENTERED~": : " "; LNS IV); ", ";
NA$ (V):" "; CHS ( V) : " "; AD ... (V) :" " j CP$ (
V )
159 PRINT "j PC S(V):" PHONE: "jTPS(V):

16 1INPUT "CHANGE ANYTHING ? (Y/N)":XS


163 IF X$ <> "Y" THEN 171
165 C:: N+l
167 CALL CLEAR
169 GOSUB 20 1
17 1INPUT "ADD MORE NAME S? ( Y/N)":XS
1 73N"" N+ l
175 IF XS: "N " THEN 181
17 7NEXT I
179 INPUT "{ 4 SPACES}'DATA FILE IS FULL'
{ 6 SPACES}'PRESS ENTER TO CONT INU E ''': X$
181 RETURN
183 REM{3 SPACES> **CHANGE DATA ••
185 PRINT" LA ST NAME OF THE PERSON
(3 SPACES} WHO SE DATA IS TO BE CHANGED: " :

187 IN P UT CS
lS9 CALL CLEAR
191 FOR C::l TO N+l
193 IF LNS(C) "" CS THEN 195 ELSE 239
1 95 PR I NT "IS THE PER SON :": " "; NAS (C) : " ";

197 INPUT " (Y/ N) ? ":XS


199 IF X ~ :: "Y· THEN 201 EL SE 239
201 PRINT: : " PRESS{3 SPACES}TO CH
ANG E" :
203 PRINT "

REET ADDRESS"
1
NAM E (S) " : " - 3
LA S T NAME":" 2
CHILDRE N ":" 4
FIRST
ST
205 R::C
207 RS _ " *ENTER THE NEW DATA;"
2 09 PRINT 5 - C ITY / PROVINCE":" 6 ~ P
OS TAL CODE":" 7 "" PHONE":" B "" NO
CHANGE" :
211 INP UT P
2 1 3 CALL CLEAR
2 15 I F P < l THEN 211
217 IF P >8 THEN 2 11
2 19 I F P ES THEN 229
22 1 ON P GOSUe 2 45 ,25 1, 257,2 63, 26 9, 275 , 28 1
223 PRINT: ;"MORE CHANGES FOR: " :" ";NA$(R) ~
: " ";LNS(R):

70
- _____• Applications

225 INPUT" (V/N)?":V~


227 IF VS <> "N" THEN 201
229 PRINT: : "CHANGE DATA FOR OTHER NAMES ?
" :
231 INPUT" (Y/N)":Z$
233 CALL CLEAR
235 IF Z$ <> "N" THEN 185
237 RETURN
239 NEXT C
2 41 RETURN
243 REM *'CHANGE LOOPS.'
245 PR I NT "LAST NA ME WAS:" : : LN$ CR) : : Rs
247 INPUT LNS(R)
249 RETURN
251 PRINT "FIRST NAMECS) WERE: ": : N AS(R):
:RS
253 INPUT NASCR)
255 RETURN
257 PRINT "CHILDREN WERE:" : :CHSCR) : :RS
259 INPUT CH$(R)
261 RETURN
263 PRINT "ADDRESS WAS : ": : ADS CR): : R'S
265 INPUT ADSCR)
267 RETURN
269 PRINT "CITY/PROVINCE WAS: " : :CP$(R):
R$
271 INPUT CP$(R)
273 RETURN
275 PRINT "POSTAL CODe WAS:": :PCs(R): :R$
277 INPUT pes(R)
279 RETURN
281 PRINT "PHONE NUMBER WAS: " : :TPSCR): :R

283
•INPUT TPS(R)
285 RETURN
287 REM{3 SPACES}"DELETE NAMESl .
289 INPUT "LAST NAME? H: X$
291 FOR 1=1 TO N
293 I F LN$(I) <>X $ THEN 325
295 PRINT: :~IS THE PERSON: " :H ";NA$(I) :
H;LN$(I):
297 INPUT" (Y/N)?" : Y$
299 IF Y$<> " Y· THEN 325
301 A- I
303 FOR O=A TO N- l
395 LNS(D)=LNS(O+ l )
307 NA$(D)=NA$(D+l)
309 CH$(D)=CH$(D+l)
311 AD$(D)=AD$(D+l)
313 CP$(D)=CP$(D+l)

71
Applications _ _ _ _ __

315 PC$(D)=PC$(D+l)
317 TP$(D ):TP$(D+l)
3 1"1 NEXT D
321 N=N - l
323 GO TO 327
325 NE XT I
327 INPUT ~MORE DELETIONS? (Y/N)";X$
329 IF XS="Y" THEN 289
33 1 RETURN
333 REM ttALPHABETI ZE LISTtt{3 SPACES}
335 PRINT " (7 SPACES}PLEASE WAIT • •. ": :" T
HE LIST IS BEING ARRANGED":

337 8=1
339 B=2t9
341 IF 9 < =N THEN 339
343 B=INT IB/2)
345 IF B=0 THEN 369
347 FOR Y=1 TO N-B
3 48 X=V
3 49 I=X+B
351 IF LNS(X)=LNS(I)THEN 363
353 IF LNS(X) < LNSII)THEN 3 65
355 GOSUB 381
357 X=X - B
359 IF X>0 THEN 349
361 GOTO 365
363 GOSUB 373
365 NEXT V
367 GOTO 343
369 RETURN
371 REM t.ORDER FIRST NAMES"{3 SPACES}
373 IF NAS(X) < NAS(I)THEN 377
375 GOSUB 381
377 RETURN
37"1 REM •• CHANG E ORDERt'
38 1 N$ =L NS( X)
383 LNSIX)=LN$(I)
385 LNS(I)=NS
387 NS = NAS (X)
389 NAS(X) = NASCI )
3"11 NAS (I) =N$
393 NS=CHS(X)
395 CH$(X)=C HS (I)
397 CHSII) "" N$
399 N$ =ADS(X)
401 AD$(X)=ADSCI)
4fi.'1 3 ADS(I)::NS
405 N$=CPS( X)
40 7 CPS(X)=CPS(I)

72
_ _ _ _ _ _ Applications

409 CPt; (I) ::N"


411 N$=PC$ (X)
413 PC$(X)=PC$(I)
415 PC$(I) : N$
417 N$ = TP$ (X)
419 TPS(X)=TPS(I)
421 TP$(I):NS
423 RETURN
425 REM .'SAVE DATA FILEtt(S SPACES}
427 SOSUB 467
429 OPEN ttl:L$,INTERNAL.OUTPUT.FIXED 150
431 PRINT ttl:N
433 FOR 1=1 TO N
435 PRINT *l:LN$ -(Il,NA$(Il,CHSCI),ADS(I),CP$
(II,PC$(I),TP$(I)
4 37 NEXT J
439 CLOSE tH
441 RETURN
443 REM{3 SPACES}t'LOAD DATA FILEt.
{6 SPACES}
445 GOSUB 46 7
447 OPEN .I:lS,INTERNAL,INPUT .FIXED 150
449 INPUT #l:N
451 FOR 1=1 TO N
453 INPUT #1: LN'* (I). NA$ (I). C H$ ( I ) , AD$ (I), CPS
(I),PCS(I).TP$(I)
455 NEXT J
457 CLOSE #1
459 CALL CLEAR
461 PRINT ,. ";L'$::" THIS FILE HA S ";N; "EN T
RIES .": :" *45 ENTRIES 1 5 MAXIMUMt":

46 3 INPUT " tPRESS ENTER TO CO NTJNUE"':X~


465 RETURN
46 7 PRINT N{ 5 SPACE S 1WHAT I S THE NAME OF":"
{ 4 SPACES~YOUR STORAGE DEVICE ? " : :" (EXAM
PLE : CSt OR DSK1.FILE ) ":

469 INPUT L~
471 RETURN
473 RE M ** SUB TO PR INT LABELS/LIST'_
475 PRINT " PRESS{ 3 SPACES}TO PRINT" : : " 1
(5 SPACES } MAILING LABELS": :" 2
{ S SPACES}MAILI NG LIST":
477 INPUT P
479 IF P ( l THEN 47 7
48 1 IF P >2 THEN 47 7
483 PRINT: :6$=

73
Applications _ _ _ _ __

485 IF P <> t THEN 51215


487 F OR 1 = 1 TO N
489 GOSUB 495
491 NEXT I
49 3 RETURN
495 OPEN tt 2 ~PS
4 97 PRINT 3 2:T AB( S) :NA$(I ) :" " :LN$ (I) :T AB(5)
:AD$ ( I):TABC5 ) :C P$( I ) :" ":PC$(I) :
49 9 CLOSE 3 2
51211 RETURN
51213 RE M{3 S PA CES} **PRINT MAIL LI S T*.
51215 F OR 1=1 TO N
513 7 GOSUB 513
5139 NEXT 1
511 RE TURN
51 3 OPEN 32:P$
515 PRINT # 2 ! TA B (S )~ LN $CI ) :". ":N A$(T);"
(6 SPACES}" , CH $ ( I ) : T AS C5) ;: AD$ ( 1 ) , "
(3 SPAC ES }" : CP$( I);" " : PC$(I)
517 PRINT 32:TAB(60):"CP) - ":TP$(I) :
5 19 CLOSE # 2
52 1 RETURN
523 REM . , F INI SH SESSION"{5 SPACES}
525 IN PUT "(7 SPAC E S} DO YOU WISH TO
(113 SPACES} TE RM INAT E THI S SESS ION ?
{5 SP ACES }(Y/ N ) ":X$
527 CA LL CLEAR
529 IF X$ <> " Y" THEN 25
531 PRINT " (6 S PA CES} HAVE A NICE DAY!" :

533 STOP

74
Statistics For
Nonstatisticians
- - - - - - A. Burke Luitich
TI Translation by Patrick Parrish

Basic statistical methods carl help you make logical decisions


in everyday situations.
For the most part, elementary statistical methods measure a
group of similar things to see how these measurements vary
when compared to some standard. Another use for statistics is
to see how creating a group of objects can cause variations in
these objects.
This program, "Statistics," takes your raw data and re-
turns figures which you can use to make everyday decisions,
for example, about the best way to build a wall or how much
cash you'll need when you go shopping.
As a first example, let's look at two ways to cut a two-by-
four by using a power table saw and a handsaw. We set the
table saw guide to one foot and cut five pieces. We cut five
more pieces using a handsaw, then measure the actual lengths
of all ten pieces to see how accurately we made the cuts.
If nothing unusual is allowed to affect the cutting, we can
expect the length of the pieces to vary depending on the pro-
cess used. Statisticians call this an unbiased ra11dom sample.
Assume the measurements are as follows:
Table saw lengths Handsaw lengths
(feet) (feet)
1.05 1.22
0.98 0.91
1.03 0.80
1.07 1.28
0.96 0.88

The Same Mean


A look at the values alone suggests that cutting with the
handsaw is a far less consistent method than using the table
saw. However, if you add up the lengths for each method and

75
Applications _ _ _ _ __

divide by 5 (the total cuts for each) you will find that both
methods give the sa me meorl (average) length of 1.018 feet.
Just finding an average length doesn 't tell us much. What
we need to know is how widespread the values are likely to
be, and which method gave us the most lengths that were
nearer our standard of one foot. In statistical terms, we need
to calculate the range and the standard deviatioll.
We find the range by subtracting the shortest length from
the longest, for each cutting method. For the handsaw the
range is .48 feet (1.28-0.80), and for the table saw the range
is .11 feet (1.07-0.96). Immediately, we can see that the table
saw cut more consistently, because the range, or variation, is
smaller.
We can use the standard deviation and the mean length
to predict how often a given length is likely to occur. You
don't have to worry about how to calculate a standard de-
viation: The program does this for you. If you type in the
above lengths for the handsaw, the program will return a
standard deviation of 0.217 feet. The standard deviation for
the table saw is 0.047 feet.
Degree of Accur acy
If we made a large number of cuts, then measured and
graphed the lengths, the graph would form a bell curve, or
normal distribution. By combining the standard deviation and
the mean length, we get a range of lengths that includes 68.3
percent of all lengths (again, you don't have to know the the-
ory; just use the number). To illustrate, first take the mean
length, 1.018 feet, and subtract from it the standard deviation
for the handsaw, 0.217 feet, to get 0.801 feet. Then add the
standard deviation to the mean length to get 1.235 feet. This
means that 68.3 percent of our lengths fall in the range be-
tween 0.801 and 1.235 feet.
By adding and subtracting the standard deviation (0.047
feet) with the mean length of the table saw cuts (1.018 feet),
we find that 68.3 percent (roughly two-thirds) of these lengths
fa ll in the range from 0.971 to 1.065 feet.
If you want a wider sample, you must increase the num-
ber of standard deviations. To include 95.4 percent of all
lengths, use two standard deviations. For the handsaw, we
now have 0.434 feet, two standard deviations. Combining it
with the mean length, we get a range of 0.584 to 1.452 feet.

76
_ _ _ _ _ _ Applications

OUT table saw range becomes 0.924 to 1.102 feet (1.0] 8 ±


0.094).

Food For Thought


You can use the same methods to calculate a food budget. In
this case, your data consists of the amounts you spent on
groceries over a I3-week period (one-fourth of a year):
Week Amount Week Amount
1 $42 8 47
2 50 9 65
3 75 10 49
4 37 11 43
5 51 12 52
6 45 13 54
7 56
If you type th is data into the Statistics program, you will find
that your mean amount spent was about $51; that your spend-
ing varied from $37 to $75, for a range of $38; that you spent
more than $50 (your medium amount) as often as you spent
less than that; and your standard deviation is about $10.
Applying the Statistics
Combin ing one standard deviation and th e mean (or average)
amount spent, we find that two-thirds of the weeks you spend
between $41 and $61 at the grocery store. One-sixth of the
time you spend less than $4 1; one-sixth of your bills are more
than $61. So, if you budget $61 for groceries, you'll have
enough 84 percent of the time.

16% 68% 16%


,.-..-.-.
---~-" ,.....--,
I
I
less $10 I $10 more
than ..
I
I • than
$41 one standard
deviation ,,,I onedeviation
standard $61

minus , plus
$41 $51 $61
(mean)

77
Applications ______•

If you want to be sure you'll have enough in case prices


rise, you might want to use two standard deviations. By add-
ing two standard deviations ($20) to the mean amount ($51),
you will find that, to be about 98 percent sure, you should
budget $71 each week. -
There are other fa ctors to be considered, of course, such
as vacations, birthday parties, or visiting relati ves, that can af-
fe ct your food budget. The Statistics program does not take
these kinds of things into account. But it does give you a tool
which takes some of the guesswork out of everyday decision
making.
Statistics
100 DIM SA(300)
110 r: AL L CLEAR
1 20 PRINT TAB( 1 0) : "S TA TISTICS"
130 PR INT
J4 0 PRINT TAB(13) : "FOR"
15 0 PRINT
1 60 PRINT TAB(71 : " NON-S TAT I5TIC IAN 5 "
1 70 PRINT
18 0 FOR K= 1 TO 4 00
190 NEXT to:
200 CAL L CLEA R
2 10 PRINT "THI S PROG RAM CALCULATES THE" :
220 P RINT "FOLLOW I NG VALUES FROM DATA" :
230 PRINT "Y OU IN P UT:"
2 4121 PR I NT
25121 PRINT TAB( 4) : "1. MEAN"
260 PRINT
27121 PRINT TAB/ill : "2. S TANDARD DEVIATION"
280 P RI NT
290 PRINT TAB(4) :" 3 . MEDIAN"
300 PR I NT
3 1!i1 PRINT TABCiI ) :"4. RA NGE"
320 PRINT
330 PRINT TRB (2) :"PRESS ANY KEY TO CO NTIN UE"
3 4 0 PRINT
350 GOSUFI 2 1 7Q1
36111 S UM= 12I
370 MEA N=0
38!Z1 OFF =0
39 0 SOOEV=~I
4!Z10 RG =0
410 REM IN S TRUC T I ONS REOlJEST
420 PRINT TAE((6 ) : " I NSTR UCT I ONS ('I' / N I--' ''
430 PR I NT :

78
_ _ _ _ _ _ Applications

44. G05UB 2170


4 59 IF (K <> B9l * <K <:) 78IT HE N 44 0
4 6. IF K=78 THE N 4 90
4 7. GOSUB 1330

-- 4 8.
4 ••
RE M DA T A E NTRY
CA LL CLEAR
509 PR INT
SUI INPUT N
TAB(3): " ENTER SA MPLE S IZE " :

52. IF (N ) 30S)+(N (= 1)THEN 490


53. CALL CLEAR
54. PRINT TAB(3);"ENTER YOUR DATA ONE VALUe"

sse PRINT "AT A TIME, THEN PRESS":


560 PRINT "RETURN. "; :
570 PRINT TAB(3);"IF YOU HAKE AN ERROR,":
580 PRINT "CONTINUE WITH DATA ENTRY.":
590 PRINT "YOU WILL BE ABLE TO HAKE";
600 PRINT "CORRECTIONS LATER,":
610 PRINT TAB(2);"PRESS ANY KEY TO CO NTINUe"

62111 GOSUB 2170


630 FOR 1=1 TO N
640 CALL CLEAR
650 PRINT "DATA ENTRY .";1;
660 INPUT R'S
670 SA(I)=VAL(R$)
680 NEXT I
690 REM ERROR CORRECTION REQUEST
700 CALL CLEAR
710 PRINT TAB(3);"ANY CORRECTIONS (YIN) ?N
720 PRINT :
730 BOSUS 2170
740 IF K< >B9 THEN 770
750 SOSUS 1800
760 REM CALCULATION OF MEAN AND S TD. DEVIATI
ON
770 PRINT TAB(9);NPLEASE WAIT-:
780 PRINT "STATI STICS BEING CALCULATED"
790 PRINT :
800 FOR 1 : 1 TO N
810 SUM:SUM+SA(I)
820 NEXT I
830 MEAN =S UM / N
840 FOR 1=1 TO N
850 DFF=DFF+(SA(I)-MEAN) ~ 2
8b0 NEXT I
870 SDDEV=SQR(DFF/(N - l»
880 REM SORT OF DATA INTO NUMERIC ORDER
890 FL=0
900 FOR 1=1 TO N- l

79
Applications _ _ _ _ __

918 IF SA(I) < =SA( I+l)THEN 960


928 Q=SA(I)
930 SA(I)=SA(I+l)
948 SACI+l)=Q
950 FL=l
960 NE)(T I
970 IF FL=1 THEN 898
980 REM CAL CULA TION OF RANGE
990 RG=SA(N) - S A(I )
1008 LR=SA(I)
1010 HR =S A(N)
1020 REM CALCULATION OF MEDIAN
183 8 IF N/2 <> INT ( N/2 )THEN 1890
1040 IF SA(N/2)< >SA(N/2+1ITHEN 1060
1050 MDD = SA ( N/ 2)
1060 IF S A(N /2)=S A(N /2 +1)THEN 1088
107 8 MDD = ( SA( N/2 )+SA(N /2 +1» /2
1888 GO TO 1110
1890 MDD=SA(INT(N /2 +1 1)
1100 REM PRINT RE S ULTS TO SC REEN
1110 CALL CLEAR
1120 PRINT TAB(5 1;NC ALCULATION RESULT S" :
* ••••••••••
11 30 PRINT N • • • • • • • • • • • • • • • • • N:

1148 PRINT NSAHPLE SIZE N;TAB(L9);N:


1150 PRINT " MEAN ( X BAR )N; TAB CI9 1 ;INT(MEAN'1
0000+.5)/10800:
1160 PRINT "STD. DEVIATION";TAB(19);INT(SDDE
V'10000+.S)/10000:
1170 PRINT "HEDIAN" ; TAB ( 191 ; INT(MDD'10000+. S
1/10000:
1180 PRINT NRANGEN;TAB(19);INT(RG*10088+.5) 1
18008:
1190 PRINT "LOWEST VALUE";TAB(19);LR:
1 208 PRINT "HIGHEST VALUE";TAB(19);HR :
1 2 10 PRINT TAB(8);"PRESS ANY KEY"
1220 GOSUe 2 178
1230 REM REQUEST TO CONTINUE OR END
1240 PRINT" WI S H TO PROCESS MORE DATA N:
1250 PRINT TAB(12 1 ;"(Y / N)?": : :

1 260 GOSUe 2170


1270 IF K=78 THEN 1320
1288 FOR 1=1 TO N
1290 SA (11=0
1300 NE XT I
1310 GOTO 3 60
1 320 END
1338 PRINT T A8( 3);"T HE MAXIMUM NUMBER OF EN -
" ,
80
______• Applications

1 3 40 PRI NT - TRIES YOU CAN MAKE IS 300.-:


13'50 PRINT "THE MINIH UM NUHBER IS 2 " .
1360 PRINT TAB(3);"THE MEAN IS THE ARITH - ":
1370 PRINT " HET IC AVERAGE OF THE NUMB ERS":
1380 PRINT "YOU ENTER. ": :
1390 PRINT TAB( 3);"STA ND ARD DEV I AT ION IS A":

1400 PRI NT -MEA SURE OF HOW WID ELY YOUR":


1410 PRINT -NUM BERS SPREAD FRO M THE":
1420 PRINT -AVERAGE ." :
1430 GOSUB 2 1 60
1440 CALL CLEAR
1450 PRINT TAB ( 3);"S IN CE THE VALUES YOU ENTE
ROO:
1460 PRINT "TEND TO FORM A BELL CURVE" :
1470 PRINT " ( NO RMA L DISTRIBUTION). THEN:
1480 PRINT "STD . DEVIATION IS A MEASURE" :
14 90 PRI NT "OF THE AREA UNDER THE BELL" :
15 00 PRINT "CURVE." :
1510 PRINT TAB(4);"NO. OF STD . (4 SPACES } X AR
EA"
15 20 PRINT TABCS);"DEV. (+ / - )"
1 530 PRI NT TAB(4) ~ " ----------- {4 SPACES }----
-- " :
1 540PRINT TAB(8);"1 { 11 SPACES}68.3"
1559 PRINT TAB(8) ; " 2{ 11 S PACES}95.5"
1 569PRINT TAB(8);" 3 { 11 SPACES}99.7 "
1 570PRINT TA8(8);"4 { 11 SPACES } 99.9 " :
1580 GOSU8 2 160
1590 PRINT TAB( 3 );"T HE MEDIAN I S THE VALUE A
T":
1699 PRINT "THE MID - POINT OF YOUR DATA . ":

1619 PRINT TA8(3);"THE RANGE IS THE DIF - ":


1620 PRI NT "FE RE NCE BETWEEN YOUR LO WE S T " :
1630 PRINT "DATA VALUE AND THE HI GHE ST . ":
1640 PRINT "IT IS A QUIC K- AND - DIRTY" :
1659 PRINT "ESTI MA TE OF THE SPREAD.":
1660 PRINT "STANDARD DEVIATION IS MORE":
1670 PRINT "RELIABLE, HOWEVER . ":
1680 PR IN T TAB(3);"PRESS ANY KEY TO START"
1690 GOSue 2170
1790 RETURN
1719 REM DISPLAY CORRECTION OPTION
1729 GOSue 2179
17 3 9 IF CK <> b7)*CK <>7 8)*(K <> Bl)THEN 1 7 2 0

81
Applications ______

1740 FL=0
1750 IF K< ) 78 THEN 1780
1760 FL=l
1770 GOTO 1980
1780 IF K=81 THEN 770
1790 REM ERROR CORRECTION SUER
1800 PRINT "REMEMBER INCORRECT SA MPLE ~":
1810 PRINT TAB<lU ;" (Y/N) ?" :

1820 GOSUB 2170


1830 IF K=78 THEN 1980
1840 INPUT "WHAT IS THE SAMPLE. ? ":EN$
1850 EN=VAL(EN$)
1860 IF (EN >N)+(EN<I)+(EN <> INT(EN»THEN 1840
1870 PRINT :
1880 PRINT "SAMPLE";EN;"{3 SPACES}"; "VALUE="
;SA(EN)
1890 PRINT
1900 PRINT "ENT ER YOUR NEW VALUE
1910 INPUT SA(EN)
1920 PRINT
1930 PRINT TAB(3);"ANY MORE CHANGES (YI N )?":

1940 GOSue 2170


1950 CALL CLEAR
1960 IF K=78 THEN 770
1970 GOTO 1800
1980 IF FL=l THEN 2020
1990 PRINT "THESE ARE THE FIRST TEN":
2000 L::l
2010 GOTO 2040
2020 CALL CLEAR
2030 PRINT "THESE ARE THE NEXT TEN":
2040 PRINT "VALUES , ":
2050 PRINT TAB(5);"ENTRY ";TAB(IS);"VALUE":
2060 FF=0
2070 FOR L=L TO L+9
2080 FF:FF+l
2090 IF L >300 THEN 770
2100 PRINT TA8(5);L;TA8C1S);SA(L)
2110 NEXT L
2120 PRINT
2130 PRINT "C=CHANGE DATA{3 SPACES} N=NEXT TA
BLE" :

82
_ _ _ _ _ _ Applications

2140 PRINT TAB(12);"C=QUIT"


21'50 GOTO 1720
2160 PRINT TAB(3);"PRESS ANY KEY FOR HORE";
2170 CALL KEY(0,K.S)
2180 IF 5=0 THEN 2170
219121 CALL CLEAR
220121 RETURN

83
TIcalc
- - - - - Raymond J. Herold

Spreadsheets are exceptionally useful tools: for calculating,


modeling, or predicting. This program creates a spreadsheet
of ample size (26 rows by 14 columns). For the TI-99 j 4A
with Extended BASIC.

" Tlcalc" is an electronic spreadsheet program for the TI-99j4A


computer with Extended BASIC. Electronic spreadsh eets, use-
ful and popular programs, allow the user to answer a mul-
titude of "what if" questions in areas such as budgeting, sales
projections, cost estimating, scheduling, and more.
Spreadsheets allow you to enter a set of values and
calculation rules for a given application, such as budgeting.
The program will then calculate the projections, estimates, to-
tals, or whatever, based on the calculation rules. Changing one
or more of the original values results in a complete recalcula-
tion of the figures. The special utility of spreadsheet programs
lies in their ability to do, in a few seconds, what a human-
with pencil, paper, and calculator-would need hours, or even
days, to do.
Program Requirements
Before explaining how to use TIcalc, let's establish the ground
rules for the program. First, it requires at least a 16K TI-99J4A
with Extended BASIC. Although the TIcalc spreadsheet is 26
rows by 14 columns, with 16K of memory built into the TI
console, you are limited to roughly 150 " slots." For example,
you could ha ve a spreadsheet that is 12 X 12, 15 X 10,
20 X 7, or 10 X 14. You will find this adequate for almost all
applications. Those of you who have the 32K memory expan-
sion can use the complete 26 X 14 spreadsheet. When using
the program, you should leave the ALPHA WCK key
depressed.
Spreadsheets can be saved and loaded from tape. If you
have a disk drive, you can change the OPEN statements in
lines 1950 and 2000 accordingly. The use of a printer is op-
tional, but the program does provide the option of making a
printout of your results.

84
_ _ _ _ _ _ Applications

The TlcaJc spreadsheet is 26 rows by 14 columns (see Fig-


ure I). The rows of the spreadsheet are defined by the letters
A-Z. The columns are defined by A-N. Note that any slot in
the spreadsheet is referred to by row and column. For ex-
ample, slot CD would be the entry at row 3, column 4; AF
would be row 1, column 6. It's important that you keep this
sequence in mind.
The TI-99/4A is not capable of displaying the entire 26 X
14 array. What will appear on your screen is a 10 X 3 "win-
dow" on the spreadsheet. Just as looking into different win-
dows of a house shows different things, the computer's
window shows different "views" of the spreadsheet, depend-
ing on where the window is positioned. A window's position
is defined by its top-left slot. Looking again at Figure 1, notice
that the shaded area marked A is the 10 by 3 spreadsheet
window at AA (remember, row and column). The shaded area
marked B is the window at IH. By moving the window, the
entire 364-slot spreadsheet is accessible 30 slots (a window) at
a time.
The best way to demonstrate Tlcalc is by example. You
should spend a few minutes getting acquainted with the com-
mand summary shown in Table 1. Also, you might want to
examine the list of major program variables shown in Table 2.
The following paragraph will detail a somewhat simplistic sce-
nario for our demonstration.

Starting a Business
We are starting a small manufacturing business and want to
estimate our net profit or loss for the first four months. We are
anticipating sales of $2,700 the first month and a 10 percent
growth rate for each succeeding month. Space is being leased
for $800 a month, and there are two employees making a total
of $1,200 a month. Cost for materials is based on sales and is
expected to be 30 percent, while utilities are expected to run at
roughly 5 percent of sales.
When the program begins, it displays the window with a
HOME position of AA. That is, it is displaying rows A through
J and columns A, B, and C. The COMMAND -> prompt is
displayed, and the program is awaiting your reply. Since the
first thing we want to do is enter spreadsheet data, reply IN-
SERT. This places the cursor (actually two sprites at line 860)
at the top-left slot in the window, in this case AA. The prompt

85
Applications _ _ _ __

Figure 1: Windows on the Spreadsheet


AB C D E F G HI J K L M N
A
B v
C
D
V
E LA
F V
G
H V
I V
J /
K
L i/
M
N ~
o /
p
/
Q
R
5
T
U
V
W
X
y
Z

asks for an INSERT COMMAND? Figure 2 shows the data we


plan to enter (refer to it as we go along). As you can see, there
isn't any data for AA, so we press X(!) to move the cursor
down to CA.
At this point we want to place the label SALES in the CA
slot, so we press L The prompt then asks us what the label is
and we type SALES. When we press ENTER, the label is
placed in CA. We then press X(!) again to get to DA and enter
the label RENT. Continue this for all the labels in column A.
Then use the arrow keys (rea lly E, 5, D, and X) to place the
cursor at AS, where you enter the label JANUARY. Then
move the cursor down to CS.
86
_ _ _ _ _ _ Applications

This slot is to be the amount of OUT first month 's sales, so


press N for numeric value. The prompt asks for the number;
respond 2700 and press ENTER. Do the same for RENT at DB
and SALARY at EB. At FB we come to the first calculation, so
press C. Remember that material costs are expected to be 30
percent of monthly sales. Therefore, we need to multiply
SALES by .30. The .30 will have to be stored as a value in a
" workfield " outside the main body of the spreadsheet. We will
arbitrarily make this BJ and make a note to ourselves to add
the value after finishing the main portion of the spreadsheet.
So, the calculation becomes JANUARY SALES «(B)".30(B)) or
CB*BJ. Refer to Table 3 for examples of valid calculations. An
error detection routine enforces valid syntax.
We then position the cursor at GB, which is January util-
ity costs. This is similar to material costs, and we make a note
to store the 5 percent figure at q. Press C and then enter
CS-CJ. The cursor is then positioned at IB, which is the slot
for total January expenses. This is again a calculation, so press
C. Enter the calculation command SUMCOLDG, which means
sum this column starting at row D (RENT) and ending with
row G (UTILITY) and place the result in this slot. The cursor
is then placed at JB, which is the NET PROFIT fLOSS for
January. This is simply SALES «(B) minus TOTAL
EXPENSES(IB) or (B - IB.
Next, position the cursor at AC and enter the February la -
bel. When you position the cursor at February SALES, you'll
see that you no longer have a number, but rather a calcula-
tion. Sales are assumed to be 10 percent greater than each pre-
vious month, so make a note to store 1.10 at AJ and enter the
calculation CS-A], which is January SALES-LID. The remain-
der of the column is entered in a manner similar to the entries
for January, adjusting for the proper row/column designators.
At this point, all the slots for the window being displayed
have been entered, so you'll need to move the window. First
press Q to exit from INSERT mode. When the command
prompt is displayed, enter HOME and press ENTER. When
asked for row and column, enter AD. The window will be
moved to view rows A through J, columns D, E, and F. Type
INSERT and press ENTER to get back into INSERT mode. The
columns for March and April can now be entered as were the
columns for January and February. Column F, the total col -
umns of the calculation, is a little different. The SUMROWBE

87
~
~ Figure 2. Example Spreadsheet
A 8 c o , p G H
~;;.
A JANUA RY FEBRUA.RY MARCH AP RIL ·TOTAL· 1.10
'" SALES
•::-.
o
8 .., o
~

C SALES CS"" ! ceo"J CO'AI SUMROWBE .OS

o
"'" .., .., SUMROW8E Cf ~OF
"NT
, SALA RY
"" SUM ROWB E CF~Ef
"00
"'" ''''
.."'"
P MATERIAL CooSI ceo III CooSI CE' SI SUMRDW8E CF"'FF
G UTILITY CR'q eeoq eooq eEoq SUMROWBE CF'IIoGf

SUMCOLDG SUMCOLDG SUMCOlDC CF"'lf


" " EX. SUMCOlDG SUMCOlDG
NET +/ - C8- IS eC- le eO- ID CE-IE CF- If CF 'IIoJF


)
_ _ _ _ _ _ Applications

command tells TlcaJc to total the row starting at column B


Qanuary) and ending at col umn E (April), and place the result
in the cu rrent slot.
We have again fill ed the window being displayed, so
press Q to exit INSERT mode. Typing the HOME command
and then AG gives us slot AG in the top left of the screen.
Type INSERT again and enter the calculation rules to give
each expense, the total expense, and net as a percent of sales.
Finally, exit (Q), HOME o n AI, INSERT, and enter the
workfield values for AI, BJ, and q. Type Q to get back to
command mode. At this point, you've completed your work-
ing copy (MODEl) of the spreadsheet.

Procedures
Now you can use the CALC command to calculate the result
of the working copy. The calculation will take anywhere from
a few seconds to a few minutes, depending on the size of the
working copy and the number of calculations. When the
calculation is complete, the program will automatically go into
MODE2 and set the HOME row and column to AA. You can
then view the results by moving the window, using the
HOME command. Figure 3 shows the results from the sample.
If you want to see the calcu lation that gave a particular result,
you can type MODEl to see the original working copy as
shown in Figure 2. Typing MODE2 will return you to the " re-
sult copy." This is particularly useful in finding errors.
Figure 3. Printout of Example Worksheet
Results
JANUARY FEBRUARY MARCH APRIL -TOTAL- '" SALES
SALES 2700 2970 3267 3593.7 12530.7
RENT 800 800 SOO 800 3200 25.53
SALARY 1200 1200 1200 1200 4800 38.3
MATERIAL 810 891 980.1 1078.11 3759.21 30
UTILITY 135 148.5 163.35 179.68 626.53 4.99
TOT EXP 2945 3039.5 3143.45 3257.79 12385.74 98.84
NET +j - - 245 - 69.5 123.55 335.91 144.96 1.15

The Dalsychaln Effect


Anytime Tlcalc encounters a calculation it cannot complete
when in its calculation mode, it will fill the current slot with
all •. This kind of error is usually caused by one of two con-
ditions. The first is when a calculation refers to a slot which is
not defined as a number or calculation. For example, if our

89
Applications ______

sample had a calculation CB· AH, the resu lt would be an error


because slot AH has no value. If a slot contained a label, the
same error would occur. The second type of error occurs when
a current calculation points to a slot that contains a calculation
which previously contained an error. In this case, the current
calculation is correct, but the calculation it refers to must be
corrected. This type of error tends to have a daisychain effect.
All calculations are taken to a maximum of two decimal
places. There is no provision for rounding. Also, all calcula-
tions are carried out in row Jcolumn sequence. That is, AA is
processed first, then AB, AC, AD, then BA, BB, BC, and BD.
This is very important to understand since errors will be gen-
erated if you re ference a slot which has not yet been pro-
cessed. For example, if slot AC contains the calculation
AB·BC, an error will occur since BC has not yet been pro-
cessed. Thus, the selection of AJ, BJ, and CJ for workfields is
not as arbitrary as it first appears.
Printing and Saving
You can print the result of the calcu lation by using the PRINT
command. It will print all rows for the beginning and ending
columns you specify. Figure 3 was produced by PRINTing for
columns A through G. You may have to adjust the OPEN
command at line 2070 for your particular printer.
You may save a spreadsheet or load one from tape. Note
that if you load a spreadsheet from tape, only the working
copy is loaded. You will have to issue the CALC command to
compute a result copy.
The usefulness of Tlcalc may be demonstrated by using
our sample. If. after the fi rst month, there were any deviations
from the assumptions made at the outset, or if you wanted to
see what a higher or lower sales figure would do, you would
merely need to change the desired variable(s) and recalculate.
Table I. T1calc Command Summary
Command Action
HOME Aligns the TIcalc window to the desired row/column.
INSERT Places TIcalc in INSERT mode; defaults to MODE 1 (see
subcommands below).
MODEl Displays the working copy; automatic for INSERT.
MODE2 Displays the result copy; automatic after CALC
command.

90
_ _ _ _ _ _ Applications

CALC Calculates the results for the values and calcu lations in
the working copy; invokes MODE2 at completion.
LOAD Load a spreadsheet from tape.
SAVE Save a spreadsheet to tape.
PRINT Print spreadsheet.

lNSERT Subcommands
Subcommands Action
.,5) Move cursor left .
-(D) Move cursor right.
HE) Move cursor up.
I (X) Move cursor down.
L Indicates a label is to be placed in the current cursor
position.
N Indicates a numeric value is to be placed in the CUT ·
rent cursor position.
C Indicates a calculation is to be placed in the current
cursor position.
Q Quit; return to command mode.

Table 2. Major Program Variables


Variable V,.
AS(r,c) Working copy array
B$(r,c) Result copy array
COMM$ Command entered
ROW Row shown at top left of window
COL Column shown at top left of window
RCS A through 2 values
MODE MODEl or MODE2 indicator
LOCS Row/column desired by HOME command
R Loop control-row
C Loop control-column
X Row DISPLAY AT position
Y Column DISPLAY AT position
SR Cursor row position
SC Cursor column position
L$ Label entered
N$ Number entered
C$ Calculation entered
RM Highest row number used
CM Highest column number used
RLiM Row limit for display window
CLiM Column limit for display window

91
Applications _ _ _ _ __

Table J . Valid Tlcalc: Calc:ulatlons


OPERATORS +'-:'/'%
SUMROWXY Where X is the beginning column and Y is the end-
ing column
SUMCOLXY Where X is the beginning row and Y is the ending
<ow

Examples
AB·CG
AL - AI
EF + AH
BC/CA
AB +CB·BC
AB + CB + CA Processed left to right
CB/AB -CH
SUMROWCF
SUMCOLAH

Tlcalc:
1121121 DIM A$(26.14),B$(26,14)
110 CALL CHAR(96."FFFFFFFFFFFFFFFF"):: CALL
COLOR(9,13,1)
129 ROW=l : : COL=1 : : RLIM=19 :: CL IM =3
130 Rcs="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
149 CALL CHAR(104,"FFFFEI2IE0E0E0FFFF"):: CALL
CHAR(10S."FFFF07070707FFFF"):: CALL CO L
OR ( 10. 7, 1 )
150 CALL CLEAR :: CALL SCREEN(9)
160 DISPLAY AT(S, 7): "E A S Y CAL C" :: DIS
PLAY AT(9.9): "ELECTRONIC" :: DISPLAY AT(
11,9):"SPREADSHEET"
170 FOR DELAY=1 TO 2000 :: NEXT DELAY
180 CALL CLEAR:: CALL SCREENCS)
199 CALL HCHAR(4, 3 .96. 29)
290 CALL VCHAR(S,4.96, 19)
210 CALL VCHAR(S, 1 3,96, 19)
220 CALL VCHAR(S,22,96, 19)
230 GOSUe 349 : : MODE=1
2 40 DISPLAY AT(I,l):"COMMAND: --- ) " :: ACeEP
T AT(1,lS)SIZE(6)BEEP:COMM$
25121 IF SEG S(COMMS ,l,4)="HO ME" THEN 41121
26121 IF SEGS(CO MMS.l, 6)="I NSERT" THEN 72121
279 IF SEGS(COM MS.l. S) - "MODEl" THEN GOSUS 52
9 :: GOTO 249
280 IF SEGS(COMMS, l,S)="MODE2" THEN GOSUe 62
" :: GOTO 240

92
_ _ _ _ _ _ Applications

290 IF SEG$(COMMS,l,4) = "CALC" T H EN 1370


300 I F SEG$(COMMS.l,4)="SAVE" T HEN 1950
310 IF SEG$(CO MMS , l,4l="LOAO" T HEN 2000
320 IF SEG$(COMMS,l , S'="PRINT" THEN 2050
330 GOTD 240
34@ FOR LOOP =2 TO 2 0 STEP 2
3 50 DISPLAY AT(3+LOOP. 1 ) : 5EGS(RCS,RO W+(LOOPI
2)-1 .• 1),
36 0 NEXT LOOP
37 0 FOR LOOP =6 TO 26 STEP 9
3 80 DISPLAY AT( 3 .LOQP) : SEG$(RCS,COL- i +(LOOPI
8) , t )
39121 NEXT LOOP
400 RETURN
41121 DISPLAY AT(J . l ) :"RQW/COL --- ) •• " : : ACe
EPT AT(1,14)VALIDATE(RCS)SIZE(-2)BEEP : LD
C$
420 IF SEG$CLOC.,2 , 1) - " . " THEN 410
4 30 IF SEG.CLOC$,2, l ' ) " N N T HEN 410
440 RQW =( AS C(S EG$(LO C S, 1 .. 1 » - 6 4 ) : : IF RO W > 17
THEN RO W- I ?
450 RlIM=ROW+9
46121 COL - (ASe (SEGS ( LO C S , 2, 1 ) ) - 64) : : 1F COL > 12
THE N COL=12
470 CLIM =C OL+2
48e GOSUB 3 40
490 IF MODE = l THEN GOSUB 520
5e0 IF MODE:2 THEN GOSUB 620
510 GO TO 24e
520 X=5 :: FOR R= RO W TO RLI M
530 Y=3
540 FOR C=COL TO CLI M
550 DISPLAY AT(X,Y): " {9 SPACES}";
560 DISPLAY AT(X,Y);SEGS(AS(R ,C) . 3 .8).
570 Y=Y+9
580 NEXT C
590 X:::X+2
600 NEXT R
610 MODE = l : ; RETUR N
620 X=5 FOR R= RO W TO RLIM
630 Y=3
640 FOR C=COL TO CLIM
650 DISPLAY AT(X,Y) :" {8 SPACES}":
660 DISPLAY AT(X,Y) : BS(R. C> :
670 Y=Y+9
680 NEXT C
690 X=X+2
7 013 NEXT R
710 MODE =2 : : RETURN

93
Applications _ _ _ _ __

720 IF MODE=2 THEN GOSUB 52121


73121 SR=32 :: SC=32 •• R=ROW :: C=COL .. X=5
Y=3
74. GOSUB Bbe
75. DISPLAY ATel.l}:"INSERT COM MAND ?" CAL
L SOUND(200.1100,4)
7 •• CALL KEYe3,KEY,STATUS):: IF STATUS=12I THE
N 7bl2l
77. IF KEY=7b THEN BB.
7BO IF KEY=7B THEN 93.
79. IF KEY=b7 THEN 11213121
BOO IF KEY=81 THEN CALL DELSPRITE(ALL):: GOT
0 240
Bl0 IF KEY=83 THEN 1 2 5121
B20 IF KEY=6B THEN 128121
B3. IF KEY""69 THEN 1 3 1121
B40 IF KEY=BB THEN 134121
BSO GO TO 75.
8be CALL SPRITE(*l,I1214,7,SR,SC,I2I,0,*2,l~5,7,
SR,SC+Sb,0.0)
B70 RETURN
BB0 DISPLAY AT(I,l):"LABEL: ---) " :: ACCEPT
ATel,13)S]ZEeB)BEEP:LS
890 DISPLAY ATeX.Y):LS;
91219 ASeR,C)="L:"~Ls
91121 RM=MAX(RM,R):: CM= MAxeCM ,C)
92121 GO TO 749
93121 DISPLAY ATel,I):"NUMBER: ---> " :: ACCEPT
ATel,14)SIZEe8)VALIDATEe"01234S67B9.-+"
lBEEP:NS
949 WS="" .. W=12I
95121 FOR Z= 8 TO 1 STEP - 1
9bl2l IF SEG$eNS,Z,l) <) "" THEN W$ =SEGSeNS,Z,I)
~ W$ ELSE W=W+l

97121 NEXT Z
98121 WS = RPTSe" ".W)~W$
99121 DISPLAY ATeX,Y):W$;
Ieee AS(R.C) = "N:"~WS
11211121 RM = MAxeRM,R):: CM=MAxeCM,C)
11212121 GOTO 74121
1121 3 121 DISPLAY ATel,I):"CALCULATION: ---) " ::
ACCEPT AT(I,19)SIZE(B)BEEP:C$
11214121 IF SEGSeCS,I,6):"SUHROW" THEN 119121
11215121 IF SEGS(CS, l.b)="SUMCOL" THEN 119121
11216121 AAS=SEGS(C$,3,1)
11217121 IF AAS="+" OR AAS=" - " OR AA$="." OR AA$
- "/" OR AAS - "X" THEN 11219121

94
_______ Applications

1980 DISPLAY AT (1. 1) : " ...... ERROR ...... " •• FOR

.3.
DELAY:::} TO 1200 :: NEXT DELAV .. GOTO 1

1090 AAf,=SEGf,(CS,l,l):: IF AAf, < "A" OR AA$)"Z


" THEN 112180
1100 AAf,=SEGS(Cs,2 , 1);; IF AAs{"A" OR AA$}"N
" THEN 1080
1110 AAf,=SEGS(CS,4.1):: IF AA$ ( "A" OR AAS)"Z
THEN 108121
"
1120 AAs=SEGS(Cs,5,1):: IF AASC"A" OR AAS)"N
" THEN 112180
1130 AAf,:::SEGf,(CS,b,l)
1140 IF CAAS::: .... OR AA$-" ")ANDISEGs(CS,7,2)(
>" .. AND SEGf,(Cs,7,2) <> " ")THEN 1080
1150 IF AA$= .... OR AA$=" .. THEN 1 210
1160 IF AAf,="+" OR AA$="-" OR AA$="'" OR AA$
="/" OR AAs="Z" THEN 1170 ELSE 1080
1170 AAS=SEGS(CS,7,1):: IF AAS C "A" OR AAS ) "Z
" THEN 1080
1180 AAS=SE6f,(CS,8,1):: IF AAS C "A" OR AAs )" N
.. THEN 111'80
1190 IF SEGS(CS,4,3):::"RDW" THEN IF SEGS(CS,7
,llC"A" OR SEG$(CS.7,1»HN~ OR SEGS(CS,
8,1) ( "A~ OR SEGS(CS.8.1»"N~ THEN 1080
1200 IF SEGS(CS.4,3):"COL" THEN IF SEGS(CS,7
.1) ( "A" OR SEGS(CS,7,l»"Z" OR SEGS(CS.
8.1)("A~ OR SEGS(CS.8,l»"Z" THEN 1080
1210 DISPLAV AT(~.V):CS;
1220 AS(R,C):"C:~~CS
1230 RM:MAX (RM,R):: CM=MAX (CM,C)
1240 GOTO 740
1250 IF SC-72(32 OR C - 1 ( 1 THEN 750
1260 SC=SC-72 :: C=C-l V=Y-9
1270 GOTO 740
12Bi'J IF SC+72)176 OR C+l ) 26 THEN 750
1290 SC=SC+72 :: C=C+l Y=Y+9
1300 GOTO 740
1310 IF SR-16 (3 2 OR R-l( l THEN 750
1320 SR=SR-16 :: R;R - l :: X=X-2
1330 GOTO 740
1 340 IF SR+16)176 OR R+l)26 THEN 7S.
1350 SR:SR+16 :: R:R+l :: X=X+2
1 360 GOTO 740
137i'J DISPLAY AT(l,I':"CALCULATION IN PROGRES
S"
1380 FOR R=l TO RM
1390 FOR C:l TO CM

95
Applications _ _ _ _ __

14(l1(l1 IF SEG$CA$CR,C),l,2)="L: " OR SEG$(A$CR,


C),1,2)::"N:" THEN B$CR,C)=SEGS(A$(R,C),
3,8)
1410 IF SEGS(ASCR,C),1,2)="C:" THEN GOSUB 14
70
142121 NEXT C
1430 DISPLAY AT(I,25):R
1440 NEXT R
1450 MODE =2 :: LOCS="AA"
1460 GOTO 440'
1470 IF SEGs (AS CR, C), 3, 3) ="SU M" THEN 17 7'll
148(l1 Rl=ASC(SEGs(A$(R.C), 3 ,1» -6 4 . . CI=ASCC
SEG$(AS(R,Cl,4,1»-64
149(l1 R2=ASCCSEGS(A$(R,C),6,1») - 64 :: C2=ASC(
SEGS(AS(R,C),7,1) ) - 64
150(l1 IF SEG$(A$(R,C),9, 1»="A" THEN R3=ASC(S
EG$(AS(R,C),9,l)} - 64 :: C3=ASC(SEGs(AS(
R,C) ,10,1) )-64
151(l1 IF SEG$(AS(RI,Cl),I,2) (> "N:" AND SEGS(A
S(Rl,Cl),l,2} <> "C:" THEN BSCR,C)="aa,aa
aaa" :: RETURN
152(l1 IF SEG$(A$CR2,C2) , l,2)< > "N:" AND SEGS(A
SCR2,C2),l,2) <> "C:" THEN BS(R,c) ="aaaaa
aa," .. RETURN
1530 IF SEGS(ASCR,C),9,l) ( "A" THEN 15S0
1540 IF SEGS(AS(R3,C3),l,2) <> "N:" AND SEGSCA
S(R3,C3),l,2) <> " C: " THEN BSCR,c)="a,aa.
aaa" . . RETURN
1550 ON ERROR 1920
1560 Wl=VALCBS(Rl,Cl»:: W2=VALCB$CR2,C2»::
IF SEG$(A$eR,C),9 , l»"A" THEN W3=VAL(B
$(R3,C3»
157(l1 W4=0 :: FS=CAseR,C»
158(l1 IF SEGS(FS.5,1)="+" THEN W4 = WI+W2
IS9(l1 IF SEGS(FS,5,1)= " - " THEN W4 =WI- W2
16PI1'I IF SEGS(FS,5.1) = "a" THEN W4::WlaW2
1610 IF SEGS(FS,S,1J= /" THEN W4=Wl/W2
162111 IF SEGS(FS,S,t}= X" THEN W4 =W2/ WlaU'l0
1630 IF SEGS(FS,B,I} = +" THEN W4=W4+W 3
1640 IF SEGS(FS,8,1) = THEN W4=W4 - W3
165121 IF SEG$(FS,B,l) = a" THEN W4 = W4aW3
1660 IF SEGS(FS,8,l)= /" THEN W4=W4 / W3
167111 IF SEG$(FS , 8,t)= X" THEN W4 = W3/ W4tt00
1680 IF INT(W4) <> W4 THEN W4 = INT CW4a100) /112I0
1690 RS=STRs (W4):: WS="" •• W=0
1700 FOR Z=8 TO 1 STEP - 1
1710 IF SEGS(RS,Z,l) <> " " THEN WS=SEGS(RS,Z,l
)&WS ELSE W= W+l
172121 NEXT Z

96
_ _ _ _ _ _ Applications

1730 W$=RPT$(" ~.W) ~W$


1 740 B$(R,C)=WS
1750 ON ERROR STOP
1760 RETURN
1770 IF SEG$(ASCR,C),6,3)="RQW " THEN 1809
178£'1 IF SEGSCASCR,C),6,3):"COL " THEN 1960
179" RETURN
1800 11.14=0 : : ON ERROR 1920
1810 V=ASC(SEGSCASCR,C),9, I ) ) - 64 W=ASC(SE
GS (AS (R. C) • 121. 1) ) - 64
1820 FOR Z-V TO W
1830 IF SEGS(AS(R,Z),l,2)=" N: " OR SEGSCAS(R,
Z),l,21="C:" THEN W4=W4+VALCBSCR,Z»
1840 NEXT Z
1850 GOTO 1680
1860 11.14 =0 :: ON ERROR 1920
1870 V=ASC(SEGS(AS(R,C),9,1»-b4 .. W:ASC(SE
GS (AS (R. C) • 10. 1) ) - 64
1880 FOR Z=V TO W
1890 IF SEG$(AS(Z,C),l,2)="N:" OR SEGSCAS(Z,
CI,l,2>="C:" THEN W4=W4+VAL(BS(Z,C»
1900 NEXT Z
1910 GOTO IbBI't'I
1920 B$(R,C)=" • • • • • • • • •
1930 RETURN 194"
1940 RETURN
1950 CALL CLEAR : : OPEN *1:"CS1·,OUTPUT,INTE
RNAL,FIXED 192
1960 PRINT *1:CM;RM
1971t'J FOR 2=1 TO RM
1980 PRINT *1: A$ (2,1) ;A$ (2,2); A$ (2, 3) j A$ (2, 4
) ;A$(Z,S) ;A$(Z,6) ;A$(2,7) ;A$(Z,8) jA$(2,
9) ; A$ <Z • un ; A$ ( Z , 1 1 ) ; A$ (Z , 12) ; A$ (Z, 13) ;
A$(Z,14)
1990 NEXT Z •. CLOSE *1 .• GOTO 180
2011.'10 CALL CLEAR: : OPEN *1:"CS1",INPUT ,INTE
RNAL,FIXED 192
2010 INPUT ttl:CM,RM
2820 FOR Z.:1 TO RM
2030 INPUT ttl :A$ (Z, 1), A$ (Z, 2), A$ (Z, 3), A$ (Z, 4
) , A$ ( Z , 5) , A$ ( Z , 6) , A$ ( Z, 7) , A$ ( Z , 8) , A$ ( Z ,
9) ,A$ (Z. 10) I A$ (Z, 11 ) , AS (Z , 12) • AS (Z, 13) ,
A$(Z,14)
2940 NEXT Z .• CLOSE .. 1 : : GOTO 180
295121 DISPLAV AT(I,I): "B EGIN/END COLUMN
ACCEPT AT(l,18)SIZEC-2)BEEP : C$
2060 IF SEG$(C$,l,I) ( "A " OR SEG$(CS,I,l»"Z"
OR SEG$(CS,2,l) ( "A" OR SEGS(C$,2,l»"N
• THEN 2051't'1

97
Applications _______

2676 OPEN .2:·RS2 32 · ~O UTPUT.DIS PLAY


2680 I:::ASCCSEGS,CCS,,1!1» - 64;: J:::ASC(SEGS,CCS,
,2,1) - 64
2090 FOR L ::: l TO RM
2100 FOR M= I TO J
21 10 P$ = RPT$(" ",10 - LEN ( B$(L.M)))LB$(L,M)
2 1 26 PRI NT . 2:PS ;
2130 NE XT M
2140 PRINT . 2 : · .. PRINT .2:· •
2 150 NE XT L
2166 CLOSE .2
2 1 76 GOTO 240

98
Financial Interests
- - - - - Doug Hapeman

Interest rafes can be a disappointment or a pleasQnt surprise


if you are payi1lg interest on a loan or eaming illterest on
your savings. "Fhlancial llllerests" can help you make sense
of such mysteries as amortization and compound interest
before you sign on that bottom line. You'll also team a few
things about finance ill general. For the Tl·99/4A, witll Ex-
tended BASIC, and 16K memory.

"Financial Interests" allows you to calculate both the va lue of


investments and the cost of borrowing.
You may be considering a savings investment fund. This
program helps you examine savings and annuities with vari-
OllS compound periods and rates, Jetting you see the future
value of your money. Or, if you're considering a loan, you can
weigh the options of various amounts, rates, and amortization
periods, and then choose the best alternative.
Simple and Compound Interes t
To understand finance, you must grasp the idea of i"terest.
There are two types: simple (or fixed) interest and compound
interest.
For instance, if you borrowed $1000 and agreed to repay
it with 12 percent interest, you would repay the principal
amount ($1000) plus the 12 percent ($120)-regardless of the
length of the repayment period. However, if you agreed to re-
pay the loan at 12 percent per annum, the loan has compound
interest. Now, 12 percent interest will be added onto the
outstanding debt each year during the repayment perio~.
The more frequent the compounding, the more costly to
the borrower. Today, most banks compound the interest
monthly on personal loans for cars, household items, vaca-
tions, etc.
For once, wouldn't it be nice to sit down with the loan
officer in the bank and know what your options are before
you sign on the dotted line? One of the frustrating things
about negotiating a loan is having to make a decision when
you don't fully understand all the options.

99
Applications _ _ _ _ __

For instance, when you're buying a new car, contrasting


the differences between a 36-month and a 48 -month repay-
ment period can be helpful. How will the different periods
affect the size of the monthly payment? How much more in-
terest is paid in a 48 -month amortization than in a 36-month
period? What portion of each monthl y payment is for interest?
For principal?
This program, Financial Interests, will help you examine
all those options and will even print them out on paper for
you. The calculations used in the program are based on the
assumption that the interest is compounded monthly and that
payments will be made monthl y.
The Dead Pledge
The word mortgage comes from two French words, mort (dead)
and gage (pledge). The pledge becomes dead when the loan is
paid off. To amortize means to deaden. To amortize a mort-
gage or a loan is to extinguish it by means of a "sinking
fund"-a series of payments over a period of time which will
reduce the debt to zero.
By the way, a mortgage deed is sometimes called an
j,ldenture. The word simply means an agreement between two
or more parties, but its etymology is pretty interesting.
Many years ago, (before carbon paper and photocopiers)
such an agreement would be penned in two original copies.
The copies would be placed evenly, one on top of the other. A
wavy line, or indentation, would literally be cut along one side
of the copies. Each party would then receive one of the
papers. When the two were later placed together, the wavy
cutting would match. Thus, authenticity was established. The
indentation matched.
Loans Vs. Mortgages
Everyone knows the difference between a loan and a mort-
gage, right? They're the same thing except you amortize a
mortgage over a longer period, such as a 20- or 30-year
period? No. Most personal loans compound the interest
monthly, but the Federal Interest Act (in Canada) requires
that, for a mortgage, interest can only be "calculated half-
yearly, or yearly, not in advance." Therefore, the primary dif-
ference between a mortgage and a loan is that mortgage
interest cannot be compounded as frequently, which means

100
_ _ _ _ _ _ Applications

lower payments. Of course, there are other differences: Mort-


gages usually offer much lower interest rates, they have stiff
penalties for paying against the principal in advance, and they
require the involvement and expense of a lawyer.
Financial Interests calculates mortgage payments on the
assumption that the interest is compounded semiannually, not
in advance. If you compare the figures from Financial Interests
with the figures from a mortgage interest guidebook, you may
find the figures vary sligh tly. This is because th e 13-digit ac-
curacy of the 99/4A gives a more exact calculation than most
guidebooks.
No More Than a Million
When either the Loans analysis or the Mortgage analysis is
chosen, the program first asks the size of the loan you are
considering. The program wi ll accept amounts up to, but not
including, one million dollars. If you are considering more
than that, adjust the program to accept larger amounts by
changing the SIZE variable of the ACCEPT statement in line
420. Second, you are asked the annual interest rate, and third,
the length of the loan in months. The information is then cal-
culated and the screen displays the monthly payment needed
to payoff the principal during the life of the loan.
At this point, you are given two options: a month-by-
month analysis of the loan, or return to the main index. When
you choose the analysis, you are asked whether you would
like the amortization schedule printed. If yes, the printer
configuration is requested. The printout shows the current
state of the loan after each payment. The information includes
the month number, the monthly payment, the month ly in-
terest and principal, the remaining balance, total interest to
date, and total payments to date.
When the printer is bypassed, the monitor screen displays
one month at a time, and you can proceed month by month
by pressing any key other than M or T. Pressing M permits
you to jump ahead to an y month you select, and pressing T
jumps to the final breakdown totals following the last
payment.

Savincs Analysis
The Savings analysis lets you examine a combination of two
investment procedures: investments (the fu ture value of a

101
Applications ______

one-time deposit) and annuities (the future value of regular


deposits).
The Savings option first asks for the present amount in
your savings account, then the rate of interest and the number
of compound periods per year. Following th is, you are asked
whether you wish to make regular deposits, and if so, how
often and how much. From there the calculations are per-
formed and displayed, showing the beginning principal, the
total deposits, the accumulated balance, and the total interest.
Analysis is displayed on a yearly basis with the option of
returning to the main menu at any time.
The two procedures, annuities and investments, can be
analyzed in conjunction with each other, or individually. If
you wish to examine just the future growth of a one-time
investment, press N (No) in response to the question " Make
regular deposits?" Calculations will then be made based solely
on the future growth of a single deposit over a designated pe-
riod of time. The growth of this fund depends upon the in -
terest paid. The interest is compounded each period. This is
interest earned on interest.
If you wish to analyze only an annuity, enter 0 in re-
sponse to " Present amount in savings:", and then continue
with the remaining information. This will give you calcula-
tions for the future growth of a regular contribution to an
annuity fund, that is, the regular periodic investment, plus in-
terest earned on the interest and on the continuing
investment.
These investment factors are all based on the assumption
that no funds will be withdrawn throughout the investment
period.
For Formula Buffs
In case you want to know how it is done or would like to
work it out the hard way, here are the formulae:
Compound Savings (Investment)
5 - Aml"(1+ I)"N

Amt = Amount deposited


5 = The future value of amount deposited
I = Interest rate per period
N - Number of compounding periods

102
______ Applications

Annuities
5 = Am t>lo(1+ lrN) - l

Amt = Amou nt deposited per period


5 = The future value of amount deposited per period
I = Interest ra te per period
N = Number of compounding periods
Loan Payments
FR ~ (1+R/ 1200) - 1

Amt·FR
5 ~ 1- (I /1+FRrN)
FR = Loa n amortization factor
R = Annual interest rate
5 = The monthly payment
Amt = Amou nt to be borrowed
N = Length of loans in months
Mortgage Payments
FR ~ «1+ R/200)( 1/6)) - 1

Amt·FR
5 - 1- (1/«1 +FRrN))
FR = Mortgage amortization factor
R = Annual interest rate
5 = The monthly payment
Amt = A mount to be borrowed
N = Length of mortgage in months
Program Outline
l00- JOO Initialization and title screen
310-340 Main menu
350-360 Finish session
370-430 Get loan and mortgage information
440-510 Calculate and display monthly payment
520-560 Month-by-month analysis
570- 630 Analysis calcu lations
640- 680 Print amortization schedule
690-790 Display calculations
800-900 Get savings in formation
910- 940 Savings analysis
950- 970 Analysis calculations
980- 1020 Display calculations
103
Applications _ _ _ _ __

Main Program Variables


Title Screen Variables
V = Vertical sprite motion
-
H = Horizonta l sprite motion
R = Dot-row sprite location
C = Dot-column sprite location
RR = Row-character position
CC = Column-character position
J ~ Flag
Loan and Mortgage Calculation Variables
AMT = Beginning principal
R = Annual interest rate
M = Months in length of loan
FR = Working factor for mortgage and loan amortization
PA = Monthly payment
TP = Total payments
IN = Interest
TI = Total interest
BA = Remaining balance

Savings Calculation Variables


AMT = Amount in savings
R = Annual interest rate
C = Number of com pound periods
o = Amount of deposits
NO - Number of deposits
Y = Number of years in analysis
CP = Interest rate per compound period
B = Future value of amount in savings
MA = Working variable for annuity
DE = Working variable for annuity
BP = Future va lue of annuity
TO = Total amount of deposits
BA = Accumu lated balance
TI = Tota l interest

Financ:ial Interest
100 REM " FINANCIA L INTERE S TS *'
110 REM EXTENDED BASI C RE QUIRED
120 DIM A(S )
130 CAL L CLEA R
140 REM ttt***' I NITIA L I ZATION L TITLE SCREEN
*'*""
104
_ _ _ _ _ _ Applications

150 FOR 1 = 0 TO 10 :: READ cs :: B<J;(I)::C$


CALL COLOR(1.2,B) : : NEXT 1
160 FOR 1 =9 TO 14 •• C ALL C OLOReI,I,I) : : NEX
T I .. CALL VCHAR(1,31. 120,96); : CAL L se

- 170 C=96
REEN( 1 2)

"9. ::
••
X= 1 2
X=8
::
y-", 10
Y= 14
..
GOSUB
GOSUB 190
180 ::
C = 12
GOTO 1

180 FOR I - X TO Y . . DISPLAY ATCI, l);RPT$( C HR


S(Cl,10,;TAB(18);RPTS(CHR'l(C ) , 1 1 ' : : C=C+
8 : : NEXT I • • RETURN
19 0 FO R 1 =6 T O 16 :: DISPLAY AT(J,12 , S IZE (-'!5
) :85 ( 1 - 6) :: NE XT I
2 00 DATA" '$ .," $$$ ","$ '$ S O',us '$ S" ," '$
$ "'5" $$"
2 10 DATA "$ '$ SN,"S '$ $", " $$$ " , " '$
220 CALL SPRITE<.1 , 36,2, 1 88 . 1 20) : : CAL L MA GN
IFY( 2' : : V= - 14 :: H =- 1 3 : : R=76 . . C= 16
. . J =0 :: GOSUB 280
23 0 V=0 : : H=27 :: R=76 : : C = 2 40 :: RR=11 •.
CC=3 :: J = l . . C$="FINANCIAL{3 SPACES} $
{3 SPACES}INTERESTS· . . Gosue 280
240 J =0 : : R= 1 72 :: C=24 V= 12: H= - 27 ::
00

GOSUB 28 121
2'5121 C=256 :: V=13 o . H=27 .. RR=23 o . CC= 4 ..
J=I .. C$="tPRESS AN Y KEY TO BEGIN." ..
GOSUB 28 9
26121 CALL DEL S PRITE(#1 1
279 CALL KEY (121, K, SI :: IF S = 0 THEN 270 EL SE 3.
2.
280 CALL MOTION(#l ,V, H):: IF J=0 THEN 313121
2913 FOR 1= 1 TO LE NC CSI : : X=ASC(SEGS(CS, I , 1)
.. CALL HCHARCRR ,C C+I .X) :: NEXT t
300 CALL COINCCtH,R,C,12,1):: IF 1=9 THEN 39
9 :: CALL HOTIONC.I,e,0):: C ALL LOCATE C.
I ,R , C) :: RETURN
3 1121 REH . t • • t •• MAIN ME NU ••• t •• t
31'5 CALL VCHARCI,3,32.672):: RETURN
32121 GOSUB 3 15 : : DISPLAY ATC5,5)BEEP:"FINANC
tAL INTERESTS": :"PRESS{3 SPACES}FOR
"; : " I = LOAN ANALYSIS": :" 2
MORTGAGE ANAL-YSI S "
339 DISPLAY ATC16 , 3) :" 3 SAV ING S ANALY S I S
": : " 4 = FINISH SESSION " : : CALL KEY
( 0, K, S ):: IF K<49 OR K >52 THEN 33i!1
3 40 ON K- 4B GO TO 380,430,910,360
359 REM • • • t.t*FINISH SESSION* •• tt ••
36i!1 DISP LAY ATC14,7)ERASE ALL: "HAVE A NI CE D
AY!" STOP
37121 RE M t t t t . t t GET LOAN IN FOR MATION*ttt*t*

105
Applications ______•

380 8$(0)="THE AMOUNT OF LOAN:" :: 8S(1)="TH

..
E RATE OF INTEREST: U : : 8$(2)="LENGTH OF
LOAN IN MONTH S :" ;: GOTO 410
390 REM tt,tlttSE T MORTGAGE IN FOR MATIONttttt

4 00 8.(I1:!)=uTHE AMOUNT TO BE MORTGAGED: " :: B


'$(!) = "THE RATE OF INTERE ST: u :: 8$(2)="M
ORTGAGE LENGTH IN MONTH S: u
410 GOSUS 315 :: J=0 :: FOR I =5 TO 1 3 STEP 4
:: DISPLAY AT(I,l):B$(J):: J=J+l :: NEX
T [
420 J=0 :: FOR 1=7 TO 15 STEP 4 :: ACCEPT AT
(1,3)SIZE(6)VALIDATE(NU MERI C)BEEP :A (J) : :
J=J+l :: NEXT I :: AMT=A ( 0):: R=A(I)::
M=A(2)
430 IF K=49 THEN 470
440 REM tt,ttt'CALCULATE MORTGAGE PAYMENTttt
t t t ..
450 FR=(1+R/200) ~( 1/6) - 1 : : PA=JNT(AMTtFR/(1
-1/«I+FR)~M»t100+.5)/ 10 0 :: GOTO 490
460 REM .. t .... tt .. CALCULATE LOAN PA YMENTttttttt
470 FR=(I+R/1200) - 1 :: PA=INT«AMTtFfO/(l -( l
1(I+FR)-M»tI00+ .5 )/ 100
480 REM t t , t •• tDIS PLAY LOAN AND MORTGAGE PAY
MENTt.ttttt
490 GOSUB 315 :: DISPLAY AT(5, 3 )SEEP: "TO BOR
ROW $":AMT: :" FOR";M;"MONTHS AT";R;"'l."
: "MONTHLY PAYMENT WILL BE:"
500 DISPLAY AT(12,2):USING "~.###~.~#" : PA : :
DISPLAY AT(22,5):"tPRESS I FOR INDEXt":
"tANY OTHER KEY FOR ANALYSISt"
510 CALL KEY (0, KEY, S) :: IF S=0 THEN 510 :: I
F KEY=73 THEN 320
520 RE M tttttttMQNTH BY MONTH ANALYSIStttttt

530 GOSUB 315 :: DISPLAY AT(l,7 ) :"MONTHLY AN
ALYSIS": : " (7 SPACES}DO YOU WISH TO":"
PRINT THE AMORTIZATION? YIN" : : "PRINCIPA
L":"REMAINING ="
540 DISPLAY AT(10 . 3):"MONTHLY":" PAYMENT = "
:" PAYMENTS u :" TO DATE =": :" INTERES
T": uTHIS MN TH =" : :" INTEREST":" TO OAT
E ="
550 ACCEPT AT(5 . 28)SIZE(-1)VAL I DATE("Y N")BEE
P:C$ :: CALL HCHAR(4,3 . 32,28) :: CALL HCH
AR (5~ 3. 32, 28):: IF C$="N" THEN 580
560 DISPLAY AT(4, t):"ENTER PRINTER DEVICE NA
ME:" ;: ACCEPT AT(5 . 3 )BEEP:P'$ :: CAL L HC
HAR ( 4.1,32,64):: OPEN #l: P.
570 REM ._tttttANALYSIS CALCULATIONS* t t t t t t

106
_ _ _ _ _ _ Applications

5818 F.TI.TP.MON=0 :: PA-PAjI00 :: SA-AMTlI00


590 FOR I=1 T O M
6180 IN =iNT( BAtFR+. 5) : : IF Z=M THEN PA-BA+IN
610 TP=TP +PA : : BA=BA-PA+IN :: TI=:TI+IN
620 IF BA ~ 0 THEN 630 :: PA=PA+BA :: TP-TP+BA
: : BA=0
6318 DISPLAY AT(4 . 1);"{4 SPACES}MQ NTH =
{7 SPACES}";Z : : IF C$="N" THEN 7180 ..
F F= 1 THEN 670

t.*_.
640 REM •• "t*.PRINT AMORTIZATION SCHEDULE'*

bS0 PRINT #1:TAB(27);"AMORTIZATION SCHEDULE"


:TAB(10':"PRINCIPAL:";AMT ; TAB( 3S); " R
ATE:";R;TA8CSS);"MONTHS:";M:
660 PRINT #1 : " MONTH{4 SP ACES } PAYMENT
{ 4 5PACES}INTEREST{3 SPACES}PRINCIPAL
{~ SPACES}BALANCE{S SPACES}TOT/INT
(3 SPACES}TOT/PAYMT" : • • F=l
670 A(0) : PA/100 : : A ( l ' = IN/100 : : A(Z)=PA/U'I
0 - IN / 100 : : A( 3,=8A/ 100 :: A(4) =T l/t00
: A (S ) =T P / 100
680 PR I NT • I, US I NG " ••••• ": Z ; : : FOR 1 = 0 TO '5
:: PRINT .1.USING . . . . . . . . . . . . . #":A(I); :
: NEXT I : : PRINT.l:"": : GOT0710
69121 RE M ••••••• DISPLAV CALCULATIONS •• ••• • •
7121121 IF Z=MON OR Z= M THEN 710 : : IF K=84 OR K
=77 THEN 760
71121 A(0)=BA/l@12I :: A(I) = PA/l@0 :: A(2)=TP/10
3 :: A( 3 )=IN / I1210 :: A(4)=TI/100
72121 J=0 :: FOR I =B TO 2121 STEP 3 : : DISPLAV A
T(I,14):USING " • • • • • ••. #.":ACJ) :: J:::J+l
:: NEXT 1
73121 IF Z=M THEN 77121 :: IF C$="Y" THEN 760 ::
DISPLAV AT(23,1'BEEP:"T:::FQR TOTALS M=S
ELECT MONTH": ".ANV OTHER KEY TO CONTINU
E'"
740 CALL KEY<0,K,S) : : IF S=3 THEN 740 : : IF
K< )77 THEN 760
75 0 DISPLAY ATC4,1):"SELECT WHICH MQNTH:- : :
ACCEPT AT(4,21)VALIDATECDIGIT)SIZE(3)BE
EP:MON : : IF MON < =Z THEN 75121
76 121 NEXT Z
77121 IF C$="N" THEN 78121 :: CL OS E .1
78121 DISPLAV AT( 23 . 1 )BEEP : "PRESS ANY KEY FOR
MAIN INDEX":RPT$(" ",28)
79121 CALL KEY(0,K,S):: IF 5=121 THEN 790 ELSE 3
2.
800 REM "'***'GET SAVINGS INFORMATION'* •• "

107
Applications _ _ _ _ __

810 B$(0)=~PRESENT AMOUNT IN SAVINGS : " :: B$


( l )="RATE OF INT EREST :" :: B$(2)="TIMES
COMPOUNDED PER YEAR : "
820 B$(3)="MAKE RE GULA R DEPOSIT S? (Y IN)" ::
B$(41="HOW MA NY DEPOSITS PER YEAR:" :: B
$(S)="HOW MUCH pER DEPOSIT : " :: GOSUe 31
5
830 J=0 : : FOR 1=3 TO 21 STEP 4
8 40 DISP LA Y AT(I.l1:B$(J):: J=J+l IF 1 () 1
5 THEN 850 . . 1=17 : : GOTO 8 40
850 NEXT I
860 J =0 :: FOR 1 =5 TO 23 S TEp 4 :: IF 1 <) 1 7
THEN 890
8711'1 ACCE PT AT(15,2 3' VALIDATE("YN u 'SIZE C- l,BE
EP:C $ :: IF C$ = "N" THE N 880 : : 1 = 19 :: G
OTO 890
880 A(3).A(4'=0 :: GOTO 9@0
890 ACCEPT AT(I,3)SIZE(6'VALIDATE(NUMERIC)BE
Ep;A(J): : J=J+l :: NEXT I
900 AMT=A(0):: R=ACl): : C=A(2):: ND=A( 3) :: D
= A(4)
910 REM tttt**t SAVINGS ANALYSIS.******
920 GOSUB 315 :: DISPLAY AT(3,7): "SAVINGS AN
ALYS I S": : "YEARS IN T H IS ANA L YSIS?" :
: "BEGIN NIN G": "PRINCIPAL =" : :"
{ 4 S PA CES} TOTAL":" DE POS IT S = "
9313 DISPLAY AT(lS,3): "ACCRUED" : " BALANCE - "
: "(4 SPACES}TOTAL" : " INTEREST ="
940 ACCEPT AT(6.2SlVALIDATE(DIGIT1SIZE(4l8EE
P :Y :: IF Y=@ THEN 9 4 13 :: DISPLAY AT(23.
2) : " (3 SPACES}ONE MOMENT PLEASE . . . " : RPT$
C" ",28)
950 REM ****a**ANAL YSIS CALCULATIONs **a t *tt
960 CP=( 1+R /(10@tC» ~ (Y*C l :: B=INT <AMTtCPt10
13+ . 5)/112111'1 :: MA:(CP-ll/(fU(100*C') :: DE=
DtND/C :: BP=I NTCOE *M A t 100+.51/100
970 TO=OtNOtY :: BA=B+BP :: T I =BA-Al"lT-TD
980 REM ttt*ttaDI SP LA Y CALCULATIO NSt******
99 0 A(0)=ANT :: A(I)=TD .. A(2)=BA :: A( 3)=T

10121121 J =t21 :: FOR 1=10 TO 19 STE P 3 : : DISPLAY


AT(I,14) : USING "****~** # ~*. ** " : A(J): :
J=J+l :: NEXT I
1~10 DISPLAY AT ( 23 , 2)BEEP: " tM=MORE SAV ING S A
NALYSIS*" : ~ANY OTHER KEY FOR MAIN I ND EX
"
10213 CALL KEY(t21 . KEY . S) :: I F S:::0 THEN 1020 ..
I F KEY=77 THEN 94121 ELSE 320 :: STOP

lOB
A Mini Data Base
-. Management
System
Raymond J. Herold

A Data Base Managemela System (DBMS) is, in its simplest


form, a system for managillg large amounts of diversified
data, These two programs will allow you to store, update or
delete records, sort data, save files to tape, Qt/d prj,a reports.
Requires Extended BASIC.
This Mini Data Base Management System (DBMS), which ac-
tually consists of two programs, was written for the TI-99/4A
in Extended TI BASIC. Most of the people who purchase a TI
computer are fi rst-time computer owners. In addition, most TI-
99/4A owners do not have disk drives and memory expansion
for their systems. My purpose in writing "M INI-DBMS" was
to provide a useful software tool that was relatively powerful,
easy to use, and would run on a minimum TI-99j4A
configuration. This minimum configuration consists of the
basic 16K TI -99j 4A, monitor or TV, cassette player and Ex-
tended BASIC (which I consider essential).
Roadblocks
The first obstacle to writing a program such as this was the
16K memory limitation. How do you include all the features
the program should have to make it useful, yet still leave
enough memory for the data? The first trade-off required split-
ting MINI-DBMS into two programs. The first, MINI-DBMS,
would be responsible for defining new files, adding and up-
dating records and sorting the file. The second, " MINI-REPT,"
would handle the summarization and reporting requirements.
Then came the question of the records themselves. Trade-
off number two: there would be a maximum of eight data
fields per record. This should be enough for most home
applications. In considering the data fields, a maximum of
20 characters per field seemed reasonable. The above two

109
Applications ______

trade-o ffs then determined the third: a maximum of 80 records


per file, depending on the record size. Again, this seemed
reasonable for the typical home application.
Consequently, the MINI-DBMS parameters break down
like this: two programs with the features deemed essential; up
to 80 records per file; 1 to 8 fields in each record; and 1 to 20
characters for each field. Not too bad for a 16K machine!
The programs are written so that they can easil y be
merged if you have more memory and a disk drive. These two
items will allow you to expand the basic parameters of MINl-
DBMS. The major program subdivisions are outlined below in
Table 1. Should you decide to make modifications to the pro-
gram, Table 2 lists the variable names and their use.
MINI. DBMS
Program 1 is MINI -DBMS. This progra m allows you to define
new DBMS files, add records to a file, display, update or de-
lete records, sort a file, and save a file to tape. When you first
type in RUN the program displays the introduction banner
then displays the main menu:
I-DEFINE NEW DBMS RECORDS
2-LOAD RECORDS FROM TAPE
3-ENTER NEW RECORDS
4-DlSPLAY/ UPDATE RECORDS
5-S0RT BY SPECIFIED FIELD
6-SAVE DATA ON TAPE
Define new DBMS records. This is where you define
what a particular file will look like. The information you must
supply includes: filename (up to eight characters); numbers of
data fields in each record (maximum allowed is eight); and de-
fine each field.
Field definition involves a number of steps. To start, give
each fie ld a I-to-6-character field name. This name (including
the periods if you leave them in) will be used to identify the
field when requesting functions such as search, sort, or sum-
marize. You must then define the field length (maximum
length is 20 characters). Fi nall y, you will te ll the program
whether the field is alpha or numeric format. Alpha fields per-
mit any character to be entered; numeric fie lds will only allow
0-9, comma, and period. In addition, only a numeric field can
be summarized. Figure 1 is an example of field definition.

110
_ _ _ _ _ Applications

Although the new fi le has now been defined this step is


not quite complete. The program will allow you to set an ini-
tial value, or mask, fo r each fie ld. These masks all ow you to
format fields for data input. They will override the default val-
- ues which are period for alpha fields and zeros for numeric
ones. You can see in Figure 2 that the DATE field was given a
mask of 00100100 rather than periods, and the AMOUNT
field was given a decimal point. The remain ing fields use the
defau lt value. You can override the periods with a mask of
blan ks if you so desire, but the periods are useful in showing
whoever is entering data how many characters they have to
work with.

Figure J. Create New DBMS Files

FIELD LEN GTH TYPE


NAME (1 - 20) (N/ A)
N AME.. 20 A
ADDR.. 20 A
CITYST 20 A
ZIP... 05 N
DATE.. 08 A
AMOUNT 08 N
FOR... 20 A

Figure 2. Set Initial Values

SET INITIAL VALUES


NAME..
ADDR..
CITYST
Zip ... 00000
DATE.. 00/ 00/00
AMOUNT 00000.00
FOR ...

Load records from tape. This option will allow you to


load an existing fi le on tape into the MINI-D BMS program.
The program will first read the fi lename on the tape and ask
you if it is the one you wanted.
Enter new records. Here is where you begin with a
newly defi ned file, or add to an existing file loaded from tape.
The program will display a screen with the name of each field

111
Applications ______

in the record and its associated mask. You simply enter the
data you want for each new record. After the record is added
a display will show how many records are currently in the file
and the maximum number allowed for that file. At this point
you can add another record or return to the main program
menu. Figure 3 shows a record that has just been added.
Figure 3. Add New Record
ADD NEW RECORD
NAME .. COMPUTE! .. . ...... .
ADDR .. P.O. BOX 5406 .... .
CITYST GREENSBO RO NC ....... .
ZIP.. 27403
DATE .. 10/04/84
AMOUNT 00024.00
FOR ... SUBSCRIPTION ......... .

Display j update records. There are two methods avail-


able for displaying records. The first displays each record start-
ing at the beginning of the file. Pressing the ENTER key
displays the next record. Pressing M will return you to the
program menu from anywhere in the file. Pressing U will put
the program in update mode for the record being displayed.
The cursor will appear in the leftmost position of the first data
field. You can change the data in the field or press ENTER to
put the cursor in the next field. This process continues until all
fields have been updated or bypassed.
If you want to completely delete the record from the file
enter $DEL into the first four positions of the first data field.
This assumes that the first field is alpha format and at least
four characters long. If you want to use a different control
code or field you can change the IF statement in line 4146.
Method two displays and updates the records in the same
manner as method one. Th e difference lies in which records
are displayed. This second method allows you to search the
file for a desired va lue in a particular field. Only records meet-
ing the search criteria are displayed, thus eliminating the need
to scroll through unwanted records. The search argument may
be a generic value. That is, the argument "SMI" would display
records for SMIT H. SMITHERS. SMILEY. etc.
Sort by specified field. You can sort the file into ascend-
ing sequence on any field. Just provide the name of the field

112
_ _ _ _ _ _ Applications

you want sorted. BASIC is a slow language for routines such


as sorts, but the exchange sort which starts at line 5000 will
sort most files in less than five minutes. The program will
continually display the number of sort passes left. You can
change the sort to descending sequence by changing the less
than sign in line 5065 to a greater than sign, and by changing
the A$ assignment in line 5050 to A$(O,Z) = " " ,
Save data on tape. Depending on the size of the file,
saving data to tape may be even slower than th e sort. But
then, n o one purchases a home computer for its tape I/O
speed.
MINI-REPT
MINI-REPT hand les the summarization and reporting
responsibilities of the MINI-DBMS system. The program menu
provides the following options:
I-LOAD RECORDS FROM TAPE
2-D1SPLAY RECORDS
3-SUMMARIZE BY FIELD(S)
<-PRODUCE PRINTED REPORT
The first two options function the same way as in Pro-
gram L except that there is no update capability for DISPLAY
RECORDS.
Summarize by field(s). You can summarize (total) a field
based on the value of one or two search fields. To summarize
using one search field you provide the name of the field to be
searched, the search argument (which may be generic), and
the name of the field to be summarized. The value of the
search field and summary field for all records meeting the
search criteria will be displayed. Once the entire file has been
searched, the program will display the number of records
meeting the search criteria and the total for the summary field.
It is possible to search on two fields. By providing the
name of the two fields and their respective search arguments,
you can have the program summarize only those records
meeting the search criteria for both fields.
If you specify the second search field argument as $ALL,
the program will qualify all records meeting the first search
fie ld criteria only. This all ows you to display the second search
field value as an identifier.
Produce printed report. This option is for those of you
with printers. It allows you to produce a report of the data in

113
Applications _ _ _ _ __

the field. You first provide the program with the number of
fields you want printed, and the name of the fields. You may
summarize a field if desired, and you may selectively print
based on the value of a search argument. The report to be
printed may be given a title. The program checks for a maxi-
mum 80 columns of print data, but allows you to print more if
desired.
If you request this option but don't have a printer you
will get a syntax error. Also, you may have to adjust the
OPEN statement in line 8006 to accommodate your particular
printer.
Table J. Program Subdivisions
Line
Number
10-30 Introduction banner
100-190 Menu display
looo-l4UO Define new DBMS file
2000-2060 Read data from tape
3000-3200 Add records to file
4000-4440 Display/update records
5000-5220 Sort routine
6000-6030 Write data to tape
7000-7430 Search, summarize and display
8000-8200 Produce printed report

Table 2. Program Variables


AS(s,s) File data array (record, field)
ARGS First search argument
ARG2$ Second search argument
FIELDS Number of fields in record
FLD Field number of user-entered fie ld name
FLD$ User-entered field name
FNM$(s) Field name array
KEY Value of key pressed
LN(5) Field length array
MASKS(s) Initial field value array
NAMES Filename
NF Number of fields to be printed
NUMREC Maximum number of records in file
OPTS User-entered option (Y or N)
PIs) Field to be printed
P$15) Name of field to be printed

114
_ _ _ _ _ _ Applications

RECS Number of search fields


SF Number of search fields
STATUS CALL KEY status
SUM Number of field to be summarized
SUMS Name of field to be summarized
TC Total characters per line in print function
TI Items selected in summary function
TOT Accumulator for summary field
TOTCHR Total characters per record
TYP${s) Field type array
X,L,Z,Q Loop control

Program l, MINI-DBMS
1 REM TI MINI - DBM S
2 REM
1121 CALL CLEAR : : CAL L SCREEN (9 )
2121 DISPLAY AT (3 . 1):RPT$("*~.28 1 :: DISPLAY AT
(4,1):"." :: DISPLAY ATC4,28):"."
22 DI S PLAY AT(5 , l ) : " t {4 SPACES}M I N I - 0 B
M S{5 SPACES}."
24 DISPLAY ATCb,I):"." :: DISPLAY AT(6,2B) : "
*" ::
DISPLAY AT(7,1):RPT$C"." . 2B)
3121 FOR X=i TO 21211210 :: NEXT X
4121 DIM At;(81 ,B)
1121121 CALL CLEAR : : CA LL SCREE NCS):: DISPLAY A
T(2,112I):"** MENU t t "
l1i21 0 I SPLAY AT (6, 1 ) : "1 - DEF I NE NEW DBMS REC
ORDS" :: DISPLAY AT(S, 1 ) :"2 - LOAD RE COR
OS FROM T APE"
120 DISPLAY AT(10. 1):" 3 - ENTER NEW RECORDS"
: : DISPLAY AT(12 , 1):"4 - DISPLAY/UPDATE
RECORDS"
130 DISPLAY AT(14 , I } :"5 - S ORT BY SPECIFIED
FIELD"
140 DISPLA Y ATiI6,1):"6 - SAVE DATA ON TAPE"
150 DISPLAY ATc2 3 . 3) :"ENTER SELECTION ---> " :
: ACCEPT AT(23.2 3 )VALIDATEC"123456")BEEP
:CHOICE
170 ON CHOICE GOTO 10B0,2000, 3 ~00.4000,5000,
6000
190 GOTO 100
4 00 FOR X=l TO 2000 :: NEXT X
41 0 GOTO 1 00
1090 CALL CLEAR :: DISPLAY AT i3 ,1):"OEFINE R
ECORO FORMAT FOR" :: DISPLAY AT{4, 1): "N
EW DBMS. YOU MAY DEFINE UP"
1005 DISPLAY AT(S, l ) : "TO B FIELDS IN THE REC
OF<D. "

115
Applications ______

1006 IF RECS > ~ THEN DISPLA Y ATC8, 1): "DE L ETE


CURRENT FILE ? YIN"
1907 IF RECS > ~ THEN CALL KEY (3 . KEY. S TATUS)::
IF STATUS=0 THEN 112107 ELS E IF KEY <>
89 THEN 1121121
10113 DISPLAY AT(S, I ':"NE W DBMS NAME: . . . . . . .
. " :: ACCEPT ATC8,16'SIZEC - B)BEEP:NAME$
H'l15 DISPLAY AT(9.1):"NUMBER OF FIELD S (1 - 8)
" :: ACCEPT ATC9,25)VALTDATE CDIGIT'SIZE
(2,BEEP:FIELDS
112116 IF FIELDS >8 THEN 112115
112118 DISPLAY ATCII,I):" FIELD{S SPACES}LENG
TH(3 SPACES}TYPE" :: DISPLAY AT C12,1):"
NAME(6 SPACES}Cl - 2121) ( 3 SPA CES) CNfA ) "
11212121 FOR L=1 TO FIELDS
112122 DISPLAY ATCI3+L,1':" . . . . . . (6 SPACES } 0
0(7 SPACES}."
1023 NEXT L
1030 FOR L=I TO FIELDS
1032 ACCEPT ATCI3+L,3'SIZEC - 6'BEEP:FNM.CL)
112134 ACCEPT ATCI3+L, lS)VALIDATECDIGITlSIZEC -
2)8EEP:LNCLl :: IF LNCL) < 01 OR LNCL' >20
THEN 1034
1036 ACCEPT ATCI3+L.24'VALIDATE("AN"'STZEC - I
, BEEP: TYP. CL ) :: IF TYP$ CL) = " . " THEN
112136
112138 NEXT L
104121 CALL CLEAR :: D I SPLAY ATC2,2):"t. SET J
NITIAL VALUES •• " :: DISPLAY AT(4,1':"K
EY IN THE DEFAULT VALUE FOR"
112142 DISPLAY ATCS, I ) : "EACH FIELD OR PRESS EN
TER TO" .. DISPLAY AT(6. I ): "ACCEPT AS I
S. "
11215121 FOR L~1 TO FIELDS
112152 DISPLAY AT(10+L,1):FNM$(L)
1054 IF TYP$(L)="N" THEN GQSUB 11121121 ELSE GOS
UB 12130
1056 NEXT L
1060 FOR L=I TO FIELDS
1062 IF TYP.CL) ="N" THEN GOSUB 1 31210 ELSE GOS
UB 1400
1064 NEXT L
11217121 TC=0 :: FOR L=1 TO FIELDS
112172 TC=TC +L NCL)
112174 NEXT L
112176 NUMREC=INT(43121l21fTC):: IF NUMREC >813 THEN
NUMREC =80
1078 CALL CLEAR :: DISPLAY AT(4,1):"YOUR FIL
E WILL HOLD ";NUMREC;"RECORDS"
UJ8121 FOR X::l TO 2121121121 :: NEXT X

116
- - - - - _ Applications

1099 RECS=0 :: GOTO lee


110'9 DISPLAY AT(10+L,8):RPTt;( " 0",LN(L»:: RE
TURN
1209 D I SPLAY AT ( 10+L. B) : RPT$ (" _ ". LN (L) ) : : RE
TURN
1 3 99 ACCEPT AT(10+L.8)VALIDATE("012 3 4~6789,_
")SIZEC-L N CL»BEEP: MASK$(L):: RETURN
1499 ACCEPT AT(10+L , B)SIZEC - LN(L »BE EP:MASK$
(LJ : : RETUR N
209£1 CALL CLEAR
2919 OPEN *l:"CSl " ,INPUT ,INTERNAL,FIXED 192
292£1 I NPUT * l : NAME$.FIELDS,RECS,NUMREC
2922 PRINT :: PRINT "INPUT FILE - ";N AME$ ..
PRINT "CO NTINUE ? YIN"
2024 CALL KEye3,KEY,STATUS):: IF 5TATUS=0 TH
EN 212124
2926 IF KEY(>89 THEN 2 959
293121 FOR L= l TO FIELDS:: INPUT .. 1: FNM$ el), T
YP$(L),LNCL),MASK$(L):: NEXT L
2935 FOR X=1 TO RECS
2940 1 N PUT .1: As (X. 1 ) ,AS (X, 2) • A$ (X. 3) • AS (X, 4
) , AS (X, 5) ,A$ (X, b ) ,A $ (X . 7) , A$ (X ~ 8)
2045 NEXT X
2050 CLOSE #1
20b0 GOTO 100
3000 IF NU MREC< 1 THEN CALL CLEAR:: DISPLAY
AT(4,1):"NO FILE DEFINED." :: GOTO 400
3004 RECS=RECS+l
3005 IF RECS >NUMREC THEN CALL CLEA R : : DISPL
AY AT(4, l) : "RECORD MAXIMUM ElCEEDED" ::
GOTO 400
3010 CALL CLEAR :: DISPLAY AT(3.7l:"tt ADD N
E W DATA tt ..
3020 FOR L = l TO FIELDS
3022 DISPLAY AT (5+L, 1 ) 51 IE (LEN (F NM'S (Ll ) ) : FNN
'S(L): : DISPLAY AT(S+L . 9)SrZE(LEN(MASK$(
L») :MASK'S(L )
3024 NEXT L
3030 FOR L=l TO FIELDS
3032 IF TYP'S(L) ="N" THEN GOSUB 3100 ELSE GaS
UB 3200
3034 NEXT L
303b DISPLAY AT ( 1 7.1):" ~ RECORDS:";RECS ; "
(3SPACES}MAX:";NUMREC
3040 CALL HCHAR(IB. 1,95.31)
3042 DISPLAY AT(20.1):"1 - TO ENTE R ANOTHER
RECORD" :: DISPLAY AT(21.t>:"2 - TO RET
URN TO MENU" :: DISPLAY AT(23,3): "E NTER
YOUR CHOICE --- >"
30 44 ACCEPT AT (23 . 2b)VALIDATE("12 " )BEEP :OPT

117
Applications ______

3 1346 IF OPT = 1 THEN 313013


30 48 IF OPT=2 THEN 11313
3 13513 GOTO 31344
3 1913 ACCEPT AT(5+L.9)VALID AT EC"13 1 23456789 •. "
)S IZE (-LE N I MASK$( L ) ))BEEP:A$(REC S . L): :
RETURN
321313 ACCEPT AT (5 +L ,9)S IZE C-LE NCMA SK $ (L»)8EE
P:A$(RECS,L): : RETURN
40013 CALL CLEAR :: DISPLAY ATC 3 , 2J : " . t D I SPL
AY/UPDATE DATA . t "
413113 DI SPLAY ATC6.1):"1 - DISPLAY ALL RECORD
S" :: DI SPLAY ATC7,l):"(4 S PA CES}FRQM B
EGINNING OF FILE . "
41315 DI SP LAY AT(9, 1):"2 - DI SPLAY BY VALUE I
NO. :: DI S PLA Y AT CI13 , I):" { q SPACES}SPEC I
FlED FIELD"
'113 20 DISPLAY AT(1 2.3) :"EN TER YOUR CHOI CE ---
) " :: ACCEPT AT<12.26)VALIDATE("12")BEE
P:OPT
4 13313 ON OPT GOT a 41 00,42130
40513 GOTO 1 1313
41 013 HOLD = RECS
41113 FOR RECS - l TO HOLD
411 5 IF RECS ) HOLD THEN 41 50
41213 GOsue 4 3 1313
41 30 CA LL KEYC3.KEY.STATUS)
41 32 IF S TATU S=13 THEN 41 30
4134 I F KEY=13 THEN 41 50
41 36 IF KEY -77 TH E N RECS=999 .. GOTO 4159
41 38 IF KEY <>85 THEN 41 313
41413 FOR L=l TO FIELDS
414 2 IF TYP$(L)="N" THEN GOS UB 3 1913 ELSE GOS
UB 321313
4144 NEXT L
4146 IF SEG$(A$(RECS.l). 1 . 4) = "$DEL" THEN GOS
US 441313
'lIse NEXT RECS
4155 REC S= HOLD
41613 GOTO 113{!1
4 21313 CALL CLEAR :: DI SPL AY AT(2,1):"t. DISPL
AY BY FIELD VALUE •• "
4 2135 DISPLAY ATCS, 1): "E NT ER THE NAME OF THE
DATA " :: DISPLAY AT(6.1):"FtELD TO BE S
EARCHED AND THE"
4 2 10 DISPLAY AT(?!) : "SEARCH ARGUMENT (VALUE
) ."
4 2213 DISPLAY AT(12 . 1): "FIELD TO BE SE ARCHED
:: ACCEPT AT(12.22)SIZEC - 6) : F LD

4221 FLD=1l'

118
______• Applications

4222 FOR L=J TO FIELDS


4224 IF FLDS=FNM$(L)THEN FLD=L :: L=99
4226 NEXT L
4228 IF FLD=@ THEN DISPLAY AT(14.1): "NO SUC H
FIELD NAME." :: DrSPLAY AT(l'5,I):'''R~
TO RETRY - "M' FOR MENU " ELSE GOTO 4250
4 230CALL KEY(3.KEY,STATUS)
4232 IF STATUS=0 THEN 4230
4234 IF KEY=B2 THEN 4200 E LS E 100
4250 DISPLAY AT(14.11 : "ENTER SEARCH VALUE
<5 SPACES}"
4252 ACCEPT ATCIS, l):ARGS
4260 HOLD =RECS
4262 FOR RECS=l TO HOLD
4 264 IF ARGS=SEGS(A'5(RECS,FLD) .1,LENCARG$»T
HEN GOSUS 4 30 0 ELSE 4290
4270 CALL KEY(3,KEY,STATUS)
4 272 IF STATUS=0 THEN 4270
4274 IF KEY=13 THEN 4290
42 76 IF KEY =7 7 THEN RECS=999 . . GOTO 4290
4 280 IF KEY <>S '5 THEN 4270
4282 FOR L=l TO FIELDS
4284 IF TYP$(L)="N" THEN BOSUB 3 100 ELSE GOS
UB 3200
4 286 NEXT L
4291t'1 NEXT RECS
4292 RECS=HOLD
4 294 GOTO 11210
4 31t'11t'1 CALL CLEAR :: DISPLAY AT(2, 1):"** DISPL
AY/UPDATE RECORDS **"
4 3 11t'1 FOR L=l TO FIELDS
4321t'1 DISPLAY AT(5+L, 1):FNM$(L):: DISPLAY AT(
5+L ,9 1 :A$(RE CS,L)
4 33121 NEXT L
4 340 DISPLAY AT(2121. l ' :"PRESS ENTER FOR NEXT
RECORD" :: DISPLAY AT <22,1): "PRESS' U'
TO UPDATE RECORD" :: DISPLAY AT(24,1):"
PRESS 'M' FOR MENU"
4350 RETURN
44121121 CALL CLEAR .. DISPLAY AT(~ , l) :" STAND BY

4410 FOR X=RECS TO HOLD FOR Y=l TO FIELDS


442121 A$(X,Y)=A$(X+J,Y)
4430 NE x r Y :: NEXT )(
444121 RECS=RECS - l :: HOLD=HOLD - l :: RETURN
500121 CALL CLEAR :: DISPLAY AT(3.9';"** SORT
.. *" :: DISPLAY AT(6,1):"NAME OF SORT FI
ELD . . . . .. " :: ACCEPT AT(6.20'SIZE( - 6)B
EEP:FLDS

119
Applications ______

51211215 FLD=I2I
512119 FOR L=1 TO FIELDS
512112 IF FLDS=FNMSILlTHEN FLD =L :: L-99
512113 NEXT L
512115 IF FLD = 12I THEN DISPLAY AT114, 1,:"NO SUCH
FIELD NAME." :: DISPLAV AT(lS,ll :'''R~
TO RETRY - 'M' FOR MENU" ELSE GOTO 51214121
51212121 CAL L KEYI3,KEY.STATUS): : IF S TATUS=9 TH
E N 51212121
51213121 IF KEY=82 THEN 50121121 ELSE 1~t21
512149 DISPLAY ATI2IZ1,I):"SORTING . . . "
595121 Y-I :: HX =@ :: FOR Z= I TO FIELDS :: AS !
121,1)=" ____ " :: NEXT 1
51215555=121 :: DISPLAY ATe2121, I): "SORTING . . . ";R
ECS-Y
596121 FOR X=Y TO RECS
512165 IF ASIX,FLD' ( AS(I2I,FLDlTHE N GOSUS 511210
512179 NE XT X
5975 IF 55=1 THEN GOSUS 5290
51218121 Y=Y +l :: FOR 1=1 TO FIELDS: : AS (121, Z)=A
SIY, Z) : ; NE XT Z
512185 IF Y( RECS THEN 512155
512199 GO TO 19121
5 1121 9 FOR 1=1 TO FIELDS •. ASe0,Z)=AseX,Z)::
NEXT Z :: HX =X : : 55 = 1 .. RETURN
52121121 FOR Z=1 T O FIELDS
521121 HS-AS(Y,Z):: AS(Y ,Z)= AS(HX,Z):: AS( HX,Z
)= HS
522121 NE XT Z :: RETURN
6el2l1Z1 CALL CLEAR
6121 1121 OPEN #l ;"CS l",OU TPUT, INTERNAL,FIXED 19 2
61212121 PRI NT #l:NAHES;FIELD S; RECS;NUMREC
61213121 FOR L = l TO FIELDS :: PRINT #l: F NMS(L l ;T
YPS( L );LNI L' ; MA SKS(L):: NEXT L
612135 F OR X=I TO RECS
69 4121 PRINT #1:AS( X,J );AS(X,2);AS(X,3);AS ( X,4
) ; At (X, 5' ; AS ( X, 6) ; AS (X, 7) ; AS (X, B)
6e4S NEXT X
61215121 CLO SE # J :: GO TO 1121 121

Program 2. MINI-HEPT
1 REM TI MINI -R EPT
2 REM
Ie CALL CLEAR :: CALL SCREEN(9)
2121 DISPLAY AT(3,1):RPT$("t",2B):: DISPLAY AT
(4,1):"." : ; DISPLAY AT(4,ZS):"."
22 DISPLAY AT(S.l ) : " ' { 4 S PA CES}M I N I - R E
P T {S S PACES } '"

110
______• Applications

24 DISPLAY ATC6,11;"'· :; DISPLAY AT(6,2S1:"


." :: DISPLAY ATI7, 1): RPT. ("''',28)
30 FOR X=l TO 2000 :: NEXT X
40 DIM A$CSI,B)
100 CALL CLEAR :: CALL SCREEN(S):: DISPLAY A
T (2, 10) : " «« MENU .«"
110 DISPLAY AT(6,l';"1 - LOAD RECORDS FROM T
APE" :: DISPLAY ATCB,l);"2 - DISPLAY REC
ORDS"
140 DISPLAY AT(10,1):"3 - SUMMARIZE BY FIELD
(5'" :: DISPLAY AT(12,11:"4 - PRODUCE PR
INTED REPORT"
150 DISPLAY AT(23,3):"ENTER SELECTION ---) " :
: ACCEPT AT(23,23)VALIDATEC"12345"lBEEP:
CHOICE
170 ON CHOICE GOTO 2000,4000,7000,8000
19121 GOT a lee
211l1iJtJ CALL CLEAR
2010 OPEN *1:"CSl",INPUT ,INTERNAL,FIXED 192
2020 INPUT *l:NAME$,FIELDS,RECS,NUMREC
2022 PRINT :: PRINT "INPUT FILE - ";NAME$ ..
PRINT "CONTINUE? YIN"
2£124 CALL KEY (3, KEY, STATUS) :: IF STATUS=£1 TH
EN 2024
2026 IF KEY <> S9 THEN 2950
2£130 FOR L=l TO FIELDS :: INPUT .1:FNM$(L) , T
YP$(L),LN(L),MASK$(L):: NEXT L
2035 FOR X=l TO RECS
2040 INPUT .1:A$(X,l),A$(X,2),A$(X.3).A$(X.4
) .A$(X.5) .A$(X.6) .A$(X,7) ,A$(X,8)
2045 NEXT X
2058 CLOSE .1
2069 GOTO 18£1
4888 CALL CLEAR :: DISPLAY AT(3,6):"** OISPL
AY DATA **"
4018 DISPLAY AT(6.1):"1 - DISPLAY ALL RECORD
S" :: DISPLAY AT(7.1):"(4 SPACES}FROM B
EGINNING OF FILE."
4015 DISPLAY AT (9,1):"2 - DISPLAY BY VALUE I
N" :: DISPLAY AT(19,l):"(4 SPACES}SPECI
FlED FIELD"
4028 DISPLAY AT(12,3):"ENTER YOUR CHOICE ---
> " :: ACCEPT AT(12,26)VALIDATEC"12")BEE
P:OPT
4039 ON OPT GOTO 4109,42£10
4£158 GOTO 1£1£1

121
Applications _ _ _ _ __

4100 HOLD=RECS
4110 FOR RECS=1 TO HOLD
4115 IF RECS >HOLD THEN 4150
4120 Bosue 4 3 00
4130 CALL KEY(3,KEV,STATUS)
4132 IF STATUS=0 THEN 4130
4134 IF KEV=13 THEN 4150
4136 IF KEV=77 THEN RECS=999 :: GOTO 4150
4138 BOTO 4130
4150 NEXT RECS
4155 RECS=HOLD
4160 BOT a 100
4200 CALL CLEAR :: DISPLAV ATC2,l):"" DISPL
AV BV FIELD VALUE •• "
4205 DISPLAV AT(5,1):NENTER THE NAME OF THE
DATA" :: DISPLAY ATlb,1): "FIELD TO BE S
EARCHED AND THE"
4210 DISPLAY ATI7,1):NSEARCH ARGUMENT (VALUE
) ."
4220 DISPLAV AT(12,1):"FIELD TO BE SEARCHED
.. ACCEPT AT(12,22)SIZE(-b):FLD

4221
•FLD=0
4222 FOR L = l TO FIELDS
4224 IF FLD$=FNM$(L)THEN FLD=L :: L =99
4226 NEXT L
4228 IF FLD=0 THEN DISPLAV ATCI4,l):"NO SUCH
FIELD NAME." :: DISPLAV AT(t5,l):'''R'
TO RETRV - "M" FOR MENU" ELSE GOTO 4250
4230 CALL KEVC3,KEY,STATUS)
4232 IF STATUS=0 THEN 4230
4234 IF KEY=82 THEN 4200 ELSE 100
4250 DISPLAV AT(14.1):-ENTER SEARCH VALUE
{S SPACES}"
425 2 ACCEPT AT(15,l):ARG$
4260 HOLD=RE CS
4262 FOR RECS:l TO HOLD
4 26 4 IF ARB$=SEG$(A$(RECS,FLD). l,LEN(ARG$»T
HEN GOSUB 4 300 ELSE 4 290
4270 CALL KEV(3,KEY,STATUS)
4272 IF STATUS=0 THEN 4270
4274 IF KEY=13 THEN 4290
4276 IF KEY=77 THEN RECS:999 BOTO 4290
4280 GOTO 42 70
4290 NEXT RECS
4292 RECS=HOLD
4294 GOlD 100
4300 CALL CLEAR :: DISPLAY AT(2,6):N" OISPL
AV RECORDS •• "

122
_ _ _ _ _ _ Applications

4310 FOR L=l TO FIELDS


4320 DISPLAY AT(S+L,l):FNM.CL):: DISPLAY ATC
5+L,10):A$(RECS,L)
4330 NEXT L
4340 DISPLAY AT(20,1):·PRESS ENTER FOR NEXT
RECORD" :: DISPLAY AT(24,11 : "PRESS "M"
FOR MENU"
4350 RETURN
7(IH~0 CALL CLEAR : : 0 I SPLAY AT (2, 1) : "t SU MMA *
RIlE BY FIELDNAHE **"
7001 DISPLAY AT(4.1):"SEARCH 1 OR 2 FIELDS?
." :: ACCEPT AT(4,23)VALIDATE("12·IBEEP
: SF
7005 TOT=0 :: TI : 0
7010 DISPLAY AT(6,l):"FIELD TO BE SEARCHED •
. . . . . • :: ACCEPT ATCb,22)SIZE(-blBEEP:F
LOS : : FLO::::"
7015 FOR L=l TO FIELDS
7016 IF FLD$=FNM$(L1THEN FLO=l : : L=99
7017 NEXT L
7020 IF FLD==0 THEN DISPLAY AT(b. l);"NO SUCH
FIELD NAME" :: DISPLAY AT(7,l):"'R" TO
RETRY - 'M" FOR MENU" ELSE GOTO 7028
7022 CALL KEY(3,KEY,STATUS)
7824 IF STATUS=8 THEN 7022
7826 IF KEY:B2 THEN 7000 ELSE 100
7028 DISPLAY ATC7,l):"ENTER SEARCH VALUE" . .
ACCEPT ATCB,l):ARGS
7029 IF SF-2 THEN GQSUB 7300 .. IF FLD2=0 TH
EN 100
7030 DISPLAY AT(17,1.:"FIELD TO BE SU MMED
. . • . • :: ACCEPT AT(17.20)SIZEC - 6)BEEP : S
UM$ :: SUM=8
7035 FOR L-l TO FIELDS
7036 IF SUM$-FNM$CL)THEN SUM-L :: L=99
7037 NEXT L
7040 IF SUM-0 THEN DISPLAY ATC17.1):"NO SUCH
FIELD NAME" :: D I SPLAY AT ( 19, 1) : "" R" T
a RETRY - "M' FOR MENU" ELSE GO TO 7050
7042 CALL KEYC3,KEY,STATUS)
7044 IF STATUS-0 THEN 7042
7046 IF KEY-82 THEN 7030 ELSE 100
7050 IF TYP$(SUM) <> "N" THEN DISPLAY ATC17,1)
:"NOT A NUMERIC FIELD· :: DISPLAY ATC19
,l):"'R' TO RETRY - 'M" FOR MENU" ELSE
GOTO 7060
7052 CALL KEYC3.KEY,STATUS)
7054 IF STATUS-0 THEN 7052
7056 IF KEY-82 THEN 7030 ELSE 100
7060 CALL CLEAR :: HOLD-RECS

123
Applications _ _ _ _ __

7062 FOR RECS=l TO HOLD


7064 IF ARG$=SEG$(A$(RECS,FLD),l,LEN(ARG$»T
HEN Bosue 7400
7~66 NEXT RECS
7~6B RECS:::HOLD
7070 PRINT PRINT PRINT US IN G "IT E MS ##
( 4 SPACES)TOTA L #######.##":Tl,TOT
7072 PRINT .. PRINT "PRESS ANY KEY FOR MENU"
707 4 CAL L KEY(3,KEY,S TA TUS) :: IF STATuS:::0 TH
EN 707 4 ELSE 100
7100 H~ = "" ;; FOR X::: 1 TO LEN(A$(RECS ,SU M))
7 1 1121 IF SEG$(A$(RECS,SUM),X, 1» = "0 " ANO SE G'"
(A$(RECS,SUM),X ,l )<: "9 " OR SEG $(A$ (RECS
,5UM),X,1) :::" ." THEN G05UB 720121
7 120 NEXT X
7130 N= VAL(H$):: TOT = TOT+N :: T I = TI +I
7 1 35 IF 5=1 THEN RETURN
714121 PRI NT A$(REC5.FLD);" ";A$(RECS,SUMl
7145 IF SF=2 THEN PRINT
7 15121 RETURN
721210 H~ ::: H$~S EG$(A$(RECS,SUM),X,ll RETURN
7300 DISPLAY AT (1121, 1): "2ND SE ARCH FIELD .. .
.. ACCEPT AT(II2l. IBl S IZE (-61 BE EP :F LD
2 $ :: FLD2=0
7310 FOR L=l TO FIELD S
732121 IF FLD2$:::FNM$(L)THEN FLD2=L :: L:::99
7325 NEXT L
733121 IF FLD 2=l1J TH EN DI SP LAY AT ( )0. 1 ) :"N O s u e
H FIELD" .. DISPLAY AT(11 ,1):" "R' TO RE
TRY - ' M' FOR MENU" .. GoTO 7340
7332 DISPLAY AT CII, Il: "ENTER 2ND S EAR CH VALU
E"
7334 ACCEPT AT(12,l)BEE P : ARG2$
7336 GO TO 73513
73 4 0 CAL L KEY(3,KEY,STATUS)
73 4 2 IF S TATUS =0 THEN 7340
7344 IF KEY:::82 THEN 7300
7350 RETURN
7 400 IF SF=! THEN GO Su e 7 100 .. RETURN
7 4 05 IF ARG2$ = "$ALL" THEN 7440
7 410 IF ARG2$=SEG$(A$(REC S, FLD2 ) . I,LEN(ARG21i
) 1 THEN 74413
7 4 20 RETURN
74 4 0 PRINT A$(RECS,FLD 2) :: GOSUB 7 10@
7450 RETURN
8000 CALL CLEAR :: DI S P LAY ATC2 , 1):",. PRODU
CE PRINTED REPORT .t"
8005 TOT=0 :: P(0) =@
8006 OPEN #2: "RS 232 ".OUT PU T,DISPLAY

124
- _____• Applications

811'110 DISPLAY AT(S, I) : "NUMBER OF FI ELDS TO PR


1NT? .~ .. ACC EPT AT C'5.28)VALIDATE (" 12 3
4 '5678"JBEEP :N F
8020 FOR L "' 1 TO NF
811'122 DI S PLAY AT(6+(2 _L ), ! ) : US I NG "NAME OF FI
"- ELD tt - •••••• ";L : ACCEPT AT (6+(2 *L l ,
19 )5 I ZEC - 6lBEEP : P $ CL)
8024 PC l l- 0 :: FOR Z=1 TO F IELD S
9026 IF P $ (L) =F NM$ (ZIT HEN PCL'=Z
8028 NEX T Z
8fl 3 11'1 IF PCL) =0 THEN L=L- I
813:32 NEXT L
813 36 D I SPLAY AT(~3 .1 ) : "TOTA L A F IELD . . . '(I N . "
ACCEPT AT(23 . 20)V ALIDA TE("YN N lSIZ E (
- I IBEEP : OPT'S I F OPT $ ~ "Y" THEN 80 '50
80 40 DISPLAY ATC24.!): "NAME OF F I ELD . . . . . . "
.. ACCEPT AT (~4 . lS) SIZE(-6) B EEP : P~(0)
8042 FOR Z= I TO F I ELDS
80 44 IF P$ (0)=FN M$(Z)THEN P(0)=Z
811'14'5 NEXT Z
8046 I F TYP$(P(13)I = "N" THEN 8058
8048 DISPLAY ATC 2 4,l ) : " tt INVALID OR NON - NIJM
ERIC f t " . . FOR Z= I TO '2!110Q! ; : NEXT Z
GOTD 81'1.! 4 11'1
80'50 GOSUB 8100 : : TC::0 :: F OR Z= 1 ro NF
TC :: TC+L N (P(Z»: : NEXT 7
8052 TC::TC t (2 tN Fl - ~
805 4 IF TC ' 80 THEN 8060
8055 DISP LA Y AT(~. I I:U S ING "REPORT WILL OVER
FLO!>I 8 Y "tI ":T C-30 :: DISPLAY ~T(5 . 1): '"
P' TO PRltlT ' M' rOR MENU"
8056 CALL ~EY( 3 . 1 EY , STArllSI
9058 IF STATU5=0 THEN 8056
905 Q IF I ~ EY ' 80 THEN 1 00
8068 CALL CLEAR :: DISPLAY AT ( 3 , I ) : " ENTER RE
PORT T IT LE" ACCEPT AT! q, ] l9EEP :RT$
906'2 D!SPLA'( AT (In ,! ) : "PRINTING,
8\1!63 PRINT 1t : : RPT'5(" ", (S,;I-LE N 'RT$) 1 I:» :
8064 PRINT tl 2 : R~ " " PRINT 1t 2 : " r-·""lNT tt
2 : " . , PR r tH tl 2 ;"
9070 FOR 0=1 TO RECS
9071 I F OPT'Ii""" N" THfN 9QI74
80 7 2 IF ARG $ ~S EG $ (A${(1 , FlDI , I . LEN ' r,f;:G-l' 1111£
t! 80813
911174 L$ = "" FO,~ 1=1 rc I·IF
9075 L Ii =L liLA$IQ , PCl J 1 l r l NF TliFt.1 L S=L$&c "

8076 NEXT L
8078 PR INT 1t 2 :L$
8079 IF p(0) <~ el THEN GOSIJB 82Q!0

125
Applications ______

8~8S NEXT Q
8982 IF P(0) = 0 THEN 8S9S
8S84 PRINT "2:" " :: PRINT #2:" .. :: PRINT ..
2:"TOTAL FOR ";FNM~(P{S » ;" ";TOT
8999 CLOSE .. 2 :: GOTO 199
81~0 CALL CLEAR : : DI S PLAY AT (3 ,1):"SEARCH 8
Y FIELD NAME ? YIN ." :: ACCEPT AT( 3 , 2 7)
VALIDATE ( "YN")BEEP:OPT~ .. IF OPT~ = ·N"
THEN RETURN
8119 DISPLAY ATCS,l):"SEARCH FIELD NAME . . . .
.. " :: ACCEPT AT('5,19) S IZE (- b)BEEP:FLD~
8120 FLD=~ :: FOR L = l TO FIELD S
81 2 '5 IF FLD~ = FNM~(L ) THEN FLD = L
81 3 0 NEXT L
8140 IF FLD = ~ THEN 8110
81'50 DI S PLAY AT(b.l':"ENTER S EARCH VALUE" ..
ACCEPT AT (7 .1):ARG~
8l b S RETURN
8200 RE CS = Q . . S UM - PC0 ' :: S= 1 •. GOSUB 7 100
:: 5= 0 :: RETURN

126
TI Word Processor
- - - - - James D. Bake<

This menu-based word processor includes many of the basic


features of commercial word processors: text creation, addi-
tion, deletion, modification, paragraphs, pagiNation, margin
control, page overflow, alld text centering. Written for the TI-
99/4A with Extended BASIC, a disk drive, and printer, the
program runs with standard 16K memory.
Just like thousands of other TI users, I have added to my sys-
tem since the original purchase of the computer and a TV set.
After I had purchased Extended BASIC, the Peripheral Expan-
sion Box, disk drive and controller, RS-232 interface, and a
printer, my next choice was word processing capability. All
the word processor packages available required 32K memory
expansion, so I decided to write my own word processor.
This program runs with standard 16K memory because of
linked list access for text files: Only one line of text is in mem-
ory at a time, with before and after indices pointing to the pre-
vious or following line of text.
With this design, addition and deletion of text lines are
possible. The addition of a single line or an entire paragraph
of text is also possible and, therefore, updating text after the
initial input process is easy.
Automatic pagination, margins (top, bottom, left, and
right), page overflow, text centering, and text modification are
also induded features.
The program is written in two distinct sections: first, the
create/edit section, then the print section. If additional fea-
tures are added, it may be necessary to split the program into
two separate programs in order to maintain the objective of
minimum memory usage.
Program Initialization
Upon initial execution of the program, the user will be asked
for a filename (assumed on DSK1) where text is stored. The
subroutine called in line 140 sets characters in lowercase.
Next, a screen menu is displayed with these options:

127
Applications _ _ _ _ __

N-NEW DATA FILE


A-ADD TO END OF EXISTING FILE
C-CHANGE EXISTING FILE
P-PRINT FILE

New Data File


Upon selection of the first option, a header record is written to
the opened disk file. This record is used to maintain a pOinter
to the last text record in the file. Initially, this record does not
contain any meaningful information, but will be updated at
the end of the program to contain the actual last record
number.
Control is then passed to the routine for entering new text
(lines 380-470). Original text is entered using the LlNPUT
statement, which limits the length of a single entry to 128
characters. However, this is not a severe limitation; the pro-
gram will simply cause wraparound of the text from one
record to the next. The computer will beep to remind you that
you have exceeded the length of the input string, and you
must then press ENTER to cause this record to be written to
disk and begin entry of the next record . Also, note that dur-
ing text entry all the standard control key operations are al-
lowed, including cursor left or right, character delete or insert,
erase, etc.
The pOinters for previous and next record locations are
then updated, and a check for one of the special control func-
tions, lEI, is performed. This is used to indicate the end of
text and must be entered as the last record of the text. If the
record just entered is not the end marker (fE/), the program
writes the text line to disk and returns for the next line of text.
When text entry is complete and the lEI is entered, lines
490-5 10 update record 0 with the record number of the last
record on file. Finally, the option of printing the text is of-
fered. If you answer Y for yes, control is passed to the print
routine (line 2400); otherwise the program ends.
Other special control functions are also incl uded for
editing. By entering lei as the first three ch aracters of the text
line, the print program will automatically center the text that
follows on that line. By entering IPI as the first three charac-
ters of a text line, the print program wili automatically indent
fi ve spaces for a new paragraph. Also, by entering INI as the
only three characters on a text line, the print program will

128
- _ _ _ _ _ Applications

automatically cause a top-ai-page routine to be executed.


These special control functions can be entered as upper- or
lowercase letters.
Appending
When this second menu option is selected, control is passed to
program line 600. This routine simply uses the pointer ob-
tained from the first record on file to retrieve the last record
on file (the l EI record). Then the last actua l text record is re-
trieved by using the previous record pointer from the JEI
record.
The last actual text record on file is then displayed, and
control is passed to the routine used fo r original text entry.
Changing an Existing File
With this option, the program retrieves the first text record,
using the pointer obtained from the first record on the file.
This line of text and a change menu are then displayed:
' ~ NEXT LINE 5 ~ ADD BEFORE
2 ~ LASTLINE 6 ~ ADD AFTER
3 = FWD X LINES 7 = CHANGE
' ~ BKW X LINES 8 ~ DELETE
9 ~ QUIT

Next Line. This option displays the next text line. If se-
lected, program execution is transferred to line 900. This rou-
tine first sets the number-of-records-forward counter to one.
The loop in lines 940-980 follows the next record pointer
through the file until the requested number of records forward
has been read.
A check is made to insure that a READ past the end of
file does not occur. If this is attempted, the program displays
the last line of text, a warning message, and returns to the
main change menu. Upon completion of the loop, program
control is returned to the main change menu.
It should be noted that the loop is not necessary in order
to display the next line. However, it is also used to advance
any number of records by using the third option discussed
below.
Last Line. This option displays the previous line of text.
The routine starting at line 1000 provides for stepping back-
ward through the text file. This routine is the same as the
prior routine except that the previous record pointer is used in
order to proceed to the previous record.
129
Applications ______

FWD X Lines and BKW X Lines. Both of these options (3


and 4) are handled in the routine beginning at line 1100. The
program asks for the number of lines to be read either forward
or backward. This value is then placed in the appropriate
counter, and control is transferred to the Next Line or Last
Line routine.
Add Before and Add After. These options (5 and 6), ini-
tially handled by the same routine (at line 1100), allow for
adding text; option 5 for adding before the current line, opti on
6 for adding after it. The program displays the current record
and , based on which type of add was requested, prompts you
to add before or after.
The new line of text is then entered and the record point-
ers from the current record are saved. The l EI is retrieved in
order to determine the next available location in the file to
store a record (next record pointer). This value is saved, and
then the lEI record is rewritten with the next record pointer
incremented. Based on the type of add being done, control is
transferred to the appropriate routine.
If you select Add Before (option 5), control is passed to
line 1350.
If you select Add After (option 6), control is passed to lin e
1450.
Control is then transferred to line 1430 and processing
continues as discussed above.
Change. This option allows you to change an existing line
of text. The routine for this option begins at line 1540. The
text line is broken into 14 lines of "equal" length. Using the
DISPLAY AT and ACCEPT AT statements all ows the setting of
default values for each of the subtext lines to their initial string
value. This eliminates the necessity of retyping the entire line
to make a minor correction.
The length of each of the subtext lines is calculated and
the first 13 lines are displayed. Note that a special character is
added to the end of each line. This is done so a space is not
lost at the end of the subtext line.
Line 1650 determines if there is any text remaining for the
fourteenth line. This is necessary to avoid an error if the string
happens to be less than 13 times the rounded. length of a single
subtext line length. The fourteenth line is then displayed in
preparation for change.

130
_ _ _ _ _ _ Applications

The 14 lines are then " looped " through, allowing any
changes desired. Note that the maximum length of any subtext
line is limited to 26 characters and that if the special end
character is accidentally deleted, the program will restore this
character. The length of the new text line is recalculated since
this length could now exceed the maximum string length
permitted by the computer.
After the text has been changed, the new text length is
checked to see if it exceeds 225 characters. If the length is less
than 226 characters, the text line is reconstructed and control
is transferred to line 2050.
If the length of the new text line exceeds 225 characters, a
menu offering two choices is displayed: either update as modi-
fied and create a new record on disk or reupdate the line. If
the reupdate choice is selected, control is transferred to the
beginning of the change routine with no changes made.
If the choice is made to update and create a new record,
lines 1900-1940 establish two new text strings consisting of
the first seven and last seven subtext lines respectively. The
current record being changed is then replaced on disk by the
first new text string created. The second new text string is then
added to the file using the Add After routine. Note that the re-
turn switch has been set in line 1950 causing control to return
to this routine after the add is completed.
The first of the new records is retrieved, and control is re-
turned to display this as the current record and to display the
main change menu.
If the change process did not cause a new record to be
added, lines 2050- 2130 display the changed text and offer
three choices: perform more updates, update the record as dis-
played, or exit with no updating.
Delete. The routine for this option, which allows you to
delete a line of text, begins at line 2180. You will be asked for
confirmation before the delete is executed. If the choice is
made not to delete the line, control is passed back to line 780
where the current line is redispJayed and the main menu
choices are available.
If you choose to delete the line, the previous and next
record pointers from this " to be deleted" record are saved. The
previous record is then read and updated with the next record
pointer from the deleted record. The record after the deleted
record is then read and updated with the previous record

131
Applications ______

pointer from the deleted record. Note that the record just
deleted is only deleted from the standpoint that the record
pointers no longer allow access to the record.
A check is then made to insure that this delete has nct
caused all text to be deleted. If this is the case, the program
displays a message to that effect and terminates. Otherwise, if
a record still exists before the deleted record, control is passed
to line 1000 and the previous record is displayed. If the record
prior to the deleted record is the header record, control is
passed to line 900, and the record follOWing the deleted record
is displayed.
Print File
The print routine begins at line 2400. Lines 2480-2540 estab-
lish the default values for top margin (TM), bottom margin
(BM), left margin (LM), page length (PL), lines per page (LPP),
and maximum line length (MAXWID). Print control infor-
mation is then requested, including mode of print (draft or fi-
nal), spacing (single or double), and optional page numbering.
The input file is then " restored" to restart from the first
record on file, and the printer output file is opened. Note that
the parallel port is used in this program. If you are using the
serial port for your printer, the OPEN statement in line 2730
will require appropriate changes.
The first record on file is read to retrieve the next record
pointer for the first text record . The main print " loop" begins
at line 2820 where the next text record is read using the next
record pointer from the previous record.
If draft printing was requested, control is passed to that
routine (line 2880). [f the current record is a forced new page
request UN I), the subroutine at line 3900 causes a page eject
and the top margin to be printed. Control is then returned to
the main print loop.
Line 2850 passes control to the ending routine if this is
the last text record. Otherwise, control is passed to the print fi-
nal routine (line 2980).
Print Draft. This routine (lines 2870-2930) simply prints
the lines of text in sequence exactly as entered. This includes
printing any special print commands, but does not effect these
commands. This is useful if you want to see what was entered
for verification purposes and do not want pagination, etc. This
print mode is also faster than final printing as the special print
commands are not executed.
132
- -_ _ _ _ Applications

Print Final. This routine begins at line 2980 and prints as


much text as will fit on the remainder of the print line, then
prints character by character until a space is encountered.
The Print Final routine first checks for any special print
commands. If a blank line, centered line, or new paragraph is
requested, control is passed to the appropriate routine. If the
last character on the text line is a period, two spaces are added
to the end of the line to insure proper spacing.
The centering routine begins at line 3550 by printing any
unfinished print line and checking for overflow. The length of
the text to be centered (excluding the centering command) and
the number of spaces required to center the text are then cal-
culated. The line is then printed and control is passed to read
the next record.
The routine to print a blank line begins at line 3700. This
routine simply prints the preceding line, a blank line, checks
for overflow and returns to read the next record.
The routines for top and bottom margins begin at line
3800 and simply loop for the necessary number of blank lines.
Page numbering is handled on line 3940,
Lowercase Definition
Finally, the DATA statements in lines 3980-4240 represent
lowercase letters. These values are aSSigned according to stan-
dard lowercase ASCII characters and are read using the loop
in lines 4250-4290.

TI Word Processor
100 RE M WORD PROCE SS I NG
130 DIM Al$(14)
140 GOsue 425121
150 CALL CLEAR
I bl2l DISPLAY AT(10.7 l : "WORD PROCESS I NG"
170 DISPLAY AT(ll.3l:" - ENTRY / UPDATE PROGRAM

180 INPUT "FILENAME - DSKi . N:F$


190 DISPLAY AT(b,8lERASE ALL: ASE LE CT OPTION "
2121121 DISPLAY AT(9.bl: "N - NEW DATA FILE"
21121 DISPLAY AT (11. bl: "A - ADD TO END OF "
220 DISPLAY ATCt2.10':"EXISTING FILE"
239 DISPLAY AT(14,b) : "C - CHANGE EXISTING"
24121 DISPLAY AT(15.1121):"FILE"
259 DISPLAY ATC17.6) : "P - PRINT FILE"
26121 DISPLAY AT(20. 10):" CHOICE"

133
Applications _ _ _ _ __

2 7 @ ACCEPT AT C2 0. 1 7) BEEP VA L IDATE ( "NACP" ) :C~


28@ IF L ENC C$ )= 0 TH E N 2 60
290 OPEN *l:"DS K l." ~ F~,RELATIVE,INTERNAL,UPD
ATE . FIXED 25 0
3 00 IF C$="P~ THEN 2410
3 10 IF C$="N~ THEN 320 ELSE 340
3 20 PRINT *l~REC 0:"EOF=";0;1
330 NXTREC=I :: GOTO 400
3 40 RECNO = 0
3 50 INPUT #l,REC RECNO : A$,EOFREC,NXTREC
3 60 IF C$ = "A" THEN 600 ELSE 670
370 REM
3 80 REM NEW ROUTINE
3 90 REM
400 CALL CLEAR
41£'1 LINPUT A$
420 LSTREC=CURREC
4 3 0 CURREC=NXTRE C
440 NXTREC = NXTRE C +l
4 5 0 IF SEG$CA$,l. 3 ) = " / E / " OR SEG$CA$, 1 ,3) = "1
e / " THEN PRINT #l,REC CURREC : A$;LSTREC;N
XTREC :: EOFREC = CURREC :: GOTO 490
460 PRINT #l,REC CURRE C : A$;LSTREC,NXTREC
470 GOTO 4113
480 REM UPDATE HEADER
490 RECNO = 0
500 INPUT #1,REC RECNO:A$ , HRECNO,NXTREC
510 PRINT #l , REC RECNO : A$,EOFREC , NXTREC
5 2 0 DISPLAY ATC1 2 .1)ERASE ALL:"DO YOU WANT T
o PRINT THE"
5 3 0 DISPLAY AT(1 3 .1):"REPORT NOW - YIN"
5411'1 ACCEPT ATCt3,18 ) BEEP SIZE(I)VALIDATE("YN
y n") :P$
550 IF P$ =" Y" OR P$ = "y" THEN 24111'1
560 CLO S E #1
570 END
580 REM
5 911'1 REM ADD ROUTINE
600 REM
610 INPUT #l.REC EOFREC:A$,CURREC,NXTREC
620 INPUT #l,REC CURREC:A$,LSTREC,DUMMY
6 3 0 CALL CLEAR
640 DI S PLAY ATC10,l):"LAST RECORD ON FILE IS
: "
650 DI S PLAY AT(12.1):A$
6611'1 LINPUT A$ :: LSTREC = CURREC . . CURREC=EOF
REC :: GOTO 4511'1
670 REM
680 REM UPDAT E ROUTINE
690 REM

134
_ _ _ _ _ _ Applications

7~" CALL CLEAR


7 10 RECNO=NXTREC
7211'1 INPUT #I , REC RECNO:A$.LSTREC~NXTREC
7311'1 DISPLAY AT(2.1):"CURRENT L INE"
74£'1 FOR 1=4 TO 13
7511'1 DISPLAY ATCI.1):" ..
760 NEXT I
7711'1 DISPLAY AT(4,1):A~
780 DISPLAY AT(14,1):"SELECT CHOI CE:"
7911'1 DISPLAY AT(16,lJ:"1=NEXT LINE{4 SPACES}S
-AD D BEFORE"
800 DISPLAY ATC17,l):"2=LAST LINE{4 SPACES}b
-ADD AFTER"
810 DISPLAY AT(18,l,:"3=FWD X LINES 7=CHANG
E"
820 DISPLAY Al(19, l,:"4 = BWK X LINES 8=DELET
E"
830 DISPLAY AT(20,lb): "9=QUIT"
840 DISPLAY AT (22, Il: "Y O UR C HOICE :"
8511'1 ACCEPT AT(22, 1 3' BEEP VAlIDATE("12345b789
" ) : C$
Sbe DISPLAY AT(24,1):""
8711'1 IF LENCC$)=0 THEN 8411'1
BB0 C=VALCC$)
890 ON C GOTO 911'18,1£'1011'1,111""'11,11£'10',118£'1,11811'1,1
5417.1,2180,490
900 REM
910 REM DISPLAY NEXT
920 REM
930 N8RFWD =1
940 FOR 1 = 1 TO N8RFWD
950 IF NXTREC =EOFREC THEN DISPLAY AT(24, 1):"
LINE DOES NOT EXIST" :: DISPLAY AT(2~ 1):
"LAST LINE OF TEXT" :: SOTO 740
960 RECNO=NXTREC
970 INPUT #l,REC RECNO:AS,LSTREC.NXTREC
989 NEXT I
990 60TO 7313
1009 REM
10113 REM DISPLAY LA ST
10213 REM
113 30 N8RBAC K=1
11340 FOR 1=1 TO NBRBA CK
1050 IF LSTREC =0 THEN DISPLAY AT(24,1):"LINE
DOES NOT EXIST" :: DISPLAV AT(2,l):"FI
RST LINE OF TEXT" :: GOTO 7 40
1060 RECNO=LSTREC
1070 INPUT #l.REC RECNO:AS,LSTREC,NXTREC
1080 NEXT I
1090 GOTO 730

135
Applications _ _ _ _ __

1100 REM
111121 REM FOWARD/BACK X LINES
112121 REM
113121 DISPLAY AT(22,16):"NBR LINES"
114121 ACCEPT AT(22,26)BEEP:NBRLNS
1150 IF C:3 THEN NBRFWD=NBRLNS :: GOTO 94121
1160 NBRBACK:NBRLNS
117121 GOTO 1040
118121 REM
119121 REM ADD BEFORE/AFTER
1200 REM
121121 CALL CLEAR
1220 IF C:6 THEN PRINT "ADD NEW LINE AFTER:"
ELSE PRINT "ADD NEW LINE BEFORE:"
1230 PRINT
124121 PRINT At;
1250 PRINT
1269 PRINT "ENTER NEW LINE" . . . .
127121 LINPUT ANt;
1289 HREC:RECNO
1290 HLST=LSTREC
1309 HNXT=NXTREC
1310 INPUT *I,REC EOFREC:A$,LSTREC,ADDREC
132121 HADD:ADDREC
1330 PRINT .1,REC EOFREC:A$,LSTREC,ADDREC+l
134121 IF C:6 OR RETSW:l THEN 1450
1350 REM
1360 REM ADD BEFORE
1370 REM
1380 PRINT .I,REC HADD:AN$.HLST,HREC
1390 INPUT *1,REC HlST:A$,LSTREC.NXTREC
1490 PRINT .I,REC HlST:AS.LSTREC,HADD
1410 INPUT .I,REC HREC:AS,LSTREC,NXTREC
1420 PRINT .I,REC HREC:AS,HADD,NXTREC
1430 NXTREC : HADD
1440 IF RETSW = l THEN 2010 ELSE GOTO 700
1450 REM
1460 REM ADD AFTER
1470 REM
1480 PRINT .I,REC HADD:ANt;,HREC,HNXT
1490 INPUT .I,REC HREC:AS,lSTREC.NXTREC
1500 PRINT .I,REC HREC:AS , LSTREC,HADD
1510 INPUT .1,REC HNXT:A$.LSTREC,NXTREC
1520 PRINT .1,REC HNXT:A$,HADD,NXTREC
1530 GOTO 1430
1540 REM
155121 REM CHANGE
156121 REM
1570 CALL CLEAR
1580 LENAl=INT(LENCA$) / 14)+1

136
- _ _ _ _ _• Applications

1590 FOR 1=1 TO 13


161210 AlS(II:SEGS(AS,LENAl'(I - ll+1,LENAI1&"

16010 DISPLAY ATCI.t>:"["


1620 DISPLAY AT(I,2):AlS(I)
1630 DISPLAY ATCI,2B):")"
1640 NEXT I
1650 IF LENCAS) ( =13'LENAI THEN Al$(14)="{,}"
:: GOTO 1670
16600 AlS(141=SE6S(AS,LENAl*13+1,LENCAS)-LENA
1'13)&"<,}"
1670 DISPLAY AT(14,1):"["
1680 DISPLAY AT(14,2':AtS(14)
1690 DISPLAY ATC14,28':"]"
170121
LENA::0
1710 FOR 1=1 TO 14
1729 ACCEPT AT(l,2)BEEP SIZEC - 26) :AlS (I)
1730 IF LENCAlS(I»=0 THEN AI'S(l)::"(.}" ELSE
IF SEGS(AlS(I),LENCAlS(I) 1.1' ( ) "{,}" T
HEN AlS(J,=AlS(I'L"<,}"
1749 LENA=LENA+(LEN(AIS(I» - l)
1750 NEXT I
1769 IF LENA ) 225 THEN 182121
1770 AS= ....
1780 FOR 1=1 TO 14
t 790 A$=ASLSEGS (A 1 .. ( I) • 1 ,pas (A 1 $ ( I ) , "(, }", 1 )
-1)
18£'1£'1 NEXT I
181£'1 GOTO 2£'15£'1
182£'1 DISPLAV AT (16,1): "NEW LINE TOO LONG"
183£'1 DISPLAV AT (18, I): "SELECT CHOICE:"
184£'1 DISPLAV AT(19,1):"I=UPDATE/CREATE NEW L
INE"
185£'1 DISPLAV AT(2e,I):"2=RE-UPDATE"
186£'1 DISPLAV AT(22,1):"VOUR CHO I CE"
187£'1 ACCEPT AT(22,13)BEEP VALIDATEC"12"':C$
188£'1 IF LEN(C$)=g THEN 186£'1
189£'1 IF C$="2" THEN 154£'1
19£'1£'1 A2$="· :: A3$=""
191£'1 FOR 1=1 TO 7
192£'1 A2$=A2$&SEG$ (Al$ ( I ' , I, POS (AI$ (I)." C.}".
1 ) -1 )
1930 A3$=A3$&SEG$(AI$(I+7',l,POS(Al$(I+7',"
C,}",l)-I)
1940 NEXT I
195£'1 RETSW=1
196£'1 HLDCUR=RECNO
197£'1 A""'A2'$
1980 PRINT .I.REC RECNO:A$,LSTREC.NXTREC
1990 AN$=A3$

137
Applications _ _ _ _ __

200111 GOTO 1280


20 1 0 INPUT .I,REC HLDCUR:A$,LS T REC,NXTREC
213213 RETSW=0
2030 CALL CLEAR
2040 GOTD 720
2050 CALL CLEAR
2060 DISPLAY ATC2,ll:"CURRENT LINEM
2070 DISPLAY ATC4,1}:A$
2080 DISPLAY ATCI4,1):"SELECT CHOICE :"
2090 DISPLAY ATCI6, l):"I=MORE UPDATES"
2HH!I DISPLAY AT(17,1):"2=UPDATE AS IS"
2110 DISPLAY ATCI8,1) : " 3= EXIT - NO UPDATE"
2120 DISPLAY AT(22,1):"YOUR CHOICE:"
2130 ACCEPT ATC22,13)BEEP VALIDATEC"123") : C$
2140 IF LENCC$)=0 THEN 2080
21S0 ON VALCC$)GOTO 1540,2160,720
2160 PRINT .I,REC RECNO:A$ , LSTREC,NXTREC
2170 GOTO 720
2180 REM
2190 REM DELETE LINE
2200 REM
2210 DISPLAY ATC24,1):"CDNFIRM DELETE - YIN"
2220 ACCEPT AT(24,221BEEP VALIDATEC"YyNn " ) : D

2230 IF D$="N" OR O$= " n" THEN DISPLAY AT(24,
I): "LINE NOT DELETED" :: GO TO 780
2240 HLST=LSTREC
2250 HNXT=NXTREC
2260 INPUT .I,REC HLST:AS,LSTREC,NXTREC
2270 PRINT .I,REC HLST:A$,LSTREC,HNXT
2290 INPUT .I,REC HNXT:AS,LSTREC,NXTREC
2290 PRINT .I,REC HNXT:AS,HLST,NXTREC
2300 LSTREC=HLST
2310 NXTREC=HNXT
2320 DISPLAY ATC24,1):"
2330 IF LSTREC >0 THEN GOTO 1000
2340 IF NXTREC=EOFREC THEN 2350 ELSE 900
2350 CALL CLEAR
2360 PRINT "TEXT NO LONGER EXISTS"
2370 PRINT
2380 CLOSE .1
2390 END
2400 REM
2410 REM WORD PROCESSING
2420 REM PRINT PROGRAM
2430 REM
2449 CALL CLEAR
2459 REM
2469 REH SET-UP DEFAULTS
2470 REH

138
_ _ _ _ _ _• Applications

2 480 TM=b
2490 BMEb
2500 LH -= t
251" PL:abb
2520 LC=0
253£1 LPP"PL - BM
2540 HAXWID -bB
2550 DI SPLAY ATCle,7): WORD PROCESSING"
2560 DISPLAY ATIlt,b): - PRINT PROGRAM - "
2570 DI SPLAY AT(tS,I): F ILENAME - DSKl.";F.
25B0 DISPLAY ATI20.l): PRINT HODE - OfF"
2590 DISPLAY AT(22,1) : SPACING - SID"
2600 DISPLAY AT(24,l): PAGE NUHBER (YIN)"
26 10 ACCEPT AT(20,20)S ZEll)BEEP VALIDATE("O
Fd-f"):Mt;
2620 IF LENIN$):" THEN 2610
2630 IF H$ z "d" THEN H$ ="O"
26 40 I F MS - "f" THEN Ht; . "F"
26S0 ACCEPT AT(22,20'SIZE(I)BEEP VALIDATEC"S
Dsd") : SPG$
2660 IF LEN<5PG$)=0 THEN 2650
2670 IF SPG$ z '·s · THEN SPGS_"S ·
2680 IF SPG$:"d " THEN SPG$="O"
269 0 ACCEPT AT(24,20)SIZE( I IBEEP VALIDATE( " Y
Nyn"):PGNO$
270 0 IF LENCPGNO$)=0 THEN 2690
2710 IF PGNO$:~yh THEN PGNO$=uY h
2720 RESTORE .1
2730 OPEN .2;"PIO"
27 40 GOSUB 3800
2750 REM
2760 REM READ INITIAL RECORD
277 0 REM
2780 INPUT *l:A$,LSTREC,NXTREC
2790 REM
2800 REM READ INPUT FI LE
2810 REM
2820 INPUT 11,REC NXTREC:A$,L STREC. NXTREC
2830 IF M$ - "D" THEN 2850
2840 IF SEG$(A $,l,3l . " / N/ " OR SEG$(A$, 1, 3)- "
In/ " THEN PRINT *2 :; LC=LC+l :: GOSUB
3900 :: GO TO 2800
2 859 TF SEG1;(A1; , I, 3 ) _ " / E / " OR SEG$(A$ , l, 3 )z"
l e I " THEN 2940
28 60 IF HS - "F~ T HEN 2980
2 87 0 REM
2 880 REM PRINT DRAFT
2 89121 REM
291210 PRI NT .2:AS
2 91121 LC = LC+l

139
Applications _ _ _ _ __

2 9 20 IF LC =L PP THEN GOSUB 3900


2930 GOTO 2800
2940 PRINT tt2
2950 GO S UB 391£'1
2960 CLOSE #1 . . CLOSE # 2
297121 END
2980 REM
299121 REM PRINT FINAL
30gB REM
3 010 IF LEN(A$' =12I THEN 36 9121
3"20 IF SEGS(AS . LEN(A"',l' = "." THEN A$=A .. ~··

3"'3£'1 IF SEG"<A", 1.3)="/P/" OR SEG$(A".1,3)="


/p/ " THEN 3 14 0
3121 4 0 IF S EG" ( A".1 ,3)= ·· /C/·· OR SE G$(A$,I,3' = "
lei " THEN 3540
305 0 IF PC+LEN(A$' (= MAXWID THEN 3 110
306121 NPOS=MAXWID-PC
31217121 STRT=1
312180 INIT = NPOS+l
31219121 IF INIT (l THEN INIT = 1
3 1121121 GOTO 33121121
3 11121 PRINT tt2:A$;
3 1 2121 PC=PC+LENCA$'
3 1 3121 GOTO 28 "'121
3 14121 REM
3 15121 REM **NEW PARAGRAPH**
3 160 REM
3 1 7121 IF PC >LM THEN PRINT # 2 . . LC=LC+l :: PR
INT # 2 :RPT$( " " ,L M) ;
3 18121 IF SPG$="D" AND P C) LM THEN PRINT tt2 ..
LC=LC+l .. PRINT # 2 : RPT$(" ",LM);
3 19121 PC=LM
321210 IF LC >=LPP THEN GOSUB 3 91210
32 10 PRINT #2 : "{5 SPACES}";
322121 IF LEN(A$'+LM+2 ) MAXWID THEN 326 0
3230 PRINT # 2 :SEG$(A".4.LEN(A$) -3' ;
32 40 PC=LEN(A$)+2+LM
325 0 GOTO 28 00
3260 NPO S= MAXWID-5 -L M
327121 STRT=4
328121 INIT = NPO S+ 4
32 90 REM
330121 REM **PRINT PAR TIAL LINE**
33 1 121 REM
332121 IF P C) MAXWID THEN 33 8121
333121 PRINT #2;SEG$(AS, ST RT,NPO S) ;
33 40 PC=MAXWID
3350 REM
3360 REM
140
- - -___• Applications

337il REM
33 80 FOR I = INIT TO LEN ( A. )
33 90 PC=PC+l
3 499 A2$ = 5EG.(A$ ~ I, 1 )
3 41 0 IF PC=l+LM AND A2$-" • THEN PC - LM .. GO
TO 3 44"
3 4 20 IF A2 $ = " " THEN 3 4b0
3 4 30 PRINT * 2:A2$;
3 448 NEXT I
3 4 50 GOTO 2800
3 4 60 INIT = 1 :: P RINT *2 :: LC=LC+l :: PRINT
*2:RPT$C" " . LM):
3 470 IF SPG$ - "D" THEN PRINT * 2 :: LC =LC+I
PRINT *2:RPT$ C" ".LM);
3 480 IF LC >= LPP THEN GOSUS 3900
3 49 13 PC = LM
35 00 IF INIT = LEN CA$)THEN 2 800
35 10 IF S EG.,(A$, INIT.l) = " .. THEN INIT oa INIT+l
:: GOTO 3590
3520 A$ =S EGS(AS.INIT.LEN ( AS) - INIT+l)
35311' GOTO 3 050
35 40 REM
355 0 REM CENTERING ROUTINE
356 9 REM
357 0 I F PC ) LM THEN PR I NT .2 .• LC = LC+ 1 :: PR
INT M2:RPTs(" ",LM):
3580 IF PC ) LM AND SPGS="D" THEN PRINT .2 ..
LC a LC+l :: PRINT MZ :R PTS(M ",LMlJ
3590 PC=L M
3 600 IF LC >= LPP THEN GOSUB 391210
3 610 C:""E N=LE N(A$) -3
3 6 20 S P=INT«MAXWID-LM - CLEN)/2>
3630 PRINT *2:RPT$(" -.SP+LM);
36 4121 PRINT * 2 :SEG$(A~.4,LEN(A~»
3650 LC=LC+l :: PRINT *2: RPT~ (" ". LM);
366121 IF S PG~ = "D " THEN PRINT *2 :: LC = LC+l
PRINT * 2 : RPT~(" ·'.LM);
3 6 7 121 IF LC >=LPP THEN GOSUS 391210
3680 GOTO 2800
3690 REM
3700 REM PRINT BLANK LINE
37 10 REM
3720 IF PC=LM THEN 3759
373121 PRINT .2 : : LC~LC+l
37 49 IF SPG$="D" THEN PRINT *2 :: LC=LC+l
3750 PRINT 12 :: LC""LC+t :: PR1NT .2:RPT~("
.. , LM) ;
376121 IF SPG~="D" THEN PRINT *2 . . LC - LC+l ::
PRINT tl2:RPT$(" ".LM):

141
App lications ______

3779 IF LC >=LPP THEN GOSUB 3999


3789 PC=LM
3790 GOTO 2800 •
3899 REM
3819 REM PRINT TOP MA RGIN
382121 REM
3839 FOR LC=1 TO TM
3849 PRINT .2
3850 NEXT LC
386121 LC = TM
3870 PRINT .2:RPT$(H H. LM);
3889 PC=LM
3 89" RETURN
3909 REM
391121 REM PRINT BOTTOM ~ TOP MARGINS
392121 REM
3939 FOR LCT=LC+l TO PL
394121 IF PGNO$="V· AND LCT = PL - 3 THEN PGNO~PGN
0+1 :: PRINT . 2 :RPTS(" ". 3 8)j"PAGE "jPG
NO ELSE PRINT . 2
395121 NEXT LCT
3 960 GOSUB 3 899
3 970 RETURN
3 98121 REM RE-DEFINE LOWER CASE CHARA CTERS
3990 DATA 900000 3 8043C443C
4090 DATA 9040497844444478
. 4019 DATA 9009003C4949493C
4920 DATA 0004043C4444443C
40 3 121 DATA 90999938447849 3 C
4940 DATA "918242029792929
4059 DATA 9009 3 048 3 8982819
412160 DATA 9949494078444444
4070 DATA 0919991919191919
498121 DATA 0994999494942418
4990 DATA 99494859b9594848
410121 DATA 0919101919191919
4119 DATA 0999992854444444
41 2 0 DATA 999999 7 844444444
41 3 9 DATA 999999 3 8444444 3 8
4140 DATA 9999 7 948 7 9494949
4150 DATA e0901C241C940404
41b9 DATA 09990058b4494040
41 7 0 DATA 000099 3C 40 3 89478
4189 DATA 999029792920 2 418
4190 DATA 99999944444444 3 8
420121 DATA 9999994444442819
4210 DATA 9"0090444454bC44
422121 DATA 99999944 2 819 2 844
42 3 121 DATA 9999442418192949
424121 DATA 000099 7 C0810 2 97C

142
_ _ _ _ _ _ Applications

4250 FOR 1=97 TO 122


4260 READ A$
4270 CAL L CH AR( I,A$ )
4 280 NEXT I
4 290 RETUR N

143
!
~
u
,
~
/

I
~

, I
~

, I
~
4
Trap
Larry Michalewicz

Each player must avoid the walls while trying to force his
opponent to collide witlt him or a wall. It gets tricky. A two-
player game, joyst icks required.

"Trap," written for the TI-99/4 and 4A, runs in TI or Ex-


tended BASIC. The object is to force your opponent to collide
with a wall while you avoid hitting any walls yourself. If you
cause your opponent to crash into your wall, his own wall, or
a boundary wall, you receive a point. The first player to get
five pOints wins the game.
Program Des cription
The playing field for the game is set up in lines 200-280.
Lines 250 and 260 draw the top and bottom barriers, and lines
270 and 280 draw the left and right walls.
The variables for player movement are initialized in lines
290-380. The beginning coordinates for player 1 are C1 and
D1; for player 2, C2 and D2.
Lines 410 and 470 examine input from the two joysticks.
If a joystick has not been moved or has been moved in a diag-
onal direction, the player will continue to move in the direc-
tion he or she was last going. The CALL GCHAR statements
in lines 520 and 570 determine the ASCII value of the charac-
ter in the next screen location. If this value is anything but a
32 (which is a s pace), then 11 or 12 is assigned the value of 1
depending on which player has collided.
Line 620 checks for a collision between players and walls.
If 11 (but not 12) is equal to 1, meaning the player on the left
side has crashed, the right side wins and is awarded a point.
Likewise, if 12 (but not 11) is 1, the left side wins and receives
a point. If both players collide (11 and 12 ~ 1) with a wall
simultaneously, each player is awarded a point.
When either player gets five points, the game is over.
Lines 830-840 then prompt for another game.

147
Recreation _______

Trap
100 P::0
110 Q::0
120 CALL CHARC1 20,"-'
13 0 CALL CHAR( 1 35,"")
140 CALL CHAR(13b,"")
150 CALL CLEAR
160 CALL 5CREEN(3)
170 CALL COLORC I 3 , l , 7)
180 CALL COLOR(14, 1,5)
190 REM 5ET UP PLAYING FIELD
200 PRINT ·PLAYER .1 "; P ,"PLAYER . 2 ";0
2 10 FOR 0::1 TO 22
220 PRINT
230 NEXT 0
2 40 CALL COLORCI2 ,2,2)
25 0 CALL HCHAR( 2,2,120,3 0 )
26 0 CALL HCHAR( 2 4, 2 , 1 20 , 3 0)
27 0 CALL VCHAR(2,2, 120,23)
280 CA LL VCHAR( 2.3 1,1 20,23)
2 90 C l :: 1 2
3 00 C2:: 1 2
3HI 01::4
320 D2:28
33 0 Rl =0
3 40 5 1: 1
35 0 R2= 0
36 0 52 :: - 1
37 0 11=0
3 80 1 2=0
390 REM MAIN L OOPCMOVEMENT)
400 CALL JOY5TC1,Bl,Al)
410 IF AB5(Al) - AB 5CB l )= 0 THEN 440
420 R l=Al / 4
430 5 1 = 81 / 4
440 Cl =C I -R l
450 01=01+51
460 CALL JOY 5T C2 ,82, A2)
470 IF AB 5( A2)- AB S CB2) =0 THEN 500
480 R2=A2/4
490 52:: B2 / 4
500 C2=C2-R2
5 10 02=02+52
52 0 CALL GCHARCCI,Dl,G)
530 IF 6= 32 THEN 550
5 40 11=1
550 CALL VCHAR (C l,DI,1 3 5)
560 CALL 50 UNO ( l ,262,0)
570 CA LL GCHARCC2,02,G)

148
_______ Recreation

5813 IF 6=32 THEN 6121121


5 9121 12:1
60121 CALL VCHAR(C2.D2, 1 36)
6 1121 CALL SQ UNO <1 ,290 ,0)
629 I F 11+1 2=121 THEN 4121121
6313 IF *
« I 1=1 1 2:: 1» +( ( 1 2 = 1) * ( 01+02 =32» THEN
7 1.
64121 IF 11 = 1 THEN 68121
65121 H$="LEFT S IDE WIN S "
66121 P=P+l
670 GO TO 7 4 13
6813 H$ = " RIG HT S IDE WIN S "
690 0=0+1
7013 GOTO 7 413
7113 H$ = "JT 'S A TIE"
720 P=P+!
7313 0=9+1
74121 PRINT H$
75 13 FOR 1=1 T O 212113
760 NE XT I
7713 FOR H= 1 TO 23
7 813 PRINT
79 121 NEXT H
8121121 IF cP <> S> .Hl <> SlT HEN 1 5121
8113 REM PLAY AGAIN?
8 213 PR INT ·PLAYER l"; P,"P LA YER 2 ";9
8 313 PRINT "DO YOU WANT TO PLAy AGAIN (YIN)?"
8413 CALL KEY (0 ,KEV,S T )
85121 IF S T =0 THEN 8413
8613 IF CK EY =89)+ ( KEY= 1 21)T HE N 1 12113
8713 END

149
Duck Leader
- - - - - Douglas E. Smith and Douglas W. Smith

This is 110 time to be feather-brained or daffy. There are


hunters lurking ill the maze of reeds ahead, and if you make
a wrong tum, you alld your (riends will be du ck soup. Two
skill levels, tell difficulty ratings.
This game will challenge your skill and memory. Your assign-
ment, as the leader of a squadron of 30 ducks, is to direct
them through a series of marsh mazes to the sa fety of a duck
sanctuary.
You must swim through five different mazes, each of
which has invisible reed patches and hidden hunters. The
reeds will send you back to the beginning of the maze. If you
find a hunter, you will lose a duck. Save as many ducks as
possible for a high score. Lose your sq uadron and it's all over.
Favorite Duck
After typing in the program, it's a good idea to list the pro-
gram, check for errors, and then save a copy to tape or disk
before ru nning the program.
When you start the game, the title graphics will appear,
followed by several questions.
1. LEVEL ~ ?(1 ~ HELP / 2 ~ NO HELP)
Enter 1 until you have gained confidence in your memory
and problem-solving ability. With level 1 you may use the H
key to quickly view the location of the reeds and hunters in
the marsh (up to fi ve times duri ng one game).
Level 2 will double your possible score, but you cannot
use the H key for help.
2. DIFFICULTY - (l - 10)
For your first game, enter 1. After some practice try the
other difficulty ratings. Ratings ]-4 are easy, 5-7 are hard,
and 8-10 are very challenging. The difficulty rating deter-
mines the complexity of the maze.

150
_ _ _ _ _ _ Recreation

3. INSTRUCTIONS? (YIN)
Enter Y to read the instructions before the game begins.
This screen briefly describes the game and the functions of the
appropriate keys used for the game. It also shows the graphic
characters used for the reeds, hunters, and the marsh exit.
4. FIRST NAME OF THE LEAD DUCK?
Type in your first name or the name of your favorite
duck, and press ENTER. The game will then begin.
If you entered Y for instructions, they will appear first. Hit
the 1 key to begin play.
At first the outline of the marsh appears, and then the
positions of the reeds and hunters are indicated. You have 15
seconds to study the locations before the reeds and hunters
become invisible.
Successful Maneuvers
The duck on the left side of the marsh represents your squad·
ron. Move the duck by using the arrow keys (E, 5, D, and X).
You do not have to press ENTER or use the FeTN key.
If you hit the sides of the marsh or the invisible reed,
your ducks will bounce back to the starting position, but you
do not lose an y ducks.
Meeting a hunter will result in gunfire and the loss o f a
duck, with the survivors returning to the start again.
The positions of the reeds and hun ters do not change un-
til you reach the exit to the next marsh .
Your goal is to maneuver your squadron to the right side
of the marsh and out the exit to the next marsh. Once you
have passed through the five marshes to safety, the program
will congratula te you, show you the remaining ducks, and
prin t your score.
The highest possible score is 6000 and can be achieved
only at level 2 with the difficulty rating 10. Nobody has
achieved this score to date.
The marsh border color changes to red if the sq uadron is
depleted to ten or fewer ducks. Losing all the squadron will
put you in Duck Soup, and give you a zero score.
After the score is printed, the program w ill ask PLAY
AGAIN? (YIN). Enter Y to play again at the last selected level
and difficulty. Enter N to choose a different level and
difficulty.

151
Recreation ______

The H key may be used if you selected level 1. Pushing


the H key while playing the game will give you a quick look
at the marsh. Using this key does not change the position of
the duck. You are limited to only five helps per game.
Remember the highest score using level 1 will be half that of
level 2.
On occasion, the program will generate a maze which is
impossible to cross. (Ducks don' t always have it easy, do
they?) Press the N key and you will move to a new marsh.
The change in marshes will cost the squadron five ducks, so
use the N key on ly if there is no way out.
Some Noteworthy Routines
The " Duck Leader" program employs several very useful TI
BASIC routines. Creation of the maze is accomplished using
the RND function to place the reeds and hunters (lines
620-670). The CALL GCHAR in line 800 tests the randomly
determined position for characters already present on the
marsh.
Line 800 checks to see if an empty space is present and, if
not, calls for a new set of coordinates to be generated.
The CALL KEY routine (line 890) is used to move the
duck through the marsh. Keys 68, 69, 83, and 88 determine
the direction of the move. Once again the CALL GCHAR is
used to test for an empty space. If fou nd, the duck is printed
in that position. If a reed or hunter is found, lines 1250-1260
execute the proper action.
Several loops and counters pause the program and keep
track of the ducks. Lines 690-720 give you time to view the
maze before the characters become invisible. The H key sends
the program to lines 1140- 1220, making the maze visible. The
ducks left are counted in lines 980 and 1310. The number of
marshes traversed is counted in line 1380. The score is cal-
culated in line 1550 and the ducks saved in line 1540.
Changing the Diff;"ulty
You may wish to make the game less difficult by making one
or more of the following changes:
1. Set the fi nal value in the FOR-NEXT loop in line 690 to a
higher value to increase the length of time you have to view
the maze.

152
_ _ _ _ _ _ Recreation

2. Increase the fi nal value for X in the FOR-NEXT loop begin-


ning in line 1170 to give you a longer look when you use
the H key.
3. Change the 5 in line 1150 to a greater number to increase
the number of times you can use the H key.
Program Summary
Lines
120-170 Reset random generator, define graph ic characters and
colors.
180-320 Print title graphicS and questions.
330-410 Duck animation GOSUB. Routine for title and game end.
420-500 Instructions.
510-610 Marsh and borderline.
620-670 Print reeds and hunters .
680-720 Allow view of the maze.
730 Make the reeds and hunters invisible.
740 Transfer control of the program to the call key routine.
750-820 Subroutine which randomly selects the positions fo r
reeds and hunters.
830-980 Use the call key routine to read the keyboard and to
branch the program for the desired action.
910 Check for the H key.
920 Check for the N key.
980-1030 Reset game for a new marsh.
980 Add five to total ducks lost (OL).
1040-1050 Sound for hitting reeds.
1060-1130 Reset value for position of the duck.
1140-1220 Reveal maze when H key is used.
1140 Check fo r level (1) input.
1150 Check for HELP limit.
1190 Count H key use.
1230-1270 Check the duck position for contact with reeds or hunters
or the Exit.
1280-1360 Print gunfire graphic, call sound, and increase DL by one.
1320 Check for OL = 20 and change border color if true.
1370- 1410 Return program for creation of a new ma rsh, and count
marshes completed.
1420-1460 Screen color change routine used to signify the beginning
and end of the game and of the completion of a marsh.
1470-1710 Print end-of-game message and play again prompt.
1540 Ca lculate ducks saved (OS).
1550 Calculate score.
1610 Print saved ducks.
1670-1690 Set OL, HELP, and MARSH !o O.

153
Recreation ______

1720-1800 Subroutine which defines the graphic characters.


128,129 Duck .
136 Border.
137 Exit.
112 Reeds.
113 Hunter.
120 Gun Shot.

Duck Leader
120 RANDOMIZE
13.0GOSUB 1720
140 CALL COLOR(1 3 ,2,1)
150 CALL COLOR(14,S,16)
160 CALL COLOR (11, 1 3, 1 )
170 CALL COLOR(12,10,1)
180 CALL CLEAR
190 CALL SCREEN(12)
2.00FOR X=1 TO 19
210 PRINT" DUCK LEADER DUCK LEADER"
220 NEXT X
230 PRINT
240 GOSUB 330
250 GO SUB 142121
26.0INPUT "LEVELs?(IEHELP/2=N0 HELP)":LEVEL
270 INPUT nDIFFICULTV~?(1-10)":DIF
280 IF (DIF < 1)+(DIF > 10)THEN 270
290 J NPUT "I NSTRUCT IONS ? (V IN) " : I NS$
30 "INPUT "FIRST NAME OF LEAD DUCK ?- :NAMES
3 10IF INSS:"Y· THEN 4 20
32" GO TO 520
330 FOR Y=12 TO 14 STEP 2
3 40FOR X=l TO 32
35 0CALL HCHAR(Y,X,1 29)
3 60CALL SOUND(25,-5,lS)
370 CALL HCHAR(V,X, 128)
38 0CALL HCHAR(Y ,X ,32)
390 NEXT X
400 NEXT V
410 RETURN
420 CALL CLEAR
430 PRINT NAMES:
440 PRINT ·YOU ARE THE LEADER OF A-: :-SQUAD
RON OF THIRT Y DUCKS." : : "PADDLE THROUGH
FIVE MARSHES- :
450 PRINT -TO SAFETY!! -: : "USE ARROW KEYS TO
Move": :"H -KEY FOR HELP(QNLV FIVE)": :"
N-K EY=NEW HAR S H(-S DUCKS)":

154
_ _ _ _ _ _ Recreation

460 PRINT "WATCH OUT FOR REEDS •• ": : "AND HUN


TERS!!": :"REEDS":"HUNTERS":"ExIT"
4 70 CALL H C HA R(2 1.1 2, 11 2)
480 CA LL HCHAR( 22 .1 2 .11 3 )
4 90 CA LL HCHAR( 23, 1 2 .1 37 )
500 INPUT "ENTER 1 TO 5TART ": SR T
510 GO T O 52t2l
'520 REM MAR S H
'530 CALL SCREE N ( l S)
540 CALL CLEAR
550 PRINT TABC101;"MAR S H _ "; MA RS H.!
560 CALL HCHAR(2,3,t 36 .28)
570 CALL HCHAR(22. 3 .1 36 .28)
580 CA LL VCHAR(Z. 3 ,1 36 . 20)
590 CALL VCHAR( 2 . 3 0. 1 36 ,20)
b00 CALL VC HAR( 6 . 7 . 1 36 . 1 2)
6 10 CAL L VC HAR( 9,30, 1 37 ,7)
620 FOR X= 1 TO COI Ft5)
630 GQSUe 750
6 40 CALL HCHARCRDW,COL. 11 2 )
659 Gosue 750
660 CALL HCHARIROW ,COL, 11 3 )
67e N ExT x
680 CAL L HCHAR(12.5.12B)
690 FOR X= l TO 50
700 CALL CO LORC1 3 ,9, 1 )
710 CALL COlOR(1 3,2, 1)
72 0 NE XT X
730 CALL SC REEN(1 3)
749 GOTO 839
750 REM RAN ROW+COL
769 ROWEINTC22tRND)
770 IF ROW <3 THEN 7b0
78 9 COL: INT C39 ' RND )
790 IF COL< 4 THEN 780
800 CALL GCHAR(ROW,COL ,G RC)
810 IF GRC <>32 THE N 7 60
820 RETURN
8 30 REM MOVE DUCK
849 R= 1 2
8:58 C- S
860 CALL HCHARCR .C ,1 2 9)
870 CALL SOUND(2S, - S,IS)
BBB C ALL HC HAR(R .C. 1 28)
B90 CALL KEYC0,KEV,ST)
900 IF (KEV=69)+(KEY=69)+(KEV=72)+(KEV - 78)+(
KEY - 83)+CKEY - 9B)THEN 910 ELSE B90
910 IF KEY=72 THEN 1140
920 IF KEY=79 THEN 980
930 CALL HCHARCR,C, 32 )
155
Recreation ______

.40 IF KEV = 68 THEN 1060


.50 IF KEV=69 THEN 1@80
960 IF KEV=8 3 THEN 1100
.70 IF KEY:88 THEN 1120
'80 DL = DL+'5
" 0 IF DL > 19 THEN 1000 ELSE 104£'1
1121121121 CALL COLOR(14.S.9)
112119 IF DL >=3 9 THEN 1029 ELSE 1049
1929 DL=39
1939 GOTO 1479
1949 CALL SOUND(109,500.0)
195121 GOTO 529
1960 C=C+l
1979 GOTO 1230
198121 R=R - l
1999 GOTO 12 3 9
1190 C:C - l
1110 GOT a 123 0
1120 R=R+l
1139 GOTO 123 0
1140 IF LEVEL < > 1 THEN 890
I1S9 IF HELP =S THEN 1219
1169 CALL SCREEN(1S)
1179 FOR X=1 TO 59
1189 NEXT X
1190 HELP = HELP+l
1 2 00 CALL SCREEN(13)
1210 CALL SOUND('5.1@00,l)
1229 GOTO 890
1239 CALL GCHAR eR, C,G R)
1249 IF GR=32 THEN 8 6@
12'59 IF (GR=136)+(GR=112)THEN 1 3'5 9
1 2 60 IF GR:113 THEN 1280
1 270 IF GR=137 THEN 1 37 0
128@ CALL HCHAR(R,C ,12 0 )
129121 CALL SOUND(I,20S,I)
1 3 09 CALL HCHAR(R,C, 11 3)
1310 DL ::D L+I
1 32 9 IF DL =20 TH E N 1 330 E L SE 1 3 40
1 339 CA LL COLOR( 14. 5,9)
1 3 49 IF DL=30 TH EN 1479 ELSE 8 4 @
135121 CALL SOUND(59,-1,10)
1360 GOTO 8 40
1370 REM NEW MARSH
138121 MAR S H=MARS H+I
1390 IF MAR S H=5 THEN 1479
1499 GOSUB 1420
1419 GOTO 5 2 0
1420 FOR SC=4 TO 16
14 3 @ CALL SCREE N( SC)

156
_ _ _ _ _ _ Recreation

1440 CALL SQUND<I.3000.1)


14 50 NEXT SC
1460 RETURN
1470 REM END OF GAME
14BI!! CALL CLEAR
1490 CN=INTC (2B - LEN(NAME$) )/2)
1500 PRINT TABCCN)jNAMES:
1510 IF DL =30 THEN 1640
1520 SOSUS 1420
1530 GOSUS 142121
1540 DS=30 - DL
1550 SCORE=LEVELtOIFtOS.10
1560 PRINT "CONGRATULATIONS YOU SAVED": : TA
B(Hn;DSj"DUCKS!": :TAB(Sl;"FOR A SCORE
OF ";SCORE
1570 FOR X=l TO 12
1580 PRINT
159121 NEXT X
161210 CL=INT« 32-DS)/Z)
1610 CALL HCHAR(b.CL.12B,DS)
1620 BOSUe 330
1630 GOTO 166121
1640 REM DUCK SOUP
1650 PRINT "OH NO ! ! YOU'RE DUCK SOUP": :TAB(
11);"SCQRE=0":
1660 INPUT "PLAY AGAIN ?(Y/N)" :PLAY$
1670 DL=0
1680 HELP::0
1690 MAR S H=(:'I
1700 CALL COLOR(14,S,16)
1710 IF PLAY$="Y" THEN 52121 ELSE 1810
172121 REM CALL CHAR
1730 CALL CHAR(128,"00040804FE7C8800")
1740 CALL C HAR(129,"00081b08FE7C4400" )
1750 CAL L CHAR(13b,~00AAAAAAAAAAAAAA")
1760 CALL CHAR(137."00080C7E0C080000~)
1770 CALL CHAR(112 , "00AAAAAAAAAAAAAA")
1780 CALL CHAR(113."0000609090677Cb4")
1790 CALL CHAR(120."S142241818244281")
1800 RETURN
1810 END

157
Freeway 2000
- - - - - John B. Dorff

Dare you cross the freeway of the future? You better ',ave all
your wits together, for this ;s olle grueling highway. It will
take all the cUl/ning and speed you call muster to cross this
fen-lane roadway. Requires Extended BASIC and joysticks. A
Speech Synthesizer is optional.
If you've been trying to write games in BASIC, you have prob-
ably found out that it can be difficult to design fast-action
games. Creating a game with many moving objects on the
screen, moving in all directions, is next to impossible; BASIC
is just too slow. Still, with TI's great graphic and sprite
capabilities, there are ways to create fun and exciting games
once you learn to work with BASIC's limitations. Extended
BASIC is the best way to create such a game.
"Freeway 2000" is just such a game. It takes advantage of
TI's graphics and sprites. To save program space, there are no
REM statements or instructions for the game included in the
program. For the same reason, and to increase speed, almost
all the lines in the program are multistatement lines. Save the
program after you have typed it in and before you run it.
Some speech has been added to enhance the game, so if
you have a speech synthesizer, connect it before you play.
There is nothing like a game that compl iments you when
you've made a good run, or chides you when you goof.

Crossing the Road


The object of the game is to get across the ten·lane highway,
using a joystick to guide your runner, without getting hit. Each
time you make it across successfully, the level of difficulty in·
creases. At the start of the game, you score ten points for each
lane passed, one thousand points for making it all the way. As
the levels increase, the points per lane increase. You start off
with six runners, gaining an extra one at six thousand point
intervals. The game is for one or two players, so challenge a
friend! Remember to ha ve the ALPHA· LOCK key up when
playing.

158
_ _ _ _ _ _ Recreation

Here's a short explanation of the program:


Line # Comment
10- 30 Call up needed speech words, construct the suffix "s" and
add it to certain words.
40-150 Title screen, defi nition of characters, and initialization of
variables. Many va riables are used to save space and to in-
crease program speed. The more important ones are:
L(l), L(2)-Player levels;
E(l ), E(2)-Score that must be reached to gain an extra
runner;
W(1), W(2)-Number of runners the players have left;
Z(1), Z(2)-Players' scores;
B(l), B(2)- Bonus points;
P-Player number.
180 Input one· or two-player game.
170-220 Set up the playing screen.
230- 320 Define sprites (cars and runners).
330 Random ly select the cars' speeds for each la ne, dependent
on the variable L(P)-player level.
340- 430 Set cars in motion.
440-460 Main control loop.
470-580 Sorry, you got hit! These lines play appropriate sound ef·
fects and find Ihe runner's position for scori ng.
580- 690 You made it across! These lines add the appropriate points
and check to see if an extra runner shou ld be awarded.
Also increase the player's level.
700-720 Main conlrol loop. (This is used when the runner is on top
of the screen and must come down to cross the freeway.)
730-780 Same as 470-560.
790- 800 Input to play agai n; reinitialize.
810-820 Input to continue the same game or start a new one;
reinitialize.
830 This subroutine waits for you to press a key to answer.
840-850 This subrou tine creates varied car sounds, dependent on
the variable O.
860-920 These lines check to see if the game is over. If not, they
subtract a ru nner and change the player number in a two'
player game. They also award an extra runner at 6000 poin t
intervals.
930 Data for constructing the suffix "s".

Fr eeway 2000
1~ RANDOMIZE : : CALL SPGET(MSET" . S$) : : CALL
SPGET(HGOOD".G$) :: CALL SPGET(" MOVE". M$ ) :
: CAll SPGET("WEll". W$)

159
Recreation _______

20 CALL SPGET{"WHAT",WHS):: FOR 1 = 1 TO 29 ::


READ A :: SSS=SSSlIcC HR$ ( AI;: NEXT J
30 J=LEN(MSJ -13 :: MS=SEG$( MS,l ,2J& CHRS(JJ&S
EG$(MS,4,J ) :: J=LEN(WHS) - 1 3 :; WH$=SEG$(W
HS,1, 2)&CHRS(J)&SEGS(WHS,4, J )
413 CALL CLEAR :: 0=18130 :: GOSUS 84~ : : DISP
LAY AT( 3. 4 ):·· ••• 'FREEWAY 2000 ' . ' * " .. L(I
) ,L (2)=S :: Vl= -2 . 5 :: V2=2.S :: 0=33 : :
Ql = 1 38
5 0 CALL SOUND(80,570,5,356,5) : E(I ) ,E(2)=60
00 :: W(1) , W(2)=5
60 S NDI (0)=430:: S NDl(1 )=5 14 .. SNDl(2)= 470
.. SND 1 (3) =3 95 : : S ND 2 (0) =300 :: SND2 (1 )
=3 59 : : SND2(2 )= 390 :: SND2(3)=24 1
70 CALL CHAR(9 6," 00 3C "):: CALL CHAR C97, "0000
003C"):: CALL CHAR CI04. "000000FFFFFFFFFF ·'
): : CALL CHAR(99, "0000000~ 0 0 3C")
80 CALL SOUND(15@,571Z1,5,356,S) : : CALL CHAR(1
05,""):: CALL CHAR(J00,"0000000@0000003C"
):: CALL CHAR(1 30 , " 191AFEBC983C4484")
90 CALL CHAR(128,"0066C9DDDDD OC 9660066938 8BB
B89366 " ) :: CALL CHAR(132 ,"000CE4 3 F3FE40C0
0"):: P =l .. Z (1), Z( 2)= @ : : 8(1),8(2)=100
o .• U=110
100 CALL SOUND(S0 , 4 30,3 , 3 00. 3) .. DI S PLAY AT(
12,1):"OARE YOU CRO SS THE FREEWAY" .. 01
SPLAY AT(1 3, t ) :"OF THE FUTURE ?????? "
110 CALL SOU ND( 80.430,3,3013,3) :: 0=2400 :: G
OSUS 840 :: D I SPLAY AT{l 3 , 1) : "
(18 SPACES }" .. DISPLAY AT(12,1):"ARE YOU
INTREPI D ENOUGH . .. N
120 0=1 600 :: GOSUS 8 40 :: DI S PLAY AT <13,1):
"ADROIT ENOUGH . . . . ·' CALL SOUNO(15e, 4 7
0 ,S,390,S) :: FOR X=1 TO 15 0 :: NEXT X
13 0 CA LL SOU ND ( lS~ , 470.S,390 , 5) :: FOR X= l TO
200 :: NEXT X . . DISPLAY AT(14 , 1):"INSA
NE ENOUGH TO T RY?'" .. 0=220121 , . GOSUB 8
4.
14121 CALL CLEAR:: DISPLAY AT ( 12,S) : ''GOO~ LUC
K,FRIEND.. . ... FOR 0::: 1 TO 1"'13 :: NEXT
o :: CAL L SOUND(4e@ , S14 . 3 . 359 , 3)
15121 FOR 0=1 TO 300 :: NEXT 0 DISPLAY AT(I
4,S):"YOU 'L L NEED IT!!'!"" . . 0=1800 ::
GOSUS 840
160 CALL CLEAR :: DISP L AY AT(1 2 ,BlBEEP SIZE(
15 ): "lOR 2 PLAYERS?" . . GOSU8 B30 :: IF
K:::49 THEN A=l ELSE A= 0
17121 CALL CLEAR .. CALL COLOR(2,2, 1 3) : : CALL
COLOR( 3 ,2 , 13):: CA LL COLOR(4,2, 13):: CAL
L COLOR(B . 2 . 1 3 ):: CALL COLOR(1 3 ,2,13)

160
- -_____ Recreation

1 8121 CALL COLORC I 0, 1 3 . 16):: CALL COLOR(9 , 15, I


6) :: CALL CO L OR(7,2,13' :: C ALL COLO R ( I, 2
,13):: CALL COLOR(S , 2 . 1 3) : ! CA L L COlORC6
, 2, 1 3)
1 9121 CALL HCHAR(l, 1,32, 16121) : : CALL HCHAR (1 9 , 1
, 32, 19 2): CALL H CHAR(6, I. J05,32 ) .. CALL
HCHAR C7 . 1 . 96 . 32) ;: CALL HC HA R(B, 1,97,32
)
2121121 CA L L H CHAR (9, 1,99, 3 2) :: CALL HC HA R ( Ie, 1 ,
11210 ,32) : : CAL L HCHAR ( t 1 , 1, 1121'5,32) : : CALL
HC HAR(12 .1. 96 . 32 ) :: CALL HCHA R( 1 3 . 1 . 97,
3 2)
2 1 121 CA LL HCHAR( 1 4 , 1 . 99 . 32); : CALL HC HAR(15,1
, 1121121 ,32) :: CALL HCHA R CI6 , 1 , 105, 32' :: CAL
l H CHAR ( 1 7 . 1 ,9 6 ,32) : : C ALL HCHAR ( 18, 1. 10
4 ,32 )
22 121 DISPLAY AT (1.1) 5 1 ZE (8): "PLAYER I" • • IF
A= 0 THEN DI SPL AY AT (2 ,1) S IZE ( 8 ' :" PL AYER
2"
23121 CALL S PRITE(tt1.1 28 ,2,41 ,12. "2 , 1 2 8 . '5,4J,6
3, "4 . 1 28,3, 41 , 18 7 )
2 4 £1 CALL S PR I TE (ItS, 1 29,6.5 1. J@£I, tl6, 1 2 9 ,7 ,51,
2€10. lt 7.129. 15 . 51,224)
25121 CA L L SPRITE( 1t 8 . 1 29.2 . 6 1 .6@. lt9,129 , 3 ,61,1
88)
26121 C AI. L S PR I TE ( 1t1 0. 128. 14,71,90, tt l J , 128, 7,7
1. 190 ~ # 1 2 .
128.9. 7 1. 22121)
27€1 CALL SPR ITE ( ltI 3, 129 . 5 . 8 1. 79 •• 14 . 129, 1 3 ,8 :
1 , 1 09, . 3 . J ~9. 2 . 8 1 . 235)
28€1 C ALL SPRITEC It1 5.1 2 8 . 7.9 t.1 23 . • 1 9 .1 28, 15,
91 . 2~0 ,tt J6 .1 28, 4.I "JI , 30, tlI 7. 1 ?'8.7 . _10
1.6121,ttI8. 128.6. 1 1111. 179)
29121 CALL S PRITEC lt 2 0.129,5.111.115.1t 2 1.129, 2,
1 1 1 , 1 4 5, tt 2 2 , 1 29, 1 4 , 1 1 1 _ I 75 )
3£1121 C A L L SPR ITE(tt 23, 128, 1 5 .1 21,84,1t 24 . 129,9 .
121, 168,tt25, 1 2 9 , 7 , 121,2 3 5)
31121 CALL S P RITE( tt 26. 1 29.5,131 , 6 8 ,# 27 . 1 2 9 , 2 . 1
31 ,184 )
32121 DISPLAY AT( 2 2, 1 ) : "PLAYER" ; F : : CALL SPRI
TE( . 28 ,1 311' . 2.16I1', 1 27)
33121 DISPLAY AT (5. 111'): "GET READ Y " " •• C AL L H
C HAR (2 4. 3 ,1 30. W (P» ; : C ALL S AY("GET " . S $ )
. . FO R N =1 TO H I : : S( N )= INT(RNO*L(P) I- \
121 : : N EXT N
3 4 121 HH=INT(R N D *4 ) : : CA LL MO T ION(#1 , 0 . - S (l l .1t
2 . 0, - S ( 1 ) , It 4.e.
-5 ( J ) )
35121 CALL MQTION(tt5,0,S( 2 ), tt 6, 0 , Se2 ) . ~ 7 .0 . S (2
»
36 121 CALL MOT ION ( tt 8,I2I,Se3) . ~q . 0 . S(3)
37121 CALL N OTIO N ( ttl €1 . 0. - S( 4),#! 1.0, -5( 4) _# 1 2 ~
0, - S( 4 })
161
Recreation _______

380 CALL MOTION<#1 3,0. S(S),'14,0,S(5 ), # 3 ,0,S


(5) )
390 CALL MOTION ( '15,e, - S(6),'19 , 0, -S (6»
400 CALL MOT ION C' 1 6,0, -S (7),'17 ,0,-S(7), #18 .
0, - 5(7»;: DISPLAY AT(S,10) ; "{4 SPACES}G
O! ! " . . CALL SAY (" GO")
410 CALL MOTION(#20,0 , S(8),'21,0,S(8),#22,0,
S ( 8) )
4 20 CALL MOTION(' 23 ,0, -S(9), #24,0, -S(9 ),#25,
O, -5 (9»)
4 3 0 CALL MOTIONC'2b,0, S( 10 ), # 27,0,S( 10) ) ; ; 0
ISPLAY AT(5,10):"{12 SPACES}" .. IF 0 = 1 T
HEN 700 ELSE 0=0
440 CALL JOYST(P,X,Y):: CA LL CO JN C(ALL~C) : :
IF C THEN 4 70
450 CALL MOTIONC.28,Y*Vl,X*V2):: CAL L POSITI
ON('28,R,V): : CA LL JOYSTCP,X,Y) ;; CAL L C
OINC (ALL, C) :: IF C THEN 4 70
46 0 CALL MO T ION C'28,Y'Vl,X,v2) : : IF R } Q THEN
440 ELSE 570
470 CALL SO UND(800,SN D I (HH),5,SN02CHH),5)::
CALL MOTI ON(. 28,0,e) :: CALL PATTERN('28 ,
13 2)
480 CALL SO UNO(10 ,55 4,l ) :: CA L L S OUND(10,52 3
,2):: CALL SO UNO C10 ,494,3): : CALL SOUND(
10 , 466 , 4):: CALL SO UND(10,440,5)
490 CA LL S OUND ( 10,415,6 ) :; CALL SOU ND(1 0 . 3 92
, 7 ): : CALL SDUND(I~ , 37@ ,eJ:: CALL SQUND(
10,349,9):: CA LL S OUND(1 0,330, 10)
500 CALL PO S ITION C# 28 ,R,V) :; ON HH+l GOTO 51
0,520,530,540
510 CALL SAY C. WH$& SS -', "THAT " ) :: GOTO 550
520 CALL SAYC" S ORRY"):: GOTO 550
5 3 0 CALL SAYC"OH",W.):: GOTO 550
5 40 CALL SAYC, WH. &SS.,"THAT")
550 FOR 0=1 33 TO 4 3 S TE P -10 :: I F R( D THE N
ZCP)=Z(P)+L(P) + L(P) :: U= U+ 8 . . CALL SO UN
DC5,U,0):: DI SP LAY AT(P.9);ZCP)ELSE 870
560 NEXT D : : GO T O 870
570 CA LL MOTIONe. 28 r 0 ,0):: IF R ) 170 OR R< 20
THEN ZCP)=0 :: DISPLAY ATC20 . 1 2):"NO F AY
R!" • . CALL SOUND{500,-3 . 0) :: GOTO 860
580 DISPLAY AT( 20 ,?) S JZE C1 3) :"NICE RUN N ING ! "
.. DI SP LAY AT(21,6 )SIZ E(19 ) : S T R $(BC P») ~
" BONUS POINTS! ~ " 0 = 0+1
590 ON HH+l GOTO 600,610,620,630
600 CALL SAY(" MEAN" , M$ &SS . ) : : GOTO 6 4 0
610 CALL SAYC "VAR Y",G.):: GO TO 6 40
620 CALL SAY( . W$,"OONE"):: GOTO 640
630 CALL SAYC,GS,"GOING" )

162
_______ Recreation

640 FOR 0 = 1 TO 10 :: V-U.S : : Z(P)=Z(P)+L(P)


+ L(P ) :: CALL SOU ND (5~U,0) :: DI SPLAY ATCP
~9) :Z(P):: NEXT 0 : : V - I t 0
650 LCP '= LCP)+t : : Z(P>=Z(P)+B<P): : CALL S OU
ND( 5 0~ S NDl(HH ) , 3,S N D2( HH ) ,3) :: CALL SO UN
~J O(100,SNDl(H H ),3,S ND2 (HHI.3)
66 0 DI S PLAY A T (P , 9):1(P):: IF Z(P)< E(P)THEN
680
670 W(P) = W( P)+I :: E(P)=E(P)+b000 :: CALL He
HAR (2 4,W(P)+2, 1 30) :: CAL L SQ UND ( 1 0.3
49 ,0) :: CALL S QUND(10,5 23 , 0)
680 CALL HCHAR( 2@,9,32,50 ' : : IF L(P)-11 OR L
(Pl = 1 6 OR L (P)=2 1 THEN B(P)=B(P)+ t 000
690 GO T D 330
700 CA LL JO VST(P,X,Y) :: CALL COINC(ALL . C);
IF C THEN 73 0
710 CALL MQTIONC .. 28,V .Vl, X.V 2, : : CALL PDStTI
ONC M28,R,V) :: CALL JOY STCP ,X, Y) :: CALL C
DINC ( ALL, C) :: IF C T HEN 731t1
720 CALL MOTI ON C"# 28 . V* Vl , Xtv 2) : : IF R< Ql TH E
N 7 99 ELSE 570
739 CALL SOU ND (800.S NDl ( HH ),5,SN D2( HH),5) ::
CAL L MOTION( * 28 ,@ ,0)
7 4 9 CALL PA TT ER N (~28,132): : CALL SOU NO(10,55
4 , 1 ):: CALC SOUND( 1 0,523 , 2l :: CALL S OUND
(19, 494 .3) :: CALL SOUNO(10~466,4):: CALL
S OUNOC19 . 44 9,5)
759 CALL SOU ND (10 ,4t 5 . 6):: CAL L SOUNOCJ0.392
. 7) :: CALL SDUN O(l@. 379,8) :: CALL SOU NO (
113,3 4 9,9) :: CALL S OUN D ( 1 0',33£1 , HI)
76£1 CA LL SAY("SORRY - ' : : CALL POS ITION ( # 28,R,
V)
770 F OR 0=49 T O 1 30 STEP 19 :: I F R ) D THEN Z
(P)=Z( P'+L ( P'+LCP): : U= U+ 8 .. CALL S OUND
(5 ,U. 0' :: DISPLAY AT(P.9' : Z(P'ELSE 87£1
780 NEXT D :: GO TO 879
799 CA L L S Aye"TR Y AGAIN") : : DISP LA Y AT( S,7'B
EEP :" PLAY AGAI N?(Y, N )" .. GOSUB 8 3 9
80121 IF K= 11 @ THE N CALL SAye"GOODBYE") :: CALL
CLEAR :: STOP
8 113 W(1) .W (2'=5 :: P; l . . 0,ZCl',Z(2)=0 D
I S PLAY AT(5,7)BEEP:" CON TI NUE GAME ?"
GOSUB 839
8213 IF K= 1 21 THEN 1 6£1 ELSE E(I) , E(2)=699@ ::
8 ( 1 ) • B (2) = 1£199 :: L ( J ) , L (2) =5 :: GOTO 1
6.
830 CA LL KEY(0,K . SS) :: I F SS=0 T HE N 839 ELSE
RETURN
840 FOR X= 18 TO £I STEP - 1 CA LL SO UNO (69 ,2
00 . 30 . 20 £1 . 3£1 . 0 . 39,-B , X' : NEX T X

163
Recreation _______

850 FOR X=0 TO 18 :: CALL SO UNDf60,200 , 30,20


0,30,O,30,-8,X):: NEXT X .. RETURN
abe DISPLAY AT(P,9):Z(P): ; FOR D=1 TO 10121 ;:
NEXT 0 :: CALL HCHAR f20, 14. 32,8)
870 U=1 10 :: IF ZfP»E(P)-1 THEN W(P)= W(P)+ l
.. CALL HCHARC24,W(P)+2,130):: EcP)=ECP
)+6000 :: CALL SO UND( le . 3 49.0 ) :: CALL so
UNO<1e, 523, 0)
,.
88121 0=121 : : IF W(P)THEN W(P) =W(P ) - 1

890 DISPLAY AT(22.11):~GAHE OVER"


GOTa 9

FOR 0 = 1
TO 200 :: NEXT 0 : : IF A THEN 790
900 CALL HCHAR(22,11, 32 ,9) :: IF P=l THEN P=2
. . A= l ELSE P=l .. A= l
91. CALL HCHAR(24 ,3 , 32 ,10):: IF A THEN 320
92. IF P=l THEN P=2 : : GOTO 320 ELSE P=l
GOTO 32 0
930 DATA 96,0,26,14,5b, 130,204,0,223, 177,26,
224, 103, 85, 3, 252, 11216, U36, 1 28, 95. 44, 4 , 2 40
,35,11,2,126,16,121

164
The Chase
- - - - - Dennis M. Reddington

"The Chase" is a chal/enging action game. It's a relatively


fast-moving game written in Tl BASIC.

Watch ou t for those ghosts. If they catch your jewel coll ectors
the price can be quite costly: Once all six of your collecters are
caught, the game ends.
The object of " The Chase" is to collect jewels. The play-
fie ld for The Chase is a 7 X 11 grid. Move your jewel collec-
tors around by moving the joystick or by using the keyboard's
arrow keys (E, up; X, down; 5, left; and D, right). If you man-
age to gather all the jewels you' ll move to the next level of
play. Be careful-don't let a ghost catch your jewel collector,
for if he's caugh t all the jewels will be placed back onto the
playing grid.
Design Considerations
The Chase is of interest to a TI-99j 4A programmer because it
demonstrates some ways to develop a relatively fast moving
game in BASIC that pressures the player to keep moving. Sev-
eral of the game design and programming considerations used
in The Chase can be used in other BASIC games to speed up
the action. They include:
• The use of color changes to give the appearance of fast game
action;
• Limiting the playing grid's size to a relatively small portion
of the screen so that, in a game like The Chase, captures and
escapes can take place quickly;
• Randomly generating each game to add variety to the game's
play;
• Checking first for the more common joystick movements and
thus reducing the amount of time required to react to the
player'S request to move;
• Changing character patterns on the screen to give the player
the feeling of action;
• Minimizing the time-consuming task of displaying the score
and other text;
• Coordinating the sound with joystick movement;
• Increasing the difficulty level as the game progresses to
higher levels.
165
Recreation ______

Game Scoring
Play continues until all six jewel collectors are captured. Each
time you clear the playing board, you will advance to the next
level of play. Scoring is based on the level of play: For each
jewel coll ected you'll get a number of pOints equal to ten times
the level. For example, level 1 scores 10 points for each jewel
collected, level 8 scores 80, and so on.
The Chase
1 00 CALL CLEAR
1 10 PRINT "T H E C H A 5 E"
120 PRINT
1 30 PRINT NJoystick 1 7 l/ENTER"
140 PRINT NJoystick 27 2/ENTERN
150 PRINT " Key board ? 3/ENTER"
160 PRINT
1 70 INPUT JT S W
180 PRINT
190 PRINT N============_="
200 IF JTS W=1 THEN 230
210 IF JT S W=2 THEN 230
220 IF JTS W<>3 THEN 11110 ELSE 25111
230 PRINT NALPHA LOCK Off"
2 40 GOTO 260
250 PRINT "ALPHA LOCK On"
260 PRI NT " =---------=-=="
270 PRINT
280 PRINT "Please Press ENTER"
290 PRINT " To BEGIN
300 CALL KEY(0.X,Y)
3 10 Z=Z+l
320 IF Y=0 THEN 300
330 IF 1 < 100 THEN 360
3 4 0 Z=Z-90
350 GOTO 330
360 RANDOMIZE Z
370 CALL CLEAR
380 H~ = " FF"
3 90 V~=N10101010t0J01010"
400 P~ = " 00B018t8"
410 PO~="00"
4212' Gl~="lB3C5AFFFF919191"
430 G2~=" 18 3 C5AFFFF242424"
44 0 SI~="003C5A5A5A7E3C"
450 S2$="003C7E42427E3C"
460 El$="0000001818"
4 70 E2$="000024181824"
480 E3$="0200249818240048"

166
.............. Recreation

49@ E 4~ =· '4A8142810 02 4814A·'


50 0 E5$=~000 40 0B0000400BIM
510 CALL SCREEN(2)
520 CALL COLOR(14 . 16 . 1)
530 CALL COLOR ( 1 3 .14.1)
540 CALL COLOR(12.5. 1 )
550 CALL C HAR(1 36 .H$)
560 CALL CHAR(128.H$)
570 CALL CHAR(120,H$)
580 CALL CHAR(137,V$)
590 CALL C HAR(129.V$)
600 CALL CHAR(121.V$)
610 CALL C HAR (138.P$)
620 CALL C HA R(130 .P$)
630 CALL CHAR(122,P$)
640 CALL COLORe!l.!! .! )
650 CALL C HAR(11 2,SI$)
660S M=112
670 CALL CHAR(113,PO$)
680 PO=11 3
690 CALL COLOR(t0,S, 1)
700 CALL CHAR([email protected]$)
710 G=104
720 CALL CHAR(105 . El$)
730 CALL CHAR( 10 6 ,E 2$)
740 CALL CHAR(107.E3 $ )
750 CALL CHAR<10B,E4$)
760 CALL CHAR(109,ES$)
770 E8 = 105
780 CALL HCHAR(1,3,1 36 ,28)
790 CALL HCHAR(2 .4.1 2B,26)
800 CALL HCHAR(3.5 . 12~ . 24)
810 CALL HCHAR(22,5, 120,24)
820 CALL HCHAR(23,4, 128,26)
830 CALL HCHAR(24,3,1 36,28)
840 CALL VCHAR(2,2,137,22)
8S0 CALL VCHAR(2,31,137,22)
860 CALL VCHAR(3,3,129,20)
870 CALL VCHAR(3,30,129.20)
880 CALL VCHAR(4,4,121,18)
890 CALL VCHAR(4,29.121,18)
900 FOR X=ll TO 21 S TEP 2
910 CALL HCHAR(16,X,SH)
920 NEXT X
930 51=11
940 52=21
950 FOR X=3 TO 8
960 CALL COLOR(X, 14,1 )
970 NEXT X
980 CALL HCHAR(19,9.83)

167
Recreation ______•

990 CALL HCHAR(19 . 10,67)


1000 CALL HCHAR(1 9, 11,7 9)
1010 CALL HCHAR(1 9,12,82)
1020 CALL HCHAR(19 , 13, 69)
10 3 0 CALL HCHAR(19.14,58)
1040 MX::2
1050 LX = LX+l
1060 IF HX =5 THEN 1080
1070 HX: MX+l
1080 PILLS=76
1090 S:S+( 10'L X)
1100 HI =0
1110 M2 =0
11 20 01:::138
11 30 0 2= 1 38
1140 FOR X=8 TO 14
11 50 FOR V=11 TO 2 1
1160 Z=(INT(3'RND)+ll'S+114
11 70 CALL HCHAR(X,V ,Z)
1180 CALL SOUND ( 1 50 , - 4, 1 )
1190 GOSUB 2700
1 200 NEXT V
1 2 1 0 NEXT X
1 220 CALL HCHAR(11,16,SH)
1 230 L=11
1 2 40 C= 16
1250 CALL HCHAR( S. 11,G)
1260 Ll :: 8
12 70 Cl=11
1 2 80 CA LL HCHAR C14. 2 I ,Gl
1290 L 2= 14
1300 C2 = 2 1
1 3 1 0 CALL SOUND ( 300 . - 5 .0 )
1 320 S HC::S HC +l
1 330 IF S HC = 1 THEN 1380
1340 SHC::0
1 350 CALL CHAR ( 11 2,S l$ )
1 36 0 CALL CHAR ( 104,Gl$)
1 370 GOTO 1400
1 380 CALL CHAR(112 ,S2 $)
1 3 90 CALL CHAR(104,G2$)
1400 CALL SOUND(I,3000,5)
1410 NL = L
14 20 NC=C
14 30 IF JTSW=3 TH E N 1440 ELSE 1500
1440 XX=0
14 50 CALL KEYC0,XX,VV)
1460 IF XX <> ASCC -S")THEN 14 7 0 ELSE 15 3 0
1470 IF XX <> ASC(- D-)TH E N 1480 E LSE 1560
1480 IF XX <> ASCC " E")T HEN 1490 ELSE 1590

168
_ _ _ _ _ _ Recreation

1490 IF XX <> ASC (MX")THEN 1860 ELSE 1620


1'500 CALL JOYST(JT S W,XX,YY)
1510 XX= (UUXX) +YY
1 520 IF XX <>- 41Z1 THEN 15513
153 0 NC =C- I
1540 Ga TO 16 30
1550 IF XX <> 41Z1 THEN 1580
1560 NC=C+l
15713 GOTO 16 30
1580 IF XX< >4 THEN 16113
1 590 NL = L - l
1600 BOTO 16 313
1 6 10 IF XX <> - 4 THEN 1860
1 62 0 NL =L +t
1 630 IF NL ( 8 THEN 18613
16413 IF NL > 14 THEN 18613
16513 IF NC ( 11 THEN 18613
166121 IF NC >21 THEN 18613
167121 CA LL GCHAR(NL,NC,X)
1680 FOR l=122 TO 138 STEP 8
1690 IF X<> Z THEN 1730
1 713 0 5=5+ (HI'LX)
1 7 10 PILLS=PILL5-1
1 7213 GO TO 1 750
17 313 NEXT Z
1740 IF X= PO THEN 1 75 13 ELSE 24413
1 7513 CALL HCHAR(L,C ,PO)
17613 CALL HCHAR(NL,NC, S M)
1770 L=NL
1780 C=NC
1790 IF PILLS <>0 THEN 1850
181313 NLSW=1
18113 FOR X=3500 TO 3300 STEP -213
1820 CALL SOUND(I.X.IZI)
18313 NEXT X
18413 BOTO 2520
18513 Bosue 2700
18613 l=INT(LX*3*RND)+1
1870 IF Z=1 THEN 13213
18813 Xl=(AeS(LI-L)+ABS(CI-C))
-~
1890 X2=(AB5(L2-L)+ABS(C2-C»
191Z11i.'1 HIT:I
1910 IF XI=1 THEN 213113
19213 IF X2=1 THEN 22313
19313 HIT=IZI
19413 IF Ml <> MX THEN 19713
1950 Ml = 1ZI
1960 GOTO 22313
1970 IF M2 <> HX THEN 2000
1980 M2 = 1ZI

169
Recreation ______

1998 GOT a 2010


2000 IF Xl>X2 THEN 2230
20 10 Ml == Ml+1
2828 NLl==Ll
2030 NC l=Cl
2 04 0 IF Ll==L THEN 21 00
2050 IF Ll >L THEN 2880
2060 NL1==Ll+l
2 8 70 GOTO 21 4121
2080 NL1=LI-1
2090 GO TO 21 40
2 100 IF Cl<C TH E N 213121
2 118 NC1 :::::C I - 1
2 1 20 GOTO 2140
2138 NCI ==C l+1
2 140 CALL GCHAR CNLl . NC 1,OlX)
2150 IF 0IX : G THEN 1 320
2160 CALL HCHAR CL1 ,C l,OI)
2170 01=OIX
2180 CA LL HCHAR CNLl,N C1 .G )
2190 Ll==NLl
2200 Cl=NCl
22 10 IF HIT = l THEN 2440
2220 GOTO 1 320
2230 M2= M2 +1
22 40 NL 2= L 2
2250 NC2=C 2
2260 IF C2=C THEN 2320
2270 IF C2(C TH E N 23121121
228121 NC2::C2-1
2290 GOTO 2360
230121 NC2==C2+1
2310 GOTO 2360
2320 IF L2 >L TH EN 2350
2330 NL2=L2+1
2340 GO TO 23 60
2350 NL2:::L2-1
2360 CA LL GCHAR ( NL 2, NC2.02X)
2378 IF 0 2X=G THEN 1320
2380 CALL HCHA R(L2 ,C2.02 )
2390
2 400
2 410
02=02X
CALL HCHARCNL 2, NC2 .G)
L2=NL2
--
2 4 20 C2: NC2
2 4 30 GOTO 22 10
2440 CA LL SOU ND (500,r5 . I )
2 4 50 FOR X=0 TO 4
2 4 60 CALL SO UNO(1 50 , - 4 ,0)
2 4 70 CAL L HCHAR(16,SI,EB+X)
2 480 NEXT X

170
_ _ _ _ _ _ Recreation

2490 CALL SQ UND(150, - 4 ,0)


259121 CALL HCHAR(1 6,Sl,PO)
2510 5 1= 5 1+ 2
252121 T"=STRt.(S)
253121 Z=LEN <T$)
25 40 FOR X=l TO Z
2550 TXt.=SESt.(TS,X , l)
2560 Y=VAL(TX$)
2579 CA LL HC HAR(19,16+ X,Y+ 4 S)
25 80 NEXT X
2599 FOR X=8 TO 14
2699 CALL HCHAR(X,11 ,PO ,11 )
26 19 NE XT X
2629 IF 51=52+2 THEN 2669
263121 IF NL S W<> 1 THEN 11218121
26 4£1 NL S W=0
2650 GOTO 10 5121
2669 FOR X=l TO 399121
2679 NE XT X
26 8121 CALL CLEAR
269121 END
279 9 Z=INT(3tRNO)+1
27 19 ON Z GOTO 2729,27 49, 2769
2729 21=14
2739 GOTO 2770
27 49 21=5
2759 GOTO 2779
2760 21=16
2779 Z= INT( 3 tRND)+1 2
2789 CALL COLO R( Z,Z t , l)
2799 RETURN

171
Thinking Andy VanDuyne
TI Version by Patrick Parrish

'Thinking"-and its advanced version, "Thinki11g Harder"-


is a ga me of pattern recognition and memory that tests your
ability to think logically.
You have nine black boxes labeled from 1 to 9 in front of you.
Your job is to make them all light up with a purple glow.
The trouble is, you can't get to them directl y. Instead, you
have a set of six switches, numbered from 1 to 6. Each switch
controls three of the boxes. When you choose switch 1, for ex-
ample, boxes 1, 4, and 8 might change condition. If they were
all dark, then they'll all glow; if they were all glowing purple,
then they'll go dark. And if 1 and 4 were purple and 8 was
black, then 1 and 4 will go dark and 8 will glow purple.
The trouble is figuring out which switches control certain
boxes. You know that there is a correct combination-three of
the switches, toggled at once, will make all nine boxes glow.
But which three? That's where luck and genius combine. It's
possible to guess right with your first three choices. But if you
aren't concentrating, it's also possible to get such a mishmash
of purple and black boxes that it could take a hundred tries
before the puzzle is solved.
How to Play
After you have typed in "Thinking" and saved it on tape or
disk, run it and the game will begin. A title screen and two
screens of instructions appear first. Press any key to go on.
Nine black boxes lettered from 1 to 9 appear in the center
of the screen. Below the boxes you can see the number of
purple boxes, which is 0 at the beginning of the game. At the
top of the screen is the number of turns you have taken,
which is 1 at the start of the game.
The input line just above the black boxes asks you for a
number from 1 to 6. Hit a number and press ENTER. Three
boxes wiJI immediately turn purple. The turn number will
change to 2 and the count of purple boxes will change to 3.

172
_ _ _ _ _ _ Recreation

Suppose you enter the number 5, and the 1, 2, and 8


boxes glow purple. You don't know about any of the other
numbers, but you know that from then on, in that game,
number 5 will toggle boxes 1, 2, and 8. The pattern for each
switch is randomly assigned at the beginning of each game,
so that each time you play there'll be a new set of patterns.
But the pattern for a particular switch will never change during
a game.
If you choose a number and don't like what it did, choos-
ing the same number again toggles the same three boxes and
restores them to the way they were originally. It will cost you
a tum each time, though, just as if you had entered a new
number.
When all nine boxes turn purple, the computer congratu-
lates you, tells you how many turns you took, and asks if you
want another game. If you choose to play again, a new set of
patterns is randomly created.
Str ategy and Frustration
At the beginning of every game there are always two perfect
solutions. The puzzle can always be solved. Winning in three
or five tries is entirely a matter of luck. Students in my school
average between 9 and 25 turns-slightly better than the
teachers. If you become totally lost, however, it can take doz-
ens or even a hundred tries to solve the puzzles.
But if you think logically, you should soon become quite
good at the game. I won't give away the whole strategy, but
you might keep in mind that any two patterns that overlap
(that change the condition of the same box) cannot possibly be
in the same winning combination. And in the last turn before
you win, you must always have exactly six purple boxes and
three black ones.
Is It Too Easy?
If you become a master at Thinking, you might want to try
" Thinking Harder." In this version of the game, you have nine
possible patterns instead of six. This makes it possible to get
much more confused, and getting it right by luck alone is
much less likely.
To play Thinking Harder, remove the word REM in lines
210-240. If Thinking Harder is too difficult, you can always
reverse the changes and go back to Thinking again.

173
Recreation ______

Thinking
lee GOTO 15e
lie FOR U ~ 1 TO LEN(O.)
12e CALL HCHAR(ROW.COL+U.ASC( S Ea.(o •. u . J»)
13e NEXT U
14£1 RETURN
15£1 CALL CLEAR
169 CALL SCREE N (6)
1 7£1 PRINT TA8(7);"T H J N KIN a":
18£1 G=6
1ge 81 R2
2e£l 82"'17
21e REM G- 9
22£1 RE M 81 -3
23e REM 92 =2 6
24e REM PRINT TA8(9);"H A ROE R"
25£1 PRINT :
26e FOR I ~ l TO 25£1
27£1 NEXT J
28£1 G.. ... STR.<G)
29£1 aosue 164 £1
3 e£l CALL CLEAR
31£1 CALL SCREE N ( 1 4)
32 9 aosue 203£1
33 0 00 = 1
3 4£1 CALL CLEAR
3 5£1 FOR N=1 TO G
3 6£1 CH(N)==e
37 £1 NEXT N
38£1 FOR N= I TO 9
3 9£1 C(NI - £1
4£1£1 CALL COlOR(N+5.2.2)
41£1 NEXT N
420 CO-0
4 3 £1 Gosue 221£1
44£1 FOR N- l TO G
459 RANDOMIZE
46£1 Z~INTIRNO 'G )+1
4 7£1 IF CH (Z) <> £1 THEN 46£1
48£1 CHIZI - N
490 NE XT N
see FOR 8=1 TO 91
51£1 FOR N= 1 TO 9
52£1 RANDOMIZE
530 Z=INT(RNOt9)+t
5 4£1 IF Y(Z) <> 0 THEN 53£1
55£1 YIZ)zN
56£1 NEXT N
57£1 FOR N ~ l TO 9

174
- -_____ Recreation

5S0 X= V(N)
59121 XS;SEG'S(STRS(X),l.l)
61'1'19 PS(B)=PS(B)~XS

6 18 N EXT N
628 FOR N=l TO 9
630 YIN)=0
6 49 NEXT N
659 GOsue 2210
6613 NEXT B
679 HS =P$(l)&PS(Z)
68121 IF 6 <> 9 THEN 79121
698 HS=P$(1)LPs<2)t.P$( 3 )
79121 FOR N=l TO 82 STEP 3
718 P$(INT(N/3)+I)=SEG$(Hs .N. 3>
729 NEXT N
73121 CALL SCREE N(1 5)
74121 FOR 1 =9 TO 23
750 CALL VCHAR(4. I .64.15)
769 NEXT I
779 Ct - 72
781'1J R-b
799 FOR 5=1 TO 3
889 J::l1
81121 FOR Q=Cl TO Cl+16 STEP 8
820 FOR I=R TO R+2
839 CALL HCHAR(I.J.Q,3)
849 NEXT I
85121 J - J+4
860 NEX T Q
870 R=-R+4
a8e Cl::Cl+24
890 NEXT 5
91210 KH:o:49
91121 FOR T = 12 TO 2121 STEP -4
929 CALL HCHAR(7.T,KH)
938 CALL HCHAR(IJ.T, KH+3)
949 CALL HCHAR(15 . T,KH+b)
950 KH..-K H+l
960 NEXT T
97121 0-0
980 RDW=2
998 COL;10
112180 O'li=". ( 1 - "t.G'$&;") ?"
112110 Gosue li e
10 20 ROW"'20
11213121 COL=ll!1
1040 D$ zM". '~ • :"
1050 GOSUB 110
1060 ROW=22

175
Recreation ______

1070 DS_H •• • ·ZH&C HR.(34)&·+ :H


10B0 G05UB 110
1090 FOR N=1 TO 9
1100 IF CCN) <) 14 THEN 11 30
1110 CALL COLORC5+N.14.14}
1120 GOTO 1140
1130 CALL COLORC5+N.2.2)
1140 NEXT N
1150 FOR 1 =1 TO 9
1160 IF CCI) <) 14 THEN 1180
1170 CO - CO+l
1180 NEXT I
1190 CALL HCHAR C22 ,21,CO+48)
1200 IF CO - 9 THEN 1450
1210 CO ,., 0
1220 Q=Q+l
1 230 D'S - STR.CQ)
1240 RO W- 20
1250 COL - 19
1260 GOSUe 110
1 270 CALL HCHARC 2 .21 . 3 0)
1 280 CALL KEY(0,K,ST)
1290 IF ST ~ l THEN 1 3 10
1300 CALL HCHARC2,21 . 32)
1310 IF CK ( 49)+(K ) 48+GITHEN 1270
1 320 CALL SOUND(50,440.4)
1330 CALL HCHARC2,21.K)
1 3 40 SE=CHCK - 4B)
1350 FOR Nz l TO 3
1360 W""VAL (SEG. CP. (SE). N . 1»
1 3 70 IF CCW) <) 0 THEN 1400
1380 CCW):14
1 390 GOTO 1420
1400 IF CCW> <) 14 THEN 1420
1410 CC W) - 0
1420 NEXT N
14 3 0 GOTO 1090
1440 REM YOU WIN !
1450 Ll-=2
1460 L2=15
1470 5 1 =1
1480 FOR U= 1 TO 3
1490 FOR I=Ll TO L2 STEP 5 1
1500 CALL SQUNDC - I , 110+t'10, 3)
1510 CALL SCREENC!)
152111 NEXT I
15 3 0 51 z 51' - 1
1540 NEXT U
155111 ROW=24
1560 COL=12

176
_ _ _ _ _ _ Recreation

1570 D.=·!/!.~ ? "


1580 sosue 110
1590 CALL KEY(0,K,ST)
161110 IF 5T=0 THEN 1590
1610 IF (K< >7B)t(K <> 89)THEN 1590
1620 IF K=B 9 THEN 330 ELSE 224~
1630 REM INSTRUCTIONS
1640 CALL CLEAR
1650 CALL SCREEN(II)
1660 PRINT "YOU WILL seE <;I BLACK BLOCKS."
1670 PRINT
1680 PRINT "BY ENTERIN G A NUMBER BETWEEN"
1690 PRINT
1 700 PRINT "1 AND ";6.;", YOU CAN CHANGE"
1710 PRINT
172111 PRINT " SO ME OF THEM TO PURPL E ."
17 30 PRINT
1740 PRINT
1750 PRINT "BUT. SOME PURPLE ONES MIGHT"
1760 PRINT
1770 PR I NT "TURN BACK TO BLACK '"
1780 PRINT
1790 PRINT
1800 PRINT "EACH NUMBER YOU ENTER WILL"
I B UI PR I NT
1820 PRINT "CHANGE THE COLORS IN ITS OWN"
1830 PRINT
1840 PRINT "WAY."
1850 PRINT
1860 GOSUe 197i'l
1870 CALL CLEAR
1880 PRINT
1890 PRINT "TRV TO CHANGE ALL THE BLOCKS"
19/iHt PRINT
1910 PRINT "TO PURPLE IN AS FEW TRIES AS"
1920 PRINT
1930 PRINT "YOU CAN."
1940 FOR 1=1 TO 10
1950 PRINT
1960 NEXT I
19711.'1 PRI NT
1990 PRINT TABI31;"PRESS A KEV TO CONTINUE":
1990 CALL KEV(0,K,ST)
2000 IF ST=0 THEN 1990
211.'1111.'1 RETURN
211.'1211.'1 REM DEFINE COLORS AND CHAR S
2 039 FOR 1=7 2 TO 1 36 STEP 8
211.'149 CALL CHARI I,"·)
2 "5" NEXT I
2"611.'1 FOR 1=1 TO 12

177
Recreation ______

2070 READ LL,L$


2080 CALL CHAR(LL,LS)
2090 NEXT I
2100 CALL COLOR(5.5. 1)
2110 FOR 1=6 TO 14
2120 CALL COLORCI.2.2)
2130 NEXT I
2140 RETURN
2150 DATA 33,003844447C444444, 3 4.007C4040784
0407C
2160 DATA 47.00 3 C4040SC444438, 3 6.00 3 81010101
01038
2170 DATA 37 , 004040404040407C, 3 8 . 00446464544
C4C44
2180 DATA 39,0078444478404040,42,00784444785
04844
2190 DATA 43,0038444038044438,44,007C1010101
01010
2200 DATA 46,0044444444444438,b4,FFFFFFFFFFF
FFFFF
2210 DD=DD+2
2220 CALL SCREEN(DD)
2230 RETURN
2240 END

178
Bowling Champ
Joseph Ganci
TI Translation by Patrick Parrish

Now you can go bowling without the expense of renting spe-


cial shoes or suffering the embarrassment of rolling a gutter
ball iN front of dozens of people. "Bowling Champ" is a game
for one to four players.
Some garnes, such as Pac-Man or Adventure, create their own
unique fantasy worlds, while others are simulations of reality.
"Bowling Champ" is an example of the latter.
It's not easy to take a game with countless physical vari-
ables (such as bowling) and reduce it to numbers so it can be
re-created by a computer-especially a microcomputer. Com-
promises must be made. Usually the game must be modified
in major ways to make it possible to program. The result is a
hybrid game, an approximation of reality, that resembles the
original but has new aspects of its own.
Bowling Champ is a reasonable simulation of a game of
ten pins, given the limitations imposed by a BASIC program
which must remain short enough to publish. The elements of
skill and luck have been preserved, and the scoring is
authentic.
Up t o Four P layers
When you first run Bowling Champ, the program asks for the
number of players. Up to four people can play.
Next you enter the players' names. All names of more
than eight characters long will be truncated to eight characters.
Now you're ready to bowl the first frame. The bowling
ball rapidly moves up and down across the alley until you
press the space bar. This rolls the ball down the alley and
knocks over the pins-unless you've thrown a gutter ball. The
trick is to time your release so the ball rolls down the center of
the alley to score a strike.
In case you're unfamiliar with how a game of ten pins is
scored, here's a brief summary:
A game consists of ten frames or turns. Each player gets
one or two balls per frame. If you roll a strike-knocking

179
Recreation ______

down all ten pins with the first ball-you don't get a second
ball, but the current ball 's score is ten plus the total of your
next two throws.
If some pins are left standing after your first ball, you get
a second ball. If you knock down all the remaining pins, it
counts as a spare, and the current ball's score is ten plus your
next throw.
If any pins remain after your second ball (no strike or
spare), the number of pins knocked down in that frame is
added to your previous score.
Rolling a spare in the tenth (last) frame gains you one ex-
tra ball; rolling a strike in the tenth frame gains two extra
balls.
Therefore, a perfect game-ten strikes during regular play
plus two strikes with the extra bowling balls-scores 300
points. Needless to say, this doesn't happen very often, either
in real bowling or in Bowling Champ.
Is It Too Hard?
You can make the game easier with just two simple changes.
Remove STEP 2 from line 1660 and delete line 1740 entirely.

Bowline Champ
I11J0 GOTO 150
110 FOR 1 =1 TO LEN(HS)
1 20 CALL HCHARCR,C+I,A SC ( SEGS( HS,I.l»)
1 30 NEXT I
140 RETURN
150 GOSUB 2 440
160 DI M NAMES( 3),SSC3),T TC 3)
1 70 G=15
lal1J H=23
1911J CALL CLEAR
200 CALL SCREEN(6)
210 PRINT TAB(S);"B 0 W LIN G": :
220 PRINT TAB(9);"C HAM P ~H: : : : : :
: : : : :
230 PR INT TAB (3) ; "HOW MANY PLAYERS (1-4) ?. H. ,
240 CALL KEY(0.A.S)
250 I F 5=0 THEN 240
260 IF (A ( 49)+(A ) 52)THEN 2 411J
270 A=A-48
280 CALL CLEAR
2911J CAL L SCREEN(13)

180
_______ Recreation

3 00 Xf;="NA ME S"
3 10 IF A<> l THEN 33 0
32 0 X$"'''NAHE''
330 PRINT "TVPE IN YOUR ";X'S;":":
3 40 FOR 1 = 0 TO A- I
356 PRINT
3 • • PRINT TAB(4);"PLAVER .";I+l;~ " .•
37 . INPUT NAME. eI)
38. NAHE$(I):SEG$ (NA HESCI) ,l ,8)
3 •• NEXT I
•••
'1.
REM DRAW GAME SC REEN
CALL CLEAR
42. CALL SCREE N ( 12)
43. H$ - "t 2 '3 " 5 6 7 8 9 10"
4'.
45.
R- l
C=l
4 •• GOSUB 110
47.
48.
4 •• GQSUS 110
5 •• FOR J = 1 TO A
SI. HS - " y y y y y y y y y ••
52. R=2tJ+l
5 3 . GOSUe 110
5 •• H$"''' xxxXXXXXXXXXXXXXXXXXXXXXXXXXXX ''
55. R- 2tJ+2
5 •• GOSUS 110
57. NEXT J
58. R-13+(A ) 2)'2

.1..2.•••
5 •• FOR J=1 TO A

639
CzI- ( (J:::2)'" (J - 4) ) t15
R'"'R - (J=3)'2
H$=NAHES(J-l)~":"
GOSUS 1 tel
640 NEXT J
650 REM INITIALIZE SCORE STATE
660 FOR J=0 TO A- I
670 SSIJ)=1
680 TTl,])"""
690 NEXT J
-- 700 REM PUT DOWN ALLEV
710
72 0
CALL COLOR(13,l,l)
FOR J = G TO H
730 CALL HCHARIJ,2,E,30)
7 40 NEXT J
759 CALL HCHAR(J4, 2,120,30)
7b0 CALL HCHAR(24, 2,120,30)
77 0 REM MAIN LOOP
780 FOR Q=1 TO 10
790 FOR RR=0 TO A- I

181
Recreation ______

BBB CC :a: (RR+l)t 3


B10 IF RR <> 3 THEN B3 B
B2B CC: 14
B3B CALL COLOR(13.2,CC)
840 CALL COLOR(11 . 1S. CC)
asa 91=a
Bb0 GOSUB 1 32 B
B7B IF JI - 1B THEN 90B
-
SBB 81 - 1
B9B GOSUB 14S0
900 IF Q<> IB THEN 92B
910 ON S GOTO 92 0, 1040 ,10 40,9 2~ .11 b0
920 NEXT RR
930 NEXT Q
94B R- 19
9S0 C"'7
9b0 H• • "PLAV AGAIN (V / N) 7 -
970 GOSUB 110
9BB CALL KEV(0,K , S T )
990 IF S T = 0 THEN 9B0
1000 IF (K <> S9)t(K <> 7B)T HEN 98~
1010 IF K-8 9 THEN 17B
1020 ST OP
10 30 RE M 10 TH FR AM E-EX T RA 8ALL S
1040 R=< 19
IBSB C=2
IBbB H. ="T AKE 2 MORE BALLS. -L NAM E.(RR)
1070 GOSUB 110
1080 FOR J = 1 TO 300
1090 NE XT I
1100 CALL HCHAR ( 19 ,2,E,29)
1110 SS(RR)=S - l
11 2 0 Bl - 1
11 3 0 GOSUB 1 32 0
1140 I F J = 10 TH EN 123 0
11 50 GOTO 1 27121
I1b0 C=3
11 70 R:a 19
1180 H. ... "TAKE 1 MORE BALL, "LNAME.(RR )
1190 GOSUB 110
1 200 F OR 1 "' 1 TO 300
121£'1 NEXT I
1 220 CALL HCHA R( 19. 3.E,2B)
1 23 0 SS(RR)- 1
1 2 4121 81 =2
1250 GOSU8 1320
1 260 GOTO 920
1270 SSC RR )- 1
1 2 80 81=2
1 290 GOSUB 14S121

182
_ _ _ _ _ _ Recreation

1 3 "" GO TO 9 2 0
1 3 10 REM FIR S T BALL
1 32 0 FOR 1 = 1 6 TO 22 S TEP 2
1330 CALL VCHAR CI, 30.1 1 2)
1340 NEXT I
1350 FO R 1 =17 TO 21 STEP 2
1360 CALL VCHA R CI, 29.1 1 2 )
1 37 0 NEXT I
1 380 CALL HCHARI18, 2B, 11 Z)
1 39 0 CALL HC HAR(20,28,11 2)
1400 C ALL HC HAR(19,2 7 , 11 2)
1410 PS=-l
14 20 Jl=0
14 30 GOT a 14610
1440 REM S E COND BALL
14 50 PS=0
1460 SOSUB 1580
14 70 T=TT(RR)
1480 S=SSCRR)
1490 T =T+J
1590 ON SS(RR)GOS UB 2200,2250,2309,23 40, 239 0
1510' TT(RR )= T
1 520' 5S(RR)=5
15 30 R=13+(A ) 2>'2-(RR ) ll'2
1540 C= 10 -« RR = 1)+(RR =3» '15
1550 HS =S TRS (T T(RR»
1560 SOSUB 110
157 0' RETURN
1 5 80 IF (Q=1),(PS=-1),(RR=0)THEN 1650'
159" C=30
160'0' FOR HH =C TO 3 S TE P - 1
1610' CALL HCHAR(15 .H H+l ,E )
1620' CALL HCHAR(1 5, HH,B)
1 630 NEX T HH
1640 CALL HCHARC15~HH+l,E)
1650 C:::3
1 660 FOR R=6 TO H 5TEP 2
16 70 CALL HCHAR(R,C ,B )
1680 CALL KEVC0,K,5T)
1 6 90 CALL HCHARCR,C,E)
1 700 I F 5 T=0 T HEN 1 730
1 710 ROW=R
17 20 R=H
1 730 NEX T R
1 7 40 6=1 5-C 8=15 )
17 50 IF 5T=0 THEN 1660
1760 R=R OW
17 70 J=0
1 780 FOR C=3 TO 25
1790 CA LL HCHARCR,C ,E)

183
Recreation ______•

1800 CALL HCHAR(R ,C+1, B)


1810 CALL SOUND( - 1.130,2}
1820 NEXT C
1830 CALL BCHARCR.C+l,X)
1840 IF CX <> 112)*(C <> 31)T HEN 2020
1850 IF C= 3 1 THEN 21216121
1860 IF X<> 112 THEN 2020
1870 CALL SOUNO(10, -7 ,5)
1880 J - J+l
1890 c-e+!
1900 FOR 0- - 1 TO 1 STEP 2
1910 YI-R
1920 Xl " C
19 3£'1 XI - Xl+l
194£'1 Yl=Yl+D
195£'1 CALL GCHAR(Yl~Xl.X)
1960 IF X<> 11 2 THEN 2£'110
19 7£'1 J sJ+ l
198£'1 CALL HCHAR(YI.Xl ,E)
1990 CALL SOUNO(l£'1, - 7,S)
2000 GOTO 19 31iJ
2£'110 NEXT 0
2020 CALL HCHARCR . C- l.E. 2)
2030 CzC+l
2040 CALL HCHAR(R.C.B)
2050 GOT a 18 3 121
2£'16£'1 CALL HCHAR(R,C,E)
2£'17£'1 Jl=Jl+']
208£'1 R=-3+RR*2
2£'19£'1 CK-2+3 *Q+81
2 10£'1 61"',]+48
2110 IF ,]1 <> 10 THEN 2 15£'1
2 1 20 61""47
2 1 30 IF PS - 0 THEN 215121
2 140 Gl &" 88
215121 IF 81 - 0 THEN 2 1 70
2160 61 - GI+5e
2170 H. - CHR.CGl)
2180 GOSUB 11£'1
219121 RETURN
220£'1 IF Jl <> 10 THEN 22 4£'1
2210 S =5
222£'1 IF ps .. e THEN 2240
223121 S=2
224121 RETURN
225121 T:T+J
226121 Sz:4
2270 IF J <> le THEN 2290
2280 5-3
229121 RETURN

1B4
_ _ _ _ _ _ Recreation

2390 T=T+J*2
2310 IF J:10 THEN 2330
2320 5=4
2330 RETURN
2340 T-T+J
-~ 2350 S=1
2369 IF Jl <> 10 THEN 2380
2370 5=5
2380 RETURN
2399 T=T+J
2400 5= 1
2410 IF J <> lt3 THEN 2430
2 420 5=2
2430 RETURN
2440 FOR 1=97 TO 107
2 4'50 READ CS
2460 CALL CHAR(I . CS)
2470 NEXT I
2480 FOR 1=112 TO 1 28 STEP 8
2490 READ CS
2'599 CALL CHAR(I.C'S)
2510 NEXT I
2'529 CALL CHAR(121."0010 101 01010100t3")
2530 CALL CHAR(138."FFBBBBD7EFD7BBBB")
2540 E=129
2550 CA LL CHAR(129,·'·)
2569 B=128
2570 RETURN
2580 DATA FFFFFBF7EFDFBFFF.FFC7BBBBBBBBBBC7,
FFEFCFEFEFEFEFC7.FFC7BBFBF7EFDF83
25913 DATA FFC7BBFBE7FBBBC7.FFF7E7D7B783F7F7.
FF83BF87FBFBBBC7
2600 DATA FFE70FBF87BBBBC7.FF8 3 FBF7EFDFDFDF.
FFC7BBBBC7BBBBC7
2610 DATA FFC7BBBBC3FBF7CF
2620 DATA lClC081C 3 E3E 3 ElC.000000FF00000000.
003C7E7E7E7E7E3C

185
Worm of Remer
- - - - - Stephen D. Fultz
TI Translation by Patrick Parrish

Nerm the worm is lost in Bemer Castle and needs your help
to get home. You must guide him through 11 rooms Qlld help
him find magic mushrooms to eat a/ollg the way. The journey
is Q nQvigator's nightmare, because you never know where
the next mushroom will grow, and if Nerm hits a wall or
gets trapped by his tail, he loses one of his lives.
"Worm of Berner" is a fast-paced arcade game in which Nerm
the Worm travels through rooms eating magic mushrooms.
Nerm is lost in Berner Castle and wants to return home. Guide
Nerm to a mushroom using the keyboard arrow keys (E, 5, D,
and X) so he can keep up his strength for the journey. After
eati ng five mushrooms in a room, Nerm can exit to the next
room. You must guide Nerm through 11 rooms before he
finds his home. You start out with four lives. If you touch
anything besides a mushroom you will lose a life.
At the top of the screen you will see th e current score,
what room Nerm is in, how many mushrooms Nerm must eat
to open the exits, and how many lives Nerm has left, includ-
ing the current life. You get 100 pOints, plus bonus points, for
every mushroom you eat. Nerm gets a bonus li fe after
completing the first two rooms and another for every third
room thereafter.
Adding More Features
You can learn a lot about programming and games by modify-
ing the action and settings in Worm of Berner. Some featu res
you might add include a routine to save the high score to disk,
adding more players, or having Nerm go to a different room _J

depending on which exit he takes. Simpler enhancements


would be changing the number of mushrooms that Nerm must
eat or changing his speed.
Worm of Bemer
3 DIM NN(29) ,RANK$(12)
5 GOSUB llli!1 !2hil

186
_ _ _ _ _ _ Recreation

19 GOTO 500121
2121 FOR 1:1 TO LEN(H~)
30 CALL HCHARCROW.COL+J . ASC(SEG'5 CHt, I. 11»
35 NEXT I
40 RETURN
100 CALL KEV(0.K,ST)
195 IF (K <> 68)+(OD - 2 ) THEN 11 0
106 OX = 1
197 DY=0
108 01 = 1
119 IF ( K<> 8 3 )+(OO : 1)THEN 115
111 DX"' - l
112 OV::I2I
113 01 = 2
115 IF (K <> 69)+(OD =3 'THEN 120
1160Y "- 1
11 7 OX"'0
118 01 = 4
129 IF ( K<> BB)+ ( OD = 4)THEN 140
12 5 OY = 1
1 3 '" DX = 0
13 5 01= 3
140 CALL HCHARCYA.XA. 1 3 6)
145 QO ::. DI
150 XA:XA+OX
152 YA:VA+DV
154 L - LEN<XA'5)
156 XA'5=XA$~CHR$(XA)
158 YAS = YA$~CHRS(YA)
160 CALL GCHAR(VA,XA ,Z >
162 IF 2 <>3 2 THEN 2 00
164 CALL HCHARCVA.XA,128>
lob CALL SOUNO(1,62 2 , 2 )
168 IF L < WO THEN 100
170 CALL HCHAR(ASCCYAS),ASC<XAS), 32 l
172 LL =LENeXAS) - 1
174 XAS = SEGS(XAS,2,LL>
176 VAS=SEGS(YAS . 2.LL)
189 GOTO 10121
2121121 CALL SOUNOC I 12I0, 3 11 , 2)
21211 CALL HCHAR(YA.XA. 1 2 8)
203 SOsue 660121
205 IF Z<) MU SH THEN 2 bl2l
2 10 WO = WO+15+2lLO
212 IF WO < 185 THEN 2 15
214 WQ=18'5
215 RANDOMIZE
216 XX - RNO*28+3
2 18 X=R ND119+4
22121 CALL GCHAR(X,XX.Hl)

187
Recreation ______

222 IF Hl <> 32 THEN 2 1b


224 SC=SC+180+LOt7
228 HI - HI - l
239 GOSUB bb88
232 IF HI >0 THEN 245
234 CALL HCHARI3, 1 7, 11214)
23b CALL HCHARI13,2,104)
238 CALL HCHARI1 3,31, 11214)
24121 CALL HCHAR( 23,17,1121 4)
2 41 FOR I ~ 3 TO 3121 STEP 3
242 CALL SOUNDI10121, 191210, I)
243 NEXT I
244 GOTO 10121
245 CALL HCHARIX ,XX, HUSH)
250 GOTO 10121
2b0 IF Z=104 THEN 27121
2bl IF LI=l THEN 75121 121
2b4 GOSUB 7500
2bb GOTO 29121
27121 CALL HCHARIVA,XA,13b)
272 GOSUB 7000
275 FOR DE=110 TO 880 STEP 32
277 PRINT
279 CALL SOU NDIl,DE ,2)
280 CALL SOUNDI- l,DE, 2)
281 NEXT DE
282 LO - LO+l
283 IF LO-12 THEN 1200
284 WO z S
285 Ll=Ll+1
28b IF LO >EX THEN 9100
287 CALL COLOR I 14, L 1, 1 )
288 CALL CLEAR
289 GOSUB 1300
290 GOSUB bb90
300 ON LO GOTO 5989,490,500.550,b09,79I21,89I21,
4 50,55121, 112199 ,111219, 1 21219
399 GOTO 5089
499 REM SECOND SCREEN
419 CALL HCHARC1 3,S, 120,24)
429 GOTO 5089
449 REM SCREEN
459 CALL VCHAR(7,15,120,lb)
455
4b9
499
CALL HCHARI9,b.120,22)
GOTO 5989
REM FOURTH SCREEN
-
,
500 CALL HCHARlb,5,120,24)
595 CALL HCHAR(29.5, 1 29,24)
510 GOTO 5080
549 REM FIFTH SCREEN
188
_ _ _ _ _ _ Recreation

sse CALL HCHAR( 7 ,b,120,22)


555 CALL VCHAR(B,15,120, 16)
S60 GOTO 5880
599 REM FRAME 6
6£10 CALL HCHAR(12, 3 ,1 20 , 1 3 )
610 CALL HCHARC12,19,12t21,12)
620 GOTO 5080
699 REM FRAME 7
70£1 FOR I - e TO 18
710 CALL HCHARCI.7 , 120, 7 )
7 15 CALL HCHARCI,J8 . 1 2 0 , 8)
7 29 NEXT I
725 GOT a 512180
799 REM FRAME 8
890 CALL HCHAR(B,3,120, 1 3 )
805 CALL HCHAR(14,12, 1 2 0,19)
au, CALL HCHAR<1S, 3 ,120, 1 3 )
815 GOTO 5£180
999 REM FRAME 9
1£10£1 Bo s ue 1400
1915 FOR T- 5 TO 2 1
1020 CALL HCHARCT , 4, 32 ,16)
1025 NEXT T
1930 GOTo 5e80
lUI" Bo s ue 1400
1110 FOR T = 5 TO 21
1115 CALL HCHARCT,4, 32 , 2 0)
1120 NEXT T
1125 GOTO 41219
1199 REM YOU WIN!!
1200 CALL CLEAR
1205 CALL SCREEN(3)
1 2 06 FOR I m4 TO 8
1207 CALL COLOReI, 2, 1)
1208 NEXT 1
1210 PRINT TA8(9);"NERM 'S HOME!"
12211.'1 PRINT
12 3 11.'1 PRINT
1 2 411.'1 PRINT TAB(ll1.'1);"THANK YOU!"
12SI1.'I FOR T = l TO 9
12611.'1 PRINT
1270 NEXT T
127S FOR T ~ 1 TO 3
1280 FOR J:110 TO 8811.'1 STEP 311.'1
1283 CALL SOUND(1.I.2)
1284 CALL SOUND(-I,J. 2 )
1285 NEXT I
1286 FOR 1 - 880 TO 110 STEP -30
1287 CALL SQUND(I.I,2)
1288 CALL SQUND(-I.I,2)

189
Recreation ______

1289 NEXT I
1299 NEXT T
1291 CALL SCREEN(2)
1293 GOTO 7700
1 3 09 CA LL CLEAR
1 305 PRINT uSCORE =u;TAB( 201; UROOM :u
1319 PRINT "MU S HROOMS :";TAB( 20);UL IV ES :U
1320 FOR T =1 TO 21
1330 PR INT
1 3 40 NEXT T
1350 RETURN
1400 FOR T=5 TO 21
1410 CA LL HCHAR(T,4 ,120, 2 6)
14 20 NEXT T
14 30 RETURN
4999 RE M UP THE GA ME
50g0 GOS UB 10000
5005 MUSH = 112
5010 L I =4
5 015 SC::0
5020 LO::!
5035 HI=5
5040 WO =5
5045 EX=2
5050 Ll=3
5055 GOSUB 5500
5060 CALL CLEAR
5065 CALL SC REEN( 2)
5066 F OR 1 =3 TO 8
50 67 CALL COLOR(I.16,1)
5068 NEXT 1
5070 GOS UE 1 309
512175 GOSUB 6690
59 8121 XA$=" U
50 81 YA$="U
512185 XA=17
5986 YA=18
509 1 OX=0
5093 DY=-l
5193 I F HI < 6 THEN 5 1 1217
511215 HI = 5
5107 IF HI )- l THEN 51 1 0
5109 HI ;11I
5 11 121 01 - 4
5 115 FOR 1 =2 TO 3 1 STEP 29
5 1 2111 CAL L VCHAR(3.I,120,21)
5125 NEXT I
5130 FOR 1 =3 TO 2 3 STEP 20
5135 CALL HCHA R< 1 ,3.120,28)
5 14 0 NEXT I

190
_ _ _ _ _ _ Recreation

51 4 5 CALL HCHAR( 2 4. 3, 1 37 ,2B)


5150 IF HI ) 0 THEN 51 7 4
5155 C ALL HCHAR( 3 , 1 7 .184 )
5160 CALL HCHAR(1 2,2, 104)
5165 CALL HCHAR(1 2,3 1 , H'4)
5167 CALL HCHAR( 23, 17,104)
5171 GOTO 150
5174 RANDOMIZE
5175 XX:RND*28+ 3
5178 X= RND*19+4
5180 CALL GCHAR(X,XX,Hl)
5185 IF Hl <>32 THEN 5174
5190 CALL HCHAR(X,XX,HU 5 H)
5 2 00 GOTO 150
5500 CALL CLEAR
5505 PRINT TAB(10);"GET READY~·
5510 FOR T = 1 TO 12
5515 PRINT
5520 NEXT T
5525 FOR 1 - 1 TO 14
5530 CALL SQUND(100, NN (I),2)
5535 N:::XT J
55 40 RETURN
6599 REM PRINT SCORE
6600 H$ = STR$( S C)
6603 ROW z l
6604 COL=UI
66 05 GQSUe 2 0
6607 H$ =ST R$(LO)
6608 C'JL-2B
6609 eOSUB 2 0
6610 H$ =STR$( HI)
6611 ROW =2
b62e COL==14
6625 GOSU8 20
6630 H$ ~S TR$(LI)
66 3 :5 COL:29
6640 eosue 2 121
6659 RETURN
6999 REM NERM LEAVES
70/210 SP"SP - 5
712105 GOSUe 660121
71211121 HI z S
7015 L=LEN<XAS)
7 1212121 FOR 1=1 TO L
712125 CALL SQUND(2,1 1e+I*2,2)
7930 CALL HCHAR(A SC(VA S),AS C<XAS),32)
7121 3 5 LL = LEN(XAs) - 1
71214121 XAS=SEGS<XAS,2,LL)
7121 45 VAS= S EGS<VAS,2 , LL)

191
Recreation ______

7858 NEXT I
7868 RETURN
7499 REM OOP!!
7'580 CALL CLEAR
7585 PRINT TAB(13);~00PS~
751£'1 FOR 1~1 TO 12
7515 PRINT
7528 NEXT I
7525 LI=LI-l
7547 FOR 1=14 TO 24
7549 CAL L SOUNO(10,I'48,2)
7551 NEXT I
7553 FOR 1 = 1 TO 39
7555 NEXT 1
7569 IF LI ( l THEN 7799
7575 eOSUB 1 399
76121121 RETURN
7699 REM THE GAME ENDS
778121 CALL CLEAR
7794 FOR 1 =3 TO 8
7795 CALL COLOR(I,16.1)
7796 NEXT I
7719 IF HS ) SC THEN 7750
7720 HS-SC
7721 FOR 1 =1 TO 5
7722 PRINT
7723 NEXT I
7725 PRINT TAB(8);NNEW HIGH SCORE"
7728 FOR T-118 TO 1768 STEP 59
7729 CALL SOUNO(2,T,2)
7730 NEXT T
7748 FOR 1=1 TO 5
77 4 3 PRINT
7745 NEXT I
7750 PRINT TAB(7);"YOUR SCORE: ";SC
7755 PRINT
7768 PRINT TAB(7);~HIGH SCORE : ";HS
7770 FOR 1 - 1 TO 3
7775 PRINT
7780 NEXT I
7785 PRINT TAB(5);"YOUR NEW RANK IS :"
7798 PRINT
7795 PRINT TAB(9) ;RANK$(LO)
7796 FOR ]=15 TO 29
7797 CA LL SOUNO(109,NNCI).2)
7798 NEXT I
7898 PRINT
7805 PRINT
7896 PRINT
7818 PRINT ~(C TO CONT INUE Q TO QUIT)N

192
______• Recreation

7815 FOR T:l TO 4


7816 PRINT
7817 NEXT T
7820 CALL KEY(0.K, S T )
7830 IF 5 T = 0 THEN 7 8 2 0
7840 IF ( K<> 6 7 It<K <> 81 ) THEN 78 2 0
7 845 IF K= 6 7 THEN 5000
7850 S TOP
9099 REM EXTRA LIFE
91011' CALL CLEAR
9110 PRINT TAB(11);"BONUS LIFE"
9120 FOR 1 = 1 TO 1 2
912'5 PRINT
91 3 0 NEXT I
91 32 FOR 1 = 1 TO 3 0 STEP 2
9134 CALL SQUNO(100,11 75 .1)
91 3 6 NEXT I
9140 EX =E X+ 3
9145 LI = LI+l
9150 GOT a 287
10000 CALL CLEAR
10001 FOR T=3 TO 8
10003 CALL COLOR(T.2.1)
10006 NEXT T
10010 CALL COLOR<14 ,3 , 1)
10015 CALL SCREEN(lS)
10020 PRINT TAB(101;MWELCOME TO"
10021 FOR T=1 TO 4
10022 PRINT
100 23 NEXT T
10025 PRINT TAB<B ) ;-NERM OF SEMER"
10028 FOR T= 1 TO 9
11210 3 0 PRINT
UI032 NEXT T
10034 PRINT ·USE E , 5,D, & X KEY S TO MOVe"
10.036 PRINT
10040 CALL HCHAR(21,3,1 3 6 . 4)
10042 CALL HCHAR(21,8.128)
10045 FOR 1=1 TO 2 2
10047 CALL HCHAR(21.6+I , 1 3 6)
1~050 CALL HCHAR<21,7+I,128)
10052 CALL SOUND(10,6 22 , 2 )
10055 CALL HCHARI21 , 2+I. 3 2)
10057 FOR T= l TO 2 0
10058 NEXT T
10060 NEXT I
10065 FOR T = 1 TO 100
10070 NEXT T
10075 RETURN
10999 REM REDEFINE CHAR S

193
Recreation ______

11000 FOR 1=104 TO 1 36 S TEP 8


11015 READ AS
11020 CALL CHARCI,AS,)
11 025 NEXT J
110 3 0 DATA FFFFFFFFFFFFFFFF,187EFFFFI8181818
,FFBIBDA5A5BDBIFF
110 32 DATA BI4 22 4 3C7 E5A 3C I8. 3 B7 CFEFEFEFE7C 3B
11033 CALL COLOR(10,2 ,2 )
11035 CALL COLOR C11 . 14, 1 )
11040 CALL COLORCI2,2.10 )
11045 CALL COLOR(1 3.7. I)
11050 CALL CHAR<137,"FFFFFFFFFFFFFFFF")
11060 FOR 1 = 1 TO 9
11065 READ RANKS,(I)
11070 NEXT I
11075 FOR 1 = 10 TO 12
11080 RANKS,(I) = "HALL OF FAME"
11085 NE XT I
11090 DATA ZERO . ROO KIE,NOVICE,AVERAGE
11092 DATA MA S TER , GRAND MA STER, WI ZARD, GRAND
WIZARD
11094 DATA SUPER S TAR
11100 FOR 1 = 1 TO 2 9
11110 READ NN(!)
11120 NEXT 1
111 3 0 DATA 262,349, 40 000,349,392 ,40 000,392,4
40,5 23 ,440,5 23, 440 ,3 4 9, 40000
111 35 DATA 3 49,40000,40000, 2 62,247, 262 ,294,2
94,262,40000 , 4000 0,40000,330 , 33 0, 3 49
11140 RETURN

194
I
'-'

, I

( I
l..J

, I
~

I
'-..-'

I
'-'
5
TI Graphics Made
Easy
---..;;~ Lyle O. Haga

There is a better way of figuring out pattern-identifier code


than that presented in the TI marmal.

The TI screen is divided up into a giant grid of 24 rows and 32


columns for graphics. This grid, shown in your TI manual in
the CALL CHAR section, makes 768 positions, or squares, for
you to p ut your graphics in. Each square of the grid is divided
into an 8 X 8 grid consisting of 64 dots to be turned on or off.
Each 8 X 8 grid is divided into a "left block" and a "right
block."

Left Right
Btock Block

Each time you define a pattern-identifier, you use all 64


dots whether or not you so stipulate. Thus, the statement
CALL CHAR( l OO:'FF") covers all 64 dots even though you
stipulated only the top row of eight dots to be turned off; the
remaining dots stay turned on. This can be seen by a simple
little exercise. Make a box outline, 4 X 4.
On the surface this sounds like a pretty simple exercise,
and it is. The problem is that many people p robably won't
think it through, and will come up with the fo llowing:
10 CA L L CLE AR
20 CAL L CHAR(100."FF")
30 CALL CHAR(101."8080808080808080")

197
Sound and Graphics _ _ _ _ __

•• CALL HCHAR(12,B,100,4)
50 CALL HCHAR(lb,8,100,4)
6. CALL HCHAR (12.8,101,4)
8.7. 8.
CALL HCHAR(12,12,101,4)
GaTa
No matter what you do, this won't work; there will al-
ways be a gap somewhere. Remember that even though you
didn't stipulate all 64 dots in CHAR 100, you still have them
to deal with.

On top of this you put the following:

You should be able to see where the gap comes in now.


When you put CHAR 101 on top of CHAR 100, the dots you
left turned on cover the dots you turned off, thus the gap.
Here's one solution to the problem:
1. CALL CLEAR
2. CALL CHAR (100, "00000000000000FF")
3. CALL CHAR (101, "FF")
•• CALL CHAR(102,"8080808080808080")
s. CALL CHAR(103,"0101010101010101")
6. CALL VCHAR(12,8.102,4)
7. CALL VCHAR ( 12, 11, 103,4)
8. CALL HCHAR (11,8,100,4)
•• CALL HCHAR(l b,8.101, 4)
1 •• GaTO 1 ••

198
_ _ _ _ _ _ Sound and Graphics

There's an easier way of defining graphics? The new


method is one your kids learned in school, ca lled base 16.
Using base 16, you write the numbers 8,4,2, 1,8.4,2,1 across
the top of each 8 X 8 grid. Let's see how this works in defin-
ing the heart; we will make it two positions h igh and two wide.
If you are planning to do ma ny graphics, you should get
some graph paper-this will make it easier. Let each square
on the graph paper represent one dot; this gives you 16
squares wide and 16 squares high. Make the outline with a
heavy line. Count horizonta ll y from the left 4, 8, and 12 lines;
make these heavier than the other lin es, and make the eighth
line even heavier and have it extend beyond the outline. This
will mark off your left and right blocks and one position from
another. Now, counting vertica ll y, go down eight and darken
this line, going beyond the outline. Across the top, put your
base 16 numbers S, 4, 2, I, S, 4, 2, I , and your paper should
look like this:
8421842 1 842 1 8421

With this, let's make our heart. First, color in all the
squares making your heart. Then, starting at the top row, add
up the nu mbers over the squares you darkened. If the total is
under ten, your pattern code will be that number, and if it is
over nine, you see the letters A-F. You do the one complete
grid and then move to the right; when you are through, move

199
Sound and Graphics _ _ _ _ __

down to the next line. You should come up with the following
results:
8 4 2 1 8 4 2 1 8 4 2 1 842 1

A - 10
B = 11
C ~ 12
D ~ 13
E ~ 14
F ~ 15

Row one has no darkened squares, so the code is zero for


both left and right blocks. You get the same results with row
two. In row three, a square under the number 1 is darkened in
the left block of grid one, so the code is 1. In the right block,
squares under the 8 and 4 are darkened, so the code is C. In
row four, the squares under the 2 and 1 are darkened; the
code is 3. Row four of the right block has darkened squares
under 8, 4, and 2, so the code is E. Just keep this up, and you
will come up with the following:
CALL CHARC100,"0 0 001C 3 E 7 F7F7F7F U )
CALL CHAR(101,"0 00 0 3 87CFEFEFEFE " )
CALL CHAR C10 2 ," 3 FIF0F070 3 010000")
CALL CHAR(10 3 ,"F C F8F0E0C0800000")

Using base 16 is easier.

200
Animating TI
Displays Without
Sprites
- - - - - Jim Schlegel

Fast animation is possible with TI BASIC through efficient


coding QlId the use of a few tricks. "Marbles," a game writ-
ten in TI BASIC, demonstrates some of these techniques.

Sprites can be used to create very smooth moving animation.


The problem with sprites is that they require the Extended
BASIC module. If you don't already have Extended BASIC, it
can be a very difficult item to find. It's possible, though, to
write animated games using just TI BASIC.
BASIC's CALL and the Hardware
When writing animated programs for the TI-99 / 4A home
computer, an understanding of its architecture will lead to
easier coding and faster program execution. In particular, the
relationship between the TI 's display hardware and the BASIC
language CALL instructions used to control this hardware is
important. The 99/4A uses Texas Instruments's TMS9918
video display processor to generate the screen display. The
display processor functions independently of the TMS9900,
the 16-bit microprocessor used in the 99/4A, but is controlled
by the TMS9900. This removes the job of generating the dis-
play from the microprocessor, allowing it to execute the BASIC
program faster.
The TMS9918 allows more flexible displays than the
owner of the TI has access to without purchasing additional
software modules. Sprites are 8 X 8, 16 X 16, or 32 X 32
pixel patterns created and controlled by the Extended BASIC
program. A pixel is the smallest point that can be changed on
the display. The sprites are then moved by the TMS9918 in-
dependent of, but under control of, the BASIC program. Ani-
mated displays can be created without sprites, but it takes a

201
Sound and Graphics _ _ _ __

little more work. Here is where the knowledge of the


TMS9918 architecture comes in handy!
The display created by the TMS9918 is controlled by
three tables which are modified by the BASIC program. These
tables and their interrelationships are shown in Figure 1.
Ficure I. TI.99/4A Display Mapping
These tables control the display generated by the TMS9918
video display processor.

CHARACTER PATTERN COWR


TABLE TABLE TABLE
row col
1 1 number 32 pattern 1 color
1 2 33 2 f b

9 2. 128 128 001 .. 00 13 2 1


.. .....
128 011 .. 10
24 31 16
24 32
158
159

Character Table
The first table, the Character Table, is a list of the 768 charac-
ters (24 rows by 32 columns) to be displayed. The numbers
stored in this table represent the characters to be displayed at
each row and column position. The letter A is represented by
the number 65, B by 66, C by 67, etc. Numbers 32-127 are
defined by the ASCII character set but can be redefined by the
BASIC program. ASCII characters 128- 159 are also available
for defining special characters. This table is accessed by four
CALL instructions:
CALL CLEAR
CALL HCHAR(row, column, character[,repetitions])
CALL VCHAR(row, column, character[,repetitions])
CALL GCHAR(row, column, character)
CALL CLEAR sets all numbers in the table to 32 (a space
character). CALL HCHAR and CALL VCHAR are used to put
numbers into the Character Table while CALL GCHAR is used
202
_ _ _ _ _ _ Sound and Graphics

to get numbers from the table. Note that the repetitions argu-
ment for the CALL HCHAR and CALL VCHAR instructions is
optional. If this argument is omitted, one character is written
to the position defined by the row and column arguments. If
this argument is used, a row or column of characters is written
to the display. The argument " repetitions" defines the length
of the row or column. For example, CALL HCHAR(l ,l ,65,lO)
will print ten letter A's horizontally starting at row one, column
one.
Pattern Table
The second table, the Pattern Table, is a list of 128 8-byte
character patterns. The first entry in the list represents the pat-
tern for character number 32, the second entry is for character
number 33, and so on. The last pattern, entry 128, represents
the pattern for character number 159. Each character is an 8 X 8
pixel, 2-color pattern where each 1-pixel represents the fore -
ground color and each O-pixel represents the background
color. This table is modified by one CALL instruction:
CALL CHAR(character, pattern)
CALL CHAR defines which pixels are to be displayed as
the foreground color and which are to be displayed as the
background color. An example of a CALL CHAR instruction is
shown in Figure 2.
Figure 2. CALL CHAR Instruction
CALL CHAR(128,"1898FF3D3C3CE404")
Binary Hexadecimal
,,--r-ipattern~=t~ 0001 1000 18
1001 1000 98
11111111 FF
0011 1101 3D
00111100 3C
00111100 3C
11100100 E4
0000 0100 04

Color Table
The color table is a list of 16 foreground and background color
combinations to be used when displaying the characters. The
charact, ~rs defined in the Pattern Table are arranged in sets of

203
Sound and Graphics ______

eight for determining which colors to use. The first eight


characters use the first foreground/background color combina-
tion, the second eight characters use the second combination,
etc. This table is modified by the CALL COWR instruction:
CALL COLOR(set, foreground-color, background-color)
Fifteen colors plus transparency are available. Any
combination of these colors can be selected by the CALL
COLOR instruction.
Table I. Colors Available on the TI-99/ 4A
Number Color Number Color
1 Transparent 9 Medium red
2 Black 10 Light red
3 Medium green 11 Dark yellow
4 Light green 12 Light yellow
5 Dark blue 13 Dark green
6 Light blue 14 Magenta
7 Dark red 15 Gray
8 Cyan 16 White

Creating Animation
Most computer games use animated players to liven up the ac-
tion during play. To do this, the program running the game
must change the pattern of the player to make them move.
Muncllman and TI Invaders are good examples of games using
animated players. Two or more patterns representing different
positions of the player are built using the CALL CHAR
instruction. The patterns are then alternately displayed creat-
ing animation. Also, using and changing colors can add to the
effect of animation.
By using the BASIC instructions for creating displays, sev-
eral different methods can be used to create the same display.
Some methods, however, are preferable because they are easier
to write and run faster. The faster a program can run , the bet-
ter the animated display will be.
Many games display the same type of player several times
and move each of these players simultaneously. TI Invaders is
a good example. Several rows of about ten aliens move

204
_ _ _ _ _ Sound and Graphics

about, each moving its legs and/or arms. Each row is made of
only one type of alien; all of the aliens in a row move their
arms and legs the same way. This type of animation can be
created two different ways on the 99j4A.
Both methods will use a common subroutine to animate
the players:
800 REM· N = Number of Players
810 REM· RP = Array of Row Positions of Players
820 REM· CP "'" Array of Col Positions of Players
830 REM· C = Character Number of Player Pattern
840 FOR I ~ 1 TO N
850 CALL HCHAR(RP(I),CP(I),C)
860 NEXT I
870 RETURN
The first method uses this subroutine when the player
changes their row and column positions and when the players
move their arms and/or legs:
100 REM· Define Player Patterns
110 CALL CHAR(I28,"1898FF3D3C3CE404")
120 CALL CHAR(129:'1819FFBC3C3C2720")

330 REM· Erase Players


340 C = 32
350 GOSUB 800
360 REM· Calculate New Rows/Cois

400 REM· Display New Positions


410 C = 128
420 GOSUB 800

520 REM· Move Arms/Legs


530 C ~ 129
540 GOSUB 800

610 C - 128
620 GOSUB 800

680 IF whatever THEN 520


690 GOTO 330

205
Sound and Graphics _ _ _ _ __

The second method uses subroutine 800 only to change


the row and column positions of the players. To move the
arms and legs, the character pattern defining the player is
changed. Lines 120, 530, and 610 are deleted, lines 540 and
620 are changed to:
540 CALL CHAR(!28,"1898FF3D3C3CE404")
620 CALL CHAR(128,"1819FFBC3C3C2720")
In the first method, characters 128 and 129 are used,
while in the second method only character 128 is used. Re-
ferring back to Figure I, the differences in these methods can
be seen. Method one changes the Character Table while
method two changes the Pattern Table when moving the arms
and legs. Method one changes each player's location in the
Character Table to point to a new pattern entry in the Pattern
Table. Method two just changes the pattern. If ten players
were displayed, method one would execute 66 instructions to
move the arms and legs while method two would execute only
2 instructions. Method one uses so many more instructions be-
cause the loop in subroutine 800 must be executed once for
each player.
Using Color
In addition to moving players to create animation, changing
colors adds to the visual effect. Again, different approaches
will produce the same display but the programming and
execution time will vary. The CALL COWR instruction lets
the program change the foreground/background color
combination for any character. It's important to remember that
each CALL COLOR changes colors for eight character pat-
terns. Care must be used to insure that players and objects are
grouped properly for coloring.
Making players and objects appear and disappear can be
accomplished three different ways.
First, move the character number of the player or object to
the Character Table to make it appear. Overwriting the player
or object with a space character would make it disappear. If
several players/objects needed to be changed, this would
mean executing many instructions.
Second, the CALL CHAR instruction could be used to
change the Pattern Table to create this effect. Setting all the
pixels in the pattern to 0 wou ld make the object disappear.

206
_ _ _ _ _ _ Sound and Graphics

Defining the object pattern would make the object rea ppear.
This requires execution of only one instruction.
Third, the CALL COLOR instruction could be used to
change the Color Table. By defining both the foreground and
background colors the same, the object is no longer visible. If
the object is on a game board, the color of the board should
be used. Setting both the foreground and background colors to
transparent (1), the color defined by the CALL SCREEN
instruction would be used. One advantage of using the CALL
COWR instruction is that up to eight distinct objects could be
made to appear and disappear with one instruction, while the
CALL CHAR instruction would have to be executed once for
each distinct object. A single object composed of up to eight
character patterns could be changed with a single CALL
COLOR instruction.
Example Animated Program
The following BASIC program uses the techniques described
in this article to produce an animated game. The object of the
game is to maneuver the marble into the hole at the opposite
comer of the display. Between the marble and the hole are
two to five kids trying to catch the marble. The kids can only
be seen at the start of the game or when one is close to the
marble. The arrow keys on the keyboard are used to maneu-
ver the marble.

Marble

••• DEFI NE
I •• REM
11. REM PLAYERS
12_ REM
13. BGC=8
14_ SQUARE:::128
1'_ SQR$="0000000000000000"
1._ CALL CHAR(SQUARE,SQR$)
17_ CALL COLOR (13,1, BGC)
18_ KID=13b
19. KDl$="1898FF3D3C3CE404"
209.1KD2$="1819FFBC3C3C2720"
21. CALL CHAR(K ID.KDl$ )
22. CALL COLOR( 14, 2,BGC)
23. MAR8LE=144

,,-
24_ MR8$="003C7E7E7E7E3C00"
CALL CHAR( MAR8LE ,MR8$)
2 •• CALL COLOR(lS.1b ,8G C)

207
Sound and Graphics _ _ _ _ __

270 HOLE=lS2
280 HOL.="FFC381818181C 3 FF"
2 90CALL CHAR(HOLE,HOLS)
3 00CALL COLOR(16 . 2.1 )
310 REM •
3 20REM • DISPLAY BOARD
33 0REM *
3 40CALL CLEAR
3 50CALL SCREEN(10 )
3 60C=7
3 70L =2 0
380 FOR R= 3 TO 22
3 90CALL HCHAR(R, C , S QUARE,L )
400 NEXT R
410 REM.
420 REM. POSITION KIDS {3 S P AC E S}
430 REH •
440 DIM KR(1 0 ).KC { 10)
450 RANDOMIZE
460 KN = INT(4'RND ) + 2
470 FOR N= l TO KN
480 KR(N)=INT (2 0'RND1+ 3
490 KC(Nl = INT(20'RND ) +7
500 CALL HCHAR( KR(N ) .K C (N). V- ID )
510 NEXT N
520 REM •
530 REM * POSITION HO LE {3 S PA CE S }
51'. 0
REM •
550 HR = 4
560 HC= 8
57 0CALL HCHA R( HR .H C .H OLE}
58 0REM •
590 REM. PO S I T ION MA R BLE
600 REM •
6 19MR =2 1
62 0MC=2 5
630 CALL HCHAR ( MR.M C .MA RBLE)
6 40REM ~ {3 S PA CE S}
650 REM. WAIT F OR VEY{5 SP ACE S ]
660 REM t {3 S PA CE S }
670 CALL KEY ( I. KE Y . S TATU S)
680 IF STATUS = 0 THEN 67 0
690 CALL COLOR(14.B GC . BGC )
700 REM •
7 10REM. BEGIN GAM E
720 REM •
730 CALL CHAR {KI D.KDI. )
740 CALL KEY( I . KE Y. S TA TUS)
750 IF STATU S= 0 THEN 97 0
760 J = l

208
______ Sound and Graphics

779 IF S TATU S 9 THEN 7 9 0


780 J=2
790 IF KEY >S THEN 9 70
B!2I0 REM $:
818 REM * MOVE MARB LE
829 REM
8311'1
*
CALL HCHAR CMR.MC. S QUARE)
8 4 9 ON KEY+t GOTO 85 0 .9 7~ .B 7 0 . Bq0.9 70 .91 0
85£1 MR = MR+J
B60 GOT a 9 2 !21
87.0 MC= MC - J
BSS GOTO 92 121
890 MC = MC+J
999 GOTO 92121
910 MR = MR- J
9211'1 IF (MR=HR ) *CM C= HC) THEN 1210
9 3 11'1 CALL HCHAR(MR.MC.MARB L E )
9411'1 REM *
959 REM * MOVE KIO ~
969 REM *
979 CALL CHARC K I D.VD 2 S )
989 FOR 1=1 TO KN
999 CALL HCHAR(KR Cl ) . ¥C CI) .SQUARE )
1911'10 I F KRCIl=MR THEN 1 12150
1010 IF t<"RCt I< MR THEN 1 0 4 121
1121211'1 KRCI)=KR(I) - I
19 39 GOTO 11215121
111'149 KR( I )=KRII)+ 1
112159 IF KCCI)=MC THEN 11911'1
1969 IF KCCI) < MC THEN 111'1911'1
1979 KCII)=KCCI)-l
1980 GOTO IIiI"
1999 KCI I) =KCI J)+l
1111'19 CALL HCHAR IKRCI),KCC I) ,K JD )
1110 *
IF (KR( I) :HR) (Ke CI) ::MCl THEN 1329
1129 R=ABS(KRCI)-MR)
11311'1 C=ABSCKC(ll - MC)
1140 IF CR+C >4)THEN 1160
11S0 CALL COLORCI4 . 2, BG C)
1160 NEXT I
11711'1 GOTO 730
11811'1 REM *
l1q9 REM *
PLAYER WIN S
1200 REM.
1 2 10 CALL CO LORCI 6 . 2 ,16)
1 220 FOR 1=0 TO 1
1 2311'1 FOR J= - l TO - 4 STEP - 1
1 2 40 CAL L SCRE ENcltS -J t 2)
1250 CALL SOUND (599. J. I)
1269 NEXT J

209
Sound and Graphics ______

1270 NEXT I
1 280 GOT a 100
1290 REM *
1 3 00 REM *
PLAYER LOSE S
1 3 1121 REM *
1320 CALL CO LOR ( 15~ 7, 8GC)
1 33 0 CALL HCHAR CMR,M C ,MARBLE)
1 3 4121 FOR J = -5 TO -7 S TEP - I
1 3 5121 CAL L SOUNDC100.J,l)
1 360 NEXT .J
1370 GOTO 10 0

210
SuperFont
---..;;~- Patrick Parrish

A powerful feature of the Tl-99/4A is its ability to redefille


th e character set. Witll "$uperFollt," a comprehensive
character definition program, you COM hamess this capability.
Requires Extended BASIC and Memory Expal1sioll.
The character graphics capabilities of the TI-99/4A are well
known . To redefine a character on the 11 by the usual means
(see the TI User's Referellce Guide, pages 11-76 to 11-79), a
tedious, multistep procedure must be followed. First, you plot
the prospective character in an 8 X 8 grid. Next, you convert
each row of the grid into a two-digit hexadecimal number and
then sequentially combine the numbers from each row to gen-
erate a patterll-idellti/ier, or coded representation of the charac-
ter. To complete this task, you place this pattern-identifier
along with a chosen ASCII value for the character in a CALL
CHAR statement. Anyone who has repeatedly endured this
process can attest to its drudgery.
Fortunately, this process is easily computerized, and sev-
eral character definition programs have been written for the
TI. Most character definition programs, though, have not taken
full advantage of the T1's capabilities. By using "SuperFont"
(Program 1) the task of character manipulations can now be
undertaken with ease.
Nineteen Commands
The original SuperFont was written for the Atari by Charles
Brannon. The Atari version first appeared in the January 1982
issue of COMPUTE! magazine and featured 18 commands for
redefining characters. After using this outstanding program on
-- several occasions, I was convinced that the TI user deserved
the pleasure and convenience it provided. So, I set about
converting the program for the TI.
In converting Super Font, a few commands with less value
to the TI user were eliminated while certain more practical
commands were added, The final product offers the following
'- 19 commands or modes:

211
Sound and Graphics _ _ _ _ __

o DOODLE
E EDIT
N INPUT
R RESTORE CH
H RESTORE CHSET
F COPY
X SWITCH
M MIRROR
V REVERSE
A ROTATE
C CLEAR
I INSERT
D DELETE
W WRITE DATA
Y QUIT
L WAD FONT
S SAVE FONT
P PRINT CH
T PRINT CHSET
When the program is run, these commands are displayed
in menu form on the screen. Above the menu is an 8 X 8 grid
which serves as a work space for redefining each character. To
the right of the grid, the current mode and .. in some cases, a
prompt will be displayed. Below this is printed the entire TI
character set (codes 32-143) with each color subset (eight
characters) depicted by a different background color. (The
colors can be toggled off and on with the Z key.)
Several commands require that you pick a character from
the character set. In these instances, a box shaped sprite,
4

CHR$(143), will appear over the last character referenced from


the set (defaults to space). To choose a character move the
joystick over the desired character and press the fire button.
Unless indicated otherwise, each command wiU return
you to the EDIT mode upon completion. Let's now examine
each command beginning with EDIT (the ALPHA-WCK key
should be up).
EDIT is the basic editing command. When selected from
the menu, you will be requested to choose a character from
the character set. The character selected is copied into the grid
and the box shaped sprite will be homed in the grid. Move
4

this sprite about the grid with the joystick. Pressing the fire
button will set or clear the point depending on its present
state. You can draw lines by holding down the button while

212
_ _ _ _ _ _ Sound and Graphics

moving the joystick. When you're pleased with the appearance


of the character in the grid, press ENTER to redefine the cho-
sen character. You 'll then be prompted for another command.
To completely redesign a character from scratch, use the
CLEAR command.
INPUT lets you type in a pattern-identifier and assign it to
a particular character code. When INPUT is selected, choose a
replaceable character from the set with the joystick and then
type in the hexadecimal code for the proposed character. The
hexadecimal code can be typed in upper- or lowercase. A rou-
tine at line 1260 automatically converts the code to uppercase.
The INPUT command is handy when attempting to associate a
pattern-identifier with a CHR$ in someone's BASIC code.
RESTORE CH restores the current character to its original
configuration. This command is useful if you wish to start over
defining a character or if you changed the wrong one.
RESTORE CHSET restores the entire character set to its ini-
tial appearance.
COPY copies a character to a second location in the
character set. You will be prompted for the first (character to
be moved) and second (destination) character. This command
is handy for arranging your customized characters to fit the
various color codes.
SWITCH swaps the location of two characters in the set.
As with COPY, you will be prompted for two characters.
MIRROR produces a mirror image of the current character
in the grid.
REVERSE puts the current character in the grid in reverse
field: all dots become blanks, and all blanks become dots.
ROTATE turns the current character 90 degrees clockwise.
CLEAR completely clears out the current character.
INSERT places a row of blanks in the current character.
Move the sprite in the grid with the joystick to the row where
you wish to insert the blanks and press ENTER. All rows be-
low that will scroll down and the bottom row will be lost.
DELETE is the opposite of INSERT. Position the sprite on
a row in the grid and press ENTER. The row will be elimi-
nated and all other rows will scroll upward. DELETE and IN-
SERT can be used in conjunction with ROTATE to scroll
characters left or right in the grid (of course, one row will be
lost in both cases).
WRITE DATA displays the pattern-identifier for each

213
Sound and Graphics _ _ _ _ __

selected character along with its ASCII value. When finished,


a prompt for another command will be issued. This is handy
when comparing characters or for providing a few character
codes for another program.
QUIT simply terminates the program.
WAD FONT loads a previously SAVEd character set (a
font) from tape or disk. You will be prompted for the device
and filename. Be sure that this is typed in the standard format
(CSI or OSK1.FILENAME). Again, capital letters need not be
used. The routine that converts from lower- to uppercase
lettering takes care of this for you. If you 're using a cassette,
the screen will be restored after the tape system messages
have been printed (the same occurs with SAVE FONT dis-
cussed below). When loading is complete, a command prompt
is given.
SAVE FONT saves to tape or disk in a data file format
only those characters in the set which have been altered since
the program was run. Since each character code is saved as a
separate record, you may need 30 minutes of tape to save a
large set if you use cassette. As with LOAD FONT, you will
be prompted for the device and filename. If you accidentally
hit L (for WAD FONT) or 5 from the main menu, simply
press ENTER to abort the errant command when prompted for
the device and filename.
Once saved, character sets can be loaded into any pro-
gram where they're needed (we'll consider this in greater de-
tail shortly). As with WAD FONT, you'll see a prompt for
another command when the SAVE is complete.
PRINT CH prints the current character in an 8 X 8 grid
along with its ASCII and pattern-identifier codes, then returns
you to the main menu. Be sure that you modify line 1660 to
correspond to the specifications of your pri1lter.
PRINT CHSET is the same as the previous command ex-
cept that it prints every character which has been modified.
Just Fo r the Fun of It
The first command in the menu, which we overlooked until
now, is the DOODLE mode. By choOSing this mode, you can
use your redefined character set to design a playfield or simply
draw for the fun of it. Your completed playfield or drawing
can even be saved and loaded back in from tape or disk for
further modification.

214
_ _ _ _ _ _ Sound and Graphics

After redefining some characters, go into the DOODLE


mode by typing O. The screen will clear except for the charac-
ter set at the bottom. The following one-line menu will be dis-
played at the top of the screen:
C F B M - MENU L S ~ SAVE

First select the character you wish to locate somewhere on


the screen by positioning the box-like sprite with the joystick
over this character and pressing the fire button. The chosen
character will become a sprite and automatically scroll up to
the row above the displayed character set. You can move this
character sprite to a desired location with the joystick and
print it there by hitting the fire button. If you hold the fire
button down while moving the character sprite, a line of
characters will be printed.
Now, referring to the above one-line menu, press C to
change the screen color, F to change the foreground color of
the current character subset, and B to change its background
color (as before, all character colors can be toggled off or on
with the Z key) . When you wish to draw with another charac-
ter, just press ENTER. The box-like sprite will once again be
placed in the character set at the bottom of the screen for an-
other selection. When you've finished drawing, type M to re-
turn to the main menu, or if you wish to save the screen
(actually, the program saves only rows 2-20), type S. (L lets
you load a screen and will wipe out any existing screen.)
Typing L or S while in the DOODLE mode results in a
prompt for the device and filename. As with font WAD and
SAVE FONT, carefully type in the device and filename. If you
use tape for storage, the screen will be restored (stored in the
array Z1) after the tape system messages scroll the screen. If
you hit L or 5 by mistake, just press ENTER to return to the
above one-line menu.
When a screen is saved from the DOODLE mode, the
screen color, and all foreground and background colors are
saved as well.
The commands offered by SuperFont are versatile, but
you may want to add others. Since the program is modular in
structure Gust follow the branching IF statements from line
520 to 1220 for the current commands), you can insert addi-
tional command routines following line 1220.

215
Sound and Graphics _ _ _ _ __

Retrievinc a Font or Screen


After you have saved a newly created character set or a set
and a screen, how do you go about recovering these for use in
another program? Program 2 is a sample program showing
how to do this.
Since line 120 dimensions for the screen array (21), the
foreground colors (FR), and background colors (B), it must be
included in your retrieval program. In line 130, the device and
filename for the character set file and the screen file are de-
fined as B$ and C$, respectively (the filenames used here are
font and screen). If you used tape to store these files, line 130
should read B$,c$ ="CS1". When loading these from tape, be
sure to load them in the proper order.
Lines 140-160 load in the new character set while lines
180-210 load the screen and color codes. In line 220, the
screen previously SAVEd from SuperFont is recreated. The de-
lay in line 230 allows you to see it.
If you only wish to retrieve a font, modify lines 120 and
130 to:
120 CALL CLEAR
130 8$ ~·'DSK1.FONT"
and eliminate lines 170-220. Of course, you may wish to re-
cover the font along with its foreground and background
colors. If so, change line 120 and 190 to:
120 DIM FR(14),B(14) :: CALL CLEAR
190 FOR I ~ 2 TO 20:: INPUT #H$:: NEXT I
and delete line 220.
A Super Utility
With Super Font, you can perform many chores with ease. You
can customize your character set (ever wished for a true
lowercase?), create graphics characters and an imated figures
(space creatures!), create composite pictures from characters,
design playfields, or just play around. The uses of this utility
are endless. I'm sure you'll find discovering them as much
fun as I have.

Program I . SuperFont
100 !MEMORY EXPANSION REQUIRED
1113 OIM A$(11t).C$(lS>,N$(112),D(lS),V(S,S),
FR(14),B(14),Zl(20,32):: L=32

216
______• Sound and Graphics

120 TT=2 :: E= 15 :: QS="DEVICECOSKl.FILE OR


cSt)?" 1630 :: GOTO 410
.. SOSUS
13. ~ERASE
14. F-e ;; SOSUB 15 0 :: GOTO 490
15. CALL HCHAR(S,14,L,16):: RETURN
16 0 CALL HCHAR(3,17,L,E):: CALL HCHAR(7.17,L
• lid :: RETURN
1 7. FOR 1=5 TO 7 ;: CALL HCHARn.13.L , 1 7 ): :
NEXT I .. RETURN
180 CALL HCHAR{B,14,L,E):: CALL HCHAR( 2 0,2,L
,27) : : RETURN
1913 ~DISPLAY A GRID CHAR
21!10 ZS=N$( W- L)
2113 FOR 1:0 TO 1'5 :: O(I)=ASC(SEG$(Z$.I+l , l)
) - 48 : : 0(1)=0(1)+(0(1»9)*7
220 NEXT I .. J=0 :: FOR 1=13 TO 7 :: DISPLAY
AT(2+I,ll:C$(O(J»::: D I SPLAY AT( 2 +I,S)
:C$(D(J+l»;:: J=J+2 .. NEX T I .. RETURN
230 ~CONVERT GRID PAT TO HEX STRING
240 CALL DEL5PRITE(~1):: DISPLAY ATCS . 15) : "P
LEASE WAIT"
250 FOR R-I TO 8 :: FOR C=1 TO B
260 IF M=1~9 THEN CALL SCHARCR+1, tl - C,H): : G
OTO 290
270 IF M=97 THEN CALL 6C HA RCI0 - C,R+2,H) .. GO
TO 290
280 CALL GCHARCR+l,2+C.H)
29. V(R,C)=H - 141 .. NEXT C NEXT R
3 •• HS ="0 1 234S6789ABCDEF" IF M= 1 18 THEN H
S="FEDCBA9876543210"
310 Z,,="" FOR R=l TO 8 .. LO = VCR . S)*8+VCR
,6)'4+VCR,7"2+VCR.8 ' +t
320 HI=VCR,l"8+U(R,2 ) '4+V CR, 3 ) ' 2 +V ( R,4)+ 1
330 Z"=Z$&SEG"(H",HI,l ' &SEG"CH$.LO, I ) : : NEXT
R
340 IF ( M(> 100)'CM <> 105)THE N 390
350 IF M(> 100 THEN 370
360 Z$:5E6$(ZS, l,ROW*2 - 2Jl!<SEG$CZ$,ROW*2+1, 1 4
)."00" .. GOTO 380
370 Z$=5E6$(Z$, 1.ROW'2 - 2'&"00 " &SEG$ ( Z$ . ROW * 2
- 1,16 - Row*2J
380 CALL CHAR(W,Z$):: N$(W-L) = Z$ . . IF ( M=10
0)+(M=105)THEN BOSUS 200
390 Gosue 150 :: RETURN
400 ~CREATE BLOCK CODES
410 F$="0000000100100011010001@10110011tt000
1001101010111100110111101111"
420 FOR 1=0 TO IS . . Z$=SEG$CF$,I *4+1,4': D
" =""

217
Sound and Graphics ______

4 30 FOR J= l TO 4 :: T =VA L( S EG$( Z$,J , lll+141


:: 05 = 05& CHR5( T l :: NEXT J :: CS(l l= OS ::
NEXT I
440 CALL CHAR(141."" , 14 2.RPT S ("F". 16). 14 3, "F
F818181818181 F F" l :: FOR 1 =1 41 TO 14 3 ::
CALL CHAR PAT(t,A S ( I - L» :: NS {I-L)=A$( I -L
) :: NEXT I
450 CA L L OEL SPR IT E{ MI , :: CALL CLEAR :: FOR I
=2 TO 14 :: F RC I '=2 : : B(I) = I ~2 :: CALL
CQLORCI.2.I+2': ; NEXT I FRC l '=2 .. B C
1, = 1
4 60 FOR I =L TO 143 :: PR I NT CHR$ ( I ) ; : : NEXT
I: : DISPLAY AT(t.l1) : "SUPERFONT" :: GOS
UB 14 20 .. IF W5 = 1 THEN CALL COLOR( 14 ,2 .
16)
4 7(0 FOR R= 1 TO 8 :: CALL HCHAR (R + 1, 3 , 141.8 ) :
: NE XT R
48 0 BR=20 :: BC=2 :: W=L
490 CALL SO UND(10 0,B00,2l: : DI SP LAY AT(3 . 15 )
: " WHI CH MODE? "
50e CALL KEY(!.;1.M.S) :: IF S= 13 THEN S0e
510 I F M<> 1 22 THEN 520 ELSE GOS UO 1 7B~ .. GO
TO 4 90
52(0 IF M<> HII THEN 670
5 312l D5="EDIT MODE " :: T = 1 :: GOSUB 1 580 :: G
OSUB 1 290 :: IF (F=ll *( K<> lt 2) THEN 14 0 E
LSE IF K= 11 2 THEN M=K :: GOsu e 1 50 :: GO
TO 1200
5 40 GOSUB 21210 :: Z= I
550 CALL SPR I TEC Ml,14 3, 10, 9 , 17' :: R=l :: C"'2
:: CA L L GCHAR(R+I,C+ i, CAR)
560 CALL KEY(0.K,Sl: : IF (K=13)+( K=1 1 2 ! T HE N
RO W"'R :: GOSUB 2 4 0 :: GOSUB 15 4 0 :: IF K
<> 11 2 THEN ON Z GOTO 49121, 760
570 IF (K > 1 3) * (K <> 1 221 TH E N M-K :: GOTO 520 E
LSE IF K=122 THEN GOSUB 1 780
580 CAL L J OYS T ( 1.X.Y ) :: I F AB S(X)+A BS (Y )=8 T
HEN 580
590 CALL KEYC t. KK,S) :: IF (KK <> 18 I t (A B SCX)~ A
BS(Y):0)T HEN 560
600 OK-0 :: IF ABSeX)+ABS(Y)=4 THEN OK-!
6 10 C= C - (X = 4 ) +CX =-4): : R=R-(V::~4)+('V"'4)
620 C=C- ( C= 1 ) * 8 + (C- 1 01 IS :: R=R-(R=0l*8+(Rm9
"8
630 CALL LOCATE(~1,8IR+l,8'C+l)
640 I F (KK= 18) I (OK=0)T HEN CALL GCHAR(R+l ~C+l
,CAR) :: CAR=2B3-CAR
650 IF (OK= 1 )*(KK<>18)THEN CALL GCHAR(R+l,C+
1, CAR)

218
_ _ _ _ _ _ Sound and Graphics

660 CALL HC H AR(R+ l~ C +l, CA R ) :: CALL SQUNDe- I,


294,3) : : GOT O 560
6 7 @ IF M<) 110 THEN 7 40
680 1==1 : : O<s =" IN PUT MODE" : : Go s ue 1 580 ::
G Q sue 12912' : : I F F= 1 THEN 141i1
690 IF W5=0 THEN CALL COLOR (3 , 2 . 15,4,2,15,9,
2 , 15 )
700 DISPLAY AT(S, 1 2' :"CHAR HEX CODE?" :: Ace
EPT AT(6,11)SIZE(16'BEEP :DS :: IF lE N (D ~
) <> 1 6 TH EN 700
710 Gosue 1 70 :: GOSUB 12 60

.,
720 Nt;(W - L) =Z $ :: GOSUB 210 :: CALL C HAR(W,Z

730 Gosue 1 5121 : : I F w 5=0 THEN CAL L COL OR (3, F


R (3) , B (3) ,4, FR ( 4 ) • B ( 3) .9. FR (9) • B (9) ) : : G
OTO 760 ELSE 760
7 40 IF M<> 114 THEN 770
750 O$="RESTORE CHAR" :: SOSUB 1580 :: CALL
CHA R(W,A$( W-L» : : NS( W-Ll=A S(W - L )
760 1=1 :: G05Ue 1 50 :: Gosue 200 :: M=10 1
: Gosue 15413 :: DI SPLAY AT(3, 1 5): "EDIT M
ODE " :: CALL SDU ND (S fZI . 88fZ1. 3 ) :: GOTO 550
770 IF M() lfZl4 THEN 810
7 80 DS = "RESTORING SET" :: GOS US 1 580
790 DISPLAY AT(5, I S) : "PLEASE WA IT"
80tl1 FOR I =L TO 143 :: CA LL CHAR ( I , A$ CI - L) ) : :
NS ( I - L )=AS(I-L) :: NEXT . ~ GOTO 760
8 10 IF M<> 1 02 THEN 860
820 DS= " COPY MODE" :: GOSUS 1580
830 DISPLAY AT(5,15) : "FIR ST CHAR ? " :: GOSUS
1 29 121 : : IF F=1 THEN 140 ELSE TM= W
84121 GOSU8 200 :: DISPLAY AT(S , 151:"SECOND CH
AR?" :: BOSUS 1 290 :: I F F=l THEN 14j:!1 EL
SE CA LL DEL SPR I TE(#I)
850 CALL CHARPAT(T M,Z$ ) :: CALL CHARCW , Z$) : :
NS ( W- L)=Z$ :: GO TO 760
860 I F M() 1 20 THEN 920
870 DS="SWITCH MO DE" : : GOSUS 1580
88 j:!1 D I SPLAY AT (5, 1 5' : "F I RST CHAR?" :: GOSUS
1290 :: IF F= l THEN 1 40 ELSE TM= W
890 GOSUS 200 :: DI SP LAY ATCS . 1 5) : "SECO ND CH
AR?" :: GOSU8 1 290 : : IF F= l THEN 14 3 EL
SE TM2=W :: CALL DELSPRITE(Ml )
900 CALL CHARPATCT M,D$I : : CALL C HARPAT(T M2 ,F
$ ) :: CALL CHAR(T M2,D$):: CA LL CHA RCT M, FS
)
9 10 NS (T M- L) =F $ :: N$(TM2 - L )= D$ :: GOTO 760
920 IF M() 109 THEN 94121

219
Sound and Graphics ______•

.,0 O$ = "MI RROR MOD E " . . GO S US 1 580 .. GO S ue


2 ' 0 .. GO TO 76.
940 IF 1"1 < > 1 1 8 T HE: N 96.
95. D$ = "RE: VERSE MODE" . . GOSUe 1S80 . . GOS u e
2 • • . . GO T O 76 •
96. IF 1"1 < } 97 THE N 1 121 1210
970 O$ = "RO TAT E MODE" :: GO s ue 15 80
9 8 121 GOsue 2 4 0 :: GOS u e 2 00 :: Go s ue 15 4 0 : :
T= 12I :: D"i = "AGA I N ( V / N ) ? " : : Gosue 16 0121 :
: Go s ue 1 '5 0 : : IF T= I THEN 9 8 0
9 9 !!! GOTQ 76 121
1 0!!!0 IF 1"1 = 99 THE N O$ = " CLEAR MOD E " : : GOS Ue I
580 : : D,,=RPT$(" 0 ".1 6 ) : : C ALL CHAR ( W,O$
) : : N$ ( W- L ) = 0 $ : : GOTO 76 121
11211 121 IF 1"1 = 105 THEN 0$ = "I N5 ERT MODE " . . GOS Ue
1 '58111 :: Z= 2 :: GO TO 550
11212111 IF M= 1 00 THE N D$ = "DEL ETE MOD E " . . GOSue
J 580 : : Z=2 : : GO TO 5 '5 121
103 0 I F 1"1 <> 119 THEN 1 100
1 0 4 0 IF W5 = 0 THEN CA L L COLO R( 3 . 2 . 1 5 . 4, 2 . 15 , 5
, 2 ,1 5 )
1 050 D$ = " WRIT E MOD E" :: T= 1 .. GOS ue 15 8 0 ::
Go s ue 1290 :: I F F = I TH E N F = 0 : : GOTO
10 9 0 EL S E GOS ue ~ 0 0
1 06 0 DI S PLAV AT( 7 . 1 6 ):" CHAR - " ;W :: D I S PLA V A
T (9 . 1 1 ):N $ (W - L )
1121 7 !!! D$ = "AGA I N(V / N ' ? " :: s o sue 16 121 0
1 080 CALL HC HAR ( 9. II, L . 1 8' :: IF T = 1 THEN GO S
UB 15111 : : GOTO 1 05 0
112190 GO S ue 1 7121 :: IF W'5 : 0 THEN CALL CO LOR (3 .
FR (3) . B ( 3 ) . 4. FR ( 4) , B ( 4, . '5 . FR ( 5 I , e (5' ) : :
GOTO 490 E LS E 4 9 0
11 121121 I F 1"1 = 1 2 1 THEN S TOP
1 1 10 IF 1"1 < >10 8 T HEN 1 15 0
11 2 13 D$ = "LOAD FO NT " :: GO S Ue 1 5 80
11 30 GO S Ue 1 23 0 :: OPEN '* 1: D'f; . 1 NTERNA L . IN P UT
. FIXED
1 1 4121 I NPUT ,* 1 :T , N$ ( T) :: I F T <> 11 2 THEN CALL
CHAR(T +L .N $(T l) :: GO TO 1 14 0 EL S E CLO S E
'* 1 : : sos u e 1 80 : : I F ASC (O$ )= 6 7 THEN 4
5 0 EL S E 4913
11 50 I F M< > 11 5 TH EN 1 2 00
1160 D$ : " SAVE FO NT" :: GO S ue 1 58 0 :: GOS UB 1
23 0
1 1 7 0 OPEN ,*1:0$. I NTERN AL , DUTP U T ,FJXEO :: F OR
l : L TO 1 4 3
11 8 0 I F N~(I - L' <> A~( I - L) TH E N P R I NT ,* l :I - L,N$
( 1- L )

220
_ _ _ _ _ _ Sound and Graphics

11 9@
..
NEX T . . T = 1 1 2 .. F $ : "" - . PRINT ,. 1 : T.
I
CL OSE • I . - GOS UB I S0 . . IF Pi sec o
-.
$) =67 T HE N 45. EL SE 4 90
1 2tHl IF M:= 11 2 TH E N H= l . . e o s us 1 6 6 13 .. GOT O
490
1 2 1 0 I F M= 11 b TH E N H:@ GOS UB 1 6 6 0.. GO TD ..
490
1 2213 I F M<> 11 1 THEN 4913 ELSE CA LL DEL SPR I TEC
~ 1) :: BOS US 1 8513 :: GO TO 49 13
1 2313 DISPLAY AT C20.2) : Q$ :: ACC EP T ATCB, 14 ) :
os :: 1F os= " " THE N GOSU S 1 B ill : : GO TO 4
913 E LSE GOS US 1 2 60
1 2 4 13 RE TURN
1 2513 ' C QN VER T TO CAP S
1 2613 Z ii =" " :: F OR 1= 1 TO L EN( O $ ) : : F $ =SEG $ <O
$,1,1 ) :: IF ( A S C (F $» 96) . (ASC(F $ ) ~ 1 23) T
HEN FS =C HR$ (ASCCF $ )- L )
1 2713 Z $ =Z $ ~F $ :: N EX T I :: 0 1i =Z$ : : RETUR N
1 2 8 13 ' GET CHAR
12913 CA LL SP RI TE UIl. 143 . FR( 1 4) • .BR f a"- l. BC t 8 +\

1 3130 CALL JOYST(1.X . Y); : IF ABS<X)"'ABS<Y)=8


T H EN 1 31313
1 3 1 13 B C=BC- ( X=4) ~(X=- 4 ) :: W=W-CX= 4 ) + (X= - 4 1
13213 BR=BR-(Y=-4 ) +CY=4): : W= W-(Y=- 4 )t28+(Y= 4
) * 28
1 330 IF S C( 2 T HEN BC=29 :: SR=BR · t
1 3 413 IF S C >2 9 TH E N BC=~ :: BR=8R~ 1
1 3513 IF BR( 2e TH E N BR=23 : : W=W+ l t~
1 3613 IF BR >23 THEN SR =20 :: w= w - t!~
1 3713 CAL L KEY(l . KK . S T 1 :: CALI IEYC!? . K.S) ::
F K= 1 22 T HE N GOSU S 1 780 :: GOTO 1 2913
1 3 8 13 I F s (> a T HE N F = 1 .. I F M= I I I T HE N RETUR
N E LS E CA L L DELSPR IT EC .1 1 :: RE TU RN
1 3 90 I F KK= 1 8 T HE N CAL L SO UN D{ 1 13 .11 0 . 2) :: I F
M= 111 T HE N RETUR N ELSE GOSU S 1513 :: CA
LL DELSPR IT E C.I ): : RE T URN
1413 13 GO TO 1 2913
141 13 'M E NU
14 213 D I S P L AY AT( I @.14 1: "0 DOOOLEN
14 3 £1 D I S PLA Y AT (I1.1 1 : "E EDI T " : T AS( 14 ) : " N IN
P UT "
144 13 D I SP LA Y AT ( 1 2 . Jl : NR RES TORE CH ": TAS( 14)
: "H RE S T ORE CHSET"
1 450 DISPLAY AT ( 1 3 .1 ) : "F COPY" : T AB( t4 ) : "X S W
I TC H"
14 6121 D IS PLA Y AT (14,1 1 :" M MI RR OR " : TA B ( 14 ) : " V
REV E RSE "

221
Sound and Graph ics ______

14713 DISPLAY AT(15 . 1):"A ROTATE" : TAB(1 4 ) ; "C


CLEAR"
1 4BI1I D I SPLAY AT(16 . 11 : "! iNSERT":TAB(14) : "0
DELE TE"
149111 OISPLAY AT(17.!) : " ", WRITE DATA" : TAB(14)
: "V QUIT"
1500 DISPLAY AT(1B . l ) : "L LOAD FONT" : TAB(14) :
-
"S SAVE FONT"
1510 DISPLAY AT(19 . 11:"P PRINT CH":TABtt41 : "
T PRINT CHSE T "
15 20 RETURN
1530 ' DRAW A FEW CHARS
1540 FOR 1:0 TO 5 STEP 2 :: CALL HCHA R ( 7 . \7+
I .W):: NE~T I : : RETURN
1550 ' PGS I T I O.I ~URSOR
1560 R=20 :: C-2 :: "' :L :: CALL SPR ITE'! n ) 14
3.2.R ' 8+\ . C t 8+ 1 ) :: RETURN
1570 'D I SPLAY HOOE
158@ GOSU B 160 :: DISPLAY AT(3.1S) : D'6 :: IF
r=1 THE N DISPLAY ATtS . I:'j ) : "CHOO S E A CHA
ROo •• TE0
1590 RETUPt-1
1600 D I SPLAY AT (S . l SI :010 : : ACCEVr AT(5.~7)EI
EEP VAl IDATE("v n")SlZ E ( 1 ) :Z" .. I F Z'6 :"
v" THEN T=1
161121 RETURN
16 20 'SAVE ORIG CHA R PATS
1 63121 CALL CLEAR : : CALL SC REEN Et :: DISPLAY
AT(t0 . 8) : " . . . PATIENCE .. . " . . DISPLAY AT
(12 . 2' : "LOADiNG CHARACTER PATTERNS"
1 6 4 0 DISPLAY AT(23.1) : "iALPHA-:"'OCV kEy HIJS T
BE UP)" :: f!"OR 1=127 TO 1 40 :: CA LL CHA
Rtl.""):: NE~T I
1 650 FOR I sL TO 14@ :: CAl l. CHARPAT('.A$(I-L
) ) :: N'S ( i -L) = A1i ( J - L ) :: NEXT I RETURN
1 660 DI SPLAY AT(3 . lS) : "PRINl MODE" :: OPEN"
I : "RS232/2.BA=9600.DA:8.PA=N"
1 670 TH=W : : I F H= 1 fHEN 1 700
16810 FOR T"'L TO 1 4 3 : : IF N${f - Ll <:' A'S(T -L1T H
EN W=T ELSE 17S~
1690 E=E+ l :: E=(E=17) t I4+E :: CALL SCREEN(E
)

1700 IF «F=I)*(H=I»"(H=01THEN GOSUB 2010::


GOSUB 1540
1 7 10 FO R R=2 TO 9 : : I F R=5 TH EN PRINT ~J: TA
8(S) : " C H R ~ ~ - ~ &~<"~STR ~ ( W )''' > ' ' ;
1720 PRINT *1 :TAB(30' : : : FOR C=3 TO 10 . . CA
LL GC HAR(R . C,X): : IF X= 1 41 THEN X=45 EL
SE X=88

zzz
_ _ _ _ _ _ Sound and Graphics

173[~ PR INT #l: CHR'I; ( XJ ; : : NEXT C:: IF R= 5 TH


EN PRINT #1 : TAB(47) : "HEX CODE - "~" < "~N
$(W- L)~ " >"

1 7 40 NEXT R .. PRINT #1 PRI NT #1 IF H=


1 T H EN 1 760
-4 1 750 NEXT T
1 760 CLOSE #1 . . F=0 : H=0 : : E =15 W=T M
CALL SCREE N CE) RE TURN
1770 'TO GGLE COLORS
t 780F OR I = I TO J 4 IF W5= 0 THEN FQRE=2 ::
BACK= ! E L SE BACK =B ( I) : : FORE : FR ( I )
1790 IF (I <> 14)THE N 1 820 ELSE IF «K= 1 22) t: (M
*
< > I 1 1 ) (W 5=0) ) + ( (M = I 22) *(
W5=0) ) THEN SA C
K:::16
1800 IF M= l l l THEN IF (W5=0 )THEN TT=FR(14) : :
FR(14 )= FQRE E L S E FR(14)=TT _. FORE=TT
1 810 IF M= 111 THEN CALL COLOR( ~I. FOR E )
18 20 CALL CO LOR ( # 2 . FOREJ:: CALL COLOR( I . FORE
. BACK) : : NE XT 1 •• W5 : - ( W5=11J) : : IF ( M "']
22) +( (K= 1 22)*( M <> l l 1 ) JT HE N RETURN
1 830 I = INT ( W/B ) -3 :
ReI ) : : RETUR N
1 8 40 !DOOD L E
185@ FO R J,.. 1 TO 15 CALL VCH AR ( I . J. L " 1 9) : :
CALL VC HAR ( 1. 3 1 - J . L . 19) :: NEYT J . . IF
W5=1 THEN CALL COLOR(14 . 2, I)
1860 D I S PLAY AT(1.I ) :" C F B M= MENU L
S AVE" ;
18 71'1:1 W= L :: BR = 20 . ' BC=2 GOSUB 1 83@ G
OS U8 1290
1 88@ Gns ue 1 93@ : : IF F= 1 THEN 19 ':' 0 El SE BAC
K= - (W5=1) -( W5 =@l fB l I )
189@ CALL SPR I TE( # ~ . W. cORE .BRt8~I.B C f B +I )
19@0 CALL JOY STl I.X.Y , : : BR= 8 R - Y/4 .. BC~BC+
Xl4
191@ BR =BR-(BR=@)+(BR ~ 1 9) : BC:::BC- ( BC= 0) ~ ( BC
=3 ! )
19 2@ CALL LOCATE ( #l. BR * B~ l . BC f 8+ 1,# 2,BR f B+ l,
BC . B-+! )
19 3£1 CALL ~· EY(I.YK. S): : IF (KV <> I B)HBR ) 1 9)T
HEN 1 9 5@
194 0 CA LL HCHAR(BR-+l,BC+ l. Wl : CALL SO UNO ( I @
.11 0 .2):: GOTO 190 0
195@ CALL YEY(@.K.5 J
196@ IF K= 1 @9 THEN CALL DELSPRITE( #I , # 2) : C
ALL CLEAR :: CALL SCREE N ( E} :: F=0 . . GO
TO 4 6@
1 97@ IF K= 1 3 THEN CALL DELSPRITE( # 2) :: GOTO
19 70

223
Sound and Graphics _ _ _ _ __

1980 IF K=122 THEN GOsue 1 780 GOTO 1900


1990 IF K~ 11 5 THEN 2140
212100 IF K=1@8 THEN 22 ~ O
20 1121 IF (~=98).(K=99).CV=I@2)THEN GOSUB ~060
2020 IF F=l THEN F=@ :: 60SlJB 130121 : : GOTO 1
B8a ELSE GOTO 1 9~0
203@ GOTD 1 8813
20 4 0 CALL COLOR CI.FRCI) . B ( I »
2050 RETURN
20b0 I F W5=1 T HEN 2110
2070 IF K<> 98 THEN 209~ ELSE B ( I)=B(I)+1
B (I) =8 ( I ) + (B ( I) ) It, 1 '1 6
2080 GOTO 2040
2090 IF K<> 102 THEN 2 11 0 ELSE FR(})=FRCIl.l
:: FfHII =FR(I) . CFR([) >- 16 1 ' 16
2100 GOSUE! 183£1 : : CALL COLOR ( '* 2 . FORE) :: IF
1=14 THEN CALL COLOR(*I .F ORE) :: GO TO 20
4£1 ELSE 212140
21 1 121 IF V<>99 TH EN 2~50 ELSE E=E i I : : E=£+ (E

2 1 20 CALL SCREEN(El :: 50 1 0 2050


2 1 30 ~SAVE SCREEN ~ COLORS
2 14 0 CALL DELSPRITE{ALL): : Gosue 228£1 :: DIS
PLAY AT( l ~ I ):"PU T TING SCREEN IN ARRAY"
2 1 5£1 FOR 1=2 TO 2121 :: FOR J=l TO L : : CA LL G
CHA R(I . J.Z I (I . J)) :: NEXT ~ : : NEXT
CALL HCHAR( I.1. L.25 )
2 160 OPEN #1:0$. INTERNAL . OUTPUT.F JXED
2 1 70 FOR 1=2 T{1 20 : : P$="" :: FOR J= t TO L
:: P$=P$&CHR$ ( ZI Cl . J»): : NEXT J :: PRIN
T ~1: P $ :: NEXT I
2180 P$:::CHR<scE): : PR I NT ttl:P$ :: P$="" :: Fa
R 1 =1 TO 14 :: Pi=P$&CHR$(FR(I))~CHR$(B
(1») :: NEXT I ! ! PRINT #I:P$
2 1 ge CL OSE #1 .. IF ASC(D$) ~ 67 THEN 1860
2200 CAL L CLEAR :: FOR I=L TO 143 : : PRINT C
HR$ ( I 1 : :: NE X T I
22 1 0 FOR 1= 2 TO 20 : : FOR J=1 TO L .. CALL H
CHAR(I.J.Zl ( t . J I ) : : NEXT J ! ! NE XT I
222@ GOTO 18b0
2230 'LOAD SC REEN
224@ CALL DELSPR I TE (ALL) :: GOSUB 22~0 : : OPE
N til : D". INTERNAL. IN PUT . FIXED
2250 FOR 1::2 TO 20 :: IN PUT .1 : P$ :: FOR J :: l
TO L : : Zl ( I.J)=A SC(S EG$ ( P$ . J , l ) : : NE
XT J :: NEXT I
226 0 INPU T tll:P$ :: E=ASC(P$): : CALL SCREE N(
E):: INPUT tlt:P$ : : FOR 1 = 1 TO 14 : : F R
(I )=A5C (5E6", (P"', 2 * 1 - 1,1») : : B (1) = ASC (5£
GS(PS.2*I,I))

224
_ _ _ _ _ _ Sound and Graphics

2270 CALL COLOR(I.FR(I J ,B (I» :: NEXT r :: CL


aSE 3 1 :: IF A5C(0'5 ):b7 THEN 221Z10 ELSE
22 10
2280 DISPLAY AT (1,1) :Q$ :: FOR 1= 1 TO 400 ::

-- NEXT I ::
0$ = "" THEN 1 860 E L S E GOSUB
2290 RETURN
AC CE PT AT ( t . l ) BEEP: O$
l: b~
• • IF

Program 2. SuperFont LOAD Demo


100 ~GAME
110 ~GET REDEFINED CHARS
1 2 11'1 0 I M Z 1 (20,32) • FR (14) , B (14) : : C ALL C LEAR
1 3 0 B$="OSKl . FONT" :: C$ = "OSK1. SC REEN" :: RE
M B$,e$- "es !": :REM eQU IVALENT FOR CASSEl
TE
140 OPEN #1: B$, INTERNAL, INPUT, FIXED
150 INPUT #l:F,NEWA$ :: IF F (> 112 THEN CALL
CHAR(F+32. NE WA5):: GOTO 150
160 CLOSE #1
170 ~GET SCREEN & COLORS
180 OPE N #i:C$ . INTERNAL. INPUT , FIXED
190 FOR 1 =2 TO 20 :: INPUT #I :P$ :: FOR J=l
TO 32 : : ZI ( I.J) = ASC(SEG$(P$,J,l»:: NEX
TJ::NEXTI
200 INPUT *I: P$: : E=ASCCP$): : CALL SCREEN<E
) :: INPUT *I:P$ :: FOR 1 = 1 TO 14 : : FR ( I
)= ASC(SEG$(P$,2*I - I . I » : : BC I )=ASC<SEG$(
P$,2* ',1 »
21121 CALL COLOR<LFRCI) . B<1» :: NEXT I : : CLO
SE .1
22 0 CALL CLEAR :: FOR 1 =2 TO 2 0 :: FOR J= l T
o 32 : : CALL HCHAR(I,J,ZI (I,J» :: NEXT J
.. NEXT I
230 FOR T=1 TO 1000 :: NEXT T

225
·.
Sound Maker -
- - - - - - Frank Elsesser

Tile TI-99/4A home computer cat! produce a great variety of


sounds. "Sound Maker" will appeal to a"yone who wallts to
add sou nd effects or music to a program. It 's also all easy,
but highly effective way to explore the audio capabilities of
your com puter.
The TI-99/ 4A, like most other computers, requires that you
use numbers to program a sound's duration, pitch , and vol-
ume. Finding the right numbers to produce exactly the sound
you wan t can be a fairly inefficient trial-and-error process. You
must type a CALL SOUND statement with each attempt, try-
ing out different values for the parameters, until you find the
combination of numbers that matches the sound you're look-
ing for. Wouldn't it be nice if this process were automated so
you could spend more time being creative and less time typing
and manipulating numbers?
"Sound Maker" does this and more. It allows you to
experiment easily with different settings of amplitude (vol -
ume), frequency (pitch), and time (duration). You can work
with simple and complex tones, noise, and modulation to cre-
ate a variety of special effects. The computer will even print
the program statements used to create the sounds so you can
add them to your own programs.
When you run the program, it will take awhile for the
computer to establish room for variables and arrays and do
other housekeeping chores before you see the introduction.
After a brief demonstration of tones and explosions, the main
menu will be displayed.
You have a choice of three basic tones: simple, noise, and
complex. Selecting simple tones allows you to experiment with
the amplitude, frequency, and time of a simple tone. Choosing
noise tones brings you a me nu of four tonal types: periodic,
periodic with tone, white, and white with tone. Complex tones
consist of three simple tones and one noise tone played
simultaneously. The frequency and amplitude of each tone can
be changed individually.

226
_ _ _ _ _ _ Sound and Graphics

After you have selected the basic tone and found the
combination of parameters which suits you r taste, you w ill be
taken to the modul ation menu. Here, you can make the am-
plitude, frequency, or time change-while the note is play-
ing-to create special effects. The procedure for modulating
frequ ency and time is fairl y straightforward . However, choos-
ing amplitude modulation displays another menu. Three types
of amplitude modulation are available: on/off clicking, pos-
itive ramp, and negative steps. On/off clicking turns the
sound on and off like the busy signal on a telephone. Positive
ramp makes the tone louder with time. Negative steps make it
quieter with time. Positive ramps and negative steps can be
used in your programs to give the effect of an approaching
and receding alien ship.
Experimenting with sounds using Sound Maker is so easy
that you will have the freedom to create sounds you never
thought possible on your TI.
Sound Maker
1 00 CALL CL EAR
110 DIM SI (60 )
1 20 R$="SOUND MA KER"
1 30 CALL SCREE N (14)
140 FOR P = 1 TO It
1 50 CALL SOU ND( 1 50. - 4 , 1 )
1 60 CALL HCHAR(12 . 9+P . ASC(SE G$ ( R$, P ,1» )
1 70 NEXT P
1 80 FOR DE = 1 T O 500
190 NEXT DE
200 CALL CLEAR
2 10 FOR 1 = 1 TO 8
220 CALL COLOR(I, 1 6, 1)
230 NE XT I
240 PRINT .. YOUR TJ CO MPUT ER I S CAPABLEOF MA
KI NG AN ALMOST ENDLESS VARIETV OF SPECIA
L EFFEC T ( 3 SPACES}SOU ND S .": :
250 PRINT" THE PURPOSE OF THIS PROGRA NI S TO
HE L P YOU FIND JUST THERIGHT SO UN D FOR Y
OUR SPEC I ALEF FECT .": :
260 P RIN T" IT ALLOWS YOU TO GENERA T E S IM PL
E TO CO MP LEX SO UN DS ANDTO THEN ADD SPEC I
AL EFF E CT MOD ULAT IONS . " : : :
270 P RINT "(4 SPACES} (ONE MOMENT PLEASE)":
280 REM COMPUTING S - OCTAVES
290 FOR N=0 TO 60
300 Sl( N) :I NT ( 110.( 2 ..... (1/1 2 » " N+.S)

227
Sound and Graphics ______

-.
3 113 CALL S aUND ( - 5S S,SI ( N).4 )
320 NEXT N
33 0 FOR A=0 TO 20 S TE P 5
3 40 CALL Sa UNO (70S.-7,A)
3513
36 0
370
380
399
NEXT A
REH START VALUE S ~ MAIN MENU
CALL CLEAR
Tl = 1000
F 2=3 0999
-
400 A3=3 0
419 F 4 :a300S0
4 20 A5 =3 9
4 30 F6"30000
449 A7 =3 121
45 121 La = 1
4 6121 A9= 3 121
4 7121 PRINT TAB(12 ) ;"M EN U":
489 PRINT TAB( 5, ;"1. SI HPLE TO NES" :
490 PRINT TAB(S';" 2 .NOJ SE TONES";
50121 PRINT TAB(5);" 3 . CO MPL EX TONES" :
5 1121 PRINT TAB(5) ;"4. EXIT ":
52121 INPUT "SELECT NO . ( 1 . 2 . 3 . OR 4 ) ": H
539 ON M GOTa 6513 .1 659 . 2830,51 1 9
54121 REM MO DULATIO N MENU
550 CALL CLEAR
569 PRINT TAB ( 1 9) ; " MODULATIONS":
579 PRINT
580 PRINT TAB (9 ):"1.AMPLITUDE" :
599 PRINT TAB(9);" 2 .FREQUEN CY ":
690 PRINT TA B(9 ) :" 3 .TIME":
610 PR INT TA8(9' ;"4.M AI N MENU":
620 IN PUT "ENTER NUHBER(1,2, 3 ,4)":N S
630 ON NS GOTO 9313.4570 .4 840 . 37 0
640 REH SINGLE TONE GEN
650 CALL CLEAR
660 PRINT TA8(9);"SIMPLE TONES" ;
b70 PRINT
bB0 PRINT " ( PRESS ENTER TO SELECT TONE)":

b90 A3=2
700 FOR N=0 TO b0
71£" F2:5I (N)
729 CALL S OUND(5SS.F2 . A3)
730 CALL KEY(S, K,Z)
7 40 IF K-13 THEN 7713
759 NEXT N
7b9 GO TO 379
-
7713 PRINT "FREQUENCY=";F2:
780 PRINT "TIME - 1000.AHPLITUDE =2" :
790 PRINT "CHANGE PARAHETERS(Y OR N' ? ":
--
228
_ _ _ _ _ _ Sound and Graphics

8~~ CALL KEY(0 , K,Z)


8110 IF Z+I=1 THEN 81010
8210 IF K=89 THEN 8410
8310 IF K=78 THEN 5510 ELSE 81010
8410 INPUT "NEW TIME= " :Tl
BSe INPUT "NEW AMPL-":A2
8610 CALL CLEAR
8710 CALL SO UNDCTt,F2,A 3)
9810 PRINT TAB(6);"TRV AGAINCY OR N)":

8910 CALL KEY(0,K,Z)


9103 IF Z+I=1 THEN 8910
9110 IF K=89 THEN 6510
9210 IF K=78 THEN 5510 ELSE 8910
9310 REM AMPL MODULATION MENU
9410 CALL CLEAR
9510 PRINT " (3 SP ACES }A MPLITUDE MODULATION":

9610 PRINT TABCS);"I . ON/OFF CLICK ING" :


9710 PRINT TAB(S);"2 . POS RAMP" :
9810 PRINT TAB(S);"3.NEG STEPS":
9910 PRINT TAB(S);"4.MODULATION MENU":
Ieee INPUT · SELEC T(1 ,2,3.0R 4)N:NM
IlOIlO ON NM GO TO 110 310 ,1 2310, 14510,5510
110210 REM ON/OFF AM GEN
1030 CALL CLEAR
11340 PRINT TABCS); "ON/OFF CLICKING":
11215121 PRINT
11216121 PRINT "FOR Z=1 TO Ie"
1137121 PRINT "CALL SOUNDC513,F2,A3, . . . '"
108121 PRINT "NEXT Z":
1090 ZZ=10
11121 3 Tl=50
111121 GOSUB 4643
112121 PRINT "CHANGE PARAMETERS(Y OR N'?" :
11 3121 FOR Z=1 TO ZZ
114121 CALL SOUND(Tl.F2,A3 . F4,A5,F6,A7, - L8,A91
1150 NEXT Z
1163 CALL KEY(0,I,Jl
117121 IF I=B9 THEN 1190
1183 IF 1=78 THEN 94121 ELSE 11313
1193 INPUT "NEW Z MAX =" :ZZ
1 213 3 INPUT "TIME=":Tl
1210 GOTO 1123
122121 REM +RAMP AM GEN
1230 CALL CLEAR
1240 PRINT TAB (8) ;"POSI TIVE RAMP":
125121 PRINT "FOR A= 30 To 121 STEP -2 "
1260 PRINT "CALL SOUNDC-21210,F2,A,F4,A, . . . ) "
1273 PRINT "NEXT A":

229
Sound and Graphics ______

1 28~ Tl"' - 200


1 290 S5 "'2
1 300 GOSUS 4640
13 1 0 PRI NT "C HANGE PARA METERSCY OR N) ?" :
1 320 FOR A= 3 0 TO 111 S TEP -S5
1 330
134 0
1 3~0
CAL L SOUNDCTl,F2,A ~ F4 ~ A . Fb,A ~ - L8,A)
NEXT A
FOR D:: 0 TO ~00
-
1 360 NEXT D
1370 CALL KEYC0 , K,1)
1380 IF 1+ 1 = 1 THEN 1 32 0
139~ IF K= 89 T HE N 1410
1 4 00 I F K=78 T HEN 940 ELSE 4 70
14 10 IN P UT "AMPL STEP SI1E=- " :55
14 20 I NPU T "TI ME = " : Tl
14 30 GOTO 1 3 1 0
144 0 REM NEG STEPS AM GEN
14 50 CALL CLEAR
1 46~ PR IN T TAB(6);"NEBATIVE S TEPS":
147~ PRI NT "FOR A= 0 TO 30 STEP ~ "
1 48 0 PRI NT "CA L L SQUND(500.F2.A,F 4 , . . ) "
1 490 PRINT " NEXT A":
1500 T l =500
1 510 55=5
1520 BOSue 4640
1530 PRI NT "CHA NGE PARA METERS(Y OR N)?" :
15 4 0 FOR A=0 TO 30 STEP 55
1 550 CAL L SQ UNDCTl ,F2 ,A,F4,A,Fb,A, - L8,A)
1 560 NEXT A
1 570 CALL KEY ( 0.K,Z)
1 580 IF 1+1=1 THEN 1540
1 590 IF K= 89 THEN 1610
1 600 IF K:78 THEN 940 ELSE 1530
1 6 10 I NPUT "A MPL STE P SIZE""';5S
1620 INPU T "TI ME= " :Tl
163 0 GOTO 1531!1
1640 RE M NOISE MENU
1650 CALL CL EAR
1660 PRIN T TAB(8):"NOISE TONES" :
16 70 P RINT TAB(6): " l.PERIODIC NOISE" :
1680 PRI NT TAB(6 ) : "2 . PERTODTC WITH TONE":
1690 PRI NT TAS(6 ) ; " 3. WH ITE NOI S E " :
1700 PRI NT TA B (6) ;"4.W H IT E WITH TO NE ":
171 0 PRINT TA D (6 ):" 5 .HAIN MENU":
1 72 0 INPUT "NOISE TVPE(I . 2,3.4 . 5 ) ":N T
1730 ON NT GOTO 1 7 50.1970 . 229 @. 2510.3 7 0
1 7 4@ REM P ERIODI C N GEN
17~0 CALL CLE AR
1 76 13 PRINT TAB ( B) : "PFRIO DI C NO IS E ":
1 77@ Tl=1000

230
_ _ _ _ _ _ Sound and Graphics

1780 A9:.. 2
1790 FOR L9 c 1 TO 4
1880 CALL SOUND(Tl . - LB.A9)
1810 PRINT TAB(1 2) ;"TYPE~";L8:
1820 NEXT La
1830 PRINT "SELECT TYPE~TIME (Y n R 1\1) 7" :
1840 CALL KEV(0,K.Z)
1850 IF 2+1=1 THEN 1840
1860 IF K=78 THEN 1 6 40
1870 IF K=S9 THEN 1880 E LSE 184 0
1980 INPUT ·TYPE=~:L8
1890 INPUT MTIME=":TI
1900 CALL SOUNDeTI . - LB.Aq )
1910 PRINT TAB CB) :"TR V AGA I N (Y OR Nl?" :
1920 CALL KEY(0.~, Z)
19 3 0 IF 2+1=1 THEN 192~
1940 IF K=B9 THEN t B8 ~
1950 IF K=78 THEN 550 ELSE 192 0
1960 REM TYPE 4 N WIT H TO NF
197 0 CALL CLEAR
1980 PRINT N PERIODIC NOI S E WIT H TO NE " :
1990 PRINT "(PRESS ENT F.:R TO S ELECT TO NE )":

200(11 Tl=2000
2910 A= 3 0
2020 A9= 2
2 /i!1 3 8 Z=0
2040 FOR N=0 TO 60
20'50 F6 = Sl (N )
2 060 CALL KEY(0.K . Z)
2070 IF K=13 THEN 2 120
2 0813 CALL S OUND(Tl.F 6, A,F6 . A . F6.A . - 4,A 9 J
213913 L8=4
2 11313 NEXT N
2 1113 GOTO 16513
21213 CALL CLEAR
21313 PRINT" TYPE - 4 PARAMETERS":
21413 PRINT "CAll SOUNDCT1.F.3e.F . . . - 4.2 )" :
2 1513 PRINT "TIME=200e " :
21613 PRINT "FREQUENCV=";F6:
21713 PRINT CDEPRES S ""R""TQ REPEAT) " :
2180 PRINT "TRV NEW PARAM E TERS(Y OR N l?" :
21913 CALL SQUND(Tl,F6,30 . F6,3e,F6,30,-4 . A9)
221313 CALL KEV(e,K,Z)
22113 IF 2+1=1 THEN 221313
2220 IF K=B9 THEN 22513
22313 IF K=82 THEN 21913
22413 IF K: 7 8 THEN ~~0 ELSE 22130
2250 INPUT "TIME=":Tl
22613 INPUT "AMPL=":A9

231
Sound and Graphics _______

227 0 GOTO 2 1 80
22811'1 REM WHIT E N GEN
2290 CALL CLEAR
2300 PRINT TAB (9) : "W H ITE NOISE" :
23HI Tl =2000
232 0 A9=2
233 11'1 F OR L B=5 TO B
23 4 0 CALL SOUNO(T l. -L8 .A 9)
23511'1 PR INT TAB(9):"TYPE = ": LB :
2360 NEXT L 8
237 0 PRINT MSEL ECT T YPELTI ME(Y OR N J~" :
2380 CALL KEY(0 . K . I)
239 13 I F Z+I=l THEN 2380
2 4 00 IF K=78 THEN 1 650
2 41 0 IF K=B9 THEN 2 4 20 E LSE 23811'1
2 4 20 IN PUT "TYPE = ":L8
2 43 0 INPUT " TIM E=" : Tl
2 44 11'1 CALL SOUNO(T l .-L8 . A9)
2 4 50 PRINT TAB(B) : " TRY AGAI N CY OR N )':""':
2 4 611'1 CALL KE YCI1'l . K.Z )
2 4 70 IF Z+I = 1 THEN 24611'1
2 4 811'1 IF K=89 THEN 24211'1
2 49 0 IF K=78 TH EN 5511'1 ELSE 2 4 6 11'1
25 11'10 REM WHI TE N WITH TONES
25 1 11'1 CALL CLEAR
25211'1 P RINT "{ 3 SPACES } WH I TE NOISE WI TH TONES
M :

2530 PRINT " CPRESS E NTER TO SE L ECT TONE) ":

25 411'1 PRINT " NOTE : GOOD EFFECTS AT HIG H


(3 SPACES}FREQUENC I E S " :
25 511'1 Tl = 111'111'111'1
25611'1 A9 =2
257'" L8=8
25811'1 Z= 11'I
2'590 F OR N=0 TO 60
26 !2l!2l F6=S l CN)
2610 CALL S OUNO(Tl,F6, 30 ,F6,3 0 ,F6, 3 0, - LB,A9)
262 11'1 CALL KEYC!2l . K,Z)
263~ IF K= 1 3 THEN 26611'1
26 411'1 NEXT N
26511'1 GO TO 1650
26613 CALL CLEAR
26713 PRINT TABC 7 ' :" TYPE -8 P ARAMETER S ":
2 6811'1 PR I NT "CALL S OUNOCT1,F, 30, F . . - B,A9 ) " :
26911'1 PRINT " {3 SPACES} T I ME= 10011'1":
2711'111'1 PR I NT "{ 3 SPACES}FREQUE NCY= " ;F 6 :
27111'1 PRINT " {3 S P ACE S } NOISE AMP =2 " :
27211'1 PRINT "( 4 SPACES} (PRE SS " - R"" TO RE P E AT)"

232
_ _ _ _ _ _ Sound and Graphics

273 121 PR INT N NE W PARA METER S(Y OR N )?N :


27 4121 CALL S OUND(Tl,Fb, 30 .F 6 . 30 . F6,30, ~ LB ,A 9)
275121 CALL KEY(0,K.Z)
276121 IF l+ I = 1 THEN 275121
277121 IF K=89 T HEN 28 121121
2780 I~ K=82 THEN 274121
279121 IF K=78 THEN 55121 ELSE 2750
28121121 INPUT "TIME : ": T!
281121 I NPUT "A MP L= ":A9
282121 GOTO 273@
293121 REM CO MPLEX TON E
28 4 121 CALL CLEAR
285121 PRINT "CALL SO UNO CTI . F2 . A3,F4 .A 5.F6 "
286121 PRI NT " ( II SPACES} A7 . - LB.A8)-:
287121 PRINT " - - ---- - - - - - - - - - - - - - - - - - - - - - ":
288121 PRINT "-USE KE YS 1 - 9 TO IN CREASE
{ 4 S P ACES}V ALUE S "
289121 PRINT " - DEPR ESS S HIFT & I - 9 KEYS TO
{3 S PA CES}OEC REA SE VALUES"
29121121 PRINT " - DEPRES S" "E NTER "- FOR REPEAT-
291121 PRINT " - DEPRE SS -NE"" TO EXI T"
292121 PRINT ___ __ _ _ ___________ __ ____ __ _ _ " .
2930 PRINT "{ 1 2 SPACES}Tl{3 SP AC ES1F2 A3 ":
29 40 PRI NT "CALL SQ UNO C{ 4 SPACES} .
{ 4 SPACES},
2 95 0 T1 : 1 000
296£1 Z""@
2970 PR INT "{9 SPACES}, . { 4 SPACES} .
) " :
2980 PRI NT " (6 SPACES}F 4 AS F6 A7 L8 A9"
2990 RE M S TA RT VALUES
3 000 F 2= 11 0
3 010 A3=5
3020F 4 = 110
3 0 30 A5:5
30 40 F6: !10
312150 A7:5
3060 La : !
3070 A9=5
30 8 0 RE M S TRIN G PRINT CTI. F2 , . . )
3090 01~=STR$(Tl)
3100 CALL HCHAR(2 0 , 17.32 )
3 11 0 FOR L = I TO LEN(Ol~)
3120 CA LL HCHA R(20 . L+ 13 , ASC(SEG$ { O l$ ,L . I ) )
3 1 3121 NEXT L
3 140 IF Z+I : 1 THEN 3 1 50 ELSE 3 600
3150 D3~=STR$(F2)
3 160 CALL HC HAR(20 . 22 . 32)
3 1 7£1 FOR L : l TO LE N( 03 $ )
3 1 80 CALL H C HAR( 20 . L+ 1 8 . ASC(SEG ~ (D3$rL. \ » )

233
Sound and Graphics _ _ _ _ __

3 19121 NEXT L
3 2 00 IF Z+I = l THEN 3 210 EL S E 3 600
32 10 D4$ = STR$CA 3)
32 2 0 CALL HCHARC 2 0, 2 5, 32 )
3 2 3 121 FOR L = l TO LEN CD4$ )
32 40 CALL HCHAR (2 0 , L~ 23 . A S C (S EG$CD4$ . L.l») __
3 25 0 NEXT L
326 0 IF Z+I = l THEN 327 0 EL S E 3 60 0
3 270 D5$ =S TR$(F4)
3 28121 FOR L= l TO LENCD5$ )
32 90 CALL HCHARC 2 1,ll, 32 )
33 121121 CALL HCHAR( 2 1,L+ 7, ASC( S EG$CDS$,L, 1» )
33 1121 NEXT L
332 121 IF Z+I = l THEN 333 121 ELSE 3 600
3330 D6 $ = STR$(A5)
33 40 F OR L=1 TO LEN ( 06$ )
33 59 CALL HCHAR(21,14 ,3 2)
3360 CALL HCHAR( 2 1.L+12.ASC(SEG$(D6$, L , 1» )
337121 NEXT L
3380 IF Z+l = l THEN 3390 ELSE 3 600
3390 D7$=STR$(F6)
341210 FOR L = l TO LEN(07$)
34 1121 CALL HCHAR(21,19,32)
3 420 CALL HCHAR(21,L+15,ASC(SEG$(07$,L, I » )
343121 NEXT L
34 4121 IF Z+I=l THEN 345121 ELSE 3 6121121
345121 08$=STR$(A7)
3460 FOR L=l TO LEN(08$)
347121 CALL HCHAR(21,22,32)
3 480 CALL HCHAR(21,L+2I21,ASC(SEG$(D8$,L,I»)
3490 NEXT L
35121121 IF Z+I=1 THEN 351121 ELSE 361210
3519 D9$=STR$(L8)
3520 CALL HCHARC21 , 25,ASCC09$»
353121 I F Z+ l =1 THEN 354121 ELSE 369121
3540 D0$=STR$(A9)
355121 FOR L = l TO LENC00$)
356121 CALL HCHARC21,28.32)
3 570 CALL HCHARC21,L+26,ASC(SEG$(D0$,L, 1»)
358121 NEXT L
3 59121 REM SEPARATE UP - ON&EXIT
360121 CALL KEVCI2I,K,Z)
3 61121 IF K= 69 THEN 559
3 62121 CALL KEY (121, I,J)
36 3 0 IF 1 < > 1 3 THEN 3 660
3 640 GOSUB 4140
365121 GO TO 3 61313
3660 IF Z+l=l THEN 36121121
3 67121 IF K ) 32 T HE N 3 68121 ELSE 3 600
3680 IF K=42 THEN 453121

234
_ _ _ _ _ _ Sound and Graphics

36 90 IF K< 4 2 THEN 4 220


37 00 IF K=b4 THEN 41 70
37 10 IF K=94 THEN 44 00
3720 JF K ) 48 THEN 37 4 0 ELS E 3 600
373 0 REM UP CO MMAND S
37 40 ON (K - 4B)GOTO 375 0.3790, 3 840,3880, 3 930,
3970.4020,4060,4 1 00
3750 IF Tl ) 3900 TH E N 3 090
3760 Tl = Tl+U'10
3770 GO sue 414 0
37 80 GOTO 3890
37 90 IF N2 >S9 THEN 3 1 50
38 11'10 N2=N2+1
:S8 1 0 F2=S l (N2)
382 0 Gosu e 4140
383 0 GO TO 3 1 50
38 4 0 IF A3 > 29 THEN 32 10
3850 A3;;:A3 +1
3860 GOS US 4140
:S870 GOT a 32 1 0
3880 I F N4 ) S9 THEN 3270
3 890 N4=N4+1
391210 F 4 sS 1 ( N4 )
39 1 0 GOSUS 4140
3920 GOTO 3270
393 0 IF AS ) 29 THE N 3330
39 40 AS= AS+l
395 0 60sue 4140
3960 GOTO 3330
397 0 IF N6 ) S9 T HEN 33 90
3980 Nb = N6+1
3990 Fb '""S I (Nb)
4 000 GOSUS 414 9
401 0 GOTO 3390
4020 IF A7 >2 9 THEN 3450
40 3 8A7= A7 +1
404 £'1
GOS US 4140
4 0:50GOTO 3 4 50
40b~ IF L8 ) 7 THEN 3 510
40 70 l8'"'L8+1
408 0 GOSUB 414 0
4090 GO TO 35 113
4109 IF A9 ) 29 THEN 35 40
4119 A9"'A9+1
41 20 GOSUB 4140
41 30 GOTO 3540
414 0 CALL SO UND ( - T l . F2~A3,F4,A5.Fb.A7. - L B .A9
)
415 £1 RE TU R N
41b 0 REM DOWN CO MMAN DS

235
Sound and Graphics _ _ _ _ __

41 70 IF N2 ( 1 THEN 3150
4180 N2 = N2- 1
4190 F2=SI(N2)
4 200 GOSUB 4140
4 210 GOTO 3 1 50
4220 ON (K-32)GOTO 4230,423121,4270,4310,4360,
4450,440121,4490
4 230 IF Tl ( 200 THEN 309 0
4 240 Tl=TI - 100
4250 GDSUB 4140
4 260 GOTO 312190
4270 IF A3 ( 1 THEN 32 1 0
4280 A3=A3 - 1
429121 GOSUB 4140
4 300 GOTO 3210
4310 IF N4 ( 1 THEN 3270
4 320 N4 = N4 - 1
4 330 F4=SlCN4)
4 3 4121 GOSUB 4140
4350 GOTO 327121
4 360 IF A5 ( 1 THEN 3330
4 370 A5=A5 -1
43Bf3 GOSUB 4140
4 39121 GOTO 3330
4400 IF N6 ( 1 THEN 3390
441121 N6= N6 - 1
4420 F6=Sl(N6)
44 3121 GOSUB 4140
4440 GOTO 339121
445121 IF A7 ( 1 THEN 3 45121
4460 A7=A7-1
44 70 GOSUB 414121
4480 GOTO 3 45121
4490 IF A9 ( 1 THEN 35 4121
4500 A9=A9-1
45UI GOSUB 4140
45 2 0 GOTO 3540
45 3 0 IF LB ( 2 THEN 35 10
4540 LB=L8 - 1
4550 GOSUB 4140
4560 GOTO 35 10
4570 REM FRED MOD
4580 CALL CLEAR
4590 PRINT ~(3 S PA CES} FREDU E NCV MODULATION":

4600 PRINT "FOR D=0 TO 100 S TEP 2"


461121 PRINT "CALL SO UND <- 5121,F2+D,A3,F4+D,
-L 8,A9 )"
46 20 PRINT "NEXT 0":
46 3121 GOTO 468121

236
_ _ _ _ _ _ Sound and Graphics

4649 PRINT "Tl"''';Tl;''F2 ''' ''jF2;''A3:'';A 3


46:i1iiJ PRINT "F4="jF4; "A5:::";AS;"F6=";Fb
4660 PRINT "A7=";A 7 ;"L8 = ";L8 ; "A9::";A9:
4670 RETURN
468121 Tl =- 5e
4699 00 = 10121
479121 FS :: 2
471121 Gosue 4640
4729 PRINT "CHANGE PARAMETERSIY OR N) ? ":
47 3 9 FOR 0=0 TO DO S TEP F S
4 7 49 CALL SQUNOITl , F 2 +D,A 3 .F4+D,AS.Fb+D,A7, -
LB,A9)
4750 NEXT 0
47 6 9 CALL KEV(0,K,Z)
4779 IF 1+1 = 1 THEN 47 3 9
4789 IF K= 89 THEN 4890
4799 IF K= 78 THEN 559 ELSe 47 3 e
4899 INPUT "FRED RANGE = ":DO
4819 INPUT "FRED STEP S= " : FS
48 2 9 INPUT "TIME - " :T1
48 3 9 GO TO 4 7 213
4849 REM TIME MOD
48:59 CALL CLEAR
4869 PRINT TAB<S):"TIME MODULATION":
4879 PRINT "FOR Tl - 1 TO 3 99 STEP Ie"
4889 PRINT " CALL SOUNOITl,F2,A 3 , . . . A9)"
4899 PRINT "FOR 0 = 9 TO 5"
49121121 PRINT "NEXT D"
491121 PRINT "NEXT Tl":
49 2 121 PRINT "LAST VALUE S "
49 3 121 GOSUB 4640
494121 TM= 3 99
49 5 121 0" 5
496£1 TS = 10
49 7 0 PRINT ·CHANGE PARAMETERS(Y OR N) ? ":
498£1 FOR Tl = T5 TO TM STEP T5
499121 FOR T = 0 TO D
5888 NEXT T
51211121 CALL SOUND(Tl,F 2 ,A 3 ,F4,AS , F6,A7, - LB,A9)
50 2 121 NEXT Tl
50 3 0 CALL KEY(0.K,Z)
51214121 IF Z+I=1 THEN 498121
51215121 IF K=89 THEN 51217121
5 868 IF K= 7 8 THEN 548 EL5E 498~
5 1217121 INPUT "TOT TIME ~ H:TM
51218121 INPUT "TIME 5TEP=":TS
51219121 INPUT "DELAY=":O
5100 GOTO 497121
511121 END

2,7
Sound Shaper
- - - - - - Steven Kaye
TI Translation by Patrick Parrish

"Sound Shaper" manipulates volume and frequency to give


the Tl with Extended BASIC a smoother, more musical
sound. The program also runs on the TI with regular BASIC.

The TI produces waveforms which are square. One micro·


second the sound is off, the next it's on. This abrupt onset of
sound produces somewhat nonmusical sounds. The tones
sound electronic and unlike any acoustic instrument.
As an alternative to turning the sound on and off
abruptly, we can increase and decrease the amplitude (vol-
ume) more gradually under control of the program.
"Sound Shaper" has two sound producing routines that
can be used in your programs. Echo effect produces a sound
that its name implies. The actual routine producing the sound is
in lines 550 to 670. The routine can be extracted as is and used.
The Shaped Musical Notes routine is a bit more flexible.
The program will ask for a rise and fall value. Experiment
with different values. Try low values like .5,2 and .1, 1 and
higher values like 10,10. For an eerie sound try 5,20. If the in·
put values are much higher the program seems to continue
endlessly, but will eventually return to the main menu.
Experiment with values and write down the ones you
like. Once you have found the effect you want for a particular
application, copy the routine from lines 400 to 490. Be sure to
supply val ues for Rand D.

Sound Shaper
IS9 CALL CLEAR
110 CALL SCREE N (lS)
129 PRINT TA8(7): "SHAPING TI SOUNDS"
1 3 9 FOR T= 1 TO 6
140 PRINT
1 50 NEXT T
160 PRINT "CHOOSE:"
170 PRINT
180 PR INT
190 PRINT TA8 (4);N1) SHAPED MUSICAL NOTE S "

238
_ _ _ _ _ _ Sound and Graphics

20. PRI NT
2 10 PRI NT TA B(4): "2> ECHO"
22. PRINT
23. PR I NT TAB(4): "3) QUIT"
24. PRINT
25. INPUT A.
269 IF (VAL(A.' C l)+CVALCA.» 3) THEN 2~0
279 ON VAL(A.)GOTO 298.529.698
288 RE M THIS PART PRODUCES "SHAPED" MU S ICAL
NOTE S
299 CALL CLEAR
399 CALL SCREE N (13)
3 19 PR INT TA8 (3l ;"' S HAPED MUS I CA L NO TES ."
32 9 FOR T = I TO 1 9
33 9 PR INT
3 4 121 N EXT T
35 9 PRI NT "ENTER RISE AND FALL T IME S -
369 PRINT "USE VALUES GRE ATER THA N ZERO";
370 PRINT
3 89 I NPUT R . D
3 99 IF (R-0)+(D-0) TH E N 3 89
480 FOR Fs110 TO 889 S TEP 39
4 1 9 FOR 08 =39 TO £I STEP -SI R
429 C ALL SOUNOC-10.F.DBl
4 30 NEXT 08
44 9 FOR 08 -9 TO 39 S T E P SID
4 59 CAL L SOU ND( - 10.F.DB )
460 NEXT DB
4 79 FOR T - 1 TO 59
489 N EXT T
4 99 N EXT F
509 GOTO 199
519 RE M THIS PART CREATES AN ECHO EFFECT
529 CALL CLEAR
539 CALL SC REEN ( 14 )
5 49 PRINT TABCS) ;"' EC HO EFFECT , .
550 FOR T- l TO 1 2
560 PRINT
570 NEXT T
580 FOR F ~ 110 TO 880 ST EP 3 0
599 FOR oB : 1 TO 3 0
600 CA LL SOU No (- 1 0~F~ oB )
610 FOR T- 1 TO 10
629 NEXT T
630 CALL S OUNDI-10,990-F,DB)
640 FOR J:1 TO 1 0
650 NEX T J
660 NEXT DB
670 NEXT F
680 GOTO 10 0
690 END 239
The Mozart
Machine
- - - - - Donald J. Eddington
TI Translation by Gregg Peele

Your computer can compose music with this special tech·


nique. The compositions are remarkably Mozartian in style.
If you've ever gone through the steps to make your computer
playa particular piece of music, you realize that it can be a
significant programming task. To have your computer actually
write music is a real feat.
To accomplish this, we've first got to find a way to work
with CALL SOUND values in DATA statements in order to
make the measures of music. Also, we need to be able to
READ the values in any order so that the songs will be dif-
ferent with each run of the program. The commonly used
string manipulation methods won't work very well here. We
need variety, and the traditional way of working with strings
quickly results in a tangled mess.
Array Referencinc
The shortest, best way to solve this problem is to use a tech-
nique ca lled array referencing. First, to get the measures of
music, you set up an array of all variables, then reference
them by subscript in a loop. Specifically, 14 variations on nine
variables are required to make the music for this program. The
random number generator is used to make the music different
every time the program is run.
A Mozartian Oavor results from a deliberate shortening of
the low notes and making the high notes of varying lengths.
And to keep the music from becoming totally random, DATA
statements select the measures by their underlying tonality-
tonic, subdominant, dominant, or supertonic. In keeping with
classical style, a cadence is provided every four measures with
a final ending chord for each tune.

240
_ _ _ _ _ _ Sound and Graphics

TI Mozart
1 00 D IH X(14 , 9)
1 1 0 RE M THE TICLANG AMAZ I US MOZART
120 CALL CLEAR
1 3@ CALL SC REE N ( t 4 )
140 PRINT "{3 SPACES}WELCOME! I AM TICLANG N

150 PRINT "{b SPACES,A MAZ I US MOZA RT . "


1 6 121 PRINT
170 PRINT " I PLAY SONGS LIKE THE CHILD"
180 PR INT "PRODIGY, WOLFGA NG AMADEUS
1 90 PR I NT MOZART MI GHT HAVE DONE."
21210 PR I NT
2 10 PRINT "{S S PACES}MOZART LIVED FROM "
220 PRINT "{B SPACES}17S6 TO 1 79 1 "
230 PRINT "AND WROTE OV E R 6 26 WORKS I N"
240 PRINT "{8 SP ACES '3 1 YEARS . ,.
25 0 PR I NT
26 0 PRINT "T HE 5 P I ECES YOU HEAR ARE"
27 0 PRINT " (3 S PA Ce S }BEING WRITTEN BY THE .,
28 0 PRINT COMPUTER AS YOU LrS TE N' "
290 PRIN T
3 121 0 PRINT
31@ PRINT
320 FOR 1 = 1 TO 1 4
330 FOR TT=1 TO '1
3 40 READ X(T.TT)
3 50 NEXT TT
3 6. NEXT T
37. DATA 196 . 494.494. 2 4 7.49 4 . 587 . 29 4,494~221il
38. DATA 1 96 . 494 ,587 . 2 4 7 , 587 . 523 .294. 4 94,294
39. DATA 19 6 ,494 ,523,2 47 ,587 . 523.294,49 4,294
•••
41.
DATA 19 6 . 523 . 587,262,659.784,330,784,262

.2. DATA 19 6 .5 23 . 659 . 26 2 .6 59 .587 . 330,523 , 2 6 2

...
431il

.5.
4 60
DATA 196,659 . 523 . 262 . 392 . 659,330,523, 196
DATA 2 20 . 523 . 587,262 . 784,587.294,523,220
DATA 220 ,440,58 7 ,220 . 52 3 . 494, 29 4 . 440,262
DATA 220 . 659.784.262,587.523.294,494,220
DATA 220 . 523 .494.26 2 . 440 . 494, 330 . 523 ,220
'7. DATA 220,523,494 . 262, 440.4Q4 ,330 , 523 ,262
'8. DATA 196,494,52 3 . 2 47.58 7,5 87,29 4, 587 , 2 94
490 DATA 1 96,587,523,220,440,440,294, 4 40, 2 20
500 DATA 1 96 ,659 , 58 7 , 262 , 523,5~3,330,523,262
510 P =25 0
520 DATA 1 . 3,6 .2. 1 .4.6 . 2,3 ,4,1, 5, 1 , 4, 6 ,7 , 1,4
. 6,2, 1. 3 . 6 ,9
5 30 DATA 1 . 1 . 4. 5.1.4 . 6 . 2 . 3 . 4.1 . 5 . 1 . 4.1.5 .1 ,4
. 6,9
541il DA T A 1.4. 6 . 2 . 3 . 6 . 1 . 5 .1.4.6. 7 ,3 . 4,6, 2 . 1 , 4
. 3,7 ,1.4 ,6 ,9
241
Sound and Graphics ______

SSe! DATA 1.4~ 3 . 7 .1. 6. 4.5. 6 . 3,b , 2 J4, 6 .1. 5.1,4


,6.9
56f21 DATA 1 ,4 . 3 .7,6. 3,6.2 ,4, 6,1,5,1 . 3 . 6 , 7 , -:; ,6
, 1 ,5,1 ,4 ,6.9 , 8
570 READ RR
5813 ON RR GOTO 65f21 .59f21. [email protected] . 6113 , 86@,64f21,9
413.11340
590 Y=12
600 GOTO 99.
61. Y=1 4
620 GOTO 99.
63. Y=1 3
640 GOTO 99.
65. Y=I
660 RANDOMIZE
670 IF RND > . 35 THEN 70121
68el Y= 3
6913 RA NDOMIZE
713 13 I F RND < .7 5 THEN 720
7 10 Y=2
7213 GOTO 9913
7313 Y= 1 0
7 4 0 RANDOMIZE
75121 I F RND > .4 THEN 7813
760 Y:ll
7713 GOTO 9913
7813 Y==4
7913 RANDOMIZE
8130 IF RND > . 35 THE N 820
810 Y=S
82121 RANDOMIZE
830 I F RND < . 75 THEN 850
8 4 121 Y=6
8513 GOTO 9913
860 Y=7
8713 RANDOMIZE
8813 IF RND > .35 THEN 913121
890 Y=8
90121 RANDOMIZE
9 1121 I F RN D< . 75 THEN 93121
920 Y=9
930 GOTO 9913
9413 PRINT "(S SPACES} WELL, THAT'S AL~"
9513 PRINT" ( 4 SPACES}HOPE YOU LI KED IT ~ I "
9 613 PRINT "RUN IT AGAIN AND HEAR FIVE
9713 PRINT "(8 SPACES}1'10RE SONGS."
9813 END
9913 FOR 1=1 TO 9 STEP 3
113013 CALL S OUND(P , X(Y,I),2,X(Y, 1+1) ,2)

242
_ _ _ _ _ _ Sound and Graph ics

HH0 CALL SQ UNO(P,X(V,I) ,30 ,X(Y,I+ 2),2)


1020 NEXT I
1030 GOTO 570
1040 CALL SQUN DC1800.19 6,2, 494, 2,784,2)
1050 FOR T - l TO 800
ISbill NEXT T
1070 KOL - INT(RNO*B)+8
1080 CALL SCREEN(KOL)
1090 GOTO 570

243
L
6
A Beginner's Guide
to Sprites
- - - - - - Gary K. Hamlin

Sprites are easy to create and use. They enhance the graphic
displays and make smooth moving objects simple to cOlltro/,
This program requires Extended BASIC.
An exciting feature of most personal computers is their color
graphics capability. Even if the computer was purchased for
financia l management or complex mathematical computations,
it's hard to resist experimenting with graphics. Defining
and manipulating your own characters-from oddly shaped
"dood les" to those resembling actual objects-can be a lot of
fun, and can have practical applications too.
Graphics are quite easy to use on the Tl-99/4A, with TI
BASIC's series of built-in graphics subprograms. Once they are
learned, subprograms used with sprites are also easy. Sprites
require the addition of the TI Extended BASIC cartridge, and
will greatly enhance the computer's possible graphics
applications.
Sprites Vs. Characters
A sprite can be one of the characters from the TI character set
or can be made from user-created dot patterns, just as is done
in standard BASIC, using the CHAR subprogram. Sprites,
however, are more versatile than standard BASIC characters.
Sprites can be positioned at 49,152 different screen locations
(192 rows by 256 columns); standard characters have only
768 possible screen positions (24 rows by 32 columns). This
permits faster and smoother character movement, a Significant
advantage in game programming.
The CALL CHAR statement is used in defining Extended
BASIC sprites much as it is in standard BASIC character defi-
nition. The same 8 X 8 dot grid and hexadecimal on/off
codes are used (Figure 1), but sprites can occupy up to four 8
X 8 dot blocks. The resulting hexadecimal code pattern identi-
fiers can contain up to 64 characters. The computer will auto-
matically reserve four blocks for each sprite, whether or not all
247
Sprites _ _ _ __

of them are actually used; therefore, it's advisable to think in


sets of fo ur blocks even if the sprite is to occupy only a small
portion of the reserved area. Figure 2 illustrates the arrange·
ment of the blocks.

Ficure I. Pattern Identifier Guide


Binary Hexadecim al
Code Code
- OFF1 - 0N)
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
100] 9
1010 A
1011 B
1100 C
1101 0
1110 E
1111 F

Flcure 2. Order of 8 X 8 dot blocks


for sprite definition and placement

, -

- IS

248
- -_ _ _ _ Sprites

Deflninc a Sprite
Sprite characters should he assigned character codes divisible
by four if they are to occupy more than one of the four blocks.
This is less critical for single-block sprites, but the character
code assigned to a single-block sprite will affect which
blocks-A, H, C, or D-the sprite will occupy. The computer
will always assign a character code divisible by four to block A.
The order of the blocks, as shown in Figure 2, is also criti-
cal when writing out the pattern identifier of a multiple-block
sprite. If the order is not observed-and if block A's character
code is not evenly divisible by four-the four segments of the
sprite will become jumbled when displayed on the screen. Al-
ways begin with the pattern identifier for block A, at the up-
per left, proceeding to the lower left (8), upper right (C), and
concluding with block 0 at the lower right.
It should also be kept in mind that in program references
to the screen location of a sprite, the specified location identi-
fies the dot occupying the upper-left corner of the four re-
served blocks (shown as the shaded dot in block A, Figure 2).
This is true whether or not that dot constitutes a visible part of
the sprite.
The sprite mapped out in Figure 3 is intended to occupy
four 8 X 8 blocks. To illustrate the proper sequence of the
hexadecimal code pattern identifiers, the pattern identifiers
will be referred to as string variables with the letter of the
variable corresponding to the letter designation of each of the
four blocks. The program statements would be:
1~~ A~=·01 020 4 020 1 23~68D"
11 0 B~=·8D~6230102040201·
120 C~=·8040204080C 46ABl·
130 D~="BI6AC4804020408~"
140 CALL CHAR(96,A~&B~&C~&D~)

While it isn't necessary to use separate statements in this


manner, it may be helpful to do so until the arrangement of
pattern identifiers becomes familiar. The same thing could be
accomplished by a single program statement:
100 CALL CHAR(96,"010204020l
235681J81J562301020402016040204
OSOC46AB16AC48040204080")

249
Sprites ____ _ _

It's only necessary to specify one character cnde in the


CALL CHAR statement; the computer automatically assigns
the other three. Even in the case of single-block sprite charac-
ters, three character codes will be set aside for the sprite in
addition to the specified character code.
Again, the computer will always assign a character code
evenly divisible by four to block A the upper-left portion of
the sprite. For the snowflake sprite just identified (Figure 3),
character 96 was specified. 96 is evenly divisible by four;
therefore, character 96 is assigned to block A. Block B will
automatically be assigned 97; block C will be assigned 98, and
character 99 will be assigned to block D.
Figure J. Snowflake Sprite

Hexadecimal Code
01 80
02 40
04 20
02 40
01 80
23 C4
56 6A
8D B1
8D B1
56 6A
23 C4
01 80
02 40
04 20
02 40
01 80

The spaceship sprite shown in Figure 4 will occupy only


one of the four blocks. If the character code used for the
spaceship were 90, the sprite itself would be placed in block
C. Since the next lower number evenly divisible by four is 88,
character code 88 would be assigned to block A.
The program line identifying the spaceship sprite would
read:
1 5 0 CA L L C HAR( 9 0."1 8 1 8 18 3C3 C3 CbbC 3 ")

250
_ _ _ _ _ _ Sprites

Figure 4. Spaceship Sprite

Hex.
Code
18
18
18
3C
3C
3C
66
C3

Displaying the Sprite


Once a sprite has been defined, the CALL SPRITE statement is
used to display it on the screen. The syntax for the CALL
SPRITE statement is: CALL SPRITE (sprite number, character
code, sprite color, row, column, row velocity, column velocity).
Values for row and column velocities, which cause the sprites
to move, are optional. The CALL MOTION statement is an-
other method to move a sprite. Both methods will be dem-
onstrated below.
The sprite number can be any number from 1 to 28. The
sprite number is always preceded by a #. The character code
must correspond to the one specified in the CALL CHAR
statement. Since the CALL SPRITE statement requires naming
a sprite color, no separate CALL COWR is needed. The back-
ground color of sprites is always transparent, so only the fore-
ground color is named in the statement.
The row and column determine the sprite's location on
the screen. Each can be in the range of 1 to 256, but only rows
above 193 will be visible on the screen: Rows 193 and 256 are
offscreen. Position 1,1 is the upper-left corner of the screen.
The va lues used for row and column will determine the screen
placement of the dot in the upper-left corner of the space
allotted to the sprite.
The following program lines, combined with lines 100 to
150 above, will clear the screen, color it gray, color the snow-
flake sprite red and the spaceship black, and place the sprites

251
Sprites ______

on the screen. Once the RUN command is given, line 200 will
cause the program to continue running until CLEAR (FCTN 4)
is pressed.
16. CALL CLEAR
17. CALL SC RE E N(l S )
18. CA L L S PRITE(#1.96.7,95.7S)
19. CALL S PRITE(#2.90 . 2 . 170,125)
2 •• GO TO 200

Magnify the Sprite


This places the two sprites on the screen. However, the snow-
flake sprite is displaying just the upper-left (block A) part of
the sprite. Only that part of a sprite whose character code is
named in the CALL SPRITE statement will appear.
A CALL MAGNIFY statement can be used to double the
size of sprites or to display multiple-block sprites-our snow-
flake. It can perform either function separately, or both to-
gether, depending upon the magllificatioll factor specified.
CALL MAGNIFY(I) would make no change in either the
size or appearance of the sprites. CALL MAGN IFY(2) would
double the size of all sprites displayed on screen. Rewriting
line 200 and adding line 210 to the sample program will simply
double the size of the spaceship and the upper-left portion of
the snowflake.
2 00 CALL MAGNIF Y (2)
2 H'I GOTQ 2 10

In order to correct the problem with sprite # 1, line 200


must read:
200 CALL MAGNI F Y ( 3)

This displays the snowflake correctly, but introduces a prob-


lem with the spaceship sprite. Extraneous characters have sur-
rounded it. The same condition would exist if a magnification
factor of four were used; only the sprites, and the extraneous
characters, would be twice as large.
2 00 CALL MA GNIFY(4 )
The extraneous characters correspond to the ASCII codes
of the characters used for the sprite. Block A is character 88
(X); block B is character 89 (Y); and the open bracket ([) is 1

252
_ _ _ _ _ _ Sprites

character 91. This problem can be avoided by using one of the


"free" character codes (128 to 143) for sprites which will oc-
cupy fewer than four blocks.
Note that the CALL MAGNIFY statement affects all
sprites in the program, and cannot be used to single out in-
dividual sprites.
The extraneous characters can be removed by changing
statements 150 and 190 to:
15 0 CALL C HAR ( 1 3~ ,·181818 3C3C3C66C3 ·)
19 0 CALL SPRITE(#2.130,2, 170,125)

All other program lines will remain the same. After making
the changes, try running the program with both magnification
factors three and four used in line 200. The two sprites will
now appear as intended. For the remaining program demon-
strations, the magnification factor should be set at three.
Where's the Sprite?
Once sprites have been correctly displayed on screen, various
subprograms can be CALLed to manipulate them. Motion can
be added, the appearance of a sprite can be altered, and infor-
mation can be obtained about character pattern identifiers,
sprite location, and the distance between sprites.
The POSITION subprogram is used when the numeric
values of the screen location of a sprite are desired. In the
CALL POSITION statement, sprite number is fi rst specified,
followed by two numeric variables. When the statement is
executed, the numeric variables are set equal to the values of
the sprite's row and column, respectively. Values returned are
for the location of the upper-left corner of the four block sprite
allotment.
The following changes and additions to the demonstration
program will illustrate the operation of the POSITION
subprogram:
21@ CALL POSITIONCMI,DRl,oCl)
220 CALL POSITIONCM2.oR2 . oC2)
23~ PRINT TAB( b) ; "ROW"."COL"
240 PRINT "Ml; ";oRI,DCI
250 PRINT ""'2 ; ": oR 2 , DC2
260 STOP

253
Sprites ______

When the program is run, the result wiU be:


ROW COL
#1, 95 75
#2, 170 125

What Does It Look Like?


Another buil t-in Extended BASIC subprogram allows the re-
view of character pattern identifiers. The CALL CHARPAT
statement is not exclusive to sprites and can also be used with
standard user-defined characters as well as with predefined
al phanumeric characters.
The CALL CHARPAT statement calls for the character
code of the character whose pattern identifier is to be found ,
followed by a string variable. The result of the stri ng variable
will be the named character's 16-character pa ttern identifier,
expressed in hexadecimal. For a multiple-block sprite like the
snow flake, a FOR-NEXT loop should be used in order to ob-
tain all four of its pattern identifiers. By making the fo llowing
alterations to the sample program, the pattern identifiers of
the snowflakes and spaceship sprites will be displ ayed, along
with the asterisk (.) and the numeral four (4) and their charac-
ter pattern identifiers.
210 CALL CHARPATC1 3 0 . CP2$ ) ::PRINT CP 2 $
220 FOR CC= 96 TO 9 9
230 CAL L CHARPAT CC C,CP \ $)
2 40PRINT CP 1 $ :: NEXT CC
2 50FOR CC= 4 2 TO 52 ST EP 1 0
2 60CALL CHAR P ATC CC,CP$ )
27 0PRINT TAB( 3) ; CHR$ ( CC ) :""; CP$
2R0 NE XT CC
290 S TOP

This will display:


1818183C3C3C66C3
010204020123568D
8D56230102040201
80402040BOC46ABI
B16AC4804{)204080
• 000028107Cl02800
4 00081828487C0808

254
_ _ _ _ _ Sprites

How Far Is It?


The CALL DISTANCE statement is used to determine the dis-
tance between two sprites, expressed as the square of the
number of dots separating them. It uses the dot occupying the
upper-left corner of the four-block allotment as the point of
measurement. CALL DISTANCE can also be used to measure
the distance between a sprite and a given screen location.
The statement will include either two sprite numbers, or a
sprite number and the row and column values of a screen
location, followed by a numeric variable. The actual dot dis-
tance is found by taking the square root of the value found for
the numeric variable. The results are calculated to eight deci-
mal places, so if it is preferred that values be expressed as
integers, the INT function can be added to the appropriate
program lines. Changing the demonstration program with the
lines below will make the program find the distance between
the two sprites and the distance between the snowflake sprite
and the upper-left corner of the screen (position 1,1):
210 CALL DISTANCE C ~1.~2. X)
220 DST =S QR(X)
230 PRINT DS T
2 40 CALL DISTANCE(~l,l.l.Y)
250 DIS =S QRCY)
260 PRINT DIS
2711' STOP
280 REM DELETE THI S LINE

The results of the sample program will be:


90.13878189
119.6327714

Moving Sprites
CALL WCATE is used to change the screen location of a
sprite. It does so immediately upon execution of the program
line, producing an abrupt change rather than gradual motion.
The syntax is CALL WCATE(sprite number,row,column).
2 10 CALL LOCATEC.2, 1,200)
220 FOR DELAY = l TO 1000 : : NEXT DELAY
230 CALL LOCATE(.2,15~15)
2 40 FOR DELAY = l TO 1000 : : NEXT DELAV
250 CALL LOCATE(~2,170,125)
260 GOTO 210
270 REM DELETE THIS LINE

255
Sprites _ _ _ _ __

These lines move the spaceship sprite from its original po-
sition first to a point near the upper right of the screen, then
near the upper left, then back to its original location. The pro~
gram will continue to run until CLEAR (FCTN 4) is pressed.
If a change in the character pattern is wanted without
otherwise affecting the sprite, the CALL PATTERN statement
is used. It can be used to completely reshape a sprite or to
make more subtle changes in appearance. When combined
with other statements, it can be used to simulate the visual
effects of motion. By changing the sample program lines as
follows, the spaceship sprite will change from vertical to hori~
zontal orientation, then back again.
2 10FOR 0=1 TO 1000 : : NEXT 0
220 CALL CHAR(1 40. "80C0783F3F7BC080")
230 CALL PATTERN(#2, 140)
2 40FOR 0=1 TO 1000 :: NEXT 0
250 CALL PATTERNC # 2.130)
260 GOTO 2 1 111

The CALL CHAR statement containing the pattern identi-


fier for the modified sprite need not immediately precede the
CALL PATTERN statement; it can be included anywhere in
the program before the CALL PATTERN statement.
Motion of the sprites can be accomplished in either of two
ways: by specifying row and column velocities in the CALL
SPRITE statement, or by adding a CALL MOTION statement
later in the program. In the CALL SPRITE statement, row and
column velocities are specified following row and column val~
ues, which then become the sprite's starting point; in CALL
MOTION statements, row and column velocities follow the
sprite number.
Values for row and column velocity fall within the range
of - 128 to 127. The closer the value is to zero, the slower the
motion will be. Negative values for row velocity move the
sprite upward while negative column velocity moves the sprite
to the left. Conversely, positive values move the sprite down
or to the right. A value of zero for row velocity means that
there is no vertical movement; likewise a column velocity of
zero prevents horizontal movement. When unidirectional
movement is desired, zero must be specified as a velocity for
the direction in which motion is not wanted.

256
_ _ _ _ _ _ Sprites

Examples of both methods of initiating sprite motion can


be added to the demonstration program as follows:
Change line 180 and lines 210 to 240, and add line 250:

lB. CALL 5PRITE(#1.96.7,95,75,5~,-50)


210 REM
22. REM
230 REM
2 4' CALL MOTION(#2. - '5.0)
258 GOTD 25.

These changes cause the snowflake sprite to move down


and to the left at a diagonal, while the spaceship moves
slowly upward. Notice that motion begins as soon as the pro-
gram line is executed and is continuous until the program is
stopped. The spaceship cycles from the bottom to the top of
the screen over and over. A time-delay FOR-NEXT loop can
be inserted to end the movement of the sprite by deleting the
sprite. Differences in sprite velocity necessitate experimenting
to find the upper limit needed in the FOR-NEXT loop. In this
case, changing the program to:
250 FOR DELAY=1 TO 2200 :: NEXT · DELAY
260 CALL OELSPRITE(#2)
270 GOTO 2711!

allows the spaceship to move as far as the top of the screen


when it will disappear. The DELSPRITE subprogram deletes
the specified sprite as soon as the program statement is ex·
ecuted. DELSPRITE can also be used to clear all sprites from
the screen by writing CALL DELSPRITE(ALL).
To restore the sprite to the screen after motion is stopped,
rewrite line 270 to send the computer back to line 240, or fol·
low line 260 with a new CALL SPRITE statement duplicating
line 190. As it was written, once the CALL DELSPRITE state·
ment is executed, the spaceship will not return to the screen.
Motion begins as soon as the CALL SPRITE or CALL
MOTION statement is reached. The start of motion can easily
be controlled, however. Adding a KEY subprogram allows mo·
tion to begin only after a certain key has been pressed. Add
these lines in place of the three REM statements:
210 CALL KEY(~ . K . S)
220 IF 5=0 T HEN 210
230 IF K=32 THEN 240 ELSE 2 10

257
Sprites _ _ _ __

Now, when the program is run, the spaceship will not


move until the space bar is pressed.
Different values for row and column velocity will, of
course, change both the speed and direction of sprite move·
ment. Changing the values may also affect the angle at which
the spri tes move. The closer the values, the greater the angle
at which the sprites move. If values of 50 were spedfied for
both row and column velocity, the angle would be 45 degrees.
If row velocity were increased to 90, the angle of movement
would be smaller, and motion would be more vertical. Accord-
ingly, a greater value for column velocity would make move-
ment more horizontal. This is true even if a negative value is
specified for either row or column velocity while the other is
positive, as demonstrated by the motion of the snowflake
sprite. Try changing the values of the row and column veloc-
ities given for both sprites. Experimenting with different val-
ues demonstrates how they change the speed and angle of
sprite motion.
Detecting Collision
The CALL COINe statement performs a function especially
useful in game programming. It instructs the computer to
monitor sprite movement to determine wh en two or more
sprites occupy the same position, or are within a certain num-
ber of dots of each other. It can also be used to determine
when a sprite reaches a specific screen location, or passes
within a certain number of dots of the screen position.
If information is needed for all sprites, then CALL
COINC(ALL) is used in the program; otherwise, CALL
CDINC is followed by two sprite numbers, or a sprite number
and the row and column of a screen location, a tolerance
value, and a numeric variable. Tolerance is simply the number
of dots which may separate the two sprites or the sprite and
screen position in order for coincidence to exist. Again, the dot
in the upper-left comer of the sprite is used for measurement
purposes.
When the CALL CDINC statement is executed, the com-
puter assigns a value to the numeric variable in the statement.
If there is no coincidence, the numeric variable is set equal to
zero; if there is coincidence within the allowance of the tol-
erance specified, the value is set equal to - 1. Instructions can
be given to the computer to act based on the value of the vari-

258
_ _ _ _ _ _ Sprites

able. IF-THEN statements employed in this way can be used


to change a score or screen color, sound a tone, or even playa
tune by using the proper sequence of CALL SOUND
statements.
It should be remembered that the coincidence of two
sprites, or of a sprite and screen location, does not have to be
visible.
Program lines 250 to 390 below demonstrate the opera -
tion of the COINe s ubprogram.
250 C AL L C OIN C( *'l.*' Z, I0 , el l
2 60 CAL L CO IN C c't 2 .1 . 1 2 5,l, C 2)
27 0 PRINT C l
280 IF C l =- I THEN 3 00 EL S E 2 90
2 90 I F C 2=- 1 THEN 35 0 ELSE 2 50
3 00 C ALL S CREEN ( lJ)
3 10 C ALL S DUND C100 ,2 62,2)
32 0 F OR 0 = 1 TO 2 00 :: NEXT 0
330 CAL L SC R E EN CtS )
3 40 GOT O 2S l1l
3 50 CALL SC REEN ( 4)
36 0 CALL S DUND(100.S 23 , 2)
370 FO R D= 1 TO 2{'10 :: NEXT 0
38 0 CALL SC REEN(l 5 )
3 9@ GO T O 250

Line 270 will continuously print the value of C1 as the


program runs. If Cl = - 1, coincidence of the two sprites ex-
ists, and control shifts to line 300, where the screen color is
changed to yellow and middle-C is sounded. When the space-
ship sprite comes within one dot of the top of the screen, C2
is set equal to - 1, and control moves to line 350, where the
screen becomes green, and C above middle-C is sounded. The
program will continue to run until CLEAR (FCTN 4) is
pressed. It will probably be necessary to allow the spaceship
sprite to cycle the screen several times before coincidence with
the snowflake sprite is detected .
You may notice that sometimes the sprites appear to col-
lide but no coincidence is detected. Coincidence is only de-
tected when the CALL COINC statement is being executed-
in this program, line 250. One way to avoid this problem is to
check coincidence often. This solution, though, tends to make
the program longer than it needs to be, thus slowing it down.
The best solution is to keep the loop (in the example, program

259
Sprites ______

lines 250-290) to as few lines as possible and adjust the tol-


erance. Since too large a tolerance will cause coincidence too
often, it is best to experiment with different values.

Demonstration Procram
These are the essentials of sprite programming, and the
demonstrations used are only representative of what can be
done with sprites. After experimenting with the different sub-
programs, you'll discover how to best use sprites in your own
programs.
Below is a complete listing of the sprite demonstration
program.
Sprite Demonstration
100 CALL CLEAR
110 PRINT TAB(S ) :" • ••• SPRI TE OE MO***."
120 PRINT :: P R INT "DE S IGNED TO ACC OM P AN Y"
13 0 PRINT ",," A BEGINNER ' S GUIDE TO
( 6 SPACES } SPRITES IN TI EXTENDeD
{S S PACES}BASIC .,,',
170 FOR 0 = 1 TO 1000 :: NEXT 0
180 CALL CLEAR
1 90 PRINT "THIS DE MON S TRATION FOLLO WS THE 5
EDUENCE OF THE ARTI CL E ."
200 PRINT : : PR IN T "THE PRO GRAM S TEP S US ED A
RE THE SA ME AS THO S E US ED IN {3 S PACES } T
HE ARTICLE."
2 10 PRINT :: PR I NT " AT THE END OF EACH DEMO .
A TONE WILL SOUND. "
220 PRINT :: PRINT ~THE N PRESS LETTER Q TO C
ON - TINUE WITH THE NEXT DEMO."
230 FOR 0 = 1 TO 1 000 :: NEXT D
2 40 CALL CLEAR
250 A$=·0102040 2 0t~ 3 S68D"
2 60 B$=HBOSb2 3 0 102040 2 0I"
270 C$="8040204080C4 6 AB1"
280 D$="BlbAC48040204080"
290 CALL CHAR ( 9b.A$tB$& C $~D$)
300 CALL CHAR ( 90." 1 81918 3 C3 C3C 6 6C 3 '"
310 CALL SCREE N (15 )
320 CALL SPRITEC.l . Q b, 7 .95.7S )
330 CALL SPRITE(.2,90.7, 1 7 0,125)
335 FOR 0= 1 TO 500 : : NEXT 0
3 40 Gosue 2'500
350 CALL MAGNIFV(2 )
3b0 DISPLAY AT( 3 . 3 ): -MAG. FACTOR 2 "
370 FOR 0=1 TO 500 :: NEXT 0

260
_ _ _ _ _ Sprite,

38 0 CALL MAGNI FV(3)


3 90 DI SP l. AV Al( 3 . 3)ERASE ALL: " MAG . FACTOR 3"
400 FOR 0: 1 TO 51210 :: NEXT 0
410 CALL MAG NI FV(4)
420 DISPLAY AT(3. 3)E RASE ALL:" MAG . FACTOR 4"
4 30 FOR D=1 TO 500 :: NEXT 0
44 0 CALL CLEAR
4 5121 CALL CHAR(13~ . NIBt8183C3C3Cb6C:Nl
4 60 Gosue 312'1012'1
4 65 DISPLAY A1 C2 .31 : MAG. FACTOR ~"
N

4 67 DISPLAY AT (3 . ~):NUN WANTED CHARACTERS NU W


RE -{] SPACES~ M OVED WHEN - - F REEN" CHAR -
(3 SPACES}AC TER CODe USED"
40 8 F OR 0=1 TO ~00 : : NEXT 0
4 70 FOR 0=1 T O 512'10 :: NE)(T 0
480 CALL MAGNIFV(4)
49 12'1 DISPLAY AT (3 . 3)ERAEE ALl : HMAG . FACTOR 4"
513121 FOR 0= 1 TO 50ft! :: NE)(T 0
51121 CALL MAGt II FY(3)
520 DISPLAY ERASE ALL
530 GOSUB 250it4
535 DISPLAY ATCZ,3);"POSI110N DEMO "
S3b FOR ~=I TO 5012'1 :: NEXT 0
5 40 CALL POS I TIONC *I ,DRl , DCI)
S50 CALL POSITION(. 2.DR2,OC2'
560 PRINT TAB<S) : "RQW" . " COL "
570 P R I NT " . 1 : " : DR I . DC 1
58121 PR INT " . , : " :D R2.DC~
599 FOR 0= 1 TO 500 :: NEXT D
609 GOSUB 2591Ct
6 l·0 CALL CLEAR
620 GOSUB 31219'"
625 DISPLAY AT(2, 31:"C HA RrAT OEMO ·'
626 FO" 0=1 TO 306 :: NE~T 0
630 CALL CHARPATCI30.CP2 ~ 1 :: PR1NT (P2 ~
6 40 FOR CC=96 TO 9q
659 CALL CHARPATCCC.CP1')
669 PR I M' CP1' : ; NEXT CC
679 FOR CC= 42 TO 52 STEP Ie
680 CALL CHARPAT(CC . CP ~ )
699 P RINT TAB(2) : CHRSCCC);" ";CPS : : NEX T CC
700 FOR 0=1 TO 500 : : NEXT 0
719 GOSUB 2599
729 CALL CLEAR
739 GOSUB 30 99
735 DISPLAY AT(2 . 3) : "DISTA NCE DEMO"
736 FOR 0 = 1 TO 390 :: NEXT 0
7 49 CALL OISTANCEC.l,.2.X)
750 OST=SOR(X)
769 PRINT DST

261
Sprites ______

770 CALL DISTANCE(#!.1. l.Y }


780 DIS=SQR(Y)
790 PRINT DIS
800 FOR 0=1 TO 500 : : NEXT 0
810 GOSUB 2500
920 CALL CLEAR
830 GOSUB 3000
835 DISPLAY AT(Z,3): "LOCATE DEMO M
B3b FOR 0=1 T O 300 : : NEXT 0
840 CALL LOCATE( # Z,l,Z00)
850 FOR 0=1 TO 5 00 :: NEXT 0
860 CALL LO CATE( # 2. 1 b. 1 6)
870 FOR 0=1 TO 500 :: NEXT 0
880 CALL LOCATE(#2.170. 125)
890 FOR 0=1 TO 500 :: NEXT 0
900 GOSUB 2500
905 DISPLAY AT ( 2,3)ERASE ALL:wPATTERN DE MO"
9136 FOR 0=1 TO 3 00 :: NEXT 0
910 CALL CHARCI 40, M80C0783F 3 F 7 8C080 M)
920 CALL PATTERN(#2, 140 )
930 FOR 0=1 TO 500 :: NEXT 0
940 CALL PATTERN( # 2. 1 3 0 )
950 GOSUB 25130
960 GOSUB 3 5013
965 D I SPLAY AT(2, 3 )ERASE ALL:"MOT I ON DEMO "
966 FOR 0=1 TO 3130 :: NEXT 0
967 DISPLAY ERASE ALL
970 FOR 0=1 TO 3 013 13 :: NEXT 0
980 GOSUB 2500
990 GOSU B 3 500
995 DISPLAY AT(2, 3 )ERASE ALL : MOELSPRITE DEMO

996 FOR 0 = 1 TO 3 00 :: NEXT 0


997 DISPLAY ERA S E ALL
11300 FOR 0=1 TO 2200 :: NEXT 0
11310 CALL DELSPRITE(#2)
102 0 FOR 0 = 1 TO 10013 :: NEXT D
1£1 3 0 GOSUB 2500
1!2140 CALL CLEAR
1045 CALL SPRITEC#2. 1 3 0.2. 1 7 13 . 1 2 5)
1 05@ GOSUB 4000
1055 DISPLAY AT(2. 3) :~USE OF CALL VEY TO IN !
TIATE MOTION"
1 056 FOR 0 = 1 TO 3 13 0 :: NEXT 0
1057 DISPLAY ERASE ALL
11360 FOR 0 = 1 TO 20130 :: NEXT 0
10813 GOSUB 2500
109£1 GOSUB 3 511'11'
1095 DISPL AY AT (Z . 3) ERA S E ALL: "COINe DEMO"
1096 FOR 0 = 1 TO 3 £113 :: NEXT 0

262
______• Sprites

1100 CALL COINe (#1. _ 2.15. e l l


11 1 0 CALL COINC( ~ 2 . 1. 1 25 . I . C2)
1120 PRINT C I
1 13 0 IF Cl =-1 THEN 115 0 ELSE 114 0
1140 IF C2 = - 1 THEN 1 200 ELSE 1100
1150 CALL SC REENCI1)
1160 CALL SQUND(100.262.2)
1 170 FOR 0= 1 TO 200 :: NE X T 0
11 80 CALL SCREE N (l S)
J 1 9@ GOTO 1 160
1200 CALL SC REEN(4 )
12 1 0 CALL SQUNDCI00.523.2l
1 220 FOR 0 = 1 TO 200 :: NEX T D
123 0 CALL SCREEN( 15)
1240 GOTO 1100
1250 STOP
2500 D I SPLAY BEEP
2510 CALL KEY ( 0 . ~. S)
2520 I F 5=0 THE N 2510
253 0 IF K=81 THEN 25 40 ELSE 2510
2 540 RETURN
3000 CALL SCREE N llS)
30 1 0 CALL S PRITE t #1 .96 . 7. 95. 7S)
3020 CALL SP RITEC * 2. 1 3 0 . 2 . 1 70 . 1 25'
3030 CA L L MAGNIFY( 3 )
3 1.1.1413 RETUR N
3 500 CAL L S PRITE( # i .96 . 7.95 . 75.50 . - 5@)
3510 CALL MOTIONC # 2 . - 5.0)
3 52121 RETUR N
3530 S TOP
4000 DISPLAY AT( 3 , 3) :NPRESS SPACE BAR TO S TA
RT MOT I ON OF SPACESHIP SPRI TE N
4005 FOR D= 1 TO 200 :: NEXT D
4006 D I SP L AY ERASE ALL
4 0 10 CAL L KE Y (0 ,K , S)
4020 IF 5= 0 THEN 4010
4 03 0 I F K=32 THEN 4040 E L SE 4 0 1 0
404 0 CA LL MOT I ON ( . 2. - 5 .0 )
40 50 RE TURN

- 263
Sprite Editor
- , . ; ; , - - - Larry Long

Here's Q way to get maximum use of sprites on the TI -


99J4A-alld Q program that generates listings for your
sprite creations. Requires Extended BASIC.

A very powerful yet often unused feature of the TI-99j4A is


its ability to display and control sprites. With the 99J4A and
the Extended BASIC Module, it's possible to generate 28
sprites for display and independent simultaneous movement.
Program 1 should convince any doubters that this can be
done. Although a lot of colored letters floating around the
screen are a bit pointless, if we can modify and control the
sprites, we will have a most useful feature.
Sprites can be designed by drawing on a piece of graph
paper and then converting the on/off pixels to a hexadecimal
number. If the two largest sizes of sprites are used, the hexa-
decimal number describing the shape of the sprite would be
64 characters long (for a more extensive discussion on sprite
creation see" A Beginner's Guide to Sprites" elsewhere in this
book). A solution is a sprite editor that will allow us to draw
the pattern we want on the screen and then have the com-
puter create the program we need to make that sprite pattern.
Program 2 will do exactly that, and more. It will allow us to
edit the sprite pattern. Then, when we press the L key, it will
display a complete listing that would, if copied on paper and
then entered into the computer, provide a sprite and the nec-
essary routine to control its movement.
Your Options
When you run the program, the first display screen will be a
design grid with a box-shaped cursor. The area under the
cursor will initially be white (signifying an off pixel). Press 1
to change the color beneath the cursor to black (representing
an on pixel) or to move the cursor about the grid using the ar-
row keys. To tum off a particular pixel, press a and the back-
ground color will be returned to white. When you have
completed your design, press the P key to see it displayed as a
sprite.
264
_ _ _ _ _ _ Sprites

At this point, you are given several options. You can mag-
nify your newly constructed sprite (M key), change its color (C
key), change its background color (6 key), or set it in motion
(E, 5, D, X keys). If you are not pleased with the sprite's
shape, you can modify it by striking the T key or (if the
changes required are quite drastic) simply press the A key to
start with a fresh grid. On the other hand, if you are satisfied
with your sprite and its color and directional parameters, press
the L key to create th e BASIC statements needed to achieve
these effects.
If using the sprite editor is your on ly concern, then skip
the Test of this article and go straight to Program 2 and enjoy
this easy access to sprites.

How the Editor Works


To understand what makes the editor work, let's take a gen-
eral overview of the program:

Lines
100-260 Set up screen display.
270- 460 The main loop of the designing portion of the program.
470-680 Evaluate the design, put its values in an array, read the
values in the array, convert them to hexadecimal num-
bers, and then build a 64-character string to describe the
sprite pattern.
690-770 Put the sprite on the screen and display new program
instructions.
780-930 Main loop of the implementation portion of the program.
940-980 Change size of sprite.
1000-1150 Display a listing ofithe sprite program.
1160-1220 Change the color of the sprite and screen.

A cursor is needed to indicate where you are located on


the design grid. I chose to use a sprite (line 220) because I
could move it around freely without disturbing the display un-
der it. Repositioning the cursor is accomplished in line 380
with a CALL LOCATE. The arrow keys reposition the cursor,
and the ENTER key changes the area under the cursor.
-- What makes "Sprite Editor" so valuable is its abili ty to
generate the hexadecimal pattern for the sprite. The loop from
line 500 through line 560 determines the character in each
position of the design grid and stores that val ue in the array
B (R,C). Line 570 provides a string with all of the possible
265
Sprites _ _ _ _ __

hexadecimal digits placed in ascending order. Line 580 sets


M$ to null. The loop from line 590 to line 630 evaluates the
array elements and converts each row in the left half of the
design grid to a pair of hexadecimal digits and concatenates
them to M$. Line 620 is probably the most significant line in
this loop, as it provides the hexadecimal numbers. It causes
the computer to look at a particular digit (element) in HEX$
determined by the values calculated for HIGH and WW. Lines
630-680 perform the same operation as 590-630, only for the
right half of the design grid.
Line 690 assigns the hexadecimal numbers to ASCII
characters 104, IDS, 106, and 107. It is necessary to specify
only the first character number in the CALL CHAR statement.
When this feature is used, it is required that you start with a
character that is evenly divisible by 4. Line 730 actually dis-
plays the sprite.
Lines 740-770 provide instructions for the implementa-
tion portion of the program. Lines 780-830 check for specific
key presses and provide appropriate branching to list the pro-
gram; end the program; start from the beginning; change the
background color; modify the existing sprite; change sprite
size; or change sprite color. Lines 840-920 check for arrow key
presses and then increment or decrement sprite speed.
Lines 940-980 change sprite size. Lines 1000-1150 dis-
playa program listing that would generate a sprite like the
one designed by the Sprite Editor. One problem with listing
the program is displaying the quote character. The computer
interprets it to mean that you want to end the PRINT state-
ment. The solution is to redefine an unused character (I chose
the lowercase 11) to look like the quote character.
Finally, lines 1160- 1220 allow you to change the color of
the sprite and screen.

Procram 1. Sprite Generati~n

10 0 CALL MA GNIF Y (2' :: FOR X=1 TO 28 :: CALL


SPR ITE ( # X.64+X.x/2 . Q6 . 1 28 . IN T(RND * 100'-5
0 ,INTCRND*1 0 0 '-50) :: NEX T X : : GOTO 100

Program 2. Sprite Editor

100 REM S PRITE EDITOR


110 DIM BCI6. 16):: SC-8

266
_ _ _ _ _ _ Sprites

1 3. C I '"'7
14 . CALL CHAR lle0 ," ")
1 5. CALL CHAR(10 1, MFFFFFFFFF FFFFF FF " )
1 •• CALL CHAR( 10 2 , "FFFFC 3 C3C3C3F FFF")
1 7. CALL COLOR(9 . 2 . 16 )
lB. CALL CLEAR
1'. DISPLAY ATCI. Ie': "SPRITE EDITOR N
2 •• FOR R=l TO 1 6 :: CALL HCHAR C4+R.2. l ee, 16
) : : NE XT R
2 1. CALL MAGNIFY(t )
2 12 IF K- 84 THEN GOTO 2 1 7
215 CALL SCREE N ( S)
217 CALL DELSPRtTECALL)
22. CALL SPR IT E ltt28, 10 2 , 14 ,32,8)
225 C AL L H C HAR( 2 1.1, 32,3 1) : : C ALL HCHAR(22 , 1
,3 2,3 1 )
23. DISPLAY AT(22,Z':"E = UP X- DOWN S-LEFT D= R
IGH T"
24. DISPLAY ATC2 3 . 2) :"PRE S S 1 - PIXEL ON ,121
- OFF"
25. DISPLAY AT(24.2) : "PRESS P TO D1 SPLAY S PR
ITE"
2 •• R "' l : : C= l
2.5 KHAR - t0 0
27. CALL KEYeS . K,S)
27 1 IF S=0 THEN 27.
272 IF K:: 4 8 TH EN K HAR = 10 0
27 4 IF 1<= 49 THEN KHAR= 101
2B.
2 ••
IF K::83 TH EN C=C- l ·
IF K:68 THEN C""C+ l · . GOTO 320
.
GOT a 32 121

3 •• IF K-69 THEN R=R - l · . GOTO 32121


31.
3 12
IF 1<= 88 THEN R= R"l
IF 1< .. 80 THEN 4 7.
·.
GOTO 32.

32. IF C( 1 THEN C::: 16


33. IF C ) 16 THEN C= l
3 4. I F R< 1 THE N RE 1 &
35. I F R ) 16 THEN R= l
38. CALL LOCATE( tt 28. (StR)+25.Sa:C+l)
4 2. CALL HCHA R( 4+R, l+C,I< HAR )
4 3. CALL SO UND< 2I21,2 00, 5)

- 4 ••
4 7.
4B.
GO TO 270
CALL DELSPRITE(ALL)
CALL HCHAR( 2 1 , 1, 32, 128)
4'. DISPLA Y AT(22 , 2): "PLEASE WAIT WHI LE I TH
IN K ."
5 •• FOR R=l TO 16
51. FOR C= I TO 1 &
52. CALL GCHAR(4+R,1+C,GC)
5 3 . GC "' GC - 100
5 4 . B(R, C )=GC

267
Sprites ______

550 NE XT C
560 NEXT R
570 HEX$ = "012 3 456 7 89ABCOEF"
580 M$ =" "
59 13 FOR R= I TO 1 6
600 LOW=B(R,S)*B+BCR,6'.4 +B (R!7l t 2 +B CR , Bl+ l
610 HIGH = BCR, 1)t 8+BCR . 2) t4 +B(R,3)t2+S(R.4)+1
629 M$ = MS&SE GS(HEX~. HIGH. l '&SE GSCHEX$,LDW . 1)
63 9 NEXT R
649 FOR R= l TO 16
65£1 LOW=B(R, 1 3 ) * 8+BCR, 14 ) t4 + B(R, IS ) t 2+ B CR, 16
) +1
66£1 HIGH=B(R,9) t 8+BCR,I@)t4+BCR,11)'2+BCR.12
) + 1
6 70 M$ = HS& 5EG S (HEX$. HIGH. 1 ) t.SEG $ (HEX $, LO W, 1 )
68£1 NEXT R
699 CALL CHAR(104,MS )
790 CALL MAGNIF V(3)
7 10 MM "'3
720 M= 4
730 CALL SPRITE< # 1.104. C l. 50 .1 70 .0. 0)
7 40 DI S PLAV AT C2 1. 2) : "C COLOR M MAGNI FV T
EDIT"
750 DISPLAY AT C22 . 2l :"A ERASE Q QUIT B SAC
KG RD"
760 DISPLAY ATC23,2): " E- UP X-DO WN S- LEFT O=R
IGHT "
770 DISPLAY AT( 24 .8 ) : "L L I S T S PROGRAM"
780 CALL KE Y< 0.K,S)
790 IF K=76 THE N GOTO 100 0
B00 IF K=8 1 THEN GOTO 99 0
B 10 IF K=65 THEN GOTO I ••
B12 IF K=66 THEN GOSUB t 20111
815 I F K=84 THEN GO TO 21.
B2. IF K=77 THEN GOTO 0 4 .
B3. IF K=67 THEN GO T O 1 160
B4. IF K=83 THEN H=H - 2
B5. I F K"'68 THEN H=H+2
B•• IF K:69 THEN V= V- 2
B7. IF V=88 THEN V=\.' + 2
BB. IF V > t 2 0 THEN V= 1 2 0
9 0. I F V< - 120 TH E N V=- 1 2 13
0 •• IF H ) 1 2 0 THEN H= 12f11
0 1. IF H < - 12~ THEN H=- 120
920 CA LL MOTIONUtl. V.H l
930 GOTO 7B.

...
04.
OS.
97111
CALL MA GN IFY CM)
MM = M
IF M=3 THEN M= 4 E L S E N =:',
FOR 0 =1 TO 2~ :: NE XT 0

268
_ _ _ _ _ _ Sprites

9813 GOTD 780


990 STOP
10013 REM PROGRAM LISTER
11305 CALL SCREEN(B)
1 010 CALL CHAR(lt0."002.:j24" )
102l!1 CAL L CLEAR
1030 PRI NT "(b S PA CES~PROGRAM LI S TING"
1035 CALL DELSPRITE(ALL)
1040 PRINT
1050 PRINT " ) 100 CALL C H AR(104.n" : .. FOR !'>j~ I
TO 64 . . PRINr SEG$ i M$ .W. I l : .. NEXT W
_. PR I N T "n)"
1 055 PRINT " l I 05 CALL SCREENt ": S C : " )
11060 PRINT " ~ 1 1 0 CALL MA GNIF 't t" : MM : " )"
1 070 PRINT " ' 1 20 CALL SPRITE(~ I . \ 0 4. " ; CI
50. 150 . " : V: ". " : 1-. : " I ..
PRINT .. )- I "";el CALL YEY(0 .~. S) "
1£180
1090 PRINT " )- 1 41') IF ,
=68 THEN H=H-+-2"
1 1130 PRINT .. )- 15L;j IF K=83 THEN H=H~2"
1 1 1 13 PRINT " ) 16121 IF 1<=88 THEN V = V+~"
11 2@ PR IN r .. } 1 713 II' /< =6<;> TH EN v=v - ~"
11 3 0 PRINT " ': 1 B !!I CALL fl OT ION (11 t. V . H)"
114 0 PRINT " 'J 1 9121 Goro J 3111"
1 IS@ PRINT .. PRI NT ; : PRINT . . PRTI\IT . . PRI
NT
1155 DISPLAY AT(2 1. 3) : "A - ERASE{ 3 SPACES ] O
- QUIT"
115 6 CALL VEY(0 . ¥ . ST): : IF ST = 0 THEN 1156
1157 IF Y=Bl THEN GOTO q90
1158 IF K=65 THEN GOTD 1 00
1 15 9 GOTO 1 156
1160 C I =C l+l .. IF C l ) 16 THEN C l =2
11 70 CALL COLORC .I ,Cl;
1 180 CALL ~:EY(l1l.K . S): : I F s ,HEN 118 ~ E LSE 7
BO
1 21110 REM SCREE N COLOR CH ANGE
12 1 0 SC=SC+ l .. IF SC= 1 7 THEN SC=2
1 220 CA LL SCREEN(SC)
12 30 CA L L KEyeO.K.SI . . IF 5 THE N 1230 ELSE
RE TURN

269
Runway 180
Using Sprites in Extended
BASIC
- - - - - - James Dunn

The efficient, remarkable sprite·JrolldIillg ability of Extended


BASIC is clearly evide"l ill til is game. The author discusses
creating sprites and explores sprite manipulation. There are
several valuable pointers here for those interested ill graph-
ics, animation, or game programming.
One of the biggest problems in designing an arcade-type game
in BASIC is that BASIC can move only one character at a
time, usually slowly and not very smoothly. Ideally, we need
the ability to move an object independently of the operation
of the main program. Once set in motion , the object would
continue in motion until acted upon by a new command from
the main program. Sprites accomplish this.
Although a sprite is a type of subprogram that runs
concurrently with a main program, the main program first
must create the sprite, define its shape, and set it in motion. A
sprite then continues its motion without requiring continuous
control from the main program, except that the main program
may at any time test the sprite for position, change the color
or pattern, delete, or change its motion (see" A Beginner's
Guide to Sprites" and "Sprite Editor" in this chapter).
Included in TI~99 / 4A Extended BASIC are 11 commands
to control sprites: CALL COLOR, CALL CHAR, CALL
SPRITE, CALL PATTERN, CALL MAGN IFY, CALL MOTION,
CALL POSITION, CALL LOCATE, CALL DISTANCE, CALL
CDINC, and CALL DELSPRITE. To illustrate the use of these
commands, we'll look at an airplane landing game, " Runway
180." Try some examples for yourself to get a feel for sprite
programming.

Creating Sprites
Certain considerations must he taken into account before
spri tes are created. If a special graphics character is to be used
for the sprite, the character must be created by use of CALL
270
_ _ _ _ _ _ Sprites

CHAR. For example, in the game there are three special


characters defined for the aircraft. One is with the wheels up
(lines 430-460), one is with the wheels down (lines 510-540),
and one is debris after a crash (lines 550-580).
To create a special character, it's necessary to redefine an
existing standard character. The standard characters corre-
spond to the numbers 32 through 127 (part of what's called
the ASCII number code). The new pattern is created by using
CALL CHAR and is referenced by its ASCII number.
Before we choose which ASCII number to use, we must
examine some other factors. CALL MAGNIFY can enlarge a
sprite to one of four magnification factors. Factor four is used
in the game (line 630). This enlarges the sprites to double~size
pixels and uses a block of four sequential characters. The
ASCII number used to define the sprite must be evenly divis~
ible by four and represents the upper-left character in the
block of four. The next three ASCII numbers represent the
10wer~ left, upper~right , and lower~right characters respectively
in the block of four.
The sprite may be colored independently of the other
characters in the same character set. In addition, the sprite
with the lower sprite number (this is a different number from
the ASCII number) will pass in front of (that is, over) the
higher numbered sprite. Since the aircraft should pass in front
of the tower, it should have a lower sprite number for each of
its three configurations (line 610).
To set up a list of sprites, first number the lines on a sheet
of paper from 32 to 143. Then beside each number, write
what set it belongs to (set 1 to 14). Since you may want to use
letters or numbers in a screen display at the same time, mark
out ASCII numbers 48 through 57 and 65 through 90. The
remaining ASCII numbers can be used to define special
characters for graphics and sprites.
ror sprites, using CALL MAGNIF'Y(4), select four sequen~
tial numbers starting at one of the numbers divisible by four.
Now you are ready to use CALL SPRITE.
CALL CLEAR will not remove a sprite from the screen.
To completely clear the screen , you must also use CALL
DELSPRITE (line 1350).

271
Sprites ______

Sprites in Motion
Now that the sprite has been created, there are two ways of
moving it around the screen. Let's call these two methods ab-
solute and relative. The absolute method uses exact row and
column positions via the CALL LOCATE command. The rel-
ative method uses row and column motion values via the
CALL MOTION command.
The absolute method uses a loop with CALL JOYST to in-
crement row and column variables, and then a CALL W -
CATE to move the sprite one step each time the loop is
executed. This is analogous to nonsprite methods of anima-
tion. Th e drawback in using this method is that the sprite does
not move independently; the main program causes the move.
A modified form of this method is used for the stall subroutine
(line 1470) and the new approach routine (line 1380).
The relative method is similar, using a loop with CALL
JOYST to increment row and column motion variables which
are used in a CALL MOTION command. This allows the
sprites to continue moving independently of the main pro-
gram. By this method, the runway stripe is moved horizontally
only (line 680) and the aircraft vertically only (also line 680).
The sprite's shape may be changed anytime during the
program by using CALL PATTERN to substitute a different
ASCII character number and therefore a different pattern.
When the fire button is depressed (line 1130), the aircraft
landing gear comes down (line 1190). The pattern is changed
again if the aircraft crashes (line 1720).
Testing for Game Conditions
During the operation of the program, it may become necessary
to test for certain conditions. For example, we see if the air-
craft has touched down on the runway (line 690), if the tower
has reached the left side of the screen (line 700), or if the air-
craft is going off the top of the screen (line 710). CALL
CDINC is used to test for these conditions,
However, there is a problem with this method. Since the
main program tests for coincidence only when CALL COINC
is executed and since the sprite moves independently of the
main program, it is quite possible to miss an exact coincidence
when it occurs. For this reason a tolerance factor is induded in
CALL COINe. So the test is really for a range of + or - tol-
erance. If the tolerance is too large, coincidence can be re-

272
_ _ _ _ _ _ Sprites

turned too early. If the tolerance is too small, coincidence can


be missed altogether. How large the toleran ce should be de-
pends upon two things: the speed of the sprite and the speed
of the loop which is testing for coincidence.
The test for the tower reaching the left side of the screen
is in both the main loop (line 700) and the stall loop (line
1480). The tolerance in the sta ll loop is much smaller because
the execution speed is so fast and the sprite moves so slowly
that coincidence is actually read twice before the sprite leaves
the tolerance range. Trial and error is the only way to find out
how large the tolerance should be.
However, a fter programming this game, it's obvious that
very fast -moving sprites will require tolerance ranges that will
make arcade-style, fast-action games nearly impossible in Ex-
tended BASIC. The problem is that the coincidence test is ex-
ecuted from the main program. If it were part of the sprite
subprogram instead, it would be possible to keep the tolerance
very small.
CALL POSITION and CA LL DISTANCE both suffer from
the same problem as CALL COINC. By the time a position or
distance can be computed and returned to the main program,
the sprite has moved elsewhere. But it's possible to stop the
sprite by using a CALL MOTION before us ing CALL PO-
SITION or CALL DISTANCE (line 1330), then to restart what-
ever motion is required.
Despite a few shortcomings, the sprite capabilities in Ex-
tended BAS IC are remarkable. For true arcade-type play, ma-
chin e language is still necessary, but Extended BASIC sprites
will carry the programmer a lot closer to this goal.
Runway 180

13~ CALL CLE AR :: CALL SC REEN (5) :: CALL COLO


R ( 1. 1 6, 1 , 2, 16, 1 • 3 . I 6 . t . 4 • 1 6 , 1 . S. 16. t • 6 . 1
6 . 1.7,16,1,8 , 16.1)
14~ DISPLAY AT (10 . 91 :U S ING "RUNWA Y 180"
150 FOR B=0 TO 30 ST EP 2 :: CA LL SOUND( - 1 0 . 1
1 0 , 3 0 , I 1~. 30,2S 00, 3 0, -8 .B):: CALL SOU NO (
- HZ', IHZI, 30 .11 0 , 3 0.4000 . 30 . -8 , B ) :: NEXT B
1 60 CALL CLEAR:: DISPLAY AT(1~.9) : US IN G " PR
ES S" :: DISPLAY AT( 12.9 ) :U S IN G " I - F OR TN
STRUCTION S"
1 79 DISPLAY AT(14 , 14' : US IN G " OR " : : DISPLAY
AT(16.9) : U51 NG " G-FOR GAME"

273
Sprites ______•

180 CALL KEY<0,K.S):: IF 5 <) 1 THEN 190


190 IF K: 1 03 THEN 330
200 IF K:105 THEN 220
210 PRINT "ALP HA LOCK MUST BE OFF" :: PRI NT
:: PRINT "TR Y AGA I N" :: FO R DELAY-! TO 6
00 :: NEXT DELAV : : GOT O 160
22 0 CALL CLEAR :: PR IN T "YOU ARe PILOTING A
J ET" :: PRINT:: PR I NT "ATRCRAFT IoJHT CH H
AS BEEN" :: PRINT:: PRINT "C L EARED TO
LAND ON":
230 PRINT "RUNWAY 180." : : PRI NT:: PRINT : :
GOSUB 3 10
240 CALL CLEAR :: PR IN T "U SE YOUR J OYST IC ¥ T
o CO NTROL" :: PRIN T :: PRINT " S IN K RATE
AND AIRSPEED . " :
243 PRINT "JOYSTICK CONTROL - " :: PRINT
2 45 PRINT "LEFT: ACCELERATE" :: PRINT " R IGHT
: BRAKE" :: PRINT "UP : DECREASE S IN K RAT
E"
2 4 7 PRINT "DOWN: IN CREA SE S IN K RATE" :: PRIN
T
25 0 PRINT " FIREBUTTON CO NTROL S LAN D IN G" :: P
RINT :: PRINT "GEAR . " :: PR INT :: PRINT
:: GO S u e 3 10 :: CALL CLEAR
260 PRINT "TO RECOVER FR OM A ST ALL" : : PR INT
:: PRINT "INCREASE AIRSPEED ABO VE 60 ."
: : PR IN T : : PRINT "IF YOU CAN NOT S T OP BE
FORE" :
270 PR INT "TOWER REACHES LEFT S ID E OF" :: P R
INT : : PRINT " SCREE N. INCREASE AIR SPEED "
:: PR INT
280 PR INT "TO 60 AND LI FT OFF FOR" :: PRINT
:: PR INT "ANOTHER PASS ." : : PR INT :: PR
INT :: GO S UB 3 1 0 :: CALL CL EAR
290 PR INT "YOU MAY HAVE FOUR PA SSES " :: PRIN
T :: PRINT " AT THE RUNWAy .. . . . " :: PR INT
:: PRINT "BEWARE OF THE WIND S HI FTS'" :
; PRINT:: PRINT
3 00 PRINT " GOOD LUCK! ~ ~!" . . PRINT .. PRIN T
;: PRI NT;; PRINT : ; GOSUB 3 10 GO TO
33 .
3 1 0 PRINT; ; DISPLAY AT( 2 4 . 1) : USING "HIT ANY
KEY TO CONTINUE"
32 0 CALL KEY(I1I,R8.S8) ;: IF S8 <) 1 THEN 320 EL
S E RETURN
339 At-1
3 49 REM INITI ALI ZE
3 50 A= 0 :: B--75 :: LG - 0 :: CAL L SCREEN( 2)
360 CALL CLEAR :: CALL C HAR (33 ~"FFFFFFFFFFFF
FFFF") ;: CALL COLOR(1.8,1)

274
_______ Sprites

37 0 LC = 0 :: FOR 1 = 1 TO 16 :: CALL HCHAR(Z , l.


33~32): : NEXT Z
3 80 CALL CHAR(42.·FFFFFFFFFFFFFFFF~) :: CALL
COLOR(2 .1 3, l )
39 0 FOR 1 - 17 TO 20 :: CALL HCHAR(Z, 1,42, 32 ' :
: N EXT Z
41110 RANDOMIZE
410 REM DEF CHAR
4 2 0 CA LL CHAR(96,"00000000FFFFFFFFFFFF FF FF00
00000000000000FFFFFFFFFFFFFF F F'"
4 30 CALL CHAR(120 . "0030181C3FtF0700")
440 CALL CHAR(121."000000")
450 CALL CHARI 122, "00000000FCFFB000" I
4 60 CA L L CHAR( 1 23. "00000000")
4 70 CALL CHAR(104 . "00000000071FlSIF"'
4 80 CALL C HAR(105, "0 203 0 302 0 3030203 ")
49 0 CAL L C HAR(106, "00008 080E0F8A8 F8 " )
500 CAL L CHAR(10 7,·C0 4 0C0C0 4 0C0C0C0 " 1
510 CALL CHARIJ 2 4, "0030181C3FIF07050000" )
520 CALL CHAR(126,"00000000FCFF8S840 0 00" )
530 CALL CHAR( 1 25 . "00000000 " )
540 CALL CHAR(127."00000000")
550 CALL C I~ARCI 2B,"0000000002 t F3900")
560 CALL CHAR(129, " 000000000E56E 30 0" )
570 CALL CHAR( 1 30, " 00000000")
580 CAL L CHAR( 1 3 1 ,"00000000")
590 REH DRAW DISPLAV
600 CALL SPRITE' tt1. <76 . 2 .1 80 , 1.0,9) : : CALL CO
LORCttI,16)
6 1 0 CALL SPRITECtt2 .1 20,2. 1 0 . 2 4 S,A.0) :: CALL
COLORCtt2,7)
620 CALL SP RITEctt 3 , 104 . 2 . 110 , 250,O, - 2)
630 CALL MA GN IFV(4)
640 FOR C5 = 1 TO 4 0 :: CALL LOCATE(M2. 10.C5':
: NEX T CS :: GOSUB 870
650 REM MA IN LOOP
660 GOSUB 1120 :: GOSua 890
670 IF J = 0 THEN 690
6 8 0 CALL M OT ION C ttl. 0.B , M 2 . ~ , 0)
690 CALL CO IN CC tt 2 , 1 7e, 40 ,9 . T)
700 CALL CO !~ :;:{ " 3, tI 0, 1 ,4,DA)
7UI CAL L CQ IN CC M2 . 240.40 . 9 . E); : I F E; - 1 THEN
A; l :: GOSUB 890 :: GOTO 680
720 IF DAz - l TH EN 1 3 2 0
730 IF T <>- I THEN 660
7 40 CALL HOTIONC. 2,e.0 )
75 0 IF A ) l TH E N GOSUB 9 2 0 .. GOSUB 960 GO
TO 16 60
760 IF LG=0 THEN 1 660
770 GOTO 1 760

275
Sprites _ _ _ _ __

780 REM UPDATE DISPLAY


790 IMAGE SI NK RATE: .~~
800 IMAGE RUNWAY ENDS ••• YDS
810 IMAG E AIRSPEED: ~ ••
820 IMAGE TOUCH ~OWN
830 IMAGE SINK RATE TOO HIGH
940 IMAGE AIRSPEED TOO HIGH
8S0 IMAGE CRASH LANDING
860 IMAGE STALL WARNING !
8717.1 DISPLAY AT(I . I!2I)SIZE(2@l : USING "ATTEMPT
NO. #":Al
8813 RETURN
8913 DI SPLAY AT(3. 10 1SIZE(20) :U SING 790 : A
9017.1 DI SPLAY ATCS, 10)SIZE(20):USING 910 : - 9
910 RETURN
9217.1 DISPLAY AT(7,5)SIZE(2@):USJNG 830
9317.1 RETURN
9417.1 DISPLAY AT(7,5)SIZE(2@'9EEP:USING 8417.1
950 DISPLAY AT(9,S,SIZE<20):USING ··BOUNCE"
: RETURN
9617.1 DISPLAY AT(9,5)SIZE(20);U51NG 8517.1
970 RETURN
9817.1 CALL HCHAR(7.5 . 3 3 . 271:: DISP L AY AT(9 .S )S
IZE(2@):UsING 920
990 RETURN
117.100 DIsPI AY AT(9 . 5)SIZE( 2 01 :USJNG " WARNIN G

117.110
DISPLAY ATCII.S'SIZE(201 : USING 800:RE
10 20RETURN
10 317.1
CAL L HCHAR(7,S,33 , 27);: RETURN
10417.1
CALL HCHAR(9 . 5 . 33 . 27): : RETURN
105£1CALL HCHAR(II.S,33 . 27) :: RETURN
1060 DISPLAY AT{9.5)SIZE(201 ; USING "LIFT OFF
" : : CALL HCHAR(I 1,5,33,27) : : RETURN
1070 DISPLAY AT(3. 117.1) : USING ·· END OF RUNWAY"
:: DISPLAY ATCS. 10):UsING "NEW APPROAC
H" : : DISPLAY ATC7, 10) :USING ""NECESSARY

117.1 80 RETURN
117.19 0 PRINT "T HAT'S 5 PASSES AT TH E" :: PRINT
:: PRINT "RUNWAY. TURN IN YOUFf" ;: PRI
NT :: PPINT "PILOT LICENSE AND PUT '·:
1100 PRINT "SO ME ONE ELSE IN THE" :: PRIN T::
PRINT "COCVPIT'· :: PRINT ;: RETURN
1110 DISPLAY ATC7,9'BEEP SIZE(217.1) : USING 860
:: RETURN
1120 REM JOYST/ LANDING GEAR
1130 CALL KEY(I,RV . ST): : IF RV:19 AND LG=0 T
HEN 11917.1

276
______• Sprites

1 140 CA LL JOVST ( 1. Y .Y ) : : IF X"'0 AND Y=0 T HEN


GOSUB 1 2 10 :: RETUR N
11 S0 A= A- Y/ 4 :: 8 = B+X / 4
11 60 IF ABSIA) ' 12 7 TH E N A= 1 27 * SG N CA )
11 7 0 IF B ) -5 0 T HEN 14 3 0
1180 J = l ~ ~ RETURN
1190 CALL PATTERN<.2,124)
1200 A E A+ 3 :: 8;8+20 :: L6"'1 :: GOTO 1160
1210 REM COMPLICATIONS
12 20 CP=INTCRNO *16 )
1 230 IF CP= 1 THEN 8 "" 8 - 1 :: GOTO 1 3 00
1240 IF CP-6 THEN 8 - 8+1 :: GOTO 1 30 0
1250 IF CP=10 THEN A= A- l .. GOTO 1280
1 260 IF CP-15 THEN A= A+l :: GOTO 1280
1 270 J = 0 :: RETURN
1280 IF ABSCA»1 27 THEN A=127*SGNCAI
1 290 GOTO 1 310
1 3 00 IF 8 <- 127 THEN 8 =- 127
1 3 10 J3 1 :: RETURN
1 32 0 REM NEW APPROACH
1 33 0 CALL HOlION e .Z.e,e):: CALL POSJTION(.2~
R4.C4)
1 3 40 IF Al > 4 THEN 1400
1 350 CA LL DELSPRITE(Ml,M 3) :: CALL CLEAR
1 360 Gosue 10 7 13
1 370 CALL PATTERNC.2, 120)
1380 FOR X=C4 TO 255 :: CALL LOCATEC. 2 , INTCR
4),X):: R4:::R4 - CR4/C2SS-C4» :: NEXT X
1390 Al=Al+l :: BOTO 340
1400 CALL DELSPRITECALL):: CALL C LEAR
1410 BOSue 1090
14 2 0 FOR DELAV:1 TO 900 :: NEXT DELAV .• BOT
o 1970
1430 REM STALL
1440 Bosue 1110
14 5 0 CALL MOTION C.2,0,0)
14b0 CALL POSITIONC. 2,S R,SC )
1470 CALL LOCATEC. 2 ,SR,SC)
1480 CALL COINCC.2,170,40,2,T)
1490 CALL COINCC-tl3,lU!I,1,2,OE):: IF DE "'- 1 TH
EN Al=Al+l :: Bosue 870 :: IF AJ ) 4 THEN
1400
1500 IF T =- l THEN 1bb0
1510 SR=S R+4
1520 CALL KEVC1,RV ,S T)
15 3 0 IF RV=18 AND LG=l THEN Ib10
1540 CALL JOV S TC1 ,X .V):: IF X= f} AND V- 0 THEN
14 70
1550 8 = 8+X / 4
ISb0 REM

- 277
Sprites _ _ _ _ __

1570 IF 9 ( -60 THEN 1640


1580 CALL MOTION(.1.0 . B)
1590 GOSUB 890
1600 GOTO 14 70
1610 CA LL PATTERN! * 2. 1 2 0)
1 620 A:A - 3 ;; 8=8-22 :: L6 =0
1630 GOTO 1560
1640 GOSUB 10 30
1650 RETURN
1 66tiJ REM CRASH
16 70 CALL MOTIONC*1,tiJ , 0,.2,tiJ ,tiJ. M3,tiJ,0, *4 . tiJ,0
)
1680 CALL S OUND(1000. -7 ,0)
1 69tiJ FOR P=1 TO 10
1 7 00 CAL L SCREE N( 2 )
1710 CALL SC REEN(16);: NEXT P :: CALL SCREE N
( 2)
17 2 9 CALL PA TT ERNC . 2 ,128)
1 73tiJ FOR DELAY - l TO 400 :: NEXT DELAY
1 7 40 CALL DEL SPR ITE CA LL)
1 759 GOTO 197 0
1 760 REM TOUCHDOWN / 8RA KE/T ~G
1 779 GOSU B 989 :: IF 8 <- 53 THEN 1940
1780 CALL JOY ST Cl .X.Y): : B=8+X/2
179 tiJ IF B )- I THEN 1 880
1800 CALL MOTIQNI* I ,9 .B )
181 0 CALL COINC( . 3 . 110 , 1.4 ,D A)
1820 IF DA=- I THEN RE = 0 :: GOSU8 1010 .. GOT
o 166 0
18 3 0 CALL DISTA NCEI * 3. IIB.l,RQ >
1 840 RE=INT(SQR(RQ» :: GOSUB 1090 :: GOS UB 9
00
1850 CA LL KEVI 1.R v . ST) :: IF RV = 18 AND B< -6 0
THEN GOSUB 1060 :: A= A-2 :: GOT a 1870
18 69 GOTO 1780
1 870 CALL MOTIONI . 2. A.0 ) :: FOR DELAY = 1 TO 2 0
o :: NEX T DELAY:: GOTO 650
1880 REM SCOR ING
1890 CALL MOTJON ( Ml . 0,e,*2,0.0.M 3 ,0 ,0 .*4, 0 ,0
)
1895 FOR DELAY - I TO 80121 :: NEXT DELAY
190 0 CALL DELSPRITE(ALL):: CALL CLEAR
1910 PRINT "CONGRATULATIONS ~" :
1929 PRI NT "YOUR SCO RE I S :" ;IRE/All '1 0 :
1930 GOTO 1 990
1 940 A: A- 2 :: CALL MOTION(*2,A.0): : GO S US 9 4
o
1950 FOR DELA Y:: 1 TO 20 :: NEXT DELAY
1960 A~A+2 :: GOsue 10 3 0 :: GOSU9 104 0 • • GO
TO 65 0

278
_ _ _ _ _ _ Sprites

1 970 REM PLAY AGAIN


19B0 CALL CLEAR
1990 PRINT "PLAY AGAIN (Y I N) ? "
20 00 CAL L KEY( 2 .RV, SV)
20 1 0 IF SV:0 THE N 2000
2020 IF RV=15 THEN 2 05 0
2 0 30 I F RV=lB THEN 33.
2£1 4 0 GOTO 1990
2050 END

279
--'
7
TI Disk DeIeter
- - - - - - Patrick Parrish

Now yo u can catalog alld delete fil es on your TI-99 j 4A disks


from BASIC. And you call print the catalog. RUlls in Co"sole
or Extended BASIC.

Although the TI-99j 4A has a DELETE command in its BASIC,


its disk operating system (~OS) lacks a cataloging command .
To overcome this limitation, TI provides the Disk Manager
Command Module with its disk systems. Both delete and cat-
alog options are available with this ROM cartridge.
Unfortunately, using this cartridge is not particularly
convenient. First, you must shut down your system, insert the
cartridge, and then power the system back up again. Even
then, a number of keystrokes may still be required to execute
the delete and catalog options. For instance, if you're unsure
of the names of the files you wish to delete, you must se-
quence through all the files on your disk from within the de-
lete option. Alternately, you can run the catalog option,
carefully record the names of files for deletion, and then re-
turn to the delete option. Either way, this is a slow and labori-
ous process.
If you happen to be programming in Extended BASIC,
this is an additional annoyance. Replacement of the Extended
BASIC Module with the Disk Manager Command Module is
not only a time-consuming interruption, but it also puts a lot
of wear and tear on the motherboard cartridge connection.
Eventually, you may even begin to experience shorting prob-
lems at this interface.
It's possible to delete a file and catalog the disk entirely
from BASIC. First, you can delete a file with DELETE
" DSKI.FlLENAME" . Then, you can catalog the disk with a
BASIC program provided in the TI Disk Memory System
manual.
But this approach is also somewhat tedious. Again, if you
are unsure of the names of the files you wish to delete, you
must first run the cataloging program and carefully record
each filename.

283
Utilities _ _ _ _ __

Of course, you can combine these two methods. For in-


stance, you can DELETE from BASIC and then catalog the
disk with the Disk Manager cartridge or vice versa. But again,
there is little, if any, advantage in this.
An Easler Way
Structured much like TJ 's BASIC ca talog program, "TI Disk
DeJeter" combines the delete and catalog functions in a single
program that runs in Console or Extended BASIC.
When run , the program immediately prompts you for the
number of the drive you wish to access. If you have only a
single drive, this drive is usuall y referenced as Dri ve 1. Enter
the appropriate number and the drive will begin to whir as the
directory is read .
Once the directory has been read, the disk name, the
amount of disk space used (in sectors where 1 sector = 256
bytes), the amount of free disk space (also in sectors), and the
page number (filenames may occupy as many as four screens)
are printed at the top of the screen. Then, a series of filenames
are printed in a two-column format. Protected files, or files
which cannot be erased or written over, will appear with an
asterisk before their names.
Next, a menu with several handy options is given at the
bottom of the screen. The six options in this menu-Advance,
Back, Kill, Print, Catalog, and Quit-are ca lled by typing their
first letters.
The Options
At this time, a pointer (an arrow-shaped character) will be po-
sitioned next to the first filename on your screen. This pointer
is used to indicate which file will be purged when you execute
the Kill function. Move this pointer to any other filename with
the arrow keys (E, 5, 0, and X). When the pointer is next to
the file you wish to delete, press K.
After you press K, you' ll be asked " Are you sure?" Press
Y (for yes) to delete the file. The filename will disappear from
the screen once the file has been deleted. Press N (for no) to
abort the deletion and return to the menu. If the file is pro-
tected, you cannot delete it without first changing its sta tus to
unprotected with the Disk Manager Command Module.
The Advance and Back options are used to move forward
and backward through pages of filenames. If you happen to be

284
_ _ _ _ _ _ Utilities

on the last page of ftlenames and press A for Advance, nothing


will happen. Likewise, if you are on the first page of filenames
and press B for Back, nothing happens.
The last three options are very straightforward. Print
sends a list of the remaining files on the disk (original catalog
minu s deleted mes) to the printer-you 'll have to adjust line
390 to suit your printer. The filename, the size of each file (in
sectors), th e file type (see below), and its status (protected files
are indicated with a P) are given. The Catalog option catalogs
any disk in the drive. So, you can clean up all your disks at
one time without rerunning the program. The last option,
Quit, simply ends the program.
File Types and Program Description
Up to 127 filenames and information on each file are read in
from disk in line 700. Filenames are read in as A$(I). Each file
type is represented as E(I). The five file types are defined in
lines 100-150 as X$(I).
The first four file types are used to store data in records.
Data in these files is stored either in binary (INTernal) or
ASCII format (DiSplay). Also, each record in these files is
either FIXed or VARiable in length.
If the va lue of E(I) is negative, the file is protected. (Only
with the Disk Manager Command Module can the protect sta~
tus be removed.) Next, the length of each file (in sectors) is
read as F(I). And finall y, G(I) is the record length of files used
for data storage.
TI Disk Deleter Program Structure
Lin es
100-190 DiMension and initialize variables
210-240 Subroutine to PRINT at any screen position
250-380 Subroutine to INPUT and PRINT general disk
in formation
390-470 OPEN printer file, define cha racter and set color codes
490-550 Clear out prior filenames
680-730 Routine to INPUT directory information
840-1180 PRINT each page of filenames
1190-1710 Main loop
1210-1450 Pointer movement
1460-1590 Scroll screen
1630- 1650 Routine to catalog
1670-1690 Quit program

285
Utilities ______•

1720- 2040 Routine to DELETE file


2050-2240 Printer routine

Disk Deleter
1~0 DIM A$CI27) .EC 1 27)~FC I 27).G( t 27) .H$(127)
,PAGE(4)
I1G X$(l)="DIS/FIX"
129 X$(2)="DIS/VAR N
130 X$(3)="JNT/FIX"
140 X$(4)="INT/VAR"
159 X$(5) = "PROGRAM"
16121 PAGECl)=1
17121 PAGE(2) =3 7
189 PAGE(3)=7 3
19121 PAGE(4' =11219
290 GOTO 390
210 FOR T=I TO LENCR$)
220 CALL HCHAR (PROW, PCOL+T . AS C (SEG$ ( R$. T, I) )
)
239 NEXT T
240 RETURN
250 OPEN #l: "DSK"&STR$CM)&N.". INPUT ,RELAT IV
E,INTERNAL
26121 INPUT #1 : B$ . C . C.A
279 IF 0=0 THEN 38G
280 PROW=I
290 R$=STR$(C - A)
399 CALL HCHARCP ROW . 2 1, 32 . 3)
319 PCOL=23-LENCR$)
32 0 GOSUB 210
330 R$=STRt;CA)
349 CALL HCHA R(PROW ~ 28.32 . 3)
350 PCOL =3 0 - LENCR$)
360 GOSue 210
370 0=0
380 RETURN
385 REM CHANGE THE P ARAMETERS IN L INE 390 TO
SU IT YOUR PRINTER (SE E YOUR MANUAL)
390 OPEN # 2 : "RS2 32 .8A =9 6G0 . PA=N.OA=8"
400 CALL CHAR (128 ." 080C0EFFFF0E0C08·')
419 CALL CHARC1 36. " H )
420 CALL COLOR(14.1.1 )
439 CALL CLEAR
440 CALL SCREEN(9)
450 FOR 1=9 TO 1 2
460 CALL COLORCI, 2 . 1)
470 NEXT 1
480 IF FL=0 THEN 56121

286
_ _ _ _ _ _ Utilities

499 PRINT " . . . CLEARIN G OL D FIL E NAME S "


590 FOR 1= 1 TO 127
SI C A~ ( I )- " "
520 NEXT I
530 FL = 0
54121 CALL CLEAR
5 5 0 GOTO 57121
569 PRINT TABCb);"TI DISK DELETER";

57 0 HI=2
580 PRINT DRIVE NUMBER { 1 - 3 { ,} ? ";
590 CALL KEY(0,K,S)
600 IF (S :: 0)+«K < 49)+(K } Sl»THEN 590
619 M=K - 48
620 CALL CLEAR
639 CALL SCREEN(1S)
640 FOR 1=9 TO 1 2
650 CALL COLOR<I,16, 1)
66" NEXT I
679 GOSUS 250
680 PRINT TAB(3';" . . . READING OIRECTORY"
690 FOR 1 = 1 TO 127
700 INPUT .J:AS(II,E(I) . F(I).G(I)
71121 IF LEN(AS(I» <> 0 THEN 7 3 9
729 1=127
730 NEXT I
740 SC = l
759 LAST = 20
769 1=1
770 ROW = 3
7 80 COL:: 3
79121 CALL CLEAR
800 CALL 5CREEN«SC+IJt2+1)
819 PRINT "DSK:";BSjTA8(16J;"U;";TA8(21 - LEN(
STRS(C - A»);C-A;TAB(23J;"F:";TA8(2B - LEN(
STRS (A) ) ) ; A
82121 PRINT TAB(21);"PAGE .";SC;
8 3 121 IF A5 = 1 THEN 85121
84121 IF (LEN (AS (I) )=0) + «(1= 3 7) + (1=73) + CI=U,9)
)THEN 95121
850 AS=12I
860 PRINT TAB(1);CHRS(136};
870 IF E(I»=12I THEN 89121
880 PRINT "* ";
890 PRINT TAB(3);AS(J);TAB(lS);CHRS(136);
900 IF E(I+l»=12I THEN 92121
91121 PRINT "*";
9 2 121 PRINT TAB(17);A$(I+l)
93121 1 = 1+2
940 GOTO 840

287
Utilities _ _ _ _ __

950 HI _ INT(tl -2 I r::, c+ lJ


960 ON HI GOTO 970,990.10 1 0, 1 030
970 OIFF"37 - I
980 GOT O 10 4 0
991<1 O I FF=73 -1
110 13111 BOTO 1104@
10 10 0IFF=112'9- I
1029 GOTO 1 0 4 0
1930 0IFF = 14 5-I
10 40 Hl z Hl+ 1
1050 U= lNT ( OtFF /2)
1 060 LA ST=20 - U
1 9712' FOR 0=1 TO U
1121813 PRINT
t i1t9i1t NEXT 0
11 £10 PR INT
tll~ PRlNT "Adv a n c e {S SP ACES}Ba ck{7 SPACES1Y
1I 1"
1120 PRINT "Prlnt{6 SPACES)Catalog
{5 SP ACES}QUlt"
11 30 PR INT " (USE ARRO W KEYS TO MOVEI to :
114 0 000=0
11 50 I F LE N ( A~(I - I » <> 0 THEN 11 80
11 60 CALL HCHARC 2+( I - CCSC - I ) t 3bl - 1 1/2 . 1 7 . 3 2)
1170000=1
1180 CALL HCHARCRD W. COI . 128 1
1190 CALL KEYC0 . ~ .5)
1299 IF 5= 12' TH E N 1 190
1 2 19 IF K(> 69 THEN 1 290
1 220 OLORO W=RO W
1 230 ROW=RO W-l
1 2 49 CALL GCHARtRO W. COL.Q J
1 25 0 I F Q= 13 6 TH E N 1 2 70
1260 ROW = LA S T- (OOO = 1 ) .C COL= 17)
1 279 CAL L HCHAR COLORO W. COL . 1 36)
1 280 GOTO 1700
1 290 IF tK <> 6B) t ,, '<> B3)THEN ! 3 80
1300 OL DCO L =COL
1 3 10 CO L"20 - COL
1 320 CALL GCHAR CRO W, COL.Q )
1 339 IF 0=136 THEN 1 369
13 4 9 COL=2 0 - COL
1 350 GOTO 1190
1 360 CALL HCHA R CROW . OLD COL . 136)
1 370 GOTO 1 700
1 3 80 I F K(> 88 THEN 14 612'
1 390 QLOROW = RQW
1400 ROW = ROW+1
141 0 CALL BCHAR(ROW.CO I ,O J
1 4 20 IF Q= 1 36 THEN 1449

288 -.
_ _ _ _ _ _ Utilities

14 30 ROW:::3
1440 CALL HCHAR fOLDRO W. COL. 136)
145121 GOTO 1 700
1460 IF K<) bS THEN 1520
1470 A5 - 1
1480 SC=SC+l
1490 IF (SC < :HI) ~ (LEN(A~( I » 0) T HEN 770
15 0 0 SC""SC- l
1510 GOTO 119 ("
15 20 IF K <~ 6b T HEN 1 600
15 3121 A S- !
1540 SC=SC- l
1550 IF SC=0 THEN 158 0
1'5 60 I = F'A GE< 5Cl
1 570 GOTO 77 0
1580 SC=- J
1 590 GOTO 119 111
1 61210 I F K=75 THEN 1 720
1610 I F ~=8' TH E N 2050

.1 6 313 CLOSE
164121 FL = l
.1
1 6 2 121 I F K() 67 THEN 1 660

165£1 GOTO 4 30
166 0 IF ~ :<) B l THEN 1 190
1 6713 CLOSE III
1 680 CLOSE 11 2
169 0 STOP
1 70121 CALL HCH ARCR QW. COL. 128)
1 710 GOTO 1 190
1~20 J=(SC- l ) . 36 ~ «RO W -2) * 2- 1 )-(COL= 1 7)
1 7 313 IF E (J ) <=0 TH EN 1 1913
1 740 C .. .. ""
1750 FOR T-2 TO 1 1
1760 CAL L GCHAR(ROW.COL+T . Z)
1 770 IF (Z >32)+(T (> 2'THEN 18 1 0
1 7801=11
1 79 0 FL::J
1 800 GOTO 185121
181 0 IF Z <>3 2 THEN 1840
18 20 T = 11
18 30 GOTO 1850
18411'1 C$ =C .&CHR${ Z)
1 8511'1 NEXT T
18611'1 IF FL -0 THEN 1 890
18 70 FL=e
18Se GOTD !!g e
18 911'1 PROW "2 1
1900 PCOL =5
19111'1 R$ "' "ARE YOU SURE (Y IN )?"
19 211'1 GOSUB 2 19

269
Utilities ______

1930 CALL KEY(0,K . 5)


19 40 IF 5=13 THEN 1930
1950 IF eK <> 78) te K<> S9)THEN 1 93 0
1960 CALL HCHAR( 2 1 , 5,32,20 )
1970
1990
19 90
IF K<) S9 THEN 1190
0 =1
DELETE " DSKH &STR$(M'&" . " , C$
-
2000 CLO SE ttl
2010 GOSUB 250
2020 CALL HCHAR (RO W,COL+2.3 2 , 10)
20313 A$eJ)=" "
2040 GOTD 11 90
2050 PRINT tt 2:"DSK";STR~ ( M):TAB(8):"DlSK NAME
":B$:"FREE = " :A:" { 8 SPACES}USED= " : C
-A
2060 PRINT tt 2 :" FILENAME SIZE { 4 SPACE S }TYPE
( 4 SPACES}ST" : " ---------- ---- --------
-- -- "
2070 FOR J=1 TO 1 2 7
2080 IF A$(J) =" " THEN 221313
21390 IF LEN CA$(J) ) () 0 THEN 2120
2 1130 J=127
2 1113 GOTO 220111
2 12 0 PRINT tt 2 :A$ (J):TABe 1 2);F(J);TAB(19) : X$(
ABSCE(JJ)J:
2 1 30 IF ABS(E(J) )=5 THEN 2 1 60
2140 W$ =" "&STR$(GeJ»
2150 PRINT " 2 : SEG$(W$.LEN(W$) - 2, 3 ) :
2 1 60 IF EeJ) ( 0 THEN 2190
2170 PRINT " 2
2 180 GOTO 22130
2190 PRINT tt2:TAB(28 ) : "P"
2200 NEXT J
2210 FOR J=l TO 5
222121 PRINT " 2
223111 NEXT J
224121 GO TO 119121

2~ -
Master Disk
Directory
Raymond 1. Herold

This menu-driven utility lets you update, list, search, delete,


sort, and print a directory of the files 011 your disks. It also
displays the 1Iumber and length of files, Qlld the remaining
free sectors per disk. Extellded BASIC, disk drive, and 32K
memory expansion are required.
"Master Disk Directory," for the TI-99/4A, requires the
following system configuration: PeripheraJ Expansion box, Ex-
tended BASIC command module, disk conrroller card, at least
one disk drive, and 32K memory board. For those who have
this system, this program provides an easy way to keep track
of the various disks and the programs and files you have
stored on them. Anyone who has a library of 20 or more disks
and a hundred or more programs knows the headache involved
in trying to keep track of where a particular program is.
Master Disk Directory maintains a catalog of all your
disks and the programs and files stored on them. Thi s pro-
gram lets you display a list of all your disks, showing how
many files and how much free space is available on each. You
can also display a list of all your programs and files, indicating
how large they are and identifying the disk on which they re-
side. You can search the directory by disk number or program
name. You can also sort the directory in program name se-
quence, list the directory on a printer, delete the entries for a
particular disk, and update and save your directory, which will
hold data for up to 50 disks and 450 programs and files.

Main Menu Options


When the program is first run, the main menu listing all avail-
able functions is displayed. Figure 1 shows t he format of this
menu. Simply type in the appropriate number for the option
you choose. The program provides prompts for easier use.

291
Utilities _ _ _ _ __

Figure I. Disk Directory Menu


I-LOAD CURRENT DIRECTORY
2- ADD NEW DISKS TO D1R.
3-LlST ALL DISKS IN D1R.
4-UST ALL FILES IN D1R.
S-SEARCH D1R. BY DISK #
6-SEARCH D1R. BY FILENAME
7-DELETE DISK # FROM D1R.
S- SORT OIR. BY FILENAME
9- SAVE NEW/ UPDATED DIR.
IO- PRINT DIRECTORY SELECTION- >
I-Load current directory. This first option allows you to
load an existing disk directory into the computer's memory. It
assumes that a directory exists with the default filename
DSK1.DISKDATA which is created by the SAVE option (9).
This operation wiJI overlay any directory currently residing in
memory. To insure that a directory in memory is not in-
advertently destroyed, you will be asked to verify loading of
an exiting directory.
2-Add new disks to directory. Th is all ows you to place
in formation for new disks into the directory file. This option is
used when a directory file is initially created, or when new
disks are to be added to the directory. The program will
prompt you to indicate which dri ve is to be used to load the
disks. Once this is established, you will be instructed to insert
a disk into the assigned drive. The program will then display
the name of that disk and ask you to enter its number (1 - 50).
If you enter 00 the program will return to the menu.
You must number your disks consecutively. You must
have cataloged disks 1 to 5 before you number a disk 6. If you
are add ing to an existing directory, it is best to follow this
procedu re: From the menu, load the current directory (option
1), list all disks in directory (option 3) to find out how many
disks you have already cata loged, use this info rmation to
determine the next available disk number, then go to the
menu and select option 2.
3-List all disks in directory. This option displ ays a list
of all disks currently in the directory. The display includes the
disk number and name, number of files on the disk, and the
number of available sectors on the disk. The format of this
display is shown in Figure 2.

292
_ _ _ _ _ Utilities

Figure 2: Disks on File


SECT
# NAME FILES FREE

-- 1 WORKDlSK
2 RHSOFTWARE
3 EDITASSMWK
7
11
5
256
102
252
, ASSMDEBUG 7 9'
5 ASSMGAMES2 3 301
6 CJFMASTERI 8 158
7E/A 11 1
8 E/A'PARTB 9 5
PRESS ENTER TO CONTINUE
4-List all files in directory. This disp1ays a list of all
files (data files and programs) in the directory. For each file,
the display provides the filename, file type, file size in sectors,
and the disk number on which the file resides. If a particular
filename exists on more than one disk, it will be listed the
appropriate number of times. This can be helpful in reducing
redundancy and, consequently, increasing available storage
space. It is helpful if the filenames have first been sorted
alphabetically. Figure 3 shows a typical screen display for this
option.
Figure 3: Files in Directory
NAME TYPE SIZE DISK
ARTICLES PROGRAM 30 11
ASSMI PROGRAM 33 3
ASSMI PROGRAM 33 7
ASSM2 PROGRAM 20 3
ASSM2 PROGRAM 20 7
BACHMUSIC PROGRAM 31 2
BARCHARTS PROGRAM 31 6
BARRICADE PROGRAM 30 10
PRESS ENTER TO CONTINUE
5-Search directory by disk #. This allows you to search
the directory file by disk number. It will generate a display
similar to Figure 3. However, the list will contain only those
files on the indicated disk number. This is useful for determin-
ing which files are on a particular disk.
6-Search directory by filename. This allows you to
search the directory file for a particular filename. It will dis-
play the disk number and name on which the requested file
293
Utilities ______

resides. This is useful when you want to locate a particular file


or program, but don't remember which disk it is on. The
search routine will handle a generic argument. For example, a
search argument of ASSM will display the location of ASSMA,
-
ASSM B, ASSMSORT, and so on. This way you can find the
location of a program even if you don't remember its exact
.-
name.
7-Delete disk # from directory. This option allows you
to delete all data for a particular disk from the directory. The
program will display the disk name and ask if you are sure
you want to delete it. If you respond with Y, all information
for that disk is erased. The filenames deleted will be displayed
on the screen.
This option has two main purposes. First, it can be used
to delete information for a disk which has been erased or de-
stroyed. Second, this option in conjunction with the add op-
tion (2) can be used to easi ly update the directory periodically.
For example, if disk 5 has had files added , changed, or deleted
since the last directory update, you would do the following:
delete disk 5; invoke the add option (2) and put disk 5 into
the appropriate drive; invoke the sort routine (8). The direc-
tory would then be updated to reflect any changes to disk 5.
Of cou rse, you can update more than one disk at a time this
way. You would only need to invoke the sort routine once at
the end. Si nce deletion creates " holes" in the directory array,
a n array compression routine is automatically invoked after
the delete fu nction is complete.
S-Sort directory by filename. This option alphabetically
sorts the directory file by filename. The routine invol ves a
BASIC sort and is therefore the slowest function in the pro-
gram. Just so you don't think the machine has bogged down,
the routine will continuously display the number of sort
passes remaining. In my own tests, the program took 13 min-
utes to sort 220 records.
9-Save new/ updated directory. This will save the
newly crea ted or updated directory file on a disk . The direc-
tory will be saved with the defau lt filename:
DSK1.DISKDATA. The file may then be referenced or updated
at a later time.
IO-Print directory. This provides a hard copy list of the
directory. The print routine is set up to use a parallel printer.

294
-
_ _ _ _ _ _ Uti.lities

If you are using a serial printer or have different parameters


than mine, you will have to change the OPEN statement in
li ne 100 15.

- Master Disk Directory


1~ DIM D$(S0, . F$(400).TF$(S)
20 TF$(l)="DIS / FIX" : : TF$( 2 ) ="D I S/ VAR" _ . T
F $( 3)=" INT / FIX" : : TF$(4'="INT / VAR" : : TF
$(S) ="PROGRAM "
30 D =J2I :: F=@
1 00 CALL CLEAR : : CALL SCREE N (6)
110 CALL CHAR(96. "FFFF FFFFFF FFFFFF" )
112 CALL CHAR(112 . "E0E0FFFFFFFFFFFF" ,
113 CALL CHAR(120,"00FFFFFFFFFFFF00" l
11 5 CA LL CHAR(104, "0 107 1 F3F3F7F7FFFFF7F7F3F3
FtF070180E0FBFCFCFEFEFFFFFEFEFCF CF8 E080 "
)
120 C ALL COLOR{9.2,2)
1 3 0 FOR L = 10 TO 19
1 35 CALL HCHAR(L , 12,96.9 )
140 NE XT L
15'" CALL . SP RIT E( tll,1 04 ,6,10 0 ,11 S) : : CALL MA G
NI FV ( 3)
160 CALL HCHAR ( 1 0. 13.112.1)
17 . DISPLAY AT~3,tl);"D 1 5K " DISPLAY AT
(5 . 6):"0 I RE C TOR Y"
19 . DISPLAY AT(2 2 . 3) ; " P RE SS AN Y VEY TO BEGIN

200 CAL L K E Y~3 . K . S T);: C=C+ l IF C=20 TH E N


DISPLA Y AT( 2 4 . I) : RPTS(" " , 281
202 IF C= 4 0 TH E N C=0 :: GOTO 1 90
2~5 I F ST~0 TH E N 213 0
2 1 13 CALL DELSP R ITE {*J )
500 CALL CLE AR:: CALL SCREE N II4)
510 DISPLAY AT( I . 2l :"** DI SV DIRECTORY MENU
t, "
5 213 DISPLAY ATC4. 1): "1 - LOAD rURRE NT DIRECT
DRY"
5313 DISPLAY AT( 6 ,1):" 2 - ADO NE W 01 5 1 5 fO 0 1
R. "
540 DI S PLAY ATI8 , 1 ) : "3 - L I ST AL L DISKS IN D
I R. "
5 5 0 DI S PLAY ATII 0 . J) ; "4 - L l ST ALL F I LES IN
D I R. "
560 DISPLAY AT(1 2 . I ) : " 5 - S EA RCH orR . BY DIS
K tt "
57 0 DISP L AY AT(14. I ) : "6 - SEA RCH O I R . BY F I L
E NAME"

295
Utilities _ _ _ _ __

575 DI SPLAY AT ( 16 , 1 );"7 - DELETE D I 5K .. FRO ~


DI R. "
580 DISPLA Y AT(lB~l ) : "B - SORT D1R . B Y FJLr
NAME"
5 90 DISPLAY ATC20 , 1) :" 9 - SAVE NEW /UPDA TED 0
1R . "
6130 DISPLAY AT (2 2 . 1) : ~10 - PR INT DIRECTORY"
610 DI S PLA Y AT C24 . 4 ) : "SELECTION ----o .. : : ACC
EP T AT (2 4. 1 9)5IZEC2)VAL I DATE(NUMER! C) BEE
P:S
6 1S IF S ) 1 0 OR S 1 THEN 6113
620 ON S GOTO 100 0 , 2000 . 3000 .4 000 . 5000 . 6000 .
7000 , 8000,9000 , 1 00~0
999 GOTO 5130
1000 CALL CLEAR :: CAl I SCREEN (8)
1 0 1 0 DI S PL AY AT (4, I): "THIS OPT 101'1 WIL L LOAD
THE"
111'20 DISPLAY AT(6,1) ; " DIRECTORY FILE FROM DI
SY. • "
10313 DISP l AY ATCS . l) : "lT WILl. O'J[RLAY ANY FI
LE"
104 13 DISPLAY A l ( 10,1) : "CURf<ENTLY IN MEMORY."
10513 DISPLAY AT(14,ll : "lOAD DIRECTORY FILE (
Y I N ) ? " : : ACCEPT AT ( 14. 78 )\.'ALIDA-E (,' Y
N" )SIZEC -j )BEEP : O'ii
1 060 IF O$="N" THEN 580
1100 OPEN tt2: "DSK 1.DI S~,D4TA ·', INPUT .I NTERN !!!; L
. FIYED 20
11135 I NPUT ** 2:NO.NF
1 1 1 0 FOR 1 = 1 TO NO
1120 INPUT tt 2 :0$(L)
11 313 NEXT L
1140 FOR L=1 TO N F
1 150 I NPUT # 2 : F${L)
1160 NEXT L
1180 DISPLAY AT C2i1l- 1 J : "D IRECTORY FILE LO ADED
" :: D I SP L AY AT(22 . I) : "PRESS AN~ ~EY FO
R MENU"
1185 CLO SE # 2
119 0 CA LL KEY(3,K,S):: IF s:e THEN 11 90
11 99 GOTO 500
2@00 CALL CLEAR :: CALL SCREE N( 8)
2005 DI SPLAY AT(4, I) :"DI SKS WIL L BE PLACED I
N" :: DISPLAY ATC6, 1):" DRIV E 1, 2 OR 3':>
" :: ACCE PT AT(6,18)VALIDATE("123")SIZE
( J 1BE E P: N :: CALL CLEAR
20 1 0 DI S PLAY AT ( 4, I) :"I NSERT DISK AND PRESS
ENT ER"
20 1 5 FOR L =l TO 1 00 :: NEXT L

296
_______ Utilities

2020 CALL KEY (3 . K . 5) ; : I F K< >1 3 THEN 211'20


203121 OPEN Ml:"DS K"~STR $( N)L " . M . INPUT ,RELATI
VE . IN TERNA L
2 04 0 IN PU T #1: AS . I. J,A
205121 DISPLAV AT( 10 , 1 ):"O I SKNAME : " :A$
20MI DISPLAY AT(1 2 . 1): "ENTER DISK N UMBE R:
. . ACC E PT AT(12, 20)VALI DATE ( NUM ERI C)S
IZE( -2) 8EEP:DN
2062 IF DN=00 THEN CLOSE #1 GOTO 50~
2065 IF DN )S0 TH EN 2060
2070 IF DS (D N) - "" THEN 2100
2 08 13 D ISPLAY AT(t6,1):"OIS K NUMBER ALREADY U
SED" .. DISPLAY AT(18,1):"PRESS R TO RE
TRY" .' DISPLAY ATI 19, I ) : "PRESS M FOR M
EN U"
2085 CALL KEY(3 , K , S) : : I F 5:121 THEN 2085
2090 IF K=82 THEN CALL CL EAR . . GOTO 2050
2 11' 95 IF K=77 THEN CLOSE # 1 : : GO TO 5011:1
2097 GOTO 2085
2 1 121121 DN$=A$~(R P T$ (" ",10 -LEN(AS})1 :
$ (" ", 3-LEN(S r R$(A) 1 )~,SlR$(A)
2105 C=0
2 110 FOR L = 1 TO 1 27
2 1 20 INPUT #I: A$. 1,J,K
2 1 30 IF LEN(A$)= 0 THEN 22~~
2 140 C=C+l •• NF-NF+ l
2 1 50 N$ -A $~ RPT$ ( " " ,I @-LE N(A'$ \) . . S t. -RPTt. ("
" ~3-LE N ( S TR'& ( J ) ) I ~,STR $ ( J ' : T $ =5TR $ l ABS
(I»:: DD$-RPT$( " ",2-LEN(STR$(ON»)&ST
R$(ON)
2 1 60 F$(NF )= N$~S$ & T'&& DD$
2190 NEXT L
2200 NF$=RPT,&(" ", 3- LEN (STR$!C) »&STR $ (C)
2202 O$ (O N )=DN$&AV$~NF$
2205 CLOSE .. 1 • • NO - NO+ 1
22 1 0 DISPLAY AT (16 . 11 : "DISI<' CAT ALOGED" .. 01
SP LA Y ATlla . 1 ) : "PRESS A TO ADD ANOTHER
DISK " DISPt AV AT(19,1) : "PRESS M FOR
MENU"
2220 CA LL KEY( 3 ,K, S) :: IF 5-0 THEN ~220
2230 IF K=65 TH E N CALL CLEAR .. GOTO 20 10
2240 I F K=77 TH E N 500
2250 GO TD 2220
3000 CALL CLEAR . . CA LL SCREEN(S)
3005 X=0
30 10 GOSUB 3 100
3020 FOR L = 1 TO 50
3022 IF O$/L) -"" THEN 3040
302:5 GOSUB 3300
3030 DISPLAY ATO*2"7.I J : US ING "## M#.ij#### # M

- ...... ...... C7 SPACES~ #~#": L ~ DN$,NF~,AV$


297
Utilities _ _ _ _ __

3 ~35 X=X+ l . . IF X=8 THEN Go s ue 32 00


3~ 40 NEXT L
3 ~5~ DI S PLAY AT (2 4 . 1 1 : "PRESS ENTER FOR MENU"
3 12160 CALL KEY(3 . K . S) :: IF I' C H3 TH EN 3@~l::l
31217@ GOTO 51210
3100 DISPL AY AT !2 .4 ) :"t~ DISKS ON FILE it"~
3 11121 DISP LA Y AT ! 4. 2 41: "SECT"
3 1 20 DISPLAY AT C5 . i ) : " M NAMEr7 S PACES;FILE S
{ol SPACES}FREE"
3 125 CALL HCHAR!6 . 3 ,4 5 . 2S)
3130 RETU RN
320121 X=0
3210 DISPLAY AT(24. I ) : " PRE SS ENTER T O Ca NTIN
UE"
3220 CALL KE Y(:' .K. S) :: IF K<~ t :. TH EN :'=20
3 230 CALL CLEAR :: GOSUB 3 1 00
3 2413 RETURN
33121 0 DN$ =SEG $ (D$ (L ) . 1.10)
33 1121 A\}$=SEG $ (0$ ( l . ) . 1 1. 3)
332 0 NF$ =SE G$ (D $ (L) . 14. ::,)
333 121 RE TURN
412100 CAL L CL E AR :: CALL SCF'ECNC1S)
4 ~1 05 )(= 13
4010 GOS UB 41 00
40 20 FOR L = 1 TO N F
4022 IF F$(L)="" THFN 40q0
40 25 GOSUB 4 30'0
4030 DISPLAY AT(X . 2+7 .1 I :U S IN G " MM#~M#~M~# M
#MM### MMM {3 SPArESl ##":N$ .T F$ (ABS(VAL(
T$ » 1. S $.00$
413 35 X=X+l :: IF X=8 THEN GO SU 8 4201£1
404121 NEXT L
4050 DISPLAY AT(24. I): "P RESS EN TER FOR MENU"
4060 CALL VE~ C3. V . C) ;: I F Y () 1 3 THEN 4060
411'170 GOTO 500
410 11'1 DISP LAY AT C2 . 31 ;"** FILES TN DIR ~C T O~(Y
**"
4110 D I S PLAY AT(4. 1):" NA ME {9 SPACES} T YPE SI
ZE DISK"
4115 CAL L HCHAR(5. 3 ,45,2B)
41 2 0 RETURN
4 200 X=0
4 2 10 DI S PLAY AT(24 , J):"PRE SS ENTER TO CONTIN
UE"
4220 CALL KEYC3,K . S } :: I F K<> 13 THEN 4220
4 230 CALL CLEAR: : GOSUS 4100
4 2 40 RETURN
4300 NS=SEG$(FSCL),1,t0)
4 310 SS = SEG$ (F'S (L), J I . 3)
4320 T$ =SEG$(F$(L) , 14, 1 )

298
- -_____ Utilities

--
43 30 DO~ =S EG~(F$(L), 1 5,2)
-. 4340 RE TURN
5000 Bosue 551210
50 03 C ALL CL EAR . . CALL SCREE N (S)
5005 X-Ill
5010 GOSUf( 51£113
5 01 5 IF O$(DN) = '''' THEN DI SP LA Y AT( 1 2~1} : " **
NO S UCH DISK # IN OI R . ** " : : GO TO 5 050
50 2 0 FOR L= l TO NF
5022 I F F$(L I= " " TH EN 5040
502 3 DW$ =RP TS(" " . 2 - LEN(STR'f(DN» )LSTR ~(DN )
50 2 4 I F D W$ <> SEG$(F $ (U.15 . 2) THEN 50413
5025 Gosue 4 300
50 30 DISPLAY AT(X * 2 + 7 , l':U S ING '.~######### #
•••••• ### (3 SPACES) •• ":N$ . TF$ ( AB 5 ( VAL(
T$» ) ,5$,0 0$
5035 X- X+l . . IF X-B THEN Gosue 5200
512140 NEXT L
5050 DISPLAY AT( 2 4, I) : "PRESS ENTER F OR MENU "
5060 CALL KEYe3,K , SI :: I F K <> l3. THEN 5060
511'1713 GO T D 500
5100 DI S PLAY AT(2,3): " ' . FI L E S ON DISK .": DN
;".*"
5 110 DI S PLA Y AT(4,1 ) : " N A ME{9 SP A CES}T'( PE 5 1
ZE DIS K"
5115 CALL HCHAR( 6 . 3 ,4 5 . 2S)
5 1 2121 RETURN
521210 X=0
5210 DI SP LAY AT (2 4 ,l): " PRE SS ENT ER TO CONT IN
UE"
5220 CALL KE Y (3 . K . S) :: IF K( } 1 3 THEN 52 20
52 3121 CALL CLEAR . . GOSUS 51 00
5240 RETURN
551210 CALL CLEAR .. CALL SCREEN(6)
55 10 DISPLAY AT ( 4, l ) :" SE AR CH DIRECT ORY BY OI
SK #"
5520 DISPLAY AT(B ,l ) : " ENTER DISK # . . AC
CEP T AT( S , 14 ) VALI DATEt NUM ERIC)S I ZE ( -
2 )BEEP:DN
5530 I F DN (0 1 OR DN} 50 THE N 552121

-- 5550 RETURN
600 £1 GOSU B 65121£1
6 0121 3 CALL CLEAR CAL L SCREE N lS)
6 01215 X=12I : : 5 W=0
6 01 0 GOSUB 6100
612120 FOR L= l TO NF
612122 IF F ~( L)="" THEN 6040
61212 4 IF SE G$(PW~ .l . LEN(P W $) (~ S EG$ (F $ ( L ) .l .L
ENtPWS»TH E N 6@ 4 @

299
Utilities ______•

60313 DISPLAY AT(X'2+-7,1):USING " -II*'


(3 SPACES}~"*,*'# ••• ". *,*,""*,#"-II-II"",SEG$(
F$ ( L )! 1'5 ,2) , SE G$(DS(VAL(SEG$ (F $(L) .1'5 . 2
»)!1,10) . SEG$(F$(L) . 1! 10)
6035 X=X+-l :: 5W=J :: IF X=B THEN G05US 62121121
bl!l41O NEXT L
61345 IF S W=0 TH EN DISPLAY AT( 1 2,4): " t . NO MA
TCH FOUND .t"
605121 DISPLAY AT(24! l):"PRES S ENTER FOR MENU"
6136121 CALL KEY(3 . K.S):: IF K<> 1 3 THEN 61360
61370 GOTO 5!i:10
6100 DISPLAY AT( 2 .6 ): "SEAR CH FOR ",PW$
61113 DI SPLAY ATC5.1) : "DI SI( DISKNAME
(3 SPACES}FILENAME"
61 15 CALL HCHAR(6.3.45 . 2B)
61213 RETURN
621010 X=@
6210 DISPLAY AT(24 . I ) : "PRES S ENTER TO CONTIN
UE"
622@ CALL KEY(3 . t' .S),: IF 1<: <) 13 THEN 622121
623121 CALL CLEAR .. Bosue 610121
6240 RETURN
650121 CALL CLEAR .. CAL L SCREE N( 6)
65110 DISPLAY AT(4 . I ) : "SEARCH DIRECTORY BY FJ
lENAME"
65213 DISPLAY ATCS. I) : "ENTER FILE NAME " :: A
CCEPT ATC8, J 71S IZE CI0)BEEP:PW$
6550 RETURN
70100 CAll CLEAR :: CALL SCREEN( 10 )
7010 DISPLAY AT ( 4. t):"THIS OPTIO N WIL L DElET
E ALL" :: DISPLAY AT (6 .1): " FILES FOR A
SPECIFIED DISK"
71320 DISPLAY ATCS, !):"NUMBER . " : : DJ~PLAY AT
(10 . 1):"DELETE DISK? YIN _" :: 0$="" .•
ACCEPT A1'-("113. 18') VAL IDATE , "YN ") 51 ZE (-1)
BEEP:OS
71213121 IF O$ =" N" THEN 500
7121513 DI SPLAY AT(12, 1):"DISK # TO BE DELETED?
" :: DEl=f21 :: ACCEPT AT(12,23)VALIDA
TE(NUMER I C)SIZE( -2) BEEP:OEL
712155 IF DEL~lOf2I T HEN 51210 -_
712157 I F DEL ) 50 THEN 713513
712159 IF D$(OEL) () ·" THEN 711210
712161!1 D I SP LA Y AT(16,1) : "*' NO SUCH DISK '* IN
OIR." :: DISPLAY AT (18 ,1)! "R TO RETRY -
M FOR MENU"
7137121 CALL KEY(3 , K , S) :: IF S=12I THEN 71217121
71218121 IF K=82 THEN CALL HCHAR ( 1 6. 1 • 32 . 32) :: C
ALL HCHAR(1B . 1,32,32):: GOTO 712150

300
______• Utilities

7085 IF K=77 THEN 72010


7 10 910 GOTO 710710
711010 CALL CL EAR :: DISPLAY AT C2 ,1 ) :" DISK T O
DE L ETE: "&SEG$(O $ ( OEL) , l. 110 ) :: DISPLAY
AT(4,1) : "DELETE? YIN
7 1110 Ot =" " ACCEPT AT(4, 1 3)V ALIDATE("YN") S
IZE(- 2)B EEP:Ot :: IF O$ =" N" THEN 7200
7 115 IF O$ <> "Y" THEN 7 111'111'1
-- 71210 CALL CLEAR:: DISPLAY AT ( 1,4 ) :"* . FILES
DE LE TED . t "
7 1 310 L2=0 :: 0$ (DEL ) ="" .. DELSTR'fi=RPT'fi (" "
2- L E N (STR $ (DEL » )~STR 'fi (OEL) : XX=NF ::
DC=0
7 1410 FOR L = 1 TO XX
71510 IF DELSTR$=5EG$(F$(L) , 15. 2)T HEN GOS UB 7
3 121121 : : DI SP LA Y AT( 3+ I NT(DC / 2 J .PC):SEG$(
F$C L),1 ,10) : :: F$C L)='''' :: DC= DC+I . ' 0
5= 1
7 1610 NE XT L
7 1710 DI S PLA Y ATC2 4 , 1):"PRESS ANY KEY TO CONT
INUE"
7 1 75 CALL KEY (3,K , S) :: IF S=@ THEN 7 175
7 1810 CALL CL EAR: : DISPLAY AT(4, l):"DELETE A
NOTHE R DISK ? YIN __ 0$ = " " .. ACCEP T
AT ( 4 ,26) VALJD ATEC"Y N" )S I ZEC - l )BEE P:0$
71910 IF O$ = " Y" THEN 710510
721010 I F OS=i?1 T HEN 510 10
72 110 CALL CLEAR:: CALL SC REEN(4 ) :: DISP LA Y
AT ( B,4) : " AUTOMATIC CO MPRESSION " __ D I SP
LAY AT(IIO,6':"ROUTINE AC TIVA TED"
72 1 5 DI( S PLAY AT(14 . 1 ) :n --- - ) PLEA SE S TAND BY
____ n

7 2 2121 L2=0 :: XX- 0


7230 FOR L = l TO NF
72 4 10 IF F $(L '= "" THE N 72610
72510 L2=L2 +1 F$ (L2)= F$(L) :: XX=XX+ l
72610 NEXT L
7262 FOR L= NF +l TO 410 10
726 4 F$(L'= " "
7266 NEXT L
727 0 NF = XX
72 90 GOTO 5010
731010 I F DC /2= INT (DC/2)TH EN PC= l ELSE P C= 1 5
73 110 RETURN
801010 CALL CLEA R :: CALL SCREEN\6)
81010 DI S PLA Y ATC I 0,S):"SQRT IN G . _ _
81020 F$(I2I)= " .. Y= l ., HX=0
81025 5S=0 :: DI SP LA Y AT( llO,l 71 :N F - Y
810310 FOR L =Y TO NF

301
Utilities _ _ _ _ __

81214121IF F~(L) < F~(0 )T HEN F$(0) : F~(L):: HX ~ L

: SS~1
80'5121 NEXT L
8060 IF 55:::1 T HEN H F ~ =F ~ ( Y): : F ~ ( Y) = F~(HX)::

8070
8080
F~(HX )- HF$
Y_Y+ I :: F$(I2I):F$(Y)
IF Y< NF THEN 812125
-
812190 GOTO 5121 121
9121121121 CALL CLEAR :: C ALL SCRE EN ( B )
912110 DISPLAY AT(4. 1 ) :"THTS OPTION WILL WRITE
THE"
91212121 DI SPL AY AT<6.1):"DtRECTORY FIL E TO DISK
IT"
9 1213 121 DI S PLAY Al(B. 1 ) :"WILL OVERLAY ANY PREVI
DllS"
91214121 DISPLAY AT(10 . 1):»OIRECTORY FILE."
91215121 DI SP LAY AT(14~1):·WRITE PILE (YIN)?
:: ACCEPT AT(14~20)VALIDATE("YN·)5JZE(
- l )BEEP;O~
91216121 IF OS="N" THEN 5121121
91121121 OPEN . 2 :"DSK1.DI5KDATA" ,OU TPUT,INTERNAL
,F IXED 2121
911215 PRINT . 2: ND,NF
911e FOR L=1 TO ND
912121 PRINT * 2 :D S(L)
913121 NEXT L
9140 FOR L=I TO NF
915121 PRINT .2:FS(L)
9160 NEXT L
9180 DISPLAY AT(20, l):"UPDATE . COMPLETE" .. D
ISPLAY AT( 2 2, Il:"PRESS ANY KEY FOR MENU

9185 CLOSE * 2
919121 CALL KEY(3 , K.S):: IF S=12I THEN 9 19121
9199 GOTO 50121
1121121121121 CALL CLEAR :: CA LL S CREEN(6 )
11211211121 DISPLAY AT(8,1): .. PRINT IN G . . . . . "
112112115 OPEN M3 : " P I0. L F" ,O UTPUT
11211212121 GOSU8 12121 121121
11210 3121 FOR L=1 TO NF
11211214121 GOSU8 4 3121121
19959 PRINT . 3 ,U SI NG " {b SPACES} ••••••••••
{5 SPACES} ••• {S SPACE S} •••••••
{ 4 SPACES}**":N~,S$,TFS ( VAL(T$»,DD$
112112160 LC-LC+l .• IF LC=58 THEN GOS UB 11121121121
11211217121 NEXT L
112112175 CLOSE . 3
11211219121 GOTO 5121121
11121121 121 FOR X=LC TO 65 .. PRINT . 3 :" " . . NEXT
X

302
_ _ _ _ _ _ Utilities

11010 GOSUB 12000


110 20 RETURN
1 2000 PR INT # 3 :"(16 SPACES}DIRECTQRY INDEX"
1 2010 PRINT # 3 :" " :: PRINT #3:" " :: PRINT
#3:" "
- 1211'120 PRINT .3:" Co SF'ACES}FILENAME
{7 SPACES}SIZE{S SPACES}TYPE
{S SPACES}DISK"
12030 PRI NT #3:" "
12040 LC=6
1 2 050 RETURN

303
A Beginner's Guide
to Typing In
Programs
What Is a Procram7
A computer cannot perfonn any task by itself. Like a car with-
out gas, a computer has potential, but without a program, it
isn't going anywhere. The programs publish ed in this book are
written in a computer language called BASIC. BASIC is easy
to learn and is built into the TI.
BASIC Procrams
Computers can he picky. Unlike the English language, which
is fu ll of ambiguities, BASIC usually has only one right way of
stating something. Every letter, character, or number is signifi-
cant. A COrnmon mistake is substituting a letter such as 0 for
the numeral 0, a lowercase 1 for the numeral 1, or an upper-
case B for the numeral 8. Also, you must enter all punctuation
such as colons and commas just as they appear in the book.
Spacing can be important. To be safe, type in the listings ex-
actly as they appear. Enter all programs with the ALPHA
LOCK on (in the down position). Release the ALPHA LOCK
to enter lowercase text.

Braces
The exception to this typing rule is when you see the braces,
such as pO SPACES} . This special situation occurs in PRINT
statements. For example,
ENERGY{IO SPACES}MANAGEMENT
means that ten spaces should be left between the words
ENERGY and MANAGEMENT. Do nol type in the braces or
the words 10 SPACES.

306
_ _ _ _ _ Appendh

About DATA Statements


Some programs contain a section or sections of DATA state·
ments. These lines provide information needed by the pro·
gram; they are especially sensitive to errors.
If a single number in anyone DATA statement is
mistyped, your machine could lock up, or crash. The keyboard
may seem dead, and the screen may go blank. Don't panic-
no damage is done. To regain control, you have to tum off
your computer, then tum it back on. This w ill erase whatever
program was in memory, so always save a copy of your program
before you run it. If your computer crashes, you can load the
program and look for your mistake.
Sometimes a mistyped DATA statement will cause an er-
ror message when the program is Tun . The error message may
refer to the program line that READs the data. The error is still
in the DATA statements, though.
Get to Know Your Machine
You should familiarize yourself with your computer before
attempting to type in a program. Learn the statements you use
to store and retrieve programs from tape or disk. You'll want
to save a copy of your program, so that you won't have to
type it in every time you want to use it. Learn to use your ma -
chine's editing functions. How do you change a line if you
made a mistake? You can always retype the line, but you at
least need to know how to backspace. It's all explained in
your owner's manual.
A Quick Revi ew
1. Type in the program a line at a time, in order. Press ENTER
at the end of each line.
2. Check the line you've typed against the line in the book.
You can check the en tire program again if you get an error
when you run the program.
3. Make sure you 've typed all the DATA statements and CALL
CHAR statements correctly.

307
Index
algorithms 41 characters, numeric codes and 19-20
AI Khuwari:tmi 41 redefining 49-54
alphabetical/linear sean::h 44 CHA RPAT subprogram 49
animation 201-7 "Chase, The" program 165-71
,mnuily fOffl1ula 103 C HRS function 20
arcrosine 31 CLEAR key 15
arcsine 30-31 command moclules 5
arTilYS 41-42 compound savings fonnula 102
arrow keys 11 "Computer Visuals" program 55-59
ASe function 20 COS function 29
ASCII character set 23-24 data base management 109
ASCII codes 9, 43-44, 49-50, 147, 211 , DATA statement 55
266, 271 defined functions 29-33
ATN function 29 DEF statement 29-33
base 16 199 d...... 30
" Basic Bubble Sort" program 38 DIM statement 41
" Basic Shell 5ort" program 38-39 disk controller 6, 291
" Basic Sort C" program 39 disk directory 291-95
" Basic Sort D" program 39-40 disk drives 6, 283- 303
binary search 45 Disk Manager Command Module 283
" Bowling Champ" program v, 179-85 DISPLAY AT statement (Extended
bubble sort 36 BASIC) 8
budgeting 77-78 " Duck Leader" program 150-57
CALL CHAR 20, 24, 49- 54. 197, 203-7, duration (sound) 226
21 1, 247-51 , 256, 266, 270-71 editing 14-17
CALL CHARrAT 254 ERASE key 15
CALL CLEAR 202-7, 271 Extended BAS IC 8, 9, 36, 56, 84, 109,
CA LL COINe 258-60, 270. 272, 273 158,20 1, 247,264,270,283
CALL COWR 56, 204-7, 25 1, 270 fantasy, in game programming 179
CALL DELSPRITE 257. 270, 271 FCTN key 14-1 5
CALL DISTANCE 255, 270, 273 features, of TI-99/ 4A computer 3-8
CALL GCHAR 147. 152, 202-5 " Financial Interest" program 99- 108
CALL HCHAR 19. 202-3 formulae
CALL JOYST 272 annuity 103
CALL KEY 12, 19, 24, 34- 35, 152 compound savings 102
CALL LOCATE 255, 265, 270, 272 loan payment 103
CALL MAGNIFY 252-53, 270-71 mortgage payment 103
CALL MOTION 251, 256-57, 270, 272 FOR-N EXT loop 152
CALL PATTERN 256, 270, 272 " Freeway 2000" program 158- 64
CALL POSITION 253-5 4, 270, 273 function key codes 22-23
CALL SCREEN 14 games, writing 9-13, 158
CALL SOUND 3-4, 226, 240 increasing speed of 165
CALL SPRITE 9. 251-52, 270, 271 graphics 3, 55-56, 197-200
CALL VCHAR 19. 202 graphics characters, user-definable 24- 25
cassette recorder 6, 109, 111-13 INPUT statement 21, 24, 35
character set 18-25
redefining 211-16
character table 202-3

308
interest, simple and compound 99-100 SIN function 29
INT function 10, 29 sorting 36-40
joysticks 11 - 13, 147, 158, 165 "Sound Maker" program 226-37
keys, functions of 14-16 "Sound Shaper" program v, 238-39
linear search 44 speech 5, 7, 158
linked list flIe access 127 speed, game design and 165
UNPUT statement 128 spreadsheets 84- 92
LIST command 16 "Sprite Demonstration" program 260-63
loan payment formula 103 "Sprite Editor" program v, 264-69
logarithms 30 sprites 8, 9, 158, 20 1, 247-79
we function 29 collisions 258-60
" Mailing Ust" program v, 65-74 defining 249-51 , 270- 72
" Marble" program 207- 10 displaying 251-52
" Master Disk Dir«tory" program magnifying 252-53
291-303 moving 255-58, 272
mazes 150 standard deviation 76-78
mean 75-78 "Statistics" program 78-83
MERGE (Extended BASIC) 8 strings 4
" MINI-DBMS" program 109-13, 115-20 "SuperFont Load Demo" program 225
" MINI-REPT" program 109, 113-14, "SuperFont" program v, 211-25
120-26 TAN function 29
modulo 33 telecommunications 7
mortgage payment formula 103 Terminal Emulator I Command Module 7
mortgage 100-101 Terminal Emulator II Command Module 7
moving objects 11 text 3
music 3 " Thinking Harder" modification of
naming variables 4-5 " Thinking" program 173
NUM command 5, 1 "Thinking" program v, 172-78
numeric codes 19-22 TI BASIC 4
OPEN statement 61 "Tleale" program 84-98
Panasonic RQ2309A cassette recorder 6 commands 90-91
" Passing Variables" program 53 hardware Tt>quirements 84-85
pattem-identifier 49-52, 197- 200,211 , missing values 89- 90
248 " TI Disk Deleter" program 283-90
peripheral box 7 TI Extended BASIC. See Extended BASIC
pitch (sound) 226 "TI Mozart" program 240-42
pixel 201, 264 TI RS-232 interface 7-8
portability 55 " TI Word Processor" program 127- 43
printers 60-62 hardware requirements 127
PRINT USING (Extended BASIC) 8 operation 128-32
radians 30 printing 132-33
RANDOMIZE command 1- 11 TMS9918 video display processor 201
random numbers 10-11 TM5S9900 chip 201
range 76 TRACE command 5
reality, game simulation of 179 tra nsferring va riables 49- 54
" Receiving Variables" program 54 "Trap" program 147- 49
RES command 5, 16-17 unbiased random umpJe 75
RND function 10 user's reference manualS, 211
rounding 31 variable data
RS-232 interface 60--61 storing 51-52
" Runway ISO" program 270--79 recovering 52
"Searching Algorithms" program 46--48 variables 41
searching data 41 - 48 volume (sound) 226
sexagesimal numbers 32 " Worm of Berner" program v, 186--94
shell sort 37

309
COMPUTE I Books
Ask your retailer for these COMPUTEI Books or order
directly from COMPUTEI .
Call toll free (in US) 800-334-0868 (in NC 919-275-
9809) or write COMPUTE! Books. P.O. Box 5406.
Greensboro. NC 27403.

--
_ _ COMPUTEI's First Book of 11 Games
_ _ COMPUTEl's Guide to Extended BASIC
Home Applications on the TI-Q9/4A
,~. TDtoI
$12.95 _ _

$12.95 _ _
_ _ Creating Arcade Gomes on the TI-99/4A $12.95 _ _
_ _ Programmer's Reference Guide to the TI-99/4A $14.95 _ _
_ _ TI Gomes for Kids $12.95 __
_ _ J.3 Programs for the TI-9Q/4A $12.95 __
__ COMPUTE!'s Guide to TI Sound & Graphics $12.95 __
__ COMPUTErs TI Collection, Volume 1 $12.95 __
__ BASIC Programs tOf Small Computers $12.95 __
__ Computing Together: A Parents & Teachers
Guide to Computing with Young Children $12.95 _ _
_ _ Personal Telecomputing $12.95 _ _
_ _ COMPUTEI's Guide to Adventure Games $12.95 _ _
'Add $2.00 pel book 'Of ~ and tlOOdIing.
OuIside us odd 55.00 '* moil Of S2 00 SlJ'foce moil

.... _ • handling, $2.00/ book


TotOi payment
=====
All orders must be prepaid (check, charge. or money order).
All payments must be in US funds.
NC residents add 4.5% sales tax.
o Payment enclosed .
Charge 0 Visa 0 MasterCard 0 American Express
Acct. No._ _ _ _ _ _ _ _ _ _ __ Exp. Oole'_ __ _
Nome' ____________________
Add~'.~L_ _____________________________________
Cily'_ _ _ _ _ _ _ _ _ _ Siole _ __ Zip,_ __
"AIOoN 4-5 weeks for delivery.
Prices and availability sub}ect to chooge.
Current cotOiog available upon request.
If you've enjoyed the orticles in this book, you'll find
the same style and quality in every monthly issue of
COMPUTEI', Gazette for Commacore.

For Fastest Service


Call Our Toll-Free US Order Line
800-334-0868
In HC call 919-275-9809

.A••
COMPUTE!'s
P.o. Sox 5406
~~.
Greensbofo, NC 27403

My computer is:
o Commodore 64 0 VIC-20 0 Other_ _ _ _ __

o $24 One Year US Subscription


o $45 Two Year US Subscription
o $65 Three Year US Subscription
Subscnption rates outside the US:
0 $30 Canada
o $45 Air Mail Delivery
o 530 International Surface Mail
Name
Address
City State Zip
Country
Payment must be in US funds drawn on a US bank, intemotional
money order. or charge card. Your subscription will begin with the
next available issue. Please allow 4--6 weeks for delivery of first issue.
Subscription prices subject to change ot any time.
D Payment Enclosed 0 Visa
o MasterCord 0 Amencan Express

Acct. No. Expires L

The COMPUTEl's Gazette subscriber list Is mode available to caetullv screened


OfQarUotlOns WIth a prodUcT or seNlce which may be of Interest to our reodefs. If you
pretEII' not to recetve such moilings, please check this box D.
,

You might also like