www.jupiter-ace.co.uk
Previous Page > General Forth index > Atom Forth from Computing Today October 1982.
Atom FORTH Reviewed from Computing Today October 1982 page 26
Review: Acorn's ATOM FORTH
ATOM
FORTH
Following our popular series on the basics
of FORTH as a programming languages,
we investigate a commercial offering.


A
TOM FORTH is a complete implementation of the FORTH language and is based on the standard model described by the FORTH Interest Group. It comes in pre-compiled form on cassette tape and requires an expanded ATOM with a minimum of 12K RAM to operate. However, the Floating Point ROM is not required.
The cassette arrives neatly packaged in the familiar Acornsoft book-like polystyrene box (while looking attractive on a bookshelf, it will probably have to be discarded if you keep your program tapes in a cassette case). The accompanying manual, FORTH Theory & Practice, is excellent and is described below.
The FORTH cassette contains:
Index
FORTH dictionary and
compiler
Tape Interface and Screen
Editor Graphics package
Graphics demonstration
The Index routine is very useful as it allows a visual check on program load-
ing enabling the correct playback volume setting to be obtained. Once the optimum setting has been found (mine worked correctly at the second attempt) FORTH itself can be loaded using the COS command, * RUN "FORTH". Loading takes about five minutes, however, my loading produced a SUM error a few blocks short of finishing. The cassette was rewound a couple of blocks and loading was completed using * FLOAD "FORTH". Executing LINK # 2800 caused the system to respond with the sign-on message:
ATOM FORTH
OK
Subsequent re-loadings using different cassette players produced the same SUM error, so presumably the fault was on my tape copy.
THE OPERATING SYSTEM
The ATOM FORTH operating system occupies about 5.5K of memory stored as two blocks. The Lower Dictionary Area is located in block zero RAM from 0240 to 03FE Hex which is normally reserved for BASIC's variables.
The Upper and Nucleus Dictionary Areas are located in the entire Lower Text Space from 2800 to 3C00 Hex. This region contains the 'boot-up' parameters used to initiate the system, followed by about 1K of machine code in the form of basic FORTH word definitions. Most of the remaining memory contains a pseudo-code compiled of 'execution addresses' which are used by the FORTH compiler as sequences of addresses of machine code subroutines to be executed. This constitutes much of the pre-compiled Nucleus Dictionary.
FORTH programs, which are more correctly known as applications, are stored in the User Dictionary Area in screen memory between 8C00 and 97C4 Hex. At the very top of the memory map is the User Area (97C4 to 97FF Hex) which is reserved for the 23 operating system variables, five of which are user definable.
UP AND RUNNING
Once running, the words present in the ATOM FORTH dictionary may be viewed by typing VLIST. A total of 184 words are included and the listing, which is continuous across the screen, can be halted temporarily by hitting the ESC key. Touching the space bar will recommence the listing.
If you followed D S Peckett's Going FORTH programming series in CT earlier this year, you will be familiar with FORTH's use of pre-fix notation. Being a comparative newcomer to FORTH, I found no particular difficulties in handling either it or the stack.
Working- through some of the many examples in the manual, I came across two bugs in the FORTH interpreter, concerning the use of the PICK and ROLL words. Both of these words are used to operate on numbers anywhere in the stack; for example, typing 5 PICK would copy the fifth stack item onto the top of the stack, while 5 ROLL would rotate the top five stack items. Use of either of these words caused the FORTH interpreter to 'hang-up' with only the Break key being recognised. A quick 'phone call to Acornsoft proved that there was indeed a fault, caused by two incorrect bytes present on early tape copies. A circular arrived in the post the following morning giving correction details:
HEX
2B 33C C!
2B 357 C!
This sequence was entered and cured the fault. Acornsoft will undertake to replace tapes with this problem if so wished, however, my replacement tape had the same problem!
Atom FORTH Reviewed from Computing Today October 1982 page 27
ATOM FORTH
The extensibility of FORTH is probably its most distinctive feature. Words may be added to the dictionary by defining their actions with words already present in the dictionary. ATOM FORTH provides six different methods of extending the dictionary - these defining words are:
: (colon)
CONSTANT
VARIABLE
USER
VOCABULARY
CREATE
CONSTANT, VARIABLE and VOCABULARY allow words and numerical values to be defined in FORTH terms, while USER provides space for up to five variables, stored in the User Variable Area, thereby allowing system modifications. CREATE is interesting as it can be used to add machine code routines to the dictionary.
As ATOM FORTH does not include an assembler, machine code must be entered in Hex. Using ATOM BASIC's assembler to generate the Hex, which can be done before loading ATOM FORTH, greatly simplifies what could otherwise be quite a tedious chore. A typical use of CREATE is given in Listing 1 which illustrates how the word '2/' could be defined. The compiling words ',' and 'C' compile two or one byte respectively, while SMUDGE is used to allow the new entry to be found in a dictionary search. Another interesting use of CREATE is to call subroutines present in the BASIC ROMs.
ATOM FORTH includes a comprehensive error handling facility with 24 error codes present, six of which are user definable. Error messages are given in the form:
cccc MSG n
where cccc is the erroneous word and n is the error code.
SCREEN EDITOR AND TAPE INTERFACE
Good editing facilities for any language are important and this is particularly so for FORTH. In BASIC, for example, it is possible to examine any particular part of a program simply by listing the relevant line. Similarly, modifications can be made just by re-typing or deleting lines; this is because BASIC programs are stored in source form. In FORTH, however, once a definition has been completed and Return typed, each word is interpreted and then compiled   into   the   dictionary   not  in
source form, but as a series of addresses of machine code routines to be executed when the new definition is encountered. Should any alterations now be required, the word must be deleted from the dictionary and the corrected version re-entered. The ATOM FORTH Screen Editor allows FORTH applications to be stored in 'screens' which preserve the source definition, allowing testing and correction of definitions before finally entering the application into the dictionary or preserving the source form on tape using the Tape Interface
The Editor and interface are provided in screens #6 to #14 and are loaded (which takes about 5 minutes) by typing 6 LOAD and playing the tape. As each screen is loaded, it is interpreted and compiled. Each screen is 512 bytes long, rather than the more standard 1024 bytes, and is comprised of eight lines, numbered 0 to 7, each of 64 characters length. The reduced screen size does mean, however, that the entire screen can be displayed on the VDU at one time.
To set up a blank screen for use, the EDITOR word PROGRAM is used, and screen numbering may be in the range 0 to 999. The line editor and string editor commands are given in Table 2. To enter a line of text to the screen, the word P is used. For example, to place the definition of TENCOUNT on line three of a screen, the following sequence would be used:
3 P : TENCOUNT 10 0 DO I . LOOP ;
The string editor commands allow location, insertion and deletion of character strings. Assuming line 6 of our screen contains 'THIS IS A SILLY DEMONSTRATION' from which we wish to delete the word 'SILLY'. The editing cursor, displayed as #, is first placed at the beginning of the offending word using F IS A. The ATOM FORTH response s:
THIS IS A #SILLY DEMONSTRATION 6 OK
and the word is deleted using:
TILL LY
which has the result:
THIS IS A DEMONSTRATION 6 OK
Once a screen is completed, it may be added to the dictionary by typing ENTER.
The tape interface provides SAVE, LIST and EMPTY-BUFFERS words which are loaded as part of the EDITOR vocabulary.
A screen is put to tape quite simply by typing SAVE and replying to the systems prompts. A screen takes about 30 seconds to be SAVEd.
GRAPHICS PACKAGE
The graphics application is provided in screens #18 to #21 and loading, which takes a minute or so, is not dependent on the presence of the Editor. All graphic modes except Mode 4 are available (its screen RAM is used as the User Dictionary Area and is protected from accidental Mode 4 calls).
Like ATOM BASIC, the word CLEAR is used to set up a particular graphics mode with the mode number being specified first in true FORTH style. Points and lines may be drawn using the PLOT, LINE and MOVE words while the plot 'colour' is specified by WHITE, BLACK or INVERT.
To draw a line in white from the origin to a point (15,25) in Mode 2, the following would suffice:
2 CLEAR 0 0 MOVE WHITE 15 25 LINE
These words all use absolute values for plotting and drawing lines. The words RMOVE, RPLOT and RLINE provide plotting using relative coordinate geometry, where the x and y values on the stack are interpreted as being relative to the last point plotted. Also included in the vocabulary is the word REL which converts relative co-ordinates to their absolute values.
The most annoying feature when using the graphics application is the amount of interference present on the display. This is an unavoidable consequence of the use of screen memory for user and application definitions, and can only be avoided by the addition of at least 2K of 'off - board' memory for use as the User Dictionary Area. If the high resolution graphics are not required, it is possible to use their screen memory as extra dictionary space for long or multiple user applications.
The graphics demonstration package uses recursive calls to draw a continuous series of rectangular loops across the Mode 3 screen. It appears on the screen at a stunning rate, greatly illustrating the speed of FORTH.
FORTH THEORY AND PRACTICE
As I've already said, and I make no apologies for repeating myself, the accompanying   manual    is   excellent
Atom FORTH Reviewed from Computing Today October 1982 page 28
Review: Acorn's ATOM FORTH
both as an introduction to FORTH and in providing an insight to its operation. Indeed, I'm sure that even non-ATOM owners with an interest in FORTH would find it fascinating. The 120 page, spiral bound volume is well laid out, easy to follow and contains copious examples throughout, which seem to be remarkably free of errors. The Tape Interface and Screen Editor are fully detailed, however, surely the chapter on graphics could have been extended to more than just three pages? Other chapters cover items such as mathematics, definitions, conditionals and loops, plus a detailed look at the use of the words < BUILDS and DOES> which can be used to define new defining words.
A chapter is also devoted to Further Examples, illustrating the use of recursion, factorals and array sorting. Also included in these examples is an application to patch FORTH into BASIC's COS commands, as well as allowing use of the VIA.
The Glossary details each word present in ATOM FORTH, giving both a description of the word's function plus its stack and system action
.
FORTHRIGHT CONCLUSIONS
ATOM FORTH provides, at the relatively low cost of £17.25, a thorough introduction to the FORTH language. Apart from the couple of bugs I encountered (which Acornsoft have now ironed out), it is simple to use and the ease of program development is a delight and leaves me wondering how I manage with BASIC.
Efficient use of the Screen Editor requires some practice, but once mastered presents no difficulties. The graphics words are as easy to use as their BASIC counterparts (if you are prepared to put up with the 'snow' they generate when used).
The manual, which can be purchased seperately for £6 would also not be out of place on any computing bookshelf.
My verdict: if you have an ATOM, get ATOM FORTH.
Finally, my thanks to Acornsoft for answering my questions and allowing me to use a couple of examples from the manual.
FORTH UTILITIES
Lo and behold, no sooner had I handed in this review of ATOM FORTH, than I received a prerelease copy of an ATOM FORTH utilities tape from Acornsoft via our hard working Editor.
The tape, accompanied by a first draft copy of   the   manual, provides   ATOM
FORTH with an assembler and discornpiler. I was pleased to see the former, though still a little disappointed that it was not included on the FORTH tape itself as it would greatly reduce the tedium of entering all but the shortest of machine code routines
Assembler definitions are enclosed in CODE and END-CODE words in the same way ':' and ';' are used for colon definitions. Nearly all the standard 6502 mnemonics are available and with Hex numbers such as ADC. I say 'nearly all' because there are no branch mnemonics! Branches are performed using loop structures similar to those available in FORTH, eg IF, ...ELSE, ...THEN, (again with terminating commas) and these test specific bits in the status register rather than items on the top of the stack, using the various test words. All addressing modes are available and are typically FORTH in requiring the operand and mode symbol to preceed the mnemonic.
Use of the computation stack is greatly simplified by the inclusion of BOT and SEC. These two words provide access to the low byte of the bottom and second stack items. Using BOT 1+ or SEC 1+ allows the high bytes of the stack items to be accessed. These words effectively make the stack transparent although SEC is somewhat confusing with the assembly language mnemonic SEC,.
Macro Assembly is also catered for, allowing sections of machine code to be used several times, inserting the machine code into the body of the application when it is needed or perhaps until a certain condition is met.
The discompiler does just as its name suggests converting previously compiled words back into an approximate source form. Loading is commenced with 36 LOAD and takes around four minutes. Acornsoft neglect to inform you that there is not enough RAM for both utilities to reside in the 'normal' system (something I found out after trying to load it!). Resetting the dictionary pointer to a lower address such as 8200 Hex creates more User Dictionary RAM at the expense of High-Res graphics.
Only two words are provided, these are DISCOMPILE and TYPE-OF. Discompiling the previous example of TENCOUNT would produce:
LIT #A 0 (DO) I . (LOOP) # -6 ;
All LITeral values and addresses are given in hexadecimal base.
TYPE-OF returns, not surprisingly, the form of definition along with its execution address. Entering TYPE-OF VLIST returns:
Image of Atom Forth memory map
ATOM FORTH memory map
COLON DEFINITION CFA= # 2FA
If the word is a constant or variable, its present value is also returned, for example:
TYPE-OF TIB
USER VARIABLE
VALUE 336
CFA= # 2E0C
This utility is extremely addictive, as my wife will testify, so beware!
My draft manual consisted of 20 pages of which 17 were dedicated to detailing the assembler (the manual assumes the reader has a basic knowledge of 6502 assembly language programming). As with FORTH Theory & Practice, Dick Harrison has done a good job (other software houses take note) presenting sound, readable documentation.
The FORTH Utilities should be available for purchase now and I stress that this is Acornsoft's prediction, not mine. Cost will be £11.50 (inc VAT) which to my mind is rather expensive. However, it does provide two useful utilities which the FORTHaholic would find difficult to be without.
Computing Today October 1982 cover page   Computing Today October 1982 page 26

Computing Today October 1982 page 27  Computing Today October 1982 page 28