home *** CD-ROM | disk | FTP | other *** search
-
- ; Register useage:
- ;
- ; AX - holds Code
- ; BX - BH is a work register, BL holds SaveByte
- ; CX - holds our loop counter CodeSize
- ; DX - holds BitsUsed
- ;
- mov ax,[bp+<Code]
- xor bx,bx
- mov cx,bx
- mov dx,bx
- mov bl,[>SaveByte]
- mov cl,[>CodeSize]
- mov dl,[>BitsUsed]
- cmp ax,-1 ;Any work to do?
- jnz Repeat ;Yup, go do it
- cmp dl,0 ;Any leftovers?
- jz AllDone ;Nope, we're done
- push bx ;Yup...push leftovers
- push cs
- call [bp+>PutCharAddr] ; and send to output
- jmp short AllDone
- ;
- Repeat: xor bh,bh ;Zero out BH
- rcr ax,1 ;Get low order bit into CY flag
- jnc SkipBit ;Was the bit set?
- inc bh ;Yes, xfer to BH
- SkipBit: xchg cx,dx ;Swap CX & DX
- shl bh,cl ;Shift bit over
- xchg cx,dx ;Put CX & DX back where they were
- inc dx ;Bump count of bit positions used
- or bl,bh ;Transfer bit to output byte (SaveByte)
- cmp dx,8 ;Full byte yet?
- jb GetNext ;Nope, go get more code bits
- push ax ;Yup, save regs in preparation
- push bx ; for call to output routine
- push cx
- push dx
- push bx ;Push byte to output onto stack
- push cs
- call [bp+>PutCharAddr] ; and call the output routine
- xor ax,ax
- mov al,[>CodeBytes] ;Recalculate position in un-arc
- inc al ; program's input code buffer
- xor cx,cx ; CodeBytes :=
- mov cl,[>CodeSize] ; Succ(CodeBytes) MOD CodeSize
- div cl
- mov al,ah
- mov [>CodeBytes],al
- pop dx
- pop cx
- pop bx
- pop ax
- xor bx,bx ;Prepare SaveByte for next byte
- mov dx,bx ;Set BitsUsed to zero
- GetNext: loop Repeat ;Repeat for all code bits
- ;
- mov [>SaveByte],bl ;Put SaveByte and BitsUsed
- mov [>BitsUsed],dl ; back in memory
- ;
- mov byte [>Ok_to_Clear],0 ;Test if it's ok to clear the
- xor ax,ax ; Code table at this time
- mov al,[>CodeBytes]
- add al,2
- cmp al,[>CodeSize] ;Ok to clear table?
- jnz AllDone ;Nope, don't set flag TRUE
- mov byte [>Ok_to_Clear],1 ;Ok, set flag
- AllDone:
-