#MKFiles 2

; --------------------
; Register definitions
; --------------------

#REG 0	Index			; value from 63 to 1 for Y graphic animation
#REG 1	Double			; =Index*2, value from 126 to 2 for X graphic animation
#REG 20	SndPtr			; My sound pointer into my note table (5 to 0)		

; --------------------
; Initializations
; --------------------

#NUM arpege STO \PPtr		; pointer to my music table
5 STO SndPtr			; table read from element 5 to element 0 (six notes)

; --------------------
; Prepare Interruption
; --------------------

1 EXEC \InterClear		; clear all interrupt informations
1 STO \InterEnable		; enable Interrupts

#NUM note ENT
1
	SET \Inter10		; Interrupt 10 will execute "note" with priority 1

$10
	STO \InterTimer2	; This interrupt 10 will be activated at the end of Timer 2 (end sound)

EXEC \InterCall			; initiate the process calling the first note ($10 yet on the stack)

; --------------------
; Prepare graphics
; --------------------

2 EXEC \Cls			; clear screen
3 SET \Gmode			; XOR mode
GRPH				; display graph

; --------------------
; Main infinite loop
; --------------------

DO

	$63 STO Index		; this is a little animation with lines

	FOR Index
		@Index 2 	SET \x0y0
		@Index $127 	EXEC \Lineto
		1 @Index 2 * =Double 1 +
				SET \x0y0
		$63 @Double 1 + EXEC \Lineto
		1 @Double 	SET \x0y0
		$63 @Double 	EXEC \Lineto
		GRPH
	NEXT
	
LOOP				; repeat animation
	
; --------------------
; Interruption at each sound end
; --------------------

note:					; each time a note ends, jump here !
	@SndPtr EXEC \GetTableWord	; one frequency from my table
	$50				; duration 50/100 = 0.5 sec
		SET \Sound		; play note
	@SndPtr 1 - 			; new pointer
	IF(X<0)THEN 5 ENDIF		; if -1, then back to 5
	STO SndPtr			; store pointer
	RTI				; return from interrupt

; --------------------
; My table with notes
; --------------------

arpege:
	#DW 659 784 1046 784 659 523 #END
