Reverted removal of 'const' from TagItem arrays/pointers in r50147
[AROS.git] / workbench / tools / SysExplorer / computer_page_cl.c
blobbb9c1c963c581f71e0fc8a6636684eaec0639411
1 /*
2 Copyright (C) 2013, The AROS Development Team.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/memory.h>
9 #include <hidd/hidd.h>
10 #include <resources/hpet.h>
11 #include <libraries/mui.h>
12 #include <mui/NFloattext_mcc.h>
13 #include <resources/processor.h>
14 #include <utility/tagitem.h>
15 #include <utility/hooks.h>
17 #include <proto/alib.h>
18 #include <proto/aros.h>
19 #include <proto/dos.h>
20 #include <proto/exec.h>
21 #include <proto/hpet.h>
22 #include <proto/kernel.h>
23 #include <proto/muimaster.h>
24 #include <proto/utility.h>
25 #include <proto/intuition.h>
26 #include <proto/processor.h>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <stdlib.h>
32 #include "classes.h"
33 #include "cpuspecific.h"
34 #include "locale.h"
36 #include <aros/debug.h>
38 #include <zune/customclasses.h>
40 APTR ProcessorBase = NULL;
43 /*** Instance Data **********************************************************/
44 struct ComputerWindow_DATA
46 /* Nothing to add */
50 ULONG ExtUDivMod32(ULONG a, ULONG b, ULONG *mod)
52 *mod = a % b;
54 return a/b;
58 void PrintNum(char *buffer, LONG bufsize, ULONG num)
60 /* MBytes ? */
61 if(num > 1023)
63 ULONG x, xx;
64 char* fmt = "meg";
66 /* GBytes ? */
67 if(num > 0xfffff)
69 num >>= 10;
70 fmt = "gig";
73 num = ExtUDivMod32(UMult32(num, 100) >> 10, 100, &x);
75 /* round */
76 x = ExtUDivMod32(x, 10, &xx);
78 if(xx > 4)
80 if(++x > 9)
82 x = 0;
83 num++;
87 snprintf(buffer, bufsize, "%d.%d %s", (int)num, (int)x, fmt);
89 else
91 snprintf(buffer, bufsize, "%d K", (int)num);
95 ULONG ComputeKBytes(APTR a, APTR b)
97 IPTR result = b - a;
99 return (ULONG)(result >> 10);
102 static ULONG GetProcessorsCount()
104 ULONG count = 0;
105 struct TagItem tags [] =
107 {GCIT_NumberOfProcessors, (IPTR)&count},
108 {TAG_DONE, TAG_DONE}
111 GetCPUInfo(tags);
113 return count;
116 struct
118 ULONG Architecture;
119 STRPTR Description;
120 } ProcessorArchitecture [] =
122 { PROCESSORARCH_UNKNOWN, "Unknown" },
123 { PROCESSORARCH_M68K, "Motorola 68K" },
124 { PROCESSORARCH_PPC, "PowerPC" },
125 { PROCESSORARCH_X86, "X86" },
126 { PROCESSORARCH_ARM, "ARM" },
127 { 0, NULL }
130 struct
132 ULONG Endianness;
133 STRPTR Description;
134 } CurrentEndianness [] =
136 { ENDIANNESS_UNKNOWN, "Unknown" },
137 { ENDIANNESS_LE, "LE" },
138 { ENDIANNESS_BE, "BE" },
139 { 0, NULL}
142 static VOID PrintProcessorInformation(char *buffer, LONG bufsize)
144 ULONG count = GetProcessorsCount();
145 ULONG i, j;
146 CONST_STRPTR modelstring;
147 ULONG architecture, endianness;
148 CONST_STRPTR architecturestring = "", endiannessstring = "";
149 UQUAD cpuspeed;
150 char *bufptr = buffer;
151 LONG slen;
153 for (i = 0; bufsize > 0 && i < count; i++)
155 struct TagItem tags [] =
157 {GCIT_SelectedProcessor, i},
158 {GCIT_ModelString, (IPTR)&modelstring},
159 {GCIT_Architecture, (IPTR)&architecture},
160 {GCIT_Endianness, (IPTR)&endianness},
161 {GCIT_ProcessorSpeed, (IPTR)&cpuspeed},
162 {TAG_DONE, TAG_DONE}
165 GetCPUInfo(tags);
167 j = 0;
168 while(ProcessorArchitecture[j].Description != NULL)
170 if (ProcessorArchitecture[j].Architecture == architecture)
172 architecturestring = ProcessorArchitecture[j].Description;
173 break;
175 j++;
178 j = 0;
179 while(CurrentEndianness[j].Description != NULL)
181 if (CurrentEndianness[j].Endianness == endianness)
183 endiannessstring = CurrentEndianness[j].Description;
184 break;
186 j++;
189 if (!modelstring)
190 modelstring = "Unknown";
192 snprintf(bufptr, bufsize, "PROCESSOR %d:\t[%s/%s] %s", (int)(i + 1), architecturestring,
193 endiannessstring, modelstring);
194 slen = strlen(bufptr);
195 bufptr += slen;
196 bufsize -= slen;
198 if (bufsize < 10)
199 break;
201 if (cpuspeed)
203 snprintf(bufptr, bufsize, " (%llu MHz)", (unsigned long long)(cpuspeed / 1000000));
204 slen = strlen(bufptr);
205 bufptr += slen;
206 bufsize -= slen;
208 snprintf(bufptr, bufsize, "\n");
209 slen = strlen(bufptr);
210 bufptr += slen;
211 bufsize -= slen;
213 PrintCPUSpecificInfo(bufptr, bufsize, i, ProcessorBase);
217 static inline void VersionStr(char *ptr, int len, struct Library *base)
219 snprintf(ptr, len, "%d.%d", base->lib_Version, base->lib_Revision);
222 static Object *ComputerWindow__OM_NEW(Class *cl, Object *self, struct opSet *msg)
224 Object *processors_flt;
225 Object *hpet_flt;
226 Object *ram_flt;
227 char aros_ver[8], exec_ver[8];
228 IPTR bootldr = 0;
229 IPTR args = 0;
230 APTR KernelBase;
231 APTR HPETBase;
233 STRPTR pagetitles[5];
234 int pagecnt = 0;
236 VersionStr(aros_ver, sizeof(aros_ver), ArosBase);
237 VersionStr(exec_ver, sizeof(exec_ver), &SysBase->LibNode);
239 KernelBase = OpenResource("kernel.resource");
240 if (KernelBase)
242 struct TagItem *bootinfo = KrnGetBootInfo();
244 bootldr = GetTagData(KRN_BootLoader, 0, bootinfo);
245 args = GetTagData(KRN_CmdLine , 0, bootinfo);
248 pagetitles[pagecnt++] = (STRPTR)_(MSG_GENERAL);
249 if ((ProcessorBase = OpenResource(PROCESSORNAME)) != NULL)
251 pagetitles[pagecnt++] = (STRPTR)_(MSG_PROCESSORS);
253 pagetitles[pagecnt++] = (STRPTR)_(MSG_RAM);
254 if ((HPETBase = OpenResource("hpet.resource")) != NULL)
256 pagetitles[pagecnt++] = (STRPTR)_(MSG_HPET);
258 pagetitles[pagecnt] = NULL;
260 self = (Object *) DoSuperNewTags
262 cl, self, NULL,
263 MUIA_Window_Title, __(MSG_SYSTEM_PROPERTIES),
264 MUIA_Window_ID, MAKE_ID('S', 'Y', 'P', 'R'),
265 WindowContents, (IPTR)(RegisterObject,
266 MUIA_Register_Titles, (IPTR) pagetitles,
267 MUIA_CycleChain, 1,
268 Child, (IPTR)(VGroup,
269 Child, (IPTR)(HGroup,
270 MUIA_FrameTitle, __(MSG_VERSION),
271 GroupFrame,
272 MUIA_Background, MUII_GroupBack,
273 Child, (IPTR)Label("AROS"),
274 Child, (IPTR)(TextObject,
275 TextFrame,
276 MUIA_Background, MUII_TextBack,
277 MUIA_CycleChain, 1,
278 MUIA_Text_Contents, (IPTR)aros_ver,
279 End),
280 Child, (IPTR)Label("Exec"),
281 Child, (IPTR)(TextObject,
282 TextFrame,
283 MUIA_Background, MUII_TextBack,
284 MUIA_CycleChain, 1,
285 MUIA_Text_Contents, (IPTR)exec_ver,
286 End),
287 End),
288 Child, (IPTR)(HGroup,
289 GroupFrame,
290 MUIA_FrameTitle, __(MSG_BOOTLOADER),
291 MUIA_Background, MUII_GroupBack,
292 Child, (IPTR)(TextObject,
293 TextFrame,
294 MUIA_Background, MUII_TextBack,
295 MUIA_CycleChain, 1,
296 MUIA_Text_Contents, bootldr,
297 End),
298 End),
299 Child, (IPTR)(HGroup,
300 GroupFrame,
301 MUIA_FrameTitle, __(MSG_ARGUMENTS),
302 MUIA_Background, MUII_GroupBack,
303 Child, (IPTR)(TextObject,
304 TextFrame,
305 MUIA_Background, MUII_TextBack,
306 MUIA_CycleChain, 1,
307 MUIA_Text_Contents, args,
308 End),
309 End),
310 End),
311 ProcessorBase ? Child : TAG_IGNORE, (IPTR)(VGroup,
312 Child, (IPTR)(NListviewObject,
313 MUIA_NListview_NList, (IPTR)(processors_flt = NFloattextObject,
314 End),
315 End),
316 End),
317 Child, (IPTR)(VGroup,
318 Child, (IPTR)(NListviewObject,
319 MUIA_NListview_NList, (IPTR)(ram_flt = NFloattextObject,
320 End),
321 End),
322 End),
323 HPETBase ? Child : TAG_IGNORE, (IPTR)(VGroup,
324 Child, (IPTR)(NListviewObject,
325 MUIA_NListview_NList, (IPTR)(hpet_flt = NFloattextObject,
326 End),
327 End),
328 End),
329 End),
330 TAG_DONE
333 if (self)
335 struct MemHeader *mh;
336 char buffer[2000];
337 char *bufptr;
338 LONG slen;
339 LONG bufsize;
341 // processors
342 *buffer = '\0';
343 if (ProcessorBase)
344 PrintProcessorInformation(buffer, sizeof(buffer));
345 // we intentionally use MUIA_Floattext_Text because it copies the text
346 SET(processors_flt, MUIA_Floattext_Text, buffer);
348 // high precision timers
349 *buffer = '\0';
350 bufptr = buffer;
351 bufsize = sizeof(buffer);
353 if (HPETBase)
355 const char *owner;
356 ULONG i = 0;
358 while (bufsize > 5 && GetUnitAttrs(i, HPET_UNIT_OWNER, &owner, TAG_DONE))
360 if (!owner)
361 owner = _(MSG_AVAILABLE);
363 snprintf(bufptr, bufsize, "HPET %u:\t\t%s\n", (unsigned)(++i), owner);
365 slen = strlen(bufptr);
366 bufptr += slen;
367 bufsize -= slen;
370 // we intentionally use MUIA_Floattext_Text because it copies the text
371 SET(hpet_flt, MUIA_Floattext_Text, buffer);
373 // RAM
374 *buffer = '\0';
375 bufptr = buffer;
376 bufsize = sizeof(buffer);
380 mh = (struct MemHeader *)SysBase->MemList.lh_Head;
381 bufsize > 5 && mh->mh_Node.ln_Succ;
382 mh = (struct MemHeader *)mh->mh_Node.ln_Succ
385 char *memtype = "ROM";
387 if (mh->mh_Attributes & MEMF_CHIP)
388 memtype = "CHIP";
389 if (mh->mh_Attributes & MEMF_FAST)
390 memtype = "FAST";
392 snprintf(bufptr, bufsize, "Node Type 0x%X, Attributes 0x%X (%s), at $%p-$%p (",
393 mh->mh_Node.ln_Type, mh->mh_Attributes, memtype, mh->mh_Lower, mh->mh_Upper - 1);
395 slen = strlen(bufptr);
396 bufptr += slen;
397 bufsize -= slen;
399 if (bufsize < 30)
400 break;
402 PrintNum(bufptr, bufsize, ComputeKBytes(mh->mh_Lower, mh->mh_Upper));
403 slen = strlen(bufptr);
404 bufptr += slen;
405 bufsize -= slen;
407 snprintf(bufptr, bufsize, ")\n");
408 slen = strlen(bufptr);
409 bufptr += slen;
410 bufsize -= slen;
412 // we intentionally use MUIA_Floattext_Text because it copies the text
413 SET(ram_flt, MUIA_Floattext_Text, buffer);
416 return self;
419 /*** Setup ******************************************************************/
420 ZUNE_CUSTOMCLASS_1
422 ComputerWindow, NULL, MUIC_Window, NULL,
423 OM_NEW, struct opSet *