CheckSum
Synopsis
CheckSum(buffer, type)
A0 D0C Prototype
void CheckSum(APTR buffer, ULONG type);Description
This command calculates the checksum of the data present in the provided buffer. Currently, the command supports two different types of checksum: BootBlock and DataBlock. Once the checksum is calculated, it is automatically inserted into the buffer at the appropriate offset.
Inputs
- buffer — Pointer to the buffer containing the data.
- type — Specifies the type of checksum to calculate. Currently, the following types are defined:
TCS_BOOTBLOCK— BootBlock checksum.TCS_DATABLOCK— DataBlock checksum.TCS_FILEBLOCK— FileBlock checksum.
Result
None. The checksum is written directly into the buffer at the appropriate offset.
Notes
This command does not modify any registers; it returns A0 and D0 intact.
See Also
assembly/asmdos.h
Implementation
The original 68020 assembly implementation:
; (15-Feb-1995) --- CheckSum(buffer,type) (a0,d0)
_LVOCheckSum
movem.l d0-d1/a0-a1,-(sp)
tst.l d0
beq.s CKSBoot
moveq #0,d0
moveq #$7F,d1
lea BB_SIZE(a0),a1 ; CheckSum pointer
move.l d0,(a1) ; Clear it
CKSLoop sub.l (a0)+,d0
dbf d1,CKSLoop
move.l d0,(a1) ; Set!!
CKSExit movem.l (sp)+,d0-d1/a0-a1
rts
CKSBoot move.l d0,BB_CHKSUM(a0) ; Clear Old CheckSum
moveq #1,d1
lea BB_CHKSUM(a0),a1 ; Save CheckSum pointer
CKSBLp add.l (a0)+,d0
bcc.s CKSJump
addq.l #1,d0
CKSJump dbf d1,CKSBLp
not.l d0
move.l d0,(a1)
movem.l (sp)+,d0-d1/a0-a1
rts
; Old Algo by =STID=
;
;CheckSumBoot
; lea 4(a0),a1
; clr.l (a1)
; move.w #$00ff,d1
; moveq #0,d0
;CheckSumBootLoop
; add.l (a0)+,d0
; bcc.s CheckSumBootJump
; addq.l #1,d0
;CheckSumBootJump
; dbf d1,CheckSumBootLoop
; not.l d0
; move.l d0,(a1)
; bra.s CheckSumExit