* Solution for the exercise SX7.6

* All initializations here
INIT_DAC	LDD	TOC1	
		ADDD	#2000	;next interrupt in 1 ms
		STD	TOC1	
		LDX	#DACTAB	
		STX	XTAB	;init pointer in DACTAB
		BSET	TFLG1,$80	;clear OC1F if any
		BSET	TMSK1,$80	;enable TOC1 interrupts
		LDAA	#$FF	
		STAA	DDRA	;PORTA all lines output
		RTS		;end of initialization
* Interrupt service routine
TOC1_ISR	BSET	TFLG1,$80	;clear interrupt flag
		LDD	TOC1	
		ADDD	#2000	;next interrupt in 1 ms
		STD	TOC1	
		LDX	XTAB	
		LDAA	0,X	;get data from table
		STAA	PORTA	;write it to DAC
		INX		;increment pointer
		CPX	#ENDTAB	;check for end of table
		BHS	TOC1X	
		STX	XTAB	;update pointer and exit
		RTI		
TCO1X		LDX	#DACTAB	;reload pointer if end of ;table detected
		STX	XTAB	
		RTI		
* Table defining the output signal
DACTAB		DB	$00	
		DB	$33	
		DB	$D6	
		DB	$A3	
		DB	$7A	
		DB	$4C	
		DB	$33	
		DB	$7A	
		DB	$A3	
		DB	$4C	
ENDTAB		EQU	*	;end of table
