/*
	xdata.c
	
 	Example program that tests the extended data library routines for use
 	with Dynamic C Deluxe version.
*/

/* declare xdata constants */

xdata d { "This is only a test!\nHa!\n",0x23,0x34,0x56};

xdata numbers {1,3,5,7,9,2,4,6,8,10,0};

xdata e {0};      /* single xdata constant 0 */

xdata v[100];     /* reserve a block in extended memory */


/* declare a group of strings in xmem */

xstring s {"one","two","three","four","five",
      "six","seven","eight","nine","ten"};

unsigned long int strPtr[10];    /* array to receive pointer to strings */

unsigned long int ll;

main() 
{
char buf[0x20];               /* character buffer for strings */
unsigned i;
unsigned long longAddress, stringAddress;

   for (i=0; i < 0x20; i++)
   	buf[i] = '\0';              /* null buffer first */

   root2xmem(buf, v, 0x20);   /* transfer to xmem data area */

   /* now all the variables are initialized to 0 */
   
   xmem2root (d, buf,  0x20);      /* transfer from xmem constant */
   root2xmem (buf, v,  0x20);      /* transfer to xmem variable */
   xmem2root (v, buf,  0x20);      /* and then transfer back to buffer */

   printf ("%s", buf);             /* show us what is transferred! */

   /* now test the xstring construct */
   longAddress = numbers;     /* loop through all numbers */

   do 
   {
   	xmem2root( longAddress,      /* get the number to local var i */
                &i, sizeof (unsigned int));
   
	   longAddress += sizeof(unsigned int);   /* advance the pointer to next */

	   if(i) 
   	{           /* if not terminated yet, */
      	/* get pointer to string */
      	xmem2root( s + (i-1) * sizeof(unsigned long int),
                   &stringAddress,    /* store it to a unsigned long */
                   sizeof(unsigned long int) ); /* specify the size */

	      xmem2root( stringAddress, buf,  10);   /* now transfer the string */
   	   printf("%s ",buf);       /* print the string */
      }

   } while(i);       /* array is null terminated */
}