<> <> <> <> <> <> <> DIRECTORY ; Checksum: DEFINITIONS = BEGIN ComputeChecksum: PROC [ cs: CARD16 _ 0, nHalfWords: CARDINAL, p: POINTER] RETURNS [checksum: CARD16] = ComputeChecksumProc[cs, nHalfWords, p]; <<... produces a checksum for nWords starting at p. Start with initial value cs (useful if forming a single checksum for discontinuous areas of memory). Note that since these checksums must agree with those computed in the existing world they are 16 bit checksums computed over an integral number of 16 bit halfwords, even though Dragon is a 32 bit machine.>> <<>> <> <> <<>> ComputeChecksumSoftware: PRIVATE PROC [ cs: CARD16 _ 0, nHalfWords: CARDINAL, p: POINTER] RETURNS [checksum: CARD16] = INLINE { FOR i: CARDINAL IN [0..nWords) DO t: CARD16; w: CARD16 = IF ODD[i] THEN LOOPHOLE[p^, Basics.LongNumber].lo ELSE LOOPHOLE[p^, Basics.LongNumber].hi; <> IF cs > (t _ cs + w) THEN cs _ t + 1 ELSE cs _ t; IF cs >= 100000B THEN cs _ cs*2 + 1 ELSE cs _ cs*2; IF ODD[i] THEN p _ p + 1; ENDLOOP; IF cs = 177777B THEN cs _ 0; RETURN[cs]; }; <<>> <> ComputeChecksumProc: PRIVATE PROC [ cs: CARD16 _ 0, nHalfWords: CARDINAL, p: POINTER] RETURNS [checksum: CARD16] = { NYI[] }; END.