Difference between revisions of "Extended BASIC"

From Ninerpedia
Jump to navigation Jump to search
(Add expansion memory test and upper case program control)
(Add use of your own sub programs with examples.)
Line 94: Line 94:
===SAVE===
===SAVE===


===[[Speech]]===
===Speech===
See article [[Speech]]


===SIZE===
===SIZE===
===SUB PROGRAMS===
As well as the built in CALLs Extended BASIC allows you to create your own sub programs.
If in a program the colours of character sets 1 to 8 are regularly changed.
It could be done with a subroutine, setting variables and then using GO SUB:
200 X=2
210 Y=4
220 GOSUB 8OO
230 GOTO 230
800 FOR T=1 TO 8
810 CALL COLOR(T,X,Y)
820 NEXT T
830 RETURN
In Extended Basic we can create a sub program called COLOUR (NOTE: English spelling! now you can call color or colour, one is built in, one you have written... ) .
Sub programs MUST appear at the end of your program. Only other sub programs can follow them.
Example:
200 CALL COLOUR(2,4)
210 GOTO 210
2000 SUB COLOUR(X,Y) :: FOR T=1 TO 8 :: CALL COLOR(X,Y) :: NEXT T :: SUBEND
Thats it!
In this example of a sub program, we have passed two VALUES to the sub program, which are taken by the local variables X and Y in the subprogram.
IMPORTANT: If X and Y are used in your main program, or indeed in other sub programs, their values are NOT changed by their use here! This X and Y are unique to this sub program.
If instead of numbers. we use variables CALL COLOUR(A,B), then in this form, the values of A and B may be changed in the sub program.
Further example:
  10 CALL EXAMPLE(A,B)
  11 PRINT A,B
  12 GOTO 12
  20 SUB EXAMPLE(X.Y) :: X=2*X :: PRINT X :: SUBEND
In this format, if A=2 and B=4 when the CALL is executed, the values of A and B are passed to X and Y in the sub program. At the end of the sub program, the values of X and Y are passed BACK to A and B, thus the sub program has changed variables in the main program.
If you do not want this to happen, it doesn't have to. You can pass variables with their values protected by using extra brackets:
CALL EXAMPLE((A))(B))
The same SUB will take its values from A and B, but at the end of the sub program, A and B will retain their original values: they will not be changed bv the sub program. Just place the variables in the CALL in brackets.


==Programming Hints==
==Programming Hints==

Revision as of 10:52, 7 October 2014

First TI produced TI BASIC, built into the console. Then came the first attempt at an Extended BASIC, in module format, which returned the value of 100 with CALL VERSION(A). This first version is quite rare and suffered several problems.

Very quickly a rewrite was issued. The second version was still called TI Extended BASIC but this time when you used CALL VERsion(A) it returned a value of 110. It was faster. (Mostly because it was no longer trying to keep track of graphic sprites that you weren't using).

Subsequent versions of Extended Basic from third parties added more powerful versions of commands or new commands- some example versions are:

Myarc Extended BASIC II

Triton Super Extended BASIC (Returned 120 with CALL VERSION(A) )

Extended BASIC III


General Notes

This page links to some notes on using Extended Basic generically and where possible each comment will address the variations.

Program Line content

PROGRAM LINES: May now contain more than one command, and can be entered up to 5 screen lines long (but limited to 128 bytes long internally).

You may use IN COMMAND MODE for instance: FOR A=110 to 220 :: CALL SOUND(200,A,0) :: NEXT A

The double colon is a statement separator. In TI Basic you could enter PRINT A::B::C.

In Extended Basic you must leave a space between the colons: PRINT A: :B: :C

(A program in TI Basic is converted automatically by the machine to the new format, but you must take care when typing in a program. Due to an omission in the error handling system, typing too many colons together in Extended Basic can cause the processor to 'lock out')

When this is linked to the new capabilities of the IF...THEN command, it is possible to put together some very powerful program lines:

IF A=B THEN C=5 :: PRINT A :: ELSE IF A=8 AND B=C THEN GOTO 3400 ELSE CALL SOUND(100,110,0) :: GOTO 200

As the lines become longer and more complex, you do need to take greater care, but the language gives you a very powerful tool.

In addition to using REM after double colons, you may use a 'tail remark', which is a '!' as follows:

140 SCORE=0 ! RESET SCORE

Memory Usage

EXTENDED BASIC uses some of the system RAM, and you do not have quite as much memory available for your programs. In addition, the cassette loader cannot handle programs over 12k.

The good news is that with Extended Basic you may access the memory expansion unit, which permits you to load (from DISK) a program up to 24k, and still have some 14k available for variables and so on.

REDO key

The new function key REDO will repeat your last entry, and if the last entry was a program line (either just entered, or recalled using FCTN X) the line reappears on the screen with the cursor at the beginning of the line NUMBER, allowing you to change the line number if you wish. This function is useful if your program contains a lot of lines either the same or with only small differences.

Alpha Lock

A program using the joysticks requires the alpha lock is UP, a relic of the TI99/4 days.

If your program requires the alpha lock to be DOWN for input etc you can instruct the console it is down:

Insert a dummy line CALL KEY(3, Z, Z)

The use of key unit 3 tells the computer to treat the alpha lock as if it were down whilst the program is running, unless we reset. Use of key unit 0 has no effect on alpha lock status. Key unit 5 will reset normal operation.

Expansion Memory Test

"Is the 32K expansion connected?" (in Extended Basic programs) - there is no need to trouble the user with this, the computer can answer this question itself:

CALL PEEK(-45, A, B, C) 
IF A+ B+ C> 0 THEN (the 32K RAM is attached!) 

Machine code programs

An added attraction of the module is that it permits you to load and run Assembly language programs, provided you have the extra peripherals required.

Example: In the USA, TI release TI INVADERS on disk for half the price of the module. You require a disk system and the 32k memory expansion.

Console Crashes

If you use CALL PEEK at some locations the console will cease to respond.

Users have encountered more system lock outs due to dirty module contacts with Extended Basic as it uses more of them than most modules.



Extended BASIC commands

ACCEPT AT, DISPLAY AT

Your own subprograms to CALL

IF THEN ELSE

LET

LINPUT

LIST

ON BREAK NEXT

ON ERROR

RUN

SAVE

Speech

See article Speech

SIZE

SUB PROGRAMS

As well as the built in CALLs Extended BASIC allows you to create your own sub programs.

If in a program the colours of character sets 1 to 8 are regularly changed.

It could be done with a subroutine, setting variables and then using GO SUB:

200 X=2 
210 Y=4
220 GOSUB 8OO
230 GOTO 230 
800 FOR T=1 TO 8
810 CALL COLOR(T,X,Y)
820 NEXT T
830 RETURN

In Extended Basic we can create a sub program called COLOUR (NOTE: English spelling! now you can call color or colour, one is built in, one you have written... ) .

Sub programs MUST appear at the end of your program. Only other sub programs can follow them.

Example:

200 CALL COLOUR(2,4)
210 GOTO 210
2000 SUB COLOUR(X,Y) :: FOR T=1 TO 8 :: CALL COLOR(X,Y) :: NEXT T :: SUBEND

Thats it!

In this example of a sub program, we have passed two VALUES to the sub program, which are taken by the local variables X and Y in the subprogram.

IMPORTANT: If X and Y are used in your main program, or indeed in other sub programs, their values are NOT changed by their use here! This X and Y are unique to this sub program.

If instead of numbers. we use variables CALL COLOUR(A,B), then in this form, the values of A and B may be changed in the sub program.

Further example:

 10 CALL EXAMPLE(A,B)
 11 PRINT A,B
 12 GOTO 12
 20 SUB EXAMPLE(X.Y) :: X=2*X :: PRINT X :: SUBEND

In this format, if A=2 and B=4 when the CALL is executed, the values of A and B are passed to X and Y in the sub program. At the end of the sub program, the values of X and Y are passed BACK to A and B, thus the sub program has changed variables in the main program.

If you do not want this to happen, it doesn't have to. You can pass variables with their values protected by using extra brackets:

CALL EXAMPLE((A))(B)) 

The same SUB will take its values from A and B, but at the end of the sub program, A and B will retain their original values: they will not be changed bv the sub program. Just place the variables in the CALL in brackets.

Programming Hints

Exchanging Variable Values

Nice bit of code here for you to look at. Let's suppose we have CAT=6 and DOG=9, how do we change those around?

We could set up a, temporary variable like this:

10 CAT=6 :: DOG=9
20 PET=CAT :: CAT=DOG :: DOG=PET
30 PRINT CAT;DOG

But we can save a little variable storage space and produce more interesting code like this...

10 CAT=6 :: DOG=9
20 CAT=CAT+DOG :: DOG=CAT-DOG :: CAT=CAT-DOG
30 PRINT CAT;DOG

Try it- it works! And saving variable names is of great value if you are programming for THE MISSING LINK, which only has limited VDP space for variable storage.

Purely in the interests of science, ExBas programmers can tackle this another way, but it is slower:

10 CAT=6 :: DOG=9
20 CAT=CAT XOR DOG :: DOG=CAT XOR DOG :: CAT=CAT XOR DOG
30 PRINT CAT:DOG