The preface to the Win32for manual in the file STARTUP.TXT gives a brief history of this interesting language.
Forth has been used much more widely that many people think. The reason that it is not recognised is that the applications are embedded into products. This package, it is hoped, will continue this tradition.
The features and implementation of the Win32for Forth, given in the Win32for manual introduction, are not quite the same as the implementation in TLM. The fundamental difference is the architecture of the different processors, PIC18F v 80X86. The IRTC compiles subroutine threaded code and optimises the constant use and some operations.
A detailed description of the TLM Forth is given here to assist those wishing to use code definitions in particular. The so called Forth inner interpreter, NEXT, and the associated call, NEST, and return, UNNEST, definitions make up the Forth machine.
This is the heart of a Forth machine. In a subroutine threaded Forth NEXT is a CALL/RCALL instruction. The return address is placed on the return stack by the processor, the address called is called the Code Field Address, CFA.
Every high level Forth word is a subroutine. It is called and the CFA points to the code. The IRTC compiler keeps track of the Forth words and compiles CALL/RCALL instructions to call each word used within a definition.
Each Forth word starts with a :
Every NEST must EXIT, as every Jump to Subroutine must Return from Subroutine. The value on top of the System Stack is popped by a RETURN instruction that is compiled by the ; at the end of each Forth word definition.
Forth is a stack based language. The Return Stack used for calls and returns has been described above. The Data that is to be manipulated is placed on the Data Stack. The processor's FSR0 is used to control this stack. The TLM does however, have an unusual feature. The top Data Stack item is always in the $000, $001. The Data Stack controlled by FSR0 containing any items below this. In a machine code definitions any of the registers must be saved if they are required by the definition, and restored if the definition itself does not affect the Data Stack. This is most easily done by pushing out onto the Return Stack at the beginning of the definition. For use by the tasks, a USER location, SP0, is reserved for saving the Data Stack pointer, the Return Stack pointer is saved on the Data Stack.
In an PIC18F embedded system the Code space is in Flash memory. The Variables must therefore have a RAM area for their contents. These two spaces are controlled by different words.
The Code space is set by ORG. This is similar to the construct in assemblers.
Use: $0200 ORG
The address $0200 is set in PIC18Fxxx.INI. It is the beginning of the Target development code space.
The Variable space is set by VORG.
Use: $0220 VORG
Tests on the validity of the memory spaces are done at compile time. The following VALUEs may be altered to reflect your memory by editing PIC18Fxxx.INI:
$0000 VALUE RAM-START
$02FF VALUE RAM-END
$0000 VALUE ROM-START
$0200 VALUE APP-START
$3FFF VALUE ROM-END
$0000 VALUE EE2-START
$00FF VALUE EE2-END
examples are for the PIC18F248