 	Section Copperlist,code_C

	opt	c-

bplen	equ	(40*256)

	move.l  4.w,a6
	;jsr     -$84(a6)	; disallow
	lea	glib,a1
	moveq	#0,d0
	move.l	4.w,a6
	jsr	-$228(a6)
	tst	d0
	beq	error
	move.l	D0,graphics	; store address of graphics lib
	
	move.l	#Screen,d0	; store address of bitplane0
	move.w	d0,bitplane0_lo	; into the copper list
	swap	d0
	move.w	d0,bitplane0_hi
	swap	d0
	add.l	#bplen,d0
	
	move.w	d0,bitplane1_lo
	swap	d0
	move.w	d0,bitplane1_hi
	swap	d0
	add.l	#bplen,d0

	move.w	d0,bitplane2_lo
	swap	d0
	move.w	d0,bitplane2_hi
	swap	d0
	add.l	#bplen,d0

	move.w	d0,bitplane3_lo
	swap	d0
	move.w	d0,bitplane3_hi
		
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$80,$dff096		; dma control write
	move.l	(a6),old_copper		; store the address of the
	move.l	#my_copper,(a6)		; old copperlist
	move.w	#$8080,$dff096		; dma control write
	move.w	#$8010,$dff09a		; interupt enable bits
	move.l	$6c.w,old_interupt	; store old level 3 int
	move.l	#new_interupt,$6c.w	; store my routine
					; into level 3 int

	bchg	#1,$bfe001		; turn led off
	jsr	mt_init

mouse:	btst	#6,$bfe001
	bne.s	mouse			; wait for lmb

	jsr	mt_end
	bchg	#1,$bfe001
	
	move.l	old_interupt,$6c.w	; resore old level 3 int
	move.l	#$10,$dff09a 		; Disable Level 3 Interupt
	move.l	graphics,a6
	add.l	#$32,a6
	move.w	#$0080,$dff096
	move.l	old_copper,(a6)		; restore old copper list
	move.w	#$8080,$dff096
	move.l	graphics,a1
	move.l	4.w,a6
	jsr	-$19e(a6)
	move.l	4.w,a6
	jsr	-138(a6)
Error:	moveq	#0,d0			; fin
	rts

new_interupt:
	movem.l	d0-d7/a0-a6,-(sp)	; my scroll text

wait_irq:
	and.w	#$10,$dff01e
	beq 	no_music
	move.w	#$10,$dff09c

	jsr	scroll_text

	jsr	mt_music

no_music:
	movem.l	(sp)+,d0-d7/a0-a6	
	dc.w	$4ef9			; jmp
old_interupt:	dc.l	0		; the old int lev 3


mt_init:lea	mt_data,a0
	add.l	#$03b8,a0
	moveq	#$7f,d0
	moveq	#0,d1
mt_init1:
	move.l	d1,d2
	subq.w	#1,d0
mt_init2:
	move.b	(a0)+,d1
	cmp.b	d2,d1
	bgt.s	mt_init1
	dbf	d0,mt_init2
	addq.b	#1,d2

mt_init3:
	lea	mt_data,a0
	lea	mt_sample1(pc),a1
	asl.l	#8,d2
	asl.l	#2,d2
	add.l	#$438,d2
	add.l	a0,d2
	moveq	#$1e,d0
mt_init4:
	move.l	d2,(a1)+
	moveq	#0,d1
	move.w	42(a0),d1
	asl.l	#1,d1
	add.l	d1,d2
	add.l	#$1e,a0
	dbf	d0,mt_init4

	lea	mt_sample1(PC),a0
	moveq	#0,d0
mt_clear:
	move.l	(a0,d0.w),a1
	clr.l	(a1)
	addq.w	#4,d0
	cmp.w	#$7c,d0
	bne.s	mt_clear

	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	clr.l	mt_partnrplay
	clr.l	mt_partnote
	clr.l	mt_partpoint

	move.b	mt_data+$3b6,mt_maxpart+1
	rts

mt_end:	clr.w	$dff0a8
	clr.w	$dff0b8
	clr.w	$dff0c8
	clr.w	$dff0d8
	move.w	#$f,$dff096
	rts

mt_music:
	addq.w	#1,mt_counter
mt_cool:cmp.w	#6,mt_counter
	bne.s	mt_notsix
	clr.w	mt_counter
	bra	mt_rout2

mt_notsix:
	lea	mt_aud1temp(PC),a6
	tst.b	3(a6)
	beq.s	mt_arp1
	lea	$dff0a0,a5		
	bsr.s	mt_arprout
mt_arp1:lea	mt_aud2temp(PC),a6
	tst.b	3(a6)
	beq.s	mt_arp2
	lea	$dff0b0,a5
	bsr.s	mt_arprout
mt_arp2:lea	mt_aud3temp(PC),a6
	tst.b	3(a6)
	beq.s	mt_arp3
	lea	$dff0c0,a5
	bsr.s	mt_arprout
mt_arp3:lea	mt_aud4temp(PC),a6
	tst.b	3(a6)
	beq.s	mt_arp4
	lea	$dff0d0,a5
	bra.s	mt_arprout
mt_arp4:rts

mt_arprout:
	move.b	2(a6),d0
	and.b	#$0f,d0
	tst.b	d0
	beq	mt_arpegrt
	cmp.b	#$01,d0
	beq.s	mt_portup
	cmp.b	#$02,d0
	beq.s	mt_portdwn
	cmp.b	#$0a,d0
	beq.s	mt_volslide
	rts

mt_portup:
	moveq	#0,d0
	move.b	3(a6),d0
	sub.w	d0,22(a6)
	cmp.w	#$71,22(a6)
	bpl.s	mt_ok1
	move.w	#$71,22(a6)
mt_ok1:	move.w	22(a6),6(a5)
	rts

mt_portdwn:
	moveq	#0,d0
	move.b	3(a6),d0
	add.w	d0,22(a6)
	cmp.w	#$538,22(a6)
	bmi.s	mt_ok2
	move.w	#$538,22(a6)
mt_ok2:	move.w	22(a6),6(a5)
	rts

mt_volslide:
	moveq	#0,d0
	move.b	3(a6),d0
	lsr.b	#4,d0
	tst.b	d0
	beq.s	mt_voldwn
	add.w	d0,18(a6)
	cmp.w	#64,18(a6)
	bmi.s	mt_ok3
	move.w	#64,18(a6)
mt_ok3:	move.w	18(a6),8(a5)
	rts
mt_voldwn:
	moveq	#0,d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	sub.w	d0,18(a6)
	bpl.s	mt_ok4
	clr.w	18(a6)
mt_ok4:	move.w	18(a6),8(a5)
	rts

mt_arpegrt:
	move.w	mt_counter(PC),d0
	cmp.w	#1,d0
	beq.s	mt_loop2
	cmp.w	#2,d0
	beq.s	mt_loop3
	cmp.w	#3,d0
	beq.s	mt_loop4
	cmp.w	#4,d0
	beq.s	mt_loop2
	cmp.w	#5,d0
	beq.s	mt_loop3
	rts

mt_loop2:
	moveq	#0,d0
	move.b	3(a6),d0
	lsr.b	#4,d0
	bra.s	mt_cont
mt_loop3:
	moveq	#$00,d0
	move.b	3(a6),d0
	and.b	#$0f,d0
	bra.s	mt_cont
mt_loop4:
	move.w	16(a6),d2
	bra.s	mt_endpart
mt_cont:
	add.w	d0,d0
	moveq	#0,d1
	move.w	16(a6),d1
	and.w	#$fff,d1
	lea	mt_arpeggio(PC),a0
mt_loop5:
	move.w	(a0,d0),d2
	cmp.w	(a0),d1
	beq.s	mt_endpart
	addq.l	#2,a0
	bra.s	mt_loop5
mt_endpart:
	move.w	d2,6(a5)
	rts

mt_rout2:
	lea	mt_data,a0
	move.l	a0,a3
	add.l	#$0c,a3
	move.l	a0,a2
	add.l	#$3b8,a2
	add.l	#$43c,a0
	move.l	mt_partnrplay(PC),d0
	moveq	#0,d1
	move.b	(a2,d0),d1
	asl.l	#8,d1
	asl.l	#2,d1
	add.l	mt_partnote(PC),d1
	move.l	d1,mt_partpoint
	clr.w	mt_dmacon

	lea	$dff0a0,a5
	lea	mt_aud1temp(PC),a6
	bsr	mt_playit
	lea	$dff0b0,a5
	lea	mt_aud2temp(PC),a6
	bsr	mt_playit
	lea	$dff0c0,a5
	lea	mt_aud3temp(PC),a6
	bsr	mt_playit
	lea	$dff0d0,a5
	lea	mt_aud4temp(PC),a6
	bsr	mt_playit
	move.w	#$01f4,d0
mt_rls:	dbf	d0,mt_rls

	move.w	#$8000,d0
	or.w	mt_dmacon,d0
	move.w	d0,$dff096

	lea	mt_aud4temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	mt_voice3
	move.l	10(a6),$dff0d0
	move.w	#1,$dff0d4
mt_voice3:
	lea	mt_aud3temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	mt_voice2
	move.l	10(a6),$dff0c0
	move.w	#1,$dff0c4
mt_voice2:
	lea	mt_aud2temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	mt_voice1
	move.l	10(a6),$dff0b0
	move.w	#1,$dff0b4
mt_voice1:
	lea	mt_aud1temp(PC),a6
	cmp.w	#1,14(a6)
	bne.s	mt_voice0
	move.l	10(a6),$dff0a0
	move.w	#1,$dff0a4
mt_voice0:
	move.l	mt_partnote(PC),d0
	add.l	#$10,d0
	move.l	d0,mt_partnote
	cmp.l	#$400,d0
	bne.s	mt_stop
mt_higher:
	clr.l	mt_partnote
	addq.l	#1,mt_partnrplay
	moveq	#0,d0
	move.w	mt_maxpart(PC),d0
	move.l	mt_partnrplay(PC),d1
	cmp.l	d0,d1
	bne.s	mt_stop
	clr.l	mt_partnrplay
mt_stop:tst.w	mt_status
	beq.s	mt_stop2
	clr.w	mt_status
	bra.s	mt_higher
mt_stop2:
	rts

mt_playit:
	move.l	(a0,d1.l),(a6)
	addq.l	#4,d1
	moveq	#0,d2
	move.b	2(a6),d2
	and.b	#$f0,d2
	lsr.b	#4,d2

	move.b	(a6),d0
	and.b	#$f0,d0
	or.b	d0,d2
	tst.b	d2
	beq.s	mt_nosamplechange

	moveq	#0,d3
	lea	mt_samples(PC),a1
	move.l	d2,d4
	asl.l	#2,d2
	mulu	#$1e,d4
	move.l	(a1,d2),4(a6)
	move.w	(a3,d4.l),8(a6)
	move.w	2(a3,d4.l),18(a6)
	move.w	4(a3,d4.l),d3
	tst.w	d3
	beq.s	mt_displace
	move.l	4(a6),d2
	add.l	d3,d2
	move.l	d2,4(a6)
	move.l	d2,10(a6)
	move.w	6(a3,d4.l),8(a6)
	move.w	6(a3,d4.l),14(a6)
	move.w	18(a6),8(a5)
	bra.s	mt_nosamplechange

mt_displace:
	move.l	4(a6),d2
	add.l	d3,d2
	move.l	d2,10(a6)
	move.w	6(a3,d4.l),14(a6)
	move.w	18(a6),8(a5)
mt_nosamplechange:
	move.w	(a6),d0
	and.w	#$fff,d0
	tst.w	d0
	beq.s	mt_retrout
	move.w	(a6),16(a6)
	move.w	20(a6),$dff096
	move.l	4(a6),(a5)
	move.w	8(a6),4(a5)
	move.w	(a6),d0
	and.w	#$fff,d0
	move.w	d0,6(a5)
	move.w	20(a6),d0
	or.w	d0,mt_dmacon

mt_retrout:
	tst.w	(a6)
	beq.s	mt_nonewper
	move.w	(a6),22(a6)

mt_nonewper:
	move.b	2(a6),d0
	and.b	#$0f,d0
	cmp.b	#$0b,d0
	beq.s	mt_posjmp
	cmp.b	#$0c,d0
	beq.s	mt_setvol
	cmp.b	#$0d,d0
	beq.s	mt_break
	cmp.b	#$0e,d0
	beq.s	mt_setfil
	cmp.b	#$0f,d0
	beq.s	mt_setspeed
	rts

mt_posjmp:
	not.w	mt_status
	moveq	#0,d0
	move.b	3(a6),d0
	subq.b	#1,d0
	move.l	d0,mt_partnrplay
	rts

mt_setvol:
	move.b	3(a6),8(a5)
	rts

mt_break:
	not.w	mt_status
	rts

mt_setfil:
	moveq	#0,d0
	move.b	3(a6),d0
	and.b	#1,d0
	rol.b	#1,d0
	and.b	#$fd,$bfe001
	or.b	d0,$bfe001
	rts

mt_setspeed:
	move.b	3(a6),d0
	and.b	#$0f,d0
	beq.s	mt_back
	clr.w	mt_counter
	move.b	d0,mt_cool+3
mt_back:rts

mt_aud1temp:
	Dcb.w	10,0
	dc.w	1
	Dcb.w	2,0
mt_aud2temp:
	Dcb.w	10,0
	dc.w	2
	Dcb.w	2,0
mt_aud3temp:
	Dcb.w	10,0
	dc.w	4
	Dcb.w	2,0
mt_aud4temp:
	Dcb.w	10,0
	dc.w	8
	Dcb.w	2,0

mt_partnote:	dc.l	0
mt_partnrplay:	dc.l	0
mt_counter:	dc.w	0
mt_partpoint:	dc.l	0
mt_samples:	dc.l	0
mt_sample1:	Dcb.l	31,0
mt_maxpart:	dc.w	0
mt_dmacon:	dc.w	0
mt_status:	dc.w	0

mt_arpeggio:
	dc.w $0358,$0328,$02fa,$02d0,$02a6,$0280,$025c
	dc.w $023a,$021a,$01fc,$01e0,$01c5,$01ac,$0194,$017d
	dc.w $0168,$0153,$0140,$012e,$011d,$010d,$00fe,$00f0
	dc.w $00e2,$00d6,$00ca,$00be,$00b4,$00aa,$00a0,$0097
	dc.w $008f,$0087,$007f,$0078,$0071,$0000,$0000,$0000

				;of the module


all_blit:

	move.l	a0,$dff054			; dest mem d
	Move.l	a1,$dff050			; source mem a
	move.w	#0,$dff064			; source a modulo 
	Move.w	#$ffff,$dff044			; blit 1st word mask source a
	Move.w	#$ffff,$dff046			; blit 1st word mask source a
	move.w	#%1001*256+$f0,$dff040		; blit cont reg 0
	move.w	#0,$dff042			; blit cont reg 1
	Move.w	a3,$dff066			; modulo for dest
	Move.w	a2,$dff058			; blit height,width
	jsr	doblit
	rts


doblit:
wait_blit:
 	Btst.b	#6,$dff002		; wait for the blit
	Bne.s	wait_blit		; to finish
	
	rts

offset		equ	68
down		equ	200*40+(11*46)+(2*48)
scroll_text:
	
	move.l	scroff,d0
	sub.l	#2,d0
	move.l	d0,scroff

	move.l	scroff,d0
	and.l	#15,d0
	move.l	d0,d1
	mulu	#16,d0
	add.l	d1,d0
	move.w	d0,scroller
	
	move.l	scroff,d0
	cmp.l	#15,d0
	beq	finished2
	cmp.l	#0,d0
	bge	finished
	
	jsr	finished2

	clr.l	d0
	move.l	textptr,a0
	move.b	(a0)+,d0
	cmp.b	#0,d0
	beq.s	text_end
	
	cmp.b	#32,d0
	blt.s	ctrl_bad

	bra.s	scroll_ok

text_end:
	lea	text,a0
	move.l	a0,textptr	
	move.b	#32,d0
	
	bra.s	scroll_ok
	
ctrl_bad:

	rts	
	
scroll_ok:
	move.l	#31,scroff

	cmp.b #"I",d0
	beq.s	small

	cmp.b #":",d0
	beq.s	small

	cmp.b #".",d0
	beq.s	small

	cmp.b #",",d0
	beq.s	small

	cmp.b #"`",d0
	beq.s	small

	cmp.b #"!",d0
	beq.s	small

	cmp.b #"1",d0
	beq.s	small

	bra.s	normal
	
small:	move.l	#15,scroff




normal:

	move.l	a0,textptr

	sub.l	#32,d0
	mulu	#252,d0
	add.l	#font,d0
	move.l	d0,a1


	move.l	#screen+offset+down,a0
	move.l	#44,a3
	move.l	#(21*64)+2,a2
	jsr	all_blit
	add.l	#(256*40),a0
	add.l	#84,a1
	jsr	all_blit
	add.l	#(256*40),a0
	add.l	#84,a1
	jsr	all_blit

finished:
	rts
	
finished2:
	move.w	#(15*16)+15,scroller
	move.l	#screen+offset+down-44,a0
	move.l	#screen+offset+down-42,a1
	move.l	#(11*64)+44,a2
	move.l	#0,a3
	jsr	all_blit
	add.l	#(256*40),a0
	add.l	#(256*40),a1
	jsr	all_blit
	add.l	#(256*40),a0
	add.l	#(256*40),a1
	jsr	all_blit
	
	rts	

	
	Section	copdat,Data_c

text:		
	dc.b	"WELCOME TO `I LIKE TRAFFIC LIGHTS`,  THIS SCROLLER MAY PROVE "
	dc.b	"CONFUSING, SO I`LL TRY TO EXPLAIN AS SIMPLY AS POSSIBLE. THERE ARE 2 "
	dc.b	"MONTY PYTHONS MENTIONED IN THIS SCROLLER, LSD`S MONTY PYTHON, AND "
	dc.b	"THE ORIGINAL MONTY PYTHON TEAM.   THIS SONG WAS CONVERTED TO THE AMIGA "
	dc.b	"BY MONTY PYTHON OF LSD. THE SAMPLE ITSELF WAS TAKEN FROM MONTY PYTHONS "
	dc.b	"CONTRACTUAL OBLIGATION LP, AND IS UNDER 330K UNPACKED, WHICH ISN`T BAD "
	dc.b	"FOR OVER 2 AND A HALF MINUTES. THE SAMPLING WAS DONE ON AN "
	dc.b	"ATARI ST USING ST REPLAY 4 AT 15KHZ, THEN REDUCED TO 12KHZ TO "
	dc.b	"SAVE MEMORY, AND FINALY CONVERTED TO THE AMIGA BY LSD`S MONTY PYTHON. "
	dc.b	"DUE TO LACK OF TIME, THIS FONT WAS "
	dc.b	"STOLEN FROM DIGILOGICS SAMPLERIPPER, ORIGIANALLY DESIGNED BY QUINCY. "
	dc.b	"  ALL CODING IS BY SHAGRATT OF LSD.   ORIGINAL CONCEPT BY PARASITE.                "
	dc.b	0
			even

textptr:	dc.l	text

mt_data:	incbin 	"mod.iltl_monty"

scroff:		dc.l	31
old_copper:	dc.l	0
graphics:	dc.l	0

my_copper:	dc.w	$100,$4200	; 4 bp - lores
		dc.w	$104,$a		; bp control reg
		dc.w	$108,0		; bp modulo - odd
		dc.w	$10a,0		; bp modulo - even
		dc.w	$180,0		; colour 0 to black
		dc.w	$102,0
		dc.w	$120,0,$122,0
	
		dc.w	$092,$38	; bp start horz
		dc.w	$08e,$2c8c	; bp window start left
		dc.w	$090,$2ce3	; bp window bot right
		dc.w	$094,$2dd0	; bp stop horz
		
		dc.w	$0e0		; bp 1 address hi-byte
bitplane0_hi:	dc.w	0
		dc.w	$e2		; bp 1 address
bitplane0_lo:	dc.w	0,$e4

bitplane1_hi:	dc.w	0
		dc.w	$e6		; bp 2 address
bitplane1_lo:	dc.w	0,$e8

bitplane2_hi:	dc.w	0
		dc.w	$ea		; bp 3 address
bitplane2_lo:	dc.w	0,$ec

bitplane3_hi:	dc.w	0
		dc.w	$ee		; bp 4 address
bitplane3_lo:	dc.w	0

		dc.w	$180,$000
		dc.w	$182,$000
		dc.w	$184,$000
		dc.w	$186,$000
 		dc.w	$188,$000
		dc.w	$18a,$000
		dc.w	$18c,$000
		dc.w	$18e,$000
		dc.w	$190,$000
		dc.w	$192,$000
		dc.w	$194,$000
		dc.w	$196,$000
		dc.w	$198,$000
		dc.w	$19a,$000
		dc.w	$19c,$000
		dc.w	$19e,$000
		
		dc.w	$3801,$ff00
		dc.w	$100,$4200

		dc.w	$180,$000
		dc.w	$182,$444
		dc.w	$184,$666
		dc.w	$186,$888
 		dc.w	$188,$886
		dc.w	$18a,$a68
		dc.w	$18c,$c8a
		dc.w	$18e,$eac
		dc.w	$190,$000
		dc.w	$192,$668
		dc.w	$194,$242
		dc.w	$196,$462
		dc.w	$198,$422
		dc.w	$19a,$644
		dc.w	$19c,$664
		dc.w	$19e,$aaa
		

		; below : $33 is y line $33, 01 is wait
		; $ff is ignore x pos, $00 ?
		; $180 is colour register 0 (bg col)
		
		dc.w	$ffe1,$fffe	; wait for end of ntsc screen

		dc.w	$100,$3200	; 3 bp - lores 
	
		dc.w	$092,$20	; bp start horz
		dc.w	$08e,$2c78	; bp window start left
		dc.w	$090,$2cc4	; bp window bot right
		dc.w	$094,$2de8	; bp stop horz
		
		dc.w	$102
scroller:	dc.w	0
		dc.w	$182,$08F
		dc.w	$184,$06D
		dc.w	$186,$04C
		dc.w	$188,$03A
		dc.w	$18a,$019
		dc.w	$18c,$008
		dc.w	$18e,$006

		dc.w	$1901,$ff00
		dc.w	$10a,-144,$108,-144

		dc.w	$182,$06C
		dc.w	$184,$04A
		dc.w	$186,$02A
		dc.w	$188,$018
		dc.w	$18a,$007
		dc.w	$18c,$006
		dc.w	$18e,$004
		dc.w	$180,$00b

		dc.w	$1a01,$ff00,$180,$008
		dc.w	$1b01,$ff00,$180,$007
		dc.w	$1c01,$ff00,$180,$006
		dc.w	$1d01,$ff00,$180,$005
		dc.w	$1e01,$ff00,$180,$004
		

		dc.w	$2701,$ff00,$100,$0200

		dc.w	$3001,$ff00	; wait for end of pal screen

		dc.w	$9c,$8010	; irq set bits - ?
		dc.w	$ffff,$fffe	; end of copper list
	
glib:		dc.b	"graphics.library",0

	even
	
screen:		incbin "monty.bin"
font:		incbin "metal.bin"

	End
