57
|
1 ; 6809 CRC16 with tests
|
|
2 ;
|
|
3 ; Johann E. Klasek, j AT klasek at
|
|
4 ;
|
|
5 ; Testprogram and finaly submitted to http://beebwiki.mdfs.net/index.php/CRC-16#6809
|
|
6
|
|
7 org $100
|
|
8 lds #$8000
|
|
9
|
|
10 ; Calculate an XMODEM 16-bit CRC from data in memory. This code is as
|
|
11 ; tight and as fast as it can be, moving as much code out of inner
|
|
12 ; loops as possible.
|
|
13 ;
|
|
14 ; On entry, reg. D = incoming CRC
|
|
15 ; reg. U = start address of data
|
|
16 ; reg. X = number of bytes
|
|
17 ; On exit, reg. D = updated CRC
|
|
18 ; reg. U = points to first byte behind data
|
|
19 ; reg. X = 0
|
|
20 ; reg. Y = 0
|
|
21 ;
|
|
22 ; Value order in memory is H,L (big endian)
|
|
23 ;
|
|
24 ; Multiple passes over data in memory can be made to update the CRC.
|
|
25 ; For XMODEM, initial CRC must be 0000.
|
|
26 ;
|
|
27 ; XMODEM setup:
|
|
28 ; polynomic
|
|
29 CRCH EQU $10
|
|
30 CRCL EQU $21
|
|
31 ; initial CRC
|
|
32 CRCINIT EQU $0000
|
|
33
|
|
34 ; input parameters ...
|
|
35 ldu #s2 ; data (samples: s1 or s2)
|
|
36 ldb ,u+
|
|
37 clra
|
|
38 tfr d,x ; data size
|
|
39 ldd #CRCINIT ; incoming CRC
|
|
40
|
|
41 crc16:
|
|
42
|
|
43 bl:
|
|
44 eora ,u+ ; fetch byte and XOR into CRC high byte
|
|
45 ldy #8 ; rotate loop counter
|
|
46 rl: aslb ; shift CRC left, first low
|
|
47 rola ; and than high byte
|
|
48 bcc cl ; Justify or ...
|
|
49 eora #CRCH ; CRC=CRC XOR polynomic, high
|
|
50 eorb #CRCL ; and low byte
|
|
51 cl: leay -1,y ; shift loop (8 bits)
|
|
52 bne rl
|
|
53 leax -1,x ; byte loop
|
|
54 bne bl
|
|
55
|
|
56 ; CRC in D
|
|
57
|
|
58 realexit:
|
|
59 sync
|
|
60
|
|
61 s1: fcb 19,"An Arbitrary String"
|
|
62 ; CRC=$DDFC
|
|
63 s2: fcb 26,"ZYXWVUTSRQPONMLKJIHGFEDBCA"
|
|
64 ; CRC=$B199
|
|
65
|
|
66 enddata
|
|
67
|
|
68 end
|