	section	lard,code
	opt	c+
	opt	d+

code:	IncDir	"DH0:Include/"
	Include	Intuition/Intuition.I
	Include	Intuition/Intuition_Lib.I
	Include	Libraries/dos_LIb.i
	Include	Libraries/Dos.i
	Include	Exec/Exec_Lib.I
	Include	Exec/Exec.I
	Include	Graphics/GfxBase.I
	Include	Graphics/Graphics_Lib.I
	Include	Graphics/Display.I

	;Include	Misc/EasyStart.i

CINIT	MACRO
	move.l	\1,a0
	move.l	#\2,d0
	CALLGRAF	UCopperListInit	
	ENDM

CMOVE	MACRO
	move.l	\1,a1
	move.w	\2,d0
	move.w	\3,d1
	CALLGRAF	CMove
	move.l	\1,a1
	CALLGRAF	CBump	
	ENDM

CWAIT	MACRO
	move.l	\1,a1
	move.w	\2,d0
	move.w	\3,d1
	CALLGRAF	CWait
	move.l	\1,a1
	CALLGRAF	CBump	
	ENDM

CEND	MACRO
	move.l	\1,a1
	move.w	#10000,d0
	move.w	#255,d1
	CALLGRAF	CWait
	move.l	\1,a1
	CALLGRAF	CBump	
	ENDM

	*-----------------*

	Lea	GFXName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l 	D0,_GfxBase
	Beq	Error

	Lea	DosName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l 	D0,_DOSBase
	Beq	Error

	Lea	IntName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l	D0,_IntuitionBase
	Beq	Error

	*-----------------------------------------------*

	Lea	MyScreen,a0
	CALLINT	OpenScreen
	Move.l	D0,_MyScrBase
	Beq	CloseInt

	Lea	MyWindow,a0
	move.l	d0,nw_Screen(a0)
	CALLINT	OpenWindow
	Move.l	D0,_MyWinBase
	Beq	CloseInt
	Move.l	D0,A0
	Move.l	wd_RPort(A0),_MyWinRPort
	Move.l	wd_UserPort(a0),_MyWinUserPort

	*-----------------------------------------------*

	move.l	#ucl_SIZEOF,d0
	move.l	#MEMF_PUBLIC+MEMF_CLEAR,d1
	CALLEXEC	AllocMem
	move.l	d0,MyCopper

	*-------------------*

	CINIT 	MyCopper,5000

	lea	CopperList,a5

.loop	movem.w	(a5)+,d0-d1
	bsr	CopCom
	
	cmp.w	#$ffff,0(a5)
	bne	.loop
	
	CEND	MyCopper

	*-------------------*

	CALLEXEC	Forbid

	Move.l	_MyWinBase,a0
	CALLINT	ViewPortAddress
	move.l	d0,a1	
	move.l	MyCopper,vp_UCopIns(a1)		;viewPort->UCopIns=uCopList

	CALLEXEC	Permit
	CALLINT	RethinkDisplay

	*-----------------------------------------------*

.WaitLoop	Move.l	_MyWinUserPort,A0
	CALLEXEC	WaitPort
	Move.l	_MyWinUserPort,A0
	CALLEXEC	GetMsg
	Move.l	D0,A1
	Move.l	im_Class(A1),D2	;D2=IDCMP Flags Directly
	Move.w	im_Code(A1),D3	;D3=Data ie key why class=Rawkey
	Move.w	im_Qualifier(A1),D4	;D4=things like CTRL SHIFT
	Move.w	im_MouseX(a1),D5	;D5=MouseX Coordinate
	Move.w	im_MouseY(a1),D6	;D5=MouseY Coordinate
	Move.l	im_IAddress(A1),D7	;D7=Addres of Intuition Obj ie Gadget
	Movem.l	D0-D7/A0-A6,-(A7)	
	CALLEXEC	ReplyMsg
	Movem.l	(a7)+,D0-D7/A0-A6

	Cmp.l	#CLOSEWINDOW,D2
	bne	.WaitLoop
	
	*-------------------------------*

	Move.l	_MyWinBase,a0
	CALLINT	ViewPortAddress
	move.l	d0,a0
	CALLGRAF	FreeVPortCopLists
	CALLINT	RethinkDisplay

	Move.l	_MyWinBase,A0
	CALLINT	CloseWindow

	Move.l	_MyScrBase,A0
	CALLINT	CloseScreen

	*-------------------------------*
	
CloseInt	Move.l	_IntuitionBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_GfxBase,A1
	CALLEXEC	CloseLibrary

	*-------------------------------*

Error	Moveq	#0,D0
	Rts

	*-------------------------------*

CopCom:	btst	#0,d0
	beq	.move

	move.w	d0,d1
	and.l	#$000000ff,d1
	lsr.w	#8,d0
	
	CWAIT 	MyCopper,d0,d1
	rts
	
.move    	CMOVE	MyCopper,d0,d1
	rts
		
	*-------------------------------*

_MyScrBase		Dc.l	0

_MyWinBase		Dc.l	0
_MyWinRPort		Dc.l	0
_MyWinUserPort	Dc.l	0
_MyWinVPort		Dc.l	0

_IntuitionBase	Dc.l	0
_DOSBase		Dc.l	0
_GfxBase		dc.l	0

GFXName		GRAFNAME
IntName		INTNAME
DosName		DOSNAME
		even

	
**************************************************

MyScreen:	dc.w	0,0
	dc.w	640,200
	dc.w	2
	dc.b	0,1
	dc.w	V_HIRES
	dc.w	CUSTOMSCREEN+SCREENQUIET
	dc.l	0
	dc.l	NewScreenName
	dc.l	0
	dc.l	0
NewScreenName:
	dc.b	'Lard',0
	cnop 0,2

MyWindow:
	dc.w	34,25
	dc.w	522,135
	dc.b	0,1
	dc.l	CLOSEWINDOW
	dc.l	WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH
	dc.l	0
	dc.l	0
	dc.l	NewWindowName1
	dc.l	0
	dc.l	0
	dc.w	5,5
	dc.w	-1,-1
	dc.w	CUSTOMSCREEN
NewWindowName1:
	dc.b	'Lard',0
	cnop 0,2


; end of PowerWindows source generation
	

**************************************************

MyCopper:	dc.l	0
	
CopperList:		dc.w	$0007,$fffe,$180,$f44
		dc.w	$0107,$fffe,$180,$aaa

		dc.w	$180,$aaa
		dc.w	$182,$000
		dc.w	$184,$fff
		dc.w	$186,$68b

		dc.w	$c807,$fffe,$180,$f44
		dc.w	$c907,$fffe,$180,$aaa

		dc.w	$ffff,$fffe	; end of copper list


	
	end



