;This proggy opens an Intuition window and lets you move a cursor around in
;it. © M.Meany 1990

		opt 		o+,ow-

		incdir		"devmaster:include/"
		include		"exec/exec_lib.i"
		include		"exec/exec.i"
		include		"intuition/intuition_lib.i"
		include		"intuition/intuition.i"
		include		"graphics/gfx.i"
		include		"graphics/graphics_lib.i"

intopen		lea		intname,a1	a1-->library name
		moveq.l		#0,d0
		CALLEXEC	OpenLibrary	open this library
		move.l		d0,_IntuitionBase  store pointer to lib
		beq		quit_fast
	
		lea		grafname,a1	a1-->library name
		moveq.l		#0,d0
		CALLEXEC	OpenLibrary	open this library
		move.l		d0,_GfxBase	store pointer to lib
		beq		intclose

		lea		About_window,a0	a0-->window structure
		CALLINT		OpenWindow	open this window
		move.l		d0,window.ptr	save window pointer
		beq		gfxclose
		move.l		d0,a0
		move.l		wd_RPort(a0),window.rport

		bsr		printmsg
		bsr		printmsg1

WaitForMsg	move.l		window.ptr,a0	
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	WaitPort	wait for something to happen
		move.l		window.ptr,a0	a0-->window pointer
		move.l		wd_UserPort(a0),a0  a0-->user port
		CALLEXEC	GetMsg		get any messages
		tst.l		d0		was there a message ?
		beq		WaitForMsg	if not loop back
		move.l		d0,a1		a1-->message
		move.l		im_Class(a1),d2	d2=IDCMP flags
		move.w		im_Code(a1),d3	d3=key code or menu details
		move.l		im_IAddress(a1),d7
		CALLEXEC	ReplyMsg	answer os or it get angry
		cmp.l		#CLOSEWINDOW,d2	window closed ?
		beq		all_done
		cmp.l		#RAWKEY,d2	keyboard input ?
		bsr		got_key	
		bra		WaitForMsg

got_key		cmpi.l		#$80,d3
		bge		bad_key
		bsr		printmsg1
		cmpi.l		#$4f,d3
		bne.s		chk_right
		cmpi.w		#8,curX
		beq.		key_done
		sub.w		#8,curX
		bra		key_done
chk_right	cmpi.l		#$4e,d3
		bne.s		chk_up
		cmpi.w		#624,curX
		beq		key_done
		add.w		#8,curX
		bra		key_done
chk_up		cmpi.l		#$4c,d3
		bne.s		chk_down
		cmpi.w		#10,curY
		beq		key_done
		sub.w		#8,curY
		bra		key_done
chk_down	cmpi.b		#$4d,d3
		bne.s		insert
		cmpi.w		#162,curY
		beq		key_done
		add.w		#8,curY
key_done	bsr		printmsg1
bad_key		rts

insert		movea.l		window.rport,a1
		moveq.l		#-8,d0
		moveq.l		#0,d1
		move.l		d1,d2
		move.l		d2,d3
		move.w		curX,d2
		move.w		curY,d3
		move.l		#632,d4
		move.l		d3,d5
		add.l		#7,d5
		CALLGRAF	ScrollRaster
		move.l		#$4e,d3
		bra		chk_right

all_done	move.l		window.ptr,a0	a0-->window
		CALLINT		CloseWindow	close this window

gfxclose	move.l		_GfxBase,a1	a1-->library base address
		CALLEXEC	CloseLibrary	close this library

intclose	move.l		_IntuitionBase,a1  a1-->library base address
		CALLEXEC	CloseLibrary	close this library
		
quit_fast	rts		

*****************************************************************************
;                          SUBROUTINES

printmsg	lea		msg_text,a1	a1-->text structure
		move.l		window.ptr,a0	a0-->window
		move.l		50(a0),a0	
		moveq.l		#8,d0		x position of text
		move.l		linenum,d1	y position of text
		CALLINT		PrintIText	print the help message
		rts

printmsg1	lea		msg_text1,a1	a1-->text structure
		move.l		window.ptr,a0	a0-->window
		move.l		50(a0),a0	
		moveq.l		#0,d0
		move.l		d0,d1
		move.w		curX,d0		x position of text
		move.w		curY,d1		y position of text
		CALLINT		PrintIText	print the help message
		rts

*****************************************************************************
;			    VARIABLES


intname		dc.b	'intuition.library',0
		even
_IntuitionBase	dc.l	0

grafname	dc.b	'graphics.library',0
		even
_GfxBase	dc.l	0

window.ptr	dc.l	0
window.rport	dc.l	0

curX		dc.w	8
curY		dc.w	10

linenum		dc.l	10
msg_text	dc.b	2,2	colours to use
mode		dc.b	0	mode to use (normal)
		even
		dc.w	0,8	text position in window
		dc.l	0	font to use (standard)
msg.ptr		dc.l	msg1	pointer to text
		dc.l	0	end of text list

msg1		dc.b	'The alphabet : '
char		dc.b	32,0
		even

msg_text1	dc.b	3,2	colours to use
		dc.b	RP_COMPLEMENT	mode to use 
		even
		dc.w	0,0	text position in window
		dc.l	0	font to use (standard)
		dc.l	msg2	pointer to text
		dc.l	0	end of text list

msg2		dc.b	'_',0
		even

About_window	dc.w	0,11		window XY origin relative to TopLeft of screen
		dc.w		640,188		window width and height
		dc.b		0,1		detail and block pens
		dc.l		CLOSEWINDOW+RAWKEY		IDCMP flags
		dc.l		WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+SIZEBRIGHT+ACTIVATE+NOCAREREFRESH		other window flags
		dc.l		0		first gadget in gadget list
		dc.l		0		custom CHECKMARK imagery
		dc.l		WindowName		window title
		dc.l		0		custom screen pointer
		dc.l		0		custom bitmap
		dc.w		250,55		minimum width and height
		dc.w		640,256		maximum width and height
		dc.w		WBENCHSCREEN		destination screen type

WindowName	dc.b		'A68K Front End  © ACC 1990',0
		even


