Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!usenet.coe.montana.edu!netnews.nwnet.net!news.uoregon.edu!cie.uoregon.edu!nparker From: nparker@cie.uoregon.edu (Neil Parker) Newsgroups: comp.sys.apple2.programmer Subject: Re: Wanted Source Code Date: 10 Aug 1993 05:14:37 GMT Organization: The Universal Society for the Prevention of Reality Lines: 91 Message-ID: <247art$gr9@pith.uoregon.edu> NNTP-Posting-Host: cie.uoregon.edu A little while ago somebody asked about source code for Xmodem, CRC-16, and CRC-32. I had a CRC-16 routine, but no Xmodem or CRC-32. Anyway, if the original poster is still interested, I may have a CRC-32 routine here. (I say "may have" because I don't have any already-working implementations of CRC-32 handy to test it against. The table generator seems to produce the correct table, though.) Unless I made a programming error, the following routines should produce the same CRC-32 that Zmodem uses. To use these routines, first call INITC32 to initialize the CRC-32 data tables, and then initialize the memory locations CRC0 through CRC3 to $FF. Next, for each byte to be checksummed, load the byte into the accumulator and call DOCRC32. Finally, EOR each of the bytes CRC0 through CRC3 with $FF, and transmit the checksum in the order CRC0, CRC1, CRC2, CRC3. * INITC32 -- initialize CRC-32 data table * by Neil Parker * W1 EQU 6 ;(scratchpad memory locations--can be anywhere) W2 EQU 7 W3 EQU 8 * INITC32 LDY #0 L1 LDA #0 STA W1 STA W2 STA W3 TYA LDX #8 L2 LSR W3 ROR W2 ROR W1 ROR BCC L3 EOR #$20 PHA LDA W1 EOR #$83 STA W1 LDA W2 EOR #$B8 STA W2 LDA W3 EOR #$ED STA W3 PLA L3 DEX BNE L2 STA CRCTAB0,Y LDA W1 STA CRCTAB1,Y LDA W2 STA CRCTAB2,Y LDA W3 STA CRCTAB3,Y INY BNE L1 RTS * CRCTAB0 DS 256 ;(reserve 1024 bytes for CRC-32 data table) CRCTAB1 DS 256 CRCTAB2 DS 256 CRCTAB3 DS 256 * DOCRC32 -- accumulate a byte into CRC-32 checksum * by Neil Parker * CRC0 EQU 6 ;(memory locations for checksum--can be anywhere) CRC1 EQU 7 CRC2 EQU 8 CRC3 EQU 9 * DOCRC32 EOR CRC0 TAY LDA CRCTAB0,Y EOR CRC1 STA CRC0 LDA CRCTAB1,Y EOR CRC2 STA CRC1 LDA CRCTAB2,Y EOR CRC3 STA CRC2 LDA CRCTAB3,Y STA CRC3 RTS -- Neil Parker No cute ASCII art...no cute quote...no cute nparker@cie.uoregon.edu disclaimer...no deposit, no return... parker@corona.uoregon.edu (This space intentionally left blank: )