Compare commits
2 commits
master
...
img-writec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33ce100bca | ||
|
|
7fed26da99 |
1 changed files with 102 additions and 73 deletions
175
src/image/img.c
175
src/image/img.c
|
|
@ -1876,15 +1876,17 @@ static void raw_setup_track(
|
||||||
im->cur_ticks = im->cur_bc * im->ticks_per_cell;
|
im->cur_ticks = im->cur_bc * im->ticks_per_cell;
|
||||||
im->ticks_since_flux = 0;
|
im->ticks_since_flux = 0;
|
||||||
|
|
||||||
decode_off = calc_start_pos(im);
|
|
||||||
|
|
||||||
rd->prod = rd->cons = 0;
|
rd->prod = rd->cons = 0;
|
||||||
bc->prod = bc->cons = 0;
|
bc->prod = bc->cons = 0;
|
||||||
|
|
||||||
if (start_pos) {
|
if (start_pos) {
|
||||||
|
decode_off = calc_start_pos(im);
|
||||||
|
|
||||||
image_read_track(im);
|
image_read_track(im);
|
||||||
bc->cons = decode_off * 16;
|
bc->cons = decode_off * 16;
|
||||||
*start_pos = start_ticks;
|
*start_pos = start_ticks;
|
||||||
|
} else {
|
||||||
|
im->img.decode_pos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1963,8 +1965,8 @@ static bool_t raw_write_track(struct image *im)
|
||||||
struct raw_sec *sec;
|
struct raw_sec *sec;
|
||||||
unsigned int i, off;
|
unsigned int i, off;
|
||||||
time_t t;
|
time_t t;
|
||||||
uint16_t crc;
|
uint16_t crc = im->img.crc;
|
||||||
uint8_t idam_r, x;
|
uint8_t idam_r;
|
||||||
|
|
||||||
/* If we are processing final data then use the end index, rounded up. */
|
/* If we are processing final data then use the end index, rounded up. */
|
||||||
barrier();
|
barrier();
|
||||||
|
|
@ -1974,69 +1976,83 @@ static bool_t raw_write_track(struct image *im)
|
||||||
|
|
||||||
while ((int16_t)(p - c) > 128) {
|
while ((int16_t)(p - c) > 128) {
|
||||||
|
|
||||||
uint32_t sc = c;
|
if (im->img.decode_pos == 0) {
|
||||||
|
|
||||||
if (im->sync == SYNC_fm) {
|
uint8_t x;
|
||||||
|
|
||||||
uint16_t sync;
|
|
||||||
if (buf[c++ & bufmask] != 0xaaaa)
|
|
||||||
continue;
|
|
||||||
sync = buf[c & bufmask];
|
|
||||||
if (mfmtobin(sync >> 1) != FM_SYNC_CLK)
|
|
||||||
continue;
|
|
||||||
x = mfmtobin(sync);
|
|
||||||
c++;
|
|
||||||
|
|
||||||
} else { /* MFM */
|
|
||||||
|
|
||||||
if (be16toh(buf[c++ & bufmask]) != 0x4489)
|
|
||||||
continue;
|
|
||||||
if ((x = mfmtobin(buf[c & bufmask])) == 0xa1)
|
|
||||||
continue;
|
|
||||||
c++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (x) {
|
|
||||||
|
|
||||||
case 0xfe: /* IDAM */
|
|
||||||
if (im->sync == SYNC_fm) {
|
if (im->sync == SYNC_fm) {
|
||||||
wrbuf[0] = x;
|
|
||||||
for (i = 1; i < 7; i++)
|
uint16_t sync;
|
||||||
wrbuf[i] = mfmtobin(buf[c++ & bufmask]);
|
if (buf[c++ & bufmask] != 0xaaaa)
|
||||||
idam_r = wrbuf[3];
|
continue;
|
||||||
|
sync = buf[c & bufmask];
|
||||||
|
if (mfmtobin(sync >> 1) != FM_SYNC_CLK)
|
||||||
|
continue;
|
||||||
|
x = mfmtobin(sync);
|
||||||
|
c++;
|
||||||
|
|
||||||
} else { /* MFM */
|
} else { /* MFM */
|
||||||
for (i = 0; i < 3; i++)
|
|
||||||
wrbuf[i] = 0xa1;
|
if (be16toh(buf[c++ & bufmask]) != 0x4489)
|
||||||
wrbuf[i++] = x;
|
continue;
|
||||||
for (; i < 10; i++)
|
if ((x = mfmtobin(buf[c & bufmask])) == 0xa1)
|
||||||
wrbuf[i] = mfmtobin(buf[c++ & bufmask]);
|
continue;
|
||||||
idam_r = wrbuf[6];
|
c++;
|
||||||
|
|
||||||
}
|
}
|
||||||
crc = crc16_ccitt(wrbuf, i, 0xffff);
|
|
||||||
if (crc != 0) {
|
switch (x) {
|
||||||
log("IDAM Bad CRC: %04x, %u\n", crc, idam_r);
|
|
||||||
|
case 0xfe: /* IDAM */
|
||||||
|
if (im->sync == SYNC_fm) {
|
||||||
|
wrbuf[0] = x;
|
||||||
|
for (i = 1; i < 7; i++)
|
||||||
|
wrbuf[i] = mfmtobin(buf[c++ & bufmask]);
|
||||||
|
idam_r = wrbuf[3];
|
||||||
|
} else { /* MFM */
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
wrbuf[i] = 0xa1;
|
||||||
|
wrbuf[i++] = x;
|
||||||
|
for (; i < 10; i++)
|
||||||
|
wrbuf[i] = mfmtobin(buf[c++ & bufmask]);
|
||||||
|
idam_r = wrbuf[6];
|
||||||
|
}
|
||||||
|
crc = crc16_ccitt(wrbuf, i, 0xffff);
|
||||||
|
if (crc != 0) {
|
||||||
|
log("IDAM Bad CRC: %04x, %u\n", crc, idam_r);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Search by sector id for this sector's logical order. */
|
||||||
|
for (i = 0, sec = im->img.sec_info;
|
||||||
|
(i < trk->nr_sectors) && (sec->r != idam_r);
|
||||||
|
i++, sec++)
|
||||||
|
continue;
|
||||||
|
im->img.write_sector = i;
|
||||||
|
if (i >= trk->nr_sectors) {
|
||||||
|
log("IDAM Bad Sector: %02x\n", idam_r);
|
||||||
|
im->img.write_sector = -2;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xfb: /* DAM */
|
||||||
|
im->img.decode_pos = 1;
|
||||||
|
im->img.decode_data_pos = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Search by sector id for this sector's logical order. */
|
|
||||||
for (i = 0, sec = im->img.sec_info;
|
|
||||||
(i < trk->nr_sectors) && (sec->r != idam_r);
|
|
||||||
i++, sec++)
|
|
||||||
continue;
|
|
||||||
im->img.write_sector = i;
|
|
||||||
if (i >= trk->nr_sectors) {
|
|
||||||
log("IDAM Bad Sector: %02x\n", idam_r);
|
|
||||||
im->img.write_sector = -2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0xfb: /* DAM */ {
|
} else {
|
||||||
unsigned int nr, todo, sec_sz;
|
|
||||||
|
/* Data record, shy address mark */
|
||||||
|
unsigned int sec_sz;
|
||||||
int sec_nr = im->img.write_sector;
|
int sec_nr = im->img.write_sector;
|
||||||
|
|
||||||
|
ASSERT(im->img.decode_pos == 1);
|
||||||
|
|
||||||
if (sec_nr < 0) {
|
if (sec_nr < 0) {
|
||||||
if (sec_nr == -1)
|
if (sec_nr == -1) {
|
||||||
sec_nr = raw_find_first_write_sector(im, write, trk);
|
sec_nr = raw_find_first_write_sector(im, write, trk);
|
||||||
|
im->img.write_sector = sec_nr;
|
||||||
|
}
|
||||||
if (sec_nr < 0) {
|
if (sec_nr < 0) {
|
||||||
log("DAM Unknown\n");
|
log("DAM Unknown\n");
|
||||||
goto dam_out;
|
goto dam_out;
|
||||||
|
|
@ -2044,40 +2060,54 @@ static bool_t raw_write_track(struct image *im)
|
||||||
}
|
}
|
||||||
|
|
||||||
sec_sz = sec_sz(im->img.sec_info[sec_nr].n);
|
sec_sz = sec_sz(im->img.sec_info[sec_nr].n);
|
||||||
if ((int16_t)(p - c) < (sec_sz + 2)) {
|
|
||||||
c = sc;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
crc = (im->sync == SYNC_fm) ? FM_DAM_CRC : MFM_DAM_CRC;
|
|
||||||
|
|
||||||
sec = &im->img.sec_info[sec_nr];
|
sec = &im->img.sec_info[sec_nr];
|
||||||
log("Write %u[%02x]/%u... ", sec_nr, sec->r, trk->nr_sectors);
|
|
||||||
t = time_now();
|
|
||||||
|
|
||||||
if (im->img.file_sec_offsets) {
|
if (im->img.file_sec_offsets) {
|
||||||
off = im->img.file_sec_offsets[sec_nr];
|
off = im->img.file_sec_offsets[sec_nr];
|
||||||
} else if (trk->img_bps != 0) {
|
} else if (trk->img_bps != 0) {
|
||||||
off = sec_nr * trk->img_bps;
|
off = sec_nr * trk->img_bps;
|
||||||
} else {
|
} else {
|
||||||
off = 0;
|
|
||||||
sec = im->img.sec_info;
|
sec = im->img.sec_info;
|
||||||
for (i = 0; i < sec_nr; i++)
|
for (i = off = 0; i < sec_nr; i++)
|
||||||
off += sec_sz(sec++->n);
|
off += sec_sz(sec++->n);
|
||||||
}
|
}
|
||||||
F_lseek(&im->fp, im->img.trk_off + off);
|
off += im->img.trk_off;
|
||||||
|
off += im->img.decode_data_pos;
|
||||||
|
|
||||||
for (todo = sec_sz; todo != 0; todo -= nr) {
|
if (im->img.decode_data_pos < sec_sz) {
|
||||||
nr = min_t(unsigned int, todo, CHUNK_SIZE);
|
unsigned int nr;
|
||||||
|
nr = sec_sz - im->img.decode_data_pos;
|
||||||
|
nr = min_t(unsigned int, nr, CHUNK_SIZE - (off & 511)); /* XXX */
|
||||||
|
if (p - c < nr)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!im->img.decode_data_pos) {
|
||||||
|
crc = (im->sync == SYNC_fm) ? FM_DAM_CRC : MFM_DAM_CRC;
|
||||||
|
log("Write %u[%02x]/%u...",
|
||||||
|
sec_nr, sec->r, trk->nr_sectors);
|
||||||
|
F_lseek(&im->fp, off);
|
||||||
|
}
|
||||||
|
|
||||||
|
t = time_now();
|
||||||
mfm_ring_to_bin(buf, bufmask, c, wrbuf, nr);
|
mfm_ring_to_bin(buf, bufmask, c, wrbuf, nr);
|
||||||
c += nr;
|
c += nr;
|
||||||
crc = crc16_ccitt(wrbuf, nr, crc);
|
crc = crc16_ccitt(wrbuf, nr, crc);
|
||||||
process_data(im, wrbuf, nr);
|
process_data(im, wrbuf, nr);
|
||||||
F_write(&im->fp, wrbuf, nr, NULL);
|
F_write(&im->fp, wrbuf, nr, NULL);
|
||||||
|
printk(" %u us", time_diff(t, time_now()) / TIME_MHZ);
|
||||||
|
im->img.decode_data_pos += nr;
|
||||||
|
if (im->img.decode_data_pos < sec_sz)
|
||||||
|
printk("...");
|
||||||
|
else
|
||||||
|
printk("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("%u us\n", time_diff(t, time_now()) / TIME_MHZ);
|
if (im->img.decode_data_pos < sec_sz)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (p - c < 2)
|
||||||
|
break;
|
||||||
mfm_ring_to_bin(buf, bufmask, c, wrbuf, 2);
|
mfm_ring_to_bin(buf, bufmask, c, wrbuf, 2);
|
||||||
c += 2;
|
c += 2;
|
||||||
crc = crc16_ccitt(wrbuf, 2, crc);
|
crc = crc16_ccitt(wrbuf, 2, crc);
|
||||||
|
|
@ -2085,15 +2115,14 @@ static bool_t raw_write_track(struct image *im)
|
||||||
log("Bad CRC: %04x, %u[%02x]\n", crc, sec_nr, sec->r);
|
log("Bad CRC: %04x, %u[%02x]\n", crc, sec_nr, sec->r);
|
||||||
}
|
}
|
||||||
|
|
||||||
dam_out:
|
dam_out:
|
||||||
im->img.write_sector = -2;
|
im->img.write_sector = -2;
|
||||||
break;
|
im->img.decode_pos = 0;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
im->img.crc = crc;
|
||||||
wr->cons = c * 16;
|
wr->cons = c * 16;
|
||||||
return flush;
|
return flush;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue