To expand a little more on Henrick's last post, this gets it down to 3.51ms:
Code:
tLED VAR BYTE
FOR Row = 0 to 31 ' Cycle thru 32 rows
TempW = ROW * 32 ' Precalculate this instead of doing it every time thru the loop
InPtr = TempW
FOR Col = 0 To 30 Step 2
tLED = lednew[InPtr]
led[InPtr] = tLED
OutPtr = InPtr
IF tLED > 0 THEN
NeoLed(OutPtr) = tLED
alive = alive + 1
dead = dead + InPtr
ELSE
NeoLED(OutPtr) = 0
ENDIF
InPtr = InPtr + 2
NEXT
InPtr = TempW + 1
FOR Col = 1 To 31 Step 2 ' Odd rows
tLED = lednew[InPtr]
led[InPtr] = tLED
OutPtr = (TempW) + (31-Col) 'Reversed order
IF tLED > 0 THEN
NeoLed(OutPtr) = tLED
alive = alive + 1
dead = dead + InPtr
ELSE
NeoLED(OutPtr) = 0
ENDIF
InPtr = InPtr + 2
NEXT
NEXT
You could get similar reductions in the other sections of code by eliminating multiple evaluations of things like 'led[CntMinus1]'.
Every time it sees an array access using a variable it has to recompute the value of where it's pointing to.
If you assign the array value to a temp byte
Code:
tLED = led[CntMinus1]
and use that it saves a bunch of code/time. Obviously that only works for the RHS of an equation or a test, not the LHS.
Bookmarks