prog8/examples/bench8/crc16.p8

31 lines
661 B
Plaintext
Raw Normal View History

2022-08-12 20:02:44 +00:00
%import textio
main {
sub crc16(uword data, uword length) -> uword {
uword crc = 0
repeat length {
crc ^= @(data) << $0008
repeat 8 {
if crc & $8000
crc = (crc<<1)^$1021
else
crc<<=1
}
data++
}
return crc
}
sub start() {
txt.print("calculating...")
c64.SETTIM(0,0,0)
uword crc = crc16($e000, $2000)
txt.print_uwhex(crc, true) ; should be $ffd0
txt.nl()
txt.print_uw(c64.RDTIM16())
txt.print(" jiffies")
sys.wait(100)
}
}