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