/* OpenAmiga.org
 *  This file is part of the OpenAmiga "xfdmaster library project"
 *
 * For more information look at:
 *   http://openamiga.org/?function=viewproject&projectid=67
 */

/****************************************************************************
*   XFD library system for cruncher handling
*   Copyright (C) 1994-1998 by Georg Hörmann
*   Copyright (C) 1998 by Dirk Stöcker <soft@dstoecker.de>
*   Copyright (C) 2014 by Fredrik Wikström <fredrik@a500.org>
*
*   This library is free software; you can redistribute it and/or
*   modify it under the terms of the GNU Lesser General Public
*   License as published by the Free Software Foundation; either
*   version 2.1 of the License, or (at your option) any later version.
*
*   This library is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*   Lesser General Public License for more details.
*
*   You should have received a copy of the GNU Lesser General Public
*   License along with this library; if not, write to the Free Software
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
****************************************************************************/

#include <interfaces/xfdmaster.h>
#include "../xfdmaster_vectors.h"
#include "../xfdmaster_internal.h"

/****** xfdmaster.library/xfdAllocObject ******************************************
*
*   NAME
*      xfdAllocObject -- Description
*
*   SYNOPSIS
*      APTR xfdAllocObject(ULONG objecttype);
*
*   FUNCTION
*
*   INPUTS
*       objecttype - 
*
*   RESULT
*       The result ...
*
*   EXAMPLE
*
*   NOTES
*
*   BUGS
*
*   SEE ALSO
*
*****************************************************************************
*
*/

static const UWORD Objects[XFDOBJ_MAX] = {
	sizeof(struct xfdBufferInfo) + 4,
	sizeof(struct xfdSegmentInfo) + 4,
	sizeof(struct xfdLinkerInfo) + 4,
	sizeof(struct xfdScanNode) + 4,
	sizeof(struct xfdScanHook) + 4
};

APTR _xfdMaster_xfdAllocObject(struct xfdMasterIFace *Self, ULONG objecttype) {
	DEBUGF("xfdAllocObject(0x%08lx, %lu)\n", Self, objecttype);
	UWORD *object = NULL;
	if (objecttype > 0 && objecttype <= XFDOBJ_MAX) {
		struct xfdMasterBase *libBase = (struct xfdMasterBase *)Self->Data.LibBase;
		struct ExecIFace *IExec = libBase->xfdm_IExec;

		object = IExec->AllocVecTags(Objects[objecttype - 1],
			AVT_Type, MEMF_SHARED,
			AVT_Lock, FALSE,
			AVT_ClearWithValue, 0,
			TAG_END);
		if (object != NULL) {
			*object++ = 0xfd0b;
			*object++ = (UWORD)objecttype;
		}
	}
	DEBUGF("xfdAllocObject: 0x%08lx\n", object);
	return object;
}

