PrintFGad	* Prints a printf()-style string into a text display gadget.
		* STACK-PARAMETERS:
		* *stringgadget (<<- this at last)
		* *string	(<<- then this
		* datastream	(<<- put these first)
		tst.l	window-j(a5)
		beq.s	.not
		movem.l	a6/a2/a3,-(sp)
		move.l	4.w,a6
		lea	6*4(sp),a1
		move.l	5*4(sp),a0
		lea	.routine(pc),a2
		lea	buf1,a3
		move.l	a3,.pt-j(a5)
		LIBCALL	RawDoFmt
		move.l	.pt(pc),a3
		clr.b	(a3)
		move.l	gadbase-j(a5),a6
		move.l	4*4(sp),a0
		move.l	window(pc),a1
		sub.l	a2,a2
		lea	.set(pc),a3
		LIBCALL	GT_SetGadgetAttrsA
		movem.l	(sp)+,a6/a2/a3
.not		rts
.routine	move.l	.pt(pc),a3
		move.b	d0,(a3)+
		move.l	a3,.pt
		rts
.pt		dc.l	0
.set		dc.l	GTTX_Text,buf1
		dc.l	TAG_DONE

FindChunk	* Finds a chunk in specified memory range.
		* a0 *current chunk
		* a1 *end of mem
		* d1 name of chunk to search for
		* RETURNS d0 *new chunk or NULL !
		* a1 is not changed !!
		move.l	d2,-(sp)
		moveq	#0,d0
.loop		cmp.l	(a0),d1
		beq.s	.found
		move.l	4(a0),d2
		addq.l	#1,d2
		and.w	#$fffe,d2
		add.l	d2,a0
		addq.w	#8,a0
		cmp.l	a1,a0
		bcs.s	.loop
		sub.l	a0,a0
.found		move.l	a0,d0
		move.l	(sp)+,d2
		rts

DecrunchBODY	* Decrunches a BODY chunk.
		* a0 *BODY chunk
		* a1 *destination mem
		* a2 *end of destination mem
		move.l	#ftype_ilbm1,current_ftype-j(a5)
		addq.w	#8,a0
.db1loop	cmp.l	a2,a1
		bcc.s	.ende
		moveq	#0,d0
		move.b	(a0)+,d0
		bmi.s	.db1gep
.db1nichtgep	move.b	(a0)+,(a1)+
		dbra	d0,.db1nichtgep
		bra.s	.db1loop
.db1gep		neg.b	d0
		move.b	(a0)+,d1
.db1gep1	move.b	d1,(a1)+
		dbra	d0,.db1gep1
		bra.s	.db1loop
.ende		rts

GetILBMData	* Extracts Picture Data from a BMHD chunk.
		* a0 *BMHD chunk
		* RETURNS d0 pagesize (upper word X lower Y) X rounded16
		*	  d1 depth
		*	  d2 1->maskplane 0->not
		*	  d3 1->byterun1 0->nothing
		*	  d4 org. pagesize X (not rounded)
		move.w	8(a0),d4
		move.w	d4,d0
		add.w	#$f,d0
		and.w	#$fff0,d0
		swap	d0
		move.w	10(a0),d0
		moveq	#0,d1
		move.b	16(a0),d1
		moveq	#0,d2
		move.b	17(a0),d2
		and.b	#1,d2
		moveq	#0,d3
		move.b	18(a0),d3
		rts

SetCycleGadget	* Sets Cycle Gadget
		* a0 *gadget
		* d0.w number
		tst.l	window-j(a5)
		beq.s	.not
		movem.l	a2/a3/a6,-(sp)
		move.l	gadbase-j(a5),a6
		lea	.sgt_cycle(pc),a3
		move.w	d0,6(a3)
		move.l	window(pc),a1
		sub.l	a2,a2
		LIBCALL	GT_SetGadgetAttrsA
		movem.l	(sp)+,a2/a3/a6
.not		rts
.sgt_cycle	dc.l	GTCY_Active,0
		dc.l	TAG_DONE

SetIntGadget	* Sets Integer Gadget
		* a0 *gadget
		* d0.l number
		tst.l	window-j(a5)
		beq.s	.not
		movem.l	a2/a3/a6,-(sp)
		move.l	gadbase-j(a5),a6
		lea	.sgt_int(pc),a3
		move.l	d0,4(a3)
		move.l	window(pc),a1
		sub.l	a2,a2
		LIBCALL	GT_SetGadgetAttrsA
		movem.l	(sp)+,a2/a3/a6
.not		rts
.sgt_int	dc.l	GTIN_Number,0
		dc.l	TAG_DONE

MakeColorTable	* Makes a color table.
		* d2 = 0 --> convert IFF CMAP (24-bit) data
		*    = 1 --> copy 96-bit color table
		* a1 *source data
		* d0 num colors
		* Returned color table is to be freed by FreeVec.
		* RETURNS d0 *colortable
		*	  d1 colortablelength
		movem.l	a2-a6/d2-d7,-(sp)
		movem.l	d0/a1,-(sp)
		mulu	#12,d0
		addq.l	#8,d0
		move.l	d0,d7		; [d7] colortablelength
		moveq	#MEMF_PUBLIC,d1
		move.l	4.w,a6
		LIBCALL	AllocVec
		move.l	d0,d6		; [d6] colortable
		movem.l	(sp)+,d0/a1

		tst.l	d6
		bne.s	.666
		moveq	#0,d0
		movem.l	(sp)+,a2-a6/d2-d7
		rts

.666		move.l	d6,a0
		move.w	d0,(a0)+
		clr.w	(a0)+
		subq.w	#1,d0
		tst.w	d2
		beq.s	.24bit
.96bit		move.l	(a1)+,(a0)+
		move.l	(a1)+,(a0)+
		move.l	(a1)+,(a0)+
		dbra	d0,.96bit
		bra.s	.cont
.24bit		bsr.s	.sub
		bsr.s	.sub
		bsr.s	.sub
		dbra	d0,.24bit
.cont		clr.l	(a0)+
		move.l	d6,d0
		move.l	d7,d1
		movem.l	(sp)+,a2-a6/d2-d7
		rts
.sub		move.b	(a1)+,d1
		move.b	d1,(a0)+
		move.b	d1,(a0)+
		move.b	d1,(a0)+
		move.b	d1,(a0)+
		rts

ChangeGadMode	* Changes Gadget Mode (Enabled/Disabled)
		* only for Gadgets of the Main Window !!!!
		* a0 *gadget
		* d0 0 or 1
		movem.l	a6/a2/a3,-(sp)
		tst.l	window
		beq.s	.not
		move.l	gadbase(pc),a6
		move.l	window(pc),a1
		sub.l	a2,a2
		lea	sgt_disable(pc),a3
		move.w	d0,6(a3)
		LIBCALL	GT_SetGadgetAttrsA
.not		movem.l	(sp)+,a6/a2/a3
		rts

long2hex	;konvertiert LONG in d0 in HEX-String nach (a0)+
		moveq	#7,d1
.1		rol.l	#4,d0
		move.b	d0,d2
		and.b	#$f,d2
		add.b	#48,d2
		cmp.b	#58,d2
		bcs.s	.2
		addq.b	#7,d2
.2		move.b	d2,(a0)+
		dbra	d1,.1
		rts

hex2long	; a0 *String (Hex-Number) terminated by any other char.
		; RETURNS d0.l Number converted
		moveq	#0,d0
.loop		move.b	(a0)+,d1
		sub.b	#"0",d1
		bmi.s	.end
		cmp.b	#9,d1
		bls.s	.ok1
		bclr	#5,d1
		subq.b	#7,d1
		cmp.b	#15,d1
		bhi.s	.end
.ok1		rol.l	#4,d0
		or.b	d1,d0
		bra.s	.loop
.end		rts

LockWindow	;a0 *window
		move.l	intbase-j(a5),a6
		lea	lockswtags(pc),a1
		LIBJMP	SetWindowPointerA
UnlockWindow	;a0 *window
		move.l	intbase-j(a5),a6
		lea	unlockswtags(pc),a1
		LIBJMP	SetWindowPointerA
lockswtags	dc.l	WA_BusyPointer,1
		dc.l	TAG_DONE
unlockswtags	dc.l	WA_Pointer,0
		dc.l	TAG_DONE


