Advertisement
Guest User

Untitled

a guest
Oct 7th, 2016
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.87 KB | None | 0 0
  1. #include <clib/exec_protos.h>
  2. #include <clib/graphics_protos.h>
  3. #include <graphics/gfxbase.h>
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define IO_LeftMouseIsPressed ((*((char *)0xbfe001) & 0x40) == 0)
  9.  
  10. void setup();
  11. void shutdown(STRPTR message);
  12.  
  13. struct IntuitionBase *IntuitionBase;
  14. struct GfxBase *GfxBase;
  15.  
  16. struct View my_view;
  17. struct View *my_old_view;
  18.  
  19. struct ViewPort view_port1;
  20. struct RasInfo ras_info1;
  21. struct BitMap bit_map1;
  22. struct RastPort rast_port1;
  23.  
  24. struct BitMap *testBitMap;
  25.  
  26. int loop;
  27.  
  28. USHORT palette[32] = {0x000, 0x00f, 0x0f0, 0xf00, 0x0ff, 0xff0, 0xf0f, 0xc34,
  29.                       0x646, 0x782, 0xd23, 0x5a9, 0x560, 0xacf, 0xedf, 0xa09,
  30.                       0x000, 0xe41, 0x733, 0x14e, 0x337, 0xee1, 0x773, 0x4e1,
  31.                       0x373, 0xad0, 0xda0, 0xf00, 0x777, 0x999, 0xbbb, 0xeee};
  32.  
  33. void setup() {
  34.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
  35.   if (!IntuitionBase)
  36.     shutdown("Could NOT open the Intuition library!");
  37.  
  38.   /* Open the Graphics library: */
  39.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  40.   if (!GfxBase)
  41.     shutdown("Could NOT open the Graphics library!");
  42.  
  43.   /* Save the current View, so we can restore it later: */
  44.   my_old_view = GfxBase->ActiView;
  45.  
  46.   /* Prepare the View structure, and give it a pointer to */
  47.   /* the first ViewPort:                                  */
  48.   InitView(&my_view);
  49.   my_view.ViewPort = &view_port1;
  50.  
  51.   /* 2. Prepare the ViewPort structures, and set some important values: */
  52.  
  53.   /* ViewPort 1 */
  54.   InitVPort(&view_port1);
  55.   view_port1.DWidth = 320;         /* Set the width.                */
  56.   view_port1.DHeight = 256;        /* Set the height.               */
  57.   view_port1.DxOffset = 0;         /* X position.                   */
  58.   view_port1.DyOffset = 0;         /* Y position.                   */
  59.   view_port1.RasInfo = &ras_info1; /* Give it a pointer to RasInfo. */
  60.   view_port1.Modes = NULL;         /* Low resolution.               */
  61.   view_port1.Next = NULL;          /* Pointer to next ViewPort.     */
  62.  
  63.   /* ViewPort 1 */
  64.   view_port1.ColorMap = (struct ColorMap *)GetColorMap(32);
  65.   if (view_port1.ColorMap == NULL)
  66.     shutdown("Could NOT get a ColorMap!");
  67.  
  68.   /* Prepare the BitMap */
  69.   /* ViewPort 1 */
  70.   InitBitMap(&bit_map1, 3, 320, 256);
  71.   /* Allocate memory for the Raster: */
  72.   for (loop = 0; loop < 3; loop++) {
  73.     bit_map1.Planes[loop] = (PLANEPTR)AllocRaster(320, 256);
  74.     if (bit_map1.Planes[loop] == NULL)
  75.       shutdown("Could NOT allocate enough memory for the raster!");
  76.     /* Clear the display memory with help of the Blitter: */
  77.     BltClear(bit_map1.Planes[loop], RASSIZE(320, 256), 0);
  78.   }
  79.  
  80.   LoadRGB4(&view_port1, &palette[0], 32);
  81.  
  82.   InitRastPort(&rast_port1);
  83.   rast_port1.BitMap = &bit_map1;
  84.   SetDrMd(&rast_port1, JAM1);
  85.  
  86.   /* Create the display */
  87.   MakeVPort(&my_view, &view_port1); /* Prepare ViewPort 1 */
  88.  
  89.   MrgCop(&my_view);
  90.  
  91.   /* 8. Show the new View: */
  92.   LoadView(&my_view);
  93. }
  94.  
  95. void shutdown(STRPTR message) {
  96.   FreeVPortCopLists(&view_port1);
  97.   FreeCprList(my_view.LOFCprList);
  98.  
  99.   ///* Deallocate the display memory, BitPlane for BitPlane: */
  100.   for (loop = 0; loop < 3; loop++)
  101.     if (bit_map1.Planes[loop])
  102.       FreeRaster(bit_map1.Planes[loop], 320, 256);
  103.  
  104.   if (view_port1.ColorMap)
  105.     FreeColorMap(view_port1.ColorMap);
  106.  
  107.   /* Close the Graphics library: */
  108.   if (GfxBase)
  109.     CloseLibrary((struct Library *)GfxBase);
  110.  
  111.   /* C Close the Intuition library:  */
  112.   if (IntuitionBase)
  113.     CloseLibrary((struct Library *)IntuitionBase);
  114.  
  115.   /* Restore the old View: */
  116.   LoadView(my_old_view);
  117.  
  118.   printf("%s\n", message);
  119.  
  120.   exit(0);
  121. }
  122.  
  123. int main() {
  124.   setup();
  125.  
  126.   SetAPen(&rast_port1, 5);
  127.   Draw(&rast_port1, 100, 100);
  128.   SetAPen(&rast_port1, 1);
  129.   Draw(&rast_port1, 200, 200);
  130.  
  131.   while (!IO_LeftMouseIsPressed) {}
  132.  
  133.   shutdown("Bye!");
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement