MASS STORAGE UTILITIES FOR THE HP-41 -- PART II Rapid Access to Existing Files By Michael Markov The HP-82161 Cassette Drive has been a real boon to HP-41 users. It provides ample storage capacity and relatively rapid access, especially when compared to the WAND or the CARD READER. It also eliminated the relatively heavy drain these units placed on the calculator batteries. The new HP-IL disc drives provide faster access, primarily because the search/rewind operations now take little or no time. For example, the maximum data access time is only 1.742 seconds for the HP-9114A disc drive. Disc drives have one major disadvantage: the power requirement is much greater! You can discharge the HP-88014A battery pack in about 40 minutes of continuous read or write operations. The 3 Watts HP82059B recharger helps, but not much: it provides about half the rated maximum input power of this battery pack. Also, peak power demand is considerably greater than the battery pack maximum power input -- recharging to the 80% level takes about 5 hours. If you have many files stored on any medium (disc or cassette), you will find that accessing files near the end of the directory takes a long time. Power consumption increases dramatically, and a new problem arises: medium wear in the directory area. These problems are especially noticable by HP-41 users because HP-41 files usually are shorter. Thus, you must work with longer directories if you want to use the full capacity of your storage media. Also, when compared to other controllers, the HP-41 is slow. This means that your drive must be "ON" for longer periods of time, thus using more power. The DIRL, DIRLX, GDIRX and SRCHX utilities were developed to overcome the above problems: 1. GDIRX (Get DIRectory by X) allows you to bypass the lengthy directory search, which can take more time and power than copying an entire file into RAM. You must however provide the file number in X. If you enter a bad file number (one that addresses a file directory entry that is not stored in the same directory sector as the target entry), no big problem: you will go through the normal MCODE directory search. 2. DIRL and DIRLX are used to get the file numbers you need to use GDIRX. DIRL is similar to DIR in that it starts at the begining of the directory. It numbers the files, including purged files (if any), prints the file name, and three numbers which tell you the file type and the start address (logical track, sector). It is intended to complement normal DIR listings. DIRLX works exactly like DIRL. The main difference is that you specify in X a file number. The listing starts with the directory sector which holds the entry you specified. 3. SRCHX is a friendly variant of GDIRX that allows you to do a directory search starting with the file number you put in X. It allows you to use normal DIR listings and ignore the posibility of purged files. The directory search is limited to three sectors, starting with the sector that holds the file specified in X. This is done to avoid potentially time consuming user code directory searches. The three sector search will allow for the existance of 15 to 23 purged files between the start of the directory and the target file, depending on the location of the target entry within the directory sector. USER INSTRUCTIONS: Extended IO ROM required, as well as a drive and an HP-IL interface. -GDIRX: If you want to avoid the directory search for file 223, enter 223 into register X. XEQ "GDIRX". You now can use GETAS, READP, READSUB, READK, READS, READA, SEEKR, READR, ZERO & WRTR normally -- just follow the instructions in the Owner's Manual(s). READRX and WRTRX also work normally, but keep in mind the medium must be positioned to the data file by SEEKR or some other data file function. GDIRX uses the stack and the ALPHA registers. It restores register M, so that a filename (seven characters max) may be put into ALPHA before you use GDIRX. This is an option, not a requirement. It allows you to use the filename if it is already in ALPHA. With GETAS, if you want to use an extended memory destination file name that is different from the mass storage file name, you must enter the filenames into ALPHA after you execute GDIRX. -SRCHX also uses a file number in register X. However, with SRCHX, you MUST also have the mass storage file name in the ALPHA register, and nothing else! The file name is used for the directory search. Seven character file names may be used. Destination file names (and the comma separator) may be appended AFTER you XEQ "SRCHX". GDIRX and SRCHX may be used as subroutines in a program. You should use extra care when you enter the target filename and file number: errors will eventually mean that you will go through the entire directory to get a "NOT FOUND" error message. The calling sequences should generally go as follows: 223 XEQ "GDIRX" "FILENAME" nn SEEKR "FILEAME" ... 125 XEQ "GDIRX" READP "FILENAME" 198 XEQ "SRCHX" READS -DIRL is used exactly like DIR. Any HP-IL printer device or video interface will work. Be sure you are in the AUTOIO and ADRON modes. Avoid trace mode. -DIRLX is used like DIRL. You must provide a file number in X that determines where the listing starts. DIRL and DIRLX use the FMT instruction. This function helps provide column formating when using the HP82162A printer. Other printers may respond to FMT in a different way: they accumulate two format specifier bytes. These bytes, at least for the MC Video Interface and the HP82905 printer, can be used instead of " " ACA or 32 ACCHR ACCHR. This saves bytes. With other printers, you may have to replace FMT with one of these sequences. THEORY: The HP82160A interface uses drive buffer 1 as an extended directory storage area. Specifically, it holds a copy of the directory sector last used, unless the drive is cleared. Most mass storage functions (but not functions that create new directory entries) will first check the contents of buffer 1 before calling the subroutine that carries out the full-fledged directory search. If the entry is there, you go directly to the file without wasting time or power. GDIRX and SRCHX go to the directory sector that should hold the file entry you want, based on the file number you enter into X. SRCHX then makes sure the file name you gave it is indeed there, while GDIRX immediatly stores it in buffer 1, where it can be used by the MCODE functions. By editing the contents of buffer 1, you can trick the HP92160 module into believing that a secured file is unsecured, or that a WRTA file is in fact a data file. In fact, you could build an entire directory entry to recover files after the directory has been ruined. (Maybe Part IV of this series?) SYNTHETIC PROGRAM LINES: -GDIRX: 09: RCL M: 144, 117 10: "D": 242, 68, 0. 25: STO M: 145, 117. -SRCHX: 09: Append 7 space- not synthetic. 12: RCL M: 144, 117 13: "D": 242, 68, 0. 29: X<>O: 206, 119. 39: STO M: 145, 117. -DIRL & DIRLX: 11: 242, 68, 0. 34: " ": 241, 32 - not synthetic. One space. LINE BY LINE ANALYSIS: -GDIRX: Lines 2-5 compute the address of the directory sector you want. Lines 6-8 select the mass storage device as the primary device. Line 9 saves the filename in ALPHA (if any) for future use. Lines 10-16 position the drive to the desired directory entry, and line 19 copies the content of the sector to buffer 0. The LBL 09 loop is a time delay that gives the drive time to seek the desired sector. This time delay is needed for the digital cassette drive. Lines 22-23 copy buffer 0 to buffer 1, and lines 24-25 restore the filename (if any) to the ALPHA register. The CLST is optional. -SRCHX: Lines 2-8 - same as GDIRX. Lines 9-11 add the default fill (space, hex 20) for the 10 character filename field. Since HP-41 file names have 7 characters maximum, line 9 appends 7 spaces. Lines 13-24 do the same job as GDIRX lines 10-21: go copy the desired sector to buffer 1. At this point, since we may have to read several sectors before we find the right entry, it makes sense to remain in the DDT2 mode. This means we must perform the filename test before we read the whole entry, or we could find ourselves reading the NEXT sector... The LBL 00 loop uses the 16 (line 6) which was stored in LASTX by FINDAID as a counter to check the filenames found in the first two sectors to be searched. If no match is found within these two sectors, it leaves the drive positioned at the following sector. Synthetic program lines 12, 29 & 39 allow you to use 7 character file names with SRCHX. Note that each directory entry is read in two parts: first, 21 characters that start with the filename, then the remaining 11 characters. You could also use 14 & 18 if you change line 29 to X<>N. Once the search is completed, the filename is restored to the ALPHA register, and the contents of buffer 0 are copied to buffer 1 (lines 37-41), for future use by mass storage functions. What happens if the file number in X or if the file name is entered incorrectly? The worst that can happen is that you will go through a standard MCODE directory search. You will either find the file, or get the same error messages you would get if you did not use these utilities. -DIRL & DIRLX: The code used by the DIRectory List routines is very similar to the code used by SRCHX. Lines 2-24 use essentially the same procedure to go to a given directory sector, with the same LBL 09 delay loop. The LBL 00 loop is again the directory read loop. The major differences are that you also must have a file number pointer. This pointer is created by lines 6-8 & 27-30. Also, the LBL 00 loop now collects the data contained in each entry in a way that facilitates the production of a printed listing: Lines 32-35: accumulate the file number and a space Lines 36-39: accumulate the filename field Lines 40-42: accumulate the distinctive file type byte Lines 43,53: accumulate two spaces/ format bytes Lines 44-48: Check for end of directory. Exit loop if done. Lines 49-55: Accumulate the file start sector. This information is not required by GDIRX or SRCHX. This data is usefull for special applications (Future article). Lines 56-61: Print the data you have collected, move the drive pointer to the start of the next directory entry, & go to LBL 00 to process the next entry until done. GENERAL COMMENTS: These routines were primarily designed to work with the HP-9114A disc drive. However, I have found them equally helpfull when working with the cassette drive. The DIRL(X) routines give HP-41 users some of the analytical capability provided by "DIRALL", an HP-75 program that uses an 80 col. printer to "tell-all" about HP-41/71/75 files, at least insofar as HP-41 files are concerned. Given a DIRL and a DIR listing, you can recreate most file entries without difficulties.