Access Key Details
||


Book index page | Stephen's Entry page

CHAPTER TWO : TI BASIC
In this section we will look at the language in your console. There are a number of general books now available on the BASIC language, and one or two of these may help you if you experience difficulty in handling the language. Many evening classes are also available.

For greater assistance this section will follow as closely as possible the order of the manual supplied with your console (link is to 1300k pdf file at whtech.com).

Do not try to take in all the information in one reading, but go back and read it again a few times.

A computer works as a large number of switches, which are either on or off. Each 'switch' is described as a BIT. In order to pass information more quickly, the computer looks at more than one BIT at a time. The TI99/4A uses a 16 bit processor: it is able to look at 16 bits at a time. For most purposes however, the computer looks at 'words' composed of 8 bits. These words are called BYTES. A BYTE is a binary number composed of eight numbers, which may be 0 or 1. In digital representation the BYTE has a maximum value of 255 (Binary 11111111).

The computer stores its commands (reserved words) as one byte, rather than a collection of letters. It can only identify the command words if you follow the rules regarding the characters permitted in front of and following command words. In general, you may only use a space, arithmetic operator, or ENTER, but there are exceptions which you will see in the program listings in the manual and in the books of TI programs now available.

For discussion of the error tracing commands (Trace, Untrace,Break) see the section on How to use TI Basic.

LIST
The command LIST is used to list the contents of a program. Used on its own,it will list the program on the screen. You may use CLEAR (FCTN and 4) to halt the LIST. To start again at say line 400, you type in LIST 400- the hyphen indicating 'to the end', or LIST 400-600

LIST can also be used in many other ways. These are described in the section on modules and peripherals.

SAVE
Please refer to the section on cassette handling.

LET
LET is optional, but uses up one byte of memory every time you use it. It is better not to.
LET A=2 is the same as
A=2

END
END is also optional, but in this case it is good practice to use it. By adding END to your program, you may be certain when you list it in the future, that you have the complete program, and not a 'working copy'.

IF...THEN...ELSE


TI BASIC may appear to be slightly limited in its use of IF...THEN compared to some other computers. TI do however allow the ELSE alternative.
The problem arises because TI insist that you use the construction only to transfer to another line, for example:
IF X=100 THEN 200 ELSE 250
You cannot add commands such as:
IF X=B THEN B=C
to do this you need Extended Basic.

However, TI BASIC does have 'relational operators' which will often help you out of this problem. These may be found described in the section on Advanced Programming.

FOR...TO...STEP


Note that in TI Basic you must always use the variable name after NEXT . NEXT on its own is in error. In some early computers you were not allowed to transfer to another line once a FOR NEXT loop had been established, but with the TI99/4A you need not worry. You may leave a FOR NEXT loop before the loop has been completed.
Sample use:
100 FOR FREQ=110 TO 200
110 CALL SOUND(100,FREQ,0)
120 NEXT FREQ

For..to..step may also be used to provide delays:
100 FOR DELAY=1 TO 300
110 NEXT DELAY
This will take a little over a second to complete in TI Basic.

INPUT
Try to use a separate INPUT for each variable. It IS possible to input more than one variable eg by using INPUT A,B but this requires the program user to input two numbers separated by a comma.

The TI form of input, INPUT "HOW MANY?":N uses a colon separator (:), most other Basics use a semi colon (;).

VARIABLES


When you wish to refer to a number, you may use that number, or a 'label' representing the number. For instance, if we tell the computer:
A=2
Then whenever the computer comes to 'A' (without other letters, that is, with spaces or brackets on either side), it will treat it as the number 2.

'A' is a VARIABLE, and can be allocated to any number. The TI99/4A may have variable names up to fifteen letters long: you may for instance use:
HIGHSCORE=12000
A variable representing a number is a NUMERIC VARIABLE and a variable representing a letter,a word, or a group of words is called a STRING VARIABLE. A string variable always ends with the dollar sign:
MESSAGE$="YOU WIN"
Strings (as they are called) are dealt with later.

READ...DATA...RESTORE


TI Basic is slow at reading DATA lines, and if you need to use a number of READs, it is essential that you do not do it more often than absolutely necessary. It is a good idea to fill a variable array, and refer to that.(ARRAYs are dealt with at some length later in this chapter).
   eg
FOR I=1 TO 5  
READ A 
IF A=1 THEN 200 
NEXT I          
DATA 2,3,1,0,6  
if used often, could be replaced with:
 FOR I=1 to 5 
 READ B(I)
 NEXT I  
then when a check is required
 FOR I=1 TO 5  
 IF B(I)=1 THEN 200 
 NEXT I            
 DATA 2,3,1,0,6    

It is worth mentioning that DATA causes more problems in debugging a program than any other command. There must be enough DATA to fill all the READs in the program, and they must be numbers if a numeric variable is READ.

Be careful how many commas you use in your DATA lines : too many or too few can cause many hours searching for errors. The error messages you will receive may be some distance from a READ line, if you have loaded an incorrect value into a numeric variable due to missing out just one comma.

PRINT


TI Basic has a fairly slow screen scroll, but your information will appear more quickly if you use the print separators instead of a number of separate PRINT lines. You will also save memory.
 eg 
100 PRINT "PRESS"      
110 PRINT "1. TO START"    
120 PRINT "2. TO TERMINATE"
130 PRINT  
140 PRINT "H FOR HELP" 

Will appear more quickly if you use:
100 PRINT "PRESS":"1. TO STA RT":"2. TO TERMINATE"::"H FO R HELP"

TI Basic allows you to key in a program line up to 4 screen lines long, so use this facility. Notice that instead of a single PRINT to scroll one line, an extra colon has been used in our single line amendment. Each colon causes the screen to scroll once.

COLOUR AND SOUND
The TI99/4A allows you to set the screen, and the foreground and background colours of the characters, to any of fifteen colours, plus transparent. The transparent colour allows the screen colour to show behind a character.

CALL SCREEN is used to set the screen colour, and
CALL COLOR is used to set the character colours.
Note that COLOR is spelt the American way.

 
  To Try: 
 100 FOR N=1 to 8
 110 CALL HCHAR(N,1,24+N*8,32)
 120 NEXT N                   
 130 FOR N=1 TO 16            
 140 CALL SCREEN(N)           
 150 FOR DELAY=1 TO 300       
 160 NEXT DELAY               
 170 CALL COLOR(N,N,1)        
 180 NEXT N           
 190 END              
           

In BASIC, characters are referred to by standard codes referred to as ASCII CODES. The ASCII code for the capital letter A is 65 for instance.These codes may simply be referred to as CHARACTER CODES.
TI BASIC allows you to define characters with the ASCII codes 32 to 159, and for colour purposes these are divided into sixteen sets. You may define different colours for each set, but all of the characters in that set must be the same colour.

Characters are defined with CALL CHAR(CODE,STRING$),where STRING$ is a string or string variable made up of HEXADECIMAL characters (0 to 9 plus A to F).
As each character occupies a grid of 8 x 8 dots, it can be defined by splitting it down the middle to form 16 rows of 4 dots. Each possible combination of ON and OFF dots in a row of four can be defined in terms of one of the sixteen hexadecimal characters.
A character with one dot ON in the top right corner is defined as: "0100000000000000".
The definition is by row, first the left side then the right.
Each row of 4 dots can be considered a row of binary switches. The right switch is 1, the next 2, the next 4 and the leftmost switch 8. When a dot is ON, add its value to the others which are ON in the same row. You will obtain a unique number, from 0 to 15.
From this decimal number you change to a single hexadecimal digit (hexadecimal numbers have a 'base' of 16). The number 15 for instance is hexadecimal F.

You may purchase the EXTENDED BASIC module at some future date. As TI BASIC programs run faster in EXTENDED BASIC, it is worth noting that that language has only 14 character sets.
Therefore,if you use characters coded 144 to 159 in your TI BASIC programs, the programs will not run in Extended Basic.
There are several versions of the console around, and there have been slight changes in the relative shades of the colours used. If you purchase a program and the colours seem awful, it was probably written on a 99/4 or an NTSC 99/4A...you should be able to change the colours to something more suitable, and it will give you good programming exercise looking for the lines to amend.

If you wish to place a single character on the screen, use the CALL HCHAR command, it is slightly faster than CALL VCHAR.

Sound is produced with CALL SOUND(TIME,F1,V1,F2,V2,F3,V3,N,V4) where TIME is in milliseconds, F1,F2 and F3 are FREQUENCY in Hertz (cycles per second) and V1,V2 and V3 are volume (0 loudest, 30 quietist). N is a noise generator which provides some sound effects.[N & V4 WILL NOT PRODUCE TI EFFECT IN TI EMULATOR]
A CALL SOUND may use only one frequency if you wish: the second and third frequencies are optional and may be omitted. The Noise is also optional.
A CALL SOUND will occupy the computer for about 50 milliseconds, and then, even if the sound is still continuing, it will proceed with the next instruction. If it comes to another CALL SOUND, the computer will wait until the first has finished, unless the second CALL SOUND has a negative time, in which case the first CALL SOUND will immediately be terminated and the second CALL SOUND begin.

TI state that you can only have tones down to 110 Hz on your computer, but that is not quite the case:

Try:
100 INPUT A
110 IF A<37 THEN 100
120 CALL SOUND(2000,200,30,2
00,30,A*3,30,-4,0)
130 CALL SOUND(500,200,30)
140 GOTO 100                             

[THIS WILL NOT WORK IN TI EMULATOR WHICH HAS ONLY 3 VOICES]
[AT WORST USING NOISE WILL PRODUCE A RACKET]
It would appear that the console can at least appear to go well below 110Hz. Try an input of say 50 or 60. If you find the sound interesting, try changing the -4 to -8.

Keep in mind that the computer takes about 40 milliseconds to process a CALL SOUND command.It is not possible to use this command to change the TYPE of sound produced.You cannot produce a piano or harpsichord sound for instance.
=====

CALL KEY


Call Key is used to sense the use of a key on the keyboard and permits data to be entered without scrolling the screen (The INPUT command causes the screen to scroll). An ACCEPT AT routine using CALL KEY can be found later in this book.

If you wish the computer to assume the ALPHA LOCK key is down, while a program is running, you can instruct it using CALL KEY, and avoid having to request the program user to ensure the key is down.
Use CALL KEY(3,K,S) in your program, and as soon as the program passes over it (no key has to be pressed) the computer will consider the alphalock key to be down, whether it is or is not.
You resume normal operation with CALL KEY(5,K,S). These switching calls can use any variables you wish, and may be dummy calls or you may actually use them to obtain a key response.

In the appendix section you will find a list of the key codes which are available from the keyboard using the CTRL and FCTN keys.The normal keyboard, with and without using SHIFT will allow you access to characters 32 to 127 (a few of these codes do require the FCTN key).

IMPORTANT: If you use the split keyboard, CALL KEY(1.. and (2.. the value returned for keys X and M is only approximately zero, and although it prints on screen as zero will not equate with it.
Instead of using IF KEY=0 THEN, you are forced to use
IF KEY+1=1 THEN...

CALL JOYST
A program illustrating the use of this command is developed in a later section of this book.

Please note that when using the joysticks, the alphalock key must be in the up position. If alphalock is down, the computer will not be able to sense when the joystick is pushed upwards.

Using Call Key(3...) does not affect joystick operation, but you should not use CALL JOYST(3...) as this may prevent correct operation of the joystick.

ATN
ATN is a trigonometrical function which you may not need to use often, but in TI BASIC it may be used to obtain an accurate value for the mathematical constant PI:
PI=4*ATN(1)
This and the other trigonometric functions provided work in radians. You may convert radians to degrees by using ATN:
DEGREES=RADIANS*180/4*ATN(1), or more simply
DEGREES=RADIANS*45*ATN(1)

INT
INTEGER is a numeric function you will use quite often. It removes the fraction from a number, so that 2.3 for instance becomes 2. It is frequently used with the RND function, and can also be used to round decimal numbers.
For example, if B is a decimal number to 13 places, and you wish to print only the first two places, you could use:
PRINT INT(B*100)/100
If you wanted the last decimal to be 'rounded', the alternative is
PRINT INT(B*100+.5)/100

RANDOM NUMBERS


Random numbers are useful in any program which you need to follow an unpredictable path. A program to display dice would be an example.

The 99/4A generates pseudo random numbers. If you have a short program:

         100 FOR I=1 TO 10
         110 PRINT RND
         120 NEXT RND   

Every time you run the program the SAME 'random' numbers will be printed. This can sometimes be of value if you wish to be certain of the effect but still have the appearance of randomness.
You may instruct the computer to start the list of 'random' numbers somewhere else, by adding the line:
90 RANDOMIZE N where N is a numeric variable.
The value of N determines where the random numbers begin.

Merely adding 90 RANDOMIZE, without 'seeding' the function with a value, will cause the computer to start at a truly random number, and if you run the program several times, different values will be printed each time.

RND takes a value between 0 and 1, and is usually used in the format: NUMBER= INT(RND*MAXIMUM)+1
The variable NUMBER will then take any integer value from 1 to MAXIMUM, including maximum. The maximum value of RND is .99999' so INT(RND*100) gives a maximum of 99. You have to add the odd 1 to enable you to actually reach the maximum you want.

You may prefer to have at the start of your program:
DEF RAN(X)=INT(RND*X)+1
Then when you want a random number up to say 12, you may enter in your program: NUMBER=RAN(12). You have created your own random function. Also see DEF.

SQR
SQR is used to obtain the SQuaRe root of a number:
A=SQR(4)

Many computers will not equate SQR(4)=2, or fail on some other comparison, due to internal rounding of numbers. Your 99/4A will equate all ten squares up to 100. Try it on a friends computer.
(webnote: this was written in 1983)
You may not need to use this very often, but it is an indication of the numeracy of the 99/4A. Try:

100 FOR I=1 TO 100
110 A=SQR(I)      
120 IF I=A*A THEN 130 ELSE 140
130 PRINT I;"PASSED THE TEST
 CORRECTLY"
140 PRINT "NEXT VALUE OF I"           
150 NEXT I                         

NOTE that 1,2,4,9,16,25,36,49,64,81 and 100 pass the test OK. The failures are due to internal rounding, which still exists, but it is not quite so marked on the 99/4A as on other computers .
If your program needs to make a comparison such as this, use the INT function to remove any (unprinted) fraction.
In the program above for instance,there is some improvement by using INT(A*A) in line 120.
There is a bigger improvement using
110 A=INT(SQR(I))
which will remove from A any invisible fraction.

STRING EXPRESSIONS


A STRING is a non-numeric value or variable.A letter of the alphabet or a word or group of words may form a string.
NB: A NUMBER may also be a string:
2 is a number, "2" is a string.
A number (no quotation marks) must be used for mathematical operations. A string expression is therefore identified by quotation marks, or if represented by a variable, by a dollar sign after the variable name:
MESSAGE$="I WIN"


POS The POS function is rarely used on other computers, but enables you to program very concisely on your 99/4a.
In the following example,CALL KEY is used to detect whether keys A B C or D are pressed, and control is passed accordingly. First,without using POS:

      100 CALL KEY(0,K,S)
      110 IF K=65 THEN 200
      120 IF K=66 THEN 250
      130 IF K=67 THEN 300
      140 IF K=68 THEN 350
      150 GOTO 400     

In this case, the keys have adjacent ASCII codes, and it would be possible to use:

110 IF S=0 THEN 400
120 IF (K<65)+(K>68) then 400
130 ON K-64 GOTOo 200,250,300
,350
                        

omitting 140 & 150.
However, in many games you may wish to test for keys which are well spread, such as AKESDXQP. The POS function can then offer the solution. Still using ABCD:
 100 CALL KEY(0,K,S)                
 110 IF S=0 THEN 400
 120 ON POS("ABCD",CHR$(K),1)
+1 GOTO 400,200,250,300,350
 omit 130-150                       


If the key pressed is not in the string used in POS, then the expression has a value of zero, so one is added to enable us to use ON..GOTO,and the first transfer occurs if an unwanted key is pressed. In this case 'only' three lines have been saved, but if you wish to use more valid keys, you still only need to use three lines. This can be very useful in a program.

Although you may use a string up to 255 characters long, the POS function is unreliable for strings longer than 127 characters.

SEG$
SEG$ is used when you wish to print a SEGment of a string, or remove a part of a string.
TI BASIC uses only one command to segment strings, SEG$. Other computers use LEFT$, RIGHT$, and MID$, but you only really need the one.
It is used for instance in this DISPLAY AT routine taken from THE TEXAS PROGRAM BOOK.

 100 REM
 110 REM PRINT AT X,Y,M$
 120 REM ROUTINE        
 130 REM               
 140 FOR J=1 TO LEN(P$)
 150 IF Y<32 THEN 180
 160 Y=3                
 170 X=X+1              
 180 IF X<24 THEN 200
 190 X=1                
 200 CH=ASC(SEG$(P$,J,1))
 210 CALL HCHAR(X,Y,CH)  
 220 Y=Y+1               
 230 NEXT J    


(Set X and Y to the start position of your word, placed in M$. Then GOSUB this routine, and remember to add RETURN at the end to go back to the place in your program you left).

VAL
VAL is intended to make a number contained in a string available as a number, for use in mathematical operations. It changes "2" into 2, and may be used NO=VAL("2"). It is the opposite of STR$, used to change a number into a string:
A$=STR$(2)
The TI VAL function will change a string such as "2" to the numeric variable 2.
For instance: A=VAL("123")

This is of great importance when memory space is short, as a string variable representing "2" uses less memory than a numeric variable representing 2. This is explained in the section on Advanced Programming.

Please note that the TI VAL will only work if the string contains numbers only. It will not function for numeric expressions such as "2*3+8" nor if alphabetical letters are used such as "12 APPLES".

DEF


DEF is used to DEFine your own functions. TI Basic gives you great freedom in using this function- you are not restricted for instance to using a definition commencing FN as on some computers. DEF may also be used to create string functions.

Below are some examples of DEFs you may wish to use:
To print a random number from 1 to X.
At the beginning of your program type:
DEF RAN(X)=INT(RND*X+1)
Then in your program, when you wish to use such a number, you type (for example)
A=RAN(7) or
A=RAN(LEVEL)
where LEVEL is a numeric variable.
Note that although X is used in the defining statement, you may use any number or variable when you use the new function. Although the function has here been called RAN, you may use any name you wish so long as it is not a reserved word( see TI manual for list).
The DEF statement is best used at the beginning of your program.
DEF PI=4*ATN(1)
Then when you wish to use PI in your program, just use the variable PI. NB: This has the same effect if you omit the DEF function. There is no advantage in using DEF instead of a simple LET.

Further uses of DEF may be found in the Advanced Programming Section.

-It is better NOT to use a proportional font to print listings!

ARRAYS


Arrays in TI Basic may have 1 2 or 3 dimensions.
A one dimensioned array may be thought of as a tower of building blocks. Each block has written on it a value or message. To find out what the message on block 3 is, we count upwards to the third block...
In TI Basic, normally the 'bottom' block is considered to be Block 0 (zero).
A tower of blocks may have blocks up to Block Number 10 without having to tell the computer how many blocks there are, but for a larger array, the computer has to be advised to reserve memory by using the DIM statement.

If you want to use an array of 16 values, before you use any of the values you must have the line DIM NAME(16) where NAME is the numeric variable for the tower of blocks.

We can place values in the array elements as follows:

         100 DIM NAME(16)
         110 FOR N=0 TO 16
         120 NAME(N)=N*2
         130 NEXT N    

Now the variable NAME(3) has a value of 6. The variable is referred to in this way, with the 'level' after the variable name, and in brackets.

TI Basic differs from some other basics in the way it handles arrays in some important ways:
You must use a number in the DIM statement. A variable is not accepted.
Once an array has been DIMensioned, you may not alter the size of the array.
If an array variable occurs in your program before a DIM statement, the array is automatically dimensioned as 10. You cannot then use the DIM statement for that array.

Both numeric and string variables may be arrayed.

TI Basic does NOT permit you to use the same name for an arrayed variable and a simple variable. You cannot use both NAME as a variable and NAME(3) say.

Arrays reserve sections of memory, and you should not use a larger array than is needed. A numeric array will use 8 bytes for each element, regardless of the value in the element.
A string array initially occupies 2 bytes per element, but as you place strings in the elements,the space for each element will depend on the string you place in it (memory used= number of characters plus 1 byte).

If you can use string arrays instead of numeric arrays, you will usually save a great deal of memory.

A string array can be converted to a number by using the VAL function: eg A=VAL(SCORE$(2))
IF YOU DO THIS,ensure that you place the character "0" (zero) in any empty sectors to prevent possible program crashes.

As stated above, the TI 99/4A will assume the bottom sector is called Number Zero. Often you will find that having the base called Number One is quite adequate. If you do not use the 'zero' element,it is a waste of memory to have that element reserved, and TI allow you to instruct the computer to use a Base of 1.

The instruction to do this is OPTION BASE 1 (Note:The number is NOT in brackets!).

You can use the base 1 for all your arrays or none of them.Once set, you cannot reset the base, and as it is automatically set by any reference to an array before the computer finds the OPTION BASE statement, it MUST occur before any such reference.

In TI Basic therefore, FIRST: If you wish to set the base to 1, use OPTION BASE 1. Then, if your array is to have more than 10 elements, use DIM ARRAYNAME(NUMBER). Then you may use the array!

You may become more familiar with arrays by studying printed programs. (NB:Some other computers use the DIM statement to reserve memory for simple strings. This does not apply to the TI99/A.).

Two dimensional arrays are similar. It may help if you consider the first element name as a hotel floor, and the second as a hotel room. For instance: DIM NAME(FLOOR,ROOM).
Use of multidimensional arrays should be cautious, and careful consideration given to the use of OPTION BASE 1.
For example, a numeric array having dimensions (20,20) totals 21x21, or 441 elements,at 8 bytes each, that is 3.5k of memory used with just one DIM line! Use OPTION BASE 1 and the number of elements drops to 20x20=400. Times 8=3.2k, saving 300 bytes.

SUBROUTINES : GO SUB-RETURN


Whenever you use the same routine several times in a program (for instance the PRINT AT routine in THE TEXAS PROGRAM BOOK, reprinted in this chapter under SEG$), you may use GOTO and ON FLAG GOTO, but it is easier to use GOSUB to enter the routine, and when you have finished, RETURN will send you back to the program line immediately following the GOSUB with which you entered the subroutine.

Note: The computer stores the line number from which you GOSUB. This memory is only freed when you RETURN. If you GOSUB, ensure that you RETURN or you will quickly find a MEMORY FULL message appearing.

It IS possible to jump into a subroutine with GOTO provided you jump out with another GOTO, but that type of programming can lead to errors if you are not very careful, and should only be resorted to when you have absolutely no option. This should be rare.

An ideal example of this can be found in a short routine to find out how much free memory there is after you have typed a program in. Add on to the end:

         10000 A=A+8
         10010 GOSUB 10000  

Now type in RUN 10000. This little program will now run, and in due course the MEMORY FULL message will appear. Now type PRINT A, and press ENTER. The value of A is approximately equal to the memory space remaining.

(Your program may still not run even if there is a lot of space remaining: memory is still required to handle the values of the variables, the return addresses of GOSUBs and so on).

You MAY use GOSUB to enter a subroutine at any stage, you do not have to GOSUB to the beginning of a routine.

Within the limitations of memory, you MAY GOSUB from a subroutine, but keep an eye on the number of RETURNS !

The ON...GOSUB command is similar to the ON...GOTO command (which see), except that instead of a simple line transfer, the computer remembers where it has jumped from, and a RETURN will send it back to the line immediately following the ON...GOSUB. REMEMBER to watch your RETURNs.


PECULIARITIES

'PAUSES'


When a program is RUNning, from time to time your computer will appear to stop operating for a very short period. This pause is especially noticeable when using the PRINT AT routine to be found later in this book, or when using Sprites with Extended Basic.
The reason for the pause is called 'garbage collection'.

When you amend a program line by re-entering it or by using the Edit mode, there is a pause before the cursor reappears, which becomes longer the longer your program is.
During this pause the computer is deleting the previous version of the line, moving all the following lines up in memory and adding the new version of the line to the bottom of the program memory : in short, doing a great deal of work.
When a program is running, and variables are defined, the values of the variables are stored in memory. When a new value is allocated to a variable, to avoid frequent delays to your program, the computer retains the old value in its memory, even though it will use the new value.
As time progresses, the memory will become full of these old variable values. When memory becomes full, the computer discards the redundant values : this is called garbage collection. It is more efficient to only do this when memory becomes full than every time a variable is redefined, but a very small pause is caused.
These pauses will be more frequent if your program is a long one, as there will be less memory to fill up with dead variable values.



REDUNDANT CHARACTER DEFINITIONS


When you switch the console on, some characters are undefined. If you define these characters in one program, the computer will retain that definition even if you use NEW and load a new program. Only by using BYE or QUIT will the definition be erased.
Therefore never assume a character is undefined : you may run a different program first which defines that character!
Example:
Type in:
100 CALL CLEAR
110 A$="FF818181818181FF"
120 B$="0000FF0000FF0000"
130 CALL HCHAR(12,1,140,128)
140 GOSUB 210               
150 CALL CHAR(140,A$)       
160 GOSUB 200               
170 CALL VCHAR(1,12,140,120)
180 CALL CHAR(140,B$)       
190 GOSUB 210              
200 STOP                   
210 FOR T=1 TO 1000        
220 NEXT T                 
230 RETURN                 
240 END                      


RUN this program. When it ends, type in:
PRINT CHR$(140) {ENTER}
Notice that the definition is still there.
If you wish, RUN the program again and note the difference at the beginning, as the character is no longer undefined.
Now type in:
NEW  {ENTER}
and repeat: 
PRINT CHR$(140) {ENTER}   


The definition is still there. If a new program is loaded, which uses this character and assumes the character is undefined, the character will not be printed as a blank but as the character we have defined with the above short program.


This TI BASIC program simulates two puzzles

The screen is used as a memory device, with CALL GCHAR used to find out what is in a particular position, and then the information is manipulated and new characters displayed.

The program can be speeded up by using a 6x6 array to hold the information and using that instead of GCHAR. This program will work: can you make it work better?

100 REM SQUARES S SHAW 1981
4X4 IS BEST
110 RANDOMIZE
120 DEF RAN(X)=CNT(X*RND)+1
130 GOSUB 2200
140 GOSUB 2100
150 GOSUB 1340
160 GOSUB 980
170 FOR C=8 TO 6+2*V STEP 2
180 FOR C2=5 TO 2*H+3 STEP 2
190 CALL GCHAR(C2,C,C4)
200 POSR=C2
210 POSV=C
220 IF C4=32 THEN 260
230 NEXT C2
240 NEXT C
250 REM
260 IF SCR=0 THEN 300
270 SCR=SCR+1
280 IF SCR=2 THEN 360
290 RETURN
300 CALL KEY(0,A,B)
310 IF A=ASC("P")THEN 130
320 CALL HCHAR(15,22,63)
330 CALL HCHAR(15,22,32)
340 IF B<1 THEN 260
350 KEY=POS("1234567890QWERP
",CHR$(A),1)+1
360 IF (H=4)*(KEY>5)THEN 260
370 ON KEY GOTO 260,390,450,
520,690,860,890,920,950,2300
,2330,2360,2390,2420,2450,13
0,130
380 SCR=SCR+1
390 REM ^
400 IF POSR=5 THEN 260
410 CALL GCHAR(POSR-2,POSV,C3)
420 CALL HCHAR(POSR-2,POSV,32)
430 CALL HCHAR(POSR,POSV,C3)
440 GOTO 170
450 REM DOWN
460 IF POSR=15 THEN 260
470 IF (H=4)*(POSR=11)THEN 260
480 CALL GCHAR(POSR+2,POSV,C3)
490 CALL HCHAR(POSR+2,POSV,32)
500 CALL HCHAR(POSR,POSV,C3)
510 GOTO 170
520 IF H=6 THEN 580
530 IF POSV=8 THEN 260
540 CALL GCHAR(POSR,POSV-2,C3)
550 CALL HCHAR(POSR,POSV-2,32)
560 CALL HCHAR(POSR,POSV,C3)
570 GOTO 170
580 M$=""
590 C5=5
600 FOR C=8 TO 18
610 CALL GCHAR(C5,C,C2)
620 M$=M$&CHR$(C2)
630 NEXT C
640 M$=SEG$(M$,3,9)&SEG$(M$
,2,1)&SEG$(M$,1,1)
650 FOR C=8 TO 18
660 CALL HCHAR(C5,C,ASC(SEG$
(M$,C-7,1)))
670 NEXT C
680 GOTO 170
690 IF H=6 THEN 750
700 IF POSV=14 THEN 260
710 CALL GCHAR(POSR,POSV+2,C3)
720 CALL HCHAR(POSR,POSV+2,32)
730 CALL HCHAR(POSR,POSV,C3)
740 GOTO 170
750 M$=""
760 C5=5
770 FOR C=8 TO 18
780 CALL GCHAR(C5,C,C2)
790 M$=M$&CHR$(C2)
800 NEXT C
810 M$=SEG$(M$,11,1)&SEG$(M
$,2,1)&SEG$(M$,1,9)
820 FOR C=8 TO 18
830 CALL HCHAR(C5,C,ASC(SEG$
(M$,C-7,1)))
840 NEXT C
850 GOTO 170
860 C5=7
870 M$=""
880 GOTO 600
890 C5=7
900 M$=""
910 GOTO 770
920 C5=9
930 M$=""
940 GOTO 600
950 C5=9
960 M$=""
970 GOTO 770
980 T$="PRESS APPROPRIATE KE
Y TO"
990 R=17
1000 VR=3
1010 GOSUB 2260
1020 T$="MOVE BLANK SQUARE"
1030 R=18
1040 VR=3
1050 GOSUB 2260
1060 IF V<5 THEN 1110
1070 T$="OR SLIDE ROWS "
1080 R=19
1090 VR=3
1100 GOSUB 2260
1110 T$="1. UP 2. DOWN"
1120 R=20
1130 VR=3
1140 GOSUB 2260
1150 IF V>5 THEN 1210
1160 T$="3. LEFT 4. RIGHT"
1170 R=21
1180 VR=3
1190 GOSUB 2260
1200 RETURN
1210 T$="3.TOP< 4.TOP> 5.2
< 6.2>"
1220 R=21
1230 VR=3
1240 GOSUB 2260
1250 T$="7.3< 8.3> 9.4
< 0.4>"
1260 R=22
1270 VR=3
1280 GOSUB 2260
1290 T$="Q.5< W.5> E.6
< R.6>"
1300 R=23
1310 VR=3
1320 GOSUB 2260
1330 RETURN
1340 CALL CLEAR
1350 REM DRAW
1360 FOR C=7 TO 7+2*V STEP 2
1370 FOR C2=4 TO 4+2*H STEP 2
1380 CALL HCHAR(C2,C,98)
1390 NEXT C2
1400 NEXT C
1410 FOR C=8 TO 6+2*V STEP 2
1420 FOR C2=4 TO 4+2*H STEP 2
1430 CALL HCHAR(C2,C,96)
1440 NEXT C2
1450 NEXT C
1460 FOR C=7 TO 7+2*V STEP 2
1470 FOR C2=5 TO 3+2*H STEP 2
1480 CALL HCHAR(C2,C,97)
1490 NEXT C2
1500 NEXT C
1510 IF V<5 THEN 1740
1520 FOR C=8 TO 18 STEP 2
1530 FOR C2=5 TO 15 STEP 2
1540 CALL HCHAR(C2,C,45+C/2)
1550 NEXT C2
1560 NEXT C
1570 CALL HCHAR(11,14,32)
1580 RANDOMIZE
1590 T$=" WAIT-RANDOMISING"
1600 R=17
1610 VR=3
1620 GOSUB 2260
1630 FOR Y=1 TO 32
1640 SCR=1
1650 KEY=RAN(14)+1
1660 GOSUB 170
1670 SCR=1
1680 KEY=RAN(2)+1
1690 GOSUB 170
1700 GOTO 1710
1710 NEXT Y
1720 SCR=0
1730 RETURN
1740 REM
1750 C3=65
1760 FOR C=5 TO 11 STEP 2
1770 FOR C2=8 TO 14 STEP 2
1780 CALL HCHAR(C,C2,C3,1)
1790 C3=C3+1
1800 NEXT C2
1810 NEXT C
1820 CALL HCHAR(11,14,32)
1830 REM
1840 T$=" WAIT-RANDOMIZING"
1850 R=17
1860 VR=3
1870 GOSUB 2260
1880 FOR Y=1 TO 55
1890 SCR=1
1900 KEY=RAN(4)+1
1910 GOSUB 170
1920 NEXT Y
1930 SCR=0
1940 RETURN
1950 PRINT "SQUARES"::"STEPH
EN SHAW 1981":"PRESS '1' OR
'2' FOR:"
1960 PRINT "1. 6X6 PROBLEM":
"2. 4X4 PROBLEM"
1970 PRINT "FOLLOW DIRECTION
S AT BOTTOM OF SCREEN AFTER
DIAGRAM":"HAS BEEN DRAWN"
1980 CALL KEY(0,A,B)
1990 IF A=49 THEN 2050
2000 IF A=50 THEN 2010 ELSE 1980
2010 H=4
2020 V=4
2030 CALL CLEAR
2040 RETURN
2050 H=6
2060 V=6
2070 CALL CLEAR
2080 RETURN
2090 CALL CLEAR
2100 PRINT "SQUARES 1981"
::"STEPHEN SHAW STOCKPORT":"
THE OBJECT IS TO RESTORE "
2110 PRINT "THE ORIGINAL PAT
TERN OF ":"SQUARES,WHICH TH
E COMPUTER":"HAS SCRAMBLED"
2120 PRINT "USING THE COMMAN
DS AVAILABLE.":"IN BOTH PUZZ
LES THE BLANK":"MOVES UP OR
DOWN"
2130 PRINT "IN THE 6X6 PUZZL
E":"IT CANNOT MOVE > OR < BU
T": "THE WHOLE ROW SLIDES "
2140 PRINT "WATCH AS THE COM
PUTER":"SCRAMBLES THE ORIGIN
AL":"PATTERN TO SEE HOW IT":
"WORKS!"
2150 PRINT "(BEING RANDOM YO
U MAY END":"UP BACK AT THE S
TART!)"
2160 PRINT "PRESS KEY P TO P
LAY AGAIN":"WHEN YOU HAVE CO
MPLETED":"YOUR PUZZLE"
2170 INPUT "PRESS ENTER":T$
2180 CALL CLEAR
2190 GOTO 1950
2200 CALL CLEAR
2210 CALL CHAR(96,"000000FF")
2220 CALL CHAR(97,"101010101
0101010")
2230 CALL CHAR(98,"101010FF1
0101010")
2240 CALL SCREEN(12)
2250 RETURN
2260 FOR G=1 TO LEN(T$)
2270 CALL HCHAR(R,VR+G,ASC(S
EG$(T$,G,1)))
2280 NEXT G
2290 RETURN
2300 C5=11
2310 M$=""
2320 GOTO 600
2330 C5=11
2340 M$=""
2350 GOTO 770
2360 C5=13
2370 M$=""
2380 GOTO 600
2390 C5=13
2400 M$=""
2410 GOTO 770
2420 C5=15
2430 M$=""
2440 GOTO 600
2450 C5=15
2460 M$=""
2470 GOTO 770
2480 END





THE INFORMATION IN THIS BOOK IS FREE. It may be copied, distributed and/or modified under the Creative Commons Attribution-NonCommercial 2.0 UK: England & Wales License. Alternative licence: Design Science License published by Michael Stutz.    See instead Stutz dsl

Book Index page | Stephen's Entry page
Access Key Details

Stephen's Entry Page | TC99/4a |Linux |Search | History St Thomas Church Heaton Chapel | Entertainment | Music Links

Light Reference | Educational Reference | Science Fiction | Travel | News Links | Anime