Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

  1. Generate CRC–32 of a local memory area (A = CRC_MEMAfor example a string)
  2. Generate CRC–32 from the current file pointer of an opened file - file handle in IX from GN_Opf (A = CRC_FILE)of complete RAM file
  3. Generate partial CRC–32 of RAM file. This enables the application to process CRC-32 across file entry while other activites are done
  4. Generate CRC–32 from a File Entry in a File Area on an Eprom or Flash card (A = CRC_EPFL)
  5. Generate partial CRC–32 a File Entry in a File Area on an Eprom or Flash card. Process CRC-32 across file entry while other activites are done

Register parameters

--------- Iterate buffer -----------
Code Block
theme
titleRST 20H, DEFW $7C09
Eclipse
titleIterate CRC-32
over
local
memory
buffer
OZ GN_Crc - RST 20H, DEFW $7C09

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


Code Block
themeEclipse
titleCRC_FILE, Iterate CRC-

...

32 on complete RAM file (from file pointer until EOF), using OS_Mv
OZ GN_Crc - RST 20H, DEFW $7C09

IN:
    A = CRC_FILE (1)
    HL =

...

 

...

pointer to file buffer (local memory)

...

 
    BC = buffer size

...

 

...

 

...

 

...

 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

...


...


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
Code Block
themeEclipse
titleIterate CRC-

...

32 partially on RAM file (from file pointer onwards), using OS_Gb
OZ GN_Crc - RST 20H, DEFW $7C09

IN:
    A = CRC_

...

PARTFILEBYTE (2)
    

...

HL = max 

...

bytes to 

...

read 

...

for this partial scan, or 

...

-1 

...

for 

...

rest 

...

of file
    DEBC = Initial CRC-32

...

 or input from result of previous partial CRC-32 scan
    

...

IX 

...

= 

...

file handle of open file (using GN_Opf)

OUT, if call successful:
    Fc = 0

...


    DEBC = partial CRC-32 

...

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:

Code Block
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)

 

 

Code Block
titleExample 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  result (DE = high-word, BC = low-word), to be used for next scan iteration 

    Fc = 1, A _RC_Eof
    DEBC = final CRC-32 result (DE = high-word, BC = low-word) 

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


Code Block
themeEclipse
titleIterate CRC-32 partially (buffered) on RAM file (from file pointer onwards), using OS_Mv
OZ GN_Crc - RST 20H, DEFW $7C09

IN:
    A = CRC_PARTFILEBUF (3)
    HL = pointer to file buffer (local memory), 
    BC = buffer size 
    DE = 0, Initialize CRC-32 with FFFFFFFFh
    DE > 0, (local) pointer to 4-byte CRC-32 (initial CRC-32 or input from result of previous partial scan)
    IX = file handle of open file (using GN_Opf)

OUT, if call successful:
    Fc = 0
    DEBC = partial CRC-32 result (DE = high-word, BC = low-word), to be used for next scan iteration

    Fc = 1, A _RC_Eof
    DEBC = final CRC-32 result (DE = high-word, BC = low-word) 

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


Code Block
themeEclipse
titleIterate CRC-32 on complete File Entry (File Card)
OZ GN_Crc - RST 20H, DEFW $7C09

IN:
    A = CRC_EPFILE (4)
    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


Code Block
themeEclipse
titleIterate CRC-32 partially on File Entry (File Card)
OZ GN_Crc - RST 20H, DEFW $7C09

IN:
    A = CRC_PARTEPFILE (5)

    Initial call:
    BHL = pointer to File Entry
    DE = max. size of bytes to read per partial scan
    IX = pointer to local memory (allocated in application/popdown workspace, 12 bytes):
    (IX + 0,3)   : Initial CRC-32 or input from result of previous partial CRC-32 scan
    (IX + 4,6)   : Reserved for 24bit file pointer (initialized after first call)
    (IX + 7,9)   : Reserved for size of file entry (initialized after first call)
    (IX + 10,11) : Reserved for max. bytes to read per partial scan

    Subsequent calls:
    BHL = 0 (this is returned automatically after initial call to this method)
    IX = pointer to updated local memory of CRC-32 variables (12 bytes):

 OUT:
    BHL = 0, always

    Fc = 0
    (IX + 0,3)   : partial CRC-32 result, low-byte, high-byte order
    (IX + 4,6)   : 24bit file pointer updated for next partial scan
    (IX + 7,9)   : Remaining file size updated for next partial scan
    (IX + 10,11) : max. bytes to read per partial scan = DE (initial input)

    Fc = 1
    A = RC_Eof (complete file scanned)
    (IX + 0,3)   : final CRC-32 result, low-byte, high-byte order;

    Fc = 1
    A = RC_xxx (System error occurred - file entry corrupt, not found, etc.)

Registers changed on return:
    ......../IXIY same
    AFBCDEHL/.... 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. FlashStore also uses it to display the checksum of a File Entry to be fetched to RAM. GN_Crc will be used more 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:

Code Block
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)

 

 

Code Block
titleExample 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               
Code Block
themeEclipse
titleExample for CRC - 32 on open RAM file using a buffer
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

        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), returned in DEBC
        oz   GN_Cl                     ; close file
Code Block
themeEclipse
titleExample for CRC - 32 on open RAM file without buffer (slowest)
include "crc32.def"
include "fileio.def"
include "error.def"

        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

        ld   a, CRC_PARTFILEBYTE
        ld   hl,1024                   ; read 1024 bytes at a time from file
        ld   bc,$ffff
        ld   d,b
        ld   e,c                       ; Use FFFFFFFFh as initial Crc-32

.scan_file
        oz   GN_Crc                    ; get CRC-32 of Open file (no buffer)
        jr   c,check_eof
        push bc
        push de
        push hl

        call do_task

        pop  hl
        pop  de
        pop  bc
        jr   scan_file

.check_eof
        oz   GN_Cl                     ; close file
        cp   Rc_eof
        ret  z                         ; CRC-32 completed, return DEBC to caller
        scf   defm "The quick brown fox jumps over the lazy dog" .crctext_end               
Code Block
titleExample for CRC - 32 on open RAM file
include "crc32.def"
include "fileio.def"

DEFC FileBufferSize = 1280
DEFVARS $2000; other error occurred - signal Fc = 1, A = RC_xxx
        ret
Code Block
titleExample for CRC - 32 on File Entry in File Card
include "crc32.def"
include "eprom.def"

        ld   c,2 ; "popdown" workspace from 2000H onwards         FileBuffer
ds.b FileBufferSize ; buffer for file I/O ENDDEF   ld       LD   A, OP_INde,epfilename          LD   BC,128 ; search for filename in filea area of LDslot 2
 HL,filename       ld   a, EP_Find
   ; pointer to local filename oz   OS_Epr     LD   D,H         LD   E,L 
       OZ ret  GN_Opfc          JR   C,not_available  ; example with no buffer:      ; file area ldnot there
 a, CRC_FILE      ret  nz ld   hl,0         ld   de,0        ; file entry not found

        ld ; Use FFFFFFFFh as initial Crc-32a, CRC_EPFILE
        ld  oz de,0  GN_Crc                    ; getUse CRC-32FFFFFFFFh ofas Open file (no buffer)initial Crc-32
        oz   GN_Cl Crc                    ; closeget fileCRC-32 of ;File exampleEntry withreturned bufferin DEBC
Code Block
titleExample for CRC - 32 on partial File Entry in File Card
include "crc32.def"
include "eprom.def"

  ld   a, CRC_FILE
 DEFVARS $2000       ld   hl,FileBuffer             ; use buffer ; "popdown" workspace from 2000H onwards
  ld   bc,FileBufferSize   FE_CRC32VARS ds.b 12 
ENDDEF

        ld   c,2  ld   de,0          
        ld   ;de,epfilename Use FFFFFFFFh as initial Crc-32        ; ozsearch for filename GN_Crcin filea area of slot 2
        ld   a, EP_Find
 ; get CRC-32 of Open file (with buffer)oz   OS_Epr      oz   GN_Cl            
        ;ret close filec   
Code Block
titleExample for CRC - 32 on File Entry in File Card
include "crc32.def" include "eprom.def"          ld   c,2      ; file area not there
        ret  nz   ld   de,epfilename             ; search for filename in filea; areafile ofentry slotnot 2found

       ld ld   a, EPCRC_FindPARTEPFILE
        ld oz  ix, OSFE_EprCRC32VARS          ; variable space for partial GN_Crc
        ld   de,1024       ret  c          ; Scan max. 1024 bytes per loop iteration, initial Crc-32 is FFFFFFFFh
.crc32_fe_loop
    ; file area not thereoz   GN_Crc      ret  nz            ; get partial CRC-32 of File Entry in BHL (or BHL = ;0 filefor entrynext notpartial foundblock)
         ldjr   ac, CRCfinal_EPFLcrc32
        ld...
  de,0      call do_task
        ...
     ; Use FFFFFFFFh asjr initial Crc-32
  crc32_fe_loop
.final_crc
      oz   GN_Crc    ; CRC-32 is available in (IX+0)
        call display_crc32
     ; get CRC-32 ofret
File Entry