into the tables. Looking at the table tab0l[x] we see that only 4 values are actually
present which means that means our precomputed table bytes are effectively XOR'ed
Integrating (i.e. EOR'ing) these into the other tables and making
Effectively making tab0l[x] futile.
This leads to this new version which saves 5 cycles per byte (~705k in our use case) and 19 bytes footprint:
Code: Select all
CRC0 = $FB
CRC1 = CRC0 + 1
CRC2 = CRC1 + 1
CRC3 = CRC2 + 1
count = $2
CRC_START = $A000
CRC_COUNT = $2000
*=$0810
sei
lda #>CRC_START
ldx #>CRC_COUNT
CalcCRC
; A = Start address high
; X = count
sta readvalue+2
stx count
lda #$FF
sta CRC0
sta CRC1
sta CRC2
sta CRC3
CRC_Loop
readvalue
lda $FF00
eor CRC0
tay
and #$0f ; compute "x"
tax
tya ; compute "y"
lsr
lsr
lsr
lsr
tay
lda CRC1
eor tab1l0h,x
eor tab0,y
sta CRC0
lda CRC2
eor tab2l1h,x
eor tab1,y
sta CRC1
lda CRC3
eor tab3l2h,x
eor tab2,y
sta CRC2
lda tab3h,x
eor tab3,y
sta CRC3
inc readvalue+1
bne CRC_Loop
not_high
inc readvalue+2
dec count
bne CRC_Loop
done
ldx #3
loopinv
lda CRC0,x
eor #$ff
sta CRC0,x
dex
bpl loopinv
cli
rts
align 256
tab3h byte $00,$77,$EE,$99,$07,$70,$E9,$9E,$0E,$79,$E0,$97,$09,$7E,$E7,$90
tab3l2h byte $00,$07,$0E,$09,$6D,$6A,$63,$64,$DB,$DC,$D5,$D2,$B6,$B1,$B8,$BF
tab2l1h byte $00,$30,$61,$51,$C4,$F4,$A5,$95,$88,$B8,$E9,$D9,$4C,$7C,$2D,$1D
tab1l0h byte $00,$96,$2C,$BA,$19,$8F,$35,$A3,$32,$A4,$1E,$88,$2B,$BD,$07,$91
tab3 byte $00,$1D,$3B,$26,$76,$6B,$4D,$50,$ED,$F0,$D6,$CB,$9B,$86,$A0,$BD
tab2 byte $00,$B7,$6E,$D9,$DC,$6B,$B2,$05,$B8,$0F,$D6,$61,$64,$D3,$0A,$BD
tab1 byte $00,$10,$20,$30,$41,$51,$61,$71,$83,$93,$A3,$B3,$C2,$D2,$E2,$F2
tab0 byte $00,$64,$C8,$AC,$90,$F4,$58,$3C,$20,$44,$E8,$8C,$B0,$D4,$78,$1C
PS: I'm really out of more ideas... but let's wait another half-year.