Pull-Down Menus
- Type
- Utility
- Category
- Programming demo: pull-down menu subroutines
- Author
- Marc Abramowitz
- Published in
- Antic, February/March 1990 (Vol. 8, No. 8)
- Year
- 1990
- Language
- Atari BASIC
- Requirements
- Atari 8-bit, Atari BASIC (the magazine specified 48K and a disk drive); joystick optional
About the program
By 1990 pull-down menus were everywhere on the Macintosh, the ST and other business computers. Marc Abramowitz of Staten Island, New York, whose game Red Squares had appeared in Antic the previous July, wanted them in his own 8-bit programs. His point was that you can look into a sub-menu without committing to it. With an ordinary numbered menu you have to pick an option, find it's the wrong one and back out again.
Pull-Down Menus is a demo, not a working application. The menu bar offers DRAW, EDIT and LAYER for an imaginary drawing program, and choosing an item simply prints its name. The subroutines are written so that you can lift them into your own BASIC programs.
Typing it in
The only hard line is 470, a short machine-language routine stored in a string. The magazine offered a short program to write it to LINES.LST for merging; the disk listing here includes it. Line 180's {DEL LINE} codes and the {INS LINE} codes in lines 300–330 are ESC followed by SHIFT-DELETE or SHIFT-INSERT. The menu frame uses CTRL-key graphics ({CTRL-U}, {CTRL-V}, {CTRL-B} and inverse {CTRL-K}, {CTRL-L}, {CTRL-I}, {CTRL-O}), typed by holding CTRL and pressing the letter, with the Atari key for the inverse ones. The disk version has no TYPO II codes.
How to use it
RUN it. Move along the menu bar with the joystick or the arrow keys (no CTRL needed), and press the trigger, the down arrow or RETURN to pull down a sub-menu. Inside a sub-menu, up/down moves the highlight, left/right jumps straight to the neighbouring menu, and ESC goes back to the bar. Press the trigger or RETURN to choose. The choice is printed on the screen, and another press starts again. Abramowitz warned that the trigger should be pressed only once.
How it works
- Menus are fixed-width strings. Each item takes nine characters of
M$(line 120 for the bar, lines 130–150 for the sub-menus), so item n starts at(n-1)*9.Nholds the number of items andXMthe screen column. - Highlighting in machine code.
INV(line 470) adds 128 to a run of bytes, which turns text inverse. Line 190 copies the menu toA$, inverts just the selected nine characters, and prints the lot. Called asD=USR(INV,address,count), it's useful in any program. - Pulling down with INSERT LINE. Lines 300–330 position the cursor on row 1 and print an insert-line code before each row of the frame. Each new row pushes the rows already drawn down the screen, and the rest of the screen moves with them. Line 180 later deletes the lines again, which "rolls the menu back up". Because each item is inserted above the previous one, the items appear in reverse order (on the LAYER menu MAKE ends up at the bottom), and line 440 converts the highlighted row back with
Y2=N-Y+1. - Two inputs at once. Lines 210–230 and 350 read
STICK(0),STRIG(0)and the last-key register (764) together, so the joystick and the arrow keys work interchangeably.
Using it in your own programs
Abramowitz's recipe: set background B and text brightness T in line 100; put each menu in M$ as nine-character items padded with spaces; set N and XM; then GOSUB 180 for the top bar or GOSUB 300 for a sub-menu. To change the number of top-level menus, add or remove lines in 130–150.
Listing
10 REM PULLDOWN MENUS
11 REM BY MARC ABRAMOWITZ
12 REM (C)1990, ANTIC PUBLISHING INC.
20 REM Pulldown Menu Subroutine DEMO
30 REM User to modify and use these subroutines in his/her own programs
100 B=0:T=14:X=1:DIM A$(99),M$(99)
110 GRAPHICS 0:POKE 709,T:POKE 710,B:POKE 752,1:GOSUB 470
120 M$=" DRAW EDIT LAYER ":N=3:XM=5:GOSUB 180:REM GO TO MAIN MENU
130 IF X=1 THEN M$="LINE CIRCLE SQUARE ":N=3:XM=5
140 IF X=2 THEN M$="ERASE COPY MOVE ":N=3:XM=14
150 IF X=3 THEN M$="MAKE SET LTYPE COLOR ":N=4:XM=23
160 GOSUB 300:REM GO TO SUB-MENU
170 POSITION XM+1,12:? M$(A+1,A+6):REM PRINT CHOICE
171 FOR LOO=1 TO 100:NEXT LOO
172 IF STRIG(0)=0 OR PEEK(764)=12 THEN RUN
173 GOTO 172
175 REM {inv}* MAIN MENU (TOP) *{/inv}
180 POSITION 0,1:? "{DEL LINE}{DEL LINE}{DEL LINE}{DEL LINE}{DEL LINE}{DEL LINE}{DEL LINE}":IF FL THEN GOTO 240
190 A=(X*9)-9:A$=M$:D=USR(INV,ADR(A$)+A,8):POSITION XM,0:? A$
200 IF FL AND FL2 THEN FL=0:FL2=0:RETURN
205 REM {inv}* MAKE A SELECTION *{/inv}
210 ST=STICK(0):TR=STRIG(0):K=PEEK(764)
220 IF K=255 AND ST=15 AND TR=1 THEN 210
230 IF K=12 OR K=15 OR TR=0 THEN RETURN
240 IF K=6 OR K=134 OR ST=11 THEN X=X-1
250 IF K=7 OR K=135 OR ST=7 THEN X=X+1
260 IF X<1 THEN X=N
270 IF X>N THEN X=1
280 POKE 764,255:GOTO 190
290 REM {inv}* DRAW SUB-MENU *{/inv}
300 POSITION 0,1:? "{INS LINE}";:POSITION XM,1:? "{inv}{CTRL-K}{/inv}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{inv}{CTRL-L}{/inv}"
310 FOR I=1 TO N
320 A=(I*9)-9:POSITION 0,1:? "{INS LINE}";:POSITION XM,1:? "{CTRL-V}";M$(A+1,A+6);"{CTRL-B}":NEXT I
330 POSITION 0,1:? "{INS LINE}";:POSITION XM,1:? "{inv}{CTRL-I}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-U}{CTRL-O}{/inv}"
340 POKE 764,255:Y=1:GOTO 440
345 REM {inv}* MAKE A SELECTION *{/inv}
350 ST=STICK(0):TR=STRIG(0):K=PEEK(764):IF K=255 AND ST=15 AND TR=1 THEN 350
360 POKE 764,255:POSITION XM+1,Y+1:? M$(A+1,A+6)
370 IF K=12 OR TR=0 THEN RETURN
380 IF K=6 OR K=7 OR K=134 OR K=135 OR ST=7 OR ST=11 THEN FL=1:FL2=1:POP :GOTO 120
390 IF K=28 THEN FL=1:FL2=0:POP :GOTO 120
400 IF K=14 OR K=142 OR ST=14 THEN Y=Y-1
410 IF K=15 OR K=143 OR ST=13 THEN Y=Y+1
420 IF Y<1 THEN Y=N
430 IF Y>N THEN Y=1
440 Y2=N-Y+1:A=(Y2*9)-9
450 A$=M$:POSITION XM+1,Y+1:D=USR(INV,ADR(A$)+A,8):? A$(A+1,A+6):GOTO 350
460 REM {inv}* ML INVERT ROUTINE *{/inv}
470 INV=ADR("h{inv}X{/inv}{CTRL-X}h{inv}{CTRL-E}L{/inv}h{inv}{CTRL-E}K{/inv}h{inv}{CTRL-E}O{/inv}h{inv}{CTRL-E}N {/inv}{CTRL-,}{inv}1K{/inv}i{inv}{CTRL-,}{CTRL-Q}KHDNPu{/inv}{CTRL-.}"):RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: PULLDOWN.BAS.
Credits
- Program listing: Pull-Down Menus — program listing (Antic, February/March 1990 (Vol. 8, No. 8)) — Marc Abramowitz
- Picture: The LAYER menu pulled down: built upwards with insert-line codes, so its items appear in reverse order. — Marc Abramowitz (program); screenshot by the site
- Antic magazine scan (OCR text layer), February/March 1990, pp. 29-30: Pull-Down Menus, by Marc Abramowitz — Rufus Reynolds; Internet Archive, 1990
- Antic Software Archive — February/March 1990 - Vol. 8 No. 8 disk: PULLDOWN.BAS — Marc Abramowitz, 1990
