
; This program was written to display an IFF picture with a bit of
; effect. This was meant for video titles, before the film starts.
; All it does is load an IFF picture, removes all the compression,
; sets up the copper list to display another memory area and then
; quickly poke the picture into that area while it is being shown.
; It does this by drawing every scanline on every line before it,
; ie. the bottom (256th) line, is drawn all the way down, then the
; 255th is drawn on 255 lines, 254th on 254 lines and so on.
; It waits for a left mouse button press before and after display,
; so you get a chance to set your video recording/stop it.
; I hope you find this mildly useful.
;PS. All good programmers, this was written years ago, and was 
;part of a much longer program which loaded a batchfile of ppacked
;pictures and displayed them one at a time. You may therefore find
;odd bits which don't seem to serve any purpose. These are probably
;bits of the old program, which I missed when deleting. Sorry.

		SECTION COPTEST,CODE_C   

OpenLib      equ -552  	;I put all these equs in so that I don't
CloseLib     equ -414  	;have to copy all the include files onto
open		=-30	;every work disk. If you have one drive
close		=-36	;you might appreciate this.
mode_old	=1005	
read		=-42
write		=-48
execute		=-222
Bpl1pth		=$e0
Bpl1ptl		=$e2
Bpl2pth		=$e4
Bpl2ptl		=$e6
Bpl3pth		=$e8
Bpl3ptl		=$ea
Bpl4pth		=$ec
Bpl4ptl		=$ee
Bpl5pth		=$f0
Bpl5ptl		=$f2
bplcon0		=$100
bplcon1		=$102
diwstart	=$8e
diwstop		=$90
ddfstart	=$92
ddfstop		=$94
spr0pth		=$120
spr0ptl		=$122
spr1pth		=$124
spr1ptl		=$126
spr2pth		=$128
spr2ptl		=$12a
spr3pth		=$12c
spr3ptl		=$12e
spr4pth		=$130
spr4ptl		=$132
spr5pth		=$134
spr5ptl		=$136
spr6pth		=$138
spr6ptl		=$13a
spr7pth		=$13c
spr7ptl		=$13e
col0		=$180
col1		=$182
col2		=$184
col3		=$186
col4		=$188
col5		=$18a
col6		=$18c
col7		=$18e
col8		=$190
col9		=$192
col10		=$194
col11		=$196
col12		=$198
col13		=$19a
col14		=$19c
col15		=$19e
col16		=$1a0
col17		=$1a2
col18		=$1a4
col19		=$1a6
col20		=$1a8
col21		=$1aa
col22		=$1ac
col23		=$1ae
col24		=$1b0
col25		=$1b2
col26		=$1b4	;You could delete a few of these colours
col27		=$1b6	;if you only intend having a 3 or 4 plane
col28		=$1b8	;picture.
col29		=$1ba
col30		=$1bc
col31		=$1be	

		move.l $4,a6
		lea dosname,a1
		moveq.l #0,d0
		jsr openlib(a6)
		move.l d0,dosbase
		beq BasicError
		
		move.l #plane1,d0	;Initialise Bitplane
		move.w d0,bp1l		;pointers
		swap d0
		move.w d0,bp1h
		move.l #plane2,d0
		move.w d0,bp2l
		swap d0
		move.w d0,bp2h
		move.l #plane3,d0
		move.w d0,bp3l
		swap d0
		move.w d0,bp3h
		move.l #plane4,d0
		move.w d0,bp4l
		swap d0
		move.w d0,bp4h
		move.l #plane5,d0
		move.w d0,bp5l
		swap d0
		move.w d0,bp5h

		Move.l $4,a6   		;Get Copper List
		Lea GFXNAME,a1   	;From library
		Moveq #0,d0   		
		jsr OpenLib(a6)   	
		Move.l d0,a1   		
		Move.l 38(a1),OLD	;Save OLD list
		Move.l $4,a6   		
		jsr CloseLib(a6) 		

		Move.l #NEW,$dff080 	;Insert our NEW list

		move.l #mode_old,d2	;Load IFF from disk
		move.l #filename,d1	;into this program.
		bsr openfile
		beq error
		move.l #plane6,d2
		bsr readdata
		move.l d0,d6
		bsr closefile
		
LOOP:    	btst #10,$dff016
		beq Error
		btst #6,$bfe001		;Mouse Wait to show   	
      		bne.s LOOP		;the picture.

NoMouse:	lea.l Plane1,a0		;This blanking the planes
		bsr BlankAPlane		;isn't strictly necessary,
		lea.l Plane2,a0		;but if you want to display
		bsr BlankAPlane		;more pictures, this should
		lea.l Plane3,a0		;be done in between.
		bsr BlankAPlane
		lea.l Plane4,a0
		bsr BlankAPlane
		lea.l Plane5,a0
		bsr BlankAPlane	

		moveq.l #0,d0
		lea.l plane6+28,a0
		move.b (a0),d0
		beq error
		move.b d0,planes
		lsl.l #4,d0
		ori.b #$02,d0
		move.b d0,noofbps	;pokes the number of bit
					;planes into Bplcon0 in the
					;copper list.
		
		bsr FindFORM		
		add.l #48,a0
		lea.l colour0,a1
		moveq.l #0,d7
		moveq.l #1,d6
		move.b noofbps,d7
		lsr.b #4,d7
NoColsLoop	lsl.b #1,d6
		subq.l #1,d7
		bne.s NoColsLoop
		move.l d6,d7
		bsr FindCMAP
		add.l #4,a0
CMAPloop	moveq.l #0,d0		;This bit pokes all the
		moveq.l #0,d1		;colours in the copper
		move.b (a0)+,d0		;list.
		lsl.l #4,d0
		move.b (a0)+,d0
		move.b (a0)+,d1
		lsr.l #4,d1
		or.b d1,d0
		move.w d0,(a1)+
		add.l #2,a1
		subq.l #1,d7
		bne.s CMAPloop
		
		bsr findBODY		;Data address in a0

		move.l a0,d5
		move.l (a0)+,d7
		add.l d7,d5		;Put end address in d5

		lea.l plane1b,a1	;This bit actually uncodes
		lea.l plane2b,a2	;the Iff picture data,
		lea.l plane3b,a3	;taking out all the runbyte
		lea.l plane4b,a4	;compression and making
		lea.l plane5b,a5	;straight bitmaps out of
PlaneLoop:	cmp.l d5,a0		;the Iff BODY part.
		bge.s DoTotal
		move.l a1,a6
		bsr DoAPlane
		move.l a6,a1
		cmp.b #2,planes
		blt.s PlaneLoop	
		move.l a2,a6
		bsr DoAPlane
		move.l a6,a2
		cmp.b #3,planes
		blt.s PlaneLoop
		move.l a3,a6
		bsr DoAPlane
		move.l a6,a3
		cmp.b #4,planes
		blt.s PlaneLoop
		move.l a4,a6
		bsr DoAPlane
		move.l a6,a4
		cmp.b #5,planes
		blt.s PlaneLoop
		move.l a5,a6
		bsr DoAPlane
		move.l a6,a5
		bra.s PlaneLoop	
				
DoTotal:	bsr TotalRecall		;Call the display effect.

MouseWait2	btst #6,$bfe001		;Mouse Wait to return   	
      		bne.s MouseWait2	;to DOS.

error:		move.l OLD,$dff080	;Put old copper list back.
BasicError:   	rts      		;Return to DOS

;********************Ending Point**********************

DoAPlane:	moveq.l #0,d4		;This bit unpacks a plane
DoMore:		moveq.l #0,d6		;of BODY data at a time.
		move.b (a0)+,d6
		bpl DoVerb
		bsr Replicate
		bra.s DoneDupl
DoVerb		bsr Verbatim
DoneDupl	cmp.l #40,d4
		blt.s DoMore
		rts

Verbatim:	addq.b #1,d6		;Verbatim means copy 
VerbLoop:	move.b (a0)+,(a6)+	;direct. It does.
		addq.l #1,d4
		subq.b #1,d6
		bne.s VerbLoop
		rts

Replicate:	cmp.b #128,d6		;Replicate copies a
		beq.s DoneRep		;string of data a 
Not128:		neg.b d6		;certain amount of
		addq.b #1,d6		;times, specified
		cmp.b #128,d6		;in the BODY data.
		beq.s DoneRep		;This is the bit
		move.b (a0)+,d0		;which uncompresses
Reploop:	move.b d0,(a6)+		;runbyte compression.
		addq.l #1,d4
		subq.b #1,d6
		bne.s RepLoop
DoneRep:	rts
		
FindBODY:	lea.l plane6,a0		;This searches for
FBLoop:		cmp.b #66,(a0)+		;the ASCII "BODY"
		bne.s FBloop		;in the IFF data.
		cmp.b #79,(a0)+
		bne.s FBloop
		cmp.b #68,(a0)+
		bne.s FBloop
		cmp.b #89,(a0)+
		bne.s FBloop
		rts

FindCMAP:	lea.l plane6+38,a0	;This searches for
FMAPLoop:	cmp.b #67,(a0)+		;the ASCII "CMAP"
		bne.s FMAPLoop		;in the IFF data.
		cmp.b #77,(a0)+
		bne.s FMAPLoop
		cmp.b #65,(a0)+
		bne.s FMAPLoop
		cmp.b #80,(a0)+
		bne.s FMAPLoop
		rts

FindFORM:	lea.l plane6,a0		;This searches for
FormLoop:	cmp.b #70,(a0)+		;the ASCII "FORM"
		bne.s FORMLoop		;in the IFF data.
		cmp.b #79,(a0)+
		bne.s FORMLoop
		cmp.b #82,(a0)+
		bne.s FORMLoop
		cmp.b #77,(a0)+
		bne.s FORMLoop
		sub.l #4,a0
		rts

ReadData:	move.l dosbase,a6	;This reads the data
		move.l filehd,d1	;from the disk file.
		move.l #$ffffff,d3
		jsr read(a6)
		rts

OpenFile:	move.l dosbase,a6
		jsr open(a6)
		move.l d0,filehd
		rts
CloseFile:	move.l dosbase,a6
		move.l filehd,d1
		jsr Close(a6)
		rts


Delay:		move.l #700000,d1	;Don't use delays like
DelayLoop:	sub.l #1,d1		;this, use a CIA timer.
		bne.s DelayLoop		;You can do this if you
		rts			;are only doing it for
					;your own use, as I was.
					;The speed will vary on
					;different Amiga models.
BlankAPlane:	move.l #2560,d7
BlankPLoop:	move.l #0,(a0)+
		subq.l #1,d7
		bne.s BlankPLoop
		rts

TotalRecall:	lea.l Plane5b+10200,a5	;This effect was called
		lea.l Plane4b+10200,a4	;"Total Recall" because
		lea.l Plane3b+10200,a3	;of the effect used by
		lea.l Plane2b+10200,a2	;Ocean in the game.
		lea.l Plane1b+10200,a1	;I called it this, so you
		lea.l Plane5+10200,a0	;know what I mean.
		move.l #Plane5+10200,CurrentPos
		moveq.l #0,d7
		moveq.l #0,d6
		moveq.l #0,d5

		move.w #256,d7		;Times to do whole screen
PassLoop:	move.w d7,d5		;No of lines to do
		move.l CurrentPos,a0	;Current Line address in a0
RasterLoop:	move.b #10,d6		;No of Longs in each line
LineLoop:	move.l (a5)+,(a0)	;Do a LongWord in each
		sub.l #20480,a0		;of destination bitplanes
		move.l (a4)+,(a0)
		sub.l #20480,a0
		move.l (a3)+,(a0)
		sub.l #20480,a0
		move.l (a2)+,(a0)
		sub.l #20480,a0
		move.l (a1)+,(a0)+
		add.l #81920,a0
		subq.b #1,d6
		bne.s LineLoop		;Done a long in each plane
		sub.l #80,a0		;Done a line
		sub.l #40,a5
		sub.l #40,a4
		sub.l #40,a3
		sub.l #40,a2
		sub.l #40,a1
		subq.w #1,d5		;Copy same line all way
		bne.s RasterLoop	;up screen
		sub.l #40,a5
		sub.l #40,a4
		sub.l #40,a3
		sub.l #40,a2
		sub.l #40,a1
		sub.l #40,CurrentPos	;Change start line and copy
		subq.w #1,d7		;upwards to 1 line less
		bne PassLoop
		rts

NEW:            dc.w diwstart,$2c81	;This is our copper list.
		dc.w diwstop,$2cc1
		dc.w ddfstart,$38
		dc.w ddfstop,$d0
		dc.w bplcon0
Noofbps		dc.w $4200
		dc.w bplcon1,$0

		dc.w $108,0,$10a,0	;clears bitplane modulos.
					;Only really necessary on
					;A1200s/A4000s.
		dc.w col0
Colour0		dc.w $000	;All these colour values get
		dc.w col1,$fff	;poked in by earlier code that
		dc.w col2,$fff	;reads their values from the
		dc.w col3,$fff	;Iff CMAP block.
		dc.w col4,$fff	;Changing these fffs won't do 
		dc.w col5,$fff	;anything.
		dc.w col6,$fff
		dc.w col7,$fff
		dc.w col8,$fff
		dc.w col9,$fff
		dc.w col10,$fff
		dc.w col11,$fff
		dc.w col12,$fff
		dc.w col13,$fff
		dc.w col14,$fff
		dc.w col15,$fff
		dc.w col16,$000
		dc.w col17,$000
		dc.w col18,$000
		dc.w col19,$000
		dc.w col20,$000
		dc.w col21,$000
		dc.w col22,$000
		dc.w col23,$000
		dc.w col24,$000
		dc.w col25,$000
		dc.w col26,$000
		dc.w col27,$000
		dc.w col28,$000
		dc.w col29,$000
		dc.w col30,$000
		dc.w col31,$000
	
		dc.w bpl1pth
Bp1h		dc.w 0
		dc.w bpl1p