aud0lch	equ	$dff0a0
aud0len	equ	$dff0a4
aud0per	equ	$dff0a6
aud0vol	equ	$dff0a8

aud1lch	equ	$dff0b0
aud1len	equ	$dff0b4
aud1per	equ	$dff0b6
aud1vol	equ	$dff0b8

aud2lch	equ	$dff0c0
aud2len	equ	$dff0c4
aud2per	equ	$dff0c6
aud2vol	equ	$dff0c8

aud3lch	equ	$dff0d0
aud3len	equ	$dff0d4
aud3per	equ	$dff0d6
aud3vol	equ	$dff0d8
dmacon	equ	$dff096
intreqr	equ	$dff01e
intreq	equ	$dff09c
dmaconr equ	$dff002
bltcon0 equ	$dff040
bltcon1 equ	$dff042
bltamod equ	$dff064			;hardware reg's
bltbmod equ	$dff062
bltcmod	equ	$dff060
bltdmod	equ	$dff066
bltafwm equ	$dff044
bltapth equ	$dff050
bltbpth equ	$dff04c
bltcpth equ	$dff048
bltdpth equ	$dff054
bltsize equ 	$dff058

execbase	equ	4
OpenLibrary 	equ	-552
CloseLibrary	equ	-414
lvo.output	equ	-60
lvo.execute	equ	-222
screenwidth	equ	48
screenheight	equ	276
MenuStart	equ	3	;NoLineDown-1
NoOpts		equ	10	;NoMenuOptions, Max=10
				;Demos must be called.. Demo0,Demo1,Demo2,etc
	incdir	"DF0:KillerByteMenu"

	lea	_dosname,a1
	moveq.l	#0,d0
	move.l	execbase.w,a6
	jsr	OpenLibrary(a6)
	move.l	d0,_dosstore
	jsr	mt_init
RTURN	move.l	#start,$80.w
	trap	#0
	bra	RTURN
	rts
start:
	cmp.b	#$10,$dff006
	bne	start
	movem.l d0-d7/a0-a6,-(a7)    	;save reg's 
	bsr	setupcopper
	bsr	PlaceRVG
	bsr	PrintText
	jsr	start_up
	jsr	waittof
	bsr	mainloop
;	jsr	mt_end
	jsr	return_system
	move.w	#0,aud0vol
	move.w	#0,aud1vol
	move.w	#0,aud2vol
	move.w	#0,aud3vol
	bsr	LoadFile
;	move.l	_dosstore,a1
;	move.l	execbase.w,a6
;	jsr	CloseLibrary(a6)	*** Goodbye Library
	movem.l (a7)+,d0-d7/a0-a6
	rte
mainloop				;THE MAINLOOP
	bsr	Mouse
	bsr	MoveRVG
	bsr	Scroll
	jsr	mt_music
	jsr	waittof
	btst	#$06,$bfe001               ;test for left mousebutton
	bne 	mainloop
	rts
**************************** Lets Scroll Captain ****************************
Scroll:
	subq.w	#1,SCnt
	bne	.nonewchar
	move.w	#8,SCnt
	move.l	STPnt,a0
	lea	Font,a2
	moveq.l	#0,d0
	move.b	(a0)+,d0
	tst.b	d0
	bne	.noreset
	move.l	#ScrollText,a0
	bra	.jump
.noreset
	cmp.b	#" ",d0
	bne	.nospace
	move.l	#MenuGFX+(251*46*3)+96+43,a1
	move.b	#0,(a1)
	move.b	#0,46*3(a1)
	move.b	#0,46*3*2(a1)
	move.b	#0,46*3*3(a1)
	move.b	#0,46*3*4(a1)
	move.b	#0,46*3*5(a1)
	move.b	#0,46*3*6(a1)
	move.b	#0,46*3*7(a1)
	bra	.jump
.nospace
	sub.b	#$28,d0
	lea	(a2,d0.w),a2
	move.l	#MenuGFX+(251*46*3)+96+43,a1
	move.b	(a2),(a1)
	move.b	52*3(a2),46*3(a1)
	move.b	52*3*2(a2),46*3*2(a1)
	move.b	52*3*3(a2),46*3*3(a1)
	move.b	52*3*4(a2),46*3*4(a1)
	move.b	52*3*5(a2),46*3*5(a1)
	move.b	52*3*6(a2),46*3*6(a1)
	move.b	52*3*7(a2),46*3*7(a1)
.jump	move.l	a0,STPnt
.nonewchar
	bsr	WaitBlt
	move.l	#MenuGFX+(251*46*3)+96-2,bltdpth
	move.l	#MenuGFX+(251*46*3)+96,bltapth
	move.w	#46*3-46,bltdmod
	move.w	#46*3-46,bltamod
	move.w	#$f9f0,bltcon0
	move.w	#$0000,bltcon1
	move.w	#8<<6+(46/2),bltsize
	rts
SCnt:	dc.w	8
STPnt:	dc.l	ScrollText
ScrollText:	;0=Reset Scroll
	dc.b	"HI JON, THIS IS KILLER BYTES MENU... I THINK IT LOOKS WELL "
	dc.b	"SMART... IF YOU NEED ANYTHING CHANGING I WILL DO SO... "
	dc.b	"ANYWAY GOT TO GO... BYE FOR NOW.... STU... ",0
	even
******************* Time To Load That God Damm Mother File ******************
LoadFile:
	move.w	YPos,d0
	lsr.w	#3,d0
	add.b	#$30,d0
	move.b	d0,File+8

	move.l	_dosstore,a6
	jsr	lvo.output(a6)
	move.l	d0,d3
	move.l	#File,d1
	moveq.l	#0,d2
	move.l	_dosstore,a6
	jsr	lvo.execute(a6)
	rts
File:	dc.b	'DF0:DEMOX',0
****************************** Mouse Tracking *******************************
Mouse:
	bsr	UnBlt
	move.w	$dff00a,d0
	lsr.w	#8,d0
	move.b	oldy,d1
	move.b	d0,oldy
	sub.b	d0,d1
	ext.w	d1
	sub.w	d1,YPos
	tst.w	YPos
	bge	.oktop
	move.w	#0,YPos
.oktop
	cmp.w	#(NoOpts-1)*8,YPos
	ble	.okbot
	move.w	#(NoOpts-1)*8,YPos
.okbot
	move.w	YPos,d0
	lsr.w	#3,d0
	move.w	d0,RealY
	mulu.w	#10,d0
	move.w	d0,d1
	move.b	d1,Sprite1
	move.b	d1,Sprite2
	move.b	d2,Sprite1+2
	move.b	d2,Sprite2+2
	add.w	#$50+(MenuStart*10),d0
	lea	BarC,a0
	move.w	#11-1,d7
.loop
	move.b	d0,(a0)
	lea	12(a0),a0
	move.b	d0,(a0)
	addq.b	#1,d0
	lea	12(a0),a0
	dbra	d7,.loop

	move.w	#$50+(MenuStart*10),d0
	add.w	d1,d0
	move.w	d0,d1
	add.w	#11,d1
	move.b	d0,Sprite1
	move.b	d0,Sprite2
	move.b	d1,Sprite1+2
	move.b	d1,Sprite2+2
	bsr	BltOn
	rts
BltOn:
	move.l	#MenuGFX+22+6670+(MenuStart*10*46*3),a0
	move.w	RealY,d0
	mulu	#46*3*10,d0
	lea	(a0,d0.w),a0
	move.l	a0,bltdpth
	move.w	#46*3-20,bltdmod
	move.w	#$01ff,bltcon0
	move.w	#$0000,bltcon1
	move.w	#11<<6+(20/2),bltsize
	rts
UnBlt:
	move.l	#MenuGFX+22+6670+(MenuStart*10*46*3),a0
	move.w	RealY,d0
	mulu	#46*3*10,d0
	lea	(a0,d0.w),a0
	move.l	a0,bltdpth
	move.w	#46*3-20,bltdmod
	move.w	#$0100,bltcon0
	move.w	#$0000,bltcon1
	move.w	#11<<6+(20/2),bltsize
	rts
YPos:	dc.w	0
RealY:	dc.w	0
oldy:	dc.w	0
*************************** Do All The Text Shit ****************************
PrintText:
	lea	MenuGFX+22+(46*(50*3)),a0
	lea	Text,a1
	move.l	#46*(10*3),d7		;CharCnt
.PrintLoop
	moveq.l	#0,d0
	lea	Font,a2
	move.b	(a1)+,d0
	cmp.b	#1,d0
	bne	.NoLine
	lea	(a0,d7.w),a0
	move.l	#46*(10*3),d7
	bra	.PrintLoop
.NoLine	cmp.b	#$20,d0
	beq	.goagai
	tst.b	d0
	beq	.ret
	sub.b	#$28,d0
	lea	(a2,d0.w),a2
	move.l	a0,a3
	move.w	#(8*3)-1,d0
.plane1	move.b	(a2),(a3)
	lea	52(a2),a2
	lea	screenwidth-2(a3),a3
	dbra	d0,.plane1
.goagai	addq.l	#1,a0
	subq.l	#1,d7
	bra	.PrintLoop
.ret	rts
Text:	;1=Next Line Please, 0=Finish Text...
	dc.b	'KILLER BYTE PRESENTS',1
	dc.b	' BITS AN BYTES NO.1 ',1,1
	dc.b	'       DEMO 0',1
	dc.b	'       DEMO 1',1
	dc.b	'       DEMO 2',1
	dc.b	'       DEMO 3',1
	dc.b	'       DEMO 4',1
	dc.b	'       DEMO 5',1
	dc.b	'       DEMO 6',1
	dc.b	'       DEMO 7',1
	dc.b	'       DEMO 8',1
	dc.b	'       DEMO 9',0
	even
************************* Move That Funky Thing!!!? *************************
XAdds	equ	400
YAdds	equ	400
MoveRVG:
	move.w	Ycnt,d0
	add.w	#YAdds,Ycnt
	move.w	#400,d7
	bsr	GetSINe
	and.l	#$ffff,d0
	mulu.w	#screenwidth*2,d0
	move.l	#screen1,d7
	add.l	d0,d7
	move.w	d7,Plane0h+6
	swap	d7
	move.w	d7,Plane0h+2
	swap	d7
	add.l	#screenwidth,d7
	move.w	d7,Plane1h+6
	swap	d7
	move.w	d7,Plane1h+2
	swap	d7
	move.w	Xcnt,d0
	add.w	#XAdds,Xcnt
	move.w	#200,d7
	bsr	GetSINe
	move.w	d0,d1
	add.w	d1,d1
	and.w	#$0020,d1
	beq	.skip
	add.w	#2,Plane0h+6
	add.w	#2,Plane1h+6
.skip
	and.w	#$000f,d0
	rol.w	#4,d0
	move.b	d0,ScrZ+3
	rts
Xcnt	dc.w	0
Ycnt	dc.w	$ffff/4
GetSINe:
	and.l	#$ffff,d0
	move.w	d0,d3
	and.w	#$7fff,d0
	move.w	#$7fff,d1
	sub.w	d0,d1
	mulu	d1,d0
	lsr.l	#8,d0
	lsr.l	#5,d0
	btst	#15,d3
	beq	.high
	neg.w	d0
.high	add.w	#$8000,d0
	divu.w	d7,d0
	rts
******************* system on off stuff & Other Stuff ***********************
PlaceRVG:
	move.l	#-1,bltafwm
	move.l	#screen1,d7
	move.w	#screenwidth-4,bltdmod
	move.w	#0,bltamod
	move.w	#$09f0,bltcon0
	move.w	#$0000,bltcon1
	move.w	#28-1,d1
	move.l	#2,d6
.LLoop	move.w	#(screenwidth/4)-1,d0
.Loop
	bsr	WaitBlt
	move.l	d7,bltdpth
	move.l	#RVGSpr,bltapth
	move.w	#20<<6+(32/16),bltsize
	add.l	#4,d7
	dbra	d0,.Loop
	add.l	#(screenwidth*31),d7
	add.l	d6,d7
	neg.l	d6
	dbra	d1,.LLoop
	rts
setupcopper:
	move.l	#screen1,d0
	move.w	d0,Plane0h+6
	swap	d0
	move.w	d0,Plane0h+2
	swap	d0
	add.l	#screenwidth,d0
	move.w	d0,Plane1h+6
	swap	d0
	move.w	d0,Plane1h+2
	swap	d0

	move.l	#MenuGFX+2,d0
	move.w	d0,MenuPl+2
	swap	d0
	move.w	d0,MenuPl-2
	swap	d0
	add.l	#46,d0
	move.w	d0,MenuPl+10
	swap	d0
	move.w	d0,MenuPl+6
	swap	d0
	add.l	#46,d0
	move.w	d0,MenuPl+18
	swap	d0
	move.w	d0,MenuPl+14

	move.l	#Sprite1,d0
	move.w	d0,spr0l+2
	swap	d0
	move.w	d0,spr0h+2
	move.l	#Sprite2,d0
	move.w	d0,spr1l+2
	swap	d0
	move.w	d0,spr1h+2
	rts
WaitBlt:
	btst	#14,dmaconr
.wait
	btst	#14,dmaconr
	bne	.wait
	rts
waittof:
	tst.b	fly
	beq	waittof
	move.b	#0,fly
	rts
start_up

	move.l	usp,a0
	move.l	a0,uspstore		*** Save USP
	lea	library,a1
	moveq	#0,d0
	move.l	execbase,a6
	jsr	OpenLibrary(a6)		*** Open Graphics Library
	tst	d0
	beq	error
	move.l	d0,libstore		*** Store graphics base

	move.l	libstore,a6		*** Set up Copper List
	add.l	#$32,a6
	move.l	(a6),copperstore	*** Store Workbench Copper List
	move.l	#copperstart,(a6)	*** Use Our Copper List
	move.w	#$85ff,$dff096		*** Well `Ard Blitter
	move.w	#$8010,$dff09a		*** Enable level 3 interrupt
	move.l	$6c.w,old		*** Store old level 3 interrupt
	move.l	$70.w,old+4		*** Store old level 3 interrupt
	move.l	$74.w,old+8		*** Store old level 3 interrupt
	move.l	$78.w,old+12		*** Store old level 3 interrupt
	move.l	$7c.w,old+16		*** Store old level 3 interrupt
	move.l	#dummy,$70.w
	move.l	#dummy,$74.w
	move.l	#dummy,$78.w
	move.l	#dummy,$7c.w
	move.l	#new,$6c.w		*** Use New Interrupt
	bset	#1,$bfe001		*** Filter Off
	move.w	#0,$dff042		*** Clear Out CLI crap
	clr.w	$dff144			*** No Sprite stripes
	rts

return_system
	bclr	#1,$bfe001
	move.l	old,$6c.w		*** Put in old level 3 Interrupt
	move.l	old+4,$70.w		*** Store old Level 3 interrupt
	move.l	old+8,$74.w		*** Store old Level 3 interrupt
	move.l	old+12,$78.w		*** Store old Level 3 interrupt
	move.l	old+16,$7c.w		*** Store old Level 3 interrupt
	move.w	#$10,$dff09a		*** Disable our L3 int.
	move.w	#$8030,$dff096		*** Sprites & Disk DMA back on
	move.l	libstore,a6
	add.l	#$32,a6
	move.l	copperstore,(a6)	*** Put back Workbench Copper
	move.l	libstore,a1		*** Close Graphics Library
	move.l	execbase,a6
	jsr	CloseLibrary(a6)	*** Goodbye Library
error:	moveq	#0,d0			*** No Workbench Errors
	move.l	uspstore,a0		*** Old USP
	move.l	a0,usp
	rts
fly:
	dc.w	0
uspstore:
	dc.l	0
_dosstore:
	dc.l	0
copperstore:
	dc.l	0
libstore:
	dc.l	0
library:
	dc.b	'graphics.library',0
	even
_dosname:
	dc.b	'dos.library',0
	even
****************** My Cool Interrupts *********************
new:	movem.l	d0-d7/a0-a6,-(a7)
	and.w	#$10,intreqr
	beq	out
	move.w	#$10,intreq
	addq.b	#1,fly
out:	movem.l	(a7)+,d0-d7/a0-a6

	dc.w	$4ef9			*** JSR Instruction
old:	dc.l	0			*** to here
	dc.l	0,0,0,0,0,0

dummy:	rte

	SECTION	"SCREENS",BSS_C
screen1:
	ds.b	screenwidth*(screenheight+172)*2

	SECTION	"DATASTUFF",DATA_C

copperstart:
	dc.w	$0180,$0212
	dc.w	$0182,$0dde
	dc.w	$0184,$0bbc
	dc.w	$0186,$0889
	dc.w	$0188,$0667
	dc.w	$018a,$0445
	dc.w	$018c,$0334
	dc.w	$018e,$0223
	dc.w	$0192,$0434
	dc.w	$0194,$0656
	dc.w	$0196,$0878
	dc.w	$01a2,$099a
	dc.w	$01a4,$0778
	dc.w	$01a6,$0556

ScrZ	dc.w	$0102,$0000
	dc.w	$0100,$5600		 ;number of bitplanes
	dc.w	$008e,$2071           ;start display window at (81,2c)
	dc.w	$0090,$34d1           ;stop display at (c1,f4)
	dc.w	$0092,$0028           ;data fetch start
	dc.w	$0094,$00d8           ;data fetch stop
	dc.w	$0108,46*2
	dc.w	$010a,screenwidth+2
spr0h	dc.w	$0120,$0000
spr0l	dc.w	$0122,$0001
spr1h	dc.w	$0124,$0000
spr1l	dc.w	$0126,$0001
Plane0h	dc.w 	$00e4,$0000
	dc.w	$00e6,$0000
Plane1h	dc.w 	$00ec,$0000
	dc.w	$00ee,$0000

	dc.w 	$00e0,$0000
MenuPl	dc.w	$00e2,$0000
	dc.w 	$00e8,$0000
	dc.w	$00ea,$0000
	dc.w 	$00f0,$0000
	dc.w	$00f2,$0000
	dc.w	$9c,$8010	;Call Copper Interrupt

C:	set	$50+(MenuStart*10)

BarC	dc.b	C,$7b,$ff,$fe
	dc.w	$0184,$099a
	dc.w	$018c,$0556
	dc.b	C,$d7,$ff,$fe
	dc.w	$0184,$0bbc
	dc.w	$018c,$0334
C:	set	C+1
	rept	11-2
	dc.b	C,$7b,$ff,$fe
	dc.w	$0184,$0445
	dc.w	$018c,$0556
	dc.b	C,$d7,$ff,$fe
	dc.w	$0184,$0bbc
	dc.w	$018c,$0334
C:	set	C+1
	endr
	dc.b	C,$7b,$ff,$fe
	dc.w	$0184,$0778
	dc.w	$018c,$0556
	dc.b	C,$d7,$ff,$fe
	dc.w	$0184,$0bbc
	dc.w	$018c,$0334

	dc.w	$ffdd,$fffe
	dc.w	$1b01,$fffe
	dc.w	$0188,$0fff
	dc.w	$018a,$0dde
	dc.w	$018c,$0bbc
	dc.w	$018e,$0889

	dc.w	$2301,$fffe
	dc.w	$0188,$0667
	dc.w	$018a,$0445
	dc.w	$018c,$0334
	dc.w	$018e,$0223

	dc.w	$ffff,$fffe	;end copper
RVGSpr:		incbin	RvgSpr.Raw
MenuGFX:	incbin	MenuGFX.Raw
Font:		incbin	Font.Raw
Bar:		incbin	Bar.Raw
Sprite1:
	dc.w	$50<<8+(MenuStart*10)<<8+$78,$5b<<8+(MenuStart*10)<<8+$00
	dc.w	$0003,$0000
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
	dc.w	$0002,$0001
Sprite2:
	dc.w	$50<<8+(MenuStart*10)<<8+$d0,$5b<<8+(MenuStart*10)<<8+$00
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$8000,$4000
	dc.w	$0000,$c000

	incdir	"DF0:Music"
mt_data:	incbin	Mod.Chip
MusicBase:	include	NoisePlayer.s
