1;===========================================================================
2; Copyright (c) 1990-2000 Info-ZIP.  All rights reserved.
3;
4; See the accompanying file LICENSE, version 2000-Apr-09 or later
5; (the contents of which are also included in zip.h) for terms of use.
6; If, for some reason, all these files are missing, the Info-ZIP license
7; also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
8;===========================================================================
9; crc_68 created by Paul Kienitz, last modified 04 Jan 96.
10;
11; Return an updated 32 bit CRC value, given the old value and a block of data.
12; The CRC table used to compute the value is gotten by calling get_crc_table().
13; This replaces the older updcrc() function used in Zip and fUnZip.  The
14; prototype of the function is:
15;
16;    ulg crc32(ulg crcval, uch *text, extent textlen);
17;
18; On the Amiga, type extent is always unsigned long, not unsigned int, because
19; int can be short or long at whim, but size_t is long.
20;
21; If using this source on a non-Amiga 680x0 system, note that we treat
22; a0/a1/d0/d1 as scratch registers not preserved across function calls.
23; We do not bother to support registerized arguments for crc32() -- the
24; textlen parm is usually large enough so that savings outside the loop
25; are pointless.
26;
27; Define NO_UNROLLED_LOOPS to use a simple short loop which might be more
28; efficient on certain machines with dinky instruction caches ('020?), or for
29; processing short strings.  If loops are unrolled, the textlen parm must be
30; less than 512K; if not unrolled, it must be less than 64K.
31;
32; 1999/09/23: for Human68k: Modified by Shimazaki Ryo.
33
34        xdef    _crc32          ; (ulg val, uch *buf, extent bufsize)
35
36DO_CRC0 MACRO
37        moveq  #0,ltemp
38        move.b (textbuf)+,ltemp
39        eor.b  crcval,ltemp
40        lsl.w  #2,ltemp
41        move.l (crc_table,ltemp.w),ltemp
42        lsr.l  #8,crcval
43        eor.l  ltemp,crcval
44        ENDM
45
46
47DO_CRC2 MACRO
48        move.b (textbuf)+,btemp
49        eor.b  crcval,btemp
50        lsr.l  #8,crcval
51        move.l (crc_table,btemp.w*4),ltemp
52        eor.l  ltemp,crcval
53        ENDM
54
55crc_table       reg     a0      array of unsigned long
56crcval          reg     d0      unsigned long initial value
57textbuf         reg     a1      array of unsigned char
58textbufsize     reg     d1      unsigned long (count of bytes in textbuf)
59btemp           reg     d2
60ltemp           reg     d3
61
62
63        xref    _get_crc_table  ; ulg *get_crc_table(void)
64
65
66
67        quad
68_crc32:
69        move.l  8(sp),d0
70        bne.s   valid
71;;;;;   moveq  #0,d0
72         rts
73valid:  movem.l btemp/ltemp,-(sp)
74        jsr     _get_crc_table
75        movea.l d0,crc_table
76        move.l  12(sp),crcval
77        move.l  16(sp),textbuf
78        move.l  20(sp),textbufsize
79        not.l   crcval
80
81    ifdef   NO_UNROLLED_LOOPS
82
83    if CPU==68000
84        bra.s   decr
85loop:    DO_CRC0
86decr:    dbra   textbufsize,loop
87        bra.s   done
88
89    else
90twenty: moveq   #0,btemp
91        bra.s   decr2
92loop2:   DO_CRC2
93decr2:   dbra   textbufsize,loop2
94    endif
95
96    ELSE    ; !NO_UNROLLED_LOOPS
97
98    if CPU==68000
99        moveq   #7,btemp
100        and     textbufsize,btemp
101        lsr.l   #3,textbufsize
102        bra     decr8
103loop8:   DO_CRC0
104         DO_CRC0
105         DO_CRC0
106         DO_CRC0
107         DO_CRC0
108         DO_CRC0
109         DO_CRC0
110         DO_CRC0
111decr8:   dbra   textbufsize,loop8
112        bra.s   decr1
113loop1:   DO_CRC0
114decr1:   dbra   btemp,loop1
115        bra     done
116
117    else
118twenty: moveq   #0,btemp
119        move.l  textbufsize,-(sp)
120        lsr.l   #3,textbufsize
121        bra     decr82
122         quad
123loop82:  DO_CRC2
124         DO_CRC2
125         DO_CRC2
126         DO_CRC2
127         DO_CRC2
128         DO_CRC2
129         DO_CRC2
130         DO_CRC2
131decr82:  dbra   textbufsize,loop82
132        moveq   #7,textbufsize
133        and.l   (sp)+,textbufsize
134        bra.s   decr12
135loop12:  DO_CRC2
136decr12:  dbra   textbufsize,loop12
137    endif
138
139    ENDC    ; ?NO_UNROLLED_LOOPS
140
141done:   movem.l (sp)+,btemp/ltemp
142        not.l   crcval
143;;;;;   move.l  crcval,d0               ; crcval already is d0
144        rts
145