View Single Post
Old 16 November 2008, 13:24   #47
Testaware
 
Posts: n/a
Amiga ADF BootBlock CheckSum

Quote:
Originally Posted by jasonver2.0 View Post
- I dont know how to calculate checksum in vb 2005 - if you know how to then please tell me
(ADFLib sources and andreas efforts in C doesnt help - i dont know C that well)
I like this tool very much and it's helpful as well

I'd read the problems to calculate a correct checksum for a BootBlock,
I can't give you a VB example coz I've never coded in VB but perhaps this
code will help you? It's coded in Amiga Assembler and converted to PureBasic:

Code:
;*******************************************************
;* Amiga ASM source to calculate checksum of BootBlock *
;*******************************************************
;* Calculate checksum of BootBlock
;* In:  A0 => Ptr to BootBlock
;* Out: D0 => CheckSum
;
;CalcBBCkSum
;      clr.l    4(a0)      ;clear old checksum
;      moveq    #0,d0      ;clear new checkSum
;      move.w   #255,d1    ;255 x DWORD
;1$    add.l    (a0)+,d0   ;add DWORD
;      bcc.s    2$         ;Caryflag?
;      addq.l   #1,d0      ;correct checksum
;2$    dbf      d1,1$      ;loop until D0 = FALSE
;      not.l    d0         ;negate checksum
;      rts


;*******************************************************
;* PureBasic source to calculate checksum of BootBlock *
;*******************************************************

;Macro to correct handling of DWORD 
Macro AmigaLong(LONG)
    ((LONG>>24)&$FF)|((LONG>>8)&$FF00)|((LONG<<8)&$FF0000)|((LONG<<24)&$FF000000)
EndMacro

;Name of ADF discimage
adf.s = "C:\Amiga\ASM\DevPac3.adf"

;Open ADF for read
If  ReadFile(0, adf)

    ;Allocate memory for BootBlock (=1024 bytes)
    *bb_Mem = AllocateMemory(1024)
    ReadData(0, *bb_Mem, 1024)
    CloseFile(0)

    ;Get old checksum for test only
    ;LONG  = PeekL(*bb_Mem + 4)
    ;LONG  = AmigaLong(LONG)
    ;Debug "Old Checksum: " + Hex(LONG)

    ;Clear old checksum (must!) 
    PokeL(*bb_Mem + 4, 0)

    ;Calculate new checksum (see ASM 1$ to 2$)
    For i = 0 To 255
        LONG  = PeekL(*bb_Mem + i * 4)
        bb_Sum+ AmigaLong(LONG)
        If  bb_Sum < 0
            bb_Sum + 1
        EndIf
    Next
    bb_Sum = AmigaLong(bb_Sum)
    bb_Sum = bb_Sum!-1
    bb_Sum = AmigaLong(bb_Sum)

    ;New calculated checksum in bb_Sum
    Debug  "New Checksum: " + Hex(bb_Sum)

EndIf
 
 
Page generated in 0.09103 seconds with 9 queries