home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff285.lzh / Rubik / Rubik3D.c < prev    next >
C/C++ Source or Header  |  1989-11-28  |  60KB  |  2,454 lines

  1. /*************************************************
  2. /*
  3. /* This code © 1989 by W. Roger uzun
  4. /* This code is for Lattice 5.0X
  5. /* compile using - lc -v -cf -L -O Rubik3D (for 68000 version)
  6. /* or lc -v -cf -L -m2 -O -dCPU020 Rubik3D (for 68020 version)
  7. /*
  8. /*************************************************/
  9.  
  10.  
  11. #include <proto/exec.h>
  12. #include <exec/memory.h>
  13. #ifdef CPU020
  14. #include <exec/execbase.h>
  15. #endif
  16. #include <proto/graphics.h>
  17. #include <proto/intuition.h>
  18. #include <graphics/gfxmacros.h>
  19. #include <proto/dos.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24.  
  25. #define WIDTH 640
  26. #define SIZE 200
  27. #define HEIGHT 400
  28. #define X0 90
  29. #define Y0 70
  30.  
  31. struct Point{
  32. long x,y;
  33. };
  34.  
  35. struct Rect{
  36. long x1,y1,x2,y2;
  37. };
  38.  
  39. WORD areabuffer[250];
  40.  
  41. struct ParaGram{
  42. long x1,y1,x2,y2,x3,y3,x4,y4;
  43. };
  44.  
  45. struct Point FFills[18]={
  46. {228,30},
  47. {307,30},
  48. {387,30},
  49. {187,64},
  50. {266,64},
  51. {346,64},
  52. {147,97},
  53. {226,97},
  54. {306,97},
  55. {386,98},
  56. {426,65},
  57. {467,31},
  58. {386,165},
  59. {426,132},
  60. {467,98},
  61. {386,232},
  62. {426,199},
  63. {467,165}
  64. };
  65.  
  66. struct ParaGram Areas[18]={
  67. {228,29,187,63,266,63,307,29},
  68. {307,29,266,63,346,63,387,29},
  69. {387,29,346,63,427,63,468,29},
  70. {187,63,148,96,227,96,266,63},
  71. {266,63,227,96,307,96,346,63},
  72. {346,63,307,96,388,96,427,63},
  73. {147,96,108,129,187,129,226,96},
  74. {226,96,187,129,267,129,306,96},
  75. {306,96,267,129,348,129,387,96},
  76. {387,96,348,129,348,196,387,163},
  77. {427,63,387,97,387,164,427,130},
  78. {468,29,427,64,427,130,468,96},
  79. {387,163,348,196,348,263,387,230},
  80. {427,130,387,164,387,231,427,197},
  81. {468,96,427,130,427,197,468,163},
  82. {387,231,348,263,348,329,387,297},
  83. {427,197,387,230,387,297,427,263},
  84. {468,163,427,197,427,263,468,229}
  85. };
  86.  
  87. struct Rect RFills[9]={
  88. {109,130,186,195},
  89. {188,130,266,195},
  90. {268,130,347,195},
  91. {109,197,186,262},
  92. {188,197,266,262},
  93. {268,197,347,262},
  94. {109,264,186,328},
  95. {188,264,266,328},
  96. {268,264,347,328}};
  97.  
  98. #define WINDOWSIGNAL (1L<<(wG->UserPort->mp_SigBit))
  99.  
  100.  
  101. /* data for cube */
  102.  
  103. int aborted=0;
  104. char q[50];
  105. BPTR fh;
  106. int PlotOn=1;
  107. ULONG speed=0L;
  108. ULONG *xchg1,*xchg2;
  109. ULONG upperface[9],leftface[9],frontface[9],rightface[9],backface[9];
  110. ULONG downface[9],x[9],y[9];
  111. int onepoint=0;
  112. int a,c,e,k;
  113.  
  114. UWORD chip WaitPtr[]={
  115. 0x0000,0x0000,      /* Position pad bytes */
  116. 0x0038,0x0000,0x0024,0x0000,0x0024,0x0000,0x0038,0x0000,
  117. 0x0024,0x0000,0x0024,0x0000,0x0038,0x0000,0x0000,0x0000,
  118. 0x0000,0x0000,0x0000,0x0000,0x0024,0x0000,0x0024,0x0000,
  119. 0x0024,0x0000,0x0024,0x0000,0x0024,0x0000,0x0024,0x0000,
  120. 0x0018,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  121. 0x0018,0x0000,0x0024,0x0000,0x0020,0x0000,0x0018,0x0000,
  122. 0x0004,0x0000,0x0024,0x0000,0x0018,0x0000,0x0000,0x0000,
  123. 0x0000,0x0000,0x0000,0x0000,0x0024,0x0000,0x0024,0x0000,
  124. 0x0024,0x0000,0x0018,0x0000,0x0018,0x0000,0x0018,0x0000,
  125. 0x0018,0x0000,
  126. 0x0000,0x0000,      /* Linkage pad bytes */
  127.  
  128. };
  129. /* ht = 25 */
  130.  
  131.  
  132. UWORD chip PickPtr[]={
  133. 0x0000,0x0000,      /* Position pad bytes */
  134. 0x0000,0x7090,0x0000,0x4810,0x0000,0x4892,0x0000,0x7094,
  135. 0x0000,0x4098,0x0000,0x4094,0x0000,0x4092,0x0000,0x0000,
  136.  
  137. 0x0000,0x0000,      /* Linkage pad bytes */
  138.  
  139. };
  140.  
  141. /* sizebody=           0x20 HEX     ....32 decimal */
  142. /* width=              0x10 HEX     ....16 decimal */
  143. /* Width in WORDS=     0x1 HEX      ....1 decimal */
  144. /* height=             0x8 HEX     ....8 decimal */
  145. /* number of planes=   0x2 HEX */
  146.  
  147. void Draw3D(int,int,int);
  148. void Move3D(int,int,int);
  149. void DrawCube(void);
  150. void __regargs CalcRealXY(int,int,int,long *,long *);
  151. void FillCube(void);
  152. ULONG __regargs *MatchBox(int,int);
  153. void DoALayer(void);
  154. void SolveCorners(void);
  155. void Parse(void);
  156. void DoVertical(void);
  157. void DoHorizontal(void);
  158. void Space2(void);
  159. void FinishLayers(void);
  160. void FaceRotate(void);
  161. void Plot(void);
  162. void __regargs PrintText(int,int,char *);
  163. void Init(void);
  164. void main(void);
  165. void __regargs HandleEvent(APTR);
  166. void DoQuit(void);
  167. void DoSolve(void);
  168. void DoRight(void);
  169. void ClearUpperCorners(void);
  170. void DoLeft(void);
  171. void DoUp(void);
  172. void DoDown(void);
  173. void DoAbout(void);
  174. void DoForward(void);
  175. void DoBack(void);
  176.  
  177. int done=0;
  178. struct RastPort *rpG;
  179. struct TextFont *myTextFont;
  180. struct Screen *sC;
  181. struct Window *wG;
  182.  
  183. struct TextAttr TOPAZ80 = {
  184.     (STRPTR)"topaz.font",
  185.     TOPAZ_EIGHTY,0,0
  186. };
  187.  
  188. struct NewScreen NewScreenStructure = {
  189.     0,0,    /* screen XY origin relative to View */
  190.     WIDTH,HEIGHT,    /* screen width and height */
  191.     3,    /* screen depth (number of bitplanes) */
  192.     0,1,    /* detail and block pens */
  193.     LACE|HIRES,    /* display modes for this screen */
  194.     CUSTOMSCREEN,    /* screen type */
  195.     &TOPAZ80,    /* pointer to default screen font */
  196.     "Rubiks Cube",    /* screen title */
  197.     NULL,    /* first in list of custom screen gadgets */
  198.     NULL    /* pointer to custom BitMap structure */
  199. };
  200.  
  201. #define NEWSCREENSTRUCTURE NewScreenStructure
  202.  
  203. #define GREEN 2
  204. #define ORANGE 3
  205. #define WHITE 4
  206. #define BLUE 5
  207. #define RED 6
  208. #define YELLOW 7
  209.  
  210. USHORT Palette[] = {
  211.     0x0777,    /* color #0 */
  212.     0x0000,    /* color #1 */
  213.     0x00B0,    /* color #2 green */
  214.     0x0F82,    /* color #3 orange */
  215.     0x0FFF,    /* color #4 white */
  216.     0x006F,    /* color #5 blue */
  217.     0x0F33,    /* color #6 Red */
  218.     0x0FF0    /* color #7 Yellow */
  219. #define PaletteColorCount 8
  220. };
  221.  
  222. #define PALETTE Palette
  223.  
  224. UBYTE MyMyGadget3SIBuff[20]={'2','5','5','\0'};
  225. struct StringInfo MyMyGadget3SInfo = {
  226.     MyMyGadget3SIBuff,    /* buffer where text will be edited */
  227.     NULL,    /* optional undo buffer */
  228.     0,    /* character position in buffer */
  229.     4,    /* maximum number of characters to allow */
  230.     0,    /* first displayed character buffer position */
  231.     0,0,0,0,0,    /* Intuition initialized and maintained variables */
  232.     0,    /* Rastport of gadget */
  233.     0,    /* initial value for integer gadgets */
  234.     NULL    /* alternate keymap (fill in if you set the flag) */
  235. };
  236.  
  237. SHORT MyBorderVectors1[] = {
  238.     0,0,
  239.     71,0,
  240.     71,13,
  241.     0,13,
  242.     0,0
  243. };
  244. struct Border MyBorder1 = {
  245.     -1,-1,    /* XY origin relative to container TopLeft */
  246.     3,0,JAM1,    /* front pen, back pen and drawmode */
  247.     5,    /* number of XY vectors */
  248.     MyBorderVectors1,    /* pointer to XY vectors */
  249.     NULL    /* next border in list */
  250. };
  251.  
  252. struct Gadget MyGadget3 = {
  253.     NULL,    /* next gadget */
  254.     42,65,    /* origin XY of hit box relative to window TopLeft */
  255.     70,12,    /* hit box width and height */
  256.     NULL,    /* gadget flags */
  257.     RELVERIFY,    /* activation flags */
  258.     STRGADGET,    /* gadget type flags */
  259.     (APTR)&MyBorder1,    /* gadget border or image to be rendered */
  260.     NULL,    /* alternate imagery for selection */
  261.     NULL,    /* first IntuiText structure */
  262.     NULL,    /* gadget mutual-exclude long word */
  263.     (APTR)&MyMyGadget3SInfo,    /* SpecialInfo structure */
  264.     NULL,    /* user-definable data */
  265.     NULL    /* pointer to user-definable data */
  266. };
  267.  
  268. UBYTE MyMyGadget2SIBuff[20];
  269. struct StringInfo MyMyGadget2SInfo = {
  270.     MyMyGadget2SIBuff,    /* buffer where text will be edited */
  271.     NULL,    /* optional undo buffer */
  272.     0,    /* character position in buffer */
  273.     20,    /* maximum number of characters to allow */
  274.     0,    /* first displayed character buffer position */
  275.     0,0,0,0,0,    /* Intuition initialized and maintained variables */
  276.     0,    /* Rastport of gadget */
  277.     0,    /* initial value for integer gadgets */
  278.     NULL    /* alternate keymap (fill in if you set the flag) */
  279. };
  280.  
  281. SHORT MyBorderVectors2[] = {
  282.     0,0,
  283.     147,0,
  284.     147,13,
  285.     0,13,
  286.     0,0
  287. };
  288. struct Border MyBorder2 = {
  289.     -1,-1,    /* XY origin relative to container TopLeft */
  290.     3,0,JAM1,    /* front pen, back pen and drawmode */
  291.     5,    /* number of XY vectors */
  292.     MyBorderVectors2,    /* pointer to XY vectors */
  293.     NULL    /* next border in list */
  294. };
  295.  
  296. struct Gadget MyGadget2 = {
  297.     &MyGadget3,    /* next gadget */
  298.     8,33,    /* origin XY of hit box relative to window TopLeft */
  299.     146,12,    /* hit box width and height */
  300.     NULL,    /* gadget flags */
  301.     RELVERIFY,    /* activation flags */
  302.     STRGADGET,    /* gadget type flags */
  303.     (APTR)&MyBorder2,    /* gadget border or image to be rendered */
  304.     NULL,    /* alternate imagery for selection */
  305.     NULL,    /* first IntuiText structure */
  306.     NULL,    /* gadget mutual-exclude long word */
  307.     (APTR)&MyMyGadget2SInfo,    /* SpecialInfo structure */
  308.     NULL,    /* user-definable data */
  309.     NULL    /* pointer to user-definable data */
  310. };
  311.  
  312. SHORT MyBorderVectors3[] = {
  313.     0,0,
  314.     46,0,
  315.     46,22,
  316.     0,22,
  317.     0,0
  318. };
  319. struct Border MyBorder3 = {
  320.     -1,-1,    /* XY origin relative to container TopLeft */
  321.     3,0,JAM1,    /* front pen, back pen and drawmode */
  322.     5,    /* number of XY vectors */
  323.     MyBorderVectors3,    /* pointer to XY vectors */
  324.     NULL    /* next border in list */
  325. };
  326.  
  327. struct IntuiText MyIText1 = {
  328.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  329.     14,7,    /* XY origin relative to container TopLeft */
  330.     NULL,    /* font pointer or NULL for default */
  331.     "OK",    /* pointer to text */
  332.     NULL    /* next IntuiText structure */
  333. };
  334.  
  335. struct Gadget MyGadget1 = {
  336.     &MyGadget2,    /* next gadget */
  337.     53,106,    /* origin XY of hit box relative to window TopLeft */
  338.     45,21,    /* hit box width and height */
  339.     NULL,    /* gadget flags */
  340.     RELVERIFY,    /* activation flags */
  341.     BOOLGADGET,    /* gadget type flags */
  342.     (APTR)&MyBorder3,    /* gadget border or image to be rendered */
  343.     NULL,    /* alternate imagery for selection */
  344.     &MyIText1,    /* first IntuiText structure */
  345.     NULL,    /* gadget mutual-exclude long word */
  346.     NULL,    /* SpecialInfo structure */
  347.     NULL,    /* user-definable data */
  348.     NULL    /* pointer to user-definable data */
  349. };
  350.  
  351. #define MyGadgetList1 MyGadget1
  352.  
  353. struct IntuiText MyIText3 = {
  354.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  355.     56,54,    /* XY origin relative to container TopLeft */
  356.     NULL,    /* font pointer or NULL for default */
  357.     "Speed",    /* pointer to text */
  358.     NULL    /* next IntuiText structure */
  359. };
  360.  
  361. struct IntuiText MyIText2 = {
  362.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  363.     41,17,    /* XY origin relative to container TopLeft */
  364.     NULL,    /* font pointer or NULL for default */
  365.     "File Name",    /* pointer to text */
  366.     &MyIText3    /* next IntuiText structure */
  367. };
  368.  
  369. #define MyIntuiTextList1 MyIText2
  370.  
  371. struct NewWindow MyNewWindowStructure1 = {
  372.     80,30,    /* window XY origin relative to TopLeft of screen */
  373.     160,135,    /* window width and height */
  374.     0,1,    /* detail and block pens */
  375.     GADGETUP,    /* IDCMP flags */
  376.     ACTIVATE+NOCAREREFRESH,    /* other window flags */
  377.     &MyGadget1,    /* first gadget in gadget list */
  378.     NULL,    /* custom CHECKMARK imagery */
  379.     "Solve The Cube!",    /* window title */
  380.     NULL,    /* custom screen pointer */
  381.     NULL,    /* custom bitmap */
  382.     5,5,    /* minimum width and height */
  383.     -1,-1,    /* maximum width and height */
  384.     CUSTOMSCREEN    /* destination screen type */
  385. };
  386.  
  387. struct IntuiText IText1 = {
  388.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  389.     0,0,    /* XY origin relative to container TopLeft */
  390.     &TOPAZ80,    /* font pointer or NULL for default */
  391.     "Quit",    /* pointer to text */
  392.     NULL    /* next IntuiText structure */
  393. };
  394.  
  395. struct MenuItem MenuItem4 = {
  396.     NULL,    /* next MenuItem structure */
  397.     0,24,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  398.     80,8,    /* hit box width and height */
  399.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  400.     0,    /* each bit mutually-excludes a same-level Item */
  401.     (APTR)&IText1,    /* Item render  (IntuiText or Image or NULL) */
  402.     NULL,    /* Select render */
  403.     'Q',    /* alternate command-key */
  404.     NULL,    /* SubItem list */
  405.     MENUNULL    /* filled in by Intuition for drag selections */
  406. };
  407.  
  408. struct IntuiText IText2 = {
  409.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  410.     0,0,    /* XY origin relative to container TopLeft */
  411.     &TOPAZ80,    /* font pointer or NULL for default */
  412.     "Solve",    /* pointer to text */
  413.     NULL    /* next IntuiText structure */
  414. };
  415.  
  416. struct MenuItem MenuItem3 = {
  417.     &MenuItem4,    /* next MenuItem structure */
  418.     0,16,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  419.     80,8,    /* hit box width and height */
  420.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  421.     0,    /* each bit mutually-excludes a same-level Item */
  422.     (APTR)&IText2,    /* Item render  (IntuiText or Image or NULL) */
  423.     NULL,    /* Select render */
  424.     'S',    /* alternate command-key */
  425.     NULL,    /* SubItem list */
  426.     MENUNULL    /* filled in by Intuition for drag selections */
  427. };
  428.  
  429. struct IntuiText IText3b = {
  430.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  431.     0,0,    /* XY origin relative to container TopLeft */
  432.     &TOPAZ80,    /* font pointer or NULL for default */
  433.     "Vert",    /* pointer to text */
  434.     NULL    /* next IntuiText structure */
  435. };
  436.  
  437. struct MenuItem SubItem8 = {
  438.     NULL, /* next SubItem structure */
  439.     65,48,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  440.     96,8,    /* hit box width and height */
  441.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  442.     0,    /* each bit mutually-excludes a same-level Item */
  443.     (APTR)&IText3b,    /* Item render  (IntuiText or Image or NULL) */
  444.     NULL,    /* Select render */
  445.     'C',    /* alternate command-key */
  446.     NULL,    /* no SubItem list for SubItems */
  447.     MENUNULL    /* filled in by Intuition for drag selections */
  448. };
  449.  
  450.  
  451. struct IntuiText IText3a = {
  452.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  453.     0,0,    /* XY origin relative to container TopLeft */
  454.     &TOPAZ80,    /* font pointer or NULL for default */
  455.     "Horiz",    /* pointer to text */
  456.     NULL    /* next IntuiText structure */
  457. };
  458.  
  459. struct MenuItem SubItem7 = {
  460.     &SubItem8, /* next SubItem structure */
  461.     65,40,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  462.     96,8,    /* hit box width and height */
  463.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  464.     0,    /* each bit mutually-excludes a same-level Item */
  465.     (APTR)&IText3a,    /* Item render  (IntuiText or Image or NULL) */
  466.     NULL,    /* Select render */
  467.     'H',    /* alternate command-key */
  468.     NULL,    /* no SubItem list for SubItems */
  469.     MENUNULL    /* filled in by Intuition for drag selections */
  470. };
  471.  
  472.  
  473.  
  474. struct IntuiText IText3 = {
  475.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  476.     0,0,    /* XY origin relative to container TopLeft */
  477.     &TOPAZ80,    /* font pointer or NULL for default */
  478.     "Back",    /* pointer to text */
  479.     NULL    /* next IntuiText structure */
  480. };
  481.  
  482. struct MenuItem SubItem6 = {
  483.     &SubItem7, /* next SubItem structure */
  484.     65,32,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  485.     96,8,    /* hit box width and height */
  486.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  487.     0,    /* each bit mutually-excludes a same-level Item */
  488.     (APTR)&IText3,    /* Item render  (IntuiText or Image or NULL) */
  489.     NULL,    /* Select render */
  490.     'B',    /* alternate command-key */
  491.     NULL,    /* no SubItem list for SubItems */
  492.     MENUNULL    /* filled in by Intuition for drag selections */
  493. };
  494.  
  495. struct IntuiText IText4 = {
  496.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  497.     0,0,    /* XY origin relative to container TopLeft */
  498.     &TOPAZ80,    /* font pointer or NULL for default */
  499.     "Forward",    /* pointer to text */
  500.     NULL    /* next IntuiText structure */
  501. };
  502.  
  503. struct MenuItem SubItem5 = {
  504.     &SubItem6,    /* next SubItem structure */
  505.     65,24,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  506.     96,8,    /* hit box width and height */
  507.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  508.     0,    /* each bit mutually-excludes a same-level Item */
  509.     (APTR)&IText4,    /* Item render  (IntuiText or Image or NULL) */
  510.     NULL,    /* Select render */
  511.     'F',    /* alternate command-key */
  512.     NULL,    /* no SubItem list for SubItems */
  513.     MENUNULL    /* filled in by Intuition for drag selections */
  514. };
  515.  
  516. struct IntuiText IText5 = {
  517.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  518.     0,0,    /* XY origin relative to container TopLeft */
  519.     &TOPAZ80,    /* font pointer or NULL for default */
  520.     "Down",    /* pointer to text */
  521.     NULL    /* next IntuiText structure */
  522. };
  523.  
  524. struct MenuItem SubItem4 = {
  525.     &SubItem5,    /* next SubItem structure */
  526.     65,16,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  527.     96,8,    /* hit box width and height */
  528.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  529.     0,    /* each bit mutually-excludes a same-level Item */
  530.     (APTR)&IText5,    /* Item render  (IntuiText or Image or NULL) */
  531.     NULL,    /* Select render */
  532.     'D',    /* alternate command-key */
  533.     NULL,    /* no SubItem list for SubItems */
  534.     MENUNULL    /* filled in by Intuition for drag selections */
  535. };
  536.  
  537. struct IntuiText IText6 = {
  538.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  539.     0,0,    /* XY origin relative to container TopLeft */
  540.     &TOPAZ80,    /* font pointer or NULL for default */
  541.     "Up",    /* pointer to text */
  542.     NULL    /* next IntuiText structure */
  543. };
  544.  
  545. struct MenuItem SubItem3 = {
  546.     &SubItem4,    /* next SubItem structure */
  547.     65,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  548.     96,8,    /* hit box width and height */
  549.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  550.     0,    /* each bit mutually-excludes a same-level Item */
  551.     (APTR)&IText6,    /* Item render  (IntuiText or Image or NULL) */
  552.     NULL,    /* Select render */
  553.     'U',    /* alternate command-key */
  554.     NULL,    /* no SubItem list for SubItems */
  555.     MENUNULL    /* filled in by Intuition for drag selections */
  556. };
  557.  
  558. struct IntuiText IText7 = {
  559.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  560.     0,0,    /* XY origin relative to container TopLeft */
  561.     &TOPAZ80,    /* font pointer or NULL for default */
  562.     "Left",    /* pointer to text */
  563.     NULL    /* next IntuiText structure */
  564. };
  565.  
  566. struct MenuItem SubItem2 = {
  567.     &SubItem3,    /* next SubItem structure */
  568.     65,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  569.     96,8,    /* hit box width and height */
  570.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  571.     0,    /* each bit mutually-excludes a same-level Item */
  572.     (APTR)&IText7,    /* Item render  (IntuiText or Image or NULL) */
  573.     NULL,    /* Select render */
  574.     'L',    /* alternate command-key */
  575.     NULL,    /* no SubItem list for SubItems */
  576.     MENUNULL    /* filled in by Intuition for drag selections */
  577. };
  578.  
  579. struct IntuiText IText8 = {
  580.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  581.     0,0,    /* XY origin relative to container TopLeft */
  582.     &TOPAZ80,    /* font pointer or NULL for default */
  583.     "Right",    /* pointer to text */
  584.     NULL    /* next IntuiText structure */
  585. };
  586.  
  587. struct MenuItem SubItem1 = {
  588.     &SubItem2,    /* next SubItem structure */
  589.     65,-8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  590.     96,8,    /* hit box width and height */
  591.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  592.     0,    /* each bit mutually-excludes a same-level Item */
  593.     (APTR)&IText8,    /* Item render  (IntuiText or Image or NULL) */
  594.     NULL,    /* Select render */
  595.     'R',    /* alternate command-key */
  596.     NULL,    /* no SubItem list for SubItems */
  597.     MENUNULL    /* filled in by Intuition for drag selections */
  598. };
  599.  
  600. struct IntuiText IText9 = {
  601.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  602.     0,0,    /* XY origin relative to container TopLeft */
  603.     &TOPAZ80,    /* font pointer or NULL for default */
  604.     "Move",    /* pointer to text */
  605.     NULL    /* next IntuiText structure */
  606. };
  607.  
  608. struct MenuItem MenuItem2 = {
  609.     &MenuItem3,    /* next MenuItem structure */
  610.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  611.     80,8,    /* hit box width and height */
  612.     ITEMTEXT+ITEMENABLED+HIGHCOMP,    /* Item flags */
  613.     0,    /* each bit mutually-excludes a same-level Item */
  614.     (APTR)&IText9,    /* Item render  (IntuiText or Image or NULL) */
  615.     NULL,    /* Select render */
  616.     NULL,    /* alternate command-key */
  617.     &SubItem1,    /* SubItem list */
  618.     MENUNULL    /* filled in by Intuition for drag selections */
  619. };
  620.  
  621. struct IntuiText IText10 = {
  622.     3,1,COMPLEMENT,    /* front and back text pens, drawmode and fill byte */
  623.     0,0,    /* XY origin relative to container TopLeft */
  624.     &TOPAZ80,    /* font pointer or NULL for default */
  625.     "About",    /* pointer to text */
  626.     NULL    /* next IntuiText structure */
  627. };
  628.  
  629. struct MenuItem MenuItem1 = {
  630.     &MenuItem2,    /* next MenuItem structure */
  631.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  632.     80,8,    /* hit box width and height */
  633.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  634.     0,    /* each bit mutually-excludes a same-level Item */
  635.     (APTR)&IText10,    /* Item render  (IntuiText or Image or NULL) */
  636.     NULL,    /* Select render */
  637.     'A',    /* alternate command-key */
  638.     NULL,    /* SubItem list */
  639.     MENUNULL    /* filled in by Intuition for drag selections */
  640. };
  641.  
  642. struct Menu Menu1 = {
  643.     NULL,    /* next Menu structure */
  644.     0,0,    /* XY origin of Menu hit box relative to screen TopLeft */
  645.     63,0,    /* Menu hit box width and height */
  646.     MENUENABLED,    /* Menu flags */
  647.     "Project",    /* text of Menu name */
  648.     &MenuItem1    /* MenuItem linked list pointer */
  649. };
  650.  
  651. #define MenuList1 Menu1
  652.  
  653. struct NewWindow NewWindowStructure1 = {
  654.     0,0,    /* window XY origin relative to TopLeft of screen */
  655.     WIDTH,HEIGHT,    /* window width and height */
  656.     0,1,    /* detail and block pens */
  657.     MOUSEBUTTONS|MENUPICK,    /* IDCMP flags */
  658.     BACKDROP+BORDERLESS+ACTIVATE+NOCAREREFRESH,    /* other window flags */
  659.     NULL,    /* first gadget in gadget list */
  660.     NULL,    /* custom CHECKMARK imagery */
  661.     "Rubiks Cube",    /* window title */
  662.     NULL,    /* custom screen pointer */
  663.     NULL,    /* custom bitmap */
  664.     320,200,    /* minimum width and height */
  665.     -1,-1,    /* maximum width and height */
  666.     CUSTOMSCREEN    /* destination screen type */
  667. };
  668.  
  669. SHORT BorderVectors1[] = {
  670.     0,0,
  671.     51,0,
  672.     51,25,
  673.     0,25,
  674.     0,0
  675. };
  676. struct Border Border1 = {
  677.     -1,-1,    /* XY origin relative to container TopLeft */
  678.     3,0,JAM1,    /* front pen, back pen and drawmode */
  679.     5,    /* number of XY vectors */
  680.     BorderVectors1,    /* pointer to XY vectors */
  681.     NULL    /* next border in list */
  682. };
  683.  
  684. struct IntuiText IText11 = {
  685.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  686.     16,10,    /* XY origin relative to container TopLeft */
  687.     NULL,    /* font pointer or NULL for default */
  688.     "OK",    /* pointer to text */
  689.     NULL    /* next IntuiText structure */
  690. };
  691.  
  692. struct Gadget Gadget1 = {
  693.     NULL,    /* next gadget */
  694.     54,101,    /* origin XY of hit box relative to window TopLeft */
  695.     50,24,    /* hit box width and height */
  696.     NULL,    /* gadget flags */
  697.     RELVERIFY,    /* activation flags */
  698.     BOOLGADGET,    /* gadget type flags */
  699.     (APTR)&Border1,    /* gadget border or image to be rendered */
  700.     NULL,    /* alternate imagery for selection */
  701.     &IText11,    /* first IntuiText structure */
  702.     NULL,    /* gadget mutual-exclude long word */
  703.     NULL,    /* SpecialInfo structure */
  704.     NULL,    /* user-definable data */
  705.     NULL    /* pointer to user-definable data */
  706. };
  707.  
  708. #define GadgetList2 Gadget1
  709.  
  710. struct IntuiText IText14 = {
  711.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  712.     33,40,    /* XY origin relative to container TopLeft */
  713.     NULL,    /* font pointer or NULL for default */
  714.     "Version 0.0",    /* pointer to text */
  715.     NULL    /* next IntuiText structure */
  716. };
  717.  
  718. struct IntuiText IText13 = {
  719.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  720.     19,61,    /* XY origin relative to container TopLeft */
  721.     NULL,    /* font pointer or NULL for default */
  722.     "By W. Roger Uzun",    /* pointer to text */
  723.     &IText14    /* next IntuiText structure */
  724. };
  725.  
  726. struct IntuiText IText12 = {
  727.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  728.     26,15,    /* XY origin relative to container TopLeft */
  729.     NULL,    /* font pointer or NULL for default */
  730.     "Rubiks3D Solve",    /* pointer to text */
  731.     &IText13    /* next IntuiText structure */
  732. };
  733.  
  734. #define IntuiTextList2 IText12
  735.  
  736. struct NewWindow NewWindowStructure2 = {
  737.     80,30,    /* window XY origin relative to TopLeft of screen */
  738.     160,135,    /* window width and height */
  739.     0,1,    /* detail and block pens */
  740.     GADGETUP,    /* IDCMP flags */
  741.     ACTIVATE+NOCAREREFRESH,    /* other window flags */
  742.     &Gadget1,    /* first gadget in gadget list */
  743.     NULL,    /* custom CHECKMARK imagery */
  744.     "About Rubiks Solve",    /* window title */
  745.     NULL,    /* custom screen pointer */
  746.     NULL,    /* custom bitmap */
  747.     160,135,    /* minimum width and height */
  748.     -1,-1,    /* maximum width and height */
  749.     CUSTOMSCREEN    /* destination screen type */
  750. };
  751.  
  752.  
  753. void __regargs HandleEvent(object)
  754. APTR object;
  755. {
  756.   if (object == (APTR)&MenuItem1) { DoAbout(); return; }
  757.   if (object == (APTR)&SubItem1) { DoRight(); return; }
  758.   if (object == (APTR)&SubItem2) { DoLeft(); return; }
  759.   if (object == (APTR)&SubItem3) { DoUp(); return; }
  760.   if (object == (APTR)&SubItem4) { DoDown(); return; }
  761.   if (object == (APTR)&SubItem5) { DoForward(); return; }
  762.   if (object == (APTR)&SubItem6) { DoBack(); return; }
  763.   if (object == (APTR)&SubItem7) { DoHorizontal(); return; }
  764.   if (object == (APTR)&SubItem8) { DoVertical(); return; }
  765.   if (object == (APTR)&MenuItem3) { DoSolve(); return; }
  766.   if (object == (APTR)&MenuItem4) { DoQuit(); return; }
  767. }
  768. #define HANDLEEVENT HandleEvent
  769.  
  770. /* end of PowerWindows source generation */
  771.  
  772.  
  773.  
  774. ULONG __regargs *MatchBox(x,y)
  775. int x,y;
  776. {
  777.  ULONG *temp;
  778.  
  779.  if ((x >= 90)&&(x <= 109)&&(y >= 16)&&(y <= 32))
  780.   temp = &upperface[0];
  781.  else if ((x >= 111)&&(x <= 130)&&(y >= 16)&&(y <= 32))
  782.   temp = &upperface[1];
  783.  else if ((x >= 132)&&(x <= 151)&&(y >= 16)&&(y <= 32))
  784.   temp = &upperface[2];
  785.  else if ((x >= 90)&&(x <= 109)&&(y >= 34)&&(y <= 50))
  786.   temp = &upperface[3];
  787.  else if ((x >= 111)&&(x <= 130)&&(y >= 34)&&(y <= 50))
  788.   temp = &upperface[4];
  789.  else if ((x >= 132)&&(x <= 151)&&(y >= 34)&&(y <= 50))
  790.   temp = &upperface[5];
  791.  else if ((x >= 90)&&(x <= 109)&&(y >= 52)&&(y <= 68))
  792.   temp = &upperface[6];
  793.  else if ((x >= 111)&&(x <= 130)&&(y >= 52)&&(y <= 68))
  794.   temp = &upperface[7];
  795.  else if ((x >= 132)&&(x <= 151)&&(y >= 52)&&(y <= 68))
  796.   temp = &upperface[8];
  797.  else if ((x >= 20)&&(x <= 39)&&(y >= 76)&&(y <= 92))
  798.   temp = &leftface[0];
  799.  else if ((x >= 41)&&(x <= 60)&&(y >= 76)&&(y <= 92))
  800.   temp = &leftface[1];
  801.  else if ((x >= 62)&&(x <= 81)&&(y >= 76)&&(y <= 92))
  802.   temp = &leftface[2];
  803.  else if ((x >= 20)&&(x <= 39)&&(y >= 94)&&(y <= 110))
  804.   temp = &leftface[3];
  805.  else if ((x >= 41)&&(x <= 60)&&(y >= 94)&&(y <= 110))
  806.   temp = &leftface[4];
  807.  else if ((x >= 62)&&(x <= 81)&&(y >= 94)&&(y <= 110))
  808.   temp = &leftface[5];
  809.  else if ((x >= 20)&&(x <= 39)&&(y >= 112)&&(y <= 128))
  810.   temp = &leftface[6];
  811.  else if ((x >= 41)&&(x <= 60)&&(y >= 112)&&(y <= 128))
  812.   temp = &leftface[7];
  813.  else if ((x >= 62)&&(x <= 81)&&(y >= 112)&&(y <= 128))
  814.   temp = &leftface[8];
  815.  else if ((x >= 90)&&(x <= 109)&&(y >= 76)&&(y <= 92))
  816.   temp = &frontface[0];
  817.  else if ((x >= 111)&&(x <= 130)&&(y >= 76)&&(y <= 92))
  818.   temp = &frontface[1];
  819.  else if ((x >= 132)&&(x <= 151)&&(y >= 76)&&(y <= 92))
  820.   temp = &frontface[2];
  821.  else if ((x >= 90)&&(x <= 109)&&(y >= 94)&&(y <= 110))
  822.   temp = &frontface[3];
  823.  else if ((x >= 111)&&(x <= 130)&&(y >= 94)&&(y <= 110))
  824.   temp = &frontface[4];
  825.  else if ((x >= 132)&&(x <= 151)&&(y >= 94)&&(y <= 110))
  826.   temp = &frontface[5];
  827.  else if ((x >= 90)&&(x <= 109)&&(y >= 112)&&(y <= 128))
  828.   temp = &frontface[6];
  829.  else if ((x >= 111)&&(x <= 130)&&(y >= 112)&&(y <= 128))
  830.   temp = &frontface[7];
  831.  else if ((x >= 132)&&(x <= 151)&&(y >= 112)&&(y <= 128))
  832.   temp = &frontface[8];
  833.  else if ((x >= 160)&&(x <= 179)&&(y >= 76)&&(y <= 92))
  834.   temp = &rightface[0];
  835.  else if ((x >= 181)&&(x <= 200)&&(y >= 76)&&(y <= 92))
  836.   temp = &rightface[1];
  837.  else if ((x >= 202)&&(x <= 221)&&(y >= 76)&&(y <= 92))
  838.   temp = &rightface[2];
  839.  else if ((x >= 160)&&(x <= 179)&&(y >= 94)&&(y <= 110))
  840.   temp = &rightface[3];
  841.  else if ((x >= 181)&&(x <= 200)&&(y >= 94)&&(y <= 110))
  842.   temp = &rightface[4];
  843.  else if ((x >= 202)&&(x <= 221)&&(y >= 94)&&(y <= 110))
  844.   temp = &rightface[5];
  845.  else if ((x >= 160)&&(x <= 179)&&(y >= 112)&&(y <= 128))
  846.   temp = &rightface[6];
  847.  else if ((x >= 181)&&(x <= 200)&&(y >= 112)&&(y <= 128))
  848.   temp = &rightface[7];
  849.  else if ((x >= 202)&&(x <= 221)&&(y >= 112)&&(y <= 128))
  850.   temp = &rightface[8];
  851.  else if ((x >= 230)&&(x <= 249)&&(y >= 76)&&(y <= 92))
  852.   temp = &backface[0];
  853.  else if ((x >= 251)&&(x <= 270)&&(y >= 76)&&(y <= 92))
  854.   temp = &backface[1];
  855.  else if ((x >= 272)&&(x <= 291)&&(y >= 76)&&(y <= 92))
  856.   temp = &backface[2];
  857.  else if ((x >= 230)&&(x <= 249)&&(y >= 94)&&(y <= 110))
  858.   temp = &backface[3];
  859.  else if ((x >= 251)&&(x <= 270)&&(y >= 94)&&(y <= 110))
  860.   temp = &backface[4];
  861.  else if ((x >= 272)&&(x <= 291)&&(y >= 94)&&(y <= 110))
  862.   temp = &backface[5];
  863.  else if ((x >= 230)&&(x <= 249)&&(y >= 112)&&(y <= 128))
  864.   temp = &backface[6];
  865.  else if ((x >= 251)&&(x <= 270)&&(y >= 112)&&(y <= 128))
  866.   temp = &backface[7];
  867.  else if ((x >= 272)&&(x <= 291)&&(y >= 112)&&(y <= 128))
  868.   temp = &backface[8];
  869.  else if ((x >= 90)&&(x <= 109)&&(y >= 136)&&(y <= 152))
  870.   temp = &downface[0];
  871.  else if ((x >= 111)&&(x <= 130)&&(y >= 136)&&(y <= 152))
  872.   temp = &downface[1];
  873.  else if ((x >= 132)&&(x <= 151)&&(y >= 136)&&(y <= 152))
  874.   temp = &downface[2];
  875.  else if ((x >= 90)&&(x <= 109)&&(y >= 154)&&(y <= 170))
  876.   temp = &downface[3];
  877.  else if ((x >= 111)&&(x <= 130)&&(y >= 154)&&(y <= 170))
  878.   temp = &downface[4];
  879.  else if ((x >= 132)&&(x <= 151)&&(y >= 154)&&(y <= 170))
  880.   temp = &downface[5];
  881.  else if ((x >= 90)&&(x <= 109)&&(y >= 172)&&(y <= 188))
  882.   temp = &downface[6];
  883.  else if ((x >= 111)&&(x <= 130)&&(y >= 172)&&(y <= 188))
  884.   temp = &downface[7];
  885.  else if ((x >= 132)&&(x <= 151)&&(y >= 172)&&(y <= 188))
  886.   temp = &downface[8];
  887.  else
  888.   temp = 0L;
  889.  return(temp);
  890. }
  891.  
  892. void DoQuit()
  893. {
  894.  done = 1;
  895. }
  896.  
  897.  
  898. void Space2()
  899. {
  900.  SetAPen(rpG,0L);
  901.  RectFill(rpG,0L,390L,319L,399L);
  902.  Move(rpG,0L,397L);
  903.  SetAPen(rpG,1L);
  904. }
  905.  
  906. void Parse()
  907. {
  908.  int i;
  909.  int j,count;
  910.  char c;
  911.  
  912.  PlotOn = 0;
  913.  for(i=0;i<strlen(q);i++)
  914.   {
  915.    c = q[i];
  916.    count = 1;
  917.    if (q[i+1] == 39)
  918.     {
  919.      i++;
  920.      count = 3;
  921.     }
  922.    switch(c)
  923.     {
  924.      case 'r' : for(j=0;((j<count)&&(!aborted));j++)
  925.          DoRight();
  926.         break; 
  927.      case 'l' : for(j=0;((j<count)&&(!aborted));j++)
  928.          DoLeft();
  929.         break; 
  930.      case 'u' : for(j=0;((j<count)&&(!aborted));j++)
  931.          DoUp();
  932.         break; 
  933.      case 'd' : for(j=0;((j<count)&&(!aborted));j++)
  934.          DoDown();
  935.         break; 
  936.      case 'f' : for(j=0;((j<count)&&(!aborted));j++)
  937.          DoForward();
  938.         break; 
  939.      case 'b' : for(j=0;((j<count)&&(!aborted));j++)
  940.          DoBack();
  941.         break; 
  942.      case 'h' : for(j=0;((j<count)&&(!aborted));j++)
  943.          DoHorizontal();
  944.         break; 
  945.      case 'c' : for(j=0;((j<count)&&(!aborted));j++)
  946.          DoVertical();
  947.         break; 
  948.     }
  949.   if (aborted)
  950.    {
  951.     PlotOn = 1;
  952.     return;
  953.    }
  954.   }
  955.  PlotOn = 1;
  956.  Plot();
  957.  if (speed > 15L)
  958.   Delay((speed/4L));
  959. }
  960.  
  961. void ClearUpperCorners()
  962. {
  963.  char str[80];
  964.  
  965.    Space2();
  966.    strcpy(str,"No Solved Sides - clear upper corners");
  967.    Text(rpG,str,strlen(str));
  968.    strcat(str,"\n");
  969.    if (fh)
  970.     Write(fh,str,strlen(str));
  971.    for(k=0;k<4;k++)
  972.     {
  973. a1660:
  974.      if ((upperface[8] != a)&&(frontface[2] != a)&&(rightface[0] != a))
  975.       {
  976.        strcat(q,"c\n");
  977.        if (fh)
  978.         Write(fh,q,strlen(q));
  979.        goto a1820;
  980.       }
  981.      else
  982.       {/* Move out of top layer */
  983. a1720:
  984.        q[0] = '\0';
  985.        if ((frontface[8] == a)||(rightface[6] == a)||(downface[2] == a))
  986.         {
  987.          strcpy(q,"d");
  988.         }
  989.        if (q[0] != '\0')
  990.         {
  991.          if (fh)
  992.           Write(fh,q,strlen(q));
  993.          Parse();if (aborted) return;
  994.          goto a1720;
  995.         }
  996. a1790:
  997.        strcpy(q,"r'd'rd");
  998.        if (fh)
  999.         Write(fh,q,strlen(q));
  1000.        Parse();if (aborted) return;
  1001.        q[0] = '\0';
  1002.        goto a1660;
  1003.       }
  1004. a1820:
  1005.        Parse();if (aborted) return;
  1006.        q[0] = '\0';
  1007.     }
  1008. }
  1009.  
  1010.  
  1011. void SolveCorners()
  1012. {
  1013.  int temp;
  1014.  
  1015.  k = 0;
  1016. a1850:
  1017.  temp = 0;
  1018.  a = upperface[4];
  1019.  c = frontface[4];
  1020.  e = rightface[4];
  1021.  if ((downface[2] == e)&&(frontface[8] == c))
  1022.   strcpy(q,"dfd'f'");
  1023.  else if ((frontface[8] == e)&&(rightface[6] == c))
  1024.   strcpy(q,"r'drfddf'");
  1025.  else if ((rightface[6] == e)&&(downface[2] == c))
  1026.   strcpy(q,"d'r'dr");
  1027.  if (q[0] != '\0')
  1028.   k++;
  1029.  else
  1030.   {
  1031.    temp = 1;
  1032.    strcpy(q,"d'");
  1033.   }
  1034.  if (fh)
  1035.   Write(fh,q,strlen(q));
  1036.  Parse();if (aborted) return;
  1037.  if (!(temp))
  1038.   {
  1039.    strcpy(q,"c");
  1040.    if (fh)
  1041.     Write(fh,q,strlen(q));
  1042.    Parse();if (aborted) return;
  1043.    if (k == 4)
  1044.     {
  1045.      return;
  1046.     }
  1047.   }
  1048.  q[0] = '\0';
  1049.  goto a1850;
  1050. }
  1051.  
  1052. void DoALayer()
  1053. { /* 2340 stuff here */
  1054.  char str[80];
  1055.  int l;
  1056.  
  1057.  strcpy(str,"Layer unfinished, Clear edges");
  1058.  Space2();
  1059.  Text(rpG,str,strlen(str));
  1060.  strcat(str,"\n");
  1061.  if (fh)
  1062.   Write(fh,str,strlen(str));
  1063.  strcpy(str,"begin by removing centers from upper layer\n");
  1064.  if (fh)
  1065.   Write(fh,str,strlen(str));
  1066.  q[0] = '\0';
  1067.  for(l=1;l<5;l++)
  1068.   {
  1069. a2390:
  1070.    if ((upperface[4] == upperface[7])||(upperface[4] == frontface[1]))
  1071.     strcpy(q,"f'u'dcf");
  1072.    if (q[0] == '\0')
  1073.     {
  1074.      strcpy(q,"c");
  1075.     }
  1076.    else
  1077.     {
  1078.      if (fh)
  1079.       Write(fh,q,strlen(q));
  1080.      Parse();if (aborted) return;
  1081.      q[0] = '\0';
  1082.      goto a2390;
  1083.     }
  1084.    if (fh)
  1085.     Write(fh,q,strlen(q));
  1086.    Parse();if (aborted) return;
  1087.    q[0] = '\0';
  1088.   }
  1089.  strcpy(str,"\nNow replace centers from center layer\n");
  1090.  if (fh)
  1091.   Write(fh,str,strlen(str));
  1092.  strcpy(str,"Edges Cleared - Solve Edges");
  1093.  Space2();
  1094.  Text(rpG,str,strlen(str));
  1095.  strcat(str,"\n");
  1096.  if (fh)
  1097.   Write(fh,str,strlen(str));
  1098.  q[0] = '\0';
  1099.  for(l=1;l<5;l++)
  1100.   {
  1101.    if ((upperface[4] == upperface[7])&&(frontface[1] == frontface[0]))
  1102.     {
  1103.      goto a2600;
  1104.     }
  1105. a2520:
  1106.    if ((upperface[4] == leftface[5])&&(frontface[3] == frontface[0]))
  1107.     strcpy(q,"u'r'ud'f");
  1108.    if ((upperface[4] == frontface[3])&&(leftface[5] == frontface[0]))
  1109.     strcpy(q,"u'ruuddl'u'");
  1110.    if ((upperface[4] == downface[1])&&(frontface[7] == frontface[0]))
  1111.     strcpy(q,"rl'fflr'");
  1112.    if ((upperface[4] == frontface[7])&&(downface[1] == frontface[0]))
  1113.     strcpy(q,"drl'f'lr'");
  1114.    if (q[0] != '\0')
  1115.     goto a2590;
  1116.    strcpy(q,"cu'");
  1117.    if (fh)
  1118.     Write(fh,q,strlen(q));
  1119.    Parse();if (aborted) return;
  1120.    q[0] = '\0';
  1121.    goto a2520;
  1122. a2590:
  1123.    if (fh)
  1124.     Write(fh,q,strlen(q));
  1125.    Parse();if (aborted) return;
  1126. a2600:
  1127.    strcpy(q,"c");
  1128.    if (fh)
  1129.     Write(fh,q,strlen(q));
  1130.    Parse();if (aborted) return;
  1131.    q[0] = '\0';   
  1132.   } 
  1133. }
  1134.  
  1135. void FinishLayers()
  1136. {
  1137.  char str[80];
  1138.  int i,temp,l;
  1139.  
  1140.  temp = 0;
  1141.  for(i=0;i<9;i++)
  1142.   {
  1143.     if (upperface[i] != upperface[4])
  1144.      temp = 1;
  1145.   }
  1146.  if (temp)
  1147.   DoALayer(); /* this is 2340 */
  1148.  else
  1149.   {
  1150.     for(i=0;i<3;i++)
  1151.      if ((leftface[i] != leftface[0])||(rightface[i] != rightface[0])||
  1152.         (backface[i] != backface[0]))
  1153.       {
  1154.        temp = 1;
  1155.       }
  1156.     if (temp)
  1157.      DoALayer(); 
  1158.   }
  1159.  if (!temp)
  1160.   {
  1161.    strcpy(str,"Top Layer Finished - Go to Middle Layer\n");
  1162.    if (fh)
  1163.     Write(fh,str,strlen(str));
  1164.    strcpy(str,"Go To Middle Layer");
  1165.    Space2();
  1166.    Text(rpG,str,strlen(str));
  1167.   }
  1168. /* 2630 stuff goes here */
  1169. /* missing a4070 and a4080 routines! */
  1170.  Space2();
  1171.  strcpy(str,"\n");
  1172.  if (fh)
  1173.   Write(fh,str,1L);
  1174.  strcpy(str,"First Layer Complete");
  1175.  Text(rpG,str,strlen(str));
  1176.  strcat(str,"\n");
  1177.  if (fh)
  1178.   Write(fh,str,strlen(str));
  1179.  strcpy(str,"Color align cubes of middle layer with top layer\n");
  1180.  if (fh)
  1181.   Write(fh,str,strlen(str));
  1182.  q[0] = '\0';
  1183. a2660:
  1184.  if (frontface[0]  != frontface[4])
  1185.   {
  1186.    strcpy(q,"cu'");
  1187.    if (fh)
  1188.     Write(fh,q,strlen(q));
  1189.    Parse();if (aborted) return;
  1190.    q[0] = '\0';
  1191.    goto a2660;
  1192.   }
  1193.  Space2();
  1194.  strcpy(str,"\nTop and Middle Layers aligned - is middle layer finished?\n");
  1195.  if (fh)
  1196.   Write(fh,str,strlen(str));
  1197.  strcpy(str,"- is middle layer finished?");
  1198.  Text(rpG,str,strlen(str));
  1199.  for(l=3;l<6;l++)
  1200.   {
  1201.    if ((leftface[l] != leftface[4])||(frontface[l] != frontface[4])||
  1202.       (rightface[l] != rightface[4])||(backface[l] != backface[4]))
  1203.     {
  1204.      goto a2790;
  1205.     }
  1206.   }
  1207.  goto a3120;
  1208. a2790:
  1209.  strcpy(str,"Middle Layer Unfinished - clear middle layer edge cubes\n");
  1210.  if (fh)
  1211.   Write(fh,str,strlen(str));
  1212.  Space2();
  1213.  strcpy(str,"- clear middle layer edge cubes");
  1214.  Text(rpG,str,strlen(str));
  1215.  q[0] = '\0';
  1216.  for(k=1;k<5;k++)
  1217.   {
  1218. a2830:
  1219.    if ((frontface[3] == downface[4])||(leftface[5] == downface[4]))
  1220.     goto a2900;
  1221.    if ((downface[5] == downface[4])||(rightface[7] == downface[4]))
  1222.     strcpy(q,"ldl'd'f'd'f");
  1223.    else
  1224.     {
  1225.      strcpy(q,"d");
  1226.      if (fh)
  1227.       Write(fh,q,strlen(q));
  1228.      Parse();if (aborted) return;
  1229.      q[0] = '\0';
  1230.      goto a2830;
  1231.     }
  1232.    if (fh)
  1233.     Write(fh,q,strlen(q));
  1234.    Parse();if (aborted) return;
  1235.  a2900:
  1236.    q[1] = '\0';
  1237.    q[0] = 'c';
  1238.    if (fh)
  1239.     Write(fh,q,strlen(q));
  1240.    Parse();if (aborted) return;
  1241.    q[0] = '\0';
  1242.   }
  1243.  /* Middle Layer Edge Destoryed */
  1244.  Space2();
  1245.  strcpy(str,"Edge Cubes Cleared - replace them");
  1246.  Text(rpG,str,strlen(str));
  1247.  strcat(str,"\n");
  1248.  if (fh)
  1249.   Write(fh,str,strlen(str));
  1250.  for(l=1;l<5;l++)
  1251.   {
  1252.    q[0] = '\0';
  1253. a2960:
  1254.    if ((downface[5] == leftface[4])&&(rightface[7] == frontface[4]))
  1255.     strcpy(q,"ldl'd'f'd'f");
  1256.    if ((downface[5] == frontface[4])&&(rightface[7] == leftface[4]))
  1257.     strcpy(q,"ldl'd'f'd'f");
  1258.    if (q[0] == '\0')
  1259.     {
  1260.      strcpy(q,"d");
  1261.      if (fh)
  1262.       Write(fh,q,strlen(q));
  1263.      Parse();if (aborted) return;
  1264.      q[0] = '\0';
  1265.      goto a2960;
  1266.     }
  1267.    if (fh)
  1268.     Write(fh,q,strlen(q));
  1269.    Parse();if (aborted) return;
  1270.    q[0] = 'c';
  1271.    q[1] = '\0';
  1272.    if (fh)
  1273.     Write(fh,q,strlen(q));
  1274.    Parse();if (aborted) return;
  1275.    q[0] = '\0';
  1276.   }
  1277.   /* Top and Middle layers are complete */
  1278.  strcpy(str,"\nTop and Middle Layers are complete\n");
  1279.  if (fh)
  1280.   Write(fh,str,strlen(str));
  1281.  Space2();
  1282.  strcpy(str,"Color Align edge cubes");
  1283.  Text(rpG,str,strlen(str));
  1284.  strcpy(str,"edge cubes replaced - color align them\n");
  1285.  if (fh)
  1286.   Write(fh,str,strlen(str));
  1287.  for(k=1;k<5;k++)
  1288.   {
  1289.    q[0] = '\0';
  1290.    if ((leftface[5] == leftface[4])&&(frontface[3] == frontface[4]))
  1291.     strcpy(q,"c");
  1292.    else
  1293.     {
  1294.      strcpy(q,"drdu'rdu'bdu'lld'ubd'urd'uffr'd'");
  1295.      if (fh)
  1296.       Write(fh,q,strlen(q));
  1297.      Parse();if (aborted) return;
  1298.      strcpy(q,"c");
  1299.     }
  1300.    if (fh)
  1301.     Write(fh,q,strlen(q));
  1302.    Parse();if (aborted) return;
  1303.    q[0] = '\0';
  1304.   }
  1305.  /* Middle Layer finished */
  1306. a3120:
  1307.  Space2();
  1308.  strcpy(str,"- place corners in bottom layer");
  1309.  Text(rpG,str,strlen(str));
  1310.  strcpy(str,"\nMiddle Layer finished - place corners in bottom layer\n");
  1311. a3140:
  1312.  if ((downface[2] == rightface[4])&&(rightface[6] == frontface[4]))
  1313.   goto a3180;
  1314.  if ((rightface[6] == rightface[4])&&(frontface[8] == frontface[4]))
  1315.   goto a3180;
  1316.  if ((frontface[8] == rightface[4])&&(downface[2] == frontface[4]))
  1317.   goto a3180;
  1318.  q[0] = 'd';
  1319.  q[1] = '\0';
  1320.  if (fh)
  1321.   Write(fh,q,strlen(q));
  1322.  Parse();if (aborted) return;
  1323.  goto a3140;
  1324. a3180:
  1325.  if ((downface[0] == frontface[4])&&(frontface[6] == leftface[4]))
  1326.   goto a3300;
  1327.  if ((frontface[6] == frontface[4])&&(leftface[8] == leftface[4]))
  1328.   goto a3300;
  1329.  if ((leftface[8] == frontface[4])&&(downface[0] == leftface[4]))
  1330.   goto a3300;
  1331.  if ((downface[6] == leftface[4])&&(leftface[6] == backface[4]))
  1332.   goto a3340;
  1333.  if ((leftface[6] == leftface[4])&&(backface[8] == backface[4]))
  1334.   goto a3340;
  1335.  if ((backface[8] == leftface[4])&&(downface[6] == backface[4]))
  1336.   goto a3340;
  1337.  if ((downface[8] == rightface[4])&&(rightface[8] == backface[4]))
  1338.   goto a3350;
  1339.  if ((rightface[8] == rightface[4])&&(backface[6] == backface[4]))
  1340.   goto a3350;
  1341.  if ((backface[6] == rightface[4])&&(downface[8] == backface[4]))
  1342.   goto a3350;
  1343.  strcpy(q,"dfd'b'df'd'b");
  1344. a3290:
  1345.  if (fh)
  1346.   Write(fh,q,strlen(q));
  1347.  Parse();if (aborted) return;
  1348.  goto a3180;
  1349. a3300:
  1350.  if ((downface[6] == leftface[4])&&(leftface[6] == backface[4]))
  1351.   goto a3360;
  1352.  if ((leftface[6] == leftface[4])&&(backface[8] == backface[4]))
  1353.   goto a3360;
  1354.  if ((backface[8] == leftface[4])&&(downface[6] == backface[4]))
  1355.   goto a3360;
  1356.  strcpy(q,"fd'b'df'd'bdd");
  1357.  goto a3290;
  1358. a3340:
  1359.  strcpy(q,"dldbd'b'l'");
  1360.  goto a3290;
  1361. a3350:
  1362.  strcpy(q,"rd'l'dr'd'ldd");
  1363.   goto a3290;
  1364. a3360:
  1365.  /* corners are in place */
  1366.   strcpy(str,"Corners in place align corner colors");
  1367.   Space2();
  1368.   Text(rpG,str,strlen(str));
  1369.   strcat(str,"\n");
  1370.   if (fh)
  1371.    Write(fh,"\n",1L);
  1372.   if (fh)
  1373.    Write(fh,str,strlen(str));
  1374. a3380:
  1375.   a = 0;
  1376.   if (downface[0] == downface[4])
  1377.    a++;
  1378.   if (downface[2] == downface[4])
  1379.    a++;
  1380.   if (downface[6] == downface[4])
  1381.    a++;
  1382.   if (downface[8] == downface[4])
  1383.    a++;
  1384.   if (a==1)
  1385.    goto a3500;
  1386.   if (a != 0)
  1387.    goto a3530;
  1388. a3450:
  1389.  if (downface[4] != backface[8])
  1390.   {
  1391.    q[0] = 'c';
  1392.    q[1] = '\0';
  1393.    if (fh)
  1394.     Write(fh,q,1L);
  1395.    Parse();if (aborted) return;
  1396.    goto a3450;
  1397.   }
  1398. a3480:
  1399.  strcpy(q,"ldl'dlddl'dd");
  1400.  if (fh)
  1401.   Write(fh,q,strlen(q));
  1402.  Parse();if (aborted) return;
  1403.  goto a3380;
  1404. a3500:
  1405.  if (downface[2] == downface[4])
  1406.   goto a3480;
  1407.  strcpy(q,"c");
  1408.  if (fh)
  1409.   Write(fh,q,1L);
  1410.  Parse();if (aborted) return;
  1411.  goto a3500;
  1412. a3530:
  1413.  if (a==4)
  1414.   goto a3610;
  1415.  if (a==2)
  1416.   goto a3570;
  1417.  if (downface[0] != downface[4])
  1418.   goto a3480;
  1419.  goto a3590;
  1420. a3570:
  1421.  if ((downface[6] == downface[4])&&(downface[8] == downface[4]))
  1422.   goto a3480;
  1423.  if ((downface[2] == downface[4])&&(downface[6] == downface[4]))
  1424.   goto a3480;
  1425. a3590:
  1426.  q[0] = 'c';
  1427.  q[1] = '\0';
  1428.  if (fh)
  1429.   Write(fh,q,1L);
  1430.  Parse();if (aborted) return;
  1431.  goto a3380;
  1432. a3610:
  1433.  strcpy(str,"- color align bottom face");
  1434.  Space2();
  1435.  Text(rpG,str,strlen(str));
  1436.  strcpy(str,"\nCorners are now aligned - color align bottom face\n");
  1437.  if (fh)
  1438.   Write(fh,str,strlen(str));
  1439.  for(k=1;k<5;k++)
  1440.   {
  1441.    if (downface[1] != downface[7])
  1442.     goto a3750;
  1443. a3650:
  1444.     if (downface[1] != downface[3])
  1445.      goto a3830;
  1446. a3660:
  1447.     q[0] = 'c';
  1448.     q[1] = '\0';
  1449.     if (fh)
  1450.      Write(fh,q,strlen(q));
  1451.     Parse();if (aborted) return;
  1452.   }
  1453.   strcpy(str,"- check edges for color alignment");
  1454.   Space2();
  1455.   Text(rpG,str,strlen(str));
  1456.   strcpy(str,"\nBottom face aligned - check edges for color alignment\n");
  1457.   if (fh)
  1458.    Write(fh,str,strlen(str));
  1459. a3680:
  1460.  if ((frontface[7] != frontface[4]))
  1461.   goto a3870;
  1462.  if (leftface[7] != leftface[4])
  1463.   goto a4030;
  1464.  if (rightface[7] != rightface[4])
  1465.   goto a4070;
  1466.  if (backface[7] != backface[4])
  1467.   goto a4080;
  1468.  strcpy(str,"\n- - Edges OK!\n");
  1469.  if (fh)
  1470.   Write(fh,str,strlen(str));
  1471.  strcpy(str,"Solution to Rubiks Cube completed\n");
  1472.  if (fh)
  1473.   Write(fh,str,strlen(str));
  1474.  Space2();
  1475.  strcpy(str,"Cube Solved!");
  1476.  Text(rpG,str,strlen(str));
  1477.  return;
  1478. a3750:
  1479.  if ((downface[1] != downface[4])&&(downface[7] != downface[4]))
  1480.   goto a3770;
  1481.  goto a3650;
  1482. a3770:
  1483.  q[0] = 'c';
  1484.  q[1] = '\0';
  1485.  if (fh)
  1486.   Write(fh,q,1L);
  1487.  Parse();if (aborted) return;
  1488.  strcpy(q,"hdu'rdu'bdu'lld'ubd'urd'uffh'");
  1489.  if (fh)
  1490.   Write(fh,q,strlen(q));
  1491.  Parse();if (aborted) return;
  1492.  strcpy(q,"c'");
  1493.  if (fh)
  1494.   Write(fh,q,2L);
  1495.  Parse();if (aborted) return;
  1496.  goto a3650;
  1497. a3830:
  1498.  if ((downface[1] != downface[4])&&(downface[3] != downface[4]))
  1499.   goto a3850;
  1500.  goto a3660;
  1501. a3850:
  1502.  strcpy(q,"f'r'hdu'rdu'bdu'lld'ubd'urd'uffh'rf");
  1503.  if (fh)
  1504.   Write(fh,q,strlen(q));
  1505.  Parse();if (aborted) return;
  1506.  goto a3660;
  1507. a3870:
  1508.  if (leftface[7] == leftface[4])
  1509.   goto a3920;
  1510.  if (rightface[7] == rightface[4])
  1511.   goto a3930;
  1512.  if (backface[7] == backface[4])
  1513.   goto a3970;
  1514.  q[0] = 'c';
  1515.  q[1] = '\0';
  1516.  if (fh)
  1517.   Write(fh,q,1L);
  1518.  Parse();if (aborted) return;
  1519.  strcpy(q,"rrdbf'rrfb'drr");
  1520.  if (fh)
  1521.   Write(fh,q,strlen(q));
  1522.  Parse();if (aborted) return;
  1523.  goto a3680;
  1524. a3920:
  1525.  strcpy(q,"rrdbf'rrfb'drr");
  1526.  if (fh)
  1527.   Write(fh,q,strlen(q));
  1528.  Parse();if (aborted) return;
  1529.  goto a3680;
  1530. a3930:
  1531.  strcpy(q,"cc");
  1532.  if (fh)
  1533.   Write(fh,q,strlen(q));
  1534.  Parse();if (aborted) return;
  1535.  strcpy(q,"rrdbf'rrfb'drr");
  1536.  if (fh)
  1537.   Write(fh,q,strlen(q));
  1538.  Parse();if (aborted) return;
  1539.  strcpy(q,"cc");
  1540.  if (fh)
  1541.   Write(fh,q,strlen(q));
  1542.  Parse();if (aborted) return;
  1543.  goto a3680;
  1544. a3970:
  1545.  strcpy(q,"c'");
  1546.  if (fh)
  1547.   Write(fh,q,2L);
  1548.  Parse();if (aborted) return;
  1549.  strcpy(q,"rrdbf'rrfb'drr");
  1550.  if (fh)
  1551.   Write(fh,q,strlen(q));
  1552.  Parse();if (aborted) return;
  1553.  strcpy(q,"c");
  1554.  if (fh)
  1555.   Write(fh,q,1L);
  1556.  Parse();if (aborted) return;
  1557.  goto a3680;
  1558. a4030:
  1559.  strcpy(q,"c");
  1560.  if (fh)
  1561.   Write(fh,q,1L);
  1562.  Parse();if (aborted) return;
  1563.  strcpy(q,"rrdbf'rrfb'drr");
  1564.  if (fh)
  1565.   Write(fh,q,strlen(q));
  1566.  Parse();if (aborted) return;
  1567.  strcpy(q,"c'");
  1568.  if (fh)
  1569.   Write(fh,q,2L);
  1570.  Parse();if (aborted) return;
  1571.  goto a3680;
  1572. a4070:
  1573. a4080:
  1574.  strcpy(str,"Cannot Solve Cube");
  1575.  Space2();
  1576.  Text(rpG,str,strlen(str));
  1577.  strcpy(str,"\nCannot solve cube because of its structure!\n");
  1578.  if (fh)
  1579.   Write(fh,str,strlen(str));
  1580. }
  1581.  
  1582. void DoSolve()
  1583. {
  1584.  register int i;
  1585.  struct Window *wG3;
  1586.  struct IntuiMessage *message;
  1587.  int done2=0;
  1588.  UWORD code;
  1589.  ULONG class,s1,s2,m1,m2;
  1590.  APTR object;
  1591.  char str[80];
  1592.  
  1593.  
  1594.  aborted = 0;
  1595.  i = 255 - speed;
  1596.  sprintf(MyMyGadget3SIBuff,"%d",i);
  1597.  if (!(wG3 = OpenWindow(&MyNewWindowStructure1)))
  1598.   return;
  1599.  PrintIText(wG3->RPort,&MyIntuiTextList1,0L,0L);
  1600.  Delay(10L);
  1601.  ActivateGadget(&MyGadget2,wG3,NULL);
  1602.  while (!done2)
  1603.   {
  1604.    WaitPort(wG3->UserPort);
  1605.    while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  1606.     {
  1607.      class = message->Class;
  1608.      code = message->Code;
  1609.      object = message->IAddress;
  1610.      ReplyMsg((struct Message *)message);
  1611.      if (object == (APTR)&MyGadget1)
  1612.       done2 = 1;
  1613.      else if (object == (APTR)&MyGadget2)
  1614.       ActivateGadget(&MyGadget3,wG3,NULL);
  1615.      else if (object == (APTR)&MyGadget3)
  1616.       ActivateGadget(&MyGadget2,wG3,NULL);
  1617.     }
  1618.   }
  1619.  CloseWindow(wG3);
  1620.  speed = atol(MyMyGadget3SIBuff);
  1621.  for(done2=0;done2<strlen(MyMyGadget3SIBuff);done2++)
  1622.   {
  1623.    if ((MyMyGadget3SIBuff[done2] > '9')||(MyMyGadget3SIBuff[done2] < '0'))
  1624.     {
  1625.      speed = 255L;
  1626.     }
  1627.   }
  1628.  if (speed > 255L)
  1629.   speed = 255L;
  1630.  speed = 255L - speed; /* speed is the delay factor from 0 - 255 */
  1631.  fh = 0L;
  1632.  if (strlen(MyMyGadget2SIBuff) > 0)
  1633.   {
  1634.    if (!(fh = Open(MyMyGadget2SIBuff,MODE_NEWFILE)))
  1635.     {
  1636.      DisplayBeep(0L);
  1637.      Delay(30L);
  1638.      DisplayBeep(0L);
  1639.     }
  1640.   }
  1641.  CurrentTime(&s1,&m1);
  1642. /* solve cube goes here */
  1643.  SetAPen(rpG,1L); /* Black */
  1644.  Space2();
  1645.  strcpy(str,"check for one side solved");
  1646.  Text(rpG,str,strlen(str));
  1647.  if (fh)
  1648.   {
  1649.    strcat(str,"\n");
  1650.    Write(fh,str,strlen(str));
  1651.   }
  1652.  done2 = 1;
  1653.  for(i=0;i<9;i++)
  1654.   if (upperface[i] != upperface[4])
  1655.    done2 = 0;
  1656.  if (!done2)
  1657.   {
  1658.    done2 = 2;
  1659.    for(i=0;i<9;i++)
  1660.     if (leftface[i] != leftface[4])
  1661.      done2 = 0;
  1662.   }
  1663.  if (!done2)
  1664.   {
  1665.    done2 = 3;
  1666.    for(i=0;i<9;i++)
  1667.     if (frontface[i] != frontface[4])
  1668.      done2 = 0;
  1669.   }
  1670.  if (!done2)
  1671.   {
  1672.    done2 = 4;
  1673.    for(i=0;i<9;i++)
  1674.     if (rightface[i] != rightface[4])
  1675.      done2 = 0;
  1676.   }
  1677.  if (!done2)
  1678.   {
  1679.    done2 = 5;
  1680.    for(i=0;i<9;i++)
  1681.     if (backface[i] != backface[4])
  1682.      done2 = 0;
  1683.   }
  1684.  if (!done2)
  1685.   {
  1686.    done2 = 6;
  1687.    for(i=0;i<9;i++)
  1688.     if (downface[i] != downface[4])
  1689.      done2 = 0;
  1690.   }
  1691.  if (done2)
  1692.   {/* a side is done */
  1693.    switch(done2)
  1694.     {
  1695.      case 1 :    Space2();
  1696.         strcpy(str,"Upper Side Solved");
  1697.         Text(rpG,str,strlen(str));
  1698.         strcat(str,"\n");
  1699.         if (fh)
  1700.          Write(fh,str,strlen(str));
  1701.         break;
  1702.      case 2 :    Space2();
  1703.         strcpy(str,"Left Side Solved");
  1704.         Text(rpG,str,strlen(str));
  1705.         strcat(str,"\n");
  1706.         if (fh)
  1707.          Write(fh,str,strlen(str));
  1708.         strcpy(q,"c'h");
  1709.         if (fh)
  1710.          Write(fh,q,strlen(q));
  1711.         Parse();if (aborted) return;
  1712.         if (aborted)
  1713.          return;
  1714.         break;
  1715.      case 3 :    Space2();
  1716.         strcpy(str,"Front Side Solved");
  1717.         Text(rpG,str,strlen(str));
  1718.         strcat(str,"\n");
  1719.         if (fh)
  1720.          Write(fh,str,strlen(str));
  1721.         strcpy(q,"h");
  1722.         if (fh)
  1723.          Write(fh,q,strlen(q));
  1724.         Parse();if (aborted) return;
  1725.         break;
  1726.      case 4 :    Space2();
  1727.         strcpy(str,"Right Side Solved");
  1728.         Text(rpG,str,strlen(str));
  1729.         strcat(str,"\n");
  1730.         if (fh)
  1731.          Write(fh,str,strlen(str));
  1732.         strcpy(q,"ch");
  1733.         if (fh)
  1734.          Write(fh,q,strlen(q));
  1735.         Parse();if (aborted) return;
  1736.         break;
  1737.      case 5 :    Space2();
  1738.         strcpy(str,"Back Side Solved");
  1739.         Text(rpG,str,strlen(str));
  1740.         strcat(str,"\n");
  1741.         if (fh)
  1742.          Write(fh,str,strlen(str));
  1743.         strcpy(q,"h'");
  1744.         if (fh)
  1745.          Write(fh,q,strlen(q));
  1746.         Parse();if (aborted) return;
  1747.         break;
  1748.      case 6 :    Space2();
  1749.         strcpy(str,"Down Side Solved");
  1750.         Text(rpG,str,strlen(str));
  1751.         strcat(str,"\n");
  1752.         if (fh)
  1753.          Write(fh,str,strlen(str));
  1754.         strcpy(q,"hh");
  1755.         if (fh)
  1756.          Write(fh,q,strlen(q));
  1757.         Parse();if (aborted) return;
  1758.         break;
  1759.     }
  1760.   }
  1761.  else
  1762.   {
  1763.    q[0] = '\0';
  1764.    a = upperface[4];
  1765.    c = frontface[4];
  1766.    e = rightface[4];
  1767.    ClearUpperCorners();
  1768.    strcpy(str,"Corners are Cleared, solve Corners");
  1769.    Space2();
  1770.    Text(rpG,str,strlen(str));
  1771.    strcat(str,"\n");
  1772.    if (fh)
  1773.     Write(fh,str,strlen(str));
  1774.    SolveCorners();
  1775.    strcpy(str,"\nCorners Finished\n");
  1776.    if (fh)
  1777.     Write(fh,str,strlen(str));
  1778.    strcpy(str,"Check For Finished Layers");
  1779.    Space2();
  1780.    Text(rpG,str,strlen(str));
  1781.    strcat(str,"\n");
  1782.    if (fh)
  1783.     Write(fh,str,strlen(str));
  1784.   }
  1785.  strcpy(str,"Now finish Centers of Upper layer\n");
  1786.  if (fh)
  1787.  Write(fh,str,strlen(str));
  1788.  FinishLayers(); /* this is sub 2240 */
  1789.  CurrentTime(&s2,&m2);
  1790.  s2 -= s1;
  1791.  sprintf(str,"Cube solved in %d secs.",s2);
  1792.  Space2();
  1793.  Text(rpG,str,strlen(str));
  1794.  strcat(str,"\n");
  1795.  if (fh)
  1796.   Write(fh,str,strlen(str));
  1797.  if (fh)
  1798.   Close(fh);
  1799.  fh = 0L;
  1800. }
  1801.  
  1802.  
  1803.  
  1804. void DoHorizontal()
  1805. {
  1806.  int i;
  1807.  
  1808.  PlotOn = 0;
  1809.  DoRight();
  1810.  DoLeft();
  1811.  DoLeft();
  1812.  DoLeft();
  1813.  for(i=0;i<9;i++)
  1814.   x[i] = frontface[i];
  1815.  frontface[1] = downface[1];
  1816.  frontface[4] = downface[4];
  1817.  frontface[7] = downface[7];
  1818.  downface[1] = backface[7];
  1819.  downface[4] = backface[4];
  1820.  downface[7] = backface[1];
  1821.  backface[1] = upperface[7];
  1822.  backface[4] = upperface[4];
  1823.  backface[7] = upperface[1];
  1824.  upperface[1] = x[1];
  1825.  upperface[4] = x[4];
  1826.  upperface[7] = x[7];
  1827.  PlotOn = 1;
  1828.  Plot();
  1829. }
  1830.  
  1831. void DoVertical()
  1832. {
  1833.  int i;
  1834.  
  1835.  PlotOn = 0;
  1836.  DoUp();
  1837.  DoDown();
  1838.  DoDown();
  1839.  DoDown();
  1840.  for(i=0;i<9;i++)
  1841.   x[i] = leftface[i];
  1842.  for(i=3;i<6;i++)
  1843.   {
  1844.    leftface[i] = frontface[i];
  1845.    frontface[i] = rightface[i];
  1846.    rightface[i] = backface[i];
  1847.    backface[i] = x[i];
  1848.   }
  1849.  PlotOn = 1;
  1850.  Plot();
  1851. }
  1852.  
  1853. void DoForward()
  1854. {
  1855.  int i;
  1856.  
  1857.  for(i=0;i<9;i++)
  1858.   x[i] = frontface[i];
  1859.  FaceRotate();
  1860.  for(i=0;i<9;i++)
  1861.   frontface[i] = x[i];
  1862.  for(i=0;i<9;i++)
  1863.   x[i] = upperface[i];
  1864.  upperface[6] = leftface[8];
  1865.  upperface[7] = leftface[5];
  1866.  upperface[8] = leftface[2];
  1867.  leftface[2] = downface[0];
  1868.  leftface[5] = downface[1];
  1869.  leftface[8] = downface[2];
  1870.  downface[0] = rightface[6];
  1871.  downface[1] = rightface[3];
  1872.  downface[2] = rightface[0];
  1873.  rightface[0] = x[6];
  1874.  rightface[3] = x[7];
  1875.  rightface[6] = x[8];
  1876.  Plot();
  1877. }
  1878.  
  1879. void DoBack()
  1880. {
  1881.  int i;
  1882.  
  1883.  for(i=0;i<9;i++)
  1884.   x[i] = backface[i];
  1885.  FaceRotate();
  1886.  for(i=0;i<9;i++)
  1887.   backface[i] = x[i];
  1888.  for(i=0;i<9;i++)
  1889.   x[i] = upperface[i];
  1890.  upperface[0] = rightface[2];
  1891.  upperface[1] = rightface[5];
  1892.  upperface[2] = rightface[8];
  1893.  rightface[2] = downface[8];
  1894.  rightface[5] = downface[7];
  1895.  rightface[8] = downface[6];
  1896.  downface[6] = leftface[0];
  1897.  downface[7] = leftface[3];
  1898.  downface[8] = leftface[6];
  1899.  leftface[0] = x[2];
  1900.  leftface[3] = x[1];
  1901.  leftface[6] = x[0];
  1902.  Plot();
  1903. }
  1904.  
  1905. void DoRight()
  1906. {
  1907.  int i;
  1908.  
  1909.  for(i=0;i<9;i++)
  1910.   x[i] = rightface[i];
  1911.  FaceRotate();
  1912.  for(i=0;i<9;i++)
  1913.   rightface[i] = x[i];
  1914.  for(i=0;i<9;i++)
  1915.   x[i] = upperface[i];
  1916.  for(i=2;i<9;i+=3)
  1917.   {
  1918.    upperface[i] = frontface[i];
  1919.    frontface[i] = downface[i];
  1920.   }
  1921.  downface[2] = backface[6];
  1922.  downface[5] = backface[3];
  1923.  downface[8] = backface[0];
  1924.  backface[0] = x[8];
  1925.  backface[3] = x[5];
  1926.  backface[6] = x[2];
  1927.  Plot();
  1928. }
  1929.  
  1930. void DoLeft()
  1931. {
  1932.  int i;
  1933.  
  1934.  for(i=0;i<9;i++)
  1935.   x[i] = leftface[i];
  1936.  FaceRotate();
  1937.  for(i=0;i<9;i++)
  1938.   leftface[i] = x[i];
  1939.  for(i=0;i<9;i++)
  1940.   x[i] = upperface[i];
  1941.  upperface[0] = backface[8];
  1942.  upperface[3] = backface[5];
  1943.  upperface[6] = backface[2];
  1944.  backface[2] = downface[6];
  1945.  backface[5] = downface[3];
  1946.  backface[8] = downface[0];
  1947.  for(i=0;i<7;i+=3)
  1948.   {
  1949.    downface[i] = frontface[i];
  1950.    frontface[i] = x[i];
  1951.   }
  1952.  Plot();
  1953. }
  1954.  
  1955. void FaceRotate()
  1956. {
  1957.  int i;
  1958.  
  1959.  y[0] = x[6];
  1960.  y[1] = x[3];
  1961.  y[2] = x[0];
  1962.  y[3] = x[7];
  1963.  y[4] = x[4];
  1964.  y[5] = x[1];
  1965.  y[6] = x[8];
  1966.  y[7] = x[5];
  1967.  y[8] = x[2];
  1968.  for(i=0;i<9;i++)
  1969.   x[i] = y[i];
  1970. }
  1971.  
  1972. void DoUp()
  1973. {
  1974.  register long i;
  1975.  
  1976.  for(i=0;i<9;i++)
  1977.   x[i] = upperface[i];
  1978.  FaceRotate();
  1979.  for(i=0;i<9;i++)
  1980.   upperface[i] = x[i];
  1981.  for(i=0;i<9;i++)
  1982.   x[i] = leftface[i];
  1983.  for(i=0;i<3;i++)
  1984.   {
  1985.    leftface[i] = frontface[i];
  1986.    frontface[i] = rightface[i];
  1987.   }
  1988.  for(i=0;i<3;i++)
  1989.   {
  1990.    rightface[i] = backface[i];
  1991.    backface[i] = x[i];
  1992.   }
  1993.  Plot();
  1994. }
  1995.  
  1996. void DoDown()
  1997. {
  1998.  int i;
  1999.  for(i=0;i<9;i++)
  2000.   x[i] = downface[i];
  2001.  FaceRotate();
  2002.  for(i=0;i<9;i++)
  2003.   downface[i] = x[i];
  2004.  for(i=0;i<6;i++)
  2005.   x[i] = 0;
  2006.  x[6] = leftface[6];
  2007.  x[7] = leftface[7];
  2008.  x[8] = leftface[8];
  2009.  for(i=6;i<9;i++)
  2010.   {
  2011.    leftface[i] = backface[i];
  2012.    backface[i] = rightface[i];
  2013.   }
  2014.  for(i=6;i<9;i++)
  2015.   {
  2016.    rightface[i] = frontface[i];
  2017.    frontface[i] = x[i];
  2018.   }
  2019.  Plot();
  2020. }
  2021.  
  2022. void DoAbout()
  2023. {
  2024.  struct Window *wG3;
  2025.  struct IntuiMessage *message;
  2026.  
  2027.  if (!(wG3 = OpenWindow(&NewWindowStructure2)))
  2028.   return;
  2029.  PrintIText(wG3->RPort,&IntuiTextList2,0L,0L);
  2030.  WaitPort(wG3->UserPort);
  2031.  while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  2032.   ReplyMsg((struct Message *)message);
  2033.  CloseWindow(wG3);
  2034. }
  2035.  
  2036. void __regargs PrintText(Line,Row,str)
  2037. int Line,Row;
  2038. char *str;
  2039. {
  2040.  
  2041.  Move(rpG,(Row*7L),(Line*10L+2L+200L));
  2042.  Text(rpG,str,strlen(str));
  2043. }
  2044.  
  2045. void Plot()
  2046. {
  2047.  int i;
  2048.  UWORD code;
  2049.  ULONG class;
  2050.  char str[80];
  2051.  struct IntuiMessage *message;
  2052.  
  2053.  if ((message = (struct IntuiMessage *)GetMsg(wG->UserPort)))
  2054.   {
  2055.    class = message->Class;
  2056.    code = message->Code;
  2057.    ReplyMsg((struct Message *)message);
  2058.    if ((class == MOUSEBUTTONS)&&(code == SELECTDOWN))
  2059.     {
  2060.      aborted = 1;
  2061.      for(i=0;i<9;i++)
  2062.       {
  2063.        upperface[i] = 2;
  2064.        leftface[i] = 3;
  2065.        frontface[i] = 4;
  2066.        rightface[i] = 5;
  2067.        backface[i] = 6;
  2068.        downface[i] = 7;
  2069.       }
  2070.     strcpy(str,"\nAborted\n");
  2071.     if (fh)
  2072.      Write(fh,str,strlen(str));
  2073.     PlotOn = 1;
  2074.    }
  2075.   }
  2076.  if (!PlotOn)
  2077.   return;
  2078.  SetPointer(wG,WaitPtr,0x25L,0x10L,0L,0L);
  2079.  for(i=0;i<9;i++)
  2080.   {
  2081.    SetOPen(rpG,frontface[i]);
  2082.    SetAPen(rpG,frontface[i]);
  2083.    RectFill(rpG,RFills[i].x1,RFills[i].y1,RFills[i].x2,RFills[i].y2);
  2084.   }
  2085.  SetOPen(rpG,1L);
  2086.  for(i=0;i<9;i++)
  2087.   {
  2088.    if (ReadPixel(rpG,FFills[i].x,FFills[i].y) != upperface[i])
  2089.     {
  2090.      SetAPen(rpG,upperface[i]);
  2091.      AreaMove(rpG,Areas[i].x1,Areas[i].y1);
  2092.      AreaDraw(rpG,Areas[i].x2,Areas[i].y2);
  2093.      AreaDraw(rpG,Areas[i].x3,Areas[i].y3);
  2094.      AreaDraw(rpG,Areas[i].x4,Areas[i].y4);
  2095.      AreaEnd(rpG);
  2096.     }
  2097.   }
  2098.  for(i=9;i<18;i++)
  2099.   {
  2100.    if (ReadPixel(rpG,FFills[i].x,FFills[i].y) != rightface[(i-9)])
  2101.     {
  2102.      SetAPen(rpG,rightface[(i-9)]);
  2103.      AreaMove(rpG,Areas[i].x1,Areas[i].y1);
  2104.      AreaDraw(rpG,Areas[i].x2,Areas[i].y2);
  2105.      AreaDraw(rpG,Areas[i].x3,Areas[i].y3);
  2106.      AreaDraw(rpG,Areas[i].x4,Areas[i].y4);
  2107.      AreaEnd(rpG);
  2108.     }
  2109.   }
  2110.  SetOPen(rpG,0L);
  2111.  ClearPointer(wG);
  2112. }
  2113.  
  2114. void Init()
  2115. {
  2116.  ULONG *temp;
  2117.  unsigned char c;
  2118.  BPTR fh;
  2119.  register ULONG i;
  2120.  short done=0;
  2121.  short more;
  2122.  
  2123.  if ((fh = Open("InitCube",MODE_OLDFILE)))
  2124.   {
  2125.    i = 0;
  2126.    temp = &upperface[0];
  2127.    while(!done)
  2128.     {
  2129.      if (Read(fh,&c,1L) != 1L)
  2130.       {
  2131.        done = 1;
  2132.        for(i=0;i<9;i++)
  2133.         {
  2134.          upperface[i] = 2;
  2135.          leftface[i] = 3;
  2136.          frontface[i] = 4;
  2137.          rightface[i] = 5;
  2138.          backface[i] = 6;
  2139.          downface[i] = 7;
  2140.         }
  2141.        DisplayBeep(0L);
  2142.       }
  2143.      else
  2144.       {
  2145.        c = toupper(c);
  2146.        switch(c)
  2147.         {
  2148.          case 'G' : temp[i%9] = GREEN;
  2149.             i++;
  2150.             break;
  2151.          case 'O' : temp[i%9] = ORANGE;
  2152.             i++;
  2153.             break;
  2154.          case 'W' : temp[i%9] = WHITE;
  2155.             i++;
  2156.             break;
  2157.          case 'B' : temp[i%9] = BLUE;
  2158.             i++;
  2159.             break;
  2160.          case 'R' : temp[i%9] = RED;
  2161.             i++;
  2162.             break;
  2163.          case 'Y' : temp[i%9] = YELLOW;
  2164.             i++;
  2165.             break;
  2166.          case ';' : 
  2167.                     more = 1;
  2168.                     while(more)
  2169.                     {
  2170.                 if (Read(fh,&c,1L) != 1L)
  2171.                      {
  2172.                done = 1;
  2173.                for(i=0;i<9;i++)
  2174.                 {
  2175.                  upperface[i] = 2;
  2176.                  leftface[i] = 3;
  2177.                  frontface[i] = 4;
  2178.                  rightface[i] = 5;
  2179.                  backface[i] = 6;
  2180.                  downface[i] = 7;
  2181.                 }
  2182.                DisplayBeep(0L);
  2183.                      }
  2184.                     else
  2185.                      {
  2186.                       if (c == '\n')
  2187.                        more = 0;
  2188.                      }
  2189.                     }
  2190.                     break;
  2191.         }
  2192.        if (i==9)
  2193.         temp = &leftface[0];
  2194.        else if (i==18)
  2195.         temp = &frontface[0];
  2196.        else if (i==27)
  2197.         temp = &rightface[0];
  2198.        else if (i==36)
  2199.         temp = &backface[0];
  2200.        else if (i==45)
  2201.         temp = &downface[0];
  2202.        else if (i==54)
  2203.         done = 1;
  2204.       }
  2205.     }
  2206.    Close(fh);
  2207.   }
  2208.  else
  2209.   {
  2210.    for(i=0;i<9;i++)
  2211.     {
  2212.      upperface[i] = 2;
  2213.      leftface[i] = 3;
  2214.      frontface[i] = 4;
  2215.      rightface[i] = 5;
  2216.      backface[i] = 6;
  2217.      downface[i] = 7;
  2218.     }
  2219.   }
  2220.  DrawCube();
  2221.  Plot();
  2222. }
  2223.  
  2224.  
  2225.  
  2226. void __regargs CalcRealXY(x,y,z,realx,realy)
  2227. int x,y,z;
  2228. long *realx,*realy;
  2229. {
  2230.  x = x + X0;
  2231.  y = y + Y0;
  2232.  *realx = x+(z)/2;
  2233.  *realy = y+(z)/2;
  2234.  *realy = abs(*realy - HEIGHT + 1);
  2235.  *realx *= 6;
  2236.  *realx /= 5;
  2237. }
  2238.  
  2239. void Draw3D(x,y,z)
  2240. int x,y,z;
  2241. {
  2242.  long realx,realy;
  2243.  
  2244.  CalcRealXY(x,y,z,&realx,&realy);
  2245.  Draw(rpG,realx,realy);
  2246. }
  2247.  
  2248.  
  2249. void Move3D(x,y,z)
  2250. int x,y,z;
  2251. {
  2252.  long realx,realy;
  2253.  
  2254.  CalcRealXY(x,y,z,&realx,&realy);
  2255.  Move(rpG,realx,realy);
  2256. }
  2257.  
  2258. void DrawCube()
  2259. {
  2260.  /* Plot y + 2/3z and x + 2/3z for 3d point */
  2261.  
  2262.  SetAPen(rpG,1L);
  2263.  Move3D(0,0,0);
  2264.  Draw3D(SIZE,0,0);
  2265.  Draw3D(SIZE,SIZE,0);
  2266.  Draw3D(0,SIZE,0);
  2267.  Draw3D(0,0,0);
  2268. /* for outline of rubik */
  2269.  Move3D(0,SIZE,0);
  2270.  Draw3D(0,SIZE,SIZE);
  2271.  Draw3D(SIZE,SIZE,SIZE);
  2272.  Draw3D(SIZE,SIZE,0);
  2273.  Move3D(SIZE,SIZE,SIZE);
  2274.  Draw3D(SIZE,0,SIZE);
  2275.  Draw3D(SIZE,0,0);
  2276. /* for full outline
  2277.  Draw3D(0,0,SIZE);
  2278.  Draw3D(SIZE,0,SIZE);
  2279.  Draw3D(SIZE,0,0);
  2280.  Move3D(0,SIZE,0);
  2281.  Draw3D(0,SIZE,SIZE);
  2282.  Draw3D(SIZE,SIZE,SIZE);
  2283.  Draw3D(SIZE,SIZE,0);
  2284.  Move3D(0,SIZE,SIZE);
  2285.  Draw3D(0,0,SIZE);
  2286.  Move3D(SIZE,SIZE,SIZE);
  2287.  Draw3D(SIZE,0,SIZE);
  2288. */
  2289.  
  2290. /* Draw Lines in Cube */
  2291.  Move3D(SIZE/3,0,0);
  2292.  Draw3D(SIZE/3,SIZE,0);
  2293.  Move3D(SIZE*2/3,0,0);
  2294.  Draw3D(SIZE*2/3,SIZE,0);
  2295.  Move3D(0,SIZE/3,0);
  2296.  Draw3D(SIZE,SIZE/3,0);
  2297.  Move3D(0,SIZE*2/3,0);
  2298.  Draw3D(SIZE,SIZE*2/3,0);
  2299.  Move3D(SIZE/3,SIZE,0);
  2300.  Draw3D(SIZE/3,SIZE,SIZE);
  2301.  Move3D(SIZE*2/3,SIZE,0);
  2302.  Draw3D(SIZE*2/3,SIZE,SIZE);
  2303.  Move3D(0,SIZE,SIZE/3);
  2304.  Draw3D(SIZE,SIZE,SIZE/3);
  2305.  Move3D(0,SIZE,SIZE*2/3);
  2306.  Draw3D(SIZE,SIZE,SIZE*2/3);
  2307.  Move3D(SIZE,SIZE/3,0);
  2308.  Draw3D(SIZE,SIZE/3,SIZE);
  2309.  Move3D(SIZE,SIZE*2/3,0);
  2310.  Draw3D(SIZE,SIZE*2/3,SIZE);
  2311.  Move3D(SIZE,0,SIZE/3);
  2312.  Draw3D(SIZE,SIZE,SIZE/3);
  2313.  Move3D(SIZE,0,SIZE*2/3);
  2314.  Draw3D(SIZE,SIZE,SIZE*2/3);
  2315.  
  2316. }
  2317.  
  2318.  
  2319.  
  2320.  
  2321. void main()
  2322. {
  2323.  PLANEPTR temp_bitplane;
  2324.  struct TmpRas *temp_buffer,temp_rast;
  2325.  int Mx,My;
  2326.  UWORD code;
  2327.  ULONG class;
  2328. #ifdef ASSd
  2329.  ULONG temp;
  2330. #endif
  2331.  APTR object;
  2332.  ULONG signals;
  2333.  struct AreaInfo myAreaInfo;
  2334.  struct IntuiMessage *message;    /* the message the IDCMP sends us */
  2335.  
  2336. #ifdef CPU020
  2337.  
  2338.  struct ExecBase **execbaseptr=(struct ExecBase **)4L;
  2339.  UWORD cpuid;
  2340.  struct ExecBase *execbase;
  2341.  
  2342.  execbase = *execbaseptr;
  2343.  cpuid = execbase->AttnFlags;
  2344.  if (!(cpuid & AFF_68020))
  2345.   {
  2346.    exit(0);
  2347.   }
  2348. #endif
  2349.  
  2350.  
  2351.  
  2352.  if (!(IntuitionBase = 
  2353.     (struct IntuitionBase *)OpenLibrary("intuition.library", 33L)))
  2354.   {
  2355.    exit(0);
  2356.   }
  2357.  if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L)))
  2358.   {
  2359.    CloseLibrary((struct Library *)IntuitionBase);
  2360.    exit(0);
  2361.   }
  2362.  if (!(myTextFont = OpenFont(&TOPAZ80)))
  2363.   {
  2364.    CloseLibrary((struct Library *)GfxBase);
  2365.    CloseLibrary((struct Library *)IntuitionBase);
  2366.    exit(0);
  2367.   }
  2368.  if (!(sC = OpenScreen(&NewScreenStructure)))
  2369.   {
  2370.    CloseFont(myTextFont);
  2371.    CloseLibrary((struct Library *)GfxBase);
  2372.    CloseLibrary((struct Library *)IntuitionBase);
  2373.    exit(0);
  2374.   }
  2375.  LoadRGB4(&(sC->ViewPort),Palette,PaletteColorCount);
  2376.  MyNewWindowStructure1.Screen = NewWindowStructure2.Screen = 
  2377.   NewWindowStructure1.Screen = sC;
  2378.  if (!(wG = OpenWindow(&NewWindowStructure1)))    /* open the window */
  2379.   {
  2380.    CloseScreen(sC);
  2381.    CloseFont(myTextFont);
  2382.    CloseLibrary((struct Library *)GfxBase);
  2383.    CloseLibrary((struct Library *)IntuitionBase);
  2384.    exit(0);
  2385.    }
  2386.   rpG = wG->RPort;    /* get a rastport pointer for the window */
  2387.   temp_buffer = rpG->TmpRas;
  2388.   if (!(temp_bitplane = AllocRaster(WIDTH,HEIGHT)))
  2389.    {
  2390.     CloseScreen(sC);
  2391.     CloseFont(myTextFont);
  2392.     CloseLibrary((struct Library *)GfxBase);
  2393.     CloseLibrary((struct Library *)IntuitionBase);
  2394.     exit(0);
  2395.    }
  2396.   rpG->TmpRas = InitTmpRas(&temp_rast,temp_bitplane,RASSIZE(WIDTH,HEIGHT));
  2397.   InitArea(&myAreaInfo,areabuffer,100L);
  2398.   rpG->AreaInfo = &myAreaInfo;
  2399.   SetFont(rpG,myTextFont);
  2400.   SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  2401.   Init();
  2402.   do
  2403.    {
  2404.     signals = Wait(WINDOWSIGNAL);
  2405.     if (signals & WINDOWSIGNAL)
  2406.         while( (message = (struct IntuiMessage *)
  2407.         GetMsg(wG->UserPort) ) != NULL)
  2408.         {
  2409.             Mx = message->MouseX;
  2410.             My = message->MouseY;
  2411.             class = message->Class;
  2412.             code = message->Code;
  2413.             object = message->IAddress;  /* Gadget */
  2414.             ReplyMsg((struct Message *)message);
  2415.             if ( class == MENUPICK )    /* MenuItems */
  2416.              HandleEvent((APTR)ItemAddress(&MenuList1,code));
  2417.                         else if ((class == MOUSEBUTTONS)&&(code == SELECTDOWN))
  2418.                          {
  2419. #ifdef ASSd
  2420.               onepoint++;
  2421.               if (onepoint == 1)
  2422.                {
  2423.                 xchg1 = MatchBox(Mx,My);
  2424.                    if (xchg1)
  2425.                   SetPointer(wG,PickPtr,8L,0x10L,0L,0L);
  2426.                 else
  2427.                  onepoint = 0;
  2428.                }
  2429.                           else
  2430.                            {
  2431.                 onepoint = 0;
  2432.                 ClearPointer(wG);
  2433.                 xchg2 = MatchBox(Mx,My);
  2434.                 if (xchg2)
  2435.                  {
  2436.                   temp = *xchg1;
  2437.                   *xchg1 = *xchg2;
  2438.                   *xchg2 = temp;
  2439.                   Plot();
  2440.                  }
  2441.                            }
  2442. #endif
  2443.                          }
  2444.         }
  2445.    } while (!done);
  2446.   rpG->TmpRas = temp_buffer;
  2447.   FreeRaster(temp_bitplane,WIDTH,HEIGHT);
  2448.   CloseWindow(wG);
  2449.   CloseFont(myTextFont);
  2450.   CloseScreen(sC);
  2451.   CloseLibrary((struct Library *)GfxBase);
  2452.   CloseLibrary((struct Library *)IntuitionBase);
  2453. }
  2454.