?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.         CCONFIG2.C: Second primary source file for the CCONFIG
  3.                     utility. See CCONFIG.C for essential information
  4. */
  5.  
  6. #include <stdio.h>
  7. #include "cconfig.h"
  8.  
  9. dooptim()
  10. {
  11.         char c;
  12.         int i;
  13.  
  14.         p("CODE OPTIMIZATION CONTROL:\n")
  15.         p("Compiled BDS C code can be optimized for either speed or space,")
  16.         p("through the use of several unique 'tuning' controls. The")
  17.         p("configuration you are about to perform sets only the default")
  18.         p("optimization mode; any")
  19.         p("compilation may be individually tailored by using the -o and -z")
  20.         p("CC command-line options.\n\n")
  21.         p("There are three code optimization modes for BDS C: ")
  22.         p("'fast', 'short' and 'extended-short'.\n\n")
  23.         p("FAST mode causes all code sequences to run")
  24.         p("as fast as possible; this can be achieved by using the \"-o\" and")
  25.         p("\"-e <xxxx>\" CC command-line options while making all variables")
  26.         p("in the program external.\n")
  27.         p("SHORT mode replaces several common code sequences by")
  28.         p("calls to equivalent subroutines in the run-time package.")
  29.         p("This slows execution down a bit, due to the subroutine overhead,")
  30.         p("but saves considerable space. This is the default")
  31.         p("mode set in the distribution package.\n")
  32.  
  33.         p("(Press RETURN to continue)"); getch();
  34.  
  35.         p("EXTENDED-SHORT mode does everything that simple-short mode does,")
  36.         p("but")
  37.         p("also takes advantage of any unused system restart vectors that")
  38.         p("may be available on a SPECIFIC target computer system.")
  39.         p("This is accomplished by collapsing")
  40.         p("certain very common, short (3-6 byte) code sequences into")
  41.         p("1-byte RST instructions. To use this mode you must first know")
  42.         p("which RST vectors")
  43.         p("are available on the target system. Then you change the")
  44.         p("appropriate symbols (ZOPT1-ZOPT7)")
  45.         p("in the run-time package source file and re-assemble the run-time")
  46.         p("package. Finally, the \"-z\" CC command-line option is")
  47.         p("used to tell CC which RST vectors are available.\n")
  48.  
  49.   go:   p("\nPlease choose the default optimization mode:\n")
  50.         p("Fast (F), Short (S), or Extended-Short (E): ")
  51.  
  52.         switch(c = toupper(getch()))
  53.         {
  54.           case 'F': optim = 0;
  55.                     break;
  56.  
  57.           case 'S': optim = 0x80;
  58.                     break;
  59.  
  60.           case 'E': optim = 0x80;
  61.                     p("For extended mode, you need to specifiy those restart")
  62.                     p("vectors that are guaranteed to be unused by any other")
  63.                     p("software on the target system. Any restart vector")
  64.                     p("except RST 0 may be used, i.e., RST 1 through RST 7.\n")
  65.                     p("Answer 'y' or 'n' to each query to specify if the")
  66.                     p("respective RST vector is available")
  67.                     p("for extended-short RST optimization:\n")
  68.                     for (i = 1; i < 8; i++)
  69.                     {
  70.                         p("RST ")
  71.                         putchar(i+'0');
  72.                         p(" ? ")
  73.                         optim |= yesp() << (i - 1);
  74.                     }
  75.                     break;
  76.  
  77.           default:  p("Invalid selection. Try again:\n");
  78.                     goto go;
  79.         }
  80. }
  81.  
  82. char *gets0(str)        /* Accept text input, ^Z aborts back to menu level */
  83. char *str;
  84. {
  85.         gets(str);
  86.         if (igsp(str) == 'Z'-0x40)
  87.                 longjmp(jbuf);
  88.         return str;
  89. }
  90.  
  91.  
  92. int yesp()
  93. {
  94.         char c;
  95.         while (1)
  96.         {
  97.                 column = 1;             /* prevent spurious newlines */
  98.  
  99.                 if ((c = toupper(igsp(gets0(strbuf)))) == 'Y')
  100.                         return TRUE;
  101.                 else if (c == 'N')
  102.                         return FALSE;
  103.                 p("Please answer 'yes' or 'no'... ? ")
  104.         }
  105. }
  106.  
  107.  
  108. display()
  109. {
  110.         int i;
  111.  
  112.         p("\nThe configuration options are currently set as follows:\n\n")
  113.  
  114.         p(" Code#       Option                   Current Setting\n")
  115.         p(" -----       ------                   ---------------")
  116.         p("\n  0:       Default Drive           ")
  117.         if (defdsk == 0xff)
  118.                 p("Currently logged drive")
  119.         else
  120.                 printf("Drive %c:", defdsk + 'A');
  121.  
  122.         p("\n  1:       Default User Area       ")
  123.         if (defusr == 0xff)
  124.                 p("Currently logged user area")
  125.         else
  126.                 printf("User %d", defusr);
  127.  
  128.         p("\n  2:       Submit File Drive       ")
  129.         if (defsub == 0xff)
  130.                 p("Currently logged drive")
  131.         else
  132.                 printf("Drive %c:", defsub + 'A');
  133.  
  134.         p("\n  3:       Console Interrupts      ")
  135.         if (conpol) p("Enabled") else p("Disabled")
  136.  
  137.         p("\n  4:       Suppress Warm Boot?     ")
  138.         if (wboote) p("No") else p("Yes")
  139.  
  140.         p("\n  5:       Strip Source Parity?    ")
  141.         if (pstrip) p("Yes") else p("No")
  142.  
  143.         p("\n  6:       Recognize User Areas?   ")
  144.         if (nouser) p("No") else p("Yes")
  145.  
  146.         p("\n  7:       Write RED Error File?   ")
  147.         if (werrs) p("Yes") else p("No")
  148.  
  149.         p("\n  8:       Optimization Mode       ")
  150.         if (optim == 0)
  151.                 p("Fast Execution, Long Code Sequences")
  152.         else
  153.         {
  154.                 p("Short Code, ")
  155.                 if (optim == 0x80)
  156.                         p("No Restarts")
  157.                 else
  158.                 {
  159.                         p("Use RST vectors: ")
  160.                         for (i = 1; i < 8; i++)
  161.                         if (optim & (1 << (i - 1)))
  162.                                 printf("%d ",i);
  163.                 }
  164.         }
  165.  
  166.         p("\n  9:       Default CDB RST Vector  ")
  167.         printf("RST %d", cdbrst);      
  168.  
  169.         p("\n\n")
  170. }
  171.  
  172. read_block()
  173. {
  174.         if ((fd_cc = open("CC.COM", 2)) == ERROR ||
  175.             (fd_clink = open("CLINK.COM", 2)) == ERROR)
  176.         {
  177.            p("\nCCONFIG requires copies of both CC.COM and CLINK.COM")
  178.            p("to be present in the currently logged directory. Please copy")
  179.            p("them to this directory now, then run CCONFIG again.\n")
  180.                 exit();
  181.         }
  182.         if (read(fd_cc, secbuf, 1) != 1)
  183.         {
  184.                 p("Disk error reading CC.COM.")
  185.                 exit();
  186.         }
  187.         movmem(&secbuf[0x55], cblock, NBYTES);
  188. }
  189.  
  190. write_block()
  191. {
  192.         movmem(cblock, &secbuf[0x55], NBYTES);
  193.         seek(fd_cc, 0, 0);
  194.         if (write(fd_cc, secbuf, 1) == 1)
  195.                 close(fd_cc);
  196.         else
  197.         {
  198.                 p("\nError writing CC.COM.")
  199.          foo:   p("Please place fresh copies of CC.COM and")
  200.                 p("CLINK.COM in the current directory, and run CCONFIG")
  201.                 p("again. Sorry, but I don't know why this happened.\n")
  202.                 exit();
  203.         }
  204.  
  205.         read(fd_clink, secbuf, 1);
  206.         movmem(cblock, &secbuf[0x03], NBYTES);
  207.         seek(fd_clink, 0, 0);
  208.         if (write(fd_clink, secbuf, 1) == 1)
  209.                 close(fd_clink);
  210.         else
  211.         {
  212.                 p("\nError writing CLINK.COM.")
  213.                 goto foo;
  214.         }
  215.  
  216.         p("\nCC.COM and CLINK.COM successfully updated.\n");
  217. }
  218.  
  219. prnt(str)       /* print given text, automatically filling to length of line */
  220. char *str;
  221. {
  222.         char c;
  223.  
  224.         while (c = *str++)
  225.         {
  226.                 if (c != '\n' && (wdlen(str) + column++) < (MAXCOL - 3))
  227.                 {
  228.                         putchar(c);
  229.                         if (!*str)
  230.                                 putchar(' ');
  231.                         continue;
  232.                 }
  233.  
  234.                 putchar('\n');
  235.  
  236.                 if (!isspace(c))
  237.                         putchar(c);
  238.  
  239.                 column = 1;
  240.         }
  241. }
  242.  
  243.  
  244. int getch()     /* get a char of text */
  245. {
  246.         int c;
  247.         if ((c = getchar()) == -1)
  248.                 longjmp(jbuf);
  249.         p("\n")
  250.         return c;
  251. }
  252.  
  253.  
  254. int wdlen(txt)  /* return length of text word */
  255. char *txt;
  256. {
  257.         int i;
  258.         for (i = 0; *txt && !isspace(*txt++); i++)
  259.                 ;
  260.         return i;
  261. }
  262.  
  263.  
  264. int ask(txt)
  265. char *txt;
  266. {
  267.         char strbuf[30];
  268.  
  269.         if (txt)
  270.                 p(txt)
  271.  
  272.         gets(strbuf);
  273.  
  274.         column = 0;
  275.  
  276.         if (tolower(igsp(strbuf)) == 'y')
  277.                 return TRUE;
  278.         else
  279.                 return FALSE;
  280. }
  281.  
  282. char igsp(txt)          /* return first non-space character */
  283. char *txt;
  284. {
  285.         char c;
  286.         while (isspace(c = *txt++))
  287.                 ;
  288.         return c;
  289. }
  290.  
  291. init()
  292. {
  293.  
  294.         int dodefdsk(), dodefusr(), dodefsub(), doconpol(), dowboote();
  295.         int dopstrip(), donouser(), dowerrs(), dooptim(), docdbrst();
  296.  
  297.         initptr(&funcs, &dodefdsk, &dodefusr, &dodefsub, &doconpol, &dowboote,
  298.                  &dopstrip, &donouser, &dowerrs, &dooptim, &docdbrst, NULL);
  299.  
  300.         made_changes = column = 0;
  301. }
  302.