/* * disk/judge_dredd.c * * Custom format as used on Judge Dredd by Virgin * * Written in 2024 by Keith Krellwitz * * RAW TRACK LAYOUT: * u16 0x5122 Sync * u32 0xaaaaaaaa or mfm decoded 0x0 * u16 0xaa92 * u32 dat[ti->len/4] * u32 checksum * * TRKTYP_judge_dredd data layout: * u8 sector_data[6144] * */ #include #include static void *judge_dredd_write_raw( struct disk *d, unsigned int tracknr, struct stream *s) { struct track_info *ti = &d->di->track[tracknr]; while (stream_next_bit(s) != -1) { uint32_t raw[2], dat[ti->len/4], csum, sum; unsigned int i; char *block; if ((uint16_t)s->word != 0x5122) continue; ti->data_bitoff = s->index_offset_bc - 15; if (stream_next_bits(s, 32) == -1) goto fail; if (mfm_decode_word(s->word) != 0) continue; if (stream_next_bits(s, 16) == -1) goto fail; if ((uint16_t)s->word != 0xaa92) continue; for (i = sum = 0; i < ti->len/4; i++) { if (stream_next_bytes(s, raw, 8) == -1) goto fail; mfm_decode_bytes(bc_mfm_odd_even, 4, raw, &dat[i]); sum += be32toh(dat[i]); } if (stream_next_bytes(s, raw, 8) == -1) goto fail; mfm_decode_bytes(bc_mfm_odd_even, 4, raw, &csum); if (be32toh(csum) != sum) continue; stream_next_index(s); block = memalloc(ti->len); memcpy(block, dat, ti->len); set_all_sectors_valid(ti); ti->total_bits = s->track_len_bc; return block; } fail: return NULL; } static void judge_dredd_read_raw( struct disk *d, unsigned int tracknr, struct tbuf *tbuf) { struct track_info *ti = &d->di->track[tracknr]; uint32_t *dat = (uint32_t *)ti->dat, sum; unsigned int i; tbuf_bits(tbuf, SPEED_AVG, bc_raw, 16, 0x5122); tbuf_bits(tbuf, SPEED_AVG, bc_mfm, 16, 0); tbuf_bits(tbuf, SPEED_AVG, bc_raw, 16, 0xaa92); for (i = sum = 0; i < ti->len/4; i++) { tbuf_bits(tbuf, SPEED_AVG, bc_mfm_odd_even, 32, be32toh(dat[i])); sum += be32toh(dat[i]); } tbuf_bits(tbuf, SPEED_AVG, bc_mfm_odd_even, 32, sum); } struct track_handler judge_dredd_handler = { .bytes_per_sector = 6144, .nr_sectors = 1, .write_raw = judge_dredd_write_raw, .read_raw = judge_dredd_read_raw }; /* * Local variables: * mode: C * c-file-style: "Linux" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */