Difference between revisions of "TI Forth"

From Ninerpedia
Jump to navigation Jump to search
(add how to enter a floating point number from the keyboard)
(Category)
 
Line 576: Line 576:
When FORTH has finished, the tracks have been laid down on the disk, and a header has been put on the disk for the Console to use: BUT the disk is full of a file called SCREENS, so, in Basic (or Ex Bas), type in:
When FORTH has finished, the tracks have been laid down on the disk, and a header has been put on the disk for the Console to use: BUT the disk is full of a file called SCREENS, so, in Basic (or Ex Bas), type in:
  DELETE "DSK1.SCREENS" and you end up with a blank initialised SSSD disk.
  DELETE "DSK1.SCREENS" and you end up with a blank initialised SSSD disk.


[[Category:Programming language]]
[[Category:Programming language]]
[[Category:Programming]]
[[Category:Programming]]
[[Category:Disk]]

Latest revision as of 12:02, 26 October 2020

TI FORTH is supplied on a floppy disk and requires a disk system, 32k, and EITHER Editor/Assembler OR Extended Basic .... (separate disk for ExBas version).


You receive your disk with TI FORTH on it.

FIRST: Copy the disk, using your Disk Manager module (read the note below)

TI's DISK MANAGER I module could very happily copy Forth disks, but unfortunately Disk Manager 2 does not: after "copying" with TI Disk Manager 2, you must then use Forth itself to copy Screens 1 to 9. To do this use:

Insert master disk in drive 1
Type

1 BLOCK UPDATE 2 BLOCK UPDATE 3 BLOCK UPDATE 4 BLOCK UPDATE 5 BLOCK UPDATE

Now insert "copied" disk:
FLUSH

Now insert 'master' disk: 6 BLOCK UPDATE 7 BLOCK UPDATE 8 BLOCK UPDATE 9 BLOCK UPDATE

Insert 'copied' disk:
FLUSH.

OR use Forth entirely:

Master disk in Drive 2, blank initialised disk in Drive 1:

 0 DISK_LO ! FORTH-COPY
(assumes -COPY has been loaded)


Note the TI supplied disk is Single Sided Single Density (90k). TI Forth as supplied assumes you are using 90k disk drives.

If you use double sided drives, initialise the copy disk as SINGLE sided: the double sided header is larger and makes a mess of the Forth screens. Later on maybe we'll go over formatting JUST the second side for your program screens... clever is Forth!

Now, put the original disk in a safe place!

System Disk

The SYSTEM DISK carries most of the FORTH language on its files "FORTH SCREENS".

It is a feature of FORTH that it rewrites the disk files, and it is easy to accidentally overwrite your system disk! So don't do ANYTHING until you have a nice safe copy!

Now...
Editor Assembler: Select "LOAD AND RUN", File name is: DSK1.FORTH
or
EXTENDED BASIC: Put the disk in the drive and select ExBas.  
                Autoload takes care of the rest.

You will see the message 'Booting Forth', followed by a menu of options, and after a short delay, a cursor will appear.

A menu will appear: only the 'kernel' of Forth has been loaded.

To use Forth, you must select portions from the menu: the more you load the less memory is free for your program.

We will use the menu to create a 'custom' Forth which loads pretty quickly...

Note as you use these Menu options just how slowly they function!

Fortunately, we can load our desired selection, then BSAVE the whole lot, to be BLOADed when required, in one piece, quickly!

Screen Dump

Now, the SCREEN DUMP is located on SCREEN 72, and may not be suitable for your printer. Lets have a look ....

In order to EDIT screen 72, we need to load an editor. Choose EITHER the 40 column editor (-EDITOR) or the 64 column editor (-64SUPPORT)

(NOTE: To start with do not use the 64 column editor, 
see note towards the end of this article).
To load these just key in the name, with the dash 
in front, and press ENTER.
Now when the cursor reappears, type in 72 EDIT [enter]
Screen 72 will be loaded and will appear on screen.
As supplied, screen 72 is set up for RS232. 
If you use PIO, make the following changes:
Line 2: Change >RS232 to >PIO
Line 3: Change >RS232 to >PIO
Line 4: Set the string to the actual file name used 
by your printer, that is " PIO" or " PIO.CR" and so on.
Remember the single space after the first quotes!!!!! 
    (quote, space, PIO, quote)

Check the screen: some versions have a typing error from TI! lf you see the word PAB_ADDR, you must change it to PAB-ADDR.

Now press FCTN 9 (BACK) to return the cursor to the bottom of the screen.
Now we write the amended screen to disk by typing FLUSH [enter]
Let's make sure everything really is been cleared out: type in COLD [enter]
and when the cursor reappears, EMPTY-BUFFERS [ENTER]

Custom Forth Disk

We are ready to customise FORTH.

As a beginning we will need to boot most of Forth...

This is MY selection.

Type EMPTY-BUFFERS [enter]
Now type in, on one line:
-PRINT -COPY -VDPMODES -BSAVE [enter]
Thats the essential FORTH.

When the disk stops at last and the cursor reappears, let's put a marker flag in there: type in:

 : FLAG1 ; [enter]
   (colon, space, FLAG1, semicolon .... then [enter]
A bit more Forth: type in, on one line:
 -GRAPH -DUMP -FLOAT [enter]

 Now another flag. Type in
  : FLAG2 ; [enter]

and finally, your choice of editor, either -64SUPPORT (see note) or -EDITOR [enter]

Thats almost everything you are likely to need.

Lets save it! To save EVERYTHING in memory, and to locate it on the disk from screen 51 onwards (deleting what was previously on those screens!!!!:

Type in:
 ' TASK 51 BSAVE [enter] 
 The first character there is a FCTN O, a single quote.

When the BSAVE has ended, you need to amend the "BOOT" screen, screen 3, to BLOAD your binary image.


New BOOT screen to load the new system disk

 Type in 3 EDIT [enter] 

and adjust your screen 3 to look something like this:

 SCR #3
 0 ( WELCOME SCREEN )
 1 BASE->R HEX 10 SYSTEM ( Clears Screen )
 2 0 0 GOTOXY ." Loading TI Forth " CR 10 83C2 C! ( Quit Off )
 3 DECIMAL 51 BLOAD 16 SYSTEM MENU
 4 1 VDPMDE !
 5 0 DISK_LO !
 6
 7 180 DISK_HI !
 8
 9 : FREE SP@ HERE - . ;
 10
 11 : PAGE 0 0 GOTOXY CLS ;
 12
 13 -6392 FENCE !
 14
 15 R->BASE

When copying, omit for the time being the FENCE line! See below...

Thats my WELCOME screen.

Explanation of bew Boot screen

180 DISK_HI ! on this screen sets the system up for two single sided drives 180 DISK_SIZE 9 on this screen sets up for one or more double sided drives 360 DISK_HI ! on this screen sets up for two double sided drives. The EXCLAMATION MARK (! is important here!) DISK_HI is the highest numbered screen, at the rate of 90 per single side. DISK_SIZE is the number of screens per DISK.

FREE will allow you to obtain the free memory at any time just by keying FREE.

PAGE will at any time clear the screen and home the cursor.

Once you have set up your screen three, as above or adjusted for your disk system, FLUSH it for the time being ..........

Press FCTN 9 (BACK) then enter FLUSH [enter]

One more step (about fences):

In Forth you can FORGET the basic Forth words, such as +... and in the course of doing so, FORGET everything above it in memory, which can be quite drastic. FORTH allows you to place a FENCE which prevents you FORGETting important things.

Having FLUSHed page 3, if you type ' PAGE . then you will receive a helpful ?.

This is because our new word PAGE is not yet in memory, we need to LOAD it!

To get our new page 3 in memory for the next step,

we now need to type EMPTY-BUFFERS
and then     3 LOAD


Let's see where the top word in the COMMAND STACK is:

Type in ' PAGE . [enter]
 (single quote, space, PAGE, space, full stop, [enter] )

The number printed is where we want to put the FENCE, so again type 3 EDIT Add to the end of the screen (as above)

[number] FENCE !
and FLUSH the screen to disk as before.

Now... cover the write protect tab!!! And your disk is all ready.

To see how quickly FORTH now loads, type in COLD again.

Screens still available

It is always a good idea to keep your boot disk separate to your own programs, but if you do need to place any new screens on it, there are a few that you can use still.

Our fairly full Forth BSAVE took up from screen 51 to screen 61.

The following screens cannot then be used for our programs:
0/5 : Used by the system 
44 : TRACE ( not Bsaved. You may want to load it later)
51/61 : Our Bsaved area! 
68/71 : FILE ( not Bsaved. May wish to use it later)
74/75 : Code and Assembler. ( not Bsaved. May wish to use it later)
88 : CRU ( not Bsaved. May wish to use it later)

The Forth loading program which contains the "kernel" of Forth is held on Screens 5 to 21. You can use a small number of screens on spare disks to have most of Forth on it and lots of rooms for your programs.

They will have almost all of TI Forth on them to draw on. Then the other screens are available for you to use. Add any of the above screens as you need them.

Copy with SCOPY or SMOVE screens 0 to 21 (Kernel) and 51 to 61 (BSaved).

If you have loaded EDITOR into the Bsaved portion, you may wish to retain the 64Support on your disk: it is on screens 22 to 29

If you have used 64Support in your Bsaved version, then you may wish to retain the 40 column EDITOR which is on screens 34 to 38.

ALL other screens are in the Bsaved portion! Screens 0 to 5 remain used by the system. Screens 4 and 5 contain the error messages.

Errata

Various sources have form time to time indicated flaws in the original version of TI Forth released by Texas Instruments. Because all of Forth can be rewritten debugging is merely a question of opening the page with the faulty code, amending it, and saving it.

Unfortunately none of the amendments below can be said to be "official", so before making them, do keep a record of any changes you make in case you need to remove them. And keep a copy of the original disk somewhere safe. Just in case.

Screens 58 and 59 - Sprites

The Sprite definitions may have been a semi-official correction:

Check your disks - use 58 LIST then 59 LIST.

Look at the dates at the top of the page. what year? If 1982, you need to make the following amendments:

Type 58 EDIT.
Change line 10 (part of SSDT definition):
formerly: ... 80 0 VFILL ENDIF
to become:... 80 0 VFILL 300 ! SATR ! ENDIF

Use FCTN 9 [back] and when back at the bottom of the screen (having removed the disk write protect tab!) type FLUSH.

Type 59 EDIT, and make amendments as follows:
Line 7 (part of SPRITE definition)
formerly .... I 2 VMBW ENDIF ....
to become: .. I 2 VMBW DROP ENDIF .... 
Line 9 (part of MOTION definition:)
Formerly: ... + >R 100 U* DROP + SP@ ...
to become: .. + >R 8 SLA SWAP 00FF AND OR SP@ ...
Use BACK and FLUSH to disk.

To be really efficient, you may wish to change the dates on the screens from 1982 to 2OOCT83!!!

Print a SCREEN

To PRINT a single screen, type in:
SWCH 3 LIST UNSWCH 
 to list screen 3 in this case.

List WORDS available

To see a list of words available to you, type in VLIST [enter]

Hold SPACE to halt the scrolling!

Entering lines in TI Forth

SPACES are IMPORTANT. If I show a space, put one in!

First, mark the beginning of the memory area you are about to use: ENTER:

 : ME ; (that is: COLON,SPACE,ME,SPACE,SEMI COLON, then ENTER)

The word ok will appear, then the cursor will come back.

This is quite important. Every word you define in FORTH is entered into memory.

If you use FORGET ME, the definition of ME is removed AND EVERY WORD DEFINED AFTERNARDS. This can avoid annoying warning messages!

Putting that blank definition of ME at the start of your work is a useful way of scrubbing definitions.

Multiple definitions of words

Now that ME is in the library, lets experiment with multiple definitions):

 ENTER : PRINT 4 . ;   (Do type in the colon after ENTER) 
 then ENTER : PRINT 5 , ;

The computer obtained a warning message from the disk: note it and continue:

ENTER : PRINT 6 , ; this time the warning message is brought from memory!

Now what does the word PRINT do? Let's try it:

  ENTER PRINT
  Hmmm. It has the LAST definition we put in!
  ENTER FORGET PRINT

ENTER PRINT now it has the 2nd to last definition!

You are warned if you redefine a word, but the new definition is the one that will be used. If you FORGET the word, the previous definition now becomes current, and so on. You can have a full stack of definitions of PRINT, and then delete them backwards!

You can even redefine basic FORTH words such as +, so be very careful! To check to see if a word is already in FORTH, key in:

  ' WORD .

and if an address is printed, the word is in there already.

Redefining words is considered bad practice!!!!

Multiple markers

Using ME as the first defined word, (we could have used AUDREY or anything else), we can still use ME to place another marker on the stack, and delete first the second section with FORGET ME, then delete the first section with another FORGET ME!

How to QUIT

HOW do you return to the title screen, as QUIT does not work?

If you have loaded -SYNONYMS (or either Editor or any Graphics mode or -FLOAT) then you have access to the Forth word MON. To return to the main TI screen just type in MON and press ENTER.

Using SOUND in TI Forth

We need to define a sound command, then we can use it. The following screen is appropriate and sets up a Forth word CALLSOUND (no space!) which will take 3 values from the stack.

ONE VOICE ONLY.

Screen:
0 ( CALL SOUND ROUTINE FOR ONE VOICE APRIL 85 SJS )
1 ( USES VDP AREA 14336 TO 14345 )
2 ( duration in ms. volume 0-30, frequency CALLSOUND --- )
3 : SINIT -31747 C@ 1 OR -31747 C! 3 14336 VSBW ;
4 : FREQ S->F >F 111860.8 FSWAP F/ F->S ;
5 : BYTE1 DUP 16 MOD 128 + 14337 VSBW ;
6 : BYTE2 16 / 14338 VSBW ;
7 : VOL 2 / 144 + 14339 VSBW ;
8 : DUR SINIT FREQ BYTE1 BYTE2 VOL 20 / 14340 VSBW ;
9 : SIL 3 14341 VSBW 159 14342 VSBW 191 14343 VSBW 223 14344 VSBW
10 0 14345 VSBW ;
11 : PLAY 56 -31796 C! 0 -31795 C! 1 -31794 C! ;
12 : CALLSOUND DUR SIL PLAY ;
13 CR ." ONE VOICE WORDS LOADED & AVAILA8LE"

To emulate CALL SOUND, I have placed data into VDP RAM as a sound table, then told the computer to play it.

The CALLSOUND requires three values on the stack, N1 N2 and N3, where N1= duration in milliseconds, N2=volume O-30, N3=frequency in cycles per second.

eg: 600 2 220 CALLSOUND 

The operation of the CALLSOUND is the same as a Basic Call Sound using a NEGATIVE duration: a second use will cut short any sound still in progress.

If you wish to use an equivalent to a positive call sound. you need to test VDP Location -31794. This becomes zero when the sound has stopped. C@ is used to place the value in this location onto the stack.

SINIT tells the computer the sound information is to be stored in VDP RAM. Note the use of C@. We then tell it that we are passing three values.

FREQ took a few seconds to develop, and together with BYTE1 and BYTE2, translates the frequency in cycles per second which you have put on the stach into the two values the computer wants. We switch the top stack value (frequency) to a floating point number, then input a floating point number. Then we swap these two floating point numbers on the stack, so that the frequency input is again on the top. Then we divide,and change the result to a single precision number.

SIL is placed at the end of the VDP data to switch the sound off after the input duration.

Forth equivalents of Extended Basic commands: VSBW is the same as CALL POKEV; C! = CALL LOAD; C@ = CALL PEEK

Using SPEECH in TI Forth

We need two screens of code to define the required Forth commands. You need the Speech Synthesiser attached. At the end of the first screen you will see --> which instructs Forth that the first screen is followed by the second screen, so when loading these screens you only need to tell it to load the first.

Some sample words have been included but you can extend or modify the vocabulary by referring to the Editor/Assembler manual.

You only need to LOAD the first screen, the --> automatically LOADs the next screen, after a pause. When LOADing is complete the computer will say READY TO START. You may then use any of the defined words in these two screens to generate speech.

For instance, if you key in (or use in a definition):
 _I AM _A TEXAS_INSTRUMENTS NINETY #9 #4 _A COMPUTER 
 that is just what the computer will say!

Note the underlines in front of I and A and between TEXAS and INSTRUMENTS.

( SPEECH WORDS 9TH APRIL 1985 SJS) CR ." LOADING WORDS .... "
: M -27648 C! ; : SE 64 M 80 M ;
: THAT_IS_INCORRECT 70 M 65 M 72 M 70 M SE ;
: THAT_IS_RIGHT 78 M 79 M 72 M 70 M SE ;
: READY_TO_START 67 M 75 M 70 M 69 M SE ;
: TEXAS_INSTRUMENTS 70 M 73 M 70 M 70 M SE ;
: WHAT_WAS_THAT 73 M 78 M 71 M 71 M SE ;
: NEGATIVE 76 M 77 M 72 M 68 M SE ;
: POINT 76 M 78 M 64 M 69 M SE ; : #1 73 M 64 M 68 M 65 M SE ;
: #3 74 M 73 M 68 M 65 M SE : : #5 65 M 67 M 69 M 65 M SE ;
: #7 72 M 78 M 69 M 65 M SE ; : #9 68 M 70 M 70 M 65 M SE ;
: POSITIVE 67 M 75 M 65 M 69 M SE ; : #0 67 M 76 M 67 M 65 M SE
; : #2 76 M 69 M 68 M 65 M SE ; : #4 71 M 78 M 68 M 65 M SE ;
: #6 72 M 74 M 69 M 65 M SE ; : #8 71 M 67 M 70 M 65 M SE ;
: ANSWER 67 M 65 M 73 M 65 M SE ;
-->
( SPEECH WORDS PART TWO APRIL 85 SJS )
: ABOUT 68 M 65 M 71 M 65 M SE ; : FOURTH 73 M 65 M 77 M 66 M SE
; : AM 64 M 67 M 72 M 65 M SE ; : _A 68 M 78 M 70 M 65 M SE ;
: WORKING 76 M 75 M 75 M 71 M SE ; : PLEASE 67 M 73 M 64 M 69 M
SE ; : PRESS 65 M 67 M 66 M 69 M SE ; : PRINTER 74 M 74 M 66 M
69 M SE ; : NICE_TRY 69 M 74 M 73 M 68 M SE ; : NINETY 78 M 68 M
74 M 68 M SE ; : DISK 77 M 66 M 68 M 66 M SE ; : _ERROR 79 M 78
M 72 M 66 M SE ; : HELLO 74 M 65 M 69 M 67 M SE ; : MEMORY 69 M
64 M 68 M 68 M SE ; : UHOH 68 M 79 M 65 M 71 M SE ; : SORRY 70
M 76 M 65 M 70 M SE ; : TRY_AGAIN 79 M 64 M 64 M 71 M SE ; : LEF
T 72 M 71 M 78 M 67 M SE ; : GOOD 70 M 77 M 64 M 67 M SE ; : SHO
ULD 68 M 66 M 79 M 69 M SE ; : YOU 78 M 75 M 65 M 71 M SE ;
: COMPUTER 68 M 67 M 64 M 66 M SE ; : IS 66 M 67 M 74 M 67 M SE
; : IT 74 M 71 M 74 M 67 M SE ; : PROBLEM 73 M 79 M 66 M 69 M SE
; : SAID 65 M 74 M 74 M 69 M SE ; : _I 67 M 73 M 71 M 67 M SE ;
 : HELP 65 M 71 M 69 M 67 M SE ; READY_TO_START 
  1. 5 defines the spoken word 5 and so on. Because we have defined AM and IT for example as words to be spoken, you cannot then use the words AM or IT as another command or as a variable.

Notes

FORTH is a useful language, as you are able to experiment with the stacks without having to actually enter and run a program. It is very like LOGO in this respect.

These simple tests have been in 'direct mode', we have not stored a program yet, merely tried defining some simple words.

That is the strength of FORTH: If a command you want does not exist, you can define it in terms of existing commands, and build up your own powerful vocabulary.

Entering a FORTH program

To enter a program onto a Forth screen, if you wish to use say Screen 15, type: 15 CLEAR 15 EDIT

Using Disk Drive 2

If the disk is in drive two, the position of screen 15 is now called Screen 105!!! (eg add 90). FORTH only uses the disk number for the FORMAT command.

When accessing screens you do so only by screen number. Disk one is 0-89, Disk two contains 90-189. .

Copying FORTH disks (SSSD)

TI's DISK MANAGER I module could very happily copy Forth disks, but unfortunately Disk Manager 2 does not: after "copying" with TI Disk Manager 2, you must then use Forth itself to copy Screens 1 to 9. To do this use:

Insert master disk in drive 1
Type

1 BLOCK UPDATE 2 BLOCK UPDATE 3 BLOCK UPDATE 4 BLOCK UPDATE 5 BLOCK UPDATE

Now insert "copied" disk:
FLUSH

Now insert 'master' disk: 6 BLOCK UPDATE 7 BLOCK UPDATE 8 BLOCK UPDATE 9 BLOCK UPDATE

Insert 'copied' disk:
FLUSH.

OR use Forth entirely:

Master disk in Drive 2, blank initialised disk in Drive 1:

 0 DISK_LO ! FORTH-COPY
(assumes -COPY has been loaded)

Copying Forth disks- DSDD

Copying DOUBLE SIDED DOUBLE DENSITY FORTH:

Initialise a disk DSDD and copy your Forth system disk as above (NB: the initial system disk. not one with a BLOAD system on it)

Now change Screen 3:

360 DISK_SIZE !
n DISK_HI ! [n=number of drives you have at 360 sectors]

Forth will now recognise your disk as having 360 screens (180 on each side). FORTH-COPY however will continue to insist your drive only has 90 screens.... to amend FORTH-COPY you need to amend Screens 39,40,0,and 4.

i. Edit Screen 39: Change 90 to 360, where it appears in DTEST and twice in FORTH-COPY.

ii.Edit Screen 40:

Line 3: Change 168 to 5A0
Line 4: Change 944 to 1244
Line 5: Replace line with:
DUP 10 + 2028 SWAP ! DUP 12 + 0202 SWAP ! DUP 14 + 24 0 FILL
Line 10: Change 165 to 59D
Line 13: Change 4016 to C059

Now edit Screen 33. and modify FORMAT-DISK to read:

: FORMAT-DISK 1+ 514 33616 ! 18 SYSTEM ;

All that is left is to modify the header sectors. This is done with a little Forth program. Make sure the “copy” disk is in drive one.

In immediate mode type in:

 HEX 0 DISK_LO !
 : DD 0 BLOCK UPDATE
 DUP A + 5A0 SWAP ! DUP C + 1244 SWAP !
 DUP 10 + 2028 SWAP ! DUP 12 + 202 SWAP !
 38 + C8 FF FILL 1 BLOCK UPDATE
 DUP E + 570 SWAP ! DUP 1C + 4D20 SWAP !
 DUP 1E + 5205 SWAP ! 20 + F059 SWAP !
FLUSH ; DECIMAL DD

The new header is easily copied either by using FORTH-COPY or by copying Screens 0 and 1 onto future Forth disks.

(from Jim Vincent)

16 SYSTEM is CLS

Using 16 SYSTEM (decimal!) clears the screen, and you can see from screen 33 that the clear screen word CLS is defined in just this manner! CLS takes up less room than 16 SYSTEM.

64SUPPORT

note on -64SUPPORT: If you load -64SUPPORT, ensure that -TEXT is loaded before you use it (-VDPMODES includes -TEXT We loaded -VDPMODES into our newly BLOADED Forth just before FLAG1 way up in this article)

If -TEXT is not resident, you will not be able to leave the 64 column split screen.

To change from the 64 column screen to normal, just back out with FCTN 9, then at the bottom of the screen enter the word TEXT [enter].

Taking input from keyboard

HOW DO YOU ENTER FROM THE KEYBOARD?

Try using QUERY... for instance:

: TEST QUERY MYSELF ;

If you run this word it will ask you to input something, then ask you again, and so on till you get tired of it. We have not inserted any means of escape so you will have to switch off.

This is better:
: TEST QUERY INTERPRET MYSELF ;

Now the computer will look at the word you type in when the cursor flashes and treat that word as a FORTH word to be executed. The word MYSELF used above merely repeats the word calling it, e.g. TEST

Try typing in BEEP (if you have it loaded) or to fall out of the loop, ABORT.

What happens if you type in an undefined word? Try it!

Entering a floating point number

: ENTFP ( --- f ) PAD 1+  DUP 20 EXPECT 
      LEN SWAP 1- C! VAL FAC>   ; 

Explanation The address of PAD+1 is placed on the stack- this is because VAL, perhaps contrary to what the Manual suggests, starts reading the entry at PAD+1. If you just used PAD, you would lose the first character, either the most significant digit, or perhaps a decimal point or a minus sign.

20 EXPECT allows you to enter up to 20 digits... more than you may need but so what!

VAL then converts the string to a floating point number.

FAC> brings the floating point number on to the stack.

If you want an integer number output, you could use FAC->S instead.

Something similar to CALL KEY

Another useful word is KEY which is the equivalent of CALL KEY... but waits for a key to be pressed, then the key value appears on the stack for you to look at and perhaps use or DROP. Try:

: TEST KEY EMIT MYSELF ;

which will form an endless loop!

A closer equivalent to CALL KEY is one which scans the keyboard and moves on, leaving a value of 0 if no key is pressed:

: TEST ?KEY IF EMIT MYSELF ELSE DROP MYSELF ENDIF ;

Lets go back to that endless loop we started with... why not test for CLEAR (Break)? Try:

: TEST KEY ?TERMINAL IF ABORT ELSE EMIT MYSELF ENDIF ;

The word MYSELF used above merely repeats the word calling it, e.g. TEST

Take a look at the TEST above using ?KEY. The basic equivalent is:

10 CALL KEY(O,K,S)
20 IF S=0 THEN 10 ELSE PRINT CHRS(K) :: GOTO 10

TI Forth for-next loops

Well, in Forth we have one important change to BASIC usage: you can only use two variables, called I and J.

Let's compare Basic to Forth... note that I and J are NOT interchangeable. J is only used when two loops are nested and J is always the OUTER loop counter

FOR I=I TO 20
PRINT "TI*MES"
NEXT I

is:

: TEST 21 1 DO ." TI*MES" CR LOOP ;

Note that 20 has to be 20+1=21 here!

A little more difficulty then:

FOR I=4 TO 16
PRINT I
NEXT I

becomes:

: TEST 17 4 DO I 48 + EMIT CR LOOP ;

Assuming we are in DECIMAL base!

We have to add 48 to I to obtain the ASCII of the character we wish to print. The ASCII of number 1 is 49. The I places the counter value on the stack, then we add the 48... ok?

Now let's get really tricky and use something else...

FOR I=5 TO 21 STEP 4
PRINT "STEP"
NEXT I

is:

: TEST 22 5 DO ." STEP" CR 4 +LOOP ;

We have used +LOOP here, with the STEP immediately in front of it.

Nested loops? No problem.

FOR J=1 TO 6
FOR I=4 TO 12
PRINT J+I
NEXT I
NEXT J
: TEST 7 I DO 13 4 DO I J + . CR LOOP LOOP ;

and if you can follow THAT you are well on the way to understanding Forth control!

Oh yes .... if you really don't like using I, you can use R instead, 'cos again they are completely interchangeable ....

Formatting Floppy Disks with TI Forth

Want a blank SSSD floppy and don't have Disk Manager? TI FORTH on its own can initialise a single sided single density drive as follows:

Load FORTH and menu choices -COPY and -SYNONYMS.
Place your disk to be formatted in disk drive number one.
Type in: 0 FORMAT-DISK DISK-HEAD

When FORTH has finished, the tracks have been laid down on the disk, and a header has been put on the disk for the Console to use: BUT the disk is full of a file called SCREENS, so, in Basic (or Ex Bas), type in:

DELETE "DSK1.SCREENS" and you end up with a blank initialised SSSD disk.