10 #define x r24 //==a1==Mh
19 #define Ml t //mod3 vars
21 #define a1 x //mul_ vars
44 .org 0x0000 ; RESET interrupt
49 .org 0x0008 ; TIM0_OVF interrupt
53 .byte 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58
54 .byte 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
56 mod3: ; mod3(Mh.Ml) -> t
60 ADC Mh, Mh ; store carry in Mh
99 ADD Xlo, t ; NOTE: can't overflow, since RAMEND == 0x5F
104 ; begin of mulitiplication:
113 ; BRCC skip2 -- this bit is always zero
141 BRCC skip6 ;sbrc t, NNN
156 MOV t, a1 ;;TODO: use a1 in loop: directly
159 main: ; setup routine
160 ; NOTE: clr i0..i2 moved to .ord 0x0
162 CLR acc ; we output a dummy sample before the actual first one
163 LDI Xhi, hi8(FLASHM + notes) ; never changes
164 LDI one, 1 ; mostly for clearing TIM0_OVF bit
168 OUT SPL, x ; init stack ptr
170 OUT PUEB, zero ; disable pullups
172 OUT DDRB, x ; PORTB0:pwm, PORTB2:debug
174 OUT CCP, x ; change protected ioregs
175 OUT CLKPSR, one ; clock prescaler 1/2 (4Mhz)
176 LDI x, 0xa7 ; determined by trial-and-error (->PORTB2)
177 OUT OSCCAL, x ; set oscillator calibration
178 OUT WDTCSR, zero; turn off watchdog
180 ;set timer/counter0 to 8bit fastpwm, non-inverting, no prescaler
185 OUT TIMSK0, one ; enable tim0_ovf
190 SLEEP ; wait for interrupt
194 OUT OCR0AL, acc ; start by outputting a sample, because routine has variable runtime
196 SBI PORTB, 2 ; to measure runtime
343 SWAP acc ; acc<<4, to be passed to OCR0AL
351 CBI PORTB, 2 ; end runtime measurement
353 OUT TIFR0, one ; clear pending interrupt (routine takes two intr.cycles)
354 RETI ; reenables interrupts