home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / modem / byepc300.arc / BYEXMDM.ARC / CRC.ASM < prev    next >
Assembly Source File  |  1987-06-17  |  7KB  |  259 lines

  1.               page 60,132
  2.               title XMDM CRC and Timing Routines MSC 3.00 & 4.00
  3. ;
  4. ;---------------------------------------------------------------------------
  5. ;    This module contains all of the 16 bit CRC routines used in
  6. ; XMDM as well as the hardware timing funtion used to perform delays.
  7. ; The CRC routines are calculated on the fly, an require speed to
  8. ; perform well. All timing functions used in XMDM use a hardware timing
  9. ; function to keep a standard timing reference on various machines.
  10. ;---------------------------------------------------------------------------
  11. ;                        General Equates
  12. ;---------------------------------------------------------------------------
  13. ;
  14. YES     equ     1
  15. NO      equ     0
  16. ;
  17. ;---------------------------------------------------------------------------
  18. ;  Memory Model selector for Microsoft C v3.0, ASM files.
  19. ;---------------------------------------------------------------------------
  20. ;  -- model --                    -- equates --
  21. ; {small}                   _LDATA = NO    _LCODE = NO
  22. ; {medium}                  _LDATA = NO    _LCODE = YES
  23. ; {compact}                 _LDATA = YES   _LCODE = NO
  24. ; {large}                   _LDATA = YES   _LCODE = YES
  25. ;---------------------------------------------------------------------------
  26. ;
  27. ;       -- Small Memory Model --
  28. ;
  29. _LDATA  equ   NO                  ; data area size
  30. _LCODE  equ   NO                  ; code pointers far.
  31. ;
  32. include  MODEL.H                  ; get memory model header
  33. ;
  34. ;
  35. ;---------------------------------------------------------------------------
  36. ; Set up the program segment according to memory model.
  37. ;---------------------------------------------------------------------------
  38. ;
  39. if _LCODE                    ; setup program segment
  40.     pseg crc
  41. else
  42.     pseg
  43. endif
  44. ;
  45. ;---------------------- CRC Storage Accumulator ----------------------------
  46. ;
  47. crcval         dw   0
  48. ;
  49. ;---------------------------------------------------------------------------
  50. ;
  51. ;---------------------------------------------------------------------------
  52. ;
  53. ;  void crc_sum(c)
  54. ;
  55. ;  Parms:      int port; 8 bit character to sum the crc with.
  56. ;
  57. ;  Purpose:    Sums the character in using CCITT CRC polynomial.
  58. ;
  59. ;  Return:     <none>
  60. ;
  61. ;---------------------------------------------------------------------------
  62. ;
  63.                public _crc_sum
  64. ;
  65. if             _LCODE
  66. _crc_sum       proc far
  67. else
  68. _crc_sum       proc near
  69. endif
  70.                push bp                  ;standard 'C' function entry
  71.                mov  bp,sp
  72.                push di
  73.                push si
  74.                mov  ax,@ab[bp]          ;get the port# argument
  75.                and  ax,00FFh            ;mask out the msb.
  76.  
  77.                mov bl,8
  78.                mov cl,al
  79.                mov dx,cs:crcval
  80.  
  81. updloop:       mov al,cl
  82.                rol al,1
  83.                mov cl,al
  84.                mov al,dl
  85.                rcl al,1
  86.                mov dl,al
  87.                mov al,dh
  88.                rcl al,1
  89.                mov dh,al
  90.                jnc skipit
  91.  
  92.                mov al,dh
  93.                xor al,10h
  94.                mov dh,al
  95.                mov al,dl
  96.                xor al,21h
  97.                mov dl,al
  98.  
  99. skipit:        dec bl
  100.                jnz updloop
  101.                mov cs:crcval,dx
  102.  
  103.                pop  si                  ;standard  'C' function exit
  104.                pop  di
  105.                mov  sp,bp
  106.                pop  bp
  107.                ret
  108.  
  109. _crc_sum       endp
  110. ;
  111. ;
  112. ;---------------------------------------------------------------------------
  113. ;
  114. ;  void crc_init()
  115. ;
  116. ;  Parms:      <none>
  117. ;
  118. ;  Purpose:    Clears the crc accumulator word to zero.
  119. ;
  120. ;  Return:     <none>
  121. ;
  122. ;---------------------------------------------------------------------------
  123. ;
  124.                public _crc_init
  125. ;
  126. if             _LCODE
  127. _crc_init      proc far
  128. else
  129. _crc_init      proc near
  130. endif
  131.                push bp                  ;standard 'C' function entry
  132.                mov  bp,sp
  133.                push di
  134.                push si
  135.  
  136.                mov cs:crcval,0
  137.  
  138.                pop  si                  ;standard  'C' function exit
  139.                pop  di
  140.                mov  sp,bp
  141.                pop  bp
  142.                ret
  143.  
  144. _crc_init      endp
  145. ;
  146. ;
  147. ;---------------------------------------------------------------------------
  148. ;
  149. ;  unsigned crc_value()
  150. ;
  151. ;  Parms:      <none>
  152. ;
  153. ;  Purpose:    Returns the crc accumulator word.
  154. ;
  155. ;  Return:     <none>
  156. ;
  157. ;---------------------------------------------------------------------------
  158. ;
  159.                public _crc_value
  160. ;
  161. if             _LCODE
  162. _crc_value     proc far
  163. else
  164. _crc_value     proc near
  165. endif
  166.                push bp                  ;standard 'C' function entry
  167.                mov  bp,sp
  168.                push di
  169.                push si
  170.  
  171.                mov ax, cs:crcval
  172.  
  173.                pop  si                  ;standard  'C' function exit
  174.                pop  di
  175.                mov  sp,bp
  176.                pop  bp
  177.                ret
  178.  
  179. _crc_value     endp
  180. ;
  181. ;---------------------------------------------------------------------------
  182. ;
  183. ;  void timer( n )
  184. ;  int n;               -- Number of 1/18.2 sec intervals to delay
  185. ;
  186. ;  Provide a timed delay of the indicated number of 1/18.2 second
  187. ;  intervals.  This permits timing of all manner of things.
  188. ;
  189. ;---------------------------------------------------------------------------
  190. ;
  191. if _LCODE
  192.     dynx    struc
  193.     xscx    dw      ?        ; timer data storage area
  194.     xsdx    dw      ?
  195.     x_bp    dw      ?
  196.     xret    dd      ?
  197.     xarg1   dw      ?
  198.     dynx    ends
  199. else
  200.     dynx    struc
  201.     xscx    dw      ?
  202.     xsdx    dw      ?
  203.     x_bp    dw      ?
  204.     xret    dw      ?
  205.     xarg1   dw      ?
  206.     dynx    ends
  207. endif
  208. ;
  209.         public _timer
  210. ;
  211. if _LCODE
  212. _timer proc     far
  213. else
  214. _timer proc     near
  215. endif
  216.         push    bp
  217.         sub     sp,4                    ; local variables
  218.         mov     bp,sp
  219.         push    si
  220.         push    di
  221.         xor     ah,ah                   ; see what ticker says first
  222.         int     1Ah                     ; CX:DX is starting point.
  223.         mov     [bp].xsdx,dx            ; save it on the stack
  224.         mov     [bp].xscx,cx
  225.  
  226. tloop:  xor     ah,ah                   ; function to get timer
  227.         int     1Ah                     ; get timer tiks to CX:DX
  228.         cmp     cx,word ptr [bp].xscx   ; check hi-order part
  229.         je      tl2                     ; if same
  230. ;
  231. ;  Hi-order part has rolled over, so add instead of subtracting
  232. ;  the lo-order parts, with increment
  233. ;
  234.         add     dx,[bp].xsdx
  235.         inc     dx
  236.  
  237. tl2:    sub     dx,[bp].xsdx            ; low-order part
  238.         cmp     dx,word ptr [bp].xarg1  ; is elapsed = specified ?
  239.         jl      tloop
  240.         add     sp,4
  241.         pop     di
  242.         pop     si
  243.         pop     bp
  244.         ret
  245. _timer  endp
  246. ;
  247. ;
  248. ;---------------------------------------------------------------------------
  249. ;   End of program code
  250. ;---------------------------------------------------------------------------
  251. ;
  252. if            _LCODE
  253.               endps crc
  254. else
  255.               endps
  256. endif
  257.               end
  258.  
  259.