/*
    (C) 1995-97 AROS - The Amiga Replacement OS
    $Id: arosinquirea.c,v 1.2 1997/04/04 14:53:35 digulla Exp $

    Desc:
    Lang: english
*/

#include <aros/config.h>
#include <exec/types.h>
#include <utility/tagitem.h>
#include <aros/libcall.h>
#include <proto/utility.h>
#include "aros_intern.h"

#define DEBUG 0
#include <aros/debug.h>
#undef kprintf

/* Kickstart ROM location offsets */
#define LOC_COOKIE	0x00
#define LOC_ADDRESS	0x04
#define LOC_MAJORV	0x0c
#define LOC_MINORV	0x0e
#define LOC_ROMSIZE	0x14		/* offset from end of ROM! */
#define ROM_END 	0x1000000

#if (AROS_FLAVOUR == AROS_FLAVOUR_NATIVE)
/* Native AROS support functions */
IPTR kicksize(void);
IPTR kickbase(void);
#endif

/*****************************************************************************

    NAME */
#include <aros/inquire.h>

	AROS_LH1(ULONG, ArosInquireA,

/*  SYNOPSIS */

	AROS_LHA(struct TagItem *, taglist, A0),

/*  LOCATION */

	struct ArosBase *, ArosBase, 5, Aros)

/*  FUNCTION
	This function is used to query system characteristics not easily
	queried with another function.

    INPUTS
	tags -- taglist with appropriate queries. The tag's ti_Data field
		should point to the location where the result of the query
		is stored. Do not forget to clear the location before, as
		queries not understood will be left untouched.

    RESULT
	All queries understood by this call will have appropriate values
	assigned to the location a tag's ti_Data pointed to.

	This function will (for now) always return 0.

    NOTES

    EXAMPLE

    BUGS

    SEE ALSO
	aros/arosbase.h

    INTERNALS

    HISTORY

******************************************************************************/
{
    struct TagItem *tag;
    ULONG ret = 0;

    D(bug("ArosInquireA(taglist=%p)\n", taglist));

    while( (tag = NextTagItem(&taglist)))
    {
	D(bug("  tag = $%lx\n", tag->ti_Tag));

	switch(tag->ti_Tag)
	{

#if (AROS_FLAVOUR == AROS_FLAVOUR_NATIVE)
	/*
	    Only support these tags if we are on the native machine. On other
	    machines this call will not touch the storage space. Set the
	    storage space to 0 if you want to see if this call touches it.
	*/

	case AI_KickstartBase:
	    *(IPTR *)tag->ti_Data = kickbase();
	    break;

	case AI_KickstartSize:
	    *(IPTR *)tag->ti_Data = kicksize();
	    break;

	case AI_KickstartVersion:
	    *(UWORD *)tag->ti_Data = *(UWORD *)(kickbase() + LOC_MAJORV);
	    break;

	case AI_KickstartRevision:
	    *(UWORD *)tag->ti_Data = *(UWORD *)(kickbase() + LOC_MINORV);
	    break;
#endif

	case AI_ArosVersion:
	    /*
		aros.library version masquerades as AROS version. This means
		that all aros modules must have the same major version number.
	    */
	    *(IPTR *)tag->ti_Data = (IPTR)(ULONG)LIBVERSION;
	    break;

	case AI_ArosReleaseMajor:
	    /* Update this whenever a new AROS is released */
	    *(IPTR *)tag->ti_Data = (IPTR)(ULONG)1;
	    break;

	case AI_ArosReleaseMinor:
	    /* Update this whenever a new AROS is released */
	    *(IPTR *)tag->ti_Data = (IPTR)(ULONG)11;
	    break;

	}

	*(ULONG *)(tag->ti_Data) = ret;
    }

    return ret;
} /* ArosInquireA */

#if (AROS_FLAVOUR == AROS_FLAVOUR_NATIVE)
/* Native AROS support functions */
IPTR kicksize(void)
{
    return *(ULONG *)(ROM_END - LOC_ROMSIZE);
}

IPTR kickbase(void)
{
    return (ROM_END - kicksize());
}
#endif
