þ a‹R þ w Qþ m^9     þ hý	 oP    þ nSystem-wide  NAME UNtdc

   data struc
      oldBP        DW    ?         ; space for BP
      retAdd       DW    ?         ; caller's return address
      pEDCBlock    DD    ?         ; parameters passed to us
      pReturnData  DD    ?
      pTDCData     DD    ?
   data ends

CGroup GROUP Code
 
ASSUME cs:cGroup

 CODE segment public 'CODE'
      public  UNtdc
      
  ;  
  ;  calling sequence for UNtdc:
  ;       CALL UNtdc (pTDCData, pReturnData, pEDCBlock);
  ;
  
   UNtdc     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].pTDCData            ; ES:SI = pTDCData
             lds     di,[bp].pReturnData         ; DS:DI = pActualData
             
             mov     cx,1                        ; for edc loop
             push    cx

             xor     ax,ax
             mov     cx,8
             push    cx
  zeroArray:
             mov     ds:[di],ax                  ; zero out ActualData area
             inc     di                          ; di points @ end of table
             inc     di
             loop    zeroArray                        
             
             pop     cx
             push    di                          ; save di for Ascii data

             lds     di,[bp].pEDCBlock           ; get address for UNedc area
  zeroEDC:
             mov     ds:[di],ax                  ; zero the edc area 
             inc     di
             inc     di
             loop    zeroEDC
             
             dec     di                          ; adjust di for end of block
             xchg    di,bx

             pop     di                          
             push    bx                          ; save edc ptr for below

  ; begin unTDCing the ascii data
  
             dec     di                          ; adjust di for end of Ascii
  nextColumn:
             mov     bx,7                        ; bit count
  nextByte:
             add     si,13                       ; si points to end of tdc area
             mov     cx,7
  nextBit:
             mov     al,es:[si]                  ; get byte j of tdc'd data
             xchg    cx,bx
             shr     al,cl                       ;get bit i of byte j to undo
             xchg    cx,bx
             and     al,1
             jz      zero
             
             dec     cx                          
             shl     al,cl                       ; move bit to correct weight
             inc     cx
             or      ds:[di],al                  ;store bit in output array
   zero:          
             sub     si,2
             loop    nextBit

             inc     si                         
             dec     di                          ; point to next byte
             sub     bx,1
             jnc     nextbyte

  ; now unTDC the EDC data
            
             mov     dx,7
             pop     bx                          ; bx contains di from above
             push    di                          ; save Ascii pointers
             push    si
             xchg    di,bx
             add     si,13                       ; set indexes for EDC data
  UNedc:
             add     si,10                       ;adjust si to end of tdc'd edc
             mov     cx,4                        ; only 5 edc bits per byte
  UNedc1:           
             mov     al,es:[si]                  ; byte j of edc code
             xchg    dx,cx
             shr     al,cl
             xchg    dx,cx
             and     al,1
             jz      around

             shl     al,cl
             or      ds:[di],al                  ; store bit in edc array
  around:           
             sub     si,2
             sub     cx,1                        ; move to next bit weight
             jnc     UNedc1

             dec     di
             sub     dx,1                        ; DX keeps track of whether 
             jnc     UNedc                       ; we are doing the even or odd
                                                 ; bytes
             xchg    di,bx
             pop     si                          ; get indexes for Ascii data
             dec     si
             pop     di
             pop     dx
             sub     dx,1                        
             push    dx                          
             push    bx                          
             jnc     nextColumn
             
             pop     bx
             pop     dx
 
             pop     si
             pop     ds
             pop     di
             pop     es
             pop     dx
             pop     cx
             pop     bx
             pop     ax

	            pop     bp
             ret     12                          ; remove ptrs passed in
              
    untdc  endp
    code   ends
    end
