Classic Computer Magazine Archive Article from Compute! magazine

PROGRAMMING THE TI

C.Regena

Drum Practice
My five children and I recently started to learn how to play the drums (yes, it gets noisy, but it's rhythmic noise). Probably the most important phase of learning to play the drums is learning rhythms-and very often other members of a band depend heavily on the drum. When we first began lessons, the younger children, who had no previous music training, started with quarter notes in 4/4 time. They soon learned to count and knew when the notes indicated a beat and when there was a rest. However, I noticed the counting was not always even.
    The CALL SOUND command in TI BASIC specifies a duration, or how long a sound plays. Therefore, we could use the computer to play a drum rhythm and keep the timing exact (to the millisecond, in fact).
    The program this month shows a drum rhythm or pattern consisting of four measures on the screen. The computer then plays the rhythm while showing the counting. The student can play the drum (or practice pad) with the computer. If you don't have a drum, you can clap along with the computer-or play another instrument with the computer beating the rhythm. Ten different patterns are shown.

How The Program Works
Line 180 sets a duration for a quarter note or quarter rest to be 300 milliseconds. You can change the tempo by changing this line. You may prefer to add some lines to let the student input a tempo or to choose among several tempos. For my youngest child, however, it was best to have no INPUTs or choices to make.
    Lines 190-220 define graphics shapes using characters numbered from 97 to 117. The character definitions are in the DATA statements in lines 230-340. When you are typing these DATA statements, be sure not to add any extra commas. Each DATA statement except the one in line 340 has four definitions. These characters will draw the staff lines, the bass clef, the time signature, bar lines, and the notes and rests.
    The program uses ten different patterns, and lines 360-380 READ the patterns from the DATA in lines 1020-1120. Feel free to change these or add your own rhythm patterns. Each DATA statement contains one pattern for the four measures. T represents a quarter note, and R represents a rest. On the screen the patterns end with a repeat bar, so the computer actually plays the pattern twice.
    After the program prints the title screen and instructions, it prompts the student to press any key to start. The ten patterns are shown in random order without repetitions. Lines 500-620 draw the basic bass staff. Lines 630-810 draw the rhythm from the pattern chosen, R$. The program examines the string R$ one character at a time in order. If the character is a T, the program draws a quarter note. If the character is an R, the program draws a rest. After four rotes or rests, the program draws a bar line to separate measures. At the end of the four measures, it draws a repeat bar.
    Line 830 plays a prompting tone, then lines 840-1000 play the rhythm (twice). Again the string R$ is examined one character at a time. If the SEGment is T, a tone plays. I chose the frequency of the noise - 7. You may want to choose a different noise or frequency instead. If so, change line 900.
    If the SEGment is R, the program uses a frequency of 9999 with a sound level of 30 to create a rest. When the note or rest starts, line 930 prints the count. Line 940 ends the sound.
    The variable J is used to print the counting and is incremented with each note or rest. Line 960 determines if J needs to be reset to count 1-2-3-4 for each measure.

Changing The Program
As listed, the program uses ten different patterns for the rhythms. If you want to change any of the patterns, simply alter the DATA statements of lines 1030-1120. Remember that T stands for a quarter note and R stands for a rest. Make sure you have 16 characters in the string. If you want more than ten patterns, you will need to DIMension P$ at the beginning of the program, then change line 360 to READ the right number of patterns, and add more DATA statements at line 1120. To play all the patterns, you will also need to change the number 10 in lines 430 and 470.
    Characters 109, 110, and 111 are the graphics characters that draw the 4/4 time signature. If you wish to change the signature, for example to 2/4, you can alter those characters or define your own graphics beyond character 117. Lines 600-620 draw the time signature.
    If you change the time signature, you will also need to adjust the DATA for the rhythms, the positions where the bar lines are drawn, and the counting.
    Another enhancement to this program would be to start adding eighth notes to the rhythms-then sixteenth notes. You would have to define some more graphics characters for the different kinds of notes, then perhaps add E and S to the DATA strings that define the patterns. You would also have to adjust the section to draw notes (lines 630-780) and the section to play the notes (lines 830-1000).
    Another idea is to use this program as a start, but instead of just playing a rhythm, have the computer choose random notes for the four measures and thus a tune. Then a student could practice reading music by playing the tune along with the computer. Each note would be drawn depending on the tone chosen-so you would need to define characters to draw the notes in all possible positions. You could use an ON-GOSUB to draw the proper note where the subroutines contain the appropriate CALL HCHAR statements. These projects should keep you busy until next month.
    If you prefer not to spend the time typing this program, you can get a copy by sending a blank cassette or disk, a stamped, self-addressed mailer, and $3 to:

C. Regena
P.O. Box 1502
Cedar City, UT 84720
Please be sure to specify the title and that you need the TI version.

A Few Answers
I appreciate your comments and ideas for columns and programs. I'll try to answer just a few questions here this month.
    First, many of you have written about the future availability of TI software. Texas Instruments announced it was dropping its home computer in October 1983. If you have sent in the registration form that came with your computer, you are on a mailing list and should receive advertisements from time to time from various companies who sell TI peripherals and software. TRITON was designated as the company to sell TI products for Texas Instruments.
    There are several third-party companies that are still producing peripherals and software for the TI. At this writing, there is still an abundance of software available and new titles coming out all the time. Many user groups are still going strong and are a good source of continuing support. Most of the groups publish newsletters. Personally, I will probably continue to write programs for the TI forever because I like the computer.
    COMPUTE! Books has published numerous books specifically for the TI-99/4A. If you don't see them in your computer store or bookstore, remember you can order directly from COMPUTE!. Several readers have written about using Forth on the TI. Texas Instruments made Forth available through the user groups. In other words, the program is considered public domain. It is available on disk. There is also a manual that was distributed to user groups. Several clubs have formed Forth special interest groups and are publishing software written in Forth and articles about Forth. I am not going to cover Forth in this column because Forth requires the disk drive system, memory expansion, and the Editor/Assembler cartridge. Most TI owners have only the basic console and a cassette recorder. I prefer to print programs that are written in Console BASIC (and maybe a few in Extended BASIC) so that any TI owner can use them.

Translating Other Programs
Some readers have asked about translating programs for other computers to work on the TI. When I first got my computer I also wondered how to translate programs, because back in 1980 very little was ever published for the TI. Now, however, there is a lot available-so you really do not need to translate. Some bookstores have a whole shelf full of TI books. I subscribe to several magazines that publish TI versions of their programs.
    If you absolutely need to translate a certain program, though, here are a few hints. The main thing is that TI BASIC allows only one command per line-so where other computers use a colon or backslash to separate commands, you need to use another line number and a separate line. An exception is the PRINT statement. By the way, Extended BASIC allows much easier translation because of its enhanced capabilities.
    Most of the commands are the same in all BASICs and work the same way-such as PRINT, INPUT, FOR-NEXT, IF-THEN, GOTO, GOSUB, ON-GOTO, ON-GOSUB, READ, DATA, and END. Therefore, you can usually figure out the basic logic of a program. You may need to make slight changes. For example, the TI INPUT statement uses a colon while many others use a semicolon. Also, our IF-THEN in Console BASIC includes an ELSE, and you must specify line numbers rather than additional commands. Simply go to a line number, then at the line number use the command.
    The biggest problems result from machinespecific coding, largely graphics and sound. Any TI statements that start with CALL are not found on other computers. For example, CALL CLEAR is equivalent to CLS in some other BASICs. All those POKEs can be confusing, too. On other machines, POKEs are often used as substitutes for missing graphics and sound commands.
    Your best bet is not to attempt to translate a program line by line, but rather design your own graphics and sounds. To translate the POKE commands on another computer, you'd really need its manual and a very good memory map to find out what the various locations do. For example, the Commodore 64 and VIC-2.0 require several POKE commands to make sounds, where TI BASIC lets you use CALL SOUND. For character graphics, a program for a Commodore computer may POKE a screen location with a symbol number, then POKE a color location with a color number. Our equivalent would be CALL COLOR and CALL HCHAR or CALL VCHAR. Some DATA statements in a Commodore program may be defining a character, but we would use CALL CHAR.
    My recommendation is that instead of trying to translate graphics directly, you should study Chapter 5 of the Beginning BASIC book that came with your TI-99/4A and learn the TI graphics. The in-house programmers at COMPUTE! rarely translate a program line by line. The translations you've seen are usually programs written completely from scratch to take advantage of each computer's strong points. Only the basic concept is carried over from the original program. Often the new version even gains something during the translation.
    Until next month-enjoy your TI.

Rhythm Player

Please refer to "COMPUTE!'s Guide To Typing In Programs" before entering this listing.

100 REM DRUM PRACTICE
110 CALL CLEAR
120 PRINT TAB(8);"DRUM PRACTICE"
130 PRINT :::"A RHYTHM PATTERN WILL
     BE"
140 PRINT :"SHOWN ON THE SCREEN."
150 PRINT :"PLAY YOUR DRUM ALONG WI
    TH"
160 PRINT :"THE COMPUTER."
170 PRINT ::"THERE ARE TEN RHYTHMS.
    ":::::
180 D=300
190 FOR C=97 TO 117
200 READ C$
210 CALL CHAR(C,C$)
220 NEXT C
230 REM DATA FOR CHARACTERS
240 DATA 000000000000FF,00000000020
    2FF02,0000FF000000FF,0202FF023A
    7E7C38
250 REM
260 DATA 10080C1830300804,1C2020100
    800FF,000000000000FF0F,00000000
    0000FFE
270 REM
280 DATA 1038FF38000OFF,311OFF08090
    8FF1,0000FF000100FF,1020FF80000
    0FF
290 REM
300 DATA 000000000000FF10,2424447E0
    404001,102424447E04FF.000000000
    000FC2C
310 REM
320 DATA 2C2CFC2CAC2CFC2C,AC2CFC2C2
    C2CFC,000000000000FF08,0808FF08
    0808FF08
330 REM
340 DATA 0808FF080808FF
350 REM
360 FOR I=0 TO 9
370 READ P$(I)
380 NEXT I
390 PRINT "PRESS ANY KEY TO START."
400 CALL KEY(0,K,S)
410 IF S<1 THEN 400
420 REM TRY TEN PATTERNS
430 FOR C=1 TO 10
440 CALL CLEAR
450 REM CHOOSE PATTERN
460 RANDOMIZE
470 R=INT(10*RND)
480 IF P$(R)="" THEN 470
490 R$=P$(R)
500 REM DRAW STAFF
510 CALL HCHAR(10,3,97,26)
520 CALL HCHAR(11,3,99,26)
530 CALL HCHAR(12,3,99,26)
540 CALL HCHAR(10,4,103)
550 CALL HCHAR(10,5,104)
560 CALL HCHAR(11,4,105)
570 CALL HCHAR(11,5,106)
580 CALL HCHAR(12,4,107)
590 CALL HCHAR(12,5,108)
600 CALL HCHAR(10,7,109)
610 CALL HCHAR(11,7,110)
620 CALL HCHAR(12,7,111)
630 REM DRAW NOTES
640 X=8
658 FOR 1=1 TO 16
660 IF SEG$(R$,I,1)="R" THEN 700
670 CALL HCHAR(10,X+1,98)
680 CALL HCHAR(11,X+1,100)
690 GOTO 730
700 CALL HCHAR(11,X+1,101)
710 CALL HCHAR(12,X+1,102)
720 IF I=16 THEN 780
730 IF I/4<>INT(I/4)THEN 780
740 X=X+1
750 CALL HCHAR(10,X+1,115)
760 CALL HCHAR(11,X+I,116)
770 CALL HCHAR(12,X+2,117)
780 NEXT I
790 CALL HCHAR(10,29,112)
800 CALL HCHAR(11,29,113)
810 CALL HCHAR(12,29,114)
820 REM PLAY RHYTHM
830 CALL SOUND(100,1497,2)
840 FOR K=1 TO 2
850 CALL HCHAR(13,8,32,20)
860 X=8
870 J=1
880 FOR I=1 TO 16
890 IF SEG$(R$,I,1)="R" THEN 920
900 CALL SOUND(D,-7,2)
910 GOTO 930
920 CALL SOUND(D,9999,30)
930 CALL HCHAR(13,X+I,J+48)
940 CALL SOUND(1,9999,30)
950 J=J+1
960 IF I/4<>INT(1/4)THEN 990
970 J=1
980 X=X+1
990 NEXT I
1000 NEXT Y,
1010 NEXT C
1020 REM DATA FOR RHYTHMS
1030 DATA TTTTTTTTTTTTTTTR
1040 DATA RTTTRTTTRTTTTTTR
1050 DATA RTRTRTRTRTRTTTTR
1060 DATA TRTRTRTRTRTRTTTR
1070 DATA TTRTTTRTTTRTTTTR
1080 DATA TRTTTRTTTRTTTTTR
1090 DATA TTTTRTTTTTTTRTTR
1100 DATA RTTTRTRTRTTTRTTR
1110 DATA TRTRRTTTRTRTRTTR
1120 DATA TTRTRTRTTTRTRTTR
1130 CALL CLEAR
1140 PRINT "CHANGE LINE 180 FOR TEM
     PO. ...
1150 END