home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / buffers.lbr / BCRC.MZC / BCRC.MAC
Encoding:
Text File  |  1987-01-14  |  1.4 KB  |  36 lines

  1.     extrn    .crc
  2. ;
  3. ; Compute a CRC16 checksum over the content of buffer hl^. The
  4. ; initial CRC checksum value is passed and returned in (bc). It
  5. ; should be initialized to 0ffffh.  .bcrc entry does not initialize,
  6. ; thus allowing the crc checksum to be applied over multiple buffer
  7. ; loads. This is intended to be used with large buffered transfers,
  8. ; between calls on .bload and the following .bdump. A file re-read
  9. ; can then quickly verify an accurate transfer. This code assumes
  10. ; the buffer never wraps, i.e. it is used solely for file/file
  11. ; transfers, so that it is always loaded from the bottom. If not
  12. ; unloaded it should be flushed (use .bflush) before reloading.
  13. ; Carry for invalid buffer state
  14. ; a,f,b,c
  15. .bcrc::    push    h
  16.     push    d
  17.     inx h    ! inx h
  18.     inx h    ! inx h;        bypass size
  19.     inx h    ! inx h;        point to cnt
  20.     mov a,m ! ani 07fh
  21.     stc    ! jnz bcrc2;        assumptions invalid
  22.     mov e,m    ! inx h ! mov d,m;    get cnt, multiple of 128
  23.     mov a,e ! ora d
  24.     jz    bcrc2;            < 128 bytes stored, exit
  25.     inx    h;            advance to rptr
  26.     mov a,m    ! inx h ! ora m;    rptr should be zero
  27.     stc    ! jnz bcrc2;        assumptions invalid, error
  28.     inx h    ! inx h ! inx h;    point to buffer start
  29. bcrc1:    mov a,m    ! inx h;        buffer known non-empty
  30.     call    .crc
  31.     dcx d    ! mov a,d ! ora e;    clears any carry
  32.     jnz    bcrc1;            more
  33. bcrc2:    pop    d
  34.     pop    h
  35.     ret
  36. <Σ