Re: nibtools, GCR, G64

From: Pete Rittwage <peter_at_rittwage.com>
Date: Thu, 30 May 2013 15:24:10 -0400 (EDT)
Message-ID: <58553.10.2.0.31.1369941850.squirrel@rittwage.com>
On Thu, May 30, 2013 3:12 pm, silverdr@wfmh.org.pl wrote:
>
> On 2013-05-30, at 20:55, Pete Rittwage wrote:
>
>>> So if I find a SYNC not being byte-aligned, I should expect that the
>>> actual data (header or sector itself) won't be aligned either, right?
>>> If
>>> that's the case then.. arrghh... %^#$
>>
>> Definitely- all the data will be aligned to the sync, so you have to
>> shift
>> everything in between the syncs... Also, you can't assume there is no
>> "illegal" GCR which will throw off the framing.
>
> And how that aligning to SYNC works when SYNC is anything between 10 and
> 40 bits? If I align byte's MSB to the first bit of the SYNC, I still don't
> know how many bits are there behind those ten I found? What if there is -
> say - only 13 consecutive '1' bits rather than 40?

Feel free to optimize.

/* this routine "fixes" non-sync-byte aligned images created from RAW
Kryoflux stream files */
void sync_align(BYTE *buffer, int length)
{
    int i,j;
    int bytes, bits;
        BYTE carry;

    // shift buffer left to edge of sync marks
    for (i = 0; i < length; i++)
    {
                if((buffer[i] == 0xff) && (buffer[i+1] != 0xff) &&
((buffer[i+1] & 0x80) == 0x80)) /* at least one bit left
over */
                {
                        i++;  //set first byte to shift
                        bits=bytes=j=0;  //reset byte count

                        // find next sync
                        while(!((buffer[i+j] == 0xff) && ((buffer[i+j+1] &
0x80) == 0x80))) { j++; bytes++; if(i+j>length)
break; }
                        printf("(bytes:%d)", bytes);

                        //shift left until MSB cleared
                        while((buffer[i] & 0x80) == 0x80)
                        {
                                if(bits++>7)
                                        printf("error shift too long!");

                                for(j=0; j<bytes; j++)
                                {
                                        if(i+j>length) goto end;
                                        carry = buffer[i+j+1];
                                buffer[i+j] = (buffer[i+j] << 1)  | (carry
>> 7);
                                }
                                buffer[i+j] |= 0x1;
                                printf("[%x]",buffer[i]);
                        }
                        end:;
                        i+=bytes;
                }
    }
    printf("\n");
}



       Message was sent through the cbm-hackers mailing list
Received on 2013-05-30 20:02:49

Archive generated by hypermail 2.2.0.