Unit Utility;

Interface
Uses Exec;


Type

pHook = ^tHook;
tHook	=	Record
				h_MinNode	:	tMinNode;
				h_Entry		:	pLongInt;
				h_SubEntry	:	pLongInt;
				h_Data		:	Pointer;
			End;
			
Tag	=	LongInt;

pTagItem	=	^tTagItem;
tTagItem	=	Record
					ti_Tag	:	Tag;
					ti_Data	:	Longint;
				End;
				
Const

TAG_DONE			=	0;
TAG_END			=	0;
TAG_IGNORE		=	1;
TAG_MORE			=	2;
TAG_SKIP			=	3;
TAG_USER			=	$80000000;
TAGFILTER_AND	=	0;
TAGFILTER_NOT	=	1;


Function FindTagItem
		 (tagVal: LongInt;
		  tagList: Pointer): LongInt;

Function GetTagData
		 (tagVal,
		  defaultVal: LongInt;
		  tagList: Pointer): LongInt;

Function PackBoolTags
		 (initialFlags: LongInt;
		  tagList,
		  boolMap: Pointer): LongInt;

Function NextTagItem (tagListPtr: Pointer): LongInt;
Function FilterTagChanges
		 (newTagList,
		  oldTagList: Pointer;
		  apply: LongInt): LongInt;

Function MapTags
		 (tagList,
		  mapList: Pointer;
		  includeMiss: LongInt): LongInt;

Function AllocateTagItems (numItems: LongInt): LongInt;
Function CloneTagItems (tagList: Pointer): LongInt;
Function FreeTagItems (tagList: Pointer): LongInt;
Function RefreshTagItemClones
		 (cloneList,
		  origList: Pointer): LongInt;

Function TagInArray
		 (tagVal: LongInt;
		  tagArray: Pointer): LongInt;

Function FilterTagItems
		 (tagList,
		  filterArray: Pointer;
		  logic: LongInt): LongInt;

Function CallHookPkt
		 (hook,
		  object,
		  paramPacket: Pointer): LongInt;

Function Amiga2Date
		 (amigaTime: LongInt;
		  date: Pointer): LongInt;

Function Date2Amiga (date: Pointer): LongInt;
Function CheckDate (date: Pointer): LongInt;
Function SMult32
		 (factor1,
		  factor2: LongInt): LongInt;

Function UMult32
		 (factor1,
		  factor2: LongInt): LongInt;

Function SDivMod32
		 (dividend,
		  divisor: LongInt): LongInt;

Function UDivMod32
		 (dividend,
		  divisor: LongInt): LongInt;

Function Stricmp
		 (string1,
		  string2: Pointer): LongInt;

Function Strnicmp
		 (string1,
		  string2: Pointer;
		  length: LongInt): LongInt;

Function ToUpper (character: LongInt): LongInt;
Function ToLower (character: LongInt): LongInt;


Var
  UtilityBase: pLibrary;



Implementation
Function FindTagItem
		 (tagVal: LongInt;
		  tagList: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a0
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$1E(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function GetTagData
		 (tagVal,
		  defaultVal: LongInt;
		  tagList: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a0
	move.l	(a6)+,d1
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$24(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function PackBoolTags
		 (initialFlags: LongInt;
		  tagList,
		  boolMap: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$2A(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function NextTagItem (tagListPtr: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),a0
	move.l	UtilityBase,a6
	jsr	-$30(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function FilterTagChanges
		 (newTagList,
		  oldTagList: Pointer;
		  apply: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d0
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$36(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function MapTags
		 (tagList,
		  mapList: Pointer;
		  includeMiss: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d0
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$3C(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function AllocateTagItems (numItems: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),d0
	move.l	UtilityBase,a6
	jsr	-$42(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function CloneTagItems (tagList: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),a0
	move.l	UtilityBase,a6
	jsr	-$48(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function FreeTagItems (tagList: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),a0
	move.l	UtilityBase,a6
	jsr	-$4E(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function RefreshTagItemClones
		 (cloneList,
		  origList: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$54(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function TagInArray
		 (tagVal: LongInt;
		  tagArray: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a0
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$5A(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function FilterTagItems
		 (tagList,
		  filterArray: Pointer;
		  logic: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d0
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$60(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function CallHookPkt
		 (hook,
		  object,
		  paramPacket: Pointer): LongInt;
XASSEMBLER;
ASM	movem.l	a2/a6,-(sp)
	lea	$C(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a2
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$66(a6)
	move.l	d0,$18(sp)
	movem.l	(sp)+,a2/a6
END;

Function Amiga2Date
		 (amigaTime: LongInt;
		  date: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a0
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$78(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function Date2Amiga (date: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),a0
	move.l	UtilityBase,a6
	jsr	-$7E(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function CheckDate (date: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),a0
	move.l	UtilityBase,a6
	jsr	-$84(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function SMult32
		 (factor1,
		  factor2: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d1
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$8A(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function UMult32
		 (factor1,
		  factor2: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d1
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$90(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function SDivMod32
		 (dividend,
		  divisor: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d1
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$96(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function UDivMod32
		 (dividend,
		  divisor: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d1
	move.l	(a6)+,d0
	move.l	UtilityBase,a6
	jsr	-$9C(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function Stricmp
		 (string1,
		  string2: Pointer): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$A2(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
END;

Function Strnicmp
		 (string1,
		  string2: Pointer;
		  length: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	lea	$8(sp),a6
	move.l	(a6)+,d0
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	UtilityBase,a6
	jsr	-$A8(a6)
	move.l	d0,$14(sp)
	move.l	(sp)+,a6
END;

Function ToUpper (character: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),d0
	move.l	UtilityBase,a6
	jsr	-$AE(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

Function ToLower (character: LongInt): LongInt;
XASSEMBLER;
ASM	move.l	a6,-(sp)
	move.l	$8(sp),d0
	move.l	UtilityBase,a6
	jsr	-$B4(a6)
	move.l	d0,$C(sp)
	move.l	(sp)+,a6
END;

End.
