		OPT	D+,C+

* Initialize stuff:
		BSR	START

* A5 now points to the screen base.
* Your code goes here:





* (End of your code.)
* Look for "Return":
		LEA	Variables(PC),A5
wait		BSR	Get_Key
		BEQ.S	wait		no key
		CMP.B	#13,D2		Return?
		BNE.S	wait		no
* Termonate:
		BRA	END
*
* Initialize:
START		LEA	Variables(PC),A5
* Open Intuition library:
	 	LEA	Intuition_Name(PC),A1
   		MOVEQ 	#0,D0		open the
   		MOVEA.L	4.W,A6		exec library
   		JSR 	-408(A6)	now
   		MOVE.L	D0,(A5)		store base address
* Allocate screen memory:
		MOVE.L	#32000,D0	this many bytes
		MOVE.L	#$10002,D1	clear chip memory
		JSR	-198(A6)	AllocMem
		MOVE.L	D0,4(A5)	screen ptr
		BEQ	insufficient_memory
* Set up 320*20 pixels, 4 plane display:
		LEA	Graphics_Name(PC),A1
		MOVEQ	#0,D0
		JSR	-408(A6)
		MOVE.L	D0,8(A5)	graphics library
*
		MOVEA.L	D0,A6
		LEA	Bit_Map(PC),A0
		MOVEQ	#4,D0		bit plane depth
		MOVE.L	#320,D1		width
		MOVE.L	#200,D2		height
		JSR	-390(A6)	Init Bit Map
* Open screen:
		MOVEA.L	4(A5),A0	screen ptr
		LEA	Bit_Map+8(PC),A1
		MOVE.L	A0,(A1)+	plane 1 ptr
		LEA	8000(A0),A0
		MOVE.L	A0,(A1)+	plane 2 ptr
		LEA	8000(A0),A0
		MOVE.L	A0,(A1)+	plane 3 ptr
		LEA	8000(A0),A0
		MOVE.L	A0,(A1)		plane 4 ptr
*
		LEA	Demo_Screen(PC),A0
		MOVEA.L	(A5),A6		intuition library
		JSR	-198(A6)	OpenScreen
		MOVE.L	D0,12(A5)
* tell window about screen:
		LEA	Where(PC),A0
		MOVE.L	D0,(A0)
* Open window:
		LEA	Demo_Window(PC),A0
		JSR	-204(A6)	OpenWindow
		MOVE.L	D0,16(A5)	my display
* Screen to front:
		MOVEA.L	12(A5),A0
		JSR	-252(A6)	ScreenToFront
* Get screen base ptr:
		MOVEA.L	4(A5),A5
		RTS
*
* Terminate:
END		MOVEA.L	(A5),A6		intuition library
* Close window:
		MOVEA.L	16(A5),A0
		JSR	-72(A6)		CloseWindow
* Close screen:
		MOVEA.L	12(A5),A0	screen ptr
		MOVEA.L	(A5),A6		intuition library
		JSR	-66(A6)		CloseScreen
* Deallocate (screen) memory:
		MOVEA.L	4.W,A6		exec library
		MOVEA.L	4(A5),A1	base ptr
		MOVE.L	#32000,D0	byte size
		JSR	-210(A6)	FreeMem
*
insufficient_memory
		MOVEQ	#0,D0
		RTS
*
* Routine to get a key. Returns Z set if no key found
* else key code in D2.
Get_Key		MOVEA.L	4.W,A6		exec
		MOVEA.L	16(A5),A2	window structure
		MOVEA.L	86(A2),A0	ptr to user port
		JSR	-372(A6)	GetMsg
		TST.L	D0		anything there?
		BEQ.S	key_done	no
		MOVEA.L	D0,A1
		MOVE.L	14+6(A1),D1	message type
		MOVE	14+6+4(A1),D2	specifier (char code etc)
		MOVE.L	D1,D3
		JSR	-378(A6)	ReplyMsg
		CMP.L	#$40000,D3
		BEQ.S	Get_Key
		CMP.L	#$80000,D3
		BEQ.S	Get_Key
key_done	RTS
*
*
Intuition_Name	DC.B 	"intuition.library",0
		EVEN
Graphics_Name	DC.B	"graphics.library",0
		EVEN
*
Demo_Screen 	DC.W 	0
   		DC.W 	0
   		DC.W 	320
   		DC.W 	200
   		DC.W 	4
   		DC.B 	0
   		DC.B 	3
   		DC.W 	0
   		DC.W 	$4F		CUSTBITMAP/CUSTOMSCREEN
   		DC.L 	0
   		DC.L 	0
   		DC.L 	0
   		DC.L 	Bit_Map
   		
Bit_Map		DS.W	1
		DS.W	1
		DS.B 	1
		DS.B	1
		DS.W	1
		DS.L	8
*
Demo_Window 	DC.W 	0
   		DC.W 	12
   		DC.W 	320
   		DC.W 	188
   		DC.B 	0
   		DC.B 	0
   		DC.L 	$2C0000		request for vanilla keys/active
   		DC.L 	$11D00		trap rmb
   		DC.L 	0
   		DC.L 	0
   		DC.L 	0
Where 		DC.L 	0
   		DC.L 	0
   		DC.W 	0
   		DC.W	0
   		DC.W 	0
   		DC.W 	0
   		DC.W 	$F		CUSTOMSCREEN
*		
*								      offset
Variables	DS.L	1	intuition library ptr			  0
		DS.L	1	screen ptr				  4
		DS.L	1	graphics ligrary ptr			  8
		DS.L	1	my screen				 12
		DS.L	1	my display				 16

