home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / TIERRA / TTURBO.C < prev   
C/C++ Source or Header  |  1992-09-09  |  12KB  |  469 lines

  1. /* ======================================================================*/
  2. /* tturbo.c 9-9-92 support for Turbo C frontend for
  3.    Tierra Simulator V4.0: Copyright (c) 1992 Dan Pirone & Virtual Life
  4.    written by Daniel pirone
  5.    v 1.0
  6. */
  7. /* ======================================================================*/
  8. #include <conio.h>
  9. #include <graphics.h>
  10. /* ======================================================================*/
  11.  
  12. int  DispText = 11, DispBack = 2, InfoText = 5, InfoBack = 3;
  13.  
  14. void FEExit(ENO)
  15. I32s ENO;
  16. {   sleep(1); textmode(C80);
  17. /*  textattr(15); */
  18.     textbackground(0);
  19.     textcolor(15);
  20.     clrscr(); exit(ENO);
  21. }
  22.  
  23. /* ======================================================================*/
  24. #define FECeol() clreol()
  25. /* ======================================================================*/
  26.  
  27. int FEGetc()
  28. {
  29. return getch();
  30. }
  31.  
  32. void FEMemCheck(msg)
  33. I8s  *msg;
  34. {
  35.     FEPrintf(1, 11, 0, "%s\n", msg);
  36.     FEPrintf(1, 12, 0, "%ld,%ld\n", InstExe.m, InstExe.i);
  37.         if (strncmp(msg,"Out of Memory", 13));
  38.     {   FEPrintf(1, 13, 0, "Hit any key to continue...\n");
  39.         FEGetc();
  40.     }
  41. }
  42.  
  43. /* ======================================================================*/
  44. /* called immediately after the soup_in file is read */
  45. /* an opportunity to interactively set soup_in vars */
  46. void FEStartup()
  47. {   FILE  *inf;
  48.     I8s tt, first[12], second[12];
  49.     I16s  gmode, color;
  50.  
  51. #if __TURBOC__ >= 0x200         /* deal with older compilers */
  52. FE_DV_Mode = DETECT;
  53. detectgraph(&FE_DV_Mode,&gmode );
  54. #endif
  55.  
  56.     if(inf = fopen("tcolors.cfg","r"))
  57.     {   fgets(Buff, 84, inf);
  58.         do
  59.         {   if (*Buff != '#' && strlen(Buff) > 3)
  60.             {   sscanf(Buff, "%11s%11s%d", first, second, &color);
  61.                 if (!strcmp(first,"information"))
  62.                 {   if (!strcmp(second,"text:"))
  63.                         InfoText = color;
  64.                     else if (!strcmp(second,"background:"))
  65.                         InfoBack = color;
  66.                 }
  67.                 else if (!strcmp(first,"display"))
  68.                 {   if (!strcmp(second,"text:"))
  69.                         DispText = color;
  70.                     else if (!strcmp(second,"background:"))
  71.                         DispBack = color;
  72.                 }
  73.             }
  74.         } while (fgets(Buff, 84, inf) != NULL);
  75.         fclose(inf);
  76.     }
  77.  
  78. fe_width = 57;
  79. IMode = PLN_STATS;
  80. PLN_X = 1;
  81. PLN_Y = 3;
  82. MSG_X = 1;
  83. MSG_Y = PLN_Y;
  84. ERR_X = 1;
  85. HLP_X = 1;
  86.  
  87. textmode(C80);   
  88. /* textattr(43); */
  89.     textbackground(DispBack);
  90.     textcolor(DispText);
  91. clrscr();
  92.  
  93. /* Title screen */
  94. gotoxy(35,5);
  95. cprintf("TIERRA");
  96. gotoxy(34,7);
  97. cprintf("July  92");
  98. gotoxy(29,9);
  99. cprintf("Artificial Life System");
  100. gotoxy(37,11);
  101. cprintf("By");
  102. gotoxy(31,13);
  103. cprintf("Dr. Thomas S. Ray");
  104. gotoxy(20,15);
  105. cprintf("Daniel Pirone, Tom Uffner & Marc Cygnus");
  106.  
  107. sleep(3);
  108. FE_DosVideoToggle(0);
  109. FEPrintf(HLP_X,HLP_Y,1,
  110. "                     Tierra initializing, please wait ...                  "
  111. );
  112.  
  113. }
  114. /* ======================================================================*/
  115. void FEPrintf(I32s scr_x, I32s scr_y, I32s scr_a,...)
  116. {
  117.     va_list ap;
  118.  
  119.  
  120.     I8s *msg_str,
  121.         buf[80];
  122.     I8s CF = 0;
  123.     va_start(ap,scr_a);
  124.  
  125.     if((scr_x < 1) || (scr_x > 80) || (scr_y < 1) || (scr_y > HLP_Y))
  126.        {sound(100); return ; }
  127.     if (scr_a)
  128.     {   textbackground(InfoBack);
  129.         textcolor(InfoText);
  130.     /*  textattr(53); */
  131.     }
  132.  
  133.     if (*(msg_str = va_arg(ap, I8s *)) != 0)
  134.        {
  135.        vsprintf(buf,msg_str,ap);
  136.        if (buf[strlen(buf)-1] == '\n') {buf[strlen(buf)-1]='\0';CF=1;}
  137.        gotoxy(scr_x,scr_y);
  138.        cprintf(buf);
  139.        if (CF) clreol();
  140.        }
  141.     va_end(ap);
  142.     if (scr_a)
  143.     {   textbackground(DispBack);
  144.         textcolor(DispText);
  145.     /*  textattr(43); */
  146.     }
  147.  
  148. }
  149.  
  150. /* ======================================================================*/
  151. void FEStats()
  152. { if (GeneBnker)
  153.   {  FEPrintf(1,1,1,
  154.      "InstExec  = %ld,%6.6ld  Cells = %4ld  Genotypes = %4ld  Sizes =%4ld ",
  155.          InstExe.m,InstExe.i,NumCells, NumGenotypes, NumSizes);
  156.      FEPrintf(1,2,1, 
  157.        "Extracted = %-20.20s                                                ",
  158.        ExtrG);
  159.   }
  160.   else /* (GeneBnker) */
  161.   {  FEPrintf(1,1,1,
  162.      "InstExec  = %ld,%6.6ld  Cells = %4ld ", InstExe.m,InstExe.i,NumCells);
  163.   }
  164. }
  165. /* ======================================================================*/
  166.  
  167. /*-----------------------------------------------------------------------*/
  168.  
  169. void FEMenu()
  170. {
  171.    I8s  answer;
  172.    I32s tsz;
  173.    I8s  data[85];
  174.  
  175. #ifdef ALCOMM
  176.    AL_run_flag = 1;
  177. #endif
  178.    while(1)
  179.       {
  180.       FEPrintf(HLP_X,HLP_Y,1,
  181. "TIERRA |  i-info  v-var  s-save  q-save&quit  Q-quit  m-misc c-continue |->"
  182.       );
  183.       answer = getch();
  184.  
  185.       if (answer == 'c')
  186.           {
  187.           break;
  188.           }
  189.       if (answer == 'v')
  190.       { IMode = 69;
  191.          FE_DosVideoToggle(0);
  192.          FEPrintf(MSG_X,MSG_Y,0,
  193.                   "To alter any global variable from soup_in, type\n");
  194.          FEPrintf(MSG_X,MSG_Y+1,0,
  195.                   "the variable name (using proper case), a space,\n");
  196.          FEPrintf(MSG_X,MSG_Y+2,0,
  197.                   "an equal sign, a space, and the new value.\n");
  198.          FEPrintf(MSG_X,MSG_Y+3,0,
  199.                   "Use no space at start of line.  Some examples:\n");
  200.          FEPrintf(MSG_X,MSG_Y+4,0, "alive = 0\n");
  201.          FEPrintf(MSG_X,MSG_Y+5,0, "DistProp = .6\n");
  202.          FEPrintf(MSG_X,MSG_Y+6,0,"GenebankPath = newpath/\n");
  203.          FEClrmsg(MSG_Y+7);
  204.          gotoxy(HLP_X,HLP_Y-2);
  205.          if ((gets(data)) == NULL) break;
  206. /* DAN get a string */
  207.     if (!GetAVar(data))
  208.         FEError(-1600,NOEXIT,NOWRITE,
  209.             "Tierra FEMenu() Not a valid soup_in variable: %s", data);
  210.         IMode = PLN_STATS;
  211.         ToggleLog(0L);
  212.        }
  213.  
  214.       if (answer == 'i')
  215.          {
  216. #ifdef ERROR
  217.          FEPrintf(1,2,1,
  218.                   "Coreleft  = %lu TotMemUse  = %6ld  FreeMemCurrent = %6ld"
  219.                   ,(unsigned long) coreleft(), TotMemUse, FreeMemCurrent);
  220. #else
  221.          FEPrintf(1,2,1,
  222.                   "Coreleft  = %lu FreeBlocks = %6ld  FreeMemCurrent = %6ld"
  223.                   ,(unsigned long) coreleft(), FreeBlocks, FreeMemCurrent);
  224. #endif
  225.          FEPrintf(HLP_X,HLP_Y,1,
  226. "INFO   | p-plan  s-size_histo g-gen_histo m-mem_histo z-size_query      |->" 
  227. );
  228.          answer = getch();
  229.          if (answer == 'z')
  230.             {
  231.             IMode = 69;
  232.             FE_DosVideoToggle(FE_DV_Mode);
  233.             FEClrmsg(MSG_Y);
  234.             sprintf(mes[0],
  235.             "Enter a size class ( eg: 80 ) to examine -> ");
  236.             FEMessage(1,mes);
  237.             gotoxy(HLP_X,HLP_Y-2);
  238.          if ((gets(data)) == NULL) break;
  239.             sscanf(data,"%d", &tsz);
  240.             FEClrmsg(MSG_Y);
  241.             if (Hist != NULL)
  242.             {  thfree(Hist);
  243.                Hist = NULL;
  244.             }
  245.             query_size((I16u)tsz);
  246.             FEPrintf(HLP_X,HLP_Y,1,
  247. "INFO   | z-size_query       Press any key to continue ...               |->" 
  248. );
  249.             getch();
  250.             IMode = PLN_STATS;
  251.             FE_DosVideoToggle(0);
  252.             }
  253.  
  254.          if (answer == 'p')
  255.             {
  256.             IMode = 69;
  257.             FE_DosVideoToggle(0);
  258.             FEClrmsg(MSG_Y);
  259.             sprintf(mes[0],
  260.              "Now in Plan Display mode, updated every million time steps \n");
  261.             FEMessage(1,mes);
  262.             IMode = PLN_STATS;
  263.             if (Hist != NULL)
  264.               {
  265.           thfree(Hist);
  266.               Hist = NULL;
  267.               }
  268.             }
  269.          if (answer == 's')
  270.             {
  271.             if(GeneBnker)
  272.                {
  273.                IMode = SIZ_HIST;
  274.                FE_DosVideoToggle(FE_DV_Mode);
  275.                query_species(fe_lines);
  276.                }
  277.             }
  278.          if (answer == 'm')
  279.             {
  280.             if(GeneBnker)
  281.                {
  282.                IMode = SIZM_HIST;
  283.                FE_DosVideoToggle(FE_DV_Mode);
  284.                query_species(fe_lines);
  285.                }
  286.             }
  287.          if (answer == 'g')
  288.             {  
  289.             if(GeneBnker) 
  290.                {
  291.                IMode = GEN_HIST;
  292.                FE_DosVideoToggle(FE_DV_Mode);
  293.                query_species(fe_lines);
  294.                }
  295.             }
  296.          answer = ' ';
  297.        } 
  298.       if (answer == 's')
  299.          {  
  300.          FEError(-1601,NOEXIT,WRITE," ");
  301.          }
  302.       if (answer == 'q')
  303.          {
  304.          FEError(-1602,EXIT,WRITE," ");
  305.          }
  306.       if (answer == 'm')
  307.           {
  308.           IMode = 69;
  309.           FE_DosVideoToggle(0);
  310.           FEClrmsg(MSG_Y);
  311.           FEPrintf(1,2,1,"VER=%1.2f INST=%d PLOIDY=%d  %s  %s  %s\n",
  312.                    VER,INST,PLOIDY,
  313. #ifdef ERROR
  314. "ERROR",
  315. #else
  316. "",
  317. #endif
  318. #ifdef MEM_PROF
  319. "MEM_PROF",
  320. #else
  321. "",
  322. #endif
  323. #ifdef MICRO
  324. "MICRO"
  325. #else
  326. ""
  327. #endif
  328.           );
  329.  
  330.           FEPrintf(HLP_X,HLP_Y,1,
  331. "MISC |  H-Histo Logging  S-DOS Shell  I-Inject Gene  %s  |->\n",
  332.  
  333. #ifdef MICRO
  334.           "M-Micro Toggle"
  335. #else
  336.           ""
  337. #endif
  338.          );
  339.          gotoxy(HLP_X+79,HLP_Y);
  340.          answer = getch();
  341.          if (answer == 'H')
  342.             {
  343.             HistPrint = (Log && !HistPrint)? 1 : 0;
  344.             sprintf(mes[0],
  345.              "%s \n",(Log)? (HistPrint)? "Logging Histograms \n":
  346.                                          "NOT Logging Histograms \n" :
  347.                            "Log NOT on ! \n");
  348.             FEMessage(1,mes);
  349.             }
  350. #ifdef MICRO
  351.          if (answer == 'M')
  352.              {
  353.              if(MC_step == -1L) MC_step = 0L;
  354.              else if(MC_step == 0L) MC_step = 1L;
  355.              else {MC_step =-1L; if(tfp_log != NULL) Log = 1L;}
  356.              sprintf(mes[0]," MICRO STEP Mode = %s\n",
  357.              (MC_step == -1)?"off": (MC_step == 1)?"keypress":"delay");
  358.              FEMessage(1,mes);
  359.              }
  360. #endif /* MICRO */
  361.  
  362.           if (answer == 'S')
  363.              {
  364.              FEPrintf(HLP_X,HLP_Y,1,
  365.              "TIERRA: shell (%s), type exit to return ... ",SHELL);
  366.              system(SHELL);
  367.              FE_DosVideoToggle(0);
  368.              }
  369.         if (answer == 'I')
  370.              {
  371.              sprintf(mes[0],"INJECT GENE TO RUNNING SIMULATION\n");
  372.              sprintf(mes[1],"Enter gene name ( eg 0080aaa) or \n");
  373.              sprintf(mes[2],"Enter abort to cancel\n");
  374.              FEMessage(3,mes);
  375.              FEPrintf(HLP_X,HLP_Y-2,0," ");
  376.              fgets(data,84,stdin);
  377.              if ((data[0] >= '0') && (data[0] <= '9') )
  378.         {
  379.                 InjectFromBank(data, -1, 0);
  380.         }
  381.          else
  382.               {
  383.                 FEError(-13667,NOEXIT,NOWRITE,"User abort of Injection!"); 
  384.         }
  385.              }
  386.   
  387.           answer = ' ';
  388.           IMode = PLN_STATS;
  389.           }     /* end of misc */
  390.  
  391.       if (answer == 'Q') FEExit(-1);
  392.       }         /* end while loop */
  393. FEPrintf(HLP_X,HLP_Y,1,
  394. "                         Press Any Key for menu ...                        "
  395. );
  396. }
  397.  
  398. /*-----------------------------------------------------------------------*/
  399.  
  400. /* ======================================================================*/
  401. void FEClrmsg(n)
  402. I32s n;
  403. {
  404. I8s t;
  405. if(n <0) return;
  406. for(t= n;  t < fe_lines; t++)
  407.     {
  408.     gotoxy(MSG_X,t);
  409.     clreol();
  410.     }
  411.  
  412. }
  413. /* ======================================================================*/
  414. void FE_DosVideoToggle(mode)
  415. I16s mode;
  416. {
  417. int tt;
  418.  
  419. #if __TURBOC__ >= 0x200         /* deal with older compilers */
  420. if (mode == EGA)
  421.    {
  422.    textmode(C4350); /* use C4350 for ega/vga */
  423.    fe_lines = 42;
  424.    ERR_Y = 42;
  425.    HLP_Y = 43;
  426.    }
  427. else
  428. if (mode == VGA)
  429.    {
  430.    textmode(C4350);
  431.    fe_lines = 49;
  432.    ERR_Y = 49;
  433.    HLP_Y = 50;
  434.    }
  435. else
  436. #endif /* __TURBOC__ >= 0x200 */
  437.    {
  438.    textmode(C80);   
  439.    fe_lines = 24;
  440.    ERR_Y = 24;
  441.    HLP_Y = 25;
  442.    }
  443. /*  textattr(43); */
  444.     textbackground(DispBack);
  445.     textcolor(DispText);
  446. clrscr();
  447.  
  448. /*  textattr(53); */
  449.     textbackground(InfoBack);
  450.     textcolor(InfoText);
  451. for(tt = 1; tt < 81; tt++)
  452.    {
  453.    gotoxy(tt,1);
  454.    cprintf(" ");
  455.    gotoxy(tt,2);
  456.    cprintf(" ");
  457.    gotoxy(tt,ERR_Y);
  458.    cprintf(" ");
  459.    gotoxy(tt,HLP_Y);
  460.    cprintf(" ");
  461.    }
  462. /*  textattr(43); */
  463.     textbackground(DispBack);
  464.     textcolor(DispText);
  465. FEStats();
  466. }
  467. /* ======================================================================*/
  468. /* ======================================================================*/
  469.