[comp.sys.handhelds] Program Packing

akcs.joehorn@hpcvbbs.UUCP (Joseph K. Horn) (01/16/91)

PACK, a program packer, by Joseph K. Horn.

Purpose: Shrinks and speeds up programs that contain SYSEVALs.  Has no
effect on programs that do not contain SYSEVALs.

Instructions: Recall program object to the stack.  Run PACK.  Store the
new program object into a new name or into its old variable name if so
desired. The newly PACKed program will be shorter and run faster than
the old one.

Theory: The SYSEVAL instruction takes a binary integer as its argument. 
But a binary integer followed by SYSEVAL takes up 31 nibbles, and can be
replaced by just the leading five nibbles of the binary integer.  Such
replacement not only uses less memory, but runs faster.  Unfortunately,
these objects do not have names, and show up in listings as "External",
rendering the program unreadable and uneditable.  But it runs just fine.

Note well: PACK was intended for use on programs, but performs the same
packing on lists.  If a list contains a binary integer immediately
followed by a SYSEVAL, both will be replaced by the equivalent External
object.

PACK should only be used on the final version of a program, because once
a program contains External objects, it is not editable by normal
methods.  A good practice might be to keep an "original version" with
SYSEVALs, and a "working copy" PACKed and ready to use, in two separate
variables.

EXAMPLE 1:  You wish to make a key assignment that puts you into the
hidden directory.  Let's put it on the POLAR key.  Normally you'd do
this:

     {  <<  HOME  #15777h  SYSEVAL  >>  82.3  }

and then press STOK (in the blue-CST menu).  That would work.  But
before you press STOK, run PACK; the list becomes { << HOME External >>
82.3 } because the address #15777h and the SYSEVAL got replaced by the
equivalent External object.  Now press STOK, and the assignment will be
26 nibbles shorter and a little bit faster.  (If you actually did this
example, you may delete this key assignment, if you wish, by typing 82.3
and pressing DELK.)

EXAMPLE 2:  You have a program that looks like this:

<<  #18CD7 SYSEVAL  #21922 SYSEVAL  #3DEF SYSEVAL  #62F89 SYSEVAL  >>

It takes a port number (0, 1 or 2) and recalls that port's objects onto
the stack.  It is 72 bytes long (checksum: #CBDAh).  PACK it, and it
shrinks to only 20 bytes long, but is no longer readable or editable.

Here is 'PACK' in Bill Wickes ASC-> form.  Download it into PACK, run
ASC-> on it, and store it back into PACK.

%%HP:;
"D9D20E1632D9D202BA81AD2A18DA16D9D20FD55035040C1C1612040CCD207200
08F14660CC8FB9760D81431301691746E50B2130D9D208813020950FD5502C23
0F6E30C1C1632230CCD20C50008F14660CC8FB9760D8143130169174143131AE
015B03103A6A31939EA903170A6A148161170CD56D8D34150B2130B9F06B2130
3303278BF1C2A2052000030303030303030303030354235314134BAC178BF1D5
032D9D202ABF133920100000000000061090DA19C2A2DBBF1C58C1E0CF178BF1
803A2A9CF1D13A290DA178BF1803A276BA1C58C1DBBF1803A25BCF1339201000
00000000061076BA1FDAA1C58C176BA176BA1B2130496328DBF1D9D202BA812B
F81D0040D9D205D55022650C1C16226509FF306C426CCD20D80008F14660CC8F
B9760D814313016817414313117716017114B31149EED13103B6A45331909E6C
215006910B6A31509E68130AA0A1500CD5AB8D341508F2D7603468F01808E300
40C9B26B9F06B2130B213093632B2130253F"

Here is 'PACK' in UUENCODED form for THOSE people...

----------------------cut here--------------------------
begin 600 pack
M2%!(4#0X+4&=+>!A(YTM(*L8VJ*!K6&=+?!=!5-`P,%A(4#`W`(G`(`?9`;,
M^)MGT!@T,1"6<61>L!(#G2V`&`,"6?!=!<(R\.8#'!PV(@/,+<`%`/A!9L",
MOWD&C4$3`V$91T$3$^H0M3`!HZ83.>F:,'&@ID$8%G'`7=;80U&P$@.;#[82
M`S,P<K@?+"I0`@`P,#`P,#`P,#`P,$4R-4$QM,IQN!]=,-+9`J+[,9,"`0``
M````8`$)K9$L*KW[P84<#OQQN!\(HZ+)'QVCDM`:A_N!,"IGJ\&%'+W[@3`J
MM?PQDP(!``````!@`6>K\:T:7,AQMAIGJ[$2`Y0V@KT?G2T@JQBRC]$`!)TM
M4%T%(E;`P6$B5I#_`\8DQMP"C0"`'V0&S/B;9]`8-#$0AG$4-#$1=V$0%T$[
M$93N'1,P:THU$PGIQA(%8!FPIA,%Z88QH`H:!<!=NMA#48`O?09#A@^!@#X`
0!)PKMOE@*S&P$@,Y-K(2`P'Y
`
end
----------------------cut here--------------------------

Thanks to Rick Grevelle & Derek Nickel for the tools used here.

--  Joseph K. Horn  --  (714) 858-0920  --  Peripheral Vision, Ltd.  --