Welcome, Guest. Please login or register.

Author Topic: MFM decode  (Read 7966 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline olsen

Re: MFM decode
« Reply #14 from previous page: December 19, 2017, 03:29:05 PM »
Quote from: orange;834223
ok, thanks.
finally found the problem.
I was using:
 $bitdata = unpack "b*",$data;
instead of
 $bitdata = unpack "B*",$data;

in perl :/

Oh well... give 'C' a try, please. Only a fraction of the expressiveness that leads Perl users to their doom, but the same degree of catastrophic errors easily triggered by a mere single wrong character that is abstrusely difficult to spot ;)
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #15 on: December 19, 2017, 06:05:06 PM »
sure, will do, thanks olsen :)
just need to figure out format of the other, nonAmiga, diskette first.

edit:
 it seems to use this format: http://nerdlypleasures.blogspot.rs/2015/11/ibm-pc-floppy-disks-deeper-look-at-disk.html

I've managed to decode the whole diskette, but couldn't check CRC of individual sectors data.
« Last Edit: December 20, 2017, 11:52:20 AM by orange »
Better sorry than worry.
 

Offline olsen

Re: MFM decode
« Reply #16 on: December 21, 2017, 02:40:51 PM »
Quote from: orange;834230
sure, will do, thanks olsen :)
just need to figure out format of the other, nonAmiga, diskette first.

edit:
 it seems to use this format: http://nerdlypleasures.blogspot.rs/2015/11/ibm-pc-floppy-disks-deeper-look-at-disk.html

I've managed to decode the whole diskette, but couldn't check CRC of individual sectors data.


The source code for messydisk.device is available from AmiNet, and the sector decoding including the CRC processing can be found in the "dev/devio2.c" file, specifically the CMD_Read() function. The CRC values are decoded along with the track data (in "dev/devio1.a") and eventually checked in CMD_Read().
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #17 on: December 21, 2017, 06:43:54 PM »
thanks, excellent, finally it works.
I didn't know that:
Quote
; The CRC is computed not only over the actual data, but including
; the SYNC mark (3 * $a1) and the 'ID/DATA - Address Mark' ($fe/$fb).
Better sorry than worry.
 

Offline olsen

Re: MFM decode
« Reply #18 on: December 22, 2017, 02:09:39 PM »
Quote from: orange;834286
thanks, excellent, finally it works.
I didn't know that:


So, you are going to publish the fruits of your research, aren't you? :)
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #19 on: December 22, 2017, 02:20:03 PM »
erm, I only got perl for now, it decodes raw .adf into Tim011 image ( CP/M )
so the 'rawread' output is input for this thing.
it probably could have been one-liner :)

Quote

#!/usr/bin/perl
# decode MFM    TIM011 SECTOR SIZE= 1024bytes, sectors_per_track=5

use strict;
use warnings;
use Digest::CRC qw(crc32 crcccitt crcccitt_hex crc16 crc16_hex crc_hex crc8_hex);

use utf8;
use bytes;

# OFFSET              Count TYPE   Description
# 0000h                   8 byte   UAE-1ADF
# 0008h                   4 byte   trackcount

# 000Eh                  4 byte   0=amigados 1=raw mfm
# 0010h                  4 byte   tracklength
# 0014h                  4 byte   tracklength in bits
# ..


my ( $i, @tracks, $trackdata, $trackcount, $header, $bitdata, @sector, @track, $image, $data );
my ( $file_in, $file_out ) = ( $ARGV[0], $ARGV[1] );
my $syncbit = unpack "B*", "\xAA\xAA\xAA\xAA\x44\x89\x44\x89\x44\x89";
my $sector_per_track = 5;
my $sector_length = 1024;

{local $/; open( FILE0, "< :raw :bytes", "$file_in" ) or die "Can't open for reading: $!\n"; $data = ; close(FILE0);}
$header = substr ($data, 0, 2004); # header = 8+4+166*12 = 2004
$trackcount = unpack "N", substr ($data, 8, 4);
$trackdata = substr ($data, 12, 12*$trackcount);
@tracks = $trackdata =~ /.{12}/gs;
$data = substr ($data, 2004); # print "\n\ndatalen1=" . length $data . "\n";# exit;
$bitdata = unpack "B*",$data;


for my $i (0 .. 159) { #159
 my $tracklenbit = unpack "N", substr ($tracks[$i], 8, 4);
 print "\ntrack=$i, tracklen=$tracklenbit \n";
 my $trackdata = substr ($bitdata, 0, $tracklenbit);
 $bitdata = substr ($bitdata, $tracklenbit);
 
 for my $j (1 .. $sector_per_track) { # 5
  my $pos = index ($trackdata, $syncbit)+length($syncbit);
  my $sector_id = substr ($trackdata, $pos, 16+ 4*8*2); #16:FE
  $sector_id =~ s/.(.)/$1/gs; #strip clock
  $sector_id = pack "B*",$sector_id;
  my ($track_num, $side_num, $sector_num, $sector_s ) = unpack("xc1c1c1c1", $sector_id);
  print  " sector=$sector_num, sector size=$sector_s \n" ;

  $pos = index ($trackdata, $syncbit, $pos)+length($syncbit);
  my $sector_dat = substr ($trackdata, $pos+16, $sector_length*8*2+32); # 16:FB 32:CRC=C74C
  $trackdata = substr ($trackdata, $pos);
  $sector_dat =~ s/.(.)/$1/gs; #strip clock
  $sector[$sector_num] = pack "B*", substr ($sector_dat, 0, $sector_length*8);
  my $crc = unpack "n*", pack "B*", substr ($sector_dat, $sector_length*8);
  my $crc_chk = crcccitt( "\xA1\xA1\xA1\xFB" . $sector[$sector_num]);
  if ( $crc eq $crc_chk) { print "CRC OK!\n"; }
  else { print "CRC ERROR! , $crc, $crc_chk \n\n" ; exit; }
 }
 
 $track[$i] = join ("", $sector[17], $sector[18], $sector[19], $sector[20], $sector[21]);
}

$image = join ("", @track);
{local $/; open( FILE0, "> :raw :bytes", "$file_out" ) or die "write err: $!\n"; print FILE0 $image; close(FILE0);}

exit;




Better sorry than worry.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: MFM decode
« Reply #20 on: February 15, 2018, 11:59:23 AM »
Quote from: orange;834196
what does ' length 12656/4' mean in output?
how long is the header, what is its format?
thanks.


edit: is it like this:

OFFSET              Count TYPE   Description
0000h                   8 byte   'UAE-1ADF'
0008h                   4 byte   trackcount
000Ch                   4 byte   0=amigados 1=raw mfm
0010h                   4 byte   tracklength
0014h                   4 byte   tracklength in bits
0018h                   4 byte   0=amigados 1=raw mfm
...





I just cant find '0xAAAA AAAA 4489 4489'   :(

( http://lclevy.free.fr/adflib/adf_info.html#p23 )


I've tried rawread, it doesn't seem to output the MFM data, it just produces and ADF with some extra metadata.

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #21 on: February 15, 2018, 05:07:56 PM »
there is an option to force 'raw' mode. if it still doesn't work, you can try with some NDOS diskette.
Better sorry than worry.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: MFM decode
« Reply #22 on: February 15, 2018, 05:37:42 PM »
Quote from: orange;836158
there is an option to force 'raw' mode. if it still doesn't work, you can try with some NDOS diskette.


I'm testing with a normal OFS floppy...

I did use the -r option... but the output is still ordinary bytes not encoded data :(

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #23 on: February 15, 2018, 06:34:22 PM »
Quote from: bloodline;836160
I'm testing with a normal OFS floppy...

I did use the -r option... but the output is still ordinary bytes not encoded data :(

try -1 and maybe -x
Better sorry than worry.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: MFM decode
« Reply #24 on: February 15, 2018, 11:24:55 PM »
Quote from: orange;836167
try -1 and maybe -x

Good call, using -x -1 I definitely get mfm data! But the first sync word is at 370,076 bytes into the file!! that can't be track 0??
« Last Edit: February 15, 2018, 11:34:53 PM by bloodline »
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show only replies by orange
Re: MFM decode
« Reply #25 on: February 16, 2018, 03:49:13 PM »
have you searched bit-by-bit? that's the hardest part. if yes, perhaps it strips sync. dunno, check source. I couldn't understand it comnpletely, perl is much easier. amiga does some weird 'interlacing', too.
Better sorry than worry.