check against the correct class. cast the value to bool before setting.
[AROS.git] / test / graphics / gfxinfo.c
bloba9a293b060bb5ea4f3ac8ce70d63ea372506ce02
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* A very hacky testcase which dumps lots of graphics subsystem internal things.
7 Please do not rely on the information you obtain using this program! Remember
8 that it some of things it will print are really private and internal! Do not
9 use techniques used by this program in common user software! */
11 /* Define this if you have no CGX SDK for some reason. You'll miss one bit of information then.
12 #define NO_CGX_API */
14 #ifdef __amigaos4__
15 #define __USE_INLINE__
16 #endif
18 #include <graphics/gfxbase.h>
19 #include <graphics/displayinfo.h>
20 #include <proto/dos.h>
21 #define __USE_BASETYPE__ // For __amigaos4__
22 #include <proto/exec.h>
23 #include <proto/graphics.h>
24 #undef __USE_BASETYPE__
26 #include <stdio.h>
27 #include <string.h>
29 #ifndef NO_CGX_API
30 #include <proto/cybergraphics.h>
31 #endif
33 #ifndef __AROS__
34 #define IPTR ULONG
35 #endif
37 struct myargs
39 IPTR nospecs;
40 IPTR nomodes;
41 IPTR allspecs;
42 IPTR displaydb;
45 /* This stuff is made static in order to reduce stack usage */
46 static struct myargs args = {FALSE, FALSE, FALSE, FALSE};
47 static struct NameInfo ni;
48 static struct DisplayInfo di;
49 static struct DimensionInfo dims;
50 static struct MonitorInfo mon;
52 int __nocommandline = 1;
54 static void PrintList(struct List *l)
56 printf(" lh_Head %p\n", l->lh_Head);
57 printf(" lh_Tail %p\n", l->lh_Tail);
58 printf(" lh_TailPred %p\n", l->lh_TailPred);
59 printf(" lh_Type %u\n", l->lh_Type);
62 static void PrintName(char *name, struct ExtendedNode *n)
64 printf("%s %p", name, n);
65 if (n)
66 printf(" %s", n->xln_Name);
67 printf("\n");
70 static void PrintNode(char *name, struct ExtendedNode *n)
72 char *nodename = "<no name>";
74 if (n->xln_Name)
75 nodename = n->xln_Name;
76 printf("%s %p %s\n", name, n, nodename);
77 printf(" xln_Succ %p\n", n->xln_Succ);
78 printf(" xln_Pred %p\n", n->xln_Pred);
79 printf(" xln_Type %d\n", n->xln_Type);
80 printf(" xln_Pri %d\n", n->xln_Pri);
81 printf(" xln_Subsystem %d\n", n->xln_Subsystem);
82 printf(" xln_Subtype %d\n", n->xln_Subtype);
83 printf(" xln_Library %p\n", (void *)n->xln_Library);
84 printf(" xln_Init %p\n", n->xln_Init);
87 static inline void PrintPoint(char *name, Point *p)
89 printf("%s (%u, %u)\n", name, p->x, p->y);
92 static inline void PrintRectangle(char *name, struct Rectangle *r)
94 printf("%s (%d, %d) - (%d, %d)\n", name, r->MinX, r->MinY, r->MaxX, r->MaxY);
97 static inline void PrintASI(char *name, struct AnalogSignalInterval *sig)
99 printf("%s Start %u Stop %u\n", name, sig->asi_Start, sig->asi_Stop);
102 static void PrintMonitorSpec(struct MonitorSpec *mspc)
104 PrintNode("MonitorSpec", &mspc->ms_Node);
105 printf (" ms_Flags 0x%04X\n", mspc->ms_Flags);
106 printf (" ratioh %d\n" , (int)mspc->ratioh);
107 printf (" ratiov %d\n" , (int)mspc->ratiov);
108 printf (" total_rows %u\n" , mspc->total_rows);
109 printf (" total_colorclocks %u\n" , mspc->total_colorclocks);
110 printf (" DeniseMaxDisplayColumn %u\n" , mspc->DeniseMaxDisplayColumn);
111 printf (" BeamCon0 0x%04X\n", mspc->BeamCon0);
112 printf (" min_row %u\n" , mspc->min_row);
113 printf (" ms_Special %p\n" , mspc->ms_Special);
114 printf (" ms_OpenCount %u\n" , mspc->ms_OpenCount);
115 printf (" ms_transform %p\n" , mspc->ms_transform);
116 printf (" ms_translate %p\n" , mspc->ms_translate);
117 printf (" ms_scale %p\n" , mspc->ms_scale);
118 printf (" ms_xoffset %u\n" , mspc->ms_xoffset);
119 printf (" ms_yoffset %u\n" , mspc->ms_yoffset);
120 PrintRectangle(" ms_LegalView " , &mspc->ms_LegalView);
121 printf (" ms_maxoscan %p\n" , mspc->ms_maxoscan);
122 printf (" ms_videoscan %p\n" , mspc->ms_videoscan);
123 printf (" DeniseMinDisplayColumn %u\n" , mspc->DeniseMinDisplayColumn);
124 printf (" DisplayCompatible 0x%08X\n", (unsigned)mspc->DisplayCompatible);
125 printf (" DisplayInfoDataBase %p\n" , &mspc->DisplayInfoDataBase);
126 PrintList(&mspc->DisplayInfoDataBase);
127 printf (" ms_MrgCop %p\n" , mspc->ms_MrgCop);
128 printf (" ms_LoadView %p\n" , mspc->ms_LoadView);
129 if (GfxBase->LibNode.lib_Version > 38)
130 printf (" ms_KillView %p\n" , mspc->ms_KillView);
132 if (mspc->ms_Special) {
133 PrintNode("SpecialMonitor", &mspc->ms_Special->spm_Node);
134 printf (" spm_Flags 0x%04X\n", mspc->ms_Special->spm_Flags);
135 printf (" do_monitor %p\n" , mspc->ms_Special->do_monitor);
136 printf (" reserved1 %p\n" , mspc->ms_Special->reserved1);
137 printf (" reserved2 %p\n" , mspc->ms_Special->reserved2);
138 printf (" reserved3 %p\n" , mspc->ms_Special->reserved3);
139 PrintASI (" hblank " , &mspc->ms_Special->hblank);
140 PrintASI (" vblank " , &mspc->ms_Special->vblank);
141 PrintASI (" hsync " , &mspc->ms_Special->hsync);
142 PrintASI (" vsync " , &mspc->ms_Special->vsync);
145 if (args.displaydb) {
146 /* We don't use DisplayInfoDataBaseSemaphore here because it may be
147 not initialized in fake MonitorSpecs.
148 What is done here is actually hack. Noone will ever need in
149 a common software. I examined many systems and these lists
150 were either empty or not initialized at all. However
151 there can be a theoretical possibility that something uses them. */
152 struct Node *n = mspc->DisplayInfoDataBase.lh_Head;
154 if (n && mspc->DisplayInfoDataBase.lh_TailPred) {
155 printf("DisplayInfoDataBase\n");
156 for (; n->ln_Succ; n = n->ln_Succ) {
157 printf(" Node %p %s\n", n, n->ln_Name);
158 printf(" ln_Type %d\n", n->ln_Type);
159 printf(" ln_Pri %d\n", n->ln_Pri);
165 int main(void)
167 struct Library *CyberGfxBase;
168 #ifdef __amigaos4__
169 struct CyberGfxIFace *ICyberGfx;
170 #endif
171 struct Library *P96Base;
172 struct RDArgs *rda;
173 struct MonitorSpec *mspc;
174 ULONG modeid = INVALID_ID;
176 rda = ReadArgs("NOSPECS/S,NOMODES/S,FORCESPECS/S,DISPLAYDB/S", (IPTR *)&args, NULL);
177 if (!rda) {
178 printf("You may supply the following switches:\n"
179 "NOSPECS - Do not list MonitorSpecs in GfxBase\n"
180 "NOMODES - Do not list Mode IDs\n"
181 "FORCESPECS - When listing Mode IDs, list MonitorSpec contents even if this MonitorSpec\n"
182 " is found in the GfxBase list. Use this in conjunction with NOSPECS to get\n"
183 " a valid information\n"
184 "DISPLAYDB - attempt to list internal nodes of DisplayInfoDataBase lists inside MonitorSpecs.\n"
185 " May crash or output garbage since it is not proven yet that these nodes actually\n"
186 " have names.\n");
187 return RETURN_FAIL;
190 CyberGfxBase = OpenLibrary("cybergraphics.library", 0);
191 P96Base = OpenLibrary("Picasso96API.library", 0);
193 printf("******** System information ********\n\n");
194 printf ("graphics.library v%u.%u\n", GfxBase->LibNode.lib_Version, GfxBase->LibNode.lib_Revision);
195 if (CyberGfxBase)
197 printf("cybergraphics.library v%u.%u\n", CyberGfxBase->lib_Version, CyberGfxBase->lib_Revision);
198 #ifdef __amigaos4__
199 ICyberGfx = (struct CyberGfxIFace *)GetInterface((struct Library *)CyberGfxBase, "main", 1, NULL);
200 #endif
202 if (P96Base)
203 printf("Picasso96API.library v%u.%u\n", P96Base->lib_Version, P96Base->lib_Revision);
204 printf("\n");
206 printf("GfxBase %p\n", GfxBase);
207 printf (" DisplayFlags 0x%04X\n", GfxBase->DisplayFlags);
208 printf (" ChipRevBits0 0x%02X\n", GfxBase->ChipRevBits0);
209 printf (" MemType 0x%02X\n", GfxBase->MemType);
210 printf (" monitor_id 0x%04X\n", GfxBase->monitor_id);
211 PrintName(" current_monitor" , &GfxBase->current_monitor->ms_Node);
212 PrintName(" default_monitor" , &GfxBase->default_monitor->ms_Node);
213 printf (" WantChips 0x%02X\n", GfxBase->WantChips);
214 printf (" BoardMemType 0x%02X\n", GfxBase->BoardMemType);
215 printf (" Bugs 0x%02X\n", GfxBase->Bugs);
216 PrintName(" natural_monitor" , &GfxBase->natural_monitor->ms_Node);
217 printf (" GfxFlags 0x%04X\n", GfxBase->GfxFlags);
218 printf ("\n");
220 printf("CyberGfxBase %p\n", CyberGfxBase);
221 printf("P96Base %p\n", P96Base);
223 if (!args.nospecs) {
224 printf("*********** MonitorSpecs ***********\n\n");
226 /* It's a good idea to lock this semaphore. It seems to be present in all OSes
227 (at least in AmigaOS v3, MorphOS and AROS)
228 However at least on AmigaOS v3 we can't call NextDisplayInfo() and such
229 while the lock is held. */
230 ObtainSemaphoreShared(GfxBase->MonitorListSemaphore);
231 for (mspc = (struct MonitorSpec *)GfxBase->MonitorList.lh_Head; mspc->ms_Node.xln_Succ; mspc = (struct MonitorSpec *)mspc->ms_Node.xln_Succ) {
232 PrintMonitorSpec(mspc);
233 printf("\n");
235 ReleaseSemaphore(GfxBase->MonitorListSemaphore);
238 if (!args.nomodes) {
239 printf("*********** Display modes **********\n\n");
240 for (;;) {
241 ULONG len;
243 modeid = NextDisplayInfo(modeid);
244 if (modeid == INVALID_ID)
245 break;
247 printf("ModeID 0x%08X ", (unsigned)modeid);
248 memset(&ni, 0, sizeof(ni));
249 len = GetDisplayInfoData(NULL, (UBYTE *)&ni, sizeof(ni), DTAG_NAME, modeid);
250 if (len > 0)
251 printf("%s\n", ni.Name);
252 else
253 printf("no NameInfo\n");
255 printf("DisplayInfo handle: %p\n", FindDisplayInfo(modeid));
256 #ifndef NO_CGX_API
257 if (CyberGfxBase)
258 printf("IsCyberModeID: %d\n", IsCyberModeID(modeid));
259 #endif
261 memset(&di, 0, sizeof(di));
262 len = GetDisplayInfoData(NULL, (UBYTE *)&di, sizeof(di), DTAG_DISP, modeid);
263 if (len > 0) {
264 printf ("DisplayInfo (%u bytes)\n", (unsigned)len);
265 printf (" NotAvailable 0x%04X\n", di.NotAvailable);
266 printf (" PropertyFlags 0x%08X\n", (unsigned)di.PropertyFlags);
267 PrintPoint(" Resolution " , &di.Resolution);
268 printf (" PixelSpeed %u\n" , di.PixelSpeed);
269 printf (" NumStdSprites %u\n" , di.NumStdSprites);
270 printf (" PaletteRange %u\n" , di.PaletteRange);
271 PrintPoint(" SpriteResolution" , &di.SpriteResolution);
272 printf (" RedBits %u\n" , di.RedBits);
273 printf (" GreenBits %u\n" , di.GreenBits);
274 printf (" BlueBits %u\n" , di.BlueBits);
275 } else
276 printf("No DisplayInfo\n");
278 memset(&dims, 0, sizeof(dims));
279 len = GetDisplayInfoData(NULL, (UBYTE *)&dims, sizeof(dims), DTAG_DIMS, modeid);
280 if (len > 0) {
281 printf ("DimensionInfo (%u bytes)\n", (unsigned)len);
282 printf (" MaxDepth %u\n", dims.MaxDepth);
283 printf (" MinRasterWidth %u\n", dims.MinRasterWidth);
284 printf (" MinRasterHeight %u\n", dims.MinRasterHeight);
285 printf (" MaxRasterWidth %u\n", dims.MaxRasterWidth);
286 printf (" MaxRasterHeight %u\n", dims.MaxRasterHeight);
287 PrintRectangle(" Nominal " , &dims.Nominal);
288 PrintRectangle(" MaxOScan " , &dims.MaxOScan);
289 PrintRectangle(" VideoOScan " , &dims.VideoOScan);
290 PrintRectangle(" TxtOScan " , &dims.TxtOScan);
291 PrintRectangle(" StdOScan " , &dims.StdOScan);
292 } else
293 printf("No DimensionInfo\n");
295 memset(&mon, 0, sizeof(mon));
296 len = GetDisplayInfoData(NULL, (UBYTE *)&mon, sizeof(mon), DTAG_MNTR, modeid);
297 if (len > 0) {
298 printf ("MonitorInfo (%u bytes)\n", (unsigned)len);
299 PrintName (" Mspc " , &mon.Mspc->ms_Node);
300 PrintPoint (" ViewPosition " , &mon.ViewPosition);
301 PrintPoint (" ViewResolution " , &mon.ViewResolution);
302 PrintRectangle(" ViewPositionRange " , &mon.ViewPositionRange);
303 printf (" TotalRows %u\n" , mon.TotalRows);
304 printf (" TotalColorClocks %u\n" , mon.TotalColorClocks);
305 printf (" MinRow %u\n" , mon.MinRow);
306 printf (" Compatibility %d\n" , mon.Compatibility);
307 PrintPoint (" MouseTicks " , &mon.MouseTicks);
308 PrintPoint (" DefaultViewPosition" , &mon.DefaultViewPosition);
309 printf (" PreferredModeID 0x%08X\n", (unsigned)mon.PreferredModeID);
311 if (args.allspecs)
312 mspc = NULL;
313 else {
314 ObtainSemaphoreShared(GfxBase->MonitorListSemaphore);
315 for (mspc = (struct MonitorSpec *)GfxBase->MonitorList.lh_Head; mspc->ms_Node.xln_Succ; mspc = (struct MonitorSpec *)mspc->ms_Node.xln_Succ) {
316 if (mspc == mon.Mspc)
317 break;
319 ReleaseSemaphore(GfxBase->MonitorListSemaphore);
321 if ((mspc != mon.Mspc) && mon.Mspc)
322 PrintMonitorSpec(mon.Mspc);
324 } else
325 printf("No MonitorInfo\n");
327 printf("\n");
331 printf("*************** End ****************\n");
332 if (P96Base)
333 CloseLibrary(P96Base);
334 if (CyberGfxBase)
335 CloseLibrary(CyberGfxBase);
337 FreeArgs(rda);
338 return 0;