	opt c- o+
NumStars	equ	30
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
bpwidth:	equ	320
bpheight:	equ	200
start:
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup
	dc.w	$a00a

	lea	palsave,a0
	move.l	#$ff8240,a1
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+

	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp
	bsr	getscrn
	lea	greypalette,a0
	bsr	mydocolors
	bsr	putpause

	bsr	setuptracker

mainloop:
	bsr	copy
	bsr	keyboard
	bsr	flip_scr
	bra	mainloop

flip_scr:
	move.l	seen,d1
	move.l	d1,d2
	add.l	#4000,d1
	add.l	#18000,d2
skloop:
	lea	$ff8205,a0
	moveq	#0,d0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	asl.l	#8,d0
	addq.l	#2,a0
	move.b	(a0),d0
	cmp.l	d1,d0
	blt.s	skloop
	cmp.l	d2,d0
	bgt.s	skloop
        move.l  seen,A0
        move.l  hiden,seen
        move.l  A0,hiden
	move.b	seen+1,$ff8201
	move.b	seen+2,$ff8203
	rts

putpause:
	move.l	seen,a0
	move.l	hiden,a1
	lea	pauseimg,a2
	lea	194*160+6(a0),a0
	lea	194*160+6(a1),a1
	move.l	a0,a3
	move.l	a1,a4
	moveq	#4,d0
pploop:
	move.l	a3,a0
	move.l	a4,a1
	rept	7
	move.w	(a2),(a0)+
	move.w	(a2)+,(a1)+
	addq.l	#6,a0
	addq.l	#6,a1
	endr
	lea	160(a3),a3
	lea	160(a4),a4
	dbf	d0,pploop
	rts

save_ints:				*save interrupts
	move.b	$fffffa07.w,mfpa07
	move.b	$fffffa09.w,mfpa09
	move.b	$fffffa13.w,mfpa13
	move.b	$fffffa15.w,mfpa15
	move.b	$fffffa19.w,mfpa19
	move.b	$fffffa1f.w,mfpa1f
	move.l	$134.w,old134
	move.l	$70.w,oldvbl
	rts
init_ints:				*init. interrupts
	clr.b	$fffffa09.w
	clr.b	$fffffa15.w
	move.w	module+$90,d0
	lea	mfp_freqs(pc),a0
	move.b	(a0,d0.w),$fffffa1f.w
	move.b	#2,$fffffa19.w
	move.b	#32,$fffffa07.w
	move.b	#32,$fffffa13.w
	bclr	#3,$fffffa17.w
	move.l	#replay_rot+$88ca,$134.w
	move.l	#vbi,$70.w
	rts
mfp_freqs:				*10 and 8.3 khz
	dc.b	24
	dc.b	29
ret_ints:				*restore interrupts
	move.b	mfpa07,$fffffa07.w
	move.b	mfpa09,$fffffa09.w
	move.b	mfpa13,$fffffa13.w
	move.b	mfpa15,$fffffa15.w
	move.b	mfpa19,$fffffa19.w
	move.b	mfpa1f,$fffffa1f.w
	move.l	old134,$134.w
	move.l	oldvbl,$70.w
	rts	
mfpa07:	dc.b	0			*the vars for saving interrupts
mfpa09:	dc.b	0
mfpa13:	dc.b	0
mfpa15:	dc.b	0
mfpa19:	dc.b	0
mfpa1f:	dc.b	0
old134:	dc.l	0
oldvbl:	dc.l	0

init_ste:
	move.w	#0,$ffff8900.w		*init. STE
	lea	setsam_dat(pc),a0
	move.w	#3,d0
mwwrite:
	move.w	#$7ff,$ffff8924.w
mwwrite2:
	cmp.w	#$07ff,$ffff8924.w
	bne.s	mwwrite2
	move.w	(a0)+,$ffff8922.w
	dbra	d0,mwwrite

	move.l	#$486,temp			
	move.b	temp+1(pc),$ffff8903.w
	move.b	temp+2(pc),$ffff8905.w
	move.b	temp+3(pc),$ffff8907.w

	move.l	#$488,temp
	move.b	temp+1(pc),$ffff890f.w
	move.b	temp+2(pc),$ffff8911.w
	move.b	temp+3(pc),$ffff8913.w

	move.w	#%0000000000000001,$ffff8920.w
	move.w	#3,$ffff8900.w
	rts
setuptracker:
	jsr	init_ste(pc)		*init. ste
	lea	module,a0		*a0=module start
	jsr	replay_rot+$20(pc)	*init. replay routine
	jsr	save_ints(pc)		*save interrupts
	jsr	init_ints(pc)		*init. interrupts
	clr.w	wfnc
	rts

vbi:
	movem.l	d0-d5/a0-a1,-(sp)	*save regs.
*	move.w	#$0000,$ff8240
	bsr	replay_rot+$24		*jump to music rout
*	bsr	stars
*	move.w	#$0002,$ff8240
	movem.l	(sp)+,d0-d5/a0-a1	*pop regs.
	rte
temp:
	dc.l	0
setsam_dat:
	dc.w	%0000000011010100  	*mastervol
	dc.w	%0000010010000110  	*treble
	dc.w	%0000010001000110  	*bass
	dc.w	%0000000000000001  	*mixer


copy:
	tst.w	paused
	bpl	nsc
	addi.l	#40,scrolly
nsc:	move.l	hiden,a1
	lea	160*10+6(a1),a1
*	addq.l	#6,a1
	lea	scrolltext,a0
	add.l	scrolly,a0
	cmp.l	#scrollend-8000,a0
	bne	cpl
	move.l	#0,scrolly
cpl:
	rept	20*179
	move.w	(a0)+,(a1)+
	addq.l	#6,a1
	endr
	rts

scrolly:
	dc.l	0


****************************************
keyboard:
*	subq.w	#1,kdelay
*	bpl	keyback
*	move.w	#5,kdelay


	cmp.b	#144,$fffc02		*space
	beq	gem		*yes/no

	cmp.b	#57,$fffc02
	bne	keyback
	move.w	#1,paused
	rts

keyback:
	move.w	#-1,paused
	rts
paused:	dc.w	-1
kdelay:	dc.w	5

*****************************************
*	number in d0.l			*
*	d1.l is base			*
*	d2,x cursor			*
*	d3,y cursor			*
*****************************************
prtnum:
	movem.l	d0/d1,-(sp)
	lea	posstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
	move.b	d3,10(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
	move.b	d2,11(a0)	
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d0/d1

	lea	linebuffer,a0
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
loop1:
	divu	d1,d0
	swap	d0
	addi	#'0',d0
	cmpi.w	#'9',d0
	ble.s	ok
	addq.w	#7,d0
ok:
	move.b	d0,-(a0)
	clr	d0
	swap	d0
	bne	loop1
loop2:
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts


linebuffer:
	ds.l	5
digits:
	dc.b	0
posstring:	dc.b	27,'Y',0,0,' ',' ',' ',' ',27,'Y',0,0,0
even



***********************************
mydocolors:
	move.l	#$ff8240,a1
	moveq	#15,d0
mdcloop:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop
	rts

************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,seen
	sub.l	#$8000,d0
	move.l	d0,hiden

	move.l	seen,a0
	move.l	hiden,a1
	move.w	#7999,d0
cl:
	move.l	#0,(a0)+
	move.l	#0,(a1)+
	dbf	d0,cl
	rts


******************************************
*               RETURN TO GEM
gem:
	jsr	ret_ints		*restore interrupts
	move.b	#%11111110,$ff820a
	move.l	#$ff8240,a0
	lea	palsave,a1
	moveq	#15,d7
rspl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,(a0)+
	dbf	d7,rspl
*	move.l	vblslot,a0
*	move.l	#0,(a0)

        move.w  ressave,-(sp)
        move.l  seen,-(sp)
        move.l  seen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        add.l  #12,sp

	move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
*illegal
	clr.w	-(sp)
	trap	#1

rvsave:	dc.l	0
resave:	dc.l	0
	even
savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
greypalette:
*	incbin	'ste.pal'
	dc.w	$0000,$0222,$0444,$000f,$0fff,$000f,$000f
	dc.w	$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f
	dc.w	$000f,$000f
save_usp:
	dc.l	0
wfnc:
	dc.w	0
save_stk:
	dc.l	0
pointer:	dc.l	0
flip:	dc.w	0
flip2:	dc.w	0
seen:	dc.l	0
hiden:	dc.l	0
clrbuffseen:	dc.l	0
clrbuffhiden:	dc.l	0
screen:	dc.l	0
	ds.w	16
*	section	bss
number:	ds.w	1
palsave:
	ds.w	16
vblslot:	ds.l	1
d7emulator:	ds.w	1
pauseimg:
	 dc.w	$7BC7,$1CFB,$C73C,$03E7,$00F1,$C89E,$F800,$8228
	 dc.w	$A282,$28A2,$0088,$808A,$28A0,$8000,$73CF,$A0F3
	 dc.w	$CFBC,$0088,$80F3,$E89C,$F000,$0A08,$A282,$28A4
	 dc.w	$0088,$8082,$2882,$8000,$F208,$9CFB,$E8A2,$0087
	 dc.w	$0082,$273C,$F800


replay_rot:				*the replay routine
	incbin	e:\demo\trackere.rot
	even
module:					*the module
	incbin 	c:\mytdm2.mod
	even
scrolltext:
	ds.b	8000
	incbin	e:\demo\ste.raw
scrollend:
	even
