+sei
+
+; jump to mainloop
+rjmp MAIN
+
+; ------------
+; main routine
+; ------------
+
+MAIN:
+
+; loop and wait for interrupts
+rjmp MAIN
+
+; ----------------
+; rec_card routine
+; ----------------
+
+REC_CARD:
+
+; save counter
+in counter_l,ICR1L
+in counter_h,ICR1H
+
+; toggle state
+eor state,state_m
+
+; toggle icp sense
+rcall TOGGLE_ICP_SENSE
+
+; fwd to cam if in stupid mode
+sbrc mode,STUPID_F
+rcall FWD_TO_CAM
+
+; calculate delta clocks if in stupid mode
+sbrc mode,COOL_F
+rcall CALC_DELTA_CLOCK ; -> calc delta, store to counter_l_tmp, counter_h_tmp
+
+; send time and state via uart
+sbrc mode,COOL_F
+rcall SEND_TO_UART ; -> prepare date & enable uart dre interrupt (sbi UCR,UDRIE)
+
+; return
+reti
+
+; ------------------------
+; toggle_icp_sense routine
+; ------------------------
+
+TOGGLE_ICP_SENSE:
+
+; toggle according to state
+cbi TCCR1B,ICES1
+sbrs state,HIGH
+sbi TCCR1B,ICES1
+
+; return
+ret
+
+; ------------------
+; fwd_to_cam routine
+; ------------------
+
+; output state on port to cam
+mov tmp,state
+andi tmp,HIGH
+lsl tmp ; as we have to set pd3 (dirty, shorter way?)
+sbi DDRD,DDD3
+out PORTD,tmp ; <- hunz: low or high if pd3 bit is set ?
+
+; return
+ret