home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTFHDX / FMT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  6.6 KB  |  277 lines

  1. /* fmt.c */
  2.  
  3.  
  4. #include <obdefs.h>
  5. #include <gemdefs.h>
  6. #include "fhdx.h"
  7. #include "define.h"
  8. #include "part.h"
  9. #include "addr.h"
  10.  
  11.  
  12. extern char sbuf[];
  13. extern int rebootp;
  14.  
  15.  
  16. /*
  17.  * These constants are used in a heuristic that determines
  18.  * if the format parameter information in the boot sector
  19.  * is intact.  (See fmtpok()).
  20.  */
  21. #define    MAXCYLS        4096        /* max number of cylinders */
  22. #define    MINCYLS        100        /* minimum number of cylinders */
  23. #define    MAXHEADS    16        /* max number of heads */
  24. #define    MINHEADS    2        /* minimum number of heads */
  25. #define    MAXLZ        16        /* max landing zone value */
  26. #define    MAXRT        2        /* max step-rate code */
  27.  
  28.  
  29. /*
  30.  * These are the default format parameters;
  31.  * they are for a 20Mb Mutsubuishi drive.
  32.  *
  33.  * If we change drives, this might have to be changed.
  34.  *
  35.  */
  36. HINFO deffmt = {
  37.     0x264,        /* 612 cylinders */
  38.     4,        /* 4 heads */
  39.     0x265,        /* no reduced write-current cylinder */
  40.     0x265,        /* no write precomp cylinder */
  41.     10,        /* landing zone position = 10 */
  42.     2,        /* use buffered seeks */
  43.     1,        /* interleave = 1 */
  44.     17        /* 17 sectors per track */
  45. };
  46.  
  47.  
  48. /*
  49.  * Set format parameters in a
  50.  * root sector image.
  51.  *
  52.  */
  53. sfmtparm(image, fmtparm)
  54. char *image;
  55. HINFO *fmtparm;
  56. {
  57.     register HINFO *rinfo;
  58.     register long siz;
  59.  
  60.     rinfo = &((RSECT *)(image + 0x200 - sizeof(RSECT)))->hd_info;
  61.  
  62.     rinfo->hi_cc = fmtparm->hi_cc;
  63.     rinfo->hi_dhc = fmtparm->hi_dhc;
  64.     rinfo->hi_rwcc = fmtparm->hi_rwcc;
  65.     rinfo->hi_wpc = fmtparm->hi_wpc;
  66.     rinfo->hi_lz = fmtparm->hi_lz;
  67.     rinfo->hi_rt = fmtparm->hi_rt;
  68.     rinfo->hi_in = fmtparm->hi_in;
  69.     rinfo->hi_spt = fmtparm->hi_spt;
  70.  
  71. }
  72.  
  73.  
  74. /*
  75.  * Determine if format parameters are good;
  76.  * return OK if they appear to be,
  77.  * ERROR if they don't appear to be.
  78.  *
  79.  */
  80. fmtpok(fmtparm)
  81. HINFO *fmtparm;
  82. {
  83.     if (fmtparm->hi_cc > MAXCYLS ||
  84.     fmtparm->hi_cc < MINCYLS ||
  85.     fmtparm->hi_dhc > MAXHEADS ||
  86.     fmtparm->hi_dhc < MINHEADS ||
  87.     fmtparm->hi_lz > MAXLZ ||
  88.     fmtparm->hi_rt > MAXRT)
  89.         return ERROR;
  90.  
  91.     return OK;
  92. }
  93.  
  94.  
  95. /*
  96.  * Setup default format parameters in hinfo;
  97.  * (REAL C compilers do this with a structure assignment...)
  98.  *
  99.  */
  100. fdefault(hinfop)
  101. HINFO *hinfop;
  102. {
  103.     hinfop->hi_cc = deffmt.hi_cc;
  104.     hinfop->hi_dhc = deffmt.hi_dhc;
  105.     hinfop->hi_rwcc = deffmt.hi_rwcc;
  106.     hinfop->hi_wpc = deffmt.hi_wpc;
  107.     hinfop->hi_lz = deffmt.hi_lz;
  108.     hinfop->hi_rt = deffmt.hi_rt;
  109.     hinfop->hi_in = deffmt.hi_in;
  110.     hinfop->hi_spt = deffmt.hi_spt;
  111. }
  112.  
  113.  
  114. /*
  115.  * Set mode information on drive.
  116.  *
  117.  */
  118. ms(dev, hinfo)
  119. int dev;
  120. HINFO *hinfo;
  121. {
  122.     int i;
  123.     char *p;
  124.     SETMODE mb;
  125.  
  126.     /* initialize parameter structure */
  127.     p = (char *)&mb;
  128.     for (i = sizeof(SETMODE); i--;)
  129.     *p++ = 0;
  130.     mb.smd_8 = 0x08;
  131.     mb.smd_1 = 0x01;
  132.     mb.smd_bs[1] = 0x02;    /* block size = 512 */
  133.  
  134.     cpw(&mb.smd_cc[0], hinfo->hi_cc);
  135.     mb.smd_dhc = hinfo->hi_dhc;
  136.     cpw(&mb.smd_rwc[0], hinfo->hi_rwcc);
  137.     cpw(&mb.smd_wpc[0], hinfo->hi_wpc);
  138.     mb.smd_lz = hinfo->hi_lz;
  139.     mb.smd_rt = hinfo->hi_rt;
  140.  
  141.     return mdselect(dev, 22, &mb);
  142. }
  143.  
  144.  
  145. /*
  146.  * Set mode information on a SCSI drive.
  147.  *
  148.  * Comments:
  149.  * (20-Jun-1990  ml.)
  150.  *    Support for page code 3 is specific for the NEC D5862 drives
  151.  * _ONLY_.  They have very weird mode select and mode sense commands.
  152.  * A mode sense page code 3 returns with data of page code 1, 3 and 4!
  153.  * This would explain some of the things done under case 3 of the switch
  154.  * statement below.  Further details of the commands, refer to the D5862
  155.  * Magnetic Disk Drive Product Description.
  156.  */
  157. char sendata[64];    /* data buffer */
  158.  
  159. scsims(dev, hinfo, pcode, hdsiz)
  160. int  dev;        /* physical device number */
  161. HINFO *hinfo;        /* parameters of dev */
  162. int  pcode;        /* page code */
  163. long *hdsiz;        /* -> hard disk size */
  164. {
  165.     int len;        /* transfer length */
  166.     int ret;        /* return code */
  167.     extern long get3bytes();
  168.  
  169.     if (pcode == 0)
  170.     len = 16;
  171.     else if (pcode == 3)
  172.     len = 36;
  173.         
  174.     if ((ret = mdsense(dev, pcode, 0, len, sendata)) != OK)
  175.     return ret;
  176.         
  177.     delay();
  178.     sendata[0] = sendata[2] = 0;    /* reserved */
  179.     
  180.     switch(pcode) {            /* set up buffer */
  181.         case 0:                /* for page code 0 */
  182.         sendata[3] = 0x08;        /* block descriptor length */
  183.         sendata[10] = 0x02;        /* block length = 512 bytes */
  184.         sendata[12] = 0;        /* page code 0 */
  185.         sendata[13] = 0x02;        /* page is 2 bytes long */
  186.         sendata[14] = 0x10;        /* set inhst bit -> no error on reset */
  187.         sendata[15] = 0;        /* device type qualifier */
  188.         len = 16;
  189.         break;
  190.         
  191.     case 3:                /* for NEC-D5862 page code 3 ONLY */
  192.         for (ret = 0; ret <= 27; ret++)    /* init data */
  193.             sendata[ret] = 0;
  194.         len = 28;
  195.         sendata[4] = 3;            /* page code 3 */
  196.         sendata[5] = 0x16;            /* page is 22 bytes long */
  197.         sendata[15] = (BYTE)hinfo->hi_spt;    /* set sectors per track */
  198.         sendata[24] = 0x40;
  199.     }
  200.     
  201.     if ((ret = mdselect(dev, len, sendata)) != OK)
  202.         return ret;
  203.  
  204.     delay();    
  205.     if ((ret = mdsense(dev, pcode, 0, len, sendata)) == OK)
  206.         *hdsiz = get3bytes(sendata+5);
  207.     return ret;
  208. }
  209.  
  210.  
  211. /*
  212.  * Move `w' to unaligned location.
  213.  *
  214.  */
  215. cpw(d, w)
  216. char *d;
  217. WORD w;
  218. {
  219.     char *s;
  220.  
  221.     s = (char *)&w;
  222.     d[0] = s[0];
  223.     d[1] = s[1];
  224. }
  225.  
  226.  
  227. /*
  228.  * Return format parameters in `hinfo', based on
  229.  * the format parameter name `fpnam' and kind of
  230.  * entry.  (entry could be "ct" for controller 
  231.  * test, or "mn" for regular format)
  232.  *
  233.  * return 0 on OK,
  234.  * -1 on [CANCEL].
  235.  *
  236.  */
  237. gfparm(modesel, hinfop, fpnam, entry)
  238. int *modesel;
  239. HINFO *hinfop;
  240. char *fpnam;
  241. char *entry;
  242. {
  243.     long num;
  244.     char name[128];
  245.     char eid[4];    /* entry id */
  246.     int  ret;
  247.  
  248.     strcpy(name, fpnam);
  249.     strcpy(eid, entry);
  250.  
  251.     if (wgetent(name, eid) == ERROR) {
  252.         nofmt[NOSCHFMT].ob_spec = name;
  253.         nofmt[NOSCHFOK].ob_state = NORMAL;
  254.         execform(nofmt, 0);
  255.     ret = ERROR;
  256.     goto gfend;
  257.     }
  258.  
  259.     fdefault(hinfop);
  260.     if (wgetnum("cy", &num) == OK) hinfop->hi_cc = (WORD)num;
  261.     if (wgetnum("hd", &num) == OK) hinfop->hi_dhc = (BYTE)num;
  262.     if (wgetnum("rw", &num) == OK) hinfop->hi_rwcc = (WORD)num;
  263.     if (wgetnum("wp", &num) == OK) hinfop->hi_wpc = (WORD)num;
  264.     if (wgetnum("lz", &num) == OK) hinfop->hi_lz = (BYTE)num;
  265.     if (wgetnum("rt", &num) == OK) hinfop->hi_rt = (BYTE)num;
  266.     if (wgetnum("in", &num) == OK) hinfop->hi_in = (BYTE)num;
  267.     if (wgetnum("sp", &num) == OK) hinfop->hi_spt = (BYTE)num;
  268.     if (wgetnum("md", &num) == OK) *modesel = (WORD)num;
  269.     ret = OK;
  270.     
  271. gfend:
  272.     /* Close the wincap file after accessing it */
  273.     wclose();
  274.             
  275.     return ret;
  276. }
  277.