home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0400 / CCE_0483.ZIP / CCE_0483.PD / LZH_SOUR.CE / LHA5.S < prev    next >
Text File  |  1992-04-10  |  36KB  |  809 lines

  1.                 import flg_n                ; <> 0, wenn kein Output
  2.  
  3.                 import output_pos
  4.                 import output_mask
  5.                 import bufsiz
  6.                 import send_block
  7.                 import buf
  8.                 import c_freq
  9.                 import p_freq
  10.  
  11.                 import avail
  12.                 import next
  13.                 export childcount
  14.                 import prev
  15.                 import parent
  16.                 import level
  17.                 import position
  18.                 import pos
  19.                 export text
  20.                 import remainder
  21.                 import infile
  22.                 import _StdErrF
  23.                 import _StdOutF
  24.                 import unpackable
  25.                 import origsize
  26.                 import compsize
  27.  
  28.                 import memmove
  29.                 import memcpy
  30.                 import fread_crc
  31.                 import fputc
  32.                 import putc
  33.                 import make_crctable
  34.                 import allocate_memory
  35.                 import start_huf
  36.                 import end_huf
  37.                 import allocate_memory
  38.                 import init_slide
  39.                 import start_huf
  40.  
  41.                 export split
  42.                 export insert_node
  43.                 export delete_node
  44.                 export get_next_match
  45.                 export encode5
  46.                 export init_encode5 
  47.                 export output5
  48.  
  49.  
  50. init_slide:
  51.                 move.l  A2,-(SP)
  52.                 move.w  #$2000,D0
  53.                 lea     level,A0
  54.                 lea     position,A1
  55.                 bra.b   islide2
  56. islide1:        movea.l (A0),A2
  57.                 move.b  #1,0(A2,D0.w)
  58.                 move.w  D0,D1
  59.                 ext.l   D1
  60.                 add.l   D1,D1
  61.                 movea.l (A1),A2
  62.                 clr.w   0(A2,D1.l)
  63.                 addq.w  #1,D0
  64. islide2:
  65.                 cmp.w   #$20FF,D0
  66.                 ble.b   islide1
  67.                 move.w  #$2000,D0
  68.                 lea     parent,A1
  69.                 bra.b   islide4
  70. islide3:
  71.                 move.w  D0,D1
  72.                 ext.l   D1
  73.                 add.l   D1,D1
  74.                 movea.l (A1),A0
  75.                 clr.w   0(A0,D1.l)
  76.                 addq.w  #1,D0
  77. islide4:
  78.                 cmp.w   #$4000,D0
  79.                 blt.b   islide3
  80.                 move.w  #1,avail
  81.                 moveq   #1,D0
  82.                 lea     next,A1
  83.                 bra.b   islide6
  84. islide5:
  85.                 moveq   #1,D1
  86.                 add.w   D0,D1
  87.                 move.w  D0,D2
  88.                 ext.l   D2
  89.                 add.l   D2,D2
  90.                 movea.l (A1),A0
  91.                 move.w  D1,0(A0,D2.l)
  92.                 addq.w  #1,D0
  93. islide6:
  94.                 cmp.w   #$1FFF,D0
  95.                 blt.b   islide5
  96.                 movea.l (A1),A0
  97.                 clr.w   $3FFE(A0)
  98.                 move.w  #$4000,D0
  99.                 bra.b   islide8
  100. islide7:
  101.                 move.w  D0,D1
  102.                 ext.l   D1
  103.                 add.l   D1,D1
  104.                 movea.l (A1),A0
  105.                 clr.w   0(A0,D1.l)
  106.                 addq.w  #1,D0
  107. islide8:
  108.                 cmp.w   #$70EF,D0
  109.                 ble.b   islide7
  110.                 movea.l (SP)+,A2
  111.                 rts
  112.  
  113. ; --------------------------------------; beg child
  114. slide:          moveq   #0,D2           ; 
  115.                 move.b  D1,D2           ;
  116.                 lsl.w   #4,D2           ; 
  117.                 add.w   D0,D2           ;
  118.                 add.w   #$4000,D2       ; h=HASH(q,c)
  119.                 ext.l   d2              ; h
  120.                 add.l   D2,D2           ; 2*h
  121.                 move.w  D0,(A2)         ; parent[NIL]=q
  122. child1:         move.w  0(A4,D2.l),D1   ; r=next[r]
  123.                 move.w  D1,D2           ; r
  124.                 ext.l   D2              ; r
  125.                 add.l   D2,D2           ; 2*r
  126.                 cmp.w   0(A2,D2.l),D0   ; while (parent[r] != NIL)
  127.                 bne.b   child1          ; 
  128.                 move.w  D1,D0           ; return r
  129.                 rts                     ; end child
  130. ; --------------------------------------;
  131. makechild:      movem.l D3/d4,-(SP)
  132.                 moveq   #0,D4
  133.                 move.b  D1,D4
  134.                 lsl.w   #4,D4           ; c<<DICBIT-9
  135.                 add.w   D0,D4           ; p+c
  136.                 add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  137.                 move.w  D4,D1           ; h
  138.                 ext.l   D4              ; h
  139.                 add.l   D4,D4           ; 2*h
  140.                 move.w  0(A4,D4.l),D3   ; t=next[h]
  141.                 move.w  D2,0(A4,D4.l)   ; next[h]=r
  142.                 move.w  D2,D4           ; r
  143.                 ext.l   D4              ; r
  144.                 add.l   D4,D4           ; 2*r
  145.                 move.w  D3,0(A4,D4.l)   ; next[r]=t
  146.                 ext.l   D3              ; t
  147.                 add.l   D3,D3           ; 2*t
  148.                 move.w  D2,0(A3,D3.l)   ; prev[t]=r
  149.                 move.w  D1,0(A3,D4.l)   ; prev[r]=h
  150.                 move.w  D0,0(A2,D4.l)   ; parent[r]=q
  151.                 movea.l childcount-pos(a6),A0   ; 
  152.                 addq.b  #1,0(A0,D0.w)   ; childcount[q]++
  153.                 movem.l (SP)+,d3/d4
  154.                 rts
  155.  
  156.  
  157. ;».MODULE LOCAL
  158.  
  159. ; --------------------------------------;
  160. insert_node:                            ;
  161.                 cmp.w   #4,d7           ; if (matchl >= 4)
  162.                 blt     inode7          ;
  163.                 subq.w  #1,d7           ; matchl--
  164.                 moveq   #1,D4           ;
  165.                 add.w   d6,D4           ;
  166.                 or.w    #$2000,D4       ; r=(matchpos+1)|DICSIZ
  167. ; --------------------------------------;
  168.  
  169. ; --------------------------------------;
  170.                 bra.b   inode2          ; while ((q=parent[r]==NIL) {
  171. inode1:         move.w  0(A4,D0.l),D4   ;   r=next[r]
  172. inode2:         move.w  D4,D0           ;   r
  173.                 ext.l   D0              ;   r
  174.                 add.l   D0,D0           ;   r * 2
  175.                 move.w  0(A2,D0.l),D5   ;   q=parent[r]
  176.                 beq.b   inode1          ; }
  177. ; --------------------------------------;
  178.  
  179. ; --------------------------------------;
  180.                 movea.l level,A0        ;
  181.                 bra.b   inode4          ; while (level[q] >= matchl) {
  182. inode3:         move.w  D5,D4           ;   r = q
  183. ;               ext.l   D5              ;   q
  184.                 add.l   D5,D5           ;   q * 2
  185.                 move.w  0(A2,D5.w),D5   ;   q=parent[q]
  186. inode4:         moveq   #0,D0           ;   
  187.                 move.b  0(A0,D5.w),D0   ;   level[q]
  188.                 cmp.w   D0,d7           ; }
  189.                 ble.b   inode3          ;
  190. ; --------------------------------------;
  191.  
  192. ; --------------------------------------;
  193.                 move.w  D5,D0           ; t = q
  194.                 movea.l position-pos(a6),A0     ; while (position[t] < 0) {
  195.                 bra.b   inode6          ;
  196. inode5:         move.w  (A6),0(A0,D0.l) ;   position[t] = pos
  197.                 move.w  0(A2,D0.l),D0   ;   t=parent[t]
  198. inode6:     ;   ext.l   D0              ;   t
  199.                 add.l   D0,D0           ;   t * 2
  200.                 move.w  0(A0,D0.l),D1   ;   position[t]
  201.                 blt.b   inode5          ; }
  202. ;    end while  ----------------------- ;
  203.                 cmp.w   #$4000,D0       ; if (t < DICSIZ) {
  204.                 bge     inode9          ;
  205.                 move.w  (A6),D2         ;   pos
  206.                 or.w    #$8000,D2       ;   pos | PERC_FLAG
  207.                 move.w  D2,0(A0,D0.l)   ;   position[t] = pos | PERC_FLAG
  208.                 bra     inode9          ;
  209. ; --------------------------------------:
  210. inode7:         move.w  (A6),D0         ; pos
  211.                 movea.l text-pos(a6),A0         ;
  212.                 moveq   #0,d5           ;
  213.                 move.b  0(A0,D0.w),D5   ; q = text[pos]
  214.                 add.w   #$2000,D5       ; + DICSIZE
  215.                 move.b  1(A0,D0.w),d7   ; c = text[pos+1]
  216.                 move.b  d7,D1           ; c
  217. ; --------------------------------------; beg child
  218.                 moveq   #0,D2           ; 
  219.                 move.b  D1,D2           ;
  220.                 lsl.w   #4,D2           ; 
  221.                 add.w   D5,D2           ;
  222.                 add.w   #$4000,D2       ; h=HASH(q,c)
  223.                 ext.l   d2              ; h
  224.                 add.l   D2,D2           ; 2*h
  225.                 move.w  D5,(A2)         ; parent[NIL]=q
  226. nchild1:        move.w  0(A4,D2.l),D1   ; r=next[r]
  227.                 move.w  D1,D2           ; r
  228.                 ext.l   D2              ; r
  229.                 add.l   D2,D2           ; 2*r
  230.                 cmp.w   0(A2,D2.l),D5   ; while (parent[r] != NIL)
  231.                 bne.b   nchild1         ; 
  232.                 move.w  D1,D0           ; return r
  233. ; --------------------------------------;
  234.                 move.w  D0,D4           ; r = child(q,c)
  235.                 bne.b   inode8          ; if ((r=child(q,c)) == NIL)
  236. ; --------------------------------------;
  237.  
  238. ; ++++++++++++++++++++++++++++++++++++++;
  239.                 move.w  (A6),D2         ; pos
  240.                 moveq   #0,d4
  241.                 move.b  d7,D4           ; c
  242. ; --------------------------------------; makechild
  243.                 lsl.w   #4,D4           ; c<<DICBIT-9
  244.                 add.w   d5,D4           ; p+c
  245.                 add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  246.                 move.w  D4,D1           ; h
  247.                 ext.l   D4              ; h
  248.                 add.l   D4,D4           ; 2*h
  249.                 move.w  0(A4,D4.l),D3   ; t=next[h]
  250.                 move.w  D2,0(A4,D4.l)   ; next[h]=r
  251.                 move.w  D2,D4           ; r
  252.                 ext.l   D4              ; r
  253.                 add.l   D4,D4           ; 2*r
  254.                 move.w  D3,0(A4,D4.l)   ; next[r]=t
  255.                 ext.l   D3              ; t
  256.                 add.l   D3,D3           ; 2*t
  257.                 move.w  D2,0(A3,D3.l)   ; prev[t]=r
  258.                 move.w  D1,0(A3,D4.l)   ; prev[r]=h
  259.                 move.w  d5,0(A2,D4.l)   ; parent[r]=q
  260.                 movea.l childcount-pos(a6),A0   ; 
  261.                 addq.b  #1,0(A0,d5.w)   ; childcount[q]++
  262. ; --------------------------------------; makechild
  263.                 move.w  #1,d7           ; matchl=1
  264.                 rts                     ; return
  265. ; ++++++++++++++++++++++++++++++++++++++;
  266.  
  267. ; --------------------------------------;
  268. inode8:         moveq   #2,d7           ; matchl=2
  269. inode9:         cmp.w   #$2000,D4       ; if (r>DICSIZ)
  270.                 blt.b   inode10         ;
  271.                 move.w  #$0100,d2       ; j = MAXMATCH
  272.                 move.w  D4,d6           ; matchpos=r
  273.                 bra.b   inode11         ;
  274. inode10:        movea.l level,A0        ;
  275.                 clr.w   d2              ;
  276.                 move.b  0(A0,D4.w),d2   ; r=level[r]
  277.                 move.w  D4,D0           ; r
  278. ;               ext.l   D0              ; r
  279.                 add.l   D0,D0           ; r*2
  280.                 movea.l position-pos(a6),A1     ;
  281.                 move.w  0(A1,D0.l),D1   ; position[r]
  282.                 and.w   #$7FFF,D1       ; position[r] & ~PERC_FLAG
  283.                 move.w  D1,d6           ; matchpos=position[r] & ~ PERC_FLAG
  284. inode11:        move.w  d6,D0           ; pos
  285.                 cmp.w   (A6),D0         ; matchpos
  286.                 blt.b   inode12         ; if (matchpos>=pos)
  287.                 subi.w  #$2000,d6       ; matchpos-=DICSIZE
  288. ; --------------------------------------;
  289. inode12:        move.w  (A6),D0         ; pos
  290.                 add.w   d7,D0           ; pos+matchl
  291.                 movea.l text-pos(a6),A0 ; text
  292.                 lea     0(a0,d0.w),a5
  293.                 move.w  d6,D1           ; matchpos
  294.                 add.w   d7,D1           ; matchpos+matchl
  295.                 lea     0(a0,d1.l),a0   ; t2=text[matchpos+matchl]
  296. itest:          move.w  d2,d0
  297.                 sub.w   d7,d0
  298.                 beq     inode14
  299.                 subq.w  #1,d0
  300. inode13:        cmpm.b  (A5)+,(A0)+     ;
  301. inode15:        dbne    d0,inode13      ; matchl<j
  302.                 bne     in_split
  303.                 neg.w   d0
  304.                 add.w   d2,d0
  305.                 subq.w  #1,d0
  306.                 move.w  d0,d7
  307. ; --------------------------------------;
  308. inode14:        cmp.w   #$0100,d7       ; if matchl>MAXMATCH
  309.                 bge     inode17         ; break
  310. ; --------------------------------------;
  311.  
  312. ; ++++++++++++++++++++++++++++++++++++++;
  313.                 move.w  D4,D0           ; r
  314.                 ext.l   D0              ;
  315.                 add.l   D0,D0           ; 2*r
  316.                 movea.l position-pos(a6),A0     ;
  317.                 move.w  (A6),0(A0,D0.l) ; position[r]=pos
  318.                 move.w  D4,D5           ; q=r
  319.                 moveq   #0,d2
  320.                 move.b  (A5),D2         ; *t1
  321. ; --------------------------------------; beg child
  322.                 lsl.w   #4,D2           ; 
  323.                 add.w   D5,D2           ;
  324.                 add.w   #$4000,D2       ; h=HASH(q,c)
  325.                 ext.l   d2              ; h
  326.                 add.l   D2,D2           ; 2*h
  327.                 move.w  D5,(A2)         ; parent[NIL]=q
  328. nchild2:        move.w  0(A4,D2.l),D1   ; r=next[r]
  329.                 move.w  D1,D2           ; r
  330.                 ext.l   D2              ; r
  331.                 add.l   D2,D2           ; 2*r
  332.                 cmp.w   0(A2,D2.l),D5   ; while (parent[r] != NIL)
  333.                 bne.b   nchild2         ; 
  334.                 move.w  D1,D0           ; return r
  335. ; --------------------------------------; end child
  336.                 move.w  D0,D4           ; r=child(q,*t1)
  337.                 bne.b   inode16         ; if ((r=child(q,*t1)) != NIL) {
  338.                 move.w  (A6),D2         ;   pos
  339.                 moveq   #0,d4
  340.                 move.b  (A5),D4         ;   *t1
  341. ; --------------------------------------; makechild
  342.                 lsl.w   #4,D4           ; c<<DICBIT-9
  343.                 add.w   d5,D4           ; p+c
  344.                 add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  345.                 move.w  D4,D1           ; h
  346.                 ext.l   D4              ; h
  347.                 add.l   D4,D4           ; 2*h
  348.                 move.w  0(A4,D4.l),D3   ; t=next[h]
  349.                 move.w  D2,0(A4,D4.l)   ; next[h]=r
  350.                 move.w  D2,D4           ; r
  351.                 ext.l   D4              ; r
  352.                 add.l   D4,D4           ; 2*r
  353.                 move.w  D3,0(A4,D4.l)   ; next[r]=t
  354.                 ext.l   D3              ; t
  355.                 add.l   D3,D3           ; 2*t
  356.                 move.w  D2,0(A3,D3.l)   ; prev[t]=r
  357.                 move.w  D1,0(A3,D4.l)   ; prev[r]=h
  358.                 move.w  d5,0(A2,D4.l)   ; parent[r]=q
  359.                 movea.l childcount-pos(a6),A0   ; 
  360.                 addq.b  #1,0(A0,d5.w)   ; childcount[q]++
  361. ; --------------------------------------; makechild
  362.                 rts                     ;   return
  363. ; ++++++++++++++++++++++++++++++++++++++;
  364.  
  365. ; --------------------------------------;
  366. inode16:        addq.w  #1,d7           ; matchl++
  367.                 bra     inode9          ; } /* for */
  368. ; --------------------------------------;
  369. inode17:        move.w  (a6),d3
  370.                 move.w  D4,D0           ; r
  371.                 ext.l   D0              ; r
  372.                 add.l   D0,D0           ; 2*r
  373.                 move.w  0(A3,D0.l),D1   ; t = prev[r]
  374.                 move.w  d3,D2           ; pos
  375.                 ext.l   D2              ; pos
  376.                 add.l   D2,D2           ; 2*pos
  377.                 move.w  D1,0(a3,D2.l)   ; prev[pos]=t
  378.                 ext.l   D1              ; t
  379.                 add.l   D1,D1           ; 2*t
  380.                 move.w  d3,0(A4,D1.l)   ; next[r] = pos
  381.                 move.w  0(A4,D0.l),D1   ; t=next[r]
  382.                 move.w  D1,0(A4,D2.l)   ; next[pos]=t
  383.                 ext.l   D1              ; t
  384.                 add.l   D1,D1           ; 2*t
  385.                 move.w  d3,0(a3,D1.l)   ; prev[t] = pos
  386.                 move.w  D5,0(A2,D2.l)   ; parent[pos]=q
  387.                 clr.w   0(A2,D0.l)      ; parent[r] = NIL
  388.                 move.w  d3,0(A4,D0.l)   ; next[r]=pos
  389. inode18:        rts                     ; 
  390. ; ++++++++++++++++++++++++++++++++++++++;
  391.  
  392. ; --------------------------------------;
  393. in_split:       
  394.                 neg.w   d0
  395.                 add.w   d2,d0
  396.                 subq.w  #1,d0
  397.                 move.w  d0,d7
  398.                 move.w  D4,D0           ;   split(r)
  399. ; --------------------------------------; split
  400. split:          move.w  avail-pos(a6),D3; new=avail
  401.                 move.w  D3,D2           ; new
  402.                 ext.l   D2              ; new
  403.                 add.l   D2,D2           ; new * 2
  404.                 move.w  0(A4,D2.l),avail-pos(a6) ; avail=next[new]
  405.                 movea.l childcount-pos(a6),A1
  406.                 clr.b   0(A1,D3.w)      ; childcount[new] = 0
  407.                 move.w  d0,d1
  408.                 ext.l   D1              ; old
  409.                 add.l   D1,D1           ; old * 2
  410.                 move.w  0(A3,D1.l),D0   ; t = prev[old]
  411.                 move.w  D0,0(A3,D2.l)   ; prev[new] = t
  412.                 ext.l   D0              ; t
  413.                 add.l   D0,D0           ; t * 2
  414.                 move.w  D3,0(A4,D0.l)   ; next[t] = new
  415.                 move.w  0(A4,D1.l),D0   ; t=next[old]
  416.                 move.w  D0,0(A4,D2.l)   ; next[new] = t
  417.                 ext.l   D0              ; t
  418.                 add.l   D0,D0           ; t * 2
  419.                 move.w  D3,0(A3,D0.l)   ; prev[t] = new
  420.                 move.w  0(A2,D1.l),0(A2,D2.l) ; parent[new] = parent[old]
  421.                 movea.l level,A0        ;
  422.                 move.b  d7,0(A0,D3.w)   ; level[new]=matchlen
  423.                 movea.l position-pos(a6),A0
  424.                 move.w  (a6),0(A0,D2.l) ; positon[new]=pos
  425. ; makechil(new,text[matchpos+matchlen],old)
  426.                 move.w  d6,D1           ;
  427.                 add.w   d7,D1           ;
  428.                 movea.l text-pos(a6),A0 ;
  429.                 move.w  d4,d2           ;
  430.                 moveq   #0,d4           ;
  431.                 move.b  0(A0,D1.w),D4   ;
  432. ; --------------------------------------;
  433.                 lsl.w   #4,D4           ; c<<DICBIT-9
  434.                 add.w   D3,D4           ; p+c
  435.                 add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  436.                 move.w  D4,D1           ; h
  437.                 ext.l   D4              ; h
  438.                 add.l   D4,D4           ; 2*h
  439.                 move.w  0(A4,D4.l),d5   ; t=next[h]
  440.                 move.w  D2,0(A4,D4.l)   ; next[h]=r
  441.                 move.w  D2,D4           ; r
  442.                 ext.l   D4              ; r
  443.                 add.l   D4,D4           ; 2*r
  444.                 move.w  d5,0(A4,D4.l)   ; next[r]=t
  445.                 ext.l   d5              ; t
  446.                 add.l   d5,d5           ; 2*t
  447.                 move.w  D2,0(A3,d5.l)   ; prev[t]=r
  448.                 move.w  D1,0(A3,D4.l)   ; prev[r]=h
  449.                 move.w  D3,0(A2,D4.l)   ; parent[r]=q
  450.                 movea.l childcount-pos(a6),A1   ; 
  451.                 addq.b  #1,0(A1,D3.w)   ; childcount[q]++
  452. ; --------------------------------------;
  453. ; makechild(new,text[pos+matchlen],pos)
  454.                 move.w  pos,D2
  455.                 move.w  d2,D0
  456.                 add.w   d7,D0
  457.                 moveq   #0,d4
  458.                 move.b  0(A0,D0.w),D4   ; text[pos+matchlen]
  459. ; --------------------------------------; makechild
  460.                 lsl.w   #4,D4           ; c<<DICBIT-9
  461.                 add.w   D3,D4           ; p+c
  462.                 add.w   #$4000,D4       ; ((p)+((c)<<(DICBIT-9))+(DICSIZ*2)
  463.                 move.w  D4,D1           ; h
  464.                 ext.l   D4              ; h
  465.                 add.l   D4,D4           ; 2*h
  466.                 move.w  0(A4,D4.l),D0   ; t=next[h]
  467.                 move.w  D2,0(A4,D4.l)   ; next[h]=r
  468.                 move.w  D2,D4           ; r
  469.                 ext.l   D4              ; r
  470.                 add.l   D4,D4           ; 2*r
  471.                 move.w  d0,0(A4,D4.l)   ; next[r]=t
  472.                 ext.l   d0              ; t
  473.                 add.l   d0,d0           ; 2*t
  474.                 move.w  D2,0(A3,d0.l)   ; prev[t]=r
  475.                 move.w  D1,0(A3,D4.l)   ; prev[r]=h
  476.                 move.w  D3,0(A2,D4.l)   ; parent[r]=q
  477.                 movea.l childcount-pos(a6),A0   ; 
  478.                 addq.b  #1,0(A0,D3.w)   ; childcount[q]++
  479. ; --------------------------------------;
  480.                 rts
  481.  
  482.  
  483. ; **************************************************************************
  484.  
  485.  
  486. get_next_match: subq.w  #1,remainder-pos(a6)
  487.                 addq.w  #1,(a6)
  488.                 cmpi.w  #$4000,(a6)
  489.                 bne.b   gnext1
  490.                 move.l  #$2100,D0
  491.                 movea.l text-pos(a6),A0
  492.                 lea     $2000(A0),A1
  493.                 bsr     memcpy
  494.                 movea.l infile,A1
  495.                 move.w  #$2000,D0
  496.                 movea.l text-pos(a6),A0
  497.                 lea     $2100(A0),A0
  498.                 bsr     fread_crc
  499.                 add.w   D0,remainder
  500.                 move.w  #$2000,pos
  501.                 move.b  flg_n,d0
  502.                 bne.b   gnext1
  503.                 lea     _StdOutF,A0
  504.                 moveq   #$2A,D0
  505.                 bsr     putc
  506. gnext1:         movem.l D3-d5/A2-A4,-(sp)
  507.                 movea.l parent-pos(a6),a2
  508.                 movea.l next-pos(a6),a4
  509.                 movea.l prev-pos(a6),a3
  510.  
  511. delete_node:    move.w  (a6),d2         ; d2=pos
  512.                 move.w  d2,D1           ; pos
  513.                 ext.l   D1              ; pos
  514.                 add.l   D1,D1           ; 2*pos
  515.                 move.w  0(A2,D1.l),D0   ; if (parent[pos] == NIL) 
  516.                 beq     dnode9          ;    return
  517.                 move.w  0(A3,D1.l),D3   ; r = prev[pos]
  518.                 move.w  0(A4,D1.l),D4   ; s = next[pos]
  519.                 move.w  D3,D0           ; r
  520.                 ext.l   D0              ; r
  521.                 add.l   D0,D0           ; 2 * r
  522.                 move.w  D4,0(A4,D0.l)   ; next[r]=s
  523.                 move.w  D4,D0           ; s
  524.                 ext.l   D0              ; s
  525.                 add.l   D0,D0           ; s * 2
  526.                 move.w  D3,0(A3,D0.l)   ; prev[s] = r
  527.                 move.w  0(A2,D1.l),D3   ; r = parent[pos]
  528.                 clr.w   0(A2,D1.l)      ; parent[pos] = NIL
  529.                 cmp.w   #$2000,D3       ; if (r >= DICSIZ)
  530.                 bge     dnode9          ;
  531.                 movea.l childcount-pos(a6),A1   ;   || 
  532.                 subq.b  #1,0(A1,D3.w)   ;   --childcount[r]
  533.                 cmpi.b  #1,0(A1,D3.w)   ;   > 1)
  534.                 bhi     dnode9          ;     return
  535.                 movea.l position-pos(a6),A1     ; position
  536.                 move.w  D3,D1           ; r
  537.                 ext.l   D1              ; r
  538.                 add.l   D1,D1           ; r * 2
  539.                 move.w  0(A1,D1.l),D5   ; t=position[r]
  540.                 and.w   #$7FFF,D5       ;      & ~PERC_FLAG
  541.                 cmp.w   d2,D5           ; if (t>=pos)
  542.                 blt.b   dnode1          ;
  543.                 sub.w   #$2000,D5       ;   t-=DICSIZ
  544. ;---------------------------------------;
  545. dnode1:         move.w  D5,D4           ; s = t
  546.                 move.w  d5,a0
  547.                 move.w  0(A2,D1.l),D0   ; q = parent[r]
  548.                 ext.l   d0              ; q
  549.                 add.l   d0,d0           ; q*2
  550.                 bra.b   dnode5          ; while ((u=position[q] & PERC_FLAG) {
  551. dnode2:         and.w   #$7FFF,d5       ;   u &= ~PERC_FLAG
  552.                 cmp.w   d2,d5           ;   if (u>=pos)
  553.                 blt.b   dnode3          ;
  554.                 sub.w   #$2000,d5       ;       u-=DICSIZ
  555. dnode3:         cmp.w   d5,D4           ;   if (u>=s)
  556.                 bge.b   dnode4          ;
  557.                 move.w  d5,D4           ;       s=u  
  558. dnode4:         move.w  D4,D1           ;   s
  559.                 or.w    #$2000,D1       ;   |DICSIZ
  560.                 move.w  D1,0(A1,D0.l)   ;   position[q] = s | DICSIZ
  561.                 move.w  0(A2,D0.l),D0   ;   q=parent[q]
  562. ;               ext.l   d0              ;   q
  563.                 add.l   d0,d0           ;   q*2
  564. dnode5:         move.w  0(A1,D0.l),d5   ;   u=position[q]
  565.                 move.w  d5,D1           ;   u
  566.                 and.w   #$8000,D1       ;   parent[r] & PERC_FLAG
  567.                 bne.b   dnode2          ; }
  568. ;   end_while   ------------------------;               
  569.                 cmp.w   #$4000,D0       ; if (q<DICISZ}
  570.                 bge.b   dnode8          ; { 
  571.                 cmp.w   d2,d5           ;   if (u>=pos)
  572.                 blt.b   dnode6          ;
  573.                 sub.w   #$2000,d5       ;      u-=DICSIZ
  574. dnode6:         cmp.w   d5,D4           ;   if (u>s)
  575.                 bge.b   dnode7          ;
  576.                 move.w  d5,D4           ;     s=u
  577. dnode7:         move.w  D4,D1           ;   s
  578.                 or.w    #$A000,D1       ;   s|DICSIZ|PERC_FLAG
  579.                 move.w  D1,0(A1,D0.l)   ;   position[q]=s|DICSIZ|PERC_FLAG
  580. ;---------------------------------------;
  581. dnode8:         movea.l level,A1        ; level
  582.                 clr.w   D0              ;
  583.                 move.b  0(A1,D3.w),D0   ; level[r]
  584.                 add.w   a0,D0           ; level[r]+t
  585.                 movea.l text-pos(a6),A1 ; text
  586.                 moveq   #0,d2
  587.                 move.b  0(A1,D0.w),D2   ; text[level[r]+t]
  588. ; --------------------------------------; beg child
  589.                 lsl.w   #4,D2           ; 
  590.                 add.w   D3,D2           ;
  591.                 add.w   #$4000,D2       ; h=HASH(q,c)
  592.                 ext.l   d2              ; h
  593.                 add.l   D2,D2           ; 2*h
  594.                 move.w  D3,(A2)         ; parent[NIL]=q
  595. dchild1:        move.w  0(A4,D2.l),D1   ; r=next[r]
  596.                 move.w  D1,D2           ; r
  597.                 ext.l   D2              ; r
  598.                 add.l   D2,D2           ; 2*r
  599.                 cmp.w   0(A2,D2.l),D3   ; while (parent[r] != NIL)
  600.                 bne.b   dchild1         ; 
  601.                 move.w  D1,D0           ; return r
  602. ; --------------------------------------; end child
  603.                 move.w  D0,D4           ; s
  604.                 ext.l   D0              ; s
  605.                 add.l   D0,D0           ; s*2
  606.                 move.w  0(A3,D0.l),D5   ; t=prev[s]
  607.                 move.w  0(A4,D0.l),D2   ; u=next[s]
  608.                 move.w  D5,D1           ; t
  609.                 ext.l   D1              ; 2*t
  610.                 add.l   D1,D1           ; t * 2
  611.                 move.w  D2,0(A4,D1.l)   ; next[t] = u
  612.                 ext.l   D2              ; u
  613.                 add.l   D2,D2           ; u * 2
  614.                 move.w  D5,0(A3,D2.l)   ; prev[u] = t
  615.                 move.w  D3,D2           ; r
  616.                 ext.l   D2              ; r
  617.                 add.l   D2,D2           ; r * 2
  618.                 move.w  0(A3,D2.l),D5   ; t = prev[r]
  619.                 move.w  D5,D1           ; t
  620.                 ext.l   D1              ; t
  621.                 add.l   D1,D1           ; t * 2
  622.                 move.w  D4,0(A4,D1.l)   ; next[t] = s
  623.                 move.w  D5,0(A3,D0.l)   ; prev[s] = t
  624.                 move.w  0(A4,D2.l),D5   ; t=next[r]
  625.                 move.w  D5,D1           ; t
  626.                 ext.l   D1              ; t
  627.                 add.l   D1,D1           ; t * 2
  628.                 move.w  D4,0(A3,D1.l)   ; prev[t]=s
  629.                 move.w  D5,0(A4,D0.l)   ; next[s]=t
  630.                 move.w  0(A2,D2.l),0(A2,D0.l) ; parent[s]=parent[r]
  631.                 clr.w   0(A2,D2.l)      ; parent[r]=NIL
  632.                 move.w  avail-pos(a6),0(A4,D2.l); next[r]=avail
  633.                 move.w  D3,avail-pos(a6); avail=r
  634. dnode9:         
  635. ; **************************************************************************
  636.                 bsr     insert_node
  637.                 movem.l (sp)+,d3-d5/a2-a4
  638.                 rts
  639.  
  640. encode5:        movem.l D3-D5/A2-A6,-(SP)
  641.                 move.l  D0,D3
  642.                 clr.w   unpackable      ; unpackable=0
  643.                 bsr     make_crctable   ; make_crctable()
  644.                 move.l  D3,origsize     ; origsize=orgsize
  645.                 clr.l   compsize        ; compsize=0
  646.                 lea     text,A2
  647.                 lea     remainder,A3    
  648.                 movea.l infile,A1       ; infile
  649.                 move.w  #$2100,D0       ; DICSIZ+MAXMATCH
  650.                 movea.l (A2),A0         ; text
  651.                 lea     $2000(A0),A0    ; text[DICSIZE]
  652.                 jsr     fread_crc(PC)   ; fread_crc
  653.                 move.w  D0,(A3)         ; remainder=fread_crcx
  654.                 move.b  flg_n,d0
  655.                 bne.b   enc51
  656.                 lea     _StdOutF,A0     ; stderr
  657.                 moveq   #$2A,D0         ; '*'
  658.                 jsr     putc(PC)        ; putc('*',stderr)
  659. enc51:          moveq   #0,d7           ; matchlen=0
  660.                 lea     pos,A6          ; pos
  661.                 move.w  #$2000,(A6)     ; pos=DICSIZ
  662.                 movem.l D3-d5/A2-A4,-(SP)   
  663.                 movea.l parent-pos(a6),a2
  664.                 movea.l next-pos(a6),a4
  665.                 movea.l prev-pos(a6),a3
  666.                 bsr     insert_node      ; insert_node
  667.                 movem.l (sp)+,D3-d5/A2-A4
  668. ; --------------------------------------;
  669.                 bra.b   encod7          ; while
  670. encod1:         move.w  d7,D4           ; lastmatchlen=matchlen
  671.                 move.w  d6,D5           ; lastmatchpos=matchpos
  672.                 bsr     get_next_match  ; get_next_match
  673.                 cmp.w   (A3),D7         ; if (matchlen>remainder)
  674.                 ble.b   encod2
  675.                 move.w  (A3),d7         ;   matchlen=remainder
  676. encod2:         cmp.w   d7,D4           ; if (matchlen>lastmatchlen
  677.                 blt.b   encod3          ; ||
  678.                 cmp.w   #3,D4           ; lastmatchlen<THRESHOLD)
  679.                 bge.b   encod4
  680. encod3:         clr.w   D1              ; 0
  681.                 move.w  (A6),D0         ; pos
  682.                 movea.l (A2),A0         ; text
  683.                 clr.w   D2              ;
  684.                 move.b  -1(A0,D0.w),D2  ; text[pos-1]
  685.                 move.w  D2,D0           ;
  686.                 bsr     output5         ; output5(..)
  687.                 bra.b   encod8
  688. ; --------------------------------------;
  689. encod4:         move.w  (A6),D1         ; pos
  690.                 sub.w   D5,D1           ; pos-lastmatchpos
  691.                 subq.w  #2,D1           ; pos-lastmatchpos-2
  692.                 and.w   #$1FFF,D1       ; (pos-lastmatchpos-2)&(UCHAR_MAX+1-THRESHOLD)
  693.                 move.w  D4,D0           ; lastmatchlen
  694.                 add.w   #$FD,D0         ; lastmatchlen+UCHAR_MAX+1-THRESHOLD
  695.                 bsr     output5         ; output5
  696. ; --------------------------------------;
  697.                 bra.b   encod6          ; while (--lastmatchlen>0)
  698. encod5:         bsr     get_next_match  ;  get_next_match
  699. encod6:         subq.w  #1,D4           ;
  700.                 bgt.b   encod5          ;
  701. ; --------------------------------------;
  702. encod7:         cmp.w   (A3),D7         ; if (matchlen>remainder)
  703.                 ble.b   encod8          ;   
  704.                 move.w  (A3),d7         ;   matchlen=remainder
  705. ; --------------------------------------;
  706. encod8:         move.w  (A3),D0         ; remainder
  707.                 ble.b   encod9          ; <0
  708.                 move.w  unpackable,D1   ; !unpackable
  709.                 beq.b   encod1          ;
  710. ; --------------------------------------;
  711. encod9:         bsr     end_huf         ; end_huf
  712.                 move.w  unpackable,D0   ; if (unpackable)
  713.                 beq.b   encod10
  714.                 moveq   #1,D1           ; 1
  715.                 add.l   D3,D1           ; orgsize+1
  716.                 move.l  D1,compsize     ; compsize=orgsize+1
  717. encod10:        move.l  compsize,D0     ; return compsize
  718.                 movem.l (SP)+,D3-D5/A2-A6
  719.                 rts
  720.  
  721.  
  722. init_encode5:
  723.                 jsr     allocate_memory(PC)
  724.                 jsr     init_slide(PC)
  725.                 jsr     start_huf(PC)
  726.                 rts
  727.  
  728.  
  729. output5:        movem.l D3-D4/A2-A3,-(SP)
  730.                 move.w  D0,D3
  731.                 move.w  D1,D4
  732.                 lea     output_pos,A2
  733.                 lea     buf,A3
  734.                 lsr.w   output_mask         ; output_mask >> 1
  735.                 move.w  output_mask,D2      ; if {output_mask = 0) {
  736.                 bne.b   out5_2
  737.                 move.w  #$80,output_mask    ; output_mask=1U <<(CHAR_BIT-1)
  738.                 moveq   #-$18,D2            ; -3*CHAR_BIT
  739.                 add.w   bufsiz,D2           ; -3*CHAR_BIT+bufsize
  740.                 movea.w (A2),A0             ; output_pos
  741.                 cmpa.w  D2,A0               ; if (output_pos>=buf...) {
  742.                 bcs.b   out5_1  
  743.                 bsr     send_block          ; send_block
  744.                 move.w  unpackable,D0       ; if (unpackable) 
  745.                 bne     out5_5              ;   return
  746.                 clr.w   (A2)                ; output_pos=0
  747. out5_1:         move.w  (A2),cpos           ; cpos=output_pos
  748.                 addq.w  #1,(A2)             ; output_pos++
  749.                 moveq   #0,D0               ; 0
  750.                 move.w  cpos,D0             ; cpos
  751.                 movea.l (A3),A0             ; buf
  752.                 clr.b   0(A0,D0.l)          ; buf[cpos]=0
  753. out5_2:         moveq   #0,D0
  754.                 move.w  (A2),D0             ; output_pos
  755.                 movea.l (A3),A0             ; buf
  756.                 move.b  D3,0(A0,D0.l)       ; buf[output_pos]=c
  757.                 addq.w  #1,(A2)             ; output_pos++
  758.                 move.w  D3,D0               ; c
  759.                 add.w   D0,D0               ; c*2
  760.                 lea     c_freq,A0           ; c_freq
  761.                 addq.w  #1,0(A0,D0.w)       ; c_freq[c]++
  762.                 cmp.w   #$0100,D3           ; if (c>=(1U<<CHAR_BIT)
  763.                 bcs.b   out5_5              ; 
  764.                 move.b  output_mask+1,D1    ; output_mask
  765.                 moveq   #0,D2               ;
  766.                 move.w  cpos,D2             ; cpos
  767.                 movea.l (A3),A1             ; buf
  768.                 or.b    D1,0(A1,D2.l)       ; buf[cpos] != output_mask
  769.                 move.w  D4,D1               ; p
  770.                 lsr.w   #8,D1               ; p>>CHAR_BIT
  771.                 moveq   #0,D2               ;
  772.                 move.w  (A2),D2             ; output_pos
  773.                 movea.l (A3),A1             ; buf
  774.                 move.b  D1,0(A1,D2.l)       ; buf[output_pos]=p>>CHAR_BIT
  775.                 addq.w  #1,(A2)             ; output_pos++
  776.                 moveq   #0,D2               ;
  777.                 move.w  (A2),D2             ; output_pos
  778.                 movea.l (A3),A1             ; buf
  779.                 move.b  D4,0(A1,D2.l)       ; buf[output_pos]=p
  780.                 addq.w  #1,(A2)             ; output_pos++
  781.                 clr.w   D3                  ; c=0
  782. ; ------------------------------------------;
  783.                 bra.b   out5_4              ; while (p) {
  784. out5_3:         lsr.w   #1,D4               ;    p>>=1
  785.                 addq.w  #1,D3               ;    c++
  786. out5_4:         tst.w   D4                  ; }
  787.                 bne.b   out5_3              ;
  788. ; ------------------------------------------;
  789.                 move.w  D3,D0               ; c
  790.                 add.w   D0,D0               ; 2*2
  791.                 lea     p_freq,A0           ; p_freq
  792.                 addq.w  #1,0(A0,D0.w)       ; p_freq[c]++
  793. out5_5:         movem.l (SP)+,D3-D4/A2-A3   ; return
  794.                 rts
  795.  
  796. position:       dc.l    0
  797. next:           dc.l    0
  798. prev:           dc.l    0
  799. parent:         dc.l    0
  800. pos:            dc.l    0
  801. avail:          dc.l    0
  802. remainder:      dc.l    0
  803. cpos:           dc.w    0
  804. text:           dc.l    0
  805. childcount:     dc.l    0
  806. unpackable:     dc.l    0
  807.  
  808.                 END
  809.