Chapter 10

P21Forth Examples and Demos


P21Forth 1.02

Color Text Demo

Type CLS CDEMO to see a demo of all of the combinations of foreground and background video colors in P21Forth.

WORDS Demo

The word WORDS will display all of the words in the Forth name dictionary. If there is a word in the input stream after the word WORDS then only the words that begin with the same characters as that word will be displayed. WORDS W will display all the words that start with W. WORDS WO will display all the words that begin with WO.

WWORDS Demo

The word WWORDS will display all of the words in the Forth name dictionary like the word WORDS. But the word WWORDS will take multiple words from the input stream and keep displaying the list of words that start with the matching strings until the input stream is exhausted. Thus WWORDS A B C would display all the words starting with A then all the words starting with B then all the words starting with C.

UNUSED Demo

The word UNUSED will display the free unused memory available to the P21Forth system. Initially P21Forth will report more than 900 kilowords of free memory.

NAMES Demo

The word NAMES will display the count of total words and also give the number of CODE words and colon definition words.

Decompiler Demo

The word SEE is the decompiler in P21Forth. This is a very simple decompiler. If an address in a word definition matches the execution address of a word in the Forth dictionary then the name of that word will be displayed rather than the address. Other hex numbers and flow control address will simply be displayed as hex numbers. Type SEE SEE to see the definition of the decompiler. The display will continue until you press the return key twice.

DUMP Demo

To see a memory dump of the DRAM boot code type 0 20 DUMP. The first number is the starting address and the address of the dumped data will be displayed on the left. The second number is the number of cells to dump. The contents of the memory specified will be displayed as both hex numbers, 4 at a time, and the same locations are displayed on the right as ascii characters.

Multitasker Demo

(See the Multitasker demo in Chapter 7)

Environmental Query Demo

The word ENV. will exercise the ANS word ENVIRONMENT? and display all the environmental query strings that were found, and the values associated with them. These indicate a number of things about the implementation details of P21Forth. To run the ENV. demo type

    40 43 THRU HEX ENV.
TASKS Demo

The word TASKS will display the names and status of all of the tasks in the task list. Try the example of the multitasker in Chapter 7, and after a second task has been created and you can wake it up or put it to sleep try the TASKS demo.

Towers of Hanoi Demo

The word HANOI will display the Towers of Hanoi problem. In this demo disks are moved in three piles without ever placing a smaller disk on top of a larger disk. To move the 9 disks from one tower to another requires 512 disk moves. These moves will be visually displayed. This program takes 13 seconds to execute on my 50 Mhz 486 under eForth 2.5, the same program executes in under a second in P21Forth. (The Towers demo is not included in compiled form in P21Forth 1.02, but the source is included in HANOI.FOX on the distribution diskette.)

Graphics Demo

The word DEMO displays a dozen captured full screens of graphics in about 1 second. To do this these graphics must first be captured. The word NEXTBUF returns the next in a series of buffer addresses each time it is called. The word G will capture a full MuP21 video screen and bit block tranfer it to the next graphics buffer. After you boot P21Forth type issue the G command. Then type CLS G to capture a blank screen Now type CLS CDEMO G then type CLS CDEMO CDEMO G, then press the return key 24 times and execute G again. Type CLS ENV. G to run the environmental query demo and capture the last screen. Then type WORDS and when the display stops type G. Type SEE SEE G and after a while press the return key a couple of times. Then type SEE EXIT G and again after a while press the return key a couple of times. Type CLS NAMES TASKS G to capture the screen with name and task information. Then type 880 80 DUMP G to capture the screen from a memory dump. At this point you should have executed G twelve times and filled all of the buffers in this demo. To test this type BUF ? and you should see 10000 displayed. If the number is not 10000 type G again and BUF ? again until it does display 10000 properly. This indicates that all the graphics buffers are now filled with graphic data that has been bit block transfered from the screens. You are ready to run the word DEMO.

The word DEMO is defined as:

: DEMO ( -- )
 BEGIN NEXTBUF PSCR ?KEY UNTIL KEY DROP ;
The BEGIN-UNTIL construct will repeat the words NEXTBUF PSCR ?KEY until a true flag is return by ?KEY when it detects that key has been pressed. Then the program exits the loop reads and discards the key with KEY DROP and exits the word at the ; Each time the word PSCR executes it will move a new image into the video display buffer to form a type of full screen animation when it repeated many times a second.

GUI DEMO

The GUI demo puts the screen in 40X16 character mode, draws a box and places the arrow cursor on the screen. It calls XKEY to read keys and moves the cursor until it sees a CR when it will quit. XKEY interprets 1AH as left cursor, 1CH as up cursor, 19H as right cursor, and 1DH as down cursor.

The demo GUI will move the arrow on the screen, but will not move it off the screen if the graphics window size has not been changed. The demo GUI will continue until a CR (0DH) has been pressed.

To run the GUI demo type the command:

GUI
then use ^Z for left, ^\ for up, ^Y for right, ^] for down, and press Enter when done. Then type
48X24 (or 32X16) CLS WHITE >FG BLACK >BG

End of Chapter 10

Return to Table of Contents

Previous Chapter

Next Chapter