Skip to content

Commit

Permalink
F1: Format cleanups and minor fixes
Browse files Browse the repository at this point in the history
Refs #73
  • Loading branch information
keirf committed Jan 28, 2020
1 parent 74d9087 commit bccc4d1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libdisk/format/amiga/f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* RAW TRACK LAYOUT:
* u16 4489
* u32 0xfe000000 + tracknr
* u32 dat[0x5b6] :: even/odd
* u32 dat[0x5b5] :: even/odd
* u32 csum
* Encoding is alternating even/odd, per longword.
* Checksum is ADD.L over all decoded data longs.
Expand All @@ -24,25 +24,25 @@ static void *f1_write_raw(

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

uint32_t dat[ti->len/4+1], raw[2], sum, i;
uint32_t dat[ti->len/4+2], raw[2], sum, i;
char *block;

if ((uint16_t)s->word != 0x4489)
continue;

ti->data_bitoff = s->index_offset_bc - 31;
ti->data_bitoff = s->index_offset_bc - 15;

for (i = sum = 0; i < ARRAY_SIZE(dat); i++) {
if (stream_next_bytes(s, raw, 8) == -1)
goto fail;
mfm_decode_bytes(bc_mfm_even_odd, 4, raw, &dat[i]);
sum += be32toh(dat[i]);
}
if (sum != 0)
if ((be32toh(dat[0]) != (0xfe000000 | tracknr)) || (sum != 0))
continue;

block = memalloc(ti->len);
memcpy(block, dat, ti->len);
memcpy(block, dat+1, ti->len);
set_all_sectors_valid(ti);
return block;
}
Expand All @@ -59,7 +59,10 @@ static void f1_read_raw(

tbuf_bits(tbuf, SPEED_AVG, bc_raw, 32, 0x4489);

for (i = sum = 0; i < ti->len/4; i++) {
sum = 0xfe000000 | tracknr;
tbuf_bits(tbuf, SPEED_AVG, bc_mfm_even_odd, 32, sum);

for (i = 0; i < ti->len/4; i++) {
tbuf_bits(tbuf, SPEED_AVG, bc_mfm_even_odd, 32, be32toh(dat[i]));
sum += be32toh(dat[i]);
}
Expand All @@ -68,7 +71,7 @@ static void f1_read_raw(
}

struct track_handler f1_handler = {
.bytes_per_sector = 5848,
.bytes_per_sector = 5844,
.nr_sectors = 1,
.write_raw = f1_write_raw,
.read_raw = f1_read_raw
Expand Down

0 comments on commit bccc4d1

Please sign in to comment.