The idea for this article came from a posting from Hans de Ruiter over at OS4Coding.net in which he wanted to know how you could identify your machine. He talked about the function GetMachineInfo() from the expansion library that could do this. With that info I set out to create some code that would do exactly that; identifying our machine. Unfortunately the GetMachineInfo() function is not that detailed when it comes to identifying your machine. It can identify the below machines:

MACHINETYPE_UNKNOWN – Unknown hardware
MACHINETYPE_BLIZZARDPPC – BlizzardPPC in an A1200
MACHINETYPE_CYBERSTORMPPC – CyberStorm PPC in an A3000/A4000
MACHINETYPE_AMIGAONE – any AmigaOne model (including XE, SE, MicroA1 or XC).

The problem lies in the AmigaOne identifier since it will only report back “AmigaOne” and not if it is a XE, SE, MicroA1 or XC. I will do some more digging into this to see if there is  way to determine what exact model of AmigaOne it is. For now this example will demonstrate some new programming code and get you to extend your knowledge. Let’s have a look at the code.  

01 #include <stdio.h>
02 #include <expansion/expansion.h>
03
04 #include <proto/exec.h>
05 #include <proto/expansion.h>
06
07 struct Library *ExpansionBase = NULL;
08
09 struct ExpansionIFace *IExpansion = NULL;
10
11 int main (void)
12
13 {
14
15  /* Opening the Expansion Library */
16  ExpansionBase = IExec->OpenLibrary(“expansion.library“, 50L);
17
18   /* Did we manage to open the Expansion Library? */
19   if (ExpansionBase != NULL)
20  {
21
22     printf (“We opened the Expansion Library!!\n”);
23
24     /* Open the Expansion Interface */
25     IExpansion = (struct ExpansionIFace *) IExec->GetInterface (ExpansionBase, “main“, 1, NULL);
26
27      /* Did we get the Expansion Interface? */
28      if (IExpansion != NULL)
29     {
30
31       printf (“We did get the Expansion Interface!!\n”);
32
33        STRPTR machine;
34
35        IExpansion->GetMachineInfoTags(GMIT_MachineString, &machine, TAG_END);
36
37        printf(“Blimey! Your model = ‘%s’\n”, machine);
38
39        /* If the Expansion Library Interface is open, close it */
40        IExec->DropInterface((struct Interface *)IExpansion);
41         }
42
43     /* We could not open the Expension Library Interface */
44     else
45     {
46
47    printf (“Unable to open the Expansion Library Interface!\n”);
48    }
49
50   /* If the Expansion Library is open, close it */
51   IExec->CloseLibrary(ExpansionBase);
52   }
53
54   /* We could not open the Expansion Library */
55   else
56  {
57
58   printf (“Unable to open the Expansion Library!\n”);
59  }
60
61 return 0;
62 }

If we compile our program and run it from the shell we will get the below output.

Running the ID machine program

As you can see I still add the code of printing if you managed to open a library or get the interface. You can leave that out if you wish.

The only strange piece of code on the block is:

02       #include <expansion/expansion.h>

05       #include <proto/expansion.h>

33        STRPTR machine;
34
35        IExpansion->GetMachineInfoTags(GMIT_MachineString, &machine, TAG_END);
36
37        printf(“Blimey! Your model = ‘%s’\n”, machine);

Line 02 and 05 will add some includes so that we can use the Expansion base library functions in our program. Line 33 till 37 is the code that will actually perform our little magic trick.

The AutoDocs from the SDK describe GMIT_MachineString as:

GMIT_MachineString (STRPTR *) — Machine model as a human-readable string.

GMIT_MachineString is part of the GetMachineInfoTags function. We use IExpansion-> to call upon GetMachineInfoTags. The value returned by GMIT_MachineString is stored in “machine”. We have set-up “machine” on line 33 which sets up “machine” as a string pointer. In line 35 the & sign will store the value as a string pointer. And at line 37 we are printing the value of “machine” which is in this case AmigaOne.

This example also shows one of the difficult parts of programming on the Amiga OS; trying to understand the AutoDocs which describes all the functions. At least for me this is the case. It does describe all the functions but not really how to use them. Well in some cases they do provide some examples but mostly it just mentions all the functions which make almost no sense. It certainly would scare some new programmers away since they might become frustrated in not understanding it. I will try to address the AutoDocs in some future articles to make it easier to understand and at some point make it possible to actually read and understand them yourself. Till next time and happy coding!

Advertisements