Skip to navigation

BBC Micro Elite

Save and load: CHECK

Name: CHECK [View in context] Type: Subroutine Category: Save and load Summary: Calculate the checksum for the last saved commander data block
Calculate the checksum for the last saved commander data block, to protect against corruption and tampering. The checksum is returned in A. This algorithm is also implemented in elite-checksum.py.
.CHECK { LDX #NT%-2 \ Set X to the size of the commander data block, less \ 2 (as there are two checksum bytes) CLC \ Clear the carry flag so we can do addition without \ the carry flag affecting the result TXA \ Seed the checksum calculation by setting A to the \ size of the commander data block, less 2 \ We now loop through the commander data block, \ starting at the end and looping down to the start \ (so at the start of this loop, the X-th byte is the \ last byte of the commander data block, i.e. the save \ count) .QUL2 ADC NA%+7,X \ Add the X-1-th byte of the data block to A, plus \ carry EOR NA%+8,X \ EOR A with the X-th byte of the data block DEX \ Decrement the loop counter BNE QUL2 \ Loop back for the next byte in the data block RTS \ Return from the subroutine }