home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
ms_dos
/
ish
/
ish200s
/
ish200s.lzh
/
CRC.H
< prev
next >
Wrap
Text File
|
1990-03-27
|
5KB
|
263 lines
;
; ish file converter for MS-DOS Ver 2.00 (90/3/27)
;
;
; Copyright (c) 1986, 1987, 1989, 1990 by M. ishizuka
; All rights reserved.
;
;-----------------------------------------------;
; ;
; @@crc_sub ;
; ;
; INPUT : ax (initial crc) ;
; cx (number of data) ;
; dx (crc table address) ;
; si (next data pointer) ;
; OUTPUT: ax (crc) ;
; ERROR : NON ;
; BREAK : flags, bx, cx, si ;
; ;
;-----------------------------------------------;
@@crc_sub macro
local crc_loop
crc_loop: mov bl, al
lodsb
xor bl, al
xor bh, bh
add bx, bx
add bx, dx
xor al, al
xor ax, [bx]
xchg ah, al
loop crc_loop
endm
;-----------------------------------------------;
; ;
; @@crc_1 ;
; ;
; INPUT : cx (number of data) ;
; dx (crc table address) ;
; si (next data pointer) ;
; OUTPUT: ax (crc) ;
; ERROR : NON ;
; BREAK : flags, bx, cx, si ;
; ;
;-----------------------------------------------;
@@crc_1 macro
mov ax, 0ffffh
@@crc_sub
not ax
endm
;-----------------------------------------------;
; ;
; @@crc32_sub ;
; ;
; INPUT : ax (initial crc-low) ;
; dx (initial crc-high) ;
; cx (number of data) ;
; si (next data pointer) ;
; OUTPUT: ax (crc-low) ;
; dx (crc-high) ;
; ERROR : NON ;
; BREAK : flags, bx, cx, si ;
; ;
;-----------------------------------------------;
@@crc32_sub macro
local crc32_loop
crc32_loop: mov bl, al
lodsb
xor bl, al
xor bh, bh
add bx, bx
add bx, bx
mov al, ah
mov ah, dl
mov dl, dh
xor dh, dh
xor ax, word ptr crc32_table[bx]
xor dx, word ptr crc32_table[bx+2]
loop crc32_loop
endm
;-----------------------------------------------;
; ;
; @@crc16_32_sub ;
; ;
; INPUT : ax (initial crc32-low) ;
; dx (initial crc32-high) ;
; cx (number of data) ;
; si (next data pointer) ;
; bp (initial crc16) ;
; OUTPUT: ax (crc32-low) ;
; dx (crc32-high) ;
; bp (crc16) ;
; ERROR : NON ;
; BREAK : flags, bx, cx, si ;
; ;
;-----------------------------------------------;
@@crc16_32_sub macro
local crc16_32_loop
crc16_32_loop: mov bl, al
lodsb
push ax
xor bl, al
xor bh, bh
add bx, bx
add bx, bx
mov al, ah
mov ah, dl
mov dl, dh
xor dh, dh
xor ax, word ptr crc32_table[bx]
xor dx, word ptr crc32_table[bx+2]
pop bx
xchg ax, bp
xor bl, al
xor bh, bh
add bx, bx
xor al, al
xor ax, word ptr crc_table[bx]
xchg ah, al
xchg ax, bp
loop crc16_32_loop
endm
;-----------------------------------------------;
; ;
; @@crc16_16_32_sub ;
; ;
; INPUT : ax (initial crc32-low) ;
; dx (initial crc32-high) ;
; cx (number of data) ;
; si (next data pointer) ;
; bp (initial crc16-1) ;
; di (initial crc16-2) ;
; OUTPUT: ax (crc32-low) ;
; dx (crc32-high) ;
; bp (crc16-1) ;
; di (crc16-2) ;
; ERROR : NON ;
; BREAK : flags, bx, cx, si ;
; ;
;-----------------------------------------------;
@@crc16_16_32_sub macro
local crc16_16_32_loop
crc16_16_32_loop:
mov bl, al
lodsb
push ax
xor bl, al
xor bh, bh
add bx, bx
add bx, bx
mov al, ah
mov ah, dl
mov dl, dh
xor dh, dh
xor ax, word ptr crc32_table[bx]
xor dx, word ptr crc32_table[bx+2]
pop bx
push bx
xchg ax, bp
xor bl, al
xor bh, bh
add bx, bx
xor al, al
xor ax, word ptr crc_table[bx]
xchg ah, al
xchg ax, bp
pop bx
xchg ax, di
xor bl, al
xor bh, bh
add bx, bx
xor al, al
xor ax, word ptr crc_table[bx]
xchg ah, al
xchg ax, di
loop crc16_16_32_loop
endm
;-----------------------------------------------;
; ;
; @@calc_crc_of_file_sub ;
; ;
; ARG : crc_macro ;
; INPUT : ax (initial crc32 (low)) ;
; dx (initial crc32 (high)) ;
; bp (initial crc16-1) ;
; ( di (initial crc16-2) ) ;
; bx (file handler) ;
; OUTPUT: CY (error) ;
; ax (~crc32 (low)) ;
; dx (~crc32 (high)) ;
; bp (~crc16-1) ;
; ( di (~crc16-2) ) ;
; ERROR : NON ;
; BREAK : flags, cx, si, bp ;
; REMARK: crc macro is one of the following.
; @@crc16_32_sub (di is not used.);
; @@crc16_16_32_sub (di is used.) ;
; OUTPUT crc is 1's complement ;
; ;
;-----------------------------------------------;
@@calc_crc_of_file_sub macro crc_macro
local calc_crc_of_file_1
local calc_crc_of_file_2
local calc_crc_of_file_3
local calc_crc_of_file_4
local calc_crc_of_file_5
calc_crc_of_file_1:
mov cx, 80d*72d
sub word ptr length_of_file_low, cx
sbb word ptr length_of_file_high, 0
jnc calc_crc_of_file_2
add cx, length_of_file_low
mov word ptr length_of_file_low, 0
mov word ptr length_of_file_high, 0
or cx, cx ; clear CY flag
jz calc_crc_of_file_4
calc_crc_of_file_2:
push ax
push dx
mov dx, offset write_buffer
mov si, dx
mov ah, 3fh
int 21h
jc calc_crc_of_file_3
cmp ax, cx
calc_crc_of_file_3:
pop dx
pop ax
jc calc_crc_of_file_5
push bx
&crc_macro
pop bx
jmp calc_crc_of_file_1
calc_crc_of_file_4:
calc_crc_of_file_5:
endm