Home > Free42 > Unsupported > txt2raw.plAs every HP-42S user finds out eventually, entering long programs into the calculator using the keyboard can be a pain. Many commands require a lot of keystrokes to enter, so even comparatively short programs, of 100-200 lines, say, can be a chore to key in.
There is still room for improvement, though. The "raw" format is relatively new in the HP-42S emulation scene, as Emu42 adopted it in late 2004 and Free42 in early 2005 -- and so there are still many program collections where the programs are in text form... And again, users are faced with the unpleasant chore of keying in those programs keystroke by keystroke. Wouldn't it be nice to be able to convert listings from text form to "raw" format automatically?
Enter txt2raw.pl, written by Vini Matangrano, and reproduced here for the benefit of HP-42S emulator users. txt2raw.pl is a Perl script that converts HP-42S listings to "raw" files, essentially the inverse of what the HP-42S does when you issue the PRP or LIST command.
The following is an actual HP-42S program listing:
00 { 488-Byte Prgm } 01>LBL "DPLOT" 02 MVAR "YMIN" 03 MVAR "YMAX" 04 MVAR "AXIS" 05 MVAR "XMIN" 06 MVAR "XMAX" 07 VARMENU "DPLOT" 08 "Enter limits; t" 09 |-"hen R/S" 10 PROMPT 11>LBL 00 12 "FCN=?" 13 SF 25 14 RCL "PFCN" 15 FC?C 25 16 GTO 01 17 |-" <" 18 ARCL ST X 19 |-">" 20>LBL 01 21 AVIEW 22 CLA 23 SF 25 24 ARCL "PFCN" 25 CF 25 26 AON 27 STOP 28 AOFF 29 ALENG 30 X=0? 31 GTO 00 32 ASTO "PFCN" 33 SF 25 34 VARMENU IND "PFCN" 35 FS?C 25 36 GTO 02 37 CLA 38 ASTO "PIND" |
39 GTO 05 40>LBL 02 41 "Set vars; selec" 42 |-"t 'x'" 43 PROMPT 44 ASTO "PIND" 45 ALENG 46 X=0? 47 GTO 02 48 CLMENU 49 "EVAL" 50 KEY 1 GTO 03 51 "SOLVE" 52 KEY 2 GTO 04 53 MENU 54 "Evaluate or sol" 55 |-"ve?" 56 PROMPT 57>LBL 03 58 CLA 59 ASTO "PDEP" 60 GTO 05 61>LBL 04 62 VARMENU IND "PFCN" 63 "Select 'y'" 64 PROMPT 65 ASTO "PDEP" 66>LBL 05 67 EXITALL 68 CLLCD 69 RCL "YMAX" 70 RCL- "AXIS" 71 LASTX 72 RCL- "YMIN" 73 ÷ 74 X<0? 75 GTO 06 76 1 77 X<>Y |
78 X>Y? 79 GTO 06 80 15 81 × 82 1 83 + 84 +/- 85 1 86 PIXEL 87>LBL 06 88 RCL "XMAX" 89 RCL "XMIN" 90 STO 00 91 - 92 130 93 ÷ 94 STO 01 95 1.131 96 STO 02 97 RCL "YMIN" 98 RCL- "YMAX" 99 STO 03 100 CLA 101 ARCL "PIND" 102 ALENG 103 X!=0? 104 GTO 14 105 8 106 STO 04 107 GTO 08 108>LBL 14 109 CLA 110 ARCL "PDEP" 111 ALENG 112 X!=0? 113 GTO 14 114 9 115 STO 04 116 GTO 09 |
117>LBL 14 118 10 119 STO 04 120 PGMSLV IND "PFCN" 121 GTO 10 122>LBL 08 123 RCL 00 124 XEQ IND "PFCN" 125 GTO 11 126>LBL 09 127 RCL 00 128 STO IND "PIND" 129 XEQ IND "PFCN" 130 GTO 11 131>LBL 10 132 RCL 00 133 STO IND "PIND" 134 RCL "YMIN" 135 STO IND "PDEP" 136 RCL "YMAX" 137 SOLVE IND "PDEP" 138>LBL 11 139 RCL- "YMAX" 140 RCL÷ 03 141 15 142 × 143 1 144 + 145 X<0? 146 GTO 14 147 RCL 02 148 PIXEL 149>LBL 14 150 RCL 01 151 STO+ 00 152 ISG 02 153 GTO IND 04 154 END |
With this listing in a file named dplot.txt, run
txt2raw.pl dplot.txt
and a file named dplot.txt.raw will be created.
00000000 C0 00 F6 00 44 50 4C 4F 54 F5 90 59 4D 49 4E F5 DPLOT YMIN 00000010 90 59 4D 41 58 F5 90 41 58 49 53 F5 90 58 4D 49 YMAX AXIS XMI 00000020 4E F5 90 58 4D 41 58 F6 C1 44 50 4C 4F 54 FF 45 N XMAX DPLOT E 00000030 6E 74 65 72 20 6C 69 6D 69 74 73 3B 20 74 F8 7F nter limits; t 00000040 68 65 6E 20 52 2F 53 8E 01 F5 46 43 4E 3D 3F A8 hen R/S FCN=? 00000050 19 F5 91 50 46 43 4E AB 19 B2 00 F3 7F 20 3C 9B PFCN < 00000060 73 F2 7F 3E 02 7E 87 A8 19 F5 B3 50 46 43 4E A9 s > ~ PFCN 00000070 19 8C 84 8B A6 41 67 B1 00 F5 B2 50 46 43 4E A8 Ag PFCN 00000080 19 F5 C9 50 46 43 4E AA 19 B3 00 87 F5 B2 50 49 PFCN PI 00000090 4E 44 B6 00 03 FF 53 65 74 20 76 61 72 73 3B 20 ND Set vars; 000000A0 73 65 6C 65 63 F6 7F 74 20 27 78 27 8E F5 B2 50 selec t 'x' P 000000B0 49 4E 44 A6 41 67 B3 00 A2 6D F4 45 56 41 4C F3 IND Ag m EVAL 000000C0 E3 01 03 F5 53 4F 4C 56 45 F3 E3 02 04 A2 5E FF SOLVE ^ 000000D0 45 76 61 6C 75 61 74 65 20 6F 72 20 73 6F 6C F4 Evaluate or sol 000000E0 7F 76 65 3F 8E 04 87 F5 B2 50 44 45 50 B6 00 05 ve? PDEP 000000F0 F5 C9 50 46 43 4E FA 53 65 6C 65 63 74 20 27 79 PFCN Select 'y 00000100 27 8E F5 B2 50 44 45 50 06 A2 6C A7 63 F5 91 59 ' PDEP l c Y 00000110 4D 41 58 F5 93 41 58 49 53 76 F5 93 59 4D 49 4E MAX AXISv YMIN 00000120 43 66 B7 00 11 00 71 45 B7 00 11 15 00 42 11 00 Cf qE B 00000130 40 54 11 00 A7 65 07 F5 91 58 4D 41 58 F5 91 58 @T e XMAX X 00000140 4D 49 4E 30 41 11 13 10 00 43 31 11 1A 11 13 11 MIN0A C1 00000150 00 32 F5 91 59 4D 49 4E F5 93 59 4D 41 58 33 87 2 YMIN YMAX3 00000160 F5 B3 50 49 4E 44 A6 41 63 BF 00 18 00 34 B9 00 PIND Ac 4 00000170 0F 87 F5 B3 50 44 45 50 A6 41 63 BF 00 19 00 34 PDEP Ac 4 00000180 BA 00 0F 11 10 00 34 F5 BD 50 46 43 4E BB 00 09 4 PFCN 00000190 20 F5 AF 50 46 43 4E BC 00 0A 20 F5 89 50 49 4E PFCN PIN 000001A0 44 F5 AF 50 46 43 4E BC 00 0B 20 F5 89 50 49 4E D PFCN PIN 000001B0 44 F5 91 59 4D 49 4E F5 89 50 44 45 50 F5 91 59 D YMIN PDEP Y 000001C0 4D 41 58 F5 BF 50 44 45 50 0C F5 93 59 4D 41 58 MAX PDEP YMAX 000001D0 F2 D4 03 11 15 00 42 11 00 40 66 BF 00 22 A7 65 B @f " e 000001E0 0F 21 92 00 96 02 AE 04 C0 00 0D !
A few things are worthy of note in this example:
>
character; the >
character occurs in
print-outs created by Free42; it represents the triangular "right arrow"
character that is used to highlight LBL instructions in program listings
made with an original HP-42S and HP-82240A printer.|-
(pipe,
dash), which is used to represent the HP-42S "append" character; and on
line 112, the sequence !=
is used to represent the HP-42S "not
equals" character.txt2raw.pl performs two different kinds of character translation, one for commands and one for strings.
The command translations include converting /
to
÷
, Rv
to R
plus "down arrow" (the
"roll down" command), etc. For details on which conversions are performed,
run txt2raw.pl without parameters, and you will receive a brief
summary of the script's operation.
The string translations are controlled by the txt2raw.prm file,
which txt2raw.pl looks for in the current directory. This file
contains pattern/replacement pairs, one pair per line; the pattern and
replacement are separated by tab characters. The txt2raw.prm file
provided here contains many mappings that are the inverse of mappings
performed by Free42 when it performs PRP or LIST, e.g. ->
for "right arrow", \Sigma
for "Greek Sigma", etc.
Note: txt2raw.pl will ignore lines in txt2raw.prm that start
with a #
character, allowing you to enter comments in the
configuration file, or to temporarily avoid translating a particular
character if necessary.
Note that some of the translations performed by Free42 cannot be reversed
reliably: the small-caps E
("exponent") is converted to a
plain uppercase E, but when translating the other way, there is no way to
tell whether an uppercase E should be translated back to "exponent", or
left alone. This is also true of several other translations, but the ones
provided in the sample txt2raw.prm are the ones that seem relatively
safe -- e.g., it is much more likely that ->
was originally
a "right arrow" than that it was originally "dash, greater than".
When using txt2raw.pl on program listings from sources other than Free42's PRP and LIST commands, it may be necessary to tweak the txt2raw.prm file to match the conventions used in those listings.
One interesting use of txt2raw.pl is to allow you to edit programs
using a text editor. To edit programs that you have in "raw" format
already, you can load those programs into Free42, convert them to text
files by using the PRP or LIST commands while "print to text file" is
enabled (see the Preferences dialog), edit the resulting text file using a
plain text editor (Notepad, vi, etc.), and finally use txt2raw.pl to
convert the programs back to "raw" format.
When using txt2raw.pl in this manner, you may have to take extra
care to make sure that the string translations don't cause unintended
changes to your programs. In order to gain total control over those
conversions, you can use "raw text" mode in Free42, which disables all
character conversions and sends pure HP-42S character codes to the output
file; you may then use any tool of your own devising to perform any
translations that you may need before being able to edit your files, and
you can then customize txt2raw.prm to make txt2raw.pl perform
the inverse translation.