459
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
) for this property to return a
meaningful value.
.Checksum Method
Function:
Calculates or verifies the checksum for the data in the
currently selected RAM buffer of the flash memory
(selection is made through the
property).
Syntax:
fd.checksum(mode as pl_fd_csum_mode, byref csum
as word) as ok_ng
Returns:
0- OK: Completed successfully (always the case when the
mode= 1- PL_FD_CSUM_MODE_CALCULATE).
1- NG : The checksum was found to be invalid (can only
be generated when the mode= 0-
PL_FD_CSUM_MODE_VERIFY).
Also returns the calculation result indirectly, through the
csum argument.
See Also:
,
,
,
,
Par
t
Description
mo
de
0- PL_FD_CSUM_MODE_VERIFY: verify the checksum.
1- PL_FD_CSUM_MODE_CALCULATE: calculate the checksum.
csu
m
Indirectly returns calculated value. When the mode= 0-
PL_FD_CSUM_MODE_VERIFY, this value returned will be 0 if the
checksum was found to be correct, or some other value if the checksum
was found to be wrong. When the mode= 1-
PL_FD_CSUM_MODE_CALCULATE, the method will return a newly
calculated checksum.
Details
Each physical sector of the flash memory has 264 bytes of data. The flash disk of
the .fd object uses 256 bytes to store the data, and two of the remaining 8 bytes
(at offsets 256 and 257, counting from 0) are used to store the checksum of the
data. This is an arbitrary choice -- there is no special reason why the .fd object
does it this way, and not in any other way.
During checksum verification, first 258 bytes of the selected RAM buffer (data +
checksum) are added together as 129 sixteen-bit values. The result is then limited
to lower 16 bits. If the value is 0, then the checksum is correct. If the value is not
0, then the checksum is incorrect.
During checksum calculation, first 256 bytes of the selected RAM buffer are added
together as 128 sixteen-bit values. The result is then limited to lower 16 bits and
subtracted from &h10000. Obtained value is the checksum which is subsequently
stored at offsets 256 and 257 of the RAM buffer.
16-bit values for these calculations are little-endian. That is, offset 0 of the RAM
buffer is presumed to be the high byte of the first 16-bit value, offset 1 -- low byte
474
458
450
472
483
468
479