Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!moe.ksu.ksu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!usc!cs.utexas.edu!uunet!mnemosyne.cs.du.edu!nyx!jmaricon From: jmaricon@nyx.cs.du.edu (Jim Maricondo) Subject: Re: Wanted Source Code Message-ID: <1993Jul31.173638.3471@mnemosyne.cs.du.edu> Sender: usenet@mnemosyne.cs.du.edu (netnews admin account) Organization: University of Denver, Dept. of Math & Comp. Sci. References: <1993Jul31.025024.22120@vicstoy.UUCP> Date: Sat, 31 Jul 93 17:36:38 GMT Lines: 9 The last or second to last issue of call apple had CRC source in it for the c02.. < References: <1993Jul31.025024.22120@vicstoy.UUCP> NNTP-Posting-Host: cie.uoregon.edu In article <1993Jul31.025024.22120@vicstoy.UUCP> aphelps@vicstoy.UUCP (Austin Phelps) writes: >I'm looking for source written in 65x02 for these. > >Xmodem (Checksum or CRC, doesn't matter) >CRC-16 (this is seperate from Xmodem) >and CRC-32 I can't help much with Xmodem or CRC-32, but CRC-16 is easy. This routine needs 512 bytes of memory reserved somewhere for a data table. The following subroutine initializes the data table, and only needs to be called once at the beginning of your code. W EQU 6 ;(a scratchpad variable) INITCRC LDY #0 L1 LDA #0 STA W TYA LDX #8 L2 ASL W ROL BCC L3 EOR #$10 PHA LDA W EOR #$21 STA W PLA L3 DEX BNE L2 STA CRCTAB1,Y LDA W STA CRCTAB2,Y INY BNE L1 RTS .... CRCTAB1 DS 256 CRCTAB2 DS 256 Once the data table is initialized, computing CRCs is very simple. Initialize the memory locations CRC1 and CRC2 to zero, and for each character to be checksummed, load the character into the accumulator, and call the following subroutine. CRC1 EQU 7 ;(any memory location will do) CRC2 EQU 8 DOCRC EOR CRC1 TAY LDA CRCTAB1,Y EOR CRC2 STA CRC1 LDA CRCTAB2,Y STA CRC2 RTS The checksum is accumulated in memory locations CRC1 (first byte) and CRC2 (second byte). (Don't forget that this routine scrambles the A and Y registers.) These routines compute the CRC using the polynomial X^16 + X^12 + X^5 + 1. Different polynomials can be used by changing the constants $10 and $21 in the initialization routine. Similar routines can be written for the CRC-32, but I don't have any code examples handy. - Neil Parker P.S. A similar CRC-16 routine (which should compute exactly the same CRC, unless I made a mistake in the above code) can be found at the end of the File Type Note for Shrinkit archives (file type $E0, auxtype $8002). -- 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: ) Newsgroups: comp.sys.apple2.programmer Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!tarpit!bilver!vicstoy!aphelps From: aphelps@vicstoy.UUCP (Austin Phelps) Subject: Re: Wanted Source Code Message-ID: <1993Aug1.040032.797@vicstoy.UUCP> Organization: vicstoy public access Unix, Orlando, FL References: <1993Jul31.025024.22120@vicstoy.UUCP> <1993Jul31.173638.3471@mnemosyne.cs.du.edu> <1993Aug1.021935.115@vicstoy.UUCP> Date: Sun, 1 Aug 1993 04:00:32 GMT Lines: 188 In article <1993Aug1.021935.115@vicstoy.UUCP> aphelps@vicstoy.UUCP (Austin Phelps) writes: >>The last or second to last issue of call apple had CRC source in it for the c02.. > >Do you know how and where I can get this. And how much will it cost to get >a copy of this. I found this in File Tech Note $E0 Aux $8002 (Shrinkit NuFx info). One is for the 65C02 that it seems generates a table while another is a 16 bit with a table. -- A Sample CRC Algorithm Paper Bag Productions provides the source code to a very fast routine which does the CRC calculation as needed for NuFX archives. The routine makeLookup needs to be called only once. After the first call, the routine doByte should be called repeatedly with each new byte in succession to generate the cumulative CRC for the block. The CRC word should be reset to null ($0000) before beginning each new CRC. This is the same CRC calculation which is done for CRC/Xmodem and Ymodem. The code is easily portable to a 16-bit environment like the Apple IIgs. The only detrimental factor with this routine is that it requires 512 bytes of main memory to operate. If you can spare the space, this is one of the fastest routines Paper Bag Productions knows to generate a CRC-16 on a 6502-type machine. The CRC word should be reset to $0000 for normal CRC-16 and to $FFFF before generating the CRC on the unpacked data for each data thread. *------------------------------- * fast crc routine based on table lookups by * Andy Nicholas - 03/30/88 - 65C02 - easily portable to nmos 6502 also. * easily portable into orca/m format, just snip and save. * Modified for generic EDAsm type assemblers - MD 6/19/89 X6502 turn 65c02 opcodes on *------------------------------- * routine to make the lookup tables *------------------------------- makeLookup LDX #0 zero first page zeroLoop STZ crclo,x zero crc lo bytes STZ crchi,x zero crc hi bytes INX BNE zeroLoop *------------------------------- * the following is the normal bitwise computation * tweeked a little to work in the table-maker docrc LDX #0 number to do crc for fetch TXA EOR crchi,x add byte into high STA crchi,x of crc LDY #8 do 8 bits loop ASL crclo,x shift current crc-16 left ROL crchi,x BCC loop1 * if previous high bit wasn't set, then don't add crc * polynomial ($1021) into the cumulative crc. else add it. LDA crchi,x add hi part of crc poly into EOR #$10 cumulative crc hi STA crchi,x LDA crclo,x add lo part of crc poly into EOR #$21 cumulative crc lo STA crclo,x loop1 DEY do next bit BNE loop done? nope, loop INX do next number in series (0-255) BNE fetch didn't roll over, so fetch more RTS done crclo ds 256 space for low byte of crc table crchi ds 256 space for high bytes of crc table *------------------------------- * do a crc on 1 byte/fast * on initial entry, CRC should be initialized to 0000 * on entry, A = byte to be included in CRC * on exit, CRC = new CRC *------------------------------- doByte EOR crc+1 add byte into crc hi byte TAX to make offset into tables LDA crc get previous lo byte back EOR crchi,x add it to the proper table entry STA crc+1 save it LDA crclo,x get new lo byte STA crc save it back RTS all done crc dw 0000 cumulative crc for all data The following CRC check is written in APW assembler format for an Apple IIgs with 16-bit memory and registers on entry. crcByte start crc equ $0 crca equ $2 crcx equ $4 crctemp equ $6 sta crca 4 stx crcx 4 eor crc+1 on entry, number to add to CRC 4 and #$00ff is in (A) 3 asl a 2 tax 2 lda crc16Table,x 5 and #$00ff 3 sta crcTemp 4 lda crc-1 4 eor crc16Table,x 5 and #$ff00 3 ora crcTemp 4 sta crc 4 lda crca 4 ldx crcx 4 rts cycles = 59 ; ; CRC-16 Polynomial = $1021 ; crc16table anop dc i'$0000, $1021, $2042, $3063, $4084, $50a5, $60c6, $70e7' dc i'$8108, $9129, $a14a, $b16b, $c18c, $d1ad, $e1ce, $f1ef' dc i'$1231, $0210, $3273, $2252, $52b5, $4294, $72f7, $62d6' dc i'$9339, $8318, $b37b, $a35a, $d3bd, $c39c, $f3ff, $e3de' dc i'$2462, $3443, $0420, $1401, $64e6, $74c7, $44a4, $5485' dc i'$a56a, $b54b, $8528, $9509, $e5ee, $f5cf, $c5ac, $d58d' dc i'$3653, $2672, $1611, $0630, $76d7, $66f6, $5695, $46b4' dc i'$b75b, $a77a, $9719, $8738, $f7df, $e7fe, $d79d, $c7bc' dc i'$48c4, $58e5, $6886, $78a7, $0840, $1861, $2802, $3823' dc i'$c9cc, $d9ed, $e98e, $f9af, $8948, $9969, $a90a, $b92b' dc i'$5af5, $4ad4, $7ab7, $6a96, $1a71, $0a50, $3a33, $2a12' dc i'$dbfd, $cbdc, $fbbf, $eb9e, $9b79, $8b58, $bb3b, $ab1a' dc i'$6ca6, $7c87, $4ce4, $5cc5, $2c22, $3c03, $0c60, $1c41' dc i'$edae, $fd8f, $cdec, $ddcd, $ad2a, $bd0b, $8d68, $9d49' dc i'$7e97, $6eb6, $5ed5, $4ef4, $3e13, $2e32, $1e51, $0e70' dc i'$ff9f, $efbe, $dfdd, $cffc, $bf1b, $af3a, $9f59, $8f78' dc i'$9188, $81a9, $b1ca, $a1eb, $d10c, $c12d, $f14e, $e16f' dc i'$1080, $00a1, $30c2, $20e3, $5004, $4025, $7046, $6067' dc i'$83b9, $9398, $a3fb, $b3da, $c33d, $d31c, $e37f, $f35e' dc i'$02b1, $1290, $22f3, $32d2, $4235, $5214, $6277, $7256' dc i'$b5ea, $a5cb, $95a8, $8589, $f56e, $e54f, $d52c, $c50d' dc i'$34e2, $24c3, $14a0, $0481, $7466, $6447, $5424, $4405' dc i'$a7db, $b7fa, $8799, $97b8, $e75f, $f77e, $c71d, $d73c' dc i'$26d3, $36f2, $0691, $16b0, $6657, $7676, $4615, $5634' dc i'$d94c, $c96d, $f90e, $e92f, $99c8, $89e9, $b98a, $a9ab' dc i'$5844, $4865, $7806, $6827, $18c0, $08e1, $3882, $28a3' dc i'$cb7d, $db5c, $eb3f, $fb1e, $8bf9, $9bd8, $abbb, $bb9a' dc i'$4a75, $5a54, $6a37, $7a16, $0af1, $1ad0, $2ab3, $3a92' dc i'$fd2e, $ed0f, $dd6c, $cd4d, $bdaa, $ad8b, $9de8, $8dc9' dc i'$7c26, $6c07, $5c64, $4c45, $3ca2, $2c83, $1ce0, $0cc1' dc i'$ef1f, $ff3e, $cf5d, $df7c, $af9b, $bfba, $8fd9, $9ff8' dc i'$6e17, $7e36, $4e55, $5e74, $2e93, $3eb2, $0ed1, $1ef0' end -- Austin Phelps - aphelps@vicstoy.oau.org -or- tf3@delphi.com UUCP - {peora,ge-dab,tous,tarpit}!bilver!vicstoy!aphelps - vicstoy Public Access Unix, Orlando FL - (407)299-3661 1200/2400/9600 V.32 24 hours 8N1