[comp.sources.amiga] v02i003: surf - produce bezier surfaces of revolution, Part02/03

page@swan.ulowell.edu (Bob Page) (10/20/88)

Submitted-by: edavies@uvvm.bitnet (Eric Davies)
Posting-number: Volume 2, Issue 3
Archive-name: graphics/surf.2of3

# This is a shell archive.  Remove anything before this line
# then unpack it by saving it in a file and typing "sh file"
# (Files unpacked will be owned by you and have default permissions).
# This archive contains the following files:
#	./gadgetdef.h
#	./gadgetuse.c
#	./getfilenames.c
#	./graypat.c
#	./lattice.make
#	./main.c
#	./manx.makefile
#	./mapcalc.c
#	./mapimgpix.c
#	./mapstuff.c
#	./mapstuff.h
#	./menu_color.c
#	./menu_files.c
#	./menu_image.c
#	./menu_scrn.c
#
if `test ! -s ./gadgetdef.h`
then
echo "writing ./gadgetdef.h"
cat > ./gadgetdef.h << '\Rogue\Monster\'
#ifndef GADGETDEF_H_FILE
#define GADGETDEF_H_FILE
#include "mytypes.h"

#define MPtrXOffset -1L
#define MPtrYOffset -1L
#define MPtrCol17 623L
#define MPtrCol18 0L
#define MPtrCol19 976L

extern UWORD *HourGlass;

extern void InitGadgets();
extern void EndGadgets();
extern void GadgetHandler();

enum GadgetName { N_DefLines, N_EditLines, N_EditBez, N_Map, N_Wire,
                  N_Shaded, N_TiltAng, N_PtIntens, N_BkIntens, N_SurfDist,
                  N_PtLocX, N_PtLocY, N_PtLocZ, N_BezSlices, N_RevSlices,
                  N_RevAngle, N_Kspec, N_Kdiffuse, N_GoPanel, N_GoSurf,
                  N_BackPlane, N_RevStart, N_RepH, N_RepV };

struct GadExtens {
    float minfval, maxfval, curfval; /* min,max, and cur float values */
    short minival, maxival, curival; /* same but short ints */
    bool isfloat;   /* true if value is floating, false if short */
};

#endif GADGETDEF_H_FILE
\Rogue\Monster\
else
  echo "will not over write ./gadgetdef.h"
fi
if `test ! -s ./gadgetuse.c`
then
echo "writing ./gadgetuse.c"
cat > ./gadgetuse.c << '\Rogue\Monster\'
/* this file contains definition for the screen */

#include "scrnio.ih"
#include <exec/memory.h>
#ifdef MANX
#include <functions.h>
#endif

#include "scrndef.h"
#include "gadgetdef.h"
#include "mytypes.h"
#include "poly.h"
#include "readilbm.h"

#define GetExtens(gei) ((struct GadExtens *)gei->UserData)


void GadgetSetVal(gad)
    struct Gadget *gad;
{
    struct GadExtens *vp;
    struct PropInfo *prop;
    long gadval;

    if( !(gad->GadgetType & PROPGADGET) ) {
        return;
    }

    if( !gad->GadgetRender ) {
        gad->GadgetRender = (APTR) malloc(sizeof(struct Image));
    }
    if( !gad->SpecialInfo ) {
        static struct PropInfo dummyprop = {
            FREEHORIZ|AUTOKNOB,
            0x8000, 1, /* HorizPot = initial value */
            0xff, 0, /* not really of interest */
            0,0,0,0,0,0
        };

        gad->SpecialInfo = (APTR) malloc(sizeof(struct PropInfo));
        *(struct PropInfo *)gad->SpecialInfo = dummyprop;
    }

    vp = GetExtens( gad );
    if(!vp)  {
        return;
    }
    prop = (struct PropInfo *) gad->SpecialInfo;

    if( vp->isfloat ) {
        gadval = (long)( (long)MAXPOT *
            ( vp->curfval - vp->minfval )/(vp->maxfval - vp->minfval));
        prop->HorizBody = MAXPOT /( 15 * 8 );
    }
    else {
        gadval = ( (long)MAXPOT *
            ( (long) vp->curival - vp->minival))/(vp->maxival - vp->minival);
        prop->HorizBody = MAXPOT /( vp->maxival - vp->minival );
    }

    prop->HorizPot = gadval;
}



void GadgetUpdate(gad, exists)
    struct Gadget *gad;
    bool exists; /* has the gadget already been displayed? */
{
    struct GadExtens *vp;
    long potvalue;
    char dbuff[25];
    char *tx, *dx;
    struct IntuiText *it;

    if(!( gad->GadgetType & PROPGADGET) ) {
        return;
    }

    vp = GetExtens( gad );
    if(!vp) return;

    potvalue = ((struct PropInfo *) gad->SpecialInfo)->HorizPot;

    if( vp->isfloat ) {
        float temp;
        temp = ( potvalue * (vp->maxfval - vp->minfval ))/ MAXPOT
                + vp->minfval;
        vp->curfval = temp;
#if !MANX
        sprintf(dbuff,"%f   ", temp);
#else
        ftoa(temp, dbuff, sizeof(dbuff)-4, 1);
#endif !MANX
    }
    else {
        long temp;
        temp = (long)( potvalue * (vp->maxival - vp->minival ))/ MAXPOT
                + vp->minival;
        vp->curival = temp;
        sprintf(dbuff,"%-12d", temp);
    }
    /*
     * find '['
     */
    it = gad->GadgetText;
    for( tx = (char *)it->IText; *tx && *tx != '['; tx++ ) {
        ;
    }
    if( !*tx ) {
        return; /* something screwy */
    }
    tx++; /* skip past opening bracket */
    dx = dbuff;
    while( *tx != ']' ) {
        *tx++ = *dx++;
    }

    if(exists){
        long tempx, tempy;
        tempx = it->LeftEdge + gad->LeftEdge;
        tempy = it->TopEdge + gad->TopEdge + 6; /*fudge factor for baseline*/
        Move( CntrlWin->RPort, tempx, tempy );
        SetAPen(CntrlWin->RPort,it->FrontPen );
        Text( CntrlWin->RPort, it->IText, strlen(it->IText ));
    }
}

SetHourGlass() {
        SetPointer( SurfWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
        SetPointer( GadWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
        SetPointer( CntrlWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);

}

ClearHourGlass() {
        ClearPointer(SurfWin);
        ClearPointer(GadWin);
        ClearPointer(CntrlWin);
}

void GadgetHandler(gadaddr)
    struct Gadget *gadaddr;
{
    short curival;
    float curfval;

    if( gadaddr->UserData ) {
        GadgetUpdate( gadaddr, true );
        curival = ((struct GadExtens *) gadaddr->UserData)->curival;
        curfval = ((struct GadExtens *) gadaddr->UserData)->curfval;
    }

    switch( (enum GadgetName) gadaddr->GadgetID ) {
    case N_PtLocX:
        LightSrc.x = (float)curival;
        break;
    case N_PtLocY:
        LightSrc.y = (float)curival;
        break;
    case N_BackPlane:
        BackColor = curival;
        break;
    case N_PtLocZ:
        LightSrc.z = (float)curival;
        break;
    case N_BkIntens:
        Ambience = curfval;
        break;
    case N_PtIntens:
        PtIntensity = curfval;
        break;
    case N_Kdiffuse:
        Kd = curfval;
        break;
    case N_Kspec:
        Ks = curfval;
        break;
    case N_Map:
        /* ResetCurve(); */
        SetHourGlass();
        RevMap();
        ClearHourGlass();
        break;
    case N_Wire:
        SetHourGlass();
        RevNoShade();
        ClearHourGlass();
        break;
    case N_Shaded:
        SetHourGlass();
        RevShade();
        ClearHourGlass();
        break;
    case N_EditBez:
        SetFitBez();
        break;
    case N_DefLines:
        SetPolyDraw();
        break;
    case N_RevAngle:
        SetRotRange( curival );
        break;
    case N_RevStart:
        SetRotStart( curival );
        break;
    case N_TiltAng:
        SetSecAng( curival );
        break;
    case N_RevSlices:
        SetRevMesh( curival );
        break;
    case N_BezSlices:
        SetBezMesh( curival );
        break;
    case N_SurfDist:
        SetSurfDist( curival);
        break;
    case N_RepV:
        MapRepV = curival;
        PrepImgPix();
        break;
    case N_RepH:
        MapRepH = curival;
        PrepImgPix();
        break;
    case N_GoSurf:
        ScreenToFront( SurfScrn );
        break;
    case N_GoPanel:
        WBenchToFront();
        WindowToFront( CntrlWin );
        break;
    default:
        break;
    }
}
\Rogue\Monster\
else
  echo "will not over write ./gadgetuse.c"
fi
if `test ! -s ./getfilenames.c`
then
echo "writing ./getfilenames.c"
cat > ./getfilenames.c << '\Rogue\Monster\'
#include <intuition/intuition.h>
#include "scrnio.ih"
#include <exec/memory.h>
#ifdef MANX
#include <functions.h>
#endif

#include "scrndef.h"
#include "mytypes.h"


#define StringSize 40
#define ROW 8
#define COL 8
#define TextX COL
#define TextY (ROW/2)
#define StringX 8
#define StringY 12
#define ReqSizeX 50*COL
#define ReqSizeY 6*ROW

#define CodeGo 100
#define CodeCancel 101

/*
 * declarations for a cancel button to be used by both
 * requestors.
 */
static struct IntuiText TextCancel = {
    1,-1,JAM1, 2, 1, NULL,(UBYTE *) "Cancel", NULL };

static short S_Cancel[] = {
    -2,-1,  -2,ROW+1,  6*COL+2,ROW+1,  6*COL+2,-1, -2,-1
 };

static struct Border B_Cancel = { 0, 0, 1, 0, JAM1, 5, S_Cancel, NULL };

static struct Gadget G_Cancel = {
    NULL,
    10*COL, ROW *4, 6*COL, ROW, /* loc and size of hit box */
    GADGHBOX,    /* complemented when pressed */
    RELVERIFY,    /* just get gadget up messages */
    BOOLGADGET | REQGADGET,
    (APTR)&B_Cancel, NULL,
    &TextCancel,
    0, NULL,
    (int)CodeCancel,
    NULL
 };

/*
 * String gadget to get ilbm filename
 */
static char OutTitle[] = { "output filename:" };
static char InTitle[] = { "input filename:" };

static struct IntuiText TextOutFile = {
    1,1,JAM1, TextX, TextY, NULL,
    (UBYTE *)OutTitle, NULL
 };
static struct IntuiText TextInFile = {
    1,1,JAM1, TextX, TextY, NULL,
    (UBYTE *)InTitle, NULL
 };


static char OutNameBuff[StringSize] = { "out.ilbm" };
static char InNameBuff[StringSize] =  { "in.ilbm" };
static char undo[StringSize];

static struct StringInfo S_OutFile = {
    (UBYTE *)OutNameBuff,
    (UBYTE *)undo,
    0,
    sizeof( OutNameBuff),
    0,
    0,
    13,
    0,
    0,0,NULL,0, NULL
};

static struct StringInfo S_InFile = {
    (UBYTE *)InNameBuff,
    (UBYTE *)undo,
    0,
    sizeof( InNameBuff),
    0,
    0,
    13,
    0,
    0,0,NULL,0, NULL
};

static short BD_InOut[] = {
    -2,-1,  -2, ROW,  (StringSize-1)*COL+1,ROW,
    (StringSize-1)*COL+1,-1, -2, -1
 };

static struct Border B_InOut = { 0, 0, 1, 0, JAM1, 5, BD_InOut, NULL };

static struct Gadget G_OutFile = {
    &G_Cancel,
    StringX , StringY,   /* loc */
    sizeof(OutNameBuff)*COL, ROW, /* size */
    GADGHCOMP,
    RELVERIFY /* | STRINGCENTER */,
    STRGADGET | REQGADGET,
    (APTR)&B_InOut, /* border */
    NULL, /* high lighted */
    &TextOutFile,
    0,
    (APTR) &S_OutFile,
    (int)CodeGo,
    NULL
 };


static struct Gadget G_InFile = {
    &G_Cancel,
    StringX , StringY,   /* loc */
    sizeof(InNameBuff)*COL, ROW, /* size */
    GADGHCOMP,
    RELVERIFY/* | STRINGCENTER */,
    STRGADGET | REQGADGET,
    (APTR)&B_InOut, /* border */
    NULL, /* high lighted */
    NULL, /* text */
    0,
    (APTR) &S_InFile,
    (int)CodeGo,
    NULL
 };

static struct Requester R_InFile = {
    NULL,
    COL*10, ROW*4, ReqSizeX, ReqSizeY,
    0, 0,
    &G_InFile,
    NULL,
    &TextInFile,
    NULL,
    2, /* backfill */
    NULL,
    { NULL },
    { NULL },
    NULL,
    { NULL },
};




static struct Requester R_OutFile = {
    NULL,
    COL*10, ROW*4, ReqSizeX, ReqSizeY,
    0, 0,
    &G_OutFile,
    NULL,
    &TextOutFile,
    NULL,
    2, /* backfill */
    NULL,
    { NULL },
    { NULL },
    NULL,
    { NULL },
};

static bool
WaitForUser() {
    struct IntuiMessage mycopy,
                        *orig;
    long wakeupmask;

    for(;;) {
        wakeupmask = Wait( 1<< CntrlWin->UserPort->mp_SigBit );

        /*
         * handle messages for the control window
         */

        while( orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort ) ) {

            mycopy = *orig;
            ReplyMsg( orig );

            if( mycopy.Class == GADGETUP ) {
                USHORT code;

                code = ((struct Gadget*)mycopy.IAddress)->GadgetID;
                if( code == CodeGo ) return( true );
                if( code == CodeCancel) return(false);
            }
        }
    }
}



char *GetInFile()
{
    bool answer;
    Request( &R_InFile, CntrlWin);
    answer = WaitForUser();
    EndRequest( &R_InFile, CntrlWin);
    return( answer?InNameBuff: NULL);
}


char *GetOutFile()
{
    bool answer;
    Request( &R_OutFile, CntrlWin);
    answer = WaitForUser();
    EndRequest( &R_OutFile, CntrlWin);
    return( answer?OutNameBuff: NULL);
}




\Rogue\Monster\
else
  echo "will not over write ./getfilenames.c"
fi
if `test ! -s ./graypat.c`
then
echo "writing ./graypat.c"
cat > ./graypat.c << '\Rogue\Monster\'
#include <exec/types.h>
/*
 * a set of gray scales so we can pretend to have a few more colors
 * (hopefully, 8 times as many)
 * derived from a set of files by Karl Kashinsky
 */
UWORD GrayPat[9][4] = {
    {
        0x0000,        0x0000,        0x0000,        0x0000
    },

    {
        0x8080,        0x0202,        0x4040,        0x1010
    },

    {
        0xaaaa,        0x0000,        0x5555,        0x0000
    },

    {
        0xA2A2,        0x1515,        0xA8A8,        0x4545
    },

    {
        0xAAAA,        0x5555,        0xAAAA,        0x5555
    },

    {
        0x7777,        0xDDDD,        0xBBBB,        0xEEEE
    },

    {
        0xAAAA,        0xffff,        0x5555,        0xffff
    },

    {
        0x7F7F,        0xFDFD,        0xBFBF,        0xEFEF
    },

    {
        0xffff,        0xffff,        0xffff,        0xffff
    }
};

\Rogue\Monster\
else
  echo "will not over write ./graypat.c"
fi
if `test ! -s ./lattice.make`
then
echo "writing ./lattice.make"
cat > ./lattice.make << '\Rogue\Monster\'
.c.o:
	copy $*.c to ram:
	lc -ct -f -oram:$@ ram:$*.c
	copy ram:$@ to $@
	-delete ram:$@
	-delete ram:$*.c

ofiles = scrnio.o scrnops.o scrndef.o main.o gadgetdef.o menudef.o graypat.o mouse.o gadgetuse.o
gfiles = bezpt.o revolve.o control.o poly.o fasttrig.o
imagefiles = readilbm.o writeilbm.o packer.o mapstuff.o mapcalc.o getfilenames.o mapimgpix.o

all:	surf MergeRGB


MergeRGB:	MergeRGB.o
		Blink with MergeRGB.lnk

Surf:		$(ofiles) $(gfiles) $(imagefiles)
		blink with surf.lnk

bezpt.o:        scrnio.h control.h bezpt.h mytypes.h

control.o:      bezpt.h control.h scrnio.h mytypes.h

fasttrig.o:     fasttrig.h

getfilenames.o:  scrnio.ih scrndef.h mytypes.h

gadgetdef.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h bezpt.h poly.h revolve.h

gadgetuse.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h poly.h

main.o: scrnio.h mytypes.h

menu_files.o:   gadgetdef.h

menu_scrn.o:    scrndef.h

menudef.o:      scrnio.h menudef.h scrndef.h poly.h menu_color.c menu_scrn.c menu_image.c menu_files.c

mouse.o:        scrnio.ih scrnio.h mytypes.h bezpt.h control.h

poly.o: mytypes.h scrnio.h bezpt.h revolve.h control.h poly.h readilbm.h

readilbm.o mapimgpix.o:     readilbm.h

revolve.o:      fasttrig.h bezpt.h revolve.h mytypes.h

scrndef.o:      scrndef.h

mapcalc.o:      mytypes.h mapstuff.h

mapstuff.o:     poly.h mapstuff.h

\Rogue\Monster\
else
  echo "will not over write ./lattice.make"
fi
if `test ! -s ./main.c`
then
echo "writing ./main.c"
cat > ./main.c << '\Rogue\Monster\'
#include "scrnio.h"
#include "mytypes.h"

main()
{
    InitWindow();
  /*  ClrWindow(true); */
    SwitchBox();
    CloseDisplay();
}

\Rogue\Monster\
else
  echo "will not over write ./main.c"
fi
if `test ! -s ./manx.makefile`
then
echo "writing ./manx.makefile"
cat > ./manx.makefile << '\Rogue\Monster\'
ofiles = scrnio.o scrnops.o scrndef.o main.o gadgetdef.o menudef.o graypat.o mouse.o gadgetuse.o
gfiles = bezpt.o revolve.o control.o poly.o fasttrig.o
imagefiles = readilbm.o writeilbm.o packer.o mapstuff.o mapcalc.o getfilenames.o mapimgpix.o

CFLAGS = +L

LFLAGS = -lm32 -lc32

surf:   $(ofiles) $(gfiles) $(imagefiles)
    ln -o surf $(ofiles) $(gfiles) $(imagefiles) $(LFLAGS)

bezpt.o:        scrnio.h control.h bezpt.h mytypes.h

control.o:      bezpt.h control.h scrnio.h mytypes.h

fasttrig.o:     fasttrig.h

getfilenames.o:  scrnio.ih scrndef.h mytypes.h

gadgetdef.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h bezpt.h poly.h revolve.h

gadgetuse.o:    scrnio.ih scrndef.h gadgetdef.h mytypes.h poly.h

main.o: scrnio.h mytypes.h

menu_files.o:   gadgetdef.h

menu_scrn.o:    scrndef.h

menudef.o:      scrnio.h menudef.h scrndef.h poly.h menu_color.c menu_scrn.c menu_image.c menu_files.c

mouse.o:        scrnio.ih scrnio.h mytypes.h bezpt.h control.h

poly.o: mytypes.h scrnio.h bezpt.h revolve.h control.h poly.h readilbm.h

readilbm.o mapimgpix.o:     readilbm.h

revolve.o:      fasttrig.h bezpt.h revolve.h mytypes.h

scrndef.o:      scrndef.h

mapcalc.o:      mytypes.h mapstuff.h

mapstuff.o:     poly.h mapstuff.h

\Rogue\Monster\
else
  echo "will not over write ./manx.makefile"
fi
if `test ! -s ./mapcalc.c`
then
echo "writing ./mapcalc.c"
cat > ./mapcalc.c << '\Rogue\Monster\'
#include <math.h>
#include "mytypes.h"
#include "revolve.h"       /* need to get scrnpair from here */
#include "mapstuff.h"
#include "menuexp.h"

#ifdef TEST
#undef DebugOn
#define DebugOn 1
#endif TEST


#define DEBUG
/*
 * this section of code derived from:
 * "The essential algorithms of ray tracing" by Eric Haines
 * presented in Sigraph proceedings on Ray Tracing
 * my major change has been to simplify it for two dimensions
 */

typedef struct {
    float x, y;
} Vector;

static float DotVector(a,b)
    Vector *a, *b;
{
    return( a->x * b->x + a->y * b->y);
}

static void DivVector(in, scale, out)
    Vector *in, *out;
    float scale;
{
    if ( fabs(scale) < SingleTinyVal ) {
        out->x = SingleLargeVal;
        out->y = SingleLargeVal;
    }
    else {
        out->x = in->x / scale;
        out->y = in->y / scale;
    }
}



static Vector Na, Nb, Nc;
static float Du0, Du1, Du2,
             Dv0, Dv1, Dv2;
static Vector Qux, Quy,
              Qvx, Qvy;
static float Dux, Duy,
             Dvx, Dvy;
static bool IsQuadu, IsQuadv;

void CalcMapConsts(vp)
    register ScrnPair *vp;
#define p00 vp[0]
#define p01 vp[1]
#define p11 vp[2]
#define p10 vp[3]
{
    Vector Pa, Pb, Pc, Pd;

    Pa.x = p00.x - p10.x + p11.x - p01.x;
    Pa.y = p00.y - p10.y + p11.y - p01.y;

    Pb.x = p10.x - p00.x;
    Pb.y = p10.y - p00.y;

    Pc.x = p01.x - p00.x;
    Pc.y = p01.y - p00.y;

    Pd.x = p00.x;
    Pd.y = p00.y;

    Na.x = Pa.y; Na.y = -Pa.x;
    Nc.x = Pc.y; Nc.y = -Pc.x;
    Nb.x = Pb.y; Nb.y = -Pb.x;

    Du0 = DotVector(&Nc, &Pd);
    Du1 = DotVector(&Na, &Pd) + DotVector(&Nc, &Pb);
    Du2 = DotVector( &Na, &Pb);

    if( fabs( Du2 ) > SingleTinyVal ) {
        float TwoDu2;

        IsQuadu = true;
        TwoDu2 = 2.0 * Du2;
        DivVector( &Na, TwoDu2, &Qux );
        DivVector( &Nc, -Du2, &Quy );
        Duy = Du0/Du2;
        Dux = -Du1/TwoDu2;
    }
    else {
        IsQuadu = false;
    }

    Dv0 = DotVector( &Nb, &Pd);
    Dv1 = DotVector(&Na, &Pd) + DotVector(&Nb, &Pc);
    Dv2 = DotVector( &Na, &Pc);
    if( fabs( Dv2 ) > SingleTinyVal ) {
        float TwoDv2;

        IsQuadv = true;
        TwoDv2 = 2.0 * Dv2;
        DivVector( &Na, TwoDv2, &Qvx);
        DivVector( &Nb, -Dv2, &Qvy);
/*      DivVector( &Nc, -Dv2, &Qvy); */
        Dvx = - Dv1/TwoDv2;
        Dvy = Dv0/Dv2;
    }
    else {
        IsQuadv = false;
    }
#ifdef DEBUG
    if( DebugOn ) {
        printf("du2 %f, du1 %f, du0 %f\n", Du2, Du1, Du0 );
        printf("dv2 %f, dv1 %f, dv0 %f\n", Dv2, Dv1, Dv0 );
        printf("Na = (%f, %f), Nb = (%f,%f), Nc = (%f,%f)\n",
        Na.x, Na.y, Nb.x, Nb.y, Nc.x, Nc.y );
        printf("IsQuad =(%c, %c)\n", IsQuadu?'t':'f', IsQuadv? 't': 'f' );
    }
#endif DEBUG

}


/*
 * given points px,py in the quadrilateral, map them to points inside a
 * unit square
 */
void  MapXYRatio(px, py, outx, outy, SweepCode)
    float px, py;
    float *outx, *outy;
    short SweepCode;
{
    float resu, resv;
    Vector Ri;


    Ri.x = px; Ri.y = py;

    if( !IsQuadu ) {
        float denom;
        denom = (Du1 - DotVector(&Na, &Ri));
        if( fabs(denom) < SingleTinyVal )
            resu = 2.0;
        else
            resu = (DotVector(&Nc, &Ri) - Du0)/denom;
    } else {
        float Ka, Kb;
        float discrim;

        Ka = Dux + DotVector( &Qux, &Ri);
        Kb = Duy + DotVector( &Quy, &Ri);
        discrim = sqrt(fabs(Ka * Ka - Kb));
        resu = Ka + ((discrim > Ka)? discrim: (-discrim));
#ifdef DEBUG
        if( DebugOn ) {
            printf("dux=%f, duy = %f, ka = %f, kb = %f\n",
                Dux, Duy, Ka, Kb );
        }
#endif DEBUG

    }

    if( !IsQuadv ) {
        float denom;
        denom = (Dv1 - DotVector(&Na, &Ri));
        if( fabs(denom) < SingleTinyVal )
            resv = 2.0;
        else
            resv = (DotVector(&Nb, &Ri) - Dv0)/denom;
    } else {
        float Ka, Kb;
        float discrim;

        Ka = Dvx + DotVector( &Qvx, &Ri);
        Kb = Dvy + DotVector( &Qvy, &Ri);
        discrim = sqrt(fabs( Ka * Ka - Kb));
        resv = Ka + ((discrim > Ka)? discrim: (-discrim));
#ifdef DEBUG
        if( DebugOn ) {
            printf("dvx=%f, dvy = %f, ka = %f, kb = %f\n",
                Dvx, Dvy, Ka, Kb );
        }
#endif DEBUG
    }

#ifdef DEBUG
    if( DebugOn ) {
        printf("(%f,%f) -> (%f, %f)\n", px, py, resu, resv );
    }
#endif DEBUG

    if( resu > 1.0 || resu < 0.0 ) {
        resu = ( SweepCode & MP_XMAX)? 1.0: 0.0;
    }
    if( resv > 1.0 || resv < 0.0 ) {
        resv = ( SweepCode & MP_YMAX)? 1.0: 0.0;
    }

    *outx = resu; *outy = resv;
}



/*
 * here abides testcode
 */
#ifdef TEST
#include <stdio.h>

ReadScrnPair(set, a)
    char *set;
    ScrnPair *a;
{
    int tx, ty;
    printf("enter screen pair %s\n",set);
    scanf("%d %d", &tx, &ty);
    a->x = tx; a->y = ty;
}

ReadLimits(a)
ScrnPair a[];
{
    ReadScrnPair("a", &a[0]);
    ReadScrnPair("b", &a[1]);
    ReadScrnPair("c", &a[2]);
    ReadScrnPair("d", &a[3]);
}

main() {
    float inx, iny;
    float outy, outx;
    ScrnPair pts[4];

    ReadLimits(pts);
    CalcMapConsts(pts);
    while(!feof(stdin)) {
        printf("enter quadrilateral points\n");
        scanf("%f %f", &inx, &iny );
        MapXYRatio( inx, iny, &outx, &outy, 0);
        printf("p(%f,%f)->p(%f,%f)\n", inx, iny, outx, outy);
    }
}
#endif TEST
\Rogue\Monster\
else
  echo "will not over write ./mapcalc.c"
fi
if `test ! -s ./mapimgpix.c`
then
echo "writing ./mapimgpix.c"
cat > ./mapimgpix.c << '\Rogue\Monster\'
#include "mytypes.h"
#include "readilbm.h"

#define DefRes 2
int MapImageV = DefRes*DefRepV,
    MapImageH= DefRes*DefRepH; /* virtual screen size */
static int PixV=DefRes,
           PixH=DefRes;  /* true ilbm size in pixels */
short MapRepV = DefRepV,
      MapRepH = DefRepH;
static short BytesPerLine;
static unsigned char *Raster= null;
static long MaxShade;
static bool AxisFlipped = DefXYFlip;
/*
 * Update the MapImageH and MapImageV variables
 */
void PrepImgPix()
{
    MapImageV = PixV * MapRepV;
    MapImageH = PixH * MapRepH;
    if( AxisFlipped ) {
        int temp;
        temp = MapImageV;
        MapImageV = MapImageH;
        MapImageH = temp;
    }
}
/*
 * free up any memory holding mapping image
 */
void CloseImgPix()
{
        if( Raster) free(Raster);
        Raster = null;
        PixV = 0xff; PixH = 0xff;
        PrepImgPix();
}

/*
 * cause x and y axises to be reversed
 */
void FlipImgPix( flip )
    bool flip;
{
    AxisFlipped = flip;
    PrepImgPix();
}

/*
 * 4 bits per pixel means 2 pixels per byte
 */
bool OpenImgPix(sizex, sizey, maxshade)
    int sizex, sizey;
    short maxshade;
{
    CloseImgPix();
    if( maxshade == 0 ) {
        OutErr("OpenImgPix: got max shade = 0\n");
        maxshade = 1;
     }
    MaxShade = maxshade;
    BytesPerLine = (sizex +1)/2;
    Raster = (unsigned char *) malloc( BytesPerLine * sizey);
    if( !Raster ) {
        printf("OpenImgPix: not enough memory\n");
        return(false); /* no memory err */
    }

    PixV = sizey;
    PixH = sizex;
    PrepImgPix();
    return(true);
}

#define CalcByte(cbx,cby) (Raster + ( BytesPerLine * cby ) + (cbx >> 1))


void SetImgPix(x, y, val)
    int x, y; /* location */
    int val;
{
    unsigned char *bite;
    unsigned char shade;

    if( x > PixH || x < 0 || y > PixV || y < 0 ) {
        OutErr("SetImgPix(%d,%d,%d) out of range\n",x,y,val);
        return;
    }

    if( !Raster) return;
    shade = ( (val<< 4)-val)/MaxShade;
    bite = CalcByte(x,y);
    if( x & 1) {
        *bite = (*bite & 0xf) | ( shade <<4 );
    }
    else {
        *bite = (*bite & 0xf0) | shade;
    }
}


short GetImgPix(x,y)
    int x, y;
{
    unsigned char *bite;
    short shade;

    if( AxisFlipped ) {
        int temp;
        temp = x; x = y; y = temp;
    }

    x %= PixH;
    y %= PixV;

    if( !Raster ) {
        return( ((x ^ y)& 0x10) ? 0xff: 0);
    }
    bite = CalcByte(x,y);

    if( x & 1) {
        return( *bite & 0xf0);
    }
    else {
        return( (*bite & 0x0f) <<4);
    }
}
\Rogue\Monster\
else
  echo "will not over write ./mapimgpix.c"
fi
if `test ! -s ./mapstuff.c`
then
echo "writing ./mapstuff.c"
cat > ./mapstuff.c << '\Rogue\Monster\'
#include <math.h>
#include "mytypes.h"
#include "poly.h"
#include "bezpt.h"
#include "revolve.h"
#include "readilbm.h"
#include "mapstuff.h"
#include "menuexp.h"

#define FarRight   1e6
#define FarLeft   -1e6
#define FarTop     0x7fff
#define FarBottom -0x7fff

/*
#ifndef MANX
#include "libraries/mathffp.h"
#define ceil	SPCeil
#define floor	SPFloor
#define fabs	SPAbs
#endif
*/

typedef struct { float left, right; } Hedge;

static float *BezMapping = null,
             *RevMapping = null;
static float revmin, revdiff,
             bezmin, bezdiff;


/*
 * given the ptlist of a polygon, find its vertical range
 */
static void FindVRange(scrnlist, top, bottom)
    register ScrnPair *scrnlist;
    short *top, *bottom;
{
    short i;
    short localtop, localbot;

    localtop = FarBottom;
    localbot = FarTop;

    for( i = 4; i--; scrnlist++ ) {
        if( localtop < scrnlist->y ) localtop = scrnlist->y;
        if( localbot > scrnlist->y ) localbot = scrnlist->y;
    }
    *top = localtop;
    *bottom = localbot;
}
/*
 * allocate table to store a quick and dirty representation of the
 * quadrilateral segments
 */
static Hedge *InitVRange( depth, tabptr, olddepth )
    short depth, *olddepth;
    Hedge *tabptr;
{
    Hedge *edgel, *tab;
    if( *olddepth < depth || !tabptr ) {
        if( tabptr ) free( tabptr);
        tab = (Hedge *) malloc(sizeof(Hedge)*depth);
        *olddepth = depth;
    }
    else {
        tab = tabptr;
    }
    if( !tab ) return( null);

    for( edgel = tab; depth--; edgel++) {
        edgel->left = FarRight;
        edgel->right = FarLeft;
    }
    return( tab );
}


/*
 * add line to quadrilateral descriptions
 */
static void AddVLine( tab, x1, y1, x2, y2 )
    Hedge *tab;
    short x1, y1, x2, y2;
{
    short dy;
    float curx, slope;
    /*
     * want y1 to have smaller value, ie, y1 below y2
     */
    if( y1 > y2 ) {
        short temp;
        temp = y1; y1 = y2; y2 = temp;
        temp = x1; x1 = x2; x2 = temp;
    }
    dy = y2 - y1;
    tab += y1;

    if( !dy ) {
        if ( x1 < x2 ) {
            short tempx;
            tempx = x1; x1 = x2; x2 = tempx;
        }
        if( x2 < tab->left ) tab->left = x2;
        if( x1 > tab->right ) tab->right = x1;
        return;
    }
    slope = (float)(x2 - x1)/dy;

    curx = x1;
#define ZipIt(xxx) { if( xxx < tab->left) tab->left = xxx; \
                     if( xxx > tab->right ) tab->right = xxx; }
    ZipIt(curx);
    while( dy--) {
        curx += slope;
        tab++;
        ZipIt(curx);
    }
}


static void AdjMapXY( inx, iny, outpair)
    float inx, iny;
    ScrnPair *outpair;
{
    float outx, outy;
    MapXYRatio( inx, iny, &outx, &outy);

    outpair->y = MapImageH * (bezmin + bezdiff * outy);
    outpair->x = MapImageV * (revmin + revdiff * outx);

/*
    if( RevAxis == RevX ) {
        outpair->y = MapImageH * (bezmin + bezdiff * outy);
        outpair->x = MapImageV * (revmin + revdiff * outx);
    } else {
        outpair->x = MapImageH * (bezmin + bezdiff * outy);
        outpair->y = MapImageV * (revmin + revdiff * outx);
    }
 */
}

static void ScanCnvQuad( tab, pt)
    Hedge *tab;
    ScrnPair pt[];
{
    register int i;
    ScrnPair *listb, *liste;

    liste = pt;
    listb = liste + 3;
    for ( i = 4; i--;) {
        AddVLine( tab, listb->x, listb->y, liste->x, liste->y);
        listb = liste++;
    }
}

static float AverageShade(pts)
    ScrnPair pts[];
{
    register Hedge *tab;
    static Hedge *tabfree = null;
    static short olddepth = 0;
    short top, bot;
    long shade = 0,
         pixcnt = 0;

    FindVRange( pts, &top, &bot);
    tabfree = tab = InitVRange( top - bot + 1, tabfree, &olddepth);
    if(!tabfree) return(0.0);

    ScanCnvQuad( tab-bot, pts );
#if DEBUG
    if( DebugOn ) {
        printf("AverageShade top is %d, bot = %d\n", top, bot );
    }
#endif DEBUG

    while( bot <= top ) {
        register int hori;
        int right, left;
#if DEBUG
    if( DebugOn ) {
        printf("....row %d    \t%d -> %d\n", bot, left, right );
    }
#endif DEBUG

        left =  (int) ceil(tab->left - SingleTinyVal);
        right = (int)floor(tab->right+ SingleTinyVal);

        for( hori= left; hori <= right; hori++ ) {
            shade += GetImgPix( bot, hori);
            pixcnt++;
        }

    /*
        if( RevAxis == RevX ) {
            for( hori= left; hori <= right; hori++ ) {
                shade += GetImgPix( bot, hori);
                pixcnt++;
            }
        }
        else {
            for( hori= left; hori <= right; hori++ ) {
                shade += GetImgPix( hori, bot);
                pixcnt++;
            }
        }
    */
        tab++;
        bot++;
    }
    return( (float)shade / (pixcnt *(15 *16)) );
}

/*
 * mess with the number so truncation doesn't
 * do nasty things to a float containing an int
 */
static int NearestInt( afloat )
    float afloat;
{
    afloat += ( afloat > 0 )? 1e-2 : -1e-2;
    return( (int)afloat );
}


static void ShadeQuad(tab, top, bot, intensity)
    register Hedge *tab;
    short top, bot;
    float intensity;
{
    short vert;
    float rowminl, rowminr,
          rowmaxl, rowmaxr;
    Hedge *oldtab, *nexttab;

    for ( vert =  bot;
        nexttab = tab+1, vert <= top;
        vert++, oldtab = tab, tab++ ) {
        float hori;
        float colmin, colmax;
        float leftmost, rightmost;
        int ihori, ileftmost, irightmost;
        ScrnPair MpPnts[4];

#define lefttop MpPnts[0]
#define leftbot MpPnts[3]
#define righttop MpPnts[1]
#define rightbot MpPnts[2]


        rowminl = (float)vert;
        rowmaxr = rowmaxl = rowminr = rowminl;

        if( vert > bot && oldtab->left < tab->left ) {
            rowminl -= 0.5;
        }
        if( vert > bot && oldtab->right > tab->right ) {
            rowminr -= 0.5;
        }
        if( vert < top && nexttab->left < tab->left ) {
            rowmaxl += 0.5;
        }
        if( vert < top && nexttab->right > tab->right ) {
            rowmaxr += 0.5;
        }

        irightmost = NearestInt( tab->right );
        rightmost = irightmost;
        ileftmost = NearestInt( tab->left );
        leftmost = ileftmost;
        if( irightmost < ileftmost ) {
            irightmost = ileftmost;
        }
        for( ihori = leftmost, hori = leftmost;
            ihori <= irightmost;
            ihori += 1, hori += 1.0 ) {


            if( AbortDraw ) { return; }

            colmin = hori - 0.5;
            colmax = hori + 0.5;

            colmin =(colmin > leftmost)?colmin: tab->left;
            colmax =(colmax < rightmost)?colmax: tab->right;

            AdjMapXY( colmin, rowmaxl, &lefttop,  MP_XMIN| MP_YMAX);
            AdjMapXY( colmax, rowmaxr, &righttop, MP_XMAX| MP_YMAX);
            AdjMapXY( colmin, rowminl, &leftbot,  MP_XMIN| MP_YMIN);
            AdjMapXY( colmax, rowminr, &rightbot, MP_XMAX| MP_YMIN);

            PaintPoint(ihori, vert, AverageShade(MpPnts) *intensity);
        }
    }
#undef lefttop
#undef righttop
#undef rightbot
#undef leftbot
}


void DrawRhomMap(mpr)
    MapRhomboid *mpr;
{
    short top, bottom;
    short vrange, hrange;
    static Hedge *tab = null;
    static short olddepth = 0;

    CalcMapConsts( mpr->rhom.pt );
    FindVRange( mpr->rhom.pt, &top, &bottom );
    tab = InitVRange( top - bottom + 1, tab, &olddepth );
    if(!tab) return;
    ScanCnvQuad( tab -bottom, mpr->rhom.pt );

    bezmin = BezMapping[mpr->bezindex];/* make it global */
    bezdiff = BezMapping[mpr->bezindex+1] - bezmin;
    revmin = RevMapping[mpr->revindex];
    revdiff = RevMapping[mpr->revindex+1] - revmin;
#if DEBUG
    if( DebugOn ) {
        DBMAP(mpr->rhom.pt, mpr->bezindex, mpr->revindex);
    }
#endif DEBUG
    ShadeQuad(tab, top, bottom, mpr->rhom.intensity);
}

#ifdef DEBUG
DBMAP(ptlist, bindex, rindex)
ScrnPair ptlist[];
short bindex, rindex;
{
    int i;

    printf("...................................\n");
    for( i = 0; i < 4; i++ ) {
        printf("%10d", ptlist[i].x);
    };
    printf("\n");
    for( i = 0; i < 4; i++ ) {
        printf("%10d", ptlist[i].y);
    };
    printf("\n");
    printf(" bezmin %f  bezdiff %f index = %d \n", bezmin, bezdiff, bindex );
    printf(" revmin %f  revdiff %f index = %d \n", revmin, revdiff, rindex );
}
#endif DEBUG


/*
 * return true if image mappings could not be performed
 * false if successful
 */
bool InitMapping() {
    float *vfmptr;
    float totallen = 0,
          scaling;
    short numvslices;

    if( BezMapping ) free( BezMapping );
    if( RevMapping ) free( RevMapping );

    /*
     * compute width of each bezier segment
     */
    numvslices = BezMesh*GetNumSegs() +1;
    vfmptr = BezMapping = (float *) malloc(sizeof(float) * numvslices);
    if( !BezMapping ) return(true);

    *vfmptr++ = totallen = 0.0;
    ResetActSeg();
    do {
        float t, ffromx, ftox, ffromy, ftoy;
        int i;
        InitCalcBez();
        for( i = 1, ffromx = StartPtX(ActSeg), ffromy = StartPtY(ActSeg);
            i <= BezMesh; i++, ffromx = ftox, ffromy = ftoy ) {
            float diffx, diffy;

            t = (float)i/BezMesh;

            CalcBezPt( t, &ftox, &ftoy );
            diffx = ftox - ffromx;
            diffy = ftoy - ffromy;
            totallen += sqrt( diffx * diffx + diffy * diffy );
            *vfmptr++ = totallen;
        }
        NextSeg();
    } while( ActSeg);
    /*
     * convert scale floating point values to integer pixel positions
     */
    scaling = 1.0 / totallen;
    for( vfmptr = BezMapping; numvslices; numvslices--, vfmptr++ ) {
        *vfmptr *= scaling;
    }
    /*
     * compute height of each revolution segment
     */
    RevMapping = (float *) malloc( sizeof(float) * (RevMesh + 1));
    if( !RevMapping ) return( true );
    {
        short i;
        for( i = 0; i <= RevMesh; i++ ) {
            RevMapping[i] =  ((float) i)/RevMesh;
        }
    }

    return(false);
}
\Rogue\Monster\
else
  echo "will not over write ./mapstuff.c"
fi
if `test ! -s ./mapstuff.h`
then
echo "writing ./mapstuff.h"
cat > ./mapstuff.h << '\Rogue\Monster\'
#define SingleTinyVal 1.0e-12
#define SingleLargeVal 1.0e12

#define MP_XMIN 0
#define MP_XMAX 1
#define MP_YMIN 0
#define MP_YMAX 2

bool InitMapping( /* void */);

void CalcMapConsts();
void MapXYRatio( /* float px, py; float *outx, outy; */);
void DrawRhomMap( /* MapRhomboid  *mpr; */ );

\Rogue\Monster\
else
  echo "will not over write ./mapstuff.h"
fi
if `test ! -s ./menu_color.c`
then
echo "writing ./menu_color.c"
cat > ./menu_color.c << '\Rogue\Monster\'
/*
 * Menu description for selecting color mapping
 */
static struct IntuiText colortext[] = {
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"grey",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"red",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"green", NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"blue",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"rainbow",NULL }
};

#define ColNum (sizeof(colortext)/sizeof(struct IntuiText))
#define ColXMask ((1<<ColNum)-1)
#define ColorExclude(entry) (ColXMask^( 1<<entry))

#define COLMEMFLAGS  ( CHECKIT | ITEMTEXT | HIGHCOMP | ITEMENABLED )

struct MenuItem coloritems[] = {
  { &coloritems[1], /* next item */
    10, 0, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    ColorExclude(0), /* mutual exclude bits */
    (APTR) &colortext[0],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &coloritems[2], /* next item */
    10, 10, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    ColorExclude(1), /* mutual exclude bits */
    (APTR) &colortext[1],     /* red */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &coloritems[3], /* next item */
    10, 20, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    ColorExclude(2), /* mutual exclude bits */
    (APTR) &colortext[2],
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &coloritems[4], /* next item */
    10, 30, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    ColorExclude(3), /* mutual exclude bits */
    (APTR) &colortext[3],
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    10, 40, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    ColorExclude(4), /* mutual exclude bits */
    (APTR) &colortext[4],
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};



void MenuSetColMap()
{
    int which;

    for( which = 0; which < ColNum; which++ ) {
        if( Selected(coloritems[which]))
            break;
    }

    SetHourGlassCol();

    switch( which ) {
    case 0:
        SetMono( 0xf, 0xf, 0xf );
        break;
    case 1:
        SetMono( 0xf, 0, 0 );
        break;
    case 2:
        SetMono( 0, 0xf, 0 );
        break;
    case 3:
        SetMono( 0x0, 0x0, 0xf );
        break;
    case 4:
        SetRainbow();
        break;
    default:
        break;
    }
}
\Rogue\Monster\
else
  echo "will not over write ./menu_color.c"
fi
if `test ! -s ./menu_files.c`
then
echo "writing ./menu_files.c"
cat > ./menu_files.c << '\Rogue\Monster\'
#include "gadgetdef.h"

static struct IntuiText filetext[] = {
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save as", NULL },
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save first", NULL },
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"save next", NULL },
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"open map", NULL },
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"close map", NULL }
};

static struct IntuiText greytext[] = {
   { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Grey model",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Average",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Lumin",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Distance",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"R only",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"G only",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"B only",   NULL }
};

static struct IntuiText packtext[] = {
    { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"compression", NULL },
    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"run length", NULL },
    { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"none", NULL }
};



#define FILEFLAGS  ( ITEMTEXT | HIGHCOMP | ITEMENABLED )

static struct MenuItem packitems[] = {
  { &packitems[1], /* next item */
    90, 0, 110 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    2, /* mutual exclude bits */
    (APTR) &packtext[1],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    90, 10, 110 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    1, /* mutual exclude bits */
    (APTR) &packtext[2],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};

#define GREYMUTUAL(pos) (077 ^ (1<<(pos)))
static struct MenuItem greyitems[] = {
  { &greyitems[1], /* next item */
    90, 0, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS|CHECKED,
    GREYMUTUAL(0), /* mutual exclude bits */
    (APTR) &greytext[1],  /* average */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &greyitems[2], /* next item */
    90, 10, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    GREYMUTUAL(1), /* mutual exclude bits */
    (APTR) &greytext[2],  /* lumin */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &greyitems[3], /* next item */
    90, 20, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    GREYMUTUAL(2), /* mutual exclude bits */
    (APTR) &greytext[3],  /* dist */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &greyitems[4], /* next item */
    90, 30, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    GREYMUTUAL(3), /* mutual exclude bits */
    (APTR) &greytext[4],  /* dist */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &greyitems[5], /* next item */
    90, 40, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    GREYMUTUAL(4), /* mutual exclude bits */
    (APTR) &greytext[5],  /* dist */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    90, 50, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    GREYMUTUAL(5), /* mutual exclude bits */
    (APTR) &greytext[6],  /* dist */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};




static struct MenuItem fileitems[] = {
  { &fileitems[1], /* next item */
    10, 0, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &filetext[0],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &fileitems[2], /* next item */
    10, 10, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &filetext[1],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &fileitems[3], /* next item */
    10, 20, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &filetext[2],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &fileitems[4], /* next item */
    10, 30, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &packtext[0],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    packitems, /* submenu item */
    0 /* next select for select dragging */
    },
  { &fileitems[5], /* next item */
    10, 40, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &filetext[3],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &fileitems[6], /* next item */
    10, 50, IMAGE_HITWIDTH , 10, /* x,y,w,h */
    COLMEMFLAGS,
    1, /* mutual exclude bits */
    (APTR) &greytext[0],     /* red */
    NULL, /* highlight image */
    'h', /* command byte ? */
    greyitems, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    10, 60, 90 , 10, /* x,y,w,h */
    FILEFLAGS,
    0, /* mutual exclude bits */
    (APTR) &filetext[4],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};

extern char *GetOutFile();
extern char *GetInFile();

MenuDoFile(item)
int item;
{
    static int filecnt = 0;
    char tempbuff[80];
    char *filename;
    bool packflag;
    int i;

    packflag = Selected( packitems[0] )?1:0;


    switch (item ) {
    case 0:
        if( (filename = GetOutFile())) {
            SetHourGlass();
            WriteIlbm(filename, &SurfWinDef, &SurfScrnDef, packflag);
        }
        break;
    case 1:
        filecnt = 0; /* deliberate fall into case 2 */
    case 2:
        if( filename = GetOutFile()) {
            SetHourGlass();
            sprintf(tempbuff, "%s.%d", filename, filecnt++ );
            WriteIlbm(tempbuff, &SurfWinDef, &SurfScrnDef, packflag);
        }
        break;
    case 4:
        if( filename = GetInFile()){
            SetHourGlass();
            ReadIlbm( filename);
        }
        break;
    case 5:
        for( i = 0; i < (sizeof(greyitems)/sizeof(greyitems[0])); i++ ) {
            if( Selected(greyitems[i])) {
                SetGreyModel(i);
            }
        }
        break;
    case 6:
        CloseImgPix();
        break;
    default:
        break;
    }

    ClearHourGlass();
}
\Rogue\Monster\
else
  echo "will not over write ./menu_files.c"
fi
if `test ! -s ./menu_image.c`
then
echo "writing ./menu_image.c"
cat > ./menu_image.c << '\Rogue\Monster\'
#include "menuexp.h"

/*
 * Menu description for selecting color mapping
 */
static struct IntuiText Specular = {
     0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Specular",  NULL
};

static struct IntuiText revtext[] = {
   { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Rev. Axis",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"X",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Y",   NULL }
};

static struct IntuiText dithertext[] = {
   { 0, 1, JAM2, 2, 0, NULL, (UBYTE *)"Dither",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"none",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"half",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"full",   NULL }
};


static struct IntuiText MiscText[] = {
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Abort Draw",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Debug",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"Flip XY Map", NULL }
};

struct MenuItem revitems[] = {
  { &revitems[1], /* next item */
    90, 0, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    2, /* mutual exclude bits */
    (APTR) &revtext[1],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    90, 10, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    1, /* mutual exclude bits */
    (APTR) &revtext[2],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};

struct MenuItem ditheritems[] = {
  { &ditheritems[1], /* next item */
    90, 0, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    2|4, /* mutual exclude bits */
    (APTR) &dithertext[1],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &ditheritems[2], /* next item */
    90, 10, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    4|1, /* mutual exclude bits */
    (APTR) &dithertext[2],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    90, 20, 80 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    1|2, /* mutual exclude bits */
    (APTR) &dithertext[3],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};


#define IMAGE_HITWIDTH 96

struct MenuItem imageitems[] = {
  { &imageitems[1], /* next item */
    1, 0, IMAGE_HITWIDTH , 10, /* x,y,w,h */
    COLMEMFLAGS,
    2, /* mutual exclude bits */
    (APTR) &revtext[0],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    revitems, /* submenu item */
    0 /* next select for select dragging */
    },
  { &imageitems[2], /* next item */
    1, 10, IMAGE_HITWIDTH , 10, /* x,y,w,h */
    COLMEMFLAGS,
    1, /* mutual exclude bits */
    (APTR) &dithertext[0],     /* red */
    NULL, /* highlight image */
    'h', /* command byte ? */
    ditheritems, /* submenu item */
    0 /* next select for select dragging */
    },
  { &imageitems[3], /* next item */
    1, 20, IMAGE_HITWIDTH , 10, /* x,y,w,h */
    COLMEMFLAGS|MENUTOGGLE,
    0, /* mutual exclude bits */
    (APTR) &Specular,
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &imageitems[4], /* next item */
    1, 30, IMAGE_HITWIDTH , 10, /* x,y,w,h */
    COLMEMFLAGS|MENUTOGGLE,
    0, /* mutual exclude bits */
    (APTR) &MiscText[2], /* Flip XY */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &imageitems[5], /* next item */
    1, 40, 100 , 10, /* x,y,w,h */
    COLMEMFLAGS| MENUTOGGLE,
    0, /* mutual exclude bits */
    (APTR) &MiscText[0], /* AbortDraw */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    1, 50, IMAGE_HITWIDTH, 10, /* x,y,w,h */
    COLMEMFLAGS|MENUTOGGLE,
    0, /* mutual exclude bits */
    (APTR) &MiscText[1],   /* debug */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};

USHORT *AbortDrawPtr = &imageitems[4].Flags;
USHORT *DebugOnPtr = &imageitems[5].Flags;


static void MenuSetImage()
{
    if( Selected(revitems[0])) {
        SetRevAxis(0); /* Xaxis */
    }
    else {
        SetRevAxis(1); /* Yaxis */
    }

    if( Selected(ditheritems[0])) {
        DitherMask = 0;
    }
    else if (Selected(ditheritems[1] ) ) {
        DitherMask = 4;
    }
    else {
        DitherMask = 7;
    }
    SpecOn = Selected( imageitems[2])?true:false;
    FlipImgPix( Selected(imageitems[3])?true:false);
}

\Rogue\Monster\
else
  echo "will not over write ./menu_image.c"
fi
if `test ! -s ./menu_scrn.c`
then
echo "writing ./menu_scrn.c"
cat > ./menu_scrn.c << '\Rogue\Monster\'
#include "scrndef.h"
/*
 * Menu description for selecting color mapping
 */

/*
 * define mutual exclusion flags
 */
#define MUBIT1 1
#define MUBIT2 2
#define MUBIT3 4
#define MUBIT4 8
#define MUBIT5 16
#define MULO 32
#define MUHI 64
#define MUHAM 128
#define MUOVER 256

static struct IntuiText scrntext[] = {
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"2 color",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"4 color ",   NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"8 color", NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"16 color",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"32 color",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"lores",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"hires",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"ham",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"overscan",  NULL },
   { 0, 1, JAM2, 20, 0, NULL, (UBYTE *)"interlace",  NULL },
};

static struct MenuItem scrnitems[] = {
  { &scrnitems[1], /* next item */
    10, 0, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS ,
    MUBIT2|MUBIT3|MUBIT4|MUBIT5, /* mutual exclude bits */
    (APTR) &scrntext[0],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[2], /* next item */
    10, 10, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    MUBIT1|MUBIT3|MUBIT4|MUBIT5, /* mutual exclude bits */
    (APTR) &scrntext[1],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[3], /* next item */
    10, 20, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    MUBIT1|MUBIT2|MUBIT4|MUBIT5, /* mutual exclude bits */
    (APTR) &scrntext[2],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[4], /* next item */
    10, 30, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    MUBIT1|MUBIT2|MUBIT3|MUBIT5, /* mutual exclude bits */
    (APTR) &scrntext[3],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[5], /* next item */
    10, 40, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    MUBIT1|MUBIT2|MUBIT3|MUBIT4|MUHI, /* mutual exclude bits */
    (APTR) &scrntext[4],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[6], /* next item */
    10, 50, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS| CHECKED,
    MUHI|MUHAM, /* mutual exclude bits */
    (APTR) &scrntext[5],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[7], /* next item */
    10, 60, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS,
    MULO|MUHAM|MUBIT5, /* mutual exclude bits */
    (APTR) &scrntext[6],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[8], /* next item */
    10, 70, 90 , 10, /* x,y,w,h */
    (COLMEMFLAGS) & ~ITEMENABLED,
    MULO|MUHI, /* mutual exclude bits */
    (APTR) &scrntext[7],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { &scrnitems[9], /* next item */
    10, 80, 90 , 10, /* x,y,w,h */
    ( COLMEMFLAGS|MENUTOGGLE)& ~ITEMENABLED ,
    0, /* mutual exclude bits */
    (APTR) &scrntext[8],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    },
  { NULL, /* next item */
    10, 90, 90 , 10, /* x,y,w,h */
    COLMEMFLAGS|MENUTOGGLE,
    0, /* mutual exclude bits */
    (APTR) &scrntext[9],  /* grey */
    NULL, /* highlight image */
    'h', /* command byte ? */
    NULL, /* submenu item */
    0 /* next select for select dragging */
    }
};



void MenuSetScrn()
{
    UBYTE colmax;

    CloseSurf();

    /*
     * overscan
     */
    SurfScrnDef.Width = 320;
    SurfScrnDef.Height = 200+ButHeight;
    SurfScrnDef.LeftEdge = SurfScrnDef.TopEdge = 0;

    if( Selected(scrnitems[8])) {
        SurfScrnDef.Width = 352;
        SurfScrnDef.Height = 220;
    }

    if( Selected(scrnitems[7])) { /* ham mode */
        SurfScrnDef.Depth = 6;
        SurfScrnDef.ViewModes = HAM;
    }
    else {
        int i;
        SurfScrnDef.Depth = 3; /* incase non of the flags are set */

        for( i = 0; i < 5; i++ ) {
            if( Selected( scrnitems[i])) {
                SurfScrnDef.Depth = i+1;
            }
        }

        if( Selected( scrnitems[5] ) ) { /* lores */
            SurfScrnDef.ViewModes = 0;
        }
        else {
            SurfScrnDef.ViewModes = HIRES;
            SurfScrnDef.Width <<= 1;
            SurfScrnDef.LeftEdge *= 2;
            if( SurfScrnDef.Depth > 4 ) {
                SurfScrnDef.Depth = 4;
            }
        }
    }

    if( Selected( scrnitems[9] )) {   /* interlace */
        SurfScrnDef.Height <<= 1;
        SurfScrnDef.Height -= ButHeight;
        SurfScrnDef.TopEdge *= 2;
        SurfScrnDef.ViewModes |= LACE;
    }


    OpenSurf();
}
\Rogue\Monster\
else
  echo "will not over write ./menu_scrn.c"
fi
echo "Finished archive 2 of 3"
# if you want to concatenate archives, remove anything after this line
exit
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
"I can't tell the difference between ABC News and Hill Street Blues" -Bono