	section	Mark,code_c
	opt	o+,ow-
	
; Intro1.0   : A smaller viewport that rolls the bitmap round and round. This
;              is going to be the first of three viewports displayed in this
;              view.
	
; Skull      : Same as Sanjay version but with my own GFX (320x500) covering
;              the full height of display.
;              Multitasking now disabled for smooth scrolling.

; Sanjay     : This is an adaption of the basic display routine. The bitplanes
;              are taller than the viewport, this allows a small vertical
;              scroll routine to 'bounce' the picture. This was written for
;              Slasher of Cryptic Uk and crunched using PowerPacker3.2.
;              M.Meany 6th July 1990.

; Version 1.3: System copper list now restored at end of program. Also
;              releases memory assigned for colour map, this was overlooked
;              in the earlier versions. Added easystart.i so program may be
;              run from the Workbench if given an icon. M.Meany July 1990.
	
; Version 1.2: picture is now centralised. This was necessary as the raw
;              data loaded into source did not cover all 320 horizontal
;              pixels.
	
; An attempt to use o/s to display my  own viewport. This routine works
; but the method of restoring the system copper list leaves a lot to
; be desired. It is necessary to click the mouse pointer into the drag
; bar of a window once the program has finished. This is made extremly
; diffecult because you cant see anything !   M.Meany  July 1990


	incdir	'df0:include/'
	include	'graphics/gfx.i'
	include	'graphics/gfxbase.i'
	include	'graphics/graphics_lib.i'
	include	'graphics/view.i'
	include	'exec/exec.i'
	include	'exec/exec_lib.i'
	include	'exec/execbase.i'
	include	'intuition/intuition_lib.i'
	include 'misc/easystart.i'
	

	CALLEXEC	Forbid

; Open the graphics library and store its base pointer

	moveq.l	#0,d0
	lea	GFXName,a1
	CALLEXEC	OpenLibrary
	move.l	d0,_GfxBase
	beq	error
	
; Get pointer to system copper list and save it for later

	move.l	d0,a0
	move.l	gb_ActiView(a0),oldcopper
	
; Initialise a View structure

	lea	my_view,a1
	CALLGRAF	InitView
	

; Initialise a View Port structure. This will be used to display my screen

	lea	my_viewport,a0
	CALLGRAF	InitVPort

; Link Viewport structure to the View structure.

	lea	my_view,a0
	move.l	#my_viewport,v_ViewPort(a0)

; Initialise a Bitmap structure

	lea	my_bitmap,a0
	moveq.l	#2,d0
	move.l	#320,d1
	move.l	#256,d2
	CALLGRAF	InitBitMap

; Link Bitmap structure to a RasInfo structure and set screen x & y offsets

	lea	my_rasinfo,a0
	move.l	#my_bitmap,ri_BitMap(a0)
	move.w	#0,ri_RxOffset(a0)
	move.w	#0,ri_RyOffset(a0)

; Link Rasinfo structure to the ViewPort structure and set
; DWidth and DHeight which define height of visible bitmap in the ViewPort.

	lea	my_viewport,a0
	move.l	#my_rasinfo,vp_RasInfo(a0)
	move.w	#320,vp_DWidth(a0)
	move.w	#28,vp_DHeight(a0)

; Initialise a structure for 4 local colours to be linked to this ViewPort.

	moveq.l	#4,d0
	CALLGRAF	GetColorMap

; Link ColourMap structure to ViewPort

	lea	my_viewport,a0
	move.l	d0,vp_ColorMap(a0)

; Copy colour values into this Structure using sys function.

	move.l	#my_colours,a1
	moveq.l	#4,d0
	CALLGRAF	LoadRGB4

; Compute bitplane pointers for all 5 bitplanes and write them 
; into the BitMap structure.

	lea	my_bitmap,a0
	adda.l	#bm_Planes,a0
	move.l	#pic,d0
	moveq.l	#1,d1
bpl_loop	move.l	d0,(a0)+
	add.l	#10240,d0
	dbra	d1,bpl_loop

; Get system to prepare display instructions for copper.

	lea	my_view,a0
	lea	my_viewport,a1
	CALLGRAF	MakeVPort

; Merge this list into a real copper list.

	lea	my_view,a1
	CALLGRAF	MrgCop

; Display this view.

	lea	my_view,a1
	CALLGRAF	LoadView
	
; Short routine to scroll up and down super bitmap
; d6 is used to flag up (=$ffff) or down (=0) scroll

	move.l	#my_viewport,a4
	move.l	#my_rasinfo,a5
	adda.l	#ri_RyOffset,a5
	moveq.l	#0,d6
		
scroll_loop	CALLGRAF	WaitTOF
	CALLGRAF	WaitTOF
	tst.w	d6
	bne.s	up
	bsr	scroll_down
	bra	mouse_test
up	bsr	top_of_bpln
	
mouse_test	btst	#6,$bfe001
	bne	scroll_loop
	
; Free up memory allocated to us

	lea	my_viewport,a0
	move.l	vp_ColorMap(a0),a0
	CALLGRAF	FreeColorMap
	lea	my_viewport,a0
	CALLGRAF	FreeVPortCopLists
	lea	my_view,a0
	move.l	v_LOFCprList(a0),a0
	CALLGRAF	FreeCprList
	
; Restore systems copper list.  

	move.l	oldcopper,a1
	CALLGRAF	LoadView
	
; Close the graphics library.

	move.l	_GfxBase,a1
	CALLEXEC	CloseLibrary

; All done so return to system.

	CALLEXEC	RethinkDisplay
	moveq.l	#0,d0	no error code
error	CALLEXEC	Permit
	rts
	
	
; Subroutines

; To scroll the viewport down

scroll_down	move.w	y_offset,d0
	move.w	d0,(a5)
	move.l	a4,a0
	CALLGRAF	ScrollVPort
	addi.w	#1,y_offset
	cmpi.w	#180,y_offset
	bne.s	still_down
	not.w	d6
still_down	rts

; To reset the y offset, ie back to start of picture

top_of_bpln	move.w	#0,(a5)
	move.l	a4,a0
	CALLGRAF	ScrollVPort
	move.w	#0,y_offset
	not.w	d6
	rts


; Program data defenition area. Note that all _SIZEOF equates
; are defined in the DevPacII include files.
	
	even
my_view	ds.b	v_SIZEOF
	even
my_viewport	ds.b	vp_SIZEOF
	even
my_rasinfo	ds.b	ri_SIZEOF
	even
my_bitmap	ds.b	bm_SIZEOF
	even
	
GFXName	dc.b	'graphics.library',0
	even
_GfxBase	dc.l	0
oldcopper	dc.l	0
y_offset	dc.w	0

; Read in raw data from disk ( 2 bitplanes 320x256 display ).
	
pic	incbin	'source_2:bitmaps/greets.bm'
	even	
my_colours	include	'source_2:source/greets.col'
	even
