home *** CD-ROM | disk | FTP | other *** search
- ;; Copyright 1988, Gail Zacharias. All rights reserved.
- ;; Permission is hereby granted to copy, reproduce, redistribute or
- ;; otherwise use this software provided there is no monetary profit
- ;; gained specifically from its use or reproduction, it is not sold,
- ;; rented, traded or otherwise marketed, and this copyright notice
- ;; and the software version number is included prominently in any copy
- ;; made.
- ;; This is compstream version 1.1.
- ;;
- ;; Send comments, suggestions, bug reports (not bloody likely), feature
- ;; requests, etc. to gz@entity.com.
- ;;
-
- load 'FlowCtlMacs.d'
- case object
-
- export (compinit, compwrite, compclose):code
- export (uncompinit, uncompread, uncompclose):code
-
- ; This is a library for use with MPW C programs. It implements compression
- ; and uncompression compatible with the unix compress/uncompress programs.
- ; (But note that the unix programs create files with a 3 byte header which
- ; is NOT handled by this library. It's up to the caller to take care of
- ; any headers).
- ;
- ;The compress module consists of three functions:
- ;(1) long compinit (maxbits, block_compress, outputfn, param)
- ; int maxbits, block_compress;
- ; int (*outputfn)();
- ; long param;
- ;This function allocates and initializes a compress stream and returns a
- ;'stream handle', or 0 if it can't allocate enough memory for its data
- ;structures (in which case MemErr contains the error code).
- ;maxbits must be an integer between 9 and 16. Larger values result in
- ; better compression but require more memory.
- ;block_compress should be non-zero to do 'block compression'. This is
- ; almost always a win, so use it. It requires no extra memory.
- ;outputfn should be the function to do actual I/O. It must be a function
- ; of 3 arguments:
- ; int outputfn(param, size, buffer)
- ; long param;
- ; int size;
- ; char *buffer;
- ; param will be the same param argument that was passed to compinit.
- ; The function should output the size bytes in buffer, and return a
- ; non-negative value if successful, or a negative value if an error
- ; occured. The outputfn will not be called again after it returns
- ; an error.
- ;(2) int compwrite (cstream, size, buffer)
- ; long cstream;
- ; int size;
- ; char *buffer;
- ; This function adds the size bytes in buffer to the compress stream. cstream
- ; is the stream handle returned by compinit. compwrite returns a non-negative
- ; value if successful or a negative value if an error occured. The value is
- ; actually the same as the value of last call to outputfn. Note that compwrite
- ; does buffering and so the calls to compwrite and outputfn are not precisely
- ; synchronized - a given call to compwrite might call outputfn several times or
- ; it might not call it at all. Once outputfn returns an error, compwrite will
- ; continue to return that error and never call outputfn again.
- ;(3) int compclose (cstream)
- ; long cstream;
- ; This function writes out any remaining characters in the stream buffer and
- ; frees its data structures. It returns an error code like compwrite.
-
- ;The uncompress module consists of three functions:
- ;(1) long uncompinit (maxbits, block_compress, inputfn, param)
- ; int maxbits, block_compress;
- ; int (*inputfn)();
- ; long param;
- ;This function allocates and initializes an uncompress stream and returns a
- ;'stream handle', or 0 if it can't allocate enough memory for its data
- ;structures (in which case MemErr contains the error code).
- ;maxbits and block_compress must be the values which were used by compress.
- ;inputfn should be the function to do actual I/O. It must be a function
- ; of 3 arguments:
- ; int inputfn(param, size, buffer)
- ; long param;
- ; int size;
- ; char *buffer;
- ; param will be the same param argument that was passed to compinit.
- ; The function should try to read size bytes into buffer, and return
- ; the number of bytes actually read. A negative value means an error
- ; occured, zero means end of file (no more bytes to be read). The inputfn
- ; will not be called again after it returns a non-positive value.
- ;(2) int uncompread (cstream, size, buffer)
- ; long cstream;
- ; int size;
- ; char *buffer;
- ; This function stores (at most) size bytes into buffer. cstream is the
- ; stream handle returned by uncompinit. uncompread returns the number of
- ; bytes read, or a non-positive value if there are no more bytes (in which case
- ; the value is actually the value returned by the last call to the inputfn).
- ; Note that uncompread does buffering and so the calls to uncompread and
- ; inputfn are not precisely synchronized - a given call to uncompread might
- ; call inputfn several times or it might not call it at all. Once inputfn
- ; returns a non-positive value, uncompread will continue to return that value
- ; and never call inputfn again.
- ;(3) int uncompclose (cstream)
- ; long cstream;
- ; This function frees the data structures used by the stream. It currently
- ; always returns 0 (no errors are possible).
-
- ; Edit history
- ; 6/3/88 gz 1.1 Started edit history. Fix in < 16 bit compression.
-
- MemErr equ $220
- _NewPtr opword $A100+30
- _DisposPtr opword $A000+31
- _Debugger opword $A9FF
-
-
- compress proc
-
- BUFSIZE equ 512 ;Output buffer size.
-
- CHECK_DIST equ 10000
-
- h equ d2
- h2 equ d3
- ch equ d4
- lastcode equ d5
- ncodes equ d6
- inpos equ d7
-
- codeptr equ a1 ;must be a1 (see write8codes)
- chtab equ a2
- lasttab equ a3
- codetab equ a4
-
- myregs reg d2-d7/a0-a4
- myregsz equ 44
- hisregs reg d2-d7/a2-a4/a6
- hisregsz equ 40
-
- fprec record 0
- hsize ds.l 1
- hshift ds.w 1
- rd_cnt ds.l 1
- rd_ptr ds.l 1
- wr_cnt ds.w 1
- wr_ptr ds.l 1
- wr_param ds.l 1
- wr_fn ds.l 1
- wr_error ds.l 1
- outpos ds.l 1
- cd_cnt ds.w 1
- cd_buf ds.w 9
- checkpos ds.l 1
- ratio ds.l 1
- codesz ds.w 1
- codelim ds.l 1
- maxcodelim ds.l 1
- savedregs ds.b myregsz
- wr_buf ds.b BUFSIZE
- fprecsz equ *
- endr
-
- macro
- writecode.&sz &code
- subq.w #1,cd_cnt(a6)
- if# mi then.s
- bsr.&default(&sz,'w') write8codes
- endif#
- move.w &code,-(codeptr)
- endm
-
- macro
- getchar.&sz &ch,&eoflab
- subq.l #1,rd_cnt(a6)
- if# ge then.s
- move.l rd_ptr(a6),a0
- moveq #0,&ch
- move.b (a0)+,&ch
- move.l a0,rd_ptr(a6)
- else#.s
- bsr filbuf
- move.l d0,&ch
- bmi.&default(&sz,'w') &eoflab
- endif#
- addq.l #1,inpos
- endm
-
- with fprec
-
- ;compinit (maxbits, block_compress, outputfn, param)
- entry compinit
- compinit
- move.l #fprecsz,d0
- _NewPtr
- if# ne then.s
- moveq #0,d0
- rts
- endif#
- movem.l hisregs,-(sp)
- move.l a0,a6
- move.l hisregsz+16(sp),wr_param(a6)
- move.l hisregsz+12(sp),wr_fn(a6)
- clr.l wr_error(a6)
- lea wr_buf(a6),a0
- move.l a0,wr_ptr(a6)
- move.w #BUFSIZE,wr_cnt(a6)
- move.l hisregsz+4(sp),d0 ;maxbits
- moveq #9,d1
- if# d0 lt.l d1 then.s
- move.l d1,d0
- endif#
- moveq #16,d1
- if# d0 gt.l d1 then.s
- move.l d1,d0
- endif#
- moveq #1,d1
- lsl.l d0,d1
- move.l d1,maxcodelim(a6)
- subq.w #8,d0
- move.w d0,hshift(a6)
- lsl.w #2,d0
- lea hsizes(pc),a0
- move.l -4(a0,d0.w),hsize(a6)
- move.l hsize(a6),d1
- move.l d1,d0
- _NewPtr
- bne @memer1
- move.l a0,chtab
- add.l d1,d1
- move.l d1,d0
- _NewPtr
- bne @memer2
- move.l a0,lasttab
- move.l d1,d0
- _NewPtr
- bne @memer3
- move.l a0,codetab
- clr.l ratio(a6)
- moveq #0,inpos
- move.l #3,outpos(a6)
- move.l #CHECK_DIST,checkpos(a6)
- move.w #9,codesz(a6)
- move.l #$200,codelim(a6)
- move.l #257,ncodes
- tst.l hisregsz+8(sp) ;block_compress
- if# eq then.s
- subq.l #1,ncodes
- move.l #-1,checkpos(a6)
- endif#
- move.l codetab,a0
- moveq #0,d0
- move.l hsize(a6),d1
- lsr.l #1,d1
- bra.s *+4
- move.l d0,(a0)+
- dbf d1,*-2
- move.w d0,(a0)
- move.w #8,cd_cnt(a6)
- lea cd_buf+16(a6),codeptr
-
- move.l a6,d0
- bsr filret
- move.l d0,lastcode
- bmi @done
- addq.l #1,inpos
-
- @loop getchar ch,@done
- move.l ch,h
- move.w hshift(a6),d0
- lsl.w d0,h
- eor.w lastcode,h
- move.l h,h2
- add.l h2,h2
- move.w 0(codetab,h2.l),d0
- if# ne then.s
- if# ch eq.b 0(chtab,h.l) then.s
- if# lastcode eq.w 0(lasttab,h2.l) then.s
- move.w d0,lastcode
- bra.s @loop
- endif#
- endif#
- moveq #1,d1
- tst.l h
- if# ne then.s
- move.l hsize(a6),d1
- sub.l h,d1
- endif#
- @search sub.l d1,h
- if# mi then.s
- add.l hsize(a6),h
- endif#
- move.l h,h2
- add.l h2,h2
- move.w 0(codetab,h2.l),d0
- if# ne then.s
- if# ch eq.b 0(chtab,h.l) then.s
- if# lastcode eq.w 0(lasttab,h2.l) then.s
- move.w d0,lastcode
- bra.s @loop
- endif#
- endif#
- ;;This imitates what looks to me like bug in unix compress,
- ;;just to stay exactly compatible...
- tst.b 0(chtab,h.l)
- bne.s @search
- tst.w 0(lasttab,h2.l)
- bne.s @search
- endif#
- endif#
- writecode lastcode
- if# ncodes eq.l codelim(a6) then.s
- bsr write8codes
- addq.w #1,cd_cnt(a6)
- addq.w #1,codesz(a6)
- move.l codelim(a6),d0
- add.l d0,d0
- if# d0 eq.l maxcodelim(a6) then.s
- addq.l #1,d0
- endif#
- move.l d0,codelim(a6)
- endif#
- if# ncodes lt.l maxcodelim(a6) then.s
- move.w ncodes,0(codetab,h2.l)
- move.b ch,0(chtab,h.l)
- move.w lastcode,0(lasttab,h2.l)
- addq.l #1,ncodes
- else#.s
- if# inpos cc.l checkpos(a6) then.s
- move.l inpos,d0
- add.l #CHECK_DIST,d0
- move.l d0,checkpos(a6)
- move.l inpos,d1
- moveq #8,d2
- sub.w cd_cnt(a6),d2
- mulu codesz(a6),d2
- lsr.w #3,d2
- add.l outpos(a6),d2
- bsr ScaledQuo
- if# d0 hi.l ratio(a6) then.s
- move.l d0,ratio(a6)
- else#.s
- writecode #256
- bsr write8codes
- addq.w #1,cd_cnt(a6)
- clr.l ratio(a6)
- move.l codetab,a0
- moveq #0,d0
- move.l hsize(a6),d1
- lsr.l #1,d1
- bra.s *+4
- move.l d0,(a0)+
- dbf d1,*-2
- move.w d0,(a0)
- move.l #257,ncodes
- move.w #9,codesz(a6)
- move.l #$200,codelim(a6)
- endif#
- endif#
- endif#
- move.l ch,lastcode
- bra @loop
-
- @done writecode lastcode
- bsr forcebuf
- move.l codetab,a0
- _DisposPtr
- @memer3 move.w MemErr,-(sp)
- move.l lasttab,a0
- _DisposPtr
- move.w (sp)+,MemErr
- @memer2 move.w MemErr,-(sp)
- move.l chtab,a0
- _DisposPtr
- move.w (sp)+,MemErr
- @memer1 move.l wr_error(a6),-(sp)
- move.w MemErr,-(sp)
- move.l a6,a0
- _DisposPtr
- move.w (sp)+,MemErr
- move.l (sp)+,d0
- movem.l (sp)+,hisregs
- rts
-
- hsizes:
- dc.l 887 ;9
- dc.l 1559 ;10
- dc.l 2801 ;11
- dc.l 5003 ;12
- dc.l 9001 ;13
- dc.l 18013 ;14
- dc.l 35023 ;15
- dc.l 69001 ;16
-
- ;256*(D1/D2) -> D0
- ScaledQuo:
- if# d1 ls.l #$FFFFFF then.s
- lsl.l #8,d1
- else#.s
- lsr.l #8,d2
- if# eq then.s
- moveq #-1,d0
- rts
- endif#
- endif#
- if# d2 ls.l #$FFFF then.s
- swap d1
- moveq #0,d0
- move.w d1,d0
- divu d2,d0
- swap d0
- move.w d0,d1
- swap d1
- divu d2,d1
- move.w d1,d0
- rts
- endif#
- moveq #0,d0
- move.w d1,d0
- swap d0
- clr.w d1
- swap d1
- move.l d2,a0
- moveq #16-1,d2
- @next add.l d0,d0
- addx.l d1,d1
- if# a0 ls.l d1 then.s
- sub.l a0,d1
- addq.w #1,d0
- endif#
- dbf d2,@next
- rts
-
- forcebuf: ;clobbers codeptr(=a1) and ncodes
- move.w cd_cnt(a6),ncodes
- cmp.w #8,ncodes
- if# ne then.s
- subq.w #1,cd_cnt(a6)
- if# pl then.s
- clr.w -(codeptr)
- endif#
- bsr.s write8codes
- mulu codesz(a6),ncodes ;Correction for really < 8 codes...
- lsr.w #3,ncodes
- sub.l ncodes,outpos(a6)
- add.w ncodes,wr_cnt(a6)
- sub.l ncodes,wr_ptr(a6)
- endif#
- tst.l wr_error(a6)
- if# pl then.s
- pea wr_buf(a6)
- move.l wr_ptr(a6),d0
- sub.l (sp),d0
- move.l d0,-(sp)
- move.l wr_param(a6),-(sp)
- move.l wr_fn(a6),a0
- jsr (a0)
- lea 12(sp),sp
- move.l d0,wr_error(a6)
- endif#
- rts
-
- ;assumes codeptr = a1
- write8codes:
- movem.l d2-d4,-(sp)
- @rewr moveq #0,d3
- move.w codesz(a6),d3
- move.l wr_ptr(a6),a0
- add.l d3,wr_ptr(a6)
- sub.w d3,wr_cnt(a6)
- if# mi then.s
- add.w wr_cnt(a6),d3
- pea wr_buf(a6)
- move.l (sp),wr_ptr(a6)
- lea BUFSIZE,a0
- move.w a0,wr_cnt(a6)
- sub.w d3,a0
- move.l a0,-(sp)
- move.l wr_param(a6),-(sp)
- tst.l wr_error(a6)
- if# pl then.s
- move.l wr_fn(a6),a0
- jsr (a0)
- move.l d0,wr_error(a6)
- endif#
- lea 12(sp),sp
- bra.s @rewr
- endif#
- add.l d3,outpos(a6)
- moveq #0,d1 ;d1 = leftover byte
- moveq #0,d2 ;d2 = # bits in this byte
- subq.w #8,d3 ;d3 = codesz - 8
- moveq #8-1,d4 ;d4 = count
- lea cd_buf+16(a6),codeptr
- @loop moveq #0,d0
- move.w -(codeptr),d0
- lsl.l d2,d0
- or.b d1,d0
- add.w d3,d2
- subq.w #8,d2
- if# mi then.s
- addq.w #8,d2
- move.w d0,(codeptr)+
- move.b -(codeptr),(a0)+
- move.b -(codeptr),d1
- else#.s
- move.l d0,(codeptr)+
- move.b -(codeptr),(a0)+
- move.b -(codeptr),(a0)+
- move.b -(codeptr),d1
- subq #1,codeptr
- endif#
- dbf d4,@loop
- lea cd_buf+16(a6),codeptr
- move.w #8-1,cd_cnt(a6)
- movem.l (sp)+,d2-d4
- rts
-
- ;compwrite(cstream, size, buf)
- entry compwrite
- compwrite:
- movem.l hisregs,-(sp)
- move.l hisregsz+4(sp),a6 ;cstream
- movem.l savedregs(a6),myregs
- move.l a0,-(sp)
- move.l wr_error(a6),d0
- bmi.s filret
- move.l hisregsz+4+12(sp),a0 ;buf
- move.l hisregsz+4+8(sp),d0 ;size
- subq.l #1,d0
- blt.s filbuf
- move.l d0,rd_cnt(a6)
- moveq #0,d0
- move.b (a0)+,d0
- move.l a0,rd_ptr(a6)
- rts
- filbuf move.l wr_error(a6),d0
- filret move.l (sp)+,a0
- movem.l myregs,savedregs(a6)
- movem.l (sp)+,hisregs
- rts
-
- ;compclose(cstream)
- export compclose
- compclose:
- move.l 4(sp),d0
- if# eq then.s
- rts
- endif#
- movem.l hisregs,-(sp)
- move.l d0,a6
- movem.l savedregs(a6),myregs
- moveq #-1,d0
- jmp (a0)
-
- endwith
- endproc
-
- uncompress proc
-
- BUFSIZE equ 512
-
- STRSIZE equ 8000
-
- lastchar equ d2
- lastcode equ d3
- ncodes equ d4
- codelim equ d5
- codesz equ d6
- readcnt equ d7
- codeptr equ a1
- strptr equ a2
- chartab equ a3
- codetab equ a4
-
- myregs reg d1-d7/a0-a4
- myregsz equ 48
- hisregs reg d2-d7/a2-a4/a6
- hisregsz equ 40
-
- fprec record 0
- codebuf ds.w 9
- strend ds.l 1
- maxcodelim ds.l 1
- rd_param ds.l 1
- rd_fn ds.l 1
- rd_ptr ds.l 1
- rd_cnt ds.w 1
- rd_error ds.l 1
- wr_cnt ds.l 1
- wr_ptr ds.l 1
- tempbuf ds.b 16
- savedregs ds.b myregsz
- rd_buf ds.b BUFSIZE
- fprecsz equ *
- endr
-
- with fprec
-
- macro
- readcode.&sz &dreg,&eoflab
- sub.w codesz,readcnt
- if# mi then.s
- bsr.&default(&sz,'w') read8codes
- bmi.&default(&sz,'w') &eoflab
- endif#
- moveq #0,&dreg
- move.w -(codeptr),&dreg
- endm
-
- macro
- putchar
- subq.l #1,wr_cnt(a6)
- if# ge then.s
- move.l wr_ptr(a6),a0
- move.b d1,(a0)+
- move.l a0,wr_ptr(a6)
- else#.s
- bsr flsbuf
- endif#
- endm
-
-
- ;uncompinit (maxbits, block_compress, inputfn, param)
- export uncompinit
- uncompinit
- move.l #fprecsz,d0
- _NewPtr
- if# ne then.s
- moveq #0,d0
- rts
- endif#
- movem.l hisregs,-(sp)
- move.l a0,a6
- move.l hisregsz+16(sp),rd_param(a6)
- move.l hisregsz+12(sp),rd_fn(a6)
- clr.w rd_cnt(a6)
- move.l #1,rd_error(a6)
- move.l hisregsz+4(sp),d0 ;maxbits
- moveq #9,d1
- if# d0 lt.l d1 then.s
- move.l d1,d0
- endif#
- moveq #16,d1
- if# d0 gt.l d1 then.s
- move.l d1,d0
- endif#
- moveq #1,d1
- lsl.l d0,d1
- move.l d1,maxcodelim(a6)
- sub.l #256,d1
- move.l d1,d0
- _NewPtr
- bne memer1
- lea -256(a0),chartab
- move.l d1,d0
- add.l d0,d0
- _NewPtr
- bne memer2
- lea -512(a0),codetab
- move.l #STRSIZE,d0
- _NewPtr
- bne memer3
- lea STRSIZE(a0),strptr
- move.l strptr,strend(a6)
-
- moveq #9,codesz
- move.l #$200,codelim
- moveq #0,readcnt
-
- move.l #256,ncodes
- tst.l hisregsz+8(sp) ;block_compress
- if# ne then.s
- addq.l #1,ncodes
- bset #31,readcnt ;use high word for flag...
- endif#
-
- move.l a6,d0
- moveq #-1,d1
- bsr flsret ;Init wr_cnt and wr_ptr.
-
- readcode lastcode,@done
- move.b lastcode,lastchar
-
- move.l lastcode,d1
- putchar
-
- @loop readcode d0,@done
- if# d0 eq.w #256 then.s
- tst.l readcnt
- if# mi then.s
- move.l d0,ncodes
- moveq #9,codesz
- move.l #$200,codelim
- clr.w readcnt
- readcode.s d0,@done
- endif#
- endif#
- move.l d0,d1
- if# d0 cc.l ncodes then.s
- move.b lastchar,-(strptr)
- move.l lastcode,d0
- endif#
- move.l d0,lastchar
- bra.s @get
- @getlp move.l lastchar,d0
- move.b 0(chartab,d0.l),-(strptr)
- add.l d0,d0
- move.w 0(codetab,d0.l),lastchar
- @get cmp.w #256,lastchar
- bcc.s @getlp
-
- if# ncodes lt.l maxcodelim(a6) then.s
- move.l ncodes,d0
- move.b lastchar,0(chartab,d0.l)
- add.l d0,d0
- move.w lastcode,0(codetab,d0.l)
- addq.l #1,ncodes
- endif#
- move.l d1,lastcode
- if# ncodes eq.l codelim then.s
- addq.w #1,codesz
- add.l codelim,codelim
- if# codelim eq.l maxcodelim(a6) then.s
- addq.l #1,codelim ;make it so this never triggers again
- endif#
- clr.w readcnt
- endif#
- move.b lastchar,d1
- bra.s @put
- @putlp move.b (strptr)+,d1
- @put putchar
- cmp.l strend(a6),strptr
- bne.s @putlp
- bra @loop
-
- @done bsr flush
- _debugger ;Shouldn't return
-
- ;Read 8 codes into codebuf
- ;Input: codesz
- ;Output: readcnt, codeptr or MI flag set if end of file.
- read8codes:
- movem.l d2-d5,-(sp)
- move.l rd_ptr(a6),a0
- move.l codesz,d0
- sub.w d0,rd_cnt(a6)
- if# lt then.s
- bsr.s fillbuf
- else#.s
- add.l d0,rd_ptr(a6)
- endif#
- lsl.w #3,d0
- sub.w codesz,d0
- bmi.s @ret
- move.w d0,readcnt
- moveq #1,d2 ;d2 = mask
- lsl.w codesz,d2
- subq.w #1,d2
- move.w codesz,d3 ;d3 = codesz - 8
- subq.w #8,d3
- lea codebuf+18(a6),codeptr
- move.w codesz,d4 ;d4 = byte count
- moveq #0,d5 ;d5 = # used bits in this byte
- @loop move.w d5,d1 ;save bit count
- add.w d3,d5
- move.b (a0)+,-(codeptr)
- subq #1,d4
- subq.w #8,d5
- if# lt then.s
- addq.w #8,d5
- move.b (a0),-(codeptr)
- move.w (codeptr)+,d0
- lsr.w d1,d0
- and.w d2,d0
- move.w d0,-(codeptr)
- bra.s @loop
- endif#
- move.b (a0)+,-(codeptr)
- move.b (a0),-(codeptr)
- subq #1,codeptr
- move.l (codeptr)+,d0
- lsr.l d1,d0
- and.w d2,d0
- move.w d0,-(codeptr)
- subq #1,d4
- bne.s @loop
- lea codebuf+18(a6),codeptr
- @ret movem.l (sp)+,d2-d5
- rts
-
- fillbuf:
- lea tempbuf(a6),codeptr ;handy areg....
- move.w rd_cnt(a6),d1
- add.w d1,d0
- bra.s @more
- move.b (a0)+,(codeptr)+
- @more dbf d0,*-2
- move.l rd_error(a6),d0
- if# gt then.s
- movem.l d1/a1,-(sp)
- pea rd_buf(a6)
- pea BUFSIZE
- move.l rd_param(a6),-(sp)
- move.l rd_fn(a6),a0
- jsr (a0)
- lea 12(sp),sp
- movem.l (sp)+,d1/a1
- move.l d0,rd_error(a6)
- endif#
- if# gt then.s
- lea rd_buf(a6),a0
- add.w d0,d1
- bmi.s @more
- sub.w d1,d0
- bra.s *+4
- move.b (a0)+,(codeptr)+
- dbf d0,*-2
- move.w d1,rd_cnt(a6)
- move.l a0,rd_ptr(a6)
- else#.s
- clr.w rd_cnt(a6)
- endif#
- move.l codeptr,d0
- lea tempbuf(a6),a0
- sub.l a0,d0
- rts
-
- ;uncompread(cstream, size, buf)
- export uncompread
- uncompread:
- movem.l hisregs,-(sp)
- move.l hisregsz+4(sp),a6 ;cstream
- movem.l savedregs(a6),myregs
- move.l a0,-(sp)
- move.l hisregsz+4+12(sp),a0 ;buf
- move.l hisregsz+4+8(sp),d0 ;size
- tst.l d1 ;we doing flush or flsbuf?
- if# mi then.s
- tst.l rd_error(a6)
- ble.s flseof
- else#.s
- subq.l #1,d0
- blt.s flsbuf
- move.b d1,(a0)+
- endif#
- move.l a0,wr_ptr(a6)
- move.l d0,wr_cnt(a6)
- rts
- flsbuf: move.l hisregsz+4+8(sp),d0 ;size
- flsret: move.l (sp)+,a0
- movem.l myregs,savedregs(a6)
- movem.l (sp)+,hisregs
- rts
-
- flush moveq #-1,d1
- move.l hisregsz+4+8(sp),d0
- sub.l wr_cnt(a6),d0
- bne.s flsret
- flseof: move.l rd_error(a6),d0
- bra.s flsret
-
- ;uncompclose(cstream)
- export uncompclose
- uncompclose:
- move.l 4(sp),d0
- if# eq then.s
- rts
- endif#
- movem.l hisregs,-(sp)
- move.l d0,a6
- movem.l savedregs(a6),myregs
- move.l strend(a6),a0
- lea -STRSIZE(a0),a0
- _DisposPtr
- memer3 move.w MemErr,-(sp)
- lea 512(codetab),a0
- _DisposPtr
- move.w (sp)+,MemErr
- memer2 move.w MemErr,-(sp)
- lea 256(chartab),a0
- _DisposPtr
- move.w (sp)+,MemErr
- memer1 move.w MemErr,-(sp)
- move.l a6,a0
- _DisposPtr
- move.w (sp)+,MemErr
- moveq #0,d0
- movem.l (sp)+,hisregs
- rts
- endwith
- endproc
-
-
- end
-