UNDER THE HOOD

Because Fig-forth v2 is a dual segment machine language program, several words and addresses have significance to both the proper operation of the package and to the programmer attempting to direct that performance. Some of these words and addresses have Forth language definitions and meaning to the programmer, while the others are specific to the current build and subject to change. For this reason any attempt at using these values should be managed with extreme care, and are not guaranteed to remain as defined in this chapter.

EXPECT

Quirks: the EXPECT word will filter out any ASCII Line Feed character received from the current input device, treating the value as an invalid character. This allows the process to accept a text file or modem input if a suitable redirection word is defined. Version 2.26 and up saves the count of characters received into the system variable HLD.

FENCE

This system variable defines the end of the compiler dictionary, marking that point beyond which using FORGET would damage the user search chain. While programmers may change this value to include any vocabularies or words relevant to the current project, setting this value below the location of TASK in the Forth vocabulary may cause the system to crash.

IN

This variable holds the offset of the next character to be processed in the current input buffer.

NEXT

This currently returns a zero though is reserved for the multi-processing version of the software.

OUT

This variable contains a count of the number of characters sent to the current display device since the last carriage return, including un-write and backspace keys.

SCR

This variable holds the last edited screen block number.

TIB

This variable contains the memory location of the text input buffer.

WIDTH

This system variable holds the size of the symbols involved in the compiler process, normally 32 characters as the limit. While the user is not expected to change this value doing so will limit the number of characters saved into the user space, however the original count of characters is retained by the compiler. E.g.;

          : NOW_IS_A_LONG_WORD ; -- will store all 18 letters

          HIDDEN 5 WIDTH ! FORTH -- change value

          : NOW_IS_A_LONG_WORD ; -- will store 4 letters

          : NOW_IS_A_LONGER_WORD ; -- does not conflict

          : NOW_IS_A_SAME_WORD ; Isn't Unique! -- does conflict

Font Table

The location of the font table within the kernel space is located at offset location 4 in the user space, pointing to the following structure;

font_tbl: word offset fnt1
word offset fnt2
word offset fnt3
word offset fnt4
word 0
word 0
word 0
word 0

This table contains the offsets within the kernel to the four internal fonts, with four additional entries for user based fonts. User based programs may use these entries to load other fonts or modify an existing font as the need arises, however a check for sufficient kernel space must be performed before using the area and font. Note that this table cannot be extended beyond 8 entries and that the end of the last font in kernel memory is not indicated.

EMJ

This value is stored at offset 6 within the user space and points between two tables inside the Forth kernel, the top of the Modem Buffer and the bottom of the Video Address Table. The Modem Buffer is a character ring buffer described under Basic Input Output, while the Video Address Table is a double word table containing the bank and memory offsets for each screen line in the graphics mode. At present the Modem Buffer is 1024 bytes in size and the Video Address Table is 8192, the video table defining a maximum of 2048 line positions. In location EMJ+1024 Fig-Forth stores the type of card the compiler believes it located upon video detection start-up.

VESA Buffer

This location is stored at offset 8 in the user space, and points to the 512 byte signature returned by VESA if it is installed when Fig-Forth makes its video card detection. (The spec says 256, but I leave twice that for future versions.)

>FILE

This word will return the file control block location of the open file given it, with the following definitions of the record structure;

          word           handle      ; returned by DOS

          word           offset       ; in block screens

          word           address of name string ; in user space

         double-word size on open  ; (as a Forth Double)

The word FILES return the value of 0 >FILES, or the first file control block to be assigned.

CONTEXT and CURRENT

The word CONTEXT returns the address of the Top of the Search Order Buffer, while CURRENT returns the address plus two. The values contained in these locations point to the address containing the location of the top-most word in the vocabulary being searched, pointing to the Name Field Address of the first entry in the search chain.

CODE OPTIMIZER

Version 2.31 and up contain an internal token thread optimizer based upon 25 occurences of source code in which Fig-Forth contains more effective operations. The compiler will replace the token generated code fragments listed below with their optimized equivalents;

Optimizer Operations
Source code fragment Resulting token thread equivalent

drop drop

2drop 

2drop drop

3drop

drop 2drop

3drop

2drop 2drop

4drop

3drop drop

4drop

drop 3drop

4drop

nip nip

2nip

2nip nip

3nip

3nip nip

4nip

nip 2nip

3nip

2nip 2nip

4nip

3nip nip

4nip

nip 3nip

4nip

swap drop

nip

2swap 2drop

dnip

rdrop rdrop

unloop

over swap

pleat

2over 2swap

2pleat

over over

2dup

swap over

tuck

dup n = if

n case:

over = if

case:

variable +constant

[effective address literal]

n +constant

[effective value literal]

constant +constant

[effective value literal]

Note that optimizer operations are cumulative, such that a NIP NIP NIP sequence will result in a single 3NIP token. As to the reason behind the use of an optimizer; it was easier than going back and correcting the code of earlier versions, particularly to take advantage of the CASE: and offset variable or constant operations. Once the peephole was made, creating the above list became rather obvious.

One should note however that the compile only word of ?EXIT literally compiles an IF EXIT THEN sequence. (3 tokens as opposed to one.)

CODE STRUCTURES & MEMORY MAP

Fig-Forth dictionary words are defined following the Cassidy model of this compiler, starting with a string count byte with the highest bit set for the purposes of the TRAVERSE word. The second highest bit is set if the word is immediate, and the third highest bit is used by smudge;

Dictionary entry structure

128 + Immediate*64 + smudge*32 + count

characters of name

last character of name + 128

link address

code field address

parameter(s)

The enforcement of the highest bit being set at the start and end of the Name Field requires that all label defining characters be under 128 on the IBM ASCII table, meaning the extended characters cannot be used for label defining symbols.

BRANCHES

Branch operations in Fig-Forth are defined by a single operative token and an offset to the branch location, which is added to the Machine Instruction Pointer (SI) when the jump takes place;

Redirection Token

Offset in bytes

USER CODE FRAGMENTS

User code is defined by as far jump of the Forth Engine to the user dictionary area, where the code fragment is entered given the conditions listed in Appendix C.

(code) or (;code) token

address of user code

---user code---

Far jump to clean process

MEMORY MODEL

The following table defines the general memory model of the operating compiler;

Segment & Hex Address Contents/Usage

0:-200

Program PSP

0:-180

Dos Command Line

0:-100

empty

0:100

Emtry Point

0:103

Auto Flag

0:104

Dos Shell Command Line

0:116

Shell Parameters

0:12C

Compiler Revision & Attributes

0:130

Cold Start Values & Vectors

0:15C

Start of Code

0:8B68

End of Code (approximate)

0:8B68

VESA Buffer (approximate)

0:AF56

Modem Buffer (approximate)

0:B390

Font Table (approximate)

0:B3A0

Internal Fonts (approximate)

0:DCDE

End of Fonts (approximate)

0:FFE0

Debugger Link Area

0:FFFF

End of Kernel

1:0000

System Save Vectors & User Variables

1:0284

Master User Code Fragment (approx.)

1:028A

Start of ROOT vocabulary (approx.)

1:1A34

End of standard vocabulary (approx.)

1:EBE6

Parameter Stack & TIB start

1:EFDE

Return Stack & First disk buffer

1:FFFF

End of User Space

2:0000

DOS Shell Area

Return to Contents.   Next Chapter.   Previous Chapter.