P21Forth 1.02
P21Forth supports colored text and graphics output to a video display, and it also supports a serial or parallel terminal or both. The user may select the type of input and output that they want to use. A terminal or at least a keyboard must be attached to the MuP21 system to use P21Forth.
When P21Forth starts it puts the message P21Forth 1.0 on the video screen and looks for a parallel or serial keyboard on the input port. If a serial terminal or keyboard is being used P21Forth will try to determine the speed of the attached device. P21Forth reads a `b' character from the '' serial device and initializes the serial input output routine.
This is done by the Forth word KEYTEST. It checks the keyboard and switches the input vector to a parallel keyboard if it finds one. Otherwise it switches the input vector to the code for the serial keyboard, and waits for a `b' character to get the serial timing using the word INITSERIAL.
The word SERIAL sets the input vector stored in the variable `?RX to the routine ?RS which reads the serial keyboard. The word PARALLEL sets the input vector to ?RX which reads a parallel keyboard. The word BOTH sets the input vector to both which will read from either keyboard if two are attached.
The multitasker is also involved in keyboard input. To turn on the multitasker to switch tasks while it waits for keyboard input with the parallel keyboard set the input vector to P?RX with the command:
` P?RX `?RX !To turn on the multitasker to switch tasks while it waits for keyboard input with the serial keyboard you need to first create a word to do this. This can be done with the command:
: P?RS ( -- c -1 ) PAUSE ?RS ;You should then set the input vector to P?RS with the command:
` P?RS `?RX !The word OUT will output one character from the stack to the parallel port. The word TX! outputs one character from the stack to the video display via OK. The word TS sends one character from the stack to the serial port.
EMIT is the Forth word to output a character to the system output device. It is vectored though the word `EMIT. The word `EMIT is a variable that holds the execution vector for the EMIT. At boot the variable `EMIT will contain the address of TX! so the default output device is the video display. To set the output device to the serial port issue the command:
` TS `EMIT !Or you can define a word to do this with the command SERIAL- OUT with the command:
: SERIAL-OUT ( c -- ) ` TS `EMIT ! ;To set the output device to the parallel port issue the command:
` OUT `EMIT !Or you can define a word to do this with the command PARALLEL-OUT with the command:
: PARALLEL-OUT ( c -- ) ` OUT `EMIT ! ;To set the output device to the video display issue the command:
` TX! `EMIT !Or you can define a word to do this with the command VIDEO- OUT with the command:
: VIDEO-OUT ( c -- ) ` OUT `EMIT ! ;To set the output device to both the video display and the serial port you need to first define a word to peform this function. To do this issue the command:
: VIDEO-SERIAL-OUT ( c -- ) DUP TX! TS ;Then you can set the vector for EMIT with the command:
` VIDEO-SERIAL-OUT `EMIT !Or you can define a word to do this with the command:
: SET-VIDEO-SERIAL-OUT ( c -- ) ` VIDEO-SERIAL-OUT `EMIT ! ;
OUT ( c -- ) 8 bit parallel output IN ( -- c ) 8 bit parallel output KEYTEST ( -- ) check for parallel or serial keyboard keytest ( -- ) used with KEYTEST BOTH ( -- ) set up SERIAL and PARALLEL keyboards both ( -- ) used in BOTH PARALLEL ( -- ) set up PARALLEL keyboard SERIAL ( -- ) set up SERIAL keyboard TS ( c -- ) transmit character to serial port INITSERIAL ( -- ) read a `b' character to set timing ?RS ( -- 0 | c -1 ) check serial keyboard status KEY ( -- c ) read key from whatever keyboard P?RX ( -- 0 | c -1 ) multitasking parallel keyboard input P?RS ( -- 0 | c -1 ) multitasking serial keyboard input TX! ( c -- ) send character to video output ?RX ( -- 0 | c -1 ) check parallel keyboard status `?KEY ( -- n ) vector for ?KEY in KEY `EMIT ( -- n ) ector for EMIT ?KEY ( 0 | c -1 ) check system keyboard status EMIT ( c -- ) output characterP?RS is not compiled in the boot image of P21Forth 1.02, instead it can be loaded from a disk block by the command B LOAD. This will load P?RS, MULTI-SERIAL, MULTI-PARALLEL, SINGLE-SERIAL, and SINGLE-PARALLEL. These words are discussed in the multitasking demo explanation in chapter 7.
character set (3.1.2 Character types, 6.1.1320 EMIT, 6.1.1750 KEY);
P21Forth uses vectored output. The variable 'EMIT holds the execution vector for EMIT. ' TX! 'EMIT ! will set the user output device to the MuP21 video output. ' TS! 'EMIT ! will set the user output device to the serial port.