Menu

#7 |TAPE format

release 0.3-beta
closed
nobody
None
12 hours ago
2026-03-03
No

|TAPE:SAVE"dummy"
die erzeugte Datei kann vom original-CPC oder anderen Emulatoren nicht gelesen werden.

Discussion

  • Dietmar Schmidt

    Dietmar Schmidt - 13 hours ago

    in 256 #Byte.Blöcken, (der letzte muss mit nullen aufgefüllt werden) abspeichern, dann eine Prüfsumme über die gesamten 256 Bytes (auch beim Header) erstellen.
    Hier der Code dazu, falls es mal jemand anders braucht:

      function CpcCrc(const Data: array of Byte;syncchar:byte): word;
      var i,bi:integer;
          Checksum:word;     // entspricht (B8D3) little-endian
          CurrentByte:byte;
          BitValue:byte;       // 0 oder 1
          A:byte;              // das "letzte geschriebene Bit" als $00 oder $FF
          H,L:byte;           // für lesbare Darstellung
      procedure UpdateChecksum; inline;
      var
        tempA:byte;
        carry:boolean;
      begin
        // ld hl,(B8D3)
        H:=hi(Checksum);
        L:=lo(Checksum);
        // xor h
        tempA:=A xor H;
        // jp p, 29A0     wenn Sign-Flag = 0 (Bit 7 = 0)  positiver Pfad
        if (tempA and $80)=0 then
          carry:=false
        else
        begin
          // 1-Bit
          // ld a,h
          // xor 08
          tempA:=H xor $08;
          H:=tempA;
          // ld a,l
          // xor 10
          tempA:=L xor $10;
          L:=tempA;
          // scf  Carry = 1
          carry:=true;
        end;
        // adc hl,hl    HL  HL*2 + Carry
        // in Pascal: Links-Shift + Carry-Bit ins LSB
        Checksum:=(word(H) shl 8) or L; // macht aus HL = Checksum
        Checksum:=(Checksum shl 1) and $FFFF;   // <<1 , oberes Bit weg
        if carry then
          Checksum:=Checksum or 1;              // Carry ins Bit 0
        // ld (B8D3),hl   schon in Checksum
      end;
      procedure UpdateChecksumByte(currentbyte:byte);
      var BitPos:integer;
      begin
        for BitPos:=7 downto 0 do
        begin
          BitValue:=(currentbyte shr BitPos) and 1;
          if BitValue = 1 then
            A:=$FF
          else
            A:=$00;
          // Routine aufrufen
          UpdateChecksum;
        end;
      end;
      begin
        Checksum:=$FFFF; // init
        if syncchar>0 then
          UpdateChecksumByte(syncchar);
        for bi:=low(data) to high(data) do
          UpdateChecksumByte(data[bi]);
        result:=Checksum xor $FFFF;
      end;
    
     
  • Dietmar Schmidt

    Dietmar Schmidt - 13 hours ago

    (hinweis: syncchar muss immer 0 sein, könnte man auch weglassen)

     
  • Dietmar Schmidt

    Dietmar Schmidt - 12 hours ago
    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB