home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 491.lha / SMan / Lib / SManLb.c < prev    next >
C/C++ Source or Header  |  1991-04-05  |  23KB  |  1,010 lines

  1. #include    "functions.h"
  2. #include    "exec/types.h"    /*Needed for SOFFSET macro*/
  3. #include    "exec/execbase.h"
  4. #include    "exec/tasks.h"
  5. #include    "exec/memory.h"
  6. #include    "exec/ports.h"
  7. #include    "clib/graphics_protos.h"
  8. #include    "graphics/view.h"
  9. #include    "graphics/gfx.h"
  10. #include    "graphics/gfxbase.h"
  11. #include    "graphics/gfxmacros.h"
  12. #include    "graphics/rastport.h"
  13. #include    "intuition/intuitionbase.h"
  14. #include    "intuition/intuition.h"
  15. #include    "intuition/preferences.h"
  16. #include    "libraries/dos.h"
  17. #include    "libraries/dosextens.h"
  18. #include    "stdio.h"
  19. #include    "exec/io.h"
  20. #include    "iff/iff.h"
  21. #include    "iff/ilbm.h"
  22.  
  23. double XWidth,XHeight,XCenter,YCenter,HWidth,HHeight,Factor,xRel,yRel,Zr,Zi,Z2;
  24. double Zr2,Zi2,Limit,FP7,Two;
  25. double LastX,LastY,LastLim,LastFactor;
  26. LONG    xtemp,ytemp,MaxCnt,CurCnt,XC,YC,LeftEdge,RightEdge,NearEdge,FarEdge;
  27. LONG    S1Height,S1Width,MltPlr;
  28. ULONG    *PlnPtr;
  29.  
  30. BPTR    FileHandle;
  31. #define    Pf_Size    0xe8
  32. #define    ScnFlg    0x1;
  33. #define    LacFlg    0x2;
  34. #define    ChdFlg    DefFlg | CHECKIT | CHECKED
  35. #define    ChkFlg    DefFlg | CHECKIT
  36.  
  37. CmpFlg    = MOUSEBUTTONS | MENUPICK;
  38. MyFlag     =    NOCAREREFRESH|REPORTMOUSE|BORDERLESS;
  39. MenFlg     =    MENUENABLED | MIDRAWN;
  40. DefFlg     =    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP;
  41.  
  42.  
  43. struct Library *DOSBase;
  44. struct GfxBase *GfxBase;
  45. struct IntuitionBase *IntuitionBase;
  46. struct ExecBase    *SysBase;
  47. struct    Gadget    *GadStuff;
  48. struct    NewScreen    ns;
  49. struct    NewWindow    nw;
  50. BYTE    CurrentXOffset;
  51. BYTE    CurrentYOffset;
  52. UBYTE    Title[] = "                          Julian Explorer";
  53. UBYTE    *WindowName;
  54. SHORT    SWidth,SHeight;
  55. USHORT    MyView,SUFlag,SysFlag,ScnSts,OvsChk,LacChk,LacMod,NLcChk,MenVal,NrmChk;
  56. struct    Screen    *IntScreen;
  57. struct    Screen    *WBScreen;
  58. struct    Window    *InfoWindow;
  59. struct    Window    *IntWindow;
  60. struct    MsgPort    *MyPort,*IntPort;
  61. struct    RastPort    *MyRasta,*WBRast,*CWRast;
  62. struct    ViewPort    VPorta,VPortb;
  63. struct    Preferences    MyNewPrefs,*CurPrefs;
  64. struct    Menu        Menu1,Menu2,Menu3,Menu4;
  65. struct    MenuItem    *MIStruct;
  66. struct    IntuiText    *ITStruct;
  67.  
  68. struct    MenuItem    MI11,MI12,MI13,MI14;
  69. struct    MenuItem    MI21,MI22,MI23,MI24;
  70. struct    MenuItem    MI31,MI32,MI33,MI34;
  71. struct    MenuItem    MI41,MI42,MI43,MI44;
  72. struct    IntuiText    IT11,IT12,IT13,IT14;
  73. struct    IntuiText    IT21,IT22,IT23,IT24;
  74. struct    IntuiText    IT31,IT32,IT33,IT34;
  75. struct    IntuiText    IT41,IT42,IT43,IT44;
  76.  
  77. struct    PLANEPTR    *PlanePtrA,*PlanePtrB;
  78. static    char    Err020[]    = "Sorry, but this Mandelbrot Generator requires both a 68881 and a 68020!";
  79. static    char    Err021[]    = "Use SManLb as a slow alternative!";
  80. static    char    Message[]     = "by David M. McKinstry";
  81. static    char    Mesag2[]    = "Copyright ";
  82. UBYTE    Mesag2b[]    = 0xa9;
  83. UBYTE    Comma[] = 0x2c;
  84. static    char    Mesag2c[]    = " 1989-91";
  85. static    char    Mesag3[]    = "System Hardware: ";
  86. static    char    Mesag4[]    = "Use the menu options on the Custom Screen to change the following parameters!";
  87. static    char    Mesag5[]    = "Click on the Close Gadget to bring the Custom Screen forward!";
  88. static    char    Mesag6[]    = "(Note:  This window won't be closed, just hidden.)";
  89. static    char    Mesag7[]    = "To return to this WorkBench Screen, select 'About' from the SManLb menu!";
  90. static    char    ScrMsg[]    = "Screen center is at ";
  91. static    char    ChpMsg[]    = "Chip Memory Free = ";
  92. static    char    ChpEnd[]    = "                ";
  93. static    char    FstMsg[]    = "Fast Memory Free = ";
  94. static    char    FstEnd[]    = "                ";
  95. static    char    WdtMsg[]    = "Screen Width =  ";
  96. static    char    WdtEnd[]    = "        ";
  97. static    char    HgtMsg[]    = "Screen Height = ";
  98. static    char    HgtEnd[]    = "        ";
  99. static    char    MagMsg[]    = "Magnification = ";
  100. static    char    MagEnd[]    = "                  ";
  101. static    char    XPos[]        = "x = ";
  102. static    char    XPsEnd[]    = "                  ";
  103. static    char    YPos[]        = "y = ";
  104. static    char    YPsEnd[]    = "                  ";
  105. static    char    CntMsg[]    = "Maximum Count = ";
  106. static    char    CntEnd[]    = "        ";
  107. static    char    HavMsg[]    = "You have at least a 68020 and 68881.  Why not use SManCP?";
  108. static    char    StrngBuffer[200];
  109. SHORT    VertPos;
  110. USHORT    CTable[] = {0,0xf00,0xff0,0x3f8,0x5ea,0xf3a,0x0de,0xf80,0x9f0,0x7df,0x69f,
  111.                     0x00f,0xf2e,0xc0e,0x60e,0x607};
  112.  
  113. SHORT    PolyTab[10];
  114. SHORT    *PolyPnt;
  115. SHORT DeltaX,DeltaY;
  116. SHORT    x1,y1,x2,y2;
  117. ULONG    IMClass;
  118.  
  119. ScanOn()
  120. {
  121.     NrmChk = ChkFlg;
  122.     OvsChk = ChdFlg;
  123.     SWidth = 704;
  124.     SHeight = 478;
  125.     S1Width = 703;
  126.     S1Height = 477;
  127.     XC = 352;
  128.     YC = 239;
  129.     NearEdge = 0;
  130.     LeftEdge = 0;
  131.     RightEdge = 704;
  132.     FarEdge = 478;
  133.     ScnSts = 1;    /* Indicate overscan on */
  134. }
  135.  
  136. ScnOff()
  137. {
  138.     NrmChk = ChdFlg;
  139.     OvsChk = ChkFlg;
  140.     SWidth = 640;
  141.     SHeight = 400;
  142.     S1Width = 639;
  143.     S1Height = 399;
  144.     XC = 320;
  145.     YC = 199;
  146.     NearEdge = 0;
  147.     LeftEdge = 0;
  148.     RightEdge = 640;
  149.     FarEdge = 400;
  150.     ScnSts = 0;    /* Change to no overscan */
  151. }
  152.  
  153. LaceOff()
  154. {
  155.     MyView = HIRES;
  156.     LacChk = ChkFlg;
  157.     NLcChk = ChdFlg;
  158.     LacMod = 0;
  159.     SHeight = SHeight/2;
  160.     S1Height = SHeight;
  161.     --S1Height;
  162.     FarEdge = FarEdge/2;
  163. }
  164.  
  165. LaceOn()
  166. {
  167.     MyView = HIRES | LACE;
  168.     LacChk = ChdFlg;
  169.     NLcChk = ChkFlg;
  170.     LacMod = 1;
  171. }
  172. ScnSet()
  173. {
  174.     if (SUFlag & 0x2)    {
  175.         LaceOn();
  176.         }
  177.     else LaceOff();
  178. }
  179.  
  180. ViewSet()
  181. {
  182.     if (SUFlag & 0x1)    {    /* See if Overscan flag set */
  183.         ScanOn();
  184.         ScnSet();
  185.         }
  186.     else {
  187.         ScnOff();
  188.         ScnSet();
  189.         }
  190. }
  191.  
  192. SetLim()
  193. {
  194.     Limit = Two*Factor;
  195.     Limit = Limit*Limit;
  196. }
  197.  
  198. InitPar()
  199. {
  200.     XWidth = SWidth;
  201.     XHeight = SHeight;
  202.     HWidth = XC;
  203.     XCenter = XC;
  204.     HHeight = YC;
  205.     YCenter = YC;
  206.     SetLim();
  207. }
  208.  
  209. HasFast()
  210. {
  211.     ViewSet();
  212.     Factor = MltPlr;
  213.     Factor = MltPlr;
  214.     InitPar();
  215. }
  216.  
  217.  
  218. void ITInit(Item,NamePtr)
  219. struct    IntuiText    *Item;
  220. UBYTE    *NamePtr;
  221. {
  222.     Item -> IText = NamePtr;
  223.     Item -> BackPen = 3;
  224.     Item -> FrontPen = 5;
  225.     Item -> DrawMode = JAM1;
  226. }
  227. MIInit(Item,NxtItem,TEdge,Cmd,ITItem,Width)
  228. struct    MenuItem    *Item,*NxtItem;
  229. APTR    ITItem;
  230. SHORT    TEdge,Width;
  231. BYTE    Cmd;
  232. {
  233.     Item -> Command = Cmd;
  234.     Item -> TopEdge = TEdge;
  235.     Item -> NextItem = NxtItem;
  236.     Item -> ItemFill = (APTR)ITItem;
  237.     Item -> Flags = (USHORT)DefFlg;
  238.     Item -> Height = 9;
  239.     Item -> Width = Width;
  240. }
  241.  
  242. void MenuInit(MenuStruct,NxtMenu,NamePtr,LEdge,MWidth)
  243. struct Menu    *MenuStruct,*NxtMenu;
  244. SHORT    LEdge,MWidth;
  245. BYTE    *NamePtr;
  246. {
  247.     MenuStruct -> NextMenu = NxtMenu;
  248.     MenuStruct -> Width = MWidth;
  249.     MenuStruct -> Height = 9;
  250.     MenuStruct -> LeftEdge = LEdge;
  251.     MenuStruct -> TopEdge = 0;
  252.     MenuStruct -> MenuName = NamePtr;
  253.     MenuStruct -> Flags = MenFlg;
  254.  
  255. }
  256.  
  257. void ScreenSet()
  258. {
  259. SHORT    MWidth,MHeight,LEdge,TEdge;
  260. UBYTE    MICommand;
  261. struct    Menu    *MenStrct;
  262. BOOL Test;
  263. ns.LeftEdge    =    0;
  264. ns.TopEdge     =   0;        /*Was 20 */
  265. ns.Width       =  SWidth;
  266. ns.Height      =  SHeight;
  267. ns.DetailPen   =   0;
  268. ns.BlockPen    =   1;
  269. ns.Depth       =   4;
  270. ns.ViewModes   =   MyView;
  271.  
  272.     IntScreen = (struct Screen *)OpenScreen( &ns );
  273.     PlanePtrA = (struct PLANEPTR *)(IntScreen -> BitMap.Planes);
  274.     MyRasta = &(IntScreen -> RastPort);
  275.     VPorta = IntScreen -> ViewPort;
  276.     LoadRGB4(&VPorta,&CTable[0],16);
  277.     if (ScnSts)    {
  278.         MyNewPrefs.ViewXOffset = 0xde;
  279.         MyNewPrefs.ViewYOffset = 0xed;
  280.         }
  281.     else    {
  282.         MyNewPrefs.ViewXOffset = CurrentXOffset;
  283.         MyNewPrefs.ViewYOffset = CurrentYOffset;
  284.         }
  285.     SetPrefs(&MyNewPrefs,Pf_Size,FALSE);
  286.  
  287.     nw.Title = NULL;
  288. nw.LeftEdge        =    0;
  289. nw.TopEdge        =    0;
  290. nw.Width        =    SWidth;
  291. nw.Height        =    SHeight;
  292. nw.DetailPen    =    5;
  293. nw.BlockPen        =    2;
  294. /*nw.IDCMPFlags    =    GADGETUP | MENUPICK;*/
  295. nw.IDCMPFlags    =    CmpFlg;
  296. nw.Type            =    CUSTOMSCREEN;
  297. nw.Flags        =    MyFlag;    ACTIVATE | SMART_REFRESH;
  298. nw.FirstGadget    =    NULL;
  299. nw.CheckMark    =    NULL;
  300. nw.Screen        =    IntScreen;
  301. nw.BitMap        =    NULL;
  302. nw.MinWidth        =    320;
  303. nw.MinHeight    =    100;
  304. nw.MaxWidth        =    SWidth;
  305. nw.MaxHeight    =    SHeight;
  306.  
  307.     IntWindow = (struct Window *)OpenWindow( &nw );
  308.  
  309. /* Get associated information about Int window */
  310. /*    GadStuff = IntWindow -> FirstGadget;*/
  311.     CWRast = IntWindow -> RPort;
  312.     SetRast(CWRast,0);
  313.     IntPort    = IntWindow -> UserPort;
  314.  
  315. /*    Template is 
  316.     MenuInit(&Menu1,&Menu2,"Strng",LEdge,MWidth);
  317.         */
  318.  
  319.     MenuInit(&Menu1,&Menu2,"SManLb",20,100);
  320.     Menu1.FirstItem = &MI11;
  321.     MIInit(&MI11,&MI12,0,0x41,&IT11,150);    
  322.     MIInit(&MI12,&MI13,9,0x52,&IT12,150);
  323.     MIInit(&MI13,&MI14,18,0x53,&IT13,150);
  324.     MIInit(&MI14,0,27,0x51,&IT14,150);    
  325.  
  326.     ITInit(&IT11,"About");
  327.     ITInit(&IT12,"Redraw(Same P)");
  328.     ITInit(&IT13,"Save");
  329.     ITInit(&IT14,"Quit");
  330.  
  331.     MenuInit(&Menu2,&Menu3,"View Mode",180,130);
  332.     Menu2.FirstItem = &MI21;
  333.     MIInit(&MI21,&MI22,0,0x4c,&IT21,150);    
  334.     MIInit(&MI22,&MI23,9,0x43,&IT22,150);
  335.     MIInit(&MI23,&MI24,18,0x4d,&IT23,150);
  336.     MIInit(&MI24,0,27,0x4e,&IT24,150);    
  337.  
  338.     ITInit(&IT21,"   Lace On");
  339.     ITInit(&IT22,"   Lace Off");
  340.     ITInit(&IT23,"   Overscan");
  341.     ITInit(&IT24,"   Normal");
  342.  
  343.     MenuInit(&Menu3,&Menu4,"Maximum Count",350,130);
  344.     Menu3.FirstItem = &MI31;
  345.     MIInit(&MI31,&MI32,0,43,&IT31,150);    
  346.     MIInit(&MI32,&MI33,9,45,&IT32,150);
  347.     MIInit(&MI33,&MI34,18,0x44,&IT33,150);
  348.     MIInit(&MI34,0,27,0x48,&IT34,150);    
  349.  
  350.     ITInit(&IT31,"Increase by 10");
  351.     ITInit(&IT32,"Decrease by 10");
  352.     ITInit(&IT33,"Double");
  353.     ITInit(&IT34,"Halve");
  354.  
  355.  
  356.     MenuInit(&Menu4,0,"Zoom",505,100);
  357.     Menu4.FirstItem = &MI41;
  358.     MIInit(&MI41,&MI42,0,0x5a,&IT41,140);    
  359.     MIInit(&MI42,0,9,0x49,&IT42,140);    
  360.  
  361.     ITInit(&IT41,"Select");
  362.     ITInit(&IT42,"Restore");
  363.  
  364.     MI21.Flags = LacChk;
  365.     MI22.Flags = NLcChk;
  366.     MI23.Flags = OvsChk;
  367.     MI24.Flags = NrmChk;
  368.     Test = SetMenuStrip(IntWindow,&Menu1);
  369.  
  370.     ActivateWindow(InfoWindow);
  371. }
  372.  
  373. void ScreensClose()
  374. {
  375.     if(InfoWindow) CloseWindow(InfoWindow);
  376.     if(IntWindow) CloseWindow(IntWindow);
  377.     if(IntScreen) CloseScreen(IntScreen);
  378. }
  379. void ScreenClose()
  380. {
  381.     if(IntWindow) ClearMenuStrip(IntWindow);
  382.     if(IntWindow) CloseWindow(IntWindow);
  383.     if(IntScreen) CloseScreen(IntScreen);
  384. }
  385.  
  386.  
  387. OpenWrite(NamPtr)
  388. char    *NamPtr;
  389. {
  390.     FileHandle = Open((UBYTE *)NamPtr,MODE_NEWFILE);
  391.     if (!FileHandle)    return(-1);
  392.     return(0);
  393. }
  394.  
  395. WriteFile(Source,FileLength)
  396. char    *Source;
  397. ULONG    FileLength;
  398. {
  399. ULONG    Count,*Destination;
  400. ULONG    ReadLength;
  401.     Write(FileHandle,(char *)Source,FileLength);
  402.     return(0);
  403. }
  404. CloseWrite()
  405. {
  406.     Close(FileHandle);
  407. }
  408.  
  409. ULONG WritePlanes(NamPtr)
  410. char    *NamPtr;
  411. {
  412. USHORT    PlnCnt,LineCount;
  413.  
  414. ULONG    Count,*Source1,*Source2,*Source3,*Source4;
  415. ULONG    FileLength,LineLength;
  416.     FileLength = 32000;
  417.     Source1 = (ULONG *)*PlnPtr++;
  418.     Source2 = (ULONG *)*PlnPtr++;
  419.     Source3 = (ULONG *)*PlnPtr++;
  420.     Source4 = (ULONG *)*PlnPtr++;
  421.     LineCount = ns.Height;
  422.     FileLength = ns.Width >> 3;
  423.     LineLength = FileLength >> 2; /* # of long words on line */
  424.     while (LineCount)    {
  425.         FileLength = Write(FileHandle,(char *)Source1,FileLength);
  426.         Source1 = Source1 + LineLength;
  427.         FileLength = Write(FileHandle,(char *)Source2,FileLength);
  428.         Source2 = Source2 + LineLength;
  429.         FileLength = Write(FileHandle,(char *)Source3,FileLength);
  430.         Source3 = Source3 + LineLength;
  431.         FileLength = Write(FileHandle,(char *)Source4,FileLength);
  432.         Source4 = Source4 + LineLength;
  433.         --LineCount;
  434.         }
  435.     return(0);
  436. }
  437.  
  438.  
  439. Save()
  440. {
  441. ULONG    *HdrSize,*HdrTop,*HdrBottom;
  442. UBYTE    *MyColors;
  443. USHORT    *CurrentColor,Red,Green,Blue;
  444. static    char    HexName[] = "Hex.iff";
  445. char    *NamPtr;
  446. ChunkHeader        *Chunk3D;
  447. BitMapHeader    *MyHeader;
  448.  
  449. typedef        struct    {
  450.     ID        ckID;
  451.     }    sChunk;
  452.  
  453. sChunk    *ChunkID;
  454. char    *HdrBuffer;
  455.  
  456. ULONG    CTSize,CTCount,FileLength,BodyLength,Depth;
  457.     HdrBuffer = AllocMem(160,MEMF_PUBLIC|MEMF_CLEAR);
  458.     Chunk3D = (ChunkHeader *) HdrBuffer;
  459.     Chunk3D -> ckID = FORM;
  460.     Chunk3D++;
  461.     ChunkID = (sChunk *) Chunk3D;
  462.     ChunkID -> ckID = ID_ILBM;
  463.     ChunkID++;
  464.     ChunkID -> ckID = ID_BMHD;
  465.     ChunkID++;
  466.     HdrSize = (ULONG *)ChunkID;
  467.     *HdrSize++ = 20;
  468.     MyHeader = (BitMapHeader *)HdrSize;
  469.     MyHeader -> w = ns.Width;
  470.     MyHeader -> h = ns.Height;
  471.     CTCount = ns.Depth;
  472.     MyHeader -> nPlanes = CTCount;
  473.     MyHeader -> xAspect = 1;
  474.     MyHeader -> yAspect = 1;
  475.     MyHeader -> pageWidth = ns.Width;
  476.     MyHeader -> pageHeight = ns.Height;
  477.     MyHeader++;
  478.     Chunk3D = (ChunkHeader *)MyHeader;
  479.     Chunk3D -> ckID = ID_CMAP;
  480.     CTSize = 1;
  481.     while (CTCount)    {
  482.         CTSize <<= 1;
  483.         --CTCount;
  484.         }
  485.     Chunk3D -> ckSize = 3*CTSize;
  486.     Chunk3D++;
  487.     MyColors = (UBYTE *)Chunk3D;
  488.     CTCount = ns.Depth;
  489.     CurrentColor = &CTable[0];
  490.     while (CTSize)    {
  491.         Red = *CurrentColor;
  492.         Red = 0xf00 & Red;
  493.         Red >>= 4;
  494.         *MyColors++ = (UBYTE)Red;
  495.         Green = *CurrentColor;
  496.         Green = 0xf0 & Green;
  497.         *MyColors++ = (UBYTE)Green;
  498.         Blue = *CurrentColor++;
  499.         Blue = 0xf & Blue;
  500.         Blue <<= 4;
  501.         *MyColors++ = (UBYTE)Blue;
  502.         --CTSize;
  503.         }
  504.     Chunk3D = (ChunkHeader *)MyColors;
  505.     Chunk3D -> ckID = ID_BODY;
  506.     CTCount = ns.Width;
  507.     CTCount >>= 3;
  508.     CTCount = CTCount*ns.Height;
  509.     CTCount = CTCount*ns.Depth;
  510.     Chunk3D -> ckSize = CTCount;
  511.     BodyLength = CTCount;
  512.     Chunk3D++;
  513.     HdrTop = (ULONG *)Chunk3D;
  514.     HdrBottom = (ULONG *)HdrBuffer;
  515.     FileLength = HdrTop - HdrBottom;
  516.     FileLength <<= 2;    /* Get # bytes */
  517.     Chunk3D = (ChunkHeader *)HdrBuffer;
  518.     CTCount = CTCount + FileLength;
  519.     Chunk3D -> ckSize = CTCount - 8;
  520.     NamPtr = &HexName[0];
  521.     OpenWrite(NamPtr);
  522.     WriteFile(HdrBuffer,FileLength);
  523.     PlnPtr = (ULONG *) PlanePtrA;
  524.     WritePlanes(NamPtr);
  525.     CloseWrite();        
  526.     if (HdrBuffer) FreeMem(HdrBuffer,160);
  527.     return(0);
  528. }
  529.  
  530. void WindowSet()
  531. {
  532.  
  533. nw.LeftEdge        =    0;
  534. nw.TopEdge        =    0;            /* Expose screen drag bar */
  535. nw.Width        =    640;
  536. nw.Height        =    200;
  537. nw.DetailPen    =    5;
  538. nw.BlockPen        =    2;
  539. nw.IDCMPFlags    =    CLOSEWINDOW;
  540. nw.Type            =    WBENCHSCREEN;
  541. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE|REPORTMOUSE;
  542. nw.FirstGadget    =    NULL;
  543. nw.CheckMark    =    NULL;
  544. nw.Screen        =    0;
  545. WindowName     = &Title[0];
  546. nw.Title        =    (UBYTE *)WindowName;
  547. nw.BitMap        =    NULL;
  548. nw.MinWidth        =    320;
  549. nw.MinHeight    =    100;
  550. nw.MaxWidth        =    SWidth+20;
  551. nw.MaxHeight    =    SHeight+20;
  552.  
  553.     InfoWindow = (struct Window *)OpenWindow( &nw );
  554.     WBRast = InfoWindow -> RPort;    
  555.     MyPort    = InfoWindow -> UserPort;
  556.     WBScreen = InfoWindow -> WScreen;
  557. }
  558. /*
  559. void ClearWindow()
  560. {
  561.     SetRast(WBRast,0);
  562.     SetWindowTitles(InfoWindow,(UBYTE *)WindowName,(UBYTE *)-1);
  563.     RefreshGadgets(GadStuff,InfoWindow,0);
  564. }*/
  565.  
  566. void ErrorDisplay()
  567. {
  568.     SetAPen(WBRast,1);
  569.     Move(WBRast,40,80);
  570.     Text(WBRast,(STRPTR)Err020,strlen(Err020));    
  571.     Move(WBRast,40,110);
  572.     Text(WBRast,(STRPTR)Err021,strlen(Err021));    
  573.     
  574. }
  575. void DescribeSystem()
  576. {
  577.     if (SysFlag == 0)    Text(WBRast,(STRPTR)" 68000",6);
  578.     else    {
  579.         if (SysFlag & AFB_68030) Text(WBRast,(STRPTR)" 68030",6);
  580.         else if (SysFlag & AFB_68020) Text(WBRast,(STRPTR)" 68020",6);
  581.         Text(WBRast,(STRPTR)Comma,1);
  582.         if (SysFlag & AFB_68882) Text(WBRast,(STRPTR)" 68882",6);
  583.         else if (SysFlag & AFB_68881) Text(WBRast,(STRPTR)" 68881",6);
  584.         }
  585. }
  586.  
  587. void WriteStuff()
  588. {
  589. ULONG    MemSize;
  590. char *TmpPtr;
  591.     SetAPen(WBRast,1);
  592.     Move(WBRast,0xd0,20);
  593.     Text(WBRast,(STRPTR)Message,strlen(Message));
  594.     SetAPen(WBRast,3);
  595.     Move(WBRast,0xd8,30);
  596.     Text(WBRast,(STRPTR)Mesag2,strlen(Mesag2));
  597.     Text(WBRast,(STRPTR)Mesag2b,1);
  598.     Text(WBRast,(STRPTR)Mesag2c,strlen(Mesag2c));
  599.     Move(WBRast,0xe0,128);
  600.     Text(WBRast,(STRPTR)ScrMsg,strlen(ScrMsg));
  601.     SetAPen(WBRast,1);
  602.     Move(WBRast,0x90,48);
  603.     Text(WBRast,(STRPTR)Mesag3,strlen(Mesag3));
  604.     DescribeSystem();
  605.     SetAPen(WBRast,2);
  606.     Move(WBRast,8,78);
  607.     Text(WBRast,(STRPTR)Mesag4,strlen(Mesag4));
  608.     Move(WBRast,0x40,152);
  609.     Text(WBRast,(STRPTR)Mesag5,strlen(Mesag5));
  610.     Move(WBRast,0x60,162);
  611.     Text(WBRast,(STRPTR)Mesag6,strlen(Mesag6));
  612.     Move(WBRast,0x18,172);
  613.     Text(WBRast,(STRPTR)Mesag7,strlen(Mesag7));
  614.     SetAPen(WBRast,1);
  615.     TmpPtr = &CntEnd[0];
  616.     --TmpPtr;
  617.     sprintf(TmpPtr,"%d",MaxCnt);
  618.     Move(WBRast,400,108);
  619.     Text(WBRast,(STRPTR)CntMsg,strlen(CntMsg));
  620.     Move(WBRast,0x28,60);
  621.     MemSize = AvailMem(MEMF_CHIP);
  622.     TmpPtr = &ChpEnd[0];
  623.     --TmpPtr;
  624.     sprintf(TmpPtr,"%d",MemSize);
  625.     Text(WBRast,(STRPTR)ChpMsg,strlen(ChpMsg));
  626.     Move(WBRast,400,60);
  627.     MemSize = AvailMem(MEMF_FAST);
  628.     TmpPtr = &FstEnd[0];
  629.     --TmpPtr;
  630.     sprintf(TmpPtr,"%d",MemSize);
  631.     Text(WBRast,(STRPTR)FstMsg,strlen(FstMsg));
  632.     Move(WBRast,0x28,94);
  633.     TmpPtr = &WdtEnd[0];
  634.     --TmpPtr;
  635.     sprintf(TmpPtr,"%d",SWidth);
  636.     Text(WBRast,(STRPTR)WdtMsg,strlen(WdtMsg));
  637.     Move(WBRast,400,94);
  638.     TmpPtr = &HgtEnd[0];
  639.     --TmpPtr;
  640.     sprintf(TmpPtr,"%d",SHeight);
  641.     Text(WBRast,(STRPTR)HgtMsg,strlen(HgtMsg));
  642.     Move(WBRast,0x28,108);
  643.     TmpPtr = &MagEnd[0];
  644.     --TmpPtr;
  645.     sprintf(TmpPtr,"%e",Factor);
  646.  
  647.     Text(WBRast,(STRPTR)MagMsg,strlen(MagMsg));
  648.     Move(WBRast,0x28,136);
  649.     TmpPtr = &XPsEnd[0];
  650.     --TmpPtr;
  651.     sprintf(TmpPtr,"%e",(HWidth-XCenter)/Factor);
  652.     Text(WBRast,(STRPTR)XPos,strlen(XPos));
  653.     Move(WBRast,400,136);
  654.     TmpPtr = &YPsEnd[0];
  655.     --TmpPtr;
  656.     sprintf(TmpPtr,"%e",(HHeight-YCenter)/Factor);
  657.     Text(WBRast,(STRPTR)YPos,strlen(YPos));
  658.     if (((SysFlag & AFB_68881)||(SysFlag & AFB_68882))&&((SysFlag & AFB_68020)||(SysFlag & AFB_68030)))    {
  659.         SetAPen(WBRast,3);
  660.         Move(WBRast,0x28,180);
  661.         Text(WBRast,(STRPTR)HavMsg,strlen(HavMsg));
  662.         SetAPen(WBRast,1);
  663.         }
  664. }
  665.  
  666.     
  667. void LibsOpen()
  668. {
  669.     if (!DOSBase)    {
  670.         DOSBase = (struct Library *)OpenLibrary((UBYTE *)"dos.library",0L);
  671.         }
  672.  
  673.     GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",0L);
  674.     IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",0L);
  675. }
  676.  
  677. void LibsClose()
  678. {
  679.     if(GfxBase)            CloseLibrary((struct Library *)GfxBase);
  680.     if(IntuitionBase)    CloseLibrary((struct Library *)IntuitionBase);
  681.     }
  682.  
  683. CheckMsg()
  684. {
  685. struct IntuiMessage *MyMsg;
  686.  
  687.     IMClass = 0;
  688.     MyMsg = (struct IntuiMessage*) GetMsg(MyPort);
  689.     if (MyMsg != NULL) {
  690.           IMClass = MyMsg -> Class;
  691.         ReplyMsg((struct Message *)MyMsg);
  692.     }
  693. }
  694.  
  695. CheckIntMsg()
  696. {
  697. struct IntuiMessage *MyMsg;
  698.     MenVal = 0;
  699.     MyMsg = (struct IntuiMessage*) GetMsg(IntPort);
  700.     if (MyMsg != NULL) {
  701.         MenVal = MyMsg -> Code;
  702.         ReplyMsg((struct Message *)MyMsg);
  703.     }
  704. }
  705.  
  706. MakeLace()
  707. {
  708.     ScreenClose();
  709.     SUFlag = SUFlag | 0x2;
  710.     ViewSet();
  711. /*    HasFast();*/
  712.     ScreenSet();
  713. }
  714.  
  715. UnLace()
  716. {
  717.     ScreenClose();
  718.     SUFlag = SUFlag & 0xfffd;
  719.     ViewSet();
  720. /*    HasFast();*/
  721.     ScreenSet();
  722. }
  723.  
  724. MakeOver()
  725. {
  726.     ScreenClose();
  727.     SUFlag = SUFlag | 0x1;
  728.     ViewSet();
  729. /*    HasFast();*/
  730.     ScreenSet();
  731. }
  732.  
  733. MakeNorm()
  734. {
  735.     ScreenClose();
  736.     SUFlag = SUFlag & 0xfffe;
  737.     ViewSet();
  738. /*    HasFast();*/
  739.     ScreenSet();
  740. }
  741.  
  742. CountChange()
  743. {
  744.     if((MenVal & 0xff) == 2)    MaxCnt = MaxCnt + 10;
  745.     if((MenVal & 0xff) == 0x22)    MaxCnt = MaxCnt - 10;
  746.     if((MenVal & 0xff) == 0x42)    MaxCnt = 2*MaxCnt;
  747.     if((MenVal & 0xff) == 0x62) MaxCnt = MaxCnt/2;
  748.     if (MaxCnt < 10)    MaxCnt = 10;
  749.     WriteStuff();
  750.     ActivateWindow(IntWindow);
  751. }
  752.  
  753. ScreenChange()
  754. {
  755. /*    HWidth = XCenter;
  756.     HHeight = YCenter;*/
  757.     if((MenVal & 0xff) == 1)    MakeLace();
  758.     if((MenVal & 0xff) == 0x21)    UnLace();
  759.     if((MenVal & 0xff) == 0x41)    MakeOver();
  760.     if((MenVal & 0xff) == 0x61) MakeNorm();
  761.     WriteStuff();
  762.     ActivateWindow(IntWindow);
  763. }
  764.  
  765. void FncFind()
  766. {
  767.     xRel = xtemp;
  768.     xRel = xRel - XCenter;
  769.     CurCnt = 0;            /* Initialize Counter */
  770.     Zr = CurCnt;
  771.     Zi = Zr;            /* Zi is 0 */
  772.     while (CurCnt < MaxCnt)    {
  773.         Zr2 = Zr*Zr;        /* Find Zr^2 */
  774.         Zi2 = Zi*Zi;        /* Find Zi^2 */
  775.         Z2 = Zr2+Zi2;        /* Find Zr^2 + Zi^2 */
  776.         if (Z2 > Limit)    {    /* is |Z| > 2*Factor */
  777.             PlotIt();
  778.             return;
  779.                 }
  780.         Zr2 = Zr2 - Zi2;    /* Find Zr^2 - Zi^2 */
  781.         Zr2 = Zr2/Factor;        /* Divide by Factor to get part of new Zr */
  782.         Zi = Two*Zi*Zr;        /* Find original Zi * Zr */
  783.         Zr = xRel + Zr2;    /* Find New Zr */
  784.         Zi = Zi/Factor;        /* Divide by Factor */
  785.         Zi = yRel + Zi;    /* Add in original Zi to get new Zi */
  786.         CurCnt++;
  787.         }
  788.     CurCnt = 0xffff;
  789.     PlotIt();
  790.     return;
  791. }
  792.  
  793. void Restore()
  794. {
  795.     Factor = LastFactor;
  796.     XCenter = LastX;
  797.     YCenter = LastY;
  798.     Limit = LastLim;
  799. }
  800.  
  801. void PolyUpDate()
  802. {
  803.     PolyPnt = &PolyTab[0];
  804.     x2 = IntWindow -> MouseX;
  805.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  806.     *PolyPnt++ = y1;
  807.     *PolyPnt++ = x2;        /* Upper-Right Corner */
  808.     *PolyPnt++ = y1;
  809.     DeltaX = x2 - x1;
  810.     DeltaY = SHeight*DeltaX/SWidth;
  811.     y2 = y1 + DeltaY;
  812.     *PolyPnt++ = x2;        /* Lower-Right Corner */
  813.     *PolyPnt++ = y2;
  814.     *PolyPnt++ = x1;        /* Lower-Left Corner */
  815.     *PolyPnt++ = y2;
  816.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  817.     *PolyPnt++ = y1;
  818.     Move(CWRast,x1,y1);
  819.     PolyPnt = &PolyTab[0];
  820.     PolyDraw(CWRast,4,PolyPnt);
  821. }
  822.  
  823. /* Clear by reversing again */
  824. void PolyClear()
  825. {
  826.     PolyPnt = &PolyTab[0];
  827.     PolyDraw(CWRast,4,PolyPnt);
  828. }
  829. /*WaitChg will wait until there is at least a difference of 10 between
  830.  the original MouseX value and the new. */
  831.  
  832. void WaitChg()
  833. {
  834.     while ((x2 - x1) < 5)    {
  835.         x2 = IntWindow -> MouseX;
  836.         Delay(1);
  837.         }
  838. }
  839.  
  840. DoZoom()
  841. {
  842. double Ratio;
  843.     x1 = 0;
  844.     y1 = 0;
  845.     x2 = 0;
  846.     y2 = 0;
  847.     while (MenVal != SELECTDOWN)    {
  848.         CheckIntMsg();
  849.         }
  850.     x1 = IntWindow -> MouseX;
  851.     y1 = IntWindow -> MouseY;
  852.  
  853. /* Now prep for complementary polygon (i.e. rectangle) */
  854.     SetDrMd(CWRast,2);
  855.     WaitChg();
  856.     PolyUpDate();
  857.     while (MenVal != SELECTUP)    {
  858.         CheckIntMsg();
  859.         PolyClear();
  860.         PolyUpDate();
  861.         Delay(1);
  862.         }
  863. /* Clear Polygon and restore drawing mode */
  864.     PolyClear();
  865.     SetDrMd(CWRast,0);
  866.     if (LacMod == 0)    {
  867.         y1 = 2*y1;    /* Double y1 if not interlace */
  868.         }
  869.     LastFactor = Factor;
  870.     LastX = XCenter;
  871.     LastY = YCenter;
  872.     LastLim = Limit;
  873.  
  874.     Ratio = XWidth/DeltaX;
  875.     Factor = Ratio*Factor;
  876.  
  877.     XCenter = XCenter - (double)x1;
  878.     XCenter = Ratio*XCenter;
  879.     YCenter = YCenter - (double)y1;
  880.     YCenter = Ratio*YCenter;
  881.     SetLim();
  882.     MenVal = 0xf803;
  883. }
  884.  
  885. void Zoom()
  886. {
  887.     if((MenVal & 0xf0) == 0x00)    DoZoom();
  888.     if((MenVal & 0xf0) == 0x20)    Restore();
  889. }
  890.  
  891. SManMen()
  892. {
  893.         if (MenVal == 0xf800)    {
  894.             WriteStuff();
  895.             WBenchToFront();
  896.             WindowToFront(InfoWindow);
  897.             ActivateWindow(InfoWindow);
  898.             }
  899.         if (MenVal == 0xf840)    Save();
  900. }
  901.  
  902. void SingleLine()
  903. {
  904.     yRel = ytemp;
  905.     if    (!LacMod) {
  906.         yRel = Two*yRel;
  907.         }
  908.     xtemp = 0;
  909.     yRel = yRel - YCenter;
  910.     while (xtemp < RightEdge)    { 
  911.         FncFind();
  912.         xtemp++;
  913.         CheckMsg();
  914.         if (IMClass == CLOSEWINDOW)    {
  915.             ScreenToFront(IntScreen);
  916.             ActivateWindow(IntWindow);
  917.             }
  918.         CheckIntMsg();
  919.         if (MenVal)    {
  920.             if ((MenVal & 0xf) == 2)    CountChange();
  921.             if (MenVal == 0xf860)    return;
  922.             if ((MenVal & 0xf) == 1) return;
  923.             if ((MenVal & 0xf) == 3) {
  924.                 Zoom();
  925.                 return;
  926.                 }
  927.             if ((MenVal & 0xf) == 0)    {
  928.                 SManMen();
  929.                 if((MenVal & 0xff) == 0x20)    return;
  930.                 }
  931.             }
  932.         }
  933. }
  934.  
  935. FullSurface()
  936. {
  937.     SetRast(CWRast,0);
  938. /*    Execute((UBYTE *)"Date",0,0);*/
  939.     ytemp = NearEdge;
  940.     while (ytemp < FarEdge)    {
  941.         SingleLine();        /*Draw next line*/
  942.         Delay(1);
  943.         if (MenVal)    {
  944.             if (MenVal == 0xf860)    return;
  945.             if ((MenVal & 0xf) == 1) return;
  946.             if ((MenVal & 0xf) == 3) return;
  947.             if ((MenVal & 0xff) == 0x20)    return;
  948.             }
  949.         ytemp++;
  950.     }
  951. /*    Execute((UBYTE *)"Date",0,0);*/
  952. }
  953.  
  954. Status()
  955. {
  956.     while (!MenVal)    {
  957.         Delay(1);
  958.         CheckMsg();
  959.         if (IMClass == CLOSEWINDOW)    {
  960.             ScreenToFront(IntScreen);
  961.             ActivateWindow(IntWindow);
  962.             MenVal = 0;
  963.             }
  964.         CheckIntMsg();
  965.         if (MenVal)    {
  966.             if (MenVal == -1) MenVal = 0;
  967.             if ((MenVal & 0xf) == 0)    {
  968.                 SManMen();
  969.                 if (MenVal == 0xf800) MenVal = 0;
  970.                 }
  971.             if ((MenVal & 0xf) == 1)    ScreenChange();
  972.             if ((MenVal & 0xf) == 2)    CountChange();
  973.             if ((MenVal & 0xf) == 3)    Zoom();
  974.             }
  975.     }
  976. }
  977. void main()
  978. {
  979.  
  980.     MltPlr = 0xa0;
  981.     MaxCnt = 31;
  982.     LibsOpen();
  983.     WindowSet();
  984.     CurPrefs = GetPrefs(&MyNewPrefs,Pf_Size);
  985.     CurrentXOffset = CurPrefs -> ViewXOffset;
  986.     CurrentYOffset = CurPrefs -> ViewYOffset;
  987.     SysFlag = SysBase -> AttnFlags;
  988.     Two = 2.000000000000;
  989.     SUFlag = SUFlag & 0xfffe;    /*Clear ScnFlg*/
  990.     SUFlag = SUFlag & 0xfffd;    /*Clear LacFlg*/
  991.     HasFast();
  992.     InitPar();
  993. ns.Type        = CUSTOMSCREEN|SCREENBEHIND;
  994.     ScreenSet();
  995. ns.Type        = CUSTOMSCREEN;
  996.     WriteStuff();
  997.     ActivateWindow(InfoWindow);
  998.     MenVal = 0xf801;
  999.     while (MenVal != 0xf860)    {
  1000.         FullSurface();
  1001.         if ((MenVal & 0xf) == 1) ScreenChange();
  1002.         Status();
  1003.         }
  1004.     MyNewPrefs.ViewXOffset = CurrentXOffset;
  1005.     MyNewPrefs.ViewYOffset = CurrentYOffset;
  1006.     SetPrefs(&MyNewPrefs,Pf_Size,FALSE);
  1007.     ScreensClose();
  1008.     LibsClose();
  1009. }
  1010.