MASS STORAGE UTILITIES FOR THE HP-41 -- PART III Saving Extended Memory with WRTA The "WA" and "RA" routines extend the capabilities of WRTA and READA. They allow you to save the entire contents of your HP-41 system RAM on mass storage media -- including the contents of both Extended Memory Modules and the Extended Function Module RAM. The information is stored in huge 1360 register files of type WA,A. (The number of registers may be less than 1360 registers with HP-41C systems without the QUAD Memory module.) These routines allow the user to take full advantage of Extended Memory by providing an easy, very fast way to recover from MEMORY LOST that does not require that each Extended Memory (EM) file be copied to EM individualy. The time saved by using "WA" and "RA" increases dramatically with the number of EM files to be saved or read. This utility allows you to use Extended Memory as a highly portable and reasonably secure RAM mass storage unit by providing convenient backup capability, by way of a cassette or disc drive. BACKGROUND: I believe the "WA" & "RA" routines were first published in the Melbourne Chapter's Technical Notes # 17, on page 77. The listing was dated November 25, 1983, and the author was Michael Pocksteiner. This early 108 bytes long version did not require any special ROMs. Toward the end of 1984, Gerhard Kruse sent me a very short version of "WA" & "RA" that uses NO synthetic program lines. This routine used functions from the soon to be available CCD ROM. I rewrote the routine, using a minimum of synthetic program lines and character manipulation functions available in the Extended IO ROM. You can also use equivalent functions from the HP-IL Development module. This version incorporates safeguards that minimize user risk associated with any program that temporarily alter the contents of status register c. MASS STORAGE UTILIZATION EFFICIENCY: The 1360 register WA,A files use 43 setors of mass storage capacity -- nearly 9% of the capacity of a mini-cassette (or nearly 2% of the capacity of a 3.5" double sided disc). The space reserved on the mass storage medium cannot be readily recovered after you purge the file. Other controllers could be used to pack the medium -- but this should be avoided, since the wear on the medium (and the drive) is significant. Therefore, you should limit the number of such files carefully. Also, since purging the file does not recover the reserved media space, I do not recommend purging such a file unless you intend to replace it with a data file that uses 1376 registers. Generally, one or two WA,A files could hold your normal "Active Work Space" configurations -- both files being secured to avoid accidental overwrite. Another (unsecured) WA,A file is handy for software development, allowing you to safeguard work in progress against "MEMORY LOST". Roughly 30% of the file contains either no information, or duplicate information. The user trades off media capacity vs. the time and incovenience associated with reloading Extended Memory files one at a time. If media capacity is a concern, you can conserve capacity by using the mass storage functions built-in the HP-812160 HP-IL interface. USER INSTRUCTIONS: You can use "WA" and "RA" exactly the same way you can use WRTA and READA, provided the utility is in main RAM. You must make sure that the HP-IL module and the Extended IO ROM are both plugged-in, that the HP-IL loop is set-up for normal mass storage operations, and that an appropriate filename is placed in the ALPHA register before you execute either "WA" or "RA". Also, when you use "RA", make sure that your system RAM configuration is the same configuration used at the time you stored the file with "WA". "RA" and "WA" must transfer roughly four times more information than READA and WRTA usually handle, after the directory search is completed. It will therefore take roughly four times longer to do the job. Make sure that your drive battery has an adequate charge before you execute "WA" or "RA". It is a good idea to have the charger plugged-in. Finally -- avoid TRACE mode. WARNING: DO NOT INTERRUPT "WA" or "RA"! These routines temporarily alter status reg. c -- Interruptions will almost certainly insure an eventual MEMORY LOST, unless you restore the "curtain" to its original value. HP-IL system errors such as NO DRIVE, NO MEDIUM, FILE NOT FOUND, NONEXISTENT , BAD MEDIUM, NO ROOM will abort the program and produce a BEEP. The routine automatically restores register c. This allows the user to correct the problem and try again. If you interrupt this routine for any reason while the drive is "BUSY", you should first reset the drive with CLRLOOP. The drive will also reset if you turn it off. However you do it -- there is the possibility that you will have to reformat your medium. Next, you must restore the contents of register c with XEQ 00. If you are lucky, you may avoid MEMORY LOST. NOTE: The following warning may be ignored if the only way you alter the address of Reg. 00 is with HP provided functions such as SIZE or PSIZE. It applies only if you use advanced Synthetic Programming techniques to "Move the cutain". WARNING FOR ADVANCED USERS: The "curtain" (the address of Reg. 00) should be in main RAM when you execute "WA". Moving the curtain to the status registers or Extended Memory will most likely waste mass storage capacity. It also could result in a variety of other problems that may result in MEMORY LOST. You could also inadvertantly crash your mass storage media. ENHANCING "WA": "WA" can be enhanced to allow it to use all available disc space (See Part I of this series). You could of course "CREATE" a 1360 register long data file and purge it. However, this procedure has one major disadvantage: the time taken by CREATE to ZERO the data file. The easiest way to enhance "WA" is: 1. Provide a GLOBAL entry point after line 71 of the "WRTP"/ "CREATE"/ .. utility program: LBL "01" (an ALPHA label, NOT a second numeric label) seemed appropriate. 2. Use "WA2" instead of "WA". See listing. "WA2" does not have all of the safeguards built into "WA". The reason is that "WA2" cannot readily differentiate between HP-IL system errors and the invalid "MEDM FULL" error. This means that you should use extra care to avoid system errors. If you encounter a genuine system error, the LBL "01" program cannot create a dummy entry -- you will get some error message such as "TRANSMIT ERR". If this happens, restore register c as soon as possible with GTO "WA2", XEQ 00. THEORY: The WRTA routine in the HP-IL interface must work with all HP-41 systems -- and HP-41C calculators may have 64, 128, 192, 256 or 320 registers of main memory, depending on the number and type of RAM modules plugged into the machine. Therefore, WRTA calls on the FNDEND main frame routine at 1730 hex, to determine the address of the last data register to be saved. FNDEND computes this address by checking every data register for existence, starting at R00. The routine accepts any curtain address it finds in status rgeister c, and proceeds until it finds a void such as is found at address 200 hex. Since the R00 address field is 12 bits long, you could (in theory) have a curtain address of FFF, or 4095 absolute -- even though main RAM ends at 1FF hex, or 511 absolute. Thus, by manipulating the contents of register c, you can force WRTA to make very large WA files. The RAM address space, however, is actually 000 to 3FF, or 1024 registers. When you attempt to read or write to a register address greater than 3FF, you actually access the register at modulo 1024. Thus, absolute address 400 hex is equivalent to 000, and 5FF to 1FF. This wrap-around effect allows to effectively copy all HP-41 RAM. See the diagram labeled "Organization of 1360 REG. WA,A Files". Note that the 1360 Reg. WA,A file is the smallest file that can be used to save Extended Function RAM with HP-41CV/CX machines. 418 registers are either void (no RAM at said address), or duplicate information. In other words -- 13 out of 43 sectors, or 30% of the capacity of the file, contain redundant information. Automatic program execution is a key feature of this program: when you execute "RA", you automatically transfer control to the copy of "RA" that was stored when you executed "WA". The program uses this feature to immediately restore the curtain, without user intervention. Automatic execution of other program files should be possible because WRTA makes an EXACT copy of RAM -- subroutine return address stack included. The program to be executed would call "WA" as a subroutine. Then, when you execute "RA" and transfer control to "RA" copied from mass storage, you should return to the calling program as soon as you restore the contents of register c. Any such program must be very carefully designed to prevent inadvertent use of "WA". This is best done with a GTO instruction: This way, you will not accidentally R/S into "WA". Example: ... GTO 00, XEQ "WA", LBL 00, .... When you want to store the file, use GTO. nnn to position yourself to the XEQ "WA" instruction, then press R/S. LINE BY LINE ANALYSIS: The LBL 00 subroutine is the "curtain" mover. It is designed to toggle a single bit of the R00 address in register c. It effectively increments/ decrements the address by 1024 registers, as required. The ALPHA register is used and then restored. The stack is used and NOT restored. The X<=Y? instruction at line 21 determines whether the R00 address needs be incremented or decremented. Advanced users should be aware that the "equal" portion of the test will be needed only when the initial curtain address was placed in the status registers. Therefore, you may prefer to use the slightly faster X