; dthook.asm
; Datatype hook function for the Be DataType descriptor.
; Written by Edmund Vermeulen <edmundv@grafix.xs4all.nl>.
;
; Load it in DTDesc through the 'Load Function...' menu to create the
; Be DataType descriptor.

	include	"libraries/dos.i"
	include	"datatypes/datatypes.i"

 STRUCTURE BeHeader,0
   LONG	 be_left
   LONG	 be_top
   LONG	 be_right
   LONG  be_bottom
   LONG  be_color_space
   LONG  be_size
   LABEL be_SIZEOF

B_COLOR_8_BIT equ 4
B_RGB_32_BIT  equ 8

	section code
; a0 comes initialised with a pointer to a DTHookContext struct
	cmpi.l	#be_SIZEOF,dthc_BufferLength(a0)
	blt.s	false
	move.l	dthc_Buffer(a0),a1	; pointer to buffer in a1

	cmpi.l	#B_COLOR_8_BIT,be_color_space(a1)
	beq.s	check
	cmpi.l	#B_RGB_32_BIT,be_color_space(a1)
	beq.s	check

false	moveq	#0,d0			; FALSE
	rts				; short way out of here

; some extra checks to make sure that it is a Be screen dump
check	move.l	be_right(a1),d0
	sub.l	be_left(a1),d0
	blt.s	false			; negative width
	cmpi.l	#65535,d0
	bge.s	false			; width larger than a word

	move.l	be_bottom(a1),d0
	sub.l	be_top(a1),d0
	blt.s	false			; negative height
	cmpi.l	#65535,d0
	bge.s	false			; height larger than a word

	moveq	#be_SIZEOF,d0		; header size in d0
	add.l	be_size(a1),d0		; add bitmap size
	move.l	dthc_FIB(a0),a1		; pointer to FIB in a1
	cmp.l	fib_Size(a1),d0		; compare with file size
	bne.s	false

	moveq	#1,d0			; TRUE
	rts

verstr	dc.b	'$VER: BE 43.1 (27.11.96)',0
	end
