Ejemplo n.º 1
0
static int CheckBounds(long start, long length, U16 handle)
{
    if (handletable[handle].Nowhere.size - start - length < 0)
    {
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, "Memory reference out of bounds.");
        DisplayHandle(handle);
        return (1);
    }
    if (length > (long)USHRT_MAX)
    {
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, "Tried to move > 65,535 bytes.");
        DisplayHandle(handle);
        return (1);
    }
    if (handletable[handle].Nowhere.stored_at == DISK &&
            (stackavail() <= DISKWRITELEN))
    {
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, "Stack space insufficient for disk memory.");
        DisplayHandle(handle);
        return (1);
    }
    if (length <= 0)
    {
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, "Zero or negative length.");
        DisplayHandle(handle);
        return (1);
    }
    if (start < 0)
    {
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, "Negative offset.");
        DisplayHandle(handle);
        return (1);
    }
    return (0);
}
Ejemplo n.º 2
0
// show floating point and bignumber corners
void showcorners(char *s)
{
    int dec = 20;
    char msg[100], msg1[100], msg3[100];
    bntostr(msg, dec, bnxmin);
    sprintf(msg1, "bnxmin=%s\nxxmin= %.20f\n\n", msg, xxmin);
    strcpy(msg3, s);
    strcat(msg3, "\n");
    strcat(msg3, msg1);
    bntostr(msg, dec, bnxmax);
    sprintf(msg1, "bnxmax=%s\nxxmax= %.20f\n\n", msg, xxmax);
    strcat(msg3, msg1);
    bntostr(msg, dec, bnymin);
    sprintf(msg1, "bnymin=%s\nyymin= %.20f\n\n", msg, yymin);
    strcat(msg3, msg1);
    bntostr(msg, dec, bnymax);
    sprintf(msg1, "bnymax=%s\nyymax= %.20f\n\n", msg, yymax);
    strcat(msg3, msg1);
    bntostr(msg, dec, bnx3rd);
    sprintf(msg1, "bnx3rd=%s\nxx3rd= %.20f\n\n", msg, xx3rd);
    strcat(msg3, msg1);
    bntostr(msg, dec, bny3rd);
    sprintf(msg1, "bny3rd=%s\nyy3rd= %.20f\n\n", msg, yy3rd);
    strcat(msg3, msg1);
    if (stopmsg(STOPMSG_NONE, msg3) == -1)
        goodbye();
}
Ejemplo n.º 3
0
void showcornersbf(char *s)
{
    int dec = decimals;
    char msg[100], msg1[100], msg3[600];
    if (dec > 20)
        dec = 20;
    bftostr(msg, dec, bfxmin);
    sprintf(msg1, "bfxmin=%s\nxxmin= %.20f decimals %d bflength %d\n\n",
            msg, xxmin, decimals, bflength);
    strcpy(msg3, s);
    strcat(msg3, "\n");
    strcat(msg3, msg1);
    bftostr(msg, dec, bfxmax);
    sprintf(msg1, "bfxmax=%s\nxxmax= %.20f\n\n", msg, xxmax);
    strcat(msg3, msg1);
    bftostr(msg, dec, bfymin);
    sprintf(msg1, "bfymin=%s\nyymin= %.20f\n\n", msg, yymin);
    strcat(msg3, msg1);
    bftostr(msg, dec, bfymax);
    sprintf(msg1, "bfymax=%s\nyymax= %.20f\n\n", msg, yymax);
    strcat(msg3, msg1);
    bftostr(msg, dec, bfx3rd);
    sprintf(msg1, "bfx3rd=%s\nxx3rd= %.20f\n\n", msg, xx3rd);
    strcat(msg3, msg1);
    bftostr(msg, dec, bfy3rd);
    sprintf(msg1, "bfy3rd=%s\nyy3rd= %.20f\n\n", msg, yy3rd);
    strcat(msg3, msg1);
    if (stopmsg(STOPMSG_NONE, msg3) == -1)
        goodbye();
}
Ejemplo n.º 4
0
void DisplayMemory()
{
    char buf[MSGLEN];

    sprintf(buf, "disk=%lu", get_disk_space());
    stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, buf);
}
Ejemplo n.º 5
0
void show_two_bf(char *s1, bf_t t1, char *s2, bf_t t2, int digits)
{
    char msg1[200], msg2[200], msg3[400];
    bftostr_e(msg1, digits, t1);
    bftostr_e(msg2, digits, t2);
    sprintf(msg3, "\n%s->%s\n%s->%s", s1, msg1, s2, msg2);
    if (stopmsg(STOPMSG_NONE, msg3) == -1)
        goodbye();
}
Ejemplo n.º 6
0
//********************************************************************
void show_var_bn(char *s, bn_t n)
{
    char msg[200];
    strcpy(msg, s);
    strcat(msg, " ");
    bntostr(msg+strlen(s), 40, n);
    msg[79] = 0;
    stopmsg(STOPMSG_NONE, msg);
}
Ejemplo n.º 7
0
// compare a double and bignumber
void comparevaluesbf(char *s, LDBL x, bf_t bfx)
{
    int dec = 40;
    char msg[300], msg1[300];
    bftostr_e(msg, dec, bfx);
    sprintf(msg1, "%s\nbignum=%s\ndouble=%.20Lf\n\n", s, msg, x);
    if (stopmsg(STOPMSG_NONE, msg1) == -1)
        goodbye();
}
Ejemplo n.º 8
0
void DisplayHandle(U16 handle)
{
    char buf[MSGLEN];

    sprintf(buf, "Handle %u, type %s, size %li", handle, memstr[handletable[handle].Nowhere.stored_at],
            handletable[handle].Nowhere.size);
    if (stopmsg(STOPMSG_CANCEL | STOPMSG_NO_BUZZER, (char *)buf) == -1)
        goodbye(); // bailout if ESC, it's messy, but should work
}
Ejemplo n.º 9
0
void ExitCheck()
{
    if (numTOTALhandles != 0)
    {
        stopmsg(STOPMSG_NONE,
            "Error - not all memory released, I'll get it.");
        for (U16 i = 1; i < MAXHANDLES; i++)
        {
            if (handletable[i].Nowhere.stored_at != NOWHERE)
            {
                char buf[MSGLEN];
                sprintf(buf, "Memory type %s still allocated.  Handle = %i.",
                        memstr[handletable[i].Nowhere.stored_at], i);
                stopmsg(STOPMSG_NONE, buf);
                MemoryRelease(i);
            }
        }
    }
}
Ejemplo n.º 10
0
//********************************************************************
void show_var_bf(char *s, bf_t n)
{
    char msg[200];
    strcpy(msg, s);
    strcat(msg, " ");
    bftostr_e(msg+strlen(s), 40, n);
    msg[79] = 0;
    if (stopmsg(STOPMSG_NONE, msg) == -1)
        goodbye();
}
Ejemplo n.º 11
0
void show_three_bf(char *s1, bf_t t1, char *s2, bf_t t2, char *s3, bf_t t3, int digits)
{
    char msg1[200], msg2[200], msg3[200], msg4[600];
    bftostr_e(msg1, digits, t1);
    bftostr_e(msg2, digits, t2);
    bftostr_e(msg3, digits, t3);
    sprintf(msg4, "\n%s->%s\n%s->%s\n%s->%s", s1, msg1, s2, msg2, s3, msg3);
    if (stopmsg(STOPMSG_NONE, msg4) == -1)
        goodbye();
}
Ejemplo n.º 12
0
static void DisplayError(int stored_at, long howmuch)
{
    // This routine is used to display an error message when the requested
    // memory type cannot be allocated due to insufficient memory, AND there
    // is also insufficient disk space to use as memory.

    char buf[MSGLEN*2];
    sprintf(buf, "Allocating %ld Bytes of %s memory failed.\n"
            "Alternate disk space is also insufficient. Goodbye",
            howmuch, memstr[stored_at]);
    stopmsg(STOPMSG_NONE, buf);
}
Ejemplo n.º 13
0
// show globals
void showbfglobals(char *s)
{
    char msg[300];
    sprintf(msg, "%s\n\
bnstep=%d bnlength=%d intlength=%d rlength=%d padding=%d\n\
shiftfactor=%d decimals=%d bflength=%d rbflength=%d \n\
bfdecimals=%d ",
            s, bnstep, bnlength, intlength, rlength, padding,
            shiftfactor, decimals, bflength, rbflength,
            bfdecimals);
    if (stopmsg(STOPMSG_NONE, msg) == -1)
        goodbye();
}
Ejemplo n.º 14
0
void showcornersdbl(char *s)
{
    char msg[400];
    sprintf(msg, "%s\n"
            "xxmin= %.20f xxmax= %.20f\n"
            "yymin= %.20f yymax= %.20f\n"
            "xx3rd= %.20f yy3rd= %.20f\n"
            "delxx= %.20Lf delyy= %.20Lf\n"
            "delx2= %.20Lf dely2= %.20Lf",
            s, xxmin, xxmax, yymin, yymax, xx3rd, yy3rd,
            delxx, delyy, delxx2, delyy2);
    if (stopmsg(STOPMSG_NONE, msg) == -1)
        goodbye();
}
Ejemplo n.º 15
0
/* Allocates a bn_t variable on stack                                   */
bn_t alloc_stack(size_t size)
   {
   long stack_addr;
   if(bf_math == 0)
      {
      static FCODE msg[] = {"alloc_stack called with bf_math==0"};
      stopmsg(0,msg);
      return(0);
      }
   stack_addr = (long)(stack_ptr-bnroot)+size+ENDVID;

   if((stack_addr) > ((long)0x10000l-(bflength+2)*22))
      {
      static FCODE msg[] = {"Aborting, Out of Bignum Stack Space"};
      stopmsg(0,msg);
      goodbye();
      }
   /* keep track of max ptr */
   if(stack_addr > maxptr)
      maxptr = stack_addr;
   stack_ptr += size;   /* increment stack pointer */
   return(stack_ptr - size);
   }
Ejemplo n.º 16
0
static void WhichDiskError(int I_O)
{
    // Set I_O == 1 after a file create, I_O == 2 after a file set value
    // Set I_O == 3 after a file write, I_O == 4 after a file read
    char buf[MSGLEN];
    const char *pats[4] =
    {
        "Create file error %d:  %s",
        "Set file error %d:  %s",
        "Write file error %d:  %s",
        "Read file error %d:  %s"
    };
    sprintf(buf, pats[(1 <= I_O && I_O <= 4) ? (I_O-1) : 0], errno, strerror(errno));
    if (debugflag == debug_flags::display_memory_statistics)
        if (stopmsg(STOPMSG_CANCEL | STOPMSG_NO_BUZZER, (char *)buf) == -1)
            goodbye(); // bailout if ESC
}
Ejemplo n.º 17
0
static int get_lsys_name(PGENSEL gs)         /* get the Lsystem formula name */
{
   int numformulas, i;
   FILE *File;
   char buf[201], tempstring[201];

   for (i = 0; i < MAX_SEL; i++) {
      gs->szNames[i][0] = 0;
      }

   _fstrcpy(tempstring, npTempParms.szLSysFileName);
   if ((File = fopen(tempstring, "rt")) == NULL) {
      sprintf(buf,"I Can't find %s", tempstring);
      stopmsg(1,buf);
      gs->szSelected[0] = 0;
      return(-1);
      }

   numformulas = 0;
   while (1) {
      int c;
      gs->szNames[numformulas][0] = 0;
      if (fscanf(File, " %F20[^ \n\t({]", gs->szNames[numformulas]) == EOF)
         break;
      while(c = getc(File)) {
         if(c == EOF || c == '{' || c == '\n')
            break;
         }
      if(c == EOF)
         break;
      else if(c != '\n') {
skipcomments:
         if(fscanf(File, "%200[^}]", buf) == EOF) break;
         if (getc(File) != '}') goto skipcomments;
         if (_fstricmp(gs->szNames[numformulas],"") != 0 &&
             _fstricmp(gs->szNames[numformulas],"comment") != 0)
                 if (++numformulas >= MAX_SEL) break;
         }
      }
   fclose(File);

   gs->sCountNames = numformulas;
   /* now sort the names */
   sel_sort(gs);
   return(0);
}
Ejemplo n.º 18
0
static int get_formula_names(PGENSEL gs)  /* get the fractal formula names */
{
   int numformulas, i;
   FILE *File;
   char msg[81], tempstring[201];

   gs->szSelected[0] = 0;             /* start by declaring failure */
   for (i = 0; i < MAX_SEL; i++) {
      gs->szNames[i][0] = 0;
      }

   _fstrcpy(tempstring, npTempParms.szFormFileName);
   if((File = fopen(tempstring, "rt")) == NULL) {
      sprintf(msg,"I Can't find %s", tempstring);
      stopmsg(1,msg);
      return(-1);
   }

   numformulas = 0;
   while(fscanf(File, " %F20[^ \n\t({]", gs->szNames[numformulas]) != EOF) {
      int c;

      while(c = getc(File)) {
         if(c == EOF || c == '{' || c == '\n')
            break;
      }
      if(c == EOF)
         break;
      else if(c != '\n'){
         numformulas++;
         if (numformulas >= MAX_SEL-1) break;
skipcomments:
         if(fscanf(File, "%200[^}]", tempstring) == EOF) break;
         if (getc(File) != '}') goto skipcomments;
         if (_fstricmp(gs->szNames[numformulas-1],"") == 0 ||
             _fstricmp(gs->szNames[numformulas-1],"comment") == 0)
                 numformulas--;
      }
   }
   fclose(File);

   gs->sCountNames = numformulas;
   /* now sort the names */
   sel_sort(gs);
   return(0);
}
Ejemplo n.º 19
0
// for aspect ratio debugging
void showaspect(char *s)
{
    bf_t bt1, bt2, aspect;
    char msg[100], str[100];
    int saved;
    saved = save_stack();
    bt1    = alloc_stack(rbflength+2);
    bt2    = alloc_stack(rbflength+2);
    aspect = alloc_stack(rbflength+2);
    sub_bf(bt1, bfxmax, bfxmin);
    sub_bf(bt2, bfymax, bfymin);
    div_bf(aspect, bt2, bt1);
    bftostr(str, 10, aspect);
    sprintf(msg, "aspect %s\nfloat %13.10f\nbf    %s\n\n",
            s,
            (yymax-yymin)/(xxmax-xxmin),
            str);
    if (stopmsg(STOPMSG_NONE, msg) == -1)
        goodbye();
    restore_stack(saved);
}
Ejemplo n.º 20
0
int init_pan_or_recalc(int do_zoomout) /* decide to recalc, or to chg worklist & pan */
{   int i,j,row,col,y,alignmask,listfull;
    if (zwidth == 0.0)
        return(0); /* no zoombox, leave calc_status as is */
    /* got a zoombox */
    if ((alignmask=check_pan()-1) < 0) {
        calc_status = 0; /* can't pan, trigger recalc */
        return(0); }
    if (zbx == 0.0 && zby == 0.0) {
        clearbox();
        return(0); } /* box is full screen, leave calc_status as is */
    col = (int)(zbx*(dxsize+PIXELROUND)); /* calc dest col,row of topleft pixel */
    row = (int)(zby*(dysize+PIXELROUND));
    if (do_zoomout) { /* invert row and col */
        row = 0-row;
        col = 0-col; }
    if ((row&alignmask) != 0 || (col&alignmask) != 0) {
        calc_status = 0; /* not on useable pixel alignment, trigger recalc */
        return(0); }
    /* pan */
    num_worklist = 0;
    if (calc_status == 2) {
       start_resume();
       get_resume(sizeof(int),&num_worklist,sizeof(worklist),worklist,0);
       } /* don't do end_resume! we might still change our mind */
    /* adjust existing worklist entries */
    for (i=0; i<num_worklist; ++i) {
        worklist[i].yystart -= row;
        worklist[i].yystop  -= row;
        worklist[i].yybegin -= row;
        worklist[i].xxstart -= col;
        worklist[i].xxstop  -= col;
        }
    /* add worklist entries for the new edges */
    listfull = i = 0;
    j = ydots-1;
    if (row < 0) {
        listfull |= add_worklist(0,xdots-1,0,0-row-1,0,0,0);
        i = 0 - row; }
    if (row > 0) {
        listfull |= add_worklist(0,xdots-1,ydots-row,ydots-1,ydots-row,0,0);
        j = ydots - row - 1; }
    if (col < 0)
        listfull |= add_worklist(0,0-col-1,i,j,i,0,0);
    if (col > 0)
        listfull |= add_worklist(xdots-col,xdots-1,i,j,i,0,0);
    if (listfull != 0) {
    static FCODE msg[] = {"\
Tables full, can't pan current image.\n\
Cancel resumes old image, continue pans and calculates a new one."};
        if (stopmsg(2,msg)) {
            zwidth = 0; /* cancel the zoombox */
            drawbox(1); }
        else
            calc_status = 0; /* trigger recalc */
        return(0); }
    /* now we're committed */
    calc_status = 2;
    clearbox();
    if (row > 0) /* move image up */
        for (y=0; y<ydots; ++y) move_row(y+row,y,col);
    else         /* move image down */
        for (y=ydots; --y>=0;)  move_row(y+row,y,col);
    fix_worklist(); /* fixup any out of bounds worklist entries */
    alloc_resume(sizeof(worklist)+10,1); /* post the new worklist */
    put_resume(sizeof(int),&num_worklist,sizeof(worklist),worklist,0);
    return(0);
    }
Ejemplo n.º 21
0
static void init_bf_2(void)
    {
    int i;
    long ptr;
    save_bf_vars(); /* copy corners values for conversion */

    calc_lengths();

    /* allocate all the memory at once within the same segment (DOS) */
#if defined(BIG_FAR) || defined(BIG_ANSI_C)
    bnroot = (bf_t)MK_FP(extraseg,ENDVID); /* ENDVID is to avoid videotable */
#else /* BASED or NEAR  */
    bnroot = (bf_t)ENDVID;  /* ENDVID is to avoid videotable */
#endif
#ifdef BIG_BASED
    bignum_seg = (_segment)extraseg;
#endif
    /* at present time one call would suffice, but this logic allows
       mulytiple kinds of alternate math eg long double */
    if((i = find_alternate_math(fractype, BIGNUM)) > -1)
       bf_math = alternatemath[i].math;
    else if((i = find_alternate_math(fractype, BIGFLT)) > -1)
       bf_math = alternatemath[i].math;
    else
       bf_math = 1; /* maybe called from cmdfiles.c and fractype not set */

    floatflag=1;

    /* Now split up the memory among the pointers */
    /* internal pointers */
    ptr        = 0;
    bntmp1     = bnroot+ptr; ptr += rlength;
    bntmp2     = bnroot+ptr; ptr += rlength;
    bntmp3     = bnroot+ptr; ptr += rlength;
    bntmp4     = bnroot+ptr; ptr += rlength;
    bntmp5     = bnroot+ptr; ptr += rlength;
    bntmp6     = bnroot+ptr; ptr += rlength;

    bftmp1     = bnroot+ptr; ptr += rbflength+2;
    bftmp2     = bnroot+ptr; ptr += rbflength+2;
    bftmp3     = bnroot+ptr; ptr += rbflength+2;
    bftmp4     = bnroot+ptr; ptr += rbflength+2;
    bftmp5     = bnroot+ptr; ptr += rbflength+2;
    bftmp6     = bnroot+ptr; ptr += rbflength+2;

    bftmpcpy1  = bnroot+ptr; ptr += (rbflength+2)*2;
    bftmpcpy2  = bnroot+ptr; ptr += (rbflength+2)*2;

    bntmpcpy1  = bnroot+ptr; ptr += (rlength*2);
    bntmpcpy2  = bnroot+ptr; ptr += (rlength*2);

    if (bf_math == BIGNUM)
    {
    bnxmin     = bnroot+ptr; ptr += bnlength;
    bnxmax     = bnroot+ptr; ptr += bnlength;
    bnymin     = bnroot+ptr; ptr += bnlength;
    bnymax     = bnroot+ptr; ptr += bnlength;
    bnx3rd     = bnroot+ptr; ptr += bnlength;
    bny3rd     = bnroot+ptr; ptr += bnlength;
    bnxdel     = bnroot+ptr; ptr += bnlength;
    bnydel     = bnroot+ptr; ptr += bnlength;
    bnxdel2    = bnroot+ptr; ptr += bnlength;
    bnydel2    = bnroot+ptr; ptr += bnlength;
    bnold.x    = bnroot+ptr; ptr += rlength;
    bnold.y    = bnroot+ptr; ptr += rlength;
    bnnew.x    = bnroot+ptr; ptr += rlength;
    bnnew.y    = bnroot+ptr; ptr += rlength;
    bnsaved.x  = bnroot+ptr; ptr += bnlength;
    bnsaved.y  = bnroot+ptr; ptr += bnlength;
    bnclosenuff= bnroot+ptr; ptr += bnlength;
    bnparm.x   = bnroot+ptr; ptr += bnlength;
    bnparm.y   = bnroot+ptr; ptr += bnlength;
    bntmpsqrx  = bnroot+ptr; ptr += rlength;
    bntmpsqry  = bnroot+ptr; ptr += rlength;
    bntmp      = bnroot+ptr; ptr += rlength;
    }
    if (bf_math == BIGFLT)
    {
    bfxdel     = bnroot+ptr; ptr += bflength+2;
    bfydel     = bnroot+ptr; ptr += bflength+2;
    bfxdel2    = bnroot+ptr; ptr += bflength+2;
    bfydel2    = bnroot+ptr; ptr += bflength+2;
    bfold.x    = bnroot+ptr; ptr += rbflength+2;
    bfold.y    = bnroot+ptr; ptr += rbflength+2;
    bfnew.x    = bnroot+ptr; ptr += rbflength+2;
    bfnew.y    = bnroot+ptr; ptr += rbflength+2;
    bfsaved.x  = bnroot+ptr; ptr += bflength+2;
    bfsaved.y  = bnroot+ptr; ptr += bflength+2;
    bfclosenuff= bnroot+ptr; ptr += bflength+2;
    bfparm.x   = bnroot+ptr; ptr += bflength+2;
    bfparm.y   = bnroot+ptr; ptr += bflength+2;
    bftmpsqrx  = bnroot+ptr; ptr += rbflength+2;
    bftmpsqry  = bnroot+ptr; ptr += rbflength+2;
    big_pi     = bnroot+ptr; ptr += bflength+2;
    bftmp      = bnroot+ptr; ptr += rbflength+2;
    }
    bf10tmp    = bnroot+ptr; ptr += bfdecimals+4;

    /* ptr needs to be 16-bit aligned on some systems */
    ptr = (ptr+1)&~1;

    stack_ptr  = bnroot + ptr;
    startstack = ptr;

    /* max stack offset from bnroot */
    maxstack = (long)0x10000l-(bflength+2)*22-ENDVID;

    /* sanity check */
    /* leave room for NUMVARS variables allocated from stack */
    /* also leave room for the safe area at top of segment */
    if(ptr + NUMVARS*(bflength+2) > (long)0x10000l -(bflength+2)*22-ENDVID)
       {
       char msg[80];
       char nmsg[80];
       static FCODE fmsg[] = {"Requested precision of %d too high, aborting"};
       far_strcpy(nmsg,fmsg);
       sprintf(msg,nmsg,decimals);
       stopmsg(0,msg);
       goodbye();
       }

    /* room for 6 corners + 6 save corners + 10 params at top of extraseg */
    /* this area is safe - use for variables that are used outside fractal*/
    /* generation - e.g. zoom box variables */
    ptr  = ((long)0x10000l-(bflength+2)*22-ENDVID);
    bfxmin     = bnroot+ptr; ptr += bflength+2;
    bfxmax     = bnroot+ptr; ptr += bflength+2;
    bfymin     = bnroot+ptr; ptr += bflength+2;
    bfymax     = bnroot+ptr; ptr += bflength+2;
    bfx3rd     = bnroot+ptr; ptr += bflength+2;
    bfy3rd     = bnroot+ptr; ptr += bflength+2;
    for(i=0;i<10;i++)
       {
       bfparms[i]  = bnroot+ptr; ptr += bflength+2;
       }
    bfsxmin    = bnroot+ptr; ptr += bflength+2;
    bfsxmax    = bnroot+ptr; ptr += bflength+2;
    bfsymin    = bnroot+ptr; ptr += bflength+2;
    bfsymax    = bnroot+ptr; ptr += bflength+2;
    bfsx3rd    = bnroot+ptr; ptr += bflength+2;
    bfsy3rd    = bnroot+ptr; ptr += bflength+2;
    /* end safe vars */

    /* good citizens initialize variables */
    if(bf_save_len)  /* leave save area */
       far_memset(bnroot+(bf_save_len+2)*22,0,(unsigned)(startstack-(bf_save_len+2)*22));
    else /* first time through - nothing saved */
       {
       /* high variables */
       far_memset(bnroot+((long)0x10000l-(bflength+2)*22-ENDVID),0,(bflength+2)*22);
       /* low variables */
       far_memset(bnroot,0,(unsigned)startstack);
       }

    restore_bf_vars();

    /* Initialize the value of pi.  Needed for trig functions. */
    /* init_big_pi(); */
/* call to init_big_pi() has been moved to fractal setup routine */
/* so as to use only when necessary. */

    }
Ejemplo n.º 22
0
U16 MemoryAlloc(U16 size, long count, int stored_at)
{
    // Returns handle number if successful, 0 or nullptr if failure
    U16 handle = 0;
    int use_this_type;
    long toallocate;

    toallocate = count * size;
    if (toallocate <= 0)    // we failed, can't allocate > 2,147,483,647
        return 0U;          // or it wraps around to negative

    /* check structure for requested memory type (add em up) to see if
       sufficient amount is available to grant request */

    use_this_type = check_for_mem(stored_at, toallocate);
    if (use_this_type == NOWHERE)
    {
        DisplayError(stored_at, toallocate);
        goodbye();
    }

    // get next available handle

    handle = next_handle();

    if (handle >= MAXHANDLES || handle == 0)
    {
        DisplayHandle(handle);
        return 0U;
        // Oops, do something about this! ?????
    }

    // attempt to allocate requested memory type
    bool success = false;
    switch (use_this_type)
    {
    default:
    case NOWHERE: // MemoryAlloc
        use_this_type = NOWHERE; // in case nonsense value is passed
        break;

    case MEMORY: // MemoryAlloc
        // Availability of memory checked in check_for_mem()
        handletable[handle].Linearmem.memory = (BYTE *)malloc(toallocate);
        handletable[handle].Linearmem.size = toallocate;
        handletable[handle].Linearmem.stored_at = MEMORY;
        numTOTALhandles++;
        success = true;
        break;

    case DISK: // MemoryAlloc
        memfile[9] = (char)(handle % 10 + (int)'0');
        memfile[8] = (char)((handle % 100) / 10 + (int)'0');
        memfile[7] = (char)((handle % 1000) / 100 + (int)'0');
        if (disktarga)
            handletable[handle].Disk.file = dir_fopen(workdir, light_name, "a+b");
        else
            handletable[handle].Disk.file = dir_fopen(tempdir, memfile, "w+b");
        rewind(handletable[handle].Disk.file);
        if (fseek(handletable[handle].Disk.file, toallocate, SEEK_SET) != 0)
            handletable[handle].Disk.file = nullptr;
        if (handletable[handle].Disk.file == nullptr)
        {
            handletable[handle].Disk.stored_at = NOWHERE;
            use_this_type = NOWHERE;
            WhichDiskError(1);
            DisplayMemory();
            driver_buzzer(buzzer_codes::PROBLEM);
            break;
        }
        numTOTALhandles++;
        success = true;
        fclose(handletable[handle].Disk.file); // so clusters aren't lost if we crash while running
        if (disktarga)
            handletable[handle].Disk.file = dir_fopen(workdir, light_name, "r+b");
        else
            handletable[handle].Disk.file = dir_fopen(tempdir, memfile, "r+b"); // reopen
        rewind(handletable[handle].Disk.file);
        handletable[handle].Disk.size = toallocate;
        handletable[handle].Disk.stored_at = DISK;
        use_this_type = DISK;
        break;
    } // end of switch

    if (stored_at != use_this_type && debugflag == debug_flags::display_memory_statistics)
    {
        char buf[MSGLEN];
        sprintf(buf, "Asked for %s, allocated %lu bytes of %s, handle = %u.",
                memstr[stored_at], toallocate, memstr[use_this_type], handle);
        stopmsg(STOPMSG_INFO_ONLY | STOPMSG_NO_BUZZER, (char *)buf);
        DisplayMemory();
    }

    if (success)
        return (handle);
    else      // return 0 if failure
        return 0U;
}
Ejemplo n.º 23
0
int abortmsg(char const *file, unsigned int line, int flags, char const *msg)
{
    char buffer[3*80];
    sprintf(buffer, "%s(%d):\n%s", file, line, msg);
    return stopmsg(flags, buffer);
}
Ejemplo n.º 24
0
int common_startdisk(long newrowsize, long newcolsize, int colors)
{
    int freemem;
    long memorysize;
    unsigned int *fwd_link = nullptr;
    long longtmp;
    unsigned int cache_size;
    BYTE *tempfar = nullptr;
    if (g_disk_flag)
    {
        enddisk();
    }
    if (driver_diskp()) // otherwise, real screen also in use, don't hit it
    {
        char buf[128];
        helptitle();
        driver_set_attr(1, 0, C_DVID_BKGRD, 24*80);  // init rest to background
        for (int i = 0; i < BOXDEPTH; ++i)
        {
            driver_set_attr(BOXROW+i, BOXCOL, C_DVID_LO, BOXWIDTH);  // init box
        }
        driver_put_string(BOXROW+2, BOXCOL+4, C_DVID_HI, "'Disk-Video' mode");
        sprintf(buf, "Screen resolution: %d x %d", sxdots, sydots);
        driver_put_string(BOXROW+4, BOXCOL+4, C_DVID_LO, buf);
        if (disktarga)
        {
            driver_put_string(-1, -1, C_DVID_LO, "  24 bit Targa");
        }
        else
        {
            driver_put_string(-1, -1, C_DVID_LO, "  Colors: ");
            sprintf(buf, "%d", colors);
            driver_put_string(-1, -1, C_DVID_LO, buf);
        }
        sprintf(buf, "Save name: %s", savename);
        driver_put_string(BOXROW+8, BOXCOL+4, C_DVID_LO, buf);
        driver_put_string(BOXROW+10, BOXCOL+4, C_DVID_LO, "Status:");
        dvid_status(0, "clearing the 'screen'");
    }
    high_offset = -1;
    seek_offset = high_offset;
    cur_offset = seek_offset;
    cur_row    = -1;
    if (disktarga)
    {
        pixelshift = 0;
    }
    else
    {
        pixelshift = 3;
        int i = 2;
        while (i < colors)
        {
            i *= i;
            --pixelshift;
        }
    }
    timetodisplay = bf_math != bf_math_type::NONE ? 10 : 1000;  // time-to-g_driver-status counter

    /* allocate cache: try for the max; leave FREEMEMk free if we can get
        that much or more; if we can't get that much leave 1/2 of whatever
        there is free; demand a certain minimum or nogo at all */
    freemem = FREEMEM;

    for (cache_size = CACHEMAX; cache_size >= CACHEMIN; --cache_size)
    {
        longtmp = ((int)cache_size < freemem) ?
                  (long)cache_size << 11 : (long)(cache_size+freemem) << 10;
        tempfar = static_cast<BYTE *>(malloc(longtmp));
        if (tempfar != nullptr)
        {
            free(tempfar);
            break;
        }
    }
    if (debugflag == debug_flags::force_disk_min_cache)
    {
        cache_size = CACHEMIN;
    }
    longtmp = (long)cache_size << 10;
    cache_start = (cache *)malloc(longtmp);
    if (cache_size == 64)
    {
        --longtmp; // safety for next line
    }
    cache_lru = cache_start;
    cache_end = cache_lru + longtmp/sizeof(*cache_start);
    membuf = (BYTE *)malloc((long)BLOCKLEN);
    if (cache_start == nullptr || membuf == nullptr)
    {
        stopmsg(STOPMSG_NONE,
            "*** insufficient free memory for cache buffers ***");
        return -1;
    }
    if (driver_diskp())
    {
        char buf[50];
        sprintf(buf, "Cache size: %dK", cache_size);
        driver_put_string(BOXROW+6, BOXCOL+4, C_DVID_LO, buf);
    }

    // preset cache to all invalid entries so we don't need free list logic
    for (int i = 0; i < HASHSIZE; ++i)
    {
        hash_ptr[i] = 0xffff; // 0xffff marks the end of a hash chain
    }
    longtmp = 100000000L;
    for (cache *ptr1 = cache_start; ptr1 < cache_end; ++ptr1)
    {
        ptr1->dirty = false;
        ptr1->lru = false;
        longtmp += BLOCKLEN;
        fwd_link = &hash_ptr[(((unsigned short)longtmp >> BLOCKSHIFT) & (HASHSIZE-1))];
        ptr1->offset = longtmp;
        ptr1->hashlink = *fwd_link;
        *fwd_link = (int)((char *)ptr1 - (char *)cache_start);
    }

    memorysize = (long)(newcolsize) * newrowsize + headerlength;
    int i = (short)memorysize & (BLOCKLEN-1);
    if (i != 0)
    {
        memorysize += BLOCKLEN - i;
    }
    memorysize >>= pixelshift;
    memorysize >>= BLOCKSHIFT;
    g_disk_flag = true;
    rowsize = (unsigned int) newrowsize;
    colsize = (unsigned int) newcolsize;

    if (disktarga)
    {
        // Retrieve the header information first
        BYTE *tmpptr;
        tmpptr = membuf;
        fseek(fp, 0L, SEEK_SET);
        for (int i = 0; i < headerlength; i++)
        {
            *tmpptr++ = (BYTE)fgetc(fp);
        }
        fclose(fp);
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, DISK);
    }
    else
    {
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, MEMORY);
    }
    if (dv_handle == 0)
    {
        stopmsg(STOPMSG_NONE, "*** insufficient free memory/disk space ***");
        g_good_mode = false;
        rowsize = 0;
        return -1;
    }

    if (driver_diskp())
    {
        driver_put_string(BOXROW+2, BOXCOL+23, C_DVID_LO,
                          (MemoryType(dv_handle) == DISK) ? "Using your Disk Drive" : "Using your memory");
    }

    membufptr = membuf;

    if (disktarga)
    {
        // Put header information in the file
        MoveToMemory(membuf, (U16)headerlength, 1L, 0, dv_handle);
    }
    else
    {
        for (long offset = 0; offset < memorysize; offset++)
        {
            SetMemory(0, (U16)BLOCKLEN, 1L, offset, dv_handle);
            if (driver_key_pressed())           // user interrupt
            {
                // esc to cancel, else continue
                if (stopmsg(STOPMSG_CANCEL, "Disk Video initialization interrupted:\n"))
                {
                    enddisk();
                    g_good_mode = false;
                    return -2;            // -1 == failed, -2 == cancel
                }
            }
        }
    }

    if (driver_diskp())
    {
        dvid_status(0, "");
    }
    return 0;
}
Ejemplo n.º 25
0
void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg )
   {
   static FCODE err_no_temp[]  = "Unable to create temporary file.\n";
   static FCODE err_no_out[]   = "Unable to create output file.\n";
   static FCODE err_badwrite[] = "Error writing temporary file.\n";
   static FCODE err_badread[]  = "Error reading temporary file.\nSystem may be corrupt!\nSave your image and re-start FRACTINT!\n";

   PRINT_DOC_INFO info;
   int            success   = 0;
   int            temp_file = -1;
   char      far *msg = NULL;
   int            dummy; /* to quiet compiler */

   info.buffer = MK_FP(extraseg, 0);

/*   help_seek((long)sizeof(int)+sizeof(long));         Strange -- should be 8 -- CWM */
   help_seek(8L);                               /* indeed it should - Bert */
   dummy = read(help_file, (char *)&info.num_contents, sizeof(int));
   dummy = read(help_file, (char *)&info.num_page, sizeof(int));

   info.cnum = info.tnum = -1;
   info.content_pos = sizeof(long)+4*sizeof(int) + num_topic*sizeof(long) + num_label*2*sizeof(int);
   info.msg_func = msg_func;

   if ( msg_func != NULL )
      msg_func(0, info.num_page);   /* initialize */

   if ( save_extraseg )
      {
      if ( (temp_file=open(TEMP_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1 )
         {
         msg = err_no_temp;
         goto ErrorAbort;
         }

      if ( farwrite(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
         {
         msg = err_badwrite;
         goto ErrorAbort;
         }
      }

   if ( (info.file = fopen(outfname, "wt")) == NULL )
      {
      msg = err_no_out;
      goto ErrorAbort;
      }

   info.margin = PAGE_INDENT;
   info.start_of_line = 1;
   info.spaces = 0;

   success = process_document((PD_FUNC)print_doc_get_info,
                              (PD_FUNC)print_doc_output,   &info);
   fclose(info.file);

   if ( save_extraseg )
      {
      if ( lseek(temp_file, 0L, SEEK_SET) != 0L )
         {
         msg = err_badread;
         goto ErrorAbort;
         }

      if ( farread(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE )
         {
         msg = err_badread;
         goto ErrorAbort;
         }
      }

ErrorAbort:
   if (temp_file != -1)
      {
      close(temp_file);
      remove(TEMP_FILE_NAME);
      temp_file = -1;
      }

   if ( msg != NULL )
      {
      helptitle();
      stopmsg(1, msg);
      }

   else if ( msg_func != NULL )
      msg_func((success) ? -1 : -2, info.num_page );
   }
Ejemplo n.º 26
0
int init_help(void)
   {
   struct help_sig_info hs;
   char   path[FILE_MAX_PATH+1];
   int    dummy; /* to quiet compiler */

   help_file = -1;

#ifndef WINFRACT
#ifndef XFRACT
   if (help_file == -1)         /* now look for help files in FRACTINT.EXE */
      {
      static FCODE err_no_open[]    = "Help system was unable to open FRACTINT.EXE!\n";
      static FCODE err_no_exe[]     = "Help system couldn't find FRACTINT.EXE!\n";
      static FCODE err_wrong_ver[]  = "Wrong help version in FRACTINT.EXE!\n";
/*
      static FCODE err_not_in_exe[] = "Help not found in FRACTINT.EXE!\n";
*/

      if ( find_file(s_fractintexe, path) )
         {
#ifdef __TURBOC__
     if ( (help_file = open(path, O_RDONLY|O_BINARY|O_DENYWRITE)) != -1 )
#else
     if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
#endif
            {
            long help_offset;

            for (help_offset = -((long)sizeof(hs)); help_offset >= -128L; help_offset--)
               {
               lseek(help_file, help_offset, SEEK_END);
               dummy = read(help_file, (char *)&hs, sizeof(hs));
               if (hs.sig == HELP_SIG)  break;
               }

            if ( hs.sig != HELP_SIG )
               {
               close(help_file);
               help_file = -1;
               /* (leave out the error message)
               stopmsg(1, err_not_in_exe);
               */
               }

            else
               {
               if ( hs.version != HELP_VERSION )
                  {
                  close(help_file);
                  help_file = -1;
                  stopmsg(1, err_wrong_ver);
                  }
               else
                  base_off = hs.base;

               }
            }
         else
            stopmsg(1, err_no_open);
         }
      else
         stopmsg(1, err_no_exe);

      }
#endif
#endif

if (help_file == -1)            /* look for FRACTINT.HLP */
   {
   if ( find_file("fractint.hlp", path) )
      {
#ifdef __TURBOC__
      if ( (help_file = open(path, O_RDONLY|O_BINARY|O_DENYWRITE)) != -1 )
#else
      if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 )
#endif
     {
         dummy = read(help_file, (char *)&hs, sizeof(long)+sizeof(int));

         if ( hs.sig != HELP_SIG )
            {
            static FCODE msg[] = {"Invalid help signature in FRACTINT.HLP!\n"};
            close(help_file);
            stopmsg(1, msg);
            }

         else if ( hs.version != HELP_VERSION )
            {
            static FCODE msg[] = {"Wrong help version in FRACTINT.HLP!\n"};
            close(help_file);
            stopmsg(1, msg);
            }

         else
            base_off = sizeof(long)+sizeof(int);
         }
      }
   }

   if (help_file == -1)         /* Can't find the help files anywhere! */
      {
      static FCODE msg[] =
#ifndef XFRACT
         {"Help Files aren't in FRACTINT.EXE, and couldn't find FRACTINT.HLP!\n"};
#else
         {"Couldn't find fractint.hlp; set FRACTDIR to proper directory with setenv.\n"};
#endif
      stopmsg(1, msg);
      }

   help_seek(0L);

   dummy = read(help_file, (char *)&max_pages, sizeof(int));
   dummy = read(help_file, (char *)&max_links, sizeof(int));
   dummy = read(help_file, (char *)&num_topic, sizeof(int));
   dummy = read(help_file, (char *)&num_label, sizeof(int));
   help_seek((long)6*sizeof(int));  /* skip num_contents and num_doc_pages */

   assert(max_pages > 0);
   assert(max_links >= 0);
   assert(num_topic > 0);
   assert(num_label > 0);

   /* allocate one big chunk for all three arrays */

   topic_offset = (long far *)farmemalloc(sizeof(long)*num_topic + 2L*sizeof(int)*num_label + sizeof(HIST)*MAX_HIST);

   if (topic_offset == NULL)
      {
      static FCODE err_no_mem[] = "Not enough memory for help system!\n";
      close(help_file);
      help_file = -1;
      stopmsg(1, err_no_mem);

      return (-2);
      }

   /* split off the other arrays */

   label = (LABEL far *)(&topic_offset[num_topic]);
   hist  = (HIST far *)(&label[num_label]);

   /* read in the tables... */

   farread(help_file, topic_offset, num_topic*sizeof(long));
   farread(help_file, label, num_label*2*sizeof(int));

   /* finished! */

   return (0);  /* success */
   }

void end_help(void)
   {
   if (help_file != -1)
      {
      close(help_file);
      farmemfree((BYTE far *)topic_offset);
      help_file = -1;
      }
   }
Ejemplo n.º 27
0
int get_video_mode(struct fractal_info *info,struct ext_blk_3 *blk_3_info)
{
   static FCODE o_hdg2[]={"key...name......................err...xdot..ydot.clr.comment.................."};
   static FCODE o_warning[]={"\nWARNING: non-standard aspect ratio; loading will change your <v>iew settings"};
   static FCODE o_select_msg[]={"\
Select a video mode.  Use the cursor keypad to move the pointer.\n\
Press ENTER for selected mode, or use a video mode function key.\n\
Press F1 for help, "};
   char far *hdg2, far *warning, far *select_msg, far *ptr;
   struct vidinf vid[MAXVIDEOMODES];
   int i,j;
   int gotrealmode;
   double ftemp,ftemp2;
   unsigned tmpflags;

   int tmpxdots,tmpydots;
   float tmpreduce;
#ifndef XFRACT
   char *nameptr;
   int  *attributes;
   int oldhelpmode;
#endif
   VIDEOINFO *vident;

   /* save overlayed strings to extraseg memory */
   ptr = (char far *)MK_FP(extraseg,ENDVID);  /* ENDVID is to avoid videotable */
   hdg2 = ptr;
   ptr += sizeof(o_hdg2);
   warning = ptr;
   ptr += sizeof(o_warning);
   select_msg = ptr;
   far_strcpy(hdg2,o_hdg2);
   far_strcpy(warning,o_warning);
   far_strcpy(select_msg,o_select_msg);

   initmode = -1;
   load_fractint_cfg(0); /* get fractint.cfg into *vidtbl (== extraseg) */

   /* try to change any VESA entries to fit the loaded image size */
   if (virtual && video_vram && initmode == -1) {
      unsigned long vram = (unsigned long)video_vram << 16,
                    need = (unsigned long)info->xdots * info->ydots;
      if (need <= vram) {
         char over[25]; /* overwrite comments with original resolutions */
         int bppx;      /* bytesperpixel multiplier */
         for (i = 0; i < vidtbllen; ++i) {
            vident = &vidtbl[i];
            if (vident->dotmode%100 == 28 && vident->colors >= 256
               && (info->xdots > vident->xdots || info->ydots > vident->ydots)
               && vram >= (unsigned long)
                  (info->xdots < vident->xdots ? vident->xdots : info->xdots)
                  * (info->ydots < vident->ydots ? vident->ydots : info->ydots)
                  * ((bppx = vident->dotmode/1000) < 2 ? ++bppx : bppx)) {

               sprintf(over,"<-VIRTUAL! at %4u x %4u",vident->xdots,vident->ydots);
               far_strcpy((char far *)vident->comment,(char far *)over);

               if (info->xdots > vident->xdots)
                  vident->xdots = info->xdots;
               if (info->ydots > vident->ydots)
                  vident->ydots = info->ydots;
             }  /* change entry to force VESA virtual scanline setup */
         }
      }
   }

   /* try to find exact match for vid mode */
   for (i = 0; i < vidtbllen; ++i) {
      vident = &vidtbl[i];
      if (info->xdots == vident->xdots && info->ydots == vident->ydots
        && filecolors == vident->colors
        && info->videomodeax == vident->videomodeax
        && info->videomodebx == vident->videomodebx
        && info->videomodecx == vident->videomodecx
        && info->videomodedx == vident->videomodedx
        && info->dotmode%100 == vident->dotmode%100) {
         initmode = i;
         break;
         }
      }

   /* exit in makepar mode if no exact match of video mode in file */
   if(*s_makepar == '\0' && initmode == -1)
      return(0);

   if (initmode == -1) /* try to find very good match for vid mode */
      for (i = 0; i < vidtbllen; ++i) {
         vident = &vidtbl[i];
         if (info->xdots == vident->xdots && info->ydots == vident->ydots
           && filecolors == vident->colors) {
            initmode = i;
            break;
            }
         }

   /* setup table entry for each vid mode, flagged for how well it matches */
   for (i = 0; i < vidtbllen; ++i) {
      far_memcpy((char far *)&videoentry,(char far *)&vidtbl[i],
                 sizeof(videoentry));
      tmpflags = VI_EXACT;
      if (videoentry.keynum == 0)
         tmpflags |= VI_NOKEY;
      if (info->xdots > videoentry.xdots || info->ydots > videoentry.ydots)
         tmpflags |= VI_SSMALL;
      else if (info->xdots < videoentry.xdots || info->ydots < videoentry.ydots)
         tmpflags |= VI_SBIG;
      if (filexdots > videoentry.xdots || fileydots > videoentry.ydots)
         tmpflags |= VI_VSMALL;
      else if (filexdots < videoentry.xdots || fileydots < videoentry.ydots)
         tmpflags |= VI_VBIG;
      if (filecolors > videoentry.colors)
         tmpflags |= VI_CSMALL;
      if (filecolors < videoentry.colors)
         tmpflags |= VI_CBIG;
      if (i == initmode)
         tmpflags -= VI_EXACT;
      if (videoentry.dotmode%100 == 11) {
         tmpflags |= VI_DISK2;
         if ((tmpflags & (VI_SBIG+VI_SSMALL+VI_VBIG+VI_VSMALL)) != 0)
            tmpflags |= VI_DISK1;
         }
      if (fileaspectratio != 0 && videoentry.dotmode%100 != 11
        && (tmpflags & VI_VSMALL) == 0) {
         ftemp = vid_aspect(filexdots,fileydots);
         if ( ftemp < fileaspectratio * 0.98
           || ftemp > fileaspectratio * 1.02)
            tmpflags |= VI_ASPECT;
         }
      vid[i].entnum = i;
      vid[i].flags  = tmpflags;
      }

if (fastrestore  && !askvideo)
   initmode = adapter;

#ifndef XFRACT
   gotrealmode = 0;
   if ((initmode < 0 || (askvideo && !initbatch)) && *s_makepar != '\0') {
      /* no exact match or (askvideo=yes and batch=no), and not
        in makepar mode, talk to user */

      qsort(vid,vidtbllen,sizeof(vid[0]),vidcompare); /* sort modes */

      attributes = (int *)&dstack[1000];
      for (i = 0; i < vidtbllen; ++i)
         attributes[i] = 1;
      vidptr = &vid[0]; /* for format_item */

      /* format heading */
      if (info->info_id[0] == 'G')
         strcpy(temp1,"      Non-fractal GIF");
      else {
         nameptr = curfractalspecific->name;
         if (*nameptr == '*') ++nameptr;
          if (display3d) nameptr = "3D Transform";
         if ((!strcmp(nameptr,"formula")) ||
             (!strcmp(nameptr,"lsystem")) ||
             (!strncmp(nameptr,"ifs",3))) /* for ifs and ifs3d */
               sprintf(temp1,"Type: %s -> %s",nameptr,blk_3_info->form_name);
         else
           sprintf(temp1,"Type: %s",nameptr);
         }
      sprintf((char *)dstack,"File: %-44s  %d x %d x %d\n%-52s",
             readname,filexdots,fileydots,filecolors,temp1);
      if (info->info_id[0] != 'G') {
         if (save_system)
            strcat((char *)dstack,"WinFract ");
         sprintf(temp1,"v%d.%01d",save_release/100,(save_release%100)/10);
         if (save_release%100) {
            i = strlen(temp1);
            temp1[i] = (char)((save_release%10) + '0');
            temp1[i+1] = 0;
            }
         if (save_system == 0 && save_release <= 1410)
            strcat(temp1," or earlier");
         strcat((char *)dstack,temp1);
         }
      strcat((char *)dstack,"\n");
      if (info->info_id[0] != 'G' && save_system == 0)
         if (initmode < 0)
            strcat((char *)dstack,"Saved in unknown video mode.");
         else {
            format_vid_inf(initmode,"",temp1);
            strcat((char *)dstack,temp1);
            }
      if (fileaspectratio != 0 && fileaspectratio != screenaspect)
         far_strcat((char *)dstack,warning);
      strcat((char *)dstack,"\n");
      /* set up instructions */
      far_strcpy(temp1,select_msg);
      if (info->info_id[0] != 'G')
         strcat(temp1,"TAB for fractal information, ");
      strcat(temp1,"ESCAPE to back out.");

      oldhelpmode = helpmode;
      helpmode = HELPLOADFILE;
      i = fullscreen_choice(0,(char *)dstack,hdg2,temp1,vidtbllen,NULL,attributes,
                             1,13,78,0,format_item,NULL,NULL,check_modekey);
      helpmode = oldhelpmode;
      if (i == -1)
         return(-1);
      if (i < 0) { /* returned -100 - videotable entry number */
         initmode = -100 - i;
         gotrealmode = 1;
         }
      else
         initmode = vid[i].entnum;
      }
#else
      initmode = 0;
      j = vidtbl[0].keynum;
      gotrealmode = 0;
#endif

   if (gotrealmode == 0) { /* translate from temp table to permanent */
      if ((j = vidtbl[i=initmode].keynum) != 0) {
         for (initmode = 0; initmode < MAXVIDEOTABLE-1; ++initmode)
            if (videotable[initmode].keynum == j) break;
         if (initmode >= MAXVIDEOTABLE-1) j = 0;
         }
      if (j == 0) /* mode has no key, add to reserved slot at end */
         far_memcpy((char far *)&videotable[initmode=MAXVIDEOTABLE-1],
                    (char far *)&vidtbl[i],sizeof(*vidtbl));
      }

   /* ok, we're going to return with a video mode */

   far_memcpy((char far *)&videoentry,(char far *)&videotable[initmode],
              sizeof(videoentry));


   if (viewwindow &&
      filexdots == videoentry.xdots && fileydots == videoentry.ydots) {
      /* pull image into a view window */
      if (calc_status != 4) /* if not complete */
          calc_status = 0;  /* can't resume anyway */
      if (viewxdots) {
         viewreduction = videoentry.xdots / viewxdots;
         viewxdots = viewydots = 0; /* easier to use auto reduction */
      }
      viewreduction = (float)((int)(viewreduction + 0.5)); /* need integer value */
      skipxdots = skipydots = (short)(viewreduction - 1);
      return(0);
   }

   skipxdots = skipydots = 0; /* set for no reduction */
   if (videoentry.xdots < filexdots || videoentry.ydots < fileydots) {
      /* set up to load only every nth pixel to make image fit */
      if (calc_status != 4) /* if not complete */
          calc_status = 0;  /* can't resume anyway */
      skipxdots = skipydots = 1;
      while (skipxdots * videoentry.xdots < filexdots) ++skipxdots;
      while (skipydots * videoentry.ydots < fileydots) ++skipydots;
      i = j = 0;
      for(;;) {
         tmpxdots = (filexdots + skipxdots - 1) / skipxdots;
         tmpydots = (fileydots + skipydots - 1) / skipydots;
         if (fileaspectratio == 0 || videoentry.dotmode%100 == 11)
            break;
         /* reduce further if that improves aspect */
         if ((ftemp = vid_aspect(tmpxdots,tmpydots)) > fileaspectratio) {
            if (j) break; /* already reduced x, don't reduce y */
            ftemp2 = vid_aspect(tmpxdots,(fileydots+skipydots)/(skipydots+1));
            if (ftemp2 < fileaspectratio
              && ftemp/fileaspectratio *0.9 <= fileaspectratio/ftemp2)
               break; /* further y reduction is worse */
            ++skipydots;
            ++i;
            }
         else {
            if (i) break; /* already reduced y, don't reduce x */
            ftemp2 = vid_aspect((filexdots+skipxdots)/(skipxdots+1),tmpydots);
            if (ftemp2 > fileaspectratio
              && fileaspectratio/ftemp *0.9 <= ftemp2/fileaspectratio)
               break; /* further x reduction is worse */
            ++skipxdots;
            ++j;
            }
         }
      filexdots = tmpxdots;
      fileydots = tmpydots;
      --skipxdots;
      --skipydots;
      }

   if ((finalaspectratio = fileaspectratio) == 0) /* assume display correct */
      finalaspectratio = (float)vid_aspect(filexdots,fileydots);
   if (finalaspectratio >= screenaspect-0.02
     && finalaspectratio <= screenaspect+0.02)
      finalaspectratio = screenaspect;
   i = (int)(finalaspectratio * 1000.0 + 0.5);
   finalaspectratio = (float)(i/1000.0); /* chop precision to 3 decimals */

   /* setup view window stuff */
   viewwindow = viewxdots = viewydots = 0;
   if (filexdots != videoentry.xdots || fileydots != videoentry.ydots) {
      /* image not exactly same size as screen */
      viewwindow = 1;
      ftemp = finalaspectratio
            * (double)videoentry.ydots / (double)videoentry.xdots
            / screenaspect;
      if (finalaspectratio <= screenaspect) {
         i = (int)((double)videoentry.xdots / (double)filexdots * 20.0 + 0.5);
         tmpreduce = (float)(i/20.0); /* chop precision to nearest .05 */
         i = (int)((double)videoentry.xdots / tmpreduce + 0.5);
         j = (int)((double)i * ftemp + 0.5);
         }
      else {
         i = (int)((double)videoentry.ydots / (double)fileydots * 20.0 + 0.5);
         tmpreduce = (float)(i/20.0); /* chop precision to nearest .05 */
         j = (int)((double)videoentry.ydots / tmpreduce + 0.5);
         i = (int)((double)j / ftemp + 0.5);
         }
      if (i != filexdots || j != fileydots) { /* too bad, must be explicit */
         viewxdots = filexdots;
         viewydots = fileydots;
         }
      else
         viewreduction = tmpreduce; /* ok, this works */
      }
   if (*s_makepar && !fastrestore && !initbatch &&
        (fabs(finalaspectratio - screenaspect) > .00001 || viewxdots != 0)) {
      static FCODE msg[] = {"\
Warning: <V>iew parameters are being set to non-standard values.\n\
Remember to reset them when finished with this image!"};
      stopmsg(4,msg);
      }
   return(0);
}