Snippets

ScorpionIlluminati Checksum Subroutine

Created by ScorpionIlluminati
; ******************************************
; Calculates the checksum and returns if it is correct
; a1 - pointer to end of rom address
; ******************************************
CalculateChecksum:
      movea.l #$200,a0                                                         ; move start of rom address into a0
      move.l  (a1),d0                                                          ; copy the value from the address pointed by a1 into d0
      moveq   #0,d1                                                            ; move 0 into d1
ChecksunLoop:
      add.w   (a0)+,d1                                                         ; add value in a1 into d0
      cmp.l   a0,d0                                                            ; did we finish checksumming the entire rom?
      bcc.s   ChecksumLoop                                                     ; if not continue checksumming the rom
      movea.l #$18E,a1                                                         ; move checksum into a1
      cmp.w   (a1),d1                                                          ; is the checksum correct?
      bne.s   @WrongChecksum                                                   ; if checksum is wrong branch to wrong checksum code 
      moveq #0, d0                                                             ; checksum is correct so set d0 to 0
      bra @CorrectChecksum                                                     ; and jump over wrong checksum code
@WrongChecksum
      moveq #1, d0                                                             ; checksum is wrong so set d0 to 1
@CorrectChecksum
    rts

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.