home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / maze / blank.c next >
C/C++ Source or Header  |  1994-10-09  |  14KB  |  663 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <dos/dos.h>
  11. #include <hardware/custom.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include "/Garshnelib/Garshnelib_protos.h"
  19. #include "/Garshnelib/Garshnelib_pragmas.h"
  20.  
  21. #include "Maze.h"
  22. #include "//defs.h"
  23. #include "/main.h"
  24.  
  25. struct ModulePrefs
  26. {
  27.     LONG Mode;
  28.     LONG Depth;
  29.     LONG CellSize;
  30.     LONG Copper;
  31. };
  32.  
  33. extern struct ModulePrefs nP;
  34. extern __far struct Custom custom;
  35.  
  36. #define NORTH 0
  37. #define EAST  1
  38. #define SOUTH 2
  39. #define WEST  3
  40.  
  41. #define HasBeenVisited( Bob, x, y )\
  42. ( (Bob)->mz_Cells[(x)*(Bob)->mz_Height+(y)] )
  43. #define Visit( Bob, x, y )\
  44. ( (Bob)->mz_Cells[(x)*(Bob)->mz_Height+(y)] = 1 )
  45.  
  46. LONG DirArray[] = {
  47.     0x00010203, 0x00010302, 0x00020103, 0x00020301, 0x00030102, 0x00030201,
  48.     0x01000203, 0x01000302, 0x01020003, 0x01020300, 0x01030002, 0x01030200,
  49.     0x02000103, 0x02000301, 0x02010003, 0x02010300, 0x02030001, 0x02030100,
  50.     0x03000102, 0x03000201, 0x03010002, 0x03010200, 0x03020001, 0x03020100
  51.     };
  52.  
  53. typedef struct _Stack
  54. {
  55.     LONG st_x;
  56.     LONG st_y;
  57.     BYTE st_DirOne;
  58.     BYTE st_DirTwo;
  59.     BYTE st_DirThree;
  60.     BYTE st_DirFour;
  61.     struct _Stack *st_Prev;
  62. } Stack;
  63.  
  64. typedef struct _Maze
  65. {
  66.     struct RastPort *mz_Rast;
  67.     LONG mz_Width;
  68.     LONG mz_Height;
  69.     LONG mz_WidStep;
  70.     LONG mz_HeiStep;
  71.     BYTE *mz_Cells;
  72.     BYTE *mz_LeftWalls;
  73.     BYTE *mz_TopWalls;
  74.     Stack *mz_Stack;
  75. } Maze;
  76.  
  77. LONG StackLength, SolutionLength, NumCols, Copper;
  78. Triplet *ColorTable = 0L;
  79.  
  80. Stack *AllocStack( LONG x, LONG y, BYTE *Directions )
  81. {
  82.     Stack *New = AllocVec( sizeof( Stack ), MEMF_ANY );
  83.     
  84.     if( New )
  85.     {
  86.         New->st_x = x;
  87.         New->st_y = y;
  88.         CopyMem( Directions, &( New->st_DirOne ), 4 * sizeof( BYTE ));
  89.         New->st_Prev = 0L;
  90.     }
  91.     
  92.     return New;
  93. }
  94.  
  95. #define Push( b, c )\
  96. StackLength++; (c)->st_Prev = (b)->mz_Stack; (b)->mz_Stack = (c)
  97.  
  98. Stack *Pop( Maze *Bob )
  99. {
  100.     Stack *Popped = Bob->mz_Stack;
  101.     
  102.     if( Popped )
  103.     {
  104.         StackLength--;
  105.         Bob->mz_Stack = Popped->st_Prev;
  106.     }
  107.     
  108.     return Popped;
  109. }
  110.  
  111. VOID FreeMaze( Maze *FreeMe )
  112. {
  113.     if( FreeMe )
  114.     {
  115.         if( FreeMe->mz_Cells )
  116.             FreeVec( FreeMe->mz_Cells );
  117.         if( FreeMe->mz_LeftWalls )
  118.             FreeVec( FreeMe->mz_LeftWalls );
  119.         if( FreeMe->mz_TopWalls )
  120.             FreeVec( FreeMe->mz_TopWalls );
  121.         FreeVec( FreeMe );
  122.     }
  123. }
  124.  
  125. Maze *AllocMaze( struct Screen *Screen, LONG Width, LONG Height, LONG Flags )
  126. {
  127.     Maze *New;
  128.     
  129.     if( New = AllocVec( sizeof( Maze ), Flags ))
  130.     {
  131.         New->mz_Rast = &Screen->RastPort;
  132.         New->mz_Width = Width;
  133.         New->mz_Height = Height;
  134.         New->mz_WidStep = ( Screen->Width - 1 ) / Width;
  135.         New->mz_HeiStep = ( Screen->Height - 1 ) / Height;
  136.         New->mz_Cells = AllocVec( sizeof( BYTE ) * Width * Height, Flags );
  137.         New->mz_LeftWalls = AllocVec( sizeof( BYTE ) * ( Width + 1 ) * Height,
  138.                                      Flags );
  139.         New->mz_TopWalls = AllocVec( sizeof( BYTE ) * Width * ( Height + 1 ),
  140.                                     Flags );
  141.         
  142.         if( New->mz_Cells && New->mz_LeftWalls && New->mz_TopWalls )
  143.             return New;
  144.         
  145.         FreeMaze( New );
  146.     }
  147.     
  148.     return 0L;
  149. }
  150.  
  151. #define ActivateLeftWall( x, y )\
  152. ( Bob->mz_LeftWalls[(x)*Bob->mz_Height+(y)] = 1 )
  153. #define ActivateTopWall( x, y )\
  154. ( Bob->mz_TopWalls[(x)*Bob->mz_Height+(y)] = 1 )
  155.  
  156. #define LeftWallActive( x, y ) ( Bob->mz_LeftWalls[(x)*Bob->mz_Height+(y)] )
  157. #define TopWallActive( x, y ) ( Bob->mz_TopWalls[(x)*Bob->mz_Height+(y)] )
  158.  
  159. VOID AddHorizWall( Maze *Bob, LONG x, LONG y )
  160. {
  161.     Move( Bob->mz_Rast, x * Bob->mz_WidStep, y * Bob->mz_HeiStep );
  162.     Draw( Bob->mz_Rast, ( x + 1 ) * Bob->mz_WidStep, y * Bob->mz_HeiStep );
  163. }
  164.  
  165. VOID AddVertWall( Maze *Bob, LONG x, LONG y )
  166. {
  167.     Move( Bob->mz_Rast, x * Bob->mz_WidStep, y * Bob->mz_HeiStep );
  168.     Draw( Bob->mz_Rast, x * Bob->mz_WidStep, ( y + 1 ) * Bob->mz_HeiStep );
  169. }
  170.  
  171. VOID DrawSolution( Maze *Bob, LONG x, LONG y, LONG Pen, LONG Trailer )
  172. {
  173.     SetAPen( Bob->mz_Rast, Pen );
  174.     switch( Trailer )
  175.     {
  176.     case NORTH:
  177.         RectFill( Bob->mz_Rast, x * Bob->mz_WidStep + 1,
  178.                  y * Bob->mz_HeiStep + 1, ( x + 1 ) * Bob->mz_WidStep - 1,
  179.                  ( y + 1 ) * Bob->mz_HeiStep );
  180.         break;
  181.     case SOUTH:
  182.         RectFill( Bob->mz_Rast, x * Bob->mz_WidStep + 1, y * Bob->mz_HeiStep,
  183.                  ( x + 1 ) * Bob->mz_WidStep - 1,
  184.                  ( y + 1 ) * Bob->mz_HeiStep - 1 );
  185.         break;
  186.     case EAST:
  187.         RectFill( Bob->mz_Rast, x * Bob->mz_WidStep + 1,
  188.                  y * Bob->mz_HeiStep + 1, ( x + 1 ) * Bob->mz_WidStep,
  189.                  ( y + 1 ) * Bob->mz_HeiStep - 1 );
  190.         break;
  191.     case WEST:
  192.         RectFill( Bob->mz_Rast, x * Bob->mz_WidStep, y * Bob->mz_HeiStep + 1,
  193.                  ( x + 1 ) * Bob->mz_WidStep - 1,
  194.                  ( y + 1 ) * Bob->mz_HeiStep - 1 );
  195.         break;
  196.     }
  197. }
  198.  
  199. BYTE *RemoveDir( BYTE *Dir, BYTE RemMe )
  200. {
  201.     static BYTE Dirs[4];
  202.     int i;
  203.     
  204.     for( i = 0; i < 4; i++ )
  205.     {
  206.         if( Dir[i] == RemMe )
  207.             Dirs[i] = 4;
  208.         else
  209.             Dirs[i] = Dir[i];
  210.     }
  211.     
  212.     return Dirs;
  213. }
  214.  
  215. #define DefRemDir( x ) RemoveDir(( BYTE * )&( DirArray[RangeRand( 24 )] ), x )
  216.  
  217. Stack *GoDirection( Maze *Bob, Stack *Cell, BYTE DirNum )
  218. {
  219.     LONG x = Cell->st_x, y = Cell->st_y;
  220.     BYTE Direction;
  221.     
  222.     switch( DirNum )
  223.     {
  224.     case 0:
  225.         Direction = Cell->st_DirOne;
  226.         Cell->st_DirOne = 4;
  227.         break;
  228.     case 1:
  229.         Direction = Cell->st_DirTwo;
  230.         Cell->st_DirTwo = 4;
  231.         break;
  232.     case 2:
  233.         Direction = Cell->st_DirThree;
  234.         Cell->st_DirThree = 4;
  235.         break;
  236.     case 3:
  237.         Direction = Cell->st_DirFour;
  238.         Cell->st_DirFour = 4;
  239.         break;
  240.     }
  241.     
  242.     switch( Direction )
  243.     {
  244.     case EAST:
  245.         if( x < Bob->mz_Width - 1 )
  246.         {
  247.             if( !HasBeenVisited( Bob, x + 1, y ))
  248.             {
  249.                 Push( Bob, Cell );
  250.                 return AllocStack( x + 1, y, DefRemDir( WEST ));
  251.             }
  252.             else
  253.             {
  254.                 AddVertWall( Bob, x + 1, y );
  255.                 ActivateLeftWall( x + 1, y );
  256.             }
  257.         }
  258.         break;
  259.     case NORTH:
  260.         if( y < Bob->mz_Height - 1 )
  261.         {
  262.             if( !HasBeenVisited( Bob, x, y + 1 ))
  263.             {
  264.                 Push( Bob, Cell );
  265.                 return AllocStack( x, y + 1, DefRemDir( SOUTH ));
  266.             }
  267.             else
  268.             {
  269.                 AddHorizWall( Bob, x, y + 1 );
  270.                 ActivateTopWall( x, y + 1 );
  271.             }
  272.         }
  273.         break;
  274.     case WEST:
  275.         if( x > 0 )
  276.         {
  277.             if( !HasBeenVisited( Bob, x - 1, y ))
  278.             {
  279.                 Push( Bob, Cell );
  280.                 return AllocStack( x - 1, y, DefRemDir( EAST ));
  281.             }
  282.             else
  283.             {
  284.                 AddVertWall( Bob, x, y );
  285.                 ActivateLeftWall( x, y );
  286.             }
  287.         }
  288.         break;
  289.     case SOUTH:
  290.         if( y > 0 )
  291.         {
  292.             if( !HasBeenVisited( Bob, x, y - 1 ))
  293.             {
  294.                 Push( Bob, Cell );
  295.                 return AllocStack( x, y - 1, DefRemDir( NORTH ));
  296.             }
  297.             else
  298.             {
  299.                 AddHorizWall( Bob, x, y );
  300.                 ActivateTopWall( x, y );
  301.             }
  302.         }
  303.         break;
  304.     default:
  305.         break;
  306.     }
  307.     
  308.     return 0L;
  309. }
  310.  
  311. LONG ConstructMaze( Maze *Bob, LONG x, LONG y, LONG sx, LONG sy )
  312. {
  313.     Stack *Cell, *NewCell;
  314.     LONG RetVal;
  315.     
  316.     Cell = AllocStack( x, y, ( BYTE * )&( DirArray[RangeRand( 24 )] ));
  317.     
  318.     do
  319.     {
  320.         RetVal = ContinueBlanking();
  321.         
  322.         if( Cell->st_x == sx && Cell->st_y == sy && !SolutionLength )
  323.             SolutionLength = StackLength;
  324.  
  325.         Visit( Bob, Cell->st_x, Cell->st_y );
  326.         
  327.         if( NewCell = GoDirection( Bob, Cell, 0 ))
  328.         {
  329.             Cell = NewCell;
  330.             continue;
  331.         }
  332.         
  333.         if( NewCell = GoDirection( Bob, Cell, 1 ))
  334.         {
  335.             Cell = NewCell;
  336.             continue;
  337.         }
  338.         
  339.         if( NewCell = GoDirection( Bob, Cell, 2 ))
  340.         {
  341.             Cell = NewCell;
  342.             continue;
  343.         }
  344.         
  345.         if( NewCell = GoDirection( Bob, Cell, 3 ))
  346.         {
  347.             Cell = NewCell;
  348.             continue;
  349.         }
  350.         
  351.         FreeVec( Cell );
  352.         Cell = Pop( Bob );
  353.     }
  354.     while( Cell &&( RetVal == OK ));
  355.     
  356.     if( Cell )
  357.     {
  358.         do
  359.             FreeVec( Cell );
  360.         while( Cell = Pop( Bob ));
  361.     }
  362.     
  363.     return RetVal;
  364. }
  365.  
  366. Stack *SolveDirection( Maze *Bob, Stack *Cell, BYTE DirNum )
  367. {
  368.     LONG x = Cell->st_x, y = Cell->st_y;
  369.     BYTE Direction;
  370.     
  371.     switch( DirNum )
  372.     {
  373.     case 0:
  374.         Direction = Cell->st_DirOne;
  375.         Cell->st_DirOne = 4;
  376.         break;
  377.     case 1:
  378.         Direction = Cell->st_DirTwo;
  379.         Cell->st_DirTwo = 4;
  380.         break;
  381.     case 2:
  382.         Direction = Cell->st_DirThree;
  383.         Cell->st_DirThree = 4;
  384.         break;
  385.     case 3:
  386.         Direction = Cell->st_DirFour;
  387.         Cell->st_DirFour = 4;
  388.         break;
  389.     }
  390.     
  391.     switch( Direction )
  392.     {
  393.     case EAST:
  394.         if( x < Bob->mz_Width - 1 )
  395.         {
  396.             if( !LeftWallActive( x + 1, y ))
  397.             {
  398.                 Push( Bob, Cell );
  399.                 DrawSolution( Bob, x + 1, y, Copper == 2 || Copper == 3 ?
  400.                              (( StackLength * NumCols / SolutionLength ) %
  401.                               NumCols ) + 1 : 3, WEST );
  402.                 return AllocStack( x + 1, y, DefRemDir( WEST ));
  403.             }
  404.         }
  405.         break;
  406.     case NORTH:
  407.         if( y < Bob->mz_Height - 1 )
  408.         {
  409.             if( !TopWallActive( x, y + 1 ))
  410.             {
  411.                 Push( Bob, Cell );
  412.                 DrawSolution( Bob, x, y + 1, Copper == 2 || Copper == 3 ?
  413.                              (( StackLength * NumCols / SolutionLength ) %
  414.                               NumCols ) + 1 : 3, SOUTH );
  415.                 return AllocStack( x, y + 1, DefRemDir( SOUTH ));
  416.             }
  417.         }
  418.         break;
  419.     case WEST:
  420.         if( x > 0 )
  421.         {
  422.             if( !LeftWallActive( x, y ))
  423.             {
  424.                 Push( Bob, Cell );
  425.                 DrawSolution( Bob, x - 1, y, Copper == 2 || Copper == 3 ?
  426.                              (( StackLength * NumCols / SolutionLength ) %
  427.                               NumCols ) + 1 : 3, EAST );
  428.                 return AllocStack( x - 1, y, DefRemDir( EAST ));
  429.             }
  430.         }
  431.         break;
  432.     case SOUTH:
  433.         if( y > 0 )
  434.         {
  435.             if( !TopWallActive( x, y ))
  436.             {
  437.                 Push( Bob, Cell );
  438.                 DrawSolution( Bob, x, y - 1, Copper == 2 || Copper == 3 ?
  439.                              (( StackLength * NumCols / SolutionLength ) %
  440.                               NumCols ) + 1 : 3, NORTH );
  441.                 return AllocStack( x, y - 1, DefRemDir( NORTH ));
  442.             }
  443.         }
  444.         break;
  445.     default:
  446.         break;
  447.     }
  448.     
  449.     return 0L;
  450. }
  451.  
  452. LONG SolveMaze( Maze *Bob, LONG x, LONG y, LONG sx, LONG sy )
  453. {
  454.     Stack *Cell, *NewCell;
  455.     LONG RetVal;
  456.     
  457.     Cell = AllocStack( x, y, ( BYTE * )&( DirArray[RangeRand( 24 )] ));
  458.     
  459.     do
  460.     {
  461.         RetVal = ContinueBlanking();
  462.  
  463.         if( Cell->st_x == sx && Cell->st_y == sy )
  464.             break;
  465.  
  466.         if( NewCell = SolveDirection( Bob, Cell, 0 ))
  467.         {
  468.             Cell = NewCell;
  469.             continue;
  470.         }
  471.         
  472.         if( NewCell = SolveDirection( Bob, Cell, 1 ))
  473.         {
  474.             Cell = NewCell;
  475.             continue;
  476.         }
  477.         
  478.         if( NewCell = SolveDirection( Bob, Cell, 2 ))
  479.         {
  480.             Cell = NewCell;
  481.             continue;
  482.         }
  483.         
  484.         if( NewCell = SolveDirection( Bob, Cell, 3 ))
  485.         {
  486.             Cell = NewCell;
  487.             continue;
  488.         }
  489.         
  490.         x = Cell->st_x;
  491.         y = Cell->st_y;
  492.  
  493.         FreeVec( Cell );
  494.         Cell = Pop( Bob );
  495.  
  496.         if( Cell->st_x > x )
  497.             DrawSolution( Bob, x, y, 0, EAST );
  498.         if( Cell->st_x < x )
  499.             DrawSolution( Bob, x, y, 0, WEST );
  500.         if( Cell->st_y > y )
  501.             DrawSolution( Bob, x, y, 0, NORTH );
  502.         if( Cell->st_y < y )
  503.             DrawSolution( Bob, x, y, 0, SOUTH );
  504.     }
  505.     while( Cell &&( RetVal == OK ));
  506.     
  507.     if( Cell )
  508.     {
  509.         do
  510.             FreeVec( Cell );
  511.         while( Cell = Pop( Bob ));
  512.     }
  513.     
  514.     return RetVal;
  515. }
  516.  
  517. LONG Blank( VOID *Prefs )
  518. {
  519.     LONG ToFrontCount = 0, i, RetVal, StartY, SolutionY;
  520.     struct ModulePrefs *mP;
  521.     struct RastPort *Rast;
  522.     struct Screen *Scr;
  523.     struct Window *Wnd;
  524.     Maze *Bob;
  525.     
  526.     if( MazeWnd )
  527.         mP = &nP;
  528.     else
  529.         mP = ( struct ModulePrefs * )Prefs;
  530.     
  531.     Scr = OpenScreenTags( 0L, SA_Depth, mP->Depth, SA_Overscan, OSCAN_STANDARD,
  532.                          SA_DisplayID, mP->Mode, SA_Quiet, TRUE,
  533.                          SA_Behind, TRUE, TAG_DONE );
  534.     
  535.     if( Scr )
  536.         Bob = AllocMaze( Scr, ( Scr->Width - 1 ) / mP->CellSize,
  537.                         ( Scr->Height - 1 ) / mP->CellSize, MEMF_CLEAR );
  538.     
  539.     if( Scr && Bob )
  540.     {
  541.         SetRGB4( &Scr->ViewPort, 0, 0L, 0L, 0L );
  542.         
  543.         Rast = &( Scr->RastPort );
  544.         NumCols = ( 1L << Rast->BitMap->Depth ) - 1;
  545.         
  546.         SetRGB4( &Scr->ViewPort, 2, 0x0FL, 0x02L, 0x02L );
  547.  
  548.         switch( Copper = mP->Copper )
  549.         {
  550.         case 0:
  551.             SetRGB4( &Scr->ViewPort, 3, 0x0DL, 0x0DL, 0x0DL );
  552.             setCopperList(( LONG )Scr->Height, 1, &Scr->ViewPort, &custom );
  553.             break;
  554.         case 1:
  555.             SetRGB4( &Scr->ViewPort, 3, 0x02L, 0x02L, 0x0DL );
  556.             setCopperList(( LONG )Scr->Height, 3, &Scr->ViewPort, &custom );
  557.             break;
  558.         case 2:
  559.             ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  560.             break;
  561.         case 3:
  562.             ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  563.             setCopperList(( LONG )Scr->Height, 1, &Scr->ViewPort, &custom );
  564.             break;
  565.         default:
  566.             break;
  567.         }
  568.  
  569.         Wnd = BlankMousePointer( Scr );
  570.         ScreenToFront( Scr );
  571.         
  572.         do
  573.         {
  574.             SetRast( Rast, 0 );
  575.  
  576.             if( Copper != 2 )
  577.                 SetRGB4( &Scr->ViewPort, 1, 0x02L + RangeRand( 3 ),
  578.                         0x0DL - RangeRand( 5 ), 0x02L + RangeRand( 3 ));
  579.  
  580.             if(!( ++ToFrontCount % 60 ))
  581.                 ScreenToFront( Scr );
  582.             
  583.             if( Copper != 2 && Copper != 4 )
  584.                 SetAPen( Rast, 1 );
  585.             else
  586.                 SetAPen( Rast, RangeRand( NumCols ) + 1L );
  587.  
  588.             Move( Rast, 0, 0 );
  589.             Draw( Rast, 0, Bob->mz_Height * Bob->mz_HeiStep );
  590.             Draw( Rast, Bob->mz_Width * Bob->mz_WidStep,
  591.                  Bob->mz_Height * Bob->mz_HeiStep );
  592.             Draw( Rast, Bob->mz_Width * Bob->mz_WidStep, 0 );
  593.             Draw( Rast, 0, 0 );
  594.             
  595.             StartY = RangeRand( Bob->mz_Height );
  596.             SolutionY = RangeRand( Bob->mz_Height );
  597.             
  598.             StackLength = SolutionLength = 0;
  599.  
  600.             RetVal = ConstructMaze( Bob, 0, StartY, Bob->mz_Width - 1,
  601.                                    SolutionY );
  602.  
  603.             if( RetVal == OK )
  604.             {
  605.                 if( Copper != 2 )
  606.                 {
  607.                     DrawSolution( Bob, 0, StartY, 2, WEST );
  608.                     DrawSolution( Bob, Bob->mz_Width - 1, SolutionY, 2, EAST );
  609.                 }
  610.                 else
  611.                 {
  612.                     DrawSolution( Bob, 0, StartY, 1, WEST );
  613.                     DrawSolution( Bob, Bob->mz_Width - 1, SolutionY, 1, EAST );
  614.                 }
  615.                 
  616.                 RetVal = SolveMaze( Bob, 0, StartY, Bob->mz_Width - 1,
  617.                                    SolutionY );
  618.  
  619.                 if( RetVal == OK )
  620.                 {
  621.                     for( i = 0; i < Bob->mz_Width * Bob->mz_Height; i++ )
  622.                         Bob->mz_Cells[i] = 0;
  623.  
  624.                     for( i = 0; i < ( Bob->mz_Width+1 ) * Bob->mz_Height; i++ )
  625.                         Bob->mz_LeftWalls[i] = 0;
  626.                     
  627.                     for( i = 0; i < Bob->mz_Width * ( Bob->mz_Height+1 ); i++ )
  628.                         Bob->mz_TopWalls[i] = 0;
  629.                 }
  630.             }
  631.         }
  632.         while( RetVal == OK );
  633.         
  634.         UnblankMousePointer( Wnd );
  635.  
  636.         switch( Copper )
  637.         {
  638.         case 0:
  639.         case 1:
  640.             clearCopperList( &Scr->ViewPort );
  641.             break;
  642.         case 3:
  643.             clearCopperList( &Scr->ViewPort );
  644.         case 2:
  645.             RainbowPalette( 0L, ColorTable, 1L, 0L );
  646.             break;
  647.         default:
  648.             break;
  649.         }
  650.  
  651.     }
  652.     else
  653.         RetVal = FAILED;
  654.     
  655.     if( Bob )
  656.         FreeMaze( Bob );
  657.     
  658.     if( Scr )
  659.         CloseScreen( Scr );
  660.     
  661.     return RetVal;
  662. }
  663.