;+------------------------------------------------------------+
;|                BlipBlopper Music Replayer                  |
;|                                                            |
;|              Tunes by 'Frazer' and 'Beast'                 |
;|     Coding by QJO and Music-driver by JASON of TKT         |
;|                                                            |
;| Altered to restore palette & resolution on exit by MUG U.K |
;+------------------------------------------------------------+

screen	equ $78000
	
	pea	0
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp
	lea.l	save_usp(pc),a0
	move.l	d0,(a0)

	move.w	#4,-(sp)
	trap	#14
	move.w	d0,oldrez
	
	move.w	#0,-(sp)
	move.l	#screen,-(sp)
	move.l	#screen,-(sp)
	move.w	#5,-(sp)
	trap	#14
	lea.l	12(sp),sp
	
	pea	text(pc)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#2,sp

	movem.l	$ff8240,d0-d7
	movem.l	d0-d7,palstore
	
	bclr	#0,$484.w
	move.w	#$000,$ff8240
	move.w	#$333,$ff8242
	move.w	#$444,$ff8244
	move.w	#$777,$ff8246
	move.w	#$777,$ff8248
	move.w	#$777,$ff824a
	move.w	#$777,$ff824c
	move.w	#$777,$ff824e
	move.w	#$777,$ff8250
	move.w	#$777,$ff8252
	move.w	#$777,$ff8254
	move.w	#$777,$ff8256
	move.w	#$777,$ff8258
	move.w	#$777,$ff825a
	move.w	#$777,$ff825c
	move.w	#$777,$ff825e
	
	move.l	#screen,a0
	move.w	#200-1,d0
color1	move.w	#$ffff,8*0(a0)
	move.w	#$ffff,8*1(a0)
	move.w	#$ffff,8*2(a0)
	move.w	#$ffff,8*3(a0)
	move.w	#$ffff,8*4(a0)
	move.w	#$ffff,8*5(a0)
	
	move.w	#$ffff,8*7+2(a0)
	move.w	#$ffff,8*8+2(a0)
	move.w	#$ffff,8*9+2(a0)
	move.w	#$ffff,8*10+2(a0)
	move.w	#$ffff,8*11+2(a0)
	move.w	#$ffff,8*12+2(a0)
	
	move.l	#$ffffffff,8*14(a0)
	move.l	#$ffffffff,8*15(a0)
	move.l	#$ffffffff,8*16(a0)
	move.l	#$ffffffff,8*17(a0)
	move.l	#$ffffffff,8*18(a0)
	move.l	#$ffffffff,8*19(a0)
	
	lea.l	160(a0),a0
	dbra	d0,color1
	
	move.l	#1,d0
	jsr	muzak


* save old & install new v- & hbl
	move.l	$70,old_vbl		* Spara gamla VBLen
	move.l	$120,old_hbl	* Spara gamla HBLen
	andi.b	#$9f,$fffa09
	andi.b	#$fe,$fffa07
	move.l	#myvbl,$70		* Sдt ny VBL
	move.l	#myhbl1,$120		* Sдt ny HBL
	ori.b	#$01,$fffa07
	ori.b	#$01,$fffa13
	
resetflag	sf.b	vblflag
wait	tst.b	vblflag
	beq	wait
	
	cmp.b	#185,$fffffc02
	bne	resetflag

	move.b	#$00,$fffffa1b.w	* Stoppa Timer B
	move.l	old_vbl,$70		* Sдt tillbaka gamla VBLen
	move.l	old_hbl,$120		* och gamla HBLen
	andi.b	#$fe,$fffa07
	clr.b	$fffa1b
	ori.b	#$60,$fffa09
	
;	move.w	#7,-(sp)
;	trap	#1
;	addq.l	#2,sp

	move.l	#$ff8800,a0
	move.l	#$08000000,(a0)
	move.l	#$09000000,(a0)
	move.l	#$0a000000,(a0)
	
	bset	#0,$484.w

	movem.l	palstore,d0-d7
	movem.l	d0-d7,$ff8240

	move.w	oldrez,-(sp)
	pea	-1
	pea	-1
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp
	
	move.l	save_usp(pc),-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq.l	#6,sp
	
	clr.w	-(sp)
	trap	#1
	
yoffs	equ 31
xoffs	equ 31
text	dc.b 27,"b",8	* textfarg
	dc.b 27,"Y",yoffs+1,xoffs+1,"Reanimators/Syndicate presents:"
	dc.b 27,"Y",yoffs+3,xoffs+1,"Soundchip tunes composed by:"
	dc.b 27,"Y",yoffs+5,xoffs+1,"-BEAST-  "
	dc.b 27,"Y",yoffs+7,xoffs+1,"-FRAZER- "
	dc.b 27,"Y",yoffs+9,xoffs+1,"                                        "
	dc.b 27,"Y",yoffs+11,xoffs+1,"Do NOT forget the credit if u are using"
	dc.b 27,"Y",yoffs+13,xoffs+1,"any of these tunes in yer demo or intro"
	dc.b 27,"Y",yoffs+15,xoffs+1,"                                       "
	dc.b 27,"Y",yoffs+17,xoffs+1,"Made with BLIPPBLOPPER 0.74 by T.K.T !"
	dc.b 0
	even

*******************************************
* VBL rout.
myvbl	clr.l	$ff8242
	clr.w	$ff8246
	move.b	#$00,$fffffa1b.w	* Stoppa Timer B
	
	jsr	muzak+16
	
	lea.l	paltab,a0
	move.w	#18-1,d0
clrpal	clr.l	(a0)+
	clr.w	(a0)+
	dbra	d0,clrpal
	
	
	move.l	#$ff8800,a0
	
	move.b	#8,(a0)
	move.b	(a0),d0
	and.w	#$f,d0
	
	move.b	#9,(a0)
	move.b	(a0),d1
	and.w	#$f,d1
	
	move.b	#10,(a0)
	move.b	(a0),d2
	and.w	#$f,d2
	
	
	lea.l	paltabend,a6
	move.l	a6,a0
vol_a	move.w	#$500,(a0)
	subq.l	#6,a0
	dbra	d0,vol_a
	
	move.l	a6,a0
vol_b	move.w	#$050,2(a0)
	subq.l	#6,a0
	dbra	d1,vol_b
	
	move.l	a6,a0
vol_c	move.w	#$005,4(a0)
	subq.l	#6,a0
	dbra	d2,vol_c
	
	lea.l	paltab,a6
	
	move.b	#1,$fffa21	* nasta hbl om x rader
	move.b	#8,$fffa1b	* Starta Timer B
	andi.b	#$fe,$fffa0f
	
	
	st.b	vblflag
	
	rte

offset1	dc.w 0
offset2	dc.w 0
offset3	dc.w 0



***************************************************
myhbl1	move.l	(a6)+,$ff8242
	move.w	(a6)+,$ff8246
	move.b	#$00,$fffffa1b.w	* Stoppa Timer B
	
	
	move.b	#11,$fffa21		* Nгta HBL om 1 raster-rad
	move.b	#8,$fffa1b		* Starta Timer B
	andi.b	#$fe,$fffa0f

	rte

paltab	ds.w 17*3
paltabend	ds.w 1*3
	dc.w $707,$707,$707

no_scrl	st.b	scrlflag
	rts

	even
scrlflag	ds.w 1
	even
save_usp	ds.l 1
physbase	ds.l 1
old_vbl	ds.l 1
old_hbl	ds.l 1
vblflag	ds.w 1
oldrez	ds.w 1
palstore	ds.w 16
muzak	incbin "new*.rpl"
	incbin "reanim.tun"
	even

* Tunes available:
*
* BEAST_1.TUN	(also used in The Syndicate Menu #17)
* BEAST_2.TUN	(also used in The Syndicate Menu #20)
* FRAZER_1.TUN 
*
* TSC_21.TUN	(The Syndicate Menu #21)
* TSC_22.TUN	(The Syndicate Menu #22)
* TSC_27.TUN	(The Syndicate Menu #27)
* TSC_28.TUN	(The Syndicate Menu #28)
* TSC_31.TUN	(The Syndicate Menu #31)
* TSC_42.TUN	(The Syndicate Menu #42)
* TSC_52.TUN	(The Syndicate Menu #52 - Preview version !!)
* REANIM.TUN	(Reanimators Music Demo - Main Menu and also
*		 The Syndicate Menu #24)
*
* BASSTEP2.TUN
* BORING.TUN
* BERTAM.TUN
* BLABLABL.TUN	(All of these were sent to me by someone who)
* BORING.TUN	(wishes to remain nameless !!)
* DEMO_TUN.TUN	(Included in BlipBlopper)
* EVERT.TUN
* GAAAAASP.TUN
* SHITT.TUN
* TJOSAN.TUN
*
* First three files originally distributed with this source, which also
* included another file which was corrupt !!
*
* Next eight files hacked by MUG U.K
*
* Remaining files sent to me by Mr. X !!!
*
* Thanks to Special FX for the Blipblopper.  Although you are a bunch
* of nasty pirates, I must thank Mr S.L Asherbog-Smythe & Mr M.E.N Tor
* sending me a copy of this long awaited music-program
*
* This doc file updated on: 27/2/1992
