#include <exec/types.h>
#include <exec/lists.h>
#include <utility/tagitem.h>
#include <graphics/displayinfo.h>
#include <dos/dos.h>

#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/dos_protos.h>

#include "vilintuisup.h"
#include "vilintuisup/ScreenMode.h"
#include "vilintuisup/vilintuisup_protos.h"

/*
 * Here are some sample tag item arrays for the VillageBestModeID call
 */

/* the biggest in the deepest color depth */

struct TagItem ti0[] = {
   { TAG_DONE, 0 }
};

/* the biggest in color depth 24 */

struct TagItem ti1[] = {
   { TAVIS_SCREEN_DEPTH, 24 },
   { TAG_DONE, 0 }
};

/* the biggest in color depth 16 */

struct TagItem ti2[] = {
   { TAVIS_SCREEN_DEPTH, 16 },
   { TAG_DONE, 0 }
};

/* the screen with 800 (or less) pixels in height in color depth 8 */

struct TagItem ti3[] = {
   { TAVIS_SCREEN_DEPTH, 8    },
   { TAVIS_SCREEN_HEIGHT, 800 },
   { TAG_DONE, 0 }
};

/* the screen with 2000 (or less) pixels in height in color depth 8 */

struct TagItem ti4[] = {
   { TAVIS_SCREEN_DEPTH, 8    },
   { TAVIS_SCREEN_HEIGHT, 2000 },
   { TAG_DONE, 0 }
};

struct Library *VilIntuiBase;

/*
 * PrintIDDimensions is a useful function when determine data from an ID
 */

void PrintIDDimensions(ULONG ID)
{
   DisplayInfoHandle Handle;
   struct DimensionInfo dimension;

   if (ID != INVALID_ID)
   {  if (Handle = FindDisplayInfo(ID))
      {  if (GetDisplayInfoData(Handle,(UBYTE *)&dimension,sizeof(dimension),DTAG_DIMS,0))
	 {
	     Printf("DisplayID: %8lx, Depth: %2ld, Width: %4ld, Height: %4ld\n",
		     ID,              dimension.MaxDepth,
				      dimension.Nominal.MaxX+1,
				      dimension.Nominal.MaxY+1);
	 }
	 else
	 {  Printf("Can't get DimensionInfo for ID %8lx\n",ID); }
      }
      else
      {  Printf("Can't find DisplayInfo for ID %8lx\n",ID); }
   }
   else
   {  PutStr("INVALID_ID is not a valid ID!\n"); }
}


int main(int argc, char *argv[])
{
   if (VilIntuiBase = OpenLibrary("vilintuisup.library",2))
   {
       PrintIDDimensions(VillageBestModeID(ti0));
       PrintIDDimensions(VillageBestModeID(ti1));
       PrintIDDimensions(VillageBestModeID(ti2));
       PrintIDDimensions(VillageBestModeID(ti3));
       PrintIDDimensions(VillageBestModeID(ti4));

       CloseLibrary(VilIntuiBase);
   }
   else
   {  PutStr("Can't open vilintuisup.library\n"); }

   return RETURN_OK;
}

