home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / gtak212b.zip / SOURCE.ZIP / OS2-ASPI / init.c < prev    next >
C/C++ Source or Header  |  1992-11-14  |  4KB  |  155 lines

  1. /*****************************************************************************
  2.  * $Id: init.c,v 2.1 1992/11/14 21:00:20 ak Exp $
  3.  *****************************************************************************
  4.  * $Log: init.c,v $
  5.  * Revision 2.1  1992/11/14  21:00:20  ak
  6.  * OS/2 2.00.1 ASPI
  7.  *
  8.  * Revision 1.1.1.1  1992/01/06  20:16:00  ak
  9.  * Alpha version.
  10.  *
  11.  * Revision 1.1  1992/01/06  20:15:58  ak
  12.  * Initial revision
  13.  *
  14.  *****************************************************************************/
  15.  
  16. static char _far rcsid[] = "$Id: init.c,v 2.1 1992/11/14 21:00:20 ak Exp $";
  17.  
  18. #include "aspitape.h"
  19. #define INCL_DOS
  20. #include <os2.h>
  21.  
  22. static char     aspiName[]    = "SCSIMGR$";
  23.  
  24. /*
  25.  * Put initialization data in a separate segment.
  26.  */
  27. char _far    noAttach[]    = "Cannot attach to SCSIMGR$\n";
  28. char _far    noOpen[]    = "Cannot open SCSIMGR$\n";
  29. char _far    badLine[]    = "ASPITAPE command line error$\n";
  30. char _far    noTape[]    = "No target ID on ASPITAPE command line\n";
  31. char _far    okMsg1[]    = "ASPI tape driver installed"
  32.                       " for adapter ";
  33. char _far    okMsg2[]    = ", target ";
  34. char _far    okMsg3[]    = ", sense mode is ";
  35. char _far    mode0Msg[]    = "Sense Key";
  36. char _far    mode1Msg[]    = "TDC3600";
  37. char _far    mode2Msg[]    = "SCSI-2";
  38. char _far    modeXMsg[]    = "invalid";
  39. char _far * _far modeMsg[]    = { mode0Msg, mode1Msg, mode2Msg };
  40.  
  41. /*
  42.  * Handle device command line.
  43.  * Line is terminated by 0.
  44.  */
  45. int
  46. cmdline(char _far *line)
  47. {
  48.     byte *name;
  49.  
  50.     /*
  51.      * Skip driver name up to first argument.
  52.      */
  53.     for (; *line && *line != ' '; ++line) ;
  54.     for (; *line == ' '; ++line) ;
  55.  
  56.     /*
  57.      * First argument is device name.
  58.      */
  59.     name = header.name;
  60.     for (; *line && *line != ' '; ++line)
  61.         if (name < header.name+8)
  62.             *name++ = *line;
  63.     while (name < header.name+8)
  64.         *name++ = ' ';
  65.  
  66.     /*
  67.      * Handle arguments.
  68.      */
  69.     for (;;++line) {
  70.         switch (*line) {
  71.         default:
  72.             return 1;
  73.         case 0:
  74.             return 0;
  75.         case ' ':
  76.             continue;
  77.         case 'D': case 'd':            /* debug level */
  78.             if (*++line < '0' || *line > '9')
  79.                 return 1;
  80.             trace = *line - '0';
  81.             continue;
  82.         case 'A': case 'a':            /* adapter number */
  83.             if (*++line < '0' || *line > '9')
  84.                 return 1;
  85.             adapter = *line - '0';
  86.             continue;
  87.         case 'T': case 't':            /* target ID */
  88.             if (*++line < '0' || *line > '9')
  89.                 return 1;
  90.         case '0': case '1': case '2': case '3': case '4':
  91.         case '5': case '6': case '7': case '8': case '9':
  92.             target = *line - '0';
  93.             continue;
  94.         case 'S': case 's':            /* sense data mode */
  95.             if (*++line < '0' || *line > '9')
  96.                 return 1;
  97.             senseMode = *line - '0';
  98.             continue;
  99.         case 'V':
  100.             video_address = 0xB8000;    /* VGA output */
  101.             continue;
  102.         case 'C':                /* type code */
  103.             if (*++line < '0' || *line > '9')
  104.                 return 1;
  105.             continue;
  106.         }
  107.     }        
  108. }
  109.  
  110. word
  111. DrvInit(char _far *line)
  112. {
  113.     word action;
  114.  
  115.     trace = 0;
  116.     blocksize = 512;
  117.     paddrSRB = VirtToPhys(&srb);
  118.  
  119.     if (AttachDD(aspiName, &aspiEntry)) {
  120.         puts(noAttach);
  121.         return ERROR+DONE+GeneralFailure;
  122.     }
  123.  
  124.     if (DosOpen((PSZ)aspiName, &aspiHandle, &action, 0L, FILE_NORMAL,
  125.             OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_READWRITE
  126.             + OPEN_SHARE_DENYNONE + OPEN_FLAGS_FAIL_ON_ERROR, 0L)) {
  127.         puts(noOpen);
  128.         return ERROR+DONE+GeneralFailure;
  129.     }
  130.     adapter = 0;
  131.     target = 0xFF;
  132.  
  133.     DosClose(aspiHandle);
  134.     aspiHandle = 0;
  135.  
  136.     if (cmdline(line)) {
  137.         puts(badLine);
  138.         return ERROR+DONE+GeneralFailure;
  139.     }
  140.  
  141.     if (target == 0xFF) {
  142.         puts(noTape);
  143.         return ERROR+DONE+GeneralFailure;
  144.     }
  145.  
  146.     puts(okMsg1);
  147.     putd(adapter);
  148.     puts(okMsg2);
  149.     putd(target);
  150.     puts(okMsg3);
  151.     puts(senseMode <= SCSI2 ? modeMsg[senseMode] : modeXMsg);
  152.     putc('\n');
  153.     return DONE;
  154. }
  155.