Diff for /np2/fdd/sxsi.c between versions 1.7 and 1.13

version 1.7, 2004/01/22 01:10:04 version 1.13, 2005/02/07 14:46:09
Line 7 Line 7
 #include        "sxsi.h"  #include        "sxsi.h"
   
   
 static const char sig_vhd[] = "VHD";  const char sig_vhd[8] = "VHD1.00";
   const char sig_nhd[15] = "T98HDDIMAGE.R0";
 static const _SXSIDEV defide = {615*33*8, 615, 256, 33, 8,  
                                                                 SXSITYPE_IDE | SXSITYPE_HDD, 256, 0, {0x00}};  
 static const _SXSIDEV defscsi = {40*16*32*8, 40*16, 256, 32, 8,  
                                                                 SXSITYPE_SCSI | SXSITYPE_HDD, 220, 0, {0x00}};  
   
 const SASIHDD sasihdd[7] = {  const SASIHDD sasihdd[7] = {
                                 {33, 4, 153},                   // 5MB                                  {33, 4, 153},                   // 5MB
Line 23  const SASIHDD sasihdd[7] = { Line 19  const SASIHDD sasihdd[7] = {
                                 {33, 6, 615},                   // 30MB                                  {33, 6, 615},                   // 30MB
                                 {33, 8, 615}};                  // 40MB                                  {33, 8, 615}};                  // 40MB
   
   #if 0
   static const _SXSIDEV defide = {615*33*8, 615, 256, 33, 8,
                                                                   SXSITYPE_IDE | SXSITYPE_HDD, 256, 0, {0x00}};
   static const _SXSIDEV defscsi = {40*16*32*8, 40*16, 256, 32, 8,
                                                                   SXSITYPE_SCSI | SXSITYPE_HDD, 220, 0, {0x00}};
   #endif
   
   
         _SXSIDEV        sxsi_dev[SASIHDD_MAX + SCSIHDD_MAX];          _SXSIDEV        sxsi_dev[SASIHDD_MAX + SCSIHDD_MAX];
   
   
Line 33  const SASIHDD *sasi; Line 37  const SASIHDD *sasi;
         UINT            i;          UINT            i;
   
         sasi = sasihdd;          sasi = sasihdd;
         for (i=0; i<sizeof(sasihdd)/sizeof(SASIHDD); i++) {          for (i=0; i<NELEMENTS(sasihdd); i++, sasi++) {
                 if ((sxsi->size == 256) &&                  if ((sxsi->size == 256) &&
                         (sxsi->sectors == sasi->sectors) &&                          (sxsi->sectors == sasi->sectors) &&
                         (sxsi->surfaces == sasi->surfaces) &&                          (sxsi->surfaces == sasi->surfaces) &&
Line 44  const SASIHDD *sasi; Line 48  const SASIHDD *sasi;
         }          }
 }  }
   
   
 // ----  // ----
   
 void sxsi_initialize(void) {  void sxsi_initialize(void) {
Line 51  void sxsi_initialize(void) { Line 56  void sxsi_initialize(void) {
         UINT    i;          UINT    i;
   
         ZeroMemory(sxsi_dev, sizeof(sxsi_dev));          ZeroMemory(sxsi_dev, sizeof(sxsi_dev));
         for (i=0; i<(sizeof(sxsi_dev)/sizeof(_SXSIDEV)); i++) {          for (i=0; i<NELEMENTS(sxsi_dev); i++) {
                 sxsi_dev[i].fh = (long)FILEH_INVALID;                  sxsi_dev[i].fh = (long)FILEH_INVALID;
         }          }
 }  }
Line 61  SXSIDEV sxsi_getptr(REG8 drv) { Line 66  SXSIDEV sxsi_getptr(REG8 drv) {
         UINT    num;          UINT    num;
   
         num = drv & 0x0f;          num = drv & 0x0f;
         if (!(drv & 0x20)) {                    // SASI or IDE          if (!(drv & 0x20)) {                                    // SASI or IDE
                 if (num < 2) {                  if (num < SASIHDD_MAX) {
                         return(sxsi_dev + num);                          return(sxsi_dev + num);
                 }                  }
         }          }
   #if defined(SUPPORT_SCSI)
         else {          else {
                 if (num < 4) {                          // SCSI                  if (num < SCSIHDD_MAX) {                        // SCSI
                         return(sxsi_dev + SASIHDD_MAX + num);                          return(sxsi_dev + SASIHDD_MAX + num);
                 }                  }
         }          }
   #endif
         return(NULL);          return(NULL);
 }  }
   
Line 87  const char *sxsi_getname(REG8 drv) { Line 94  const char *sxsi_getname(REG8 drv) {
   
 BOOL sxsi_hddopen(REG8 drv, const char *file) {  BOOL sxsi_hddopen(REG8 drv, const char *file) {
   
         SXSIDEV         sxsi;          SXSIDEV sxsi;
 const char              *ext;          FILEH   fh;
         FILEH           fh;  const char      *ext;
         THDHDR          thd;          UINT16  type;
         HDIHDR          hdi;          long    totals;
         VHDHDR          vhd;          UINT32  headersize;
           UINT32  surfaces;
           UINT32  cylinders;
           UINT32  sectors;
           UINT32  size;
   
         if ((file == NULL) || (file[0] == '\0')) {          if ((file == NULL) || (file[0] == '\0')) {
                 goto sxsiope_err;                  goto sxsiope_err1;
         }          }
         sxsi = sxsi_getptr(drv);          sxsi = sxsi_getptr(drv);
         if (sxsi == NULL) {          if (sxsi == NULL) {
                 goto sxsiope_err;                  goto sxsiope_err1;
           }
           fh = file_open(file);
           if (fh == FILEH_INVALID) {
                   goto sxsiope_err1;
         }          }
         ext = file_getext((char *)file);          ext = file_getext((char *)file);
           type = SXSITYPE_HDD;
         if ((!file_cmpname(ext, str_thd)) && (!(drv & 0x20))) {          if ((!file_cmpname(ext, str_thd)) && (!(drv & 0x20))) {
                 fh = file_open(file);                                                           // T98 HDD (IDE)                  THDHDR thd;                                             // T98 HDD (IDE)
                 if (fh == FILEH_INVALID) {                  if (file_read(fh, &thd, sizeof(thd)) != sizeof(thd)) {
                         goto sxsiope_err;                          goto sxsiope_err2;
                 }                  }
                 if (file_read(fh, &thd, sizeof(thd)) == sizeof(thd)) {                  headersize = 256;
                         *sxsi = defide;                  surfaces = 8;
                         sxsi->cylinders = LOADINTELWORD(thd.cylinders);                  cylinders = LOADINTELWORD(thd.cylinders);
                         sxsi->totals = sxsi->cylinders * sxsi->sectors * sxsi->surfaces;                  sectors = 33;
                         sasihddcheck(sxsi);                  size = 256;
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));                  totals = cylinders * sectors * surfaces;
                         sxsi->fh = (long)fh;          }
                         return(SUCCESS);          else if ((!file_cmpname(ext, str_nhd)) && (!(drv & 0x20))) {
                 }                  NHDHDR nhd;                                             // T98Next HDD (IDE)
                 file_close(fh);                  if ((file_read(fh, &nhd, sizeof(nhd)) != sizeof(nhd)) ||
                           (memcmp(nhd.sig, sig_nhd, 15))) {
                           goto sxsiope_err2;
                   }
                   headersize = LOADINTELDWORD(nhd.headersize);
                   surfaces = LOADINTELWORD(nhd.surfaces);
                   cylinders = LOADINTELDWORD(nhd.cylinders);
                   sectors = LOADINTELWORD(nhd.sectors);
                   size = LOADINTELWORD(nhd.sectorsize);
                   totals = cylinders * sectors * surfaces;
         }          }
         else if ((!file_cmpname(ext, str_hdi)) && (!(drv & 0x20))) {          else if ((!file_cmpname(ext, str_hdi)) && (!(drv & 0x20))) {
                 fh = file_open(file);                           // ANEX86 HDD (SASI) thanx Mamiya                  HDIHDR hdi;                                             // ANEX86 HDD (SASI) thanx Mamiya
                 if (fh == FILEH_INVALID) {                  if (file_read(fh, &hdi, sizeof(hdi)) != sizeof(hdi)) {
                         goto sxsiope_err;                          goto sxsiope_err2;
                 }                  }
                 if (file_read(fh, &hdi, sizeof(hdi)) == sizeof(hdi)) {                  headersize = LOADINTELDWORD(hdi.headersize);
                         *sxsi = defide;                  surfaces = LOADINTELDWORD(hdi.surfaces);
                         sxsi->size = LOADINTELWORD(hdi.sectorsize);                  cylinders = LOADINTELDWORD(hdi.cylinders);
                         sxsi->headersize = LOADINTELDWORD(hdi.headersize);                  sectors = LOADINTELDWORD(hdi.sectors);
                         sxsi->cylinders = LOADINTELWORD(hdi.cylinders);                  size = LOADINTELDWORD(hdi.sectorsize);
                         sxsi->surfaces = hdi.surfaces[0];                  totals = cylinders * sectors * surfaces;
                         sxsi->sectors = hdi.sectors[0];  
                         sxsi->totals = sxsi->cylinders * sxsi->sectors * sxsi->surfaces;  
                         sasihddcheck(sxsi);  
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));  
                         sxsi->fh = (long)fh;  
                         return(SUCCESS);  
                 }  
                 file_close(fh);  
         }          }
         else if ((!file_cmpname(ext, str_hdd)) && (drv & 0x20)) {          else if ((!file_cmpname(ext, str_hdd)) && (drv & 0x20)) {
                 TRACEOUT(("insert hdd - %.2x", drv));                  VHDHDR vhd;                                             // Virtual98 HDD (SCSI)
                 fh = file_open(file);                                           // Virtual98 HDD (SCSI)                  if ((file_read(fh, &vhd, sizeof(vhd)) != sizeof(vhd)) ||
                 if (fh == FILEH_INVALID) {                          (memcmp(vhd.sig, sig_vhd, 5))) {
                         goto sxsiope_err;                          goto sxsiope_err2;
                 }                  }
                 if ((file_read(fh, &vhd, sizeof(vhd)) == sizeof(vhd)) &&                  headersize = sizeof(vhd);
                         (!memcmp(vhd.sig, sig_vhd, 3))) {                  surfaces = vhd.surfaces;
                         *sxsi = defscsi;                  cylinders = LOADINTELWORD(vhd.cylinders);
                         sxsi->totals = (SINT32)LOADINTELDWORD(vhd.totals);                  sectors = vhd.sectors;
                         sxsi->cylinders = LOADINTELWORD(vhd.cylinders);                  size = LOADINTELWORD(vhd.sectorsize);
                         sxsi->size = LOADINTELWORD(vhd.sectorsize);                  totals = (SINT32)LOADINTELDWORD(vhd.totals);
                         sxsi->sectors = vhd.sectors;          }
                         sxsi->surfaces = vhd.surfaces;          else {
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));                  goto sxsiope_err2;
                         sxsi->fh = (long)fh;  
                         TRACEOUT(("success"));  
                         return(SUCCESS);  
                 }  
                 file_close(fh);  
         }          }
   
 sxsiope_err:          // フォーマット確認〜
           if ((surfaces == 0) || (surfaces >= 256) ||
                   (cylinders == 0) || (cylinders >= 65536) ||
                   (sectors == 0) || (sectors >= 256) ||
                   (size == 0) || ((size & (size - 1)) != 0)) {
                   goto sxsiope_err2;
           }
           if (!(drv & 0x20)) {
                   type |= SXSITYPE_IDE;
           }
           else {
                   type |= SXSITYPE_SCSI;
                   if (!(size & 0x700)) {                  // not 256,512,1024
                           goto sxsiope_err2;
                   }
           }
           sxsi->totals = totals;
           sxsi->cylinders = (UINT16)cylinders;
           sxsi->size = (UINT16)size;
           sxsi->sectors = (UINT8)sectors;
           sxsi->surfaces = (UINT8)surfaces;
           sxsi->type = type;
           sxsi->headersize = headersize;
           sxsi->fh = (long)fh;
           file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));
           if (type == (SXSITYPE_IDE | SXSITYPE_HDD)) {
                   sasihddcheck(sxsi);
           }
           return(SUCCESS);
   
   sxsiope_err2:
           file_close(fh);
   
   sxsiope_err1:
         return(FAILURE);          return(FAILURE);
 }  }
   
Line 176  void sxsi_open(void) { Line 221  void sxsi_open(void) {
                         drv++;                          drv++;
                 }                  }
         }          }
   #if defined(SUPPORT_SCSI)
         drv = 0x20;          drv = 0x20;
         for (i=0; i<4; i++) {          for (i=0; i<4; i++) {
                 if (sxsi_hddopen(drv, np2cfg.scsihdd[i]) == SUCCESS) {                  if (sxsi_hddopen(drv, np2cfg.scsihdd[i]) == SUCCESS) {
                         drv++;                          drv++;
                 }                  }
         }          }
   #endif
 }  }
   
 void sxsi_flash(void) {  void sxsi_flash(void) {
Line 190  void sxsi_flash(void) { Line 237  void sxsi_flash(void) {
         SXSIDEV sxsiterm;          SXSIDEV sxsiterm;
   
         sxsi = sxsi_dev;          sxsi = sxsi_dev;
         sxsiterm = sxsi + (sizeof(sxsi_dev)/sizeof(_SXSIDEV));          sxsiterm = sxsi + NELEMENTS(sxsi_dev);
         while(sxsi < sxsiterm) {          while(sxsi < sxsiterm) {
                 if ((FILEH)sxsi->fh != FILEH_INVALID) {                  if ((FILEH)sxsi->fh != FILEH_INVALID) {
                         file_close((FILEH)sxsi->fh);                          file_close((FILEH)sxsi->fh);
Line 206  void sxsi_trash(void) { Line 253  void sxsi_trash(void) {
         SXSIDEV sxsiterm;          SXSIDEV sxsiterm;
   
         sxsi = sxsi_dev;          sxsi = sxsi_dev;
         sxsiterm = sxsi + (sizeof(sxsi_dev)/sizeof(_SXSIDEV));          sxsiterm = sxsi + NELEMENTS(sxsi_dev);
         while(sxsi < sxsiterm) {          while(sxsi < sxsiterm) {
                 if ((FILEH)sxsi->fh != FILEH_INVALID) {                  if ((FILEH)sxsi->fh != FILEH_INVALID) {
                         file_close((FILEH)sxsi->fh);                          file_close((FILEH)sxsi->fh);
                         sxsi->fh = (long)FILEH_INVALID;  
                 }                  }
                 sxsi->fname[0] = '\0';                  ZeroMemory(sxsi, sizeof(_SXSIDEV));
                   sxsi->fh = (long)FILEH_INVALID;
                 sxsi++;                  sxsi++;
         }          }
 }  }
   
 static SXSIDEV getdrive(REG8 drv) {  static SXSIDEV getdrive(REG8 drv) {
   
         UINT    num;  
         SXSIDEV ret;          SXSIDEV ret;
   
         num = drv & 0x0f;          ret = sxsi_getptr(drv);
         if (num >= 2) {          if ((ret == NULL) || (ret->fname[0] == '\0')) {
                 return(NULL);  
         }  
         num += (drv & 0x20) >> 4;  
         ret = sxsi_dev + num;  
         if (ret->fname[0] == '\0') {  
                 return(NULL);                  return(NULL);
         }          }
         if ((FILEH)ret->fh == FILEH_INVALID) {          if ((FILEH)ret->fh == FILEH_INVALID) {
Line 242  static SXSIDEV getdrive(REG8 drv) { Line 283  static SXSIDEV getdrive(REG8 drv) {
         return(ret);          return(ret);
 }  }
   
 REG8 sxsi_read(REG8 drv, long pos, BYTE *buf, UINT size) {  BOOL sxsi_issasi(void) {
   
           REG8    drv;
           SXSIDEV sxsi;
           BOOL    ret;
           UINT    sxsiif;
   
           ret = FALSE;
           for (drv=0x00; drv<0x04; drv++) {
                   sxsi = sxsi_getptr(drv);
                   if (sxsi) {
                           sxsiif = sxsi->type & SXSITYPE_IFMASK;
                           if (sxsiif == SXSITYPE_SASI) {
                                   ret = TRUE;
                           }
                           else if (sxsiif == SXSITYPE_IDE) {
                                   ret = FALSE;
                                   break;
                           }
                   }
           }
           return(ret);
   }
   
   BOOL sxsi_isscsi(void) {
   
           REG8    drv;
           SXSIDEV sxsi;
   
           for (drv=0x20; drv<0x28; drv++) {
                   sxsi = sxsi_getptr(drv);
                   if ((sxsi) && (sxsi->type)) {
                           return(TRUE);
                   }
           }
           return(FALSE);
   }
   
   BOOL sxsi_iside(void) {
   
           REG8    drv;
           SXSIDEV sxsi;
   
           for (drv=0x00; drv<0x04; drv++) {
                   sxsi = sxsi_getptr(drv);
                   if ((sxsi) && (sxsi->type)) {
                           return(TRUE);
                   }
           }
           return(FALSE);
   }
   
   REG8 sxsi_read(REG8 drv, long pos, UINT8 *buf, UINT size) {
   
 const _SXSIDEV  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
Line 252  const _SXSIDEV *sxsi; Line 345  const _SXSIDEV *sxsi;
         if (sxsi == NULL) {          if (sxsi == NULL) {
                 return(0x60);                  return(0x60);
         }          }
         pos = pos * sxsi->size + sxsi->headersize;          if ((pos < 0) || (pos >= sxsi->totals)) {
         r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);  
         if (r == -1) {  
                 return(0x40);                  return(0x40);
         }          }
           pos = pos * sxsi->size + sxsi->headersize;
           r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);
         if (pos != r) {          if (pos != r) {
                 return(0xd0);                  return(0xd0);
         }          }
Line 272  const _SXSIDEV *sxsi; Line 365  const _SXSIDEV *sxsi;
         return(0x00);          return(0x00);
 }  }
   
 REG8 sxsi_write(REG8 drv, long pos, const BYTE *buf, UINT size) {  REG8 sxsi_write(REG8 drv, long pos, const UINT8 *buf, UINT size) {
   
 const _SXSIDEV  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
Line 282  const _SXSIDEV *sxsi; Line 375  const _SXSIDEV *sxsi;
         if (sxsi == NULL) {          if (sxsi == NULL) {
                 return(0x60);                  return(0x60);
         }          }
         pos = pos * sxsi->size + sxsi->headersize;          if ((pos < 0) || (pos >= sxsi->totals)) {
         r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);  
         if (r == -1) {  
                 return(0x40);                  return(0x40);
         }          }
           pos = pos * sxsi->size + sxsi->headersize;
           r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);
         if (pos != r) {          if (pos != r) {
                 return(0xd0);                  return(0xd0);
         }          }
Line 307  REG8 sxsi_format(REG8 drv, long pos) { Line 400  REG8 sxsi_format(REG8 drv, long pos) {
 const _SXSIDEV  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
         UINT16          i;          UINT16          i;
         BYTE            work[256];          UINT8           work[256];
         UINT            size;          UINT            size;
         UINT            wsize;          UINT            wsize;
   
Line 315  const _SXSIDEV *sxsi; Line 408  const _SXSIDEV *sxsi;
         if (sxsi == NULL) {          if (sxsi == NULL) {
                 return(0x60);                  return(0x60);
         }          }
         pos = pos * sxsi->size + sxsi->headersize;          if ((pos < 0) || (pos >= sxsi->totals)) {
         r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);  
         if (r == -1) {  
                 return(0x40);                  return(0x40);
         }          }
           pos = pos * sxsi->size + sxsi->headersize;
           r = file_seek((FILEH)sxsi->fh, pos, FSEEK_SET);
         if (pos != r) {          if (pos != r) {
                 return(0xd0);                  return(0xd0);
         }          }

Removed from v.1.7  
changed lines
  Added in v.1.13


RetroPC.NET-CVS <cvs@retropc.net>