  /* Mandelbrot Set Generator    *//* Adapted from hercules-      *//* monochrome version written  *//* for the IBM PC. This version*//* is for the 8bit Atari, mode8*//* written with Lightspeed C   *//* --- Review for ANTIC     ---*//* By M. Ratcliff  23-APR-88   */     #include "stdio.h"     /* Module globals              */     int max_iter; /* 1000 is best  */              /* use 30-100 if */              /* you want it   */              /* THIS YEAR!    */  char mode, mask, alarm;  char pmin[6];  char pmax[6];  char qmin[6];  char qmax[6];  char tempf[6];  char max_sz[6];#define MAX_SIZE 4int     XMAX;int     YMAX;#define ESC  27#define SAVMSC 88#define MODE2C 24 /* 2color mode */#define MODE4C 31 /* 4color mode */#define BLUE 134#define RED 34#define YELLOW 26#define BLACK 0#define LOGRAY 4/******************************//* mandel - Generate the      *//* Mandelbrot point set       *//******************************/     mandel()     $(     int i, colr, row, col,slo,cs,cl,key;  /* More FLOATs as char strings */  char p[6], q[6], modulus[6];  char kolr;  char flstr[20], max_sz[6];  char deltap[6], deltaq[6];  char xcur[6], ycur[6], ylast[6],xlast[6];  char fzero[6],ftwo[6];       /* Determine real axis      */  /* increment                 */  itof(MAX_SIZE, max_sz);  atof(ftwo,"2.0000");  atof(fzero,"0.000");  fast(); /* Screen off */  slo = 0; /* Not slow but fast */ key = 0;  /* deltap=(pmax-pmin)/(maxcol-1); */  fsub(pmax, pmin, deltap);  i = XMAX - 1;  itof(i, tempf);  fdiv(deltap, tempf, deltap);  /* Next determine imaginary  */  /* axis increment.           */  /* deltaq=(qmax-qmin)/(maxrow-1); */  fsub(qmax, qmin, deltaq);  i = YMAX-1;  itof(i, tempf);  fdiv(deltaq, tempf, deltaq );  /* Look at each point on scr*/            for (cs=0;cs<40;cs++)  $(    for (cl=0;cl<8;cl++)    $(      col=cl*40+cs;      for (row=0;row<=YMAX;row++)      $(        /* p=pmin+col*deltap */        itof(col, tempf);        fmul(tempf, deltap, p);        fadd(p, pmin, p);        /* q=qmin+row*deltaq */        itof(row, tempf);        fmul(tempf, deltaq, q);        fadd(q, qmin, q);        /* xlast=ylast=modulus=0.0 */        move(fzero,xlast,6);        move(fzero,ylast,6);        move(fzero,modulus,6);        colr = 0;        while( colr < max_iter )        $(          /* Go around until max */          /* iterations or func  */          /* blows up            */          fmul(xlast, xlast, xcur);          fadd(xcur, p, xcur );          fmul(ylast, ylast, tempf);          fsub(xcur, tempf, xcur);          /* If Lightspeed supported */          /* standard floating point */          /* the above would be:     */          /* xcur=xlast*xlast+ylast*ylast+p */          fmul(xlast,ftwo,ycur);          fmul(ycur,ylast,ycur);          fadd(ycur,q,ycur);          colr = colr + 1;          /* xlast=xcur        */          move(xcur,xlast, 6);          /* ylast=ycur        */          move(ycur,ylast, 6);          /* modulus = xcur*xcur + ycur*ycur */          fmul(xcur, xcur, modulus);          fmul(ycur, ycur, tempf );          fadd(modulus, tempf, modulus);          /* if (modulus>=max_sz) break; */          fsub(modulus,max_sz,tempf);          sprintf(flstr,"%f\n",tempf);          /* if modulus is < max_sz, then */          /* we'll find a minus in the string */          if (flstr[0] != 45) break;        $) /* while end */        if (inkey())        $(          key=getkey();          if (key==1)          break;          else key = 0;        $)             kolr = colr & mask;                  color(kolr);        plot(col, row);             if ((!strig(0)) && (!slo))        $(          slo = 1;          slow();          poke (77,0);        $)        else if ((strig(0)) && (slo))        $(          fast();          slo = 0;        $)  $) /* end for row */       if (key==1) break;  $) /* cs end for */if (key == 1) break;$) /* cl end for */return(key);$) /* mandel end function */     doalarm()$(     int i,j;  char stk;       while ( (stk = strig(0)) == 1)  $(    for(i=15; i>-1; i--)    $(      sound(0,60,10,i);      stk = strig(0);      if (stk == 0) break;      for (j=0; j<50; j++);    $)    for (j=0; j<150; j++)    $(      stk = strig(0);      if (stk == 0) break;    $)  $)sound( stk, stk, stk, stk );$)        /* MAIN Module */main()          $(     int x, i,cstat, j;  int status, iocb;  char file[64], *screen;  char float[40],outbuf[120];       graphics( 0 );  poke(710,0);  printf("Lightspeed C MANDELBROT set\n");  printf("fractal generator, by Mat*Rat\n\n");  printf("Graphics mode ?\n");  printf("[1] 300x192, 2 color\n");  printf("[2] 160x192, 4 color\n");  printf("<2 is for XL/XEs only>\n");  gets(float);  if (float[0] =='2')  $(    mode = 31; /* 4 color mode */    mask = 3;    XMAX = 159;    YMAX = 191;    $)  else    $(    mode = 24; /* 2 color mode */    mask = 1;    XMAX = 320;    YMAX = 191;$)   /* Wake up call ALARM when done? */  printf("ALARM prompt when plot done?\n");  printf("(y/n) ?  ");  gets(float);  if ( (float[0]=='n') || (float[0]=='N') )    alarm = 0;  else    alarm = 1;       printf("pmax (i.e. 0.55)? ");  gets(float);  printf("\n");  atof(pmax, float);  printf("pmin (i.e. -1.500) ?");  gets(float);  printf("\n");  atof(pmin, float);  printf("qmax? (i.e. 1.025) ?");  gets(float);  printf("\n");  atof(qmax, float);  fsub(pmax, pmin, tempf);  fsub(qmax, tempf, qmin);  /* qmin = qmax - (pmax-pmin); */  printf("Max iterations (i.e. 40)? ");  gets(tempf);  printf("\n");  max_iter = atoi(tempf);       printf("Save file for finished fractal?\n");  gets(file);  if (mode == MODE2C)    normalize(file,"PI2");  else    normalize(file,"PI4");  printf("\n\nPMAX: %f  PMIN: %f\n",pmax, pmin);  printf("QMAX: %f  QMIN: %f\n",qmax, qmin);  printf("Max iterations: %d\n",max_iter);  printf("Save Filename : %s\n",file);  printf("%d colors, GR. %d\n",mask+1,mode);  if (alarm == 0) printf("ALARM ΟΖΖ\n");  else printf("ALARM ΣΕΤ\n");  printf("Press [RETURN] to continue\n");  printf("Or [ESCAPE] to cancel/exit ξοχ?\n");  printf("<Press FIRE button to see screen>\n");  printf("(press ^A to abort plot process)\n\n");  i = getkey();  if (i == ESC)  $(    graphics(0);    return(0);  $)  graphics(mode);  screen=peek(SAVMSC)+256*peek(SAVMSC+1);  for (i=screen;i<screen+7680;i++) *i=255;  if (mode == MODE4C)  $(    poke(708,YELLOW);    poke(709,BLUE);    poke(710,RED);  $)  else    $(    poke(710,BLACK);    poke(712,LOGRAY);    $)  cstat = mandel();  slow();       if (alarm != 0) doalarm();  iocb = -1;  iocb = fopen(file,"w");  if (iocb < 0)  $(  graphics(0);  printf("IOCB Error %d\n", iocb);  $)  if (iocb > 0)  $(    screen = peek(SAVMSC)+256*peek(SAVMSC+1);         status = fwrite(screen,1,7680,iocb);  if (status >= 0)  $(    sprintf(outbuf,"Pmax:%f Pmin:%f\nQmax:%f Qmin:%f\nIterations:%d\n",    pmax, pmin, qmax, qmin, max_iter);    status = cputs(outbuf, iocb);  $)  fclose(iocb);  graphics(0);  poke(710,0);  if (cstat)  $(    printf("Fractal INCOMPLETE\n");    poke(764,255);  $)  else    printf("Fractal complete\n");  printf("%s\n\n", outbuf);  printf("Press [RETURN] ?");  i = getkey();  graphics(0);