home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / ish / ish200s / ish200s.lzh / CRC.H < prev    next >
Text File  |  1990-03-27  |  5KB  |  263 lines

  1. ;
  2. ;        ish file converter for MS-DOS  Ver 2.00 (90/3/27)
  3. ;
  4. ;
  5. ;        Copyright (c) 1986, 1987, 1989, 1990  by  M. ishizuka
  6. ;        All rights reserved.
  7. ;
  8.  
  9.  
  10.  
  11. ;-----------------------------------------------;
  12. ;                        ;
  13. ;    @@crc_sub                ;
  14. ;                        ;
  15. ;    INPUT :    ax (initial crc)        ;
  16. ;        cx (number of data)        ;
  17. ;        dx (crc table address)        ;
  18. ;        si (next data pointer)        ;
  19. ;    OUTPUT:    ax (crc)            ;
  20. ;    ERROR :    NON                ;
  21. ;    BREAK : flags, bx, cx, si        ;
  22. ;                        ;
  23. ;-----------------------------------------------;
  24.  
  25. @@crc_sub    macro
  26.         local    crc_loop
  27. crc_loop:    mov    bl, al
  28.         lodsb
  29.         xor    bl, al
  30.         xor    bh, bh
  31.         add    bx, bx
  32.         add    bx, dx
  33.         xor    al, al
  34.         xor    ax, [bx]
  35.         xchg    ah, al
  36.         loop    crc_loop
  37.         endm
  38.  
  39.  
  40.  
  41. ;-----------------------------------------------;
  42. ;                        ;
  43. ;    @@crc_1                    ;
  44. ;                        ;
  45. ;    INPUT :    cx (number of data)        ;
  46. ;        dx (crc table address)        ;
  47. ;        si (next data pointer)        ;
  48. ;    OUTPUT:    ax (crc)            ;
  49. ;    ERROR :    NON                ;
  50. ;    BREAK : flags, bx, cx, si        ;
  51. ;                        ;
  52. ;-----------------------------------------------;
  53.  
  54. @@crc_1        macro
  55.         mov    ax, 0ffffh
  56.         @@crc_sub
  57.         not    ax
  58.         endm
  59.  
  60.  
  61.  
  62. ;-----------------------------------------------;
  63. ;                        ;
  64. ;    @@crc32_sub                ;
  65. ;                        ;
  66. ;    INPUT :    ax (initial crc-low)        ;
  67. ;        dx (initial crc-high)        ;
  68. ;        cx (number of data)        ;
  69. ;        si (next data pointer)        ;
  70. ;    OUTPUT:    ax (crc-low)            ;
  71. ;        dx (crc-high)            ;
  72. ;    ERROR :    NON                ;
  73. ;    BREAK : flags, bx, cx, si        ;
  74. ;                        ;
  75. ;-----------------------------------------------;
  76.  
  77. @@crc32_sub    macro
  78.         local    crc32_loop
  79. crc32_loop:    mov    bl, al
  80.         lodsb
  81.         xor    bl, al
  82.         xor    bh, bh
  83.         add    bx, bx
  84.         add    bx, bx
  85.         mov    al, ah
  86.         mov    ah, dl
  87.         mov    dl, dh
  88.         xor    dh, dh
  89.         xor    ax, word ptr crc32_table[bx]
  90.         xor    dx, word ptr crc32_table[bx+2]
  91.         loop    crc32_loop
  92.         endm
  93.  
  94.  
  95.  
  96. ;-----------------------------------------------;
  97. ;                        ;
  98. ;    @@crc16_32_sub                ;
  99. ;                        ;
  100. ;    INPUT :    ax (initial crc32-low)        ;
  101. ;        dx (initial crc32-high)        ;
  102. ;        cx (number of data)        ;
  103. ;        si (next data pointer)        ;
  104. ;        bp (initial crc16)        ;
  105. ;    OUTPUT:    ax (crc32-low)            ;
  106. ;        dx (crc32-high)            ;
  107. ;        bp (crc16)            ;
  108. ;    ERROR :    NON                ;
  109. ;    BREAK : flags, bx, cx, si        ;
  110. ;                        ;
  111. ;-----------------------------------------------;
  112.  
  113. @@crc16_32_sub    macro
  114.         local    crc16_32_loop
  115. crc16_32_loop:    mov    bl, al
  116.         lodsb
  117.         push    ax
  118.         xor    bl, al
  119.         xor    bh, bh
  120.         add    bx, bx
  121.         add    bx, bx
  122.         mov    al, ah
  123.         mov    ah, dl
  124.         mov    dl, dh
  125.         xor    dh, dh
  126.         xor    ax, word ptr crc32_table[bx]
  127.         xor    dx, word ptr crc32_table[bx+2]
  128.         pop    bx
  129.         xchg    ax, bp
  130.         xor    bl, al
  131.         xor    bh, bh
  132.         add    bx, bx
  133.         xor    al, al
  134.         xor    ax, word ptr crc_table[bx]
  135.         xchg    ah, al
  136.         xchg    ax, bp
  137.         loop    crc16_32_loop
  138.         endm
  139.  
  140.  
  141.  
  142. ;-----------------------------------------------;
  143. ;                        ;
  144. ;    @@crc16_16_32_sub            ;
  145. ;                        ;
  146. ;    INPUT :    ax (initial crc32-low)        ;
  147. ;        dx (initial crc32-high)        ;
  148. ;        cx (number of data)        ;
  149. ;        si (next data pointer)        ;
  150. ;        bp (initial crc16-1)        ;
  151. ;        di (initial crc16-2)        ;
  152. ;    OUTPUT:    ax (crc32-low)            ;
  153. ;        dx (crc32-high)            ;
  154. ;        bp (crc16-1)            ;
  155. ;        di (crc16-2)            ;
  156. ;    ERROR :    NON                ;
  157. ;    BREAK : flags, bx, cx, si        ;
  158. ;                        ;
  159. ;-----------------------------------------------;
  160.  
  161. @@crc16_16_32_sub    macro
  162.         local    crc16_16_32_loop
  163. crc16_16_32_loop:
  164.         mov    bl, al
  165.         lodsb
  166.         push    ax
  167.         xor    bl, al
  168.         xor    bh, bh
  169.         add    bx, bx
  170.         add    bx, bx
  171.         mov    al, ah
  172.         mov    ah, dl
  173.         mov    dl, dh
  174.         xor    dh, dh
  175.         xor    ax, word ptr crc32_table[bx]
  176.         xor    dx, word ptr crc32_table[bx+2]
  177.         pop    bx
  178.         push    bx
  179.         xchg    ax, bp
  180.         xor    bl, al
  181.         xor    bh, bh
  182.         add    bx, bx
  183.         xor    al, al
  184.         xor    ax, word ptr crc_table[bx]
  185.         xchg    ah, al
  186.         xchg    ax, bp
  187.         pop    bx
  188.         xchg    ax, di
  189.         xor    bl, al
  190.         xor    bh, bh
  191.         add    bx, bx
  192.         xor    al, al
  193.         xor    ax, word ptr crc_table[bx]
  194.         xchg    ah, al
  195.         xchg    ax, di
  196.         loop    crc16_16_32_loop
  197.         endm
  198.  
  199.  
  200.  
  201. ;-----------------------------------------------;
  202. ;                        ;
  203. ;    @@calc_crc_of_file_sub            ;
  204. ;                        ;
  205. ;    ARG   : crc_macro            ;
  206. ;    INPUT :    ax (initial crc32 (low))    ;
  207. ;        dx (initial crc32 (high))    ;
  208. ;        bp (initial crc16-1)        ;
  209. ;          (    di (initial crc16-2) )        ;
  210. ;        bx (file handler)        ;
  211. ;    OUTPUT:    CY (error)            ;
  212. ;        ax (~crc32 (low))        ;
  213. ;        dx (~crc32 (high))        ;
  214. ;        bp (~crc16-1)            ;
  215. ;          (    di (~crc16-2) )            ;
  216. ;    ERROR :    NON                ;
  217. ;    BREAK :    flags, cx, si, bp        ;
  218. ;    REMARK: crc macro is one of the following.
  219. ;        @@crc16_32_sub (di is not used.);
  220. ;        @@crc16_16_32_sub (di is used.)    ;
  221. ;        OUTPUT crc is 1's complement    ;
  222. ;                        ;
  223. ;-----------------------------------------------;
  224.  
  225. @@calc_crc_of_file_sub    macro    crc_macro
  226.         local    calc_crc_of_file_1
  227.         local    calc_crc_of_file_2
  228.         local    calc_crc_of_file_3
  229.         local    calc_crc_of_file_4
  230.         local    calc_crc_of_file_5
  231. calc_crc_of_file_1:
  232.         mov    cx, 80d*72d
  233.         sub    word ptr length_of_file_low, cx
  234.         sbb    word ptr length_of_file_high, 0
  235.         jnc    calc_crc_of_file_2
  236.         add    cx, length_of_file_low
  237.         mov    word ptr length_of_file_low, 0
  238.         mov    word ptr length_of_file_high, 0
  239.         or    cx, cx            ; clear CY flag
  240.         jz    calc_crc_of_file_4
  241. calc_crc_of_file_2:
  242.         push    ax
  243.         push    dx
  244.         mov    dx, offset write_buffer
  245.         mov    si, dx
  246.         mov    ah, 3fh
  247.         int    21h
  248.         jc    calc_crc_of_file_3
  249.         cmp    ax, cx
  250. calc_crc_of_file_3:
  251.         pop    dx
  252.         pop    ax
  253.         jc    calc_crc_of_file_5
  254.         push    bx
  255.         &crc_macro
  256.         pop    bx
  257.         jmp    calc_crc_of_file_1
  258.  
  259. calc_crc_of_file_4:
  260. calc_crc_of_file_5:
  261.  
  262.         endm
  263.