home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / utilities / iff2bin207.lzh / I2BTBin.c next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.4 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. #define WIDTH  320 /* 640 pixels wide (high resolution)                */
  9. #define HEIGHT 200 /* 200 lines high (non interlaced NTSC display)     */ 
  10. #define DEPTH    6 /* 3 BitPlanes should be used, gives eight colours. */
  11. #define COLOURS  32 /* 2^3 = 8                                          */
  12.  
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15. struct GfxBase *GfxBase;
  16.  
  17. extern UWORD far bp1;
  18.  
  19. struct View my_view;
  20. struct View *my_old_view;
  21. struct ViewPort my_view_port;
  22. struct RasInfo my_ras_info;
  23. struct BitMap my_bit_map;
  24. struct RastPort my_rast_port;
  25.  
  26.  
  27. extern UWORD far my_color_table[]; 
  28.  
  29.  
  30. void clean_up(STRPTR message);
  31. void main(void);
  32.  
  33.  
  34. void main(void)
  35. {
  36.   UWORD *pointer;
  37.   int loop;
  38.   
  39.   /* Open the Intuition library: */
  40.   IntuitionBase = (struct IntuitionBase *)
  41.     OpenLibrary( "intuition.library", 0 );
  42.   if( !IntuitionBase )
  43.     clean_up( "Could NOT open the Intuition library!" );
  44.  
  45.   /* Open the Graphics library: */
  46.   GfxBase = (struct GfxBase *)
  47.     OpenLibrary( "graphics.library", 0 );
  48.   if( !GfxBase )
  49.     clean_up( "Could NOT open the Graphics library!" );
  50.  
  51.  
  52.   /* Save the current View, so we can restore it later: */
  53.   my_old_view = GfxBase->ActiView;
  54.  
  55.  
  56.   /* 1. Prepare the View structure, and give it a pointer to */
  57.   /*    the first ViewPort:                                  */
  58.   InitView( &my_view );
  59.   my_view.ViewPort = &my_view_port;
  60.  
  61.  
  62.   /* 2. Prepare the ViewPort structure, and set some important values: */
  63.   InitVPort( &my_view_port );
  64.   my_view_port.DWidth = WIDTH;         /* Set the width.                */
  65.   my_view_port.DHeight = HEIGHT;       /* Set the height.               */
  66.   my_view_port.RasInfo = &my_ras_info; /* Give it a pointer to RasInfo. */
  67.   my_view_port.Modes = HAM;          /* High resolution.              */
  68.  
  69.  
  70.   /* 3. Get a colour map, link it to the ViewPort, and prepare it: */
  71.   my_view_port.ColorMap = (struct ColorMap *) GetColorMap( COLOURS );
  72.   if( my_view_port.ColorMap == NULL )
  73.     clean_up( "Could NOT get a ColorMap!" );
  74.  
  75.   /* Get a pointer to the colour map: */
  76.   pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  77.  
  78.   /* Set the colours: */
  79.   for( loop = 0; loop < COLOURS; loop++ )
  80.     *pointer++ = my_color_table[ loop ];
  81.  
  82.  
  83.   /* 4. Prepare the BitMap: */
  84.   InitBitMap( &my_bit_map, DEPTH, WIDTH, HEIGHT );
  85.  
  86.   my_bit_map.Planes[ 0 ] = (PLANEPTR)&bp1;
  87.   my_bit_map.Planes[ 1 ] = (PLANEPTR)(&bp1)+8000;
  88.   my_bit_map.Planes[ 2 ] = (PLANEPTR)(&bp1)+16000;
  89.   my_bit_map.Planes[ 3 ] = (PLANEPTR)(&bp1)+24000;
  90.   my_bit_map.Planes[ 4 ] = (PLANEPTR)(&bp1)+32000;
  91.   my_bit_map.Planes[ 5 ] = (PLANEPTR)(&bp1)+40000;
  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 < DEPTH; loop++ )
  137.     if( my_bit_map.Planes[ loop ] )
  138.       FreeRaster( my_bit_map.Planes[ loop ], WIDTH, HEIGHT );
  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();
  152. }
  153.