CRC ???

ZXNet echo conference «zx.spectrum»

From Pavel Fedin To All 4 October 1997


People! Anyone who is good at algorithms, please post a decent subroutine for calculating a block checksum. I decided to start making a program for my link; I wrote an exchange driver, but I don’t know how to calculate the checksum so that there would be a maximum degree of protection. :-(

bye, with all the best wishes, Pavel Fedin.


From Konstantin Winogradow To All 5 October 1997

CRC16 will work? Disadvantage - you need a 1kb buffer for the table, although you can
get rid of it...

=== Cut ===
;----------------------
;creating a crc16 table
;----------------------
make_crc_tab
LD HL,crc16tab
LD C,0
3$ LD D,C
LD E,0
LD B,8
2$ SLA E
RL D
JR NC,1$
LD A,10h
XOR D
LD D,A
LD A,21h
XOR E
LD E,A
1$ DJNZ 2$
LD (HL),E
INC HL
LD (HL),D
INC HL
INC C
JR NZ,3$
RET
;-------------------
;calculate crc16
;input A:byte
;return DE:crc16
;-------------------
upd_crc PUSH AF
PUSH BC
LD IX,crc16tab
XOR D
RLA
LD C,A
LD B,0
RL B
ADD IX,BC
LD A,E
LD E,(IX+0)
XOR (IX+1)
LD D,A
POP BC
POP AF
RET
;--------------------
crc16tab BLKB 1024.0
=== Cut ===

From Pavel Myakotin To All 5 October 1997


Hello, Pavel!

PF> People! Anyone who is good at algorithms, please post a decent subroutine
PF> for calculating the block checksum. I decided to start making a program for
PF> my link, I wrote an exchange driver, but here’s how to calculate the control

^^^^^^^^^^^^^^^^^^^^^^
Does it really work? :)))

PF> the amount so that the maximum degree of protection would be, I don’t know. :-(

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is it necessary?

PF> bye, with all the best wishes, Pavel Fedin.

Sincerely, Pavel.


From Pavel Fedin To All 6 October 1997


hello, Pavel Myakotin! I remember, 05 Oct 97 you took it and launched it at me with this:

PM> Does it really work? :)))

I haven’t tried it yet. Someone needs to bring a second Speck from BB55.

From Yuri Lekarkin To All 7 October 1997


Hello Pavel!

PF> People! Anyone who is good at algorithms, please post a decent
PF> subroutine for calculating the block checksum. I decided to start making a
PF> program for my link, I wrote an exchange driver, but I don’t know how to calculate the
PF> checksum so that the maximum degree of protection would be.

The highest degree of noise immunity is possessed by cyclic
check codes built on the basis of polynomials. Moreover, the
higher the degree of the polynomial, the more reliable the CRC.

Here things are like this... The check area of blocks of a fixed
length and frames must contain the inverted remainder of the division modulo two by the polynomial forming the set of bits
of the service and information areas, multiplied by X^K, where
K is the size of the check area in bits.

So when recording on floppy magnetic disks, a 16th degree polynomial is used with a minimum code distance of 4:

X^16+X^12+X^5+1

(in accordance with GOST 17422-82). In this case, the block length should
be no more than 2^15 bits.

The same idea is used in hard magnetic
disk drives, and even in everyone’s favorite RAR archiver.

Now let’s get closer to the point... I present a subroutine demonstrating
the method of calculating CRC by a controller VG-93 (and not only them!):

LD IX, ARRAY ADDRESS
LD DE, ARRAY LENGTH
LD HL,0 INITIAL CONDITIONS
LDB,(IX+00)
LD C,08
M1 LD A,B
XOR H
SLA B
SLA L
JR C,M2
SLA H
JR M3
M2 SLA H
INC H
M3 BIT 7,A
JR Z,M4
INC L
JR M5
M4 LD A,20
XOR L
LD L,A
LD A,10
XOR H
LD H,A
M5 DEC C
JR NZ,M1
INC IX
LD B,(IX+00)
LD C,08
DEC DE
LD A,D
OR E
JR NZ,M1

CRC will be located at the output in HL !

I warn you right away - for the subroutine to work it takes
sufficient time, because all flop controllers consider
this is a hardware issue!

So if there are brakes - reduce the degree polynomial!

Good luck!

Crack-Band "Black Cat". Chelyabinsk 1997