*** SFX (SelF-eXtracting LHA/LZH compressed files)
*** Document revision: 1.3
*** Last updated: March 11, 2004
*** Contributors/sources: Chris Smeets

  These  files  are  actually  LHA  archives,  except  there  they  have  a
decompressor program prepended to the file,  capable  of  decompressing  on
either a C64 or a C128, independant of the load address. The  beginning  of
the file is a BASIC program (with an unusual load address):

       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
       -----------------------------------------------
00000: 01 1C 28 1C C6 07 97 32 30 2C 30 3A 8B C2 28 32 <-Note load address
00010: 30 29 B2 30 A7 FE 02 30 3A 9E C2 28 34 36 29 AC
00020: 32 35 36 AA 36 36 3A 80 00 3C 1C D0 07 9E C2 28
00030: 34 34 29 AC 32 35 36 AA 36 36 3A 80 00 00 00 ..

which when decoded looks like this:

1990 POKE20,0:IFPEEK(20)=0THEN<254><2>0:SYSPEEK(46)*256+66:END
2000 SYSPEEK(44)*256+66:END

  This was decoded on a C64... the two codes in line 1990,  the  <254>  and
<2>0 are not decodable on the C64, but are on  the  C128.  The  first  line
checks for whether it is running on a C64 or a 128. If it is a C64, it will
execute the SYS call line 2000, otherwise it executes the SYS on line 1990.

  Later on in the header, we have the copyright  message.  Any  SFX  should
have this message.

       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F        ASCII
       -----------------------------------------------   ----------------
00D20: .. .. .. .. .. .. .. .. .. .. .. 43 36 34 2F 43   ...........C64/C
00D30: 31 32 38 20 53 45 4C 46 20 45 58 54 52 41 43 54   128 SELF EXTRACT
00D40: 49 4E 47 20 4C 48 41 52 43 48 49 56 45 0D 43 4F   ING LHARCHIVE.CO
00D50: 50 59 52 49 47 48 54 20 31 39 39 30 20 2D 20 43   PYRIGHT 1990 - C
00D60: 2E 53 4D 45 45 54 53 0D 54 4F 52 4F 4E 54 4F 2C   .SMEETS.TORONTO,
00D70: 43 41 4E 41 44 41 .. .. .. .. .. .. .. .. .. ..   CANADA..

  I have seen two different versions of the header, one which is 3711 bytes
long, and the other standard one which is 3721 bytes long. The only way  to
tell them apart is to examine the byte value at offset $0067 into the file.
If it is $CE, then we have the 3721 byte header. If it is $C4, then  it  is
the shorter 3711 byte header. Notice that the difference  between  the  two
values is 10, the same as the header difference.

  Typically, at address $0E89 (3721 bytes into the file) or at $0E7F  (3711
bytes in) you will find the beginning of the LHA archive,  denoted  by  two
bytes and the signature '-LH1-'.

00E80: .. .. .. .. .. .. .. .. .. 1E B6 2D 6C 68 31 2D   ...........-LH1-

  *ALL* LHA/LZH archives  have  this  type  of  signature  string  in  them
('-lhx-', where x is the type of compression used, with C64 archives  being
1, and most PC archives being 5). The actual archive starts 2 bytes  before
this string is found, and goes to the end of  the  file.  If  you  want  to
convert them to LHA, you can chop the front end off the  file  (up  to  two
bytes before the -lhx- string), and rename it to an LHA. It will then be  a
normal LHA file.

  Another way to handle SFX's is  to  extract  them  with  Star  LHA.  This
program handles both LHA and SFX formats, as they are basically  the  same.
Extract them as you would an LHA file (StarLHA -x xxxxxxxx.SFX).  For  more
information on the LHA/LZH layout, refer to the LHA topic.