grub2: bring back build of aros-side grub2 tools
[AROS.git] / test / uae / test.c
blob0bcc9eab7dda655b97cf55393d202757625b562f
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include "types.h"
8 #include "lists.h"
10 /* Print the contents of a piece of memory. */
11 void hexdump (const void * start, int size)
13 int t;
14 const unsigned char * ptr = (const unsigned char *)start;
16 for (t=0; size > 0; t++, size--)
18 if (!(t & 15)) printf ("%08lx: ", ((long)ptr));
19 printf ("%02x", *ptr++);
20 if ((t & 3) == 3) putchar (' ');
21 if ((t & 15) == 15) putchar ('\n');
24 if (t & 15) putchar ('\n');
27 int main (int argc, char ** argv)
29 int a;
30 short b;
31 APTR ptr;
32 WORD c;
33 struct List l;
34 ListPtr lptr;
35 struct Node n;
37 /* Store an int in a BE 16bit data type */
38 c = 15;
39 a = c; // Check if all conversions work
40 b = c;
42 // Try to print the data
43 printf ("Must be 15 15 15: %d %d %d\n", a, b, (int)c);
44 putchar ('\n');
46 // Same with a pointer
47 ptr = &lptr;
49 // Note that the pointer must be casted but the compiler will print
50 // a warning if the cast is missing:
51 // warning: cannot pass objects of type `APTR' through `...'
52 // These three lines must print the same values.
53 printf ("APTR %p %p\n", &lptr, (void *)ptr);
54 hexdump (&ptr, sizeof (ptr));
55 ptr.print (); putchar ('\n');
56 putchar ('\n');
58 // Same with a pointer
59 char * p1;
60 STRPTR p2;
62 p1 = "hello";
63 p2 = p1;
65 // Note that the pointer must be casted but the compiler will print
66 // a warning if the cast is missing:
67 // warning: cannot pass objects of type `STRPTR' through `...'
68 // The first line must print two equal pointers and the second line
69 // must print two times "hello".
70 printf ("string %p %p\n", p1, (void *)p2);
71 printf ("%s %s\n", p1, (const char *)p2);
72 putchar ('\n');
74 // Show the contents of the memory (to prove that the actual data is BE)
75 printf ("Contents of p1 (host endianess) and p2 (big endian):\n");
76 hexdump (&p1, sizeof (p1));
77 hexdump (&p2, sizeof (p2));
78 putchar ('\n');
80 // Same with a structure
81 lptr = &l;
82 // Print address of list header
83 printf ("&lptr %p\n", &lptr);
84 // Print list pointers (host and BE) which must be equal (otherwise the
85 // BE pointer is not converted correctly).
86 printf ("List %p %p\n", &l, (void *)lptr);
87 // Show that it's really a BE pointer
88 hexdump (&lptr, sizeof (lptr));
89 // Print the real contents of the variable in host endianess
90 lptr.print ();
91 putchar ('\n');
92 putchar ('\n');
94 // Try some functions on the list
95 NEWLIST(lptr);
96 printf ("NewList %p %p %p\n", (void *)(l.lh_Head), (void *)l.lh_Tail, (void *)l.lh_TailPred);
97 printf ("NewList %p %p %p\n", (void *)(lptr->lh_Head), (void *)lptr->lh_Tail, (void *)lptr->lh_TailPred);
98 hexdump (&l, sizeof (struct List));
99 putchar ('\n');
101 ADDHEAD(lptr, &n);
102 printf ("&Node %p\n", &n);
103 printf ("AddHead %p %p %p\n", (void *)l.lh_Head, (void *)l.lh_Tail, (void *)l.lh_TailPred);
104 putchar ('\n');
106 return 0;