FOR I=1 TO 1000
CALL HCHAR(3,4,45)
NEXT I
100 CALL HCHAR(ROW,COL,42)
An array is being filled from a DATA statement, eg FOR I=1 TO 5 READ A VAR(I)=A NEXT I DATA 23,54,8,A,5
i)WHAT each part of the program does ii)HOW it does it & iii)WHY it does it.
100 REM DEMO OF COLOUR 110 REM IN TI BASIC 120 REM 130 RANDOMIZE 140 PRINT " "::::"ONE MOMENT...":::::: 150 DIM F(100) 160 DEF RAN(A)=INT(A*RND)+1 170 M$="0" 180 FOR CHARR=32 TO 152 STEP 8 190 CALL CHAR(CHARR,M$) 200 NEXT CHARR 210 FOR SET=1 TO 16 220 CALL COLOR(SET,16,SET) 230 CALL VCHAR(1,2*SET-1,24+SET*8,48) 240 NEXT SET 250 FOR SET=1 TO 9 260 CALL HCHAR(22,2*SET,48+SET) 270 NEXT SET 280 CALL HCHAR(22,20,48) 290 FOR SET=11 TO 16 300 CALL HCHAR(22,2*SET,38+SET) 310 NEXT SET 320 FOR SET=10 TO 16 330 CALL HCHAR(22,2*SET-1,49) 340 NEXT SET 350 FOR X=1 TO 1000 360 NEXT X 370 FOR SET=3 TO 14 380 CALL HCHAR(2*SET-5,1,24+SET*8,32) 390 NEXT SET 400 FOR X=1 TO 4000 410 NEXT X 420 INPUT " ENTER TO CONTINUE":A$ 430 CALL CLEAR 440 CALL SCREEN(12) 450 FOR X=1 TO 150 460 R=RAN(24) 470 VR=RAN(32) 480 SET=RAN(16) 490 CALL HCHAR(R,VR,24+SET*8) 500 NEXT X 510 FOR X=1 TO 50 520 R=RAN(24) 530 VR=RAN(32) 540 SET=24+8*RAN(16) 550 NO=RAN(32-VR) 560 CALL HCHAR(R,VR,SET,NO) 570 CALL HCHAR(25-R,33-VR,24+8*RAN(14),NO) 580 CALL VCHAR(1+VR/2,R/1.5+1,SET,3/4*NO) 590 NEXT X 600 FOR COUNT=32 TO 152 STEP 8 610 CALL CHAR(COUNT,"88CCEEFF88CCEEFF") 620 CALL CHAR(COUNT+1,"80C0E0F0F8FCFEFF") 630 CALL CHAR(COUNT+2,"7F3F1F0F070301") 640 CALL CHAR(COUNT+3,"FF3C181818183CFF") 650 CALL CHAR(COUNT+4,"00C3E7E7E7E7C3") 660 CALL CHAR(COUNT+5,"FFFEFCF8F0E0C080") 670 CALL CHAR(COUNT+6,"000103070F1F3F7F") 680 CALL CHAR(COUNT+7,"183C7EFFFF7E3C18") 690 NEXT COUNT 700 FOR COUNT=1 TO 100 710 CALL HCHAR(RAN(24),RAN(31),RAN(129)+31) 720 NEXT COUNT 730 X=110 740 K=2^(1/50) 750 FOR COUNT=1 TO 100 760 F(COUNT)=X*K^COUNT 770 NEXT COUNT 780 FOR COUNT=1 TO 100 790 CALL SOUND(100,F(RAN(100)),1) 800 CALL COLOR(RAN(16),RAN(16),RAN(16)) 810 IF RAN(10)>3 THEN 830 820 CALL SCREEN(RAN(16)) 830 NEXT COUNT 840 FOR Z=1 TO 5 850 FOR COUNT=3 TO 30 860 CALL VCHAR(8,COUNT,RAN(129)+31,2) 870 CALL VCHAR(5,COUNT,RAN(129)+31,2) 880 CALL SOUND(-100,F(RAN(100)),1) 890 NEXT COUNT 900 FOR COUNT=30 TO 3 STEP -1 910 CALL COLOR(RAN(16),RAN(16),RAN(16)) 920 CALL VCHAR(12,COUNT,RAN(127)+32,2) 930 CALL VCHAR(15,COUNT,RAN(127)+32,2) 940 CALL SOUND(-110,F(RAN(100)),1) 950 NEXT COUNT 960 NEXT Z 970 FOR Z=1 TO 26 980 FOR X=1 TO 28 990 M$=CHR$(RAN(127)+32)&M$ 1000 NEXT X 1010 PRINT M$ 1020 M$="" 1030 CALL SOUND(-400,F(RAN(100)),1) 1040 NEXT Z 1050 FOR X=1 TO 100 1060 CALL COLOR(RAN(16),RAN(16),RAN(16)) 1070 NEXT X 1080 M$="1234567809ABCDEF" 1090 X=0 1100 FOR Z=1 TO 8 1110 FOR CT2=1 TO 16 1120 P$=P$&SEG$(M$,RAN(16),1) 1130 CALL SOUND(-100,RAN(200)+110,RAN(10)) 1140 NEXT CT2 1150 FOR CT=1 TO 8 1160 CALL CHAR(8*CT+24+X,P$) 1170 NEXT CT 1180 X=X+1 1190 P$="" 1200 NEXT Z 1220 CALL SCREEN(RAN(16)) 1230 FOR X=1 TO 100 1240 CALL HCHAR(RAN(24),RAN(32),RAN(127)+32) 1250 CALL SOUND(-50,F(RAN(100)),RAN(20)) 1260 CALL COLOR(RAN(16),RAN(16),RAN(16)) 1270 NEXT X 1280 CALL SCREEN(RAN(16)) 1290 FOR X=1 TO 100 1300 CALL COLOR(RAN(16),RAN(16),RAN(16)) 1310 CALL SOUND(-20,110+20*RAN(40),3) 1320 NEXT X 1330 CALL SCREEN(RAN(16)) 1340 M$="" 1350 FOR Z=1 TO 26 1360 FOR CT=1 TO 28 1370 M$=CHR$(RAN(127)+32)&M$ 1380 NEXT CT 1390 PRINT M$ 1400 M$="" 1410 CALL SCREEN(RAN(16)) 1420 CALL COLOR(RAN(16),RAN(16),RAN(16)) 1430 NEXT Z 1440 FOR CT2=1 TO 100 1450 CALL COLOR(RAN(16),RAN(16),RAN(16)) 1460 NEXT CT2 1470 CALL SCREEN(RAN(16)) 1480 STOP
The use of brackets after RAN in line 160:
DEF RAN(X)=...
does NOT indicate that RAN is a variable array. They inform
the computer that when the newly created FUNCtion RAN is used
in a program, a variable will be passed to the definition by means
of the brackets.
e.g. 460 R=RAN(24)
The computer replaces RAN(24) with the defined statement
using the value 24 in place of X.
The use of brackets does not always imply an array!
COLOUR DEMONSTRATION PROGRAM:
This program has been provided to give a practical
demonstration of some of the features of TI BASIC described
earlier.
The program has been written in small blocks, and each block
will be described separately.
The first section, lines 100 to 420 form the start of the
program. The first block is intended to display the colours
available, and by making them cross over each other, show the
relative contrasts.
Because some random patterns are created later, RANDOMIZE has
been used to provide different patterns each time the program is
run. The array F contains frequency values for use with CALL
SOUND later on. As it will contain 100 values, DIM is used to
instruct the computer to allocate memory to hold the values.
The DEF function is used to create a new random function,
which will provide integer (eg no fraction) numbers from 1 to
the figure used with the new function in the program: watch out
for the new function RAN(X) in the program.
M$ has been set to "0" (a string with a zero in it) for use
in defining all the characters as blanks (eg spaces) in the
following loop in lines 180 to 200. The string "0" could have
been placed in the definition function in line 190, instead of
the string variable.
NB: Although the TI99/4A distinguishes the number 0 from the
letter O on screen by squaring the O, in listings a slashed 0
usually represents the number.
Each group of eight characters is in a separate character
set, and each set may be a different colour. Lines 210 to 240
change the colour of each set: TI Basic has 16 sets, and 16
colours. The foreground colour of every set has been set to
WHITE( code 16).
Line 230 places a number of vertical stripes on the screen,
each a different colour. As the screen is 32 columns wide, the
stripes have been set to 2 columns wide each, and therefore each
CALL VCHAR uses 48 characters (2x the 24 rows).
So that we know which colours are which, they are labelled by
the routine in lines 250 to 340.
Lines 350-360 give a small delay.
It is not possible to provide 16 horizontal bands with a space
between each, as the screen only has 24 rows, but lines 370 to
390 cross the screen with as many rows as can fit.
In lines 430 to 500, random characters are placed on a blank
screen, and in lines 510 to 590, random stripes and columns are
placed on screen.
Lines 600 to 690 redefine the characters for the purposes of
the following sections of the program. Remember that the strings
used with CALL CHAR can only contain the numbers 0 to 9 and the
letters A to F.
700 to 720 again place random characters on screen.
Lines 730 to 770 fill the F array with values to be used with
subsequent CALL SOUNDs. Line 730 sets the lowest possible
frequency, and line 740 sets the basis for the tones: the
formula used creates what is known as 'microtonal' music, with
very little difference between adjacent tones.
Then, accompanied with random tones, the character colours
are varied at random in lines 780 to 830.
Lines 840 to 960 provide sound, colour changes, and small
bars of random characters.
Lines 970 to 1040 use the PRINT routine to place random
characters on screen, and the colour is varied in 1050 to 1070.
In lines 1080 to 1200, characters are given a random
definition and in 1220 to 1260, the colours are varied, random
chracters placed and tones generated.
1270 to 1310 again varies the colours, and uses a different
random tone generation method (line 1300).
The remainder of the program again uses PRINT to provide a
random display and the colours are varied.
Note in particular the usefulness of the DEF statement in this
program.
There are many 'loops', and some loops contain other loops :
see for example lines 840 to 960. These loops are 'nested', with
the COUNT loop inside the Z loop.
An ARRAY is used to store frequencies.
The loop counters (eg CHARR, SET and so on) also function as
numeric variables in the loops. Their value increases by one for
each cycle of the loop until the maximum value (set by the TO X
in FOR TO NEXT ) has been reached.
In line 1120, SEG$ is used with the string variable M$ (set in
1080) to create a random definition of a character. A letter is
chosen at random from the string variable M$, and used to create
the definition in the variable P$.
Note that P$ is reset to a 'nul' (empty) string after each
character has been defined. Then it is reused with different
letters to form a new definition.
TI BASIC GLOSSARY
A list of all the commands and functions available in TI BASIC,
with brief descriptions.
ABS(X) Used to obtain an ABSolute value - eg it ignores the + or - sign. APPEND Used to extend files when using the disk system or mini memory module. ATN(X) Provides the arctangent : this is a trigonometrical function. ATN(X) provides the angle in radians whose tangent is X. BREAK Used in a program to temporarily halt execution. A message is placed on screen. The program is continued by typing in CONTINUE BYE Used to return to the master screen. Preferable to the use of the QUIT key, as only BYE will properly close any open files, and ensure no data is lost. CALL CHAR(N,STRING$) Used to define character N by means of a hexadecimal string STRING$. CALL CLEAR Used to clear the screen. CALL COLOR(SET,FG,BG) Used to defing the foreground (FG) and background (BG) colours of each of 16 sets of characters. Sixteen colours, including transparent are available. CALL GCHAR(ROW,COL,CH) Places in the variable CH the ASCII code of the character on the screen in ROW, COLumn. CALL HCHAR(ROW,COL,CH,NO) Used to display a character CH in ROW, COLumn. When a number or variable in the position NO is used, the character is repeated horizontally NO times. CALL JOYST(NO,X,Y) Returns X and Y values for Joystick NO. CALL KEY(NO,CODE,STATUS) Interrogates the keyboard. If a key is depressed the ASCII code is placed in variable CODE. STATUS indicates if a key is pressed, and if it is the same key when two adjacent CALL KEYs detect a key pressed. NO indicates the key unit, and is used to split the keyboard and to switch the codes returned by the Function and Control keys. CALL SCREEN(NUMB) Used to change the colour of the screen. CALL SOUND(TIME,F1,V1,F2,V2,F3,V3,N,V4) Used to generate sound. Up to three tones may be used with an optional noise channel. TIME is in milliseconds and F1,F2 and F3 are the frequencies in cycles per second. CALL VCHAR(ROW,COL,CH,NO) As CALL HCHAR, but the character CH is repeated vertically NO times. CHR$(CODE) Used to make a character CODE available as a string. CLOSE Used to close a data file. CONTINUE Used to resume a program when execution has been halted with the CLEAR key or a BREAK command. COS(X) Provides the cosine of angle X, where X is in radians. DATA Used as a heading on lines containing values to be READ. DEF Used to DEFine a function of your own. DELETE Used with the disk system to DELETE a file. DIM Used to DIMension an Array. DISPLAY i. Same effect as PRINT ii.One of two file storage formats. DISPLAY uses the same codes and format as the computer uses for screen displays. EDIT One method of entering EDIT mode. END An optional marker for the end of your program. EOF 'End Of File' used with disk files. EXP(NO) The inverse of the natural logarithm function LOG. Thus X=EXP(LOG(X)) FIXED Used to define data files. The alternative, not available with cassettes, is VARIABLE. FOR...TO..(STEP) Used to establish loops which execute until the counter reaches the value following TO. GOSUB Used for a line transfer when the program is to RETURN to the line following the GOSUB line after the section transferred to is completed. GOTO Used to make a simple line transfer. IF...THEN...ELSE Used to make conditional line transfers, with an optional alternative transfer if ELSE is used. INPUT i. Used to fill a variable from the keyboard,or other device if a data file is used. ii.Used to specify a file is to be used for INPUT only. INT(NO) Used to provide the INTeger of a number NO. eg any fraction is removed. INTERNAL Used to specify the format of a data file. INTERNAL specifies the codes used by the processor internally. The alternative is DISPLAY. LEN(STRING$) Used to provide the LENgth of the string STRING$. LET Optional. LET A=2 and A=2 are both accepted. LIST Lists a program on screen or other device. LOG(NO) Provides the natural logarithm of number NO. NEW Used to clear the console memory in preparation for a new program. NUM / NUMBER Provides line numbers automatically when a program is to be keyed in. Starting number and increment may be defined. Default is to start at 100 and increase each line number by 10. OLD Used to load a program from cassette or other storage device. ON...GOSUB Used for GOSUB transfers when the value following ON determines which of the line numbers following GOSUB are to be used. ON...GOTO Similar to the above, but for simple line transfers when it is not wished to RETURN to the line following the transfer. OPEN Used to OPEN a file to a device.The format of the file is specified after the OPENcommand. OPTION BASE Used to set the minimum value of an array to zero or one. OUTPUT Used to specify a data file is to be used for output only. POS(STRING$,X$,NO) Used to obtain the first occurrence in STRING$ of X$. PRINT i. Used to display characters on the screen and to scroll the screen upwards. ii. Used to send data to an external storage device when used with files. RND Used to obtain a RaNDom number. The same sequence of numbers is generated every time a program is RUN. RANDOMIZE Used to set the initial number used by RND to be different each time a program is RUN. READ Used to place the values in DATA statements into variables. REC Used with the disk system to specify a specific RECord in the file. RELATIVE Used with the disk system for random access to data on a file by using RECord numbers. REM Used to add REMarks to programs. RES / RESEQUENCE Used to resequence a program, that is, change the line numbers. Default is to start the program at line 100 and use increments of 10, but start number and increment may be specified. RESTORE Used to reset the DATA pointer, either to the first data item, or to data on a particular line. RETURN Any line transfer by GOSUB must be terminated with RETURN. The program then transfers to the line following the GOSUB. RUN Instructs the computer to RUN the program in its memory. SAVE Used to SAVE a PROGRAM to a storage device. SEQUENTIAL Used to specify that file data is recorded in the order it is output. The alternative is RELATIVE, which is not available with cassette files. SGN(NO) Used to obtain the SiGN of the number NO. Indicates if NO is zero,negative or positive. SIN(X) Provides the SINe of the angle X where X is in radians. SQR(X) Provides the SQuare Root of the number X. STOP Used to STOP program execution. A STOPped program may only be resumed by re-RUNning it. STR$(NO) Used to change a number or numeric variable into a string. The converse is VAL. TAB Used when PRINTing to print at from a specified column. TAN(X) Provides the TANgent of angle X where X is in radians. TRACE Causes the computer to list on screen the number of each line as a program is executed. Switched off with UNTRACE. UNBREAK Used in command mode to remove BREAK commands which have been placed in command mode. UNTRACE Switches TRACE off. UPDATE Used with disk file processing to enable a file to be read or written to. VAL Used to obtain the numeric equivalent to a string. The string must be composed only of valid numbers. VARIABLE Used with disk files to indicate the file is to be as long as the item to be stored, which may vary.