The Museum of HP Calculators


User-Code File Converter / Compiler / De-compiler / Bar-Code Generator

User-Code File Converter/Compiler/De-compiler/Bar-Code Generator Copyright (c) Leo Duran, 2000. The program and this document may be freely used and distributed. E-mail author at: leo_duran@yahoo.com.

Download:

Download the zip file. The Zip file contains a text version of this page plus the PC executable.

Introduction:

The purpose of this utility is provide a means for handling common file formats used by various PC software that support the HP-41 calculator. Of course, this implies that there must be a transfer mechanism to link the calculator to the PC. HP-IL provides this mechanism. For a brief description on transfer methods, see the "Shuttle Disk" and "Direct Link" sections that follow in this document.

The file converter is used to "package" compiled user-code putting a suitable "wrapper" around it. This is done preceding the code with a "header", appending a valid "checksum", and adding "filler" (don't care) bytes to satisfy file size requirements. These files formats are simply "containers" for user-code. The de-compiler takes compiled user-code, packaged in any of the supported formats, and creates a text file that can be edited or printed out. The compiler takes user-code in text form, and compiles it to a supported file format. And finally, the barcode generator creates a printable file with raster graphics data for supported printers.

Table Of Contents:

LIF File Format
P41 File Format
RAW File Format
BIN File Format
DAT File Format
Barcode Generator
De-Compiler Notes
Compiler Rules
"Shuttle Disk" Transfers
"Shuttle Disk": HP-41 => PC
"Shuttle Disk": PC => HP-41
"Direct Link" Transfers
"Direct Link": PC => HP-41
"Direct Link": HP-41 => PC
Appendix A - 41UCC Compatibility
Appendix B - Listing of "WL"
Credits/References


Note: The "|-" character used in this document is the append symbol ( 0xC3, ASCII ).

Brief Overview:

Supported file formats:

Features:

 File Converter:
  [ LIF, P41, RAW, DAT, BIN ] => [ BIN, DAT, RAW, P41, LIF ]

 Compiler:
  [ TXT ] => [ LIF, P41, RAW, DAT, BIN ]

 De-compiler:
  [ LIF, P41, RAW, DAT, BIN ] => [ TXT ]

 Bar-Code Generator:
  [ RAW ] => [ WND, PCL, PS ]

LIF Format:

File system used for HP-IL mass-storage devices.
See overview at: http://ftp.agilent.com/pub/mpusup/pc/index.html
LIF Specification is at: http://www.finseth.com/~fin/hpdata/lif.html
LIF Utilities are at: http://ftp.agilent.com/pub/mpusup/pc/index.html

Usage: optional parameters are surrounded by <>

 LIF file to P41 file ( search LIF name: <name>, <outfile> or [infile] )
   /l=infile<.lif>  /p<=outfile.p41>  <name>

 LIF file to RAW file
   /l=infile<.lif>  /r<=outfile.raw>  <name>  </k>
  Use /k option to exclude checksum and trailer bytes in RAW file.

 LIF file to BIN file
   /l=infile<.lif>  /b<=outfile.bin>  <name>

 LIF file to DAT file ( hex digits in ASCII form )
   /l=infile<.lif>  /d<=outfile.dat>  <name>

 LIF directory listing ( search for <name> only, if specified )
   /l=infile<.lif>  <name>

 LIF file to TXT file ( de-compile )
   /l=infile<.lif>  /t<=outfile.txt>  <name>  </a>  </n>  </x>

  De-compiler Options:
   /a - append text using: [ "|-text" ], instead of: [ >"text" ]
   /n - generate line numbers
   /x - use [ XROM mm,ff ] for Ext/Time functions: [ X<>F ] => [ XROM 25,46 ]

P41 Format:

[32-byte header] + [compiled code] + [1-byte checksum] + [trailer]
  [32-byte header] - single LIF directory entry for the program
  [1-byte checksum] - sum of all [compiled code] bytes
  [trailer] - filler bytes, so that filesize = 32 + multiple 256-byte blocks

P41 archives are at: ftp://ftp.math.jyu.fi/pub/hpil/

Usage: optional parameters are surrounded by <>

 P41 file(s) to LIF file
   /p=infile<.p41>  /l<=outfile.lif>

  If output file is specified, [infile] can be a directory of P41 files
  For example: hp41uc /p=\p41dir\*.p41 /l=hpil.lif

 P41 file to RAW file ( remove 32-byte header )
   /p=infile<.p41>  /r<=outfile.raw>  </k>
  Use /k option to exclude checksum and trailer bytes in RAW file.

 P41 file to BIN file
   /p=infile<.p41>  /b<=outfile.bin>

 P41 file to DAT file ( hex digits in ASCII form )
   /p=infile<.p41>  /d<=outfile.dat>

 P41 directory listing ( from 32-byte header )
   /p=infile<.p41>

 P41 file to TXT file ( de-compile )
   /p=infile.p41  /t<=outfile.txt>  </a>  </n>  </x>

  De-compiler Options:
   /a - append text using: [ "|-text" ], instead of: [ ">text" ]
   /n - generate line numbers
   /x - use [ XROM mm,ff ] for Ext/Time functions: [ X<>F ] => [ XROM 25,46 ]

RAW Format:

[compiled code] + [1-byte checksum] + [trailer]
  [1-byte checksum] - sum of all [compiled code] bytes
  [trailer] - filler bytes, so that filesize = multiple 256-byte blocks

Usage: optional parameters are surrounded by <>

 RAW file(s) to LIF file ( LIF name = <name> or [infile] )
   /r=infile<.raw>  /l<=outfile.lif>  <name>

  If output file is specified, [infile] can be a directory of RAW files.
  For example: hp41uc /r=\rawdir\*.raw /l=hpil.lif

 RAW file to P41 file ( P41 name = <name> or [infile] )
   /r=infile<.raw>  /p<=outfile.p41>  <name>

 RAW file to BIN file
   /r=infile<.raw>  /b<=outfile.bin>

 RAW file to DAT file ( hex digits in ASCII form )
   /r=infile<.raw>  /d<=outfile.dat>

 RAW file to TXT file ( de-compile )
   /r=infile<.raw>  /t<=outfile.txt>  </a>  </n>  </x>

  De-compiler Options:
   /a - append text using: [ "|-text" ], instead of: [ >"text" ]
   /n - generate line numbers
   /x - use [ XROM mm,ff ] for Ext/Time functions: [ X<>F ] => [ XROM 25,46 ]

BIN Format:

[2-byte header] + [compiled code] + [1-byte checksum] + [trailer]
  [2-byte header] - size of [compiled code] in big-endian format
  [1-byte checksum] - sum of all [compiled code]+[2-byte header]
  [trailer] - filler bytes, so that filesize = multiple 128-byte blocks

Usage: optional parameters are surrounded by <>

 BIN file(s) to LIF file ( LIF name = <name> or [infile] )
   /b=infile<.bin>  /l<=outfile.lif>  <name>

  If output file is specified, [infile] can be a directory of BIN files.
  For example: hp41uc /b=\bindir\*.bin /l=hpil.lif

 BIN file to P41 file ( P41 name = <name> or [infile] )
   /b=infile<.bin>  /p<=outfile.p41>  <name>

 BIN file to RAW file ( remove 2-byte header )
   /b=infile<.bin>  /r<=outfile.raw>  </k>
  Use /k option to exclude checksum and trailer bytes in RAW file.

 BIN file to DAT file ( hex digits in ASCII form )
   /b=infile<.bin>  /d<=outfile.dat>

 BIN file to TXT file ( de-compile )
   /b=infile<.bin>  /t<=outfile.txt>  </a>  </n>  </x>

  De-compiler Options:
   /a - append text using: [ "|-text" ], instead of: [ >"text" ]
   /n - generate line numbers
   /x - use [ XROM mm,ff ] for Ext/Time functions: [ X<>F ] => [ XROM 25,46 ]

DAT Format:

[4-byte header] + [compiled code] + [2-byte checksum]
  [4-byte header] - size of [compiled code] in big-endian format
  [2-byte checksum] - sum of [compiled code]+size of [compiled code]
All bytes are hex digits in ASCII form.

Usage: optional parameters are surrounded by <>

 DAT file(s) to LIF file ( LIF name = <name> or [infile] )
   /d=infile<.dat>  /l<=outfile.lif>  <name>

  If output file is specified, [infile] can be a directory of DAT files.
  For example: hp41uc /d=\bindir\*.dat /l=hpil.lif

 DAT file to P41 file ( P41 name = <name> or [infile] )
   /d=infile<.dat>  /p<=outfile.p41>  <name>

 DAT file to RAW file ( remove 2-byte header )
   /d=infile<.dat>  /r<=outfile.raw>  </k>
  Use /k option to exclude checksum and trailer bytes in RAW file.

 DAT file to BIN file
   /d=infile<.dat>  /b<=outfile.raw>

 DAT file to TXT file ( de-compile )
   /d=infile<.dat>  /t<=outfile.txt>  </a>  </n>  </x>

  De-compiler Options:
   /a - append text using: [ "|-text" ], instead of: [ >"text" ]
   /n - generate line numbers
   /x - use [ XROM mm,ff ] for Ext/Time functions: [ X<>F ] => [ XROM 25,46 ]

Barcode Generator:

Reference: "Creating Your Own HP-41 Barcode Manual"
Usage: optional parameters are surrounded by <>

1) RAW file to PCL (HP raster graphics) file:
   /r=infile<.raw>  /h<=outfile.pcl>  <"Program Title">

To print the barcode, copy the output file to the printer device.
Example: hp41uc /r=prog.raw /h "Program Title"
         copy prog.pcl lpt1

2) RAW file to Postcript file:
   /r=infile<.raw>  /s<=outfile.ps>  <"Program Title">

To print the barcode, copy the output file to the printer device.
Example: hp41uc /r=prog.raw /s "Program Title"
         copy prog.ps lpt1

3) RAW file to Wand file
   /r=infile<.raw>  /w<=outfile.wnd>  <"Program Title">

The output file will be a 16-byte per row hex dump in text form.

Sending a "Postscript" or "PCL" file to the printer from "Windows" can be kind of tricky, but there is a "free-ware" utility that does exactly that, and is called "PrintFile".

De-Compiler Notes:

1) Empty alpha strings are commented for clarification:

        ""  ;F0 (single-byte synthetic NOP)
        GTO ""  ;1D F0
        XEQ ""  ;1E F0


2) Spare intructions generate a comment-line:

        ;GTO IND __ (SPARE)  ;AF,45


3) Non-printable characters (0x00..0x19, 0x7F..0xFF) withing strings
generate a "" (0x04) and are commented with a esc-sequence:

        "Text"  ;"Text\0D\0A"
        LBL "abcfg"  ;"abc\F3fg"


4) Global-alpha labels with key assignments generate a comment:

        LBL "label"  ; Key: -15  (label assigned to shift-LN key).

Compiler Rules:

  1. Prefixes are case-insensitive: [ rcl 00 ] same as [ RCL 00 ]
  2. Postfixes are case-sensitive: [ lbl a ] different from [ lbl A ]
  3. Append text is allowed with: [ >"text" ], [ "\-text" ], or [ "|-text" ]
  4. Synthetic instructions are allowed: [ rcl M ], [ sto R ]
  5. Synthetic NOP (TEXT0) is allowed using an empty text line: [ "" ]
  6. Synthetic text is allowed with C-style esc-sequences: [ "\0D\0A\n" ]
  7. Comments are allowed preceded by ";" or "#": [ ; comment ]
  8. Functions from external modules recognized: ExtFunc/Time, HP-IL, ExtI/O, HP-IL Dev, Plotter, and Wand. All others supported with [ XROM mm,ff ].
  9. Key assignment for global labels are supported: [ lbl "label" Key: 15 ].
  10. Multiple intructions per line are allowed if separated by comma+space.

Command-line options:

   /n - ignore line numbers in text file: [ 100 STO 00 ]
   /g - force global alpha labels if using quotes: [ XEQ "A" ] is not [ XEQ A ]

Usage: optional parameters are surrounded by <>

 TXT file(s) to LIF file ( LIF name = <name> or [infile] )
   /t=infile<.txt>  /l<=outfile.lif>  <name>  </n>  </g>

  If output file is specified, [infile] can be a directory of TXT files
  For example: hp41uc /t=\txtdir\*.txt /l=hpil.lif

 TXT file to P41 file ( P41 name = <name> or [infile] )
   /t=infile<.txt>  /p<=outfile.p41>  <name>  </n>

 TXT file to RAW file
   /t=infile<.txt>  /r<=outfile.raw>  </n> </k>
  Use /k option to exclude checksum and trailer bytes in RAW file.

 TXT file to BIN file
   /t=infile<.txt>  /b<=outfile.bin>  </n>

Recognized C-style esc-sequences in alpha/text strings: [ "\0D\OA" ]

  Esc-sequence          Hex/ASCII Equivalent
--------------------------------------------
    \a                  0x07    ( alert bell )
    \b                  0x08    ( back-space )
    \f                  0x0C    ( form-feed )
    \n                  0x0A    ( newline )
    \r                  0x0D    ( return )
    \t                  0x09    ( horz tab )
    \v                  0x0B    ( vert tab )
    \-                  0x7F    ( append text, only at the start of string )
    \?                  ?       ( ascii )
    \"                  "       ( ascii )
    \'                  '       ( ascii )
    \\                  \       ( ascii )
    \hh                 0xhh    ( hh = hex digits: 0-9, A-F, a-f )
    \xhh                0xhh    ( hh = hex digits: 0-9, A-F, a-f )

"Shuttle Disk" Transfers:

Required Hardware:

Required PC Sotfware:


       +-------+ HP-IL +------+                +------+
       | HP-41 |<=====>| 9114 |<===> 720K <===>|  PC  |
       +-------+       +------+    Shuttle     +------+
         WRTP                        Disk     LIFUTIL.EXE
         READP

       Figure 1. "Shuttle Disk" Transfers

Note: since LIFUTIL expects a Volume label in the media, and the HP-41 format function (NEWM) does not create a volume label, it is recommended that disks be formatted on the PC using LIFUTIL. If you have problems reading a disk formatted on the PC try changing the BIOS setting for the drive from 1.44M to 720K. An alternate solution is to format the disk from the calculator with the 9114 drive. In this case, you must create a volume label for the disk. This issue was addressed in the PPC Journal article: "The Volume Label", V14N2 Feb 1987, by Cristian Rusquelles. A listing is included in "Appendix B" of this document.

"Shuttle Disk": PC => HP-41

Let's say you've downloaded some P41 files from the internet, and want to transfer the programs that are "packaged" in these files to your calculator using a "shuttle disk".

1) Remove the 32-byte header from each of the P41 files, and make a note of the LIF directory information in the header: name, size, and implementation. You can use HP41UC.EXE to accomplish this task:

   hp41uc /p=infile.p41 /r=outfile.raw

HP41UC.EXE will remove the 32-byte header and display the LIF directory information: name, size, and implementation. The output (RAW) file should be 32 bytes shorter than the input (P41) file.

2) Transfer the program, contained in outfile.raw, to the shuttle disk using LIFUTIL.EXE. Refer to "Appendix I" of Dan McDonald's article listed in the reference section at the end of this document.

3) Insert the shuttle disk in your 9114 disc drive, and the read the program from your calculator using the READP function. Be sure to match the program name exactly as saved by LIFUTIL, as the name is case-sensitive.

"Shuttle Disk": HP-41 => PC

Let's say you have a program on the calculator that you want to edit on your PC and transfer back to the calculator using the previous procedure.

1) Calculate the program size in bytes. On a HP-41CX, you can simply use CATALOG 1, watching for the number listed at the "END" indicator of your program. For other machines refer to a discussion on the subject on Chapter 5 of "HP-41 Extended Functions Made Easy" by Keith Jarett. This is a well-documented subject covered by many HP-41 books and articles.

2) Copy the program to the shuttle disk using the WRTP function.

3) Insert the shuttle disk on your PC diskette drive, and extract the program using LIFUTIL.EXE. The output file should be a RAW file with a size of multiple 256-byte blocks. So, for eaxmple, an 56-byte program will be extracted as a 256-byte RAW file.

4) If you're interested in sharing your creation with the rest of the world, you may convert the file to P41 format using HP41UC.EXE:

   hp41uc /r=infile.raw /p=outfile.p41 NAME /s=SIZE

Where [ SIZE ] is the program size in hex. For example, for a 56-byte program, you'd use: /s=38. The optional [ NAME ] parameter will be the name used in creating the 32-byte LIF directory header. If [ NAME ] is not specified, the input (RAW) filename is used (with all CAPS).

5) To edit the program on your PC, you'd need to de-compile it:

   hp41uc /r=infile.raw /t=outfile.txt /s=SIZE

If you'd like to print it, you may want to add the [ /n ] option. to generate line numbers in the output file:

   hp41uc /r=infile.raw /t=outfile.txt /s=SIZE /n

6) Compile your program to a RAW file that can be used by LIFUTIL.EXE:

   hp41uc /t=infile.txt /r=outfile.raw

HP41UC will display the LIF information required by LIFUTIL: name, size, and implementation. Note, if you added line numbers to your de-compiled file, you must alert the compiler to ignore line numbers by using the [ /n ] option:

   hp41uc /t=infile.txt /r=outfile.raw /n

7) To transfer to program to the calculator, using the output RAW file, simply go to step #2 of the previous "PC => HP-41" procedure.

"Direct Link" Transfers:

Required Hardware:

Required PC Sotfware:

Note: Contrary to popular belief, a fast PC can be used with an HP-IL card. The requirement for a slow PC, as the original IBM AT, is strictly a limitation (timing loops that are CPU-speed dependent) in most transfer software, but it is not an issue with Trans41.

              +-------+ HP-IL +------+
              | HP-41 |<=====>|  PC  |
              +-------+       +------+
                WRTP         Trans41.EXE
                READP

           Figure 2. "Direct Link" Transfers

"Direct Link" HP-41 => PC

Let's say you have a program on the calculator, called TEST, that you want to edit on your PC and later transfer back to the calculator. We will assume that you are using the Trans41 utility an HP-IL card on the PC.

1) Establish the HP-IL link with Trans41 using the HPSIDE1.PAK transfer file.

2) Upload the program, TEST, to the PC using WRTP on the calculator. This will copy the program to HPSIDE1.PAK on the PC side.

3) Extract and de-compile the program from HPSIDE1.PAK using HP41UC.EXE:

   hp41uc /l=hpside1.pak TEST /t=test.txt

Notice that the program name, TEST, is case-sensitive, and must match the ALPHA label used with WRTP.

4) Edit test.txt and compile it to a LIF file with HP41UC.EXE:

   hp41uc /t=test /l

In this case, HP41UC will create a default output file: test.lif, and use a default LIF program name: TEST (input filename, with all CAPS).

If your program has synthetic text strings, the de-compiler will append a comment with esc-sequences that can be used by the compiler.

For example: "Text"  ;"Text\0D\0A"
To re-compile this line, simply remove the text preceding the [ ; ]:
   [ "Text"  ;"Text\0D\0A" ] => [ "Text\0D\0A" ]

Direct Link" PC => HP-41

Assuming that you have created a LIF file to "package" your program, you can transfer it to the calculator with the following procedure:

1) Over-write Trans41's transfer file with the created LIF file:

   copy test.lif hpside1.pak

You may also rename the existing transfer file to save its contents:

   rename hpside1.pak backup1.pak
   rename test.lif hpside.pak

Or you may simply over-write the transfer file on your compilation step:

   hp41uc /t:text /l:hpside1.pak

2) Establish the HP-IL link using the new HPSIDE1.PAK transfer file.

3) Download the program on the calculator using READP and that's it!

Appendix A - 41UCC Compatility:

The following instructions are allowed by the compiler for compatibility with 41UCC.

41UCC Form                              HP41UC Form
---------------------------------------------------
10**X                                   10^X
APPEND, APPND, APND "Text"              >"Text"
CLSIGMA                                 CLS
D->R                                    D-R
E**X                                    E^X
E**X-1                                  E^X-1
ENTER^                                  ENTER
GOTO                                    GTO
P->R                                    P-R
R->D                                    R-D
R->P                                    R-P
SIGMA+                                  S+
SIGMA-                                  S-
SIGMAREG                                SREG
STO*, STO/, STO+, STO-                  ST*, ST/, ST+, ST-
T "Text String"                         "Text String"
X!=0?, X<>0?                            X#0?
X!=Y?, X<>Y?                            X#Y?
X**2                                    X^2
Y**X                                    Y^X

Appendix B - Listing of "WL":

From the PPC Journal article: "The Volume Label",V14N2 Feb 1987, by Cristian Rusquelles. Requires an Extended I/O module.

 01 LBL "WL"
 02 >"     "    ; append 6 spaces
 03 ASTO 00
 04 LBL 00
 05 AID
 06 16
 07 X=Y?
 08 GTO 01
 09 "NOT A DRIVE"
 10 PROMPT
 11 GTO 00
 12 LBL 01
 13 CLRDEV
 14 3
 15 DEVL
 16 2
 17 OUTXB
 18 6
 19 DEVL
 20 "D"
 21 ARCL 00
 22 OUTAE
 23 8
 24 DEVL
 25 END

Credits/References:

Dan McDonald - For his article: "Ancient Data - Modern Machines: Handling HP-IL Files on Today's PC", posted at the Museum of HP calculators under: "HP-IL Files: Where, What, Why, How, etc.". http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi.

Warren Furlow - For his work in support of the HP-41: V41 Emulator, and M-Code development tools. And also, for his comments and suggestions as contributions to this project. http://www.hp41.org.

LIFUTIL - Free-ware program provided by Hewlett Packard(tm). See the "Shuttle Disk" section for a description of its use. Distributed at: http://ftp.agilent.com/pub/mpusup/pc/index.html

Trans41 - HP-IL Transfer utility by Eclipse Logic Inc and Tacit Logic Systems. Works fine on today's fast PCs. See the "Direct Link" section for a description of its use.

DOSLink - HP-IL Transfer utility by Southern Software. Requires the use of a slow PC (AT compatible: 286/16Mhz). Can be used as described with Trans41, except it uses a transfer file called HPILDISC, instead of HPSIDE1.PAK.

41UCC - User-code compiler written by Leslie Brooks & Jim De Arras. Distributed by Hand Held Products, Inc.

A Program Byte Counter - "HP-41 Extended Functions Made Easy", by Keith Jarett. Chapter 5, page 97.

Listing of "WL" - PPC Journal article: "The Volume Label", V14N2 Feb 1987, by Cristian Rusquelles.

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall