--- e:\uae\uae-0.8.17\src\disk.c	Sat Jul 28 16:44:50 2001
+++ e:\projects\WinUAE0817JIT\src\disk.c	Fri Sep 21 20:13:34 2001
@@ -32,6 +32,7 @@
 #include "osemu.h"
 #include "execlib.h"
 #include "savestate.h"
+#include "fdi2raw.h"
 
 #define FLOPPY_GAP_LEN 360
 /* writable track length with normal 2us bitcell/300RPM motor */
@@ -75,7 +76,7 @@
 #define DRIVE_ID_35HD  0xAAAAAAAA
 #define DRIVE_ID_525DD 0x55555555 /* 40 track 5.25 drive , kickstart does not recognize this */
 
-typedef enum { ADF_NORMAL, ADF_EXT1, ADF_EXT2 } drive_filetype;
+typedef enum { ADF_NORMAL, ADF_EXT1, ADF_EXT2, ADF_FDI } drive_filetype;
 typedef struct {
     FILE *diskfile;
     drive_filetype filetype;
@@ -107,6 +108,7 @@
     int ddhd; /* 1=DD 2=HD */
     int drive_id_scnt; /* drive id shift counter */
     unsigned long drive_id; /* drive id to be reported */
+    FDI *fdi;
 } drive;
 
 static drive floppy[4];
@@ -210,7 +212,16 @@
     gui_filename (dnum, fname);
 
     fread (buffer, sizeof (char), 8, drv->diskfile);
-    if (strncmp ((char *) buffer, "UAE-1ADF", 8) == 0) {
+    if (drv->fdi = fdi2raw_header (drv->diskfile)) {
+	int len;
+	drv->num_tracks = fdi2raw_get_last_track (drv->fdi);
+	drv->filetype = ADF_FDI;
+	fdi2raw_read_track (drv->fdi, 0, &len);
+	drv->num_secs = 11;
+	if (len > 16000) drv->num_secs = 22;
+	drv->wrprot = 1;
+	
+    } else if (strncmp ((char *) buffer, "UAE-1ADF", 8) == 0) {
 	int offs;
 	int i;
 
@@ -404,7 +415,16 @@
     if (drv->buffered_cyl == drv->cyl && drv->buffered_side == side)
 	return;
 
-    if (ti->type == TRACK_AMIGADOS) {
+    if (drv->filetype == ADF_FDI) {
+	uae_u8 *data;
+	int i;
+	data = fdi2raw_read_track (drv->fdi, tr, &drv->tracklen);
+	for (i = 0; i < (drv->tracklen + 15) / 16; i++) {
+	    uae_u16 *mfm = drv->bigmfmbuf + i;
+	    mfm[0] = (data[0] << 8) | data[1];
+	    data += 2;
+	}
+    } else if (ti->type == TRACK_AMIGADOS) {
 	/* Normal AmigaDOS format track */
 	int sec;
 	drv->tracklen = (drv->num_secs * 544 + FLOPPY_GAP_LEN) * 2 * 8;
@@ -679,6 +699,9 @@
     case ADF_EXT1:
 	write_log ("writing to ADF_EXT1 not supported\n");
 	return;
+    case ADF_FDI:
+	write_log ("writing to ADF_FDI not supported\n");
+	return;
     case ADF_EXT2:
 	ret = drive_write_adf_amigados (drv);
 	if (ret) {
@@ -694,6 +717,9 @@
 {
     if (!drive_empty (drv))
 	zfile_close (drv->diskfile);
+    if (drv->fdi)
+	fdi2raw_header_free (drv->fdi);
+    drv->fdi = 0;
 
     drv->dskchange = 4;
     drv->dskchange_time = 20;
