Changes

Jump to: navigation, search

Programming:CRC32

1,862 bytes added, 07:16, 26 July 2006
Initial page
== The author ==
Author of this code is 84plusfreak. He wrote this routine for the TI84 calculator, but it should work on the CPC without big modifications (just change the addresses which are used).

== The Code ==
'''CRC32Init'''

<pre>
CRC32Init:
;Inputs:
; A=0 -> Use 'default' Polynomial (the one used in the ZIP Format)
; A=1 -> Use custom Polynomial
; -> DEHL=Polynomial
;Outputs:
; ($8292)=Polynomial
; ($8296)=Current CRC (~($8296)=CRC32)
;Destroys:
; AF,DE,HL
or a
jr nz,$+08
ld de,$EDB8
ld hl,$8320
ld a,d
ld d,e
ld e,a
ld a,h
ld h,l
ld l,a
ld ($8292),de
ld ($8294),hl
ld hl,$FFFF
ld ($8296),hl
ld ($8298),hl
ret
</pre>


'''CRC32Update'''

<pre>
CRC32Update:
;Inputs:
; HL -> Points to data
; BC -> Number of bytes
;Outputs:
; ($8296) = Updated
;Destroys:
; AF,BC,DE,HL
ld a,b
or c
ret z
push hl
push bc
ld b,(hl)
call CRC32Update_Routine
pop bc
pop hl
inc hl
dec bc
jr CRC32Update
CRC32Update_OneByte:
;Inputs:
; A = Byte to add to CRC
;Destroys:
; AF,BC,DE,HL
ld b,a
CRC32Update_Routine:
ld a,($8296)
xor b
call CRC32TableLookup
ld a,($8297)
xor l
ld ($8296),a
ld a,($8298)
xor h
ld ($8297),a
ld a,($8299)
xor e
ld ($8298),a
ld a,d
ld ($8299),a
ret
CRC32TableLookup:
ld de,$0000
ld h,d
ld l,a
ld b,8
CRC32TableLookupLoop:
push bc
or a
rr d
rr e
rr h
rr l
jr nc,CRC32TableLookupLoopEnd
push hl
pop bc
ld hl,$8292
ld a,d
xor (hl)
inc hl
ld d,a
ld a,e
xor (hl)
inc hl
ld e,a
ld a,b
xor (hl)
inc hl
ld b,a
ld a,c
xor (hl)
ld c,a
push bc
pop hl
CRC32TableLookupLoopEnd:
pop bc
djnz CRC32TableLookupLoop
ret
</pre>


'''CRC32Finalize'''

<pre>
CRC32Finalize:
;Inputs:
; None
;Outputs:
; DEHL = CRC32
;Destroys:
; AF,BC,DE,HL
ld de,($8298)
ld bc,($8296)
ld hl,$FFFF
push hl
or a
sbc hl,bc
ex (sp),hl
sbc hl,de
ex de,hl
pop hl
ret
</pre>
1,165
edits