þ a‹R þ d þ w ÿÿÿÿÿÿÿÿÿþ mV9     þ hý	 oH     þ nSystem-wide$symbols
$xref

name	TDC

dsa	struc
old_bp	dw	?	; and the base pointer
return	dw	?	; the return address
pdata	dd	?
pactual	dd	?
dsa	ends

cgroup	group	code
assume	cs:cgroup

extrn	edc:byte

code	segment	public 'CODE'
	public	TDC
;
; calling sequence
;	call tdc (pActualData, pDataToSend)
;	dcl (pActualData, pDataToSend) ptr;
;
;	requires the external data block "edc",
;	which contains edc values for bytes.
;	(kept in BitRoutines.plm)
;
TDC	proc	near
	push	bp
	mov	bp,sp

	push	ax
	push	bx
	push	cx
	push	dx
	push	es
	push	di
	push	ds
	push	si

	les	si,[bp].pData	; initialize data
	xor	ax,ax		; zero ax
	mov	cx,12		; zero out 12 words
zloop:
	mov	es:[si],ax
	inc	si		; point to the next word
	inc	si
	loop	zloop
;
	les	si,[bp].pActual	; get pActualData
	add	si,15		; start at end of table

	mov	cx,16		; for i:=16 downto 0
				; 16 to 1 for LOOP instruction
iloop1:
	dec	cx		; make (16 to 1) into (15 to 0)
	mov	bx,cx		; save I for bottom of loop
	push	bx
	lds	di,[bp].pData	; get pDataToSend

;	shr	cx,3		; I div 8
	shr	cx,1
	shr	cx,1
	shr	cx,1
;
	add	di,cx
	push	di		; save base + I div 8
	add	di,12
	mov	cx,7		; for j:=0 to 6
jloop1:
	dec	cx		; as for I loop
	mov	al,es:[si]	; get Ith byte of ActualData
	shr	al,cl		; get the Jth bit
	and	al,1
	jz	jloop11		; we save time if there isn't a bit to 
				; shift
;
	xchg	bx,cx
	push	cx
	and	cx,7		; I mod 8
	shl	al,cl		; shift by I mod 8
	pop	cx
	xchg	bx,cx
;
	or	ds:[di],al	; store the bit
jloop11:
	sub	di,2		; move down in the table (this is
	 			; faster than DEC, DEC)
	inc	cx		; (6 to 0) to (7 to 1)
	loop	jloop1

	pop	di		; get base + I div 8
	add	di,22		; + 2*J

	mov	al,es:[si]	; ActualData[I]
	and	ax,07fh
	push	bx
	push	es
	mov	bx,ax
	mov	ax,seg edc
	mov	es,ax
	mov	dh,es:edc[bx]
	pop	es
	pop	bx
	mov  	cx,5		; for j:=11 downto 7
jloop2:
	dec	cx
	mov	dl,dh		; get edc byte
	shr	dl,cl		; get the Jth bit
	and	dl,1
	jz	jloop21		; don't shift if no bit
;
	xchg	bx,cx		; (bit j) at (bit I mod 8)
	push	cx
	and	cx,7		; I mod 8
	shl	dl,cl		; put (bit J) at (I mod 8)
	pop	cx
	xchg	bx,cx
;
	or	ds:[di],dl	; store the bit
jloop21:
	sub	di,2		; move down table
	inc	cx
	loop	jloop2

	dec	si		; move down in ActualData

	pop	cx
	inc	cx
	loop	iloop1

	pop	si
	pop	ds
	pop	di
	pop	es
	pop	dx
	pop	cx
	pop	bx
	pop	ax

	pop	bp
	ret	8		; remove parameters
;
TDC	endp
	code	ends
	end
