home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-4 / DEVICE.C < prev    next >
Text File  |  2000-06-30  |  9KB  |  345 lines

  1. /*
  2.     Program:  DEVICE
  3.     Author:  Richard Conn
  4.     Version:  1.0
  5.     Date:  22 Aug 82
  6.     Previous Versions:  None
  7. */
  8. #define    ver    10        /* Version Number */
  9. #define    defname    "DEVICE.COM"    /* Default File Name */
  10.  
  11. /*
  12.  
  13.     DEVICE -- a program for assigning mnemonic names to the
  14. CP/M physical devices and allowing these devices to be selected
  15. by the assigned names
  16.  
  17.     Command Forms:
  18.  
  19.         DEV CON: USERNAME    <-- Select Device
  20.             LST: USERNAME
  21.             RDR: USERNAME
  22.             PUN: USERNAME
  23.  
  24.         DEV //            <-- HELP
  25.  
  26.         DEV /DISPLAY        <-- Display USERNAMEs and
  27.                         current settings
  28.  
  29.         DEV /SET        <-- Define USERNAMEs and
  30.                         comments
  31.  
  32.     Concept and Examples:
  33.  
  34.         DEV CON: REMOTE        <-- Select Remote Console
  35.         DEV LST: MODEM        <-- Select Modem Output
  36.         DEV /D            <-- Display UNs and Settings
  37.             CON: Mnemonic Devices --
  38.                 TTY    CRT    MODEM    CRT/MODEM
  39.             LST: Mnemonic Devices --
  40.                 TTY    CRT    REMOTE    MODEM
  41.             RDR: Mnemonic Devices --
  42.                 TTY    CRT    CLOCK    MODEM
  43.             PUN: Mnemonic Devices --
  44.                 TTY    CRT    CLOCK    MODEM
  45.  
  46.             Current Settings --
  47.                 CON: = CRT
  48.                 LST: = MODEM
  49.                 RDR: = CLOCK
  50.                 PUN: = CLOCK
  51.  
  52. */
  53.  
  54. /*  Global Definitions and Variables  */
  55. char username[16][9];  /* 16 User Names of 8 Chars + Ending NULL Each */
  56.  
  57. /*  Main Program  */
  58. main(argc,argv)
  59. int argc;
  60. char **argv;
  61. {
  62.     printf("DEVICE, Version %d.%d",ver/10,ver%10);
  63.     switch (argc) {
  64.         case 2 : if (*argv[1] == '/') option(argv[1]);
  65.                 else help();
  66.              break;
  67.         case 3 : set(argv[1], argv[2]); break;
  68.         default : help(); break;
  69.         }
  70. }
  71.  
  72. /*  Option Processor  */
  73. option(ostr)
  74. char *ostr;
  75. {
  76.     char *tstr;
  77.  
  78.     tstr = ostr;  /* assign temp ptr */
  79.     printf("  -- Option: ");
  80.     switch (*++tstr) {
  81.         case 'D' : printf("Display Device Mnemonics and Status");
  82.                display(); break;
  83.         case 'S' : printf("Setup of Device Mnemonics");
  84.                setup(); break;
  85.         default  : printf("Help");
  86.                help(); break;
  87.         }
  88. }
  89.  
  90. /*  Help Message  */
  91. help()
  92. {
  93.     printf("\n\tDEVICE Program Help Information\n");
  94.  
  95.     printf("\nDEVICE is a program used to assign mnemonic names to");
  96.     printf("\nthe CP/M physical devices and allow these devices to");
  97.     printf("\nbe selected by these names.");
  98.     printf("\n");
  99.  
  100.     printf("\nThe forms of this command are --");
  101.  
  102.     printf("\n\tDEVICE ldev mnemonic\t<-- select device");
  103.     printf("\n\t\tldev may be one of:");
  104.         printf("\n\t\t\tCON  LST  PUN  RDR");
  105.         printf("\n\t\t-- only first letter is required");
  106.  
  107.     printf("\n\tDEVICE /DISPLAY\t<-- display mnemonics and current ");
  108.         printf("settings");
  109.  
  110.     printf("\n\tDEVICE /SET\t<-- define mnemonics");
  111.  
  112.     printf("\n\tDEVICE //\t<-- print HELP information\n");
  113. }
  114.  
  115. /*  Display Mnemonics and Current Settings  */
  116. display()
  117. {
  118.     int i,dev;
  119.  
  120.     printf("\nPhysical Device Mnemonics --");
  121.     for (dev = 0; dev < 4; dev++) {
  122.         prdev(dev);  /* Print Device Names */
  123.         printf(" Mnemonic Names --\n\t");
  124.         for (i = dev*4; i < (dev+1)*4; i++) {
  125.             printf("\t");
  126.             prun(i);  /* Print User Name */
  127.             }
  128.         }
  129.     disp2();
  130. }
  131.  
  132. /*  Display Current Device Assignments  */
  133. disp2()
  134. {
  135.     int dev,i;
  136.  
  137.     printf("\n\nCurrent Device Assignments --");
  138.     for (dev = 0; dev < 4; dev++) {
  139.         prdev(dev); printf(" = ");
  140.         i = dev*4 + binit(dev);  /* Get Number of User Name */
  141.         prun(i);  /* Print User Name */
  142.         }
  143.     printf("\n");
  144. }
  145.  
  146. /*  Print Names of Devices  */
  147. prdev(dev)
  148. int dev;
  149. {
  150.     printf("\n\t");
  151.     switch (dev) {
  152.         case 0 : printf("CON:"); break;
  153.         case 1 : printf("RDR:"); break;
  154.         case 2 : printf("PUN:"); break;
  155.         case 3 : printf("LST:"); break;
  156.         }
  157. }
  158.  
  159. /*  Print User Name  */
  160. prun(map)
  161. int map;
  162. {
  163.     printf(username[map]);
  164. }
  165.  
  166. /*  Extract Binit Number for Logical Device  */
  167. binit(dev)
  168. int dev;
  169. {
  170.     int stat,i;
  171.  
  172.     stat = bdos(7,0);  /* Get current I/O Byte */
  173.     for (i = 0; i < dev; i++) stat = stat >> 2;
  174.     stat &= 3;  /* 2 LSB only */
  175.     return(stat);
  176. }
  177.  
  178. /*  Set up Mnemonic Names  */
  179. setup()
  180. {
  181.     char cmd, fname[40];
  182.     int i,j,fd;
  183.     unsigned cend,base;
  184.  
  185.     printf("\nDEVICE Setup Subsystem");
  186.     do {
  187.         printf("\nSetup Command (? for Help)? ");
  188.         cmd = toupper(getchar());  /* Get Response */
  189.         switch (cmd) {
  190.             case 'C' : while(setdev(0) == 0); break;
  191.             case 'R' : while(setdev(1) == 0); break;
  192.             case 'P' : while(setdev(2) == 0); break;
  193.             case 'L' : while(setdev(3) == 0); break;
  194.             case 'I' : initdev(); break;
  195.             case 'D' : display(); break;
  196.             case 'Q' : printf("\tVerify Abort (Y/N)? ");
  197.                     if (toupper(getchar()) == 'Y')
  198.                         return(-1);
  199.                     break;
  200.             case 'X' : break;
  201.             default  : sethlp(); break;
  202.             }
  203.     } while (cmd != 'X');
  204.     printf("\tWrite New File (Y/N)? ");
  205.     if (toupper(getchar()) != 'Y') return(-1);
  206.     printf("\nName of File (RETURN = %s)? ",defname);
  207.     dots(12);
  208.     scanf("%s",fname); strcap(fname);  /* Input and Capitalize File Name */
  209.     if (strlen(fname) == 0) strcpy(fname,defname);  /* Set FN if none */
  210.     if (strscan(fname) == 0) strcat(fname,".COM");  /* Make type COM */
  211.     printf("\nWriting File %s to Disk ...",fname);
  212.     fd = creat(fname);  /* Delete old file and open new one */
  213.     if (fd == -1) {
  214.         printf("\nError -- Can't Create File %s",fname);
  215.         return(-1);
  216.         }
  217.     cend = codend()/128;  /* Determine last 128-byte block of code */
  218.     write(fd,0x100,cend);  /* Write file to disk */
  219.     close(fd);  /* Close file -- done */
  220.     printf(" File %s Written to Disk\n",fname);
  221. }
  222.  
  223. /*  Set Mnemonic String for Device Number Given; return -1 to abort  */
  224. setdev(devno)
  225. int devno;
  226. {
  227.     int i;
  228.     char name[20];
  229.  
  230.     printf("\n\tPhysical Device Number (RETURN=Done or 0-3)? ");
  231.     i = getchar() - '0';  /* Get response and convert to binary */
  232.     if ((i < 0) || (i > 4))  /* i is out of range */
  233.         return(-1);
  234.     do {
  235.         printf("\n\tDevice Name (RETURN = Clear Device Name)? ");
  236.         dots(8);
  237.         scanf("%s",name); strcap(name);  /* Get and Capitalize Name */
  238.         if (strlen(name) > 8)
  239.             printf("Device Name is too Long -- Reenter");
  240.     } while (strlen(name) > 8);
  241.     i = devno*4 + i; username[i][0]='\0'; /* Pt to name and clear it */
  242.     if (strlen(name) == 0) {
  243.         printf("\nName Cleared");
  244.         return(-1);
  245.         }
  246.     strcat(username[i],name);  /* Make entry in array */
  247.     return(0);  /* Continue Flag */
  248. }
  249.  
  250. /*  Initialize all devices to clear  */
  251. initdev()
  252. {
  253.     int i;
  254.     char ans;
  255.  
  256.     printf("\tVerify Initialization (Y/N)? ");
  257.     if (toupper(getchar()) != 'Y') {
  258.         printf("\nInitialization Aborted");
  259.         return(-1);
  260.         }
  261.     for (i=0; i<16; i++) username[i][0] = '\0';
  262.     printf("\nAll Mnemonic Device Names Cleared");
  263. }
  264.  
  265. /*  Set Binit in I/O Byte for Device (String 1) Mnemonic (String 2)  */
  266. set(devs,user)
  267. char *devs, *user;
  268. {
  269.     int dev,i,match,iobyte,mask;
  270.  
  271.     switch (*devs) {
  272.         case 'C' : dev = 0; break;
  273.         case 'R' : dev = 1; break;
  274.         case 'P' : dev = 2; break;
  275.         case 'L' : dev = 3; break;
  276.         default : printf("\nError -- Invalid Logical Device Name\n");
  277.               help(); return(-1);
  278.         }
  279.     match = -1;
  280.     for (i = dev*4; i < (dev+1)*4; i++)
  281.         if (strcmp(username[i],user) == 0) match = i-dev*4;
  282.     if (match == -1) {
  283.         printf("\nError -- Invalid Device Mnemonic\n");
  284.         help(); return(-1);
  285.         }
  286.     iobyte = bdos(7,0);  /* Get I/O Byte */
  287.     mask = 3;  /* Set Mask */
  288.     for (i = 0; i < dev; i++) {
  289.         mask = mask << 2;  /* Set Mask on Target */
  290.         match = match << 2;  /* Set Match on Target */
  291.         }
  292.     iobyte = iobyte & ~mask;  /* Complement Mask and Set Target to 0 */
  293.     iobyte |= match;  /* Map In New Binit onto Target */
  294.     bdos(8,iobyte);  /* Set New I/O Byte */
  295.     disp2();  /* Display New Settings */
  296.     return(0);  /* Return with Continuation Flag Set */
  297. }
  298.  
  299. /*  Capitalize String  */
  300. strcap(str)
  301. char *str;
  302. {
  303.     char *tstr;
  304.  
  305.     tstr = str;
  306.     while (*tstr != '\0') {
  307.         *tstr = toupper(*tstr);
  308.         tstr++;
  309.         }
  310. }
  311.  
  312. /*  Help File for Interactive Setup Commands  */
  313. sethlp()
  314. {
  315.     printf("\nDEVICE Setup Subsystem Command Summary");
  316.     printf("\n\tC, R, P, L -- Define Mnemonic for CON:, RDR:, PUN:, ");
  317.     printf("or LST: Devices");
  318.     printf("\n\tD -- Display Currently-Defined Device Mnemonics");
  319.     printf("\n\tI -- Initialize and Clear All Device Mnemonics");
  320.     printf("\n\tQ -- Quit without Changing Program on Disk");
  321.     printf("\n\tX -- Exit and Update Program on Disk");
  322. }
  323.  
  324. /*  Print num dots followed by num <BS> on screen  */
  325. dots(num)
  326. int num;
  327. {
  328.     int i;
  329.  
  330.     for (i=0; i<num; i++) putchar('.');
  331.     for (i=0; i<num; i++) putchar('\010');
  332. }
  333.  
  334. /*  Scan passed string for a decimal and return zero if not found  */
  335. strscan(str)
  336. char *str;
  337. {
  338.     char *tstr;
  339.  
  340.     tstr = str;  /* pt to first char */
  341.     while (*tstr != '\0')
  342.         if (*tstr++ == '.') return (-1);
  343.     return(0);  /* Didn't find dot */
  344. }
  345.