CRC-16

ZXNet echo conference «code.zx»

From Kirill Frolov To All 22 August 2000

Press RESET immediately, All! I see a lot of places where these tables are inserted ready-made. Lameness this. The table can be calculated: CRCPOLY equ 0x1021 ; for CCITT CRCINIT equ 0 crc_table ds 0x100*2 init_crctable: ldhl,0 add hl, sp exx di ld sp, 0x100*2+crc_table ld de, CRCPOLY ld c, 0 @@byte: ld l, 0 ld h, c dec h ld b, 8 @@nbit: add hl, hl jr c, @@nxor ld a, l xor e ld l, a ld a, h xor d ld h, a @@nxor: djnz @@nbit push hl dec c jr nz, @@byte exx ld sp, hl ei ret ; hl = data ptr, bc = size of block --> hl=crc crc_count: ld de, CRCINIT @@byte: ld a, b or c jr z, @@end ld a, d xor (hl) exx ld h, crc_table/256 scf adc a,crc_table256 jr nc, @@nc inc h @@nc: ld l, a ld a, (hl) exx xor e ld d,a exx dec hl ld a, (hl) exx ld e, a dec bc inc hl jr @@byte @@end: ex de, hl ret I don’t know how many errors I inserted here when transferring to ASM. Asm mazday.