home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / ADDBFTCC.C < prev    next >
C/C++ Source or Header  |  1991-07-11  |  2KB  |  100 lines

  1. #pragma inline                    /* tell turbo assemble to use inline assembly */
  2. #ifndef LINT
  3. static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/addbftcc.c,v $\n\
  4. $Id: addbftcc.c,v 1.1 91/07/07 18:40:11 dhesi Exp $";
  5. #endif /* LINT */
  6.  
  7. extern unsigned int crccode;
  8. extern unsigned crctab[];
  9.  
  10. void addbfcrc(buffer,count)
  11. char *buffer;
  12. int count;
  13. {
  14.     (void) kbhit();                /* allow keyboard interrupt to occur */
  15.     _AX = crccode;                    /* ax holds crccode value */
  16.     _CX = count;                    /* cx holds byte count */
  17.     asm     les di,buffer            /* es:di holds buffer address */
  18.  
  19.     asm     jcxz    done        /* if zero bytes, just skip */
  20.  
  21. /* loop begins here */
  22. xloop:
  23.     asm     sub bh,bh
  24.     asm    mov bl,al
  25.     asm     xor bl,es:[di]        /* now bx = (crccode xor c) & 0x00ff */
  26.     /* next statement shifts _BX left (2-byte items) */
  27.    _DX = crctab[_BX];        /* dx <= *buffer == exp2 */
  28.     asm    sub bh,bh            /* bh = 0 */
  29.     asm    mov bl,ah            /* bx <- exp1 */
  30.     asm    xor bx,dx            /* bx <- exp1 xor exp2 */
  31.     asm    mov ax,bx            /* crccode <- exp1 xor exp2 */
  32.     asm    inc di                /* inc buffer pointer */
  33.     asm    loop xloop            /* dec CX, jump if not zero */
  34. /* loop ends here */
  35.  
  36.     crccode = _AX;                /* put back calculated CRC value */
  37.  
  38. done:
  39.     ;
  40.  
  41. }
  42.  
  43.  
  44. #if 0
  45. ; The following (edited) code was generated by Turbo C from the
  46. ; preceding code.  It is supplied here for porting to other systems
  47. ; and for user education.
  48.  
  49. _TEXT    segment byte public 'CODE'
  50. _TEXT    ends
  51.  
  52. DGROUP    group    _DATA,_BSS
  53.     assume    cs:_TEXT,ds:DGROUP
  54.  
  55. _DATA    segment word public 'DATA'
  56. _DATA    ends
  57.  
  58. _BSS    segment word public 'BSS'
  59. _BSS    ends
  60.  
  61. _TEXT    segment byte public 'CODE'
  62.  
  63.     assume    cs:_TEXT
  64. _addbfcrc    proc    near
  65.     push    bp
  66.     mov    bp,sp
  67.     push    di
  68.  
  69.     call    near ptr _kbhit
  70.     mov    ax,word ptr DGROUP:_crccode
  71.     mov    cx,word ptr [bp+8]
  72.          les     di,[bp+4]
  73.     jcxz    short @1@362
  74. @1@98:
  75.      sub     bh,bh
  76.     mov     bl,al
  77.      xor     bl,es:[di]
  78.     shl    bx,1
  79.     mov    dx,word ptr DGROUP:_crctab[bx]
  80.     sub     bh,bh
  81.     mov     bl,ah
  82.     xor     bx,dx
  83.     mov     ax,bx
  84.     inc     di
  85.     loop    short @1@98
  86.     mov    word ptr DGROUP:_crccode,ax
  87. @1@362:
  88.     pop    di
  89.     pop    bp
  90.     ret
  91. _addbfcrc    endp
  92. _TEXT    ends
  93.  
  94.     extrn    _crccode:word
  95.     extrn    _kbhit:near
  96.     extrn    _crctab:word
  97.     public    _addbfcrc
  98.     end
  99. #endif
  100.