Skip to content

Commit

Permalink
Support F1 by Lankhor/Domark
Browse files Browse the repository at this point in the history
Refs #73
  • Loading branch information
keirf committed Jan 28, 2020
1 parent 4679f1e commit 74d9087
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
6 changes: 5 additions & 1 deletion disk-analyse/formats
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ probe_amiga
* amigados copylock fun_factory

"Crystals Of Arborea"
158-159 crystals_of_arborea_longtrack
158-159 silmarils_longtrack
* amigados

"Cyberblast"
Expand Down Expand Up @@ -571,6 +571,10 @@ probe_amiga

"Eye Of The Beholder II" = amigados

"F1"
158 silmarils_longtrack
* amigados f1

"F-15 Strike Eagle II" = amigados

"F17 Challenge" = rnc_pdos
Expand Down
85 changes: 85 additions & 0 deletions libdisk/format/amiga/f1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* f1.c
*
* Custom format used on F1 by Domark.
*
* Written in 2020 by Keir Fraser
*
* RAW TRACK LAYOUT:
* u16 4489
* u32 0xfe000000 + tracknr
* u32 dat[0x5b6] :: even/odd
* u32 csum
* Encoding is alternating even/odd, per longword.
* Checksum is ADD.L over all decoded data longs.
*/

#include <libdisk/util.h>
#include <private/disk.h>

static void *f1_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 dat[ti->len/4+1], raw[2], sum, i;
char *block;

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

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

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)
continue;

block = memalloc(ti->len);
memcpy(block, dat, ti->len);
set_all_sectors_valid(ti);
return block;
}

fail:
return NULL;
}

static void f1_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, i;

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

for (i = sum = 0; i < ti->len/4; i++) {
tbuf_bits(tbuf, SPEED_AVG, bc_mfm_even_odd, 32, be32toh(dat[i]));
sum += be32toh(dat[i]);
}

tbuf_bits(tbuf, SPEED_AVG, bc_mfm_even_odd, 32, -sum);
}

struct track_handler f1_handler = {
.bytes_per_sector = 5848,
.nr_sectors = 1,
.write_raw = f1_write_raw,
.read_raw = f1_read_raw
};

/*
* Local variables:
* mode: C
* c-file-style: "Linux"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
12 changes: 6 additions & 6 deletions libdisk/format/amiga/longtrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ struct track_handler tiertex_longtrack_handler = {
.read_raw = protoscan_longtrack_read_raw
};

/* TRKTYP_crystals_of_arborea_longtrack: Crystals Of Arborea
/* TRKTYP_silmarils_longtrack: Used on French titles by Silmarils and Lankhor.
* u16 0xa144 :: sync
* u8[] "ROD0" (encoded bc_mfm)
* Rest of track is (MFM-encoded) zeroes
* Track is checked to be >= 104128 bits long (track is ~110000 bits long)
* Specifically, protection checks for > 6500 0xaaaa/0x5555 raw words
* starting 12 bytes into the DMA buffer (i.e., 12 bytes after the sync) */

static void *crystals_of_arborea_longtrack_write_raw(
static void *silmarils_longtrack_write_raw(
struct disk *d, unsigned int tracknr, struct stream *s)
{
struct track_info *ti = &d->di->track[tracknr];
Expand All @@ -171,7 +171,7 @@ static void *crystals_of_arborea_longtrack_write_raw(
return NULL;
}

static void crystals_of_arborea_longtrack_read_raw(
static void silmarils_longtrack_read_raw(
struct disk *d, unsigned int tracknr, struct tbuf *tbuf)
{
unsigned int i;
Expand All @@ -182,9 +182,9 @@ static void crystals_of_arborea_longtrack_read_raw(
tbuf_bits(tbuf, SPEED_AVG, bc_mfm, 8, 0);
}

struct track_handler crystals_of_arborea_longtrack_handler = {
.write_raw = crystals_of_arborea_longtrack_write_raw,
.read_raw = crystals_of_arborea_longtrack_read_raw
struct track_handler silmarils_longtrack_handler = {
.write_raw = silmarils_longtrack_write_raw,
.read_raw = silmarils_longtrack_read_raw
};

/* TRKTYP_infogrames_longtrack: Hostages, Jumping Jack Son, and others
Expand Down
3 changes: 2 additions & 1 deletion libdisk/include/libdisk/track_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ X(variable_raw_dd, "Variable-Rate Raw DD")
X(variable_raw_hd, "Variable-Rate Raw HD")
X(variable_raw_ed, "Variable-Rate Raw ED")
X(kickoff2, "AmigaDOS (Kick Off 2 Long Track)")
X(crystals_of_arborea_longtrack, "Crystals Of Arborea Copy Protection")
X(silmarils_longtrack, "Silmarils/Lankhor Copy Protection")
X(psygnosis_c, "Psygnosis C")
X(psygnosis_c_track0, "Psygnosis C - Track 0")
X(psygnosis_c_custom_rll, "Psygnosis C - Custom RLL")
Expand Down Expand Up @@ -206,3 +206,4 @@ X(turrican_3a, "Turrican 3 A")
X(turrican_3b, "Turrican 3 B")
X(turrican_3c, "Turrican 3 C")
X(head_over_heels, "Head Over Heels (Special FX)")
X(f1, "F1")

0 comments on commit 74d9087

Please sign in to comment.