Beispiel #1
0
static void *psygnosis_c_track0_write_raw(
    struct disk *d, unsigned int tracknr, struct stream *s)
{
    struct track_info *ti = &d->di->track[tracknr];
    uint16_t dat[V1_METABLK_WORDS+1], raw[2];
    char *ablk, *block;
    unsigned int i, metablk_words, ver;

    init_track_info(ti, TRKTYP_amigados);
    ablk = handlers[TRKTYP_amigados]->write_raw(d, tracknr, s);
    if ((ablk == NULL) || (ti->type != TRKTYP_amigados))
        goto fail;

    for (ver = 1; ver <= 2; ver++) {

        stream_reset(s);

        metablk_words = (ver == 1) ? V1_METABLK_WORDS : V2_METABLK_WORDS;

        while (stream_next_bit(s) != -1) {

            if ((uint16_t)s->word != 0x428a)
                continue;
            ti->data_bitoff = s->index_offset - 15;

            if ((ver == 2) &&
                ((stream_next_bits(s, 16) == -1) ||
                 ((uint16_t)s->word != 0xaaaa)))
                continue;

            for (i = 0; i < (metablk_words + 1); i++) {
                if (stream_next_bytes(s, raw, 4) == -1)
                    break;
                mfm_decode_bytes(bc_mfm_even_odd, 2, raw, &dat[i]);
            }

            if (checksum(&dat[1], metablk_words, ver) != be16toh(dat[0]))
                continue;

            init_track_info(ti, TRKTYP_psygnosis_c_track0);
            ti->len += metablk_words*2;
            ti->total_bits = 105500;
            block = memalloc(ti->len);
            memcpy(block, ablk, 512*11);
            memcpy(&block[512*11], &dat[1], metablk_words*2);
            memfree(ablk);
            return block;
        }
    }

fail:
    memfree(ablk);
    return NULL;
}
Beispiel #2
0
static struct container *eadf_open(struct disk *d)
{
    struct disk_header dhdr;
    struct track_header thdr;
    struct disk_info *di;
    struct track_info *ti;
    unsigned int i;

    lseek(d->fd, 0, SEEK_SET);

    read_exact(d->fd, &dhdr, sizeof(dhdr));
    if (strncmp(dhdr.sig, "UAE-1ADF", sizeof(dhdr.sig)))
        return NULL;

    d->di = di = memalloc(sizeof(*di));
    di->nr_tracks = be16toh(dhdr.nr_tracks);
    di->track = memalloc(di->nr_tracks * sizeof(struct track_info));

    for (i = 0; i < di->nr_tracks; i++) {
        ti = &di->track[i];
        read_exact(d->fd, &thdr, sizeof(thdr));
        thdr.type = be16toh(thdr.type);
        if (thdr.type != 1) {
            warnx("Bad track type %u in Ext-ADF", thdr.type);
            goto cleanup_error;
        }
        init_track_info(ti, TRKTYP_raw);
        ti->len = be32toh(thdr.len);
        if (ti->len == 0) {
            init_track_info(ti, TRKTYP_unformatted);
            ti->total_bits = TRK_WEAK;
        } else {
            ti->dat = memalloc(ti->len);
            ti->total_bits = be32toh(thdr.bitlen);
        }
    }

    for (i = 0; i < di->nr_tracks; i++) {
        ti = &di->track[i];
        read_exact(d->fd, ti->dat, ti->len);
    }

    return &container_eadf;

cleanup_error:
    for (i = 0; i < di->nr_tracks; i++)
        memfree(di->track[i].dat);
    memfree(di->track);
    memfree(di);
    d->di = NULL;
    return NULL;
}
static void *interceptor_software_write_raw(
    struct disk *d, unsigned int tracknr, struct stream *s)
{
    struct track_info *ti = &d->di->track[tracknr];
    char *ablk;
    unsigned int i;

    init_track_info(ti, TRKTYP_amigados);
    ablk = handlers[TRKTYP_amigados]->write_raw(d, tracknr, s);
    if ((ablk == NULL) || (ti->type != TRKTYP_amigados))
        goto fail;

    stream_reset(s);

    while (stream_next_bit(s) != -1) {

        /* Sync word 0xa144 precedes the AmigaDOS block by ~2000 bits. */
        if ((uint16_t)s->word != 0xa144)
            continue;
        ti->data_bitoff = s->index_offset_bc - 15;

        /* Check for a decent-length zero sequence after the sync. */
        for (i = 0; i < 32; i++)
            if ((stream_next_bits(s, 32) == -1)
                || mfm_decode_word(s->word))
                break;
        if (i != 32)
            continue;

        /* Skip 104400 bits after the sync pattern. Check for 0xa145
         * fill pattern, repeating. */
        stream_next_bits(s, 104400-32*32);
        if (s->word != 0xa145a145)
            continue;

        init_track_info(ti, TRKTYP_interceptor_software);
        ti->total_bits = 105550;
        return ablk;
    }

fail:
    memfree(ablk);
    return NULL;
}
Beispiel #4
0
static void adf_init_track(struct track_info *ti)
{
    unsigned int i;

    init_track_info(ti, TRKTYP_amigados);
    ti->dat = memalloc(ti->len);
    ti->data_bitoff = 1024;
    ti->total_bits = DEFAULT_BITS_PER_TRACK;

    set_all_sectors_invalid(ti);

    for (i = 0; i < ti->len/4; i++)
        memcpy(ti->dat+i*4, "NDOS", 4);
}