[A83] Re: Special ram areas?


[Prev][Next][Index][Thread]

[A83] Re: Special ram areas?




> Van: Joe Pemberton <dArkSk8eR@buffbody.com>
> 
> There is an easy way to make 99.99% sure the contents of the program is
> intact and still in the same memory location - do a Cyclic Redundancy
> Check.  Add up every single byte in the compiled routine (the actuall
> binary values for the opcodes).  Then put a checksum at the end of the
> routine that already has the correct sum.  If the added up value equals
> the checksum, then you can call the routine.  Else, the routine has been
> written over.

CRC routine? Ah well, here you have one (dunno about the speed). You
probably want to put the _CRCByte routine into the loop of _CRCBlock...

;/************************************************************************\
;	CRC-16 Calculcations
;
;	Author : Greg Young, Z-World.
;
;	These functions compute the 1021-CRC used in many applications
;	(XModem, Opto-22 Networking, Etc.)
;\************************************************************************/

;_CRCByte : Shift One Byte into Current CRC-CCITT
;
; INPUT  :
;          HL = CRC Accumulator
;          DE = Pointer to Data
; OUTPUT :
;          HL = CRC Accumulator
;          DE = DE + 1

_CRCByte:
               push     bc             ; Protect BC
               ld       b,8            ; B = Bit Counter
               ld       a,(de)         ; C = Next Data Byte
               ld       c,a            ;
               inc      de             ; Bump Input Pointer
_CRCB0:
               ld       a,c            ; A.7 = Data.7 ^ CRC.15
               xor      h              ;
               add      hl,hl          ; Accumulator <<= 1
               jp       p,_CRCB1      ; If A.7 Clear, Move to Next Bit
               ld       a,10h          ; Accumulator ^= 0x1021
               xor      h              ;
               ld       h,a            ;
               ld       a,21h          ;
               xor      l              ;
               ld       l,a            ;
_CRCB1:
               rl       c              ; Ready Next Bit
               djnz     _CRCB0        ; Continue til All Bits Shifted
               pop      bc             ; Restore BC
               ret                     ; Done

; _CRCBlock : Compute CRC-CCITT for Block
;
; INPUT  :
;          HL = Accumulator
;          DE = Data Input Pointer
;          BC = Byte Counter
; OUTPUT :
;          HL = Accumulator
;          DE = DE + BC

_CRCBlock:
               call     _CRCByte      ; Shift in Next Byte
               dec      bc             ; Adjust Byte Count
               ld       a,b            ; Continue til Zero
               or       c
               jr       nz,_CRCBlock
               ret                     ; Done




Follow-Ups: