home *** CD-ROM | disk | FTP | other *** search
- ;
- ; ENCODECH_ - Huffman encode and output a character
- ;
- ; Action - Encodes a value to a bit string according to the Huffman
- ; tree. Encoded character is output, tree is updated.
- ; Input - H/L is the value to be encoded
- ; be inserted.
- ; Output - See Action
- ; Entry - encodech_
- ; Registers - All scratch except B/C (preserved)
- ; Calls - Putcode_, Update_
-
- ;void EncodeChar(unsigned c)
- ;{
- ; unsigned i;
- ; int j, k;
- ;
- ; k = prnt[c + T];
- ;
- ; /* search connections from leaf node to the root */
- ; do {
- ; i >>= 1;
- ;
- ; /*
- ; if node's address is odd, output 1
- ; else output 0
- ; */
- ; if (k & 1) i += 0x8000;
- ; j++;
- ; } while ((k = prnt[k]) != R);
- ; Putcode(j, i);
- ; code = i;
- ; len = j;
- ; update(c);
- ;}
- CSEG
- ENCODECH_:
-
- PUSH B ; Save b for exit
-
- SHLD SMALLC ; Save for exit call
- DAD H ; Double (for pre-multiplication)
-
- LXI D,T2 ; Index into beginning of char table
- DAD D ; H/l is starting index
- XRA A ; Length is 0
- MOV B,A ; 'CODE' part 1
- MOV C,A ; 'CODE' part 2
- LOAD <LXI D>,%(PRNT_) ; Point to parent base
- CODEL: STA TEMPL ; Save length
- DAD D ; Point to table
- MOV A,M ; Get low
- INX H
- MOV H,M ; 'k' in h/a
- MOV L,A ; Get low
-
- CPI R2 AND 0FFH
- JNZ LBL5 ; Not equal
- MOV A,H ; Get high
- CPI R2 SHR 8 AND 0FFH
- JZ FROOT
- MOV A,L ; Get node addr
- LBL5:
- RAR ; Lsb to carry
- RAR ; Times 2 (for index pre-mult)
- MOV A,B ; Get code
- RAR ; Ripple in carry
- MOV B,A ; Restore
- MOV A,C ; Get low
- RAR ; Propagate
- MOV C,A ; Save
- MVI A,00 ; Get length
- TEMPL EQU $-1
- INR A ; Count
- JMP CODEL ;
-
- FROOT: LDA TEMPL ; Get length
- MOV H,B ; Get code
- MOV L,C ; To h/l
- CALL PUTCODE_
-
- ; note: 'c' saved for this call at entry
-
- CALL UPDATE_
- POP B ; Restore entry b/c
- RET
-