Hi again, Nevo:
Here is a face-saving exercise, in my typical cycle-counting style.
I counted the cycles in your routine, and found that it takes 63 cycles most of the time, and an additional 2 cycles when a triac triggers.
LDX m_DimmerCount ; 3
CLRA ; 1
CPX m_ChannelDimValue:0 ; 4
BNE testCh1 ; 3
ORA #1 ; 2
testCh1:
CPX m_ChannelDimValue:1 ; 4
BNE testCh2 ; 3
ORA #2 ; 2
testCh2:
CPX m_ChannelDimValue:2 ; 4
BNE testCh3 ; 3
ORA #4 ; 2
testCh3:
CPX m_ChannelDimValue:3 ; 4
BNE testCh4 ; 3
ORA #8 ; 2
testCh4:
CPX m_ChannelDimValue:4 ; 4
BNE testCh5 ; 3
ORA #16 ; 2
testCh5:
CPX m_ChannelDimValue:5 ; 4
BNE testCh6 ; 3
ORA #32 ; 2
testCh6:
CPX m_ChannelDimValue:6 ; 4
BNE testCh7 ; 3
ORA #64 ; 2
testCh7:
CPX m_ChannelDimValue:7 ; 4
BNE writePortA ; 3
ORA #128 ; 2
writePortA:
STA _PTAD ; 3
; ;--
; =63 cycles + 2 cycles for each light that comes on
I have an uglier version, which does it in 38 cycles most of the time, but takes 7 additional cycles when the triac triggers.
;
; Index through the table, checking each value.
;
LDA m_DimmerCount ; 3
LDHX m_ChannelDimValue ; 3
;
CBEQ X+,on1 ; 4
do2: CBEQ X+,on2 ; 4
do3: CBEQ X+,on3 ; 4
do4: CBEQ X+,on4 ; 4
do5: CBEQ X+,on5 ; 4
do6: CBEQ X+,on6 ; 4
do7: CBEQ X+,on7 ; 4
do8: CBEQ X+,on8 ; 4
done: RTN ?
; ;--
; =38 cycles + 7 cycles for each light that comes on
;
; Each one of these turns a light on.
;
on1: BSET 0,_PTAD ; 4
BRA do2 ; 3
;
on2: BSET 1,_PTAD ; 4
BRA do3 ; 3
;
on3: BSET 2,_PTAD ; 4
BRA do4 ; 3
;
on4: BSET 3,_PTAD ; 4
BRA do5 ; 3
;
on5: BSET 4,_PTAD ; 4
BRA do6 ; 3
;
on6: BSET 5,_PTAD ; 4
BRA do7 ; 3
;
on7: BSET 6,_PTAD ; 4
BRA do8 ; 3
;
on8: BSET 7,_PTAD ; 4
BRA done ; 3
This one does use indexed addressing, so the table can be anywhere in memory. This is what I mistakenly thought you were doing originally.