Classic Computer Magazine Archive COMPUTE! ISSUE 65 / OCTOBER 1985 / PAGE 95

Apple II
Pull-Down Menus

Lee Swoboda

With this program, you can add attractive, Macintosh-like pull-down menus and instruction screens to any BASIC program. For all Apple II-series computers with DOS 3.3 or ProDOS.


Apple's Macintosh has forced programmers to reevaluate software for the venerable Apple II. Recent Apple II programs go to some lengths to emulate the Mac's pulldown menus and icons to make the software less intimidating. No amount of programming magic will turn an Apple II into a Mac, but the following programs let you add pull-down menus and instruction screens to any Applesoft BASIC program.
    Two programs are needed to make this happen: a BASIC subroutine you can easily add to the end of any BASIC program, and a machine language (ML) routine that temporarily saves and later restores the text behind the pull-down menu. Although BASIC takes several seconds to move an entire text screen, machine language performs the same task in an instant. Don't worry if you're unfamiliar with machine language. We've listed a BASIC filemaker program that automatically creates the ML routine for you.

Starting Out
To get "Pull-Down Menus" running, you need to type in and save both programs listed below. Program 1 is the filemaker program that automatically saves the ML routine to disk as a binary file named MOVE. Type it in and save a copy, then run it. Program 2 is an example BASIC program that demonstrates pull-down menus. It is designed to run with either DOS 3.3 or ProDOS. If you're using DOS 3.3, type the program exactly as shown. For ProDOS, change line 150 as shown here:

75 150 HIMEN:35840

    Since this program loads the MOVE file from disk, be sure to put the right disk in the drive before you run it. Once you have it running, the program simulates a crude word processor with a screenful of text. You can type on the screen and move the cursor with the arrow keys (use CTRL-J and CTRL-K for the up and down cursor keys if you don't have a IIe or IIc). When you press the ESC key, the pull-down menu appears. Then you can move the selection cursor inside the menu with the cursor keys, and choose a selection by pressing RETURN. Note that the text behind the menu is always restored correctly when you leave the menu.

Create Your Own Menus
The important part of the demonstration program is the subroutine beginning at line 63000. This routine allows you to add pull-down menus to your own programs with a minimum of work: It generates the window shape and calls MOVE at the appropriate time. All you need to do is add lines 63000-63500 to the end of any BASIC program, and follow the steps listed below:
  1. Your program must BLOAD MOVE as shown in lines 180-190 before calling the ML routine.
  2. Set HIMEM immediately (line 150) before you declare any strings or open any files. Use a value of 36914 for DOS 3.3 or 35840 for ProDOS.
  3. Set the variable NN to equal the maximum number of items you will have in the largest menu (line 160). The menu subroutine automatically determines how many items are in each menu and adjusts the size of the menu window accordingly.
  4. DIMension the string array MM$ for the number of menu selection labels you need (line 170). Then fill each array element with a label string, either by READing string DATA as in lines 200-220 or by defining each string expressly (with statements like MM$(1)="Leave menu").
  5. Define the string variable TITLE$ as your menu title (line 470). The menu subroutine automatically centers the title for you.
  6. Provide some means of branching to the rest of your program based on the value of the variable SELECT (line 480). This may be done with ON SELECT GOTO as in this program, or with ON SELECT GOSUB or a series of IF-THEN statements.
    Lines 690-850 of the program show how to use MOVE to add instructions to your programs with out losing the original screen. In this case, CTRL-I is used to request instructions.

Using A Mouse
If you have an Apple mouse, you can use it to call the menu and make selections. This requires several changes in the demonstration program. First, delete lines 320, 330, and 63360-63460. Then change lines 310, 450, and 63350 as follows:

E9 310 PRINT "PRESS ESC KEY OR M
       OUSE BUTTON FOR MENU";
9B 450 GOTO 311
66 63350 HTAB 3: VTAB SELECT + 2
       : INVERSE : PRINT ">" C
       HR$ (8);s NORMAL

Now add these lines:

D2 235 PRINT : HOME : PRINT D$"P
       R442"s PRINT CHRS (1): PRI
       NT D$"PR#0"
0A 311 VTAB 15: HTAB 1: PRINT CH
       R$ (13)D$"IN#2"
55 312 VTAB 23: HTAB 40s INPUT "
       ";X,Y,B0
IF 313 IF B0 = 1 OR B0 < 0 THEN
       316
80 314 VTAB CV: HTAB CH: FLASH :
        PRINT " ";: NORMAL
AB 315 GOTO 312
C2 316 PRINT D$"IN#0"
57 317 IF B0 = 1 THEN IN$ = CHRS
        (27): GOTO 319
8F 318 IN$ = CHR$ ( PEEK ( - 163
       84) - 128)
34 319 POKE - 16368,0
BD 320 VTAB CV: HTAB CH: PRINT "
        ";
F7 395 IF CH > 0 THEN HTAB CH
79 396 IF CV > 0 THEN VTAB CV
F8 63360 VTAB 1: HTAB LMAX + 5:
       PRINT : HTAB LMAX + 5:
       PRINT D$"IN#2": VTAB 1:
        HTAB LMAX + 5: INPUT "
       ";X0,Y0,B0
61 63370 IF B0 = 1 THEN 63430
80 63380 Y0 = INT (Y0 / 10)
6B 63390 VTAB SELECT + 2: HTAB 3
       : PRINT " ";
C9 63400 SELECT = Y0: IF SELECT
       > NITEMS THEN SELECT =
       NITEMS
3D 63410 IF SELECT < 1 THEN SELE
       CT = 1
04 63420 GOTO 63350
DC 63430 PRINT D$"IN#0"

    If you're using ProDOS, change line 311 to the following:

01 311 VTAB 15: HTAB 1: PRINT D$
       "IN#2"

    The PR#2 and IN#2 in lines 235, 311, and 63360 assume the mouse interface is in slot 2. If your interface is in another slot, substitute the appropriate slot number in those lines. If you have an Apple IIc, substitute PR#4 and IN#4 for PR#2 and IN#2 in those lines. (Although the IIc doesn't have physical slots, the mouse is in logical slot 4.) Once you've made all the changes, install the mouse and rerun the program. It works much as described above, using the mouse button instead of RETURN for menu selections.

For instructions on entering these listings,
please refer to "COMPUTEI's Guide to Typing
In Programs" published bimonthly in COMPUTE!.


Program 1: MOVE Filemaker

B7 100 REM BASIC PROGRAM FOR
AD 110 REM GENERATING THE
44 120 REM BINARY FILE
29 130 REM 'MOVE'
4C 140 HOME
IC 150 VTAB 12: PRINT "WORKING .
       .."
92 160 FOR I = 0 TO 459
21 170 READ A
CC 180 POKE 36915 + I,A
D1 190 VTAB 12: HTAB 13: PRINT I
        + 1
DE 200 NEXT I
FF 210 PRINT CHR$ (4)"BSAVE MOVE
       ,A36915, L460"
2A 220 PRINT : PRINT "DONE!"
AB 230 DATA 173,89,170,72,165,21
       7,72,165,118,72,169
3F 240 DATA 2,133,118,169,255,13
       3,217,169,191,133,51
5D 250 DATA 169,0,133,243,76,86,
       144,76,86,76,86
D8 260 DATA 76,86,169,80,133,133
       ,169,144,160,0,162
33 270 DATA 5,32,254,144,76,104,
       144,76,104,169,102
35 280 DATA 133,133,169,144,160,
       0,162,1,32,254,144
97 290 DATA 169,0,141,80,144,169
       ,4,141,81,144,173
F5 300 DATA 81,144,201,8,48,14,2
       08,9,173,80,144
60 310 DATA 201,0,144,5,240,3,76
       ,234,144,173,80
7D 320 DATA 144,141,161,144,173,
       81,144,141,162,144,173
99 330 DATA 0,16,141,82,144,169,
       0,141,83,144,24
D1 340 DATA 169,255,109,102,144,
       141,84,144,169,145,109
0D 350 DATA 103,144,141,85,144,1
       73,84,144,141,204,144
8D 360 DATA 173,85,144,141,205,1
       44,173,82,144,141,0
D9 370 DATA 16,24,173,102,144,10
       5,1,141,102,144,173
6E 380 DATA 103,144,105,0,141,10
       3,144,238,80,144,208
63 390 DATA 3,238,81,144,76,127,
       144,104,133,118,104
35 400 DATA 133,217,104,141,89,1
       70,169,141,141,1,2
C2 410 DATA 169,1,133,52,96,133,
       134,132,135,160,0
88 420 DATA 169,0,145,133,200,20
       8,2,230,134,138,208
F3 430 DATA 4,198,135,48,4,202,7
       6,4,145,96,173
83 440 DATA 89,170,72,165,217,72
       ,165,118,72,169,2
BA 450 DATA 133,118,169,255,133,
       217,169,191,133,51,169
44 460 DATA 0,133,243,76,60,145,
       76,60,76,60,76
E6 470 DATA 60,169,54,133,133,16
       9,145,160,0,162,5
84 480 DATA 32,228,145,76,78,145
       ,76,78,169,76,133
7A 490 DATA 133,169,145,160,0,16
       2,1,32,228,145,169
E7 500 DATA 255,141,54,145,169,1
       45,141,55,145,173,55
5A 510 DATA 145,201,149,48,14,20
       8,9,173,54,145,201
85 520 DATA 255,144,5,240,3,76,2
       08,145,173,54,145
A7 530 DATA 141,135,145,173,55,1
       45,141,136,145,173,0
1E 540 DATA 16,141,56,145,169,0,
       141,57,145,24,169
B0 550 DATA 0,109,76,145,141,58,
       145,169,4,109,77
74 560 DATA 145,141,59,145,173,5
       8,145,141,178,145,173
4D 570 DATA 59,145,141,179,145,1
       73,56,145,141,0,16
0E 580 DATA 24,173,76,145,105,1,
       141,76,145,173,77
04 590 DATA 145,105,0,141,77,145
       ,238,54,145,208,3
07 600 DATA 238,55,145,76,101,14
       5,104,133,118,104,133
22 610 DATA 217,104,141,89,170,1
       69,141,141,1,2,169
33 620 DATA 1,133,52,96,133,134,
       132,135,160,0,169
41 630 DATA 0,145,133,200,208,2,
       230,134,138,208,4
C9 640 DATA 198,135,48,4,202,76,
       234,145,96

Program 2: Apple II Pull-
Down Menus


1C 100 REM LINES 150-850 ARE
DB 110 REM A SAMPLE PROGRAM
EA 120 REM DEMONSTRATING
D6 130 REM PULL-DOWN MENUS
BA 140 REM
5B 150 HIMEM: 36914: REM FOR DOS
        3.3 ONLY. FOR PRODOS USE
        35840
14 160 NN = 20: REM   MAXIMUM NU
       MBER OF ITEMS IN ANY MENU
C6 170 DIM MM$(NN): REM MM$=MENU
        SELECTIONS
62 180 D$ = CHRS (4)
5C 190 PRINT D$"BLOAD MOVE"
FD 200 FOR I = 1 TO 5
BE 210 READ MMS(I)
E2 220 NEXT I
4B 230 HOME
41 240 FOR I = 1 TO 15
57 250 PRINT "THIS IS A SAMPLE P
       ULL-DOWN MENU. ";
EA 260 NEXT I
B3 270 CV = 13:CH = 16
12 280 VTAB 21: HTAB 1: PRINT "-
       -------------------------
       -------------": REM 39 DA
       SHES
BE 290 PRINT TAB( 5)"USE ARROW K
       EYS TO MOVE CURSOR"
35 300 PRINT TAB( 5)"PRESS CTRL-
       I FOR INSTRUCTIONS"
36 310 PRINT TAB( 8)"PRESS ESC K
       EY FOR MENU ";
8A 320 VTAB CV: HTAB CH
91 330 GET IN$
62 340 IF IN$ = CHR$ (9) THEN GO
       SUB 690
31 350 IF IN$ = CHR$ (27) THEN 4
       70
C4 360 IF IN$ = CHR$ (8) THEN CH
       = CH - 1
71 370 IF IN$ = CHR$ (21) THEN C
       H = CH + 1
D9 380 IF IN$ = CHR$ (11) THEN C
       V = CV - 1
53 390 IF IN$ = CHR$ (10) THEN C
       V = CV + 1
BA 400 IF IN$ > CHR$ (31) THEN P
       RINT IN$;:CH = CH + 1: IF
        CH > 40 THEN CH = 1:CV =
        CV + 1
73 410 IF CH < 1 THEN CH = 1
C6 420 IF CH > 40 THEN CH = 40
7E 430 IF CV < 1 THEN CV = 1
4F 440 IF CV > 20 THEN CV = 20
9A 450 GOTO 320
36 460 REM THE FOLLOWING LINE AC
       TIVATES THE MENU
33 470 TITLE$ = "MENU": GOSUB 63
       040
59 480 ON SELECT GOTO 280,490,50
       0,510,590
54 90 HOME : PRINT "THE FIRST F
      UNCTION OF YOUR PROGRAM G
      OES HERE": GOTO 520
74 500 HOME : PRINT "THE SECOND
       FUNCTION OF YOUR PROGRAM
       GOESHERE": GOTO 520
08 510 HOME : PRINT "THE THIRD F
       UNCTION OF YOUR PROGRAM G
       OES HERE": GOTO 520
3F 520 VTAB 24: PRINT "PRESS ANY
       KEY TO CONTINUE ... ";
D7 530 GET A$
35 540 FOR I = 1 TO NITEMS
97 550 MM$ (I) = ""
ED 560 NEXT I
D0 570 RESTORE
1F 580 GOTO 200
25 590 HOME : PRINT "GOOD-BYE!":
        END
99 600 DATA "LEAVE MENU"
CD 610 DATA "FIRST SELECTION"
71 620 DATA "SECOND SELECTION"
B0 630 DATA "THIRD SELECTION"
AE 640 DATA "QUIT PROGRAM"
98 650 END
93 660 REM
8E 670 REM INSTRUCTIONS
97 680 REM
6C 690 CALL 36915
D5 700 HOME : INVERSE : PRINT BL
       ANK$
DC 710 VTAB 1: HTAB 14: PRINT "I
       NSTRUCTIONS": NORMAL : VT
       AB 3
68 750 PRINT "FOR THIS SAMPLE PR
       OGRAM, YOU CAN MOVE"
12 760 PRINT "THE CURSOR WITH TH
       E ARROW KEYS AND TYPE"
39 770 PRINT "ON THE SCREEN.  WH
       EN YOU PRESS ESC, THE"
64 780 PRINT "COMPUTER WILL DISP
       LAY A PULL DOWN MENU."
30 790 PRINT "USE THE ARROW KEYS
        TO MOVE THE SELEC-"
47 800 PRINT "TION CURSOR TO THE
        DESIRED OPTION, THEN"
9A 810 PRINT "PRESS RETURN TO SE
       LECT IT."
42 820 VTAB 24: PRINT "PRESS ANY
        KEY TO CONTINUE ... ";
DA 830 GET A$
61 840 CALL 37145
22 850 RETURN
A5 62999 REM #63000
24 63000 REM
EA 63010 REM PULL-DOWN MENU
81 63020 REM SUBROUTINE
3C 63030 REM
90 63040 BLANK$ = "
                              
         ": REM 39 SPACES
A4 63050 LMAX = 0:NITEMS = 0
53 63060 REM DETERMINE MENU SIZE
24 63070 FOR II = 1 TO NN
59 63080 IF MM$(II) = "" THEN 63
       120
A3 63090 LL = LEN (MM$(II))
62 63100 IF LL > LMAX THEN LMAX
       = LL
C2 63110 NITEMS = NITEMS + 1
CC 63120 NEXT II
65 63130 IF LMAX > 28 THEN PRINT
        "NAME IS TOO LONG": EN
       D
83 63140 REM SAVE SCREEN TEXT
9B 63150 CALL 36915
A3 63160 REM DISPLAY MENU
BA 63170 POKE 32,5: POKE 33,LMAX
        + 5: POKE 34,0: POKE 3
       5,NITEMS + 4: REM SET T
       EXT WINDOW FOR MENU SIZ
       E
6F 63180 HOME
32 63190 INVERSE : PRINT LEFT$ (
       BL$,LMAX + 5)
D4 63200 VTAB 1: HTAB 3 + ((LMAX
        - LEN (TITLE$)) / 2):
       PRINT TITLE$
C0 63210 FOR II = 1 TO NITEMS +
       2
0C 63220 VTAB II + 1: HTAB 1: PR
       INT " ";
6C 63230 HTAB LMAX + 5: PRINT "
       ";
E0 63240 NEXT II
C0 63250 POKE 35,24
0F 63260 PRINT LEFT$ (BL$,LMAX +
        5);
17 63270 POKE 35,NITEMS + 4
D0 63280 VTAB 1
7D 63290 NORMAL
AB 63300 FOR II = 1 TO NITEMS
78 63310 HTAB 4: VTAB II + 2: PR
       INT MM$(II)
D4 63320 NEXT II
03 63330 REM MAKE SELECTION
99 63340 SELECT = 1
88 63350 HTAB 3: VTAB SELECT + 2
       : PRINT ">" CHR$ (8);
43 63360 GET SELECT$
91 63370 HTAB 3: VTAB SELECT + 2
       : PRINT " "
A4 63380 IF SELECT$ = CHR$ (13)
       THEN 63480
DF 63390 IF SELECT$ < > CHR$ (10
       ) AND SELECT$ < > CHR$
      (21) THEN 63430
18 63400 SELECT = SELECT + 1
06 63410 IF SELECT > NITEMS THEN
        SELECT = 1
04 63420 GOTO 63350
56 63430 IF SELECT$ < > CHR$ (11
       ) AND SELECT$ < > CHR$
       (8) GOTO 63350
40 63440 SELECT = SELECT - 1
83 63450 IF SELECT < 1 THEN SELE
       CT = NITEMS
24 63460 GOTO 63350
5C 63470 REM RESTORE SCREEN TEXT
B3 63480 CALL 37145
94 63490 POKE 32,0: POKE 33,40:
       POKE 34,0: POKE 35,24:
       REM RETURN THE TEXT WI
       NDOW TO NORMAL
72 63500 RETURN