home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / frasrc18.zip / REALDOS.C < prev    next >
C/C++ Source or Header  |  1993-05-24  |  53KB  |  1,767 lines

  1. /*
  2.     Miscellaneous C routines used only in DOS Fractint.
  3. */
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7. #ifndef XFRACT
  8. #include <dos.h>
  9. #include <io.h>
  10. #include <process.h>
  11. #endif
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <fcntl.h>
  15. #include <math.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18. #include "fractint.h"
  19. #include "fractype.h"
  20. #include "helpdefs.h"
  21. #include "prototyp.h"
  22.  
  23. /* routines in this module    */
  24.  
  25. static int menu_checkkey(int curkey,int choice);
  26.  
  27. int release=1800; /* this has 2 implied decimals; increment it every synch */
  28. int patchlevel=0; /* patchlevel for DOS version */
  29. int xrelease=109;
  30.  
  31. /* fullscreen_choice options */
  32. #define CHOICERETURNKEY 1
  33. #define CHOICEMENU    2
  34. #define CHOICEHELP    4
  35.  
  36. extern char diskfilename[];
  37. extern int using_jiim;
  38. extern int  xdots, ydots, sxdots, sydots, sxoffs, syoffs;
  39. extern int  colors;
  40. extern int  dotmode;
  41. extern int  oktoprint;
  42. extern int  textrow, textcol, textrbase, textcbase;
  43. extern int  debugflag;
  44. extern int  fractype;
  45. extern int  calc_status;
  46. extern double param[];
  47. extern int  tabmode;
  48. extern int  color_dark,color_medium,color_bright;
  49. extern int  lookatmouse;
  50. extern int  gotrealdac;
  51. extern int  reallyega;
  52. extern int  extraseg;
  53. extern int  active_system;
  54. extern int  first_init;
  55. extern int initbatch;        /* 1 if batch run (no kbd)  */
  56.  
  57.  
  58. /* int stopmsg(flags,message) displays message and waits for a key:
  59.      message should be a max of 9 lines with \n's separating them;
  60.        no leading or trailing \n's in message;
  61.        no line longer than 76 chars for best appearance;
  62.      flag options:
  63.        &1 if already in text display mode, stackscreen is not called
  64.       and message is displayed at (12,0) instead of (4,0)
  65.        &2 if continue/cancel indication is to be returned;
  66.       when not set, "Any key to continue..." is displayed
  67.       when set, "Escape to cancel, any other key to continue..."
  68.       -1 is returned for cancel, 0 for continue
  69.        &4 set to suppress buzzer
  70.        &8 for Fractint for Windows & parser - use a fixed pitch font
  71.       &16 for info only message (green box instead of red in DOS vsn)
  72.    */
  73. int stopmsg (int flags, CHAR far *msg)
  74. {
  75.    int ret,toprow,color,savelookatmouse;
  76.    if (active_system == 0 /* DOS */
  77.      && first_init) {      /* & cmdfiles hasn't finished 1st try */
  78.       setvideotext();
  79.       buzzer(2);
  80.       putstring(0,0,15,"*** Error during startup:");
  81.       putstring(2,0,15,msg);
  82.       movecursor(8,0);
  83. #ifdef XFRACT
  84.       sleep(1);
  85.       UnixDone();
  86. #endif
  87.       exit(1);
  88.       }
  89.    if (initbatch == 1) { /* in batch mode */
  90.       initbatch = 4; /* used to set errorlevel */
  91.       return (-1);
  92.       }
  93.    ret = 0;
  94.    savelookatmouse = lookatmouse;
  95.    lookatmouse = -13;
  96.    if ((flags & 1))
  97.       blankrows(toprow=12,10,7);
  98.    else {
  99.       stackscreen();
  100.       toprow = 4;
  101.       movecursor(4,0);
  102.       }
  103.    textcbase = 2; /* left margin is 2 */
  104.    putstring(toprow,0,7,msg);
  105.    if (flags & 2)
  106.       putstring(textrow+2,0,7,"Escape to cancel, any other key to continue...");
  107.    else
  108.       putstring(textrow+2,0,7,"Any key to continue...");
  109.    textcbase = 0; /* back to full line */
  110.    color = (flags & 16) ? C_STOP_INFO : C_STOP_ERR;
  111.    setattr(toprow,0,color,(textrow+1-toprow)*80);
  112.    movecursor(25,80);    /* cursor off */
  113.    if ((flags & 4) == 0)
  114.       buzzer((flags & 16) ? 0 : 2);
  115.    while (keypressed()) /* flush any keyahead */
  116.       getakey();
  117.    if (getakeynohelp() == ESC)
  118.       ret = -1;
  119.    if ((flags & 1))
  120.       blankrows(toprow,10,7);
  121.    else
  122.       unstackscreen();
  123.    lookatmouse = savelookatmouse;
  124.    return ret;
  125. }
  126.  
  127.  
  128. static char far *temptextsave = NULL;
  129. static int  textxdots,textydots;
  130.  
  131. /* texttempmsg(msg) displays a text message of up to 40 characters, waits
  132.       for a key press, restores the prior display, and returns (without
  133.       eating the key).
  134.       It works in almost any video mode - does nothing in some very odd cases
  135.       (HCGA hi-res with old bios), or when there isn't 10k of temp mem free. */
  136. int texttempmsg(char *msgparm)
  137. {
  138.    if (showtempmsg(msgparm))
  139.       return(-1);
  140. #ifndef XFRACT
  141.    while (!keypressed()) {} /* wait for a keystroke but don't eat it */
  142. #else
  143.    waitkeypressed(0); /* wait for a keystroke but don't eat it */
  144. #endif
  145.    cleartempmsg();
  146.    return(0);
  147. }
  148.  
  149. void freetempmsg()
  150. {
  151.    if(temptextsave != NULL)
  152.       farmemfree(temptextsave);
  153.    temptextsave = NULL;
  154. }
  155.  
  156. int showtempmsg(char *msgparm)
  157. {
  158.    static long size = 0;
  159.    extern int color_dark,color_medium;
  160.    CHAR msg[41];
  161.    BYTE buffer[640];
  162.    char far *fartmp;
  163.    BYTE far *fontptr;
  164.    BYTE *bufptr;
  165.    int i,j,k,xrepeat,yrepeat,fontchar,charnum;
  166.    int save_sxoffs,save_syoffs;
  167.    strncpy(msg,msgparm,40);
  168.    msg[40] = 0; /* ensure max message len of 40 chars */
  169.    if (dotmode == 11) { /* disk video, screen in text mode, easy */
  170.       dvid_status(0,msg);
  171.       return(0);
  172.       }
  173.    if ((fontptr = findfont(0)) == NULL) { /* old bios, no font table? */
  174.       if (oktoprint == 0           /* can't printf */
  175.     || sxdots > 640 || sydots > 200) /* not willing to trust char cell size */
  176.      return(-1); /* sorry, message not displayed */
  177.       textydots = 8;
  178.       textxdots = sxdots;
  179.       }
  180.    else {
  181.       xrepeat = (sxdots >= 640) ? 2 : 1;
  182.       yrepeat = (sydots >= 300) ? 2 : 1;
  183.       textxdots = strlen(msg) * xrepeat * 8;
  184.       textydots = yrepeat * 8;
  185.       }
  186.    /* worst case needs 10k */
  187.    if(temptextsave !=NULL)
  188.       if(size != (long)textxdots * (long)textydots)
  189.          freetempmsg();      
  190.    size = (long)textxdots * (long)textydots;
  191.    save_sxoffs = sxoffs;
  192.    save_syoffs = syoffs;
  193.    sxoffs = syoffs = 0;
  194.    if(temptextsave == NULL) /* only save screen first time called */
  195.    {
  196.       if ((temptextsave = farmemalloc(size)) == NULL)
  197.          return(-1); /* sorry, message not displayed */
  198.       fartmp = temptextsave;
  199.       for (i = 0; i < textydots; ++i) {
  200.          get_line(i,0,textxdots-1,buffer);
  201.          for (j = 0; j < textxdots; ++j) /* copy it out to far memory */
  202.          *(fartmp++) = buffer[j];
  203.          }
  204.       }
  205.    if (fontptr == NULL) { /* bios must do it for us */
  206.       home();
  207.       printf(msg);
  208.       }
  209.    else { /* generate the characters */
  210.       find_special_colors(); /* get color_dark & color_medium set */
  211.       for (i = 0; i < 8; ++i) {
  212.      memset(buffer,color_dark,640);
  213.      bufptr = buffer;
  214.      charnum = -1;
  215.      while (msg[++charnum] != 0) {
  216.         fontchar = *(fontptr + msg[charnum]*8 + i);
  217.         for (j = 0; j < 8; ++j) {
  218.            for (k = 0; k < xrepeat; ++k) {
  219.           if ((fontchar & 0x80) != 0)
  220.              *bufptr = color_medium;
  221.           ++bufptr;
  222.           }
  223.            fontchar <<= 1;
  224.            }
  225.         }
  226.      for (j = 0; j < yrepeat; ++j)
  227.         put_line(i*yrepeat+j,0,textxdots-1,buffer);
  228.      }
  229.       }
  230.    sxoffs = save_sxoffs;
  231.    syoffs = save_syoffs;
  232.    return(0);
  233. }
  234.  
  235. void cleartempmsg()
  236. {
  237.    BYTE buffer[640];
  238.    char far *fartmp;
  239.    int i,j;
  240.    int save_sxoffs,save_syoffs;
  241.    if (dotmode == 11) /* disk video, easy */
  242.       dvid_status(0,"");
  243.    else if (temptextsave != NULL) {
  244.       save_sxoffs = sxoffs;
  245.       save_syoffs = syoffs;
  246.       sxoffs = syoffs = 0;
  247.       fartmp = temptextsave;
  248.       for (i = 0; i < textydots; ++i) {
  249.      for (j = 0; j < textxdots; ++j) /* copy back from far memory */
  250.         buffer[j] = *(fartmp++);
  251.      put_line(i,0,textxdots-1,buffer);
  252.      }
  253.      if(using_jiim == 0)  /* jiim frees memory with freetempmsg() */
  254.      {
  255.          farmemfree(temptextsave);
  256.          temptextsave = NULL;
  257.       }
  258.       sxoffs = save_sxoffs;
  259.       syoffs = save_syoffs;
  260.       }
  261. }
  262.  
  263.  
  264. void blankrows(int row,int rows,int attr)
  265. {
  266.    char buf[81];
  267.    memset(buf,' ',80);
  268.    buf[80] = 0;
  269.    while (--rows >= 0)
  270.       putstring(row++,0,attr,buf);
  271.    }
  272.  
  273.  
  274. void helptitle()
  275. {
  276.    char msg[80],buf[80];
  277.    setclear(); /* clear the screen */
  278. #ifdef XFRACT
  279.    sprintf(msg,"XFRACTINT  Version %d.%02d (FRACTINT Version %d.%02d)",
  280.            xrelease/100,xrelease%100, release/100,release%100);
  281.    putstringcenter(0,0,80,C_TITLE,msg);
  282. #else
  283. #ifdef WAITE
  284.    release=1811;
  285.    patchlevel = 0;
  286.    sprintf(msg,"Special FRACTINT  Version %d.%01d",release/100,(release%100)/10);
  287. #else
  288.    sprintf(msg,"FRACTINT  Version %d.%01d",release/100,(release%100)/10);
  289. #endif
  290.    if (release%10) {
  291.       sprintf(buf,"%01d",release%10);
  292.       strcat(msg,buf);
  293.       }
  294. #ifndef XFRACT
  295.    if (patchlevel) {
  296.       sprintf(buf," Patch %d",patchlevel);
  297.       strcat(msg,buf);
  298.       }
  299. #endif
  300. #ifdef WAITE /* realdos.c */
  301.    strcat(msg," for the Waite Group's Fractal Creations 2nd Ed.");
  302. #endif /* WAITE - realdos.c */
  303.    putstringcenter(0,0,80,C_TITLE,msg);
  304. #ifdef WAITE
  305.    return;
  306. #endif
  307. #endif
  308. /* uncomment next for production executable: */
  309. /* return; */
  310.    /*NOTREACHED*/
  311.    if (debugflag == 3002) return;
  312. /* putstring(0,2,C_TITLE_DEV,"Development Version"); */
  313. /* replace above by next after creating production release, for release source */
  314.    putstring(0,3,C_TITLE_DEV, "Customized Version"); 
  315.    putstring(0,55,C_TITLE_DEV,"Not for Public Release");
  316. }
  317.  
  318.  
  319. int putstringcenter(int row, int col, int width, int attr, char far *msg)
  320. {
  321.    char buf[81];
  322.    int i,j,k;
  323.    i = 0;
  324. #ifdef XFRACT
  325.    if (width==80) width=79; /* Some systems choke in column 80 */
  326. #endif
  327.    while (msg[i]) ++i; /* strlen for a far */
  328.    if (i == 0) return(-1);
  329.    j = (width - i) / 2;
  330.    j -= (width + 10 - i) / 20; /* when wide a bit left of center looks better */
  331.    memset(buf,' ',width);
  332.    buf[width] = 0;
  333.    i = 0;
  334.    k = j;
  335.    while (msg[i]) buf[k++] = msg[i++]; /* strcpy for a far */
  336.    putstring(row,col,attr,buf);
  337.    return j;
  338. }
  339.  
  340.  
  341. #ifndef XFRACT
  342. static int screenctr=-1;
  343. #else
  344. static int screenctr=0;
  345. #endif
  346. #define MAXSCREENS 3
  347. static BYTE far *savescreen[MAXSCREENS];
  348. static int saverc[MAXSCREENS+1];
  349. static FILE *savescf=NULL;
  350. static char scsvfile[]="fractscr.tmp";
  351. extern int text_type;
  352. extern int textaddr;
  353.  
  354. void stackscreen()
  355. {
  356. #ifndef XFRACT
  357.    BYTE far *vidmem;
  358.    int savebytes;
  359.    int i;
  360.    BYTE far *ptr;
  361.    char buf[100];
  362.    saverc[screenctr+1] = textrow*80 + textcol;
  363.    if (++screenctr) { /* already have some stacked */
  364.      static char far msg[]={"stackscreen overflow"};
  365.       if ((i = screenctr - 1) >= MAXSCREENS) { /* bug, missing unstack? */
  366.      stopmsg(1,msg);
  367.      exit(1);
  368.      }
  369.       vidmem = MK_FP(textaddr,0);
  370.       savebytes = (text_type == 0) ? 4000 : 16384;
  371.       if ((ptr = savescreen[i] = farmemalloc((long)savebytes)))
  372.      far_memcpy(ptr,vidmem,savebytes);
  373.       else {
  374.      if (savescf == NULL) { /* create file just once */
  375.         if ((savescf = fopen(scsvfile,"wb")) == NULL)
  376.            goto fileproblem;
  377.         if (fwrite(buf,MAXSCREENS,16384,savescf) != 16384)
  378.            goto fileproblem;
  379.         fclose(savescf);
  380.         if ((savescf = fopen(scsvfile,"r+b")) == NULL) {
  381.         static char far msg[]={"insufficient memory, aborting"};
  382. fileproblem:   stopmsg(1,msg);
  383.            exit(1);
  384.            }
  385.         }
  386.      fseek(savescf,(long)(savebytes*i),SEEK_SET);
  387.      while (--savebytes >= 0)
  388.         putc(*(vidmem++),savescf);
  389.      }
  390.       setclear();
  391.       }
  392.    else
  393.       setfortext();
  394. #else
  395.    int i;
  396.    BYTE far *ptr;
  397.    saverc[screenctr+1] = textrow*80 + textcol;
  398.    if (++screenctr) { /* already have some stacked */
  399.          static char far msg[]={"stackscreen overflow"};
  400.       if ((i = screenctr - 1) >= MAXSCREENS) { /* bug, missing unstack? */
  401.          stopmsg(1,msg);
  402.          exit(1);
  403.          }
  404.       if (ptr = savescreen[i] = farmemalloc(sizeof(int *)))
  405.          savecurses(ptr);
  406.       else {
  407.          stopmsg(1,msg);
  408.          exit(1);
  409.         }
  410.       setclear();
  411.       }
  412.    else
  413.       setfortext();
  414. #endif
  415. }
  416.  
  417. void unstackscreen()
  418. {
  419. #ifndef XFRACT
  420.    char far *vidmem;
  421.    int savebytes;
  422.    BYTE far *ptr;
  423.    textrow = saverc[screenctr] / 80;
  424.    textcol = saverc[screenctr] % 80;
  425.    if (--screenctr >= 0) { /* unstack */
  426.       vidmem = MK_FP(textaddr,0);
  427.       savebytes = (text_type == 0) ? 4000 : 16384;
  428.       if ((ptr = savescreen[screenctr])) {
  429.      far_memcpy(vidmem,ptr,savebytes);
  430.      farmemfree(ptr);
  431.      }
  432.       else {
  433.      fseek(savescf,(long)(savebytes*screenctr),SEEK_SET);
  434.      while (--savebytes >= 0)
  435.         *(vidmem++) = getc(savescf);
  436.      }
  437.       }
  438.    else
  439.       setforgraphics();
  440.    movecursor(-1,-1);
  441. #else
  442.    BYTE far *ptr;
  443.    textrow = saverc[screenctr] / 80;
  444.    textcol = saverc[screenctr] % 80;
  445.    if (--screenctr >= 0) { /* unstack */
  446.       ptr = savescreen[screenctr];
  447.       restorecurses(ptr);
  448.       farmemfree(ptr);
  449.       }
  450.    else
  451.       setforgraphics();
  452.    movecursor(-1,-1);
  453. #endif
  454. }
  455.  
  456. void discardscreen()
  457. {
  458.    if (--screenctr >= 0) { /* unstack */
  459.       if (savescreen[screenctr])
  460.      farmemfree(savescreen[screenctr]);
  461.       }
  462.    else
  463.       discardgraphics();
  464. }
  465.  
  466.  
  467. /* --------------------------------------------------------------------- */
  468.  
  469. char speed_prompt[]="Speed key string";
  470.  
  471. int fullscreen_choice(
  472.     int options,         /* &2 use menu coloring scheme           */
  473.                  /* &4 include F1 for help in instructions */
  474.                  /* &8 add caller's instr after normal set */
  475.     char far *hdg,         /* heading info, \n delimited           */
  476.     char far *hdg2,         /* column heading or NULL               */
  477.     char far *instr,     /* instructions, \n delimited, or NULL    */
  478.     int numchoices,      /* How many choices in list           */
  479.     char **choices,      /* array of choice strings            */
  480.     int *attributes,     /* &3: 0 normal color, 1,3 highlight      */
  481.                  /* &256 marks a dummy entry           */
  482.     int boxwidth,         /* box width, 0 for calc (in items)       */
  483.     int boxdepth,         /* box depth, 0 for calc, 99 for max      */
  484.     int colwidth,         /* data width of a column, 0 for calc     */
  485.     int current,         /* start with this item               */
  486.     void (*formatitem)(),/* routine to display an item or NULL     */
  487.     char *speedstring,   /* returned speed key value, or NULL >[30]*/
  488.     int (*speedprompt)(),/* routine to display prompt or NULL      */
  489.     int (*checkkey)()    /* routine to check keystroke or NULL     */
  490. )
  491.    /* return is: n>=0 for choice n selected,
  492.          -1 for escape
  493.           k for checkkey routine return value k (if not 0 nor -1)
  494.       speedstring[0] != 0 on return if string is present
  495.       */
  496. {
  497. static char far choiceinstr1a[]="Use the cursor keys to highlight your selection";
  498. static char far choiceinstr1b[]="Use the cursor keys or type a value to make a selection";
  499. static char far choiceinstr2a[]="Press ENTER for highlighted choice, or ESCAPE to back out";
  500. static char far choiceinstr2b[]="Press ENTER for highlighted choice, ESCAPE to back out, or F1 for help";
  501. static char far choiceinstr2c[]="Press ENTER for highlighted choice, or F1 for help";
  502.  
  503.    int titlelines,titlewidth;
  504.    int reqdrows;
  505.    int topleftrow,topleftcol;
  506.    int topleftchoice;
  507.    int speedrow;  /* speed key prompt */
  508.    int boxitems;  /* boxwidth*boxdepth */
  509.    int curkey,increment,rev_increment;
  510.    int redisplay;
  511.    int i,j,k;
  512.    char far *charptr;
  513.    char buf[81];
  514.    int speed_match = 0;
  515.    char curitem[81];
  516.    char *itemptr;
  517.    int ret,savelookatmouse;
  518.  
  519.    savelookatmouse = lookatmouse;
  520.    lookatmouse = 0;
  521.    ret = -1;
  522.    if (speedstring
  523.      && (i = strlen(speedstring)) > 0) { /* preset current to passed string */
  524.       current = 0;
  525.       while (current < numchoices
  526.     && (k = strncasecmp(speedstring,choices[current],i)) > 0)
  527.      ++current;
  528.       if (k < 0 && current > 0)  /* oops - overshot */
  529.      --current;
  530.       if (current >= numchoices) /* bumped end of list */
  531.      current = numchoices - 1;
  532.       }
  533.  
  534.    while (1) {
  535.       if (current >= numchoices)  /* no real choice in the list? */
  536.      goto fs_choice_end;
  537.       if ((attributes[current] & 256) == 0)
  538.      break;
  539.       ++current;          /* scan for a real choice */
  540.       }
  541.  
  542.    titlelines = titlewidth = 0;
  543.    if (hdg) {
  544.       charptr = hdg;          /* count title lines, find widest */
  545.       i = 0;
  546.       titlelines = 1;
  547.       while (*charptr) {
  548.      if (*(charptr++) == '\n') {
  549.         ++titlelines;
  550.         i = -1;
  551.         }
  552.      if (++i > titlewidth)
  553.         titlewidth = i;
  554.      }
  555.       }
  556.  
  557.    if (colwidth == 0)          /* find widest column */
  558.       for (i = 0; i < numchoices; ++i)
  559.      if (strlen(choices[i]) > colwidth)
  560.         colwidth = strlen(choices[i]);
  561.  
  562.    /* title(1), blank(1), hdg(n), blank(1), body(n), blank(1), instr(?) */
  563.    reqdrows = 3;          /* calc rows available */
  564.    if (hdg)
  565.       reqdrows += titlelines + 1;
  566.    if (instr) {           /* count instructions lines */
  567.       charptr = instr;
  568.       ++reqdrows;
  569.       while (*charptr)
  570.      if (*(charptr++) == '\n')
  571.         ++reqdrows;
  572.       if ((options & 8))      /* show std instr too */
  573.      reqdrows += 2;
  574.       }
  575.    else
  576.       reqdrows += 2;          /* standard instructions */
  577.    if (speedstring) ++reqdrows;   /* a row for speedkey prompt */
  578.    if (boxdepth > (i = 25 - reqdrows)) /* limit the depth to max */
  579.       boxdepth = i;
  580.    if (boxwidth == 0) {       /* pick box width and depth */
  581.       if (numchoices <= i - 2) {  /* single column is 1st choice if we can */
  582.      boxdepth = numchoices;
  583.      boxwidth = 1;
  584.      }
  585.       else {              /* sort-of-wide is 2nd choice */
  586.      boxwidth = 60 / (colwidth + 1);
  587.      if (boxwidth == 0
  588.        || (boxdepth = (numchoices+boxwidth-1)/boxwidth) > i - 2) {
  589.         boxwidth = 80 / (colwidth + 1); /* last gasp, full width */
  590.         if ((boxdepth = (numchoices+boxwidth-1)/boxwidth) > i)
  591.            boxdepth = i;
  592.         }
  593.      }
  594.       }
  595.    if ((i = 77 / boxwidth - colwidth) > 3) /* spaces to add @ left each choice */
  596.       i = 3;
  597.    j = boxwidth * (colwidth += i) + i;       /* overall width of box */
  598.    if (j < titlewidth+2)
  599.       j = titlewidth + 2;
  600.    if (j > 80)
  601.       j = 80;
  602.    if (j <= 70 && boxwidth == 2) {       /* special case makes menus nicer */
  603.       ++j;
  604.       ++colwidth;
  605.       }
  606.    k = (80 - j) / 2;               /* center the box */
  607.    k -= (90 - j) / 20;
  608.    topleftcol = k + i;               /* column of topleft choice */
  609.    i = (25 - reqdrows - boxdepth) / 2;
  610.    i -= i / 4;                   /* higher is better if lots extra */
  611.    topleftrow = 3 + titlelines + i;       /* row of topleft choice */
  612.  
  613.    /* now set up the overall display */
  614.    helptitle();                /* clear, display title line */
  615.    setattr(1,0,C_PROMPT_BKGRD,24*80);       /* init rest to background */
  616.    for (i = topleftrow-1-titlelines; i < topleftrow+boxdepth+1; ++i)
  617.       setattr(i,k,C_PROMPT_LO,j);       /* draw empty box */
  618.    if (hdg) {
  619.       textcbase = (80 - titlewidth) / 2;   /* set left margin for putstring */
  620.       textcbase -= (90 - titlewidth) / 20; /* put heading into box */
  621.       putstring(topleftrow-titlelines-1,0,C_PROMPT_HI,hdg);
  622.       textcbase = 0;
  623.       }
  624.    if (hdg2)                   /* display 2nd heading */
  625.       putstring(topleftrow-1,topleftcol,C_PROMPT_MED,hdg2);
  626.    i = topleftrow + boxdepth + 1;
  627.    if (instr == NULL || (options & 8)) {   /* display default instructions */
  628.       if (i < 20) ++i;
  629.       if (speedstring) {
  630.      speedrow = i;
  631.      *speedstring = 0;
  632.      if (++i < 22) ++i;
  633.      }
  634.       putstringcenter(i++,0,80,C_PROMPT_BKGRD,
  635.         (speedstring) ? choiceinstr1b : choiceinstr1a);
  636.       putstringcenter(i++,0,80,C_PROMPT_BKGRD,
  637.         (options&CHOICEMENU) ? choiceinstr2c
  638.         : ((options&CHOICEHELP) ? choiceinstr2b : choiceinstr2a));
  639.       }
  640.    if (instr) {                /* display caller's instructions */
  641.       charptr = instr;
  642.       j = -1;
  643.       while ((buf[++j] = *(charptr++)))
  644.      if (buf[j] == '\n') {
  645.         buf[j] = 0;
  646.         putstringcenter(i++,0,80,C_PROMPT_BKGRD,buf);
  647.         j = -1;
  648.         }
  649.       putstringcenter(i,0,80,C_PROMPT_BKGRD,buf);
  650.       }
  651.  
  652.    boxitems = boxwidth * boxdepth;
  653.    topleftchoice = 0;               /* pick topleft for init display */
  654.    while (current - topleftchoice >= boxitems
  655.      || (current - topleftchoice > boxitems/2
  656.      && topleftchoice + boxitems < numchoices))
  657.       topleftchoice += boxwidth;
  658.    redisplay = 1;
  659.  
  660.    while (1) { /* main loop */
  661.  
  662.       if (redisplay) {                 /* display the current choices */
  663.      if ((options & CHOICEMENU) == 0) {
  664.         memset(buf,' ',80);
  665.         buf[boxwidth*colwidth] = 0;
  666.         for (i = (hdg2) ? 0 : -1; i <= boxdepth; ++i)  /* blank the box */
  667.            putstring(topleftrow+i,topleftcol,C_PROMPT_LO,buf);
  668.         }
  669.      for (i = 0; i+topleftchoice < numchoices && i < boxitems; ++i) {
  670.         /* display the choices */
  671.         if ((k = attributes[j = i+topleftchoice] & 3) == 1)
  672.            k = C_PROMPT_LO;
  673.         else if (k == 3)
  674.            k = C_PROMPT_HI;
  675.         else
  676.            k = C_PROMPT_MED;
  677.         if (formatitem)
  678.            (*formatitem)(j,charptr=buf);
  679.         else
  680.            charptr = choices[j];
  681.         putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  682.               k,charptr);
  683.         }
  684.      /***
  685.      ... format differs for summary/detail, whups, force box width to
  686.      ...  be 72 when detail toggle available?  (2 grey margin each
  687.      ...  side, 1 blue margin each side)
  688.      ***/
  689.      if (topleftchoice > 0 && hdg2 == NULL)
  690.         putstring(topleftrow-1,topleftcol,C_PROMPT_LO,"(more)");
  691.      if (topleftchoice + boxitems < numchoices)
  692.         putstring(topleftrow+boxdepth,topleftcol,C_PROMPT_LO,"(more)");
  693.      redisplay = 0;
  694.      }
  695.  
  696.       i = current - topleftchoice;         /* highlight the current choice */
  697.       if (formatitem)
  698.      (*formatitem)(current,itemptr=curitem);
  699.       else
  700.      itemptr = choices[current];
  701.       putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  702.         C_CHOICE_CURRENT,itemptr);
  703.  
  704.       if (speedstring) {             /* show speedstring if any */
  705.      memset(buf,' ',80);
  706.      buf[80] = 0;
  707.      putstring(speedrow,0,C_PROMPT_BKGRD,buf);
  708.      if (*speedstring) {             /* got a speedstring on the go */
  709.         putstring(speedrow,15,C_CHOICE_SP_INSTR," ");
  710.         if (speedprompt)
  711.            j = speedprompt(speedrow,16,C_CHOICE_SP_INSTR,speedstring,speed_match);
  712.         else {
  713.            putstring(speedrow,16,C_CHOICE_SP_INSTR,speed_prompt);
  714.            j = strlen(speed_prompt);
  715.            }
  716.         strcpy(buf,speedstring);
  717.         i = strlen(buf);
  718.         while (i < 30)
  719.            buf[i++] = ' ';
  720.         buf[i] = 0;
  721.         putstring(speedrow,16+j,C_CHOICE_SP_INSTR," ");
  722.         putstring(speedrow,17+j,C_CHOICE_SP_KEYIN,buf);
  723.         movecursor(speedrow,17+j+strlen(speedstring));
  724.         }
  725.      else
  726.         movecursor(25,80);
  727.      }
  728.       else
  729.      movecursor(25,80);
  730.  
  731. #ifndef XFRACT
  732.       while (!keypressed()) { } /* enables help */
  733. #else
  734.       waitkeypressed(0); /* enables help */
  735. #endif
  736.       curkey = getakey();
  737. #ifdef XFRACT
  738.       if (curkey==F10) curkey=')';
  739.       if (curkey==F9) curkey='(';
  740.       if (curkey==F8) curkey='*';
  741. #endif
  742.  
  743.       i = current - topleftchoice;         /* unhighlight current choice */
  744.       if ((k = attributes[current] & 3) == 1)
  745.      k = C_PROMPT_LO;
  746.       else if (k == 3)
  747.      k = C_PROMPT_HI;
  748.       else
  749.      k = C_PROMPT_MED;
  750.       putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  751.         k,itemptr);
  752.  
  753.       increment = 0;
  754.       switch (curkey) {              /* deal with input key */
  755.      case ENTER:
  756.      case ENTER_2:
  757.         ret = current;
  758.         goto fs_choice_end;
  759.      case ESC:
  760.         goto fs_choice_end;
  761.      case DOWN_ARROW:
  762.      case DOWN_ARROW_2:
  763.         rev_increment = 0 - (increment = boxwidth);
  764.         break;
  765.      case UP_ARROW:
  766.      case UP_ARROW_2:
  767.         increment = 0 - (rev_increment = boxwidth);
  768.         break;
  769.      case RIGHT_ARROW:
  770.      case RIGHT_ARROW_2:
  771.         if (boxwidth == 1) break;
  772.         increment = 1; rev_increment = -1;
  773.         break;
  774.      case LEFT_ARROW:
  775.      case LEFT_ARROW_2:
  776.         if (boxwidth == 1) break;
  777.         increment = -1; rev_increment = 1;
  778.         break;
  779.      case PAGE_UP:
  780.         if (numchoices > boxitems) {
  781.            topleftchoice -= boxitems;
  782.            increment = -boxitems;
  783.            rev_increment = boxwidth;
  784.            redisplay = 1;
  785.            }
  786.         break;
  787.      case PAGE_DOWN:
  788.         if (numchoices > boxitems) {
  789.            topleftchoice += boxitems;
  790.            increment = boxitems;
  791.            rev_increment = -boxwidth;
  792.            redisplay = 1;
  793.            }
  794.         break;
  795.      case CTL_HOME:
  796.      case HOME:
  797.         current = -1;
  798.         increment = rev_increment = 1;
  799.         break;
  800.      case CTL_END:
  801.      case END:
  802.         current = numchoices;
  803.         increment = rev_increment = -1;
  804.         break;
  805.      default:
  806.         if (checkkey) {
  807.            if ((ret = (*checkkey)(curkey,current)) < -1 || ret > 0)
  808.           goto fs_choice_end;
  809.            if (ret == -1)
  810.           redisplay = -1;
  811.            }
  812.         ret = -1;
  813.         if (speedstring) {
  814.            i = strlen(speedstring);
  815.            if (curkey == 8 && i > 0) /* backspace */
  816.           speedstring[--i] = 0;
  817.            if (33 <= curkey && curkey <= 126 && i < 30) {
  818.           curkey = tolower(curkey);
  819.           speedstring[i] = curkey;
  820.           speedstring[++i] = 0;
  821.           }
  822.            if (i > 0) {         /* locate matching type */
  823.           current = 0;
  824.           while (current < numchoices
  825.             && (speed_match = strncasecmp(speedstring,choices[current],i)) > 0)
  826.              ++current;
  827.           if (speed_match < 0 && current > 0)  /* oops - overshot */
  828.              --current;
  829.           if (current >= numchoices) /* bumped end of list */
  830.              current = numchoices - 1;
  831.           }
  832.            }
  833.         break;
  834.      }
  835.  
  836.       if (increment) {            /* apply cursor movement */
  837.      current += increment;
  838.      if (speedstring)        /* zap speedstring */
  839.         speedstring[0] = 0;
  840.      }
  841.       while (1) {            /* adjust to a non-comment choice */
  842.      if (current < 0 || current >= numchoices)
  843.          increment = rev_increment;
  844.      else if ((attributes[current] & 256) == 0)
  845.          break;
  846.      current += increment;
  847.      }
  848.       if (topleftchoice > numchoices - boxitems)
  849.      topleftchoice = ((numchoices+boxwidth-1)/boxwidth)*boxwidth - boxitems;
  850.       if (topleftchoice < 0)
  851.      topleftchoice = 0;
  852.       while (current < topleftchoice) {
  853.      topleftchoice -= boxwidth;
  854.      redisplay = 1;
  855.      }
  856.       while (current >= topleftchoice + boxitems) {
  857.      topleftchoice += boxwidth;
  858.      redisplay = 1;
  859.      }
  860.       }
  861.  
  862. fs_choice_end:
  863.    lookatmouse = savelookatmouse;
  864.    return(ret);
  865.  
  866. }
  867.  
  868.  
  869. #ifndef XFRACT
  870. /* case independent version of strncmp */
  871. int strncasecmp(char *s,char *t,int ct)
  872. {
  873.    for(; (tolower(*s) == tolower(*t)) && --ct ; s++,t++)
  874.       if(*s == '\0')
  875.      return(0);
  876.    return(tolower(*s) - tolower(*t));
  877. }
  878. #endif
  879.  
  880.  
  881. static int menutype;
  882. #define MENU_HDG 3
  883. #define MENU_ITEM 1
  884.  
  885. int main_menu(int fullmenu)
  886. {
  887.    char *choices[44]; /* 2 columns * 22 rows */
  888.    int attributes[44];
  889.    int choicekey[44];
  890.    int i;
  891.    int nextleft,nextright;
  892.    int oldtabmode,oldhelpmode;
  893.    oldtabmode = tabmode;
  894.    oldhelpmode = helpmode;
  895. top:
  896.    menutype = fullmenu;
  897.    tabmode = 0;
  898.    for (i = 0; i < 44; ++i) {
  899.       attributes[i] = 256;
  900.       choices[i] = "";
  901.       choicekey[i] = -1;
  902.       }
  903.    nextleft = -2;
  904.    nextright = -1;
  905.  
  906.    if (fullmenu) {
  907.       choices[nextleft+=2] = "      CURRENT IMAGE";
  908.       attributes[nextleft] = 256+MENU_HDG;
  909.       choicekey[nextleft+=2] = 13; /* enter */
  910.       attributes[nextleft] = MENU_ITEM;
  911.       if (calc_status == 2)
  912.      choices[nextleft] = "continue calculation";
  913.       else
  914.      choices[nextleft] = "return to image";
  915.       choicekey[nextleft+=2] = 9; /* tab */
  916.       attributes[nextleft] = MENU_ITEM;
  917.       choices[nextleft] = "info about image      <tab>";
  918.       choicekey[nextleft+=2] = -10;
  919.       attributes[nextleft] = MENU_ITEM;
  920.       choices[nextleft] = "zoom box functions...";
  921.       choicekey[nextleft+=2] = 'o';
  922.       attributes[nextleft] = MENU_ITEM;
  923.       choices[nextleft] = "orbits window          <o>";
  924.       if(!(fractype==JULIA || fractype==JULIAFP || fractype==INVERSEJULIA))
  925.           nextleft+=2; 
  926.       }
  927.    choices[nextleft+=2] = "      NEW IMAGE";
  928.    attributes[nextleft] = 256+MENU_HDG;
  929.    choicekey[nextleft+=2] = DELETE;
  930.    attributes[nextleft] = MENU_ITEM;
  931.    choices[nextleft] = "select video mode...  <del>";
  932.    choicekey[nextleft+=2] = 't';
  933.    attributes[nextleft] = MENU_ITEM;
  934.    choices[nextleft] = "select fractal type    <t>";
  935.    if (fullmenu) {
  936.       if ((curfractalspecific->tojulia != NOFRACTAL
  937.       && param[0] == 0.0 && param[1] == 0.0)
  938.       || curfractalspecific->tomandel != NOFRACTAL) {
  939.          choicekey[nextleft+=2] = ' ';
  940.          attributes[nextleft] = MENU_ITEM;
  941.          choices[nextleft] = "toggle to/from julia <space>";
  942.       }    
  943.       if(fractype==JULIA || fractype==JULIAFP || fractype==INVERSEJULIA) {
  944.          choicekey[nextleft+=2] = 'j';
  945.          attributes[nextleft] = MENU_ITEM;
  946.          choices[nextleft] = "toggle to/from inverse <j>";
  947.       }
  948.       choicekey[nextleft+=2] = '\\';
  949.       attributes[nextleft] = MENU_ITEM;
  950.       choices[nextleft] = "return to prior image  <\\>";
  951.    }
  952.    nextleft += 2;
  953.    choices[nextleft+=2] = "      OPTIONS";
  954.    attributes[nextleft] = 256+MENU_HDG;
  955.    choicekey[nextleft+=2] = 'x';
  956.    attributes[nextleft] = MENU_ITEM;
  957.    choices[nextleft] = "basic options...       <x>";
  958.    choicekey[nextleft+=2] = 'y';
  959.    attributes[nextleft] = MENU_ITEM;
  960.    choices[nextleft] = "extended options...    <y>";
  961.    choicekey[nextleft+=2] = 'z';
  962.    attributes[nextleft] = MENU_ITEM;
  963.    choices[nextleft] = "type-specific parms... <z>";
  964.    choicekey[nextleft+=2] = 'v';
  965.    attributes[nextleft] = MENU_ITEM;
  966.    choices[nextleft] = "view window options... <v>";
  967.    choicekey[nextleft+=2] = 'i';
  968.    attributes[nextleft] = MENU_ITEM;
  969.    choices[nextleft] = "fractal 3D parms...    <i>";
  970.  
  971.    choices[nextright+=2] = "        FILE";
  972.    attributes[nextright] = 256+MENU_HDG;
  973.    choicekey[nextright+=2] = '@';
  974.    attributes[nextright] = MENU_ITEM;
  975.    choices[nextright] = "run saved command set... <@>";
  976.    if (fullmenu) {
  977.       choicekey[nextright+=2] = 's';
  978.       attributes[nextright] = MENU_ITEM;
  979.       choices[nextright] = "save image to file       <s>";
  980.       }
  981.    choicekey[nextright+=2] = 'r';
  982.    attributes[nextright] = MENU_ITEM;
  983.    choices[nextright] = "load image from file...  <r>";
  984.    choicekey[nextright+=2] = '3';
  985.    attributes[nextright] = MENU_ITEM;
  986.    choices[nextright] = "3d transform from file...<3>";
  987.    if (fullmenu) {
  988.       choicekey[nextright+=2] = '#';
  989.       attributes[nextright] = MENU_ITEM;
  990.       choices[nextright] = "3d overlay from file.....<#>";
  991.       choicekey[nextright+=2] = 'b';
  992.       attributes[nextright] = MENU_ITEM;
  993.       choices[nextright] = "save current parameters..<b>";
  994.       choicekey[nextright+=2] = 'p';
  995.       attributes[nextright] = MENU_ITEM;
  996.       choices[nextright] = "print image              <p>";
  997.       }
  998.    choicekey[nextright+=2] = 'd';
  999.    attributes[nextright] = MENU_ITEM;
  1000.    choices[nextright] = "shell to dos             <d>";
  1001.    choicekey[nextright+=2] = 'g';
  1002.    attributes[nextright] = MENU_ITEM;
  1003.    choices[nextright] = "give command string      <g>";
  1004.    choicekey[nextright+=2] = ESC;
  1005.    attributes[nextright] = MENU_ITEM;
  1006.    choices[nextright] = "quit Fractint           <esc>";
  1007.    choicekey[nextright+=2] = INSERT;
  1008.    attributes[nextright] = MENU_ITEM;
  1009.    choices[nextright] = "restart Fractint        <ins>";
  1010.    if (fullmenu && gotrealdac && colors >= 16) {
  1011.       nextright += 2;
  1012.       choices[nextright+=2] = "       COLORS";
  1013.       attributes[nextright] = 256+MENU_HDG;
  1014.       /*** choicekey[nextright+=2] = -12;
  1015.         attributes[nextright] = MENU_ITEM;
  1016.         choices[nextright] = "color cycling menu...";
  1017.         choicekey[nextright+=2] = -13;
  1018.         attributes[nextright] = MENU_ITEM;
  1019.         choices[nextright] = "palette editing menu..."; ***/
  1020.       choicekey[nextright+=2] = 'c';
  1021.       attributes[nextright] = MENU_ITEM;
  1022.       choices[nextright] = "color cycling mode       <c>";
  1023.       choicekey[nextright+=2] = '+';
  1024.       attributes[nextright] = MENU_ITEM;
  1025.       choices[nextright] = "rotate palette      <+>, <->";
  1026.       if (colors > 16) {
  1027.      if (!reallyega) {
  1028.         choicekey[nextright+=2] = 'e';
  1029.         attributes[nextright] = MENU_ITEM;
  1030.         choices[nextright] = "palette editing mode     <e>";
  1031.         }
  1032.      choicekey[nextright+=2] = 'a';
  1033.      attributes[nextright] = MENU_ITEM;
  1034.      choices[nextright] = "make starfield           <a>";
  1035.      }
  1036.       }
  1037.  
  1038.    i = (keypressed()) ? getakey() : 0;
  1039.    if (menu_checkkey(i,0) == 0) {
  1040.       helpmode = HELPMAIN;       /* switch help modes */
  1041.       if ((nextleft += 2) < nextright)
  1042.      nextleft = nextright + 1;
  1043.       i = fullscreen_choice(CHOICEMENU,
  1044.       "MAIN MENU",
  1045.       NULL,NULL,nextleft,choices,attributes,
  1046.       2,nextleft/2,29,0,NULL,NULL,NULL,menu_checkkey);
  1047.       if (i == -1)     /* escape */
  1048.      i = ESC;
  1049.       else if (i < 0)
  1050.      i = 0 - i;
  1051.       else {              /* user selected a choice */
  1052.      i = choicekey[i];
  1053.      switch (i) {          /* check for special cases */
  1054.         case -10:          /* zoombox functions */
  1055.            helpmode = HELPZOOM;
  1056.            help(0);
  1057.            i = 0;
  1058.            break;
  1059.         }
  1060.      }
  1061.       }
  1062.    if (i == ESC) {           /* escape from menu exits Fractint */
  1063.       static char far s[] = "Exit from Fractint (y/n)? y";
  1064.       helptitle();
  1065.       setattr(1,0,C_GENERAL_MED,24*80);
  1066.       for (i = 9; i <= 11; ++i)
  1067.      setattr(i,18,C_GENERAL_INPUT,40);
  1068.       putstringcenter(10,18,40,C_GENERAL_INPUT,s);
  1069.       movecursor(25,80);
  1070.       while ((i = getakey()) != 'y' && i != 'Y' && i != 13) {
  1071.      if (i == 'n' || i == 'N')
  1072.         goto top;
  1073.      }
  1074.       goodbye();
  1075.       }
  1076.    if (i == TAB) {
  1077.       tab_display();
  1078.       i = 0;
  1079.       }
  1080.    if (i == ENTER || i == ENTER_2)
  1081.       i = 0;             /* don't trigger new calc */
  1082.    tabmode = oldtabmode;
  1083.    return(i);
  1084. }
  1085.  
  1086. static int menu_checkkey(int curkey,int choice)
  1087. {
  1088.    int testkey;
  1089.    testkey = (curkey>='A' && curkey<='Z') ? curkey+('a'-'A') : curkey;
  1090. #ifdef XFRACT
  1091.    /* We use F2 for shift-@, annoyingly enough */
  1092.    if (testkey == F2) return(0-testkey);
  1093. #endif
  1094.    if (strchr("@txyzgvir3dj",testkey) || testkey == INSERT
  1095.      || testkey == ESC || testkey == DELETE)
  1096.       return(0-testkey);
  1097.    if (menutype) {
  1098.       if (strchr("\\sobp",testkey) || testkey == 9)
  1099.      return(0-testkey);
  1100.       if (testkey == ' ')
  1101.      if ((curfractalspecific->tojulia != NOFRACTAL
  1102.           && param[0] == 0.0 && param[1] == 0.0)
  1103.        || curfractalspecific->tomandel != NOFRACTAL)
  1104.      return(0-testkey);
  1105.       if (gotrealdac && colors >= 16) {
  1106.      if (strchr("c+-",testkey))
  1107.         return(0-testkey);
  1108.      if (colors > 16
  1109.        && (testkey == 'a' || (!reallyega && testkey == 'e')))
  1110.         return(0-testkey);
  1111.      }
  1112.       }
  1113.    if (check_vidmode_key(0,testkey) >= 0)
  1114.       return(0-testkey);
  1115.    return(0);
  1116. }
  1117.  
  1118.  
  1119. int input_field(
  1120.     int options,          /* &1 numeric, &2 integer, &4 double */
  1121.     int attr,          /* display attribute */
  1122.     char *fld,          /* the field itself */
  1123.     int len,          /* field length (declare as 1 larger for \0) */
  1124.     int row,          /* display row */
  1125.     int col,          /* display column */
  1126.     int (*checkkey)(int)  /* routine to check non data keys, or NULL */
  1127.     )
  1128. {
  1129.    char savefld[81];
  1130.    char buf[81];
  1131.    int insert, started, offset, curkey, display;
  1132.    int i, j;
  1133.    int ret,savelookatmouse;
  1134.    savelookatmouse = lookatmouse;
  1135.    lookatmouse = 0;
  1136.    ret = -1;
  1137.    strcpy(savefld,fld);
  1138.    insert = started = offset = 0;
  1139.    display = 1;
  1140.    while (1) {
  1141.       strcpy(buf,fld);
  1142.       i = strlen(buf);
  1143.       while (i < len)
  1144.      buf[i++] = ' ';
  1145.       buf[len] = 0;
  1146.       if (display) {                    /* display current value */
  1147.      putstring(row,col,attr,buf);
  1148.      display = 0;
  1149.      }
  1150.       curkey = keycursor(row+insert,col+offset);  /* get a keystroke */
  1151.       switch (curkey) {
  1152.      case ENTER:
  1153.      case ENTER_2:
  1154.         ret = 0;
  1155.         goto inpfld_end;
  1156.      case ESC:
  1157.         goto inpfld_end;
  1158.      case RIGHT_ARROW:
  1159.      case RIGHT_ARROW_2:
  1160.         if (offset < len-1) ++offset;
  1161.         started = 1;
  1162.         break;
  1163.      case LEFT_ARROW:
  1164.      case LEFT_ARROW_2:
  1165.         if (offset > 0) --offset;
  1166.         started = 1;
  1167.         break;
  1168.      case HOME:
  1169.         offset = 0;
  1170.         started = 1;
  1171.         break;
  1172.      case END:
  1173.         offset = strlen(fld);
  1174.         started = 1;
  1175.         break;
  1176.      case 8:
  1177.      case 127:                /* backspace */
  1178.         if (offset > 0) {
  1179.            j = strlen(fld);
  1180.            for (i = offset-1; i < j; ++i)
  1181.           fld[i] = fld[i+1];
  1182.            --offset;
  1183.            }
  1184.         started = display = 1;
  1185.         break;
  1186.      case DELETE:                /* delete */
  1187.         j = strlen(fld);
  1188.         for (i = offset; i < j; ++i)
  1189.            fld[i] = fld[i+1];
  1190.         started = display = 1;
  1191.         break;
  1192.      case INSERT:                /* insert */
  1193.         insert ^= 0x8000;
  1194.         started = 1;
  1195.         break;
  1196.      case F5:
  1197.         strcpy(fld,savefld);
  1198.         insert = started = offset = 0;
  1199.         display = 1;
  1200.         break;
  1201.      default:
  1202.             if (nonalpha(curkey)) {
  1203.            if (checkkey && (ret = (*checkkey)(curkey)))
  1204.           goto inpfld_end;
  1205.            break;                     /* non alphanum char */
  1206.            }
  1207.         if (offset >= len) break;             /* at end of field */
  1208.         if (insert && started && strlen(fld) >= len)
  1209.            break;                     /* insert & full */
  1210.         if ((options & 1)
  1211.           && (curkey < '0' || curkey > '9')
  1212.           && curkey != '+' && curkey != '-') {
  1213.            if ((options & 2))
  1214.           break;
  1215.            /* allow scientific notation, and specials "e" and "p" */
  1216.            if ( ((curkey != 'e' && curkey != 'E') || offset >= 18)
  1217.          && ((curkey != 'p' && curkey != 'P') || offset != 0 )
  1218.          && curkey != '.')
  1219.           break;
  1220.            }
  1221.         if (started == 0) /* first char is data, zap field */
  1222.            fld[0] = 0;
  1223.         if (insert) {
  1224.            j = strlen(fld);
  1225.            while (j >= offset) {
  1226.           fld[j+1] = fld[j];
  1227.           --j;
  1228.           }
  1229.            }
  1230.         if (offset >= strlen(fld))
  1231.            fld[offset+1] = 0;
  1232.         fld[offset++] = curkey;
  1233.         /* if "e" or "p" in first col make number e or pi */
  1234.         if ((options & 3) == 1) { /* floating point */
  1235.            double tmpd;
  1236.            int specialv;
  1237.            char tmpfld[30];
  1238.            specialv = 0;
  1239.            if (*fld == 'e' || *fld == 'E') {
  1240.           tmpd = exp(1.0);
  1241.           specialv = 1;
  1242.           }
  1243.            if (*fld == 'p' || *fld == 'P') {
  1244.           tmpd = atan(1.0) * 4;
  1245.           specialv = 1;
  1246.           }
  1247.            if (specialv) {
  1248.           if ((options & 4) == 0)
  1249.              roundfloatd(&tmpd);
  1250.           sprintf(tmpfld,"%.15g",tmpd);
  1251.           tmpfld[len-1] = 0; /* safety, field should be long enough */
  1252.           strcpy(fld,tmpfld);
  1253.           offset = 0;
  1254.           }
  1255.            }
  1256.         started = display = 1;
  1257.      }
  1258.       }
  1259. inpfld_end:
  1260.    lookatmouse = savelookatmouse;
  1261.    return(ret);
  1262. }
  1263.  
  1264. int field_prompt(
  1265.     int options,        /* &1 numeric value, &2 integer */
  1266.     char *hdg,        /* heading, \n delimited lines */
  1267.     char *instr,        /* additional instructions or NULL */
  1268.     char *fld,        /* the field itself */
  1269.     int len,        /* field length (declare as 1 larger for \0) */
  1270.     int (*checkkey)(int)   /* routine to check non data keys, or NULL */
  1271.     )
  1272. {
  1273.    char *charptr;
  1274.    int boxwidth,titlelines,titlecol,titlerow;
  1275.    int promptcol;
  1276.    int i,j;
  1277.    char buf[81];
  1278.    helptitle();               /* clear screen, display title */
  1279.    setattr(1,0,C_PROMPT_BKGRD,24*80);      /* init rest to background */
  1280.    charptr = hdg;              /* count title lines, find widest */
  1281.    i = boxwidth = 0;
  1282.    titlelines = 1;
  1283.    while (*charptr) {
  1284.       if (*(charptr++) == '\n') {
  1285.      ++titlelines;
  1286.      i = -1;
  1287.      }
  1288.       if (++i > boxwidth)
  1289.      boxwidth = i;
  1290.       }
  1291.    if (len > boxwidth)
  1292.       boxwidth = len;
  1293.    i = titlelines + 4;              /* total rows in box */
  1294.    titlerow = (25 - i) / 2;          /* top row of it all when centered */
  1295.    titlerow -= titlerow / 4;          /* higher is better if lots extra */
  1296.    titlecol = (80 - boxwidth) / 2;      /* center the box */
  1297.    titlecol -= (90 - boxwidth) / 20;
  1298.    promptcol = titlecol - (boxwidth-len)/2;
  1299.    j = titlecol;              /* add margin at each side of box */
  1300.    if ((i = (82-boxwidth)/4) > 3)
  1301.       i = 3;
  1302.    j -= i;
  1303.    boxwidth += i * 2;
  1304.    for (i = -1; i < titlelines+3; ++i)      /* draw empty box */
  1305.       setattr(titlerow+i,j,C_PROMPT_LO,boxwidth);
  1306.    textcbase = titlecol;          /* set left margin for putstring */
  1307.    putstring(titlerow,0,C_PROMPT_HI,hdg); /* display heading */
  1308.    textcbase = 0;
  1309.    i = titlerow + titlelines + 4;
  1310.    if (instr) {               /* display caller's instructions */
  1311.       charptr = instr;
  1312.       j = -1;
  1313.       while ((buf[++j] = *(charptr++)))
  1314.      if (buf[j] == '\n') {
  1315.         buf[j] = 0;
  1316.         putstringcenter(i++,0,80,C_PROMPT_BKGRD,buf);
  1317.         j = -1;
  1318.         }
  1319.       putstringcenter(i,0,80,C_PROMPT_BKGRD,buf);
  1320.       }
  1321.    else                   /* default instructions */
  1322.       putstringcenter(i,0,80,C_PROMPT_BKGRD,
  1323.           "Press ENTER when finished (or ESCAPE to back out)");
  1324.    return(input_field(options,C_PROMPT_INPUT,fld,len,
  1325.               titlerow+titlelines+1,promptcol,checkkey));
  1326. }
  1327.  
  1328.  
  1329. /* thinking(1,message):
  1330.       if thinking message not yet on display, it is displayed;
  1331.       otherwise the wheel is updated
  1332.       returns 0 to keep going, -1 if keystroke pending
  1333.    thinking(0,NULL):
  1334.       call this when thinking phase is done
  1335.    */
  1336.  
  1337. int thinking(int options,char *msg)
  1338. {
  1339.    static int thinkstate = -1;
  1340.    static char *wheel[] = {"-","\\","|","/"};
  1341.    static int thinkcol;
  1342.    char buf[81];
  1343.    if (options == 0) {
  1344.       if (thinkstate >= 0) {
  1345.      thinkstate = -1;
  1346.      unstackscreen();
  1347.      }
  1348.       return(0);
  1349.       }
  1350.    if (thinkstate < 0) {
  1351.       stackscreen();
  1352.       thinkstate = 0;
  1353.       helptitle();
  1354.       strcpy(buf,"  ");
  1355.       strcat(buf,msg);
  1356.       strcat(buf,"    ");
  1357.       putstring(4,10,C_GENERAL_HI,buf);
  1358.       thinkcol = textcol - 3;
  1359.       }
  1360.    putstring(4,thinkcol,C_GENERAL_HI,wheel[thinkstate]);
  1361.    movecursor(25,80); /* turn off cursor */
  1362.    thinkstate = (thinkstate + 1) & 3;
  1363.    return (keypressed());
  1364. }
  1365.  
  1366.  
  1367. void clear_screen(void)  /* a stub for a windows only subroutine */
  1368. {
  1369. }
  1370.  
  1371.  
  1372. /* savegraphics/restoregraphics: video.asm subroutines */
  1373.  
  1374. static BYTE far *swapsavebuf;
  1375. static unsigned int memhandle;
  1376. unsigned long swaptotlen;
  1377. unsigned long swapoffset;
  1378. BYTE far *swapvidbuf;
  1379. int swaplength;
  1380. static int swaptype = -1;
  1381. static int swapblklen; /* must be a power of 2 */
  1382. #ifndef XFRACT
  1383. extern BYTE suffix[4096];
  1384. #else
  1385. BYTE suffix[4096];
  1386. #endif
  1387.  
  1388. #ifndef XFRACT
  1389.  
  1390. int savegraphics()
  1391. {
  1392.    extern int made_dsktemp;
  1393.    int i;
  1394.    struct XMM_Move   xmmparms;
  1395.  
  1396.    discardgraphics(); /* if any emm/xmm in use from prior call, release it */
  1397.    swaptotlen = (long)sxdots * sydots;
  1398.    i = colors;
  1399.    while (i <= 16) {
  1400.       swaptotlen >>= 1;
  1401.       i = i * i;
  1402.       }
  1403.    swapoffset = 0;
  1404.    if (debugflag != 420 && debugflag != 422 /* 422=xmm test, 420=disk test */
  1405.      && (swapsavebuf = emmquery()) != NULL
  1406.      && (memhandle = emmallocate((unsigned int)((swaptotlen + 16383) >> 14)))
  1407.      != 0) {
  1408.       swaptype = 0; /* use expanded memory */
  1409.       swapblklen = 16384;
  1410.       }
  1411.    else if (debugflag != 420
  1412.      && xmmquery() !=0
  1413.      && (memhandle = xmmallocate((unsigned int)((swaptotlen + 1023) >> 10)))
  1414.      != 0) {
  1415.       swaptype = 1; /* use extended memory */
  1416.       swapblklen = 16384;
  1417.       }
  1418.    else {
  1419.       swaptype = 2; /* use disk */
  1420.       swapblklen = 4096;
  1421.  
  1422.    /* MCP 7-7-91, If 'memhandle' is an 'unsigned int', how is it ever going
  1423.       to be equal to -1?
  1424.  
  1425.       if ((memhandle = open(diskfilename,O_CREAT|O_WRONLY|O_BINARY,S_IWRITE))
  1426.      == -1) {
  1427.    */
  1428.       if ((memhandle = open(diskfilename,O_CREAT|O_WRONLY|O_BINARY,S_IWRITE))
  1429.      == 0xffff) {
  1430.  
  1431.  
  1432. dskfile_error:
  1433.      setvideotext(); /* text mode */
  1434.      setclear();
  1435.          {
  1436.             extern char diskfilename[];
  1437.             static char far s1[] = {"error in temp file "};
  1438.             static char far s2[] = { " (disk full?) - aborted\n\n"};
  1439.         printf("%Fs%s%Fs",s1,diskfilename,s2);
  1440.      }   
  1441.      exit(1);
  1442.      }
  1443.       made_dsktemp = 1;
  1444.       }
  1445.    while (swapoffset < swaptotlen) {
  1446.       swaplength = swapblklen;
  1447.       if ((swapoffset & (swapblklen-1)) != 0)
  1448.      swaplength = swapblklen - (swapoffset & (swapblklen-1));
  1449.       if (swaplength > swaptotlen - swapoffset)
  1450.      swaplength = swaptotlen - swapoffset;
  1451.       (*swapsetup)(); /* swapoffset,swaplength -> sets swapvidbuf,swaplength */
  1452.       switch(swaptype) {
  1453.      case 0:
  1454.         emmgetpage((unsigned int)(swapoffset>>14),memhandle);
  1455.         movewords(swaplength>>1,swapvidbuf,
  1456.               swapsavebuf+(swapoffset&(swapblklen-1)));
  1457.         break;
  1458.      case 1:
  1459.         xmmparms.Length = swaplength;
  1460.         xmmparms.SourceHandle = 0; /* Source is conventional memory */
  1461.         xmmparms.SourceOffset = (unsigned long)swapvidbuf;
  1462.         xmmparms.DestHandle = memhandle;
  1463.         xmmparms.DestOffset = swapoffset;
  1464.         xmmmoveextended(&xmmparms);
  1465.         break;
  1466.      default:
  1467.         movewords(swaplength>>1,swapvidbuf,(BYTE far *)suffix);
  1468.         if (write(memhandle,suffix,swaplength) == -1)
  1469.            goto dskfile_error;
  1470.      }
  1471.       swapoffset += swaplength;
  1472.       }
  1473.    if (swaptype == 2)
  1474.       close(memhandle);
  1475.    return 0;
  1476. }
  1477.  
  1478. void restoregraphics()
  1479. {
  1480.    struct XMM_Move   xmmparms;
  1481.  
  1482.    swapoffset = 0;
  1483.    if (swaptype == 2)
  1484.       memhandle = open(diskfilename,O_RDONLY|O_BINARY,S_IREAD);
  1485.    swapvidbuf = MK_FP(extraseg+0x1000,0); /* for swapnormwrite case */
  1486.    while (swapoffset < swaptotlen) {
  1487.       swaplength = swapblklen;
  1488.       if ((swapoffset & (swapblklen-1)) != 0)
  1489.      swaplength = swapblklen - (swapoffset & (swapblklen-1));
  1490.       if (swaplength > swaptotlen - swapoffset)
  1491.      swaplength = swaptotlen - swapoffset;
  1492.       if (swapsetup != swapnormread)
  1493.      (*swapsetup)(); /* swapoffset,swaplength -> sets swapvidbuf,swaplength */
  1494.       switch(swaptype) {
  1495.      case 0:
  1496.         emmgetpage((unsigned int)(swapoffset>>14),memhandle);
  1497.         movewords(swaplength>>1,swapsavebuf+(swapoffset&(swapblklen-1)),
  1498.               swapvidbuf);
  1499.         break;
  1500.      case 1:
  1501.         xmmparms.Length = swaplength;
  1502.         xmmparms.SourceHandle = memhandle;
  1503.         xmmparms.SourceOffset = swapoffset;
  1504.         xmmparms.DestHandle = 0; /* conventional memory */
  1505.         xmmparms.DestOffset = (unsigned long)swapvidbuf;
  1506.         xmmmoveextended(&xmmparms);
  1507.         break;
  1508.      default:
  1509.         read(memhandle,suffix,swaplength);
  1510.         movewords(swaplength>>1,(BYTE far *)suffix,swapvidbuf);
  1511.      }
  1512.       if (swapsetup == swapnormread)
  1513.      swapnormwrite();
  1514.       swapoffset += swaplength;
  1515.       }
  1516.    if (swaptype == 2)
  1517.       close(memhandle);
  1518.    discardgraphics();
  1519. }
  1520.  
  1521. #endif
  1522.  
  1523. void discardgraphics() /* release expanded/extended memory if any in use */
  1524. {
  1525. #ifndef XFRACT
  1526.    switch(swaptype) {
  1527.       case 0:
  1528.      emmdeallocate(memhandle);
  1529.      break;
  1530.       case 1:
  1531.      xmmdeallocate(memhandle);
  1532.       }
  1533.    swaptype = -1;
  1534. #endif
  1535. }
  1536.  
  1537. extern int extraseg;
  1538. extern int badconfig;
  1539. extern struct videoinfo far videotable[];
  1540. struct videoinfo far *vidtbl;  /* temporarily loaded fractint.cfg info */
  1541. int vidtbllen;               /* number of entries in above           */
  1542.  
  1543. int load_fractint_cfg(int options)
  1544. {
  1545.    /* Reads fractint.cfg, loading videoinfo entries into extraseg. */
  1546.    /* Sets vidtbl pointing to the loaded table, and returns the    */
  1547.    /* number of entries (also sets vidtbllen to this).           */
  1548.    /* Past vidtbl, cfglinenums are stored for update_fractint_cfg. */
  1549.    /* If fractint.cfg is not found or invalid, issues a message    */
  1550.    /* (first time the problem occurs only, and only if options is  */
  1551.    /* zero) and uses the hard-coded table.               */
  1552.  
  1553.    FILE *cfgfile;
  1554.    struct videoinfo far *vident;
  1555.    int far *cfglinenums;
  1556.    int linenum;
  1557.    int i, j, keynum, ax, bx, cx, dx, dotmode, xdots, ydots, colors;
  1558.    int commas[10];
  1559.    int textsafe2;
  1560.    char tempstring[150];
  1561.  
  1562.    vidtbl = MK_FP(extraseg,0);
  1563.    cfglinenums = (int far *)(&vidtbl[MAXVIDEOMODES]);
  1564.  
  1565. #ifdef XFRACT
  1566.     badconfig = -1;
  1567. #endif
  1568.  
  1569.    if (badconfig)  /* fractint.cfg already known to be missing or bad */
  1570.       goto use_resident_table;
  1571.  
  1572.    findpath("fractint.cfg",tempstring);
  1573.    if (tempstring[0] == 0                 /* can't find the file */
  1574.      || (cfgfile = fopen(tempstring,"r")) == NULL)   /* can't open it */
  1575.       goto bad_fractint_cfg;
  1576.  
  1577.    vidtbllen = 0;
  1578.    linenum = 0;
  1579.    vident = vidtbl;
  1580.    while (vidtbllen < MAXVIDEOMODES
  1581.      && fgets(tempstring, 120, cfgfile)) {
  1582.       ++linenum;
  1583.       if (tempstring[0] == ';') continue;   /* comment line */
  1584.       tempstring[120] = 0;
  1585.       tempstring[strlen(tempstring)-1] = 0; /* zap trailing \n */
  1586.       memset(commas,0,20);
  1587.       i = j = -1;
  1588.       while (1) {
  1589.      if (tempstring[++i] < ' ') {
  1590.         if (tempstring[i] == 0) break;
  1591.         tempstring[i] = ' '; /* convert tab (or whatever) to blank */
  1592.         }
  1593.      else if (tempstring[i] == ',' && ++j < 10) {
  1594.         commas[j] = i + 1;     /* remember start of next field */
  1595.         tempstring[i] = 0;     /* make field a separate string */
  1596.         }
  1597.      }
  1598.       keynum = check_vidmode_keyname(tempstring);
  1599.       sscanf(&tempstring[commas[1]],"%x",&ax);
  1600.       sscanf(&tempstring[commas[2]],"%x",&bx);
  1601.       sscanf(&tempstring[commas[3]],"%x",&cx);
  1602.       sscanf(&tempstring[commas[4]],"%x",&dx);
  1603.       dotmode      = atoi(&tempstring[commas[5]]);
  1604.       xdots      = atoi(&tempstring[commas[6]]);
  1605.       ydots      = atoi(&tempstring[commas[7]]);
  1606.       colors      = atoi(&tempstring[commas[8]]);
  1607.       textsafe2   = dotmode / 100;
  1608.       dotmode     %= 100;
  1609.       if (j != 9 ||
  1610.         keynum < 0 ||
  1611.         dotmode < 0 || dotmode > 30 ||
  1612.         textsafe2 < 0 || textsafe2 > 4 ||
  1613.         xdots < 160 || xdots > MAXPIXELS ||
  1614.         ydots < 160 || ydots > MAXPIXELS ||
  1615.         (colors != 0 && colors != 2 && colors != 4 && colors != 16 &&
  1616.          colors != 256)
  1617.        )
  1618.      goto bad_fractint_cfg;
  1619.       cfglinenums[vidtbllen] = linenum; /* for update_fractint_cfg */
  1620.       far_memcpy(vident->name,     (char far *)&tempstring[commas[0]],25);
  1621.       far_memcpy(vident->comment,(char far *)&tempstring[commas[9]],25);
  1622.       vident->name[25] = vident->comment[25] = 0;
  1623.       vident->keynum      = keynum;
  1624.       vident->videomodeax = ax;
  1625.       vident->videomodebx = bx;
  1626.       vident->videomodecx = cx;
  1627.       vident->videomodedx = dx;
  1628.       vident->dotmode      = textsafe2 * 100 + dotmode;
  1629.       vident->xdots      = xdots;
  1630.       vident->ydots      = ydots;
  1631.       vident->colors      = colors;
  1632.       ++vident;
  1633.       ++vidtbllen;
  1634.       }
  1635.    fclose(cfgfile);
  1636.    return (vidtbllen);
  1637.  
  1638. bad_fractint_cfg:
  1639.    badconfig = -1; /* bad, no message issued yet */
  1640.    if (options == 0)
  1641.       bad_fractint_cfg_msg();
  1642.  
  1643. use_resident_table:
  1644.    vidtbllen = 0;
  1645.    vident = vidtbl;
  1646.    for (i = 0; i < MAXVIDEOTABLE; ++i) {
  1647.       if (videotable[i].xdots) {
  1648.      far_memcpy((char far *)vident,(char far *)&videotable[i],
  1649.             sizeof(*vident));
  1650.      ++vident;
  1651.      ++vidtbllen;
  1652.      }
  1653.       }
  1654.    return (vidtbllen);
  1655.  
  1656. }
  1657.  
  1658. void bad_fractint_cfg_msg()
  1659. {
  1660. static char far badcfgmsg[]={"\
  1661. File FRACTINT.CFG is missing or invalid.\n\
  1662. See Hardware Support and Video Modes in the full documentation for help.\n\
  1663. I will continue with only the built-in video modes available."};
  1664.    stopmsg(0,badcfgmsg);
  1665.    badconfig = 1; /* bad, message issued */
  1666. }
  1667.  
  1668. void load_videotable(int options)
  1669. {
  1670.    /* Loads fractint.cfg and copies the video modes which are */
  1671.    /* assigned to function keys into videotable.          */
  1672.    int keyents,i;
  1673.    load_fractint_cfg(options); /* load fractint.cfg to extraseg */
  1674.    keyents = 0;
  1675.    far_memset((char far *)videotable,0,sizeof(*vidtbl)*MAXVIDEOTABLE);
  1676.    for (i = 0; i < vidtbllen; ++i) {
  1677.       if (vidtbl[i].keynum > 0) {
  1678.      far_memcpy((char far *)&videotable[keyents],(char far *)&vidtbl[i],
  1679.             sizeof(*vidtbl));
  1680.      if (++keyents >= MAXVIDEOTABLE)
  1681.         break;
  1682.      }
  1683.       }
  1684. }
  1685.  
  1686. int check_vidmode_key(int option,int k)
  1687. {
  1688.    int i;
  1689.    /* returns videotable entry number if the passed keystroke is a  */
  1690.    /* function key currently assigned to a video mode, -1 otherwise */
  1691.    if (k == 1400)           /* special value from select_vid_mode  */
  1692.       return(MAXVIDEOTABLE-1); /* for last entry with no key assigned */
  1693.    if (k != 0)
  1694.       if (option == 0) { /* check resident video mode table */
  1695.      for (i = 0; i < MAXVIDEOTABLE; ++i) {
  1696.         if (videotable[i].keynum == k)
  1697.            return(i);
  1698.         }
  1699.      }
  1700.       else { /* check full vidtbl */
  1701.      for (i = 0; i < vidtbllen; ++i) {
  1702.         if (vidtbl[i].keynum == k)
  1703.            return(i);
  1704.         }
  1705.      }
  1706.    return(-1);
  1707. }
  1708.  
  1709. int check_vidmode_keyname(char *kname)
  1710. {
  1711.    /* returns key number for the passed keyname, 0 if not a keyname */
  1712.    int i,keyset;
  1713.    keyset = 1058;
  1714.    if (*kname == 'S' || *kname == 's') {
  1715.       keyset = 1083;
  1716.       ++kname;
  1717.       }
  1718.    else if (*kname == 'C' || *kname == 'c') {
  1719.       keyset = 1093;
  1720.       ++kname;
  1721.       }
  1722.    else if (*kname == 'A' || *kname == 'a') {
  1723.       keyset = 1103;
  1724.       ++kname;
  1725.       }
  1726.    if (*kname != 'F' && *kname != 'f')
  1727.       return(0);
  1728.    if (*++kname < '1' || *kname > '9')
  1729.       return(0);
  1730.    i = *kname - '0';
  1731.    if (*++kname != 0 && *kname != ' ') {
  1732.       if (*kname != '0' || i != 1)
  1733.      return(0);
  1734.       i = 10;
  1735.       ++kname;
  1736.       }
  1737.    while (*kname)
  1738.       if (*(kname++) != ' ')
  1739.      return(0);
  1740.    if ((i += keyset) < 2)
  1741.       i = 0;
  1742.    return(i);
  1743. }
  1744.  
  1745. void vidmode_keyname(int k,char *buf)
  1746. {
  1747.    /* set buffer to name of passed key number */
  1748.    *buf = 0;
  1749.    if (k > 0) {
  1750.       if (k > 1103) {
  1751.      *(buf++) = 'A';
  1752.      k -= 1103;
  1753.      }
  1754.       else if (k > 1093) {
  1755.      *(buf++) = 'C';
  1756.      k -= 1093;
  1757.      }
  1758.       else if (k > 1083) {
  1759.      *(buf++) = 'S';
  1760.      k -= 1083;
  1761.      }
  1762.       else
  1763.      k -= 1058;
  1764.       sprintf(buf,"F%d",k);
  1765.       }
  1766. }
  1767.