#include #include #define WIDTH 320 #define FWIDTH 320. #define HEIGHT 200 #define FHEIGHT 200. #define SCRSIZ 32000L #define HIDE_MOUSE graf_mouse(256,&dummy) #define SHOW_MOUSE graf_mouse(257,&dummy) #define FNcolor(c) ((c) == maxcnt ? 1 : (((c)>>colfactor)%14)+2) int contrl[12], intin[256], ptsin[256], intout[256], ptsout[256]; double xinc,yinc,x,y,zx,zy,XMIN,XRANGE,YMIN,YRANGE,rx,ry; int dummy,count,handle,ix,iy; int maxcnt; int pxy[4]; int colfactor; int iystep,ixstep; char *picfile[10] = { "pic1.pic", "pic2.pic", "pic3.pic", "pic4.pic", "pic5.pic", "pic6.pic", "pic7.pic", "pic8.pic", "pic9.pic", "pic0.pic" }; #define F1 0x3b00 #define F2 0x3c00 #define UNDO 0x6100 #define HELP 0x6200 #define ESC 0x0127 #define TRUE 1 #define FALSE 0 struct _iorec { long ibuf; int ibufsiz, ibufhd,ibuftl,ibuflow,ibufhi; } *iorec; #define Interrupt() (iorec->ibufhd != iorec->ibuftl) int event; int coltab[16] = { 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 }; int plotflag; int gsoft; main() { int i; int mx,my,width,height,keystate; int key; extern int _fpexists; iorec = Iorec(1); /* initialize so Interrupt() macro works */ /* Set the system up to do GEM calls*/ appl_init(); /* Get the handle of the desktop */ handle=graf_handle(&dummy,&dummy,&dummy,&dummy); /* Open the workstation. */ for (i=0; i<10; ++i) intin[i] = 1; intin[10] = 2; v_opnvwk(intin, &handle, intout); if (intout[0] != (WIDTH-1) || intout[1] != (HEIGHT-1)) { form_alert(1,"[3][Must run in low resolution.][CANCEL]"); goto quit; } pxy[0]=0; pxy[1]=0; pxy[2]=intout[0]; pxy[3]=intout[1]; vs_clip(handle,1,pxy); vsf_perimeter(handle,0); graf_mouse(0,&dummy); /* goto bigloop to reset zoom to max */ bigloop: plotflag = TRUE; gsoft = TRUE; maxcnt = 32; colfactor=0; XMIN = (-2.); XRANGE = 3.; YMIN = (-1.3); YRANGE = 2.6; domnd(); while (1) { event = evnt_multi(MU_KEYBD|MU_BUTTON, 1,1,1, /* evnt_button */ 0,0,0,0,0, /*evnt_mouse1*/ 0,0,0,0,0, /*evnt_mouse2*/ &dummy, /*evnt_mesg*/ 0,0, /*evnt_timer*/ &mx,&my, /* mouse x,y */ &dummy, /* mouse button */ &keystate, /* shift keys */ &key, /* keypress */ &dummy); /* number of clicks */ if (event & MU_BUTTON) { graf_rubbox(mx,my,1,1,&width,&height); if (width<2 || height<2) continue; XMIN = XMIN+mx*(XRANGE/FWIDTH); YMIN = YMIN+my*(YRANGE/FHEIGHT); XRANGE = XRANGE*(width/FWIDTH); YRANGE = YRANGE*(height/FHEIGHT); /* fall down to drawmand with this new box */ } else if (event & MU_KEYBD) { gotkey: if ((key&0xff00) >= 0x0200 && (key&0xff00) <= 0x0B00) { /* number key: shift means SAVE, unshift means LOAD */ int fd; key = (key >> 8) - 2; /* key=0..9 */ HIDE_MOUSE; if (keystate & 3) { /* shift key down: write */ if ((fd = Fcreate(picfile[key],0)) < 0) { Cconws("Error creating "); Cconws(picfile[key]); SHOW_MOUSE; continue; } if ((Fwrite(fd,(long)SCRSIZ,Logbase()) != (long)SCRSIZ) || (Fwrite(fd,(long)(sizeof (double)),&XMIN) != (sizeof (double))) || (Fwrite(fd,(long)(sizeof (double)),&YMIN) != (sizeof (double))) || (Fwrite(fd,(long)(sizeof (double)),&XRANGE) != (sizeof (double))) || (Fwrite(fd,(long)(sizeof (double)),&YRANGE) != (sizeof (double))) || (Fwrite(fd,2L,&maxcnt) != 2) || (Fwrite(fd,2L,&colfactor) != 2) || (Fclose(fd))) { Fclose(fd); Cconws("Error writing "); Cconws(picfile[key]); Cconws("\r\n"); SHOW_MOUSE; continue; } } else { /* no shift: read */ if ((fd = Fopen(picfile[key],0)) < 0) { Cconws("Error opening "); Cconws(picfile[key]); Cconws("\r\n"); SHOW_MOUSE; continue; } if (Fread(fd,(long)SCRSIZ,Logbase()) != (long)SCRSIZ || Fread(fd,(long)(sizeof (double)),&XMIN) != (sizeof (double)) || Fread(fd,(long)(sizeof (double)),&YMIN) != (sizeof (double)) || Fread(fd,(long)(sizeof (double)),&XRANGE) != (sizeof (double)) || Fread(fd,(long)(sizeof (double)),&YRANGE) != (sizeof (double)) || Fread(fd,2L,&maxcnt) != 2 || Fread(fd,2L,&colfactor) != 2 || Fclose(fd)) { Fclose(fd); Cconws("Error reading "); Cconws(picfile[key]); Cconws("\r\n"); SHOW_MOUSE; continue; } } SHOW_MOUSE; continue; } else if (key == F1) goto bigloop; else if (key == UNDO || key == ESC) goto quit; else if (key == HELP) { help(); continue; } else switch(key & 0xff) { /* God knows *why* you would use a colfactor of 16384... */ case '+': if (++colfactor > 16384) colfactor = 16384; continue; case '-': if (--colfactor < 0) colfactor = 0; continue; case '>': if ((maxcnt <<= 1) <= 0) maxcnt = 0x4000; continue; case '<': if ((maxcnt >>= 1) == 0) maxcnt = 1; continue; case ' ': break; /* fall down to domnd() */ case 'p': plotflag = FALSE; continue; case 'P': plotflag = TRUE; continue; case 's': gsoft = TRUE; continue; case 'h': gsoft = FALSE; continue; default: continue; /* other keys do nothing */ } } /* end if keyboard */ if (key = domnd()) goto gotkey; } /* end while (1) */ quit: /* Close the workstation. */ v_clsvwk(handle); /* Release GEM calls */ appl_exit(); exit(0); } domnd() { long time, frac, sec, min, gettime(), save; HIDE_MOUSE; time = gettime(); save = drawmand(); time = gettime() - time; frac = (time % 200) * 5; sec = time / 200; min = sec/60; sec %= 60; printf("\033HTime: %ld:%02ld.%03ld\n",min,sec,frac); SHOW_MOUSE; return save; } putlong(num,size) register long num; register int size; { char buf[10]; register char *ptr = &buf[9]; *ptr = '\0'; do { *(--ptr) = (num%10) + '0'; num /= 10; if (size) --size; } while (num || size); Cconws(ptr); } drawmand() { register int count; register int flag; /* true for first iteration (new screen) */ register int rowcount,colcount; register int ixsize; register int soft = gsoft; long key; int c; static int real_fpexists = 0; extern int fpexists; v_clrwk(handle); iystep=32; flag = 1; for (ixstep = 32,ixsize=5; ixsize >= 0 ; --ixsize,ixstep >>= 1) { pixinit(ixsize); y=YMIN; yinc=(YRANGE/HEIGHT)*iystep; xinc=(XRANGE/WIDTH)*ixstep; for (iy=0,rowcount=0; iy> 8)); } } /* end of keyboard interrupt check */ } else pixskip(); x += xinc; } y=y+yinc; } flag = 0; /* end of first iteration */ iystep/=2; } return 0; } long gettime() { long oldssp = Super(0L); long ret = *(long *)0x4ba; Super(oldssp); return ret; } char *hstr[] = { "****************************************", "\033E MANDELBROT DEMO HELP SCREEN", "", "Hit UNDO to leave.", "", "Hit HELP to see this screen.", "", "Hit RETURN then use the mouse to select", "a rectange to zoom in on.", "", "Hit F1 to reset to the top level.", "", "Hit Space to start plotting again.", "", "Hold SHIFT and hit a number key to save", "a picture, and the number key alone to", "load it back.", "", "When plotting, hit 'h' to use the 68881", "hardware directly, 's' to use the soft-", "ware library. When in 's' mode, if the", "68881 exists, hit 'f' to toggle it on", "and off.", "", "Now, hit space to restart plotting: ", 0L }; help() { char *s = hstr[0]; while (s) Cconws(s++); }