OSDN Git Service

[VM][General] Merge Upstream 20180530.
[csp-qt/common_source_project-fm7.git] / source / src / vm / disk.cpp
index de7be05..5c20d6b 100644 (file)
@@ -115,10 +115,14 @@ void DISK::setup_fd_formats(void)
                type_m5 = true;
                nt = { MEDIA_TYPE_2D,  40, 2, 18,  256, MFM };  // 2D   360KB
        } else if(osd->check_feature(_T("_MZ80B")) || osd->check_feature(_T("_MZ2000")) ||
-                       osd->check_feature(_T("_MZ2200")) || osd->check_feature(_T("_MZ2500"))) {
+                         osd->check_feature(_T("_MZ2200")) || osd->check_feature(_T("_MZ2500"))) {
                checked = true;
                type_mz80b = true;
                nt = { MEDIA_TYPE_2DD, 80, 2, 16,  256, MFM };  // 2DD  640KB
+       } else if (osd->check_feature(_T("_YIS"))) {
+               checked = true;
+               type_yis = true;
+               nt = { MEDIA_TYPE_2DD,  80, 1, 16,  256, MFM }; // 1DD  320KB
        }
        if(osd->check_feature(_T("_FM7")) || osd->check_feature(_T("_FM8"))) {
                checked = false;
@@ -258,19 +262,140 @@ void DISK::open(const _TCHAR* file_path, int bank)
                        } catch(...) {
                                // failed to convert the disk image
                        }
-               } else if(check_file_extension(file_path, _T(".2d"))  && file_size.d == 40 * 2 * 16 * 256) {
-                       // 2d image for SHARP X1 series
+               } else if(check_file_extension(file_path, _T(".nfd"))) {
+                       // T98-NEXT nfd r0/r1 image for NEC PC-98x1 series
                        try {
-                               if(solid_to_d88(fio, MEDIA_TYPE_2D, 40, 2, 16, 256, true)) {
+                               if(nfdr0_to_d88(fio) || nfdr1_to_d88(fio)) {
+                                       inserted = changed = true;
+                                       my_stprintf_s(dest_path, _MAX_PATH, _T("%s.D88"), file_path);
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".fdi"))) {
+                       // Anex86 fdi image for NEC PC-98x1 series
+                       if(file_size.d == 4096 + 77 * 2 * 8 * 1024) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_2HD, 77, 2, 8, 1024, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       } else if(file_size.d == 4096 + 80 * 2 * 15 * 512) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_2HD, 80, 2, 15, 512, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       } else if(file_size.d == 4096 + 80 * 2 * 18 * 512) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_144, 80, 2, 18, 512, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       } else if(file_size.d == 4096 + 77 * 2 * 26 * 256) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_2HD, 77, 2, 26, 256, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       } else if(file_size.d == 4096 + 80 * 2 * 9 * 512) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_2DD, 80, 2, 9, 512, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       } else if(file_size.d == 4096 + 80 * 2 * 8 * 512) {
+                               try {
+                                       fio->Fread(fdi_header, 4096, 1);
+                                       if(solid_to_d88(fio, MEDIA_TYPE_2DD, 80, 2, 8, 512, true)) {
+                                               inserted = changed = is_solid_image = is_fdi_image = true;
+                                       }
+                               } catch(...) {
+                                       // failed to convert the disk image
+                               }
+                       }
+               } else if(check_file_extension(file_path, _T(".hdm")) && file_size.d == 77 * 2 * 8 * 1024) {
+                       // BKDSK hdm image for NEC PC-98x1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2HD, 77, 2, 8, 1024, true)) {
                                        inserted = changed = is_solid_image = true;
                                }
                        } catch(...) {
                                // failed to convert the disk image
                        }
-               } else if(check_file_extension(file_path, _T(".img"))  && file_size.d == 70 * 1 * 16 * 256) {
-                       // img image for SONY SMC-70/777 series
+               } else if(check_file_extension(file_path, _T(".hd5")) && file_size.d == 80 * 2 * 15 * 512) {
+                       // BKDSK hd5 image for NEC PC-98x1 series
                        try {
-                               if(solid_to_d88(fio, MEDIA_TYPE_2DD, 70, 1, 16, 256, true)) {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2HD, 80, 2, 15, 512, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".hd4")) && file_size.d == 80 * 2 * 18 * 512) {
+                       // BKDSK hd4 image for NEC PC-98x1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_144, 80, 2, 18, 512, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".hdb")) && file_size.d == 77 * 2 * 26 * 256) {
+                       // BKDSK hdb image for NEC PC-98x1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2HD, 77, 2, 26, 256, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".dd9")) && file_size.d == 80 * 2 * 9 * 512) {
+                       // BKDSK dd9 image for NEC PC-98x1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2DD, 80, 2, 9, 512, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".dd6")) && file_size.d == 80 * 2 * 8 * 512) {
+                       // BKDSK dd6 image for NEC PC-98x1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2DD, 80, 2, 8, 512, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".xdf")) && file_size.d == 77 * 2 * 8 * 1024) {
+                       // EX68 xdf image for SHARP X680x0 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2HD, 77, 2, 8, 1024, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
+               } else if(check_file_extension(file_path, _T(".2d"))  && file_size.d == 40 * 2 * 16 * 256) {
+                       // 2d image for SHARP X1 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2D, 40, 2, 16, 256, true)) {
                                        inserted = changed = is_solid_image = true;
                                }
                        } catch(...) {
@@ -285,23 +410,25 @@ void DISK::open(const _TCHAR* file_path, int bank)
                        } catch(...) {
                                // failed to convert the disk image
                        }
+               } else if(check_file_extension(file_path, _T(".img"))  && file_size.d == 70 * 1 * 16 * 256) {
+                       // img image for SONY SMC-70/777 series
+                       try {
+                               if(solid_to_d88(fio, MEDIA_TYPE_2DD, 70, 1, 16, 256, true)) {
+                                       inserted = changed = is_solid_image = true;
+                               }
+                       } catch(...) {
+                               // failed to convert the disk image
+                       }
                }
                if(!inserted) {
                        // check solid image file format
-                       bool is_fdi_tmp = check_file_extension(file_path, _T(".fdi"));
                        for(int i = 0;; i++) {
                                const fd_format_t *p = &fd_formats[i];
                                if(p->type == -1) {
                                        break;
                                }
-                               int len = p->ncyl * p->nside * p->nsec * p->size;
-                               // 4096 bytes: FDI header ???
-                               if(file_size.d == (uint32_t)(len + (is_fdi_tmp ? 4096 : 0))) {
+                               if(file_size.d == (uint32_t)(p->ncyl * p->nside * p->nsec * p->size)) {
                                        fio->Fseek(0, FILEIO_SEEK_SET);
-                                       if(is_fdi_tmp) {
-                                               is_fdi_image = true;
-                                               fio->Fread(fdi_header, 4096, 1);
-                                       }
                                        int type = p->type;
                                        int ncyl = p->ncyl;
                                        int nside = p->nside;
@@ -374,6 +501,24 @@ void DISK::open(const _TCHAR* file_path, int bank)
                        }
                }
                
+               // check two side
+               int valid_side = 0;
+               
+               for(int trk = 0; trk < 82; trk++) {
+                       for(int side = 0; side < 2; side++) {
+                               int trkside = trk * 2 + side;
+                               pair_t offset;
+                               offset.read_4bytes_le_from(buffer + 0x20 + trkside * 4);
+                               
+                               if(IS_VALID_TRACK(offset.d)) {
+                                       valid_side |= (1 << side);
+                               }
+                       }
+                       if(valid_side == 3) break;
+               }
+               // FIXME: unformat disk is recognized as two side
+               two_side = (valid_side != 1);
+               
                // fix write protect flag
                if(buffer[0x1a] != 0) {
                        buffer[0x1a] = 0x10;
@@ -392,15 +537,38 @@ void DISK::open(const _TCHAR* file_path, int bank)
                                // check first track
                                pair_t offset, sector_num, data_size;
                                offset.read_4bytes_le_from(buffer + 0x20);
+
                                if(IS_VALID_TRACK(offset.d)) {
                                        // check the sector (c,h,r,n) = (0,0,7,1) or (0,0,f7,2)
                                        uint8_t* t = buffer + offset.d;
                                        sector_num.read_2bytes_le_from(t + 4);
-                                       for(int i = 0; i < sector_num.sd; i++) {
+                                       for(int _i = 0; _i < sector_num.sd; _i++) {
                                                data_size.read_2bytes_le_from(t + 14);
                                                if(data_size.sd == 0x100 && t[0] == 0 && t[1] == 0 && t[2] == 7 && t[3] == 1) {
-                                                       static const uint8_t gambler[] = {0xb7, 0xde, 0xad, 0xdc, 0xdd, 0xcc, 0xde, 0xd7, 0xb1, 0x20, 0xbc, 0xde, 0xba, 0xc1, 0xad, 0xb3, 0xbc, 0xdd, 0xca};
-                                                       if(memcmp((void *)(t + 0x30), gambler, sizeof(gambler)) == 0) {
+                                                       /* Type 1: Sec07, +$50- "1989/09/12 ... "*/
+                                                       static const uint8_t gamblerfm_1[] = {
+                                                               0x31, 0x39, 0x38, 0x39, 0x2f, 0x30, 0x39, 0x2f,
+                                                               0x31, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                               0x28, 0x43, 0x29, 0x47, 0x41, 0x4d, 0x45, 0x41,
+                                                               0x52, 0x54, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00,
+                                                               0x20, 0x20, 0x20, 0x59, 0x45, 0x4c, 0x4c, 0x4f,
+                                                               0x57, 0x48, 0x4f, 0x52, 0x4e, 0x00, 0x00, 0x00,
+                                                               0x20, 0x20, 0x20, 0x4b, 0x4f, 0x55, 0x44, 0x41,
+                                                               0x4e, 0x53, 0x59, 0x41, 0x20, 0x59, 0x4f, 0x55,
+                                                               0x4e, 0x47, 0x2d, 0x4d, 0x41, 0x47, 0x41, 0x5a,
+                                                               0x49, 0x4e, 0x45, 0x00 
+                                                       };
+                                                       /* Type 2: Sec07, +$30- */
+                                                       static const uint8_t gamblerfm_2[] = {
+                                                               0xb7, 0xde, 0xad, 0xdc, 0xdd, 0xcc, 0xde, 0xd7,
+                                                               0xb1, 0x20, 0xbc, 0xde, 0xba, 0xc1, 0xad, 0xb3,
+                                                               0xbc, 0xdd, 0xca
+                                                       };
+                                                       if(memcmp((void *)(t + 0x50), gamblerfm_1, sizeof(gamblerfm_1)) == 0) {
+                                                               is_special_disk = SPECIAL_DISK_FM7_GAMBLER;
+                                                               break;
+                                                       }
+                                                       if(memcmp((void *)(t + 0x30), gamblerfm_2, sizeof(gamblerfm_2)) == 0) {
                                                                is_special_disk = SPECIAL_DISK_FM7_GAMBLER;
                                                                break;
                                                        }
@@ -444,8 +612,8 @@ void DISK::open(const _TCHAR* file_path, int bank)
                                                        if(memcmp((void *)(t + 0x10 + 0x60), xanadu2fm_d_1, sizeof(xanadu2fm_d_1)) == 0) {
                                                                if(memcmp((void *)(t + 0x10 + 0x70), xanadu2fm_d_2, sizeof(xanadu2fm_d_2)) == 0) {
                                                                        is_special_disk = SPECIAL_DISK_FM7_XANADU2_D;
+                                                                       break;
                                                                }
-                                                               break;
                                                        }
                                                } else if(data_size.sd == 0x100 && t[0] == 0 && t[1] == 0 && t[2] == 8 && t[3] == 1) {
                                                        // Xanadu 1
@@ -472,8 +640,8 @@ void DISK::open(const _TCHAR* file_path, int bank)
                                                        if(memcmp((void *)(t + 0x10 + 0), xanadu1fm_d_1, sizeof(xanadu1fm_d_1)) == 0) {
                                                                if(memcmp((void *)(t + 0x10 + 0xb0), xanadu1fm_d_2, sizeof(xanadu1fm_d_2)) == 0) {
                                                                        is_special_disk = SPECIAL_DISK_FM7_XANADU2_D; // Same issue as Xanadu2.
+                                                                       break;
                                                                }
-                                                               break;
                                                        }
                                                } else if(data_size.sd == 0x100 && t[0] == 0 && t[1] == 0 && t[2] == 1 && t[3] == 1) {
                                                        //$03 + $2D + "PSY-O-BLADE   Copyright 1988 by T&E SOFT Inc." + $B6 + $FD + $05
@@ -726,7 +894,7 @@ void DISK::close()
 //#ifdef _ANY2D88
 void DISK::save_as_d88(const _TCHAR* file_path)
 {
-#ifdef _ANY2D88
+//#ifdef _ANY2D88
        if(inserted) {
                FILEIO* fio = new FILEIO();
                if(fio->Fopen(file_path, FILEIO_WRITE_BINARY)) {
@@ -743,12 +911,27 @@ void DISK::save_as_d88(const _TCHAR* file_path)
                }
                delete fio;
        }
-#endif
+//#endif
 }
 //#endif
 
 bool DISK::get_track(int trk, int side)
 {
+       if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
+               if(trk >= 0) {
+                       if(trk & 1) {
+                               return false; // unformat
+                       }
+                       trk >>= 1;
+               }
+       } else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
+               if(trk >= 0) trk <<= 1;
+       }
+       return get_track_tmp(trk, side);
+}
+
+bool DISK::get_track_tmp(int trk, int side)
+{
        sector_size.sd = sector_num.sd = 0;
        invalid_format = false;
 //     no_skew = true;
@@ -895,9 +1078,24 @@ bool DISK::get_track(int trk, int side)
 
 bool DISK::make_track(int trk, int side)
 {
+       if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
+               if(trk >= 0) {
+                       if(trk & 1) {
+                               return false; // unformat
+                       }
+                       trk >>= 1;
+               }
+       } else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
+               if(trk >= 0) trk <<= 1;
+       }
+       return make_track_tmp(trk, side);
+}
+
+bool DISK::make_track_tmp(int trk, int side)
+{
        int track_size = get_track_size();
        
-       if(!get_track(trk, side)) {
+       if(!get_track_tmp(trk, side)) {
                // create a dummy track
                for(int i = 0; i < track_size; i++) {
                        track[i] = rand();
@@ -938,16 +1136,18 @@ bool DISK::make_track(int trk, int side)
                        if(p < track_size) track[p++] = 0x00;
                }
                // am1
+               uint16_t crc = 0xffff;
                for(int j = 0; j < am_size; j++) {
                        if(p < track_size) track[p++] = 0xa1;
+                       crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ 0xa1]);
                }
                if(p < track_size) track[p++] = 0xfe;
+               crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ 0xfe]);
                // id
                if(p < track_size) track[p++] = t[0];
                if(p < track_size) track[p++] = t[1];
                if(p < track_size) track[p++] = t[2];
                if(p < track_size) track[p++] = t[3];
-               uint16_t crc = 0;
                crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[0]]);
                crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[1]]);
                crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[2]]);
@@ -965,12 +1165,15 @@ bool DISK::make_track(int trk, int side)
                                if(p < track_size) track[p++] = 0x00;
                        }
                        // am2
+                       crc = 0xffff;
                        for(int j = 0; j < am_size; j++) {
                                if(p < track_size) track[p++] = 0xa1;
+                               crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ 0xa1]);
                        }
-                       if(p < track_size) track[p++] = (t[7] != 0) ? 0xf8 : 0xfb;
+                       uint8_t am2 = (t[7] != 0) ? 0xf8 : 0xfb;
+                       if(p < track_size) track[p++] = am2;
+                       crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ am2]);
                        // data
-                       crc = 0;
                        for(int j = 0; j < data_size.sd; j++) {
                                if(p < track_size) track[p++] = t[0x10 + j];
                                crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[0x10 + j]]);
@@ -985,6 +1188,21 @@ bool DISK::make_track(int trk, int side)
 
 bool DISK::get_sector(int trk, int side, int index)
 {
+       if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
+               if(trk >= 0) {
+                       if(trk & 1) {
+                               return false; // unformat
+                       }
+                       trk >>= 1;
+               }
+       } else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
+               if(trk >= 0) trk <<= 1;
+       }
+       return get_sector_tmp(trk, side, index);
+}
+
+bool DISK::get_sector_tmp(int trk, int side, int index)
+{
        sector_size.sd = sector_num.sd = 0;
        sector = NULL;
        
@@ -1030,18 +1248,23 @@ bool DISK::get_sector(int trk, int side, int index)
 void DISK::set_sector_info(uint8_t *t)
 {
        // header info
+       int am_size = track_mfm ? 3 : 0;
+       uint16_t crc = 0xffff;
+       for(int i = 0; i < am_size; i++) {
+               crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ 0xa1]);
+       }
+       crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ 0xfe]);
        id[0] = t[0];
        id[1] = t[1];
        id[2] = t[2];
        id[3] = t[3];
-       uint16_t crc = 0;
        crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[0]]);
        crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[1]]);
        crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[2]]);
        crc = (uint16_t)((crc << 8) ^ crc_table[(uint8_t)(crc >> 8) ^ t[3]]);
        id[4] = (crc >> 8) & 0xff;
        id[5] = (crc >> 0) & 0xff;
-       // http://www,gnu-darwin.or.jp/www001/src/ports/emulators/quasi88/work/quasi88-0.6.3/document/FORMAT.TXT
+       // http://www.gnu-darwin.or.jp/www001/src/ports/emulators/quasi88/work/quasi88-0.6.3/document/FORMAT.TXT
        // t[6]: 0x00 = double-density, 0x40 = single-density
        // t[7]: 0x00 = normal, 0x10 = deleted mark
        // t[8]: 0x00 = valid, 0x10 = valid (deleted data), 0xa0 = id crc error, 0xb0 = data crc error, 0xe0 = address mark missing, 0xf0 = data mark missing
@@ -1092,6 +1315,21 @@ void DISK::set_data_mark_missing()
 
 bool DISK::format_track(int trk, int side)
 {
+       if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
+               if(trk >= 0) {
+                       if(trk & 1) {
+                               return false; // unformat
+                       }
+                       trk >>= 1;
+               }
+       } else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
+               if(trk >= 0) trk <<= 1;
+       }
+       return format_track_tmp(trk, side);
+}
+
+bool DISK::format_track_tmp(int trk, int side)
+{
        // disk not inserted or invalid media type
        if(!(inserted && check_media_type())) {
                return false;
@@ -1223,7 +1461,18 @@ void DISK::trim_buffer()
        file_size.write_4bytes_le_to(tmp_buffer + 0x1c);
        
        memset(buffer, 0, sizeof(buffer));
-       memcpy(buffer, tmp_buffer, min(sizeof(buffer), file_size.d));
+       memcpy(buffer, tmp_buffer, min((unsigned int)sizeof(buffer), file_size.d));
+}
+
+int DISK::get_max_tracks()
+{
+       if(drive_type != DRIVE_TYPE_UNK) {
+               return (drive_type != DRIVE_TYPE_2D) ? 84 : 42;
+       } else if(inserted) {
+               return (media_type != MEDIA_TYPE_2D) ? 84 : 42;
+       } else {
+               return 84; // 2DD or 2HD
+       }
 }
 
 int DISK::get_rpm()
@@ -1239,7 +1488,9 @@ int DISK::get_rpm()
 
 int DISK::get_track_size()
 {
-       if(inserted) {
+       if(track_size != 0) {
+               return track_size;
+       } else if(inserted) {
                return media_type == MEDIA_TYPE_144 ? 12500 : media_type == MEDIA_TYPE_2HD ? 10410 : track_mfm ? 6250 : 3100;
        } else {
                return drive_type == DRIVE_TYPE_144 ? 12500 : drive_type == DRIVE_TYPE_2HD ? 10410 : drive_mfm ? 6250 : 3100;
@@ -1265,11 +1516,7 @@ bool DISK::check_media_type()
 {
        switch(drive_type) {
        case DRIVE_TYPE_2D:
-               if(type_fm77av_2dd) {
                        return (media_type == MEDIA_TYPE_2D || media_type == MEDIA_TYPE_2DD);
-               } else {
-                       return (media_type == MEDIA_TYPE_2D);
-               }
        case DRIVE_TYPE_2DD:
                return (media_type == MEDIA_TYPE_2D || media_type == MEDIA_TYPE_2DD);
        case DRIVE_TYPE_2HD:
@@ -2070,6 +2317,196 @@ bool DISK::cpdread_to_d88(FILEIO *fio)
        return true;
 }
 
+// nfd r0/r1 image decoder
+
+bool DISK::nfdr0_to_d88(FILEIO *fio)
+{
+       // from NFD r0\8c`\8e®\83t\83@\83C\83\8b\8d\\91¢\8ed\97l 2001/01/22 LED
+       typedef struct {
+           BYTE  C;                            // C \81i0xFF\82Ì\8e\9e\83Z\83N\83^\96³\82µ\81j
+           BYTE  H;                            // H
+           BYTE  R;                            // R
+           BYTE  N;                            // N
+           BYTE  flMFM;                        // 0:FM / 1:MFM
+           BYTE  flDDAM;                       // 0:DAM / 1:DDAM
+           BYTE  byStatus;                     // READ DATA(FDDBIOS)\82Ì\8c\8b\89Ê
+           BYTE  byST0;                        // READ DATA(FDDBIOS)\82Ì\8c\8b\89Ê ST0
+           BYTE  byST1;                        // READ DATA(FDDBIOS)\82Ì\8c\8b\89Ê ST1
+           BYTE  byST2;                        // READ DATA(FDDBIOS)\82Ì\8c\8b\89Ê ST2
+           BYTE  byPDA;                        // FDDBIOS\82Å\8eg\97p\82·\82é\83A\83h\83\8c\83X
+           char Reserve1[5];                   // \97\\96ñ
+       }NFD_SECT_ID,*LP_NFD_SECT_ID;
+       
+       typedef struct {
+           char  szFileID[15];                 // \8e¯\95ÊID "T98FDDIMAGE.R0"
+           char  Reserve1[1];                  // \97\\96ñ
+           char  szComment[0x100];             // \83C\83\81\81[\83W\83R\83\81\83\93\83g(ASCIIz)
+           DWORD dwHeadSize;                   // \83w\83b\83_\95\94\82Ì\83T\83C\83Y
+           BYTE  flProtect;                    // 0\88È\8aO : \83\89\83C\83g\83v\83\8d\83e\83N\83g
+           BYTE  byHead;                       // \83w\83b\83h\90\94
+           char  Reserve2[10];                 // \97\\96ñ
+           NFD_SECT_ID si[163][26];            // \83Z\83N\83^ID(\8cã\8fq)
+           char  Reserve3[0x10];               // \97\\96ñ
+       }NFD_FILE_HEAD,*LP_NFD_FILE_HEAD;
+       
+       // check nfd header
+       NFD_FILE_HEAD head;
+       
+       fio->Fseek(0, FILEIO_SEEK_SET);
+       fio->Fread(&head, sizeof(head), 1);
+       
+       if(strncmp(head.szFileID, "T98FDDIMAGE.R0", 14) != 0) {
+               return false;
+       }
+       fio->Fseek(head.dwHeadSize, FILEIO_SEEK_SET);
+       
+       // create d88 header
+       d88_hdr_t d88_hdr;
+       d88_sct_t d88_sct;
+       
+       memset(&d88_hdr, 0, sizeof(d88_hdr_t));
+       my_strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "NFD R0");
+       d88_hdr.protect = head.flProtect;
+       
+       file_size.d = 0;
+       COPYBUFFER(&d88_hdr, sizeof(d88_hdr_t));
+       
+       // create tracks
+       int trkptr = sizeof(d88_hdr_t);
+       
+       for(int c = 0; c < 163; c++) {
+               int nsec = 0;
+               
+               for(int s = 0; s < 26; s++) {
+                       if(head.si[c][s].C != 0xff) {
+                               nsec++;
+                       }
+               }
+               if(nsec) {
+                       d88_hdr.trkptr[c] = trkptr;
+                       
+                       // read sectors in this track
+                       for(int s = 0; s < 26; s++) {
+                               if(head.si[c][s].C != 0xff) {
+                                       // create d88 sector header
+                                       memset(&d88_sct, 0, sizeof(d88_sct_t));
+                                       d88_sct.c = head.si[c][s].C;
+                                       d88_sct.h = head.si[c][s].H;
+                                       d88_sct.r = head.si[c][s].R;
+                                       d88_sct.n = head.si[c][s].N;
+                                       d88_sct.nsec = nsec;
+                                       d88_sct.dens = head.si[c][s].flMFM ? 0 : 0x40;
+                                       d88_sct.del = head.si[c][s].flDDAM ? 0x10 : 0;
+                                       if(head.si[c][s].byST1 & 0x20) {
+                                               if(head.si[c][s].byST2 & 0x20) {
+                                                       d88_sct.stat = 0xb0; // data crc error
+                                               } else {
+                                                       d88_sct.stat = 0xa0; // id crc error
+                                               }
+                                       } else if(head.si[c][s].byST1 & 0x01) {
+                                               d88_sct.stat = 0xe0; // address mark missing
+                                       } else if(head.si[c][s].byST2 & 0x01) {
+                                               d88_sct.stat = 0xf0; // data mark missing
+                                       } else {
+                                               d88_sct.stat = d88_sct.del;
+                                       }
+                                       d88_sct.size = secsize[d88_sct.n & 3];
+                                       
+                                       // create sector image
+                                       uint8_t dst[16384];
+                                       memset(dst, 0xe5, sizeof(dst));
+                                       fio->Fread(dst, d88_sct.size, 1);
+                                       
+                                       // copy to d88
+                                       COPYBUFFER(&d88_sct, sizeof(d88_sct_t));
+                                       COPYBUFFER(dst, d88_sct.size);
+                                       trkptr += sizeof(d88_sct_t) + d88_sct.size;
+                                       
+                                       if(head.si[c][s].byPDA == 0x10) {
+                                               d88_hdr.type = MEDIA_TYPE_2DD;
+                                       } else {
+                                               d88_hdr.type = MEDIA_TYPE_2HD;
+                                       }
+                               }
+                       }
+               }
+       }
+       d88_hdr.size = trkptr;
+       memcpy(buffer, &d88_hdr, sizeof(d88_hdr_t));
+       return true;
+}
+
+bool DISK::nfdr1_to_d88(FILEIO *fio)
+{
+       // from NFD r1\8c`\8e®\83t\83@\83C\83\8b\8d\\91¢\8ed\97l 2001/09/14 LED
+       typedef struct {
+//         char szFileID[sizeof(NFD_FILE_ID1)];        /* \8e¯\95ÊID "T98FDDIMAGE.R1"  */
+//         char Reserv1[0x10-sizeof(NFD_FILE_ID1)];    /* \97\\94õ                     */
+           char  szFileID[15];                         /* \8e¯\95ÊID "T98FDDIMAGE.R1"  */
+           char  Reserve1[1];                          /* \97\\96ñ                     */
+           char szComment[0x100];                      /* \83R\83\81\83\93\83g                 */
+           DWORD dwHeadSize;                           /* \83w\83b\83_\82Ì\83T\83C\83Y           */
+           BYTE flProtect;                             /* \83\89\83C\83g\83v\83\8d\83e\83N\83g0\88È\8aO    */
+           BYTE byHead;                                /* \83w\83b\83h\90\94 1-2             */
+           char Reserv2[0x10-4-1-1];                   /* \97\\94õ                     */
+           DWORD dwTrackHead[164];                     /* \83g\83\89\83b\83NID\88Ê\92u           */
+           DWORD dwAddInfo;                            /* \92Ç\89Á\8fî\95ñ\83w\83b\83_\82Ì\83A\83h\83\8c\83X */
+           char Reserv3[0x10-4];                       /* \97\\94õ                     */
+       }NFD_FILE_HEAD1,*LP_NFD_FILE_HEAD1;
+       
+       typedef struct {
+           WORD wSector;                               /* \83Z\83N\83^ID\90\94               */
+           WORD wDiag;                                 /* \93Á\8eê ID\90\94                */
+           char Reserv1[0x10-4];                       /* \97\\94õ                     */
+       }NFD_TRACK_ID1,*LP_NFD_TRACK_ID1;
+       
+       typedef struct {
+           BYTE    C;                                  /* C                        */
+           BYTE    H;                                  /* H                        */
+           BYTE    R;                                  /* R                        */
+           BYTE    N;                                  /* N                        */
+           BYTE    flMFM;                              /* MFM(1)/FM(0)             */
+           BYTE    flDDAM;                             /* DDAM(1)/DAM(0)           */
+           BYTE    byStatus;                           /* READ DATA RESULT         */
+           BYTE    bySTS0;                             /* ST0                      */
+           BYTE    bySTS1;                             /* ST1                      */
+           BYTE    bySTS2;                             /* ST2                      */
+           BYTE    byRetry;                            /* RetryData\82È\82µ(0)\82 \82è(1-) */
+           BYTE    byPDA;                              /* PDA                      */
+           char Reserv1[0x10-12];                      /* \97\\94õ                     */
+       }NFD_SECT_ID1,*LP_NFD_SECT_ID1;
+       
+       typedef struct {
+           BYTE    Cmd;                                /* Command                  */
+           BYTE    C;                                  /* C                        */
+           BYTE    H;                                  /* H                        */
+           BYTE    R;                                  /* R                        */
+           BYTE    N;                                  /* N                        */
+           BYTE    byStatus;                           /* READ DATA RESULT         */
+           BYTE    bySTS0;                             /* ST0                      */
+           BYTE    bySTS1;                             /* ST1                      */
+           BYTE    bySTS2;                             /* ST2                      */
+           BYTE    byRetry;                            /* RetryData\82È\82µ(0)\82 \82è(1-) */
+           DWORD   dwDataLen;
+           BYTE    byPDA;                              /* PDA                      */
+           char Reserv1[0x10-15];                      /* \97\\94õ                     */
+       }NFD_DIAG_ID1,*LP_NFD_DIAG_ID1;
+       
+       // check nfd header
+       NFD_FILE_HEAD1 head;
+       
+       fio->Fseek(0, FILEIO_SEEK_SET);
+       fio->Fread(&head, sizeof(head), 1);
+       
+       if(strncmp(head.szFileID, "T98FDDIMAGE.R1", 14) != 0) {
+               return false;
+       }
+       fio->Fseek(head.dwHeadSize, FILEIO_SEEK_SET);
+       
+       // not implemented yet :-(
+       return false;
+}
+
 // solid image decoder
 
 bool DISK::solid_to_d88(FILEIO *fio, int type, int ncyl, int nside, int nsec, int size, bool mfm)
@@ -2144,106 +2581,175 @@ bool DISK::solid_to_d88(FILEIO *fio, int type, int ncyl, int nside, int nsec, in
        return true;
 }
 
-#define STATE_VERSION  13
+#define STATE_VERSION  14
+
+#include "../../statesub.h"
+#include "../../qt/gui/csp_logger.h"
 
+void DISK::decl_state(void *p)
+{
+       CSP_Logger *p_logger = (CSP_Logger *)p;
+       state_entry = new csp_state_utils(STATE_VERSION, drive_num, _T("FLOPPY_DISK"), p_logger);
+
+       DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+       DECL_STATE_ENTRY_STRING(orig_path, sizeof(orig_path) / sizeof(_TCHAR));
+       DECL_STATE_ENTRY_STRING(dest_path, sizeof(dest_path) / sizeof(_TCHAR));
+       
+       DECL_STATE_ENTRY_PAIR(file_size);
+       DECL_STATE_ENTRY_INT32(file_bank);
+       DECL_STATE_ENTRY_UINT32(orig_file_size);
+       DECL_STATE_ENTRY_UINT32(orig_crc32);
+       DECL_STATE_ENTRY_BOOL(trim_required);
+       DECL_STATE_ENTRY_BOOL(is_1dd_image);
+       DECL_STATE_ENTRY_BOOL(is_solid_image);
+       DECL_STATE_ENTRY_BOOL(is_fdi_image);
+       
+       DECL_STATE_ENTRY_1D_ARRAY(fdi_header, sizeof(fdi_header));
+       
+       DECL_STATE_ENTRY_INT32(solid_ncyl);
+       DECL_STATE_ENTRY_INT32(solid_nside);
+       DECL_STATE_ENTRY_INT32(solid_nsec);
+       DECL_STATE_ENTRY_INT32(solid_size);
+       DECL_STATE_ENTRY_BOOL(solid_mfm);
+       DECL_STATE_ENTRY_BOOL(inserted);
+       DECL_STATE_ENTRY_BOOL(ejected);
+       DECL_STATE_ENTRY_BOOL(write_protected);
+       DECL_STATE_ENTRY_BOOL(changed);
+       DECL_STATE_ENTRY_UINT8(media_type);
+       DECL_STATE_ENTRY_INT32(is_special_disk);
+       
+       DECL_STATE_ENTRY_1D_ARRAY(track, sizeof(track));
+                                                         
+       DECL_STATE_ENTRY_PAIR(sector_num);
+       DECL_STATE_ENTRY_BOOL(track_mfm);
+       DECL_STATE_ENTRY_BOOL(invalid_format);
+//     DECL_STATE_ENTRY_BOOL(no_skew);
+       DECL_STATE_ENTRY_1D_ARRAY(sync_position, sizeof(sync_position) / sizeof(int));
+       DECL_STATE_ENTRY_1D_ARRAY(am1_position, sizeof(am1_position) / sizeof(int));
+       DECL_STATE_ENTRY_1D_ARRAY(id_position, sizeof(id_position) / sizeof(int));
+       DECL_STATE_ENTRY_1D_ARRAY(data_position, sizeof(data_position) / sizeof(int));
+//     DECL_STATE_ENTRY_INT32(gap3_size);
+       DECL_STATE_ENTRY_INT32(_tmp_sector_offset);
+       DECL_STATE_ENTRY_PAIR(sector_size);
+       
+       DECL_STATE_ENTRY_1D_ARRAY(id, sizeof(id));
+       DECL_STATE_ENTRY_UINT8(density);
+       DECL_STATE_ENTRY_BOOL(deleted);
+       DECL_STATE_ENTRY_BOOL(addr_crc_error);
+       DECL_STATE_ENTRY_BOOL(data_crc_error);
+       DECL_STATE_ENTRY_UINT8(drive_type);
+       DECL_STATE_ENTRY_INT32(drive_rpm);
+       DECL_STATE_ENTRY_BOOL(drive_mfm);
+}
 void DISK::save_state(FILEIO* state_fio)
 {
-       state_fio->FputUint32(STATE_VERSION);
-       
-       state_fio->Fwrite(buffer, sizeof(buffer), 1);
-       state_fio->Fwrite(orig_path, sizeof(orig_path), 1);
-       state_fio->Fwrite(dest_path, sizeof(dest_path), 1);
-       state_fio->FputUint32(file_size.d);
-       state_fio->FputInt32(file_bank);
-       state_fio->FputUint32(orig_file_size);
-       state_fio->FputUint32(orig_crc32);
-       state_fio->FputBool(trim_required);
-       state_fio->FputBool(is_1dd_image);
-       state_fio->FputBool(is_solid_image);
-       state_fio->FputBool(is_fdi_image);
-       state_fio->Fwrite(fdi_header, sizeof(fdi_header), 1);
-       state_fio->FputInt32(solid_ncyl);
-       state_fio->FputInt32(solid_nside);
-       state_fio->FputInt32(solid_nsec);
-       state_fio->FputInt32(solid_size);
-       state_fio->FputBool(solid_mfm);
-       state_fio->FputBool(inserted);
-       state_fio->FputBool(ejected);
-       state_fio->FputBool(write_protected);
-       state_fio->FputBool(changed);
-       state_fio->FputUint8(media_type);
-       state_fio->FputInt32(is_special_disk);
-       state_fio->Fwrite(track, sizeof(track), 1);
-       state_fio->FputInt32(sector_num.sd);
-       state_fio->FputBool(track_mfm);
-       state_fio->FputBool(invalid_format);
+       _tmp_sector_offset = (sector != NULL) ? (int)(sector - buffer) : -1;
+       
+       if(state_entry != NULL) {
+               state_entry->save_state(state_fio);
+       }
+       //state_fio->FputUint32(STATE_VERSION);
+       
+       //state_fio->Fwrite(buffer, sizeof(buffer), 1);
+       //state_fio->Fwrite(orig_path, sizeof(orig_path), 1);
+       //state_fio->Fwrite(dest_path, sizeof(dest_path), 1);
+       //state_fio->FputUint32(file_size.d);
+       //state_fio->FputInt32(file_bank);
+       //state_fio->FputUint32(orig_file_size);
+       //state_fio->FputUint32(orig_crc32);
+       //state_fio->FputBool(trim_required);
+       //state_fio->FputBool(is_1dd_image);
+       //state_fio->FputBool(is_solid_image);
+       //state_fio->FputBool(is_fdi_image);
+       //state_fio->Fwrite(fdi_header, sizeof(fdi_header), 1);
+       //state_fio->FputInt32(solid_ncyl);
+       //state_fio->FputInt32(solid_nside);
+       //state_fio->FputInt32(solid_nsec);
+       //state_fio->FputInt32(solid_size);
+       //state_fio->FputBool(solid_mfm);
+       //state_fio->FputBool(inserted);
+       //state_fio->FputBool(ejected);
+       //state_fio->FputBool(write_protected);
+       //state_fio->FputBool(changed);
+       //state_fio->FputUint8(media_type);
+       //state_fio->FputInt32(is_special_disk);
+       //state_fio->Fwrite(track, sizeof(track), 1);
+       //state_fio->FputInt32(sector_num.sd);
+       //state_fio->FputBool(track_mfm);
+       //state_fio->FputBool(invalid_format);
 //     state_fio->FputBool(no_skew);
-       state_fio->Fwrite(sync_position, sizeof(sync_position), 1);
-       state_fio->Fwrite(am1_position, sizeof(am1_position), 1);
-       state_fio->Fwrite(id_position, sizeof(id_position), 1);
-       state_fio->Fwrite(data_position, sizeof(data_position), 1);
+       //state_fio->Fwrite(sync_position, sizeof(sync_position), 1);
+       //state_fio->Fwrite(am1_position, sizeof(am1_position), 1);
+       //state_fio->Fwrite(id_position, sizeof(id_position), 1);
+       //state_fio->Fwrite(data_position, sizeof(data_position), 1);
 //     state_fio->FputInt32(gap3_size);
-       state_fio->FputInt32(sector ? (int)(sector - buffer) : -1);
-       state_fio->FputInt32(sector_size.sd);
-       state_fio->Fwrite(id, sizeof(id), 1);
-       state_fio->FputUint8(density);
-       state_fio->FputBool(deleted);
-       state_fio->FputBool(addr_crc_error);
-       state_fio->FputBool(data_crc_error);
-       state_fio->FputUint8(drive_type);
-       state_fio->FputInt32(drive_rpm);
-       state_fio->FputBool(drive_mfm);
+       //state_fio->FputInt32(sector ? (int)(sector - buffer) : -1);
+       //state_fio->FputInt32(sector_size.sd);
+       //state_fio->Fwrite(id, sizeof(id), 1);
+       //state_fio->FputUint8(density);
+       //state_fio->FputBool(deleted);
+       //state_fio->FputBool(addr_crc_error);
+       //state_fio->FputBool(data_crc_error);
+       //state_fio->FputUint8(drive_type);
+       //state_fio->FputInt32(drive_rpm);
+       //state_fio->FputBool(drive_mfm);
 }
 
 bool DISK::load_state(FILEIO* state_fio)
 {
-       if(state_fio->FgetUint32() != STATE_VERSION) {
-               return false;
-       }
-       state_fio->Fread(buffer, sizeof(buffer), 1);
-       state_fio->Fread(orig_path, sizeof(orig_path), 1);
-       state_fio->Fread(dest_path, sizeof(dest_path), 1);
-       file_size.d = state_fio->FgetUint32();
-       file_bank = state_fio->FgetInt32();
-       orig_file_size = state_fio->FgetUint32();
-       orig_crc32 = state_fio->FgetUint32();
-       trim_required = state_fio->FgetBool();
-       is_1dd_image = state_fio->FgetBool();
-       is_solid_image = state_fio->FgetBool();
-       is_fdi_image = state_fio->FgetBool();
-       state_fio->Fread(fdi_header, sizeof(fdi_header), 1);
-       solid_ncyl = state_fio->FgetInt32();
-       solid_nside = state_fio->FgetInt32();
-       solid_nsec = state_fio->FgetInt32();
-       solid_size = state_fio->FgetInt32();
-       solid_mfm = state_fio->FgetBool();
-       inserted = state_fio->FgetBool();
-       ejected = state_fio->FgetBool();
-       write_protected = state_fio->FgetBool();
-       changed = state_fio->FgetBool();
-       media_type = state_fio->FgetUint8();
-       is_special_disk = state_fio->FgetInt32();
-       state_fio->Fread(track, sizeof(track), 1);
-       sector_num.sd = state_fio->FgetInt32();
-       track_mfm = state_fio->FgetBool();
-       invalid_format = state_fio->FgetBool();
+       bool mb = false;
+       if(state_entry != NULL) {
+               mb = state_entry->load_state(state_fio);
+       }
+       if(!mb) return false;
+       //if(state_fio->FgetUint32() != STATE_VERSION) {
+       //      return false;
+       //}
+       //state_fio->Fread(buffer, sizeof(buffer), 1);
+       //state_fio->Fread(orig_path, sizeof(orig_path), 1);
+       //state_fio->Fread(dest_path, sizeof(dest_path), 1);
+       //file_size.d = state_fio->FgetUint32();
+       //file_bank = state_fio->FgetInt32();
+       //orig_file_size = state_fio->FgetUint32();
+       //orig_crc32 = state_fio->FgetUint32();
+       //trim_required = state_fio->FgetBool();
+       //is_1dd_image = state_fio->FgetBool();
+       //is_solid_image = state_fio->FgetBool();
+       //is_fdi_image = state_fio->FgetBool();
+       //state_fio->Fread(fdi_header, sizeof(fdi_header), 1);
+       //solid_ncyl = state_fio->FgetInt32();
+       //solid_nside = state_fio->FgetInt32();
+       //solid_nsec = state_fio->FgetInt32();
+       //solid_size = state_fio->FgetInt32();
+       //solid_mfm = state_fio->FgetBool();
+       //inserted = state_fio->FgetBool();
+       //ejected = state_fio->FgetBool();
+       //write_protected = state_fio->FgetBool();
+       //changed = state_fio->FgetBool();
+       //media_type = state_fio->FgetUint8();
+       //is_special_disk = state_fio->FgetInt32();
+       //state_fio->Fread(track, sizeof(track), 1);
+       //sector_num.sd = state_fio->FgetInt32();
+       //track_mfm = state_fio->FgetBool();
+       //invalid_format = state_fio->FgetBool();
 //     no_skew = state_fio->FgetBool();
-       state_fio->Fread(sync_position, sizeof(sync_position), 1);
-       state_fio->Fread(am1_position, sizeof(am1_position), 1);
-       state_fio->Fread(id_position, sizeof(id_position), 1);
-       state_fio->Fread(data_position, sizeof(data_position), 1);
+       //state_fio->Fread(sync_position, sizeof(sync_position), 1);
+       //state_fio->Fread(am1_position, sizeof(am1_position), 1);
+       //state_fio->Fread(id_position, sizeof(id_position), 1);
+       //state_fio->Fread(data_position, sizeof(data_position), 1);
 //     gap3_size = state_fio->FgetInt32();
-       int offset = state_fio->FgetInt32();
-       sector = (offset != -1) ? buffer + offset : NULL;
-       sector_size.sd = state_fio->FgetInt32();
-       state_fio->Fread(id, sizeof(id), 1);
-       density = state_fio->FgetUint8();
-       deleted = state_fio->FgetBool();
-       addr_crc_error = state_fio->FgetBool();
-       data_crc_error = state_fio->FgetBool();
-       drive_type = state_fio->FgetUint8();
-       drive_rpm = state_fio->FgetInt32();
-       drive_mfm = state_fio->FgetBool();
+       //int offset = state_fio->FgetInt32();
+       //sector = (offset != -1) ? buffer + offset : NULL;
+       //sector_size.sd = state_fio->FgetInt32();
+       //state_fio->Fread(id, sizeof(id), 1);
+       //density = state_fio->FgetUint8();
+       //deleted = state_fio->FgetBool();
+       //addr_crc_error = state_fio->FgetBool();
+       //data_crc_error = state_fio->FgetBool();
+       //drive_type = state_fio->FgetUint8();
+       //drive_rpm = state_fio->FgetInt32();
+       //drive_mfm = state_fio->FgetBool();
+       sector = (_tmp_sector_offset != -1) ? (buffer + _tmp_sector_offset) : NULL;
        return true;
 }