10 #define x r24 //==a1==Mh
19 #define Ml t //mod3 vars
21 #define a1 x //mul_ vars
48 .org 0x0000 ; RESET interrupt
51 .org 0x0004 ; PCINT0 interrupt
52 CBI PCICR, 0 ; disable interrupt
54 .org 0x0008 ; TIM0_OVF interrupt
58 .byte 0x84, 0x9d, 0xb0, 0x69, 0x9d, 0x84, 0x69, 0x58
59 .byte 0x75, 0x8c, 0xb0, 0x69, 0x8c, 0x75, 0x69, 0x58
61 mod3: ; mod3(Mh.Ml) -> t
65 ADC Mh, Mh ; store carry in Mh
104 ADD Xlo, t ; NOTE: notes are positioned so that hi8(notes) never changes
109 ; begin of mulitiplication:
118 ; BRCC skip2 -- this bit is always zero
146 BRCC skip6 ;sbrc t, NNN
161 MOV t, a1 ;;TODO: use a1 in loop: directly
164 main: ; setup routine
165 ; NOTE: clr i0 moved to .ord 0x0
169 CLR acc ; we output a dummy sample before the actual first one
170 LDI Xhi, hi8(FLASHM + notes) ; never changes
171 LDI one, 1 ; mostly for clearing TIM0_OVF bit
175 OUT SPL, x ; init stack ptr
177 OUT PUEB, zero ; disable pullups
179 OUT DDRB, x ; PORTB0:pwm, PORTB2:debug
181 OUT CCP, x ; change protected ioregs
182 OUT CLKPSR, one ; clock prescaler 1/2 (4Mhz)
183 LDI x, 0xa7 ; determined by trial-and-error (->PORTB2)
184 OUT OSCCAL, x ; set oscillator calibration
185 OUT WDTCSR, zero; turn off watchdog
187 ;set timer/counter0 to 8bit fastpwm, non-inverting, no prescaler
192 OUT TIMSK0, one ; enable tim0_ovf
197 CPI i2, 0x78>>5 ; 16m23 -- one loop
201 SLEEP ; wait for interrupt -- XXX: does not work, since we forgot to set sleep_enable bit!
205 CLR i2 ; clear halt condition
208 ; disable periphials (timer0), then set all pins as input+pullup to conserve battery.
209 LDI x, 0x3 ; could use one-register to save on ROM (would keep adc enabled on attiny5/10)
215 SBI PCMSK, 2 ; listen for pin change on the audio out pin (i.e. wake up when a audio sink is connected)
217 SBI PCICR, 0 ; enable PCINT0
219 ;enter power-down-mode
220 LDI x, 0x05 ; sleep mode: power-down, enabled
223 OUT SMCR, one ; sleep mode: idle, enabled
228 SBI PCIFR, 0 ; clear interrupt
233 OUT PRR, x ; not using zero, so devices with adc keep it disabled
238 OUT OCR0AL, acc ; start by outputting a sample, because routine has variable runtime
240 SBI PORTB, 2 ; to measure runtime
387 SWAP acc ; acc<<4, to be passed to OCR0AL
395 CBI PORTB, 2 ; end runtime measurement
397 OUT TIFR0, one ; clear pending interrupt (routine takes two intr.cycles)
398 RETI ; reenables interrupts