	opt	l+,o+

; ----------------------------------------------------------
; --                Assembler Image Demo                  --
; ----------------------------------------------------------
; -- Author    : Roger Fischlin                           --
; -- Copyright : Public Domain                            --
; -- Assembler : DevPac Assembler V2.11                   --
; ----------------------------------------------------------
; -- create linkable code and link objectfile & "Fish.o". --
; ----------------------------------------------------------

	INCDIR	"dh1:include/"

	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"intuition/intuition_lib.i"
	INCLUDE	"intuition/intuition.i"


WIDTH	equ	132	; taken from 'SAVE' requester
HEIGHT	equ	57

	XREF	_ImageData

	Section	"",CODE

; ---------------- include startup code  ----------------

	INCLUDE	"misc/easystart.i"

; ------------ open "intuition.library" V33 -------------

	lea.l	IntName,a1
	moveq.l	#33,d0
	move.l	4.w,a6
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,a5
	tst.l	d0
	bne.s	OpenWd
	moveq.l	#20,d0	; fatal error !
	rts

; -------------------- open window ---------------------

OpenWd	lea.l	NWindow,a0
	exg	a6,a5	; use IntuitionBase
	jsr	_LVOOpenWindow(a6)
	exg	a6,a5
	move.l	d0,a4
	tst.l	d0	; error ?
	beq.s	CloseInt

; ------------------ draw image -----------------------

DrawImage	move.l	wd_RPort(a4),a0
	lea.l	Bild,a1
	moveq.l	#0,d0
	moveq.l	#0,d1
	move.b	wd_BorderLeft(a4),d0
	move.b	wd_BorderTop(a4),d1
	addq.w	#8,d0
	addq.w	#4,d1
	exg	a6,a5	; use IntuitionBase
	jsr	_LVODrawImage(a6)
	exg	a6,a5

; ---------------------- wait -------------------------

Wait	move.l	wd_UserPort(a4),a2
	move.l	a2,a0
	jsr	_LVOWaitPort(a6)
	move.l	a2,a0
	jsr	_LVOGetMsg(a6)
	tst.l	d0
	beq.s	Wait
	move.l	d0,a1
	move.l	im_Class(a1),d2; get Class
	jsr	_LVOReplyMsg(a6)
	cmp.l	#CLOSEWINDOW,d2
	beq.s	CloseWd	; CLOSEWINDOW -> close window
	cmp.l	#NEWSIZE,d2
	beq.s	DrawImage	; NEWSIZE -> draw image again
	bra.s	Wait
	

; ------------------- close window ---------------------

CloseWd	move.l	a4,a0
	exg	a6,a5	; use IntuitionBase
	jsr	_LVOCloseWindow(a6)
	exg	a6,a5
	
; ------------ close "intuition.library" ---------------

CloseInt	move.l	a5,a1
	jsr	_LVOCloseLibrary(a6)
	moveq.l	#0,d0
	rts

; ------------------ data section ----------------------

	Section	"",DATA

IntName	DC.B	"intuition.library",0
	EVEN

NWindow	DC.W	20,20,WIDTH+40,HEIGHT+20
	DC.B	-1,-1
	DC.L	CLOSEWINDOW!NEWSIZE
	DC.L	WINDOWSIZING!WINDOWDRAG!WINDOWDEPTH!WINDOWCLOSE!SMART_REFRESH!ACTIVATE
	DC.L	0,0,Title
	DC.L	0,0
	DC.W	WIDTH+40,HEIGHT+20,-1,-1
	DC.W	WBENCHSCREEN

Title	DC.B	"Assembler-Image-Demo",0
	EVEN
	
Bild	DC.W	0,0,WIDTH,HEIGHT,2
	DC.L	_ImageData
	DC.B	1+2,0
	DC.L	0

