Facility Reference

StrongForth's implementation of the ANS Forth Facility word set is provided as source code in blocks 936 to 939.

Name Word Set Location Comment
AT-XY FACILITY Block 936  
KEY? FACILITY Block 936  
PAGE FACILITY Block 936  
EKEY FACILITY EXT Block 937  
EKEY>CHAR FACILITY EXT Block 937  
EKEY? FACILITY EXT Block 937  
EMIT? FACILITY EXT Block 937  
MS FACILITY EXT Block 939  
TIME&DATE FACILITY EXT Block 938 to 939  

The complete Facility word set becomes available after compiling it into the dictionary with

936 939 THRU

Note that the StrongForth assembler (blocks 100 to 129) is required in order to compile the Facility word set, because some words use BIOS interrupts and are thus implemented as code definitions.

Cursor Positioning

AT-XY is implemented as a code definition, because it calls a BIOS interrupt that does exactly what is specified by ANS Forth.

Unfortunately, the BIOS does not provide a system function that clears the screen. PAGE simply prints 25 new lines and then positions the cursor at the top of the screen using HOME. Note that HOME is not part of the ANS Forth specification.

Keyboard Words

Another BIOS function provides the semantics of KEY?. EKEY? is an alias to KEY?. Extended key codes, that are associated with non-ASCII keys, like the function keys F1 to F12 and the cursor movement keys, are encoded with 0 as an escape key code. If only KEY is being used for keyboard entry, escape sequences have to be decoded manually. An alternative is using EKEY instead of KEY. EKEY detects the escape key code and provides an extended key code by adding 256 to all key codes that are preceded by the escape key code. Note that the output parameter of EKEY is of data type UNSIGNED, because this value is not necessarily an ASCII character.

EKEY>CHAR decodes the value provided by EKEY. It returns a TRUE flag if EKEY delivered an ASCII character, and a FALSE flag if the output of EKEY was an extended key code. However, EKEY>CHAR still returns an item of data type UNSIGNED. A typical application of EKEY>CHAR in StrongForth will look like this:

... EKEY EKEY>CHAR IF CAST CHARACTER ... ELSE ... THEN ...

In this code fragment, the IF branch processes ordinary ASCII characters, while the ELSE branch takes care of extended key codes.

EMIT? always returns TRUE, because the status of the output channel cannot be determined.

The System Clock

The BIOS system clock ticks 18.2 times per second. TICKS returns the value of a double-cell counter, that is incremented with each tick. TICKS is not an ANS Forth word, but it is used in the implementation of MS. MS is supposed to cause a delay in milliseconds, but due to the granularity of the system clock, it actually delays by a period that is a multiple of a tick.

DOS provides two functions that deliver the system time and the system date, respectively. (GET-DATE) returns four unsigned numbers that represent the current day (1 to 31), month (1 to 12), year (1980 to 2099), and the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday). The four unsigned numbers returned by (GET-TIME) represent the current time of the system clock as centiseconds (0 to 99), seconds (0 to 59), minutes (0 to 59) and hours (0 to 23). The ANS Forth word TIME&DATE simply executes these two DOS functions, extracting year, month, day, hour, minute, and second.


Dr. Stephan Becher - January 9th, 2008