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

version 1.2, 2003/10/18 01:21:58 version 1.7, 2004/01/22 01:10:04
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
   #include        "strres.h"
 #include        "dosio.h"  #include        "dosio.h"
   #include        "sysmng.h"
   #include        "cpucore.h"
 #include        "pccore.h"  #include        "pccore.h"
 #include        "sxsi.h"  #include        "sxsi.h"
   
   
 typedef struct {  static const char sig_vhd[] = "VHD";
         char    vhd[3];  
         char    ver[4];  
         char    delimita;  
         char    comment[128];  
         BYTE    padding[4];  
         BYTE    mbsize[2];  
         BYTE    sectorsize[2];  
         BYTE    sectors;  
         BYTE    surfaces;  
         BYTE    tracks[2];  
         BYTE    totals[4];  
 } V98SCSIHDR;  
   
 typedef struct {  
         BYTE    tracks[2];  
 } THDHDR;  
   
 typedef struct {  
         BYTE    dummy[8];  
         BYTE    headersize[4];  
         BYTE    filesize[4];  
         BYTE    sectorsize[4];  
         BYTE    sectors[4];  
         BYTE    surfaces[4];  
         BYTE    tracks[4];  
 } HDIHDR;  
   
 static const _SXSIHDD defsasi = {615*33*8, 615, 256, 33, 8,  
                                                                                         HDDTYPE_SASI, 256, {0x00}};  
 static const _SXSIHDD defscsi = {40*16*32*8, 40*16, 256, 32, 8,  
                                                                                         HDDTYPE_SCSI, 220, {0x00}};  
   
   
         _SXSIHDD        sxsi_hd[4];  
   
   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] = {
                                   {33, 4, 153},                   // 5MB
                                   {33, 4, 310},                   // 10MB
                                   {33, 6, 310},                   // 15MB
                                   {33, 8, 310},                   // 20MB
                                   {33, 4, 615},                   // 20MB (not used!)
                                   {33, 6, 615},                   // 30MB
                                   {33, 8, 615}};                  // 40MB
   
           _SXSIDEV        sxsi_dev[SASIHDD_MAX + SCSIHDD_MAX];
   
   
   // SASI規格HDDかチェック
   static void sasihddcheck(SXSIDEV sxsi) {
   
   const SASIHDD   *sasi;
           UINT            i;
   
           sasi = sasihdd;
           for (i=0; i<sizeof(sasihdd)/sizeof(SASIHDD); i++) {
                   if ((sxsi->size == 256) &&
                           (sxsi->sectors == sasi->sectors) &&
                           (sxsi->surfaces == sasi->surfaces) &&
                           (sxsi->cylinders == sasi->cylinders)) {
                           sxsi->type = (UINT16)(SXSITYPE_SASI + (i << 8) + SXSITYPE_HDD);
                           break;
                   }
           }
   }
   
 // ----  // ----
   
Line 47  void sxsi_initialize(void) { Line 50  void sxsi_initialize(void) {
   
         UINT    i;          UINT    i;
   
         ZeroMemory(sxsi_hd, sizeof(sxsi_hd));          ZeroMemory(sxsi_dev, sizeof(sxsi_dev));
         for (i=0; i<(sizeof(sxsi_hd)/sizeof(_SXSIHDD)); i++) {          for (i=0; i<(sizeof(sxsi_dev)/sizeof(_SXSIDEV)); i++) {
                 sxsi_hd[i].fh = (void *)FILEH_INVALID;                  sxsi_dev[i].fh = (long)FILEH_INVALID;
         }          }
 }  }
   
 SXSIHDD sxsi_getptr(BYTE drv) {  SXSIDEV sxsi_getptr(REG8 drv) {
   
         UINT    num;          UINT    num;
   
         num = drv & 0x0f;          num = drv & 0x0f;
         if (num >= 2) {          if (!(drv & 0x20)) {                    // SASI or IDE
                 return(NULL);                  if (num < 2) {
                           return(sxsi_dev + num);
                   }
         }          }
         num += (drv & 0x20) >> 4;          else {
         return(sxsi_hd + num);                  if (num < 4) {                          // SCSI
                           return(sxsi_dev + SASIHDD_MAX + num);
                   }
           }
           return(NULL);
 }  }
   
 const char *sxsi_getname(BYTE drv) {  const char *sxsi_getname(REG8 drv) {
   
         SXSIHDD sxsi;          SXSIDEV sxsi;
   
         sxsi = sxsi_getptr(drv);          sxsi = sxsi_getptr(drv);
         if (sxsi) {          if (sxsi) {
Line 76  const char *sxsi_getname(BYTE drv) { Line 85  const char *sxsi_getname(BYTE drv) {
         return(NULL);          return(NULL);
 }  }
   
 BOOL sxsi_hddopen(BYTE drv, const char *file) {  BOOL sxsi_hddopen(REG8 drv, const char *file) {
   
         SXSIHDD         sxsi;          SXSIDEV         sxsi;
 const char              *ext;  const char              *ext;
         FILEH           fh;          FILEH           fh;
         THDHDR          thd;          THDHDR          thd;
         HDIHDR          hdi;          HDIHDR          hdi;
         V98SCSIHDR      v98;          VHDHDR          vhd;
   
         if ((file == NULL) || (file[0] == '\0')) {          if ((file == NULL) || (file[0] == '\0')) {
                 goto sxsiope_err;                  goto sxsiope_err;
Line 93  const char  *ext; Line 102  const char  *ext;
                 goto sxsiope_err;                  goto sxsiope_err;
         }          }
         ext = file_getext((char *)file);          ext = file_getext((char *)file);
         if ((!file_cmpname(ext, "thd")) && (!(drv & 0x20))) {          if ((!file_cmpname(ext, str_thd)) && (!(drv & 0x20))) {
                 fh = file_open(file);                                                           // T98 HDD (SASI)                  fh = file_open(file);                                                           // T98 HDD (IDE)
                 if (fh == FILEH_INVALID) {                  if (fh == FILEH_INVALID) {
                         goto sxsiope_err;                          goto sxsiope_err;
                 }                  }
                 if (file_read(fh, &thd, sizeof(thd)) == sizeof(thd)) {                  if (file_read(fh, &thd, sizeof(thd)) == sizeof(thd)) {
                         *sxsi = defsasi;                          *sxsi = defide;
                         sxsi->tracks = LOADINTELWORD(thd.tracks);                          sxsi->cylinders = LOADINTELWORD(thd.cylinders);
                         sxsi->totals = sxsi->tracks * sxsi->sectors * sxsi->surfaces;                          sxsi->totals = sxsi->cylinders * sxsi->sectors * sxsi->surfaces;
                           sasihddcheck(sxsi);
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));                          file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));
                         sxsi->fh = (void *)fh;                          sxsi->fh = (long)fh;
                         return(SUCCESS);                          return(SUCCESS);
                 }                  }
                 file_close(fh);                  file_close(fh);
         }          }
         else if ((!file_cmpname(ext, "hdi")) && (!(drv & 0x20))) {          else if ((!file_cmpname(ext, str_hdi)) && (!(drv & 0x20))) {
                 fh = file_open(file);                           // ANEX86 HDD (SASI) thanx Mamiya                  fh = file_open(file);                           // ANEX86 HDD (SASI) thanx Mamiya
                 if (fh == FILEH_INVALID) {                  if (fh == FILEH_INVALID) {
                         goto sxsiope_err;                          goto sxsiope_err;
                 }                  }
                 if (file_read(fh, &hdi, sizeof(hdi)) == sizeof(hdi)) {                  if (file_read(fh, &hdi, sizeof(hdi)) == sizeof(hdi)) {
                         *sxsi = defsasi;                          *sxsi = defide;
                         sxsi->size = LOADINTELWORD(hdi.sectorsize);                          sxsi->size = LOADINTELWORD(hdi.sectorsize);
                         sxsi->headersize = LOADINTELDWORD(hdi.headersize);                          sxsi->headersize = LOADINTELDWORD(hdi.headersize);
                         sxsi->tracks = LOADINTELWORD(hdi.tracks);                          sxsi->cylinders = LOADINTELWORD(hdi.cylinders);
                         sxsi->surfaces = hdi.surfaces[0];                          sxsi->surfaces = hdi.surfaces[0];
                         sxsi->sectors = hdi.sectors[0];                          sxsi->sectors = hdi.sectors[0];
                         sxsi->totals = sxsi->tracks * sxsi->sectors * sxsi->surfaces;                          sxsi->totals = sxsi->cylinders * sxsi->sectors * sxsi->surfaces;
                           sasihddcheck(sxsi);
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));                          file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));
                         sxsi->fh = (void *)fh;                          sxsi->fh = (long)fh;
                         return(SUCCESS);                          return(SUCCESS);
                 }                  }
                 file_close(fh);                  file_close(fh);
         }          }
         else if ((!file_cmpname(ext, "hdd")) && (drv & 0x20)) {          else if ((!file_cmpname(ext, str_hdd)) && (drv & 0x20)) {
                   TRACEOUT(("insert hdd - %.2x", drv));
                 fh = file_open(file);                                           // Virtual98 HDD (SCSI)                  fh = file_open(file);                                           // Virtual98 HDD (SCSI)
                 if (fh == FILEH_INVALID) {                  if (fh == FILEH_INVALID) {
                         goto sxsiope_err;                          goto sxsiope_err;
                 }                  }
                 if ((file_read(fh, &v98, sizeof(v98)) == sizeof(v98)) &&                  if ((file_read(fh, &vhd, sizeof(vhd)) == sizeof(vhd)) &&
                         (!memcmp(v98.vhd, "VHD", 3))) {                          (!memcmp(vhd.sig, sig_vhd, 3))) {
                         sxsi = &sxsi_hd[drv+2];  
                         *sxsi = defscsi;                          *sxsi = defscsi;
                         sxsi->totals = (SINT32)LOADINTELDWORD(v98.totals);                          sxsi->totals = (SINT32)LOADINTELDWORD(vhd.totals);
                         sxsi->tracks = LOADINTELWORD(v98.tracks);                          sxsi->cylinders = LOADINTELWORD(vhd.cylinders);
                         sxsi->size = LOADINTELWORD(v98.sectorsize);                          sxsi->size = LOADINTELWORD(vhd.sectorsize);
                         sxsi->sectors = v98.sectors;                          sxsi->sectors = vhd.sectors;
                         sxsi->surfaces = v98.surfaces;                          sxsi->surfaces = vhd.surfaces;
                         file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));                          file_cpyname(sxsi->fname, file, sizeof(sxsi->fname));
                         sxsi->fh = (void *)fh;                          sxsi->fh = (long)fh;
                           TRACEOUT(("success"));
                         return(SUCCESS);                          return(SUCCESS);
                 }                  }
                 file_close(fh);                  file_close(fh);
Line 155  sxsiope_err: Line 167  sxsiope_err:
 void sxsi_open(void) {  void sxsi_open(void) {
   
         int             i;          int             i;
         BYTE    sasi;          REG8    drv;
   
         sxsi_trash();          sxsi_trash();
         sasi = 0;          drv = 0;
         for (i=0; i<2; i++) {          for (i=0; i<2; i++) {
                 if (sxsi_hddopen(sasi, np2cfg.hddfile[i]) == SUCCESS) {                  if (sxsi_hddopen(drv, np2cfg.sasihdd[i]) == SUCCESS) {
                         sasi++;                          drv++;
                   }
           }
           drv = 0x20;
           for (i=0; i<4; i++) {
                   if (sxsi_hddopen(drv, np2cfg.scsihdd[i]) == SUCCESS) {
                           drv++;
                 }                  }
         }          }
 }  }
   
 void sxsi_flash(void) {  void sxsi_flash(void) {
   
         SXSIHDD sxsi;          SXSIDEV sxsi;
         SXSIHDD sxsiterm;          SXSIDEV sxsiterm;
   
         sxsi = sxsi_hd;          sxsi = sxsi_dev;
         sxsiterm = sxsi + (sizeof(sxsi_hd)/sizeof(_SXSIHDD));          sxsiterm = sxsi + (sizeof(sxsi_dev)/sizeof(_SXSIDEV));
         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 = (void *)FILEH_INVALID;                          sxsi->fh = (long)FILEH_INVALID;
                 }                  }
                 sxsi++;                  sxsi++;
         }          }
Line 184  void sxsi_flash(void) { Line 202  void sxsi_flash(void) {
   
 void sxsi_trash(void) {  void sxsi_trash(void) {
   
         SXSIHDD sxsi;          SXSIDEV sxsi;
         SXSIHDD sxsiterm;          SXSIDEV sxsiterm;
   
         sxsi = sxsi_hd;          sxsi = sxsi_dev;
         sxsiterm = sxsi + (sizeof(sxsi_hd)/sizeof(_SXSIHDD));          sxsiterm = sxsi + (sizeof(sxsi_dev)/sizeof(_SXSIDEV));
         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 = (void *)FILEH_INVALID;                          sxsi->fh = (long)FILEH_INVALID;
                 }                  }
                 sxsi->fname[0] = '\0';                  sxsi->fname[0] = '\0';
                 sxsi++;                  sxsi++;
         }          }
 }  }
   
 static SXSIHDD getdrive(BYTE drv) {  static SXSIDEV getdrive(REG8 drv) {
   
         UINT    num;          UINT    num;
         SXSIHDD ret;          SXSIDEV ret;
   
         num = drv & 0x0f;          num = drv & 0x0f;
         if (num >= 2) {          if (num >= 2) {
                 return(NULL);                  return(NULL);
         }          }
         num += (drv & 0x20) >> 4;          num += (drv & 0x20) >> 4;
         ret = sxsi_hd + num;          ret = sxsi_dev + num;
         if (ret->fname[0] == '\0') {          if (ret->fname[0] == '\0') {
                 return(NULL);                  return(NULL);
         }          }
         if ((FILEH)ret->fh == FILEH_INVALID) {          if ((FILEH)ret->fh == FILEH_INVALID) {
                 ret->fh = (void *)file_open(ret->fname);                  ret->fh = (long)file_open(ret->fname);
                 if ((FILEH)ret->fh == FILEH_INVALID) {                  if ((FILEH)ret->fh == FILEH_INVALID) {
                         ret->fname[0] = '\0';                          ret->fname[0] = '\0';
                         return(NULL);                          return(NULL);
                 }                  }
         }          }
           sysmng_hddaccess(drv);
         return(ret);          return(ret);
 }  }
   
 BYTE sxsi_read(BYTE drv, long pos, BYTE *buf, UINT16 size) {  REG8 sxsi_read(REG8 drv, long pos, BYTE *buf, UINT size) {
   
 const _SXSIHDD  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
         UINT16          rsize;          UINT            rsize;
   
         sxsi = getdrive(drv);          sxsi = getdrive(drv);
         if (sxsi == NULL) {          if (sxsi == NULL) {
Line 243  const _SXSIHDD *sxsi; Line 262  const _SXSIHDD *sxsi;
         }          }
         while(size) {          while(size) {
                 rsize = min(size, sxsi->size);                  rsize = min(size, sxsi->size);
                 nevent.remainclock -= rsize;                  CPU_REMCLOCK -= rsize;
                 if (file_read((FILEH)sxsi->fh, buf, rsize) != rsize) {                  if (file_read((FILEH)sxsi->fh, buf, rsize) != rsize) {
                         return(0xd0);                          return(0xd0);
                 }                  }
Line 253  const _SXSIHDD *sxsi; Line 272  const _SXSIHDD *sxsi;
         return(0x00);          return(0x00);
 }  }
   
 BYTE sxsi_write(BYTE drv, long pos, const BYTE *buf, UINT16 size) {  REG8 sxsi_write(REG8 drv, long pos, const BYTE *buf, UINT size) {
   
 const _SXSIHDD  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
         UINT16          wsize;          UINT            wsize;
   
         sxsi = getdrive(drv);          sxsi = getdrive(drv);
         if (sxsi == NULL) {          if (sxsi == NULL) {
Line 273  const _SXSIHDD *sxsi; Line 292  const _SXSIHDD *sxsi;
         }          }
         while(size) {          while(size) {
                 wsize = min(size, sxsi->size);                  wsize = min(size, sxsi->size);
                 nevent.remainclock -= wsize;                  CPU_REMCLOCK -= wsize;
                 if (file_write((FILEH)sxsi->fh, buf, wsize) != wsize) {                  if (file_write((FILEH)sxsi->fh, buf, wsize) != wsize) {
                         return(0x70);                          return(0x70);
                 }                  }
Line 283  const _SXSIHDD *sxsi; Line 302  const _SXSIHDD *sxsi;
         return(0x00);          return(0x00);
 }  }
   
 BYTE sxsi_format(BYTE drv, long pos) {  REG8 sxsi_format(REG8 drv, long pos) {
   
 const _SXSIHDD  *sxsi;  const _SXSIDEV  *sxsi;
         long            r;          long            r;
         UINT16          i;          UINT16          i;
         BYTE            work[256];          BYTE            work[256];
Line 310  const _SXSIHDD *sxsi; Line 329  const _SXSIHDD *sxsi;
                 while(size) {                  while(size) {
                         wsize = min(size, sizeof(work));                          wsize = min(size, sizeof(work));
                         size -= wsize;                          size -= wsize;
                         nevent.remainclock -= wsize;                          CPU_REMCLOCK -= wsize;
                         if (file_write((FILEH)sxsi->fh, work, wsize) != wsize) {                          if (file_write((FILEH)sxsi->fh, work, wsize) != wsize) {
                                 return(0x70);                                  return(0x70);
                         }                          }

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


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