📄 jiim.c
字号:
if (FromMemDisk(8*ListFront, sizeof(pop.x), &pop.x) &&
FromMemDisk(8*ListFront +sizeof(pop.x), sizeof(pop.y), &pop.y))
--lsize;
return pop;
}
pop.x = 0;
pop.y = 0;
return pop;
}
int
EnQueueFloat(float x, float y)
{
return PushFloat(x, y);
}
int
EnQueueLong(long x, long y)
{
return PushLong(x, y);
}
_CMPLX
DeQueueFloat()
{
_CMPLX out;
float outx, outy;
if (ListBack != ListFront)
{
if (FromMemDisk(8*ListBack, sizeof(outx), &outx) &&
FromMemDisk(8*ListBack +sizeof(outx), sizeof(outy), &outy))
{
ListBack = (ListBack + 1) % ListSize;
out.x = outx;
out.y = outy;
lsize--;
}
return out;
}
out.x = 0;
out.y = 0;
return out;
}
LCMPLX
DeQueueLong()
{
LCMPLX out;
out.x = 0;
out.y = 0;
if (ListBack != ListFront)
{
if (FromMemDisk(8*ListBack, sizeof(out.x), &out.x) &&
FromMemDisk(8*ListBack +sizeof(out.x), sizeof(out.y), &out.y))
{
ListBack = (ListBack + 1) % ListSize;
lsize--;
}
return out;
}
out.x = 0;
out.y = 0;
return out;
}
/*
* End MIIM section;
*/
static BOOLEAN MemoryAlloc(long size)
{
char far *temp;
if (debugflag == 420)
return(FALSE);
temp = (char far *)farmemalloc(FAR_RESERVE); /* minimum free space */
if (temp == NULL)
{
stored_at = NOWHERE;
return (FALSE); /* can't do it */
}
memory = (char far *)farmemalloc( size );
farmemfree(temp);
if ( memory == NULL )
{
stored_at = NOWHERE;
return (FALSE);
}
else
{
stored_at = MEMORY;
return (TRUE);
}
}
static void SaveRect(int x, int y, int width, int depth)
{
char buff[MAXRECT];
int yoff;
if(hasinverse == 0)
return;
/* first, do any de-allocationg */
switch( stored_at )
{
case NOWHERE:
break;
case DISK:
break;
case MEMORY:
if (memory != NULL)
{
farmemfree(memory);
}
memory = NULL;
break;
}
/* allocate space and store the rect */
memset(dstack, color_dark, width);
if ( MemoryAlloc( (long)width*(long)depth) )
{
char far *ptr = memory;
char far *bufptr = buff; /* MSC needs this indirection to get it right */
Cursor_Hide();
for (yoff=0; yoff<depth; yoff++)
{
getrow(x, y+yoff, width, buff);
putrow(x, y+yoff, width, dstack);
movedata(FP_SEG(bufptr), FP_OFF(bufptr), FP_SEG(ptr), FP_OFF(ptr), width);
ptr = (char far *)normalize(ptr+width);
}
Cursor_Show();
}
else /* to disk */
{
stored_at = DISK;
if ( file == NULL )
{
file = fopen(scrnfile, "w+b");
if (file == NULL)
{
stored_at = NOWHERE;
buzzer(3);
return ;
}
}
rewind(file);
Cursor_Hide();
for (yoff=0; yoff<depth; yoff++)
{
getrow(x, y+yoff, width, buff);
putrow(x, y+yoff, width, dstack);
if ( fwrite(buff, width, 1, file) != 1 )
{
buzzer(3);
break;
}
}
Cursor_Show();
}
}
static void RestoreRect(x, y, width, depth)
{
char buff[MAXRECT];
int yoff;
if(hasinverse == 0)
return;
switch ( stored_at )
{
case DISK:
rewind(file);
Cursor_Hide();
for (yoff=0; yoff<depth; yoff++)
{
if ( fread(buff, width, 1, file) != 1 )
{
buzzer(3);
break;
}
putrow(x, y+yoff, width, buff);
}
Cursor_Show();
break;
case MEMORY:
{
char far *ptr = memory;
char far *bufptr = buff; /* MSC needs this indirection to get it right */
Cursor_Hide();
for (yoff=0; yoff<depth; yoff++)
{
movedata(FP_SEG(ptr), FP_OFF(ptr), FP_SEG(bufptr), FP_OFF(bufptr), width);
putrow(x, y+yoff, width, buff);
ptr = (char far *)normalize(ptr+width);
}
Cursor_Show();
break;
}
case NOWHERE:
break;
} /* switch */
}
/*
* interface to FRACTINT
*/
int jfractype;
extern int row, col;
extern double far *dx0, far *dy0;
extern double far *dx1, far *dy1;
extern int integerfractal;
extern long far *lx0, far *ly0;
extern long far *lx1, far *ly1;
extern int bitshift;
extern int helpmode;
/* the following macros and function call the setup, per_pixel, and orbit
routines and calculate an orbit at row 0 column 0. Have to save and
restore the first elements of dx0 ... dy1 as well as row and col */
#define PER_IMAGE fractalspecific[o_fractype].per_image
#define PER_PIXEL fractalspecific[o_fractype].per_pixel
#define ORBITCALC fractalspecific[o_fractype].orbitcalc
int do_fractal_routines(double cr, double ci, int (*func)())
{
int ret;
int old_row, old_col;
double old_dx0, old_dx1, old_dy0, old_dy1;
old_dx0 = *dx0; old_dx1 = *dx1;
old_dy0 = *dy0; old_dy1 = *dy1;
old_row = row; old_col = col;
row = col = 0;
*dx0 = cr; *dy0 = ci; *dx1 = *dy1 = 0.0;
ret = func();
*dx0 = old_dx0; *dx1 = old_dx1;
*dy0 = old_dy0; *dy1 = old_dy1;
row = old_row; col = old_col;
return(ret);
}
void Jiim(int which) /* called by fractint */
{
struct affine cvt;
int exact = 0;
int oldhelpmode;
int count = 0; /* coloring julia */
static int mode = 0; /* point, circle, ... */
int oldlookatmouse = lookatmouse;
double cr, ci, r;
int xfactor, yfactor; /* aspect ratio */
int xoff, yoff; /* center of the window */
int x, y;
int still, kbdchar;
int xcrsr,ycrsr; /* coords of the cursor / offsets to move it */
int iter;
int color;
float zoom;
int oldsxoffs, oldsyoffs;
int savehasinverse;
int (*oldcalctype)();
extern int (*calctype)();
int o_fractype;
int old_x, old_y;
double aspect;
static int randir = 0;
static int rancnt = 0;
static _CMPLX SaveC = {-3000.0, -3000.0};
int actively_computing = 1;
int first_time = 1;
ENTER_OVLY(OVLY_ROTATE);
/* must use standard fractal and have a float variant */
if(fractalspecific[fractype].calctype != StandardFractal ||
(fractalspecific[fractype].isinteger &&
fractalspecific[fractype].tofloat == NOFRACTAL))
{
EXIT_OVLY;
return;
}
oldhelpmode = helpmode;
if(which == JIIM)
helpmode = HELP_JIIM;
else
{
helpmode = HELP_ORBITS;
hasinverse = 1;
}
if(fractalspecific[fractype].isinteger)
o_fractype = fractalspecific[fractype].tofloat;
else
o_fractype = fractype;
oldsxoffs = sxoffs;
oldsyoffs = syoffs;
oldcalctype = calctype;
show_numbers = 0;
using_jiim = 1;
mem_init(strlocn, 10*1024);
line_buff = newx(max(sxdots,sydots));
aspect = ((double)xdots*3)/((double)ydots*4); /* assumes 4:3 */
actively_computing = 1;
SetAspect(aspect);
lookatmouse = 3;
Cursor_Construct();
/*
* MIIM code:
* Grab far memory for Queue/Stack before SaveRect gets it.
*/
OKtoMIIM = 0;
if (which == JIIM && debugflag != 300)
OKtoMIIM = Init_Queue((long)8*1024); /* Queue Set-up Successful? */
maxhits = 1;
if (which == ORBIT)
plot = c_putcolor; /* for line with clipping */
/*
* end MIIM code.
*/
if(sxoffs != 0 || syoffs != 0) /* we're in view windows */
{
savehasinverse = hasinverse;
hasinverse = 1;
SaveRect(0,0,xdots,ydots);
sxoffs = 0;
syoffs = 0;
RestoreRect(0,0,xdots,ydots);
hasinverse = savehasinverse;
}
if(which == ORBIT)
do_fractal_routines(cr, ci,PER_IMAGE);
else
color = color_bright;
oldhelpmode = helpmode;
if(which == JIIM)
helpmode = HELP_JIIM;
else
helpmode = HELP_ORBITS;
if(xdots == sxdots || ydots == sydots ||
sxdots-xdots < sxdots/3 ||
sydots-ydots < sydots/3 ||
xdots >= MAXRECT )
{
/* this mode puts orbit/julia in an overlapping window 1/3 the size of
the physical screen */
windows = 0; /* full screen or large view window */
xd = sxdots / 3;
yd = sydots / 3;
xc = xd * 2;
yc = yd * 2;
xoff = xd * 5 / 2;
yoff = yd * 5 / 2;
}
else if(xdots > sxdots/3 && ydots > sydots/3)
{
/* Julia/orbit and fractal don't overlap */
windows = 1;
xd = sxdots-xdots;
yd = sydots-ydots;
xc = xdots;
yc = ydots;
xoff = xc + xd/2;
yoff = yc + yd/2;
}
else
{
/* Julia/orbit takes whole screen */
windows = 2;
xd = sxdots;
yd = sydots;
xc = 0;
yc = 0;
xoff = xd/2;
yoff = yd/2;
}
xfactor = xd/5.33;
yfactor = -yd/4;
if(windows == 0)
SaveRect(xc,yc,xd,yd);
else if(windows == 2) /* leave the fractal */
{
fillrect(xdots, yc, xd-xdots, yd, color_dark);
fillrect(xc , ydots, xdots, yd-ydots, color_dark);
}
else /* blank whole window */
fillrect(xc, yc, xd, yd, color_dark);
setup_convert_to_screen(&cvt);
/* reuse last location if inside window */
xcrsr = cvt.a*SaveC.x + cvt.b*SaveC.y + cvt.e + .5;
ycrsr = cvt.c*SaveC.x + cvt.d*SaveC.y + cvt.f + .5;
if(xcrsr < 0 || xcrsr >= xdots ||
ycrsr < 0 || ycrsr >= ydots)
{
cr = (xxmax + xxmin) / 2.0;
ci = (yymax + yymin) / 2.0;
}
else
{
cr = SaveC.x;
ci = SaveC.y;
}
old_x = old_y = -1;
xcrsr = cvt.a*cr + cvt.b*ci + cvt.e + .5;
ycrsr = cvt.c*cr + cvt.d*ci + cvt.f + .5;
Cursor_SetPos(xcrsr, ycrsr);
Cursor_Show();
color = color_bright;
iter = 1;
still = 1;
zoom = 1;
#ifdef XFRACT
Cursor_StartMouseTracking();
#endif
while (still)
{
int dxcrsr, dycrsr;
if (actively_computing) {
Cursor_CheckBlink();
} else {
Cursor_WaitKey();
}
if(keypressed() || first_time) /* prevent burning up UNIX CPU */
{
first_time = 0;
while(keypressed())
{
Cursor_WaitKey();
kbdchar = getakey();
dxcrsr = dycrsr = 0;
xcjul = BIG;
ycjul = BIG;
switch (kbdchar)
{
case 1143: /* ctrl - keypad 5 */
case 1076: /* keypad 5 */
break; /* do nothing */
case CTL_PAGE_UP:
dxcrsr = 4;
dycrsr = -4;
break;
case CTL_PAGE_DOWN:
dxcrsr = 4;
dycrsr = 4;
break;
case CTL_HOME:
dxcrsr = -4;
dycrsr = -4;
break;
case CTL_END:
dxcrsr = -4;
dycrsr = 4;
break;
case PAGE_UP:
dxcrsr = 1;
dycrsr = -1;
break;
case PAGE_DOWN:
dxcrsr = 1;
dycrsr = 1;
break;
case HOME:
dxcrsr = -1;
dycrsr = -1;
break;
case END:
dxcrsr = -1;
dycrsr = 1;
break;
case UP_ARROW:
dycrsr = -1;
break;
case DOWN_ARROW:
dycrsr = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -