Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <clib/exec_protos.h>
- #include <clib/graphics_protos.h>
- #include <graphics/gfxbase.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define IO_LeftMouseIsPressed ((*((char *)0xbfe001) & 0x40) == 0)
- void setup();
- void shutdown(STRPTR message);
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct View my_view;
- struct View *my_old_view;
- struct ViewPort view_port1;
- struct RasInfo ras_info1;
- struct BitMap bit_map1;
- struct RastPort rast_port1;
- struct BitMap *testBitMap;
- int loop;
- USHORT palette[32] = {0x000, 0x00f, 0x0f0, 0xf00, 0x0ff, 0xff0, 0xf0f, 0xc34,
- 0x646, 0x782, 0xd23, 0x5a9, 0x560, 0xacf, 0xedf, 0xa09,
- 0x000, 0xe41, 0x733, 0x14e, 0x337, 0xee1, 0x773, 0x4e1,
- 0x373, 0xad0, 0xda0, 0xf00, 0x777, 0x999, 0xbbb, 0xeee};
- void setup() {
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
- if (!IntuitionBase)
- shutdown("Could NOT open the Intuition library!");
- /* Open the Graphics library: */
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
- if (!GfxBase)
- shutdown("Could NOT open the Graphics library!");
- /* Save the current View, so we can restore it later: */
- my_old_view = GfxBase->ActiView;
- /* Prepare the View structure, and give it a pointer to */
- /* the first ViewPort: */
- InitView(&my_view);
- my_view.ViewPort = &view_port1;
- /* 2. Prepare the ViewPort structures, and set some important values: */
- /* ViewPort 1 */
- InitVPort(&view_port1);
- view_port1.DWidth = 320; /* Set the width. */
- view_port1.DHeight = 256; /* Set the height. */
- view_port1.DxOffset = 0; /* X position. */
- view_port1.DyOffset = 0; /* Y position. */
- view_port1.RasInfo = &ras_info1; /* Give it a pointer to RasInfo. */
- view_port1.Modes = NULL; /* Low resolution. */
- view_port1.Next = NULL; /* Pointer to next ViewPort. */
- /* ViewPort 1 */
- view_port1.ColorMap = (struct ColorMap *)GetColorMap(32);
- if (view_port1.ColorMap == NULL)
- shutdown("Could NOT get a ColorMap!");
- /* Prepare the BitMap */
- /* ViewPort 1 */
- InitBitMap(&bit_map1, 3, 320, 256);
- /* Allocate memory for the Raster: */
- for (loop = 0; loop < 3; loop++) {
- bit_map1.Planes[loop] = (PLANEPTR)AllocRaster(320, 256);
- if (bit_map1.Planes[loop] == NULL)
- shutdown("Could NOT allocate enough memory for the raster!");
- /* Clear the display memory with help of the Blitter: */
- BltClear(bit_map1.Planes[loop], RASSIZE(320, 256), 0);
- }
- LoadRGB4(&view_port1, &palette[0], 32);
- InitRastPort(&rast_port1);
- rast_port1.BitMap = &bit_map1;
- SetDrMd(&rast_port1, JAM1);
- /* Create the display */
- MakeVPort(&my_view, &view_port1); /* Prepare ViewPort 1 */
- MrgCop(&my_view);
- /* 8. Show the new View: */
- LoadView(&my_view);
- }
- void shutdown(STRPTR message) {
- FreeVPortCopLists(&view_port1);
- FreeCprList(my_view.LOFCprList);
- ///* Deallocate the display memory, BitPlane for BitPlane: */
- for (loop = 0; loop < 3; loop++)
- if (bit_map1.Planes[loop])
- FreeRaster(bit_map1.Planes[loop], 320, 256);
- if (view_port1.ColorMap)
- FreeColorMap(view_port1.ColorMap);
- /* Close the Graphics library: */
- if (GfxBase)
- CloseLibrary((struct Library *)GfxBase);
- /* C Close the Intuition library: */
- if (IntuitionBase)
- CloseLibrary((struct Library *)IntuitionBase);
- /* Restore the old View: */
- LoadView(my_old_view);
- printf("%s\n", message);
- exit(0);
- }
- int main() {
- setup();
- SetAPen(&rast_port1, 5);
- Draw(&rast_port1, 100, 100);
- SetAPen(&rast_port1, 1);
- Draw(&rast_port1, 200, 200);
- while (!IO_LeftMouseIsPressed) {}
- shutdown("Bye!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement