home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols100 / vol181 / rt11.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-13  |  7.5 KB  |  325 lines

  1. /*
  2.     RT-11 Adapter Package for CP/M
  3.  
  4.     Rev. 1.0 -- July 1980
  5.  
  6.     Rev. 1.1 -- March 1981 consisting of adding a valid system date
  7.             word to all files placed on the RT-11 disk and
  8.             putting the volume ID on a disk when the directory
  9.             is initialized.  This will keep RT-11 versions
  10.             later than V02C from choking.
  11.  
  12.     copyright (c) 1980, William C. Colley, III
  13.  
  14.     Rev. 1.2 -- Craig Davenport - Incitec Ltd      (Feb 1984)
  15.                       P O Box 140
  16.                       Morningside,
  17.                       Qld 4170,
  18.                       Australia.
  19.          -- Modified for Digital Research C compiler under CP/M-86
  20.                  -- Assebmbly language routines added for BIOS calls etc.
  21.  
  22. The main-line routine is here, as are the individual command processors.
  23. */
  24.  
  25. #include "B:RT11.H"
  26.  
  27. #include "B:STDIO.H"
  28.  
  29. #include "B:CTYPE.H"
  30.  
  31. /*
  32. Main program..........
  33. */
  34.  
  35. main()
  36. {
  37.     char temp[20], t;
  38.     int  m, d, y;
  39.     puts("\nRT-11 File I/O Package -- Rev. 1.2 -- Feb 1984\n");
  40.     puts("\nPut RT-11 disk into drive B, and CP/M disk into drive A.\n");
  41.     puts("THIS IS IMPORTANT.  Hit CR when you're ready.");
  42.     while(1)
  43.     {
  44.         gets(temp);
  45.         if (temp[0] == '\0') break;
  46.         puts("Are you sure?");
  47.     }
  48.     puts("\nOK.\n");
  49.     BDOS(INIT_BDOS);
  50.  
  51. /* Get system date word for later RT-11 versions. */
  52.  
  53.     do
  54.     {
  55.         puts("Today's date (mm/dd/yy)? ");
  56.         scanf("%2d/%2d/%2d",&m,&d,&y);
  57.     }
  58.     while (m == 0 || m > 12 || d == 0 || d > 31 || y < 72 || y > 99);
  59.     sysdate = (m << 10) + (d << 5) + (y - 0110);
  60.  
  61.     while((t = getcom()) != 'Q')
  62.     {
  63.         switch (t)
  64.         {
  65.             case 'D':    list_dir();        break;
  66.             case 'E':    erase_file();        break;
  67.             case 'G':    get_file();        break;
  68.             case 'I':    init_disk();        break;
  69.             case 'P':    put_file();        break;
  70.             case 'R':    rename_file();        break;
  71.             case 'T':    type_file();        break;
  72.             default:
  73.                 puts("\nCommands available are:\n\n");
  74.                 puts("(D)irectory list\n");
  75.                 puts("(E)rase file on RT-11 disk\n");
  76.                 puts("(G)et file from RT-11 disk\n");
  77.                 puts("(I)initialize RT-11 disk\n");
  78.                 puts("(P)ut file onto RT-11 disk\n");
  79.                 puts("(R)ename file on RT-11 disk\n");
  80.                 puts("(Q)uit program\n");
  81.                 puts("(T)ype file on RT-11 disk\n");
  82.                 putchar('\n');
  83.                 break;
  84.         }
  85.     }
  86.     puts("\nReinsert system disk and type any key.");
  87.     getchar();
  88.     putchar('\n');
  89. }
  90.  
  91. /*
  92. Routine to erase a file on the RT-11 disk.
  93. */
  94.  
  95. erase_file()
  96. {
  97.     int file_name[3];
  98.     if (!get_RT_name("File to erase? ",file_name)) return;
  99.     if (!delete(file_name)) puts("Error -- file does not exist\n");
  100. }
  101.  
  102. /*
  103. Routine to rename a file on the RT-11 disk.
  104. */
  105.  
  106. rename_file()
  107. {
  108.     int old_name[3], new_name[3];
  109.     if (!get_RT_name("Old name of file? ",old_name)) return;
  110.     if (!get_RT_name("New name of file? ",new_name)) return;
  111.     if (!rename(old_name,new_name)) puts("Error -- file does not exist\n");
  112. }
  113.  
  114. /*
  115. Routine to list the directory on the RT-11 disk.
  116. */
  117.  
  118. list_dir()
  119. {
  120.     int t;
  121.     char s[4], volume_id[512], temp[13];
  122.     temp[12] = '\0';
  123.     emt_375(BIOSREAD,1,1,volume_id);
  124.     puts("\nVolume: ");
  125.     putstr(temp,&volume_id[236*2]);
  126.     puts(temp);
  127.     puts("  Owner: ");
  128.     putstr(temp,&volume_id[242*2]);
  129.     puts(temp);
  130.  
  131.     usrcom();
  132.     puts("\n\nName  .Ext   Blks    Date     Start    Extras\n\n");
  133.     do
  134.     {
  135.         while(*(dir_pointer + 1) != ENDSEG)
  136.         {
  137.             if (*(dir_pointer + 1) == PERM)
  138.             {
  139.                 print_name(dir_pointer + 2);
  140.                 printf("   %3o   ",_getword(dir_pointer,4));
  141.                 if (t = _getword(dir_pointer,6) & 0x7fff)
  142.                 {
  143.                     getmon(t >> 10,s);
  144.                     printf("%2d-%s-%2d   ",(t >> 5) & 037,
  145.                         s,(t & 037) + 0110);
  146.                 }
  147.                 else puts("            ");
  148.                 printf("%3o   ",file_start);
  149.                 for (t = 0; t < directory.extra_bytes; t++)
  150.                     printf("  %3o",*(dir_pointer+t+14));
  151.             }
  152.             else printf("< unused >   %3o               %3o",
  153.                 _getword(dir_pointer,4),file_start);
  154.             incr1();
  155.             putchar('\n');
  156.         }
  157.     }
  158.     while (nxblk());
  159. }
  160.  
  161. /*
  162. Function to get a file from the RT-11 disk onto the CP/M disk.
  163. */
  164.  
  165. get_file()
  166. {
  167.     char CP_file[20], xfer_buffer[512];
  168.     int t, RT_file[3], fd;
  169.     if (!get_RT_name("RT-11 file name? ",RT_file)) return;
  170.     puts("CP/M file name? ");
  171.     gets(CP_file);
  172.     if (CP_file[0] == '\0') sprint_name(RT_file,CP_file);
  173.     if (!lookup(RT_file))
  174.     {
  175.         puts("Error -- no source file\n");
  176.         return;
  177.     }
  178.     if ((fd = creat(CP_file)) == -1)
  179.     {
  180.         puts("Error -- could not create destination file\n");
  181.         return;
  182.     }
  183.     for (t = _getword(dir_pointer,4); t > 0; t--)
  184.     {
  185.         emt_375(BIOSREAD,file_start++,1,xfer_buffer);
  186.         if (write(fd,xfer_buffer,512) != 512)
  187.         {
  188.             puts("Error -- CP/M disk full\n");
  189.             close(fd);
  190.             return;
  191.         }
  192.     }
  193.     close(fd);
  194. }
  195.  
  196. /*
  197. Routine to type an RT-11 file on the console.
  198. */
  199.  
  200. type_file()
  201. {
  202.     char c, xfer_buffer[512];
  203.     int file_name[3], i, j;
  204.     if (!get_RT_name("File to type? ",file_name)) return;
  205.     if (!lookup(file_name))
  206.     {
  207.         puts("Error -- file does not exist\n");
  208.         return;
  209.     }
  210.     for (i = _getword(dir_pointer,4); i > 0; i--)
  211.     {
  212.         emt_375(BIOSREAD,file_start++,1,xfer_buffer);
  213.         for (j = 0; j < 512; j++)
  214.         {
  215.             if ((c = xfer_buffer[j]) == '\0' || c == ('Z' - 64))
  216.                 return;
  217.             putchar(c);
  218.         }
  219.     }
  220. }
  221.  
  222. /*
  223. Routine to put a file onto the RT-11 disk.
  224. */
  225.  
  226. put_file()
  227. {
  228.     int RT_file[3], fd, size,numbyte;
  229.     char CP_file[20], xfer_buffer[512];
  230.     puts("CP/M file name? ");
  231.     gets(CP_file);
  232.     if (CP_file[0] == '\0') return;
  233.     if (!get_RT_name("RT-11 file name? ",RT_file)) return;
  234.     if ((fd = open(CP_file,0)) == -1)
  235.     {
  236.         puts("Error -- could not open source file\n");
  237.         return;
  238.     }
  239.     size = filesize(CP_file);
  240.     if ((file_start = enter(RT_file,size)) == 0) return;
  241.     while (--size >= 0)
  242.     {
  243.         if ((numbyte=read(fd,xfer_buffer,512)) == -1)
  244.         {
  245.             puts("Error -- disk read on CP/M disk\n");
  246.             close(fd);
  247.             return;
  248.         }
  249.         if (numbyte != 512)                /* eof */
  250.             SETMEM(xfer_buffer+numbyte,512-numbyte,'Z'-64);
  251.         emt_375(WRITE,file_start++,1,xfer_buffer);
  252.     }
  253.     close(fd);
  254.     klose(RT_file);
  255. }
  256.  
  257. /*
  258. Routine to initialize the directory on an RT-11 disk.
  259. */
  260.  
  261. init_disk()
  262. {
  263.     char temp[50];
  264.     unsigned volume_id[256];
  265.     puts("Are you sure you want to do this (Y/N)? ");
  266.     gets(temp);
  267.     if (temp[0] != 'Y')
  268.     {
  269.         puts("\t.....Aborted\n");
  270.         return;
  271.     }
  272.     SETMEM(&directory,1024,0);
  273.     puts("Number of directory segments (1 to 31)? ");
  274.     while (1)
  275.     {
  276.         scanf("%d",&directory.total_segments);
  277.         if (directory.total_segments > 0 &&
  278.             directory.total_segments < 32) break;
  279.         puts("Say again? ");
  280.     }
  281.     puts("Extra bytes per directory entry? ");
  282.     scanf("%d",&directory.extra_bytes);
  283.     directory.highest_segment = 1;
  284.     directory.first_block = (directory.highest_segment + 1) * 2 + 4;
  285.     directory.entries[1] = EMPTY;
  286.     _putword(directory.entries,4,488 - 2 * directory.total_segments);
  287.     directory.entries[15 + directory.extra_bytes] = ENDSEG;
  288.     segrw(WRITE,1);
  289.     SETMEM(volume_id,512,' ');
  290.     volume_id[0] = 0;
  291.     volume_id[233] = 1;
  292.     volume_id[234] = 6;
  293.     volume_id[235] = 0107251;
  294.     temp="";
  295.     puts("Volume ID (CR for default)? ");
  296.     gets(temp);
  297.     gets(temp);
  298.     putstr(&volume_id[236], temp[0]==0 ? "RT11A" : temp);
  299.     puts("Owner name (CR for default)? ");
  300.     gets(temp);
  301.     if (temp[0] != 0) 
  302.         putstr(&volume_id[242], temp);
  303.      putstr(&volume_id[248], "DECRT11A");
  304.     emt_375(WRITE,1,1,volume_id);
  305.     puts("\t.....Done\n");
  306. }
  307.  
  308. /*
  309. Internal function in initialize directory routine to put up to 12 characters
  310. from a string into the core image of the volume ID block (block 1 on the disk).
  311. Note that this routine is an addition at Ver 1.0.
  312. */
  313.  
  314. putstr(buffer,string)
  315. char *buffer, *string;
  316. {
  317.     char i;
  318.     for (i = 12; i > 0 && *string != '\0'; i--)
  319.     {
  320.         *buffer = toupper(*string);
  321.         buffer+=1;
  322.         string+=1;
  323.     }
  324. }
  325.