Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

GN_Crc allows to generate a CRC–32 (Cyclic Redundancy Check) for memory area, RAM files and File Entries on File Cards. Three different methods are available:

  1. Generate CRC–32 of a local memory area (A = CRC_MEMA)
  2. Generate CRC–32 from the current file pointer of an opened file - file handle in IX from GN_Opf (A = CRC_FILE)
  3. Generate CRC–32 from a File Entry in a File Area on an Eprom or Flash card (A = CRC_EPFL)

Register parameters

RST 20H, DEFW $7C09
--------- Iterate CRC-32 over local memory buffer -----------
IN:
    A = CRC_MEMA (0)
    HL = pointer to buffer (local memory), 
    BC = buffer size
    DE = 0, Initialize CRC-32 with FFFFFFFFh
    DE > 0, (local) pointer to initial 4-byte CRC-32

OUT, if call successful:
     Fc = 0
     DEBC = CRC-32 result (DE = high-word, BC = low-word)
OUT, if call failed:
     Fc = 1
     A = RC_BAD ($04) - bad argument

Registers changed after return:
     ......HL/IXIY same
     AFBCDE../.... different
-------------------------------------------------------------

-------- Iterate CRC-32 on open RAM file until EOF ----------
IN:
    A = CRC_FILE (1)
    HL = 0, no buffer
    HL > 0, pointer to file buffer (local memory),
    BC = buffer size (if HL > 0)
    DE = 0, Initialize CRC-32 with FFFFFFFFh
    DE > 0, (local) pointer to initial 4-byte CRC-32
    IX = file handle of open file (using GN_Opf) 

OUT, if call successful:
    Fc = 0,
    DEBC = CRC-32
    File pointer has reached EOF
OUT, if call failed:
    Fc = 1,
	A = RC_BAD ($04) - bad argument
    A = RC_xxx (file & handle related errors)

 Registers changed after return:
    ......HL/IXIY same
    AFBCDE../.... different
-------------------------------------------------------------

------- Iterate CRC-32 on File Entry in a File Card ---------
IN:
    A = CRC_EPFL (2)
    BHL = pointer to file entry
    DE = 0, Initialize CRC-32 with FFFFFFFFh
    DE > 0, (local) pointer to initial 4-byte CRC-32

OUT, if call successful:
    Fc = 0,
    DEBC = CRC-32
OUT, if call failed:
    Fc = 1,
	A = RC_BAD ($04) - bad argument
    A = RC_xxx (file card related errors)

 Registers changed after return:
    ......HL/IXIY same
    AFBCDE../.... different
-------------------------------------------------------------

Related calls

None.

Notes

GN_Crc was implemented in OZ V4.5. It is used by the integrated EazyLink popdown to validate uploaded file content. GN_Crc will be used in future OZ developments.

If this system call is used in stand-alone applications, it is necessary to validate which OZ version the application is running on:

include "fileio.def"

      ld   a,FA_PTR
      ld   ix,ffffh
      ld   de,0          ; result in DEBC
      oz   OS_Frm
      ld   a,44h         ; OZ versions are embedded as hexnibbles in C register.
      cp   c
      jr   nc, not_ozv45 ; Check for OZ V4.5 failed (44h-45h gives Fc = 1)

 

 

Example for CRC - 32 on memory contents
include "crc32.def"
      ld   a,CRC_MEMA
      ld   hl,crctext
      ld   bc,crctext_end - crctext
      ld   de,0
      oz   GN_Crc
      ; CRC–32 returned is 0x414FA339 (DE = 0x414F, BC = 0xA339)
.crctext       
      defm "The quick brown fox jumps over the lazy dog"
.crctext_end               
Example for CRC - 32 on open RAM file
include "crc32.def"
include "fileio.def"

DEFC FileBufferSize = 1280
DEFVARS $2000                          ; "popdown" workspace from 2000H onwards
        FileBuffer ds.b FileBufferSize ; buffer for file I/O
ENDDEF

        LD   A, OP_IN
        LD   BC,128
        LD   HL,filename               ; pointer to local filename
        LD   D,H
        LD   E,L
        OZ   GN_Opf 
        JR   C,not_available

; example with no buffer:
        ld   a, CRC_FILE
        ld   hl,0
        ld   de,0                      ; Use FFFFFFFFh as initial Crc-32
        oz   GN_Crc                    ; get CRC-32 of Open file (no buffer)
        oz   GN_Cl                     ; close file

; example with buffer
        ld   a, CRC_FILE
        ld   hl,FileBuffer             ; use buffer
        ld   bc,FileBufferSize             
        ld   de,0                      ; Use FFFFFFFFh as initial Crc-32
        oz   GN_Crc                    ; get CRC-32 of Open file (with buffer)
        oz   GN_Cl                     ; close file


Example for CRC - 32 on File Entry in File Card
include "crc32.def"
include "eprom.def"

        ld   c,2               
        ld   de,epfilename             ; search for filename in filea area of slot 2
        ld   a, EP_Find
        oz   OS_Epr                     
        ret  c                         ; file area not there
        ret  nz                        ; file entry not found

        ld   a, CRC_EPFL
        ld   de,0                      ; Use FFFFFFFFh as initial Crc-32
        oz   GN_Crc                    ; get CRC-32 of File Entry
  • No labels