prevent null pointer access crashes/memory trashing.
[AROS.git] / test / graphics / blttemplatealpha.c
blob49721a57ab9b9b886c85131065adccbe7696807f
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <intuition/intuition.h>
8 #include <graphics/gfx.h>
9 #include <cybergraphx/cybergraphics.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/graphics.h>
13 #include <proto/cybergraphics.h>
14 #include <proto/intuition.h>
16 #include <math.h>
17 #include <stdio.h>
18 #include <stdlib.h>
20 #define SCREENWIDTH 300
21 #define SCREENHEIGHT 200
22 #define SCREENCY (SCREENHEIGHT / 2)
24 /***********************************************************************************/
26 struct IntuitionBase *IntuitionBase;
27 struct GfxBase *GfxBase;
28 struct Library *CyberGfxBase;
29 struct Screen *scr;
30 struct Window *win;
31 struct RastPort *rp;
33 UBYTE buf[SCREENWIDTH * SCREENHEIGHT];
35 /***********************************************************************************/
37 static void cleanup(char *msg)
39 if (msg)
41 printf("BltTemplateAlpha: %s\n",msg);
44 if (win) CloseWindow(win);
46 if (scr) UnlockPubScreen(0, scr);
48 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
49 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
50 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
52 exit(0);
55 /***********************************************************************************/
57 static void openlibs(void)
59 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
61 cleanup("Can't open intuition.library V39!");
64 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
66 cleanup("Can't open graphics.library V39!");
69 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
71 cleanup("Can't open cybergraphics.library!");
75 /***********************************************************************************/
77 static void getvisual(void)
79 if (!(scr = LockPubScreen(NULL)))
81 cleanup("Can't lock pub screen!");
84 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
86 cleanup("Need hi or true color screen!");
90 /***********************************************************************************/
92 static void makewin(void)
94 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
95 WA_InnerWidth , SCREENWIDTH,
96 WA_InnerHeight , SCREENHEIGHT,
97 WA_Title , (IPTR)"BltTemplateAlpha: Moving mouse is useless!",
98 WA_DragBar , TRUE,
99 WA_DepthGadget , TRUE,
100 WA_CloseGadget , TRUE,
101 WA_Activate , TRUE,
102 WA_IDCMP , IDCMP_CLOSEWINDOW,
103 WA_BackFill , (IPTR) LAYERS_NOBACKFILL,
104 TAG_DONE);
106 if (!win) cleanup("Can't open window");
108 rp = win->RPort;
112 /***********************************************************************************/
114 #define KC_LEFT 0x4F
115 #define KC_RIGHT 0x4E
116 #define KC_UP 0x4C
117 #define KC_DOWN 0x4D
118 #define KC_ESC 0x45
120 /***********************************************************************************/
122 /***********************************************************************************/
124 static void action(void)
126 int x, y;
127 for(y = 0; y < SCREENHEIGHT; y++)
129 for(x = 0; x < SCREENWIDTH; x++)
131 buf[y * SCREENWIDTH + x] = (y + x) & 255;
135 SetABPenDrMd(rp, 1, 2, JAM1);
137 BltTemplateAlpha(buf, 0, SCREENWIDTH, rp, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT);
140 WaitPort(win->UserPort);
143 /***********************************************************************************/
145 int main(void)
147 openlibs();
148 getvisual();
149 makewin();
150 action();
151 cleanup(0);
153 return 0;
156 /***********************************************************************************/