home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / utilities / iff2bin207.lzh / I2BTObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.3 KB  |  153 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <graphics/gfxbase.h>
  4. #include <proto/all.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. struct IntuitionBase *IntuitionBase;
  9. struct GfxBase *GfxBase;
  10.  
  11. extern UWORD far bp1;
  12. extern UWORD far bp2;
  13. extern UWORD far bp3;
  14. extern UWORD far bp4;
  15. extern UWORD far bp5;
  16. extern UWORD far bp6;
  17. extern UWORD far bpCmap[];
  18. extern ULONG far bpHeight;
  19. extern ULONG far bpWidth;
  20. extern ULONG far bpDepth;
  21. extern ULONG far bpModes;
  22.  
  23. struct View my_view;
  24. struct View *my_old_view;
  25. struct ViewPort my_view_port;
  26. struct RasInfo my_ras_info;
  27. struct BitMap my_bit_map;
  28. struct RastPort my_rast_port;
  29.  
  30.  
  31. void clean_up(STRPTR message);
  32. void main(void);
  33.  
  34.  
  35. void main(void)
  36. {
  37.   UWORD *pointer;
  38.   int loop;
  39.   
  40.   /* Open the Intuition library: */
  41.   IntuitionBase = (struct IntuitionBase *)
  42.     OpenLibrary( "intuition.library", 0 );
  43.   if( !IntuitionBase )
  44.     clean_up( "Could NOT open the Intuition library!" );
  45.  
  46.   /* Open the Graphics library: */
  47.   GfxBase = (struct GfxBase *)
  48.     OpenLibrary( "graphics.library", 0 );
  49.   if( !GfxBase )
  50.     clean_up( "Could NOT open the Graphics library!" );
  51.  
  52.  
  53.   /* Save the current View, so we can restore it later: */
  54.   my_old_view = GfxBase->ActiView;
  55.  
  56.  
  57.   /* 1. Prepare the View structure, and give it a pointer to */
  58.   /*    the first ViewPort:                                  */
  59.   InitView( &my_view );
  60.   my_view.ViewPort = &my_view_port;
  61.  
  62.  
  63.   /* 2. Prepare the ViewPort structure, and set some important values: */
  64.   InitVPort( &my_view_port );
  65.   my_view_port.DWidth = (UWORD)bpWidth;         /* Set the width.                */
  66.   my_view_port.DHeight = (UWORD)bpHeight;       /* Set the height.               */
  67.   my_view_port.RasInfo = &my_ras_info; /* Give it a pointer to RasInfo. */
  68.   my_view_port.Modes = (UWORD)bpModes;          /* High resolution.              */
  69.  
  70.  
  71.   /* 3. Get a colour map, link it to the ViewPort, and prepare it: */
  72.   my_view_port.ColorMap = (struct ColorMap *) GetColorMap( 32 );
  73.   if( my_view_port.ColorMap == NULL )
  74.     clean_up( "Could NOT get a ColorMap!" );
  75.  
  76.   /* Get a pointer to the colour map: */
  77.   pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  78.  
  79.   /* Set the colours: */
  80.   for( loop = 0; loop < 32; loop++ )
  81.     *pointer++ = bpCmap[ loop ];
  82.  
  83.   /* 4. Prepare the BitMap: */
  84.   InitBitMap( &my_bit_map, bpDepth, bpWidth, bpHeight );
  85.  
  86.   my_bit_map.Planes[ 0 ] = (PLANEPTR)&bp1;
  87.   my_bit_map.Planes[ 1 ] = (PLANEPTR)&bp2;
  88.   my_bit_map.Planes[ 2 ] = (PLANEPTR)&bp3;
  89.   my_bit_map.Planes[ 3 ] = (PLANEPTR)&bp4;
  90.   my_bit_map.Planes[ 4 ] = (PLANEPTR)&bp5;
  91.   my_bit_map.Planes[ 5 ] = (PLANEPTR)&bp6;
  92.  
  93.   /* 5. Prepare the RasInfo structure: */
  94.   my_ras_info.BitMap = &my_bit_map; /* Pointer to the BitMap structure.  */
  95.   my_ras_info.RxOffset = 0;         /* The top left corner of the Raster */
  96.   my_ras_info.RyOffset = 0;         /* should be at the top left corner  */
  97.                                     /* of the display.                   */
  98.   my_ras_info.Next = NULL;          /* Single playfield - only one       */
  99.                                     /* RasInfo structure is necessary.   */
  100.  
  101.   /* 6. Create the display: */
  102.   MakeVPort( &my_view, &my_view_port );
  103.   MrgCop( &my_view );
  104.  
  105.  
  106.   /* 7. Prepare the RastPort, and give it a pointer to the BitMap. */
  107.   InitRastPort( &my_rast_port );
  108.   my_rast_port.BitMap = &my_bit_map;
  109.   
  110.  
  111.   /* 8. Show the new View: */
  112.   LoadView( &my_view );
  113.  
  114.    Delay(1500);
  115.  
  116.   /* 9. Restore the old View: */
  117.   LoadView( my_old_view );
  118.  
  119.  
  120.   /* Free all allocated resources and leave. */
  121.   clean_up( "THE END" );
  122. }
  123.  
  124.  
  125. /* Returns all allocated resources: */
  126. void clean_up( message )
  127. STRPTR message;
  128. {
  129.   int loop;
  130.  
  131.   /* Free automatically allocated display structures: */
  132.   FreeVPortCopLists( &my_view_port );
  133.   FreeCprList( my_view.LOFCprList );
  134.   
  135.   /* Deallocate the display memory, BitPlane for BitPlane: */
  136.   for( loop = 0; loop < bpDepth; loop++ )
  137.     if( my_bit_map.Planes[ loop ] )
  138.       FreeRaster( my_bit_map.Planes[ loop ], bpWidth, bpHeight );
  139.  
  140.   /* Deallocate the ColorMap: */
  141.   if( my_view_port.ColorMap ) FreeColorMap( my_view_port.ColorMap );
  142.  
  143.   /* Close the Graphics library: */
  144.   if( GfxBase ) CloseLibrary((struct LIBRARY*) GfxBase );
  145.  
  146.   /* Close the Intuition library: */
  147.   if( IntuitionBase ) CloseLibrary( IntuitionBase );
  148.  
  149.   /* Print the message and leave: */
  150.   printf( "%s\n", message ); 
  151.   exit(0);
  152. }
  153.