Classic Computer Magazine Archive COMPUTE! ISSUE 90 / NOVEMBER 1987 / PAGE 96

Directory Menu For IBM

Paul W. Carlson

This handy utility displays a directory of all the BASIC programs on your disk and allows you to load, run, rename, or delete them with just the touch of a key. A color/graphics adapter or equivalent hardware is required, along with BASICA for the PC, GW-BASIC for compatibles, or Cartridge BASIC for the PCjr.


Have you ever wished that managing your BASIC programs was easier? There are BASIC commands to load, run, rename, and delete files, but they can be time-consuming and cumbersome to use. "Directory Menu for IBM" makes performing these BASIC file operations simple and fast.

To get started, type in and save the program below. Save it with a short name that's easy to remember (for example, DM for DISK MENU) so that you can run it quickly—it's a program you're likely to use often. In fact, you'll probably want a copy of the program on any disk with which you'll be doing BASIC programming. The program is only 1667 bytes long, so it won't use much disk space.

Now run the program. You'll see the current directory displayed at the top of the screen followed by a list of all the BASIC programs (.BAS files) in the directory. After the list of files, the total number of free bytes on the disk is shown. The menu selections appear at the bottom of the screen. An arrow will be pointing to the name of the first file in the list. Use the cursor keys to move the arrow. Don't be concerned about moving the arrow too far—the program won't let you move it off of the list.

With the arrow pointing at the file you want to load, run, rename, or delete, simply press the key corresponding to the highlighted letter of the menu selection. If you press N to rename a file, you'll be prompted for the new name. (The program will allow you to enter a name with an extension other than .BAS, but the new name won't appear in the updated directory listing.) After you enter the new name, the directory of BASIC programs will be redisplayed and you can continue with the menu program. The file that you renamed will probably not be in the same location in the list as it was previously.

If you press D, the file the arrow is pointing to will be deleted immediately, so be sure you really want to delete it—you won't get a second chance. After a file is deleted, the directory of BASIC programs is redisplayed and you can continue with the menu program.

If you load or run a program, it will replace the menu program if it is in memory. This means you won't be able to continue with the menu program unless you reload it from disk and run it again.

The program will trap any errors and, after printing an error message, will allow you either to continue or to quit the menu program. There is one exception: If a syntax error is found, the program will stop and display the line containing the syntax error.

How It Works

Directory Menu for IBM uses the PC's memory-mapped video. (Memory-mapped simply means that anything displayed on the screen is also stored at known locations in memory.) Since you may want to use video memory in programs of your own, here's a brief explanation of how it works (for more details, see page 173 of Mapping the IBM PC and PCjr from COMPUTE! Books). Some of the variables involved are NF, the number of files displayed; F, the number of the file that the arrow moves from; T, the number of the file that the arrow moves to; and F$, the name of the file.

The program sets the default segment to &HB800 (line 10). This is the beginning of video memory for the IBM color/graphics adapter. All PEEK and POKE values will now be the number of bytes counting from the beginning of video memory. The program uses the FILES statement to display all the .BAS files on the screen and place the names in video memory (line 40). Then it counts the number of files displayed by PEEKing in video memory and checking for the presence of the period (.) that separates the filename from its BAS extension (line 50). The program POKEs the number 112 into the proper attribute bytes in video memory to highlight the first character for each of the menu selections (lines 70 through 110).

The program reads the names of the files directly from video memory by starting at the memory location corresponding to the beginning of a filename and PEEKing every other memory location (skipping the attribute bytes) until either a space or a period is found (lines 450 through 470). This eliminates the extra spaces, if any, after the filename. The .BAS extension is added to the filename before a file is renamed or deleted.

Directory Menu For IBM

For instructions on entering this program, please refer to " COMPUTR!‘s Guide to Typing In Programs" elsewhere in this issue.

.
AB	1	REM COPYRIGHT 1987 COMPUTE ! PUBLICATIONS, INC. ALL RIGHTS RESERVED.
JB	2	CLS:LOCATE 10, 30:PRINT "COPYRIGHT 1987":LOCATE 11, 24:PRINT "COMPUTE!PUBLICATIONS, INC."
EC	3	LOCATE 12,27:PRINT"ALL Rights Reserved.":FOR I = 1 to 1500:next i
NC	10	T = 0:F = 0:DEF SEG = &HB800:SCREEN 0, 0, 0, 0:WIDTH 80:KEY OFF
FC	20	P$ (17) + CHR$(205) + CHR$ (205) +CHR$(60)
DI	30	ON ERROR GOTO 270
KL	40	CLS:LOCATE,,0:A$ = "F":FILES"*.BAS":NF + 0:PRINT:PRINT
CN	50	K = 176 + 160 * (NF/4) + 36* (NF MOD 4) : j = PEEK (K) : IF J = 46 THEN NF = NF+1: GOTO 50
MC	60	GOSUB 480
NL	70	LOCATE 25, 10, 0:PRINT "Load" : POKE 3879,112
FI	80	LOCATE 25, 20, 0:PRINT "RUN"; : POKE 3879,112
LL	90	LOCATE 25, 30, 0 : PRINT "NAME"; : POKE 3899,112
HH	100	LOCATE 25, 40, 0 : PRINT "DELETE"; : POKE 3919, 112
CE	120	ON KEY (11) GOSUB 500
GE	130	ON KEY (12) GOSUB 520
KE	140	ON KEY (13) GOSUB 540
DE	150	ON KEY (14) GOSUB 560
DL	160	KEY (11) ON : KEY (12) ON : KEY (13) ON : KEY (14) ON
GA	170	A$ = INKEY$ : IF A$ = " " THEN 170
PD	180	KEY (11) OFF : KEY (12) OFF:KEY (13) OFF : KEY (14) OFF
FB	190	A$ < > "L" AND A$ < > "R" THEN 210
DA	200	GOSUB 450 : CLS : PRINT "Searching for " : F $ : ".BAS"
EL	210	IF A$ = "L" THEN LOAD F $
CB	220	IF A$ = "R" THEN LOAD F $,R
DF	230	IF A$ = "D" THEN GOSUB 450 : KILL F$ = ". BAS" : T = 0 : F = 0 : GOTO 40
HC	240	IF A$ = "N" THEN GOSUB 450 : GOTO 330
IB	250	IF A$ < > "Q" THEN 160
BL	260	CLS:ON ERROR GOTO 0:END
IP	270	IF ERR < 51 THEN 260
JL	280	RESUME 290
EN	290	IF A$ = "N" THEN 350
GN	300	IF A$ = "L" OR A$ = "R" THEN 390
BC	310	IF A$ = "D" THEN CLS : GOTO 390
IL	320	IF A$ = "F" THEN 400
OE	330	CLS : PRINT "RENAME "; F $; " . BAS TO "; : LINE INPUT; N $
EC	340	NAME F $ + " . BAS" AS N $ : GOTO 40
BK	350	PRINT CHR $ (7) : PRINT "ERROR -possible causes : "
BH	360	PRINT " New file name was illegal"
IP	370	PRINT " New file name already exists"
ON	380	PRINT " Disk access error" : PRINT CHR $ (7) : PRINT F $; " . BAS not found. " : print : goto 410
ID	400	PRINT CHR$(7): PRINT "NO .BAS files in this directory " : PRINT
ND	410	PRINT "Press C to continue or Q to quit…";
AH	420	R $ = INKEY $ : IF R $ = "C" OR R $ = "C" THEN 40
JJ	430	IF R$ = "q" OR R $ = "q" THEN 260
EL	440	GOTO 420
IJ	450	F$ = " " : E = 160 + 160 * (T\4) + 36 * (T OD 4)
IP	460	U = PEEK (E) : IF U < > 46 AND U< >32 THEN F $ = F $ + CHR $ (U) : E = E + 2 : GOTO 460
NM	470	RETURN
PK	480	RW = F \ 4 + 2 : CL = 18 * (F MOD 4 + 1) - 5 : LOCATE RW,CL,0 : PRINT " ";
OL	490	RW = T \ 4 + 2 : CL = 18 * (T MOD 4 + 1) - 5 :LOCATE RW,CL,0 : PRINT P $; : F = T : RETURN
AA	500	V = F - 4 : IF V > = 0 THEN T = V : GOSUB 480
MB	510	RETURN
PJ	520	V = F - 1 : IF V > = 0 THEN T = V : GOSUB 480
MF	530	RETURN
EF	540	V = F + 1 : IF V < NF THEN T = V : GOSUB 480
NJ	550	RETURN
GE	560	V = F + 4 : IF V < NF THEN T = V : GOSUB 480
NN	570	RETURN