
; Int_eg1.s

; First the include files

		incdir		sys:include/
		include		exec/exec_lib.i		exec function defs
		include		intuition/intuition.i	int data defs
		include		intuition/intuition_lib.i int function defs


; Now for the program

;--------------	Open the Intuition library

		lea		intname,a1		a1->lib name
		moveq.l		#0,d0			any version
		CALLEXEC	OpenLibrary		and open it
		move.l		d0,_IntuitionBase	save base pointer
		beq		error			quit if no lib

;--------------	Open a window

		lea		MyWindow,a0		a0->New Window struct
		CALLINT		OpenWindow		and open it
		move.l		d0,window.ptr		ptr to Window struct
		beq		error1			quit if failed

;--------------	Obtain and save pointer to UserPort

		move.l		d0,a0
		move.l		wd_UserPort(a0),window.up

;--------------	Now the Event loop explained in the text

LOOP		move.l		window.up,a0		a0->Port
		CALLEXEC	WaitPort		wait for message
		move.l		window.up,a0		a0->Port
		CALLEXEC	GetMsg			get addr of msg
		move.l		d0,a1			a1->Message struct
		move.l		im_Class(a1),d5		d5=IDCMP flag
		CALLEXEC	ReplyMsg		answer Intuition

;--------------	Thats Intuition taken care of, now see what the message was

		cmpi.l		#CLOSEWINDOW,d5		close gadget ?
		bne		LOOP			loop back if not

;--------------	Well if we get this far the windows close gadget must have
;		been hit. Close the window.

		move.l		window.ptr,a0		a0->Window struct
		CALLINT		CloseWindow		and close it

;-------------- Now close Intuition library

error1		move.l		_IntuitionBase,a1	a1->lib base
		CALLEXEC	CloseLibrary		and close it

;--------------	All done so finish

error		rts					go home


;--------------
;-------------- Variables and data area
;--------------

intname		INTNAME

_IntuitionBase	dc.l		0

window.ptr	dc.l		0
window.up	dc.l		0

MyWindow	dc.w		0,10
		dc.w		640,189	
		dc.b		-1,-1
		dc.l		CLOSEWINDOW
		dc.l		WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIZEBRIGHT+ACTIVATE+NOCAREREFRESH
		dc.l		0	
		dc.l		0	
		dc.l		WindowName
		dc.l		0	
		dc.l		0	
		dc.w		50,50	
		dc.w		640,256	
		dc.w		WBENCHSCREEN

WindowName	dc.b		' Marks Window',0

