*
*
*	Obnoxio's MAD MAX musak player
*	use tab of 8 for tidy listing!
*
*	if you want to hear the music at the right speed
*	look at the hertz changer, and incorprate ONE line into
*	this code. I won't tell you which one...you figure it out!
*
* go from user mode to supervisor mode or else you can't fiddle with the
* interrupts or any other protected vector....ie hertz mode. 
	
	clr.l	-(a7)		;clear stack 
	move.w	#$20,-(a7)	;push 32 onto stack (supervisor call#)
	trap	#1		;call gem
	add.l	#6,sp		;clean up stack
	move.l	d0,ss		;save user stack pointer

* If you don't save the user stack after calling supervisor, you may 
* experience a crash when you return to user....Neat, if yer into that
* Sort of thing.... 

	eori.b	#2,$ff820a
* Stick music routine in the interupt and wait for key press
	clr.l	$4d6
	moveq	#1,d0		;stick # of music into d0 register
				;there may be more than 1 music file
				; use different numbers here...up to $F
	jsr	music+4		;jump subroutine 'music'	
	move.l	#music,$4d6	;move address of music into interupt at $4de
	move.w	#1,-(sp)	;put 1 on stack (conin call#) wait for key press
	trap	#1		;call gem
	addq.l	#2,sp		;tidy up 

	move.b 	#1,music+$59e
	move.b	#7,$ff8800
	move.b	#$ff,$ff8802
* Tidy up everything and exit supervisor mode	

	clr.l	$4d6		;clear out the interrupt..see NOTE
	move.l	ss,-(sp)	;put user stack pointer back
	move.w	#$20,-(sp)	;call super again...got to user this time
	trap	#1		;call gem
	add.l	#6,sp		;tidy the stack

* Return to calling program...in this case GEM

	clr.w	-(a7)		;put 0 onto stack...quicker this way
	trap	#1		;call gem...and return to gem...or whatever

* NOTE...if you don't clear $4de before you exit...music will play
* after you have exited...makes for background music while using GEM
* crashes if anything elses tries to use $4de though....flash doesn't!
	
music	incbin	spud.eds
	
ss	dc.w	0		;declare all variables...1 this time
