

procedure crcinit;
  begin
    inline
    (
      $21/CRCTBL/   {          LD    HL,CRCTBL    }
      $0E/00/       {          LD    C,0          }
      $EB/          {GLOOP:    EX    DE,HL        }
      $21/00/00/    {          LD    HL,0         }
      $79/          {          LD    A,C          }
      $C5/          {          PUSH  BC           }
      $06/$08/      {          LD    B,8          }
      $AC/          {          XOR   H            }
      $67/          {          LD    H,A          }
      $29/          {LLOOP:    ADD   HL,HL        }
      $30/$08/      {          JR    NC,LSKIP     }
      $3E/$10/      {          LD    A,10H        }
      $AC/          {          XOR   H            }
      $67/          {          LD    H,A          }
      $3E/$21/      {          LD    A,21H        }
      $AD/          {          XOR   L            }
      $6F/          {          LD    L,A          }
      $10/$F3/      {LSKIP:    DJNZ  LLOOP        }
      $C1/          {          POP   BC           }
      $EB/          {          EX    DE,HL        }
      $72/          {          LD    (HL),D       }
      $24/          {          INC   H            }
      $73/          {          LD    (HL),E       }
      $25/          {          DEC   H            }
      $23/          {          INC   HL           }
      $0C/          {          INC   C            }
      $20/$DF       {          JR    NZ,GLOOP     }
    );
  end;

procedure crc(abyte:integer;var crcwd:integer);
  begin
    inline
    (
      $2A/CRCWD/    {CRCUPD:   LD    HL,(CRCWD)   ; Point HL at crcwd }
      $5E/          {          LD    E,(HL)       ; Put value into DE }
      $23/          {          INC   HL           }
      $56/          {          LD    D,(HL)       ; DE holds crcwd }
      $ED/$4B/ABYTE/{          LD    BC,(ABYTE)   ; C holds byte to be added }
      $79/          {          LD    A,C          ; A holds byte to be added }
      $06/$00/      {          LD    B,0          }
      $AA/          {          XOR   D            }
      $4F/          {          LD    C,A          }
      $21/CRCTBL/   {          LD    HL,CRCTBL    }
      $09/          {          ADD   HL,BC        }
      $7E/          {          LD    A,(HL)       }
      $AB/          {          XOR   E            }
      $57/          {          LD    D,A          }
      $24/          {          INC   H            }
      $5E/          {          LD    E,(HL)       }
      $2A/CRCWD/    {          LD    HL,(CRCWD)   }
      $73/          {          LD    (HL),E       }
      $23/          {          INC   HL           }
      $72           {          LD    (HL),D       }
    );
  end;
