- Set a default PCM volume so that something can be heard when driver is
[AROS.git] / test / CGXTest.c
blob971841e48dd0cb7c56b0335b0c3a74e826ae8239
1 /*
2 * This source was ocassionally found by Google here:
3 * http://megaburken.net/~patrik/
5 * The code is unmodified (except fixed #include file names in order to compile
6 * on modern systems)
8 * I hope the original author is not against spreading it, especially taking
9 * into account its experimental nature.
10 * Pavel Fedin <pavel_fedin@mail.ru>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <exec/exec.h>
17 #include <graphics/gfxbase.h>
18 #include <cybergraphx/cybergraphics.h>
19 #include <intuition/intuition.h>
21 #include <proto/exec.h>
22 #include <proto/graphics.h>
23 #include <proto/intuition.h>
25 #include <proto/cybergraphics.h>
27 #define WIDTH 320
28 #define HEIGHT 240
29 #define DEPTH 8
32 struct GfxBase *GfxBase;
33 struct Library *CyberGfxBase;
34 struct IntuitionBase *IntuitionBase;
36 int main(int argc, char *argv[])
38 struct Screen *myScreen;
39 struct Window *myWindow;
40 struct RastPort myRastPort;
41 struct BitMap *myBitMap;
43 APTR bitMapHandle;
45 ULONG result;
47 ULONG width;
48 ULONG height;
49 ULONG depth;
51 ULONG bm_width;
52 ULONG bm_depth;
53 ULONG bm_height;
54 ULONG bm_pixfmt;
55 ULONG bm_bytesperpix;
56 ULONG bm_bytesperrow;
57 IPTR bm_baseaddress;
58 IPTR bm_endaddress;
59 volatile ULONG *bm_curraddress;
61 if(argc == 1)
63 width = WIDTH;
64 height = HEIGHT;
65 depth = DEPTH;
67 else if(argc == 4)
69 width = atoi(argv[1]);
70 height = atoi(argv[2]);
71 depth = atoi(argv[3]);
73 else
75 printf("Wrong number of arguments!\n\n");
76 printf("Usage: CGXTest width height depth\n\n");
77 return 1;
81 GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39L);
82 if(!GfxBase)
84 printf("Couldnt open graphics.library 40.\n");
85 return 2;
87 CyberGfxBase = OpenLibrary("cybergraphics.library", 41L);
88 if(!CyberGfxBase)
90 printf("Couldnt open cybergraphics.library 41.\n");
91 CloseLibrary((struct Library *)GfxBase);
92 return 3;
94 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39L);
95 if(!IntuitionBase)
97 printf("Couldnt open intuition.library 39.\n");
98 CloseLibrary(CyberGfxBase);
99 CloseLibrary((struct Library *)GfxBase);
100 return 4;
103 myScreen = LockPubScreen(NULL);
104 if(myScreen != NULL)
106 UnlockPubScreen(NULL, myScreen);
108 else
110 printf("Couldnt get screen data.\n");
111 CloseLibrary((struct Library*)IntuitionBase);
112 CloseLibrary(CyberGfxBase);
113 CloseLibrary((struct Library *)GfxBase);
115 return 5;
118 myBitMap = AllocBitMap(width, height, depth, BMF_MINPLANES | BMF_DISPLAYABLE, myScreen->RastPort.BitMap);
119 if(!myBitMap)
121 printf("Couldnt allocate bitmap.\n");
122 CloseLibrary(CyberGfxBase);
123 CloseLibrary((struct Library *)GfxBase);
124 CloseLibrary((struct Library *)IntuitionBase);
125 return 6;
128 //Creates the RastPort used for blitting
129 InitRastPort(&myRastPort);
130 myRastPort.BitMap = myBitMap;
132 myWindow = OpenWindowTags(NULL, //WA_Left, 100,
133 //WA_Top, 100,
134 WA_InnerWidth, width,
135 WA_InnerHeight, height,
136 WA_ScreenTitle, "Watch out for that trashing! ;)",
137 TAG_END);
138 if(myWindow == NULL)
140 printf("Couldnt open a new window.\n");
141 FreeBitMap(myBitMap);
143 CloseLibrary((struct Library *)IntuitionBase);
144 CloseLibrary(CyberGfxBase);
145 CloseLibrary((struct Library *)GfxBase);
146 return 5;
150 printf("Allocated BitMap data:\n");
152 result=GetCyberMapAttr(myBitMap, CYBRMATTR_ISCYBERGFX);
153 if(result)
154 printf("It is a CyberGraphX bitmap!\n");
155 else
156 printf("It is not a CyberGraphX bitmap!\n");
158 result=GetCyberMapAttr(myBitMap, CYBRMATTR_ISLINEARMEM);
159 if(result)
160 printf("It supports linear memory access!\n");
161 else
162 printf("It does not support linear memory access!\n");
164 result=GetCyberMapAttr(myBitMap, CYBRMATTR_WIDTH);
165 printf("Width: %d\n", (int)result);
167 result=GetCyberMapAttr(myBitMap, CYBRMATTR_HEIGHT);
168 printf("Height: %d\n", (int)result);
170 result=GetCyberMapAttr(myBitMap, CYBRMATTR_DEPTH);
171 printf("Depth: %d\n", (int)result);
173 result=GetCyberMapAttr(myBitMap, CYBRMATTR_PIXFMT);
174 printf("Pixel format: ");
175 switch(result)
177 case PIXFMT_LUT8:
178 printf("LUT8");
179 break;
180 case PIXFMT_RGB15:
181 printf("RGB15");
182 break;
183 case PIXFMT_BGR15:
184 printf("BGR15");
185 break;
186 case PIXFMT_RGB15PC:
187 printf("RGB15PC");
188 break;
189 case PIXFMT_BGR15PC:
190 printf("BGR15PC");
191 break;
192 case PIXFMT_RGB16:
193 printf("RGB16");
194 break;
195 case PIXFMT_BGR16:
196 printf("BGR16");
197 break;
198 case PIXFMT_RGB16PC:
199 printf("RGB16PC");
200 break;
201 case PIXFMT_BGR16PC:
202 printf("BGR16PC");
203 break;
204 case PIXFMT_RGB24:
205 printf("RGB24");
206 break;
207 case PIXFMT_BGR24:
208 printf("BGR24");
209 break;
210 case PIXFMT_ARGB32:
211 printf("ARGB32");
212 break;
213 case PIXFMT_BGRA32:
214 printf("BGRA32");
215 break;
216 case PIXFMT_RGBA32:
217 printf("RGBA32");
218 break;
219 default:
220 printf("UNDEFINED");
222 printf("\n");
224 result=GetCyberMapAttr(myBitMap, CYBRMATTR_BPPIX);
225 printf("Bytes per pixel: %d\n", (int)result);
227 result=GetCyberMapAttr(myBitMap, CYBRMATTR_XMOD);
228 printf("Bytes per row: %d\n\n", (int)result);
230 printf("Locking BitMap and writing to it...");
231 bitMapHandle = LockBitMapTags(myBitMap,
232 LBMI_WIDTH, &bm_width,
233 LBMI_HEIGHT, &bm_height,
234 LBMI_DEPTH, &bm_depth,
235 LBMI_PIXFMT, &bm_pixfmt,
236 LBMI_BYTESPERPIX, &bm_bytesperpix,
237 LBMI_BYTESPERROW, &bm_bytesperrow,
238 LBMI_BASEADDRESS, &bm_baseaddress,
239 TAG_END);
241 if(bitMapHandle)
243 //Trashing?
244 bm_endaddress = bm_baseaddress + bm_bytesperrow * bm_height;
245 for(bm_curraddress = (ULONG *)bm_baseaddress; bm_curraddress < (ULONG *)bm_endaddress; bm_curraddress++)
246 *bm_curraddress = 0x102B5FF1;
248 UnLockBitMap(bitMapHandle);
250 printf("...done.\n\n");
253 printf("Locked BitMap data:\n");
254 printf("Base address: %p\n", (APTR)bm_baseaddress);
255 printf("Width: %d\n", (int)bm_width);
256 printf("Height: %d\n", (int)bm_height);
257 printf("Depth: %d\n", (int)bm_depth);
258 printf("Pixel format: ");
259 switch(bm_pixfmt)
261 case PIXFMT_LUT8:
262 printf("LUT8");
263 break;
264 case PIXFMT_RGB15:
265 printf("RGB15");
266 break;
267 case PIXFMT_BGR15:
268 printf("BGR15");
269 break;
270 case PIXFMT_RGB15PC:
271 printf("RGB15PC");
272 break;
273 case PIXFMT_BGR15PC:
274 printf("BGR15PC");
275 break;
276 case PIXFMT_RGB16:
277 printf("RGB16");
278 break;
279 case PIXFMT_BGR16:
280 printf("BGR16");
281 break;
282 case PIXFMT_RGB16PC:
283 printf("RGB16PC");
284 break;
285 case PIXFMT_BGR16PC:
286 printf("BGR16PC");
287 break;
288 case PIXFMT_RGB24:
289 printf("RGB24");
290 break;
291 case PIXFMT_BGR24:
292 printf("BGR24");
293 break;
294 case PIXFMT_ARGB32:
295 printf("ARGB32");
296 break;
297 case PIXFMT_BGRA32:
298 printf("BGRA32");
299 break;
300 case PIXFMT_RGBA32:
301 printf("RGBA32");
302 break;
303 default:
304 printf("UNDEFINED");
306 printf("\n");
307 printf("Bytes per pixel: %d\n", (int)bm_bytesperpix);
308 printf("Bytes per row: %d\n", (int)bm_bytesperrow);
309 printf("\n");
311 printf("Blitting BitMap to window...");
312 ClipBlit(&myRastPort, 0, 0, myWindow->RPort, myWindow->BorderLeft, myWindow->BorderTop, bm_width, bm_height, 0xC0);
313 printf("...done.\n");
315 else
316 printf("failed, couldnt lock bitmap.\n");
318 printf("\nPress enter to close the window.");
319 result = (ULONG)getchar();
321 CloseWindow(myWindow);
323 FreeBitMap(myBitMap);
325 CloseLibrary((struct Library *)IntuitionBase);
326 CloseLibrary(CyberGfxBase);
327 CloseLibrary((struct Library *)GfxBase);
329 printf("\nExiting.\n");
330 return 0;