(1) Compile any code needed for this program. This includes the graphics toolbox, the event handling tools, the EZMenu system, and a random number generator.

(2) Declare a copy of an EZMENU structure as described above. We will be using only one menu.

(3) Define the words and variables that control the drawing mode. The variable DRAW-MODE is set by picking Lines or Boxes from the menu. This variable is then used by another routine to decide what to draw.

(4) Define a word to clear the window. This demonstrates how to call an Amiga library routine from JForth. We will use the Amiga SetRast function to set the entire RastPort to the background color. The first line in CLEAR.WINDOW gets the address of the current RastPort. This variable will be set when the window is opened. The routine is called with the line:

CALL GRAPHICS_LB SetRast

The CALL word in JForth builds a call to the named routine by searching the Amiga "FD" files for the necessary information. It figures out which parameters go in which 68000 register, determines the offset of the routine in the library, then builds the proper 68000 machine code. This system will work with any Amiga library that has an FD file including the ARP library, custom MIDI libraries, or whatever.

(5) The word MY-MENU.INIT initializes the menu. First we set the width for the menu items to 10 pixels. Then we dynamically allocate the structures needed for our 4 menu items with the line:-

4 MY-MENU EZMENU.ALLOC

The word EZMENU.ALLOC allocates enough memory for 4 MenuItems and 4 IntuiText structures and attaches them to MY-MENU. It also allocates space for 4 CFA's. The next command line uses EZMENU.SETUP to give the menu a name. It also initializes all of the Menu, MenuItem, and IntuiText structures to reasonable defaults, then links these structures together into a complete Intuition menu.

We now use the word EZMENU.TEXT! to specify the text for each menu item. Notice how we use the word "0" to generate the NUL terminated, 'C' like, text strings needed by Intuition. We now use EZMENU.CFA[] to tell the EZMenu system what to do when a menu item is picked. We could set each one individually like we did with the text above, but I decided to use a DO LOOP just for fun. We could stop here and have a workable pull down menu. Let's continue, however, and make them a little fancier.

(6) Put a checkmark beside the Lines or Boxes item in the menu to show which one is current. We can use the Amiga's mutual exclusion feature to make one check mark automatically disappear when the other appears. Intuition allows you to give each menu item a bit pattern. When you select a menu item, its pattern tells Intuition which other menu items to turn off. There are 32 bits in the pattern, but we will only look at the 4 lowest bits since we have only four items.

When we select menu item 1, "Boxes" , we want menu item 0, "Lines" to become unchecked. The "Boxes" item would now have the checkmark. The other items will be unaffected. Thus the exclusion pattern for Boxes should have bit 0 set to 1. The bits are numbered from right to left, 0-31. Thus the pattern

Continued