How can HP-41C RAW/P41 files be used with HP-42X?

During the last two years, I developed HP-IL emulation for both HP-41X and HP-71X giving them a possibility to load hundreds of programs (data, key assignments, ...) in the RAW/P41 format from the standard LIF files stored on a computer. The ability to easily load all these programs greatly enhances the usefulness of my emulators. Unfortunatelly, HP-42S calculator doesn’t have HP-IL. In fact, it doesn’t even provide two-way communication between two calculators or a calculator and the computer. The IR transmitter on HP-42S can only send data to the IR printer or to the HP-48 calculator (which can capture HP-42S output using the INPRT program).

Taking into account the number of HP-41C programs and the (relative) similarity between HP-41C and HP-42S, I was investigating a possibility to load some of HP-41C programs into my HP-42X emulator. As you already know, HP-42X has the ability to load programs using the “!LOAD” external command so the necessary loading mechanism has already been built into the emulator core. !LOAD expects the character string object containing the program to be put onto the HP-48/49 stack prior to execution. After the header, this character string object contains the program in the binary format exactly as it is stored in RAW or P41 file. RAW files don’t have any header and P41 files have the standard LIF header but, apart from these differences, everything else is the same. So, it seems possible to convert RAW and P41 files into the format which would be recognizeable by HP-42X and which can be loaded with !LOAD. I wrote a small program called RAW42.EXE to accomplish this task. It does exactly what I described before - converts the RAW/P41 files into 42X files which can then be sent via serial cable to the calculator and loaded into the emulator. Run RAW42 with /49 option to produce HP-49G compatible file.

So far, I loaded a few HP-41C programs and they worked well. The only difference I noticed is the display representation of numerical constants in programs. On HP-42S, every numerical constant is followed by a NULL byte, even if the following instruction is not a numerical constant. This is different from HP-41C where NULL byte separate only two numerical constants in succession. For example, the following HP-41C program (LBL “TEST” 0 LBL 01 1 + VIEW X GTO 01 END) will show up as (LBL “TEST” 0210832 LBL 01 10832 + VIEW X GTO 01 END) on HP-42X but will function correctly beside the display representation differences. SST/BST will work as expected, too. It is obvious that HP-42S shows low nibble of the instruction until it comes to the NULL byte. For this reason, the above program would look different after the first execution because of the compilation of jumps in GTO/XEQ instructions. This is a small sacrifice in the functionality but, as programs are working properly and numerical constants are properly interpreted, I don’t regard this as a big problem. However, in the latest HP-42X release this has been fixed in the firmware and number constants are displayed properly. BTW, HP-41C programs loaded into HP-42X are shorter than appropriate HP-42S programs because they don’t contain unnecessary NULL bytes. One must be careful when typing another number after such numerical constants because (as the previous one isn’t terminated by a NULL byte) it will be appended to the previous one.

Synthetic programs won’t function properly on HP-42S so it doesn’t make sense to load programs containing synthetic instructions as well as programs containing various XROM instructions which aren’t present in HP-42S. With the aid of excellent HP41UC program developed by Leo Duran it is possible to convert (text) listings of HP-41C programs into the RAW/P41 format which can be converted to 42X format and loaded into the emulator. This possibility can be used to enter HP-42S programs and send them to HP-42X, as well, providing that you don't use TEXT instructions (like RCL "ABC") and enter new HP-42S instructions (which HP41UC doesn't recognize) in XROM form and not by name. The exceptions are some XF (XROM 25) and Printer (XROM 29) instructions which exist in HP-42S and they can be entered by name. New TEXT instructions can be entered using C-style sequences like "\91ABC" instead of RCL "ABC". Furthermore, simple search & replace in the editor can be used to convert all TEXT instructions of the same kind into the appropriate C-style sequence. For example, search for [RCL "] and replace with ["\91] . Maybe this seems inconvenient at first, but after some practice, almost all HP-42S programs can be entered, compiled and loaded into HP-42X using above technique.