Welcome, Guest. Please login or register.

Author Topic: MFM decode  (Read 7978 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
MFM decode
« on: December 17, 2017, 05:36:04 PM »
does 'rawread' dump MFM encoded data? if so, how to decode it with given sync, track size, etc..? (not a standard 880K diskette)
Better sorry than worry.
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #1 on: December 17, 2017, 07:00:51 PM »
thanks Thomas.
« Last Edit: December 17, 2017, 07:41:33 PM by orange »
Better sorry than worry.
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #2 on: December 18, 2017, 08:42:07 PM »
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 )
« Last Edit: December 18, 2017, 11:15:50 PM by orange »
Better sorry than worry.
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #3 on: December 19, 2017, 08:56:34 AM »
Quote from: olsen;834214
Shrug... this does not look like anything I would expect to find on a standard Amiga formatted floppy disk. Are you sure you are looking for MFM data? If this is the data structure layout, I would expect it to be a container format, not the contents.

that is an output of rawread command, it writes 'extended' ADF format, at least when raw tracks are present.

Quote
You may not be able to see this pattern in the encoded MFM data at all. The thing is, this is a bit pattern, not a byte pattern. It can start in the MFM bit stream at virtually any position in the track buffer, but usually it's somewhere near the beginning of the buffer.

thanks. I was searching at bit-level, but will try again. perhaps rawread removes the sync?

Quote
So, how do you find the bit position where it starts? The key is the 0xAAAA pattern, which either shows up as 0xAAAA in the MFM bit stream (if the header starts at an even bit position), or as 0x5555 (if it starts at an odd bit position).

The first step to decoding is to find out where the 0xAAAA bit pattern shows up. Because it covers 32 bits, you should be able to find it by looking for any two consecutive bytes which either read as 0xAA or as 0x55.
...

thanks. will try.

I've tried encoding 'DOS' to MFM data (after splitting to odd and even bits?bytes?), but can't find the bit pattern in input.
« Last Edit: December 19, 2017, 09:20:34 AM by orange »
Better sorry than worry.
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #4 on: December 19, 2017, 01:32:03 PM »
ok, thanks.
finally found the problem.
I was using:
 $bitdata = unpack "b*",$data;
instead of
 $bitdata = unpack "B*",$data;

in perl :/
Better sorry than worry.
 

Offline orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #5 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 orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #6 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 orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #7 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 orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #8 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 orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #9 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 orangeTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2003
  • Posts: 2796
    • Show all replies
Re: MFM decode
« Reply #10 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.