IGN_ADV_FIRE: bset #ign_pin, porta ; turn on the SAW, we'll turn it off in the timer int lda rpm ; 28 x100rpm ror a ; divide rpm by 2 to get 200 rpm bins 14 x100rpm cmp #min_adv_tbl ; if rpm < min advance table rpm bls IGN_MIN_RPM ; use the minimum advance bin sub #min_adv_tbl ; 0 reference the RPM to the table 10 x100rpm bin 10 cmp #rpm_tbl_bins ; 0 to 15 bins bhi IGN_MAX_RPM ; use the maximum advance bin ldx a ; set the table offset bra IGN_SET_ADV IGN_MIN_RPM: ldx #0 ; fallthrough for min rpm bra IGN_SET_ADV IGN_MAX_RPM: ldx #adv_tbl_bins ; fallthrough for max rpm IGN_SET_ADV: lda adv_rpm_tbl, x ; get advance for rpm beq IGN_ADV_DONE ; if our delay is 0, don't SAW, the module will LOS to 10BTDC sta ign_delay ; set our count in timer ticks (100us per tick) IGN_ADV_DONE: rts IGN_ADV_KILL_CHECK: lda ign_delay beq IGN_KILL_DONE ; if it's already 0, then ignore; we get more timer ints than tach dec a beq IGN_KILL_SAW ; we hit 0, so turn off the SAW IGN_KILL_DONE: rts IGN_KILL_SAW: bclr #ign_pin, porta rts